Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/8165_fix.md
Original file line number Diff line number Diff line change
@@ -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)]
19 changes: 11 additions & 8 deletions src/plots/cartesian/constraints.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,24 @@ 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;
}
}

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++) {
Expand Down Expand Up @@ -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;
}
Expand Down
27 changes: 27 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down