Interval-aware default tick formats
When the data only contains integers, it would be great if the default tickFormat would not do "1.0, 2.0, 3.0"… but rather "1, 2, 3".
In #849 I hoped that indicating an integer interval would be used, in this case to infer an intent of only having integers. (Similarly, if we used interval: d3.utcYear we'd rather format the ticks as "%Y", and d3.utcMonth would result in a default of "%Y-%m" or something.)
Example: the test plot integer-interval.js (svg) should have inferred an integer tickFormat for the x axis. (See also the discussion here.)
Also related to #768
I’ve retitled this issue to describe the more general issue.
A related typical use case is
Plot.tickX([new Date(2001, 0, 1), new Date(2001, 1, 1)]).plot({
x: {interval: "day", tickRotate:40},
height: 70, marginBottom: 50})
Since the interval is "day" we could have a stricter tickFormat than the default "multiscale".
cc: @mootari
Related feedback from Misha Tsvelik: https://vimeo.com/829300247/91d6c7eeef
This issue applies to ticks, and not just tick formats: for example if the data is just integers, then we wouldn’t want to show ticks at 0.1, 0.2, 0.3, etc., or if the data is just months, we don’t want to show weekly ticks.
I guess we would need some heuristic that looks at the channel values and guesses what the interval is; if we guess successfully, then we can choose an appropriate tick interval and accompanying tick format.
This is pretty much fixed by #1728 for time axes, but we’d need to do something similar to numbers/integers. ~~And also this isn’t fixed for binning, in the sense of you don’t want to bin hourly if you only have daily data.~~ That latter issue is #1013.
I got this working in #1790, but messy:
: tickFormat === undefined && data && isNumeric(data) && scale.interval?.[intervalDuration]
? format(`.${`${scale.interval?.[intervalDuration] % 1}`.length - 2}f`)