fix: Respect axis range when formatting K/M/B axis labels - #2113
Open
a1573595 wants to merge 2 commits into
Open
fix: Respect axis range when formatting K/M/B axis labels#2113a1573595 wants to merge 2 commits into
a1573595 wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Utils.formatNumberreceivesaxisMin/axisMaxso it can pick a sensible precision, but only the sub-thousand branch actually used them. TheK/M/Bbranches calledtoStringAsFixed(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 reads1.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 theMbranch 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.0suffix, which would leave1.10Monce more than one digit is produced.Note on the test diff: some existing
formatNumberrows 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
///.example.Breaking Change?
Related Issues
Closes #1584