Skip to content

Fix errors from zero-dimension scales #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2021
Merged

Conversation

joshkel
Copy link
Contributor

@joshkel joshkel commented Jun 13, 2021

Trying to pan a zero-dimension linear scale results in a RangeError: minimumFractionDigits value is out of range when LinearBaseScale tries to format its ticks.

This can happen a couple of ways:

  • If a scale is configured with an identical min and max - that seems like a misconfiguration, but Chart.js by itself at least attempts to handle it.
  • If the browser window is shrunk enough for the chart area to have 0 dimensions

The problem occurs because panNumericalScale calculates a newMin and newMax of NaN here. This, in turn, is because getDecimalForPixel (used by getValueForPixel) and getPixelForValue return NaN for 0-dimension scales.

Fixes #543

Trying to pan a zero-dimension linear scale results in a `RangeError: minimumFractionDigits value is out of range` when LinearBaseScale tries to format its ticks.

This can happen a couple of ways:

* If a scale is configured with an identical min and max - that seems like a misconfiguration, but Chart.js by itself at least attempts to handle it.
* If the browser window is shrunk enough for the chart area to have 0 dimensions

The problem occurs because panNumericalScale calculates a newMin and newMax of NaN here. This, in turn, is because getDecimalForPixel (used by getValueForPixel) and getPixelForValue return NaN for 0-dimension scales.

Fixes chartjs#543
@kurkle kurkle added the bug label Jun 21, 2021
@kurkle kurkle merged commit 2cb5f93 into chartjs:master Jun 21, 2021
@joshkel joshkel deleted the pan-nan branch June 21, 2021 11:30
@kurkle kurkle added this to the 1.1.0 milestone Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Errors from zero-dimension scales
2 participants