-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix legend container overflow #7158
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
Open
attatrol
wants to merge
15
commits into
plotly:master
Choose a base branch
from
attatrol:fix-legend-container-overflow
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+223
−21
Open
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5757a02
Fix legend size calculations when it is anchored to container.
d5e9935
Add draftlog for PR 7072
1fc4266
Code formatting.
68980a4
Calculate flags isBelowPlotArea/isAbovePlotArea when legend yref is c…
1d5aea2
Update draftlogs/7072-fix.md
archmoj 5be7cec
Merge remote-tracking branch 'origin/master' into fix-legend-containe…
camdecoster 4a1119a
Update block to handle user specified maxheight
camdecoster 737ae2a
Merge remote-tracking branch 'origin/master' into pr/7249
alexshoe e6732be
Reduce variable repetition and simplify logic
alexshoe 7a6e064
Add image mock for testing the bug fix
alexshoe 76b6ce6
Fix linting error using `biome`
alexshoe ba666af
Add baseline image for new mock
alexshoe 30590f0
Merge branch 'master' into pr/7158
alexshoe 9dd1b48
Add CircleCI generated baseline images
alexshoe 5be429b
Improve logic and readability for legend height calculation
alexshoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix maximum dimensions for legend that is anchored to container [[#7072](https://github.com/plotly/plotly.js/pull/7072)] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -774,18 +774,32 @@ function computeLegendDimensions(gd, groups, traces, legendObj) { | |
| var endPad = 2 * (bw + itemGap); | ||
|
|
||
| var yanchor = getYanchor(legendObj); | ||
| var isBelowPlotArea = legendObj.y < 0 || (legendObj.y === 0 && yanchor === 'top'); | ||
| var isAbovePlotArea = legendObj.y > 1 || (legendObj.y === 1 && yanchor === 'bottom'); | ||
| var isBelowPlotArea; | ||
| var isAbovePlotArea; | ||
|
|
||
| var traceGroupGap = legendObj.tracegroupgap; | ||
| var legendGroupWidths = {}; | ||
|
|
||
| // - if below/above plot area, give it the maximum potential margin-push value | ||
| // - otherwise, extend the height of the plot area | ||
| legendObj._maxHeight = Math.max( | ||
| (isBelowPlotArea || isAbovePlotArea) ? fullLayout.height / 2 : gs.h, | ||
| 30 | ||
| ); | ||
| if(legendObj.yref === 'paper') { | ||
| isBelowPlotArea = legendObj.y < 0 || (legendObj.y === 0 && yanchor === 'top'); | ||
| isAbovePlotArea = legendObj.y > 1 || (legendObj.y === 1 && yanchor === 'bottom'); | ||
| // - if below/above plot area, give it the maximum potential margin-push value | ||
| // - otherwise, extend the height of the plot area | ||
| legendObj._maxHeight = Math.max( | ||
| (isBelowPlotArea || isAbovePlotArea) ? fullLayout.height / 2 : gs.h, | ||
| 30 | ||
| ); | ||
| } else { | ||
| isBelowPlotArea = legendObj.y * fullLayout.height < gs.b || (legendObj.y * fullLayout.height === gs.b && yanchor === 'top'); | ||
| isAbovePlotArea = legendObj.y * fullLayout.height > gs.b + gs.h || (legendObj.y * fullLayout.height === gs.b + gs.h && yanchor === 'bottom'); | ||
| if(yanchor === 'top') | ||
| legendObj._maxHeight = legendObj.y * fullLayout.height; | ||
| else if(yanchor === 'bottom') | ||
| legendObj._maxHeight = (1 - legendObj.y) * fullLayout.height; | ||
| else // if (yanchor === 'middle') | ||
| legendObj._maxHeight = 2 * Math.min(1 - legendObj.y, legendObj.y) * fullLayout.height; | ||
| legendObj._maxHeight = Math.max(legendObj._maxHeight, 30); | ||
| } | ||
|
|
||
| var toggleRectWidth = 0; | ||
| legendObj._width = 0; | ||
|
|
@@ -815,19 +829,30 @@ function computeLegendDimensions(gd, groups, traces, legendObj) { | |
| } | ||
| } else { | ||
| var xanchor = getXanchor(legendObj); | ||
| var isLeftOfPlotArea = legendObj.x < 0 || (legendObj.x === 0 && xanchor === 'right'); | ||
| var isRightOfPlotArea = legendObj.x > 1 || (legendObj.x === 1 && xanchor === 'left'); | ||
| var isBeyondPlotAreaY = isAbovePlotArea || isBelowPlotArea; | ||
| var hw = fullLayout.width / 2; | ||
|
|
||
| // - if placed within x-margins, extend the width of the plot area | ||
| // - else if below/above plot area and anchored in the margin, extend to opposite margin, | ||
| // - otherwise give it the maximum potential margin-push value | ||
| legendObj._maxWidth = Math.max( | ||
| isLeftOfPlotArea ? ((isBeyondPlotAreaY && xanchor === 'left') ? gs.l + gs.w : hw) : | ||
| isRightOfPlotArea ? ((isBeyondPlotAreaY && xanchor === 'right') ? gs.r + gs.w : hw) : | ||
| gs.w, | ||
| 2 * textGap); | ||
| if(legendObj.xref === 'paper') { | ||
| var isLeftOfPlotArea = legendObj.x < 0 || (legendObj.x === 0 && xanchor === 'right'); | ||
| var isRightOfPlotArea = legendObj.x > 1 || (legendObj.x === 1 && xanchor === 'left'); | ||
| var isBeyondPlotAreaY = isAbovePlotArea || isBelowPlotArea; | ||
| var hw = fullLayout.width / 2; | ||
|
|
||
| // - if placed within x-margins, extend the width of the plot area | ||
| // - else if below/above plot area and anchored in the margin, extend to opposite margin, | ||
| // - otherwise give it the maximum potential margin-push value | ||
| legendObj._maxWidth = Math.max( | ||
| isLeftOfPlotArea ? ((isBeyondPlotAreaY && xanchor === 'left') ? gs.l + gs.w : hw) : | ||
| isRightOfPlotArea ? ((isBeyondPlotAreaY && xanchor === 'right') ? gs.r + gs.w : hw) : | ||
| gs.w, | ||
| 2 * textGap); | ||
| } else { | ||
| if(xanchor === 'right') | ||
| legendObj._maxWidth = legendObj.x * fullLayout.width; | ||
| else if(xanchor === 'left') | ||
| legendObj._maxWidth = (1 - legendObj.x) * fullLayout.width; | ||
| else // if (xanchor === 'center') | ||
| legendObj._maxWidth = 2 * Math.min(1 - legendObj.x, legendObj.x) * fullLayout.width; | ||
| legendObj._maxWidth = Math.max(legendObj._maxWidth, 2 * textGap); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style nit: probably clearer to use a temp variable for |
||
| } | ||
|
|
||
| var maxItemWidth = 0; | ||
| var combinedItemWidth = 0; | ||
| traces.each(function(d) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.