@@ -429,7 +429,6 @@ function setupTraceToggle(g, gd) {
429429
430430function computeTextDimensions ( g , gd ) {
431431 var legendItem = g . data ( ) [ 0 ] [ 0 ] ,
432- bg = g . selectAll ( '.legendtoggle' ) ,
433432 mathjaxGroup = g . select ( 'g[class*=math-group]' ) ,
434433 opts = gd . _fullLayout . legend ,
435434 lineHeight = opts . font . size * 1.3 ,
@@ -466,8 +465,6 @@ function computeTextDimensions(g, gd) {
466465
467466 height = Math . max ( height , 16 ) + 3 ;
468467
469- bg . attr ( { x : 0 , y : - height / 2 , height : height } ) ;
470-
471468 legendItem . height = height ;
472469 legendItem . width = width ;
473470}
@@ -508,12 +505,21 @@ function computeLegendDimensions(gd, groups, traces) {
508505 opts . height += ( opts . _lgroupsLength - 1 ) * opts . tracegroupgap ;
509506 }
510507
511- traces . selectAll ( '.legendtoggle' )
512- . attr ( 'width' , ( gd . _context . editable ? 0 : opts . width ) + 40 ) ;
513-
514508 // make sure we're only getting full pixels
515509 opts . width = Math . ceil ( opts . width ) ;
516510 opts . height = Math . ceil ( opts . height ) ;
511+
512+ traces . each ( function ( d ) {
513+ var legendItem = d [ 0 ] ,
514+ bg = d3 . select ( this ) . select ( '.legendtoggle' ) ;
515+
516+ bg . call ( Drawing . setRect ,
517+ 0 ,
518+ - legendItem . height / 2 ,
519+ ( gd . _context . editable ? 0 : opts . width ) + 40 ,
520+ legendItem . height
521+ ) ;
522+ } ) ;
517523 }
518524 else if ( isGrouped ) {
519525 opts . width = 0 ;
@@ -564,8 +570,17 @@ function computeLegendDimensions(gd, groups, traces) {
564570 opts . width = Math . ceil ( opts . width ) ;
565571 opts . height = Math . ceil ( opts . height ) ;
566572
567- traces . selectAll ( '.legendtoggle' )
568- . attr ( 'width' , ( gd . _context . editable ? 0 : opts . width ) ) ;
573+ traces . each ( function ( d ) {
574+ var legendItem = d [ 0 ] ,
575+ bg = d3 . select ( this ) . select ( '.legendtoggle' ) ;
576+
577+ bg . call ( Drawing . setRect ,
578+ 0 ,
579+ - legendItem . height / 2 ,
580+ ( gd . _context . editable ? 0 : opts . width ) ,
581+ legendItem . height
582+ ) ;
583+ } ) ;
569584 }
570585 else {
571586 opts . width = 0 ;
@@ -581,7 +596,6 @@ function computeLegendDimensions(gd, groups, traces) {
581596 } ) ;
582597
583598 traces . each ( function ( d ) {
584-
585599 var legendItem = d [ 0 ] ,
586600 traceWidth = maxTraceWidth ,
587601 traceGap = opts . tracegroupgap || 5 ;
@@ -613,8 +627,17 @@ function computeLegendDimensions(gd, groups, traces) {
613627 opts . width = Math . ceil ( opts . width ) ;
614628 opts . height = Math . ceil ( opts . height ) ;
615629
616- traces . selectAll ( '.legendtoggle' )
617- . attr ( 'width' , ( gd . _context . editable ? 0 : opts . width ) ) ;
630+ traces . each ( function ( d ) {
631+ var legendItem = d [ 0 ] ,
632+ bg = d3 . select ( this ) . select ( '.legendtoggle' ) ;
633+
634+ bg . call ( Drawing . setRect ,
635+ 0 ,
636+ - legendItem . height / 2 ,
637+ ( gd . _context . editable ? 0 : opts . width ) ,
638+ legendItem . height
639+ ) ;
640+ } ) ;
618641 }
619642}
620643
0 commit comments