Skip to content

Fix x-only zoom moves when xaxis.fixedrange: true #2776

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
Jul 5, 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
5 changes: 2 additions & 3 deletions src/plots/cartesian/dragbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,9 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
// look for small drags in one direction or the other,
// and only drag the other axis
else if(!yActive || dy < Math.min(Math.max(dx * 0.6, MINDRAG), MINZOOM)) {
if(dx < MINDRAG) {
if(dx < MINDRAG || !xActive) {
noZoom();
}
else {
} else {
box.t = 0;
box.b = ph;
zoomMode = 'x';
Expand Down
67 changes: 67 additions & 0 deletions test/jasmine/tests/cartesian_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,73 @@ describe('axis zoom/pan and main plot zoom', function() {
.catch(failTest)
.then(done);
});

it('should draw correct zoomboxes corners', function(done) {
var dragCoverNode;
var p1;

function _dragStart(p0, dp) {
var node = getDragger('xy', 'nsew');
mouseEvent('mousemove', p0[0], p0[1], {element: node});
mouseEvent('mousedown', p0[0], p0[1], {element: node});

var promise = drag.waitForDragCover().then(function(dcn) {
dragCoverNode = dcn;
p1 = [p0[0] + dp[0], p0[1] + dp[1]];
mouseEvent('mousemove', p1[0], p1[1], {element: dragCoverNode});
});
return promise;
}

function _assertAndDragEnd(msg, exp) {
var zl = d3.select(gd).select('g.zoomlayer');
var d = zl.select('.zoombox-corners').attr('d');

if(exp.cornerCnt) {
var actual = (d.match(/Z/g) || []).length;
expect(actual).toBe(exp.cornerCnt, 'zoombox corner cnt: ' + msg);
} else {
expect(d).toBe('M0,0Z', 'no zoombox corners: ' + msg);
}

mouseEvent('mouseup', p1[0], p1[1], {element: dragCoverNode});
return drag.waitForDragCoverRemoval();
}

Plotly.plot(gd, [{ y: [1, 2, 1] }])
.then(function() { return _dragStart([170, 170], [30, 30]); })
.then(function() {
return _assertAndDragEnd('full-x full-y', {cornerCnt: 4});
})
.then(function() { return _dragStart([170, 170], [5, 30]); })
.then(function() {
return _assertAndDragEnd('full-y', {cornerCnt: 2});
})
.then(function() { return _dragStart([170, 170], [30, 2]); })
.then(function() {
return _assertAndDragEnd('full-x', {cornerCnt: 2});
})
.then(function() { return Plotly.relayout(gd, 'xaxis.fixedrange', true); })
.then(function() { return _dragStart([170, 170], [30, 30]); })
.then(function() {
return _assertAndDragEnd('full-x full-y w/ fixed xaxis', {cornerCnt: 2});
})
.then(function() { return _dragStart([170, 170], [30, 5]); })
.then(function() {
return _assertAndDragEnd('full-x w/ fixed xaxis', {cornerCnt: 0});
})
.then(function() { return Plotly.relayout(gd, {'xaxis.fixedrange': false, 'yaxis.fixedrange': true}); })
.then(function() { return _dragStart([170, 170], [30, 30]); })
.then(function() {
return _assertAndDragEnd('full-x full-y w/ fixed yaxis', {cornerCnt: 2});
})
.then(function() { return _dragStart([170, 170], [5, 30]); })
.then(function() {
return _assertAndDragEnd('full-y w/ fixed yaxis', {cornerCnt: 0});
})
.catch(failTest)
.then(done);
});
});

describe('Event data:', function() {
Expand Down