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