Skip to content

fix(linear-scale): respect stepSize for non-divisible min/max ranges#12225

Open
syawqy wants to merge 1 commit intochartjs:masterfrom
syawqy:fix/12165-linear-stepsize-nondivisible
Open

fix(linear-scale): respect stepSize for non-divisible min/max ranges#12225
syawqy wants to merge 1 commit intochartjs:masterfrom
syawqy:fix/12165-linear-stepsize-nondivisible

Conversation

@syawqy
Copy link
Copy Markdown

@syawqy syawqy commented Mar 30, 2026

Fixes #12165

Summary

When min, max, and stepSize are set, linear tick generation used a spacing-based tolerance (spacing / 1000) to detect whole step counts.
With larger step sizes, that tolerance can be too loose and misclassify non-divisible ranges as divisible, producing evenly distributed ticks instead of stepSize increments.

This change switches the whole-step check to a machine-precision-based epsilon derived from stepCount.

Behavior after fix

For non-divisible ranges, ticks follow stepSize multiples and keep max as the final shorter interval:

  • min: 0, max: 3333, stepSize: 500
  • ticks: [0, 500, 1000, 1500, 2000, 2500, 3000, 3333]

Floating-point divisible ranges still behave correctly:

  • min: 0, max: 0.3, stepSize: 0.1

Tests

Added regression tests in test/specs/scale.linear.tests.js for:

  1. Large non-divisible range (0..3333, stepSize: 500)
  2. Floating-point divisible range (0..0.3, stepSize: 0.1)

Validated with:

  • pnpm run lint-js
  • pnpm run test-ci-karma scale.linear.tests

References

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.

Inconsistent step size behaviour when step size is not a divisor of (max - min)

1 participant