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

year and integer type scales #1268

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

year and integer type scales #1268

wants to merge 5 commits into from

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Feb 10, 2023

Adds an integer flag on a scale when the associated channels are all integers, either because the interval option is integer, or because we checked a sample of 40 values in each channel.

This flag cannot be specified by the user (but they can use interval: 1), and is censored when the scale is exported.

When the axis text mark decides on its tickFormat, the heuristic is that if the scale is integer and the domain is covered by [1500...2200], it's probably best to default to "d" rather than formatDefault (for ordinal scales) or the linear scale’s default number format, since it's possible that the values are years.

Closes #768

(This is built on top of #1265 but the same logic could be built on the scale function.)

Related: #932

For axes, we also need to pass the following elements, which are not exposed by _plot_.scale("x"):
- the scale's label
- the underlying D3 scale’s tickFormat and tick functions
- the range of the identity scale
@Fil Fil changed the title First pass at #768, works for linear-integer year and integer type scales Feb 10, 2023
@Fil Fil changed the base branch from main to fil/pass-scales February 12, 2023 14:06
Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we did this by introducing a new year scale type? Then we could change the inferScaleType function to choose year over linear if the data matches. We already have a bunch of inference in inferScaleType (rather than mixing inference into Scales), and using a new scale type gives an explicit way for the user to opt-in or opt-out of this behavior.

I guess we’d need year-point and year-band for the ordinal case? Or maybe a separate year option? I dunno. I’ll need to think about that one.

@mbostock
Copy link
Member

mbostock commented Apr 1, 2023

Can we do this without coupling it to #1265? I’m looking for smaller wins.

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.

2 participants