Skip to content

Conversation

@mishu2424
Copy link

@mishu2424 mishu2424 commented Nov 7, 2025

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant