Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the text measuring of legend items when rendering large amount of traces #1586

Closed
wants to merge 2 commits into from
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