From 4792a975ee15869116cb15b8ebc4cfa0350dfa12 Mon Sep 17 00:00:00 2001 From: Igor Raits Date: Wed, 18 Mar 2020 19:16:34 +0100 Subject: [PATCH] Backport features needed for ytop Signed-off-by: Igor Raits --- 0001-Add-header_gap-field-to-Table.patch | 63 ++++++++ 0002-Add-linechart-support.patch | 141 ++++++++++++++++++ ...ge-linechart-to-draw-the-points-also.patch | 38 +++++ rust-tui.spec | 11 +- 4 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 0001-Add-header_gap-field-to-Table.patch create mode 100644 0002-Add-linechart-support.patch create mode 100644 0003-Change-linechart-to-draw-the-points-also.patch diff --git a/0001-Add-header_gap-field-to-Table.patch b/0001-Add-header_gap-field-to-Table.patch new file mode 100644 index 0000000..6b327af --- /dev/null +++ b/0001-Add-header_gap-field-to-Table.patch @@ -0,0 +1,63 @@ +From 4493e4035354ad221d35c99829b7b7678312dbb7 Mon Sep 17 00:00:00 2001 +From: Caleb Bassi +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 + diff --git a/0002-Add-linechart-support.patch b/0002-Add-linechart-support.patch new file mode 100644 index 0000000..f58d7e9 --- /dev/null +++ b/0002-Add-linechart-support.patch @@ -0,0 +1,141 @@ +From 915aeba393c139dade33b215a3fc975901d5aa7e Mon Sep 17 00:00:00 2001 +From: Caleb Bassi +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 + diff --git a/0003-Change-linechart-to-draw-the-points-also.patch b/0003-Change-linechart-to-draw-the-points-also.patch new file mode 100644 index 0000000..32055f3 --- /dev/null +++ b/0003-Change-linechart-to-draw-the-points-also.patch @@ -0,0 +1,38 @@ +From 3dff2a48a7e253216d72f412019d84733a60f96a Mon Sep 17 00:00:00 2001 +From: Caleb Bassi +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 + diff --git a/rust-tui.spec b/rust-tui.spec index fc2df13..b5c6dcb 100644 --- a/rust-tui.spec +++ b/rust-tui.spec @@ -7,13 +7,19 @@ Name: rust-%{crate} Version: 0.8.0 -Release: 2%{?dist} +Release: 3%{?dist} Summary: Library to build rich terminal user interfaces or dashboards # Upstream license specification: MIT License: MIT URL: https://crates.io/crates/tui Source: %{crates_source} +# https://github.com/fdehau/tui-rs/commit/7aae9b380eef239f5eec227868ca42438aa7f12f +Patch0001: 0001-Add-header_gap-field-to-Table.patch +# https://github.com/fdehau/tui-rs/commit/262bf441ceedbe51acafbeffc78c6bc3370514b4 +Patch0002: 0002-Add-linechart-support.patch +# https://github.com/fdehau/tui-rs/commit/829b7b6b70274053442bd4910ac4fac1d30de2a8 +Patch0003: 0003-Change-linechart-to-draw-the-points-also.patch ExclusiveArch: %{rust_arches} %if %{__cargo_skip_build} @@ -144,6 +150,9 @@ which use "termion" feature of "%{crate}" crate. %endif %changelog +* Wed Mar 18 2020 Igor Raits - 0.8.0-3 +- Backport features needed for ytop + * Thu Jan 30 2020 Fedora Release Engineering - 0.8.0-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild