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

Interval-aware default ticks/tick formats #932

Open
Fil opened this issue Jun 10, 2022 · 5 comments
Open

Interval-aware default ticks/tick formats #932

Fil opened this issue Jun 10, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@Fil
Copy link
Contributor

Fil commented Jun 10, 2022

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

@mbostock mbostock added the enhancement New feature or request label Jun 10, 2022
@mbostock mbostock changed the title format integers without the decimal dot Interval-aware default tick formats Jun 10, 2022
@mbostock
Copy link
Member

I’ve retitled this issue to describe the more general issue.

@Fil
Copy link
Contributor Author

Fil commented Jan 28, 2023

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})

Capture d’écran 2023-01-28 à 13 38 15

Since the interval is "day" we could have a stricter tickFormat than the default "multiscale".

cc: @mootari

@mbostock mbostock changed the title Interval-aware default tick formats Interval-aware default ticks/tick formats May 23, 2023
@mbostock
Copy link
Member

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.

@mbostock
Copy link
Member

mbostock commented Jun 27, 2023

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.

@mbostock
Copy link
Member

mbostock commented Aug 23, 2023

I got this working in #1790, but messy:

    : tickFormat === undefined && data && isNumeric(data) && scale.interval?.[intervalDuration]
    ? format(`.${`${scale.interval?.[intervalDuration] % 1}`.length - 2}f`)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants