Skip to content
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

Check for isNaN before building number formatter options #11238

Merged
merged 2 commits into from
Apr 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/core/core.ticks.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ const formatters = {
}

const logDelta = log10(Math.abs(delta));
const numDecimal = Math.max(Math.min(-1 * Math.floor(logDelta), 20), 0); // toFixed has a max of 20 decimal places

// When datasets have values approaching Number.MAX_VALUE, the tick calculations might result in
// infinity and eventually NaN. Passing NaN for minimumFractionDigits or maximumFractionDigits
// will make the number formatter throw. So instead we check for isNaN and use a fallback value.
//
// toFixed has a max of 20 decimal places
const numDecimal = isNaN(logDelta) ? 1 : Math.max(Math.min(-1 * Math.floor(logDelta), 20), 0);

const options = {notation, minimumFractionDigits: numDecimal, maximumFractionDigits: numDecimal};
Object.assign(options, this.options.ticks.format);
Expand Down