use crate::{Align, Color, Size};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChartType {
Bar,
Line,
Pie,
}
#[derive(Debug, Clone)]
pub struct Chart {
pub chart_type: ChartType,
pub data: Vec<f64>,
pub labels: Option<Vec<String>>,
pub width: Size,
pub height: Size,
pub color: Option<Color>,
pub align: Align,
pub show_values: bool,
}
impl Chart {
pub fn new(data: Vec<f64>) -> Self {
Self {
chart_type: ChartType::Bar,
data,
labels: None,
width: Size::Points(300.0),
height: Size::Points(200.0),
color: None,
align: Align::Left,
show_values: false,
}
}
pub fn show_values(mut self, show: bool) -> Self {
self.show_values = show;
self
}
pub fn chart_type(mut self, t: ChartType) -> Self {
self.chart_type = t;
self
}
pub fn width(mut self, w: impl Into<Size>) -> Self {
self.width = w.into();
self
}
pub fn height(mut self, h: impl Into<Size>) -> Self {
self.height = h.into();
self
}
pub fn labels(mut self, l: Vec<&str>) -> Self {
self.labels = Some(l.into_iter().map(|s| s.to_string()).collect());
self
}
pub fn color(mut self, c: Color) -> Self {
self.color = Some(c);
self
}
pub fn align(mut self, a: Align) -> Self {
self.align = a;
self
}
}