Skip to content

fix: Keep axis title values on the interval grid for large values - #2112

Open
a1573595 wants to merge 1 commit into
imaNNeo:mainfrom
a1573595:fix/1473-axis-max-title
Open

fix: Keep axis title values on the interval grid for large values#2112
a1573595 wants to merge 1 commit into
imaNNeo:mainfrom
a1573595:fix/1473-axis-max-title

Conversation

@a1573595

Copy link
Copy Markdown

Description

AxisChartHelper.iterateThroughAxis walked the axis with axisSeek += interval. Accumulating in a loop makes the floating point error grow with every step, so on large values — epoch timestamps being the common case — the last emitted value drifts slightly off the grid. With minX: 1698797425, maxX: 1698797426 the iteration yields 1698797425.999999 instead of 1698797426, so a getTitlesWidget that renders a label only when value == meta.max never matches and the trailing title silently disappears.

The loop now derives each value as initialValue + index * interval, which keeps the error bounded instead of cumulative, and snaps to the exact max when a step lands on it (within the interval-scaled epsilon that was already used for the loop bound). Behavior for small ranges is unchanged — the existing iterateThroughAxis tests pass untouched.

Added a regression test that reproduces the issue's exact numbers and asserts both that the last value equals max and that no artifact value sits closer than half an interval to its neighbor.

TestResult

Left Before, Right After

Android

iOS

Chrome

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation and added dartdoc comments with ///.
  • I have updated/added relevant examples in example.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Closes #1473

…aNNeo#1473)

iterateThroughAxis accumulated axisSeek += interval, so on large values
like epoch timestamps the rounding error built up and emitted artifacts
such as 1698797425.999999 in place of the exact data maximum, which broke
value == meta.max checks in getTitlesWidget. Values are now computed as
initialValue + index * interval and snapped to max when they land on it.
@a1573595 a1573595 changed the title fix: Keep axis title values on the interval grid for large values (#1… fix: Keep axis title values on the interval grid for large values Jul 25, 2026
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.

LineChartData bottomTitles max value is not equal to TitleMeta max value

1 participant