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

WIP: Legend Scrolling #243

Merged
merged 28 commits into from
Feb 22, 2016
Merged

WIP: Legend Scrolling #243

merged 28 commits into from
Feb 22, 2016

Conversation

mdtusz
Copy link
Contributor

@mdtusz mdtusz commented Feb 8, 2016

There's still a bug or two to work out, but it's in a working state.

When you toggle a trace for the first time, the width changes and hides the scrollbar until you scroll (for some reason the text-width is being changed when you toggle for the first time).

Otherwise, it will automatically enable the scroll if the height of the list of traces is greater than the height of the plot. I need to add a check whether the scrollbar will be inserted and rework the details on what sets the bounds, but the main logic is there.

.call(Plotly.Drawing.setRect, borderwidth/2, borderwidth/2,
legendwidth-borderwidth, legendheight-borderwidth);

var legendsvg = fullLayout._infolayer.selectAll('svg.legend'),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This section should likely be moved to the draw step, but everything is highly coupled right now and the order of drawing/sizing/positioning is very scattered.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mdtusz Any reason for putting this section in repostionLegend in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mainly for ease of development. The scroll handler requires the final height of the legend to calculate the viewbox offset and at the time, I was still trying to wrap my head around the control flow in here.

It will be moved out into draw before we merge though

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for the info. 👍

@etpinard
Copy link
Contributor

etpinard commented Feb 9, 2016

@mdtusz This PR is looking great.

To add some background info (cc @alexcjohnson @cldougl):

  • Adding legend scroll brings in another nested <svg>, though it can be easily extracted in the to-image step if we like.
  • The viewbox height will be computed via the plot's height and vertical margin. Down the road, we'll make that height configurable via an attribute, but not in this PR.
  • Features like the scroll bar dimensions and colour could also be associated to attributes in future development.

@cldougl
Copy link
Member

cldougl commented Feb 9, 2016

  • The viewbox height will be computed via the plot's height and vertical margin. Down the road, we'll make that height configurable via an attribute, but not in this PR.

Pretty nice that this is dynamically computed now even cooler it will be configurable in the future 🎆

@alexcjohnson
Copy link
Collaborator

Can we get away from adding another nested svg, and do it with <g clip-path=...> instead? @jackparmer forwarded me another complaint about illustrator compatibility just last night. I started down that road with shapes (clipping to axes) and contours with missing data (which wouldn't have been possible at all otherwise as it's non-rectangular clipping). See drawing.setClipUrl. It probably wouldn't be very hard to axe ALL nested svgs right now, but we should at least not be adding new ones.

@mdtusz
Copy link
Contributor Author

mdtusz commented Feb 10, 2016

I'm not sure the best way how we could easily do this with a clip path - the reason it works now is because of the shifting viewBox. As far as I understand, with a clip-path, we'd need to have the clip-path coordinates shift, as well as an opposing shift of the element containing the legend items. I.e. legend items moves up while clip-path on it moves down to make the apparent legend box look stationary.

This could/would work, but I imagine the scrolling would appear janky because of the moving outer element - having the movements be perfectly in sync would likely be hard to achieve.

@alexcjohnson
Copy link
Collaborator

If you make a <g> with clipping and put another <g> inside it with a shifting transform, the clip path should not need to change. This is basically what happens to shapes when you drag an axis - though there I probably change its path rather than its transform, but the idea is the same.

@alexcjohnson
Copy link
Collaborator

having the movements be perfectly in sync would likely be hard to achieve.

Not an issue here because you can do it with a single transform... but as far as I've seen, browsers will not repaint during synchronous js execution. This is in fact the primary motivation behind syncOrAsync, so we can chain things that may or may not contain async parts without making every link in the chain async. That way when you are sync there are no intermediate flashes.

@mdtusz
Copy link
Contributor Author

mdtusz commented Feb 10, 2016

Yep, I played around and have gotten it to work using a <g> instead of the scrollBox <svg>, but if we want to change the pre-existing legendsvg to a <g> as well, we will need to rewrite a fair amount of positioning code - <g> elements don't have width, height, x, or y attributes to them unfortunately.

@alexcjohnson
Copy link
Collaborator

I mainly wanted to avoid making the nested svg problem worse... so I won't complain if you leave it at that. But I suspect it wouldn't be that hard: x and y --> transform=translate(x,y), and width and height --> clipPath width and height. Granted a lot of ugly math could probably be cleaned up with a more substantial rewrite...

Up to @jackparmer how much he wants Illustrator compatibility, people have been complaining about it forever but at a low level.


function mMove(e) {
if(e.buttons === 1){
scrollHandler(e.movementY);
Copy link
Contributor

Choose a reason for hiding this comment

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

This felt a little a crude on my laptop.

The mouse wheel scaling is very smooth though 👍

@mdtusz
Copy link
Contributor Author

mdtusz commented Feb 19, 2016

For archival reasons, I'll mention that this PR will fix #251.

@etpinard
Copy link
Contributor

💃

@mdtusz
Copy link
Contributor Author

mdtusz commented Feb 22, 2016

FINALLY!

mdtusz added a commit that referenced this pull request Feb 22, 2016
@mdtusz mdtusz merged commit d430e30 into master Feb 22, 2016
@mdtusz mdtusz deleted the dropdown-filter branch February 22, 2016 21:35
@jackparmer
Copy link
Contributor

BOOM! 💥

On Mon, Feb 22, 2016 at 4:34 PM, Miklos Tusz notifications@github.com
wrote:

Merged #243 #243.


Reply to this email directly or view it on GitHub
#243 (comment).

@arikfr
Copy link

arikfr commented Feb 23, 2016

Best thing since open sourcing plotly.js :-) 🎉
Thanks!

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

Successfully merging this pull request may close these issues.

7 participants