Skip to content

Commit 2e141a3

Browse files
committed
Zoom: Fix scrollZoom functionailty
1 parent 69ea5f1 commit 2e141a3

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/plots/cartesian/dragbox.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
347347
var scrollViewBox = [0, 0, pw, ph],
348348
// wait a little after scrolling before redrawing
349349
redrawTimer = null,
350-
REDRAWDELAY = 300,
350+
REDRAWDELAY = 50,
351351
mainplot = plotinfo.mainplot ?
352352
fullLayout._plots[plotinfo.mainplot] : plotinfo;
353353

@@ -608,19 +608,24 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
608608
editY = ns && ya.indexOf(ya2) !== -1 && !ya2.fixedrange;
609609

610610
if(editX || editY) {
611-
// plot requires offset position and
612-
// clip moves with opposite sign
613-
var clipDx = editX ? viewBox[0] : 0,
614-
clipDy = editY ? viewBox[1] : 0,
615-
plotDx = xa2._offset - clipDx,
611+
612+
var xScaleFactor = xa2._length / viewBox[2],
613+
yScaleFactor = ya2._length / viewBox[3];
614+
615+
var clipDx = editX ? (viewBox[0] / viewBox[2] * xa2._length) : 0,
616+
clipDy = editY ? (viewBox[1] / viewBox[3] * ya2._length) : 0;
617+
618+
var plotDx = xa2._offset - clipDx,
616619
plotDy = ya2._offset - clipDy;
617620

618621
var clipId = 'clip' + fullLayout._uid + subplots[i] + 'plot';
619622

620623
fullLayout._defs.selectAll('#' + clipId)
621-
.attr('transform', 'translate(' + clipDx + ', ' + clipDy + ')');
624+
.call(Lib.setTranslate, viewBox[0], viewBox[1])
625+
.call(Lib.setScale, 1 / xScaleFactor, 1 / yScaleFactor);
622626
subplot.plot
623-
.attr('transform', 'translate(' + plotDx + ', ' + plotDy + ')');
627+
.call(Lib.setTranslate, plotDx, plotDy)
628+
.call(Lib.setScale, xScaleFactor, yScaleFactor);
624629
}
625630
}
626631
}

0 commit comments

Comments
 (0)