Skip to content

Commit

Permalink
feat(showcase): showcase sparkline widget (#471)
Browse files Browse the repository at this point in the history
Relates to #249.
  • Loading branch information
mccartney authored Feb 25, 2024
1 parent 4e57f06 commit 2a2ec90
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 1 deletion.
9 changes: 9 additions & 0 deletions code/widget-showcase/sparkline.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# A VHS tape. See https://github.com/charmbracelet/vhs
Output "../../src/content/docs/showcase/widgets/sparkline.gif"
Set Theme "Aardvark Blue"
Set Width 800
Set Height 300
Type "cargo run -- -w sparkline" Enter
Sleep 2s
Screenshot "../../src/content/docs/showcase/widgets/sparkline.png"
Sleep 1s
1 change: 1 addition & 0 deletions code/widget-showcase/src/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub mod gauge;
pub mod line_gauge;
pub mod list;
pub mod paragraph;
pub mod sparkline;
pub mod table;
17 changes: 17 additions & 0 deletions code/widget-showcase/src/examples/sparkline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use ratatui::{prelude::*, widgets::*};

pub fn render(frame: &mut Frame) {
let sparkline = Sparkline::default()
.block(Block::default().title("Sparkline").borders(Borders::ALL))
.data(&[
35, 40, 44, 49, 52, 55, 58, 59, 60, 60, 59, 57, 55, 52, 48, 44, 39,
34, 29, 24, 19, 15, 11, 7, 4, 2, 1, 0, 0, 1, 3, 6, 9, 13, 17, 22,
27, 32, 36, 41, 46, 50, 53, 56, 58, 59, 60, 60, 59, 57, 54, 51, 47,
42, 38, 33, 28, 23, 18,
])
.max(62)
.direction(RenderDirection::LeftToRight)
.style(Style::default().yellow());

frame.render_widget(sparkline, frame.size());
}
2 changes: 2 additions & 0 deletions code/widget-showcase/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum Widget {
LineGauge,
List,
Paragraph,
Sparkline,
Table,
}

Expand Down Expand Up @@ -106,6 +107,7 @@ impl App {
Widget::LineGauge => line_gauge::render(frame),
Widget::List => list::render(frame),
Widget::Paragraph => paragraph::render(frame),
Widget::Sparkline => sparkline::render(frame),
Widget::Table => table::render(frame),
}
Ok(())
Expand Down
4 changes: 3 additions & 1 deletion src/content/docs/showcase/widgets/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ https://github.com/ratatui-org/website/issues/249 for information about how to c

## Scrollbar <LinkBadge href="https://docs.rs/ratatui/latest/ratatui/widgets/struct.Scrollbar.html" text="Docs" /> <LinkBadge text="Help Wanted" href="https://github.com/ratatui-org/website/issues/249" variant="caution" />

## Sparkline <LinkBadge href="https://docs.rs/ratatui/latest/ratatui/widgets/struct.Sparkline.html" text="Docs" /> <LinkBadge text="Help Wanted" href="https://github.com/ratatui-org/website/issues/249" variant="caution" />
## Sparkline <LinkBadge href="https://docs.rs/ratatui/latest/ratatui/widgets/struct.Sparkline.html" text="Docs" />

![Sparkline](./sparkline.png)

## Table <LinkBadge href="https://docs.rs/ratatui/latest/ratatui/widgets/struct.Table.html" text="Docs" />

Expand Down
3 changes: 3 additions & 0 deletions src/content/docs/showcase/widgets/sparkline.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/content/docs/showcase/widgets/sparkline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2a2ec90

Please sign in to comment.