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

Best practice to avoid clipped axis ticks' labels #944

Open
zefirka opened this issue Apr 23, 2024 · 2 comments
Open

Best practice to avoid clipped axis ticks' labels #944

zefirka opened this issue Apr 23, 2024 · 2 comments

Comments

@zefirka
Copy link
Contributor

zefirka commented Apr 23, 2024

Hi @leeoniya

I faced with issue and I'd like to discuss it

The problem:

The last tick's label may be clipped (text appears outside of plotting area). This happens when splits' last element calculated too close to the series last element and provided options.padding is not enough to fit text. This issue appears quite rare, but anyway it's pretty annoying.

Simple example here: https://codesandbox.io/p/sandbox/test-uplot-nz5rcy?file=%2Findex.html

Workarounds:

  • Unconditionally increase corresponding padding. This will fix the problem but it will take a lot of usable space as well, and 99 out of 100 times it's just useless.

  • Try to get splits by incrs and manually calculate required and available space and increase padding when it's necessary. This will fix the problem only when it appear and will save space when there's no need for padding increase. But I think it's kind of overcomplicated and also that's not very good to have a lot of charts with inconsistent paddings on same page (imagine a dashboard of charts with a bunch of different padding 🤢)

  • Don't render labels on canvas, but write a plugin to render labels as HTML elements. Seems that it will work and provide much more control for rendering. But it looks like sledgehammer to crack a nut to me.

All given workarounds have significant disadvantages, so I thought maybe you have opinion on this case, like you know, Highcharts for instance trying to align every label in such way to fit into plotting area, or something like this. At current point the best thing I decided to do is to do nothing :)

@leeoniya
Copy link
Owner

leeoniya commented Apr 27, 2024

take a look at https://leeoniya.github.io/uPlot/demos/axis-autosize.html

the internals of this are actually quite complex/ungreat, and i want to refine them soonish.

the problem here is chicken-egg, since plotting area size (and padding and axis size) is affected by rendered tick values but the ticks which are rendered depend on the plotting area size + scale range. solving both things in a single pass is not possible, so uPlot has to run both functions twice until it converges on some solution that satisfies both somehow.

@zefirka
Copy link
Contributor Author

zefirka commented Apr 30, 2024

Thanks, I missed out that I can use callbacks for paddings, it made your solution a bit easier then mine.

But i'll guess I'll wait for refine

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

No branches or pull requests

2 participants