-
Notifications
You must be signed in to change notification settings - Fork 185
expose scales #538
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 #538
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of materializing a family field on the internal scale object, I wonder if we can have a function that takes a specific scale type and returns either a corresponding family, or a boolean. For example:
function isTemporalType(type) {
return type === "time" || type === "utc";
}
Or the other approach:
const quantitative = Symbol("quantitative");
const temporal = Symbol("temporal");
const ordinal = Symbol("ordinal");
function family(type, key) {
switch (type) {
case "diverging":
case "diverging-sqrt":
case "diverging-pow":
case "diverging-log":
case "diverging-symlog":
case "cyclical":
case "sequential":
case "linear":
case "sqrt":
case "threshold":
case "quantile":
case "pow":
case "log":
case "symlog":
return quantitative;
case "identity":
return registry.get(key) === position ? quantitative : ordinal;
case "utc":
case "time":
return temporal;
case "ordinal":
case "categorical":
case "point":
case "band":
return ordinal;
}
}
This would be useful when coercing channel values based on the scale type, for example. (I haven’t reviewed the suggested code above closely…)
7e10fa9
to
524d01b
Compare
Thanks for the help. I’m going to continue rewriting the tests today (schedule permitting). |
Okay, I think this is 99% ready. The last things I want to think through are:
The latter one embodies the difference between Plot’s internal and external representations. Externally, scales and axes options are on the same object, but internally, we split them up. Probably we want to favor the external representation when we materialize scale objects and return them from plot.scale. Although I suppose alternatively we could add a plot.axis method in the future, and you’d be expected to splat them together if needed. But at any rate since we are already exposing the label axis option on the returned scale object, I’m guessing that we do in fact want to include all the axis options in the exposed scale and use a unified representation. Okay, maybe that’s more like 92% ready. 😉 |
Co-authored-by: Mike Bostock <[email protected]>
Co-authored-by: Mike Bostock <[email protected]>
Co-authored-by: Mike Bostock <[email protected]>
Co-authored-by: Mike Bostock <[email protected]>
tiny difference with the parent commit: a non-position scale (such as opacity) can have an automatic label (including "%")
62e0e3b
to
5f9a553
Compare
exposing scales, extracted from #484
build at https://observablehq.com/@observablehq/expose-plot-scales-538
With many tests!