From: Angus Comrie Date: Sat, 3 Aug 2019 01:23:15 +0000 (+0200) Subject: clamps argument of toExponential between 0 and 20 (#6423) X-Git-Tag: v2.9.0~1^2~31 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a46dd96ddfe44e6b71fdd8ac3635f6661e269dc8;p=thirdparty%2FChart.js.git clamps argument of toExponential between 0 and 20 (#6423) --- diff --git a/src/core/core.ticks.js b/src/core/core.ticks.js index c9e75181f..d9049fd2f 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