From 4d4a3956970f1f56fd2729cbea2697974113f500 Mon Sep 17 00:00:00 2001 From: Matthew Crumley Date: Tue, 13 Oct 2020 20:59:59 -0400 Subject: [PATCH] Fix Maximum call stack size exception in computeLabelSizes (#7881) Calling Math.max with a large number of values was throwing an exception. Tracking the current largest width and height as the widths and heights are built up should be faster and avoids the exception. --- src/core/core.scale.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 0c1413d4a03..cc45a0be645 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -130,6 +130,8 @@ function computeLabelSizes(ctx, tickFonts, ticks, caches) { var widths = []; var heights = []; var offsets = []; + var widestLabelSize = 0; + var highestLabelSize = 0; var i, j, jlen, label, tickFont, fontString, cache, lineHeight, width, height, nestedLabel, widest, highest; for (i = 0; i < length; ++i) { @@ -157,11 +159,13 @@ function computeLabelSizes(ctx, tickFonts, ticks, caches) { widths.push(width); heights.push(height); offsets.push(lineHeight / 2); + widestLabelSize = Math.max(width, widestLabelSize); + highestLabelSize = Math.max(height, highestLabelSize); } garbageCollect(caches, length); - widest = widths.indexOf(Math.max.apply(null, widths)); - highest = heights.indexOf(Math.max.apply(null, heights)); + widest = widths.indexOf(widestLabelSize); + highest = heights.indexOf(highestLabelSize); function valueAt(idx) { return {