@@ -413,15 +413,15 @@ function drawTexts(g, gd) {
413413 var groupbyIndices = Registry . getTransformIndices ( fullInput , 'groupby' ) ;
414414 var index = groupbyIndices [ groupbyIndices . length - 1 ] ;
415415
416- var carr = Lib . keyedContainer ( fullInput , 'transforms[' + index + '].styles' , 'target' , 'value.name' ) ;
416+ var kcont = Lib . keyedContainer ( fullInput , 'transforms[' + index + '].styles' , 'target' , 'value.name' ) ;
417417
418418 if ( origText === '' ) {
419- carr . remove ( legendItem . trace . _group ) ;
419+ kcont . remove ( legendItem . trace . _group ) ;
420420 } else {
421- carr . set ( legendItem . trace . _group , text ) ;
421+ kcont . set ( legendItem . trace . _group , text ) ;
422422 }
423423
424- update = carr . constructUpdate ( ) ;
424+ update = kcont . constructUpdate ( ) ;
425425 } else {
426426 update . name = text ;
427427 }
@@ -490,7 +490,7 @@ function handleClick(g, gd, numClicks) {
490490 var fullTrace = legendItem . trace ;
491491 var legendgroup = fullTrace . legendgroup ;
492492
493- var i , j , carr , key , keys , val ;
493+ var i , j , kcont , key , keys , val ;
494494 var attrUpdate = { } ;
495495 var attrIndices = [ ] ;
496496 var carrs = [ ] ;
@@ -516,20 +516,28 @@ function handleClick(g, gd, numClicks) {
516516 function setVisibility ( fullTrace , visibility ) {
517517 var fullInput = fullTrace . _fullInput ;
518518 if ( Registry . hasTransform ( fullInput , 'groupby' ) ) {
519- var carr = carrs [ fullInput . index ] ;
520- if ( ! carr ) {
519+ var kcont = carrs [ fullInput . index ] ;
520+ if ( ! kcont ) {
521521 var groupbyIndices = Registry . getTransformIndices ( fullInput , 'groupby' ) ;
522522 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 ;
525525 }
526526
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+ }
529537
530538 if ( curState !== false ) {
531539 // true -> legendonly. All others toggle to true:
532- carr . set ( fullTrace . _group , visibility ) ;
540+ kcont . set ( fullTrace . _group , visibility ) ;
533541 }
534542 carrIdx [ fullInput . index ] = insertUpdate ( fullInput . index , 'visible' , fullInput . visible === false ? false : true ) ;
535543 } else {
@@ -593,15 +601,14 @@ function handleClick(g, gd, numClicks) {
593601 case false :
594602 nextVisibility = false ;
595603 break ;
596- default :
597604 case 'legendonly' :
598605 nextVisibility = true ;
599606 break ;
600607 }
601608
602609 if ( hasLegendgroup ) {
603610 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 ) {
605612 setVisibility ( fullData [ i ] , nextVisibility ) ;
606613 }
607614 }
@@ -652,9 +659,9 @@ function handleClick(g, gd, numClicks) {
652659 }
653660
654661 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 ( ) ;
658665
659666 var updateKeys = Object . keys ( update ) ;
660667 for ( j = 0 ; j < updateKeys . length ; j ++ ) {
0 commit comments