Skip to content

Commit a9e1dd6

Browse files
authoredFeb 28, 2017
Merge pull request #1425 from plotly/axes-expand-fixup
Fixup for `Axes.expand` in the early return case
2 parents 5627584 + e32eb90 commit a9e1dd6

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed
 

‎src/plots/cartesian/axes.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,11 @@ axes.saveRangeInitial = function(gd, overwrite) {
378378
// tozero: (boolean) make sure to include zero if axis is linear,
379379
// and make it a tight bound if possible
380380
axes.expand = function(ax, data, options) {
381-
var needsAutorange = (ax.autorange || Lib.nestedProperty(ax, 'rangeslider.autorange'));
381+
var needsAutorange = (
382+
ax.autorange ||
383+
!!Lib.nestedProperty(ax, 'rangeslider.autorange').get()
384+
);
385+
382386
if(!needsAutorange || !data) return;
383387

384388
if(!ax._min) ax._min = [];

‎test/jasmine/tests/axes_test.js

+37-6
Original file line numberDiff line numberDiff line change
@@ -1264,11 +1264,11 @@ describe('Test axes', function() {
12641264
// way of getting a new clean copy each time.
12651265
function getDefaultAx() {
12661266
return {
1267+
autorange: true,
12671268
c2l: Number,
12681269
type: 'linear',
12691270
_length: 100,
1270-
_m: 1,
1271-
_needsExpand: true
1271+
_m: 1
12721272
};
12731273
}
12741274

@@ -1284,15 +1284,14 @@ describe('Test axes', function() {
12841284

12851285
it('calls ax.setScale if necessary', function() {
12861286
ax = {
1287+
autorange: true,
12871288
c2l: Number,
12881289
type: 'linear',
1289-
setScale: function() {},
1290-
_needsExpand: true
1290+
setScale: function() {}
12911291
};
12921292
spyOn(ax, 'setScale');
1293-
data = [1];
12941293

1295-
expand(ax, data);
1294+
expand(ax, [1]);
12961295

12971296
expect(ax.setScale).toHaveBeenCalled();
12981297
});
@@ -1450,6 +1449,38 @@ describe('Test axes', function() {
14501449
expect(ax._min).toEqual([{val: 0, pad: 0}]);
14511450
expect(ax._max).toEqual([{val: 6, pad: 15}]);
14521451
});
1452+
1453+
it('should return early if no data is given', function() {
1454+
ax = getDefaultAx();
1455+
1456+
expand(ax);
1457+
expect(ax._min).toBeUndefined();
1458+
expect(ax._max).toBeUndefined();
1459+
});
1460+
1461+
it('should return early if `autorange` is falsy', function() {
1462+
ax = getDefaultAx();
1463+
data = [2, 5];
1464+
1465+
ax.autorange = false;
1466+
ax.rangeslider = { autorange: false };
1467+
1468+
expand(ax, data, {});
1469+
expect(ax._min).toBeUndefined();
1470+
expect(ax._max).toBeUndefined();
1471+
});
1472+
1473+
it('should consider range slider `autorange`', function() {
1474+
ax = getDefaultAx();
1475+
data = [2, 5];
1476+
1477+
ax.autorange = false;
1478+
ax.rangeslider = { autorange: true };
1479+
1480+
expand(ax, data, {});
1481+
expect(ax._min).toEqual([{val: 2, pad: 0}]);
1482+
expect(ax._max).toEqual([{val: 5, pad: 0}]);
1483+
});
14531484
});
14541485

14551486
describe('calcTicks and tickText', function() {

0 commit comments

Comments
 (0)