Skip to content

Commit 3e2b0ac

Browse files
authored
Merge pull request #7067 from Lexachoc/fix_legend_scroll
fix wrong scrollBoxY value for legend scroll
2 parents 6e7b128 + 7c5053e commit 3e2b0ac

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

draftlogs/7067_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix wrong scrolling behavior for legend [[#7067](https://github.com/plotly/plotly.js/pull/7067)]

src/components/legend/draw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ function drawOne(gd, opts) {
337337
legend.on('wheel', function() {
338338
scrollBoxY = Lib.constrain(
339339
legendObj._scrollY +
340-
((d3.event.deltaY / scrollBarYMax) * scrollBoxYMax),
340+
((d3.event.deltaY / scrollBoxYMax) * scrollBarYMax),
341341
0, scrollBoxYMax);
342342
scrollHandler(scrollBoxY, scrollBarHeight, scrollRatio);
343343
if(scrollBoxY !== 0 && scrollBoxY !== scrollBoxYMax) {

test/jasmine/tests/legend_scroll_test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,15 @@ describe('The legend', function() {
101101
var initialDataScroll = getScroll(gd);
102102
var wheelDeltaY = 100;
103103
var finalDataScroll = Lib.constrain(initialDataScroll +
104-
wheelDeltaY / scrollBarYMax * scrollBoxYMax,
104+
((wheelDeltaY / scrollBoxYMax) * scrollBarYMax),
105105
0, scrollBoxYMax);
106106

107107
legend.dispatchEvent(scrollTo(wheelDeltaY));
108-
109-
expect(getScroll(gd)).toBe(finalDataScroll);
108+
109+
var dataScroll = getScroll(gd);
110+
expect(dataScroll).toBeCloseTo(finalDataScroll, 3);
110111
expect(scrollBox.getAttribute('transform')).toBe(
111-
'translate(0,' + -finalDataScroll + ')');
112+
'translate(0,' + -dataScroll + ')');
112113
});
113114

114115
function dragScroll(element, rightClick, mainClick) {

0 commit comments

Comments
 (0)