@@ -630,7 +630,6 @@ function computeLegendDimensions(gd, groups, traces) {
630
630
var offsetX = 0 ;
631
631
var fullTracesWidth = 0 ;
632
632
var traceGap = opts . tracegroupgap || 5 ;
633
- var oneRowLegend ;
634
633
635
634
// calculate largest width for traces and use for width of all legend items
636
635
traces . each ( function ( d ) {
@@ -639,15 +638,16 @@ function computeLegendDimensions(gd, groups, traces) {
639
638
} ) ;
640
639
641
640
// check if legend fits in one row
642
- oneRowLegend = fullLayout . _size . w > borderwidth + fullTracesWidth - traceGap ;
641
+ var oneRowLegend = fullLayout . _size . w > borderwidth + fullTracesWidth - traceGap ;
642
+
643
643
traces . each ( function ( d ) {
644
644
var legendItem = d [ 0 ] ;
645
645
var traceWidth = oneRowLegend ? 40 + d [ 0 ] . width : maxTraceWidth ;
646
646
647
647
if ( ( borderwidth + offsetX + traceGap + traceWidth ) > fullLayout . _size . w ) {
648
648
offsetX = 0 ;
649
- rowHeight = rowHeight + maxTraceHeight ;
650
- opts . _height = opts . _height + maxTraceHeight ;
649
+ rowHeight += maxTraceHeight ;
650
+ opts . _height += maxTraceHeight ;
651
651
// reset for next row
652
652
maxTraceHeight = 0 ;
653
653
}
@@ -657,16 +657,20 @@ function computeLegendDimensions(gd, groups, traces) {
657
657
( 5 + borderwidth + legendItem . height / 2 ) + rowHeight ) ;
658
658
659
659
opts . _width += traceGap + traceWidth ;
660
- opts . _height = Math . max ( opts . _height , legendItem . height ) ;
661
660
662
661
// keep track of tallest trace in group
663
662
offsetX += traceGap + traceWidth ;
664
663
maxTraceHeight = Math . max ( legendItem . height , maxTraceHeight ) ;
665
664
} ) ;
666
665
666
+ if ( oneRowLegend ) {
667
+ opts . _height = maxTraceHeight ;
668
+ } else {
669
+ opts . _height += maxTraceHeight ;
670
+ }
671
+
667
672
opts . _width += borderwidth * 2 ;
668
673
opts . _height += 10 + borderwidth * 2 ;
669
-
670
674
}
671
675
672
676
// make sure we're only getting full pixels
0 commit comments