From c55c2a8fac7263d12ad447a5bf429bf48f12753f Mon Sep 17 00:00:00 2001 From: Lovecraftian Horror Date: Mon, 29 Jun 2020 07:03:31 -0400 Subject: [PATCH] Previously the scaling would be based on all entries recorded instead of just the entries displayed. This meant that high transmission or reception rates would cause the scaling to drown out any small entries even if the high rates were not being displayed. This change passes in just the amount of samples needed to fill the block instead. --- src/sparkline.rs | 1 + src/widgets/net.rs | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/sparkline.rs b/src/sparkline.rs index 7a769db..5bfec00 100644 --- a/src/sparkline.rs +++ b/src/sparkline.rs @@ -64,6 +64,7 @@ impl<'a> Sparkline<'a> { self } + #[allow(dead_code)] pub fn max(mut self, max: u64) -> Sparkline<'a> { self.max = Some(max); self diff --git a/src/widgets/net.rs b/src/widgets/net.rs index d523a4a..4771c99 100644 --- a/src/widgets/net.rs +++ b/src/widgets/net.rs @@ -155,12 +155,11 @@ impl Widget for &NetWidget<'_, '_> { .iter() .cloned() .rev() - .collect::>() - .as_slice(), + .take(top_sparkline.width as usize) + .collect::>(), ) .direction(RenderDirection::RTL) .show_baseline(true) - .max(*self.bytes_recv.iter().max().unwrap()) .style(self.colorscheme.net_bars) .render(top_sparkline, buf); @@ -192,12 +191,11 @@ impl Widget for &NetWidget<'_, '_> { .iter() .cloned() .rev() - .collect::>() - .as_slice(), + .take(bottom_sparkline.width as usize) + .collect::>(), ) .direction(RenderDirection::RTL) .show_baseline(true) - .max(*self.bytes_sent.iter().max().unwrap()) .style(self.colorscheme.net_bars) .render(bottom_sparkline, buf); }