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

first attempt at strip_text_x ha adjustment for facets #871

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jwhendy
Copy link

@jwhendy jwhendy commented Sep 10, 2024

For review. Current status:

  • hard codes info.ha as e.g. 'right' for testing purposes
  • accepts 'left', 'center', and 'right' text args as well as float (matched approach here)
  • anchor (justification) variable added and set to match info.ha (if str passed), or is 'left' if ha < 0.5 else 'right'

@has2k1
Copy link
Owner

has2k1 commented Sep 12, 2024

ha and va get their values from

ha, va = "center", "bottom"

You can read those from the theme to get rid of the hard-corded values.

# This says, read the ha property of the strip_text_x themeable.
# If none has been set, use "center"
ha = theme.getp(("strip_text_x", "ha"), "center")
va = theme.getp(("strip_text_x", "va"), "bottom")

@has2k1
Copy link
Owner

has2k1 commented Sep 12, 2024

Ignore the margin for now.

Then to make the [0, 1] range seem natural when used for positioning we have to take more control of the alignment.

Note that, when:

  1. ha = "left" or ha = 0, the left of the text should be at the left of the strip box. i.e. we set horizontal alignment to left.
  2. ha = "center" or ha = 0.5, the center of the text should be at the center of the strip box. i.e. we set horizontal alignment to center`.
  3. ha = "right" or ha = 0, the right of the text should be at the right of the strip box. i.e. we set horizontal alignment to right.

That means when;

  • ha = 0.2, the 0.2 * width_of_text point should be at 0.2 * width_of_strip_box.
  • ha = 0.65, the 0.65 * width_of_text point should be at 0.65 * width_of_strip_box.
  • ...

The way to do this is set the horizontal alignment to the left and calculate the x position with that in mind. This is what happens here

box = bbox_in_figure_space(text, pack.figure, pack.renderer)
x = params.left * (1 - f) + (params.right - box.width) * f
text.set_x(x)
text.set_horizontalalignment("left")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants