@@ -413,15 +413,15 @@ function drawTexts(g, gd) {
413
413
var groupbyIndices = Registry . getTransformIndices ( fullInput , 'groupby' ) ;
414
414
var index = groupbyIndices [ groupbyIndices . length - 1 ] ;
415
415
416
- var carr = Lib . keyedContainer ( fullInput , 'transforms[' + index + '].styles' , 'target' , 'value.name' ) ;
416
+ var kcont = Lib . keyedContainer ( fullInput , 'transforms[' + index + '].styles' , 'target' , 'value.name' ) ;
417
417
418
418
if ( origText === '' ) {
419
- carr . remove ( legendItem . trace . _group ) ;
419
+ kcont . remove ( legendItem . trace . _group ) ;
420
420
} else {
421
- carr . set ( legendItem . trace . _group , text ) ;
421
+ kcont . set ( legendItem . trace . _group , text ) ;
422
422
}
423
423
424
- update = carr . constructUpdate ( ) ;
424
+ update = kcont . constructUpdate ( ) ;
425
425
} else {
426
426
update . name = text ;
427
427
}
@@ -490,7 +490,7 @@ function handleClick(g, gd, numClicks) {
490
490
var fullTrace = legendItem . trace ;
491
491
var legendgroup = fullTrace . legendgroup ;
492
492
493
- var i , j , carr , key , keys , val ;
493
+ var i , j , kcont , key , keys , val ;
494
494
var attrUpdate = { } ;
495
495
var attrIndices = [ ] ;
496
496
var carrs = [ ] ;
@@ -516,20 +516,28 @@ function handleClick(g, gd, numClicks) {
516
516
function setVisibility ( fullTrace , visibility ) {
517
517
var fullInput = fullTrace . _fullInput ;
518
518
if ( Registry . hasTransform ( fullInput , 'groupby' ) ) {
519
- var carr = carrs [ fullInput . index ] ;
520
- if ( ! carr ) {
519
+ var kcont = carrs [ fullInput . index ] ;
520
+ if ( ! kcont ) {
521
521
var groupbyIndices = Registry . getTransformIndices ( fullInput , 'groupby' ) ;
522
522
var lastGroupbyIndex = groupbyIndices [ groupbyIndices . length - 1 ] ;
523
- carr = Lib . keyedContainer ( fullInput , 'transforms[' + lastGroupbyIndex + '].styles' , 'target' , 'value.visible' ) ;
524
- carrs [ fullInput . index ] = carr ;
523
+ kcont = Lib . keyedContainer ( fullInput , 'transforms[' + lastGroupbyIndex + '].styles' , 'target' , 'value.visible' ) ;
524
+ carrs [ fullInput . index ] = kcont ;
525
525
}
526
526
527
- // If not specified, assume visible:
528
- var curState = carr . get ( fullTrace . _group ) || true ;
527
+ var curState = kcont . get ( fullTrace . _group ) ;
528
+
529
+ // If not specified, assume visible. This happens if there are other style
530
+ // properties set for a group but not the visibility. There are many similar
531
+ // ways to do this (e.g. why not just `curState = fullTrace.visible`??? The
532
+ // answer is: because it breaks other things like groupby trace names in
533
+ // subtle ways.)
534
+ if ( curState === undefined ) {
535
+ curState = true ;
536
+ }
529
537
530
538
if ( curState !== false ) {
531
539
// true -> legendonly. All others toggle to true:
532
- carr . set ( fullTrace . _group , visibility ) ;
540
+ kcont . set ( fullTrace . _group , visibility ) ;
533
541
}
534
542
carrIdx [ fullInput . index ] = insertUpdate ( fullInput . index , 'visible' , fullInput . visible === false ? false : true ) ;
535
543
} else {
@@ -593,15 +601,14 @@ function handleClick(g, gd, numClicks) {
593
601
case false :
594
602
nextVisibility = false ;
595
603
break ;
596
- default :
597
604
case 'legendonly' :
598
605
nextVisibility = true ;
599
606
break ;
600
607
}
601
608
602
609
if ( hasLegendgroup ) {
603
610
for ( i = 0 ; i < fullData . length ; i ++ ) {
604
- if ( fullData [ i ] . visible && fullData [ i ] . legendgroup === legendgroup ) {
611
+ if ( fullData [ i ] . visible !== false && fullData [ i ] . legendgroup === legendgroup ) {
605
612
setVisibility ( fullData [ i ] , nextVisibility ) ;
606
613
}
607
614
}
@@ -652,9 +659,9 @@ function handleClick(g, gd, numClicks) {
652
659
}
653
660
654
661
for ( i = 0 ; i < carrs . length ; i ++ ) {
655
- carr = carrs [ i ] ;
656
- if ( ! carr ) continue ;
657
- var update = carr . constructUpdate ( ) ;
662
+ kcont = carrs [ i ] ;
663
+ if ( ! kcont ) continue ;
664
+ var update = kcont . constructUpdate ( ) ;
658
665
659
666
var updateKeys = Object . keys ( update ) ;
660
667
for ( j = 0 ; j < updateKeys . length ; j ++ ) {
0 commit comments