1use super::{Box, Color};
14use crate::Point;
15use serde::{Deserialize, Serialize};
16
17#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
18pub enum Position {
19 #[default]
20 Left,
21 Top,
22 Right,
23 Bottom,
24 Inside,
25}
26
27#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Default)]
28pub enum Align {
29 Left,
30 #[default]
31 Center,
32 Right,
33}
34
35#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
36pub enum Symbol {
37 None,
38 Circle(f32, Option<Color>),
39}
40
41#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
42pub enum SeriesCategory {
43 Line,
44 Bar,
45}
46
47#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Default)]
48pub enum MarkLineCategory {
49 #[default]
50 Average,
51 Min,
52 Max,
53}
54
55#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Default)]
56pub enum MarkPointCategory {
57 #[default]
58 Min,
59 Max,
60}
61
62#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Default)]
63pub struct MarkLine {
64 pub category: MarkLineCategory,
65}
66
67#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Default)]
68pub struct MarkPoint {
69 pub category: MarkPointCategory,
70}
71
72#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Default)]
73pub struct Series {
74 pub name: String,
76 pub data: Vec<f32>,
78 pub start_index: usize,
80 pub index: Option<usize>,
82 pub y_axis_index: usize,
84 pub label_show: bool,
86 pub mark_lines: Vec<MarkLine>,
88 pub mark_points: Vec<MarkPoint>,
90 pub colors: Option<Vec<Option<Color>>>,
92 pub category: Option<SeriesCategory>,
94 pub stroke_dash_array: Option<String>,
96}
97
98#[derive(Clone, PartialEq, Debug, Default)]
99pub struct SeriesLabel {
100 pub point: Point,
101 pub text: String,
102}
103
104impl Series {
105 pub fn new(name: String, data: Vec<f32>) -> Self {
106 Series {
107 name,
108 data,
109 index: None,
110 ..Default::default()
111 }
112 }
113}
114impl From<(&str, Vec<f32>)> for Series {
115 fn from(value: (&str, Vec<f32>)) -> Self {
116 Series::new(value.0.to_string(), value.1)
117 }
118}
119
120#[derive(Serialize, Deserialize, Clone, Debug, Default)]
121pub struct YAxisConfig {
122 pub axis_font_size: f32,
123 pub axis_font_color: Color,
124 pub axis_font_weight: Option<String>,
125 pub axis_stroke_color: Color,
126 pub axis_width: Option<f32>,
127 pub axis_split_number: usize,
128 pub axis_name_gap: f32,
129 pub axis_name_align: Option<Align>,
130 pub axis_margin: Option<Box>,
131 pub axis_formatter: Option<String>,
132 pub axis_min: Option<f32>,
133 pub axis_max: Option<f32>,
134}