Skip to content

Commit bb60510

Browse files
committed
Might fix #769 - added check for pushing past plot margin and starting new row of legend items
1 parent a3aebfe commit bb60510

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/components/legend/draw.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -568,18 +568,33 @@ 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;
571574

572575
traces.each(function(d) {
576+
573577
var legendItem = d[0],
574578
traceWidth = 40 + legendItem.width,
575579
traceGap = opts.tracegroupgap || 5;
576580

577-
Lib.setTranslate(this,
578-
(borderwidth + opts.width),
579-
(5 + borderwidth + legendItem.height / 2));
581+
if((borderwidth + startX + traceGap + traceWidth) > fullLayout.width - fullLayout.margin.r) {
582+
startX = 0;
583+
rowHeight = rowHeight + maxTraceHeight;
584+
opts.height = opts.height + maxTraceHeight;
585+
}
580586

581587
opts.width += traceGap + traceWidth;
582588
opts.height = Math.max(opts.height, legendItem.height);
589+
590+
Lib.setTranslate(this,
591+
(borderwidth + startX),
592+
(5 + borderwidth + legendItem.height / 2) + rowHeight);
593+
594+
595+
//keep track of tallest trace in group
596+
startX += traceGap + traceWidth;
597+
maxTraceHeight = (legendItem.height > maxTraceHeight) ? legendItem.height : maxTraceHeight;
583598
});
584599

585600
opts.width += borderwidth * 2;

0 commit comments

Comments
 (0)