-
Notifications
You must be signed in to change notification settings - Fork 185
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
ordinal interval #849
ordinal interval #849
Conversation
Taking a bit more time than expected because it has implications on the warnings; for example if you have a date interval on x you don't want a warning that the dates are unexpected in an ordinal scale. |
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.
This is going to be so useful! Solving a good part of the trouble with ordinal years.
#852 complements this PR by suppressing the warning on ordinal dates in the case of a scale interval.
A few more suggestions, maybe for a fast follow:
|
Should this be a more general error if you have a Very High Cardinality Domain (VHCD) on an ordinal scale? Or maybe just for a point or band scale? I think it’d be pretty easy to add this check in the scale constructor when the domain is not set explicitly.
If x has interval: 1, then it will have a default transform of Math.floor, so you shouldn’t get any fractional values in the domain (unless you set the domain explicitly).
Yeah, I think this is a general confusion around scale transforms, which is that they happen after any mark data transforms. It might be better if they happened before instead, but I don’t think that’s possible (since the scale options aren’t exposed to mark data transforms). I think maybe we just live with this one. |
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.
The interval option should be exposed with plot.scale("x"); it is not enough to expose the materialized domain: we are missing the derived transform option.
(A way to solve this is suggested in #852, with tests)
* Specifying a scale interval shows the intent of having ordinal numerical or ordinal dates: suppress warning. Side note: if a numeric interval was specified, string numerics have already been coerced to numbers by the scale transform; so this in fact only has consequences for ordinal dates, such as in the downloads-ordinal test plot. * document scale intervals * test plot with year intervals * Update src/scales.js Co-authored-by: Mike Bostock <[email protected]> * Update src/scales.js Co-authored-by: Mike Bostock <[email protected]> * Update src/scales.js Co-authored-by: Mike Bostock <[email protected]> * d3.utcDay-like intervals do not parse string dates * reusable interval option * When the interval option is applied on a quantitative scale, generate the ticks with the interval; also set the tickFormat so that we don't show 1.0, 2.0, 3.0 if the interval is an integer. * tests * normalize intervals lists a few TODOs re: the default tick format: - we don't want decimal notation if the interval is specified as an integer - we don't want months to appear if the interval is specified as d3.utcYear - we don't want years to appear with commas (#768) * formatDefault for ordinal scales * Update README * call maybeInterval sooner * tabular-nums for interval’d ordinal axes Co-authored-by: Mike Bostock <[email protected]>
48166af
to
51741f4
Compare
This should be ready to go. |
Excellent! The only thing I don't like is the formatting of integers as 1.0, 2.0 etc in the test/output/integerInterval.svg plot. I hoped we could use the interval to infer that the format should not include the decimal dot—but that will be for another issue. |
* bail out if the inferred ordinal domain has more than 10k values (see #849 (comment)) * only on point and band scales * only throw an error for position scales * apply review suggestion: key as first argument to ScaleO * shorter error message Co-authored-by: Mike Bostock <[email protected]>
* bail out if the inferred ordinal domain has more than 10k values (see observablehq/plot#849 (comment)) * only on point and band scales * only throw an error for position scales * apply review suggestion: key as first argument to ScaleO * shorter error message Co-authored-by: Mike Bostock <[email protected]>
* bail out if the inferred ordinal domain has more than 10k values (see observablehq/plot#849 (comment)) * only on point and band scales * only throw an error for position scales * apply review suggestion: key as first argument to ScaleO * shorter error message Co-authored-by: Mike Bostock <[email protected]>
* bail out if the inferred ordinal domain has more than 10k values (see observablehq/plot#849 (comment)) * only on point and band scales * only throw an error for position scales * apply review suggestion: key as first argument to ScaleO * shorter error message Co-authored-by: Mike Bostock <[email protected]>
* bail out if the inferred ordinal domain has more than 10k values (see observablehq/plot#849 (comment)) * only on point and band scales * only throw an error for position scales * apply review suggestion: key as first argument to ScaleO * shorter error message Co-authored-by: Mike Bostock <[email protected]>
Fixes #513.
When a scale has an interval option, interval.floor is used as the scale transform, and then for ordinal scales, the domain is computed using interval.range(min, max), ensuring that gaps are shown and that ordinal values appear in the intended order.