66 lines
1.9 KiB
Rust
66 lines
1.9 KiB
Rust
use eframe::egui;
|
|
use egui_plot::{Line, Plot, PlotPoints};
|
|
|
|
use crate::{formatters};
|
|
|
|
use crate::StatusMessage;
|
|
|
|
pub fn show_freuqencies(ui: &mut egui::Ui, state: &StatusMessage) {
|
|
ui.horizontal(|ui| {
|
|
ui.label(
|
|
egui::RichText::new(format!(
|
|
"Measured: {}",
|
|
formatters::frequency(state.measured_frequency as f64/ 1_000_000_000.0)
|
|
))
|
|
.family(egui::FontFamily::Monospace)
|
|
.size(20.0),
|
|
);
|
|
|
|
ui.add_space(100.0);
|
|
|
|
ui.label(
|
|
egui::RichText::new(format!(
|
|
"Average: {}",
|
|
formatters::frequency(state.average_frequency as f64 / 1_000_000_000.0)
|
|
))
|
|
.family(egui::FontFamily::Monospace)
|
|
.size(20.0),
|
|
);
|
|
});
|
|
}
|
|
|
|
pub fn show_plots(ui: &mut egui::Ui, average_points: &Vec<[f64; 2]>, pwm_points: &Vec<[f64; 2]>) {
|
|
let average_line = Line::new(PlotPoints::new(average_points.clone()));
|
|
Plot::new("frequency_plot")
|
|
.width(900.0)
|
|
.view_aspect(3.0)
|
|
.allow_zoom(false)
|
|
.allow_scroll(false)
|
|
.allow_drag(false)
|
|
.allow_boxed_zoom(false)
|
|
.y_axis_width(12)
|
|
.y_axis_formatter(|val, _, _| formatters::frequency(val))
|
|
.label_formatter(|name, value| format!("{}: {}", name, formatters::frequency(value.y)))
|
|
.show(ui, |plot_ui| {
|
|
plot_ui.set_auto_bounds([true, true].into());
|
|
plot_ui.line(average_line);
|
|
//plot_ui.line(measured_line);
|
|
});
|
|
|
|
ui.add_space(20.0);
|
|
|
|
let pwm_line = Line::new(PlotPoints::new(pwm_points.clone()));
|
|
Plot::new("pwm_plot")
|
|
.width(900.0)
|
|
.view_aspect(3.0)
|
|
.allow_zoom(false)
|
|
.allow_scroll(false)
|
|
.allow_drag(false)
|
|
.allow_boxed_zoom(false)
|
|
.y_axis_width(12)
|
|
.show(ui, |plot_ui| {
|
|
plot_ui.set_auto_bounds([true, true].into());
|
|
plot_ui.line(pwm_line);
|
|
});
|
|
}
|