(&mut self, ui: &mut egui::Ui)
| 25 | |
| 26 | #[expect(clippy::needless_pass_by_ref_mut, reason = "to allow mutation of self")] |
| 27 | pub fn show_plot(&mut self, ui: &mut egui::Ui) -> Response { |
| 28 | let mut plot = Plot::new("Span Demo"); |
| 29 | if self.show_legend { |
| 30 | plot = plot.legend(Legend::default().position(Corner::LeftBottom)); |
| 31 | } |
| 32 | |
| 33 | plot.show(ui, |plot_ui| { |
| 34 | let span = Span::new("Span 1", -10.0..=-5.0) |
| 35 | .border_style(egui_plot::LineStyle::Dashed { length: 50.0 }) |
| 36 | .border_width(3.0); |
| 37 | plot_ui.span(span); |
| 38 | |
| 39 | let span = Span::new("Span 2", 0.0..=1.0); |
| 40 | plot_ui.span(span); |
| 41 | |
| 42 | let span = Span::new("Span 3", 5.0..=6.0).axis(egui_plot::Axis::Y); |
| 43 | plot_ui.span(span); |
| 44 | |
| 45 | let color4: Color32 = Hsva::new(0.1, 0.85, 0.5, 0.15).into(); |
| 46 | let span4 = Span::new("Span 4", 5.0..=5.5) |
| 47 | .border_width(0.0) |
| 48 | .fill(color4) |
| 49 | .label_align(Align2::LEFT_BOTTOM); |
| 50 | plot_ui.span(span4.clone()); |
| 51 | |
| 52 | let color5: Color32 = Hsva::new(0.3, 0.85, 0.5, 0.15).into(); |
| 53 | let span5 = Span::new("Span 5", 5.5..=6.5) |
| 54 | .border_width(0.0) |
| 55 | .fill(color5) |
| 56 | .label_align(Align2::LEFT_BOTTOM); |
| 57 | plot_ui.span(span5.clone()); |
| 58 | |
| 59 | let span = span4.clone().range(6.5..=8.0); |
| 60 | plot_ui.span(span); |
| 61 | |
| 62 | let span = span5.clone().range(8.0..=10.0); |
| 63 | plot_ui.span(span); |
| 64 | |
| 65 | let span = Span::new("Infinite span", 10.0..=f64::INFINITY); |
| 66 | plot_ui.span(span); |
| 67 | |
| 68 | let sine_points = PlotPoints::from_explicit_callback(|x| x.sin(), .., 5000); |
| 69 | let sine_line = Line::new("Sine", sine_points).name("Sine"); |
| 70 | |
| 71 | plot_ui.line(sine_line); |
| 72 | }) |
| 73 | .response |
| 74 | } |
| 75 | } |
no test coverage detected