@@ -38,11 +38,28 @@ module.exports = function handleClick(g, gd, numClicks) {
38
38
var legendItem = g . data ( ) [ 0 ] [ 0 ] ;
39
39
if ( legendItem . groupTitle && legendItem . noClick ) return ;
40
40
41
+ var i , j ;
41
42
var fullData = gd . _fullData ;
43
+ var allLegendItems = fullData . slice ( ) ;
44
+ if ( fullLayout . shapes ) {
45
+ for ( i = 0 ; i < fullLayout . shapes . length ; i ++ ) {
46
+ var shapeLegend = fullLayout . shapes [ i ] ; // TODO: make a copy instead!
47
+ if ( shapeLegend . visible ) {
48
+ shapeLegend . index = i ;
49
+ shapeLegend . _fullInput = shapeLegend ;
50
+ allLegendItems . push ( shapeLegend ) ;
51
+ }
52
+ }
53
+ }
54
+
42
55
var fullTrace = legendItem . trace ;
56
+ if ( fullTrace . _isShape ) {
57
+ fullTrace = fullTrace . _fullInput ;
58
+ }
59
+
43
60
var legendgroup = fullTrace . legendgroup ;
44
61
45
- var i , j , kcont , key , keys , val ;
62
+ var kcont , key , keys , val ;
46
63
var dataUpdate = { } ;
47
64
var dataIndices = [ ] ;
48
65
var carrs = [ ] ;
@@ -81,7 +98,6 @@ module.exports = function handleClick(g, gd, numClicks) {
81
98
82
99
var fullInput = fullTrace . _fullInput ;
83
100
var isShape = fullInput . _isShape ;
84
- if ( isShape ) fullInput = fullTrace ;
85
101
var index = fullInput . index ;
86
102
87
103
if ( Registry . hasTransform ( fullInput , 'groupby' ) ) {
@@ -171,8 +187,8 @@ module.exports = function handleClick(g, gd, numClicks) {
171
187
var traceIndicesInGroup = [ ] ;
172
188
var tracei ;
173
189
if ( hasLegendgroup ) {
174
- for ( i = 0 ; i < fullData . length ; i ++ ) {
175
- tracei = fullData [ i ] ;
190
+ for ( i = 0 ; i < allLegendItems . length ; i ++ ) {
191
+ tracei = allLegendItems [ i ] ;
176
192
if ( ! tracei . visible ) continue ;
177
193
if ( tracei . legendgroup === legendgroup ) {
178
194
traceIndicesInGroup . push ( i ) ;
@@ -197,15 +213,9 @@ module.exports = function handleClick(g, gd, numClicks) {
197
213
198
214
if ( hasLegendgroup ) {
199
215
if ( toggleGroup ) {
200
- var allLegendItems = fullData . concat ( fullLayout . shapes || [ ] ) ;
201
216
for ( i = 0 ; i < allLegendItems . length ; i ++ ) {
202
217
var item = allLegendItems [ i ] ;
203
218
if ( item . visible !== false && item . legendgroup === legendgroup ) {
204
- if ( i > fullData . length ) { // case of shapes
205
- item . index = i - fullData . length ;
206
- item . _isShape = true ;
207
- item . _fullInput = item ;
208
- }
209
219
setVisibility ( item , nextVisibility ) ;
210
220
}
211
221
}
@@ -218,40 +228,43 @@ module.exports = function handleClick(g, gd, numClicks) {
218
228
} else if ( mode === 'toggleothers' ) {
219
229
// Compute the clicked index. expandedIndex does what we want for expanded traces
220
230
// but also culls hidden traces. That means we have some work to do.
221
- var isClicked , isInGroup , notInLegend , otherState ;
231
+ var isClicked , isInGroup , notInLegend , otherState , _item ;
222
232
var isIsolated = true ;
223
- for ( i = 0 ; i < fullData . length ; i ++ ) {
224
- isClicked = fullData [ i ] === fullTrace ;
225
- notInLegend = fullData [ i ] . showlegend !== true ;
233
+ for ( i = 0 ; i < allLegendItems . length ; i ++ ) {
234
+ _item = allLegendItems [ i ] ;
235
+ isClicked = _item === fullTrace ;
236
+ notInLegend = _item . showlegend !== true ;
226
237
if ( isClicked || notInLegend ) continue ;
227
238
228
- isInGroup = ( hasLegendgroup && fullData [ i ] . legendgroup === legendgroup ) ;
239
+ isInGroup = ( hasLegendgroup && _item . legendgroup === legendgroup ) ;
229
240
230
- if ( ! isInGroup && fullData [ i ] . visible === true && ! Registry . traceIs ( fullData [ i ] , 'notLegendIsolatable' ) ) {
241
+ if ( ! isInGroup && _item . visible === true && ! Registry . traceIs ( _item , 'notLegendIsolatable' ) ) {
231
242
isIsolated = false ;
232
243
break ;
233
244
}
234
245
}
235
246
236
- for ( i = 0 ; i < fullData . length ; i ++ ) {
247
+ for ( i = 0 ; i < allLegendItems . length ; i ++ ) {
248
+ _item = allLegendItems [ i ] ;
249
+
237
250
// False is sticky; we don't change it. Also ensure we don't change states of itmes in other legend
238
- if ( fullData [ i ] . visible === false || fullData [ i ] . legend !== thisLegend ) continue ;
251
+ if ( _item . visible === false || _item . legend !== thisLegend ) continue ;
239
252
240
- if ( Registry . traceIs ( fullData [ i ] , 'notLegendIsolatable' ) ) {
253
+ if ( Registry . traceIs ( _item , 'notLegendIsolatable' ) ) {
241
254
continue ;
242
255
}
243
256
244
257
switch ( fullTrace . visible ) {
245
258
case 'legendonly' :
246
- setVisibility ( fullData [ i ] , true ) ;
259
+ setVisibility ( _item , true ) ;
247
260
break ;
248
261
case true :
249
262
otherState = isIsolated ? true : 'legendonly' ;
250
- isClicked = fullData [ i ] === fullTrace ;
263
+ isClicked = _item === fullTrace ;
251
264
// N.B. consider traces that have a set legendgroup as toggleable
252
- notInLegend = ( fullData [ i ] . showlegend !== true && ! fullData [ i ] . legendgroup ) ;
253
- isInGroup = isClicked || ( hasLegendgroup && fullData [ i ] . legendgroup === legendgroup ) ;
254
- setVisibility ( fullData [ i ] , ( isInGroup || notInLegend ) ? true : otherState ) ;
265
+ notInLegend = ( _item . showlegend !== true && ! _item . legendgroup ) ;
266
+ isInGroup = isClicked || ( hasLegendgroup && _item . legendgroup === legendgroup ) ;
267
+ setVisibility ( _item , ( isInGroup || notInLegend ) ? true : otherState ) ;
255
268
break ;
256
269
}
257
270
}
0 commit comments