Draft
Conversation
Member
Author
|
Work in progress… Screen.Recording.2024-06-13.at.1.43.29.PM.movNote that the axis ticks don’t change because I haven’t implemented re-running mark initializers yet. |
|
I'm rooting for your updates! |
Draft
|
How about using the escape key to reset the zoom? That way, everything can be controlled via keyboard shortcuts. |
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.
This adds a top-level zoom option which can be set to true to enable panning and zooming (via d3-zoom). The option can also be set to xy to zoom both the x and y scales, x to only zoom the x scale, y to only zoom the y scale, or false (the default) or null to disable zooming.
Setting the zoom option is functionally equivalent to setting the domains of the x and y scales interactively; all marks that use position scales are affected, as well as any transforms or initializers that may depend on these scales. (See Julien Colot’s notebook for a userland example of this technique.)
The goal of this initial implementation is not optimal performance, but rather functional correctness. I make some effort at performance — for example, tracking which channels need to be rescaled when the x or y domains change, and only re-rendering the affected marks — but there is room for future improvement, especially if mark implementations can assist by updating the DOM directly rather than re-rendering and replacing.
I am also interested in exploring usability improvements to panning and zooming. I’d like keyboard shortcuts (when the plot is focused), such as + to zoom in, - to zoom out, and arrow keys ↑↓←→ to pan. I also want a reset button to zoom to the home view, but I don’t know yet where that button should live. We might also support one-dimensional zooming by clicking in the axes.
I’d also like programmatic zooming with zoom transitions (a plot.zoom method), and a configurable duration for zoom transitions (such as double-clicking to zoom in). Another possibility is a dedicated method for updating a scale’s domain and recomputing everything downstream, though at least for now I’m just interested in position scales (x and y).
TODO
Fixes #1590.
Previously #1738 #1964.