Skip to content

Commit b16f32a

Browse files
Check for isNaN before building number formatter options (#11238)
* Check for isNaN before building number formatter options 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. Instead we check for isNaN and use a fallback value so the formatter does not throw. * Update src/core/core.ticks.js Co-authored-by: Jacco van den Berg <[email protected]> --------- Co-authored-by: Jacco van den Berg <[email protected]>
1 parent b34e273 commit b16f32a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/core/core.ticks.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ const formatters = {
4545
}
4646

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

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

0 commit comments

Comments
 (0)