Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e40c326

Browse files
committed
Zoom: Fix for when fixedRange = true
1 parent 2e141a3 commit e40c326

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/plots/cartesian/dragbox.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -601,32 +601,35 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
601601
subplots = Object.keys(plotinfos);
602602

603603
for(var i = 0; i < subplots.length; i++) {
604+
604605
var subplot = plotinfos[subplots[i]],
606+
clipId = 'clip' + fullLayout._uid + subplots[i] + 'plot',
605607
xa2 = subplot.x(),
606608
ya2 = subplot.y(),
607609
editX = ew && xa.indexOf(xa2) !== -1 && !xa2.fixedrange,
608610
editY = ns && ya.indexOf(ya2) !== -1 && !ya2.fixedrange;
609611

610-
if(editX || editY) {
611612

612-
var xScaleFactor = xa2._length / viewBox[2],
613-
yScaleFactor = ya2._length / viewBox[3];
613+
var xScaleFactor = editX ? xa2._length / viewBox[2] : 1,
614+
yScaleFactor = editY ? ya2._length / viewBox[3] : 1;
614615

615-
var clipDx = editX ? (viewBox[0] / viewBox[2] * xa2._length) : 0,
616-
clipDy = editY ? (viewBox[1] / viewBox[3] * ya2._length) : 0;
616+
var clipDx = editX ? viewBox[0] : 0,
617+
clipDy = editY ? viewBox[1] : 0;
617618

618-
var plotDx = xa2._offset - clipDx,
619-
plotDy = ya2._offset - clipDy;
619+
var fracDx = editX ? (viewBox[0] / viewBox[2] * xa2._length) : 0,
620+
fracDy = editY ? (viewBox[1] / viewBox[3] * ya2._length) : 0;
620621

621-
var clipId = 'clip' + fullLayout._uid + subplots[i] + 'plot';
622+
var plotDx = xa2._offset - fracDx,
623+
plotDy = ya2._offset - fracDy;
622624

623-
fullLayout._defs.selectAll('#' + clipId)
624-
.call(Lib.setTranslate, viewBox[0], viewBox[1])
625-
.call(Lib.setScale, 1 / xScaleFactor, 1 / yScaleFactor);
626-
subplot.plot
627-
.call(Lib.setTranslate, plotDx, plotDy)
628-
.call(Lib.setScale, xScaleFactor, yScaleFactor);
629-
}
625+
626+
fullLayout._defs.selectAll('#' + clipId)
627+
.call(Lib.setTranslate, clipDx, clipDy)
628+
.call(Lib.setScale, 1 / xScaleFactor, 1 / yScaleFactor);
629+
630+
subplot.plot
631+
.call(Lib.setTranslate, plotDx, plotDy)
632+
.call(Lib.setScale, xScaleFactor, yScaleFactor);
630633
}
631634
}
632635

0 commit comments

Comments
 (0)