@@ -34,7 +34,7 @@ var STATIC_CANVAS, STATIC_CONTEXT;
34
34
35
35
function render ( scene ) {
36
36
37
- //Update size of svg container
37
+ // update size of svg container
38
38
var svgContainer = scene . svgContainer ;
39
39
var clientRect = scene . container . getBoundingClientRect ( ) ;
40
40
var width = clientRect . width , height = clientRect . height ;
@@ -45,7 +45,7 @@ function render(scene) {
45
45
computeTickMarks ( scene ) ;
46
46
scene . glplot . axes . update ( scene . axesOptions ) ;
47
47
48
- //Check if pick has changed
48
+ // check if pick has changed
49
49
var keys = Object . keys ( scene . traces ) ;
50
50
var lastPicked = null ;
51
51
var selection = scene . glplot . selection ;
@@ -59,22 +59,28 @@ function render(scene) {
59
59
}
60
60
61
61
function formatter ( axisName , val ) {
62
- if ( val === undefined ) return undefined ;
63
62
if ( typeof val === 'string' ) return val ;
64
63
65
64
var axis = scene . fullSceneLayout [ axisName ] ;
66
65
return Axes . tickText ( axis , axis . c2l ( val ) , 'hover' ) . text ;
67
66
}
68
67
68
+ var oldEventData ;
69
+
69
70
if ( lastPicked !== null ) {
70
71
var pdata = project ( scene . glplot . cameraParams , selection . dataCoordinate ) ,
71
- hoverinfo = lastPicked . data . hoverinfo ;
72
+ trace = lastPicked . data ,
73
+ hoverinfo = trace . hoverinfo ;
74
+
75
+ var xVal = formatter ( 'xaxis' , selection . traceCoordinate [ 0 ] ) ,
76
+ yVal = formatter ( 'yaxis' , selection . traceCoordinate [ 1 ] ) ,
77
+ zVal = formatter ( 'zaxis' , selection . traceCoordinate [ 2 ] ) ;
72
78
73
79
if ( hoverinfo !== 'all' ) {
74
80
var hoverinfoParts = hoverinfo . split ( '+' ) ;
75
- if ( hoverinfoParts . indexOf ( 'x' ) === - 1 ) selection . traceCoordinate [ 0 ] = undefined ;
76
- if ( hoverinfoParts . indexOf ( 'y' ) === - 1 ) selection . traceCoordinate [ 1 ] = undefined ;
77
- if ( hoverinfoParts . indexOf ( 'z' ) === - 1 ) selection . traceCoordinate [ 2 ] = undefined ;
81
+ if ( hoverinfoParts . indexOf ( 'x' ) === - 1 ) xVal = undefined ;
82
+ if ( hoverinfoParts . indexOf ( 'y' ) === - 1 ) yVal = undefined ;
83
+ if ( hoverinfoParts . indexOf ( 'z' ) === - 1 ) zVal = undefined ;
78
84
if ( hoverinfoParts . indexOf ( 'text' ) === - 1 ) selection . textLabel = undefined ;
79
85
if ( hoverinfoParts . indexOf ( 'name' ) === - 1 ) lastPicked . name = undefined ;
80
86
}
@@ -83,18 +89,42 @@ function render(scene) {
83
89
Fx . loneHover ( {
84
90
x : ( 0.5 + 0.5 * pdata [ 0 ] / pdata [ 3 ] ) * width ,
85
91
y : ( 0.5 - 0.5 * pdata [ 1 ] / pdata [ 3 ] ) * height ,
86
- xLabel : formatter ( 'xaxis' , selection . traceCoordinate [ 0 ] ) ,
87
- yLabel : formatter ( 'yaxis' , selection . traceCoordinate [ 1 ] ) ,
88
- zLabel : formatter ( 'zaxis' , selection . traceCoordinate [ 2 ] ) ,
92
+ xLabel : xVal ,
93
+ yLabel : yVal ,
94
+ zLabel : zVal ,
89
95
text : selection . textLabel ,
90
96
name : lastPicked . name ,
91
97
color : lastPicked . color
92
98
} , {
93
99
container : svgContainer
94
100
} ) ;
95
101
}
102
+
103
+ var eventData = {
104
+ points : [ {
105
+ x : xVal ,
106
+ y : yVal ,
107
+ z : zVal ,
108
+ data : trace . _input ,
109
+ fullData : trace ,
110
+ curveNumber : trace . index ,
111
+ pointNumber : selection . data . index
112
+ } ]
113
+ } ;
114
+
115
+ if ( selection . buttons && selection . distance < 5 ) {
116
+ scene . graphDiv . emit ( 'plotly_click' , eventData ) ;
117
+ }
118
+ else {
119
+ scene . graphDiv . emit ( 'plotly_hover' , eventData ) ;
120
+ }
121
+
122
+ oldEventData = eventData ;
123
+ }
124
+ else {
125
+ Fx . loneUnhover ( svgContainer ) ;
126
+ scene . graphDiv . emit ( 'plotly_unhover' , oldEventData ) ;
96
127
}
97
- else Fx . loneUnhover ( svgContainer ) ;
98
128
}
99
129
100
130
function initializeGLPlot ( scene , fullLayout , canvas , gl ) {
@@ -110,9 +140,9 @@ function initializeGLPlot(scene, fullLayout, canvas, gl) {
110
140
autoBounds : false
111
141
} ;
112
142
113
- //For static plots, we reuse the WebGL context as WebKit doesn't collect them
114
- // reliably
115
- if ( scene . staticMode ) {
143
+ // for static plots, we reuse the WebGL context
144
+ // as WebKit doesn't collect them reliably
145
+ if ( scene . staticMode ) {
116
146
if ( ! STATIC_CONTEXT ) {
117
147
STATIC_CANVAS = document . createElement ( 'canvas' ) ;
118
148
try {
@@ -178,11 +208,14 @@ function initializeGLPlot(scene, fullLayout, canvas, gl) {
178
208
179
209
function Scene ( options , fullLayout ) {
180
210
181
- //Create sub container for plot
211
+ // create sub container for plot
182
212
var sceneContainer = document . createElement ( 'div' ) ;
183
213
var plotContainer = options . container ;
184
214
185
- //Create SVG container for hover text
215
+ // keep a ref to the graph div to fire hover+click events
216
+ this . graphDiv = options . graphDiv ;
217
+
218
+ // create SVG container for hover text
186
219
var svgContainer = document . createElementNS (
187
220
'http://www.w3.org/2000/svg' ,
188
221
'svg' ) ;
0 commit comments