Signed-off-by: Igor Raits <ignatenkobrain@fedoraproject.org>epel9
parent
7e74ab8f1f
commit
4792a975ee
@ -0,0 +1,63 @@
|
||||
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/3] 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
|
||||
|
@ -0,0 +1,141 @@
|
||||
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/3] 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
|
||||
|
@ -0,0 +1,38 @@
|
||||
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/3] 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
|
||||
|
Loading…
Reference in new issue