Skip to content

Conversation

@mkalte666
Copy link
Contributor

@mkalte666 mkalte666 commented Jul 18, 2024

This commit is an initial implementation for adding logarithmic plotting axis.

This very much needs more testing!

The basic idea is, that everything stays the same, but PlotTransform does the much needed coordinate transformation for us.

That is, unfortunatley not all of the story.

  • In a lot of places, we need estimates of "how many pixels does 1 plot space unit take" and the likes, either for overdraw reduction, or generally to size things. PlotTransform has been modifed for that for now, so this should work.
  • While the normal grid spacer renders just fine, it will also casually try to generate 100s of thousands of lines for a bigger range log plot. So GridInput has been made aware if there is a log axis present. The default spacer has also been modified to work initially.
  • All of the PlotBound transformations within PlotTransform need to be aware and handle the log scaling properly. This is done and works well, but its a bit.. icky, for lack of a better word. If someone has a better idea how to handle this, be my guest :D

Especially the spacer generation is still kinda WIP; it is messy at best right now. Especially for zooming in, it currently only adds it on the lower bound due to the way the generator function works right now.

I will address this in a follow up commit (or someone else will).

Things to consider / to do

  • Arbitrary bases for the log plotting. The mark generator already can handle them i think. Wouldn't be too hard.
  • Move the transformation logic into the AxisTransform enum, so that the PlotTransform code because less coupled to that struct.
  • Test images and plot marks and the likes
  • A few more robustness additions are needed for programmatic interactions with the plot.
  • More documentation, especially in Plot::log_axes to explain what is going on and why some things are a bad idea in log plots.

Other work in this direction :

@mkalte666 mkalte666 changed the title Logarithmic plot axes Add logarithmic plot axes Jul 18, 2024
@mkalte666 mkalte666 force-pushed the log_plot branch 2 times, most recently from 6cd8528 to 65c354c Compare December 18, 2024 09:21
@mkalte666 mkalte666 force-pushed the log_plot branch 2 times, most recently from c19e013 to 3c3fd09 Compare January 6, 2025 14:23
@mkalte666
Copy link
Contributor Author

I have this PR in productive use again, and will probably force push around quite a bit.

Main to-dos for me are the grid spacer and arbitrary log bases. The former works ok enough for now, but there is probably room to make it both efficient and pretty.

Arbitrary log bases is trivial - basically replace the vec2b with something option, and use base.powf and log(base) instead of hardcoding log 10.

Slightly related: Is there a way to disable the pipelines for now? I'd like to avoid spamming whoever else gets the emails.

This commit is an initial implementation for adding logarithmic plotting
axis.

This very much needs more testing!

The basic idea is, that everything stays the same, but PlotTransform
does the much needed coordinate transformation for us.

That is, unfortunatley not all of the story.

 * In a lot of places, we need estimates of "how many pixels does 1 plot
   space unit take" and the likes, either for overdraw reduction, or
   generally to size things. PlotTransform has been modifed for that for
   now, so this should work.
 * While the normal grid spacer renders just fine, it will also casually
   try to generate 100s of thousands of lines for a bigger range log
   plot. So GridInput has been made aware if there is a log axis
   present. The default spacer has also been modified to work initially.
 * All of the PlotBound transformations within PlotTransform need to be
   aware and handle the log scaling properly. This is done and works
   well, but its a bit.. icky, for lack of a better word. If someone has
   a better idea how to handle this, be my guest :D
 * PlotPoint generation from generator functions has to become aware of
   logarithmic plotting, otherwise the resolution of the plotted points
   will suffer.

Especially the spacer generation is still kinda WIP; it is messy at best
right now. Especially for zooming in, it currently only adds lines on the
lower bound due to the way the generator function works right now.

I will address this in a follow up commit/--amend (or someone else will).
@upsj
Copy link

upsj commented Sep 26, 2025

Hi @mkalte666, what is the state of this PR? I would also like to use (semi-)log plots with egui, and this seems the closest effort to getting them supported. I'd be happy to contribute some time to it.

@mkalte666
Copy link
Contributor Author

mkalte666 commented Oct 1, 2025

Hi @mkalte666, what is the state of this PR? I would also like to use (semi-)log plots with egui, and this seems the closest effort to getting them supported. I'd be happy to contribute some time to it.

I am keeping this up to date with releases now and then, as i am using this PR at work. It should (tm) be trivial to rebase at the moment. But try as i might, i have not found the time to clean this up enough to make this mergable. Sorry for that.

I dare say you should be fine to use this as-is, but there are some things left to do. Mostly grid/axis tick generator is a big mess right now and the code needs to be more generic on the axis transformation. I also think at some point i should look at API names one more time, to make sure they are consistent with the rest of egui_plot.

If you have time to help out feel free; otherwise i still think ill finish this at some point. Just, so much to do etc etc.

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