Skip to content

Commit d0934f3

Browse files
committed
changes based on @n-riesco comments
1 parent 5b5a102 commit d0934f3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/components/legend/draw.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -568,32 +568,34 @@ function computeLegendDimensions(gd, groups, traces) {
568568
else {
569569
opts.width = 0;
570570
opts.height = 0;
571-
var rowHeight = 0;
572-
var maxTraceHeight = 0;
573-
var startX = 0;
571+
var rowHeight = 0,
572+
maxTraceHeight = 0,
573+
offsetX = 0;
574574

575575
traces.each(function(d) {
576576

577577
var legendItem = d[0],
578578
traceWidth = 40 + legendItem.width,
579579
traceGap = opts.tracegroupgap || 5;
580580

581-
if((borderwidth + startX + traceGap + traceWidth) > fullLayout.width - fullLayout.margin.r) {
582-
startX = 0;
581+
if((borderwidth + offsetX + traceGap + traceWidth) > fullLayout.width - fullLayout.margin.r) {
582+
offsetX = 0;
583583
rowHeight = rowHeight + maxTraceHeight;
584584
opts.height = opts.height + maxTraceHeight;
585+
//reset for next row
586+
maxTraceHeight = 0;
585587
}
586588

587589
Lib.setTranslate(this,
588-
(borderwidth + startX),
590+
(borderwidth + offsetX),
589591
(5 + borderwidth + legendItem.height / 2) + rowHeight);
590592

591593
opts.width += traceGap + traceWidth;
592594
opts.height = Math.max(opts.height, legendItem.height);
593595

594596
//keep track of tallest trace in group
595-
startX += traceGap + traceWidth;
596-
maxTraceHeight = (legendItem.height > maxTraceHeight) ? legendItem.height : maxTraceHeight;
597+
offsetX += traceGap + traceWidth;
598+
maxTraceHeight = Math.max(legendItem.height, maxTraceHeight);
597599
});
598600

599601
opts.width += borderwidth * 2;

0 commit comments

Comments
 (0)