Signed-off-by: Igor Raits <ignatenkobrain@fedoraproject.org>epel9
parent
6e0167d1a9
commit
7d9f0af0f4
@ -0,0 +1,78 @@
|
||||
From 911f839151801be3301ffe92ea15ccb9b1f94736 Mon Sep 17 00:00:00 2001
|
||||
From: Joseph Price <pricejosephd@gmail.com>
|
||||
Date: Sat, 11 Jan 2020 12:10:57 -0500
|
||||
Subject: [PATCH 4/6] allow controlling sparkline direction
|
||||
|
||||
---
|
||||
src/widgets/mod.rs | 2 +-
|
||||
src/widgets/sparkline.rs | 20 +++++++++++++++++++-
|
||||
2 files changed, 20 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs
|
||||
index 8a89c42..b94e2d0 100644
|
||||
--- a/src/widgets/mod.rs
|
||||
+++ b/src/widgets/mod.rs
|
||||
@@ -19,7 +19,7 @@ pub use self::chart::{Axis, Chart, Dataset, GraphType, Marker};
|
||||
pub use self::gauge::Gauge;
|
||||
pub use self::list::{List, SelectableList};
|
||||
pub use self::paragraph::Paragraph;
|
||||
-pub use self::sparkline::Sparkline;
|
||||
+pub use self::sparkline::{Sparkline, RenderDirection};
|
||||
pub use self::table::{Row, Table};
|
||||
pub use self::tabs::Tabs;
|
||||
|
||||
diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs
|
||||
index 46a5146..8a1b70a 100644
|
||||
--- a/src/widgets/sparkline.rs
|
||||
+++ b/src/widgets/sparkline.rs
|
||||
@@ -31,6 +31,13 @@ pub struct Sparkline<'a> {
|
||||
/// The maximum value to take to compute the maximum bar height (if nothing is specified, the
|
||||
/// widget uses the max of the dataset)
|
||||
max: Option<u64>,
|
||||
+ // The direction to render the sparkine, either from left to right, or from right to left
|
||||
+ direction: RenderDirection,
|
||||
+}
|
||||
+
|
||||
+pub enum RenderDirection {
|
||||
+ LTR,
|
||||
+ RTL
|
||||
}
|
||||
|
||||
impl<'a> Default for Sparkline<'a> {
|
||||
@@ -40,6 +47,7 @@ impl<'a> Default for Sparkline<'a> {
|
||||
style: Default::default(),
|
||||
data: &[],
|
||||
max: None,
|
||||
+ direction: RenderDirection::LTR,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,6 +72,12 @@ impl<'a> Sparkline<'a> {
|
||||
self.max = Some(max);
|
||||
self
|
||||
}
|
||||
+
|
||||
+ pub fn direction(mut self, direction: RenderDirection) -> Sparkline<'a> {
|
||||
+ self.direction = direction;
|
||||
+ self
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
impl<'a> Widget for Sparkline<'a> {
|
||||
@@ -110,7 +124,11 @@ impl<'a> Widget for Sparkline<'a> {
|
||||
7 => bar::SEVEN_EIGHTHS,
|
||||
_ => bar::FULL,
|
||||
};
|
||||
- buf.get_mut(spark_area.left() + i as u16, spark_area.top() + j)
|
||||
+ let x = match self.direction {
|
||||
+ RenderDirection::LTR => spark_area.left() + i as u16,
|
||||
+ RenderDirection::RTL => spark_area.right() - i as u16 - 1
|
||||
+ };
|
||||
+ buf.get_mut(x, spark_area.top() + j)
|
||||
.set_symbol(symbol)
|
||||
.set_fg(self.style.fg)
|
||||
.set_bg(self.style.bg);
|
||||
--
|
||||
2.25.1
|
||||
|
@ -0,0 +1,56 @@
|
||||
From cde0592ddcf5748b228f8aaa26ef36da2cc13093 Mon Sep 17 00:00:00 2001
|
||||
From: Joseph Price <pricejosephd@gmail.com>
|
||||
Date: Sat, 11 Jan 2020 12:29:56 -0500
|
||||
Subject: [PATCH 5/6] fix format
|
||||
|
||||
---
|
||||
src/widgets/mod.rs | 2 +-
|
||||
src/widgets/sparkline.rs | 5 ++---
|
||||
2 files changed, 3 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs
|
||||
index b94e2d0..5d0da6d 100644
|
||||
--- a/src/widgets/mod.rs
|
||||
+++ b/src/widgets/mod.rs
|
||||
@@ -19,7 +19,7 @@ pub use self::chart::{Axis, Chart, Dataset, GraphType, Marker};
|
||||
pub use self::gauge::Gauge;
|
||||
pub use self::list::{List, SelectableList};
|
||||
pub use self::paragraph::Paragraph;
|
||||
-pub use self::sparkline::{Sparkline, RenderDirection};
|
||||
+pub use self::sparkline::{RenderDirection, Sparkline};
|
||||
pub use self::table::{Row, Table};
|
||||
pub use self::tabs::Tabs;
|
||||
|
||||
diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs
|
||||
index 8a1b70a..33af6cb 100644
|
||||
--- a/src/widgets/sparkline.rs
|
||||
+++ b/src/widgets/sparkline.rs
|
||||
@@ -37,7 +37,7 @@ pub struct Sparkline<'a> {
|
||||
|
||||
pub enum RenderDirection {
|
||||
LTR,
|
||||
- RTL
|
||||
+ RTL,
|
||||
}
|
||||
|
||||
impl<'a> Default for Sparkline<'a> {
|
||||
@@ -77,7 +77,6 @@ impl<'a> Sparkline<'a> {
|
||||
self.direction = direction;
|
||||
self
|
||||
}
|
||||
-
|
||||
}
|
||||
|
||||
impl<'a> Widget for Sparkline<'a> {
|
||||
@@ -126,7 +125,7 @@ impl<'a> Widget for Sparkline<'a> {
|
||||
};
|
||||
let x = match self.direction {
|
||||
RenderDirection::LTR => spark_area.left() + i as u16,
|
||||
- RenderDirection::RTL => spark_area.right() - i as u16 - 1
|
||||
+ RenderDirection::RTL => spark_area.right() - i as u16 - 1,
|
||||
};
|
||||
buf.get_mut(x, spark_area.top() + j)
|
||||
.set_symbol(symbol)
|
||||
--
|
||||
2.25.1
|
||||
|
@ -0,0 +1,75 @@
|
||||
From 3b0f769584cce48c398ead3a1698f7655c32de2b Mon Sep 17 00:00:00 2001
|
||||
From: Caleb Bassi <calebjbassi@gmail.com>
|
||||
Date: Tue, 14 Jan 2020 08:18:18 -0800
|
||||
Subject: [PATCH 6/6] Add show_baseline field to sparkline
|
||||
|
||||
---
|
||||
src/widgets/sparkline.rs | 24 +++++++++++++++++++++++-
|
||||
1 file changed, 23 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs
|
||||
index 33af6cb..0ae28c9 100644
|
||||
--- a/src/widgets/sparkline.rs
|
||||
+++ b/src/widgets/sparkline.rs
|
||||
@@ -33,6 +33,8 @@ pub struct Sparkline<'a> {
|
||||
max: Option<u64>,
|
||||
// The direction to render the sparkine, either from left to right, or from right to left
|
||||
direction: RenderDirection,
|
||||
+ /// If true, draws a baseline of `bar::ONE_EIGHTH` spanning the bottom of the sparkline graph
|
||||
+ show_baseline: bool,
|
||||
}
|
||||
|
||||
pub enum RenderDirection {
|
||||
@@ -48,6 +50,7 @@ impl<'a> Default for Sparkline<'a> {
|
||||
data: &[],
|
||||
max: None,
|
||||
direction: RenderDirection::LTR,
|
||||
+ show_baseline: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,6 +80,10 @@ impl<'a> Sparkline<'a> {
|
||||
self.direction = direction;
|
||||
self
|
||||
}
|
||||
+ pub fn show_baseline(mut self, show_baseline: bool) -> Sparkline<'a> {
|
||||
+ self.show_baseline = show_baseline;
|
||||
+ self
|
||||
+ }
|
||||
}
|
||||
|
||||
impl<'a> Widget for Sparkline<'a> {
|
||||
@@ -93,6 +100,15 @@ impl<'a> Widget for Sparkline<'a> {
|
||||
return;
|
||||
}
|
||||
|
||||
+ if self.show_baseline {
|
||||
+ for i in spark_area.left()..spark_area.right() {
|
||||
+ buf.get_mut(i, spark_area.bottom() - 1)
|
||||
+ .set_symbol(bar::ONE_EIGHTH)
|
||||
+ .set_fg(self.style.fg)
|
||||
+ .set_bg(self.style.bg);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
let max = match self.max {
|
||||
Some(v) => v,
|
||||
None => *self.data.iter().max().unwrap_or(&1u64),
|
||||
@@ -113,7 +129,13 @@ impl<'a> Widget for Sparkline<'a> {
|
||||
for j in (0..spark_area.height).rev() {
|
||||
for (i, d) in data.iter_mut().enumerate() {
|
||||
let symbol = match *d {
|
||||
- 0 => " ",
|
||||
+ 0 => {
|
||||
+ if self.show_baseline && j == spark_area.height - 1 {
|
||||
+ bar::ONE_EIGHTH
|
||||
+ } else {
|
||||
+ " "
|
||||
+ }
|
||||
+ }
|
||||
1 => bar::ONE_EIGHTH,
|
||||
2 => bar::ONE_QUARTER,
|
||||
3 => bar::THREE_EIGHTHS,
|
||||
--
|
||||
2.25.1
|
||||
|
Loading…
Reference in new issue