Skip to content

Commit 82da615

Browse files
authored
Merge pull request #5336 from plotly/fix5290-autorange-false-error
Avoid autoscale error with false autorange
2 parents 468b759 + 5dee4fc commit 82da615

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/plot_api/plot_api.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,9 @@ function axRangeSupplyDefaultsByPass(gd, flags, specs) {
19481948
var axIn = gd.layout[axName];
19491949
var axOut = fullLayout[axName];
19501950
axOut.autorange = axIn.autorange;
1951-
axOut.range = axIn.range.slice();
1951+
if(axIn.range) {
1952+
axOut.range = axIn.range.slice();
1953+
}
19521954
axOut.cleanRange();
19531955

19541956
if(axOut._matchGroup) {

test/jasmine/tests/axes_test.js

+50
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,56 @@ describe('Test axes', function() {
14331433
});
14341434
});
14351435

1436+
describe('autorange relayout', function() {
1437+
var gd;
1438+
1439+
beforeEach(function() {
1440+
gd = createGraphDiv();
1441+
});
1442+
1443+
afterEach(destroyGraphDiv);
1444+
1445+
it('can relayout autorange', function(done) {
1446+
Plotly.newPlot(gd, {
1447+
data: [{
1448+
x: [0, 1],
1449+
y: [0, 1]
1450+
}],
1451+
layout: {
1452+
width: 400,
1453+
height: 400,
1454+
margin: {
1455+
t: 40,
1456+
b: 40,
1457+
l: 40,
1458+
r: 40
1459+
},
1460+
xaxis: {
1461+
autorange: false,
1462+
},
1463+
yaxis: {
1464+
autorange: true,
1465+
}
1466+
}
1467+
}).then(function() {
1468+
expect(gd._fullLayout.xaxis.range).toEqual([-1, 6]);
1469+
expect(gd._fullLayout.yaxis.range).toBeCloseToArray([-0.07, 1.07]);
1470+
1471+
return Plotly.relayout(gd, 'yaxis.autorange', false);
1472+
}).then(function() {
1473+
expect(gd._fullLayout.yaxis.autorange).toBe(false);
1474+
expect(gd._fullLayout.yaxis.range).toBeCloseToArray([-0.07, 1.07]);
1475+
1476+
return Plotly.relayout(gd, 'xaxis.autorange', true);
1477+
}).then(function() {
1478+
expect(gd._fullLayout.xaxis.autorange).toBe(true);
1479+
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.07, 1.07]);
1480+
})
1481+
.catch(failTest)
1482+
.then(done);
1483+
});
1484+
});
1485+
14361486
describe('constraints relayout', function() {
14371487
var gd;
14381488

0 commit comments

Comments
 (0)