@@ -21,11 +21,13 @@ var Color = require('../color');
21
21
var svgTextUtils = require ( '../../lib/svg_text_utils' ) ;
22
22
23
23
var constants = require ( './constants' ) ;
24
+ var interactConstants = require ( '../../constants/interactions' ) ;
24
25
var getLegendData = require ( './get_legend_data' ) ;
25
26
var style = require ( './style' ) ;
26
27
var helpers = require ( './helpers' ) ;
27
28
var anchorUtils = require ( './anchor_utils' ) ;
28
29
30
+ var SHOWISOLATETIP = true ;
29
31
30
32
module . exports = function draw ( gd ) {
31
33
var fullLayout = gd . _fullLayout ;
@@ -399,7 +401,7 @@ function drawTexts(g, gd) {
399
401
function setupTraceToggle ( g , gd ) {
400
402
var newMouseDownTime ,
401
403
numClicks = 1 ,
402
- DBLCLICKDELAY = constants . DBLCLICKDELAY ;
404
+ DBLCLICKDELAY = interactConstants . DBLCLICKDELAY ;
403
405
404
406
var traceToggle = g . selectAll ( 'rect' )
405
407
. data ( [ 0 ] ) ;
@@ -432,7 +434,7 @@ function setupTraceToggle(g, gd) {
432
434
}
433
435
434
436
if ( numClicks === 1 ) {
435
- legend . _clickTimeout = setTimeout ( function ( ) { handleClick ( g , gd , numClicks ) ; } , 300 ) ;
437
+ legend . _clickTimeout = setTimeout ( function ( ) { handleClick ( g , gd , numClicks ) ; } , DBLCLICKDELAY ) ;
436
438
} else if ( numClicks === 2 ) {
437
439
if ( legend . _clickTimeout ) {
438
440
clearTimeout ( legend . _clickTimeout ) ;
@@ -455,6 +457,13 @@ function handleClick(g, gd, numClicks) {
455
457
tracei ,
456
458
newVisible ;
457
459
460
+
461
+ if ( numClicks === 1 && SHOWISOLATETIP && gd . data && gd . _context . showTips ) {
462
+ Lib . notifier ( 'Double click on legend to isolate individual trace' , 'long' ) ;
463
+ SHOWISOLATETIP = false ;
464
+ } else {
465
+ SHOWISOLATETIP = false ;
466
+ }
458
467
if ( Registry . traceIs ( trace , 'pie' ) ) {
459
468
var thisLabel = legendItem . label ,
460
469
thisLabelIndex = hiddenSlices . indexOf ( thisLabel ) ;
@@ -469,37 +478,50 @@ function handleClick(g, gd, numClicks) {
469
478
hiddenSlices . push ( d . label ) ;
470
479
}
471
480
} ) ;
481
+ if ( gd . _fullLayout . hiddenlabels && gd . _fullLayout . hiddenlabels . length === hiddenSlices . length && thisLabelIndex === - 1 ) {
482
+ hiddenSlices = [ ] ;
483
+ }
472
484
}
473
485
474
486
Plotly . relayout ( gd , 'hiddenlabels' , hiddenSlices ) ;
475
487
} else {
476
- var otherTraces = [ ] ,
477
- traceIndex ,
488
+ var allTraces = [ ] ,
489
+ traceVisibility = [ ] ,
478
490
i ;
479
491
480
492
for ( i = 0 ; i < fullData . length ; i ++ ) {
481
- otherTraces . push ( i ) ;
493
+ allTraces . push ( i ) ;
494
+ traceVisibility . push ( 'legendonly' ) ;
482
495
}
483
496
484
497
if ( legendgroup === '' ) {
485
498
traceIndicesInGroup = [ trace . index ] ;
486
- otherTraces . splice ( trace . index , 1 ) ;
499
+ traceVisibility [ trace . index ] = true ;
487
500
} else {
488
501
for ( i = 0 ; i < fullData . length ; i ++ ) {
489
502
tracei = fullData [ i ] ;
490
503
if ( tracei . legendgroup === legendgroup ) {
491
504
traceIndicesInGroup . push ( tracei . index ) ;
492
- traceIndex = otherTraces . indexOf ( i ) ;
493
- otherTraces . splice ( traceIndex , 1 ) ;
505
+ traceVisibility [ allTraces . indexOf ( i ) ] = true ;
494
506
}
495
507
}
496
508
}
509
+
497
510
if ( numClicks === 1 ) {
498
511
newVisible = trace . visible === true ? 'legendonly' : true ;
499
512
Plotly . restyle ( gd , 'visible' , newVisible , traceIndicesInGroup ) ;
500
513
} else if ( numClicks === 2 ) {
501
- Plotly . restyle ( gd , 'visible' , true , traceIndicesInGroup ) ;
502
- Plotly . restyle ( gd , 'visible' , 'legendonly' , otherTraces ) ;
514
+ var sameAsLast = true ;
515
+ for ( i = 0 ; i < fullData . length ; i ++ ) {
516
+ if ( fullData [ i ] . visible !== traceVisibility [ i ] ) {
517
+ sameAsLast = false ;
518
+ break ;
519
+ }
520
+ }
521
+ if ( sameAsLast ) {
522
+ traceVisibility = true ;
523
+ }
524
+ Plotly . restyle ( gd , 'visible' , traceVisibility , allTraces ) ;
503
525
}
504
526
}
505
527
}
0 commit comments