Skip to content

Commit a692379

Browse files
authored
Merge pull request #8165 from X6M-Work/fix-shared-axes-autorange-8053
Keep autorange on matching axes when another match group sets a range
2 parents 0e96b5a + 88383f9 commit a692379

3 files changed

Lines changed: 38 additions & 8 deletions

File tree

‎draftlogs/8165_fix.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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)]

‎src/plots/cartesian/constraints.js‎

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

109109
function setAttrVal() {
110110
val = axOut[attr];
111+
if(attr === 'range') {
112+
hasRange = !!(val &&
113+
axIn.range &&
114+
axIn.range.length === 2 &&
115+
axIn.range[0] !== null &&
116+
axIn.range[1] !== null
117+
);
118+
}
111119
if(attr === 'rangebreaks') {
112120
hasDayOfWeekBreaks = axOut._hasDayOfWeekBreaks;
113121
}
114122
}
115123

116124
for(i = 0; i < matchGroups.length; i++) {
117125
group = matchGroups[i];
126+
// a range set in another match group must not disable autorange here
127+
hasRange = false;
118128

119129
// find 'matching' range attrs
120130
for(var j = 0; j < matchAttrs.length; j++) {
@@ -145,14 +155,6 @@ exports.handleDefaults = function(layoutIn, layoutOut, opts) {
145155
// special logic for coupling of range and autorange
146156
// if nobody explicitly specifies autorange, but someone does
147157
// 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-
}
156158
if(attr === 'autorange' && val === null && hasRange) {
157159
val = false;
158160
}

‎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)