parent
7d9f0af0f4
commit
9d06231537
@ -1,2 +1,3 @@
|
||||
/tui-0.7.0.crate
|
||||
/tui-0.8.0.crate
|
||||
/tui-0.9.1.crate
|
||||
|
@ -1,63 +0,0 @@
|
||||
From 4493e4035354ad221d35c99829b7b7678312dbb7 Mon Sep 17 00:00:00 2001
|
||||
From: Caleb Bassi <calebjbassi@gmail.com>
|
||||
Date: Sun, 12 Jan 2020 14:13:28 -0800
|
||||
Subject: [PATCH 1/6] Add header_gap field to Table
|
||||
|
||||
(cherry picked from commit 7aae9b380eef239f5eec227868ca42438aa7f12f)
|
||||
---
|
||||
src/widgets/table.rs | 11 ++++++++++-
|
||||
1 file changed, 10 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/widgets/table.rs b/src/widgets/table.rs
|
||||
index 6399cac..105923c 100644
|
||||
--- a/src/widgets/table.rs
|
||||
+++ b/src/widgets/table.rs
|
||||
@@ -67,6 +67,8 @@ where
|
||||
widths: &'a [Constraint],
|
||||
/// Space between each column
|
||||
column_spacing: u16,
|
||||
+ /// Space between the header and the rows
|
||||
+ header_gap: u16,
|
||||
/// Data to display in each row
|
||||
rows: R,
|
||||
}
|
||||
@@ -88,6 +90,7 @@ where
|
||||
widths: &[],
|
||||
rows: R::default(),
|
||||
column_spacing: 1,
|
||||
+ header_gap: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,6 +112,7 @@ where
|
||||
widths: &[],
|
||||
rows,
|
||||
column_spacing: 1,
|
||||
+ header_gap: 1,
|
||||
}
|
||||
}
|
||||
pub fn block(mut self, block: Block<'a>) -> Table<'a, T, H, I, D, R> {
|
||||
@@ -159,6 +163,11 @@ where
|
||||
self.column_spacing = spacing;
|
||||
self
|
||||
}
|
||||
+
|
||||
+ pub fn header_gap(mut self, gap: u16) -> Table<'a, T, H, I, D, R> {
|
||||
+ self.header_gap = gap;
|
||||
+ self
|
||||
+ }
|
||||
}
|
||||
|
||||
impl<'a, T, H, I, D, R> Widget for Table<'a, T, H, I, D, R>
|
||||
@@ -238,7 +247,7 @@ where
|
||||
x += *w + self.column_spacing;
|
||||
}
|
||||
}
|
||||
- y += 2;
|
||||
+ y += 1 + self.header_gap;
|
||||
|
||||
// Draw rows
|
||||
let default_style = Style::default();
|
||||
--
|
||||
2.25.1
|
||||
|
@ -1,141 +0,0 @@
|
||||
From 915aeba393c139dade33b215a3fc975901d5aa7e Mon Sep 17 00:00:00 2001
|
||||
From: Caleb Bassi <calebjbassi@gmail.com>
|
||||
Date: Fri, 10 Jan 2020 15:58:44 -0800
|
||||
Subject: [PATCH 2/6] Add linechart support
|
||||
|
||||
Closes #73
|
||||
|
||||
This commit only adds support for linecharts for the braille marker.
|
||||
|
||||
(cherry picked from commit 262bf441ceedbe51acafbeffc78c6bc3370514b4)
|
||||
---
|
||||
src/widgets/chart.rs | 45 +++++++++++++++++++++++++++++++++++++-------
|
||||
src/widgets/mod.rs | 2 +-
|
||||
2 files changed, 39 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/src/widgets/chart.rs b/src/widgets/chart.rs
|
||||
index c1df662..78593ea 100644
|
||||
--- a/src/widgets/chart.rs
|
||||
+++ b/src/widgets/chart.rs
|
||||
@@ -6,7 +6,7 @@ use crate::buffer::Buffer;
|
||||
use crate::layout::Rect;
|
||||
use crate::style::Style;
|
||||
use crate::symbols;
|
||||
-use crate::widgets::canvas::{Canvas, Points};
|
||||
+use crate::widgets::canvas::{Canvas, Line, Points};
|
||||
use crate::widgets::{Block, Borders, Widget};
|
||||
|
||||
/// An X or Y axis for the chart widget
|
||||
@@ -87,6 +87,14 @@ pub enum Marker {
|
||||
Braille,
|
||||
}
|
||||
|
||||
+/// Used to determine which style of graphing to use
|
||||
+pub enum GraphType {
|
||||
+ /// Draw each point
|
||||
+ Scatter,
|
||||
+ /// Draw each point and lines between each point using the same marker
|
||||
+ Line,
|
||||
+}
|
||||
+
|
||||
/// A group of data points
|
||||
pub struct Dataset<'a> {
|
||||
/// Name of the dataset (used in the legend if shown)
|
||||
@@ -95,6 +103,8 @@ pub struct Dataset<'a> {
|
||||
data: &'a [(f64, f64)],
|
||||
/// Symbol used for each points of this dataset
|
||||
marker: Marker,
|
||||
+ /// Determines graph type used for drawing points
|
||||
+ graph_type: GraphType,
|
||||
/// Style used to plot this dataset
|
||||
style: Style,
|
||||
}
|
||||
@@ -105,6 +115,7 @@ impl<'a> Default for Dataset<'a> {
|
||||
name: "",
|
||||
data: &[],
|
||||
marker: Marker::Dot,
|
||||
+ graph_type: GraphType::Scatter,
|
||||
style: Style::default(),
|
||||
}
|
||||
}
|
||||
@@ -126,6 +137,11 @@ impl<'a> Dataset<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
+ pub fn graph_type(mut self, graph_type: GraphType) -> Dataset<'a> {
|
||||
+ self.graph_type = graph_type;
|
||||
+ self
|
||||
+ }
|
||||
+
|
||||
pub fn style(mut self, style: Style) -> Dataset<'a> {
|
||||
self.style = style;
|
||||
self
|
||||
@@ -166,7 +182,7 @@ impl Default for ChartLayout {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
-/// # use tui::widgets::{Block, Borders, Chart, Axis, Dataset, Marker};
|
||||
+/// # use tui::widgets::{Block, Borders, Chart, Axis, Dataset, Marker, GraphType};
|
||||
/// # use tui::style::{Style, Color};
|
||||
/// # fn main() {
|
||||
/// Chart::default()
|
||||
@@ -186,11 +202,13 @@ impl Default for ChartLayout {
|
||||
/// .datasets(&[Dataset::default()
|
||||
/// .name("data1")
|
||||
/// .marker(Marker::Dot)
|
||||
+/// .graph_type(GraphType::Scatter)
|
||||
/// .style(Style::default().fg(Color::Cyan))
|
||||
/// .data(&[(0.0, 5.0), (1.0, 6.0), (1.5, 6.434)]),
|
||||
/// Dataset::default()
|
||||
/// .name("data2")
|
||||
/// .marker(Marker::Braille)
|
||||
+/// .graph_type(GraphType::Line)
|
||||
/// .style(Style::default().fg(Color::Magenta))
|
||||
/// .data(&[(4.0, 5.0), (5.0, 8.0), (7.66, 13.5)])]);
|
||||
/// # }
|
||||
@@ -452,11 +470,24 @@ where
|
||||
.background_color(self.style.bg)
|
||||
.x_bounds(self.x_axis.bounds)
|
||||
.y_bounds(self.y_axis.bounds)
|
||||
- .paint(|ctx| {
|
||||
- ctx.draw(&Points {
|
||||
- coords: dataset.data,
|
||||
- color: dataset.style.fg,
|
||||
- });
|
||||
+ .paint(|ctx| match dataset.graph_type {
|
||||
+ GraphType::Scatter => {
|
||||
+ ctx.draw(&Points {
|
||||
+ coords: dataset.data,
|
||||
+ color: dataset.style.fg,
|
||||
+ });
|
||||
+ }
|
||||
+ GraphType::Line => {
|
||||
+ for i in 0..dataset.data.len() - 1 {
|
||||
+ ctx.draw(&Line {
|
||||
+ x1: dataset.data[i].0,
|
||||
+ y1: dataset.data[i].1,
|
||||
+ x2: dataset.data[i + 1].0,
|
||||
+ y2: dataset.data[i + 1].1,
|
||||
+ color: dataset.style.fg,
|
||||
+ })
|
||||
+ }
|
||||
+ }
|
||||
})
|
||||
.draw(graph_area, buf);
|
||||
}
|
||||
diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs
|
||||
index 8752691..8a89c42 100644
|
||||
--- a/src/widgets/mod.rs
|
||||
+++ b/src/widgets/mod.rs
|
||||
@@ -15,7 +15,7 @@ mod tabs;
|
||||
|
||||
pub use self::barchart::BarChart;
|
||||
pub use self::block::Block;
|
||||
-pub use self::chart::{Axis, Chart, Dataset, Marker};
|
||||
+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;
|
||||
--
|
||||
2.25.1
|
||||
|
@ -1,38 +0,0 @@
|
||||
From 3dff2a48a7e253216d72f412019d84733a60f96a Mon Sep 17 00:00:00 2001
|
||||
From: Caleb Bassi <calebjbassi@gmail.com>
|
||||
Date: Tue, 14 Jan 2020 09:47:07 -0800
|
||||
Subject: [PATCH 3/6] Change linechart to draw the points also
|
||||
|
||||
(cherry picked from commit 829b7b6b70274053442bd4910ac4fac1d30de2a8)
|
||||
---
|
||||
src/widgets/chart.rs | 14 ++++++--------
|
||||
1 file changed, 6 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/src/widgets/chart.rs b/src/widgets/chart.rs
|
||||
index 78593ea..2a0bfea 100644
|
||||
--- a/src/widgets/chart.rs
|
||||
+++ b/src/widgets/chart.rs
|
||||
@@ -470,14 +470,12 @@ where
|
||||
.background_color(self.style.bg)
|
||||
.x_bounds(self.x_axis.bounds)
|
||||
.y_bounds(self.y_axis.bounds)
|
||||
- .paint(|ctx| match dataset.graph_type {
|
||||
- GraphType::Scatter => {
|
||||
- ctx.draw(&Points {
|
||||
- coords: dataset.data,
|
||||
- color: dataset.style.fg,
|
||||
- });
|
||||
- }
|
||||
- GraphType::Line => {
|
||||
+ .paint(|ctx| {
|
||||
+ ctx.draw(&Points {
|
||||
+ coords: dataset.data,
|
||||
+ color: dataset.style.fg,
|
||||
+ });
|
||||
+ if let GraphType::Line = dataset.graph_type {
|
||||
for i in 0..dataset.data.len() - 1 {
|
||||
ctx.draw(&Line {
|
||||
x1: dataset.data[i].0,
|
||||
--
|
||||
2.25.1
|
||||
|
@ -1,78 +0,0 @@
|
||||
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
|
||||
|
@ -1,56 +0,0 @@
|
||||
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
|
||||
|
@ -1,75 +0,0 @@
|
||||
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
|
||||
|
@ -1 +1 @@
|
||||
SHA512 (tui-0.8.0.crate) = 20b97cbc4f1c5f2d79361d401c43f1eafcbb203994a6fbbf9651b7d1fc083c97c4678a7c76b449ee6c81f016febdc510ee39edcbddefa572b9d99f1f86483b58
|
||||
SHA512 (tui-0.9.1.crate) = 02ab1a25eca3febc4fdc9343e4fa948051b3ee654546a584e72d846bd0f8983bf50e55761c5e6856719e4ee57c402c3b1fdc33d03350aca21a270bef0964b0ea
|
||||
|
@ -1,11 +0,0 @@
|
||||
--- tui-0.8.0/Cargo.toml 1970-01-01T00:00:00+00:00
|
||||
+++ tui-0.8.0/Cargo.toml 2020-03-19T00:25:28.244864+00:00
|
||||
@@ -113,7 +113,7 @@
|
||||
version = "0.3"
|
||||
|
||||
[dependencies.crossterm]
|
||||
-version = "0.14"
|
||||
+version = "0.16"
|
||||
optional = true
|
||||
|
||||
[dependencies.easycurses]
|
Loading…
Reference in new issue