From 395deb70dad5407cc44aeb42aa78ecd57fe122e9 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Wed, 2 Mar 2022 23:38:43 -0500 Subject: [PATCH] cleanup some plot code --- src/egui_app.rs | 61 +++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/src/egui_app.rs b/src/egui_app.rs index ac92e73..5c6e0dd 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -421,42 +421,39 @@ impl epi::App for MathApp { }); return; } + let available_width: usize = ui.available_width() as usize; - let plot_size = ui.available_size(); - let plot_size = Vec2::new(plot_size.x, plot_size.y); - ui.allocate_ui(plot_size, |ui| { - Plot::new("plot") - .set_margin_fraction(Vec2::ZERO) - .data_aspect(1.0) - .include_y(0) - .show(ui, |plot_ui| { - let bounds = plot_ui.plot_bounds(); - let minx_bounds: f64 = bounds.min()[0]; - let maxx_bounds: f64 = bounds.max()[0]; + Plot::new("plot") + .set_margin_fraction(Vec2::ZERO) + .data_aspect(1.0) + .include_y(0) + .show(ui, |plot_ui| { + let bounds = plot_ui.plot_bounds(); + let minx_bounds: f64 = bounds.min()[0]; + let maxx_bounds: f64 = bounds.max()[0]; - for (i, function) in self.functions.iter_mut().enumerate() { - if self.func_strs[i].is_empty() { - continue; - } - - function.update_bounds(minx_bounds, maxx_bounds, available_width); - - let (back_values, bars) = function.run(); - plot_ui.line(back_values.color(Color32::RED)); - - area_list.push({ - if let Some(bars_data) = bars { - let (bar_chart, area) = bars_data; - plot_ui.bar_chart(bar_chart.color(Color32::BLUE).width(step)); - digits_precision(area, 8) - } else { - f64::NAN - } - }); + for (i, function) in self.functions.iter_mut().enumerate() { + if self.func_strs[i].is_empty() { + continue; } - }); - }); + + function.update_bounds(minx_bounds, maxx_bounds, available_width); + + let (back_values, bars) = function.run(); + plot_ui.line(back_values.color(Color32::RED)); + + area_list.push({ + if let Some(bars_data) = bars { + let (bar_chart, area) = bars_data; + plot_ui.bar_chart(bar_chart.color(Color32::BLUE).width(step)); + digits_precision(area, 8) + } else { + f64::NAN + } + }); + } + }); }); self.last_info = (area_list, start.elapsed());