-
Notifications
You must be signed in to change notification settings - Fork 184
expose scales #425
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
expose scales #425
Conversation
accepts a function that receives the scale; if that function returns a DOM node, adds it to the figure.
Now we can add |
… be used to recreate the scale in another plot. In particular it doesn't show the (D3) scale anymore. Instead, a convenience function Plot.scale(options) is provided, that will turn a scale *options* object into a D3 scale, ready to use in another context. (This also clears the question of mutability.)
For anyone following this, 228565b exposes Plot.scale(options), allowing to create a D3 scale from Plot options. |
Co-authored-by: Mike Bostock <[email protected]>
Co-authored-by: Mike Bostock <[email protected]>
ensure we don't compute the scale options twice always return label, clamp, type
Color legends in #432 ! |
I have to work again on this, since some options are missing (like exponent: 0.3 for type="exp" scales), and we want all options including those that are not consumed by the scales, but could be used by the legend (like "columns" for swatches). |
…", "identity") and type ("utc", "time" / "linear", "sqrt", "log"… / "categorical" / "identity")
except the following which are part of the definition of: scale.domain() // domain, nice, scale.range() // range, inset, reverse, scale.interpolate() // interpolate, clamp, round paddingInner & paddingOuter // padding
I plan on looking at this next. Exposing (materialized) scales will be great for debugging, too. I’m leaning towards just exposing plot.scales to start, and not the plot.scale method which returns a D3 scale instance. But mostly that’s so I can focus on getting this landed sooner and minimizing new API. 🙂 |
deferring to #484 |
The scales are exposed on the figure through a .scales property, a function that lazily computes scale option objects that can be used to reproduce the same scales in a different plot.
The function takes a scale name as parameter, and returns a scale definition that matches the given scale as instanciated by the plot's data. (If no scale name is given, it returns all the scales.)
With a lot of unit tests.
A (very messy) notebook with the build is https://observablehq.com/@fil/expose-scales-425
TODO: