Crate tui_piechart

Crate tui_piechart 

Source
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.