Skip to content

Commit b4dd516

Browse files
committed
Keep autorange on matching axes when another match group sets a range
`hasRange` was never reset between match groups, so once a group with an explicit range was processed, every later group without `autorange` got `autorange: false` and fell back to the default range. With shared x and y axes on a grid and a range set on the x axes, the y axes stopped autoranging. The explicit-range check also read `axIn` after the loop, which is the last axis visited rather than the axis the range came from. Check it where the value is picked instead. Fixes #8053
1 parent 7d92747 commit b4dd516

2 files changed

Lines changed: 38 additions & 8 deletions

File tree

‎src/plots/cartesian/constraints.js‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,24 @@ exports.handleDefaults = function(layoutIn, layoutOut, opts) {
108108

109109
function setAttrVal() {
110110
val = axOut[attr];
111+
if(attr === 'range') {
112+
// check the input of the axis the value comes from
113+
hasRange = !!(val &&
114+
axIn.range &&
115+
axIn.range.length === 2 &&
116+
axIn.range[0] !== null &&
117+
axIn.range[1] !== null
118+
);
119+
}
111120
if(attr === 'rangebreaks') {
112121
hasDayOfWeekBreaks = axOut._hasDayOfWeekBreaks;
113122
}
114123
}
115124

116125
for(i = 0; i < matchGroups.length; i++) {
117126
group = matchGroups[i];
127+
// a range set in another match group must not disable autorange here
128+
hasRange = false;
118129

119130
// find 'matching' range attrs
120131
for(var j = 0; j < matchAttrs.length; j++) {
@@ -145,14 +156,6 @@ exports.handleDefaults = function(layoutIn, layoutOut, opts) {
145156
// special logic for coupling of range and autorange
146157
// if nobody explicitly specifies autorange, but someone does
147158
// explicitly specify range, autorange must be disabled.
148-
if(attr === 'range' && val &&
149-
axIn.range &&
150-
axIn.range.length === 2 &&
151-
axIn.range[0] !== null &&
152-
axIn.range[1] !== null
153-
) {
154-
hasRange = true;
155-
}
156159
if(attr === 'autorange' && val === null && hasRange) {
157160
val = false;
158161
}

‎test/jasmine/tests/axes_test.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,33 @@ describe('Test axes', function() {
11871187
_assertMatchingAxes(['xaxis4', 'yaxis4'], false, [-1, 3]);
11881188
});
11891189

1190+
it('should not disable autorange on a matching group because an earlier group has a range', function() {
1191+
// shared x and y axes on a 2x2 grid, with a range on the x axes only
1192+
layoutIn = {
1193+
xaxis: {range: [0, 100], matches: 'x3'},
1194+
xaxis2: {range: [0, 100], matches: 'x4'},
1195+
xaxis3: {range: [0, 100]},
1196+
xaxis4: {range: [0, 100]},
1197+
yaxis: {},
1198+
yaxis2: {matches: 'y'},
1199+
yaxis3: {},
1200+
yaxis4: {matches: 'y3'}
1201+
};
1202+
layoutOut._subplots.cartesian.push('x2y2', 'x3y3', 'x4y4');
1203+
layoutOut._subplots.xaxis.push('x2', 'x3', 'x4');
1204+
layoutOut._subplots.yaxis.push('y2', 'y3', 'y4');
1205+
1206+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
1207+
1208+
expect(layoutOut._axisMatchGroups.length).toBe(4);
1209+
['xaxis', 'xaxis2', 'xaxis3', 'xaxis4'].forEach(function(n) {
1210+
expect(layoutOut[n].autorange).toBe(false, n);
1211+
});
1212+
['yaxis', 'yaxis2', 'yaxis3', 'yaxis4'].forEach(function(n) {
1213+
expect(layoutOut[n].autorange).toBe(true, n);
1214+
});
1215+
});
1216+
11901217
it('should match set axis range value for matching axes even when matching a *missing* axis', function() {
11911218
layoutIn = {
11921219
// N.B. xaxis is set, but does not correspond to a subplot

0 commit comments

Comments
 (0)