Skip to content

Commit 9dbac47

Browse files
authored
Merge pull request #3028 from plotly/xy-drag-dblclick-x-or-y-only-drag-fix
Reset updates object on every zoomDone
2 parents 4225f9e + 7c03fb4 commit 9dbac47

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/plots/cartesian/dragbox.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
8585
var editX, editY;
8686
// graph-wide optimization flags
8787
var hasScatterGl, hasOnlyLargeSploms, hasSplom, hasSVG;
88+
// collected changes to be made to the plot by relayout at the end
89+
var updates;
8890

8991
function recomputeAxisLists() {
9092
xa0 = plotinfo.xaxis;
@@ -291,9 +293,6 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
291293
// zoom takes over minDrag, so it also has to take over gd._dragged
292294
var zoomDragged;
293295

294-
// collected changes to be made to the plot by relayout at the end
295-
var updates = {};
296-
297296
function zoomPrep(e, startX, startY) {
298297
var dragBBox = dragger.getBoundingClientRect();
299298
x0 = startX - dragBBox.left;
@@ -386,6 +385,8 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
386385
}
387386

388387
function zoomDone() {
388+
updates = {};
389+
389390
// more strict than dragged, which allows you to come back to where you started
390391
// and still count as dragged
391392
if(Math.min(box.h, box.w) < MINDRAG * 2) {
@@ -936,6 +937,7 @@ function zoomAxRanges(axList, r0Fraction, r1Fraction, updates, linkedAxes) {
936937
axi.l2r(axRangeLinear0 + axRangeLinearSpan * r0Fraction),
937938
axi.l2r(axRangeLinear0 + axRangeLinearSpan * r1Fraction)
938939
];
940+
939941
updates[axi._name + '.range[0]'] = axi.range[0];
940942
updates[axi._name + '.range[1]'] = axi.range[1];
941943
}

test/jasmine/tests/cartesian_interact_test.js

+19
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,25 @@ describe('axis zoom/pan and main plot zoom', function() {
654654
.catch(failTest)
655655
.then(done);
656656
});
657+
658+
it('handles xy, x-only and y-only zoombox updates', function(done) {
659+
function _assert(msg, xrng, yrng) {
660+
expect(gd.layout.xaxis.range).toBeCloseToArray(xrng, 2, 'xrng - ' + msg);
661+
expect(gd.layout.yaxis.range).toBeCloseToArray(yrng, 2, 'yrng - ' + msg);
662+
}
663+
664+
Plotly.plot(gd, [{ y: [1, 2, 1] }])
665+
.then(doDrag('xy', 'nsew', 50, 50))
666+
.then(function() { _assert('after xy drag', [1, 1.208], [1.287, 1.5]); })
667+
.then(doDblClick('xy', 'nsew'))
668+
.then(doDrag('xy', 'nsew', 50, 0))
669+
.then(function() { _assert('after x-only drag', [1, 1.208], [0.926, 2.073]); })
670+
.then(doDblClick('xy', 'nsew'))
671+
.then(doDrag('xy', 'nsew', 0, 50))
672+
.then(function() { _assert('after y-only drag', [-0.128, 2.128], [1.287, 1.5]); })
673+
.catch(failTest)
674+
.then(done);
675+
});
657676
});
658677

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

0 commit comments

Comments
 (0)