summaryrefslogtreecommitdiffstats
path: root/src/options.rs
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2021-04-04 05:38:57 -0400
committerGitHub <noreply@github.com>2021-04-04 05:38:57 -0400
commiteb6a737d3430920061cd5e54bf4dc40da21f1fc5 (patch)
treeb329c4b729f31de80405b3a2d015c1525d80d618 /src/options.rs
parent40f4c796f8d1832e7ef9db7c87db558a1ce12b62 (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/options.rs')
-rw-r--r--src/options.rs71
1 files changed, 65 insertions, 6 deletions
diff --git a/src/options.rs b/src/options.rs
index badc32b8..7855a8da 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -12,6 +12,7 @@ use crate::{
app::{layout_manager::*, *},
canvas::ColourScheme,
constants::*,
+ units::data_units::DataUnit,
utils::error::{self, BottomError},
};
@@ -157,6 +158,15 @@ pub struct ConfigFlags {
#[builder(default, setter(strip_option))]
pub advanced_kill: Option<bool>,
+
+ #[builder(default, setter(strip_option))]
+ pub network_use_bytes: Option<bool>,
+
+ #[builder(default, setter(strip_option))]
+ pub network_use_log: Option<bool>,
+
+ #[builder(default, setter(strip_option))]
+ pub network_use_binary_prefix: Option<bool>,
}
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
@@ -265,6 +275,10 @@ pub fn build_app(
let is_default_command = get_is_default_process_command(matches, config);
let is_advanced_kill = get_is_using_advanced_kill(matches, config);
+ let network_unit_type = get_network_unit_type(matches, config);
+ let network_scale_type = get_network_scale_type(matches, config);
+ let network_use_binary_prefix = get_network_use_binary_prefix(matches, config);
+
for row in &widget_layout.rows {
for col in &row.children {
for col_row in &col.children {
@@ -319,7 +333,12 @@ pub fn build_app(
Net => {
net_state_map.insert(
widget.widget_id,
- NetWidgetState::init(default_time_value, autohide_timer),
+ NetWidgetState::init(
+ default_time_value,
+ autohide_timer,
+ // network_unit_type.clone(),
+ // network_scale_type.clone(),
+ ),
);
}
Proc => {
@@ -404,6 +423,9 @@ pub fn build_app(
no_write: false,
show_table_scroll_position: get_show_table_scroll_position(matches, config),
is_advanced_kill,
+ network_scale_type,
+ network_unit_type,
+ network_use_binary_prefix,
};
let used_widgets = UsedWidgets {
@@ -818,11 +840,9 @@ fn get_default_widget_and_count(
let widget_count = if let Some(widget_count) = matches.value_of("default_widget_count") {
Some(widget_count.parse::<u128>()?)
} else if let Some(flags) = &config.flags {
- if let Some(widget_count) = flags.default_widget_count {
- Some(widget_count as u128)
- } else {
- None
- }
+ flags
+ .default_widget_count
+ .map(|widget_count| widget_count as u128)
} else {
None
};
@@ -1031,3 +1051,42 @@ fn get_is_using_advanced_kill(matches: &clap::ArgMatches<'static>, config: &Conf
}
false
}
+
+fn get_network_unit_type(matches: &clap::ArgMatches<'static>, config: &Config) -> DataUnit {
+ if matches.is_present("network_use_bytes") {
+ return DataUnit::Byte;
+ } else if let Some(flags) = &config.flags {
+ if let Some(network_use_bytes) = flags.network_use_bytes {
+ if network_use_bytes {
+ return DataUnit::Byte;
+ }
+ }
+ }
+
+ DataUnit::Bit
+}
+
+fn get_network_scale_type(matches: &clap::ArgMatches<'static>, config: &Config) -> AxisScaling {
+ if matches.is_present("network_use_log") {
+ return AxisScaling::Log;
+ } else if let Some(flags) = &config.flags {
+ if let Some(network_use_log) = flags.network_use_log {
+ if network_use_log {
+ return AxisScaling::Log;
+ }
+ }
+ }
+
+ AxisScaling::Linear
+}
+
+fn get_network_use_binary_prefix(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
+ if matches.is_present("network_use_binary_prefix") {
+ return true;
+ } else if let Some(flags) = &config.flags {
+ if let Some(network_use_binary_prefix) = flags.network_use_binary_prefix {
+ return network_use_binary_prefix;
+ }
+ }
+ false
+}