Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hover / unhover events on the 2d WebGL plots #994

Merged
merged 10 commits into from
Oct 5, 2016
47 changes: 20 additions & 27 deletions src/plots/gl2d/scene2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,24 @@ proto.updateTraces = function(fullData, calcData) {
}
};

proto.emitPointAction = function(nextSelection, eventType) {

var curveIndex = this._inputs[nextSelection.trace.uid];

this.graphDiv.emit(eventType, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nicely done.

points: [{
x: nextSelection.traceCoord[0],
y: nextSelection.traceCoord[1],
curveNumber: curveIndex,
pointNumber: nextSelection.pointIndex,
data: this.fullData[curveIndex]._input,
fullData: this.fullData,
xaxis: this.xaxis,
yaxis: this.yaxis
}]
});
};

proto.draw = function() {
if(this.stopped) return;

Expand Down Expand Up @@ -507,22 +525,9 @@ proto.draw = function() {
);

var nextSelection = result && result.object._trace.handlePick(result);
var curveIndex;

if(nextSelection && mouseUp) {
curveIndex = this._inputs[nextSelection.trace.uid];
this.graphDiv.emit('plotly_click', {
points: [{
x: nextSelection.traceCoord[0],
y: nextSelection.traceCoord[1],
curveNumber: curveIndex,
pointNumber: nextSelection.pointIndex,
data: this.fullData[curveIndex]._input,
fullData: this.fullData,
xaxis: this.xaxis,
yaxis: this.yaxis
}]
});
this.emitPointAction(nextSelection, 'plotly_click');
}

if(result && result.object._trace.hoverinfo !== 'skip' && fullLayout.hovermode) {
Expand Down Expand Up @@ -554,19 +559,7 @@ proto.draw = function() {

// this needs to happen before the next block that deletes traceCoord data
// also it's important to copy, otherwise data is lost by the time event data is read
curveIndex = this._inputs[nextSelection.trace.uid];
this.graphDiv.emit('plotly_hover', {
points: [{
x: nextSelection.traceCoord[0],
y: nextSelection.traceCoord[1],
curveNumber: curveIndex,
pointNumber: nextSelection.pointIndex,
data: this.fullData[curveIndex]._input,
fullData: this.fullData,
xaxis: this.xaxis,
yaxis: this.yaxis
}]
});
this.emitPointAction(nextSelection, 'plotly_hover');

var hoverinfo = selection.hoverinfo;
if(hoverinfo !== 'all') {
Expand Down