pub struct PieChart<'a> { /* private fields */ }Expand description
A widget that displays a pie chart.
A PieChart displays data as slices of a circle, where each slice represents
a proportion of the total.
§Examples
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);Implementations§
Source§impl<'a> PieChart<'a>
impl<'a> PieChart<'a>
Sourcepub fn new(slices: Vec<PieSlice<'a>>) -> Self
pub fn new(slices: Vec<PieSlice<'a>>) -> Self
Creates a new PieChart with the given slices.
§Examples
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),
];
let piechart = PieChart::new(slices);Sourcepub fn slices(self, slices: Vec<PieSlice<'a>>) -> Self
pub fn slices(self, slices: Vec<PieSlice<'a>>) -> Self
Sets the slices of the pie chart.
§Examples
use ratatui::style::Color;
use tui_piechart::{PieChart, PieSlice};
let slices = vec![
PieSlice::new("Rust", 45.0, Color::Red),
];
let piechart = PieChart::default().slices(slices);Sourcepub fn block(self, block: Block<'a>) -> Self
pub fn block(self, block: Block<'a>) -> Self
Wraps the pie chart with the given block.
§Examples
use ratatui::style::Color;
use ratatui::widgets::Block;
use tui_piechart::{PieChart, PieSlice};
let slices = vec![PieSlice::new("Rust", 45.0, Color::Red)];
let piechart = PieChart::new(slices)
.block(Block::bordered().title("Statistics"));Sourcepub fn style<S: Into<Style>>(self, style: S) -> Self
pub fn style<S: Into<Style>>(self, style: S) -> Self
Sets the base style of the widget.
§Examples
use ratatui::style::{Color, Style};
use tui_piechart::PieChart;
let piechart = PieChart::default()
.style(Style::default().fg(Color::White));Sourcepub const fn show_legend(self, show: bool) -> Self
pub const fn show_legend(self, show: bool) -> Self
Sets whether to show the legend.
§Examples
use tui_piechart::PieChart;
let piechart = PieChart::default().show_legend(true);Sourcepub const fn show_percentages(self, show: bool) -> Self
pub const fn show_percentages(self, show: bool) -> Self
Sets whether to show percentages on slices.
§Examples
use tui_piechart::PieChart;
let piechart = PieChart::default().show_percentages(true);Sourcepub const fn pie_char(self, c: char) -> Self
pub const fn pie_char(self, c: char) -> Self
Sets the character used to draw the pie chart.
You can use any Unicode character for custom visualization.
§Examples
Using a predefined symbol:
use tui_piechart::{PieChart, symbols};
let piechart = PieChart::default()
.pie_char(symbols::PIE_CHAR_BLOCK);Using a custom character:
use tui_piechart::PieChart;
let piechart = PieChart::default().pie_char('█');Sourcepub const fn legend_marker(self, marker: &'a str) -> Self
pub const fn legend_marker(self, marker: &'a str) -> Self
Sets the marker used for legend items.
You can use any string (including Unicode characters) for custom markers.
§Examples
Using a predefined symbol:
use tui_piechart::{PieChart, symbols};
let piechart = PieChart::default()
.legend_marker(symbols::LEGEND_MARKER_CIRCLE);Using custom markers:
use tui_piechart::PieChart;
// Simple arrow
let piechart = PieChart::default().legend_marker("→");
// Or any Unicode character
let piechart = PieChart::default().legend_marker("★");
// Or even multi-character strings
let piechart = PieChart::default().legend_marker("-->");Sourcepub const fn resolution(self, resolution: Resolution) -> Self
pub const fn resolution(self, resolution: Resolution) -> Self
Sets the rendering resolution mode.
Different resolution modes provide varying levels of detail:
Standard: Regular characters (1 dot per cell)Braille: 2×4 patterns (8 dots per cell, 8x resolution)
§Examples
use tui_piechart::{PieChart, Resolution};
let standard = PieChart::default().resolution(Resolution::Standard);
let braille = PieChart::default().resolution(Resolution::Braille);Sourcepub const fn high_resolution(self, enabled: bool) -> Self
pub const fn high_resolution(self, enabled: bool) -> Self
Sets whether to use high resolution rendering with braille patterns.
This is a convenience method that sets the resolution to Braille when enabled,
or Standard when disabled. For more control, use resolution.
§Examples
use tui_piechart::PieChart;
let piechart = PieChart::default().high_resolution(true);Sourcepub const fn legend_position(self, position: LegendPosition) -> Self
pub const fn legend_position(self, position: LegendPosition) -> Self
Sets the position of the legend relative to the pie chart.
§Examples
use tui_piechart::{PieChart, LegendPosition};
let piechart = PieChart::default()
.legend_position(LegendPosition::Right);Sourcepub const fn legend_layout(self, layout: LegendLayout) -> Self
pub const fn legend_layout(self, layout: LegendLayout) -> Self
Sets the layout mode for the legend.
§Examples
use tui_piechart::{PieChart, LegendLayout};
// Single horizontal row
let piechart = PieChart::default()
.legend_layout(LegendLayout::Horizontal);
// Vertical stacking (default)
let piechart = PieChart::default()
.legend_layout(LegendLayout::Vertical);Sourcepub const fn legend_alignment(self, alignment: LegendAlignment) -> Self
pub const fn legend_alignment(self, alignment: LegendAlignment) -> Self
Sets the alignment of legend items within the legend area.
§Examples
use tui_piechart::{PieChart, LegendAlignment};
// Center-align legend items
let piechart = PieChart::default()
.legend_alignment(LegendAlignment::Center);
// Right-align legend items
let piechart = PieChart::default()
.legend_alignment(LegendAlignment::Right);Trait Implementations§
impl<'a> StructuralPartialEq for PieChart<'a>
Auto Trait Implementations§
impl<'a> Freeze for PieChart<'a>
impl<'a> RefUnwindSafe for PieChart<'a>
impl<'a> Send for PieChart<'a>
impl<'a> Sync for PieChart<'a>
impl<'a> Unpin for PieChart<'a>
impl<'a> UnwindSafe for PieChart<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<'a, T, U> Stylize<'a, T> for Uwhere
U: Styled<Item = T>,
impl<'a, T, U> Stylize<'a, T> for Uwhere
U: Styled<Item = T>,
fn bg<C>(self, color: C) -> T
fn fg<C>(self, color: C) -> T
fn add_modifier(self, modifier: Modifier) -> T
fn remove_modifier(self, modifier: Modifier) -> T
fn reset(self) -> T
Source§fn on_magenta(self) -> T
fn on_magenta(self) -> T
magenta.Source§fn on_dark_gray(self) -> T
fn on_dark_gray(self) -> T
dark_gray.Source§fn on_light_red(self) -> T
fn on_light_red(self) -> T
light_red.Source§fn light_green(self) -> T
fn light_green(self) -> T
light_green.Source§fn on_light_green(self) -> T
fn on_light_green(self) -> T
light_green.Source§fn light_yellow(self) -> T
fn light_yellow(self) -> T
light_yellow.Source§fn on_light_yellow(self) -> T
fn on_light_yellow(self) -> T
light_yellow.Source§fn light_blue(self) -> T
fn light_blue(self) -> T
light_blue.Source§fn on_light_blue(self) -> T
fn on_light_blue(self) -> T
light_blue.Source§fn light_magenta(self) -> T
fn light_magenta(self) -> T
light_magenta.Source§fn on_light_magenta(self) -> T
fn on_light_magenta(self) -> T
light_magenta.Source§fn light_cyan(self) -> T
fn light_cyan(self) -> T
light_cyan.Source§fn on_light_cyan(self) -> T
fn on_light_cyan(self) -> T
light_cyan.Source§fn not_italic(self) -> T
fn not_italic(self) -> T
ITALIC modifier.Source§fn underlined(self) -> T
fn underlined(self) -> T
UNDERLINED modifier.Source§fn not_underlined(self) -> T
fn not_underlined(self) -> T
UNDERLINED modifier.Source§fn slow_blink(self) -> T
fn slow_blink(self) -> T
SLOW_BLINK modifier.Source§fn not_slow_blink(self) -> T
fn not_slow_blink(self) -> T
SLOW_BLINK modifier.Source§fn rapid_blink(self) -> T
fn rapid_blink(self) -> T
RAPID_BLINK modifier.Source§fn not_rapid_blink(self) -> T
fn not_rapid_blink(self) -> T
RAPID_BLINK modifier.Source§fn not_reversed(self) -> T
fn not_reversed(self) -> T
REVERSED modifier.HIDDEN modifier.HIDDEN modifier.Source§fn crossed_out(self) -> T
fn crossed_out(self) -> T
CROSSED_OUT modifier.Source§fn not_crossed_out(self) -> T
fn not_crossed_out(self) -> T
CROSSED_OUT modifier.