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

2D plotting functionality #155

Closed
EmbersArc opened this issue Feb 2, 2021 · 7 comments
Closed

2D plotting functionality #155

EmbersArc opened this issue Feb 2, 2021 · 7 comments
Labels
feature New feature or request

Comments

@EmbersArc
Copy link
Contributor

EmbersArc commented Feb 2, 2021

Having a 2D plotting library inside egui would be highly beneficial. It already has most of the capabilities necessary for implementing one. Taking some inspiration from implot for imgui, I put together a prototype of what this feature may look like.

Note that I only have a surface-level understanding of egui, so much of what I do here may not be "best practice" and there may be better ways to do things. I am willing to continue work on this, but would appreciate occasional reviews, advice or even collaboration from someone who is more proficient with the internal workings of egui. So let me know if you want to help.

https://github.com/EmbersArc/eplot
simplescreenrecorder-2021-02-02_21 22 15

@EmbersArc EmbersArc added the feature New feature or request label Feb 2, 2021
@emilk
Copy link
Owner

emilk commented Feb 3, 2021

Very cool and impressive!

I have a vague plan of adding an immediate mode plot library to egui. My initial inclination is to make something very simple: plotting colored lines without any mouse interaction except hover.

I think a more fully-featured plotting library like you are demoing would make sense as a separate crate (eplot).

Let me know how eplot progresses and how I can help! In particular if there are any features you miss in egui.

One thing I've been planning to add is a transform to Painter to make it easier to build things like this. The transform would be applied to each Shape passed to the Painter. I think initially it would only support translation and non-uniform scaling (including mirroring).

@EmbersArc
Copy link
Contributor Author

You're right that this should better be a separate crate since creating/maintaining it would be quite an endeavor. I don't yet know how far I'm going to take this but so far working with egui has been great.

As for missing features, the biggest ones are related to text rendering. I haven't been able to find a way to rotate text (note the missing y-axis label) and text positioning in the plot seems to be quite tricky as well but I probably didn't try hard enough there.

The transformation function you mention would indeed be helpful, especially with axis mirroring. I am currently doing this in my own function. But I'm afraid linear transformations won't be enough for things like plots with log-log scaling anyways, and there might not be a case to add those to egui itself.
I wouldn't recommend scaling whole shapes in this function, just coordinates. There are some cases where I want to transform the position of polygons, but not their individual vertices. But such a function might have other applications that I'm not thinking of right now.

@emilk
Copy link
Owner

emilk commented Feb 4, 2021

There is no way to rotate text at the moment. I think adding emath::Rot2 to Shape::Text should be pretty easy.

As for positioning text: use Shape::text which allows you to position text relative some anchor (e.g. CENTER_BOTTOM): https://docs.rs/epaint/0.8.0/epaint/enum.Shape.html#method.text

@yan-zaretskiy
Copy link

yan-zaretskiy commented Feb 9, 2021

One missing feature that I came across in ImPlot, which targets Dear Imgui, is plotting dashed lines and curves. Doing this by drawing a bunch of tiny line segments can become a performance issue. Dear Imgui itself does not provide a way to draw dashed line segments, polylines or curves, so this could be something for you to consider.

@emilk
Copy link
Owner

emilk commented Feb 18, 2021

I've pushed an immediate mode plotter to master, with basic support for grid lines and tick labels. There is some minor polishing left to do, but it will be included in egui 0.10.

plot

@emilk
Copy link
Owner

emilk commented Feb 28, 2021

Closed by a19140e

@JPGygax68
Copy link

I have implemented something that is somewhat tangential to plotting, a "Canvas" struct that supports rulers, panning and scaling.
Because of panning and scaling, it is necessary to convert coordinates prior to issuing calls to the Painter, which is slightly annoying as it makes the user-facing interface more complex (conversions are made available via an extra struct called "Surface".

Hence the following question: would it be possible to add an optional 2D transformation matrix to the Painter struct? Combined with the already existing and excellent clipping support, this would make rendering in "content" spaces a breeze.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants