Skip to content

fix: apply ticks.format to the value 0#12260

Open
harukikuri wants to merge 1 commit into
chartjs:masterfrom
harukikuri:fix/ticks-format-zero
Open

fix: apply ticks.format to the value 0#12260
harukikuri wants to merge 1 commit into
chartjs:masterfrom
harukikuri:fix/ticks-format-zero

Conversation

@harukikuri
Copy link
Copy Markdown

Closes #11905

Ticks.formatters.numeric returned the literal '0' for a zero tick, short-circuiting before formatNumber. As a result a configured ticks.format (e.g. { style: 'currency', currency: 'USD' } or { style: 'percent' }) was ignored only for the value 0 — an axis would render 0 instead of $0 / 0%, while every other tick was formatted correctly.

Zero now flows through formatNumber with the configured format, but with minimumFractionDigits/maximumFractionDigits forced to 0 and handled before the scientific-notation logic. This preserves the existing behavior (plain 0, no decimals, no scientific notation) when no format is set, while applying the format when one is provided.

Test plan

  • Added unit tests in test/specs/core.ticks.tests.js:
    • ticks.format (currency / percent) is applied to 0$0, 0%
    • with no format, 0 stays 0 (no decimals; and no 0E0 even for huge ranges)
  • core.ticks spec passes on Chrome (6/6).

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.

Tick NumberFormat not working for 0

1 participant