diff --git a/draftlogs/8165_fix.md b/draftlogs/8165_fix.md new file mode 100644 index 00000000000..6d6c1a959bb --- /dev/null +++ b/draftlogs/8165_fix.md @@ -0,0 +1 @@ +- Fix matching axes losing autorange when another group of matching axes has an explicit range [[#8165](https://github.com/plotly/plotly.js/pull/8165)] diff --git a/src/plots/cartesian/constraints.js b/src/plots/cartesian/constraints.js index 2dd1e665df1..4db1c589cbc 100644 --- a/src/plots/cartesian/constraints.js +++ b/src/plots/cartesian/constraints.js @@ -108,6 +108,15 @@ exports.handleDefaults = function(layoutIn, layoutOut, opts) { function setAttrVal() { val = axOut[attr]; + if(attr === 'range') { + // check the input of the axis the value comes from + hasRange = !!(val && + axIn.range && + axIn.range.length === 2 && + axIn.range[0] !== null && + axIn.range[1] !== null + ); + } if(attr === 'rangebreaks') { hasDayOfWeekBreaks = axOut._hasDayOfWeekBreaks; } @@ -115,6 +124,8 @@ exports.handleDefaults = function(layoutIn, layoutOut, opts) { for(i = 0; i < matchGroups.length; i++) { group = matchGroups[i]; + // a range set in another match group must not disable autorange here + hasRange = false; // find 'matching' range attrs for(var j = 0; j < matchAttrs.length; j++) { @@ -145,14 +156,6 @@ exports.handleDefaults = function(layoutIn, layoutOut, opts) { // special logic for coupling of range and autorange // if nobody explicitly specifies autorange, but someone does // explicitly specify range, autorange must be disabled. - if(attr === 'range' && val && - axIn.range && - axIn.range.length === 2 && - axIn.range[0] !== null && - axIn.range[1] !== null - ) { - hasRange = true; - } if(attr === 'autorange' && val === null && hasRange) { val = false; } diff --git a/test/jasmine/tests/axes_test.js b/test/jasmine/tests/axes_test.js index 31dd67c46cb..df953b832ce 100644 --- a/test/jasmine/tests/axes_test.js +++ b/test/jasmine/tests/axes_test.js @@ -1187,6 +1187,33 @@ describe('Test axes', function() { _assertMatchingAxes(['xaxis4', 'yaxis4'], false, [-1, 3]); }); + it('should not disable autorange on a matching group because an earlier group has a range', function() { + // shared x and y axes on a 2x2 grid, with a range on the x axes only + layoutIn = { + xaxis: {range: [0, 100], matches: 'x3'}, + xaxis2: {range: [0, 100], matches: 'x4'}, + xaxis3: {range: [0, 100]}, + xaxis4: {range: [0, 100]}, + yaxis: {}, + yaxis2: {matches: 'y'}, + yaxis3: {}, + yaxis4: {matches: 'y3'} + }; + layoutOut._subplots.cartesian.push('x2y2', 'x3y3', 'x4y4'); + layoutOut._subplots.xaxis.push('x2', 'x3', 'x4'); + layoutOut._subplots.yaxis.push('y2', 'y3', 'y4'); + + supplyLayoutDefaults(layoutIn, layoutOut, fullData); + + expect(layoutOut._axisMatchGroups.length).toBe(4); + ['xaxis', 'xaxis2', 'xaxis3', 'xaxis4'].forEach(function(n) { + expect(layoutOut[n].autorange).toBe(false, n); + }); + ['yaxis', 'yaxis2', 'yaxis3', 'yaxis4'].forEach(function(n) { + expect(layoutOut[n].autorange).toBe(true, n); + }); + }); + it('should match set axis range value for matching axes even when matching a *missing* axis', function() { layoutIn = { // N.B. xaxis is set, but does not correspond to a subplot