78 lines
2.3 KiB
Rust
78 lines
2.3 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::format_frequency_mhz(state.measured_frequency as f64 / 1000.0)
|
|
))
|
|
.family(egui::FontFamily::Monospace)
|
|
.size(20.0),
|
|
);
|
|
|
|
ui.add_space(100.0);
|
|
|
|
ui.label(
|
|
egui::RichText::new(format!(
|
|
"Average: {}",
|
|
formatters::format_frequency_mhz(state.average_frequency as f64 / 1000.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::format_frequency_mhz(val))
|
|
.label_formatter(|name, value| {
|
|
if !name.is_empty() {
|
|
format!("{}: {}", name, formatters::format_frequency_mhz(value.y))
|
|
} else {
|
|
format!(
|
|
"x = {}\ny= {}",
|
|
value.x,
|
|
formatters::format_frequency_mhz(value.y)
|
|
)
|
|
}
|
|
})
|
|
.link_cursor("plots", true, false)
|
|
.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)
|
|
.link_cursor("plots", true, false)
|
|
.show(ui, |plot_ui| {
|
|
plot_ui.set_auto_bounds([true, true].into());
|
|
plot_ui.line(pwm_line);
|
|
});
|
|
}
|