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

Component | Axis: Hiding overlapping tick labels #466

Merged
merged 6 commits into from
Oct 31, 2024

Conversation

rokotyan
Copy link
Contributor

@rokotyan rokotyan commented Oct 18, 2024

This PR implements a feature that automatically hides overlapping Axis labels. The overlapping detection has only a single iteration, so overlap is still possible, but I think it's a reasonable trade off. We can tweak that later if needed.

Screen.Recording.2024-10-18.at.2.48.27.PM.mp4

Another important thing here, is that I've fixed the problem with wrong auto margins on the first render leading to tick labels go off screen.

Before

SCR-20241018-lrxm

After

SCR-20241018-lrvg

Docs update

image

- Adding `tickTextHideOverlapping` config option to Axis component and implementing collision detection algorithm to hide overlapping tick labels
- Configurable `minMaxTicksOnlyWhenWidthIsLess` property (was hard coded before)
Fixes the problem with axis tick labels going off screen because the auto margins were not calculated properly.

It was happening when a different scale (e.g. Scale.scaleTime()) is provided to the container (and it generates ticks differently from the default scale), because this new scale was not passed to the Axis component during pre-render
@lee00678
Copy link
Collaborator

Awesome fix for auto margin!

@rokotyan rokotyan marked this pull request as draft October 30, 2024 22:11
@rokotyan
Copy link
Contributor Author

@lee00678 Thanks. Can you please wait a little with merging this one? I was experimenting with adding more iterations to the label hiding logic and it worked pretty well. So I want to commit this change

@lee00678
Copy link
Collaborator

@lee00678 Thanks. Can you please wait a little with merging this one? I was experimenting with adding more iterations to the label hiding logic and it worked pretty well. So I want to commit this change

Sounds good. I wonder for the example in the doc, we could do something like <XYWrapper {...defaultProps()} numTicks={25} containerProps={{ xDomain: [0, 100] }} hiddenProps={{x:d=>d.x}} tickTextHideOverlapping={true}/>

Essentially the first example in the dev example. I feel like it's more clear with more ticks, less number of digits. But maybe once you fix the label hiding logic, it won't be an issue anymore.

@rokotyan
Copy link
Contributor Author

@lee00678 Not sure I got your point, can you please elaborate a little more?

Also, I've just pushed my changes

Screen.Recording.2024-10-30.at.3.54.37.PM.mp4

@rokotyan rokotyan marked this pull request as ready for review October 30, 2024 22:57
@lee00678
Copy link
Collaborator

@lee00678 Not sure I got your point, can you please elaborate a little more?

Sorry for the confusion, I meant this:
Screenshot 2024-10-30 at 4 23 38 PM
(This is a screenshot taken with your update, and it looks a lot better. So you can ignore my previous comment)

@rokotyan
Copy link
Contributor Author

@lee00678 I see, sounds good, feel free to merge the PR if you don't have any comments or questions

@lee00678 lee00678 merged commit 040082e into f5:main Oct 31, 2024
4 checks passed
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