use crate::controllers::ThresholdController;
use crate::controllers::TracesController;
use crate::controllers::{FFTController, UiActionController, WindowController};
use crate::data::hotkeys::Hotkeys;
use crate::data::x_formatter::XFormatter;
use crate::events::EventController;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum ScopeButton {
Scopes,
Traces,
Math,
Hotkeys,
Thresholds,
Triggers,
Measurement,
Fft,
Export,
PauseResume,
ClearAll,
Custom(String),
}
impl ScopeButton {
pub fn matches_panel_title(&self, title: &str) -> bool {
match self {
ScopeButton::Traces => title == "Traces",
ScopeButton::Math => title == "Math",
ScopeButton::Hotkeys => title == "Hotkeys",
ScopeButton::Thresholds => title == "Thresholds",
ScopeButton::Triggers => title == "Triggers",
ScopeButton::Measurement => title == "Measurement",
ScopeButton::Fft => title == "FFT",
ScopeButton::Export => title == "Export",
ScopeButton::Custom(t) => t.as_str() == title,
ScopeButton::Scopes | ScopeButton::PauseResume | ScopeButton::ClearAll => false,
}
}
pub fn all_defaults() -> Vec<ScopeButton> {
vec![
ScopeButton::Scopes,
ScopeButton::Traces,
ScopeButton::Math,
ScopeButton::Hotkeys,
ScopeButton::Thresholds,
ScopeButton::Triggers,
ScopeButton::Measurement,
ScopeButton::Fft,
ScopeButton::Export,
ScopeButton::PauseResume,
ScopeButton::ClearAll,
]
}
}
pub use crate::{ColorScheme, CustomColorScheme};
#[derive(Clone, Debug)]
pub struct FeatureFlags {
pub top_bar: bool,
pub sidebar: bool,
pub markers: bool,
pub thresholds: bool,
pub triggers: bool,
pub measurement: bool,
pub export: bool,
pub math: bool,
pub hotkeys: bool,
pub fft: bool,
pub x_tick_labels: bool,
pub y_tick_labels: bool,
pub grid: bool,
pub legend: bool,
pub scopes: bool,
pub pause_resume: bool,
pub clear_all: bool,
}
impl Default for FeatureFlags {
fn default() -> Self {
Self {
top_bar: true,
sidebar: true,
markers: true,
thresholds: true,
triggers: true,
measurement: true,
export: true,
math: true,
hotkeys: true,
fft: true,
x_tick_labels: true,
y_tick_labels: true,
grid: true,
legend: true,
scopes: true,
pause_resume: true,
clear_all: true,
}
}
}
#[derive(Clone, Debug)]
pub struct ResponsiveLayout {
pub top_bar_buttons: Option<Vec<ScopeButton>>,
pub sidebar_buttons: Option<Vec<ScopeButton>>,
pub min_width_for_y_ticklabels: f32,
pub min_height_for_x_ticklabels: f32,
pub min_height_for_top_bar: f32,
pub min_width_for_sidebar: f32,
pub min_height_for_sidebar: f32,
pub min_width_for_legend: f32,
pub min_height_for_legend: f32,
}
impl Default for ResponsiveLayout {
fn default() -> Self {
Self {
top_bar_buttons: None,
sidebar_buttons: None,
min_width_for_y_ticklabels: 250.0,
min_height_for_x_ticklabels: 200.0,
min_height_for_top_bar: 200.0,
min_width_for_sidebar: 150.0,
min_height_for_sidebar: 200.0,
min_width_for_legend: 0.0,
min_height_for_legend: 0.0,
}
}
}
#[derive(Clone, Debug)]
pub struct AutoFitConfig {
pub auto_fit_to_view: bool,
pub keep_max_fit: bool,
}
impl Default for AutoFitConfig {
fn default() -> Self {
Self {
auto_fit_to_view: true,
keep_max_fit: false,
}
}
}
#[derive(Clone, Default)]
pub struct Controllers {
pub window: Option<WindowController>,
pub fft: Option<FFTController>,
pub ui_action: Option<UiActionController>,
pub threshold: Option<ThresholdController>,
pub traces: Option<TracesController>,
pub event: Option<EventController>,
}
pub struct LivePlotConfig {
pub time_window_secs: f64,
pub max_points: usize,
pub y_unit: Option<String>,
pub y_log: bool,
pub title: String,
pub headline: Option<String>,
pub subheadline: Option<String>,
pub native_options: Option<eframe::NativeOptions>,
pub features: FeatureFlags,
pub layout: ResponsiveLayout,
pub color_scheme: ColorScheme,
pub overlays: Option<
Box<
dyn for<'a> FnMut(
&mut egui_plot::PlotUi,
&crate::data::scope::ScopeData,
&crate::data::traces::TracesCollection,
) + 'static,
>,
>,
pub auto_fit: AutoFitConfig,
pub x_formatter: XFormatter,
pub hotkeys: Option<Hotkeys>,
pub controllers: Controllers,
}
impl Clone for LivePlotConfig {
fn clone(&self) -> Self {
Self {
time_window_secs: self.time_window_secs,
max_points: self.max_points,
y_unit: self.y_unit.clone(),
y_log: self.y_log,
title: self.title.clone(),
headline: self.headline.clone(),
subheadline: self.subheadline.clone(),
native_options: self.native_options.clone(),
features: self.features.clone(),
layout: self.layout.clone(),
color_scheme: self.color_scheme.clone(),
overlays: None, auto_fit: self.auto_fit.clone(),
x_formatter: self.x_formatter.clone(),
hotkeys: self.hotkeys.clone(),
controllers: self.controllers.clone(),
}
}
}
impl Default for LivePlotConfig {
fn default() -> Self {
Self {
time_window_secs: 10.0,
max_points: 10_000,
y_unit: None,
y_log: false,
title: "LivePlot".to_string(),
headline: None,
subheadline: None,
native_options: None,
features: FeatureFlags::default(),
layout: ResponsiveLayout::default(),
color_scheme: ColorScheme::default(),
overlays: None,
auto_fit: AutoFitConfig::default(),
x_formatter: XFormatter::Auto,
hotkeys: None,
controllers: Controllers::default(),
}
}
}