diff --git a/src/app/data_harvester/cpu/heim.rs b/src/app/data_harvester/cpu/heim.rs index cdb6c8c2..de4fd033 100644 --- a/src/app/data_harvester/cpu/heim.rs +++ b/src/app/data_harvester/cpu/heim.rs @@ -18,7 +18,10 @@ cfg_if::cfg_if! { } } -use crate::data_harvester::cpu::{CpuData, CpuDataType, CpuHarvest, PastCpuTotal, PastCpuWork}; +use crate::{ + components::tui_widget::time_chart::Point, + data_harvester::cpu::{CpuData, CpuDataType, CpuHarvest, PastCpuTotal, PastCpuWork}, +}; use futures::StreamExt; use std::collections::VecDeque; @@ -28,8 +31,8 @@ pub async fn get_cpu_data_list( previous_average_cpu_time: &mut Option<(PastCpuWork, PastCpuTotal)>, ) -> crate::error::Result { fn calculate_cpu_usage_percentage( - (previous_working_time, previous_total_time): (f64, f64), - (current_working_time, current_total_time): (f64, f64), + (previous_working_time, previous_total_time): Point, + (current_working_time, current_total_time): Point, ) -> f64 { ((if current_working_time > previous_working_time { current_working_time - previous_working_time diff --git a/src/app/data_harvester/cpu/heim/linux.rs b/src/app/data_harvester/cpu/heim/linux.rs index 542685d4..f7bf3ead 100644 --- a/src/app/data_harvester/cpu/heim/linux.rs +++ b/src/app/data_harvester/cpu/heim/linux.rs @@ -1,7 +1,9 @@ //! Linux-specific functions regarding CPU usage. +use crate::components::tui_widget::time_chart::Point; use heim::cpu::os::linux::CpuTimeExt; -pub fn convert_cpu_times(cpu_time: &heim::cpu::CpuTime) -> (f64, f64) { + +pub fn convert_cpu_times(cpu_time: &heim::cpu::CpuTime) -> Point { let working_time: f64 = (cpu_time.user() + cpu_time.nice() + cpu_time.system() diff --git a/src/app/data_harvester/cpu/heim/windows_macos.rs b/src/app/data_harvester/cpu/heim/windows_macos.rs index 34abc818..6c110aab 100644 --- a/src/app/data_harvester/cpu/heim/windows_macos.rs +++ b/src/app/data_harvester/cpu/heim/windows_macos.rs @@ -1,6 +1,8 @@ //! Windows and macOS-specific functions regarding CPU usage. -pub fn convert_cpu_times(cpu_time: &heim::cpu::CpuTime) -> (f64, f64) { +use crate::components::tui_widget::time_chart::Point; + +pub fn convert_cpu_times(cpu_time: &heim::cpu::CpuTime) -> Point { let working_time: f64 = (cpu_time.user() + cpu_time.system()).get::(); ( diff --git a/src/app/data_harvester/processes/linux.rs b/src/app/data_harvester/processes/linux.rs index a53a3e9a..a2e5e253 100644 --- a/src/app/data_harvester/processes/linux.rs +++ b/src/app/data_harvester/processes/linux.rs @@ -2,6 +2,7 @@ use std::collections::hash_map::Entry; +use crate::components::tui_widget::time_chart::Point; use crate::utils::error::{self, BottomError}; use crate::Pid; @@ -36,7 +37,7 @@ impl PrevProcDetails { } } -fn calculate_idle_values(line: String) -> (f64, f64) { +fn calculate_idle_values(line: String) -> Point { /// Converts a `Option<&str>` value to an f64. If it fails to parse or is `None`, then it will return `0_f64`. fn str_to_f64(val: Option<&str>) -> f64 { val.and_then(|v| v.parse::().ok()).unwrap_or(0_f64) @@ -61,9 +62,7 @@ fn calculate_idle_values(line: String) -> (f64, f64) { (idle, non_idle) } -fn cpu_usage_calculation( - prev_idle: &mut f64, prev_non_idle: &mut f64, -) -> error::Result<(f64, f64)> { +fn cpu_usage_calculation(prev_idle: &mut f64, prev_non_idle: &mut f64) -> error::Result { use std::io::prelude::*; use std::io::BufReader; diff --git a/src/canvas.rs b/src/canvas.rs index 13d79583..f171bddd 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -455,7 +455,7 @@ impl Painter { #[cfg(feature = "zfs")] { - let arc_data: &[(f64, f64)] = &app_state.converted_data.arc_data; + let arc_data = &app_state.converted_data.arc_data; if let Some(arc) = arc_data.last() { if arc.1 != 0.0 { mem_rows += 1; // add row for arc diff --git a/src/canvas/widgets/mem_basic.rs b/src/canvas/widgets/mem_basic.rs index 1d3c9969..3e5e585d 100644 --- a/src/canvas/widgets/mem_basic.rs +++ b/src/canvas/widgets/mem_basic.rs @@ -13,8 +13,8 @@ impl Painter { pub fn draw_basic_memory( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, ) { - let mem_data: &[(f64, f64)] = &app_state.converted_data.mem_data; - let swap_data: &[(f64, f64)] = &app_state.converted_data.swap_data; + let mem_data = &app_state.converted_data.mem_data; + let swap_data = &app_state.converted_data.swap_data; let margined_loc = Layout::default() .constraints({ @@ -90,7 +90,7 @@ impl Painter { #[cfg(feature = "zfs")] { - let arc_data: &[(f64, f64)] = &app_state.converted_data.arc_data; + let arc_data = &app_state.converted_data.arc_data; let arc_ratio = if let Some(arc) = arc_data.last() { arc.1 / 100.0 } else { diff --git a/src/canvas/widgets/mem_graph.rs b/src/canvas/widgets/mem_graph.rs index 25ca272e..bd959d28 100644 --- a/src/canvas/widgets/mem_graph.rs +++ b/src/canvas/widgets/mem_graph.rs @@ -32,7 +32,7 @@ impl Painter { let mut size = 0; #[cfg(feature = "zfs")] { - let arc_data: &[(f64, f64)] = &app_state.converted_data.arc_data; + let arc_data = &app_state.converted_data.arc_data; if let Some(arc) = arc_data.last() { if arc.1 != 0.0 { size += 1; // add capacity for ARC @@ -61,7 +61,7 @@ impl Painter { } #[cfg(feature = "zfs")] if let Some((label_percent, label_frac)) = &app_state.converted_data.arc_labels { - let arc_data: &[(f64, f64)] = &app_state.converted_data.arc_data; + let arc_data = &app_state.converted_data.arc_data; if let Some(arc) = arc_data.last() { if arc.1 != 0.0 { let arc_label = format!("ARC:{}{}", label_percent, label_frac); diff --git a/src/canvas/widgets/network_graph.rs b/src/canvas/widgets/network_graph.rs index c70f496d..ad8c9679 100644 --- a/src/canvas/widgets/network_graph.rs +++ b/src/canvas/widgets/network_graph.rs @@ -1,7 +1,10 @@ use crate::{ app::{App, AxisScaling}, canvas::{drawing_utils::should_hide_x_label, Painter}, - components::time_graph::{GraphData, Point, TimeGraph}, + components::{ + time_graph::{GraphData, TimeGraph}, + tui_widget::time_chart::Point, + }, units::data_units::DataUnit, utils::gen_util::*, }; @@ -52,8 +55,8 @@ impl Painter { hide_legend: bool, ) { if let Some(network_widget_state) = app_state.net_state.widget_states.get_mut(&widget_id) { - let network_data_rx: &[(f64, f64)] = &app_state.converted_data.network_data_rx; - let network_data_tx: &[(f64, f64)] = &app_state.converted_data.network_data_tx; + let network_data_rx = &app_state.converted_data.network_data_rx; + let network_data_tx = &app_state.converted_data.network_data_tx; let time_start = -(network_widget_state.current_display_time as f64); let border_style = self.get_border_style(widget_id, app_state.current_widget.widget_id); let x_bounds = [0, network_widget_state.current_display_time]; @@ -201,7 +204,7 @@ impl Painter { fn get_max_entry( rx: &[Point], tx: &[Point], time_start: f64, network_scale_type: &AxisScaling, network_use_binary_prefix: bool, -) -> (f64, f64) { +) -> Point { /// Determines a "fake" max value in circumstances where we couldn't find one from the data. fn calculate_missing_max( network_scale_type: &AxisScaling, network_use_binary_prefix: bool, diff --git a/src/components/time_graph.rs b/src/components/time_graph.rs index 11527eb3..6403eb45 100644 --- a/src/components/time_graph.rs +++ b/src/components/time_graph.rs @@ -13,10 +13,7 @@ use tui::{ use concat_string::concat_string; use unicode_segmentation::UnicodeSegmentation; -use super::tui_widget::time_chart::{Axis, Dataset, TimeChart, DEFAULT_LEGEND_CONSTRAINTS}; - -/// A single graph point. -pub type Point = (f64, f64); // FIXME: Move this to tui time chart? +use super::tui_widget::time_chart::{Axis, Dataset, Point, TimeChart, DEFAULT_LEGEND_CONSTRAINTS}; /// Represents the data required by the [`TimeGraph`]. pub struct GraphData<'a> { diff --git a/src/components/tui_widget/time_chart.rs b/src/components/tui_widget/time_chart.rs index 7b791d1d..249568f8 100644 --- a/src/components/tui_widget/time_chart.rs +++ b/src/components/tui_widget/time_chart.rs @@ -14,6 +14,9 @@ use unicode_width::UnicodeWidthStr; use crate::utils::gen_util::partial_ordering; +/// A single graph point. +pub type Point = (f64, f64); + /// An X or Y axis for the chart widget #[derive(Debug, Clone)] pub struct Axis<'a> { @@ -70,7 +73,7 @@ pub struct Dataset<'a> { /// Name of the dataset (used in the legend if shown) name: Cow<'a, str>, /// A reference to the actual data - data: &'a [(f64, f64)], + data: &'a [Point], /// Symbol used for each points of this dataset marker: symbols::Marker, /// Determines graph type used for drawing points @@ -101,7 +104,7 @@ impl<'a> Dataset<'a> { self } - pub fn data(mut self, data: &'a [(f64, f64)]) -> Dataset<'a> { + pub fn data(mut self, data: &'a [Point]) -> Dataset<'a> { self.data = data; self } @@ -589,7 +592,7 @@ fn get_end(dataset: &Dataset<'_>, end_bound: f64) -> (usize, Option) { } /// Returns the y-axis value for a given `x`, given two points to draw a line between. -fn interpolate_point(older_point: &(f64, f64), newer_point: &(f64, f64), x: f64) -> f64 { +fn interpolate_point(older_point: &Point, newer_point: &Point, x: f64) -> f64 { let delta_x = newer_point.0 - older_point.0; let delta_y = newer_point.1 - older_point.1; let slope = delta_y / delta_x; diff --git a/src/data_conversion.rs b/src/data_conversion.rs index eabaaf55..4575bf42 100644 --- a/src/data_conversion.rs +++ b/src/data_conversion.rs @@ -7,7 +7,7 @@ use crate::app::{ data_harvester::temperature::TemperatureType, widgets::{DiskWidgetData, TempWidgetData}, }; -use crate::components::time_graph::Point; +use crate::components::tui_widget::time_chart::Point; use crate::utils::gen_util::*; use crate::{app::AxisScaling, units::data_units::DataUnit};