pub struct PieChart { /* private fields */ }Expand description
Shares of a whole as slices of a disc, clockwise from the top, with a
legend naming each slice and its percentage; with
donut, a ring with a hole, and text in the hole.
- Slice
Ntakes the theme stylechart.series.N(they cycle), or its ownSlice::style. Charset::Blocks(the default) draws with half blocks (▀▄█): two pixels a cell, each slice’s colour, so two slices can share a cell. Without colour it draws a cell a slice, each slice in its own fill (█░▓▒▚▞), and the legend shows the fills.Charset::Brailledraws 2×4 dots a cell and leaves the dots on the edges between slices out, so the slices read as wedges without colour too; a cell takes the colour of the slice with most of its dots.Charset::Asciidraws a cell a slice in#+@:%=o*, and is what an ASCII-only console gets whatever was asked for.- The disc is
heightrows tall (default: the height it is given, or 8) and twice that wide, so it looks round. The legend goes beside it when there is room, under it otherwise; given less width than the disc, the disc shrinks. - A value that is not a finite number above zero takes no part of the
disc; the legend writes
-for its percentage. A slice too small for a cell is still in the legend.
use rich::Console;
use rich_ext::chart::{Charset, PieChart};
let console = Console::builder().width(40).color_system(None).build();
let pie = PieChart::from_pairs([("api", 50.0), ("web", 30.0), ("cron", 20.0)])
.height(4)
.charset(Charset::Ascii);
assert_eq!(
console.render_export(&pie),
concat!(
" @@@### # api 50.0%\n",
"+@@@#### + web 30.0%\n",
"++++#### @ cron 20.0%\n",
" +++### \n",
)
);Implementations§
Source§impl PieChart
impl PieChart
Sourcepub fn from_pairs<L: Into<String>>(
pairs: impl IntoIterator<Item = (L, f64)>,
) -> Self
pub fn from_pairs<L: Into<String>>( pairs: impl IntoIterator<Item = (L, f64)>, ) -> Self
A chart of (label, value) pairs.
Sourcepub fn donut(self, hole: f64) -> Self
pub fn donut(self, hole: f64) -> Self
Draw a ring: hole is the hole’s share of the radius (0 for a pie,
at most 0.9; 0.5 is a common donut).
Sourcepub fn centre_text(self, text: impl Into<String>) -> Self
pub fn centre_text(self, text: impl Into<String>) -> Self
Text written in a donut’s hole, such as the total, when it fits.
Sourcepub fn height(self, rows: usize) -> Self
pub fn height(self, rows: usize) -> Self
Rows for the disc (at least 1); it is twice as many cells wide.
Sourcepub fn charset(self, charset: Charset) -> Self
pub fn charset(self, charset: Charset) -> Self
Glyphs to draw with (default Charset::Auto: half blocks).
Sourcepub fn show_percentages(self, show: bool) -> Self
pub fn show_percentages(self, show: bool) -> Self
Write each slice’s percentage in the legend (default on).
Sourcepub fn show_values(self, show: bool) -> Self
pub fn show_values(self, show: bool) -> Self
Write each slice’s value in the legend (default off).
Sourcepub fn format(self, format: ValueFormat) -> Self
pub fn format(self, format: ValueFormat) -> Self
How values are written (default ValueFormat::Compact).
Each slice’s share of the whole (0 to 1), None for one that takes
no part.
Trait Implementations§
Source§impl AccessibleText for PieChart
Pie chart, 3 slices, total 100, then every slice (up to six) with its
value and percentage, or the three largest and the smallest. A donut
says Donut chart.
impl AccessibleText for PieChart
Pie chart, 3 slices, total 100, then every slice (up to six) with its
value and percentage, or the three largest and the smallest. A donut
says Donut chart.
Source§fn accessible_text(&self, _width: usize) -> String
fn accessible_text(&self, _width: usize) -> String
width where layout matters.Source§impl Renderable for PieChart
impl Renderable for PieChart
fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>
Source§fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
(minimum, maximum) cell width this renderable wants. Port of
__rich_measure__. The default is what upstream’s Measurement.get
returns for a renderable without one: anything from nothing to the
whole width, (0, max_width).Source§fn fit_to_measurement(&self) -> bool
fn fit_to_measurement(&self) -> bool
Console::print shrinks this renderable to its
measured width. Upstream renders every top-level renderable at the full
console width, so the default is false; an extension may opt in.Source§fn vertical(&self) -> Option<VerticalAlign>
fn vertical(&self) -> Option<VerticalAlign>
Table cell holding this renderable uses in
place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.Source§fn print_end_line(&self, _options: &ConsoleOptions) -> bool
fn print_end_line(&self, _options: &ConsoleOptions) -> bool
"\n", so a print adds the final line break. A renderable
whose upstream output stops without one (Screen, LiveRender, a
Rule whose end has no newline) returns false, and the next
output continues its last line. options are the print’s options.