Skip to content

Fix axis autorange on doubleClick #3351

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 1 commit into from
Dec 19, 2018
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
15 changes: 8 additions & 7 deletions src/plots/cartesian/dragbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,13 +703,14 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
for(i = 0; i < axList.length; i++) {
ax = axList[i];

if(!ax._rangeInitial) {
attrs[ax._name + '.autorange'] = true;
}
else {
rangeInitial = ax._rangeInitial;
attrs[ax._name + '.range[0]'] = rangeInitial[0];
attrs[ax._name + '.range[1]'] = rangeInitial[1];
if(!ax.fixedrange) {
if(!ax._rangeInitial) {
attrs[ax._name + '.autorange'] = true;
} else {
rangeInitial = ax._rangeInitial;
attrs[ax._name + '.range[0]'] = rangeInitial[0];
attrs[ax._name + '.range[1]'] = rangeInitial[1];
}
}
}
}
Expand Down
91 changes: 91 additions & 0 deletions test/jasmine/tests/click_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var DBLCLICKDELAY = require('@src/constants/interactions').DBLCLICKDELAY;
var d3 = require('d3');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var failTest = require('../assets/fail_test');
var mouseEvent = require('../assets/mouse_event');
var getRectCenter = require('../assets/get_rect_center');

Expand Down Expand Up @@ -900,6 +901,96 @@ describe('Test click interactions:', function() {
});
});

it('should not try to autorange fixedrange:true axes when rangeInitial is not set', function(done) {
var fig = {
data: [{
x: [1, 2, 3, 4],
y: [1, 2, 3, 4]
}, {
x: [1, 2, 3, 4],
y: [0.2, 999, 0.3, 0.4],
yaxis: 'y2'
}],
layout: {
xaxis: {
title: 'xaxis',
range: [0, 4]
},
yaxis: {
titel: 'yaxis',
range: [-1, 5]
},
yaxis2: {
title: 'yaxis2',
overlaying: 'y',
side: 'right',
showgrid: false,
zeroline: false,
range: [-1, 1],
fixedrange: true
},
width: 500,
height: 500
}
};

function _assert(msg, exp) {
var fullLayout = gd._fullLayout;
var xa = fullLayout.xaxis;
var ya = fullLayout.yaxis;
var ya2 = fullLayout.yaxis2;

expect(xa._rangeInitial).toBe(undefined);
expect(ya._rangeInitial).toBe(undefined);
expect(ya2._rangeInitial).toBe(undefined);

expect(xa.range).toBeCloseToArray(exp.xRng, 1, msg);
expect(ya.range).toBeCloseToArray(exp.yRng, 1, msg);
expect(ya2.range).toBeCloseToArray(exp.y2Rng, 1, msg);
}

Plotly.newPlot(gd, [], {})
.then(function() {
expect(gd._fullLayout.xaxis._rangeInitial).toBe(undefined);
expect(gd._fullLayout.yaxis._rangeInitial).toBe(undefined);
expect(gd._fullLayout.yaxis2).toBe(undefined);
})
.then(function() { return Plotly.react(gd, fig); })
.then(function() {
_assert('after react into fig', {
xRng: [0, 4],
yRng: [-1, 5],
y2Rng: [-1, 1]
});
})
.then(function() { return drag(200, 200, 250, 250); })
.then(function() {
_assert('after zoom', {
xRng: [1.509, 2.138],
yRng: [2.187, 3.125],
y2Rng: [-1, 1]
});
})
.then(function() { return doubleClick(250, 250); })
.then(function() {
_assert('after double click autorange', {
xRng: [0.788, 4.211],
yRng: [0.788, 4.211],
y2Rng: [-1, 1]
});
})
.then(function() { return doubleClick(250, 250); })
.then(function() {
// more info in: https://github.com/plotly/plotly.js/issues/2718
_assert('after 2nd double click autorange (does not reset as rangeInitial is not set)', {
xRng: [0.788, 4.211],
yRng: [0.788, 4.211],
y2Rng: [-1, 1]
});
})
.catch(failTest)
.then(done);
});
});

describe('zoom interactions', function() {
Expand Down