]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
clamps argument of toExponential between 0 and 20 (#6423)
authorAngus Comrie <accomrie@gmail.com>
Sat, 3 Aug 2019 01:23:15 +0000 (03:23 +0200)
committerEvert Timberg <evert.timberg+github@gmail.com>
Sat, 3 Aug 2019 01:23:15 +0000 (21:23 -0400)
src/core/core.ticks.js

index c9e75181fb2d48d4782b9d51e8d84e93cca289c7..d9049fd2f90c6aae9aecf1b8a0b001a9192b6ebe 100644 (file)
@@ -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