Expand description
§tui-piechart
A customizable pie chart widget for Ratatui TUI applications.
§Features
- 🥧 Simple pie chart with customizable slices
- 🎨 Customizable colors for each slice
- 🔤 Labels and percentages
- 📊 Legend support
- 📦 Optional block wrapper
- ✨ Custom symbols for pie chart and legend
- ⚡ Zero-cost abstractions
§Examples
Basic usage:
use ratatui::style::Color;
use tui_piechart::{PieChart, PieSlice};
let slices = vec![
PieSlice::new("Rust", 45.0, Color::Red),
PieSlice::new("Go", 30.0, Color::Blue),
PieSlice::new("Python", 25.0, Color::Green),
];
let piechart = PieChart::new(slices);With custom styling:
use ratatui::style::{Color, Style};
use tui_piechart::{PieChart, PieSlice};
let slices = vec![
PieSlice::new("Rust", 45.0, Color::Red),
PieSlice::new("Go", 30.0, Color::Blue),
];
let piechart = PieChart::new(slices)
.style(Style::default())
.show_legend(true)
.show_percentages(true);With custom symbols:
use ratatui::style::Color;
use tui_piechart::{PieChart, PieSlice, symbols};
let slices = vec![
PieSlice::new("Rust", 45.0, Color::Red),
PieSlice::new("Go", 30.0, Color::Blue),
];
// Use predefined symbols
let piechart = PieChart::new(slices.clone())
.pie_char(symbols::PIE_CHAR_BLOCK)
.legend_marker(symbols::LEGEND_MARKER_CIRCLE);
// Or use any custom characters
let piechart = PieChart::new(slices)
.pie_char('█')
.legend_marker("→");With custom border styles:
use ratatui::style::Color;
use tui_piechart::{PieChart, PieSlice, border_style::BorderStyle};
// Or use backwards-compatible path: use tui_piechart::symbols::BorderStyle;
let slices = vec![
PieSlice::new("Rust", 45.0, Color::Red),
PieSlice::new("Go", 30.0, Color::Blue),
];
// Use predefined border styles
let piechart = PieChart::new(slices)
.block(BorderStyle::Rounded.block().title("My Chart"));Re-exports§
pub use legend::LegendAlignment;pub use legend::LegendLayout;pub use legend::LegendPosition;pub use title::BlockExt;pub use title::TitleAlignment;pub use title::TitlePosition;pub use title::TitleStyle;
Modules§
- border_
style - Border styles for pie chart block wrappers.
- legend
- Legend positioning and layout configuration for pie charts.
- macros
- Macro utilities for reducing boilerplate code.
- symbols
- Symbols for pie chart widget and legends
- title
- Title positioning, alignment, and styling configuration for block wrappers.
Macros§
- assert_
eq_ test - Generate an equality assertion test.
- assert_
test - Generate a simple assertion test.
- conversion_
test - Test that a conversion (From/Into) works correctly.
- debug_
format_ tests - Generate debug format tests for multiple enum variants.
- enum_
tests - Generate standard enum tests (default, clone, debug).
- instantiate_
variants_ test - Test that multiple enum variants can be instantiated.
- multi_
render_ test - Test rendering with multiple widget configurations.
- no_
panic_ test - Test that a method doesn’t panic with a given input.
- render_
empty_ test - Test that rendering to an empty area doesn’t panic.
- render_
test - Test that rendering to a buffer doesn’t panic.
- render_
with_ size_ test - Test that rendering with specific dimensions doesn’t panic.
- string_
transform_ test - Test that a string transformation preserves certain properties.
Structs§
- PieChart
- A widget that displays a pie chart.
- PieSlice
- A slice of the pie chart representing a portion of data.
Enums§
- Resolution
- Rendering resolution mode for pie charts.