From 0f4ca6317e9189a91a89104b049614c333a0776f Mon Sep 17 00:00:00 2001 From: Angus Comrie Date: Sat, 3 Aug 2019 03:23:15 +0200 Subject: [PATCH] clamps argument of toExponential between 0 and 20 (#6423) --- src/core/core.ticks.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/core.ticks.js b/src/core/core.ticks.js index c9e75181fb2..d9049fd2f90 100644 --- a/src/core/core.ticks.js +++ b/src/core/core.ticks.js @@ -49,7 +49,9 @@ module.exports = { var maxTick = Math.max(Math.abs(ticks[0]), Math.abs(ticks[ticks.length - 1])); if (maxTick < 1e-4) { // all ticks are small numbers; use scientific notation var logTick = helpers.log10(Math.abs(tickValue)); - tickString = tickValue.toExponential(Math.floor(logTick) - Math.floor(logDelta)); + var numExponential = Math.floor(logTick) - Math.floor(logDelta); + numExponential = Math.max(Math.min(numExponential, 20), 0); + tickString = tickValue.toExponential(numExponential); } else { var numDecimal = -1 * Math.floor(logDelta); numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places