charming_fork_zephyr/series/
candlestick.rs

1use serde::Serialize;
2
3use crate::{
4    datatype::{DataFrame, DataPoint},
5    element::{ColorBy, CoordinateSystem},
6};
7
8#[derive(Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Candlestick {
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    coordiate_system: Option<CoordinateSystem>,
22
23    #[serde(skip_serializing_if = "Option::is_none")]
24    color_by: Option<ColorBy>,
25
26    #[serde(skip_serializing_if = "Option::is_none")]
27    legend_hover_link: Option<bool>,
28
29    #[serde(skip_serializing_if = "Vec::is_empty")]
30    data: DataFrame,
31}
32
33impl Candlestick {
34    pub fn new() -> Self {
35        Self {
36            type_: "candlestick".to_string(),
37            id: None,
38            name: None,
39            coordiate_system: None,
40            color_by: None,
41            legend_hover_link: None,
42            data: vec![],
43        }
44    }
45
46    pub fn id<S: Into<String>>(mut self, id: S) -> Self {
47        self.id = Some(id.into());
48        self
49    }
50
51    pub fn name<S: Into<String>>(mut self, name: S) -> Self {
52        self.name = Some(name.into());
53        self
54    }
55
56    pub fn coordiate_system<C: Into<CoordinateSystem>>(mut self, coordiate_system: C) -> Self {
57        self.coordiate_system = Some(coordiate_system.into());
58        self
59    }
60
61    pub fn color_by(mut self, color_by: ColorBy) -> Self {
62        self.color_by = Some(color_by);
63        self
64    }
65
66    pub fn legend_hover_link(mut self, legend_hover_link: bool) -> Self {
67        self.legend_hover_link = Some(legend_hover_link);
68        self
69    }
70
71    pub fn data<D: Into<DataPoint>>(mut self, data: Vec<D>) -> Self {
72        self.data = data.into_iter().map(|d| d.into()).collect();
73        self
74    }
75}