@@ -609,19 +609,17 @@ function computeLegendDimensions(gd, groups, traces) {
609609            maxItems  =  Math . max ( maxItems ,  group . length ) ; 
610610        } ) ; 
611611
612-         var  traceGroupGap  =  opts . tracegroupgap  ||  5 ; 
613- 
614-         maxHeight  +=  traceGroupGap ; 
612+         maxHeight  +=  opts . tracegroupgap  ||  5 ; 
615613
616614        var  groupXOffsets  =  [ opts . _width ] ; 
617615        var  rowHeights  =  [ ] ; 
618616        var  rowNum  =  1 ; 
619617        for ( var  i  =  0 ,  n  =  groupData . length ;  i  <  n ;  i ++ )  { 
620-             opts . _width  +=  traceGroupGap   +   maxWidth ; 
618+             opts . _width  +=  maxWidth ; 
621619
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 ; 
625623                rowNum ++ ; 
626624            } 
627625
@@ -633,7 +631,7 @@ function computeLegendDimensions(gd, groups, traces) {
633631
634632            rowHeights . push ( currRowHeight ) ; 
635633
636-             opts . _width  +=  traceGroupGap   +   maxWidth ; 
634+             opts . _width  +=  maxWidth ; 
637635
638636            groupXOffsets . push ( opts . _width ) ; 
639637        } 
@@ -659,10 +657,10 @@ function computeLegendDimensions(gd, groups, traces) {
659657            } ) ; 
660658        } ) ; 
661659
662-         opts . _height  +=  rowNum  *  maxHeight ; 
660+         opts . _height  +=  ( borderwidth   *   2 )   +   ( rowNum  *  maxHeight ) ; 
663661
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 ; 
666664        opts . _width  +=  borderwidth  *  2 ; 
667665    } 
668666    else  { 
0 commit comments