charming_fork_zephyr/series/
line.rs1use serde::Serialize;
2
3use crate::{
4 datatype::{DataFrame, DataPoint},
5 element::{
6 AreaStyle, CoordinateSystem, DimensionEncode, Emphasis, ItemStyle, Label, LineStyle,
7 MarkArea, MarkLine, MarkPoint, Symbol,
8 },
9};
10
11#[derive(Serialize)]
12#[serde(rename_all = "camelCase")]
13pub struct Line {
14 #[serde(rename = "type")]
15 type_: String,
16
17 #[serde(skip_serializing_if = "Option::is_none")]
18 id: Option<String>,
19
20 #[serde(skip_serializing_if = "Option::is_none")]
21 name: Option<String>,
22
23 #[serde(skip_serializing_if = "Option::is_none")]
24 coordinate_system: Option<CoordinateSystem>,
25
26 #[serde(skip_serializing_if = "Option::is_none")]
27 symbol: Option<Symbol>,
28
29 #[serde(skip_serializing_if = "Option::is_none")]
30 symbol_size: Option<i64>,
31
32 #[serde(skip_serializing_if = "Option::is_none")]
33 show_symbol: Option<bool>,
34
35 #[serde(skip_serializing_if = "Option::is_none")]
36 stack: Option<String>,
37
38 #[serde(skip_serializing_if = "Option::is_none")]
39 label: Option<Label>,
40
41 #[serde(skip_serializing_if = "Option::is_none")]
42 line_style: Option<LineStyle>,
43
44 #[serde(skip_serializing_if = "Option::is_none")]
45 area_style: Option<AreaStyle>,
46
47 #[serde(skip_serializing_if = "Option::is_none")]
48 item_style: Option<ItemStyle>,
49
50 #[serde(skip_serializing_if = "Option::is_none")]
51 emphasis: Option<Emphasis>,
52
53 #[serde(skip_serializing_if = "Option::is_none")]
54 smooth: Option<i64>,
55
56 #[serde(skip_serializing_if = "Option::is_none")]
57 mark_point: Option<MarkPoint>,
58
59 #[serde(skip_serializing_if = "Option::is_none")]
60 mark_line: Option<MarkLine>,
61
62 #[serde(skip_serializing_if = "Option::is_none")]
63 mark_area: Option<MarkArea>,
64
65 #[serde(skip_serializing_if = "Option::is_none")]
66 dataset_id: Option<String>,
67
68 #[serde(skip_serializing_if = "Option::is_none")]
69 encode: Option<DimensionEncode>,
70
71 #[serde(skip_serializing_if = "Option::is_none")]
72 x_axis_index: Option<i64>,
73
74 #[serde(skip_serializing_if = "Option::is_none")]
75 y_axis_index: Option<i64>,
76
77 #[serde(skip_serializing_if = "Vec::is_empty")]
78 data: DataFrame,
79}
80
81impl Line {
82 pub fn new() -> Self {
83 Self {
84 type_: "line".to_string(),
85 id: None,
86 name: None,
87 coordinate_system: None,
88 symbol: None,
89 symbol_size: None,
90 show_symbol: None,
91 stack: None,
92 label: None,
93 line_style: None,
94 area_style: None,
95 item_style: None,
96 emphasis: None,
97 smooth: None,
98 mark_point: None,
99 mark_line: None,
100 mark_area: None,
101 dataset_id: None,
102 encode: None,
103 x_axis_index: None,
104 y_axis_index: None,
105 data: vec![],
106 }
107 }
108
109 pub fn id<S: Into<String>>(mut self, id: S) -> Self {
110 self.id = Some(id.into());
111 self
112 }
113
114 pub fn name<S: Into<String>>(mut self, name: S) -> Self {
116 self.name = Some(name.into());
117 self
118 }
119
120 pub fn coordinate_system<C: Into<CoordinateSystem>>(mut self, coordinate_system: C) -> Self {
121 self.coordinate_system = Some(coordinate_system.into());
122 self
123 }
124
125 pub fn symbol<S: Into<Symbol>>(mut self, symbol: S) -> Self {
126 self.symbol = Some(symbol.into());
127 self
128 }
129
130 pub fn symbol_size<F: Into<i64>>(mut self, symbol_size: F) -> Self {
131 self.symbol_size = Some(symbol_size.into());
132 self
133 }
134
135 pub fn show_symbol(mut self, show_symbol: bool) -> Self {
136 self.show_symbol = Some(show_symbol);
137 self
138 }
139
140 pub fn stack<S: Into<String>>(mut self, stack: S) -> Self {
141 self.stack = Some(stack.into());
142 self
143 }
144
145 pub fn label<L: Into<Label>>(mut self, label: L) -> Self {
146 self.label = Some(label.into());
147 self
148 }
149
150 pub fn line_style<L: Into<LineStyle>>(mut self, line_style: L) -> Self {
151 self.line_style = Some(line_style.into());
152 self
153 }
154
155 pub fn area_style<A: Into<AreaStyle>>(mut self, area_style: A) -> Self {
156 self.area_style = Some(area_style.into());
157 self
158 }
159
160 pub fn item_style<I: Into<ItemStyle>>(mut self, item_style: I) -> Self {
161 self.item_style = Some(item_style.into());
162 self
163 }
164
165 pub fn emphasis<E: Into<Emphasis>>(mut self, emphasis: E) -> Self {
166 self.emphasis = Some(emphasis.into());
167 self
168 }
169
170 pub fn smooth<F: Into<i64>>(mut self, smooth: F) -> Self {
172 self.smooth = Some(smooth.into());
173 self
174 }
175
176 pub fn mark_point<M: Into<MarkPoint>>(mut self, mark_point: M) -> Self {
177 self.mark_point = Some(mark_point.into());
178 self
179 }
180
181 pub fn mark_line<M: Into<MarkLine>>(mut self, mark_line: M) -> Self {
182 self.mark_line = Some(mark_line.into());
183 self
184 }
185
186 pub fn mark_area<M: Into<MarkArea>>(mut self, mark_area: M) -> Self {
187 self.mark_area = Some(mark_area.into());
188 self
189 }
190
191 pub fn dataset_id<S: Into<String>>(mut self, dataset_id: S) -> Self {
192 self.dataset_id = Some(dataset_id.into());
193 self
194 }
195
196 pub fn encode<E: Into<DimensionEncode>>(mut self, encode: E) -> Self {
197 self.encode = Some(encode.into());
198 self
199 }
200
201 pub fn x_axis_index<F: Into<i64>>(mut self, x_axis_index: F) -> Self {
202 self.x_axis_index = Some(x_axis_index.into());
203 self
204 }
205
206 pub fn y_axis_index<F: Into<i64>>(mut self, y_axis_index: F) -> Self {
207 self.y_axis_index = Some(y_axis_index.into());
208 self
209 }
210
211 pub fn data<D: Into<DataPoint>>(mut self, data: Vec<D>) -> Self {
212 self.data = data.into_iter().map(|d| d.into()).collect();
213 self
214 }
215}