@@ -361,17 +361,35 @@ function setupDragElement(gd, shapePath, shapeOptions, index) {
361
361
362
362
var xa , ya , x2p , y2p , p2x , p2y ;
363
363
364
- var dragBBox , dragMode ;
365
-
366
364
var dragOptions = {
367
- element : shapePath . node ( ) ,
368
- prepFn : startDrag ,
369
- doneFn : endDrag
370
- } ;
365
+ setCursor : updateDragMode ,
366
+ element : shapePath . node ( ) ,
367
+ prepFn : startDrag ,
368
+ doneFn : endDrag
369
+ } ,
370
+ dragBBox = dragOptions . element . getBoundingClientRect ( ) ,
371
+ dragMode ;
371
372
372
373
dragElement . init ( dragOptions ) ;
373
374
374
- function startDrag ( evt , startX , startY ) {
375
+ function updateDragMode ( evt ) {
376
+ // choose 'move' or 'resize'
377
+ // based on initial position of cursor within the drag element
378
+ var w = dragBBox . right - dragBBox . left ,
379
+ h = dragBBox . bottom - dragBBox . top ,
380
+ x = evt . clientX - dragBBox . left ,
381
+ y = evt . clientY - dragBBox . top ,
382
+ cursor = ( w > MINWIDTH && h > MINHEIGHT ) ?
383
+ dragElement . getCursor ( x / w , 1 - y / h ) :
384
+ 'move' ;
385
+
386
+ setCursor ( shapePath , cursor ) ;
387
+
388
+ // possible values 'move', 'sw', 'w', 'se', 'e', 'ne', 'n', 'nw' and 'w'
389
+ dragMode = cursor . split ( '-' ) [ 0 ] ;
390
+ }
391
+
392
+ function startDrag ( evt ) {
375
393
// setup conversion functions
376
394
xa = Axes . getFromId ( gd , shapeOptions . xref ) ;
377
395
ya = Axes . getFromId ( gd , shapeOptions . yref ) ;
@@ -418,23 +436,8 @@ function setupDragElement(gd, shapePath, shapeOptions, index) {
418
436
419
437
update = { } ;
420
438
421
- // choose 'move' or 'resize'
422
- // based on initial position of cursor within the drag element
423
- dragBBox = dragOptions . element . getBoundingClientRect ( ) ;
424
-
425
- var w = dragBBox . right - dragBBox . left ,
426
- h = dragBBox . bottom - dragBBox . top ,
427
- x = startX - dragBBox . left ,
428
- y = startY - dragBBox . top ,
429
- cursor = ( w > MINWIDTH && h > MINHEIGHT ) ?
430
- dragElement . getCursor ( x / w , 1 - y / h ) :
431
- 'move' ;
432
-
433
- setCursor ( shapePath , cursor ) ;
434
-
435
- // possible values 'move', 'sw', 'w', 'se', 'e', 'ne', 'n', 'nw' and 'w'
436
- dragMode = cursor . split ( '-' ) [ 0 ] ;
437
-
439
+ // setup dragMode and the corresponding handler
440
+ updateDragMode ( evt ) ;
438
441
dragOptions . moveFn = ( dragMode === 'move' ) ? moveShape : resizeShape ;
439
442
}
440
443
0 commit comments