-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Drag and zoom support for plots #317
Conversation
bff4e3d
to
ec3bda0
Compare
Co-authored-by: ilya sheprut <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR; it works really well, and nice use of the new memory feature!
egui/src/widgets/plot.rs
Outdated
impl Default for PlotMemory { | ||
fn default() -> Self { | ||
Self { | ||
bounds: Bounds::new_symmetrical(1.), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite arbitrary. Would it make more sense to use Bounds::EMPTY
here, and have that to mean "automatic"? Then at the first frame we would get the automatic bounds
egui/src/widgets/plot.rs
Outdated
impl Default for Plot { | ||
fn default() -> Self { | ||
impl Plot { | ||
pub fn new(name: impl Into<String>) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be either changed to id_source: impl Hash
, or we should actually use it as a String
- i.e. show it on hover. Though then I wonder what the difference would be between a plot name and on_hover_ui
-tooltip. Probably better to go with id_source: impl Hash
and change the examples to use something that looks less like a user-visible name and more like an identifier ("my_plot"
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we use the same system that Window uses with a constructor that takes the shown name and
an id method to set a custom id when required? The title will be visible to the user at some point,
I just haven't thought about how to show it yet.
egui/src/widgets/plot.rs
Outdated
/// If true, the bounds will be set based on the data. | ||
pub fn automatic_bounds(mut self, enabled: bool) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit under-documented (what is the default? what does it mean for it to be false
?).
I wonder if we really need this at all? I like the behavior of automatically calculating bounds at the start and on double-click, but otherwise allow users to scroll and zoom.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, wrong account
Thanks for the review! I share your concerns about how to handle the plot bounds. Is it alright with you when the plotting functionality keeps growing? In #155 you mentioned that |
I'm a bit hesitant to merge a PR that removes a desired feature (
I'm alright with that, but it would be good to sync exactly in what direction it is growing before you do too much work! Perhaps you can open a tracking issue with your plans? |
Understandable, I added back those methods, and made automatic bounds the default. I'll open a tracking issue and a PR soon for the coming changes. Question: Is there a way to tell if a window has been drawn for the first time? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized there is an important use-case that this breaks: plotting dynamic data. For instance, plotting the last few seconds of a recorded time series. In this case we want the bounds to automatically follow the data each frame.
I suggest a (hopefully) simple change: add a auto_bounds: bool
to PlotMemory
and initialize it to true
. This is set to false
on zoom/pan, and reset to true
on double-tap. Then we will maintain previous behavior (tracking dynamic plots) while still allowing the new awesome zoom/pan behavior.
A second use case that need to work is the include_x/include_y
(e.g. .include_y(0.0)
to include the X-axis in a plot). This should be used when computing automatic bounds, but ignored when users pan and zoom. I suggest changing Plot::bounds
to be called Plot::min_auto_bounds
and use it as the starting point when computing automatic bounds.
PS: thanks for your patience and work :)
Thanks for the great suggestions! I tried to apply all of them. Might not work in all cases thought, but I don't have time to test it more thoroughly right now. |
I've opened up a PR based on this one: #331 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!
Hey guys, awesome library first of all. I found this PR after having problems with zoom. I am not sure how i'm supposed to achieve that on a Plot (mac with magic mouse if it matters). I tried reading the code and zoom seems to require hovering but i only see labels if i hover? And if I hover + track (or slide my finger on my mouse rather), the plot is just dragged. Am I doing something dumb? :D egui = "0.12.0" |
@blagovestb2c2 You need to hold control while scrolling to zoom |
Closes #316.