Skip to content

Commit d2cfa2f

Browse files
committed
fixes plotly#2262 selection on different subplots
+ displays selection box on relevant subplot + removes selection box and selected points from other subplots
1 parent ac2c579 commit d2cfa2f

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/plots/cartesian/select.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,22 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
4444
yAxisIds = dragOptions.yaxes.map(getAxId),
4545
allAxes = dragOptions.xaxes.concat(dragOptions.yaxes),
4646
filterPoly, testPoly, mergedPolygons, currentPolygon,
47-
subtract = e.altKey;
47+
subtract = e.altKey,
48+
priorSubplotTarget = dragOptions.gd._priorSubplotTarget;
4849

50+
if (priorSubplotTarget && plotinfo.id != priorSubplotTarget.id){
51+
52+
for(i = 0; i < priorSubplotTarget.traces.length; i++) {
53+
searchInfo = priorSubplotTarget.traces[i];
54+
searchInfo.selectPoints(searchInfo, false);
55+
}
56+
57+
updateSelectedState(gd, priorSubplotTarget.traces);
58+
priorSubplotTarget = {};
59+
plotinfo.selection = {};
60+
plotinfo.selection.polygons = dragOptions.polygons = [];
61+
plotinfo.selection.mergedPolygons = dragOptions.mergedPolygons = [];
62+
}
4963

5064
// take over selection polygons from prev mode, if any
5165
if((e.shiftKey || e.altKey) && (plotinfo.selection && plotinfo.selection.polygons) && !dragOptions.polygons) {
@@ -67,9 +81,10 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
6781

6882
outlines.enter()
6983
.append('path')
70-
.attr('class', function(d) { return 'select-outline select-outline-' + d; })
71-
.attr('transform', 'translate(' + xs + ', ' + ys + ')')
72-
.attr('d', path0 + 'Z');
84+
.attr('class', function(d) { return 'select-outline select-outline-' + d; });
85+
86+
outlines.attr('transform', 'translate(' + xs + ', ' + ys + ')')
87+
.attr('d', path0 + 'Z');
7388

7489
var corners = zoomLayer.append('path')
7590
.attr('class', 'zoombox-corners')
@@ -225,8 +240,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
225240
var ppts = mergedPolygons[i];
226241
paths.push(ppts.join('L') + 'L' + ppts[0]);
227242
}
228-
outlines.attr('d', 'M' + paths.join('M') + 'Z')
229-
.attr('transform', 'translate(' + xs + ', ' + ys + ')');
243+
outlines.attr('d', 'M' + paths.join('M') + 'Z');
230244

231245
throttle.throttle(
232246
throttleID,
@@ -288,6 +302,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
288302
throttle.done(throttleID).then(function() {
289303
throttle.clear(throttleID);
290304
dragOptions.gd.emit('plotly_selected', eventData);
305+
dragOptions.gd._priorSubplotTarget = {id: plotinfo.id, traces:searchTraces};
291306

292307
if(currentPolygon && dragOptions.polygons) {
293308
// save last polygons

0 commit comments

Comments
 (0)