-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Plot label quadrant #3028
Comments
Having the label move around relative to the cursor does not seem great to me, and then you are still going to clip if the label is too big to fit into the graph area (happens a lot if you use multiple narrow plots next to each other, for example). I find that using For example: bandicam.2023-05-25.14-40-49-494.mp4 |
I totally agree with all that. In fact small graphs is exactly the reason I did that modification.
That is really helpful! I didn't know that functionality existed But the resulting ui itself is miles better than what I had before. I could really use some snapping tho |
What you want to snap is not the location of the pointer, it's the location egui samples on the graph. All you have to do is cache the See the following in my code (ignore the
This still leverages the snapping and calculations egui does, but caches the value that gets computed by accessing it from the formatter, and then uses it to make as complex and as detailed a "tooltip" as I desire at whatever the actual pointer location will be (close to the point but not snapped). Works very well. EDIT: I left out the important plot definition code - added it now :) |
BTW you can see in my video that you still get the plot location snapped and highlighted by egui, as desired. |
Thank you a lot, this works great! |
First of all - thank you for such an amazing job with this project!
Is your feature request related to a problem? Please describe.
Plot label currently is stuck in top-right corner of the pointer, which is an issue if you want to read label at the edge of a plot (top edge, or right edge). Label isn't drawn in that case (screenshot below)
Describe the solution you'd like
I don't know internals of the library well enough to produce a sensible solution (and very new to rust as a whole), but I made a simple hack for my own purposes, which is: compare value (which i assume just pointer coordinates in plot space) with plot bounds (screenshot with solution below). That way we can put label in the opposite quadrant of the cursor compared to cursor's position in the plot (it's in the egui/crates/egui/src/widgets/plot/items/mod.rs rulers_at_value())
Describe alternatives you've considered
I think a much better way to do this would be to provide some setting for user to decide how label is displayed
Additional context
again, much thanks for the work you all put into this project, it's extremely useful.
code of hacky solution in the screenshot:
// determine which quadrant cursor is placed in.
let bounds = plot.transform.bounds();
let mut quadrant: [bool; 2] = [true, true];
quadrant[0] = value.x > bounds.min()[0] + (bounds.max()[0] - bounds.min()[0]) / 2.0;
quadrant[1] = value.y > bounds.min()[1] + (bounds.max()[1] - bounds.min()[1]) / 2.0;
The text was updated successfully, but these errors were encountered: