charming_fork_zephyr/series/
parallel.rs

1use serde::Serialize;
2
3use crate::{
4    datatype::{DataFrame, DataPoint},
5    element::{ColorBy, CoordinateSystem, Emphasis, LineStyle},
6};
7
8#[derive(Serialize)]
9#[serde(rename_all = "snake_case")]
10pub enum ProgressiveChunkMode {
11    Sequential,
12    Mod,
13}
14
15#[derive(Serialize)]
16#[serde(rename_all = "camelCase")]
17pub struct Parallel {
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    coordinate_system: Option<CoordinateSystem>,
26
27    #[serde(skip_serializing_if = "Option::is_none")]
28    parallel_index: Option<i64>,
29
30    #[serde(skip_serializing_if = "Option::is_none")]
31    name: Option<String>,
32
33    #[serde(skip_serializing_if = "Option::is_none")]
34    color_by: Option<ColorBy>,
35
36    #[serde(skip_serializing_if = "Option::is_none")]
37    line_style: Option<LineStyle>,
38
39    #[serde(skip_serializing_if = "Option::is_none")]
40    emphasis: Option<Emphasis>,
41
42    #[serde(skip_serializing_if = "Option::is_none")]
43    inactive_opacity: Option<i64>,
44
45    #[serde(skip_serializing_if = "Option::is_none")]
46    active_opacity: Option<i64>,
47
48    #[serde(skip_serializing_if = "Option::is_none")]
49    realtime: Option<bool>,
50
51    #[serde(skip_serializing_if = "Option::is_none")]
52    smooth: Option<i64>,
53
54    #[serde(skip_serializing_if = "Option::is_none")]
55    progressive: Option<i64>,
56
57    #[serde(skip_serializing_if = "Option::is_none")]
58    progressive_threshold: Option<i64>,
59
60    #[serde(skip_serializing_if = "Option::is_none")]
61    progressive_chunk_mode: Option<ProgressiveChunkMode>,
62
63    #[serde(skip_serializing_if = "Vec::is_empty")]
64    data: DataFrame,
65}
66
67impl Parallel {
68    pub fn new() -> Self {
69        Self {
70            type_: "parallel".to_string(),
71            id: None,
72            coordinate_system: None,
73            parallel_index: None,
74            name: None,
75            color_by: None,
76            line_style: None,
77            emphasis: None,
78            inactive_opacity: None,
79            active_opacity: None,
80            realtime: None,
81            smooth: None,
82            progressive: None,
83            progressive_threshold: None,
84            progressive_chunk_mode: None,
85            data: vec![],
86        }
87    }
88
89    pub fn id<S: Into<String>>(mut self, id: S) -> Self {
90        self.id = Some(id.into());
91        self
92    }
93
94    pub fn coordinate_system<C: Into<CoordinateSystem>>(mut self, coordinate_system: C) -> Self {
95        self.coordinate_system = Some(coordinate_system.into());
96        self
97    }
98
99    pub fn parallel_index<F: Into<i64>>(mut self, parallel_index: F) -> Self {
100        self.parallel_index = Some(parallel_index.into());
101        self
102    }
103
104    pub fn name<S: Into<String>>(mut self, name: S) -> Self {
105        self.name = Some(name.into());
106        self
107    }
108
109    pub fn color_by<C: Into<ColorBy>>(mut self, color_by: C) -> Self {
110        self.color_by = Some(color_by.into());
111        self
112    }
113
114    pub fn line_style<S: Into<LineStyle>>(mut self, line_style: S) -> Self {
115        self.line_style = Some(line_style.into());
116        self
117    }
118
119    pub fn emphasis<E: Into<Emphasis>>(mut self, emphasis: E) -> Self {
120        self.emphasis = Some(emphasis.into());
121        self
122    }
123
124    pub fn inactive_opacity<F: Into<i64>>(mut self, inactive_opacity: F) -> Self {
125        self.inactive_opacity = Some(inactive_opacity.into());
126        self
127    }
128
129    pub fn active_opacity<F: Into<i64>>(mut self, active_opacity: F) -> Self {
130        self.active_opacity = Some(active_opacity.into());
131        self
132    }
133
134    pub fn realtime(mut self, realtime: bool) -> Self {
135        self.realtime = Some(realtime);
136        self
137    }
138
139    pub fn smooth<F: Into<i64>>(mut self, smooth: F) -> Self {
140        self.smooth = Some(smooth.into());
141        self
142    }
143
144    pub fn progressive<F: Into<i64>>(mut self, progressive: F) -> Self {
145        self.progressive = Some(progressive.into());
146        self
147    }
148
149    pub fn progressive_threshold<F: Into<i64>>(mut self, progressive_threshold: F) -> Self {
150        self.progressive_threshold = Some(progressive_threshold.into());
151        self
152    }
153
154    pub fn progressive_chunk_mode<P: Into<ProgressiveChunkMode>>(
155        mut self,
156        progressive_chunk_mode: P,
157    ) -> Self {
158        self.progressive_chunk_mode = Some(progressive_chunk_mode.into());
159        self
160    }
161
162    pub fn data<D: Into<DataPoint>>(mut self, data: Vec<D>) -> Self {
163        self.data = data.into_iter().map(|d| d.into()).collect();
164        self
165    }
166}