diff --git a/draftlogs/7704_fix.md b/draftlogs/7704_fix.md new file mode 100644 index 00000000000..c7672c90c18 --- /dev/null +++ b/draftlogs/7704_fix.md @@ -0,0 +1 @@ +- Fix visual jumps when zooming/scrolling through plots [[#7704](https://github.com/plotly/plotly.js/pull/7704)] diff --git a/src/plots/cartesian/dragbox.js b/src/plots/cartesian/dragbox.js index f8fa211ad8f..5aca52ce337 100644 --- a/src/plots/cartesian/dragbox.js +++ b/src/plots/cartesian/dragbox.js @@ -38,6 +38,9 @@ var MINZOOM = constants.MINZOOM; // flag for showing "doubleclick to zoom out" only at the beginning var SHOWZOOMOUTTIP = true; +// Current (sub)plot that initiated a scroll +let CURRENT_SCROLLING_SUBPLOT = null; + // dragBox: create an element to drag one or more axis ends // inputs: // plotinfo - which subplot are we making dragboxes on? @@ -467,6 +470,15 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) { return; } + if (CURRENT_SCROLLING_SUBPLOT == null) { + CURRENT_SCROLLING_SUBPLOT = plotinfo.id; + } + // Early exit to prevent jitters if this subplot didn't initiate the scroll + if (CURRENT_SCROLLING_SUBPLOT !== plotinfo.id) { + e.preventDefault(); + return; + } + clearAndResetSelect(); // If a transition is in progress, then disable any behavior: @@ -528,6 +540,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) { } // viewbox redraw at first + gd._fullLayout._replotting = true; updateSubplots(scrollViewBox); ticksAndAnnotations(); @@ -537,6 +550,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) { // no more scrolling is coming redrawTimer = setTimeout(function() { if(!gd._fullLayout) return; + CURRENT_SCROLLING_SUBPLOT = null; scrollViewBox = [0, 0, pw, ph]; dragTail(); }, REDRAWDELAY);