Skip to content

Commit f68344b

Browse files
committed
Legend: compute size only after drawing texts
* This change not only improves drawing performance, but it will also allows for `drawTexts` to be moved to `styles.js`. * Checked all jasmine and image tests still pass.
1 parent 9dc2609 commit f68344b

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/components/legend/draw.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,15 @@ module.exports = function draw(gd) {
123123
}
124124
})
125125
.each(function(d) {
126-
drawTexts(gd, this, d[0], traces);
126+
drawTexts(gd, this, d[0]);
127127
setupTraceToggle(gd, this, d[0]);
128128
});
129129

130+
if(gd.firstRender) {
131+
computeLegendDimensions(gd, traces);
132+
expandMargin(gd);
133+
}
134+
130135
// Position and size the legend
131136
var lyMin = 0,
132137
lyMax = fullLayout.height;
@@ -312,7 +317,7 @@ module.exports = function draw(gd) {
312317
}
313318
};
314319

315-
function drawTexts(gd, context, legendItem, traces) {
320+
function drawTexts(gd, context, legendItem) {
316321
var fullLayout = gd._fullLayout,
317322
trace = legendItem.trace,
318323
isPie = Plots.traceIs(trace, 'pie'),
@@ -335,11 +340,7 @@ function drawTexts(gd, context, legendItem, traces) {
335340
function textLayout(s) {
336341
Plotly.util.convertToTspans(s, function() {
337342
s.selectAll('tspan.line').attr({x: s.attr('x')});
338-
339-
if(gd.firstRender) {
340-
computeLegendDimensions(gd, traces);
341-
expandMargin(gd);
342-
}
343+
computeTextDimensions(gd, context, legendItem);
343344
});
344345
}
345346

@@ -461,11 +462,8 @@ function computeLegendDimensions(gd, traces) {
461462
opts.height = 0;
462463

463464
traces.each(function(d) {
464-
var legendItem = d[0];
465-
466-
computeTextDimensions(gd, this, legendItem);
467-
468-
var textHeight = legendItem.height,
465+
var legendItem = d[0],
466+
textHeight = legendItem.height,
469467
textWidth = legendItem.width;
470468

471469
d3.select(this).attr('transform',

0 commit comments

Comments
 (0)