Skip to content

fix for incorrect final position when dragging legend #6528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/6528_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- fix dragging of legend when xanchor is not 'left' or yanchor is not 'top' [[#6528](https://github.com/plotly/plotly.js/pull/6528)]
9 changes: 5 additions & 4 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ function _draw(gd, legendObj) {
}

if(gd._context.edits.legendPosition) {
var xf, yf, x0, y0;
var xf, yf, x0, y0, legendWidth, legendHeight;

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

Expand All @@ -319,15 +319,16 @@ function _draw(gd, legendObj) {
var transform = Drawing.getTranslate(legend);
x0 = transform.x;
y0 = transform.y;
legendWidth = legendObj._width;
legendHeight = legendObj._height;
},
moveFn: function(dx, dy) {
var newX = x0 + dx;
var newY = y0 + dy;

Drawing.setTranslate(legend, newX, newY);

xf = dragElement.align(newX, 0, gs.l, gs.l + gs.w, legendObj.xanchor);
yf = dragElement.align(newY, 0, gs.t + gs.h, gs.t, legendObj.yanchor);
xf = dragElement.align(newX, legendWidth, gs.l, gs.l + gs.w, legendObj.xanchor);
yf = dragElement.align(newY + legendHeight, -legendHeight, gs.t + gs.h, gs.t, legendObj.yanchor);
},
doneFn: function() {
if(xf !== undefined && yf !== undefined) {
Expand Down