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

Plotting: Add line markers #363

Merged
merged 32 commits into from
May 27, 2021
Merged

Plotting: Add line markers #363

merged 32 commits into from
May 27, 2021

Conversation

EmbersArc
Copy link
Contributor

@EmbersArc EmbersArc commented May 9, 2021

Closes #362

recording.mp4

@EmbersArc EmbersArc marked this pull request as ready for review May 11, 2021 15:53
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.

The markers look sweet!

I'm not sure it makes sense to couple them to Curve though.

It seems likely users will want them to show e.g. a scatterplot, or to show the datapoint to which a smooth curve has been fitted. But right now it is more designed to highlight the corners of a coarse curve (like the demo shows), which is just a weird use case to me (but that may just be me). Such a coarse curve isn't very... well, curvy!think

Consider an alternative where markers where instead part of a separate Points primitive. So you can add a curve and points, or just points, or just a curve. That way we can keep Curve for smooth things (and add methods to e.g. show the derivative/tangent on hover) and use the markers for sparse point data.

What do you think?

egui/src/widgets/plot/items.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/items.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/items.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/items.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/items.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/items.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/items.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/items.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/mod.rs Show resolved Hide resolved
@EmbersArc
Copy link
Contributor Author

@emilk Thanks for the review! I'm very much open to having a separate Points primitive, in fact I was going to take this approach first. But everything is very much built around Curve right now and introducing a separate Points struct would lead to a lot of duplicate code. Maybe we could unite them in a Series primitive which has a field that defines whether it's a curve or a set of points? Maybe you have an idea?

@EmbersArc
Copy link
Contributor Author

@emilk I've now created a separate Points primitive, let me know what you think. It has lead to some duplicate code but made other parts much cleaner and straight forward. Both Curves and Points now have just one constructor, which takes a ValuesSeries object, like so:

let curve = Curve::new(ValueSeries::from_values_iter(sin));
let points = Points::new(ValueSeries::from_values_iter(sin));
ui.add(
    Plot::new("Test Plot").curve(curve).points(points)
);

@EmbersArc
Copy link
Contributor Author

One issue with this approach (apart from the duplicate code) is that points are always drawn on top of curves. But I want the user to have full control over the drawing order. One way to fix both issues might be to share an interface between Points and Curve and then store them in a vector of boxes. I can give that a shot...

@EmbersArc
Copy link
Contributor Author

Done, I'm quite happy with how this turned out. I also took the chance to rename Curve to Line since it's more general and we're breaking a lot here anyways.

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.

Much better!

I only have some minor notes

@@ -208,19 +265,295 @@ impl Curve {
self
}

/// Stroke color. Default is `Color32::TRANSPARENT` which means a color will be auto-assigned.
Copy link
Owner

Choose a reason for hiding this comment

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

Is this no longer true?

egui/src/widgets/plot/items.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
egui/src/widgets/plot/items.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/mod.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/items.rs Show resolved Hide resolved
egui_demo_lib/src/apps/demo/plot_demo.rs Outdated Show resolved Hide resolved
egui_demo_lib/src/apps/demo/plot_demo.rs Outdated Show resolved Hide resolved
egui_demo_lib/src/apps/demo/plot_demo.rs Outdated Show resolved Hide resolved
egui_demo_lib/src/apps/demo/plot_demo.rs Show resolved Hide resolved
EmbersArc and others added 6 commits May 26, 2021 23:47
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
@EmbersArc
Copy link
Contributor Author

@emilk Thanks for having another look. Much appreciated. I applied all your suggestions.

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.

Thanks for this!

@emilk emilk merged commit 8623909 into emilk:master May 27, 2021
@EmbersArc EmbersArc deleted the plot-markers branch May 27, 2021 16:42
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.

Plotting: Add line markers
2 participants