Skip to main content

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
  • 🎛️ GaugeChart with 15 styles, plus RadialBar, RingStack, Funnel, RadarChart, Treemap and Waterfall
  • 🍩 Donut / segmented / HUD / rose pies via PieStyle
  • ⚡ 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 funnel::Funnel;
pub use funnel::FunnelStage;
pub use funnel::FunnelStyle;
pub use gauge::GaugeChart;
pub use gauge::GaugeStyle;
pub use legend::LegendAlignment;
pub use legend::LegendLayout;
pub use legend::LegendPosition;
pub use pie_style::PieStyle;
pub use radar::RadarChart;
pub use radar::RadarSeries;
pub use radial::RadialBar;
pub use radial::RadialRing;
pub use radial::RadialSweep;
pub use radial::RingStack;
pub use title::BlockExt;
pub use title::TitleAlignment;
pub use title::TitlePosition;
pub use title::TitleStyle;
pub use treemap::Treemap;
pub use treemap::TreemapItem;
pub use waterfall::Waterfall;
pub use waterfall::WaterfallStep;

Modules§

border_style
Border styles for pie chart block wrappers.
funnel
Funnel: stages narrowing from top to bottom, as bars or a smooth trapezoid.
gauge
Gauge widget with many looks: radial dials, segmented rings, LED meters, progress bars, batteries and more.
legend
Legend positioning and layout configuration for pie charts.
macros
Macro utilities for reducing boilerplate code.
pie_style
Pie looks beyond the plain disc: segmented ring, HUD band and rose (polar area), plus gaps and exploded slices. All drawn with braille dots.
radar
RadarChart: several series compared over shared axes (spider / web chart).
radial
Concentric progress rings: RadialBar (value / max per ring) and RingStack (percentages, always a 270° sweep).
symbols
Symbols for pie chart widget and legends
title
Title positioning, alignment, and styling configuration for block wrappers.
treemap
Treemap: nested rectangles sized by value (squarified layout).
waterfall
Waterfall: running totals built from up / down steps and total bars.

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.
matches_test
Generate a test asserting that an expression matches a pattern.
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.