progress
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
use crate::chart_manager::ChartManager;
|
||||
use crate::misc::{digits_precision, test_func};
|
||||
use crate::misc::{digits_precision, test_func, Cache};
|
||||
use eframe::{egui, epi};
|
||||
use egui::widgets::plot::{Bar, BarChart};
|
||||
use egui::{
|
||||
plot::{Line, Plot, Value, Values},
|
||||
};
|
||||
use egui::{Color32};
|
||||
use std::time::Instant;
|
||||
use egui::{Color32, plot};
|
||||
|
||||
pub struct MathApp {
|
||||
func_str: String,
|
||||
@@ -15,6 +14,7 @@ pub struct MathApp {
|
||||
num_interval: usize,
|
||||
resolution: usize,
|
||||
chart_manager: ChartManager,
|
||||
bar_cache: Cache<Vec<Bar>>,
|
||||
}
|
||||
|
||||
impl Default for MathApp {
|
||||
@@ -26,6 +26,7 @@ impl Default for MathApp {
|
||||
num_interval: 100,
|
||||
resolution: 10000,
|
||||
chart_manager: ChartManager::new("x^2".to_string(), -10.0, 10.0, 100, 10000),
|
||||
bar_cache: Cache::new_empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,10 +48,13 @@ impl epi::App for MathApp {
|
||||
min_x,
|
||||
max_x,
|
||||
num_interval,
|
||||
resolution: _,
|
||||
resolution,
|
||||
chart_manager,
|
||||
bar_cache,
|
||||
} = self;
|
||||
let start = Instant::now();
|
||||
|
||||
// Note: This Instant implementation does not show microseconds when using wasm.
|
||||
let start = instant::Instant::now();
|
||||
|
||||
let min_x_total: f32 = -1000.0;
|
||||
let max_x_total: f32 = 1000.0;
|
||||
@@ -91,6 +95,10 @@ impl epi::App for MathApp {
|
||||
ui.add(egui::Slider::new(num_interval, 1..=usize::MAX).text("Interval"));
|
||||
});
|
||||
|
||||
|
||||
let update_back = chart_manager.do_update_back(func_str.clone(), *min_x, *max_x);
|
||||
let update_front = chart_manager.do_update_front(*num_interval, *resolution);
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
if !parse_error.is_empty() {
|
||||
ui.label(format!("Error: {}", parse_error));
|
||||
@@ -99,10 +107,10 @@ impl epi::App for MathApp {
|
||||
|
||||
let (filtered_data, rect_data, area) = chart_manager.update(
|
||||
self.func_str.clone(),
|
||||
self.min_x,
|
||||
self.max_x,
|
||||
self.num_interval,
|
||||
self.resolution,
|
||||
*min_x,
|
||||
*max_x,
|
||||
*num_interval,
|
||||
*resolution,
|
||||
);
|
||||
|
||||
let filtered_data_values = filtered_data
|
||||
@@ -112,17 +120,39 @@ impl epi::App for MathApp {
|
||||
|
||||
let curve = Line::new(Values::from_values(filtered_data_values)).color(Color32::RED);
|
||||
|
||||
let bars = rect_data
|
||||
.iter()
|
||||
.map(|(x, y)| Bar::new(*x, *y))
|
||||
.collect();
|
||||
let barchart = BarChart::new(bars).color(Color32::BLUE);
|
||||
let bars: Vec<Bar> = match update_front {
|
||||
true => {
|
||||
let bars: Vec<Bar> = rect_data
|
||||
.iter()
|
||||
.map(|(x, y)| Bar::new(*x, *y))
|
||||
.collect();
|
||||
|
||||
bar_cache.set(bars.clone());
|
||||
bars
|
||||
},
|
||||
false => {
|
||||
if bar_cache.is_valid() {
|
||||
bar_cache.get().clone()
|
||||
} else {
|
||||
let bars: Vec<Bar> = rect_data
|
||||
.iter()
|
||||
.map(|(x, y)| Bar::new(*x, *y))
|
||||
.collect();
|
||||
|
||||
bar_cache.set(bars.clone());
|
||||
bars
|
||||
}
|
||||
},
|
||||
};
|
||||
let bar_chart = BarChart::new(bars).color(Color32::BLUE);
|
||||
|
||||
|
||||
Plot::new("plot")
|
||||
.view_aspect(1.0)
|
||||
.include_y(0)
|
||||
.show(ui, |plot_ui| {
|
||||
plot_ui.line(curve);
|
||||
plot_ui.bar_chart(barchart);
|
||||
plot_ui.bar_chart(bar_chart);
|
||||
});
|
||||
|
||||
let duration = start.elapsed();
|
||||
|
||||
Reference in New Issue
Block a user