charming_fork_zephyr/series/
pie.rs1use serde::Serialize;
2
3use crate::{
4 datatype::{CompositeValue, DataFrame, DataPoint},
5 element::{ColorBy, CoordinateSystem, Emphasis, ItemStyle, Label, LabelLine},
6};
7
8#[derive(Serialize)]
9#[serde(rename_all = "snake_case")]
10pub enum PieRoseType {
11 Radius,
12 Area,
13}
14
15#[derive(Serialize)]
16#[serde(rename_all = "camelCase")]
17pub struct Pie {
18 #[serde(rename = "type")]
19 type_: String,
20
21 #[serde(skip_serializing_if = "Option::is_none")]
22 id: Option<String>,
23
24 #[serde(skip_serializing_if = "Option::is_none")]
25 name: Option<String>,
26
27 #[serde(skip_serializing_if = "Option::is_none")]
28 color_by: Option<ColorBy>,
29
30 #[serde(skip_serializing_if = "Option::is_none")]
31 legend_hover_link: Option<bool>,
32
33 #[serde(skip_serializing_if = "Option::is_none")]
34 coordiate_system: Option<CoordinateSystem>,
35
36 #[serde(skip_serializing_if = "Option::is_none")]
37 geo_index: Option<i64>,
38
39 #[serde(skip_serializing_if = "Option::is_none")]
40 calendar_index: Option<i64>,
41
42 #[serde(skip_serializing_if = "Option::is_none")]
43 selected_mode: Option<bool>,
44
45 #[serde(skip_serializing_if = "Option::is_none")]
46 selected_offset: Option<i64>,
47
48 #[serde(skip_serializing_if = "Option::is_none")]
49 clockwise: Option<bool>,
50
51 #[serde(skip_serializing_if = "Option::is_none")]
52 avoid_label_overlap: Option<bool>,
53
54 #[serde(skip_serializing_if = "Option::is_none")]
55 start_angle: Option<i64>,
56
57 #[serde(skip_serializing_if = "Option::is_none")]
58 rose_type: Option<PieRoseType>,
59
60 #[serde(skip_serializing_if = "Option::is_none")]
61 label: Option<Label>,
62
63 #[serde(skip_serializing_if = "Option::is_none")]
64 label_line: Option<LabelLine>,
65
66 #[serde(skip_serializing_if = "Option::is_none")]
67 item_style: Option<ItemStyle>,
68
69 #[serde(skip_serializing_if = "Option::is_none")]
70 emphasis: Option<Emphasis>,
71
72 #[serde(skip_serializing_if = "Option::is_none")]
73 center: Option<CompositeValue>,
74
75 #[serde(skip_serializing_if = "Option::is_none")]
76 radius: Option<CompositeValue>,
77
78 #[serde(skip_serializing_if = "Vec::is_empty")]
79 data: DataFrame,
80}
81
82impl Pie {
83 pub fn new() -> Self {
84 Pie {
85 type_: "pie".to_string(),
86 id: None,
87 name: None,
88 color_by: None,
89 legend_hover_link: None,
90 coordiate_system: None,
91 geo_index: None,
92 calendar_index: None,
93 selected_mode: None,
94 selected_offset: None,
95 clockwise: None,
96 avoid_label_overlap: None,
97 start_angle: None,
98 rose_type: None,
99 label: None,
100 label_line: None,
101 item_style: None,
102 emphasis: None,
103 center: None,
104 radius: 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 {
115 self.name = Some(name.into());
116 self
117 }
118
119 pub fn color_by<C: Into<ColorBy>>(mut self, color_by: C) -> Self {
120 self.color_by = Some(color_by.into());
121 self
122 }
123
124 pub fn legend_hover_link(mut self, legend_hover_link: bool) -> Self {
125 self.legend_hover_link = Some(legend_hover_link);
126 self
127 }
128
129 pub fn coordiate_system<C: Into<CoordinateSystem>>(mut self, coordiate_system: C) -> Self {
130 self.coordiate_system = Some(coordiate_system.into());
131 self
132 }
133
134 pub fn geo_index<F: Into<i64>>(mut self, geo_index: F) -> Self {
135 self.geo_index = Some(geo_index.into());
136 self
137 }
138
139 pub fn calendar_index<F: Into<i64>>(mut self, calendar_index: F) -> Self {
140 self.calendar_index = Some(calendar_index.into());
141 self
142 }
143
144 pub fn selected_mode(mut self, selected_mode: bool) -> Self {
145 self.selected_mode = Some(selected_mode);
146 self
147 }
148
149 pub fn selected_offset<F: Into<i64>>(mut self, selected_offset: F) -> Self {
150 self.selected_offset = Some(selected_offset.into());
151 self
152 }
153
154 pub fn clockwise(mut self, clockwise: bool) -> Self {
155 self.clockwise = Some(clockwise);
156 self
157 }
158
159 pub fn avoid_label_overlap(mut self, avoid_label_overlap: bool) -> Self {
160 self.avoid_label_overlap = Some(avoid_label_overlap);
161 self
162 }
163
164 pub fn start_angle<F: Into<i64>>(mut self, start_angle: F) -> Self {
165 self.start_angle = Some(start_angle.into());
166 self
167 }
168
169 pub fn rose_type<P: Into<PieRoseType>>(mut self, rose_type: P) -> Self {
170 self.rose_type = Some(rose_type.into());
171 self
172 }
173
174 pub fn label<L: Into<Label>>(mut self, label: L) -> Self {
175 self.label = Some(label.into());
176 self
177 }
178
179 pub fn label_line<L: Into<LabelLine>>(mut self, label_line: L) -> Self {
180 self.label_line = Some(label_line.into());
181 self
182 }
183
184 pub fn item_style<I: Into<ItemStyle>>(mut self, item_style: I) -> Self {
185 self.item_style = Some(item_style.into());
186 self
187 }
188
189 pub fn emphasis<E: Into<Emphasis>>(mut self, emphasis: E) -> Self {
190 self.emphasis = Some(emphasis.into());
191 self
192 }
193
194 pub fn center<C: Into<CompositeValue>>(mut self, center: C) -> Self {
195 self.center = Some(center.into());
196 self
197 }
198
199 pub fn radius<C: Into<CompositeValue>>(mut self, radius: C) -> Self {
200 self.radius = Some(radius.into());
201 self
202 }
203
204 pub fn data<D: Into<DataPoint>>(mut self, data: Vec<D>) -> Self {
205 self.data = data.into_iter().map(|d| d.into()).collect();
206 self
207 }
208}