@@ -429,7 +429,6 @@ function setupTraceToggle(g, gd) {
429
429
430
430
function computeTextDimensions ( g , gd ) {
431
431
var legendItem = g . data ( ) [ 0 ] [ 0 ] ,
432
- bg = g . selectAll ( '.legendtoggle' ) ,
433
432
mathjaxGroup = g . select ( 'g[class*=math-group]' ) ,
434
433
opts = gd . _fullLayout . legend ,
435
434
lineHeight = opts . font . size * 1.3 ,
@@ -466,8 +465,6 @@ function computeTextDimensions(g, gd) {
466
465
467
466
height = Math . max ( height , 16 ) + 3 ;
468
467
469
- bg . attr ( { x : 0 , y : - height / 2 , height : height } ) ;
470
-
471
468
legendItem . height = height ;
472
469
legendItem . width = width ;
473
470
}
@@ -508,12 +505,21 @@ function computeLegendDimensions(gd, groups, traces) {
508
505
opts . height += ( opts . _lgroupsLength - 1 ) * opts . tracegroupgap ;
509
506
}
510
507
511
- traces . selectAll ( '.legendtoggle' )
512
- . attr ( 'width' , ( gd . _context . editable ? 0 : opts . width ) + 40 ) ;
513
-
514
508
// make sure we're only getting full pixels
515
509
opts . width = Math . ceil ( opts . width ) ;
516
510
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
+ } ) ;
517
523
}
518
524
else if ( isGrouped ) {
519
525
opts . width = 0 ;
@@ -564,8 +570,17 @@ function computeLegendDimensions(gd, groups, traces) {
564
570
opts . width = Math . ceil ( opts . width ) ;
565
571
opts . height = Math . ceil ( opts . height ) ;
566
572
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
+ } ) ;
569
584
}
570
585
else {
571
586
opts . width = 0 ;
@@ -581,7 +596,6 @@ function computeLegendDimensions(gd, groups, traces) {
581
596
} ) ;
582
597
583
598
traces . each ( function ( d ) {
584
-
585
599
var legendItem = d [ 0 ] ,
586
600
traceWidth = maxTraceWidth ,
587
601
traceGap = opts . tracegroupgap || 5 ;
@@ -613,8 +627,17 @@ function computeLegendDimensions(gd, groups, traces) {
613
627
opts . width = Math . ceil ( opts . width ) ;
614
628
opts . height = Math . ceil ( opts . height ) ;
615
629
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
+ } ) ;
618
641
}
619
642
}
620
643
0 commit comments