@@ -14,10 +14,29 @@ var Registry = require('../../registry');
1414var SHOWISOLATETIP = true ;
1515
1616module . exports = function handleClick ( g , gd , numClicks ) {
17+ var fullLayout = gd . _fullLayout ;
18+
1719 if ( gd . _dragged || gd . _editing ) return ;
1820
19- var hiddenSlices = gd . _fullLayout . hiddenlabels ?
20- gd . _fullLayout . hiddenlabels . slice ( ) :
21+ var itemClick = fullLayout . legend . itemclick ;
22+ var itemDoubleClick = fullLayout . legend . itemdoubleclick ;
23+
24+ if ( numClicks === 1 && itemClick === 'toggle' && itemDoubleClick === 'toggleothers' &&
25+ SHOWISOLATETIP && gd . data && gd . _context . showTips
26+ ) {
27+ Lib . notifier ( Lib . _ ( gd , 'Double-click on legend to isolate one trace' ) , 'long' ) ;
28+ SHOWISOLATETIP = false ;
29+ } else {
30+ SHOWISOLATETIP = false ;
31+ }
32+
33+ var mode ;
34+ if ( numClicks === 1 ) mode = itemClick ;
35+ else if ( numClicks === 2 ) mode = itemDoubleClick ;
36+ if ( ! mode ) return ;
37+
38+ var hiddenSlices = fullLayout . hiddenlabels ?
39+ fullLayout . hiddenlabels . slice ( ) :
2140 [ ] ;
2241
2342 var legendItem = g . data ( ) [ 0 ] [ 0 ] ;
@@ -85,21 +104,14 @@ module.exports = function handleClick(g, gd, numClicks) {
85104 }
86105 }
87106
88- if ( numClicks === 1 && SHOWISOLATETIP && gd . data && gd . _context . showTips ) {
89- Lib . notifier ( Lib . _ ( gd , 'Double-click on legend to isolate one trace' ) , 'long' ) ;
90- SHOWISOLATETIP = false ;
91- } else {
92- SHOWISOLATETIP = false ;
93- }
94-
95107 if ( Registry . traceIs ( fullTrace , 'pie-like' ) ) {
96108 var thisLabel = legendItem . label ;
97109 var thisLabelIndex = hiddenSlices . indexOf ( thisLabel ) ;
98110
99- if ( numClicks === 1 ) {
111+ if ( mode === 'toggle' ) {
100112 if ( thisLabelIndex === - 1 ) hiddenSlices . push ( thisLabel ) ;
101113 else hiddenSlices . splice ( thisLabelIndex , 1 ) ;
102- } else if ( numClicks === 2 ) {
114+ } else if ( mode === 'toggleothers' ) {
103115 hiddenSlices = [ ] ;
104116 gd . calcdata [ 0 ] . forEach ( function ( d ) {
105117 if ( thisLabel !== d . label ) {
@@ -126,7 +138,7 @@ module.exports = function handleClick(g, gd, numClicks) {
126138 }
127139 }
128140
129- if ( numClicks === 1 ) {
141+ if ( mode === 'toggle' ) {
130142 var nextVisibility ;
131143
132144 switch ( fullTrace . visible ) {
@@ -150,7 +162,7 @@ module.exports = function handleClick(g, gd, numClicks) {
150162 } else {
151163 setVisibility ( fullTrace , nextVisibility ) ;
152164 }
153- } else if ( numClicks === 2 ) {
165+ } else if ( mode === 'toggleothers' ) {
154166 // Compute the clicked index. expandedIndex does what we want for expanded traces
155167 // but also culls hidden traces. That means we have some work to do.
156168 var isClicked , isInGroup , otherState ;
0 commit comments