Skip to content

Commit 390a8f8

Browse files
authored
Merge pull request #2776 from plotly/fixedrange-nozoom
Fix x-only zoom moves when `xaxis.fixedrange: true`
2 parents f06032f + 4055866 commit 390a8f8

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

src/plots/cartesian/dragbox.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,9 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
331331
// look for small drags in one direction or the other,
332332
// and only drag the other axis
333333
else if(!yActive || dy < Math.min(Math.max(dx * 0.6, MINDRAG), MINZOOM)) {
334-
if(dx < MINDRAG) {
334+
if(dx < MINDRAG || !xActive) {
335335
noZoom();
336-
}
337-
else {
336+
} else {
338337
box.t = 0;
339338
box.b = ph;
340339
zoomMode = 'x';

test/jasmine/tests/cartesian_interact_test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,73 @@ describe('axis zoom/pan and main plot zoom', function() {
587587
.catch(failTest)
588588
.then(done);
589589
});
590+
591+
it('should draw correct zoomboxes corners', function(done) {
592+
var dragCoverNode;
593+
var p1;
594+
595+
function _dragStart(p0, dp) {
596+
var node = getDragger('xy', 'nsew');
597+
mouseEvent('mousemove', p0[0], p0[1], {element: node});
598+
mouseEvent('mousedown', p0[0], p0[1], {element: node});
599+
600+
var promise = drag.waitForDragCover().then(function(dcn) {
601+
dragCoverNode = dcn;
602+
p1 = [p0[0] + dp[0], p0[1] + dp[1]];
603+
mouseEvent('mousemove', p1[0], p1[1], {element: dragCoverNode});
604+
});
605+
return promise;
606+
}
607+
608+
function _assertAndDragEnd(msg, exp) {
609+
var zl = d3.select(gd).select('g.zoomlayer');
610+
var d = zl.select('.zoombox-corners').attr('d');
611+
612+
if(exp.cornerCnt) {
613+
var actual = (d.match(/Z/g) || []).length;
614+
expect(actual).toBe(exp.cornerCnt, 'zoombox corner cnt: ' + msg);
615+
} else {
616+
expect(d).toBe('M0,0Z', 'no zoombox corners: ' + msg);
617+
}
618+
619+
mouseEvent('mouseup', p1[0], p1[1], {element: dragCoverNode});
620+
return drag.waitForDragCoverRemoval();
621+
}
622+
623+
Plotly.plot(gd, [{ y: [1, 2, 1] }])
624+
.then(function() { return _dragStart([170, 170], [30, 30]); })
625+
.then(function() {
626+
return _assertAndDragEnd('full-x full-y', {cornerCnt: 4});
627+
})
628+
.then(function() { return _dragStart([170, 170], [5, 30]); })
629+
.then(function() {
630+
return _assertAndDragEnd('full-y', {cornerCnt: 2});
631+
})
632+
.then(function() { return _dragStart([170, 170], [30, 2]); })
633+
.then(function() {
634+
return _assertAndDragEnd('full-x', {cornerCnt: 2});
635+
})
636+
.then(function() { return Plotly.relayout(gd, 'xaxis.fixedrange', true); })
637+
.then(function() { return _dragStart([170, 170], [30, 30]); })
638+
.then(function() {
639+
return _assertAndDragEnd('full-x full-y w/ fixed xaxis', {cornerCnt: 2});
640+
})
641+
.then(function() { return _dragStart([170, 170], [30, 5]); })
642+
.then(function() {
643+
return _assertAndDragEnd('full-x w/ fixed xaxis', {cornerCnt: 0});
644+
})
645+
.then(function() { return Plotly.relayout(gd, {'xaxis.fixedrange': false, 'yaxis.fixedrange': true}); })
646+
.then(function() { return _dragStart([170, 170], [30, 30]); })
647+
.then(function() {
648+
return _assertAndDragEnd('full-x full-y w/ fixed yaxis', {cornerCnt: 2});
649+
})
650+
.then(function() { return _dragStart([170, 170], [5, 30]); })
651+
.then(function() {
652+
return _assertAndDragEnd('full-y w/ fixed yaxis', {cornerCnt: 0});
653+
})
654+
.catch(failTest)
655+
.then(done);
656+
});
590657
});
591658

592659
describe('Event data:', function() {

0 commit comments

Comments
 (0)