diff --git a/draftlogs/7283_fix.md b/draftlogs/7283_fix.md new file mode 100644 index 00000000000..d848bdd74b7 --- /dev/null +++ b/draftlogs/7283_fix.md @@ -0,0 +1 @@ +- Fix handling of new domain values given in the Plotly.react function to prevent loss of new domain values. [[#7283](https://github.com/plotly/plotly.js/pull/7283)] \ No newline at end of file diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 39f9bc93496..d38f3c861d0 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -2811,6 +2811,32 @@ function diffLayout(gd, oldFullLayout, newFullLayout, immutable, transition) { return PlotSchema.getLayoutValObject(newFullLayout, parts); } + // Clear out any _inputDomain that's no longer valid + for (var key in newFullLayout) { + if (!key.startsWith('xaxis') && !key.startsWith('yaxis')) { + continue; + } + if (!oldFullLayout[key]) { + continue; + } + var newDomain = newFullLayout[key].domain; + var oldDomain = oldFullLayout[key].domain; + var oldInputDomain = oldFullLayout[key]._inputDomain; + if (oldFullLayout[key]._inputDomain) { + if (newDomain[0] === oldInputDomain[0] && newDomain[1] === oldInputDomain[1]) { + // what you're asking for hasn't changed, so let plotly.js start with what it + // concluded last time and iterate from there + newFullLayout[key].domain = oldFullLayout[key].domain; + } else if (newDomain[0] !== oldDomain[0] || newDomain[1] !== oldDomain[1]) { + // what you're asking for HAS changed, so clear _inputDomain and let us start from scratch + newFullLayout[key]._inputDomain = null; + } + // We skip the else case (newDomain !== oldInputDomain && newDomain === oldDomain) + // because it's likely that if the newDomain and oldDomain are the same, the user + // passed in the same layout object and we should keep the _inputDomain. + } + } + var diffOpts = { getValObject: getLayoutValObject, flags: flags, @@ -2863,11 +2889,6 @@ function getDiffFlags(oldContainer, newContainer, outerparts, opts) { flags.rangesAltered[outerparts[0]] = 1; } - // clear _inputDomain on cartesian axes with altered domains - if(AX_DOMAIN_RE.test(astr)) { - nestedProperty(newContainer, '_inputDomain').set(null); - } - // track datarevision changes if(key === 'datarevision') { flags.newDataRevision = 1; diff --git a/test/jasmine/tests/axes_test.js b/test/jasmine/tests/axes_test.js index 2d6e1c9d970..e42cf4a60df 100644 --- a/test/jasmine/tests/axes_test.js +++ b/test/jasmine/tests/axes_test.js @@ -1796,6 +1796,23 @@ describe('Test axes', function() { 'input range, ' + msg + ': ' + ax.range); } + it('can change axis domain on call to react when template is present', function(done) { + Plotly.newPlot(gd, + [{z: [[0, 1], [2, 3]], type: 'heatmap'}], + { template: {}, xaxis: { domain: [0,1], scaleanchor: 'y' } } + ) + .then(function() { + return Plotly.react(gd, + [{z: [[0, 1], [2, 3]], type: 'heatmap'}], + { template: {}, xaxis: { domain: [0.1, 0.9] } } + ); + }) + .then(function() { + assertRangeDomain('xaxis', [-0.5,1.5], [0.1, 0.9], [0.1, 0.9]); + }) + .then(done, done.fail); + }); + it('can change per-axis constrain:domain/range and constraintoward', function(done) { Plotly.newPlot(gd, // start with a heatmap as it has no padding so calculations are easy