Skip to content

Commit 37a664a

Browse files
committed
include range and lassoPoints depending on rect and lasso
1 parent ad2e740 commit 37a664a

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/components/selections/select.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,16 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
284284
selection = _doSelect(selectionTesters, searchTraces);
285285

286286
eventData = {points: selection};
287-
fillRangeItems(eventData, filterPoly ? filterPoly.filtered : currentPolygon);
287+
288+
var poly;
289+
if(filterPoly) {
290+
poly = filterPoly.filtered;
291+
} else {
292+
poly = currentPolygon;
293+
poly.isRect = selectionTesters.isRect;
294+
}
295+
fillRangeItems(eventData, poly);
296+
288297
dragOptions.gd.emit('plotly_selecting', eventData);
289298
}
290299
);
@@ -1310,20 +1319,21 @@ function makeFillRangeItems(allAxes) {
13101319
var id = ax._id;
13111320
var axLetter = id.charAt(0);
13121321

1313-
if(!range) range = {};
1314-
var min = poly[axLetter + 'min'];
1315-
var max = poly[axLetter + 'max'];
1322+
if(poly.isRect) {
1323+
if(!range) range = {};
1324+
var min = poly[axLetter + 'min'];
1325+
var max = poly[axLetter + 'max'];
13161326

1317-
if(min !== undefined && max !== undefined) {
1318-
range[id] = [
1319-
p2r(ax, min),
1320-
p2r(ax, max)
1321-
].sort(ascending);
1322-
}
1323-
if(!lassoPoints) {
1324-
lassoPoints = {};
1327+
if(min !== undefined && max !== undefined) {
1328+
range[id] = [
1329+
p2r(ax, min),
1330+
p2r(ax, max)
1331+
].sort(ascending);
1332+
}
1333+
} else {
1334+
if(!lassoPoints) lassoPoints = {};
1335+
lassoPoints[id] = poly.map(axValue(ax));
13251336
}
1326-
lassoPoints[id] = poly.map(axValue(ax));
13271337
}
13281338

13291339
if(range) {

src/lib/polygon.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ polygon.tester = function tester(ptsIn) {
2929
var ymax = ymin;
3030
var i;
3131

32-
pts.push(pts[0]);
32+
if(
33+
pts[pts.length - 1][0] !== pts[0][0] ||
34+
pts[pts.length - 1][1] !== pts[0][1]
35+
) {
36+
// close the polygon
37+
pts.push(pts[0]);
38+
}
39+
3340
for(i = 1; i < pts.length; i++) {
3441
xmin = Math.min(xmin, pts[i][0]);
3542
xmax = Math.max(xmax, pts[i][0]);

0 commit comments

Comments
 (0)