From 55d54026031d70ed33c3a8e31de9d0c7e2a3b280 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Sat, 9 May 2026 03:30:34 -0400 Subject: [PATCH] refactor: small time series graph refactor (#2060) Just a quick refactor. --- docs/content/usage/widgets/temperature-graph.md | 2 ++ src/app/data/time_series.rs | 2 ++ src/{components/mod.rs => components.rs} | 0 src/components/time_series.rs | 12 +++--------- src/components/time_series/auto_y.rs | 2 +- src/components/time_series/percent.rs | 4 ++-- src/options/config/flags.rs | 2 +- 7 files changed, 11 insertions(+), 13 deletions(-) rename src/{components/mod.rs => components.rs} (100%) diff --git a/docs/content/usage/widgets/temperature-graph.md b/docs/content/usage/widgets/temperature-graph.md index 61af02e2..91db9686 100644 --- a/docs/content/usage/widgets/temperature-graph.md +++ b/docs/content/usage/widgets/temperature-graph.md @@ -26,3 +26,5 @@ Note that key bindings are generally case-sensitive. | Binding | Action | | ------------ | -------------------------------------------------------------- | | ++"Scroll"++ | Scrolling up or down zooms in or out of the graph respectively | + + diff --git a/src/app/data/time_series.rs b/src/app/data/time_series.rs index a6246bac..d1a5c27d 100644 --- a/src/app/data/time_series.rs +++ b/src/app/data/time_series.rs @@ -62,6 +62,8 @@ pub struct TimeSeriesData { pub gpu_mem: HashMap, /// Temperature data. + /// + /// TODO: Maybe make this use TypedTemperature? pub temperature: HashMap>, } diff --git a/src/components/mod.rs b/src/components.rs similarity index 100% rename from src/components/mod.rs rename to src/components.rs diff --git a/src/components/time_series.rs b/src/components/time_series.rs index d8e144e0..340f7196 100644 --- a/src/components/time_series.rs +++ b/src/components/time_series.rs @@ -34,21 +34,15 @@ pub struct TimeseriesState { } impl TimeseriesState { - /// Create a new [`TimeseriesState`] using the given config. - pub fn new(config: TimeseriesConfig) -> Self { + /// Create a new [`TimeseriesState`] using the given config and `autohide_timer` setting. + pub fn new(config: TimeseriesConfig, autohide_timer: Option) -> Self { Self { current_display_time: config.default_time_value, config, - autohide_timer: None, + autohide_timer, } } - /// Set the autohide timer. - pub fn with_autohide_timer(mut self, autohide_timer: Option) -> Self { - self.autohide_timer = autohide_timer; - self - } - /// Get a mutable reference to the autohide timer. pub fn autohide_timer_mut(&mut self) -> &mut Option { &mut self.autohide_timer diff --git a/src/components/time_series/auto_y.rs b/src/components/time_series/auto_y.rs index 127519d0..2525b572 100644 --- a/src/components/time_series/auto_y.rs +++ b/src/components/time_series/auto_y.rs @@ -99,7 +99,7 @@ pub struct AutoYAxisTimeGraph { impl AutoYAxisTimeGraph { pub(crate) fn new(config: TimeseriesConfig, autohide_timer: Option) -> Self { AutoYAxisTimeGraph { - state: TimeseriesState::new(config).with_autohide_timer(autohide_timer), + state: TimeseriesState::new(config, autohide_timer), height_cache: GraphHeightCache::default(), } } diff --git a/src/components/time_series/percent.rs b/src/components/time_series/percent.rs index 6197b671..47891af6 100644 --- a/src/components/time_series/percent.rs +++ b/src/components/time_series/percent.rs @@ -7,7 +7,7 @@ use super::{ }; /// A time series graph that expects data to be in a percentage format, -/// from 0.0 to 100.0. +/// from 0% to 100%. pub struct PercentTimeGraph { state: TimeseriesState, } @@ -15,7 +15,7 @@ pub struct PercentTimeGraph { impl PercentTimeGraph { pub(crate) fn new(config: TimeseriesConfig, autohide_timer: Option) -> Self { PercentTimeGraph { - state: TimeseriesState::new(config).with_autohide_timer(autohide_timer), + state: TimeseriesState::new(config, autohide_timer), } } diff --git a/src/options/config/flags.rs b/src/options/config/flags.rs index c8c99bbd..16f2ccff 100644 --- a/src/options/config/flags.rs +++ b/src/options/config/flags.rs @@ -53,7 +53,7 @@ pub(crate) struct GeneralConfig { pub(crate) disable_click: Option, pub(crate) disable_keys: Option, pub(crate) no_write: Option, - pub(crate) network_legend: Option, + pub(crate) network_legend: Option, // TODO: Migrate this to per-widget config pub(crate) memory_legend: Option, pub(crate) process_memory_as_value: Option, pub(crate) tree: Option,