//! Charts: an embedded data grid plus type and element options.
use serde::{Deserialize, Serialize};
use crate::style::{ColorRef, Fill, Line};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum ChartType {
#[default]
Column,
StackedColumn,
PercentColumn,
Bar,
StackedBar,
PercentBar,
Line,
LineMarkers,
StackedLine,
Area,
StackedArea,
Pie,
Doughnut,
Scatter,
Bubble,
Radar,
FilledRadar,
Stock,
Surface,
Histogram,
Pareto,
BoxWhisker,
Waterfall,
Funnel,
Treemap,
Sunburst,
Combo,
}
impl ChartType {
pub const MAIN: [ChartType; 12] = [
ChartType::Column,
ChartType::Bar,
ChartType::Line,
ChartType::Area,
ChartType::Pie,
ChartType::Doughnut,
ChartType::Scatter,
ChartType::Radar,
ChartType::Waterfall,
ChartType::Funnel,
ChartType::Histogram,
ChartType::Treemap,
];
pub fn label(self) -> &'static str {
match self {
ChartType::Column => "Clustered Column",
ChartType::StackedColumn => "Stacked Column",
ChartType::PercentColumn => "100% Stacked Column",
ChartType::Bar => "Clustered Bar",
ChartType::StackedBar => "Stacked Bar",
ChartType::PercentBar => "100% Stacked Bar",
ChartType::Line => "Line",
ChartType::LineMarkers => "Line with Markers",
ChartType::StackedLine => "Stacked Line",
ChartType::Area => "Area",
ChartType::StackedArea => "Stacked Area",
ChartType::Pie => "Pie",
ChartType::Doughnut => "Doughnut",
ChartType::Scatter => "Scatter",
ChartType::Bubble => "Bubble",
ChartType::Radar => "Radar",
ChartType::FilledRadar => "Filled Radar",
ChartType::Stock => "Stock",
ChartType::Surface => "Surface",
ChartType::Histogram => "Histogram",
ChartType::Pareto => "Pareto",
ChartType::BoxWhisker => "Box and Whisker",
ChartType::Waterfall => "Waterfall",
ChartType::Funnel => "Funnel",
ChartType::Treemap => "Treemap",
ChartType::Sunburst => "Sunburst",
ChartType::Combo => "Combo",
}
}
pub fn is_bar_like(self) -> bool {
matches!(
self,
ChartType::Column
| ChartType::StackedColumn
| ChartType::PercentColumn
| ChartType::Bar
| ChartType::StackedBar
| ChartType::PercentBar
| ChartType::Histogram
| ChartType::Pareto
| ChartType::Waterfall
)
}
pub fn horizontal(self) -> bool {
matches!(self, ChartType::Bar | ChartType::StackedBar | ChartType::PercentBar | ChartType::Funnel)
}
pub fn stacked(self) -> bool {
matches!(
self,
ChartType::StackedColumn
| ChartType::StackedBar
| ChartType::StackedLine
| ChartType::StackedArea
| ChartType::PercentColumn
| ChartType::PercentBar
)
}
pub fn percent(self) -> bool {
matches!(self, ChartType::PercentColumn | ChartType::PercentBar)
}
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct Series {
pub name: String,
pub values: Vec