@@ -20,15 +20,15 @@ var SHOWISOLATETIP = true;
2020exports . handleItemClick = function handleItemClick ( g , gd , legendObj , mode ) {
2121 var fullLayout = gd . _fullLayout ;
2222
23- if ( gd . _dragged || gd . _editing ) return ;
23+ if ( gd . _dragged || gd . _editing ) return ;
2424
2525 var legendItem = g . data ( ) [ 0 ] [ 0 ] ;
26- if ( legendItem . groupTitle && legendItem . noClick ) return ;
26+ if ( legendItem . groupTitle && legendItem . noClick ) return ;
2727
2828 var groupClick = legendObj . groupclick ;
2929
3030 // Show isolate tip on first single click when default behavior is active
31- if ( mode === 'toggle' && legendObj . itemdoubleclick === 'toggleothers' &&
31+ if ( mode === 'toggle' && legendObj . itemdoubleclick === 'toggleothers' &&
3232 SHOWISOLATETIP && gd . data && gd . _context . showTips
3333 ) {
3434 Lib . notifier ( Lib . _ ( gd , 'Double-click on legend to isolate one trace' ) , 'long' , gd ) ;
@@ -42,11 +42,11 @@ exports.handleItemClick = function handleItemClick(g, gd, legendObj, mode) {
4242 [ ] ;
4343
4444 var fullData = gd . _fullData ;
45- var shapesWithLegend = ( fullLayout . shapes || [ ] ) . filter ( function ( d ) { return d . showlegend ; } ) ;
45+ var shapesWithLegend = ( fullLayout . shapes || [ ] ) . filter ( function ( d ) { return d . showlegend ; } ) ;
4646 var allLegendItems = fullData . concat ( shapesWithLegend ) ;
4747
4848 var fullTrace = legendItem . trace ;
49- if ( fullTrace . _isShape ) {
49+ if ( fullTrace . _isShape ) {
5050 fullTrace = fullTrace . _fullInput ;
5151 }
5252
@@ -61,11 +61,11 @@ exports.handleItemClick = function handleItemClick(g, gd, legendObj, mode) {
6161 function insertDataUpdate ( traceIndex , value ) {
6262 var attrIndex = dataIndices . indexOf ( traceIndex ) ;
6363 var valueArray = dataUpdate . visible ;
64- if ( ! valueArray ) {
64+ if ( ! valueArray ) {
6565 valueArray = dataUpdate . visible = [ ] ;
6666 }
6767
68- if ( dataIndices . indexOf ( traceIndex ) === - 1 ) {
68+ if ( dataIndices . indexOf ( traceIndex ) === - 1 ) {
6969 dataIndices . push ( traceIndex ) ;
7070 attrIndex = dataIndices . length - 1 ;
7171 }
@@ -75,7 +75,7 @@ exports.handleItemClick = function handleItemClick(g, gd, legendObj, mode) {
7575 return attrIndex ;
7676 }
7777
78- var updatedShapes = ( fullLayout . shapes || [ ] ) . map ( function ( d ) {
78+ var updatedShapes = ( fullLayout . shapes || [ ] ) . map ( function ( d ) {
7979 return d . _input ;
8080 } ) ;
8181
@@ -87,19 +87,19 @@ exports.handleItemClick = function handleItemClick(g, gd, legendObj, mode) {
8787 }
8888
8989 function setVisibility ( fullTrace , visibility ) {
90- if ( legendItem . groupTitle && ! toggleGroup ) return ;
90+ if ( legendItem . groupTitle && ! toggleGroup ) return ;
9191
9292 var fullInput = fullTrace . _fullInput || fullTrace ;
9393 var isShape = fullInput . _isShape ;
9494 var index = fullInput . index ;
95- if ( index === undefined ) index = fullInput . _index ;
95+ if ( index === undefined ) index = fullInput . _index ;
9696
9797 // false -> false (not possible since will not be visible in legend)
9898 // true -> legendonly
9999 // legendonly -> true
100100 var nextVisibility = fullInput . visible === false ? false : visibility ;
101101
102- if ( isShape ) {
102+ if ( isShape ) {
103103 insertShapesUpdate ( index , nextVisibility ) ;
104104 } else {
105105 insertDataUpdate ( index , nextVisibility ) ;
@@ -111,37 +111,37 @@ exports.handleItemClick = function handleItemClick(g, gd, legendObj, mode) {
111111 var fullInput = fullTrace . _fullInput ;
112112 var isShape = fullInput && fullInput . _isShape ;
113113
114- if ( ! isShape && Registry . traceIs ( fullTrace , 'pie-like' ) ) {
114+ if ( ! isShape && Registry . traceIs ( fullTrace , 'pie-like' ) ) {
115115 var thisLabel = legendItem . label ;
116116 var thisLabelIndex = hiddenSlices . indexOf ( thisLabel ) ;
117117
118- if ( mode === 'toggle' ) {
119- if ( thisLabelIndex === - 1 ) hiddenSlices . push ( thisLabel ) ;
118+ if ( mode === 'toggle' ) {
119+ if ( thisLabelIndex === - 1 ) hiddenSlices . push ( thisLabel ) ;
120120 else hiddenSlices . splice ( thisLabelIndex , 1 ) ;
121- } else if ( mode === 'toggleothers' ) {
121+ } else if ( mode === 'toggleothers' ) {
122122 var changed = thisLabelIndex !== - 1 ;
123123 var unhideList = [ ] ;
124- for ( i = 0 ; i < gd . calcdata . length ; i ++ ) {
124+ for ( i = 0 ; i < gd . calcdata . length ; i ++ ) {
125125 var cdi = gd . calcdata [ i ] ;
126- for ( j = 0 ; j < cdi . length ; j ++ ) {
126+ for ( j = 0 ; j < cdi . length ; j ++ ) {
127127 var d = cdi [ j ] ;
128128 var dLabel = d . label ;
129129
130130 // ensure we toggle slices that are in this legend)
131- if ( thisLegend === cdi [ 0 ] . trace . legend ) {
132- if ( thisLabel !== dLabel ) {
133- if ( hiddenSlices . indexOf ( dLabel ) === - 1 ) changed = true ;
131+ if ( thisLegend === cdi [ 0 ] . trace . legend ) {
132+ if ( thisLabel !== dLabel ) {
133+ if ( hiddenSlices . indexOf ( dLabel ) === - 1 ) changed = true ;
134134 pushUnique ( hiddenSlices , dLabel ) ;
135135 unhideList . push ( dLabel ) ;
136136 }
137137 }
138138 }
139139 }
140140
141- if ( ! changed ) {
142- for ( var q = 0 ; q < unhideList . length ; q ++ ) {
141+ if ( ! changed ) {
142+ for ( var q = 0 ; q < unhideList . length ; q ++ ) {
143143 var pos = hiddenSlices . indexOf ( unhideList [ q ] ) ;
144- if ( pos !== - 1 ) {
144+ if ( pos !== - 1 ) {
145145 hiddenSlices . splice ( pos , 1 ) ;
146146 }
147147 }
@@ -153,20 +153,20 @@ exports.handleItemClick = function handleItemClick(g, gd, legendObj, mode) {
153153 var hasLegendgroup = legendgroup && legendgroup . length ;
154154 var traceIndicesInGroup = [ ] ;
155155 var tracei ;
156- if ( hasLegendgroup ) {
157- for ( i = 0 ; i < allLegendItems . length ; i ++ ) {
156+ if ( hasLegendgroup ) {
157+ for ( i = 0 ; i < allLegendItems . length ; i ++ ) {
158158 tracei = allLegendItems [ i ] ;
159- if ( ! tracei . visible ) continue ;
160- if ( tracei . legendgroup === legendgroup ) {
159+ if ( ! tracei . visible ) continue ;
160+ if ( tracei . legendgroup === legendgroup ) {
161161 traceIndicesInGroup . push ( i ) ;
162162 }
163163 }
164164 }
165165
166- if ( mode === 'toggle' ) {
166+ if ( mode === 'toggle' ) {
167167 var nextVisibility ;
168168
169- switch ( fullTrace . visible ) {
169+ switch ( fullTrace . visible ) {
170170 case true :
171171 nextVisibility = 'legendonly' ;
172172 break ;
@@ -178,11 +178,11 @@ exports.handleItemClick = function handleItemClick(g, gd, legendObj, mode) {
178178 break ;
179179 }
180180
181- if ( hasLegendgroup ) {
182- if ( toggleGroup ) {
183- for ( i = 0 ; i < allLegendItems . length ; i ++ ) {
181+ if ( hasLegendgroup ) {
182+ if ( toggleGroup ) {
183+ for ( i = 0 ; i < allLegendItems . length ; i ++ ) {
184184 var item = allLegendItems [ i ] ;
185- if ( item . visible !== false && item . legendgroup === legendgroup ) {
185+ if ( item . visible !== false && item . legendgroup === legendgroup ) {
186186 setVisibility ( item , nextVisibility ) ;
187187 }
188188 }
@@ -192,36 +192,36 @@ exports.handleItemClick = function handleItemClick(g, gd, legendObj, mode) {
192192 } else {
193193 setVisibility ( fullTrace , nextVisibility ) ;
194194 }
195- } else if ( mode === 'toggleothers' ) {
195+ } else if ( mode === 'toggleothers' ) {
196196 // Compute the clicked index. expandedIndex does what we want for expanded traces
197197 // but also culls hidden traces. That means we have some work to do.
198198 var isClicked , isInGroup , notInLegend , otherState , _item ;
199199 var isIsolated = true ;
200- for ( i = 0 ; i < allLegendItems . length ; i ++ ) {
200+ for ( i = 0 ; i < allLegendItems . length ; i ++ ) {
201201 _item = allLegendItems [ i ] ;
202202 isClicked = _item === fullTrace ;
203203 notInLegend = _item . showlegend !== true ;
204- if ( isClicked || notInLegend ) continue ;
204+ if ( isClicked || notInLegend ) continue ;
205205
206206 isInGroup = ( hasLegendgroup && _item . legendgroup === legendgroup ) ;
207207
208- if ( ! isInGroup && _item . legend === thisLegend && _item . visible === true && ! Registry . traceIs ( _item , 'notLegendIsolatable' ) ) {
208+ if ( ! isInGroup && _item . legend === thisLegend && _item . visible === true && ! Registry . traceIs ( _item , 'notLegendIsolatable' ) ) {
209209 isIsolated = false ;
210210 break ;
211211 }
212212 }
213213
214- for ( i = 0 ; i < allLegendItems . length ; i ++ ) {
214+ for ( i = 0 ; i < allLegendItems . length ; i ++ ) {
215215 _item = allLegendItems [ i ] ;
216216
217217 // False is sticky; we don't change it. Also ensure we don't change states of itmes in other legend
218- if ( _item . visible === false || _item . legend !== thisLegend ) continue ;
218+ if ( _item . visible === false || _item . legend !== thisLegend ) continue ;
219219
220- if ( Registry . traceIs ( _item , 'notLegendIsolatable' ) ) {
220+ if ( Registry . traceIs ( _item , 'notLegendIsolatable' ) ) {
221221 continue ;
222222 }
223223
224- switch ( fullTrace . visible ) {
224+ switch ( fullTrace . visible ) {
225225 case 'legendonly' :
226226 setVisibility ( _item , true ) ;
227227 break ;
@@ -237,13 +237,13 @@ exports.handleItemClick = function handleItemClick(g, gd, legendObj, mode) {
237237 }
238238 }
239239
240- for ( i = 0 ; i < carrs . length ; i ++ ) {
240+ for ( i = 0 ; i < carrs . length ; i ++ ) {
241241 kcont = carrs [ i ] ;
242- if ( ! kcont ) continue ;
242+ if ( ! kcont ) continue ;
243243 var update = kcont . constructUpdate ( ) ;
244244
245245 var updateKeys = Object . keys ( update ) ;
246- for ( j = 0 ; j < updateKeys . length ; j ++ ) {
246+ for ( j = 0 ; j < updateKeys . length ; j ++ ) {
247247 key = updateKeys [ j ] ;
248248 val = dataUpdate [ key ] = dataUpdate [ key ] || [ ] ;
249249 val [ carrIdx [ i ] ] = update [ key ] ;
@@ -255,18 +255,18 @@ exports.handleItemClick = function handleItemClick(g, gd, legendObj, mode) {
255255 // as updates and not accidentally reset to the default value. This fills
256256 // out sparse arrays with the required number of undefined values:
257257 keys = Object . keys ( dataUpdate ) ;
258- for ( i = 0 ; i < keys . length ; i ++ ) {
258+ for ( i = 0 ; i < keys . length ; i ++ ) {
259259 key = keys [ i ] ;
260- for ( j = 0 ; j < dataIndices . length ; j ++ ) {
260+ for ( j = 0 ; j < dataIndices . length ; j ++ ) {
261261 // Use hasOwnProperty to protect against falsy values:
262- if ( ! dataUpdate [ key ] . hasOwnProperty ( j ) ) {
262+ if ( ! dataUpdate [ key ] . hasOwnProperty ( j ) ) {
263263 dataUpdate [ key ] [ j ] = undefined ;
264264 }
265265 }
266266 }
267267
268- if ( shapesUpdated ) {
269- Registry . call ( '_guiUpdate' , gd , dataUpdate , { shapes : updatedShapes } , dataIndices ) ;
268+ if ( shapesUpdated ) {
269+ Registry . call ( '_guiUpdate' , gd , dataUpdate , { shapes : updatedShapes } , dataIndices ) ;
270270 } else {
271271 Registry . call ( '_guiRestyle' , gd , dataUpdate , dataIndices ) ;
272272 }
@@ -286,7 +286,7 @@ exports.handleTitleClick = function handleTitleClick(gd, legendObj, mode) {
286286 const fullLayout = gd . _fullLayout ;
287287 const fullData = gd . _fullData ;
288288 const legendId = helpers . getId ( legendObj ) ;
289- const shapesWithLegend = ( fullLayout . shapes || [ ] ) . filter ( function ( d ) { return d . showlegend ; } ) ;
289+ const shapesWithLegend = ( fullLayout . shapes || [ ] ) . filter ( function ( d ) { return d . showlegend ; } ) ;
290290 const allLegendItems = fullData . concat ( shapesWithLegend ) ;
291291
292292 function isInLegend ( item ) {
@@ -296,17 +296,17 @@ exports.handleTitleClick = function handleTitleClick(gd, legendObj, mode) {
296296 var toggleThisLegend ;
297297 var toggleOtherLegends ;
298298
299- if ( mode === 'toggle' ) {
299+ if ( mode === 'toggle' ) {
300300 // If any item is visible in this legend, hide all. If all are hidden, show all
301- const anyVisibleHere = allLegendItems . some ( function ( item ) {
301+ const anyVisibleHere = allLegendItems . some ( function ( item ) {
302302 return isInLegend ( item ) && item . visible === true ;
303303 } ) ;
304304
305305 toggleThisLegend = ! anyVisibleHere ;
306306 toggleOtherLegends = false ;
307307 } else {
308308 // isolate this legend or set all legends to visible
309- const anyVisibleElsewhere = allLegendItems . some ( function ( item ) {
309+ const anyVisibleElsewhere = allLegendItems . some ( function ( item ) {
310310 return ! isInLegend ( item ) && item . visible === true && item . showlegend !== false ;
311311 } ) ;
312312
@@ -316,26 +316,26 @@ exports.handleTitleClick = function handleTitleClick(gd, legendObj, mode) {
316316
317317 const dataUpdate = { visible : [ ] } ;
318318 const dataIndices = [ ] ;
319- const updatedShapes = ( fullLayout . shapes || [ ] ) . map ( function ( d ) { return d . _input ; } ) ;
319+ const updatedShapes = ( fullLayout . shapes || [ ] ) . map ( function ( d ) { return d . _input ; } ) ;
320320 var shapesUpdated = false ;
321321
322- for ( var i = 0 ; i < allLegendItems . length ; i ++ ) {
322+ for ( var i = 0 ; i < allLegendItems . length ; i ++ ) {
323323 const item = allLegendItems [ i ] ;
324324 const inThisLegend = isInLegend ( item ) ;
325325
326326 // If item is not in this legend, skip if in toggle mode
327327 // or if item is not displayed in the legend
328- if ( ! inThisLegend ) {
328+ if ( ! inThisLegend ) {
329329 const notDisplayed = ( item . showlegend !== true && ! item . legendgroup ) ;
330- if ( mode === 'toggle' || notDisplayed ) continue ;
330+ if ( mode === 'toggle' || notDisplayed ) continue ;
331331 }
332332
333333 const shouldShow = inThisLegend ? toggleThisLegend : toggleOtherLegends ;
334334 const newVis = shouldShow ? true : 'legendonly' ;
335335
336336 // Only update if visibility would actually change
337- if ( ( item . visible !== false ) && ( item . visible !== newVis ) ) {
338- if ( item . _isShape ) {
337+ if ( ( item . visible !== false ) && ( item . visible !== newVis ) ) {
338+ if ( item . _isShape ) {
339339 updatedShapes [ item . _index ] . visible = newVis ;
340340 shapesUpdated = true ;
341341 } else {
@@ -345,9 +345,9 @@ exports.handleTitleClick = function handleTitleClick(gd, legendObj, mode) {
345345 }
346346 }
347347
348- if ( shapesUpdated ) {
349- Registry . call ( '_guiUpdate' , gd , dataUpdate , { shapes : updatedShapes } , dataIndices ) ;
350- } else if ( dataIndices . length ) {
348+ if ( shapesUpdated ) {
349+ Registry . call ( '_guiUpdate' , gd , dataUpdate , { shapes : updatedShapes } , dataIndices ) ;
350+ } else if ( dataIndices . length ) {
351351 Registry . call ( '_guiRestyle' , gd , dataUpdate , dataIndices ) ;
352352 }
353353} ;
0 commit comments