Skip to content

Commit c708190

Browse files
committed
fix axis range animation for bar traces
... and other traces that require a _module.setPositions call
1 parent ecebe14 commit c708190

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

src/plot_api/plot_api.js

+1-23
Original file line numberDiff line numberDiff line change
@@ -292,29 +292,7 @@ exports.plot = function(gd, data, layout, config) {
292292
return;
293293
}
294294

295-
var subplots = fullLayout._subplots.cartesian;
296-
var modules = fullLayout._modules;
297-
var setPositionsArray = [];
298-
299-
// position and range calculations for traces that
300-
// depend on each other ie bars (stacked or grouped)
301-
// and boxes (grouped) push each other out of the way
302-
303-
var subplotInfo, i, j;
304-
305-
for(j = 0; j < modules.length; j++) {
306-
Lib.pushUnique(setPositionsArray, modules[j].setPositions);
307-
}
308-
309-
if(setPositionsArray.length) {
310-
for(i = 0; i < subplots.length; i++) {
311-
subplotInfo = fullLayout._plots[subplots[i]];
312-
313-
for(j = 0; j < setPositionsArray.length; j++) {
314-
setPositionsArray[j](gd, subplotInfo);
315-
}
316-
}
317-
}
295+
Plots.doSetPositions(gd);
318296

319297
// calc and autorange for errorbars
320298
Registry.getComponentMethod('errorbars', 'calc')(gd);

src/plots/plots.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -2238,9 +2238,8 @@ plots.transition = function(gd, data, layout, traces, frameOpts, transitionOpts)
22382238
delete gd.calcdata;
22392239

22402240
plots.supplyDefaults(gd);
2241-
22422241
plots.doCalcdata(gd);
2243-
2242+
plots.doSetPositions(gd);
22442243
Registry.getComponentMethod('errorbars', 'calc')(gd);
22452244

22462245
return Promise.resolve();
@@ -2265,7 +2264,6 @@ plots.transition = function(gd, data, layout, traces, frameOpts, transitionOpts)
22652264
var aborted = false;
22662265

22672266
function executeTransitions() {
2268-
22692267
gd.emit('plotly_transitioning', []);
22702268

22712269
return new Promise(function(resolve) {
@@ -2564,6 +2562,30 @@ function clearAxesCalc(axList) {
25642562
}
25652563
}
25662564

2565+
plots.doSetPositions = function(gd) {
2566+
var fullLayout = gd._fullLayout;
2567+
var subplots = fullLayout._subplots.cartesian;
2568+
var modules = fullLayout._modules;
2569+
var methods = [];
2570+
var i, j;
2571+
2572+
// position and range calculations for traces that
2573+
// depend on each other ie bars (stacked or grouped)
2574+
// and boxes (grouped) push each other out of the way
2575+
2576+
for(j = 0; j < modules.length; j++) {
2577+
Lib.pushUnique(methods, modules[j].setPositions);
2578+
}
2579+
if(!methods.length) return;
2580+
2581+
for(i = 0; i < subplots.length; i++) {
2582+
var subplotInfo = fullLayout._plots[subplots[i]];
2583+
for(j = 0; j < methods.length; j++) {
2584+
methods[j](gd, subplotInfo);
2585+
}
2586+
}
2587+
};
2588+
25672589
plots.rehover = function(gd) {
25682590
if(gd._fullLayout._rehover) {
25692591
gd._fullLayout._rehover();

test/jasmine/tests/animate_test.js

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var Lib = require('@src/lib');
33
var Registry = require('@src/registry');
44
var Plots = Plotly.Plots;
55

6+
var d3 = require('d3');
67
var createGraphDiv = require('../assets/create_graph_div');
78
var destroyGraphDiv = require('../assets/destroy_graph_div');
89
var failTest = require('../assets/fail_test');
@@ -862,6 +863,11 @@ describe('animating scatter traces', function() {
862863
});
863864
})
864865
.then(function() {
866+
// sanity-check that scatter points and bars are still there
867+
var gd3 = d3.select(gd);
868+
expect(gd3.select('.scatterlayer').selectAll('.point').size()).toBe(3, '# of pts on graph');
869+
expect(gd3.select('.barlayer').selectAll('.point').size()).toBe(3, '# of bars on graph');
870+
865871
// the only redraw should occur during Cartesian.transitionAxes,
866872
// where Registry.call('relayout') is called leading to a _module.plot call
867873
expect(gd._fullData[0]._module.basePlotModule.transitionAxes).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)