charming_fork_zephyr/series/
custom.rs1use serde::Serialize;
2
3use crate::{
4 datatype::{CompositeValue, DataFrame, DataPoint, Dimension},
5 element::{
6 ColorBy, CoordinateSystem, DimensionEncode, ItemStyle, LabelLayout, LabelLine, RawString,
7 },
8};
9
10#[derive(Serialize)]
11#[serde(rename_all = "camelCase")]
12pub struct Custom {
13 type_: String,
14
15 #[serde(skip_serializing_if = "Option::is_none")]
16 id: Option<String>,
17
18 #[serde(skip_serializing_if = "Option::is_none")]
19 name: Option<String>,
20
21 #[serde(skip_serializing_if = "Option::is_none")]
22 color_by: Option<ColorBy>,
23
24 #[serde(skip_serializing_if = "Option::is_none")]
25 legend_hover_link: Option<bool>,
26
27 #[serde(skip_serializing_if = "Option::is_none")]
28 coordinate_system: Option<CoordinateSystem>,
29
30 #[serde(skip_serializing_if = "Option::is_none")]
31 x_axis_index: Option<CompositeValue>,
32
33 #[serde(skip_serializing_if = "Option::is_none")]
34 y_axis_index: Option<CompositeValue>,
35
36 #[serde(skip_serializing_if = "Option::is_none")]
37 polar_index: Option<CompositeValue>,
38
39 #[serde(skip_serializing_if = "Option::is_none")]
40 geo_index: Option<CompositeValue>,
41
42 #[serde(skip_serializing_if = "Option::is_none")]
43 calendar_index: Option<CompositeValue>,
44
45 #[serde(skip_serializing_if = "Option::is_none")]
46 render_item: Option<RawString>,
47
48 #[serde(skip_serializing_if = "Option::is_none")]
49 item_style: Option<ItemStyle>,
50
51 #[serde(skip_serializing_if = "Option::is_none")]
52 label_line: Option<LabelLine>,
53
54 #[serde(skip_serializing_if = "Option::is_none")]
55 label_layout: Option<LabelLayout>,
56
57 #[serde(skip_serializing_if = "Option::is_none")]
58 selected_mode: Option<bool>,
59
60 #[serde(skip_serializing_if = "Vec::is_empty")]
61 dimensions: Vec<Dimension>,
62
63 #[serde(skip_serializing_if = "Option::is_none")]
64 encode: Option<DimensionEncode>,
65
66 #[serde(skip_serializing_if = "Vec::is_empty")]
67 data: DataFrame,
68}
69
70impl Custom {
71 pub fn new() -> Self {
72 Self {
73 type_: "custom".to_string(),
74 id: None,
75 name: None,
76 color_by: None,
77 legend_hover_link: None,
78 coordinate_system: None,
79 x_axis_index: None,
80 y_axis_index: None,
81 polar_index: None,
82 geo_index: None,
83 calendar_index: None,
84 render_item: None,
85 item_style: None,
86 label_line: None,
87 label_layout: None,
88 selected_mode: None,
89 dimensions: vec![],
90 encode: None,
91 data: vec![],
92 }
93 }
94
95 pub fn id<S: Into<String>>(mut self, id: S) -> Self {
96 self.id = Some(id.into());
97 self
98 }
99
100 pub fn name<S: Into<String>>(mut self, name: S) -> Self {
101 self.name = Some(name.into());
102 self
103 }
104
105 pub fn color_by<C: Into<ColorBy>>(mut self, color_by: C) -> Self {
106 self.color_by = Some(color_by.into());
107 self
108 }
109
110 pub fn legend_hover_link(mut self, legend_hover_link: bool) -> Self {
111 self.legend_hover_link = Some(legend_hover_link);
112 self
113 }
114
115 pub fn coordinate_system<C: Into<CoordinateSystem>>(mut self, coordinate_system: C) -> Self {
116 self.coordinate_system = Some(coordinate_system.into());
117 self
118 }
119
120 pub fn x_axis_index<C: Into<CompositeValue>>(mut self, x_axis_index: C) -> Self {
121 self.x_axis_index = Some(x_axis_index.into());
122 self
123 }
124
125 pub fn y_axis_index<C: Into<CompositeValue>>(mut self, y_axis_index: C) -> Self {
126 self.y_axis_index = Some(y_axis_index.into());
127 self
128 }
129
130 pub fn polar_index<C: Into<CompositeValue>>(mut self, polar_index: C) -> Self {
131 self.polar_index = Some(polar_index.into());
132 self
133 }
134
135 pub fn geo_index<C: Into<CompositeValue>>(mut self, geo_index: C) -> Self {
136 self.geo_index = Some(geo_index.into());
137 self
138 }
139
140 pub fn calendar_index<C: Into<CompositeValue>>(mut self, calendar_index: C) -> Self {
141 self.calendar_index = Some(calendar_index.into());
142 self
143 }
144
145 pub fn render_item<R: Into<RawString>>(mut self, render_item: R) -> Self {
146 self.render_item = Some(render_item.into());
147 self
148 }
149
150 pub fn item_style<I: Into<ItemStyle>>(mut self, item_style: I) -> Self {
151 self.item_style = Some(item_style.into());
152 self
153 }
154
155 pub fn label_line<L: Into<LabelLine>>(mut self, label_line: L) -> Self {
156 self.label_line = Some(label_line.into());
157 self
158 }
159
160 pub fn label_layout<L: Into<LabelLayout>>(mut self, label_layout: L) -> Self {
161 self.label_layout = Some(label_layout.into());
162 self
163 }
164
165 pub fn selected_mode(mut self, selected_mode: bool) -> Self {
166 self.selected_mode = Some(selected_mode);
167 self
168 }
169
170 pub fn dimensions<D: Into<Dimension>>(mut self, dimensions: Vec<D>) -> Self {
171 self.dimensions = dimensions.into_iter().map(|d| d.into()).collect();
172 self
173 }
174
175 pub fn encode<E: Into<DimensionEncode>>(mut self, encode: E) -> Self {
176 self.encode = Some(encode.into());
177 self
178 }
179
180 pub fn data<D: Into<DataPoint>>(mut self, data: Vec<D>) -> Self {
181 self.data = data.into_iter().map(|d| d.into()).collect();
182 self
183 }
184}