diff --git a/draftlogs/8229_fix.md b/draftlogs/8229_fix.md new file mode 100644 index 00000000000..c56e7af66d8 --- /dev/null +++ b/draftlogs/8229_fix.md @@ -0,0 +1 @@ +- Fix `_template` property leaking into user `layout` rangeslider axis options [[#8229](https://github.com/plotly/plotly.js/pull/8229)], with thanks to @abdulhamid999 for the contribution! diff --git a/src/plots/cartesian/autorange.js b/src/plots/cartesian/autorange.js index 9113cd855d4..eb45a8b2414 100644 --- a/src/plots/cartesian/autorange.js +++ b/src/plots/cartesian/autorange.js @@ -401,8 +401,10 @@ function doAutoRange(gd, ax, presetRange) { if(axeRangeOpts.rangemode === 'auto') { axeRangeOpts.range = getAutoRange(gd, ax); } + const inputRangeOpts = Lib.extendFlat({}, axeRangeOpts); + delete inputRangeOpts._template; + anchorAx._input.rangeslider[ax._name] = inputRangeOpts; } - 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..0787384ac11 100644 --- a/test/jasmine/tests/range_slider_test.js +++ b/test/jasmine/tests/range_slider_test.js @@ -1221,6 +1221,45 @@ describe('rangesliders in general', function() { }) .then(done, done.fail); }); + + it('should not copy _template into layout rangeslider axis options', (done) => { + Plotly.newPlot(gd, [{ + y: [1, 2, 3] + }], { + xaxis: {rangeslider: {visible: true}} + }) + .then(() => { + expect('_template' in gd.layout.xaxis.rangeslider.yaxis).toBe(false); + expect(gd._fullLayout.xaxis.rangeslider.yaxis._template).toBe(null); + + return Plotly.newPlot(gd, [{ + y: [1, 2, 3] + }], { + xaxis: {rangeslider: {visible: true}}, + template: { + layout: { + xaxis: { + rangeslider: { + yaxis: {rangemode: 'auto'} + } + } + } + } + }); + }) + .then(() => { + expect('_template' in gd.layout.xaxis.rangeslider.yaxis).toBe(false); + expect(gd.layout.xaxis.rangeslider.yaxis.rangemode).toEqual('auto'); + expect(gd._fullLayout.xaxis.rangeslider.yaxis._template).toEqual({rangemode: 'auto'}); + + return Plotly.relayout(gd, 'xaxis.rangeslider.yaxis.rangemode', 'match'); + }) + .then(() => { + expect('_template' in gd.layout.xaxis.rangeslider.yaxis).toBe(false); + expect(gd.layout.xaxis.rangeslider.yaxis.rangemode).toEqual('match'); + }) + .then(done, done.fail); + }); }); function slide(fromX, fromY, toX, toY) {