-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
- if margins get larger than 0.5*fullLayout.width, reduce margins instead of setting them to zero! - honors positioning even if legends are large
src/components/legend/draw.js
Outdated
@@ -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); |
There was a problem hiding this comment.
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
)
Can you check what happens with I don't think this needs any new tests added, unless you encounter and fix any weird behavior. |
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! |
Thanks for the update! |
@etpinard Is there any ETA on merging this? 😸 |
Not soon, unfortunately. |
@antoinerg I'll like to bring this PR back to life. Don't worry, I handle all the work 😉 Back in October, you wrote:
Could you elaborate on the "weird behavior" you encountered. I suspect merging master might help. PR #3323 fixed a few "odd" auto-margin scenarios. |
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 |
Ok. Like I said, maybe merging master is all we need to "fix" these issues. |
PR #4160 essentially supersedes this PR here. Ok if we close it? |
Sure! Thanks for taking this on :) |
This PR improves how we deal with:
To achieve this, I made the following changes:
autoMargin
: if margins get larger than half the figure's size, scale down the margins instead of setting them to zero!lx = gs.l;
andly = gs.t;