diff --git a/Cargo.toml b/Cargo.toml index e9d21213..44746c2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ dirs = "2.0.2" fern = "0.6.0" futures = "0.3.4" heim = "0.0.10" +itertools = "0.9.0" log = "0.4.8" regex = "1.3" sysinfo = "0.12" diff --git a/src/app.rs b/src/app.rs index bf5bc3cd..fb5c5b8f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -583,6 +583,7 @@ impl App { cpu_widget_state.scroll_state.current_scroll_position = new_position; cpu_widget_state.scroll_state.previous_scroll_position = 0; } + self.is_resized = true; } } BottomWidgetType::CpuLegend => { @@ -600,6 +601,7 @@ impl App { cpu_widget_state.scroll_state.current_scroll_position = new_position; cpu_widget_state.scroll_state.previous_scroll_position = 0; } + self.is_resized = true; } } BottomWidgetType::Proc => { @@ -614,6 +616,7 @@ impl App { .search_state .is_enabled = false; } + self.is_resized = true; } } BottomWidgetType::ProcSearch => { @@ -629,6 +632,7 @@ impl App { .is_enabled = false; self.move_widget_selection_up(); } + self.is_resized = true; } } _ => {} @@ -1943,7 +1947,7 @@ impl App { if let Some(cpu_widget_state) = self .cpu_state .widget_states - .get_mut(&self.current_widget.widget_id) + .get_mut(&(self.current_widget.widget_id - 1)) { cpu_widget_state.scroll_state.current_scroll_position = 0; cpu_widget_state.scroll_state.scroll_direction = ScrollDirection::UP; @@ -2010,7 +2014,7 @@ impl App { if let Some(cpu_widget_state) = self .cpu_state .widget_states - .get_mut(&self.current_widget.widget_id) + .get_mut(&(self.current_widget.widget_id - 1)) { let cap = if is_filtering_or_searching { self.canvas_data.cpu_data.len() diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs index b8cd06d5..9d27dd53 100644 --- a/src/app/data_farmer.rs +++ b/src/app/data_farmer.rs @@ -54,8 +54,7 @@ pub struct DataCollection { pub process_harvest: Vec, pub disk_harvest: Vec, pub io_harvest: disks::IOHarvest, - pub io_labels: Vec<(u64, u64)>, - io_prev: Vec<(u64, u64)>, + pub io_labels_and_prev: Vec<((u64, u64), (u64, u64))>, pub temp_harvest: Vec, } @@ -72,8 +71,7 @@ impl Default for DataCollection { process_harvest: Vec::default(), disk_harvest: Vec::default(), io_harvest: disks::IOHarvest::default(), - io_labels: Vec::default(), - io_prev: Vec::default(), + io_labels_and_prev: Vec::default(), temp_harvest: Vec::default(), } } @@ -89,8 +87,7 @@ impl DataCollection { self.process_harvest = Vec::default(); self.disk_harvest = Vec::default(); self.io_harvest = disks::IOHarvest::default(); - self.io_labels = Vec::default(); - self.io_prev = Vec::default(); + self.io_labels_and_prev = Vec::default(); self.temp_harvest = Vec::default(); } @@ -219,20 +216,18 @@ impl DataCollection { // Note this only pre-calculates the data points - the names will be // within the local copy of cpu_harvest. Since it's all sequential // it probably doesn't matter anyways. - for (itx, cpu) in harvested_data.cpu.iter().enumerate() { - let cpu_joining_pts = if let Some((time, last_pt)) = self.timed_data_vec.last() { - generate_joining_points( - *time, - last_pt.cpu_data[itx].0, - harvested_time, - cpu.cpu_usage, - ) - } else { - Vec::new() - }; - - let cpu_pt = (cpu.cpu_usage, cpu_joining_pts); - new_entry.cpu_data.push(cpu_pt); + if let Some((time, last_pt)) = self.timed_data_vec.last() { + for (cpu, last_pt_data) in harvested_data.cpu.iter().zip(&last_pt.cpu_data) { + let cpu_joining_pts = + generate_joining_points(*time, last_pt_data.0, harvested_time, cpu.cpu_usage); + let cpu_pt = (cpu.cpu_usage, cpu_joining_pts); + new_entry.cpu_data.push(cpu_pt); + } + } else { + for cpu in harvested_data.cpu.iter() { + let cpu_pt = (cpu.cpu_usage, Vec::new()); + new_entry.cpu_data.push(cpu_pt); + } } self.cpu_harvest = harvested_data.cpu.clone(); @@ -257,19 +252,16 @@ impl DataCollection { let io_r_pt = io.read_bytes; let io_w_pt = io.write_bytes; - if self.io_labels.len() <= itx { - self.io_prev.push((io_r_pt, io_w_pt)); - self.io_labels.push((0, 0)); - } else { - let r_rate = ((io_r_pt - self.io_prev[itx].0) as f64 - / time_since_last_harvest) - .round() as u64; - let w_rate = ((io_w_pt - self.io_prev[itx].1) as f64 - / time_since_last_harvest) - .round() as u64; + if self.io_labels_and_prev.len() <= itx { + self.io_labels_and_prev.push(((0, 0), (io_r_pt, io_w_pt))); + } else if let Some((io_curr, io_prev)) = self.io_labels_and_prev.get_mut(itx) { + let r_rate = + ((io_r_pt - io_prev.0) as f64 / time_since_last_harvest).round() as u64; + let w_rate = + ((io_w_pt - io_prev.1) as f64 / time_since_last_harvest).round() as u64; - self.io_labels[itx] = (r_rate, w_rate); - self.io_prev[itx] = (io_r_pt, io_w_pt); + *io_curr = (r_rate, w_rate); + *io_prev = (io_r_pt, io_w_pt); } } } diff --git a/src/canvas.rs b/src/canvas.rs index 8244e1d6..4dbf283a 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -1,3 +1,4 @@ +use itertools::izip; use std::cmp::max; use std::collections::HashMap; @@ -442,103 +443,101 @@ impl Painter { let col_draw_locs = self .col_constraints .iter() - .enumerate() - .map(|(itx, col_constraint)| { + .zip(&row_draw_locs) + .map(|(col_constraint, row_draw_loc)| { Layout::default() .constraints(col_constraint.as_ref()) .direction(Direction::Horizontal) - .split(row_draw_locs[itx]) + .split(*row_draw_loc) }) .collect::>(); let col_row_draw_locs = self .col_row_constraints .iter() - .enumerate() - .map(|(col_itx, col_row_constraints)| { + .zip(&col_draw_locs) + .map(|(col_row_constraints, row_draw_loc)| { col_row_constraints .iter() - .enumerate() - .map(|(itx, col_row_constraint)| { + .zip(row_draw_loc) + .map(|(col_row_constraint, col_draw_loc)| { Layout::default() .constraints(col_row_constraint.as_ref()) .direction(Direction::Vertical) - .split(col_draw_locs[col_itx][itx]) + .split(*col_draw_loc) }) .collect::>() }) .collect::>(); // Now... draw! - self.layout_constraints.iter().enumerate().for_each( - |(row_itx, col_constraint_vec)| { - col_constraint_vec.iter().enumerate().for_each( - |(col_itx, col_row_constraint_vec)| { - col_row_constraint_vec.iter().enumerate().for_each( - |(col_row_itx, widget_constraints)| { - let widget_draw_locs = Layout::default() - .constraints(widget_constraints.as_ref()) - .direction(Direction::Horizontal) - .split( - col_row_draw_locs[row_itx][col_itx][col_row_itx], - ); + izip!( + &self.layout_constraints, + col_row_draw_locs, + &self.widget_layout.rows + ) + .for_each(|(row_constraint_vec, row_draw_loc, cols)| { + izip!(row_constraint_vec, row_draw_loc, &cols.children).for_each( + |(col_constraint_vec, col_draw_loc, col_rows)| { + izip!(col_constraint_vec, col_draw_loc, &col_rows.children).for_each( + |(col_row_constraint_vec, col_row_draw_loc, widgets)| { + // Note that col_row_constraint_vec CONTAINS the widget constraints + let widget_draw_locs = Layout::default() + .constraints(col_row_constraint_vec.as_ref()) + .direction(Direction::Horizontal) + .split(col_row_draw_loc); - for (widget_itx, widget) in self.widget_layout.rows[row_itx] - .children[col_itx] - .children[col_row_itx] - .children - .iter() - .enumerate() - { - match widget.widget_type { - Empty => {} - Cpu => self.draw_cpu( - &mut f, - app_state, - widget_draw_locs[widget_itx], - widget.widget_id, - ), - Mem => self.draw_memory_graph( - &mut f, - app_state, - widget_draw_locs[widget_itx], - widget.widget_id, - ), - Net => self.draw_network( - &mut f, - app_state, - widget_draw_locs[widget_itx], - widget.widget_id, - ), - Temp => self.draw_temp_table( - &mut f, - app_state, - widget_draw_locs[widget_itx], - true, - widget.widget_id, - ), - Disk => self.draw_disk_table( - &mut f, - app_state, - widget_draw_locs[widget_itx], - true, - widget.widget_id, - ), - Proc => self.draw_process_and_search( - &mut f, - app_state, - widget_draw_locs[widget_itx], - true, - widget.widget_id, - ), - _ => {} - } + for (widget, widget_draw_loc) in + widgets.children.iter().zip(widget_draw_locs) + { + match widget.widget_type { + Empty => {} + Cpu => self.draw_cpu( + &mut f, + app_state, + widget_draw_loc, + widget.widget_id, + ), + Mem => self.draw_memory_graph( + &mut f, + app_state, + widget_draw_loc, + widget.widget_id, + ), + Net => self.draw_network( + &mut f, + app_state, + widget_draw_loc, + widget.widget_id, + ), + Temp => self.draw_temp_table( + &mut f, + app_state, + widget_draw_loc, + true, + widget.widget_id, + ), + Disk => self.draw_disk_table( + &mut f, + app_state, + widget_draw_loc, + true, + widget.widget_id, + ), + Proc => self.draw_process_and_search( + &mut f, + app_state, + widget_draw_loc, + true, + widget.widget_id, + ), + _ => {} } - }, - ); - }, - ); - }, - ); + } + }, + ); + }, + ); + }); } })?; diff --git a/src/canvas/canvas_colours/colour_utils.rs b/src/canvas/canvas_colours/colour_utils.rs index 631aac7e..35e0cb0c 100644 --- a/src/canvas/canvas_colours/colour_utils.rs +++ b/src/canvas/canvas_colours/colour_utils.rs @@ -83,10 +83,12 @@ pub fn gen_n_styles(num_to_gen: i32) -> Vec