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

Axis with d3.scaleTime scale and specified number of ticks is apparently mislabelled #6

Closed
robinhouston opened this issue Apr 15, 2016 · 3 comments
Assignees

Comments

@robinhouston
Copy link

An axis that uses a date scale (d3.scaleTime) and has a specified number of ticks (.ticks(6)) is apparently mislabelled. All the ticks are labelled with the string "6".

See demo here.

@robinhouston
Copy link
Author

Sorry, my mistake. This is documented behaviour:

These arguments are also passed to the scale’s tickFormat method to generate a tick format (unless a tick format is specified explicitly via axis.tickFormat)

Is there any way to specify the number of ticks while retaining the default tick format?

@robinhouston
Copy link
Author

So, one can do it like this:

axis.ticks(5).tickFormat(scale.tickFormat());

That feels a little bit convoluted, though.

@mbostock mbostock added the bug label Apr 15, 2016
@mbostock mbostock self-assigned this Apr 15, 2016
@mbostock mbostock reopened this Apr 15, 2016
@mbostock
Copy link
Member

mbostock commented Apr 15, 2016

Yeah, I think this is a bug. The problem is that the time scale’s tickFormat method isn’t consistent with the other scales, which all take a suggested count as the first argument.

In D3 3.x this wasn’t an issue because the time scale ignored all arguments to scale.tickFormat. So, if you specified a count to axis.ticks, it would affect scale.ticks, but not scale.tickFormat (because a time scale always renders times the same way, dependent only on the input time and not the number of ticks).

We should retain that behavior for D3 4.0.

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