Skip to content

isYearIntegers#2403

Open
mbostock wants to merge 5 commits intomainfrom
mbostock/four-digits
Open

isYearIntegers#2403
mbostock wants to merge 5 commits intomainfrom
mbostock/four-digits

Conversation

@mbostock
Copy link
Copy Markdown
Member

@mbostock mbostock commented Apr 1, 2026

Alternative to #2395. Fixes #768.

@mbostock mbostock requested a review from Fil April 1, 2026 16:55
@mbostock
Copy link
Copy Markdown
Member Author

mbostock commented Apr 1, 2026

I’m not sure about [1000, 3000] vs. [0, 9999] vs. [1500, 2500] as I used in this PR. The smaller heuristic avoided what I saw as an undesirable change to the autoLineFacet test (which has a y-domain of about [~0, ~2400]). But it’s also because this is applying the heuristic to the tick values, not the full scale domain, and thus is more likely to trigger.

@Fil
Copy link
Copy Markdown
Contributor

Fil commented Apr 1, 2026

I'm not seeing a clear-cut mathematical definition of what is best on this feature. The status quo feels bad, but we don't want to upset it too much either. This approach seems fine as it will do the right thing in most cases (for ticks). I wanted to do it for tips, too, but that could be a follow-up.

We need to document it.

@mbostock
Copy link
Copy Markdown
Member Author

mbostock commented Apr 1, 2026

We should do this for an ordinal scale, too… I’ll keep working.

@mbostock
Copy link
Copy Markdown
Member Author

mbostock commented Apr 1, 2026

How’s this @Fil?

@mbostock
Copy link
Copy Markdown
Member Author

mbostock commented Apr 1, 2026

(I thought about adding some documentation to the tip mark, but I don’t think it’s necessary as we don’t need to provide a complete specification of the “default format”.)

@mbostock mbostock enabled auto-merge (squash) April 1, 2026 20:09
```
:::

If the tick values are all integers between 1,500 and 2,500 (inclusive), Plot assumes the values represent years and formats ticks by default without thousand separators, such as 1996 instead of 1,996. You can explicitly suppress thousand separators with `tickFormat: "d"`, or enable them with `tickFormat: ",d"`. <VersionBadge pr="2403" />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Upon re-reading "Plot assumes the values represent years" is a bit of an exaggeration. That assumption does not lead Plot to do anything more than setting the format. A more modest and accurate description could be:

If the tick values are all integers between 1,500 and 2,500 (inclusive), Plot formats ticks by default without thousand separators, such as 1996 instead of 1,996 — better when the values represent years.

I'm happy to merge with the "assumes" wording, though.

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.

Smarter formatting for year number channels?

2 participants