Skip to content

Commit 855d25c

Browse files
author
John Soklaski
committed
Fix layout calculation for multiline legend elements.
Previously if the user specified a legend element that spanned multiple lines (included <br>), Plotly would calculate the legend item's width as if it were: multi line legend instead of: multi line legend This ended up being caused by a stale bbox stored in Plotly's cache. The solution for now is to force bbox recalculation for this particular bbox in the legend component. I'm not sure if this is the long term solution though.
1 parent b11c365 commit 855d25c

File tree

6 files changed

+91649
-92596
lines changed

6 files changed

+91649
-92596
lines changed

dist/plotly-geo-assets.js

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/plotly-with-meta.js

Lines changed: 45774 additions & 46240 deletions
Large diffs are not rendered by default.

dist/plotly.js

Lines changed: 45832 additions & 46302 deletions
Large diffs are not rendered by default.

dist/plotly.min.js

Lines changed: 36 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/drawing/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,14 @@ drawing.makeTester = function(gd) {
483483
// always returns a copy of the bbox, so the caller can modify it safely
484484
var savedBBoxes = [],
485485
maxSavedBBoxes = 10000;
486-
drawing.bBox = function(node) {
486+
drawing.bBox = function(node, forceReCalc) {
487487
// cache elements we've already measured so we don't have to
488488
// remeasure the same thing many times
489-
var saveNum = node.attributes['data-bb'];
490-
if(saveNum && saveNum.value) {
491-
return Plotly.Lib.extendFlat({}, savedBBoxes[saveNum.value]);
489+
if(!forceReCalc) {
490+
var saveNum = node.attributes['data-bb'];
491+
if(saveNum && saveNum.value) {
492+
return Plotly.Lib.extendFlat({}, savedBBoxes[saveNum.value]);
493+
}
492494
}
493495

494496
var test3 = d3.select('#js-plotly-tester'),

src/components/legend/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ legend.repositionLegend = function(td, traces){
583583
tspans = g.selectAll('.legendtext>tspan'),
584584
tHeight = opts.font.size * 1.3,
585585
tLines = tspans[0].length||1,
586-
tWidth = text.node() && Plotly.Drawing.bBox(text.node()).width,
586+
tWidth = text.node() && Plotly.Drawing.bBox(text.node(), true).width,
587587
mathjaxGroup = g.select('g[class*=math-group]'),
588588
textY,
589589
tHeightFull;

0 commit comments

Comments
 (0)