MCPcopy Create free account
hub / github.com/emilk/egui_plot / show_plot

Method show_plot

examples/interaction/src/app.rs:20–58  ·  view source on GitHub ↗
(&mut self, ui: &mut egui::Ui)

Source from the content-addressed store, hash-verified

18
19impl InteractionExample {
20 pub fn show_plot(&mut self, ui: &mut egui::Ui) -> Response {
21 let id = ui.make_persistent_id("interaction_demo");
22
23 let plot = Plot::new("interaction_demo").id(id).height(300.0);
24
25 let PlotResponse {
26 response,
27 inner: (screen_pos, pointer_coordinate, pointer_coordinate_drag_delta, bounds, hovered),
28 hovered_plot_item,
29 ..
30 } = plot.show(ui, |plot_ui| {
31 plot_ui.line(
32 Line::new("sin", PlotPoints::from_explicit_callback(move |x| x.sin(), .., 100))
33 .color(egui::Color32::RED),
34 );
35 plot_ui.line(
36 Line::new("cos", PlotPoints::from_explicit_callback(move |x| x.cos(), .., 100))
37 .color(egui::Color32::BLUE),
38 );
39
40 (
41 plot_ui.screen_from_plot(PlotPoint::new(0.0, 0.0)),
42 plot_ui.pointer_coordinate(),
43 plot_ui.pointer_coordinate_drag_delta(),
44 plot_ui.plot_bounds(),
45 plot_ui.response().hovered(),
46 )
47 });
48
49 // Store for display in controls
50 self.last_bounds = Some(bounds);
51 self.last_screen_pos = screen_pos;
52 self.last_pointer_coordinate = pointer_coordinate;
53 self.last_pointer_drag_delta = pointer_coordinate_drag_delta;
54 self.last_hovered = hovered;
55 self.last_hovered_item = hovered_plot_item;
56
57 response
58 }
59
60 pub fn show_controls(&self, ui: &mut egui::Ui) -> Response {
61 if let Some(bounds) = &self.last_bounds {

Callers 1

show_uiMethod · 0.45

Calls 12

showMethod · 0.80
lineMethod · 0.80
screen_from_plotMethod · 0.80
pointer_coordinateMethod · 0.80
plot_boundsMethod · 0.80
responseMethod · 0.80
heightMethod · 0.45
idMethod · 0.45
colorMethod · 0.45
sinMethod · 0.45
cosMethod · 0.45

Tested by

no test coverage detected