Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9d2db8

Browse files
committed
use mergedPolygons in plotly_selecting event
1 parent 37a664a commit b9d2db8

File tree

1 file changed

+46
-15
lines changed

1 file changed

+46
-15
lines changed

src/components/selections/select.js

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,35 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
277277
selectionTesters = _res.selectionTesters;
278278
eventData = _res.eventData;
279279

280+
var poly;
281+
if(filterPoly) {
282+
poly = filterPoly.filtered;
283+
} else {
284+
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+
}
307+
}
308+
280309
throttle.throttle(
281310
throttleID,
282311
constants.SELECTDELAY,
@@ -285,13 +314,6 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
285314

286315
eventData = {points: selection};
287316

288-
var poly;
289-
if(filterPoly) {
290-
poly = filterPoly.filtered;
291-
} else {
292-
poly = currentPolygon;
293-
poly.isRect = selectionTesters.isRect;
294-
}
295317
fillRangeItems(eventData, poly);
296318

297319
dragOptions.gd.emit('plotly_selecting', eventData);
@@ -1127,14 +1149,7 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
11271149
var xref = activePolygons[0].xref;
11281150
var yref = activePolygons[0].yref;
11291151
if(xref && yref) {
1130-
var activePolygon = activePolygons[0];
1131-
// handle active shape with multiple polygons
1132-
for(var n = 1; n < activePolygons.length; n++) {
1133-
// close previous polygon
1134-
activePolygon.push(activePolygon[0]);
1135-
// add this polygon
1136-
activePolygon = activePolygon.concat(activePolygons[n]);
1137-
}
1152+
var activePolygon = castMultiPolygon(activePolygons);
11381153

11391154
var fillRangeItems = makeFillRangeItems([
11401155
getFromId(gd, xref, 'x'),
@@ -1309,6 +1324,22 @@ function convert(ax, d) {
13091324
return ax.type === 'log' ? ax.c2p(d) : ax.r2p(d, null, ax.calendar);
13101325
}
13111326

1327+
function castMultiPolygon(allPolygons) {
1328+
var len = allPolygons.length;
1329+
1330+
// descibe multi polygons in one polygon
1331+
var p = [];
1332+
for(var i = 0; i < len; i++) {
1333+
var polygon = allPolygons[i];
1334+
p = p.concat(polygon);
1335+
1336+
// add starting vertex to close
1337+
// which indicates next polygon
1338+
p = p.concat([polygon[0]]);
1339+
}
1340+
return p;
1341+
}
1342+
13121343
function makeFillRangeItems(allAxes) {
13131344
return function(eventData, poly) {
13141345
var range;

0 commit comments

Comments
 (0)