Skip to content

Commit fdba7f1

Browse files
committed
add hover+click event trigger in render loop:
- makes use of (new) selection.buttons to determine if event is hover or click.
1 parent f059957 commit fdba7f1

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/plots/gl3d/scene.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ function render(scene) {
6666
return Axes.tickText(axis, axis.c2l(val), 'hover').text;
6767
}
6868

69+
function makeEventData(xVal, yVal, zVal, trace, selection) {
70+
return {points: [{
71+
x: xVal,
72+
y: yVal,
73+
z: zVal,
74+
data: trace._input,
75+
fullData: trace,
76+
curveNumber: trace.index,
77+
pointNumber: selection.data.index
78+
}]};
79+
}
80+
81+
var oldEventData;
82+
6983
if(lastPicked !== null) {
7084
var pdata = project(scene.glplot.cameraParams, selection.dataCoordinate),
7185
trace = lastPicked.data,
@@ -96,8 +110,17 @@ function render(scene) {
96110
}, {
97111
container: svgContainer
98112
});
113+
114+
var eventType = (selection.buttons) ? 'plotly_click' : 'plotly_hover',
115+
eventData = makeEventData(xVal, yVal, zVal, trace, selection);
116+
117+
scene.graphDiv.emit(eventType, eventData);
118+
oldEventData = eventData;
119+
}
120+
else {
121+
Fx.loneUnhover(svgContainer);
122+
scene.graphDiv.emit('plotly_unhover', oldEventData);
99123
}
100-
else Fx.loneUnhover(svgContainer);
101124
}
102125

103126
function initializeGLPlot(scene, fullLayout, canvas, gl) {

0 commit comments

Comments
 (0)