diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2021-04-04 05:38:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-04 05:38:57 -0400 |
commit | eb6a737d3430920061cd5e54bf4dc40da21f1fc5 (patch) | |
tree | b329c4b729f31de80405b3a2d015c1525d80d618 /src/app.rs | |
parent | 40f4c796f8d1832e7ef9db7c87db558a1ce12b62 (diff) |
feature: Rework network y-axis, linear interpolation for off-screen data (#437)
Rewrite of the y-axis labeling and scaling for the network widget, along with more customization. This still has one step to be optimized (cache results so we don't have to recalculate the legend each time), but will be done in another PR for sake of this one being too large already.
Furthermore, this change adds linear interpolation at the 0 point in the case a data point shoots too far back - this seems to have lead to ugly gaps to the left of graphs in some cases, because the left hand limit was not big enough for the data point. We address this by grabbing values just outside the time range and linearly interpolating at the leftmost limit. This affects all graph widgets (CPU, mem, network).
This can be optimized, and will hopefully be prior to release in a separate change.
Diffstat (limited to 'src/app.rs')
-rw-r--r-- | src/app.rs | 71 |
1 files changed, 41 insertions, 30 deletions
@@ -21,6 +21,7 @@ use crate::{ options::Config, options::ConfigFlags, options::WidgetIdEnabled, + units::data_units::DataUnit, utils::error::{BottomError, Result}, Pid, }; @@ -34,6 +35,12 @@ pub mod states; const MAX_SEARCH_LENGTH: usize = 200; +#[derive(Debug, Clone)] +pub enum AxisScaling { + Log, + Linear, +} + /// AppConfigFields is meant to cover basic fields that would normally be set /// by config files or launch options. #[derive(Debug)] @@ -55,6 +62,10 @@ pub struct AppConfigFields { pub no_write: bool, pub show_table_scroll_position: bool, pub is_advanced_kill: bool, + // TODO: Remove these, move network details state-side. + pub network_unit_type: DataUnit, + pub network_scale_type: AxisScaling, + pub network_use_binary_prefix: bool, } /// For filtering out information @@ -708,7 +719,7 @@ impl App { if self.delete_dialog_state.is_showing_dd { if self.dd_err.is_some() { self.close_dd(); - } else if self.delete_dialog_state.selected_signal != KillSignal::CANCEL { + } else if self.delete_dialog_state.selected_signal != KillSignal::Cancel { // If within dd... if self.dd_err.is_none() { // Also ensure that we didn't just fail a dd... @@ -886,7 +897,7 @@ impl App { if kbd_signal > 31 { kbd_signal %= 10; } - self.delete_dialog_state.selected_signal = KillSignal::KILL(kbd_signal); + self.delete_dialog_state.selected_signal = KillSignal::Kill(kbd_signal); if kbd_signal < 10 { self.delete_dialog_state.keyboard_signal_select = kbd_signal; } else { @@ -991,15 +1002,15 @@ impl App { { if self.app_config_fields.is_advanced_kill { match self.delete_dialog_state.selected_signal { - KillSignal::KILL(prev_signal) => { + KillSignal::Kill(prev_signal) => { self.delete_dialog_state.selected_signal = match prev_signal - 1 { - 0 => KillSignal::CANCEL, + 0 => KillSignal::Cancel, // 32+33 are skipped - 33 => KillSignal::KILL(31), - signal => KillSignal::KILL(signal), + 33 => KillSignal::Kill(31), + signal => KillSignal::Kill(signal), }; } - KillSignal::CANCEL => {} + KillSignal::Cancel => {} }; } else { self.delete_dialog_state.selected_signal = KillSignal::default(); @@ -1007,7 +1018,7 @@ impl App { } #[cfg(target_os = "windows")] { - self.delete_dialog_state.selected_signal = KillSignal::KILL(1); + self.delete_dialog_state.selected_signal = KillSignal::Kill(1); } } } @@ -1067,23 +1078,23 @@ impl App { { if self.app_config_fields.is_advanced_kill { let new_signal = match self.delete_dialog_state.selected_signal { - KillSignal::CANCEL => 1, + KillSignal::Cancel => 1, // 32+33 are skipped #[cfg(target_os = "linux")] - KillSignal::KILL(31) => 34, + KillSignal::Kill(31) => 34, #[cfg(target_os = "macos")] - KillSignal::KILL(31) => 31, - KillSignal::KILL(64) => 64, - KillSignal::KILL(signal) => signal + 1, + KillSignal::Kill(31) => 31, + KillSignal::Kill(64) => 64, + KillSignal::Kill(signal) => signal + 1, }; - self.delete_dialog_state.selected_signal = KillSignal::KILL(new_signal); + self.delete_dialog_state.selected_signal = KillSignal::Kill(new_signal); } else { - self.delete_dialog_state.selected_signal = KillSignal::CANCEL; + self.delete_dialog_state.selected_signal = KillSignal::Cancel; } } #[cfg(target_os = "windows")] { - self.delete_dialog_state.selected_signal = KillSignal::CANCEL; + self.delete_dialog_state.selected_signal = KillSignal::Cancel; } } } @@ -1091,15 +1102,15 @@ impl App { pub fn on_page_up(&mut self) { if self.delete_dialog_state.is_showing_dd { let mut new_signal = match self.delete_dialog_state.selected_signal { - KillSignal::CANCEL => 0, - KillSignal::KILL(signal) => max(signal, 8) - 8, + KillSignal::Cancel => 0, + KillSignal::Kill(signal) => max(signal, 8) - 8, }; if new_signal > 23 && new_signal < 33 { new_signal -= 2; } self.delete_dialog_state.selected_signal = match new_signal { - 0 => KillSignal::CANCEL, - sig => KillSignal::KILL(sig), + 0 => KillSignal::Cancel, + sig => KillSignal::Kill(sig), }; } } @@ -1107,13 +1118,13 @@ impl App { pub fn on_page_down(&mut self) { if self.delete_dialog_state.is_showing_dd { let mut new_signal = match self.delete_dialog_state.selected_signal { - KillSignal::CANCEL => 8, - KillSignal::KILL(signal) => min(signal + 8, MAX_SIGNAL), + KillSignal::Cancel => 8, + KillSignal::Kill(signal) => min(signal + 8, MAX_SIGNAL), }; if new_signal > 31 && new_signal < 42 { new_signal += 2; } - self.delete_dialog_state.selected_signal = KillSignal::KILL(new_signal); + self.delete_dialog_state.selected_signal = KillSignal::Kill(new_signal); } } @@ -1672,8 +1683,8 @@ impl App { if let Some(current_selected_processes) = &self.to_delete_process_list { #[cfg(target_family = "unix")] let signal = match self.delete_dialog_state.selected_signal { - KillSignal::KILL(sig) => sig, - KillSignal::CANCEL => 15, // should never happen, so just TERM + KillSignal::Kill(sig) => sig, + KillSignal::Cancel => 15, // should never happen, so just TERM }; for pid in ¤t_selected_processes.1 { #[cfg(target_family = "unix")] @@ -2229,7 +2240,7 @@ impl App { } else if self.help_dialog_state.is_showing_help { self.help_dialog_state.scroll_state.current_scroll_index = 0; } else if self.delete_dialog_state.is_showing_dd { - self.delete_dialog_state.selected_signal = KillSignal::CANCEL; + self.delete_dialog_state.selected_signal = KillSignal::Cancel; } } @@ -2312,7 +2323,7 @@ impl App { .max_scroll_index .saturating_sub(1); } else if self.delete_dialog_state.is_showing_dd { - self.delete_dialog_state.selected_signal = KillSignal::KILL(MAX_SIGNAL); + self.delete_dialog_state.selected_signal = KillSignal::Kill(MAX_SIGNAL); } } @@ -2871,13 +2882,13 @@ impl App { }, ) { Some((_, _, _, _, 0)) => { - self.delete_dialog_state.selected_signal = KillSignal::CANCEL + self.delete_dialog_state.selected_signal = KillSignal::Cancel } Some((_, _, _, _, idx)) => { if *idx > 31 { - self.delete_dialog_state.selected_signal = KillSignal::KILL(*idx + 2) + self.delete_dialog_state.selected_signal = KillSignal::Kill(*idx + 2) } else { - self.delete_dialog_state.selected_signal = KillSignal::KILL(*idx) + self.delete_dialog_state.selected_signal = KillSignal::Kill(*idx) } } _ => {} |