fix(axes): add MinSeparators floor so auto-step keeps grids readable (#2071) - #2180
Conversation
ade2574 to
b11d7a1
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses axis auto-tick selection on short/compact charts by introducing a minimum separator count floor, ensuring automatic step “nice-number” snapping doesn’t result in only 1–2 visible grid separators.
Changes:
- Added
MinSeparatorstoIPlane(default3) and implemented it inCoreAxisandCorePolarAxis. - Updated Cartesian and Polar
GetTickcalculations to step down the “nice-number ladder” untilrange / tick >= MinSeparators(unlessForceStepToMinorMinSeparators <= 0). - Added snapshot tests and baselines covering the default floor behavior and opt-out (
MinSeparators = 0).
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/LiveChartsCore/Kernel/Sketches/IPlane.cs |
Introduces the new MinSeparators API surface on planes/axes. |
src/LiveChartsCore/CoreAxis.cs |
Implements MinSeparators (default 3) for Cartesian axes. |
src/LiveChartsCore/CorePolarAxis.cs |
Implements MinSeparators (default 3) for polar axes. |
src/LiveChartsCore/Kernel/Extensions.cs |
Enforces the MinSeparators floor during tick selection for both Cartesian and Polar axes. |
tests/SnapshotTests/AxesTests.cs |
Adds snapshot tests covering floor enabled vs disabled behavior. |
tests/SnapshotTests/Snapshots/AxesTests_MinSeparatorsFloor.png |
New baseline image for default floor behavior. |
tests/SnapshotTests/Snapshots/AxesTests_MinSeparatorsDisabled.png |
New baseline image for opt-out behavior (MinSeparators = 0). |
Thanks for your contribution!Benchmark delta — ✅ 3 improvements, no regressionsShow detailsBase: master — Head: 7025abc (run)
Build summary for run #359. Packing ✅Download the NuGet packages for this build here (dev-359). Available for 30 days — you can either use them directly or wait for this PR to be merged to have them published to NuGet.org. Tests ✅ |
The auto-step logic snaps the calculated step up to a nice number (1, 2, 5, 10 x magnitude). On short axes with awkward ranges this could leap a whole tier and leave only 1-2 separators in view, which is what issue #2071 reports. Add a MinSeparators property on IPlane (default 3) and walk the nice-number ladder downward when the snap-up would yield fewer separators than requested. ForceStepToMin still wins since the user explicitly pinned the step there. The ladder uses thresholds at the bucket midpoints (7.5, 3.5, 1.5) rather than exact comparisons so floating-point noise on tick/magnitude (e.g. 9.999... when both were derived from 10 * 0.1) cannot skip a tier. The magnitude underflow guard uses !(m > 0) so NaN is also caught. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pair of tests on the same 400x120 short chart with values [0, 11]: MinSeparatorsFloor exercises the default behavior (Y axis renders 0/5/10) and MinSeparatorsDisabled locks in the original snap-up behavior with MinSeparators=0 (Y axis renders only 0), proving the opt-out path stays available. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds a section right after MinStep on docs/cartesianChart/axes.md that describes the new floor on the auto-step (default 3), how to opt out (MinSeparators = 0), and the interaction with ForceStepToMin. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3ad533c to
7025abc
Compare
…in-separators fix(axes): add MinSeparators floor so auto-step keeps grids readable (Live-Charts#2071)
Summary
int MinSeparatorstoIPlane(default3) implemented onCoreAxisandCorePolarAxis. After computing the nice-number tick, bothGetTickoverloads now walk the ladder downward (10 → 5 → 2 → 1 → 0.5 → 0.2 → …) untilrange / tick >= MinSeparators.ForceStepToMinstill wins — when the user pinned the step explicitly we don't second-guess them. SettingMinSeparators = 0opts out entirely.Why default to 3
Quoting the issue author: "I would prefer an ugly graph over an unreadable one." Three separators is the smallest count where the axis communicates a scale (min, mid, max) instead of a single landmark.
Test plan
dotnet run --project tests/CoreTests/CoreTests.csproj --framework net8.0— all 461 passdotnet run --project tests/SnapshotTests/SnapshotTests.csproj --framework net10.0— all 102 pass (no existing baselines shifted)AxesTests.MinSeparatorsFloorandAxesTests.MinSeparatorsDisabledcover the on/off behavior on the same 400×120 short chart withrange = 11:MinSeparators = 0: Y axis renders only 0 (the original buggy behavior, locked in to prove opt-out).🤖 Generated with Claude Code