@@ -277,6 +277,35 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
277
277
selectionTesters = _res . selectionTesters ;
278
278
eventData = _res . eventData ;
279
279
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
+
280
309
throttle . throttle (
281
310
throttleID ,
282
311
constants . SELECTDELAY ,
@@ -285,13 +314,6 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
285
314
286
315
eventData = { points : selection } ;
287
316
288
- var poly ;
289
- if ( filterPoly ) {
290
- poly = filterPoly . filtered ;
291
- } else {
292
- poly = currentPolygon ;
293
- poly . isRect = selectionTesters . isRect ;
294
- }
295
317
fillRangeItems ( eventData , poly ) ;
296
318
297
319
dragOptions . gd . emit ( 'plotly_selecting' , eventData ) ;
@@ -1127,14 +1149,7 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
1127
1149
var xref = activePolygons [ 0 ] . xref ;
1128
1150
var yref = activePolygons [ 0 ] . yref ;
1129
1151
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 ) ;
1138
1153
1139
1154
var fillRangeItems = makeFillRangeItems ( [
1140
1155
getFromId ( gd , xref , 'x' ) ,
@@ -1309,6 +1324,22 @@ function convert(ax, d) {
1309
1324
return ax . type === 'log' ? ax . c2p ( d ) : ax . r2p ( d , null , ax . calendar ) ;
1310
1325
}
1311
1326
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
+
1312
1343
function makeFillRangeItems ( allAxes ) {
1313
1344
return function ( eventData , poly ) {
1314
1345
var range ;
0 commit comments