Skip to content

Conversation

@ryan-williams
Copy link

@ryan-williams ryan-williams commented Nov 28, 2025

Summary

Fixes a bug where pan/zoom fails on the first interaction when traces have different zorder values. On first drag, one trace moves with the grid while the other stays frozen in place. The second pan (and all subsequent pans) work correctly — both traces move together 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

ryan-williams and others added 2 commits November 27, 2025 18:28
When traces have different `zorder` values, plotly.js creates z-indexed
subplots (e.g., `xyz2`, `xyz3`) in `drawFramework`. However, when
`relayout` is called (e.g., during resize), `supplyDefaults` resets
`_plots` via `linkSubplots`, losing these z-indexed subplots. Since
`relayout` doesn't trigger `drawFramework`, they aren't recreated.

This caused pan/zoom to fail on the first attempt in react-plotly.js,
because `updateSubplots` in `dragbox.js` couldn't find the z-indexed
subplots to transform.

Fix:
1. In `linkSubplots`, preserve z-indexed subplots from `oldSubplots`
2. In `updateSubplots`, include z-indexed subplots from `_plots`

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants