Repository navigation
Conversation
mbostock
reviewed
Nov 11, 2026
| import {tickIncrement} from "./ticks.js"; | ||
|
|
||
| export default function nice(start, stop, count) { | ||
| if (count > 0) count = Math.max(count, start < 0 && stop > 0 ? 2 : 1); |
Member
There was a problem hiding this comment.
Suggested change
| if (count > 0) count = Math.max(count, start < 0 && stop > 0 ? 2 : 1); | |
| if (count > 0) count = Math.max(count, start <= 0 || stop >= 0 ? 2 : 1); |
Is it not something more lax like this? I guess you don’t need 2 in the [0, 0] case but that doesn’t really matter anyway.
Member
Author
There was a problem hiding this comment.
I think start <= 0 || stop >= 0 is always true? Did you mean start <= 0 && stop >= 0?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With a small count,
nicenever converged:nice(-1, 5, 1)returned[-1e308, 1e308], andbin().thresholds(1)([-1.4, 5.6])returned bins withNaNbounds.A niced interval spans at least one step. When it crosses zero, it has at least two, since 0 is a tick for every step.
nice(-1, 5, 1)→[-10, 10]nice(0, 1, 0.5)→[0, 1](was[0, 1e308])bin().thresholds(1)([-1.4, 5.6])→[-10, 0),[0, 10]Built on #293, which fixed the case crossing zero, simplifying it to also cover counts less than one.
Fixes #292.
Supersedes #293.