(&mut self, ui: &mut egui::Ui)
| 23 | |
| 24 | impl ItemsExample { |
| 25 | pub fn show_plot(&mut self, ui: &mut egui::Ui) -> Response { |
| 26 | let n = 100; |
| 27 | let mut sin_values: Vec<_> = (0..=n) |
| 28 | .map(|i| egui::remap(i as f64, 0.0..=n as f64, -TAU..=TAU)) |
| 29 | .map(|i| [i, i.sin()]) |
| 30 | .collect(); |
| 31 | |
| 32 | let line = Line::new("sin(x)", sin_values.split_off(n / 2)).fill(-1.5); |
| 33 | let polygon = Polygon::new( |
| 34 | "polygon", |
| 35 | PlotPoints::from_parametric_callback( |
| 36 | |t| (4.0 * t.sin() + 2.0 * t.cos(), 4.0 * t.cos() + 2.0 * t.sin()), |
| 37 | 0.0..TAU, |
| 38 | 100, |
| 39 | ), |
| 40 | ); |
| 41 | let points = Points::new("sin(x)", sin_values).stems(-1.5).radius(1.0); |
| 42 | |
| 43 | let arrows = { |
| 44 | let pos_radius = 8.0; |
| 45 | let tip_radius = 7.0; |
| 46 | let arrow_origins = |
| 47 | PlotPoints::from_parametric_callback(|t| (pos_radius * t.sin(), pos_radius * t.cos()), 0.0..TAU, 36); |
| 48 | let arrow_tips = |
| 49 | PlotPoints::from_parametric_callback(|t| (tip_radius * t.sin(), tip_radius * t.cos()), 0.0..TAU, 36); |
| 50 | Arrows::new("arrows", arrow_origins, arrow_tips) |
| 51 | }; |
| 52 | |
| 53 | let texture: &egui::TextureHandle = self |
| 54 | .texture |
| 55 | .get_or_insert_with(|| ui.load_texture("plot_demo", egui::ColorImage::example(), Default::default())); |
| 56 | let image = PlotImage::new( |
| 57 | "image", |
| 58 | texture, |
| 59 | PlotPoint::new(0.0, 10.0), |
| 60 | 5.0 * vec2(texture.aspect_ratio(), 1.0), |
| 61 | ); |
| 62 | |
| 63 | let plot = Plot::new("items_demo") |
| 64 | .legend( |
| 65 | Legend::default() |
| 66 | .position(egui_plot::Corner::RightBottom) |
| 67 | .title("Items"), |
| 68 | ) |
| 69 | .show_x(false) |
| 70 | .show_y(false) |
| 71 | .data_aspect(1.0); |
| 72 | plot.show(ui, |plot_ui| { |
| 73 | plot_ui.hline(HLine::new("Lines horizontal", 9.0)); |
| 74 | plot_ui.hline(HLine::new("Lines horizontal", -9.0)); |
| 75 | plot_ui.vline(VLine::new("Lines vertical", 9.0)); |
| 76 | plot_ui.vline(VLine::new("Lines vertical", -9.0)); |
| 77 | plot_ui.line(line.name("Line with fill").id("line_with_fill")); |
| 78 | plot_ui.polygon(polygon.name("Convex polygon").id("convex_polygon")); |
| 79 | plot_ui.points(points.name("Points with stems").id("points_with_stems")); |
| 80 | plot_ui.text(Text::new("Text", PlotPoint::new(-3.0, -3.0), "wow").id("text0")); |
| 81 | plot_ui.text(Text::new("Text", PlotPoint::new(-2.0, 2.5), "so graph").id("text1")); |
| 82 | plot_ui.text(Text::new("Text", PlotPoint::new(3.0, 3.0), "much color").id("text2")); |
no test coverage detected