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

Fix axis labels overlap with axis ticks #57

Merged
merged 2 commits into from
Dec 17, 2024
Merged

Conversation

mkalte666
Copy link
Contributor

@mkalte666 mkalte666 commented Nov 8, 2024

Currently, when you have custom axis labels, you will end up with the following:

plot_clipps

What i would expect (and what this pr does) is that the axis labels do not overlap with the ticks.

This PR does two things:

  • First, it adds a top axis to the custom axis demo, so that the demo can be used to verify that its not clipping anymore, in all axis configurations.
  • Second, it fixes the overlap by adding the "text_thickness" to the axis thickness in the axis' ui() function.

This results in the following:

no_clip_fixed

A possible optimization would be to figure out the max tick thickness around the axis label, instead of using the maximal thickness - that could result in a tad smaller axis for plots where the order of magnitude changes in the current view.

However, with this PR, the issue is fixed to a level where i'd say its usable.

I have

  • run check.sh locally and it went rhough
  • tested it using the demo
  • thrown this pr into a larger project that uses egui_plot and have not seen any issues arise from this.

Thanks for your time!

EDIT: as is tradition, i immediately noticed something of as soon as i wrote all this. I have updated the image and am gonna force-push a fix in a sec.

~mkalte

@@ -563,6 +563,10 @@ impl CustomAxesDemo {
ui.label("Zoom in on the X-axis to see hours and minutes");

let x_axes = vec![
AxisHints::new_x()
Copy link
Contributor

Choose a reason for hiding this comment

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

2x x axis?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added one to the top here, so that there are axis all around the plot. This helps to show when there are issues with clipping.

@emilk emilk added bug Something isn't working include in changelog This change will be included in the changelog labels Dec 17, 2024
@emilk emilk merged commit 3074792 into emilk:main Dec 17, 2024
@jordens jordens mentioned this pull request Jan 15, 2025
1 task
emilk pushed a commit that referenced this pull request Jan 29, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui_plot/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo f or a new
example.
* Do NOT open PR:s from your `master` or `main` branch, as that makes it
hard for maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! We will review your PR, but our time is limited!
-->

When adding a bit longer axis labels it becomes clear that the Y axis
label thickness is calculated wrong since
#57. This fixes the computation.

Before (current main):

![image](https://github.com/user-attachments/assets/531b868b-5723-488a-b676-87b7dcfdf106)

After:

![image](https://github.com/user-attachments/assets/6d657f1e-ed3e-4124-92bc-2da665fd8815)


<!-- * Closes
<https://github.com/emilk/egui_plot/issues/THE_RELEVANT_ISSUE> -->
* [x] I have followed the instructions in the PR template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working include in changelog This change will be included in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants