charming_fork_zephyr/element/
mark_area.rs

1use serde::Serialize;
2
3use super::{blur::Blur, emphasis::Emphasis, item_style::ItemStyle, label::Label};
4
5#[derive(Serialize)]
6#[serde(rename_all = "camelCase")]
7pub struct MarkAreaData {
8    #[serde(skip_serializing_if = "Option::is_none")]
9    name: Option<String>,
10
11    #[serde(skip_serializing_if = "Option::is_none")]
12    x_axis: Option<String>,
13
14    #[serde(skip_serializing_if = "Option::is_none")]
15    y_axis: Option<String>,
16}
17
18impl MarkAreaData {
19    pub fn new() -> Self {
20        Self {
21            name: None,
22            x_axis: None,
23            y_axis: None,
24        }
25    }
26
27    pub fn name<S: Into<String>>(mut self, name: S) -> Self {
28        self.name = Some(name.into());
29        self
30    }
31
32    pub fn x_axis<F: Into<String>>(mut self, x_axis: F) -> Self {
33        self.x_axis = Some(x_axis.into());
34        self
35    }
36
37    pub fn y_axis<F: Into<String>>(mut self, y_axis: F) -> Self {
38        self.y_axis = Some(y_axis.into());
39        self
40    }
41}
42
43#[derive(Serialize)]
44#[serde(rename_all = "camelCase")]
45pub struct MarkArea {
46    #[serde(skip_serializing_if = "Option::is_none")]
47    silent: Option<bool>,
48
49    #[serde(skip_serializing_if = "Option::is_none")]
50    label: Option<Label>,
51
52    #[serde(skip_serializing_if = "Option::is_none")]
53    item_style: Option<ItemStyle>,
54
55    #[serde(skip_serializing_if = "Option::is_none")]
56    emphasis: Option<Emphasis>,
57
58    #[serde(skip_serializing_if = "Option::is_none")]
59    blur: Option<Blur>,
60
61    #[serde(skip_serializing_if = "Vec::is_empty")]
62    data: Vec<(MarkAreaData, MarkAreaData)>,
63}
64
65impl MarkArea {
66    pub fn new() -> Self {
67        Self {
68            silent: None,
69            label: None,
70            item_style: None,
71            emphasis: None,
72            blur: None,
73            data: vec![],
74        }
75    }
76
77    pub fn silent(mut self, silent: bool) -> Self {
78        self.silent = Some(silent);
79        self
80    }
81
82    pub fn label<L: Into<Label>>(mut self, label: L) -> Self {
83        self.label = Some(label.into());
84        self
85    }
86
87    pub fn item_style<S: Into<ItemStyle>>(mut self, item_style: S) -> Self {
88        self.item_style = Some(item_style.into());
89        self
90    }
91
92    pub fn emphasis<E: Into<Emphasis>>(mut self, emphasis: E) -> Self {
93        self.emphasis = Some(emphasis.into());
94        self
95    }
96
97    pub fn blur<B: Into<Blur>>(mut self, blur: B) -> Self {
98        self.blur = Some(blur.into());
99        self
100    }
101
102    pub fn data<D: Into<MarkAreaData>>(mut self, data: Vec<(D, D)>) -> Self {
103        self.data = data
104            .into_iter()
105            .map(|(d1, d2)| (d1.into(), d2.into()))
106            .collect();
107        self
108    }
109}