Skip to content

Commit 4623196

Browse files
committed
provide ranges for rect selection edits in plotly_selected
1 parent b9d2db8 commit 4623196

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

src/components/selections/select.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -282,28 +282,6 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
282282
poly = filterPoly.filtered;
283283
} else {
284284
poly = castMultiPolygon(mergedPolygons);
285-
poly.isRect = poly.length === 5 &&
286-
poly[0][0] === poly[4][0] &&
287-
poly[0][1] === poly[4][1] &&
288-
(
289-
poly[0][0] === poly[1][0] &&
290-
poly[2][0] === poly[3][0] &&
291-
poly[0][1] === poly[3][1] &&
292-
poly[1][1] === poly[2][1]
293-
) ||
294-
(
295-
poly[0][1] === poly[1][1] &&
296-
poly[2][1] === poly[3][1] &&
297-
poly[0][0] === poly[3][0] &&
298-
poly[1][0] === poly[2][0]
299-
);
300-
301-
if(poly.isRect) {
302-
poly.xmin = Math.min(poly[0][0], poly[2][0]);
303-
poly.xmax = Math.max(poly[0][0], poly[2][0]);
304-
poly.ymin = Math.min(poly[0][1], poly[2][1]);
305-
poly.ymax = Math.max(poly[0][1], poly[2][1]);
306-
}
307285
}
308286

309287
throttle.throttle(
@@ -398,6 +376,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
398376

399377
throttle.done(throttleID).then(function() {
400378
throttle.clear(throttleID);
379+
401380
dragOptions.gd.emit('plotly_selected', eventData);
402381

403382
if(!immediateSelect && currentPolygon && dragOptions.selectionDefs) {
@@ -1149,14 +1128,14 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
11491128
var xref = activePolygons[0].xref;
11501129
var yref = activePolygons[0].yref;
11511130
if(xref && yref) {
1152-
var activePolygon = castMultiPolygon(activePolygons);
1131+
var poly = castMultiPolygon(activePolygons);
11531132

11541133
var fillRangeItems = makeFillRangeItems([
11551134
getFromId(gd, xref, 'x'),
11561135
getFromId(gd, yref, 'y')
11571136
]);
11581137

1159-
fillRangeItems(eventData, activePolygon);
1138+
fillRangeItems(eventData, poly);
11601139
}
11611140

11621141
gd.emit('plotly_selected', eventData);
@@ -1337,7 +1316,35 @@ function castMultiPolygon(allPolygons) {
13371316
// which indicates next polygon
13381317
p = p.concat([polygon[0]]);
13391318
}
1340-
return p;
1319+
1320+
return computeRectAndRanges(p);
1321+
}
1322+
1323+
function computeRectAndRanges(poly) {
1324+
poly.isRect = poly.length === 5 &&
1325+
poly[0][0] === poly[4][0] &&
1326+
poly[0][1] === poly[4][1] &&
1327+
(
1328+
poly[0][0] === poly[1][0] &&
1329+
poly[2][0] === poly[3][0] &&
1330+
poly[0][1] === poly[3][1] &&
1331+
poly[1][1] === poly[2][1]
1332+
) ||
1333+
(
1334+
poly[0][1] === poly[1][1] &&
1335+
poly[2][1] === poly[3][1] &&
1336+
poly[0][0] === poly[3][0] &&
1337+
poly[1][0] === poly[2][0]
1338+
);
1339+
1340+
if(poly.isRect) {
1341+
poly.xmin = Math.min(poly[0][0], poly[2][0]);
1342+
poly.xmax = Math.max(poly[0][0], poly[2][0]);
1343+
poly.ymin = Math.min(poly[0][1], poly[2][1]);
1344+
poly.ymax = Math.max(poly[0][1], poly[2][1]);
1345+
}
1346+
1347+
return poly;
13411348
}
13421349

13431350
function makeFillRangeItems(allAxes) {

0 commit comments

Comments
 (0)