Skip to content
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

Legend scroll fix #2426

Merged
merged 6 commits into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 10 additions & 4 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,19 @@ module.exports = function draw(gd) {
scrollBar.on('.drag', null);
scrollBox.on('.drag', null);

var drag = d3.behavior.drag().on('drag', function() {
var e3 = d3.event;
var e = e3.sourceEvent;
var eventY0, scrollBarY0;

var drag = d3.behavior.drag()
.on('dragstart', function() {
eventY0 = d3.event.sourceEvent.clientY;
scrollBarY0 = scrollBarY;
})
.on('drag', function() {
var e = d3.event.sourceEvent;
if(e.buttons === 2 || e.ctrlKey) return;

scrollBarY = Lib.constrain(
e3.y - constants.scrollBarHeight / 2,
e.clientY - eventY0 + scrollBarY0,
constants.scrollBarMargin,
constants.scrollBarMargin + scrollBarYMax);
scrollBoxY = - (scrollBarY - constants.scrollBarMargin) /
Expand Down
9 changes: 5 additions & 4 deletions test/jasmine/tests/legend_scroll_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ describe('The legend', function() {
it('should scroll when there\'s a wheel event', function() {
var legend = getLegend();
var scrollBox = getScrollBox();
var scrollBar = getScrollBar();
var legendHeight = getLegendHeight(gd);
var scrollBoxYMax = gd._fullLayout.legend._height - legendHeight;
var scrollBarYMax = legendHeight -
constants.scrollBarHeight -
scrollBar.getBoundingClientRect().height -
2 * constants.scrollBarMargin;
var initialDataScroll = scrollBox.getAttribute('data-scroll');
var wheelDeltaY = 100;
Expand All @@ -100,19 +101,19 @@ describe('The legend', function() {
function dragScroll(element, rightClick) {
var scrollBox = getScrollBox();
var scrollBar = getScrollBar();
var scrollBarBB = scrollBar.getBoundingClientRect();
var legendHeight = getLegendHeight(gd);
var scrollBoxYMax = gd._fullLayout.legend._height - legendHeight;
var scrollBarYMax = legendHeight -
constants.scrollBarHeight -
scrollBarBB.height -
2 * constants.scrollBarMargin;
var initialDataScroll = scrollBox.getAttribute('data-scroll');
var dy = 50;
var finalDataScroll = '' + Lib.constrain(initialDataScroll -
dy / scrollBarYMax * scrollBoxYMax,
-scrollBoxYMax, 0);

var scrollBarBB = scrollBar.getBoundingClientRect();
var y0 = scrollBarBB.top + scrollBarBB.height / 2;
var y0 = scrollBarBB.top + scrollBarBB.height / 5;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notice that I moved the drag point away from the center of the scrollBar, thereby testing that it drags from where you grab it rather than snapping to the center.

var y1 = y0 + dy;

var elBB = element.getBoundingClientRect();
Expand Down