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

time.ticks and time.tickFormat don’t accept the same arguments. #183

Closed
mbostock opened this issue Jul 31, 2019 · 1 comment
Closed

time.ticks and time.tickFormat don’t accept the same arguments. #183

mbostock opened this issue Jul 31, 2019 · 1 comment

Comments

@mbostock
Copy link
Member

This is closely related to #57 and d3/d3-axis#6. For example:

d3.axisBottom(d3.scaleTime()).ticks(d3.timeHour, 3)

This generates ticks every three hours, where d3.timeHour is the interval and 3 is the step (deprecated in 16d5789 but not removed), but the ticks are all formatted as the string “3” because when you call

time.tickFormat(d3.timeHour, 3)

d3.timeHour is interpreted as the count which is ignored, and 3 is interpreted as the specified, thus making it equivalent to

d3.timeFormat(3)

which gives you a function that just returns the string “3”.

It appears that the desired behavior is that you use interval.every instead:

d3.axisBottom(d3.scaleTime()).ticks(d3.timeHour.every(3))

This does produce the desired result, but it means that you have to call axis.tickFormat separately if you want to also specify the tick format, and you also have to construct the d3.timeFormat explicitly (or d3.utcFormat with d3.scaleUtc, which is another opportunity for error). If you try to pass the specifier and use interval.every:

d3.axisBottom(d3.scaleTime()).ticks(d3.timeHour.every(3), "%I")

Then you get an error

TypeError: n.every is not a function 

because it tries to call interval.every again on the interval returned by interval.every, which is nonsensical (and not supported).

@mbostock
Copy link
Member Author

Given that the step was deprecated way back in 2016 (1.0.1), and that we just released 3.0.0 (but not yet d3@6.0.0), I’ll argue that this is a bug, and that we shouldn’t still be supporting the secret step argument to time.ticks, and that instead the second argument should be ignored so that it can be compatible with time.tickFormat and hence axis.ticks.

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

1 participant