@@ -151,6 +151,14 @@ const Helpers = {
151
151
} ;
152
152
} ,
153
153
154
+ constrainPoint ( point , fullDomainBox ) {
155
+ const { x1, y1, x2, y2 } = mapValues ( fullDomainBox , Number ) ;
156
+ return {
157
+ x : Math . min ( Math . max ( point . x , x1 ) , x2 ) ,
158
+ y : Math . min ( Math . max ( point . y , y1 ) , y2 )
159
+ } ;
160
+ } ,
161
+
154
162
hasMoved ( props ) {
155
163
const { x1, x2, y1, y2, mouseMoveThreshold } = props ;
156
164
const brushDimension = this . getDimension ( props ) ;
@@ -262,11 +270,7 @@ const Helpers = {
262
270
} ,
263
271
264
272
// eslint-disable-next-line max-statements, complexity
265
- onMouseMove ( evt , targetProps ) {
266
- // if a panning or selection has not been started, ignore the event
267
- if ( ! targetProps . isPanning && ! targetProps . isSelecting ) {
268
- return { } ;
269
- }
273
+ onGlobalMouseMove ( evt , targetProps ) {
270
274
const {
271
275
scale,
272
276
isPanning,
@@ -276,15 +280,13 @@ const Helpers = {
276
280
allowResize,
277
281
allowDrag,
278
282
horizontal,
279
- mouseMoveThreshold
283
+ mouseMoveThreshold,
284
+ parentSVG
280
285
} = targetProps ;
281
286
const brushDimension = this . getDimension ( targetProps ) ;
282
- const parentSVG = targetProps . parentSVG || Selection . getParentSVG ( evt ) ;
283
287
const { x, y } = Selection . getSVGEventCoordinates ( evt , parentSVG ) ;
284
- // Ignore events that occur outside of the maximum domain region
285
288
if (
286
289
( ! allowResize && ! allowDrag ) ||
287
- ! this . withinBounds ( { x, y } , fullDomainBox ) ||
288
290
( mouseMoveThreshold > 0 && ! this . hasMoved ( { ...targetProps , x2 : x , y2 : y } ) )
289
291
) {
290
292
return { } ;
@@ -312,8 +314,13 @@ const Helpers = {
312
314
}
313
315
] ;
314
316
} else if ( allowResize && isSelecting ) {
315
- const x2 = brushDimension !== "y" ? x : targetProps . x2 ;
316
- const y2 = brushDimension !== "x" ? y : targetProps . y2 ;
317
+ const { x : x2 , y : y2 } = this . constrainPoint (
318
+ {
319
+ x : brushDimension !== "y" ? x : targetProps . x2 ,
320
+ y : brushDimension !== "x" ? y : targetProps . y2
321
+ } ,
322
+ fullDomainBox
323
+ ) ;
317
324
const currentDomain = Selection . getBounds ( {
318
325
x2,
319
326
y2,
@@ -337,7 +344,12 @@ const Helpers = {
337
344
return { } ;
338
345
} ,
339
346
340
- onMouseUp ( evt , targetProps ) {
347
+ // eslint-disable-next-line complexity
348
+ onGlobalMouseUp ( evt , targetProps ) {
349
+ // if a panning or selection has not been started, ignore the event
350
+ if ( ! targetProps . isPanning && ! targetProps . isSelecting ) {
351
+ return { } ;
352
+ }
341
353
// eslint-disable-line max-statements, complexity
342
354
const {
343
355
x1,
@@ -384,25 +396,15 @@ const Helpers = {
384
396
mutation : ( ) => mutatedProps
385
397
}
386
398
] ;
387
- } ,
388
-
389
- onMouseLeave ( ) {
390
- return [
391
- {
392
- target : "parent" ,
393
- mutation : ( ) => ( { isPanning : false , isSelecting : false } )
394
- }
395
- ] ;
396
399
}
397
400
} ;
398
401
399
402
export default {
400
403
...Helpers ,
401
404
onMouseDown : Helpers . onMouseDown . bind ( Helpers ) ,
402
- onMouseUp : Helpers . onMouseUp . bind ( Helpers ) ,
403
- onMouseLeave : Helpers . onMouseLeave . bind ( Helpers ) ,
404
- onMouseMove : throttle (
405
- Helpers . onMouseMove . bind ( Helpers ) ,
405
+ onGlobalMouseUp : Helpers . onGlobalMouseUp . bind ( Helpers ) ,
406
+ onGlobalMouseMove : throttle (
407
+ Helpers . onGlobalMouseMove . bind ( Helpers ) ,
406
408
16 , // eslint-disable-line no-magic-numbers
407
409
{ leading : true , trailing : false }
408
410
)
0 commit comments