Skip to content

Commit 9f77c11

Browse files
committed
DRY up event emission
1 parent 2e8db74 commit 9f77c11

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

src/plots/gl2d/scene2d.js

+20-27
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,24 @@ proto.updateTraces = function(fullData, calcData) {
464464
}
465465
};
466466

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+
467485
proto.draw = function() {
468486
if(this.stopped) return;
469487

@@ -507,22 +525,9 @@ proto.draw = function() {
507525
);
508526

509527
var nextSelection = result && result.object._trace.handlePick(result);
510-
var curveIndex;
511528

512529
if(nextSelection && mouseUp) {
513-
curveIndex = this._inputs[nextSelection.trace.uid];
514-
this.graphDiv.emit('plotly_click', {
515-
points: [{
516-
x: nextSelection.traceCoord[0],
517-
y: nextSelection.traceCoord[1],
518-
curveNumber: curveIndex,
519-
pointNumber: nextSelection.pointIndex,
520-
data: this.fullData[curveIndex]._input,
521-
fullData: this.fullData,
522-
xaxis: this.xaxis,
523-
yaxis: this.yaxis
524-
}]
525-
});
530+
this.emitPointAction(nextSelection, 'plotly_click');
526531
}
527532

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

555560
// this needs to happen before the next block that deletes traceCoord data
556561
// also it's important to copy, otherwise data is lost by the time event data is read
557-
curveIndex = this._inputs[nextSelection.trace.uid];
558-
this.graphDiv.emit('plotly_hover', {
559-
points: [{
560-
x: nextSelection.traceCoord[0],
561-
y: nextSelection.traceCoord[1],
562-
curveNumber: curveIndex,
563-
pointNumber: nextSelection.pointIndex,
564-
data: this.fullData[curveIndex]._input,
565-
fullData: this.fullData,
566-
xaxis: this.xaxis,
567-
yaxis: this.yaxis
568-
}]
569-
});
562+
this.emitPointAction(nextSelection, 'plotly_hover');
570563

571564
var hoverinfo = selection.hoverinfo;
572565
if(hoverinfo !== 'all') {

0 commit comments

Comments
 (0)