Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: use wrapped text in Text._get_layout #25346

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

Merged
merged 1 commit into from
Feb 28, 2023
Merged

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented Feb 28, 2023

PR Summary

Fixes #25336.

Constrained layout here relies on Text.get_tightbbox, which calls Text.get_window_extent, which calls Text._get_layout. The example code in the issue now produces:

test

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • [N/A] API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • [N/A] Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@rcomer rcomer added topic: text topic: geometry manager LayoutEngine, Constrained layout, Tight layout PR: bugfix Pull requests that fix identified bugs labels Feb 28, 2023
@@ -367,7 +367,7 @@ def _get_layout(self, renderer):
of a rotated text when necessary.
"""
thisx, thisy = 0.0, 0.0
lines = self.get_text().split("\n") # Ensures lines is not empty.
lines = self._get_wrapped_text().split("\n") # Ensures lines is not empty.
Copy link
Member

Choose a reason for hiding this comment

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

Do you understand what the comment is about?

Copy link
Member Author

@rcomer rcomer Feb 28, 2023

Choose a reason for hiding this comment

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

Not completely, though I can see that there are a bunch of necessary variables defined in the loop at lines 383-414, which would not exist if lines was empty. So maybe this is just providing reassurance for that?

@jklymak jklymak merged commit 6462a01 into matplotlib:main Feb 28, 2023
@rcomer
Copy link
Member Author

rcomer commented Feb 28, 2023

Thanks @timhoffm @jklymak

@rcomer rcomer deleted the text-wrap branch February 28, 2023 18:18
@rcomer rcomer added this to the v3.7.1 milestone Feb 28, 2023
@rcomer
Copy link
Member Author

rcomer commented Feb 28, 2023

@meeseeksdev backport to v3.7.x

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Feb 28, 2023
oscargus added a commit that referenced this pull request Feb 28, 2023
…346-on-v3.7.x

Backport PR #25346 on branch v3.7.x (FIX: use wrapped text in Text._get_layout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: bugfix Pull requests that fix identified bugs topic: geometry manager LayoutEngine, Constrained layout, Tight layout topic: text
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: constrained layout with wrapped titles
3 participants