Repository navigation
Conversation
Since plotly#3882 the plotly_relayout handler copies user edits (zoom, pan, ...) into the figure prop. The graph then re-plots with them as figure input, so plotly.js takes them as the new starting point and drops them from its uirevision bookkeeping. The next figure that leaves them out resets the view, even with the same uirevision. Remember the value each synced layout key had before the edit, and while the figure still holds the synced value under the same uirevision, give that value to plotly.js instead, so plotly.js keeps the edit itself. Only do this for edits that plotly.js keeps under uirevision, so other edits are not undone. Fixes plotly#4093
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #4093
Since #3882, the
plotly_relayouthandler copies user edits (zoom, pan, ...) into thefigureprop so that a laterPatchdoesn't revert them. That prop change makes the graph re-plot with the edits as figure input. plotly.js then treats them as the new starting point and drops them from its uirevision bookkeeping (_preGUI), so the next figure that leaves them out resets the view, even whenuirevisionhasn't changed.So with
uirevision=True, zooming and then returning a new figure from a callback loses the zoom (the report in #4093). Zooming, applying aPatch, and then returning a new figure loses it too.Fix
When a layout key is synced, remember the value it had before the edit and the uirevision at that time. When the graph plots a figure that still holds the synced value under the same uirevision, it gives plotly.js the value from before the edit instead. plotly.js then sees an unchanged input and keeps the edit itself, as it did before #3882. The
figureprop keeps the synced edits, so #3810 stays fixed.This is only done for edits that plotly.js keeps under uirevision (
layoutUIControlPatternsin plotly.jsplot_api.js: axis ranges, shapes, annotations, dragmode, map center, ...). For other edits, like an edited legend title, putting the old value back would undo the user's edit right away, so those keys keep the current behavior.Testing
test_grbs013: zoom with a real mouse drag, then return a new figure, thenPatchand return a new figure again; the zoom stays. It fails ondev(range back to autorange) and passes with the change.test_grbs014: an edit that uirevision does not track (legend title) is not undone by the sync or by a laterPatch. I checked that it fails if the "edits plotly keeps" check is removed.tests/integration/graph: 53 passed, 1 skipped, run twice. Jest in dash-core-components: 85 passed.I also ran user journeys in headless Chrome against the published 4.4.0 and 4.4.1 wheels and against this branch. All with
uirevision=Trueunless noted. Every zoom and pan is a real mouse drag:On this branch, switching to pan from the modebar and panning a
scattermap(map center) also survive a new figure and aPatchfollowed by a new figure.The added work per plot is one
equalson each key the user edited. It costs less than theclonethatgetLayoutalready does on the same layout: about 1.5 us for an axis, and about 1 ms for 1000 edited shapes.Contributor Checklist
optionals
CHANGELOG.md