From 38e1c1874b08625ef428bc278aa3893907a3b5e7 Mon Sep 17 00:00:00 2001 From: Roman Shtylman Date: Wed, 19 Apr 2023 08:12:30 -0700 Subject: [PATCH 1/2] 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. --- src/core/core.ticks.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/core.ticks.js b/src/core/core.ticks.js index eac44444af5..463fc4dea2f 100644 --- a/src/core/core.ticks.js +++ b/src/core/core.ticks.js @@ -45,7 +45,15 @@ 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); From 9c482a7d52c7f81e6514ba244ecee6715e08e547 Mon Sep 17 00:00:00 2001 From: Roman Shtylman Date: Wed, 19 Apr 2023 12:46:21 -0700 Subject: [PATCH 2/2] Update src/core/core.ticks.js Co-authored-by: Jacco van den Berg --- src/core/core.ticks.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core/core.ticks.js b/src/core/core.ticks.js index 463fc4dea2f..c0e34b11eda 100644 --- a/src/core/core.ticks.js +++ b/src/core/core.ticks.js @@ -51,9 +51,7 @@ const formatters = { // 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 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);