@@ -48,11 +48,11 @@ module.exports = function handleClick(g, gd, numClicks) {
4848 var carrs = [ ] ;
4949 var carrIdx = [ ] ;
5050
51- function insertUpdate ( traceIndex , key , value ) {
51+ function insertDataUpdate ( traceIndex , value ) {
5252 var attrIndex = dataIndices . indexOf ( traceIndex ) ;
53- var valueArray = dataUpdate [ key ] ;
53+ var valueArray = dataUpdate . visible ;
5454 if ( ! valueArray ) {
55- valueArray = dataUpdate [ key ] = [ ] ;
55+ valueArray = dataUpdate . visible = [ ] ;
5656 }
5757
5858 if ( dataIndices . indexOf ( traceIndex ) === - 1 ) {
@@ -65,6 +65,17 @@ module.exports = function handleClick(g, gd, numClicks) {
6565 return attrIndex ;
6666 }
6767
68+ var updatedShapes = ( fullLayout . shapes || [ ] ) . map ( function ( d ) {
69+ return d . _input ;
70+ } ) ;
71+
72+ var shapesUpdated = false ;
73+
74+ function insertShapesUpdate ( shapeIndex , value ) {
75+ updatedShapes [ shapeIndex ] . visible = value ;
76+ shapesUpdated = true ;
77+ }
78+
6879 function setVisibility ( fullTrace , visibility ) {
6980 if ( legendItem . groupTitle && ! toggleGroup ) return ;
7081
@@ -97,17 +108,17 @@ module.exports = function handleClick(g, gd, numClicks) {
97108 // true -> legendonly. All others toggle to true:
98109 kcont . set ( fullTrace . _group , visibility ) ;
99110 }
100- carrIdx [ index ] = insertUpdate ( index , 'visible' , fullInput . visible === false ? false : true ) ;
111+ carrIdx [ index ] = insertDataUpdate ( index , fullInput . visible === false ? false : true ) ;
101112 } else {
102113 // false -> false (not possible since will not be visible in legend)
103114 // true -> legendonly
104115 // legendonly -> true
105116 var nextVisibility = fullInput . visible === false ? false : visibility ;
106117
107118 if ( isShape ) {
108- Registry . call ( '_guiRelayout' , gd , 'shapes[' + index + '].visible' , nextVisibility ) ;
119+ insertShapesUpdate ( index , nextVisibility ) ;
109120 } else {
110- insertUpdate ( index , 'visible' , nextVisibility ) ;
121+ insertDataUpdate ( index , nextVisibility ) ;
111122 }
112123 }
113124 }
@@ -183,9 +194,16 @@ module.exports = function handleClick(g, gd, numClicks) {
183194
184195 if ( hasLegendgroup ) {
185196 if ( toggleGroup ) {
186- for ( i = 0 ; i < fullData . length ; i ++ ) {
187- if ( fullData [ i ] . visible !== false && fullData [ i ] . legendgroup === legendgroup ) {
188- setVisibility ( fullData [ i ] , nextVisibility ) ;
197+ var allLegendItems = fullData . concat ( fullLayout . shapes || [ ] ) ;
198+ for ( i = 0 ; i < allLegendItems . length ; i ++ ) {
199+ var item = allLegendItems [ i ] ;
200+ if ( item . visible !== false && item . legendgroup === legendgroup ) {
201+ if ( i > fullData . length ) { // case of shapes
202+ item . index = i - fullData . length ;
203+ item . _isShape = true ;
204+ item . _fullInput = item ;
205+ }
206+ setVisibility ( item , nextVisibility ) ;
189207 }
190208 }
191209 } else {
@@ -264,6 +282,10 @@ module.exports = function handleClick(g, gd, numClicks) {
264282 }
265283 }
266284
267- Registry . call ( '_guiRestyle' , gd , dataUpdate , dataIndices ) ;
285+ Registry . call ( '_guiRestyle' , gd , dataUpdate , dataIndices ) . then ( function ( ) {
286+ if ( shapesUpdated ) {
287+ Registry . call ( '_guiRelayout' , gd , { shapes : updatedShapes } ) ;
288+ }
289+ } ) ;
268290 }
269291} ;
0 commit comments