Skip to main content

PieArtist

Struct PieArtist 

Source
pub struct PieArtist {
    pub sizes: Vec<f64>,
    pub labels: Option<Vec<String>>,
    pub colors: Option<Vec<Color>>,
    pub explode: Option<Vec<f64>>,
    pub autopct: bool,
    pub start_angle: f64,
    pub radius: f64,
    pub label: Option<String>,
    pub color: Color,
}
Expand description

A pie chart rendering proportional wedge slices from a set of sizes.

Each entry in sizes is automatically normalised so that the wedges sum to a full circle. The starting angle, explode offsets, and colors can be customised through the builder API.

Fields§

§sizes: Vec<f64>

Wedge sizes (auto-normalised to sum to 1.0 during rendering).

§labels: Option<Vec<String>>

Optional labels for each wedge, drawn outside the wedge arc.

§colors: Option<Vec<Color>>

Optional custom colors for each wedge. When None, the theme color cycle is used.

§explode: Option<Vec<f64>>

Optional explode offset for each wedge, as a fraction of the radius. A value of 0.0 means no offset.

§autopct: bool

When true, percentage labels are drawn at the midpoint of each wedge arc.

§start_angle: f64

Starting angle in degrees, counter-clockwise from the positive x-axis. Default is 90.0 (top of the circle).

§radius: f64

Radius of the pie in data-space units. Default is 1.0.

§label: Option<String>

Optional legend label. When Some, the pie appears in the legend.

§color: Color

Primary color (used for legend swatch when no custom colors are set).

Implementations§

Source§

impl PieArtist

Source

pub fn data_bounds(&self) -> (f64, f64, f64, f64)

Computes the data-space bounding box (xmin, xmax, ymin, ymax).

Returns a fixed square region that accommodates the pie radius plus any explode offsets, with a small margin so that labels do not get clipped.

Source§

impl PieArtist

Source

pub fn labels(&mut self, labels: Vec<&str>) -> &mut Self

Sets the wedge labels displayed next to each slice.

The number of labels should match the number of wedge sizes. If fewer labels are provided, extra wedges will have no label.

§Arguments
  • labels - A vector of label strings, one per wedge.
§Examples
let mut pie = PieArtist {
    sizes: vec![1.0, 2.0, 3.0],
    labels: None,
    colors: None,
    explode: None,
    autopct: false,
    start_angle: 90.0,
    radius: 1.0,
    label: None,
    color: plotkit_core::primitives::Color::TAB_BLUE,
};
pie.labels(vec!["A", "B", "C"]);
assert_eq!(pie.labels.as_ref().unwrap().len(), 3);
Source

pub fn colors(&mut self, colors: Vec<Color>) -> &mut Self

Sets custom colors for each wedge.

When not set, the theme color cycle is used automatically.

§Arguments
  • colors - A vector of Color values, one per wedge.
§Examples
let mut pie = PieArtist {
    sizes: vec![1.0, 2.0],
    labels: None,
    colors: None,
    explode: None,
    autopct: false,
    start_angle: 90.0,
    radius: 1.0,
    label: None,
    color: Color::TAB_BLUE,
};
pie.colors(vec![Color::TAB_RED, Color::TAB_GREEN]);
assert_eq!(pie.colors.as_ref().unwrap().len(), 2);
Source

pub fn explode(&mut self, explode: Vec<f64>) -> &mut Self

Sets the explode offsets for each wedge.

Each value represents the fraction of the radius by which the corresponding wedge is offset from the center. A value of 0.0 means no offset; 0.1 pushes the wedge outward by 10% of the radius.

§Arguments
  • explode - A vector of offset fractions, one per wedge.
§Examples
let mut pie = PieArtist {
    sizes: vec![1.0, 2.0, 3.0],
    labels: None,
    colors: None,
    explode: None,
    autopct: false,
    start_angle: 90.0,
    radius: 1.0,
    label: None,
    color: Color::TAB_BLUE,
};
pie.explode(vec![0.1, 0.0, 0.0]);
assert_eq!(pie.explode.as_ref().unwrap()[0], 0.1);
Source

pub fn autopct(&mut self, show: bool) -> &mut Self

Enables or disables automatic percentage labels on each wedge.

When enabled, each wedge displays its percentage of the total as text positioned at the midpoint of the wedge arc.

§Arguments
  • show - true to show percentage labels, false to hide them.
§Examples
let mut pie = PieArtist {
    sizes: vec![1.0, 2.0],
    labels: None,
    colors: None,
    explode: None,
    autopct: false,
    start_angle: 90.0,
    radius: 1.0,
    label: None,
    color: Color::TAB_BLUE,
};
pie.autopct(true);
assert!(pie.autopct);
Source

pub fn start_angle(&mut self, angle: f64) -> &mut Self

Sets the starting angle for the first wedge in degrees.

The default is 90.0 (top of the circle). Angles increase counter-clockwise.

§Arguments
  • angle - The starting angle in degrees.
§Examples
let mut pie = PieArtist {
    sizes: vec![1.0, 2.0],
    labels: None,
    colors: None,
    explode: None,
    autopct: false,
    start_angle: 90.0,
    radius: 1.0,
    label: None,
    color: Color::TAB_BLUE,
};
pie.start_angle(0.0);
assert!((pie.start_angle - 0.0).abs() < f64::EPSILON);
Source

pub fn radius(&mut self, radius: f64) -> &mut Self

Sets the radius of the pie chart in data-space units.

The default radius is 1.0. The pie is drawn in a square coordinate space that accommodates the radius plus any explode offsets.

§Arguments
  • radius - The radius of the pie.
§Examples
let mut pie = PieArtist {
    sizes: vec![1.0, 2.0],
    labels: None,
    colors: None,
    explode: None,
    autopct: false,
    start_angle: 90.0,
    radius: 1.0,
    label: None,
    color: Color::TAB_BLUE,
};
pie.radius(0.8);
assert!((pie.radius - 0.8).abs() < f64::EPSILON);
Source

pub fn label(&mut self, label: &str) -> &mut Self

Sets the legend label for the pie chart.

When a legend is displayed on the figure, this label will appear next to the color swatch for this pie chart.

§Arguments
  • label - A string slice that will be stored as the legend entry.
§Examples
let mut pie = PieArtist {
    sizes: vec![1.0, 2.0],
    labels: None,
    colors: None,
    explode: None,
    autopct: false,
    start_angle: 90.0,
    radius: 1.0,
    label: None,
    color: Color::TAB_BLUE,
};
pie.label("pie chart");
assert_eq!(pie.label.as_deref(), Some("pie chart"));

Trait Implementations§

Source§

impl Clone for PieArtist

Source§

fn clone(&self) -> PieArtist

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PieArtist

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.