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

Add Arc and Pie Drawing and Plotting Features #4424

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

varphone
Copy link
Contributor

Summary

This PR introduces several new features related to drawing and plotting arcs and pies in the egui ecosystem.

Changes

  • epaint: Introduced ArcPieShape, a new shape that represents an arc or a pie slice with specified radius, angle, fill, and stroke properties.
  • egui: Added Painter::{arc, pie} methods, which simplify the process of drawing arcs and pies.
  • egui_plot: Introduced three new plot types: ArcLine, Pie, and PieChart. ArcLine renders a simple arc line, Pie renders a single pie slice, and PieChart renders a pie chart with data and labels.
  • egui_demo_lib: Added demonstrations for ArcPieShape, ArcLine, Pie, and PieChart. These demos showcase how to use these new features in a variety of contexts.

Impact

These changes enhance the capabilities of the egui ecosystem by providing users with more options for drawing and plotting.
The new demos also serve as valuable examples for users to learn from.

screencast-egui_demo_app-2024-04-27.webm

Copy link
Contributor

@murl-digital murl-digital left a comment

Choose a reason for hiding this comment

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

Only thing I saw was using Stroke instead of PathStroke for lines.

crates/egui/src/painter.rs Outdated Show resolved Hide resolved
crates/epaint/src/shape.rs Outdated Show resolved Hide resolved
crates/epaint/src/shape.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@murl-digital murl-digital left a comment

Choose a reason for hiding this comment

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

Thanks for pushing that change! I'm a bit tired right now so I'll look over everything else when I get the chance. (feel free to poke me)

let stroke_color = match stroke.color {
ColorMode::Solid(color) => color,
ColorMode::UV(callback) => {
// We can't use the callback here, so we just use the center of the circle.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this behavior should be documented somewhere? I'm also not fully sure if you can't use the callback here, could you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The entire pie is rendered as a circle, but CircleShape is not compatible with PathStroke.
As a workaround, I use a callback to obtain the center color from PathStroke.
This issue should be addressed once CircleShape supports PathStroke.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I understand. Thanks for elaborating!

Im hoping that the underlying ColorMode will be used for more shapes in the future, but for the time being it is only for paths. If you want, I can look into opening a PR to support PathStroke for more shapes

This commit introduces a new shape to the `epaint` library, named `ArcPieShape`.
This shape represents an arc or a pie slice that can be rendered with specified radius, angle, fill, and stroke properties.

It's useful for rendering pie charts, donut charts, and other circular data visualizations.
This commit adds `Painter::{arc, pie}` methods to `egui::Painter`.
These methods simplify the process of drawing arcs and pies.
This commit introduces three new plot types to the `egui_plot` library: `ArcLine`, `Pie`, and `PieChart`.

- `ArcLine` is a plot that renders a simple arc line.
- `Pie` is a plot that renders a single pie slice.
- `PieChart` is a plot that renders a pie chart with data and labels.
…PieChart`

This commit adds demonstrations for `ArcPieShape`, `ArcLine`, `Pie`, and `PieChart` to the `egui_demo_lib` library.
These demos showcase how to use these new features in a variety of contexts.
Copy link
Contributor

@murl-digital murl-digital left a comment

Choose a reason for hiding this comment

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

Everything LGTM, I did have some performance concerns but eyeballing the frame render times in the standalone demo didn't justify benchmarks. Playing around with the demo you included, I wasn't able to break it visually, and I do think you already account for start and end angles that result in a full circle.

@enomado
Copy link
Contributor

enomado commented May 11, 2024

@murl-digital
Copy link
Contributor

murl-digital commented May 11, 2024

Take a look to a bezier curve arc approximation methods, it could be faster(may be)

It could also be more accurate, if you'd like an example, I have a duplicate PR: #4426

Side note: I probably should have caught this in my review. Sorry!

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

3 participants