Skip to content

Conversation

@mbostock
Copy link
Member

I noticed that this returns zero ticks:

d3.ticks(1, 364, 1.1)

That’s because the chosen tick step is 500, and of course neither 0 or 500 is within [1, 364]. A more egregious case which also returns the empty array for the same reasons is:

d3.ticks(1, 499, 1.5)

The fix is simply to double the number of requested ticks recursively when the actual number of ticks is zero. (That’s because tickIncrement does not take into account the alignment of the domain with the tick values.) To avoid any risk of infinite recursion, we only double the count when the count is in the range [0.5, 2); at most two doublings as possible.

This means that this:

d3.ticks(1, 499, 0.5)

likewise now returns [200, 400] instead of [], but that seems consistent with the documented behavior of returning count + 1 = 1.5 values.

@mbostock mbostock requested a review from Fil December 26, 2022 18:31
@mbostock
Copy link
Member Author

Should we do this inside of tickIncrement instead of ticks so that the two are guaranteed to be consistent?

@mbostock mbostock marked this pull request as draft January 18, 2023 00:45
@mbostock mbostock marked this pull request as ready for review January 18, 2023 16:42
@mbostock mbostock requested a review from Fil January 18, 2023 16:42
Copy link
Member

@Fil Fil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants