fix(tickStep&logticks): prevent division by zero and handle invalid c… #8198
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.
fix(ticks): harden tick generation to prevent NaN/∞ and bad secondary ticks (bug #8194 )
Summary
This PR fixes two defects in tick generation that could produce non-finite numbers and misleading intermediate (secondary) log ticks.
Fix-1: Guard tickStep() against invalid count
Root cause: step0 = |stop - start| / Math.max(0, count) divides by 0 when count ≤ 0, yielding Infinity/NaN.
Change: Add a fail-fast guard to ensure count is a positive, finite number; throw a clear error otherwise.
Impact: Prevents non-finite values from propagating into axis/tick rendering and downstream math.
Fix-2: Stabilize secondary ticks in getLogTicks()
Root cause: Using secondaryTickCount directly could create an invalid window (start ≥ end) and/or a zero/too-small count between main ticks.
Change:
Clamp the effective secondary count: const adjustedTickCount = Math.max(1, secondaryTickCount - 2);
Generate secondary ticks within a margin inside the main-tick span to avoid touching endpoints:
ticks(
tick + rangeBetweenMainTicks / (secondaryTickCount + 1),
nextTick - rangeBetweenMainTicks / (secondaryTickCount + 1),
adjustedTickCount
)
Impact: Produces well-spaced, reproducible secondary ticks without overlapping main ticks or collapsing ranges.
Code changes
tickStep(start, stop, count)
if (count <= 0 || !Number.isFinite(count)) {
throw new Error('Count must be a positive finite number');
}
getLogTicks(start, stop, mainTickCount = 8, secondaryTickCount = 6)
const adjustedTickCount = Math.max(1, secondaryTickCount - 2);
// secondary window shrunk in from both ends; then symlog’ed
Checklist
-Fixes numerical instability in tickStep
-Stabilizes secondary tick generation in getLogTicks
-Lint & build passing locally
-Behavior unchanged for valid inputs