@@ -33,6 +33,7 @@ function Scene2D(options, fullLayout) {
33
33
this . staticPlot = ! ! options . staticPlot ;
34
34
35
35
this . fullLayout = fullLayout ;
36
+ this . fullData = null ;
36
37
this . updateAxes ( fullLayout ) ;
37
38
38
39
this . makeFramework ( ) ;
@@ -49,6 +50,7 @@ function Scene2D(options, fullLayout) {
49
50
50
51
// trace set
51
52
this . traces = { } ;
53
+ this . _inputs = { } ;
52
54
53
55
// create axes spikes
54
56
this . spikes = createSpikes ( this . glplot ) ;
@@ -58,6 +60,9 @@ function Scene2D(options, fullLayout) {
58
60
outerFill : true
59
61
} ) ;
60
62
63
+ // last button state
64
+ this . lastButtonState = 0 ;
65
+
61
66
// last pick result
62
67
this . pickResult = null ;
63
68
@@ -332,6 +337,8 @@ proto.destroy = function() {
332
337
this . container . removeChild ( this . svgContainer ) ;
333
338
this . container . removeChild ( this . mouseContainer ) ;
334
339
340
+ this . fullData = null ;
341
+ this . _inputs = null ;
335
342
this . glplot = null ;
336
343
this . stopped = true ;
337
344
} ;
@@ -422,6 +429,8 @@ proto.updateTraces = function(fullData, calcData) {
422
429
var traceIds = Object . keys ( this . traces ) ;
423
430
var i , j , fullTrace ;
424
431
432
+ this . fullData = fullData ;
433
+
425
434
// remove empty traces
426
435
trace_id_loop:
427
436
for ( i = 0 ; i < traceIds . length ; i ++ ) {
@@ -443,7 +452,7 @@ proto.updateTraces = function(fullData, calcData) {
443
452
// update / create trace objects
444
453
for ( i = 0 ; i < fullData . length ; i ++ ) {
445
454
fullTrace = fullData [ i ] ;
446
-
455
+ this . _inputs [ fullTrace . uid ] = i ;
447
456
var calcTrace = calcData [ i ] ,
448
457
traceObj = this . traces [ fullTrace . uid ] ;
449
458
@@ -455,6 +464,24 @@ proto.updateTraces = function(fullData, calcData) {
455
464
}
456
465
} ;
457
466
467
+ proto . emitPointAction = function ( nextSelection , eventType ) {
468
+
469
+ var curveIndex = this . _inputs [ nextSelection . trace . uid ] ;
470
+
471
+ this . graphDiv . emit ( eventType , {
472
+ points : [ {
473
+ x : nextSelection . traceCoord [ 0 ] ,
474
+ y : nextSelection . traceCoord [ 1 ] ,
475
+ curveNumber : curveIndex ,
476
+ pointNumber : nextSelection . pointIndex ,
477
+ data : this . fullData [ curveIndex ] . _input ,
478
+ fullData : this . fullData ,
479
+ xaxis : this . xaxis ,
480
+ yaxis : this . yaxis
481
+ } ]
482
+ } ) ;
483
+ } ;
484
+
458
485
proto . draw = function ( ) {
459
486
if ( this . stopped ) return ;
460
487
@@ -463,8 +490,11 @@ proto.draw = function() {
463
490
var glplot = this . glplot ,
464
491
camera = this . camera ,
465
492
mouseListener = camera . mouseListener ,
493
+ mouseUp = this . lastButtonState === 1 && mouseListener . buttons === 0 ,
466
494
fullLayout = this . fullLayout ;
467
495
496
+ this . lastButtonState = mouseListener . buttons ;
497
+
468
498
this . cameraChanged ( ) ;
469
499
470
500
var x = mouseListener . x * glplot . pixelRatio ;
@@ -494,8 +524,13 @@ proto.draw = function() {
494
524
( y / glplot . pixelRatio ) - ( size . t + ( 1 - domainY [ 1 ] ) * size . h )
495
525
) ;
496
526
527
+ var nextSelection = result && result . object . _trace . handlePick ( result ) ;
528
+
529
+ if ( nextSelection && mouseUp ) {
530
+ this . emitPointAction ( nextSelection , 'plotly_click' ) ;
531
+ }
532
+
497
533
if ( result && result . object . _trace . hoverinfo !== 'skip' && fullLayout . hovermode ) {
498
- var nextSelection = result . object . _trace . handlePick ( result ) ;
499
534
500
535
if ( nextSelection && (
501
536
! this . lastPickResult ||
@@ -522,6 +557,10 @@ proto.draw = function() {
522
557
glplot . pixelRatio
523
558
] ;
524
559
560
+ // this needs to happen before the next block that deletes traceCoord data
561
+ // also it's important to copy, otherwise data is lost by the time event data is read
562
+ this . emitPointAction ( nextSelection , 'plotly_hover' ) ;
563
+
525
564
var hoverinfo = selection . hoverinfo ;
526
565
if ( hoverinfo !== 'all' ) {
527
566
var parts = hoverinfo . split ( '+' ) ;
@@ -549,6 +588,7 @@ proto.draw = function() {
549
588
else if ( ! result && this . lastPickResult ) {
550
589
this . spikes . update ( { } ) ;
551
590
this . lastPickResult = null ;
591
+ this . graphDiv . emit ( 'plotly_unhover' ) ;
552
592
Fx . loneUnhover ( this . svgContainer ) ;
553
593
}
554
594
}
0 commit comments