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: boolWhen true, percentage labels are drawn at the midpoint of each
wedge arc.
start_angle: f64Starting angle in degrees, counter-clockwise from the positive
x-axis. Default is 90.0 (top of the circle).
radius: f64Radius 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: ColorPrimary color (used for legend swatch when no custom colors are set).
Implementations§
Source§impl PieArtist
impl PieArtist
Sourcepub fn labels(&mut self, labels: Vec<&str>) -> &mut Self
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);Sourcepub fn colors(&mut self, colors: Vec<Color>) -> &mut Self
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 ofColorvalues, 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);Sourcepub fn explode(&mut self, explode: Vec<f64>) -> &mut Self
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);Sourcepub fn autopct(&mut self, show: bool) -> &mut Self
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-trueto show percentage labels,falseto 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);Sourcepub fn start_angle(&mut self, angle: f64) -> &mut Self
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);Sourcepub fn radius(&mut self, radius: f64) -> &mut Self
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);Sourcepub fn label(&mut self, label: &str) -> &mut Self
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"));