Skip to content

Commit

Permalink
Fix Maximum call stack size exception in computeLabelSizes (#7883)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
silentmatt committed Oct 17, 2020
1 parent 063b7dc commit 42ed589
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/core.scale.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 42ed589

Please sign in to comment.