]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix Maximum call stack size exception in _computeLabelSizes (#7906)
authorMatthew Crumley <email@matthewcrumley.com>
Sun, 18 Oct 2020 03:52:56 +0000 (23:52 -0400)
committerGitHub <noreply@github.com>
Sun, 18 Oct 2020 03:52:56 +0000 (06:52 +0300)
Issue #7881

src/core/core.scale.js

index 82433fc199051fa162fa05c10e1d34a0fa3420ee..06c50395c6b674c687c565fe38c67524ce3eb597 100644 (file)
@@ -894,6 +894,8 @@ export default class Scale extends Element {
                const widths = [];
                const heights = [];
                const offsets = [];
+               let widestLabelSize = 0;
+               let highestLabelSize = 0;
                let ticks = me.ticks;
                if (sampleSize < ticks.length) {
                        ticks = sample(ticks, sampleSize);
@@ -926,11 +928,13 @@ export default class Scale extends Element {
                        widths.push(width);
                        heights.push(height);
                        offsets.push(lineHeight / 2);
+                       widestLabelSize = Math.max(width, widestLabelSize);
+                       highestLabelSize = Math.max(height, highestLabelSize);
                }
                garbageCollect(caches, length);
 
-               const widest = widths.indexOf(Math.max.apply(null, widths));
-               const highest = heights.indexOf(Math.max.apply(null, heights));
+               const widest = widths.indexOf(widestLabelSize);
+               const highest = heights.indexOf(highestLabelSize);
 
                function valueAt(idx) {
                        return {