Skip to content

Commit daadbc5

Browse files
committed
fix for incorrect final position when dragging legend
1 parent a19f685 commit daadbc5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/components/legend/draw.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ function _draw(gd, legendObj) {
308308
}
309309

310310
if(gd._context.edits.legendPosition) {
311-
var xf, yf, x0, y0;
311+
var xf, yf, x0, y0, legend_width, legend_height;
312312

313313
legend.classed('cursor-move', true);
314314

@@ -319,15 +319,17 @@ function _draw(gd, legendObj) {
319319
var transform = Drawing.getTranslate(legend);
320320
x0 = transform.x;
321321
y0 = transform.y;
322+
var bbox = legend.node().getBBox();
323+
legend_width = bbox.width;
324+
legend_height = bbox.height;
322325
},
323326
moveFn: function(dx, dy) {
324327
var newX = x0 + dx;
325328
var newY = y0 + dy;
326329

327330
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);
331333
},
332334
doneFn: function() {
333335
if(xf !== undefined && yf !== undefined) {

0 commit comments

Comments
 (0)