From 477514697c260e7b3dd99754b256b8775458eac3 Mon Sep 17 00:00:00 2001 From: ClementTsang <34804052+ClementTsang@users.noreply.github.com> Date: Sun, 1 Jun 2025 01:15:17 -0400 Subject: [PATCH] some starting work on a temp graph widget; I'll do disk in a separate PR --- src/app/data/time_series.rs | 4 +++ src/widgets/disk_graph.rs | 2 ++ src/widgets/mod.rs | 6 ++++ src/widgets/temperature_graph.rs | 56 ++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) diff --git a/src/app/data/time_series.rs b/src/app/data/time_series.rs index d93f2130..a89bb818 100644 --- a/src/app/data/time_series.rs +++ b/src/app/data/time_series.rs @@ -55,6 +55,10 @@ pub struct TimeSeriesData { #[cfg(feature = "gpu")] /// GPU memory data. pub gpu_mem: HashMap, + + /// Temperature data, if needed. A mapping of sensor names to + /// their temperature values. + pub temp: HashMap, } impl TimeSeriesData { diff --git a/src/widgets/disk_graph.rs b/src/widgets/disk_graph.rs index 560a1f9e..137ea60e 100644 --- a/src/widgets/disk_graph.rs +++ b/src/widgets/disk_graph.rs @@ -1 +1,3 @@ //! Code for a disk graph widget. + +// TODO: Implement this. diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index ffe50b9c..67351355 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -19,3 +19,9 @@ pub use network_graph::*; pub use process_table::*; pub use temperature_graph::*; pub use temperature_table::*; + +/// Whether an event is handled by the current element or not. +pub enum EventHandled { + Handled, + NotHandled, +} diff --git a/src/widgets/temperature_graph.rs b/src/widgets/temperature_graph.rs index 9f5bec14..9f73b3bb 100644 --- a/src/widgets/temperature_graph.rs +++ b/src/widgets/temperature_graph.rs @@ -1 +1,57 @@ //! Code for a temperature graph widget. + +use std::time::Instant; + +use crossterm::event::{KeyEvent, MouseEvent}; +use tui::{Frame, layout::Rect}; + +use crate::app::{App, data::TemperatureType}; + +use super::EventHandled; + +/// A temperature graph widget. +/// +/// The current implementation of this uses tuine-style code; this will +/// become the standard later on for all widgets. +#[derive(Default)] +pub struct TemperatureGraph { + current_display_time: u64, + autohide_timer: Option, + current_max_temperature: u32, + temperature_unit: TemperatureType, +} + +impl TemperatureGraph { + pub fn temperature_unit(mut self, unit: TemperatureType) -> Self { + self.temperature_unit = unit; + self + } + + /// How this widget handles key events. + /// + /// TODO: This may merge with [`Self::handle_mouse_event`] in the future. + pub fn handle_key_event(event: KeyEvent) -> EventHandled { + EventHandled::NotHandled + } + + /// How this widget handles mouse events. + /// + /// TODO: This may merge with [`Self::handle_key_event`] in the future. + pub fn handle_mouse_event(event: MouseEvent) -> EventHandled { + EventHandled::NotHandled + } + + // /// How to lay out this widget in terms of sizing. + // + // For now, this is not implemented, and we will directly give sizes. + // pub fn layout() {} + + /// How to draw this widget. + /// + /// This implementation is a bit of a hack/placeholder, in the future we don't want to bring in stuff like [`App`]. + pub fn draw(&mut self, frame: &mut Frame<'_>, app_state: &mut App, draw_area: Rect) { + let data = &app_state.data_store.get_data().timeseries_data.temp; + + // Inspect the newest entry of each sensor to determine the current max temperature. + } +}