Skip to content

Commit 5b4ab14

Browse files
committed
call Legend.style after drawTexts
... so that `height` and `lineHeight` are defined during Legend.style for pie traces.
1 parent 51b5c25 commit 5b4ab14

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

src/components/legend/draw.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,20 @@ module.exports = function draw(gd) {
108108
traces.enter().append('g').attr('class', 'traces');
109109
traces.exit().remove();
110110

111-
traces.call(style, gd)
112-
.style('opacity', function(d) {
113-
var trace = d[0].trace;
114-
if(Registry.traceIs(trace, 'pie')) {
115-
return hiddenSlices.indexOf(d[0].label) !== -1 ? 0.5 : 1;
116-
} else {
117-
return trace.visible === 'legendonly' ? 0.5 : 1;
118-
}
119-
})
120-
.each(function() {
121-
d3.select(this)
122-
.call(drawTexts, gd, maxLength)
123-
.call(setupTraceToggle, gd);
124-
});
111+
traces.style('opacity', function(d) {
112+
var trace = d[0].trace;
113+
if(Registry.traceIs(trace, 'pie')) {
114+
return hiddenSlices.indexOf(d[0].label) !== -1 ? 0.5 : 1;
115+
} else {
116+
return trace.visible === 'legendonly' ? 0.5 : 1;
117+
}
118+
})
119+
.each(function() {
120+
d3.select(this)
121+
.call(drawTexts, gd, maxLength)
122+
.call(setupTraceToggle, gd);
123+
})
124+
.call(style, gd);
125125

126126
Lib.syncOrAsync([Plots.previousPromises,
127127
function() {
@@ -522,8 +522,7 @@ function computeTextDimensions(g, gd) {
522522
width = mathjaxBB.width;
523523

524524
Drawing.setTranslate(mathjaxGroup, 0, (height / 4));
525-
}
526-
else {
525+
} else {
527526
var text = g.select('.legendtext');
528527
var textLines = svgTextUtils.lineCount(text);
529528
var textNode = text.node();
@@ -535,12 +534,10 @@ function computeTextDimensions(g, gd) {
535534
// to avoid getBoundingClientRect
536535
var textY = lineHeight * (0.3 + (1 - textLines) / 2);
537536
svgTextUtils.positionText(text, constants.textOffsetX, textY);
538-
legendItem.lineHeight = lineHeight;
539537
}
540538

541-
height = Math.max(height, 16) + 3;
542-
543-
legendItem.height = height;
539+
legendItem.lineHeight = lineHeight;
540+
legendItem.height = Math.max(height, 16) + 3;
544541
legendItem.width = width;
545542
}
546543

src/components/legend/style.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = function style(s, gd) {
3131
var height = d[0].height;
3232

3333
if(valign === 'middle' || !lineHeight || !height) {
34-
layers.attr('transform', null); // this here is a fun d3 trick to unset DOM attributes
34+
layers.attr('transform', null);
3535
} else {
3636
var factor = {top: 1, bottom: -1}[valign];
3737
var markerOffsetY = factor * (0.5 * (lineHeight - height + 3));

0 commit comments

Comments
 (0)