Skip to content

Commit 66c3ca0

Browse files
committed
restyle: call manageArrayContainers on array-container updates
- at the moment that means 'on restyle involving transforms'
1 parent e2524ea commit 66c3ca0

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

src/plot_api/plot_api.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1414,9 +1414,6 @@ function _restyle(gd, aobj, _traces) {
14141414
continue;
14151415
}
14161416

1417-
// take no chances on transforms
1418-
if(ai.substr(0, 10) === 'transforms') flags.docalc = true;
1419-
14201417
// set attribute in gd.data
14211418
undoit[ai] = a0();
14221419
for(i = 0; i < traces.length; i++) {
@@ -1556,6 +1553,10 @@ function _restyle(gd, aobj, _traces) {
15561553
}
15571554
helpers.swapXYData(cont);
15581555
}
1556+
else if(Plots.dataArrayContainers.indexOf(param.parts[0]) !== -1) {
1557+
helpers.manageArrayContainers(param, newVal, undoit);
1558+
flags.docalc = true;
1559+
}
15591560
// all the other ones, just modify that one attribute
15601561
else param.set(newVal);
15611562

test/jasmine/tests/transform_multi_test.js

+67
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,70 @@ describe('multiple traces with transforms:', function() {
580580
});
581581
});
582582
});
583+
584+
describe('restyle applied on transforms:', function() {
585+
'use strict';
586+
587+
afterEach(destroyGraphDiv);
588+
589+
it('should be able', function(done) {
590+
var gd = createGraphDiv();
591+
592+
var data = [{ y: [2, 1, 2] }];
593+
594+
var transform0 = {
595+
type: 'filter',
596+
target: 'y',
597+
operation: '>',
598+
value: 1
599+
};
600+
601+
var transform1 = {
602+
type: 'groupby',
603+
groups: ['a', 'b', 'b']
604+
};
605+
606+
Plotly.plot(gd, data).then(function() {
607+
expect(gd.data.transforms).toBeUndefined();
608+
609+
return Plotly.restyle(gd, 'transforms[0]', transform0);
610+
})
611+
.then(function() {
612+
var msg = 'to generate blank transform objects';
613+
614+
expect(gd.data[0].transforms[0]).toBe(transform0, msg);
615+
616+
// make sure transform actually works
617+
expect(gd._fullData[0].y).toEqual([2, 2], msg);
618+
619+
return Plotly.restyle(gd, 'transforms[1]', transform1);
620+
})
621+
.then(function() {
622+
var msg = 'to generate blank transform objects (2)';
623+
624+
expect(gd.data[0].transforms[0]).toBe(transform0, msg);
625+
expect(gd.data[0].transforms[1]).toBe(transform1, msg);
626+
expect(gd._fullData[0].y).toEqual([2], msg);
627+
628+
return Plotly.restyle(gd, 'transforms[0]', null);
629+
})
630+
.then(function() {
631+
var msg = 'to remove transform objects';
632+
633+
expect(gd.data[0].transforms[0]).toBe(transform1, msg);
634+
expect(gd.data[0].transforms[1]).toBeUndefined(msg);
635+
expect(gd._fullData[0].y).toEqual([2], msg);
636+
expect(gd._fullData[1].y).toEqual([1, 2], msg);
637+
638+
return Plotly.restyle(gd, 'transforms', null);
639+
})
640+
.then(function() {
641+
var msg = 'to remove all transform objects';
642+
643+
expect(gd.data[0].transforms).toBeUndefined(msg);
644+
expect(gd._fullData[0].y).toEqual([2, 1, 2], msg);
645+
})
646+
.then(done);
647+
});
648+
649+
});

0 commit comments

Comments
 (0)