Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,16 @@ function computeTextDimensions(g, gd) {
textLines = textSpans[0].length || 1;

height = lineHeight * textLines;
width = text.node() && Drawing.bBox(text.node()).width;

// If there are more than 20 traces (> 20 legend items), estimate the text width
// so that the overhead of measureing text is not too big
if(gd.data.length <= 20) {
width = text.node() && Drawing.bBox(text.node()).width;
} else {
// "7" is empirical number based on some case studies in Sketch
width = legendItem.trace.name.length * 7 * opts.font.size / 11;
}


// approximation to height offset to center the font
// to avoid getBoundingClientRect
Expand Down