Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixup for Axes.expand in the early return case #1425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 28, 2017
Merged
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
6 changes: 5 additions & 1 deletion src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,11 @@ axes.saveRangeInitial = function(gd, overwrite) {
// tozero: (boolean) make sure to include zero if axis is linear,
// and make it a tight bound if possible
axes.expand = function(ax, data, options) {
var needsAutorange = (ax.autorange || Lib.nestedProperty(ax, 'rangeslider.autorange'));
var needsAutorange = (
ax.autorange ||
!!Lib.nestedProperty(ax, 'rangeslider.autorange').get()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if ax.rangeslider is undefined, Lib.nestedProperty(ax, 'rangeslider.autorange') return an object (which is of course truthy) - which made needsAutorange always be truthy, removing the early return 🐎 path.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha I've made exactly that mistake more than once...

);

if(!needsAutorange || !data) return;

if(!ax._min) ax._min = [];
Expand Down
43 changes: 37 additions & 6 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1264,11 +1264,11 @@ describe('Test axes', function() {
// way of getting a new clean copy each time.
function getDefaultAx() {
return {
autorange: true,
c2l: Number,
type: 'linear',
_length: 100,
_m: 1,
_needsExpand: true
_m: 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an artefact that of the old range slider + autorange implementation that should've been taken out in cebc31c

My mistake.

};
}

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

it('calls ax.setScale if necessary', function() {
ax = {
autorange: true,
c2l: Number,
type: 'linear',
setScale: function() {},
_needsExpand: true
setScale: function() {}
};
spyOn(ax, 'setScale');
data = [1];

expand(ax, data);
expand(ax, [1]);

expect(ax.setScale).toHaveBeenCalled();
});
Expand Down Expand Up @@ -1450,6 +1449,38 @@ describe('Test axes', function() {
expect(ax._min).toEqual([{val: 0, pad: 0}]);
expect(ax._max).toEqual([{val: 6, pad: 15}]);
});

it('should return early if no data is given', function() {
ax = getDefaultAx();

expand(ax);
expect(ax._min).toBeUndefined();
expect(ax._max).toBeUndefined();
});

it('should return early if `autorange` is falsy', function() {
ax = getDefaultAx();
data = [2, 5];

ax.autorange = false;
ax.rangeslider = { autorange: false };

expand(ax, data, {});
expect(ax._min).toBeUndefined();
expect(ax._max).toBeUndefined();
});

it('should consider range slider `autorange`', function() {
ax = getDefaultAx();
data = [2, 5];

ax.autorange = false;
ax.rangeslider = { autorange: true };

expand(ax, data, {});
expect(ax._min).toEqual([{val: 2, pad: 0}]);
expect(ax._max).toEqual([{val: 5, pad: 0}]);
});
});

describe('calcTicks and tickText', function() {
Expand Down