pub struct PieChart {
pub title: String,
pub datasets: Vec<(String, f64, [u8; 3])>,
pub config: FigureConfig,
}
Expand description
Represents a pie chart with title, datasets, and configuration settings.
Fields§
§title: String
Title of the pie chart.
datasets: Vec<(String, f64, [u8; 3])>
A collection of datasets, where each dataset contains:
- A label (
String
). - A value (
f64
). - A color in RGB format (
[u8; 3]
).
config: FigureConfig
Configuration settings for rendering the chart (e.g., fonts, colors, grid).
Implementations§
source§impl PieChart
impl PieChart
sourcepub fn new(title: &str, config: FigureConfig) -> Self
pub fn new(title: &str, config: FigureConfig) -> Self
Creates a new PieChart
instance with the specified title and configuration.
§Parameters
title
: The title of the pie chart.config
: TheFigureConfig
containing appearance and behavior settings.
§Returns
A new PieChart
instance with no datasets.
§Example
use crate::figure::configuration::figureconfig::FigureConfig;
use crate::figure::piechart::PieChart;
let config = FigureConfig::default();
let pie_chart = PieChart::new("Market Share", config);
sourcepub fn add_slice(&mut self, label: &str, value: f64, color: [u8; 3])
pub fn add_slice(&mut self, label: &str, value: f64, color: [u8; 3])
Adds a slice to the pie chart.
§Parameters
label
: The label for the slice.value
: The value representing the proportion of the slice.color
: The RGB color of the slice.
§Example
pie_chart.add_slice("Product A", 30.0, [255, 0, 0]);
pie_chart.add_slice("Product B", 50.0, [0, 255, 0]);
pie_chart.add_slice("Product C", 20.0, [0, 0, 255]);
sourcepub fn draw_slice(
&self,
canvas: &mut PixelCanvas,
center_x: i32,
center_y: i32,
radius: i32,
start_angle: f64,
end_angle: f64,
color: [u8; 3],
)
pub fn draw_slice( &self, canvas: &mut PixelCanvas, center_x: i32, center_y: i32, radius: i32, start_angle: f64, end_angle: f64, color: [u8; 3], )
Draws a slice of the pie chart on the canvas.
§Parameters
canvas
: ThePixelCanvas
to draw the slice on.center_x
: The x-coordinate of the center of the pie chart.center_y
: The y-coordinate of the center of the pie chart.radius
: The radius of the pie chart.start_angle
: The starting angle of the slice in radians.end_angle
: The ending angle of the slice in radians.color
: The RGB color of the slice.
§Details
This method fills a portion of the circle defined by start_angle
and end_angle
.
It ensures that only points within the slice and the circle are drawn.
§Example
pie_chart.draw_slice(&mut canvas, 200, 200, 100, 0.0, 1.0, [255, 0, 0]);
Trait Implementations§
source§impl Drawer for PieChart
impl Drawer for PieChart
source§fn draw_svg(&mut self, svg_canvas: &mut SvgCanvas)
fn draw_svg(&mut self, svg_canvas: &mut SvgCanvas)
Draws the plot content on an
SvgCanvas
. Read moresource§fn draw(&mut self, canvas: &mut PixelCanvas)
fn draw(&mut self, canvas: &mut PixelCanvas)
Draws the main content of the plot on a
PixelCanvas
. Read moresource§fn draw_legend(&self, canvas: &mut PixelCanvas)
fn draw_legend(&self, canvas: &mut PixelCanvas)
Draws the legend for the plot on a
PixelCanvas
. Read moresource§fn draw_grid(&self, canvas: &mut PixelCanvas, config: &FigureConfig)
fn draw_grid(&self, canvas: &mut PixelCanvas, config: &FigureConfig)
Draws the grid for the plot based on the provided configuration. Read more
source§fn draw_axis(
&self,
canvas: &mut PixelCanvas,
config: &FigureConfig,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
)
fn draw_axis( &self, canvas: &mut PixelCanvas, config: &FigureConfig, x1: i32, y1: i32, x2: i32, y2: i32, )
Draws an axis line on the canvas. Read more
source§fn draw_label(
&self,
canvas: &mut PixelCanvas,
config: &FigureConfig,
x: u32,
y: u32,
text: &str,
)
fn draw_label( &self, canvas: &mut PixelCanvas, config: &FigureConfig, x: u32, y: u32, text: &str, )
Draws a text label on the canvas. Read more
source§fn draw_title(
&self,
canvas: &mut PixelCanvas,
config: &FigureConfig,
x: u32,
y: u32,
text: &str,
)
fn draw_title( &self, canvas: &mut PixelCanvas, config: &FigureConfig, x: u32, y: u32, text: &str, )
Draws the plot title on the canvas. Read more
source§fn draw_axis_value(
&self,
canvas: &mut PixelCanvas,
config: &FigureConfig,
x: u32,
y: u32,
text: &str,
axis: AxisType,
)
fn draw_axis_value( &self, canvas: &mut PixelCanvas, config: &FigureConfig, x: u32, y: u32, text: &str, axis: AxisType, )
Draws a value on the axis (tick label) based on its type. Read more
source§impl Hover for PieChart
impl Hover for PieChart
source§fn find_closest_point(
&self,
mouse_x: u32,
mouse_y: u32,
canvas: &PixelCanvas,
) -> Option<((f64, f64), f64)>
fn find_closest_point( &self, mouse_x: u32, mouse_y: u32, canvas: &PixelCanvas, ) -> Option<((f64, f64), f64)>
Finds the closest point to the mouse position on the plot. Read more
source§fn to_canvas_coordinates(
&self,
x: f64,
y: f64,
_canvas: &PixelCanvas,
) -> (u32, u32)
fn to_canvas_coordinates( &self, x: f64, y: f64, _canvas: &PixelCanvas, ) -> (u32, u32)
Converts plot coordinates into canvas pixel coordinates. Read more
source§fn handle_hover(
&self,
mouse_x: u32,
mouse_y: u32,
canvas: &PixelCanvas,
) -> Option<Vec<u32>>
fn handle_hover( &self, mouse_x: u32, mouse_y: u32, canvas: &PixelCanvas, ) -> Option<Vec<u32>>
Handles hover functionality and returns an updated buffer if applicable. Read more
Auto Trait Implementations§
impl Freeze for PieChart
impl RefUnwindSafe for PieChart
impl Send for PieChart
impl Sync for PieChart
impl Unpin for PieChart
impl UnwindSafe for PieChart
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.