Skip to content

Commit ad2e740

Browse files
committed
provide range and lassoPoints for modified selections
1 parent 211548b commit ad2e740

File tree

3 files changed

+52
-27
lines changed

3 files changed

+52
-27
lines changed

src/components/selections/select.js

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ var shapeHelpers = require('../shapes/helpers');
1919
var shapeConstants = require('../shapes/constants');
2020

2121
var displayOutlines = require('../shapes/display_outlines');
22-
var handleEllipse = require('../shapes/draw_newshape/helpers').handleEllipse;
23-
var readPaths = require('../shapes/draw_newshape/helpers').readPaths;
22+
23+
var newShapeHelpers = require('../shapes/draw_newshape/helpers');
24+
var handleEllipse = newShapeHelpers.handleEllipse;
25+
var readPaths = newShapeHelpers.readPaths;
26+
2427
var newShapes = require('../shapes/draw_newshape/newshapes');
2528

2629
var newSelections = require('./draw_newselection/newselections');
@@ -281,7 +284,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
281284
selection = _doSelect(selectionTesters, searchTraces);
282285

283286
eventData = {points: selection};
284-
fillRangeItems(eventData, currentPolygon, filterPoly);
287+
fillRangeItems(eventData, filterPoly ? filterPoly.filtered : currentPolygon);
285288
dragOptions.gd.emit('plotly_selecting', eventData);
286289
}
287290
);
@@ -1110,6 +1113,28 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
11101113
var clickmode = fullLayout.clickmode;
11111114
var sendEvents = clickmode.indexOf('event') > -1;
11121115
if(sendEvents) {
1116+
var activePolygons = getLayoutPolygons(gd, true);
1117+
1118+
var xref = activePolygons[0].xref;
1119+
var yref = activePolygons[0].yref;
1120+
if(xref && yref) {
1121+
var activePolygon = activePolygons[0];
1122+
// handle active shape with multiple polygons
1123+
for(var n = 1; n < activePolygons.length; n++) {
1124+
// close previous polygon
1125+
activePolygon.push(activePolygon[0]);
1126+
// add this polygon
1127+
activePolygon = activePolygon.concat(activePolygons[n]);
1128+
}
1129+
1130+
var fillRangeItems = makeFillRangeItems([
1131+
getFromId(gd, xref, 'x'),
1132+
getFromId(gd, yref, 'y')
1133+
]);
1134+
1135+
fillRangeItems(eventData, activePolygon);
1136+
}
1137+
11131138
gd.emit('plotly_selected', eventData);
11141139
}
11151140
}
@@ -1157,12 +1182,16 @@ function addTester(layoutPolygons, xRef, yRef, selectionTesters) {
11571182
return selectionTesters;
11581183
}
11591184

1160-
function getLayoutPolygons(gd) {
1185+
function getLayoutPolygons(gd, onlyActiveOnes) {
11611186
var allPolygons = [];
1162-
var allSelections = gd._fullLayout.selections;
1187+
1188+
var fullLayout = gd._fullLayout;
1189+
var allSelections = fullLayout.selections;
11631190
var len = allSelections.length;
11641191

11651192
for(var i = 0; i < len; i++) {
1193+
if(onlyActiveOnes && i !== fullLayout._activeSelectionIndex) continue;
1194+
11661195
var selection = allSelections[i];
11671196
if(!selection) continue;
11681197

@@ -1198,6 +1227,7 @@ function getLayoutPolygons(gd) {
11981227
polygon.yref = yref;
11991228

12001229
polygon.subtract = false;
1230+
polygon.isRect = true;
12011231

12021232
allPolygons.push(polygon);
12031233
} else if(selection.type === 'path') {
@@ -1271,42 +1301,37 @@ function convert(ax, d) {
12711301
}
12721302

12731303
function makeFillRangeItems(allAxes) {
1274-
return function(eventData, poly, filterPoly) {
1275-
var range = {};
1276-
var ranges = {};
1277-
1278-
var hasRange = false;
1279-
var hasRanges = false;
1304+
return function(eventData, poly) {
1305+
var range;
1306+
var lassoPoints;
12801307

12811308
for(var i = 0; i < allAxes.length; i++) {
12821309
var ax = allAxes[i];
1283-
var axLetter = ax._id.charAt(0);
1310+
var id = ax._id;
1311+
var axLetter = id.charAt(0);
12841312

1313+
if(!range) range = {};
12851314
var min = poly[axLetter + 'min'];
12861315
var max = poly[axLetter + 'max'];
12871316

12881317
if(min !== undefined && max !== undefined) {
1289-
range[ax._id] = [
1318+
range[id] = [
12901319
p2r(ax, min),
12911320
p2r(ax, max)
12921321
].sort(ascending);
1293-
1294-
hasRange = true;
12951322
}
1296-
1297-
if(filterPoly && filterPoly.filtered) {
1298-
ranges[ax._id] = filterPoly.filtered.map(axValue(ax));
1299-
1300-
hasRanges = true;
1323+
if(!lassoPoints) {
1324+
lassoPoints = {};
13011325
}
1326+
lassoPoints[id] = poly.map(axValue(ax));
13021327
}
13031328

1304-
if(hasRange) {
1329+
if(range) {
13051330
eventData.range = range;
13061331
}
13071332

1308-
if(hasRanges) {
1309-
eventData.lassoPoints = ranges;
1333+
if(lassoPoints) {
1334+
eventData.lassoPoints = lassoPoints;
13101335
}
13111336
};
13121337
}

src/plots/geo/geo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ proto.updateFx = function(fullLayout, geoLayout) {
440440
];
441441
};
442442
} else if(dragMode === 'lasso') {
443-
fillRangeItems = function(eventData, poly, pts) {
443+
fillRangeItems = function(eventData, poly) {
444444
var dataPts = eventData.lassoPoints = {};
445-
dataPts[_this.id] = pts.filtered.map(invert);
445+
dataPts[_this.id] = poly.map(invert);
446446
};
447447
}
448448

src/plots/mapbox/mapbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,9 @@ proto.updateFx = function(fullLayout) {
559559
];
560560
};
561561
} else {
562-
fillRangeItems = function(eventData, poly, pts) {
562+
fillRangeItems = function(eventData, pts) {
563563
var dataPts = eventData.lassoPoints = {};
564-
dataPts[self.id] = pts.filtered.map(invert);
564+
dataPts[self.id] = pts.map(invert);
565565
};
566566
}
567567

0 commit comments

Comments
 (0)