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