Skip to content

Commit c087b0a

Browse files
committed
improved transitionAxes yes/no logic
- use old vs new (after subroutines.doAutoRangeAndConstraints) range values to determine if we call transitionAxes or not, instead of "just" calling transitionAxes for all subplots with altered *and* autoranged axes.
1 parent 19e2bb2 commit c087b0a

File tree

3 files changed

+85
-15
lines changed

3 files changed

+85
-15
lines changed

src/plot_api/plot_api.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,7 +2872,6 @@ function diffLayout(gd, oldFullLayout, newFullLayout, immutable, transition) {
28722872
var flags = editTypes.layoutFlags();
28732873
flags.arrays = {};
28742874
flags.rangesAltered = {};
2875-
flags.autorangedAxes = {};
28762875
flags.nChanges = 0;
28772876
flags.nChangesAnim = 0;
28782877

@@ -2948,11 +2947,6 @@ function getDiffFlags(oldContainer, newContainer, outerparts, opts) {
29482947
var parts = outerparts.concat(key);
29492948
astr = parts.join('.');
29502949

2951-
// track auto-ranged cartesian axes, changed or not
2952-
if(AX_AUTORANGE_RE.test(astr) && newVal === true) {
2953-
flags.autorangedAxes[outerparts[0]] = 1;
2954-
}
2955-
29562950
if(key.charAt(0) === '_' || typeof oldVal === 'function' || oldVal === newVal) continue;
29572951

29582952
// FIXME: ax.tick0 and dtick get filled in during plotting (except for geo subplots),

src/plots/plots.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,8 +2541,6 @@ plots.transition2 = function(gd, restyleFlags, relayoutFlags, oldFullLayout) {
25412541
function prepareTransitions() {
25422542
var fullLayout = gd._fullLayout;
25432543
var subplots = fullLayout._plots;
2544-
var rangesAltered = relayoutFlags.rangesAltered;
2545-
var autorangedAxes = relayoutFlags.autorangedAxes;
25462544

25472545
// no need to redraw at end of transition,
25482546
// if all changes are animatable
@@ -2555,16 +2553,23 @@ plots.transition2 = function(gd, restyleFlags, relayoutFlags, oldFullLayout) {
25552553
var plotinfo = subplots[k];
25562554
var xa = plotinfo.xaxis;
25572555
var ya = plotinfo.yaxis;
2556+
var xr0 = oldFullLayout[xa._name].range.slice();
2557+
var yr0 = oldFullLayout[ya._name].range.slice();
2558+
var xr1 = xa.range.slice();
2559+
var yr1 = ya.range.slice();
25582560

2559-
if(rangesAltered[xa._name] || rangesAltered[ya._name] ||
2560-
autorangedAxes[xa._name] || autorangedAxes[ya._name]
2561+
xa.setScale();
2562+
ya.setScale();
2563+
2564+
if(xr0[0] !== xr1[0] || xr0[1] !== xr1[1] ||
2565+
yr0[0] !== yr1[0] || yr0[1] !== yr1[1]
25612566
) {
25622567
edits[k] = {
25632568
plotinfo: plotinfo,
2564-
xr0: oldFullLayout[xa._name].range.slice(),
2565-
yr0: oldFullLayout[ya._name].range.slice(),
2566-
xr1: xa.range.slice(),
2567-
yr1: ya.range.slice()
2569+
xr0: xr0,
2570+
yr0: yr0,
2571+
xr1: xr1,
2572+
yr1: yr1
25682573
};
25692574
}
25702575
}

test/jasmine/tests/transition_test.js

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ describe('Plotly.react transitions:', function() {
643643
.then(done);
644644
});
645645

646-
it('should transition layout when one or more axes has *autorange:true*', function(done) {
646+
it('should transition layout when one or more axis auto-ranged value changed', function(done) {
647647
var data = [{y: [1, 2, 1]}];
648648
var layout = {transition: {duration: 10}};
649649

@@ -662,6 +662,7 @@ describe('Plotly.react transitions:', function() {
662662
assertAxAutorange('axes are autorange:true by default', true);
663663
})
664664
.then(function() {
665+
// N.B. marker.size can expand axis range
665666
data[0].marker = {size: 30};
666667
return Plotly.react(gd, data, layout);
667668
})
@@ -698,6 +699,76 @@ describe('Plotly.react transitions:', function() {
698699
.then(done);
699700
});
700701

702+
it('should not transition layout when axis auto-ranged value do not changed', function(done) {
703+
var data = [{y: [1, 2, 1]}];
704+
var layout = {transition: {duration: 10}};
705+
706+
function assertAxAutorange(msg, exp) {
707+
expect(gd.layout.xaxis.autorange).toBe(exp, msg);
708+
expect(gd.layout.yaxis.autorange).toBe(exp, msg);
709+
expect(gd._fullLayout.xaxis.autorange).toBe(exp, msg);
710+
expect(gd._fullLayout.yaxis.autorange).toBe(exp, msg);
711+
}
712+
713+
Plotly.react(gd, data, layout)
714+
.then(function() {
715+
methods.push([gd._fullLayout._basePlotModules[0], 'plot']);
716+
methods.push([gd._fullLayout._basePlotModules[0], 'transitionAxes2']);
717+
addSpies();
718+
assertAxAutorange('axes are autorange:true by default', true);
719+
})
720+
.then(function() {
721+
// N.B. different coordinate, but same auto-range value
722+
data[0].y = [2, 1, 2];
723+
return Plotly.react(gd, data, layout);
724+
})
725+
.then(function() {
726+
assertSpies('do not transition autoranged axes, just the traces', [
727+
[Plots, 'transition2', 1],
728+
[gd._fullLayout._basePlotModules[0], 'transitionAxes2', 0],
729+
[gd._fullLayout._basePlotModules[0], 'plot', 1]
730+
]);
731+
assertAxAutorange('axes are still autorange:true', true);
732+
})
733+
.then(function() {
734+
// N.B. different coordinates with different auto-range value
735+
data[0].y = [20, 10, 20];
736+
return Plotly.react(gd, data, layout);
737+
})
738+
.then(function() {
739+
assertSpies('both trace and layout transitions', [
740+
[Plots, 'transition2', 1],
741+
[gd._fullLayout._basePlotModules[0], 'transitionAxes2', 1],
742+
[Registry, 'call', [
743+
// xaxis call to _storeDirectGUIEdit from doAutoRange
744+
['_storeDirectGUIEdit', gd.layout, gd._fullLayout._preGUI, {
745+
'xaxis.range': [-0.12852664576802508, 2.128526645768025],
746+
'xaxis.autorange': true
747+
}],
748+
// yaxis call to _storeDirectGUIEdit from doAutoRange
749+
['_storeDirectGUIEdit', gd.layout, gd._fullLayout._preGUI, {
750+
'yaxis.range': [9.26751592356688, 20.73248407643312],
751+
'yaxis.autorange': true
752+
}],
753+
['relayout', gd, {
754+
'xaxis.range': [-0.12852664576802508, 2.128526645768025],
755+
'yaxis.range': [9.26751592356688, 20.73248407643312]
756+
}]]
757+
],
758+
[gd._fullLayout._basePlotModules[0], 'plot', [
759+
// one instantaneous transition options to halt
760+
// other trace transitions (if any)
761+
[gd, null, {duration: 0, easing: 'cubic-in-out'}, 'function'],
762+
// one _module.plot call from the relayout at end of axis transition
763+
[gd]
764+
]],
765+
]);
766+
assertAxAutorange('axes are now autorange:false', false);
767+
})
768+
.catch(failTest)
769+
.then(done);
770+
});
771+
701772
it('should emit transition events', function(done) {
702773
var events = ['transitioning', 'transitioned', 'react'];
703774
var store = {};

0 commit comments

Comments
 (0)