charming_fork_zephyr/series/
effect_scatter.rs1use serde::Serialize;
2
3use crate::{
4 datatype::{DataFrame, DataPoint},
5 element::{
6 Color, ColorBy, CoordinateSystem, Emphasis, ItemStyle, Label, LabelLayout, LabelLine,
7 Symbol,
8 },
9};
10
11#[derive(Serialize)]
12#[serde(rename_all = "snake_case")]
13pub enum EffectType {
14 Ripple,
15}
16
17#[derive(Serialize)]
18#[serde(rename_all = "snake_case")]
19pub enum ShowEffectOn {
20 Render,
21 Emphasis,
22}
23
24#[derive(Serialize)]
25#[serde(rename_all = "snake_case")]
26pub enum RippleEffectBrushType {
27 Fill,
28 Stroke,
29}
30
31#[derive(Serialize)]
32#[serde(rename_all = "camelCase")]
33pub struct RippleEffect {
34 #[serde(skip_serializing_if = "Option::is_none")]
35 color: Option<Color>,
36
37 #[serde(skip_serializing_if = "Option::is_none")]
38 number: Option<i64>,
39
40 #[serde(skip_serializing_if = "Option::is_none")]
41 period: Option<i64>,
42
43 #[serde(skip_serializing_if = "Option::is_none")]
44 scale: Option<i64>,
45
46 #[serde(skip_serializing_if = "Option::is_none")]
47 brush_type: Option<RippleEffectBrushType>,
48}
49
50impl RippleEffect {
51 pub fn new() -> Self {
52 Self {
53 color: None,
54 number: None,
55 period: None,
56 scale: None,
57 brush_type: None,
58 }
59 }
60
61 pub fn color<C: Into<Color>>(mut self, color: C) -> Self {
62 self.color = Some(color.into());
63 self
64 }
65
66 pub fn number<F: Into<i64>>(mut self, number: F) -> Self {
67 self.number = Some(number.into());
68 self
69 }
70
71 pub fn period<F: Into<i64>>(mut self, period: F) -> Self {
72 self.period = Some(period.into());
73 self
74 }
75
76 pub fn scale<F: Into<i64>>(mut self, scale: F) -> Self {
77 self.scale = Some(scale.into());
78 self
79 }
80
81 pub fn brush_type<B: Into<RippleEffectBrushType>>(mut self, brush_type: B) -> Self {
82 self.brush_type = Some(brush_type.into());
83 self
84 }
85}
86
87#[derive(Serialize)]
88#[serde(rename_all = "camelCase")]
89pub struct EffectScatter {
90 #[serde(rename = "type")]
91 type_: String,
92
93 #[serde(skip_serializing_if = "Option::is_none")]
94 id: Option<String>,
95
96 #[serde(skip_serializing_if = "Option::is_none")]
97 name: Option<String>,
98
99 #[serde(skip_serializing_if = "Option::is_none")]
100 color_by: Option<ColorBy>,
101
102 #[serde(skip_serializing_if = "Option::is_none")]
103 legend_hover_link: Option<bool>,
104
105 #[serde(skip_serializing_if = "Option::is_none")]
106 effect_type: Option<EffectType>,
107
108 #[serde(skip_serializing_if = "Option::is_none")]
109 show_effect_on: Option<ShowEffectOn>,
110
111 #[serde(skip_serializing_if = "Option::is_none")]
112 coordinate_system: Option<CoordinateSystem>,
113
114 #[serde(skip_serializing_if = "Option::is_none")]
115 x_axis_index: Option<i64>,
116
117 #[serde(skip_serializing_if = "Option::is_none")]
118 y_axis_index: Option<i64>,
119
120 #[serde(skip_serializing_if = "Option::is_none")]
121 polar_index: Option<i64>,
122
123 #[serde(skip_serializing_if = "Option::is_none")]
124 geo_index: Option<i64>,
125
126 #[serde(skip_serializing_if = "Option::is_none")]
127 calendar_index: Option<i64>,
128
129 #[serde(skip_serializing_if = "Option::is_none")]
130 symbol: Option<Symbol>,
131
132 #[serde(skip_serializing_if = "Option::is_none")]
133 symbol_size: Option<i64>,
134
135 #[serde(skip_serializing_if = "Option::is_none")]
136 symbol_rotate: Option<i64>,
137
138 #[serde(skip_serializing_if = "Option::is_none")]
139 symbol_keep_aspect: Option<bool>,
140
141 #[serde(skip_serializing_if = "Option::is_none")]
142 symbol_offset: Option<(String, String)>,
143
144 #[serde(skip_serializing_if = "Option::is_none")]
145 label: Option<Label>,
146
147 #[serde(skip_serializing_if = "Option::is_none")]
148 label_line: Option<LabelLine>,
149
150 #[serde(skip_serializing_if = "Option::is_none")]
151 label_layout: Option<LabelLayout>,
152
153 #[serde(skip_serializing_if = "Option::is_none")]
154 item_style: Option<ItemStyle>,
155
156 #[serde(skip_serializing_if = "Option::is_none")]
157 emphasis: Option<Emphasis>,
158
159 #[serde(skip_serializing_if = "Vec::is_empty")]
160 data: DataFrame,
161}
162
163impl EffectScatter {
164 pub fn new() -> Self {
165 Self {
166 type_: "effectScatter".to_string(),
167 id: None,
168 name: None,
169 color_by: None,
170 legend_hover_link: None,
171 effect_type: None,
172 show_effect_on: None,
173 coordinate_system: None,
174 x_axis_index: None,
175 y_axis_index: None,
176 polar_index: None,
177 geo_index: None,
178 calendar_index: None,
179 symbol: None,
180 symbol_size: None,
181 symbol_rotate: None,
182 symbol_keep_aspect: None,
183 symbol_offset: None,
184 label: None,
185 label_line: None,
186 label_layout: None,
187 item_style: None,
188 emphasis: None,
189 data: vec![],
190 }
191 }
192
193 pub fn id<S: Into<String>>(mut self, id: S) -> Self {
194 self.id = Some(id.into());
195 self
196 }
197
198 pub fn name<S: Into<String>>(mut self, name: S) -> Self {
199 self.name = Some(name.into());
200 self
201 }
202
203 pub fn color_by<C: Into<ColorBy>>(mut self, color_by: C) -> Self {
204 self.color_by = Some(color_by.into());
205 self
206 }
207
208 pub fn legend_hover_link(mut self, legend_hover_link: bool) -> Self {
209 self.legend_hover_link = Some(legend_hover_link);
210 self
211 }
212
213 pub fn effect_type<E: Into<EffectType>>(mut self, effect_type: E) -> Self {
214 self.effect_type = Some(effect_type.into());
215 self
216 }
217
218 pub fn show_effect_on<S: Into<ShowEffectOn>>(mut self, show_effect_on: S) -> Self {
219 self.show_effect_on = Some(show_effect_on.into());
220 self
221 }
222
223 pub fn coordinate_system<C: Into<CoordinateSystem>>(mut self, coordinate_system: C) -> Self {
224 self.coordinate_system = Some(coordinate_system.into());
225 self
226 }
227
228 pub fn x_axis_index<F: Into<i64>>(mut self, x_axis_index: F) -> Self {
229 self.x_axis_index = Some(x_axis_index.into());
230 self
231 }
232
233 pub fn y_axis_index<F: Into<i64>>(mut self, y_axis_index: F) -> Self {
234 self.y_axis_index = Some(y_axis_index.into());
235 self
236 }
237
238 pub fn polar_index<F: Into<i64>>(mut self, polar_index: F) -> Self {
239 self.polar_index = Some(polar_index.into());
240 self
241 }
242
243 pub fn geo_index<F: Into<i64>>(mut self, geo_index: F) -> Self {
244 self.geo_index = Some(geo_index.into());
245 self
246 }
247
248 pub fn calendar_index<F: Into<i64>>(mut self, calendar_index: F) -> Self {
249 self.calendar_index = Some(calendar_index.into());
250 self
251 }
252
253 pub fn symbol<S: Into<Symbol>>(mut self, symbol: S) -> Self {
254 self.symbol = Some(symbol.into());
255 self
256 }
257
258 pub fn symbol_size<F: Into<i64>>(mut self, symbol_size: F) -> Self {
259 self.symbol_size = Some(symbol_size.into());
260 self
261 }
262
263 pub fn symbol_rotate<F: Into<i64>>(mut self, symbol_rotate: F) -> Self {
264 self.symbol_rotate = Some(symbol_rotate.into());
265 self
266 }
267
268 pub fn symbol_keep_aspect(mut self, symbol_keep_aspect: bool) -> Self {
269 self.symbol_keep_aspect = Some(symbol_keep_aspect);
270 self
271 }
272
273 pub fn symbol_offset<S: Into<String>>(mut self, symbol_offset: (S, S)) -> Self {
274 self.symbol_offset = Some((symbol_offset.0.into(), symbol_offset.1.into()));
275 self
276 }
277
278 pub fn label<L: Into<Label>>(mut self, label: L) -> Self {
279 self.label = Some(label.into());
280 self
281 }
282
283 pub fn label_line<L: Into<LabelLine>>(mut self, label_line: L) -> Self {
284 self.label_line = Some(label_line.into());
285 self
286 }
287
288 pub fn label_layout<L: Into<LabelLayout>>(mut self, label_layout: L) -> Self {
289 self.label_layout = Some(label_layout.into());
290 self
291 }
292
293 pub fn item_style<I: Into<ItemStyle>>(mut self, item_style: I) -> Self {
294 self.item_style = Some(item_style.into());
295 self
296 }
297
298 pub fn emphasis<E: Into<Emphasis>>(mut self, emphasis: E) -> Self {
299 self.emphasis = Some(emphasis.into());
300 self
301 }
302
303 pub fn data<D: Into<DataPoint>>(mut self, data: Vec<D>) -> Self {
304 self.data = data.into_iter().map(|d| d.into()).collect();
305 self
306 }
307}