Skip to content

Instantly share code, notes, and snippets.

@ryan-williams
Last active November 28, 2025 15:21
Show Gist options
  • Select an option

  • Save ryan-williams/e9f78b2d6c7426120081a17b77993c56 to your computer and use it in GitHub Desktop.

Select an option

Save ryan-williams/e9f78b2d6c7426120081a17b77993c56 to your computer and use it in GitHub Desktop.

plotly/plotly.js#7659 fix: preserve z-indexed subplots during relayout for correct pan/zoom

Summary

Fixes a bug with the first pan/zoom after page load, when traces have different zorder values: some traces are not redrawn until the pan/zoom completes (while others are). All traces are redrawn continuously during subsequent pans/zooms, as expected. This is particularly noticeable in react-plotly.js, which calls Plotly.Plots.resize() after mount.

Root cause: When relayout is called (e.g., during resize), supplyDefaults resets _plots via linkSubplots, losing z-indexed subplots (e.g., xyz2, xyz3). Since relayout doesn't trigger drawFramework, they aren't recreated, causing updateSubplots in dragbox.js to miss them during pan/zoom.

Fix:

  • In linkSubplots (plots.js): preserve z-indexed subplots from oldSubplots
  • In updateSubplots (dragbox.js): include z-indexed subplots from _plots

Demo

bug.mp4

Live before/after comparison: https://runsascoded.github.io/plotly.js/

To reproduce the bug:

  1. Open the Before Fix demo
  2. Drag the chart to pan horizontally
  3. First drag: one trace (blue) moves with the grid, but the other trace (red) stays frozen
  4. Release and drag again
  5. Second drag: both traces move correctly together
  6. Compare with After Fix — first drag works correctly

Test plan

  • Existing cartesian_interact tests pass
  • Manual testing with react-plotly.js confirms fix
  • CI tests

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment