refactor: small time series graph refactor (#2060)

Just a quick refactor.
This commit is contained in:
Clement Tsang
2026-05-09 03:30:34 -04:00
committed by GitHub
parent 2c7c6c25be
commit 55d5402603
7 changed files with 11 additions and 13 deletions
@@ -26,3 +26,5 @@ Note that key bindings are generally case-sensitive.
| Binding | Action | | Binding | Action |
| ------------ | -------------------------------------------------------------- | | ------------ | -------------------------------------------------------------- |
| ++"Scroll"++ | Scrolling up or down zooms in or out of the graph respectively | | ++"Scroll"++ | Scrolling up or down zooms in or out of the graph respectively |
<!--TODO: Add screenshots of widgets -->
+2
View File
@@ -62,6 +62,8 @@ pub struct TimeSeriesData {
pub gpu_mem: HashMap<String, Values>, pub gpu_mem: HashMap<String, Values>,
/// Temperature data. /// Temperature data.
///
/// TODO: Maybe make this use TypedTemperature?
pub temperature: HashMap<String, ChunkedData<f32>>, pub temperature: HashMap<String, ChunkedData<f32>>,
} }
+3 -9
View File
@@ -34,21 +34,15 @@ pub struct TimeseriesState {
} }
impl TimeseriesState { impl TimeseriesState {
/// Create a new [`TimeseriesState`] using the given config. /// Create a new [`TimeseriesState`] using the given config and `autohide_timer` setting.
pub fn new(config: TimeseriesConfig) -> Self { pub fn new(config: TimeseriesConfig, autohide_timer: Option<Instant>) -> Self {
Self { Self {
current_display_time: config.default_time_value, current_display_time: config.default_time_value,
config, config,
autohide_timer: None, autohide_timer,
} }
} }
/// Set the autohide timer.
pub fn with_autohide_timer(mut self, autohide_timer: Option<Instant>) -> Self {
self.autohide_timer = autohide_timer;
self
}
/// Get a mutable reference to the autohide timer. /// Get a mutable reference to the autohide timer.
pub fn autohide_timer_mut(&mut self) -> &mut Option<Instant> { pub fn autohide_timer_mut(&mut self) -> &mut Option<Instant> {
&mut self.autohide_timer &mut self.autohide_timer
+1 -1
View File
@@ -99,7 +99,7 @@ pub struct AutoYAxisTimeGraph {
impl AutoYAxisTimeGraph { impl AutoYAxisTimeGraph {
pub(crate) fn new(config: TimeseriesConfig, autohide_timer: Option<Instant>) -> Self { pub(crate) fn new(config: TimeseriesConfig, autohide_timer: Option<Instant>) -> Self {
AutoYAxisTimeGraph { AutoYAxisTimeGraph {
state: TimeseriesState::new(config).with_autohide_timer(autohide_timer), state: TimeseriesState::new(config, autohide_timer),
height_cache: GraphHeightCache::default(), height_cache: GraphHeightCache::default(),
} }
} }
+2 -2
View File
@@ -7,7 +7,7 @@ use super::{
}; };
/// A time series graph that expects data to be in a percentage format, /// 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 { pub struct PercentTimeGraph {
state: TimeseriesState, state: TimeseriesState,
} }
@@ -15,7 +15,7 @@ pub struct PercentTimeGraph {
impl PercentTimeGraph { impl PercentTimeGraph {
pub(crate) fn new(config: TimeseriesConfig, autohide_timer: Option<Instant>) -> Self { pub(crate) fn new(config: TimeseriesConfig, autohide_timer: Option<Instant>) -> Self {
PercentTimeGraph { PercentTimeGraph {
state: TimeseriesState::new(config).with_autohide_timer(autohide_timer), state: TimeseriesState::new(config, autohide_timer),
} }
} }
+1 -1
View File
@@ -53,7 +53,7 @@ pub(crate) struct GeneralConfig {
pub(crate) disable_click: Option<bool>, pub(crate) disable_click: Option<bool>,
pub(crate) disable_keys: Option<bool>, pub(crate) disable_keys: Option<bool>,
pub(crate) no_write: Option<bool>, pub(crate) no_write: Option<bool>,
pub(crate) network_legend: Option<String>, pub(crate) network_legend: Option<String>, // TODO: Migrate this to per-widget config
pub(crate) memory_legend: Option<String>, pub(crate) memory_legend: Option<String>,
pub(crate) process_memory_as_value: Option<bool>, pub(crate) process_memory_as_value: Option<bool>,
pub(crate) tree: Option<bool>, pub(crate) tree: Option<bool>,