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/8092_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix autorange turning off for matched axes that have no set range, when another match group sets a range [[#XXXX](https://github.com/plotly/plotly.js/pull/XXXX)]
13 changes: 9 additions & 4 deletions src/plots/cartesian/constraints.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,21 @@ exports.handleDefaults = function(layoutIn, layoutOut, opts) {
];
var hasRange = false;
var hasDayOfWeekBreaks = false;
var rangeIn;

function setAttrVal() {
val = axOut[attr];
if(attr === 'range') {
rangeIn = axIn.range;
}
if(attr === 'rangebreaks') {
hasDayOfWeekBreaks = axOut._hasDayOfWeekBreaks;
}
}

for(i = 0; i < matchGroups.length; i++) {
group = matchGroups[i];
hasRange = false;

// find 'matching' range attrs
for(var j = 0; j < matchAttrs.length; j++) {
Expand Down Expand Up @@ -146,10 +151,10 @@ exports.handleDefaults = function(layoutIn, layoutOut, opts) {
// 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
rangeIn &&
rangeIn.length === 2 &&
rangeIn[0] !== null &&
rangeIn[1] !== null
) {
hasRange = true;
}
Expand Down
28 changes: 28 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,34 @@ describe('Test axes', function() {
_assertMatchingAxes(['xaxis4', 'yaxis4'], false, [-1, 3]);
});

it('should not turn off autorange in match groups that have no set range', function() {
// shared x and y axes on a 2x2 grid, with a range on every x axis
layoutIn = {
xaxis: {matches: 'x3', range: [0, 100]},
xaxis2: {matches: 'x4', range: [0, 100]},
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((axName) => {
expect(layoutOut[axName].autorange).withContext(axName).toBe(false);
});
['yaxis', 'yaxis2', 'yaxis3', 'yaxis4'].forEach((axName) => {
expect(layoutOut[axName].autorange).withContext(axName).toBe(true);
});
});

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