Skip to content

Commit c503634

Browse files
authored
Merge pull request #6997 from OpportunityLiu/fix/legend-scrollbar
Fix drag on legend scrollbar while `edits.legendPosition` is `true`
2 parents 8b09892 + c40b180 commit c503634

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

draftlogs/6997_fix.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Fix drag on legend scrollbar while `edits.legendPosition` is `true` [[#6997](https://github.com/plotly/plotly.js/pull/6997)],
2+
with thanks to @OpportunityLiu for the contribution!

src/components/legend/draw.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -423,18 +423,23 @@ function drawOne(gd, opts) {
423423
dragElement.init({
424424
element: legend.node(),
425425
gd: gd,
426-
prepFn: function() {
426+
prepFn: function(e) {
427+
if(e.target === scrollBar.node()) {
428+
return;
429+
}
427430
var transform = Drawing.getTranslate(legend);
428431
x0 = transform.x;
429432
y0 = transform.y;
430433
},
431434
moveFn: function(dx, dy) {
432-
var newX = x0 + dx;
433-
var newY = y0 + dy;
435+
if(x0 !== undefined && y0 !== undefined) {
436+
var newX = x0 + dx;
437+
var newY = y0 + dy;
434438

435-
Drawing.setTranslate(legend, newX, newY);
436-
xf = dragElement.align(newX, legendObj._width, gs.l, gs.l + gs.w, legendObj.xanchor);
437-
yf = dragElement.align(newY + legendObj._height, -legendObj._height, gs.t + gs.h, gs.t, legendObj.yanchor);
439+
Drawing.setTranslate(legend, newX, newY);
440+
xf = dragElement.align(newX, legendObj._width, gs.l, gs.l + gs.w, legendObj.xanchor);
441+
yf = dragElement.align(newY + legendObj._height, -legendObj._height, gs.t + gs.h, gs.t, legendObj.yanchor);
442+
}
438443
},
439444
doneFn: function() {
440445
if(xf !== undefined && yf !== undefined) {

0 commit comments

Comments
 (0)