From 60cc15bbb064faa704f78ca51ae60584b5f7ca31 Mon Sep 17 00:00:00 2001 From: FujiApple Date: Sun, 20 Oct 2024 10:49:05 +0800 Subject: [PATCH] feat!: add support for empty bar style to `Sparkline` (#1326) - distingiush between empty bars and bars with a value of 0 - provide custom styling for empty bars - provide custom styling for individual bars - inverts the rendering algorithm to be item first Closes: #1325 BREAKING CHANGE: `Sparkline::data` takes `IntoIterator` instead of `&[u64]` and is no longer const Co-authored-by: Josh McKinney --- BREAKING-CHANGES.md | 30 ++ examples/demo2/tabs/traceroute.rs | 2 +- src/symbols.rs | 8 + src/widgets.rs | 2 +- src/widgets/sparkline.rs | 475 ++++++++++++++++++++++++++---- 5 files changed, 465 insertions(+), 52 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index ed9b2940..bd2c07a7 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -11,6 +11,7 @@ GitHub with a [breaking change] label. This is a quick summary of the sections below: - [v0.29.0](#unreleased) + - `Sparkline::data` takes `IntoIterator` instead of `&[u64]` and is no longer const - Removed public fields from `Rect` iterators - `Line` now implements `From` - `Table::highlight_style` is now `Table::row_highlight_style` @@ -73,6 +74,35 @@ This is a quick summary of the sections below: ## Unreleased +### `Sparkline::data` takes `IntoIterator` instead of `&[u64]` and is no longer const ([#1326]) + +[#1326]: https://github.com/ratatui/ratatui/pull/1326 + +The `Sparkline::data` method has been modified to accept `IntoIterator` +instead of `&[u64]`. + +`SparklineBar` is a struct that contains an `Option` value, which represents an possible +_absent_ value, as distinct from a `0` value. This change allows the `Sparkline` to style +data points differently, depending on whether they are present or absent. + +`SparklineBar` also contains an `Option