use super::{LabelFormatter, ValueFormatter};
use animate::{prelude::*, Gradient};
use animate::{Color, TextStyle};
#[derive(Debug, Clone)]
pub enum Fill {
None,
Solid(Color),
Gradient(Gradient),
}
impl Default for Fill {
fn default() -> Self {
Self::None
}
}
pub enum Position {
Above,
Middle,
Below,
Left,
Top,
Bottom,
Right,
None,
}
pub trait BaseOption {
fn animation(&self) -> &AnimationOptions;
fn colors(&self) -> &Vec<Fill>;
fn title(&self) -> &TitleOptions;
fn legend(&self) -> &LegendOptions;
fn tooltip(&self) -> &TooltipOptions;
fn background(&self) -> &Fill;
}
pub struct AnimationOptions {
pub duration: usize,
pub easing: String,
pub on_end: Option<fn()>,
}
pub struct LegendOptions {
pub label_formatter: Option<LabelFormatter>,
pub position: Position,
pub style: StyleOptions,
}
pub struct TitleOptions {
pub position: Position,
pub style: StyleOptions,
pub text: Option<String>,
}
pub struct TooltipOptions {
pub enabled: bool,
pub label_formatter: Option<LabelFormatter>,
pub style: StyleOptions,
pub value_formatter: Option<ValueFormatter>,
}
#[derive(Debug, Clone)]
pub struct BarChartSeriesOptions {
pub labels: Option<StyleOptions>,
}
pub struct BarChartCrosshairOptions {
pub color: Color,
}
pub struct BarChartXAxisLabelsOptions {
pub max_rotation: i64,
pub min_rotation: i64,
pub style: StyleOptions,
}
pub struct BarChartXAxisOptions {
pub crosshair: Option<BarChartCrosshairOptions>,
pub grid_line_color: Color,
pub grid_line_width: f64,
pub line_color: Color,
pub line_width: f64,
pub labels: BarChartXAxisLabelsOptions,
pub position: Position,
pub title: TitleOption,
}
pub struct BarChartYAxisLabelsOptions {
pub formatter: Option<ValueFormatter>,
pub style: StyleOptions,
}
pub struct BarChartYAxisOptions {
pub grid_line_color: Color,
pub grid_line_width: f64,
pub line_color: Color,
pub line_width: f64,
pub interval: Option<f64>,
pub labels: BarChartYAxisLabelsOptions,
pub max_value: Option<usize>,
pub min_interval: Option<f64>,
pub min_value: Option<usize>,
pub position: Position,
pub title: TitleOption,
}
pub struct BarChartOptions {
pub channel: BarChartSeriesOptions,
pub xaxis: BarChartXAxisOptions,
pub yaxis: BarChartYAxisOptions,
pub animation: AnimationOptions,
pub background: Fill,
pub colors: Vec<Fill>,
pub legend: LegendOptions,
pub title: TitleOptions,
pub tooltip: TooltipOptions,
}
impl BaseOption for BarChartOptions {
fn animation(&self) -> &AnimationOptions {
&self.animation
}
fn colors(&self) -> &Vec<Fill> {
&self.colors
}
fn title(&self) -> &TitleOptions {
&self.title
}
fn legend(&self) -> &LegendOptions {
&self.legend
}
fn tooltip(&self) -> &TooltipOptions {
&self.tooltip
}
fn background(&self) -> &Fill {
&self.background
}
}
pub struct TitleOption {
pub style: StyleOptions,
pub text: Option<String>,
}
impl Default for BarChartOptions {
fn default() -> Self {
Self {
channel: BarChartSeriesOptions { labels: None },
xaxis: BarChartXAxisOptions {
crosshair: None,
grid_line_color: color::GRAY_5,
grid_line_width: 1.,
line_color: color::GRAY_5,
line_width: 1.,
labels: BarChartXAxisLabelsOptions {
max_rotation: 0,
min_rotation: -90,
style: Default::default(),
},
position: Position::Bottom,
title: TitleOption {
style: Default::default(),
text: None,
},
},
yaxis: BarChartYAxisOptions {
grid_line_color: color::GRAY_5,
grid_line_width: 0.,
line_color: color::GRAY_5,
line_width: 0.,
interval: None,
labels: BarChartYAxisLabelsOptions {
formatter: None,
style: Default::default(),
},
max_value: None,
min_interval: None,
min_value: None,
position: Position::Left,
title: TitleOption {
style: Default::default(),
text: None,
},
},
animation: AnimationOptions {
duration: 800,
easing: "easeOutQuint".into(),
on_end: None,
},
background: Fill::Solid(color::WHITE),
colors: vec![
Fill::Solid(Color::rgb(0x7c, 0xb5, 0xec)),
Fill::Solid(Color::rgb(0x43, 0x43, 0x48)),
Fill::Solid(Color::rgb(0x90, 0xed, 0x7d)),
Fill::Solid(Color::rgb(0xf7, 0xa3, 0x5c)),
Fill::Solid(Color::rgb(0x80, 0x85, 0xe9)),
Fill::Solid(Color::rgb(0xf1, 0x5c, 0x80)),
Fill::Solid(Color::rgb(0xe4, 0xd3, 0x54)),
Fill::Solid(Color::rgb(0x80, 0x85, 0xe8)),
Fill::Solid(Color::rgb(0x8d, 0x46, 0x53)),
Fill::Solid(Color::rgb(0x91, 0xe8, 0xe1)),
],
legend: LegendOptions {
label_formatter: None,
position: Position::Right,
style: Default::default(),
},
title: TitleOptions {
position: Position::Above,
style: Default::default(),
text: None,
},
tooltip: TooltipOptions {
enabled: true,
label_formatter: None,
style: Default::default(),
value_formatter: None,
},
}
}
}
#[derive(Debug, Clone)]
pub struct StyleOptions {
pub background: Color,
pub border_color: Color,
pub border_width: f64,
pub color: Color,
pub fontfamily: Option<String>,
pub fontsize: Option<f64>,
pub fontstyle: Option<TextStyle>,
}
impl Default for StyleOptions {
fn default() -> Self {
Self {
background: color::WHITE,
border_color: color::GRAY_4,
border_width: 0_f64,
color: color::GRAY_9,
fontfamily: Some("Roboto".into()),
fontsize: Some(12_f64),
fontstyle: Some(TextStyle::Normal),
}
}
}
pub struct GaugeChartOptions {
pub labels: Option<StyleOptions>,
pub animation: AnimationOptions,
pub background: Fill,
pub gauge_background: Color,
pub colors: Vec<Fill>,
pub legend: LegendOptions,
pub title: TitleOptions,
pub tooltip: TooltipOptions,
}
impl BaseOption for GaugeChartOptions {
fn animation(&self) -> &AnimationOptions {
&self.animation
}
fn colors(&self) -> &Vec<Fill> {
&self.colors
}
fn title(&self) -> &TitleOptions {
&self.title
}
fn legend(&self) -> &LegendOptions {
&self.legend
}
fn tooltip(&self) -> &TooltipOptions {
&self.tooltip
}
fn background(&self) -> &Fill {
&self.background
}
}
impl Default for GaugeChartOptions {
fn default() -> Self {
Self {
labels: Default::default(),
animation: AnimationOptions {
duration: 800,
easing: "easeOutQuint".into(),
on_end: None,
},
background: Fill::Solid(color::WHITE),
gauge_background: color::GRAY_3,
colors: vec![
Fill::Solid(Color::rgb(0x7c, 0xb5, 0xec)),
Fill::Solid(Color::rgb(0x43, 0x43, 0x48)),
Fill::Solid(Color::rgb(0x90, 0xed, 0x7d)),
Fill::Solid(Color::rgb(0xf7, 0xa3, 0x5c)),
Fill::Solid(Color::rgb(0x80, 0x85, 0xe9)),
Fill::Solid(Color::rgb(0xf1, 0x5c, 0x80)),
Fill::Solid(Color::rgb(0xe4, 0xd3, 0x54)),
Fill::Solid(Color::rgb(0x80, 0x85, 0xe8)),
Fill::Solid(Color::rgb(0x8d, 0x46, 0x53)),
Fill::Solid(Color::rgb(0x91, 0xe8, 0xe1)),
],
legend: LegendOptions {
label_formatter: None,
position: Position::Right,
style: Default::default(),
},
title: TitleOptions {
position: Position::Above,
style: Default::default(),
text: None,
},
tooltip: TooltipOptions {
enabled: true,
label_formatter: None,
style: Default::default(),
value_formatter: None,
},
}
}
}
pub struct LineChartSeriesMarkersOptions {
pub enabled: bool,
pub fill_color: Option<Fill>,
pub line_width: usize,
pub stroke_color: Option<Fill>,
pub size: f64,
}
pub struct LineChartSeriesOptions {
pub curve_tension: f64,
pub fill_opacity: f64,
pub line_width: f64,
pub labels: Option<StyleOptions>,
pub markers: LineChartSeriesMarkersOptions,
}
pub struct LineChartXAxisLabelsOptions {
pub max_rotation: i64,
pub min_rotation: i64,
pub style: StyleOptions,
}
pub struct LineChartXAxisOptions {
pub grid_line_color: Color,
pub grid_line_width: f64,
pub line_color: Color,
pub line_width: f64,
pub labels: LineChartXAxisLabelsOptions,
pub position: Position,
pub title: TitleOption,
}
pub struct LineChartYAxisLabelsOptions {
pub formatter: Option<ValueFormatter>,
pub style: StyleOptions,
}
pub struct LineChartYAxisOptions {
pub grid_line_color: Color,
pub grid_line_width: f64,
pub line_color: Color,
pub line_width: f64,
pub interval: Option<f64>,
pub labels: LineChartYAxisLabelsOptions,
pub max_value: Option<usize>,
pub min_interval: Option<f64>,
pub min_value: Option<usize>,
pub position: Position,
pub title: TitleOption,
}
pub struct LineChartOptions {
pub channel: LineChartSeriesOptions,
pub xaxis: LineChartXAxisOptions,
pub yaxis: LineChartYAxisOptions,
pub animation: AnimationOptions,
pub background: Fill,
pub colors: Vec<Fill>,
pub legend: LegendOptions,
pub title: TitleOptions,
pub tooltip: TooltipOptions,
}
impl BaseOption for LineChartOptions {
fn animation(&self) -> &AnimationOptions {
&self.animation
}
fn colors(&self) -> &Vec<Fill> {
&self.colors
}
fn title(&self) -> &TitleOptions {
&self.title
}
fn legend(&self) -> &LegendOptions {
&self.legend
}
fn tooltip(&self) -> &TooltipOptions {
&self.tooltip
}
fn background(&self) -> &Fill {
&self.background
}
}
impl Default for LineChartOptions {
fn default() -> Self {
Self {
channel: LineChartSeriesOptions {
curve_tension: 0.4,
fill_opacity: 0.25,
line_width: 2_f64,
labels: None,
markers: LineChartSeriesMarkersOptions {
enabled: true,
fill_color: None,
line_width: 1,
stroke_color: Some(Fill::Solid(color::WHITE)),
size: 4.,
},
},
xaxis: LineChartXAxisOptions {
grid_line_color: color::GRAY_5,
grid_line_width: 1.,
line_color: color::GRAY_5,
line_width: 1.,
labels: LineChartXAxisLabelsOptions {
max_rotation: 0,
min_rotation: -90,
style: Default::default(),
},
position: Position::Bottom,
title: TitleOption {
style: Default::default(),
text: None,
},
},
yaxis: LineChartYAxisOptions {
grid_line_color: color::GRAY_5,
grid_line_width: 0.,
line_color: color::GRAY_5,
line_width: 0.,
interval: None,
labels: LineChartYAxisLabelsOptions {
formatter: None,
style: Default::default(),
},
max_value: None,
min_interval: None,
min_value: None,
position: Position::Left,
title: TitleOption {
style: Default::default(),
text: None,
},
},
animation: AnimationOptions {
duration: 800,
easing: "easeOutQuint".into(),
on_end: None,
},
background: Fill::Solid(color::WHITE),
colors: vec![
Fill::Solid(Color::rgb(0x7c, 0xb5, 0xec)),
Fill::Solid(Color::rgb(0x43, 0x43, 0x48)),
Fill::Solid(Color::rgb(0x90, 0xed, 0x7d)),
Fill::Solid(Color::rgb(0xf7, 0xa3, 0x5c)),
Fill::Solid(Color::rgb(0x80, 0x85, 0xe9)),
Fill::Solid(Color::rgb(0xf1, 0x5c, 0x80)),
Fill::Solid(Color::rgb(0xe4, 0xd3, 0x54)),
Fill::Solid(Color::rgb(0x80, 0x85, 0xe8)),
Fill::Solid(Color::rgb(0x8d, 0x46, 0x53)),
Fill::Solid(Color::rgb(0x91, 0xe8, 0xe1)),
],
legend: LegendOptions {
label_formatter: None,
position: Position::Right,
style: Default::default(),
},
title: TitleOptions {
position: Position::Above,
style: Default::default(),
text: None,
},
tooltip: TooltipOptions {
enabled: true,
label_formatter: None,
style: Default::default(),
value_formatter: None,
},
}
}
}
pub struct PieChartSeriesLabelsOptions {
pub enabled: bool,
pub formatter: Option<ValueFormatter>,
pub style: StyleOptions,
}
pub struct PieChartSeriesOptions {
pub counterclockwise: bool,
pub labels: PieChartSeriesLabelsOptions,
pub start_angle: f64,
}
pub struct PieChartOptions {
pub pie_hole: f64,
pub channel: PieChartSeriesOptions,
pub animation: AnimationOptions,
pub background: Fill,
pub colors: Vec<Fill>,
pub legend: LegendOptions,
pub title: TitleOptions,
pub tooltip: TooltipOptions,
}
impl BaseOption for PieChartOptions {
fn animation(&self) -> &AnimationOptions {
&self.animation
}
fn colors(&self) -> &Vec<Fill> {
&self.colors
}
fn title(&self) -> &TitleOptions {
&self.title
}
fn legend(&self) -> &LegendOptions {
&self.legend
}
fn tooltip(&self) -> &TooltipOptions {
&self.tooltip
}
fn background(&self) -> &Fill {
&self.background
}
}
impl Default for PieChartOptions {
fn default() -> Self {
Self {
pie_hole: 0_f64,
channel: PieChartSeriesOptions {
counterclockwise: false,
labels: PieChartSeriesLabelsOptions {
enabled: false,
formatter: None,
style: Default::default(),
},
start_angle: -90_f64,
},
animation: AnimationOptions {
duration: 800,
easing: "easeOutQuint".into(),
on_end: None,
},
background: Fill::Solid(color::WHITE),
colors: vec![
Fill::Solid(Color::rgb(0x7c, 0xb5, 0xec)),
Fill::Solid(Color::rgb(0x43, 0x43, 0x48)),
Fill::Solid(Color::rgb(0x90, 0xed, 0x7d)),
Fill::Solid(Color::rgb(0xf7, 0xa3, 0x5c)),
Fill::Solid(Color::rgb(0x80, 0x85, 0xe9)),
Fill::Solid(Color::rgb(0xf1, 0x5c, 0x80)),
Fill::Solid(Color::rgb(0xe4, 0xd3, 0x54)),
Fill::Solid(Color::rgb(0x80, 0x85, 0xe8)),
Fill::Solid(Color::rgb(0x8d, 0x46, 0x53)),
Fill::Solid(Color::rgb(0x91, 0xe8, 0xe1)),
],
legend: LegendOptions {
label_formatter: None,
position: Position::Right,
style: Default::default(),
},
title: TitleOptions {
position: Position::Above,
style: Default::default(),
text: None,
},
tooltip: TooltipOptions {
enabled: true,
label_formatter: None,
style: Default::default(),
value_formatter: None,
},
}
}
}
pub struct RadarChartSeriesMarkersOptions {
pub enabled: bool,
pub fill_color: Option<Fill>,
pub line_width: f64,
pub stroke_color: Option<Fill>,
pub size: f64,
}
pub struct RadarChartSeriesOptions {
pub fill_opacity: f64,
pub line_width: f64,
pub labels: Option<StyleOptions>,
pub markers: RadarChartSeriesMarkersOptions,
}
pub struct RadarChartXAxisLabelsOptions {
pub formatter: Option<ValueFormatter>,
pub style: StyleOptions,
}
pub struct RadarChartXAxisOptions {
pub grid_line_color: Color,
pub grid_line_width: f64,
pub labels: RadarChartXAxisLabelsOptions,
}
pub struct RadarChartYAxisLabelsOptions {
pub formatter: Option<ValueFormatter>,
pub style: StyleOptions,
}
pub struct RadarChartYAxisOptions {
pub grid_line_color: Color,
pub grid_line_width: f64,
pub interval: Option<f64>,
pub labels: RadarChartYAxisLabelsOptions,
pub min_interval: Option<f64>,
}
pub struct RadarChartOptions {
pub channel: RadarChartSeriesOptions,
pub xaxis: RadarChartXAxisOptions,
pub yaxis: RadarChartYAxisOptions,
pub animation: AnimationOptions,
pub background_color: Fill,
pub colors: Vec<Fill>,
pub legend: LegendOptions,
pub title: TitleOptions,
pub tooltip: TooltipOptions,
}
impl BaseOption for RadarChartOptions {
fn animation(&self) -> &AnimationOptions {
&self.animation
}
fn colors(&self) -> &Vec<Fill> {
&self.colors
}
fn title(&self) -> &TitleOptions {
&self.title
}
fn legend(&self) -> &LegendOptions {
&self.legend
}
fn tooltip(&self) -> &TooltipOptions {
&self.tooltip
}
fn background(&self) -> &Fill {
&self.background_color
}
}
impl Default for RadarChartOptions {
fn default() -> Self {
Self {
channel: RadarChartSeriesOptions {
fill_opacity: 0.25,
line_width: 2.,
labels: None,
markers: RadarChartSeriesMarkersOptions {
enabled: true,
fill_color: None,
line_width: 1.,
stroke_color: Some(Fill::Solid(color::WHITE)),
size: 4.,
},
},
xaxis: RadarChartXAxisOptions {
grid_line_color: color::GRAY_5,
grid_line_width: 1_f64,
labels: RadarChartXAxisLabelsOptions {
formatter: None,
style: Default::default(),
},
},
yaxis: RadarChartYAxisOptions {
grid_line_color: color::GRAY_5,
grid_line_width: 1_f64,
interval: None,
labels: RadarChartYAxisLabelsOptions {
formatter: None,
style: Default::default(),
},
min_interval: None,
},
animation: AnimationOptions {
duration: 800,
easing: "easeOutQuint".into(),
on_end: None,
},
background_color: Fill::Solid(color::WHITE),
colors: vec![
Fill::Solid(Color::rgb(0x7c, 0xb5, 0xec)),
Fill::Solid(Color::rgb(0x43, 0x43, 0x48)),
Fill::Solid(Color::rgb(0x90, 0xed, 0x7d)),
Fill::Solid(Color::rgb(0xf7, 0xa3, 0x5c)),
Fill::Solid(Color::rgb(0x80, 0x85, 0xe9)),
Fill::Solid(Color::rgb(0xf1, 0x5c, 0x80)),
Fill::Solid(Color::rgb(0xe4, 0xd3, 0x54)),
Fill::Solid(Color::rgb(0x80, 0x85, 0xe8)),
Fill::Solid(Color::rgb(0x8d, 0x46, 0x53)),
Fill::Solid(Color::rgb(0x91, 0xe8, 0xe1)),
],
legend: LegendOptions {
label_formatter: None,
position: Position::Right,
style: Default::default(),
},
title: TitleOptions {
position: Position::Above,
style: Default::default(),
text: None,
},
tooltip: TooltipOptions {
enabled: true,
label_formatter: None,
style: Default::default(),
value_formatter: None,
},
}
}
}