From a34e37e3f72ffbf8b9ad606248c8c1bab78c7bd1 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Mon, 7 Mar 2022 20:16:19 -0500 Subject: [PATCH] name lines --- src/egui_app.rs | 25 ++++++++++++++++++------- src/function.rs | 2 ++ src/parsing.rs | 2 ++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/egui_app.rs b/src/egui_app.rs index 7eb900e..8320f75 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -481,20 +481,31 @@ impl epi::App for MathApp { function.update_bounds(minx_bounds, maxx_bounds, available_width); let (back_values, bars, derivative) = function.run(); - plot_ui.line(back_values.color(Color32::RED)); + let func_str = function.get_func_str(); + plot_ui.line(back_values.color(Color32::RED).name(func_str)); if let Some(derivative_data) = derivative { - plot_ui.line(derivative_data.color(Color32::GREEN)); + plot_ui.line( + derivative_data + .color(Color32::GREEN) + .name(function.get_derivative_str()), + ); } if let Some(bars_data) = bars { let (integral_bar, integral_line, area) = bars_data; match self.settings.integral_display_type { - IntegralDisplay::Rectangles => plot_ui - .bar_chart(integral_bar.color(Color32::BLUE).width(step)), - IntegralDisplay::Line => { - plot_ui.line(integral_line.color(Color32::BLUE)) - } + IntegralDisplay::Rectangles => plot_ui.bar_chart( + integral_bar + .color(Color32::BLUE) + .width(step) + .name(format!("Integral of {}", func_str)), + ), + IntegralDisplay::Line => plot_ui.line( + integral_line + .color(Color32::BLUE) + .name(format!("Integral of {}", func_str)), + ), } digits_precision(area, 8) } else { diff --git a/src/function.rs b/src/function.rs index c2e261a..f67b85a 100644 --- a/src/function.rs +++ b/src/function.rs @@ -310,6 +310,8 @@ impl FunctionEntry { self.integral_max_x = max_x; self } + + pub fn get_derivative_str(&self) -> &str { self.function.get_derivative_str() } } #[test] diff --git a/src/parsing.rs b/src/parsing.rs index 3ae0be8..eab5078 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -19,6 +19,8 @@ impl BackingFunction { } } + pub fn get_derivative_str(&self) -> &str { self.derivative_1.unparse() } // TODO: maybe pretty-ify the output here? idk, it's pretty ugly + pub fn get(&self, x: f64) -> f64 { self.function.eval(&[x]).unwrap_or(f64::NAN) } pub fn derivative(&self, x: f64) -> f64 { self.derivative_1.eval(&[x]).unwrap_or(f64::NAN) }