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

Introduce type parameter for plot points #4719

Closed
wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Jun 27, 2024

In order to supply custom data to plot points for use mainly in the label_formatter this introduces a new field which stores userdata.

Hovering over a plot point Hovering over anything else
image image

Of course this requires PlotPoint to have a generic type parameter which then requires lots of other structs to be generic too.

The userdata field is optional, since a PlotPoint can be a Point supplied by the user when constructing a plot item, but it can also be generated by the library.

A demo for this is implemented as you can see in the screenshot.

Of course I would like there to be an easier way to do this, but currently I'm not aware of any.

@ghost ghost marked this pull request as ready for review June 27, 2024 14:16
@Mingun
Copy link
Contributor

Mingun commented Jun 27, 2024

At least, you can make generic parameters optional (<T = ()>)

@ghost
Copy link
Author

ghost commented Jun 28, 2024

Yes thats a good Idea, but when I did that I realized that the default type parameter only applies when you use <T> and not T itself.

See rust-lang/rust#36980.

image
image

@ghost ghost force-pushed the plot-point-userdata branch from fa177fa to 8e7f22e Compare June 28, 2024 09:01
Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

I'm not a big fan of adding templates to everything. It not only makes the core more complex, it also means monomorphization will duplicate the code in the binary, ballooning e.g. the .wasm size.

If you want to attach user-data to points, I suggest you report Points::id together with the point index (usize) to the user. The user can then look up the data they need with a hashmap or similar.

@ghost ghost force-pushed the plot-point-userdata branch from 8e7f22e to d5e2056 Compare July 3, 2024 10:26
@ghost
Copy link
Author

ghost commented Jul 3, 2024

@emilk I tried it and it works with only a few modifications to the library.
But it is quite cumbersome to use, since you need an Arc<Mutex<...>> for the label_formatter and the plot_ui to be able to use the same HashMap. This also requires you to create or at least re-fill the HashMap on every draw...

Is this what you had in mind or is there a simpler way to do this?

image image

@ghost ghost requested a review from emilk July 10, 2024 12:34
@emilk
Copy link
Owner

emilk commented Jul 15, 2024

egui_plot has recently been moved to its own repository, at https://github.com/emilk/egui_plot

This will hopefully speed up its development by having more reviewers and maintainers.

Please re-open this PR at https://github.com/emilk/egui_plot/pulls

See also:

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.

None yet

2 participants