@@ -630,7 +630,6 @@ function computeLegendDimensions(gd, groups, traces) {
630630 var offsetX = 0 ;
631631 var fullTracesWidth = 0 ;
632632 var traceGap = opts . tracegroupgap || 5 ;
633- var oneRowLegend ;
634633
635634 // calculate largest width for traces and use for width of all legend items
636635 traces . each ( function ( d ) {
@@ -639,15 +638,16 @@ function computeLegendDimensions(gd, groups, traces) {
639638 } ) ;
640639
641640 // 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+
643643 traces . each ( function ( d ) {
644644 var legendItem = d [ 0 ] ;
645645 var traceWidth = oneRowLegend ? 40 + d [ 0 ] . width : maxTraceWidth ;
646646
647647 if ( ( borderwidth + offsetX + traceGap + traceWidth ) > fullLayout . _size . w ) {
648648 offsetX = 0 ;
649- rowHeight = rowHeight + maxTraceHeight ;
650- opts . _height = opts . _height + maxTraceHeight ;
649+ rowHeight += maxTraceHeight ;
650+ opts . _height += maxTraceHeight ;
651651 // reset for next row
652652 maxTraceHeight = 0 ;
653653 }
@@ -657,16 +657,20 @@ function computeLegendDimensions(gd, groups, traces) {
657657 ( 5 + borderwidth + legendItem . height / 2 ) + rowHeight ) ;
658658
659659 opts . _width += traceGap + traceWidth ;
660- opts . _height = Math . max ( opts . _height , legendItem . height ) ;
661660
662661 // keep track of tallest trace in group
663662 offsetX += traceGap + traceWidth ;
664663 maxTraceHeight = Math . max ( legendItem . height , maxTraceHeight ) ;
665664 } ) ;
666665
666+ if ( oneRowLegend ) {
667+ opts . _height = maxTraceHeight ;
668+ } else {
669+ opts . _height += maxTraceHeight ;
670+ }
671+
667672 opts . _width += borderwidth * 2 ;
668673 opts . _height += 10 + borderwidth * 2 ;
669-
670674 }
671675
672676 // make sure we're only getting full pixels
0 commit comments