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

Add xref and yref to legends #6589

Merged
merged 14 commits into from
May 12, 2023
Merged

Add xref and yref to legends #6589

merged 14 commits into from
May 12, 2023

Conversation

hannahker
Copy link
Contributor

@hannahker hannahker commented May 2, 2023

Summary: Add support for container-referenced positioning for plot legends. See demo CodePen here: https://codepen.io/hannahker/pen/wvEZZvN

API changes: yref and xref parameters are added to layout.legend.

Expected behaviour:

  • The legend may be positioned relative to the full container area if layout.legend.yref or layout.legend.xref are set to 'container'.
  • If a legend has container-referenced positioning, then space will be added to the _fullLayout._reservedMargin accordingly, meaning that legends may be automatically positioned to avoid components such as automargined axes.
    • If xref='container', then margin space will be added to the _reservedMargin on the left or the right of a plot area (depending if x > 0.5)
    • If yref='container', then margin space will be added to the _reservedMargin on the top or bottom of a plot area (depending if y > 0.5).
    • If both xref='container' and yref='container', then margin spacing will be added to the top or bottom if orientation='v' and left or right if orientation='h'.

The defaults for yanchor, xanchor, y, and x have also been adjusted for cases where container-referencing is applied.

@archmoj
Copy link
Contributor

archmoj commented May 3, 2023

Great PR 🥇 thanks to @hannahker.
Looking good to me.
Over to @alexcjohnson for 🔎 second 🔍 review.

@hannahker hannahker mentioned this pull request May 8, 2023
1 task
Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

Looks great! Just one more remnant of moving the min/max logic to defaults. 💃

@hannahker hannahker merged commit cc88162 into master May 12, 2023
1 check passed
@hannahker hannahker deleted the legend-positioning branch May 12, 2023 18:17
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.

None yet

3 participants