@@ -383,27 +383,44 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer, editHe
383
383
removeVisualCues ( shapeLayer ) ;
384
384
}
385
385
386
- function moveShape ( dx , dy ) {
387
- if ( shapeOptions . type === 'path' ) {
388
- var noOp = function ( coord ) { return coord ; } ;
389
- var moveX = noOp ;
390
- var moveY = noOp ;
386
+ // Compute moveX or moveY, ax is xa or ya, p2xy is p2x or p2y, xy2p is x2p
387
+ // or y2p, dxy is dx or dy
388
+ function computeMove ( ax , p2xy , xy2p , dxy ) {
389
+ var move = function ( xy ) { return p2xy ( xy2p ( xy ) + dxy ) ; } ;
390
+ if ( ax && ax . type === 'date' ) {
391
+ move = helpers . encodeDate ( move ) ;
392
+ }
393
+ if ( ax && ax . type === 'category' ) {
394
+ move = function ( xy ) {
395
+ return p2xy ( helpers . castNumericStringsToNumbers ( xy2p ) ( xy ) + dxy ) ;
396
+ } ;
397
+ }
398
+ return move ;
399
+ }
391
400
392
- if ( xPixelSized ) {
393
- modifyItem ( 'xanchor' , shapeOptions . xanchor = p2x ( xAnchor + dx ) ) ;
394
- } else {
395
- moveX = function moveX ( x ) { return p2x ( x2p ( x ) + dx ) ; } ;
396
- if ( xa && xa . type === 'date' ) moveX = helpers . encodeDate ( moveX ) ;
397
- }
401
+ function doPathMoveOrResize ( dx , dy ) {
402
+ var noOp = function ( coord ) { return coord ; } ;
403
+ var moveX = noOp ;
404
+ var moveY = noOp ;
398
405
399
- if ( yPixelSized ) {
400
- modifyItem ( 'yanchor' , shapeOptions . yanchor = p2y ( yAnchor + dy ) ) ;
401
- } else {
402
- moveY = function moveY ( y ) { return p2y ( y2p ( y ) + dy ) ; } ;
403
- if ( ya && ya . type === 'date' ) moveY = helpers . encodeDate ( moveY ) ;
404
- }
406
+ if ( xPixelSized ) {
407
+ modifyItem ( 'xanchor' , shapeOptions . xanchor = p2x ( xAnchor + dx ) ) ;
408
+ } else {
409
+ moveX = computeMove ( xa , p2x , x2p , dx ) ;
410
+ }
411
+
412
+ if ( yPixelSized ) {
413
+ modifyItem ( 'yanchor' , shapeOptions . yanchor = p2y ( yAnchor + dy ) ) ;
414
+ } else {
415
+ moveY = computeMove ( ya , p2y , y2p , dy ) ;
416
+ }
417
+
418
+ modifyItem ( 'path' , shapeOptions . path = movePath ( pathIn , moveX , moveY ) ) ;
419
+ }
405
420
406
- modifyItem ( 'path' , shapeOptions . path = movePath ( pathIn , moveX , moveY ) ) ;
421
+ function moveShape ( dx , dy ) {
422
+ if ( shapeOptions . type === 'path' ) {
423
+ doPathMoveOrResize ( dx , dy ) ;
407
424
} else {
408
425
if ( xPixelSized ) {
409
426
modifyItem ( 'xanchor' , shapeOptions . xanchor = p2x ( xAnchor + dx ) ) ;
@@ -426,26 +443,7 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer, editHe
426
443
427
444
function resizeShape ( dx , dy ) {
428
445
if ( isPath ) {
429
- // TODO: implement path resize, don't forget to update dragMode code
430
- var noOp = function ( coord ) { return coord ; } ;
431
- var moveX = noOp ;
432
- var moveY = noOp ;
433
-
434
- if ( xPixelSized ) {
435
- modifyItem ( 'xanchor' , shapeOptions . xanchor = p2x ( xAnchor + dx ) ) ;
436
- } else {
437
- moveX = function moveX ( x ) { return p2x ( x2p ( x ) + dx ) ; } ;
438
- if ( xa && xa . type === 'date' ) moveX = helpers . encodeDate ( moveX ) ;
439
- }
440
-
441
- if ( yPixelSized ) {
442
- modifyItem ( 'yanchor' , shapeOptions . yanchor = p2y ( yAnchor + dy ) ) ;
443
- } else {
444
- moveY = function moveY ( y ) { return p2y ( y2p ( y ) + dy ) ; } ;
445
- if ( ya && ya . type === 'date' ) moveY = helpers . encodeDate ( moveY ) ;
446
- }
447
-
448
- modifyItem ( 'path' , shapeOptions . path = movePath ( pathIn , moveX , moveY ) ) ;
446
+ doPathMoveOrResize ( dx , dy ) ;
449
447
} else if ( isLine ) {
450
448
if ( dragMode === 'resize-over-start-point' ) {
451
449
var newX0 = x0 + dx ;
0 commit comments