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

improve legend positioning in edge cases #3024

Closed
wants to merge 2 commits into from

Conversation

antoinerg
Copy link
Contributor

This PR improves how we deal with:

To achieve this, I made the following changes:

  • in autoMargin: if margins get larger than half the figure's size, scale down the margins instead of setting them to zero!
  • honors positioning even if legends are large by removing lines lx = gs.l; and ly = gs.t;

- if margins get larger than 0.5*fullLayout.width, reduce margins instead of setting them to zero!
- honors positioning even if legends are large
@antoinerg
Copy link
Contributor Author

cc @alexcjohnson @etpinard

@@ -170,10 +170,9 @@ module.exports = function draw(gd) {

// Make sure the legend left and right sides are visible
var legendWidth = opts._width,
legendWidthMax = gs.w;
legendWidthMax = gs.w * Math.max(1 - opts.x, 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This calculation makes sense for the (default) xanchor: 'left' - seems like there's something similar for 'right' like * Math.max(opts.x, 1), not sure what it should look like for 'center', and 'auto' should presumably depend on which alignment it auto-chose.

(and similarly with legendHeightMax and yanchor)

@alexcjohnson
Copy link
Collaborator

Can you check what happens with config: {editable: true} when you drag the legend around and bump up against these various limits? Does the legend end up where you expected after you drop it? Is it ever possible to drag it totally off the edge and lose it (cc #2940)? If you're in one of these situations (esp. off the edge where the legend has increased the margin) and you drag it just a few pixels, is the result always a small change in the expected direction or does it jump one way or another?

I don't think this needs any new tests added, unless you encounter and fix any weird behavior.

@antoinerg
Copy link
Contributor Author

As you know, I encountered some weird behavior and I will need to better spec out how legend positioning/sizing should be handled to submit a solid PR. To be continued!

@etpinard
Copy link
Contributor

To be continued!

Thanks for the update!

@Braintelligence
Copy link

@etpinard Is there any ETA on merging this? 😸

@etpinard
Copy link
Contributor

Not soon, unfortunately.

@etpinard
Copy link
Contributor

@antoinerg I'll like to bring this PR back to life. Don't worry, I handle all the work 😉

Back in October, you wrote:

I encountered some weird behavior and I will need to better spec out how legend positioning/sizing should be handled to submit a solid PR

Could you elaborate on the "weird behavior" you encountered. I suspect merging master might help. PR #3323 fixed a few "odd" auto-margin scenarios.

@antoinerg
Copy link
Contributor Author

I would have to refresh my memory. I do remember however having troubles with drag and dropping the legend in a new position. Once dropped, it would drastically change position.

Let me get back to you on this one

@etpinard
Copy link
Contributor

. I do remember however having troubles with drag and dropping the legend in a new position.

Ok. Like I said, maybe merging master is all we need to "fix" these issues.

@etpinard
Copy link
Contributor

PR #4160 essentially supersedes this PR here. Ok if we close it?

@antoinerg
Copy link
Contributor Author

PR #4160 essentially supersedes this PR here. Ok if we close it?

Sure! Thanks for taking this on :)

@antoinerg antoinerg closed this Aug 30, 2019
@etpinard etpinard deleted the 2337-fix-legend-position branch September 23, 2019 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
4 participants