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

Legend scroll fix #2426

merged 6 commits into from
Mar 1, 2018

Conversation

alexcjohnson
Copy link
Collaborator

Fixes #2387 - don't allow dragging from the scroll box of a legend, only from the scroll bar itself, and even then not on right clicks, only left click. I also made the scroll bar handle a little bit wider so it's a bit easier to grab. And another part of the issue is that the scrollbar would jump to be centered on the mouse cursor, rather than simply moving with it from wherever you grabbed it. I fixed that too.

Fixes the legend part of #1859 - makes the scrollbar scale to show the fraction of the legend that's visible.

cc @etpinard

@alexcjohnson
Copy link
Collaborator Author

Since this doesn't show up in test images, here's what the new scrollbars look like - a little wider and a lot taller:
screen shot 2018-02-28 at 4 21 05 pm

@etpinard
Copy link
Contributor

Fixes the legend part of #1859

Referencing #2054, more than ever it would be nice to unify all our scrollbox implementations.

return finalDataScroll;
}

it('should scroll on dragging the scrollbar', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these general legend scrollbox tests and/or tests that 🔒 the fix for #2387? (I'm asking as I would be surprised if #2387 was reproducible in a jasmine test).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, these do test #2387, if I'm interpreting it correctly. What I think was happening in #2387 is that somehow the scrollBox drag was being triggered - and that's what I decided (with no dissent) had no reason ever to happen. So this test shows that regular drag works, then the next one shows that the scrollBox won't drag even if it does somehow get the event, and then the third new test shows that right-click (the only form of #2387 I could reproduce on my own computer) even on the scrollBar will not trigger drag.

@etpinard
Copy link
Contributor

Probably related to #808. The new variable-height scroll bar doesn't update. For example, from legend_scroll repeatedly calling Plotly.deleteTraces(gd, [0]) gives:

peek 2018-02-28 16-47

No need to fix this in this PR though, just confirming that scrollable legends don't update well as first reported in #808

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.

and when `this` isn't important - ie in all of our helper functions
but we still need `call` for `d3.behavior.drag()`
too confusing with it always being negative
@alexcjohnson
Copy link
Collaborator Author

Fixed #808 (and #2426 (comment)) in 569b378


var scrollBarY = constants.scrollBarMargin;
var scrollBoxY = scrollBox.attr('data-scroll') || 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. Way better to use _ then a DOM attr 🎉

@@ -243,8 +243,7 @@ module.exports = function draw(gd) {
var scrollBoxYMax = opts._height - legendHeight;
var scrollRatio = scrollBarYMax / scrollBoxYMax;

// scrollBoxY is 0 or a negative number
var scrollBoxY = Math.max(opts._scrollY || 0, -scrollBoxYMax);
var scrollBoxY = Math.min(opts._scrollY || 0, scrollBoxYMax);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

@etpinard
Copy link
Contributor

etpinard commented Mar 1, 2018

Amazing PR! 💃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clicking legend item causes legend to scroll
2 participants