Skip to content

Commit d9f6c1b

Browse files
authored
Merge pull request #1488 from plotly/restyle-docalc
Make restyling arrayOk attribute redo calcdata
2 parents 388287b + 7dcaef3 commit d9f6c1b

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/plot_api/plot_api.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1576,9 +1576,17 @@ function _restyle(gd, aobj, _traces) {
15761576
helpers.manageArrayContainers(param, newVal, undoit);
15771577
flags.docalc = true;
15781578
}
1579-
// all the other ones, just modify that one attribute
1580-
else param.set(newVal);
1579+
else {
1580+
var moduleAttrs = (contFull._module || {}).attributes || {};
1581+
var valObject = Lib.nestedProperty(moduleAttrs, ai).get() || {};
15811582

1583+
if(valObject.arrayOk && (Array.isArray(newVal) || Array.isArray(oldVal))) {
1584+
flags.docalc = true;
1585+
}
1586+
1587+
// all the other ones, just modify that one attribute
1588+
param.set(newVal);
1589+
}
15821590
}
15831591

15841592
// swap the data attributes of the relevant x and y axes?

test/jasmine/tests/plot_api_test.js

+30
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,36 @@ describe('Test plot api', function() {
285285
expect(gd.calcdata).toBeDefined();
286286
});
287287

288+
it('should do full replot when arrayOk attributes are updated', function() {
289+
var gd = {
290+
data: [{x: [1, 2, 3], y: [1, 2, 3]}],
291+
layout: {}
292+
};
293+
294+
mockDefaultsAndCalc(gd);
295+
Plotly.restyle(gd, 'marker.color', [['red', 'green', 'blue']]);
296+
expect(gd.calcdata).toBeUndefined();
297+
expect(PlotlyInternal.plot).toHaveBeenCalled();
298+
299+
mockDefaultsAndCalc(gd);
300+
PlotlyInternal.plot.calls.reset();
301+
Plotly.restyle(gd, 'marker.color', 'yellow');
302+
expect(gd.calcdata).toBeUndefined();
303+
expect(PlotlyInternal.plot).toHaveBeenCalled();
304+
305+
mockDefaultsAndCalc(gd);
306+
PlotlyInternal.plot.calls.reset();
307+
Plotly.restyle(gd, 'marker.color', 'blue');
308+
expect(gd.calcdata).toBeDefined();
309+
expect(PlotlyInternal.plot).not.toHaveBeenCalled();
310+
311+
mockDefaultsAndCalc(gd);
312+
PlotlyInternal.plot.calls.reset();
313+
Plotly.restyle(gd, 'marker.color', [['red', 'blue', 'green']]);
314+
expect(gd.calcdata).toBeUndefined();
315+
expect(PlotlyInternal.plot).toHaveBeenCalled();
316+
});
317+
288318
it('calls plot on xgap and ygap styling', function() {
289319
var gd = {
290320
data: [{z: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], showscale: false, type: 'heatmap'}],

0 commit comments

Comments
 (0)