| Crates.io | tui-piechart |
| lib.rs | tui-piechart |
| version | 0.2.8 |
| created_at | 2025-11-08 02:41:01.641655+00 |
| updated_at | 2025-12-06 18:02:01.997179+00 |
| description | A customizable pie chart widget for Ratatui TUI applications |
| homepage | https://github.com/sorinirimies/tui-piechart |
| repository | https://github.com/sorinirimies/tui-piechart |
| max_upload_size | |
| id | 1922433 |
| size | 403,327 |
A customizable pie chart widget for Ratatui TUI applications.

Add this to your Cargo.toml:
[dependencies]
tui-piechart = "0.1.0"
ratatui = "0.29"
Or install with cargo:
cargo add tui-piechart
use ratatui::style::Color;
use tui_piechart::{PieChart, PieSlice};
// Create slices
let slices = vec![
PieSlice::new("Rust", 45.0, Color::Red),
PieSlice::new("Go", 30.0, Color::Blue),
PieSlice::new("Python", 25.0, Color::Green),
];
// Create pie chart
let piechart = PieChart::new(slices);
// With customization
let piechart = PieChart::new(slices)
.show_legend(true)
.show_percentages(true)
.pie_char('β');
// With a block
use ratatui::widgets::Block;
let piechart = PieChart::new(slices)
.block(Block::bordered().title("Statistics"));
// With high resolution mode (braille patterns for 8x resolution)
let piechart = PieChart::new(slices)
.high_resolution(true);
// Or use the Resolution enum
use tui_piechart::Resolution;
let standard = PieChart::new(slices).resolution(Resolution::Standard);
let braille = PieChart::new(slices).resolution(Resolution::Braille);
The library provides comprehensive legend control with three key aspects:
Control where the legend appears relative to the pie chart:
use tui_piechart::{PieChart, LegendPosition};
let chart = PieChart::new(slices)
.legend_position(LegendPosition::Right) // Default
.legend_position(LegendPosition::Left)
.legend_position(LegendPosition::Top)
.legend_position(LegendPosition::Bottom);
Choose between vertical (stacked) or horizontal (single row) arrangement:
use tui_piechart::{PieChart, LegendLayout};
let chart = PieChart::new(slices)
.legend_layout(LegendLayout::Vertical) // Default - items stacked
.legend_layout(LegendLayout::Horizontal); // Items in a row
Align legend items within their allocated space (particularly useful for grid layouts):
use tui_piechart::{PieChart, LegendAlignment};
let chart = PieChart::new(slices)
.legend_alignment(LegendAlignment::Left) // Default
.legend_alignment(LegendAlignment::Center) // Centered - great for grids
.legend_alignment(LegendAlignment::Right); // Right-aligned
let chart = PieChart::new(slices)
.legend_position(LegendPosition::Bottom)
.legend_layout(LegendLayout::Horizontal)
.legend_alignment(LegendAlignment::Center);
This gives you 24 possible combinations (4 positions Γ 2 layouts Γ 3 alignments) to perfectly match your UI design!
The library is organized into focused modules:
legend - Legend positioning, layout, and alignment configuration
LegendPosition - Position legend on any side (Right, Left, Top, Bottom)LegendLayout - Vertical or Horizontal layout modesLegendAlignment - Align items Left, Center, or Right within their areatitle - Title positioning, alignment, and font styling for block wrappers
TitleAlignment - Horizontal alignment (Start, Center, End)TitlePosition - Vertical position (Top, Bottom)TitleStyle - Unicode font styles (Bold, Italic, Script, Sans-Serif, Monospace, etc.)BlockExt - Extension trait for ergonomic title customizationborder_style - Predefined border styles for block wrappers
symbols - Predefined Unicode symbols for pie charts and legends
All commonly used types are re-exported from the crate root for convenience:
use tui_piechart::{PieChart, PieSlice, LegendPosition, LegendLayout};
// Or import from specific modules:
use tui_piechart::legend::{LegendPosition, LegendLayout};
use tui_piechart::title::{TitleAlignment, TitlePosition, BlockExt};
use tui_piechart::border_style::BorderStyle;
Run the included examples:
# Main interactive example (4 charts)
cargo run --example piechart
# Predefined symbols examples (4 charts each):
cargo run --example symbols_circles_squares # Default, Block, Circle, Square
cargo run --example symbols_stars_hearts # Diamond, Star, White Star, Heart
cargo run --example symbols_triangles_hexagons # Triangle, Hexagon, Bullseye, Square Box
cargo run --example symbols_shades_bars # Asterism, Horizontal Bar, Shade, Light
# Layout and positioning examples:
cargo run --example legend_positioning # 4 positions Γ 2 layouts
cargo run --example legend_alignment # 3 alignments Γ 4 positions Γ 2 layouts
cargo run --example title_positioning # 2 positions Γ 3 alignments
cargo run --example title_styles_example # 10 Unicode font styles
# Border styles showcase (11 charts in 4-row grid)
cargo run --example border_styles
# Custom (non-predefined) symbols showcase (6 charts)
cargo run --example custom_symbols
# High resolution mode demo (animated, toggle with Space)
cargo run --example high_resolution
# Or use just commands:
just run-legend-positioning
just run-legend-alignment
just run-title-positioning
just run-title-styles-example
just run-border-styles
just run-custom-symbols
just run-high-resolution
For comprehensive documentation of all examples, see EXAMPLES.md.
Run: cargo run --example piechart





Run: cargo run --example legend_positioning

Run: cargo run --example title_positioning

Run: cargo run --example title_styles_example

Run: cargo run --example border_styles

Run: cargo run --example custom_symbols

Run: cargo run --example high_resolution

| Example | Command | Features |
|---|---|---|
| Main Demo | cargo run --example piechart |
4 chart types, interactive |
| Circles & Squares | cargo run --example symbols_circles_squares |
Basic symbols |
| Stars & Hearts | cargo run --example symbols_stars_hearts |
Decorative symbols |
| Triangles & Hexagons | cargo run --example symbols_triangles_hexagons |
Geometric symbols |
| Shades & Bars | cargo run --example symbols_shades_bars |
Pattern symbols |
| Legend Positioning | cargo run --example legend_positioning |
4 positions Γ 2 layouts |
| Legend Alignment | cargo run --example legend_alignment |
3 alignments Γ 4 positions Γ 2 layouts |
| Title Positioning | cargo run --example title_positioning |
2 positions Γ 3 alignments |
| Title Styles | cargo run --example title_styles_example |
10 font styles |
| Border Styles | cargo run --example border_styles |
11 border variants |
| Custom Symbols | cargo run --example custom_symbols |
8 custom symbols |
| High Resolution | cargo run --example high_resolution |
Braille rendering |
For detailed documentation on each example, usage patterns, and more, see EXAMPLES.md.
Navigate through different chart types with your keyboard:
The interactive mode demonstrates:
Press Tab to switch to the API showcase view, which displays:
new(), default(), slices())show_legend(), show_percentages(), pie_char())Each slice can have its own color:
let slices = vec![
PieSlice::new("Category A", 40.0, Color::Red),
PieSlice::new("Category B", 35.0, Color::Blue),
PieSlice::new("Category C", 25.0, Color::Green),
];
Control what information is shown:
let piechart = PieChart::new(slices)
.show_legend(true) // Show/hide legend
.show_percentages(true); // Show/hide percentages in legend
Customize the appearance of the block wrapper using predefined border styles:
use tui_piechart::border_style::BorderStyle;
// Or use backwards-compatible path: use tui_piechart::symbols::BorderStyle;
// Standard single-line borders (default)
let piechart = PieChart::new(slices)
.block(BorderStyle::Standard.block().title("My Chart"));
// Rounded corners
let piechart = PieChart::new(slices)
.block(BorderStyle::Rounded.block().title("My Chart"));
// Dashed borders (dashed lines throughout)
let piechart = PieChart::new(slices)
.block(BorderStyle::Dashed.block().title("My Chart"));
// Corner gaps only (minimalist look)
let piechart = PieChart::new(slices)
.block(BorderStyle::CornerGapped.block().title("My Chart"));
// Thick borders
let piechart = PieChart::new(slices)
.block(BorderStyle::Thick.block().title("My Chart"));
// Double-line borders
let piechart = PieChart::new(slices)
.block(BorderStyle::DoubleLineStandard.block().title("My Chart"));
Available Border Styles (11 total):
Single-line variants:
BorderStyle::Standard - Standard single-line borders (default)BorderStyle::Rounded - Rounded corners with single-line bordersBorderStyle::Dashed - Dashed lines throughout (βββ)BorderStyle::RoundedDashed - Rounded corners with dashed linesBorderStyle::CornerGapped - Continuous lines with gaps only at cornersBorderStyle::RoundedCornerGapped - Rounded with gaps only at cornersDouble-line variants:
BorderStyle::DoubleLineStandard - Double-line borders (βββ)BorderStyle::DoubleLineRounded - Double-line edges with rounded corners (mixed style)*Thick-line variants:
BorderStyle::Thick - Thick/heavy line borders (βββ)BorderStyle::ThickRounded - Thick edges with rounded corners (mixed style)*BorderStyle::ThickDashed - Thick dashed lines (β
β
β
)See the border_styles example for a visual demonstration of all styles.
Note: *DoubleLineRounded and ThickRounded use mixed styles (single-line rounded corners with double/thick-line edges) because Unicode doesn't have true rounded double-line or thick-line box-drawing characters.
Customize the alignment and position of block titles:
use tui_piechart::border_style::{BorderStyle, BlockExt, TitleAlignment, TitlePosition};
// Horizontal alignment
let block = BorderStyle::Rounded.block()
.title("My Chart")
.title_alignment_horizontal(TitleAlignment::Center); // Left, Center, Right
// Vertical position
let block = BorderStyle::Rounded.block()
.title("Top Title")
.title_vertical_position(TitlePosition::Top)
.title_bottom("Bottom Title")
.title_alignment(Alignment::Center);
Available Options:
TitleAlignment::Left, TitleAlignment::Center, TitleAlignment::RightTitlePosition::Top, TitlePosition::BottomControl where the legend appears and how it's laid out:
use tui_piechart::{PieChart, LegendPosition, LegendLayout};
// Position the legend
let chart = PieChart::new(slices)
.legend_position(LegendPosition::Right) // Right, Left, Top, Bottom
.legend_layout(LegendLayout::Vertical); // Vertical or Horizontal
// Example: horizontal legend at the bottom
let chart = PieChart::new(slices)
.legend_position(LegendPosition::Bottom)
.legend_layout(LegendLayout::Horizontal);
Legend Positions:
LegendPosition::Right - Legend on the right side (default)LegendPosition::Left - Legend on the left sideLegendPosition::Top - Legend at the topLegendPosition::Bottom - Legend at the bottomLegend Layouts:
LegendLayout::Vertical - Items stacked vertically (default)LegendLayout::Horizontal - Items in a single rowThe legend automatically calculates the required space based on content to prevent text cutoff.
See the legend_positioning example for an interactive demonstration.
The pie chart widget allows full customization of symbols used for rendering. You can use any Unicode character for the pie chart and any string for legend markers.
use tui_piechart::symbols;
// Using predefined symbols
let piechart = PieChart::new(slices)
.pie_char(symbols::PIE_CHAR_BLOCK) // β
.legend_marker(symbols::LEGEND_MARKER_CIRCLE); // β
// Using custom characters
let piechart = PieChart::new(slices)
.pie_char('β
') // Any Unicode character
.legend_marker("β"); // Any string
The symbols module provides carefully selected characters that work well in most terminals:
Basic Shapes:
symbols::PIE_CHAR - β (default, filled circle)symbols::PIE_CHAR_BLOCK - β (solid block, high density)symbols::PIE_CHAR_CIRCLE - β (circle with center dot)symbols::PIE_CHAR_SQUARE - β (solid square)symbols::PIE_CHAR_DIAMOND - β (solid diamond)symbols::PIE_CHAR_HEXAGON - β¬’ (filled hexagon)symbols::PIE_CHAR_BULLSEYE - β (bullseye circle)symbols::PIE_CHAR_SQUARE_BOX - β£ (squared box)Shading Patterns:
symbols::PIE_CHAR_SHADE - β (medium shade pattern)symbols::PIE_CHAR_LIGHT - β (light shade pattern)symbols::PIE_CHAR_DARK - β (dark shade pattern)Circle Variations:
symbols::PIE_CHAR_SMALL_CIRCLE - β’ (small filled circle)symbols::PIE_CHAR_WHITE_CIRCLE - β (hollow circle)symbols::PIE_CHAR_DOUBLE_CIRCLE - β (circle with ring)Square Variations:
symbols::PIE_CHAR_SMALL_SQUARE - βͺ (small filled square)symbols::PIE_CHAR_WHITE_SQUARE - β‘ (hollow square)Diamond Variations:
symbols::PIE_CHAR_SMALL_DIAMOND - β (small filled diamond)symbols::PIE_CHAR_WHITE_DIAMOND - β (hollow diamond)Stars:
symbols::PIE_CHAR_STAR - β
(filled star)symbols::PIE_CHAR_WHITE_STAR - β (hollow star)Triangles:
symbols::PIE_CHAR_TRIANGLE_UP - β² (triangle pointing up)symbols::PIE_CHAR_TRIANGLE_DOWN - βΌ (triangle pointing down)symbols::PIE_CHAR_TRIANGLE_RIGHT - βΆ (triangle pointing right)symbols::PIE_CHAR_TRIANGLE_LEFT - β (triangle pointing left)Card Suits:
symbols::PIE_CHAR_HEART - β₯ (filled heart)symbols::PIE_CHAR_WHITE_HEART - β‘ (hollow heart)symbols::PIE_CHAR_SPADE - β (spade)symbols::PIE_CHAR_CLUB - β£ (club)Other:
symbols::PIE_CHAR_PLUS - β (plus sign)symbols::PIE_CHAR_CROSS - β (cross/multiply)symbols::PIE_CHAR_DOT - Β· (middle dot)symbols::PIE_CHAR_ASTERISM - β» (reference mark)symbols::PIE_CHAR_HORIZONTAL_BAR - β° (horizontal bar)Basic Markers:
symbols::LEGEND_MARKER - β (default, solid square)symbols::LEGEND_MARKER_CIRCLE - β (filled circle)symbols::LEGEND_MARKER_SQUARE - βͺ (small square)symbols::LEGEND_MARKER_DIAMOND - β (solid diamond)symbols::LEGEND_MARKER_ARROW - βΆ (right-pointing triangle)Stars:
symbols::LEGEND_MARKER_STAR - β
(filled star)symbols::LEGEND_MARKER_WHITE_STAR - β (hollow star)Circles:
symbols::LEGEND_MARKER_SMALL_CIRCLE - β’ (small circle)symbols::LEGEND_MARKER_WHITE_CIRCLE - β (hollow circle)Shapes:
symbols::LEGEND_MARKER_TRIANGLE - β² (triangle)symbols::LEGEND_MARKER_HEART - β₯ (filled heart)symbols::LEGEND_MARKER_WHITE_HEART - β‘ (hollow heart)Symbols:
symbols::LEGEND_MARKER_PLUS - β (plus sign)symbols::LEGEND_MARKER_CROSS - β (cross)symbols::LEGEND_MARKER_CHECK - β (checkmark)Arrows & Lines:
symbols::LEGEND_MARKER_RIGHT_ARROW - β (right arrow)symbols::LEGEND_MARKER_DOUBLE_RIGHT - Β» (double right)symbols::LEGEND_MARKER_DASH - β (dash)symbols::LEGEND_MARKER_DOT - Β· (dot)Special Shapes:
symbols::LEGEND_MARKER_HEXAGON - ⬑ (hollow hexagon)symbols::LEGEND_MARKER_BULLSEYE - β (bullseye)symbols::LEGEND_MARKER_SQUARE_BOX - β’ (hollow square box)symbols::LEGEND_MARKER_ASTERISM - β (asterism)symbols::LEGEND_MARKER_HORIZONTAL_BAR - β± (hollow horizontal bar)// Professional/Corporate Theme
let piechart = PieChart::new(slices)
.pie_char(symbols::PIE_CHAR_BLOCK)
.legend_marker(symbols::LEGEND_MARKER);
// Minimal/Clean Theme
let piechart = PieChart::new(slices)
.pie_char('Β·')
.legend_marker("β’");
// Geometric Theme
let piechart = PieChart::new(slices)
.pie_char('β')
.legend_marker("β");
// Playful Theme
let piechart = PieChart::new(slices)
.pie_char('β
')
.legend_marker("β");
You have access to the full Unicode character set:
// Arrows and triangles
let piechart = PieChart::new(slices)
.pie_char('β²')
.legend_marker("βΆ");
// Playing card suits
let piechart = PieChart::new(slices)
.pie_char('β ')
.legend_marker("β£");
// Decorative symbols
let piechart = PieChart::new(slices)
.pie_char('β')
.legend_marker("β¦");
// Emoji (if your terminal supports it)
let piechart = PieChart::new(slices)
.pie_char('π₯')
.legend_marker("π");
Legend markers can be multiple characters for unique styles:
// ASCII arrows
let piechart = PieChart::new(slices)
.legend_marker("-->");
// Brackets
let piechart = PieChart::new(slices)
.legend_marker("[ ]");
// Custom prefix
let piechart = PieChart::new(slices)
.legend_marker("=> ");
Predefined Symbols Examples (4 charts each in 2x2 grid):
# Circles and squares
cargo run --example symbols_circles_squares
# Stars and hearts
cargo run --example symbols_stars_hearts
# Triangles and hexagons
cargo run --example symbols_triangles_hexagons
# Shades and bars
cargo run --example symbols_shades_bars
Each example showcases 4 predefined symbol combinations:
Border Styles Example:
cargo run --example border_styles

This example showcases all 11 available border styles for PieChart blocks:
Custom Symbols Example:
cargo run --example custom_symbols
This example showcases truly custom Unicode characters NOT in the predefined list:
Terminal Compatibility: Not all terminals support all Unicode characters. Test your symbols in your target environment.
Solid Characters: Use solid, dense characters (β, β, β ) for best visibility in pie charts.
Consistent Themes: Match your pie character with your legend marker for visual consistency.
Size Considerations: For small charts (< 40 chars wide), use simpler characters like β or β.
Testing: Always test your custom symbols in the actual terminal where your application will run.
Enable high resolution rendering using Unicode braille patterns for dramatically smoother pie charts.
Live animated demo: The high_resolution example includes smooth animations that showcase the quality difference between standard and braille rendering in real-time.
let piechart = PieChart::new(slices)
.high_resolution(true);
// Or use the Resolution enum
use tui_piechart::Resolution;
let standard = PieChart::new(slices).resolution(Resolution::Standard);
let braille = PieChart::new(slices).resolution(Resolution::Braille);
Visual Comparison:
Standard mode (1 dot per cell):
βββββββββ
βββββββββββββββ
βββββββββββββββββββ
βββββββββββββββββββββ
Braille mode (8 dots per cell):
β£β£β£β£β£β£β£β£β£β£β‘
β’⣠⣴⣢⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣢⣀β£
⣠⣢⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦β‘
β’°β£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£Ώβ£·
How it works:
Example usage:
// Standard resolution (blocky)
let standard = PieChart::new(slices);
// High resolution (smooth) - just add one method!
let high_res = PieChart::new(slices).high_resolution(true);
Interactive animated demo:
cargo run --example high_resolution
# Press Space/Enter/H to toggle between modes
# Values animate smoothly to showcase rendering quality
Best for:
Note: The difference is immediately visible - high-res creates smooth circles instead of blocky shapes!
If you have VHS installed, you can generate demo GIFs for all examples:
# Main interactive demo
vhs examples/vhs/piechart.tape
# Predefined symbols examples
vhs examples/vhs/symbols_circles_squares.tape
vhs examples/vhs/symbols_stars_hearts.tape
vhs examples/vhs/symbols_triangles_hexagons.tape
vhs examples/vhs/symbols_shades_bars.tape
# Border styles demo
vhs examples/vhs/border_styles.tape
# Custom symbols demo
vhs examples/vhs/custom_symbols.tape
# High resolution demo
vhs examples/vhs/high_resolution.tape
# Or generate all at once using just
just vhs-all
Install tools:
just install-tools
# Run example
just run
# Run tests
just test
# Format and lint
just fmt
just clippy
# Check all
just check-all
# Generate demo GIF (requires VHS)
just vhs
# Bump version
just bump 0.1.0
See all available commands:
just --list
MIT License - see LICENSE for details.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
This widget was created for the Ratatui ecosystem.
Special thanks to the Ratatui team for creating such an amazing TUI framework.