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

2-day ticks between months #245

Closed
FlorianDr opened this issue Apr 16, 2021 · 2 comments
Closed

2-day ticks between months #245

FlorianDr opened this issue Apr 16, 2021 · 2 comments

Comments

@FlorianDr
Copy link

Hey there,

I'm trying to create uniformly-spaced time ticks with 'time.ticks()'. However, the function returns non equidistant intervals for the 2-day ticks going over the end of a month. Here is an example:

https://jsfiddle.net/6vopq2by/

The document states "The returned tick values are uniformly-spaced (mostly)". Why "mostly"?

How can I achieve my use cases for the provided instance? Will I need to make use of '.every()' with a custom interval?

Thank you in advance,
Florian

@mbostock
Copy link
Member

See interval.every:

The meaning of step is dependent on this interval’s parent interval as defined by the field function. For example, d3.timeMinute.every(15) returns an interval representing every fifteen minutes, starting on the hour: :00, :15, :30, :45, etc. Note that for some intervals, the resulting dates may not be uniformly-spaced; d3.timeDay’s parent interval is d3.timeMonth, and thus the interval number resets at the start of each month.

If you want every other day rather than every odd date, then you need to create a custom time interval and use that instead of time.ticks() (which uses d3.timeTicks or d3.utcTicks internally). Here’s how you would do that:

https://observablehq.com/d/906f777c9f2f0701

@FlorianDr
Copy link
Author

Awesome! Thank you for the fast response, @mbostock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants