@@ -308,7 +308,7 @@ function _draw(gd, legendObj) {
308
308
}
309
309
310
310
if ( gd . _context . edits . legendPosition ) {
311
- var xf , yf , x0 , y0 ;
311
+ var xf , yf , x0 , y0 , legend_width , legend_height ;
312
312
313
313
legend . classed ( 'cursor-move' , true ) ;
314
314
@@ -319,15 +319,17 @@ function _draw(gd, legendObj) {
319
319
var transform = Drawing . getTranslate ( legend ) ;
320
320
x0 = transform . x ;
321
321
y0 = transform . y ;
322
+ var bbox = legend . node ( ) . getBBox ( ) ;
323
+ legend_width = bbox . width ;
324
+ legend_height = bbox . height ;
322
325
} ,
323
326
moveFn : function ( dx , dy ) {
324
327
var newX = x0 + dx ;
325
328
var newY = y0 + dy ;
326
329
327
330
Drawing . setTranslate ( legend , newX , newY ) ;
328
-
329
- xf = dragElement . align ( newX , 0 , gs . l , gs . l + gs . w , legendObj . xanchor ) ;
330
- yf = dragElement . align ( newY , 0 , gs . t + gs . h , gs . t , legendObj . yanchor ) ;
331
+ xf = dragElement . align ( newX , legend_width , gs . l , gs . l + gs . w , legendObj . xanchor ) ;
332
+ yf = dragElement . align ( newY + legend_height , - legend_height , gs . t + gs . h , gs . t , legendObj . yanchor ) ;
331
333
} ,
332
334
doneFn : function ( ) {
333
335
if ( xf !== undefined && yf !== undefined ) {
0 commit comments