Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot.rescale #2251

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

plot.rescale #2251

wants to merge 1 commit into from

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Nov 24, 2024

This is a first cut at an alternate take to zooming, focusing on the programmatic API first rather than the interaction. This exposes a plot.rescale method that takes scale definitions, allowing scales to be modified after a plot is rendered; the plot is re-rendered in place with the new scale definitions.

For zooming, we would use plot.rescale to redefine the x and y domains (or, in the case of an ordinal position scale, we might redefine the range instead). But the plot.rescale method could have other uses as well, such as adjusting the r scale as you zoom in or out, switching from a linear to a log scale, redefining the color scale to highlight certain elements, and so on.

Additionally, it should be simpler to sketch this if we focus on the programmatic API first. We should be able to easily implement interactive zooming and zoom transitions on top of this API. Here is a little demo of a panning animation:

Screen.Recording.2024-11-23.at.7.21.07.PM.mov

The implementation so far is as minimal as I could make it. A new plot is rendered with the new options, and then the contents of the old plot are replaced with the contents of the new plot. I don’t think this approach will work as-is (for example, I think it breaks the tip mark); but I think we can make a smarter, faster implementation that has the same API.

We also need to figure out what scale options are valid to pass to plot.rescale. Since these options are merged not with the original options, but with the materialized scales, the results may not be what you expect; for example, passing the scheme option for a color scale typically has no effect because it is lower priority than the materialized range or interpolate option.

Fixes #1590.

Previously #2083 #1964 #1738.

@mbostock mbostock changed the title _plot_.rescale plot.rescale Nov 24, 2024
src/plot.js Show resolved Hide resolved
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.

Panning and zooming
2 participants