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

try to generate at least one tick #264

Merged
merged 3 commits into from
Jan 18, 2023
Merged

try to generate at least one tick #264

merged 3 commits into from
Jan 18, 2023

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.

2 participants