@@ -117,17 +117,16 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
117
117
fillRangeItems = plotinfo . fillRangeItems ;
118
118
} else {
119
119
if ( mode === 'select' ) {
120
- fillRangeItems = function ( eventData , currentPolygon ) {
120
+ fillRangeItems = function ( eventData , poly ) {
121
121
var ranges = eventData . range = { } ;
122
122
123
123
for ( i = 0 ; i < allAxes . length ; i ++ ) {
124
124
var ax = allAxes [ i ] ;
125
125
var axLetter = ax . _id . charAt ( 0 ) ;
126
- var x = axLetter === 'x' ;
127
126
128
127
ranges [ ax . _id ] = [
129
- ax . p2d ( currentPolygon [ 0 ] [ x ? 0 : 1 ] ) ,
130
- ax . p2d ( currentPolygon [ 2 ] [ x ? 0 : 1 ] )
128
+ ax . p2d ( poly [ axLetter + 'min' ] ) ,
129
+ ax . p2d ( poly [ axLetter + 'max' ] )
131
130
] . sort ( ascending ) ;
132
131
}
133
132
} ;
@@ -154,6 +153,10 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
154
153
if ( dy < Math . min ( dx * 0.6 , MINSELECT ) ) {
155
154
// horizontal motion: make a vertical box
156
155
currentPolygon = [ [ x0 , 0 ] , [ x0 , ph ] , [ x1 , ph ] , [ x1 , 0 ] ] ;
156
+ currentPolygon . xmin = Math . min ( x0 , x1 ) ;
157
+ currentPolygon . xmax = Math . max ( x0 , x1 ) ;
158
+ currentPolygon . ymin = Math . min ( 0 , ph ) ;
159
+ currentPolygon . ymax = Math . max ( 0 , ph ) ;
157
160
// extras to guide users in keeping a straight selection
158
161
corners . attr ( 'd' , 'M' + Math . min ( x0 , x1 ) + ',' + ( y0 - MINSELECT ) +
159
162
'h-4v' + ( 2 * MINSELECT ) + 'h4Z' +
@@ -164,6 +167,10 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
164
167
else if ( dx < Math . min ( dy * 0.6 , MINSELECT ) ) {
165
168
// vertical motion: make a horizontal box
166
169
currentPolygon = [ [ 0 , y0 ] , [ 0 , y1 ] , [ pw , y1 ] , [ pw , y0 ] ] ;
170
+ currentPolygon . xmin = Math . min ( 0 , pw ) ;
171
+ currentPolygon . xmax = Math . max ( 0 , pw ) ;
172
+ currentPolygon . ymin = Math . min ( y0 , y1 ) ;
173
+ currentPolygon . ymax = Math . max ( y0 , y1 ) ;
167
174
corners . attr ( 'd' , 'M' + ( x0 - MINSELECT ) + ',' + Math . min ( y0 , y1 ) +
168
175
'v-4h' + ( 2 * MINSELECT ) + 'v4Z' +
169
176
'M' + ( x0 - MINSELECT ) + ',' + ( Math . max ( y0 , y1 ) - 1 ) +
@@ -172,6 +179,10 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
172
179
else {
173
180
// diagonal motion
174
181
currentPolygon = [ [ x0 , y0 ] , [ x0 , y1 ] , [ x1 , y1 ] , [ x1 , y0 ] ] ;
182
+ currentPolygon . xmin = Math . min ( x0 , x1 ) ;
183
+ currentPolygon . xmax = Math . max ( x0 , x1 ) ;
184
+ currentPolygon . ymin = Math . min ( y0 , y1 ) ;
185
+ currentPolygon . ymax = Math . max ( y0 , y1 ) ;
175
186
corners . attr ( 'd' , 'M0,0Z' ) ;
176
187
}
177
188
}
@@ -181,7 +192,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
181
192
}
182
193
183
194
// create outline & tester
184
- if ( dragOptions . polygons . length ) {
195
+ if ( dragOptions . polygons && dragOptions . polygons . length ) {
185
196
mergedPolygons = polybool ( dragOptions . mergedPolygons , [ currentPolygon ] , 'or' ) ;
186
197
testPoly = multipolygonTester ( dragOptions . polygons . concat ( [ currentPolygon ] ) ) ;
187
198
}
@@ -231,6 +242,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
231
242
232
243
dragOptions . doneFn = function ( dragged , numclicks ) {
233
244
corners . remove ( ) ;
245
+
234
246
throttle . done ( throttleID ) . then ( function ( ) {
235
247
throttle . clear ( throttleID ) ;
236
248
@@ -248,11 +260,13 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
248
260
dragOptions . gd . emit ( 'plotly_selected' , eventData ) ;
249
261
}
250
262
251
- // save last polygons
252
- dragOptions . polygons . push ( currentPolygon ) ;
263
+ if ( currentPolygon && dragOptions . polygons ) {
264
+ // save last polygons
265
+ dragOptions . polygons . push ( currentPolygon ) ;
253
266
254
- // we have to keep reference to arrays, therefore just replace items
255
- dragOptions . mergedPolygons . splice . apply ( dragOptions . mergedPolygons , [ 0 , dragOptions . mergedPolygons . length ] . concat ( mergedPolygons ) ) ;
267
+ // we have to keep reference to arrays, therefore just replace items
268
+ dragOptions . mergedPolygons . splice . apply ( dragOptions . mergedPolygons , [ 0 , dragOptions . mergedPolygons . length ] . concat ( mergedPolygons ) ) ;
269
+ }
256
270
} ) ;
257
271
} ;
258
272
} ;
0 commit comments