Skip to content

fix: Respect axis range when formatting K/M/B axis labels - #2113

Open
a1573595 wants to merge 2 commits into
imaNNeo:mainfrom
a1573595:fix/1584-format-number-axis-range
Open

fix: Respect axis range when formatting K/M/B axis labels#2113
a1573595 wants to merge 2 commits into
imaNNeo:mainfrom
a1573595:fix/1584-format-number-axis-range

Conversation

@a1573595

Copy link
Copy Markdown

Description

Utils.formatNumber receives axisMin / axisMax so it can pick a sensible precision, but only the sub-thousand branch actually used them. The K / M / B branches called toStringAsFixed(1) unconditionally, so the axis range was ignored as soon as a value crossed 1000. With the reporter's data (minY: 976405.27, maxY: 1135594.31) every left title above 1M rounds to the same string and the axis reads 1.1M / 1.1M / 1.1M.

Each branch now derives its fraction digits from the axis diff scaled by the same divisor it uses for the value — getFractionDigits(diff / million) for the M branch and so on — so precision follows how much the axis actually spans. The trailing-zero trim was also generalized: it previously only stripped a literal .0 suffix, which would leave 1.10M once more than one digit is produced.

Note on the test diff: some existing formatNumber rows passed an axis range unrelated to the value being formatted (e.g. formatNumber(0, 10, 2345123) — a range of 10 with a value in the millions). Those combinations cannot occur in a real chart, and with the fix they would ask for a precision the old hardcoded value silently ignored. They are updated to ranges matching the value scale (formatNumber(0, 5000000, 2345123)); the expected outputs are unchanged. Rows where the range was already consistent are untouched.

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 #1584

formatNumber hardcoded one fraction digit in the K/M/B branches, so a
narrow axis range over large values (e.g. min 976405, max 1135594)
collapsed every label into the same text like 1M. Fraction digits now
derive from the axis diff scaled by the same divisor, and trailing zeros
are trimmed generically. Legacy test rows fed axis ranges inconsistent
with their values; they now use ranges matching the value scale.
@a1573595 a1573595 changed the title fix: Respect axis range when formatting K/M/B axis labels (#1584) fix: Respect axis range when formatting K/M/B axis labels 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.

Side Title(Vertical title) is having issue of Number formtting.

1 participant