@@ -609,19 +609,17 @@ function computeLegendDimensions(gd, groups, traces) {
609
609
maxItems = Math . max ( maxItems , group . length ) ;
610
610
} ) ;
611
611
612
- var traceGroupGap = opts . tracegroupgap || 5 ;
613
-
614
- maxHeight += traceGroupGap ;
612
+ maxHeight += opts . tracegroupgap || 5 ;
615
613
616
614
var groupXOffsets = [ opts . _width ] ;
617
615
var rowHeights = [ ] ;
618
616
var rowNum = 1 ;
619
617
for ( var i = 0 , n = groupData . length ; i < n ; i ++ ) {
620
- opts . _width += traceGroupGap + maxWidth ;
618
+ opts . _width += maxWidth ;
621
619
622
- if ( fullLayout . _size . w < ( borderwidth + opts . _width ) ) {
623
- groupXOffsets [ groupXOffsets . length - 1 ] = 0 ;
624
- opts . _width = maxWidth + traceGroupGap ;
620
+ if ( fullLayout . _size . w < ( borderwidth + opts . _width + maxWidth ) ) {
621
+ groupXOffsets [ groupXOffsets . length - 1 ] = groupXOffsets [ 0 ] ;
622
+ opts . _width = maxWidth ;
625
623
rowNum ++ ;
626
624
}
627
625
@@ -633,7 +631,7 @@ function computeLegendDimensions(gd, groups, traces) {
633
631
634
632
rowHeights . push ( currRowHeight ) ;
635
633
636
- opts . _width += traceGroupGap + maxWidth ;
634
+ opts . _width += maxWidth ;
637
635
638
636
groupXOffsets . push ( opts . _width ) ;
639
637
}
@@ -659,10 +657,10 @@ function computeLegendDimensions(gd, groups, traces) {
659
657
} ) ;
660
658
} ) ;
661
659
662
- opts . _height += rowNum * maxHeight ;
660
+ opts . _height += ( borderwidth * 2 ) + ( rowNum * maxHeight ) ;
663
661
664
- var totalRows = Math . ceil ( groupData . length / rowNum ) ;
665
- opts . _width = ( totalRows * ( 40 + maxWidth + traceGroupGap ) ) + 40 ;
662
+ var maxOffset = Math . max . apply ( null , groupXOffsets ) ;
663
+ opts . _width = maxOffset + maxWidth + 40 ;
666
664
opts . _width += borderwidth * 2 ;
667
665
}
668
666
else {
0 commit comments