@@ -13,7 +13,6 @@ var d3 = require('d3');
13
13
14
14
var Plotly = require ( '../../plotly' ) ;
15
15
var Lib = require ( '../../lib' ) ;
16
- var setCursor = require ( '../../lib/setcursor' ) ;
17
16
var Plots = require ( '../../plots/plots' ) ;
18
17
var dragElement = require ( '../dragelement' ) ;
19
18
var Drawing = require ( '../drawing' ) ;
@@ -321,38 +320,35 @@ module.exports = function draw(gd) {
321
320
}
322
321
323
322
if ( gd . _context . editable ) {
324
- var xf ,
325
- yf ,
326
- x0 ,
327
- y0 ,
328
- lw ,
329
- lh ;
323
+ var xf , yf , x0 , y0 ;
324
+
325
+ legend . classed ( 'cursor-move' , true ) ;
330
326
331
327
dragElement . init ( {
332
328
element : legend . node ( ) ,
333
329
prepFn : function ( ) {
334
- x0 = Number ( legend . attr ( 'x' ) ) ;
335
- y0 = Number ( legend . attr ( 'y' ) ) ;
336
- lw = Number ( legend . attr ( 'width' ) ) ;
337
- lh = Number ( legend . attr ( 'height' ) ) ;
338
- setCursor ( legend ) ;
330
+ // regex pattern for 'translate(123.45px, 543.21px)'
331
+ var re = / ( .* \( ) ( \d * \. ? \d * ) ( [ ^ \d ] * ) ( \d * \. ? \d * ) ( [ ^ \d ] * ) / ,
332
+ transform = legend . attr ( 'transform' )
333
+ . replace ( re , function ( match , p1 , p2 , p3 , p4 ) {
334
+ return [ p2 , p4 ] . join ( ' ' ) ;
335
+ } )
336
+ . split ( ' ' ) ;
337
+
338
+ x0 = + transform [ 0 ] || 0 ;
339
+ y0 = + transform [ 1 ] || 0 ;
339
340
} ,
340
341
moveFn : function ( dx , dy ) {
341
- var gs = gd . _fullLayout . _size ;
342
-
343
- legend . call ( Drawing . setPosition , x0 + dx , y0 + dy ) ;
342
+ var newX = x0 + dx ,
343
+ newY = y0 + dy ;
344
344
345
- xf = dragElement . align ( x0 + dx , lw , gs . l , gs . l + gs . w ,
346
- opts . xanchor ) ;
347
- yf = dragElement . align ( y0 + dy + lh , - lh , gs . t + gs . h , gs . t ,
348
- opts . yanchor ) ;
345
+ var transform = 'translate(' + newX + ', ' + newY + ')' ;
346
+ legend . attr ( 'transform' , transform ) ;
349
347
350
- var csr = dragElement . getCursor ( xf , yf ,
351
- opts . xanchor , opts . yanchor ) ;
352
- setCursor ( legend , csr ) ;
348
+ xf = dragElement . align ( newX , 0 , gs . l , gs . l + gs . w , opts . xanchor ) ;
349
+ yf = dragElement . align ( newY , 0 , gs . t + gs . h , gs . t , opts . yanchor ) ;
353
350
} ,
354
351
doneFn : function ( dragged ) {
355
- setCursor ( legend ) ;
356
352
if ( dragged && xf !== undefined && yf !== undefined ) {
357
353
Plotly . relayout ( gd , { 'legend.x' : xf , 'legend.y' : yf } ) ;
358
354
}
0 commit comments