Skip to content

Commit 42ed589

Browse files
authored
Fix Maximum call stack size exception in computeLabelSizes (#7883)
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.
1 parent 063b7dc commit 42ed589

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/core/core.scale.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ function computeLabelSizes(ctx, tickFonts, ticks, caches) {
130130
var widths = [];
131131
var heights = [];
132132
var offsets = [];
133+
var widestLabelSize = 0;
134+
var highestLabelSize = 0;
133135
var i, j, jlen, label, tickFont, fontString, cache, lineHeight, width, height, nestedLabel, widest, highest;
134136

135137
for (i = 0; i < length; ++i) {
@@ -157,11 +159,13 @@ function computeLabelSizes(ctx, tickFonts, ticks, caches) {
157159
widths.push(width);
158160
heights.push(height);
159161
offsets.push(lineHeight / 2);
162+
widestLabelSize = Math.max(width, widestLabelSize);
163+
highestLabelSize = Math.max(height, highestLabelSize);
160164
}
161165
garbageCollect(caches, length);
162166

163-
widest = widths.indexOf(Math.max.apply(null, widths));
164-
highest = heights.indexOf(Math.max.apply(null, heights));
167+
widest = widths.indexOf(widestLabelSize);
168+
highest = heights.indexOf(highestLabelSize);
165169

166170
function valueAt(idx) {
167171
return {

0 commit comments

Comments
 (0)