@@ -13,7 +13,6 @@ var d3 = require('d3');
1313
1414var Plotly = require ( '../../plotly' ) ;
1515var Lib = require ( '../../lib' ) ;
16- var setCursor = require ( '../../lib/setcursor' ) ;
1716var Plots = require ( '../../plots/plots' ) ;
1817var dragElement = require ( '../dragelement' ) ;
1918var Drawing = require ( '../drawing' ) ;
@@ -326,38 +325,35 @@ module.exports = function draw(gd) {
326325 }
327326
328327 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 ) ;
335331
336332 dragElement . init ( {
337333 element : legend . node ( ) ,
338334 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 ;
344345 } ,
345346 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 ;
349349
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 ) ;
354352
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 ) ;
358355 } ,
359356 doneFn : function ( dragged ) {
360- setCursor ( legend ) ;
361357 if ( dragged && xf !== undefined && yf !== undefined ) {
362358 Plotly . relayout ( gd , { 'legend.x' : xf , 'legend.y' : yf } ) ;
363359 }
0 commit comments