Skip to content

Commit f9325a4

Browse files
committed
add functions to centralize select emit events
1 parent e252cc8 commit f9325a4

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/components/selections/select.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
350350

351351
fillRangeItems(eventData, poly);
352352

353-
gd.emit('plotly_selecting', eventData);
353+
emitSelecting(gd, eventData);
354354
}
355355
);
356356
}
@@ -381,7 +381,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
381381

382382
clearSelectionsCache(dragOptions);
383383

384-
gd.emit('plotly_deselect', null);
384+
emitDeselect(gd);
385385

386386
if(searchTraces.length) {
387387
var clickedXaxis = searchTraces[0].xaxis;
@@ -419,7 +419,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
419419
// but in case anyone depends on it we don't want to break it now.
420420
// Note that click-to-select introduced pre v3 also emitts proper
421421
// event data when clickmode is having 'select' in its flag list.
422-
gd.emit('plotly_selected', undefined);
422+
emitSelected(gd, undefined);
423423
}
424424
}
425425

@@ -452,7 +452,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
452452
}
453453

454454
eventData.selections = gd.layout.selections;
455-
gd.emit('plotly_selected', eventData);
455+
emitSelected(gd, eventData);
456456
}).catch(Lib.error);
457457
};
458458
}
@@ -491,7 +491,7 @@ function selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutli
491491
clearSelectionsCache(dragOptions);
492492

493493
if(sendEvents) {
494-
gd.emit('plotly_deselect', null);
494+
emitDeselect(gd);
495495
}
496496
} else {
497497
subtract = evt.shiftKey &&
@@ -531,7 +531,7 @@ function selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutli
531531

532532
if(sendEvents) {
533533
eventData.selections = gd.layout.selections;
534-
gd.emit('plotly_selected', eventData);
534+
emitSelected(gd, eventData);
535535
}
536536
}
537537
}
@@ -1196,7 +1196,7 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
11961196
}
11971197

11981198
eventData.selections = gd.layout.selections;
1199-
gd.emit('plotly_selected', eventData);
1199+
emitSelected(gd, eventData);
12001200
}
12011201

12021202
fullLayout._reselect = false;
@@ -1217,7 +1217,7 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
12171217
if(sendEvents) {
12181218
if(eventData.points.length) {
12191219
eventData.selections = gd.layout.selections;
1220-
gd.emit('plotly_selected', eventData);
1220+
emitSelected(gd, eventData);
12211221
} else {
12221222
gd.emit('plotly_deselect', null);
12231223
}
@@ -1506,6 +1506,17 @@ function getFillRangeItems(dragOptions) {
15061506
);
15071507
}
15081508

1509+
function emitSelecting(gd, eventData) {
1510+
gd.emit('plotly_selecting', eventData);
1511+
}
1512+
1513+
function emitSelected(gd, eventData) {
1514+
gd.emit('plotly_selected', eventData);
1515+
}
1516+
1517+
function emitDeselect(gd) {
1518+
gd.emit('plotly_deselect', null);
1519+
}
15091520

15101521
module.exports = {
15111522
reselect: reselect,

0 commit comments

Comments
 (0)