-
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
Allow cursors to be linked for plots #1722
Conversation
That would be a nice contribution. Waiting for the feature! Thanks in advance ;) |
It would be nice of an example of this so we can test it! |
Wanted this feature |
2ac8f80
to
d826072
Compare
I did some refactoring and added the ability to link cursors to the linked axis demo. |
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.
Very nice feature, but I think there is an opportunity to simplify the implementation while also making it more powerful!
egui/src/widgets/plot/mod.rs
Outdated
pub(crate) bounds: Rc<Cell<Option<PlotBounds>>>, | ||
cursors: Rc<RefCell<Vec<(Id, Vec<Cursor>)>>>, |
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 agree with clippy
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.
Also needs documentation explaining it.
egui/src/widgets/plot/items/mod.rs
Outdated
}; | ||
|
||
for pos in elem.arguments_with_ruler() { | ||
push_argument_ruler(pos, shapes); | ||
push_argument_ruler(pos, cursors); |
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.
Not new in this PR, but I really don't see why push_argument_ruler
exists and is not just inlined in the loop
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.
Looks good, but the use of the word "frame" through me off. In egui it either means "one ui layout time slice" (as in "frames per second"), or it means egui::Frame
(for drawing a border around widgets).
If think in this PR it just means "plot widget", so it would be better to call it CursorsForPlot
or similar, with plot_id: Id
for extra clairy.
egui/src/widgets/plot/mod.rs
Outdated
Vertical { x: f64 }, | ||
} | ||
|
||
/// Contains the cursors drawn for a specific frame of a 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.
frame
as in "frames per second"? Or just is it just "for a specific plot widget"? (each widget has a unique id
)
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.
It's what was drawn for a specific plot widget in a frame with the "frames per second" meaning.
egui/src/widgets/plot/mod.rs
Outdated
.map(|(i, _)| i); | ||
|
||
// Remove our previous frame and all older frames as these are no longer displayed. | ||
index.map(|index| frames.drain(0..=index)); |
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 don't really follow this. What is frames
sorted on? The docstring doesn't mention it being ordered by anything.
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.
frames
is the oldest drawn widget to the newest. Each time a plot widget is drawn, it is appended to frames
. Previous entries are removed here to avoid unbounded growth.
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.
Oh, now I see. Thanks for explaining! Could you please add those explanations to the code and then I will merge this!
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 added some more explanations.
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.
Thanks!
This adds
set_link_cursor
toLinkedAxisGroup
which allow the cursor to show up in linked plots.This only handles the default
PlotItem
case. I think changingPlotItem::on_hover
to produce a list of cursors would make sense.The
PartialEq
implementation forLinkedAxisGroup
also seems a bit questionable given it carries identity.