diff --git a/draftlogs/7967_fix.md b/draftlogs/7967_fix.md new file mode 100644 index 00000000000..a9550d1a6a9 --- /dev/null +++ b/draftlogs/7967_fix.md @@ -0,0 +1 @@ +- Fix range slider drawing spurious grey bands on initial render when `rangeslider.yaxis.rangemode` is `"fixed"` and the counter axis is autoranged [[#7967](https://github.com/plotly/plotly.js/pull/7967)] diff --git a/src/components/rangeslider/defaults.js b/src/components/rangeslider/defaults.js index a2efeae718d..3ad94dce797 100644 --- a/src/components/rangeslider/defaults.js +++ b/src/components/rangeslider/defaults.js @@ -67,6 +67,10 @@ module.exports = function handleDefaults(layoutIn, layoutOut, axName) { var rangeMode = coerceRange('rangemode', rangemodeDflt); if(rangeMode !== 'match') { coerceRange('range', yAxOut.range.slice()); + + if(rangeMode === 'fixed' && !rangemodeDflt && yAxOut.autorange) { + rangeContainerOut._rangeDfltFromAutorangedAx = true; + } } } } diff --git a/src/plots/cartesian/autorange.js b/src/plots/cartesian/autorange.js index 9113cd855d4..870b54d0d5a 100644 --- a/src/plots/cartesian/autorange.js +++ b/src/plots/cartesian/autorange.js @@ -398,8 +398,9 @@ function doAutoRange(gd, ax, presetRange) { if(anchorAx && anchorAx.rangeslider) { var axeRangeOpts = anchorAx.rangeslider[ax._name]; if(axeRangeOpts) { - if(axeRangeOpts.rangemode === 'auto') { + if(axeRangeOpts.rangemode === 'auto' || axeRangeOpts._rangeDfltFromAutorangedAx) { axeRangeOpts.range = getAutoRange(gd, ax); + delete axeRangeOpts._rangeDfltFromAutorangedAx; } } anchorAx._input.rangeslider[ax._name] = Lib.extendFlat({}, axeRangeOpts); diff --git a/test/jasmine/tests/range_slider_test.js b/test/jasmine/tests/range_slider_test.js index fed44189d9a..2691e50ebce 100644 --- a/test/jasmine/tests/range_slider_test.js +++ b/test/jasmine/tests/range_slider_test.js @@ -1127,6 +1127,30 @@ describe('rangesliders in general', function() { .then(done, done.fail); }); + it('should not leave "fixed" rangemode on the placeholder range of an autoranged counter axis', function(done) { + Plotly.newPlot(gd, [{ + // use a heatmap because it doesn't add any padding + x0: 0, dx: 1, + y0: 1, dy: 1, + z: [[1, 2, 3], [2, 3, 4], [3, 4, 5]], + type: 'heatmap' + }], { + xaxis: { + rangeslider: {visible: true, yaxis: {rangemode: 'fixed'}} + } + }) + .then(function() { + expect(gd._fullLayout.yaxis.range).toBeCloseToArray([0.5, 3.5], 3); + expect(gd._fullLayout.xaxis.rangeslider.yaxis.range).toBeCloseToArray([0.5, 3.5], 3); + return Plotly.restyle(gd, {dy: 4}); + }) + .then(function() { + expect(gd._fullLayout.yaxis.range).toBeCloseToArray([-1, 11], 3); + expect(gd._fullLayout.xaxis.rangeslider.yaxis.range).toBeCloseToArray([0.5, 3.5], 3); + }) + .then(done, done.fail); + }); + it('should be able to turn on rangeslider x/y autorange implicitly by deleting x range', function(done) { // this does not apply to y ranges, because the default there is 'match' Plotly.newPlot(gd, [{