Skip to main content

umya_spreadsheet/structs/drawing/charts/
line_chart.rs

1use std::io::Cursor;
2
3use quick_xml::{
4    Reader,
5    Writer,
6    events::{
7        BytesStart,
8        Event,
9    },
10};
11
12// lineChart
13use super::AreaChartSeries;
14use super::{
15    AreaChartSeriesList,
16    AxisId,
17    DataLabels,
18    Grouping,
19    ShowMarker,
20    Smooth,
21    VaryColors,
22};
23use crate::{
24    structs::Workbook,
25    writer::driver::{
26        write_end_tag,
27        write_start_tag,
28    },
29    xml_read_loop,
30};
31
32#[derive(Clone, Default, Debug)]
33pub struct LineChart {
34    grouping:               Grouping,
35    vary_colors:            VaryColors,
36    area_chart_series_list: AreaChartSeriesList,
37    data_labels:            DataLabels,
38    show_marker:            ShowMarker,
39    smooth:                 Smooth,
40    axis_id:                Vec<AxisId>,
41}
42
43impl LineChart {
44    #[must_use]
45    pub fn grouping(&self) -> &Grouping {
46        &self.grouping
47    }
48
49    #[must_use]
50    #[deprecated(since = "3.0.0", note = "Use grouping()")]
51    pub fn get_grouping(&self) -> &Grouping {
52        self.grouping()
53    }
54
55    pub fn grouping_mut(&mut self) -> &mut Grouping {
56        &mut self.grouping
57    }
58
59    #[deprecated(since = "3.0.0", note = "Use grouping_mut()")]
60    pub fn get_grouping_mut(&mut self) -> &mut Grouping {
61        self.grouping_mut()
62    }
63
64    pub fn set_grouping(&mut self, value: Grouping) -> &mut Self {
65        self.grouping = value;
66        self
67    }
68
69    #[must_use]
70    pub fn vary_colors(&self) -> &VaryColors {
71        &self.vary_colors
72    }
73
74    #[must_use]
75    #[deprecated(since = "3.0.0", note = "Use vary_colors()")]
76    pub fn get_vary_colors(&self) -> &VaryColors {
77        self.vary_colors()
78    }
79
80    pub fn vary_colors_mut(&mut self) -> &mut VaryColors {
81        &mut self.vary_colors
82    }
83
84    #[deprecated(since = "3.0.0", note = "Use vary_colors_mut()")]
85    pub fn get_vary_colors_mut(&mut self) -> &mut VaryColors {
86        self.vary_colors_mut()
87    }
88
89    pub fn set_vary_colors(&mut self, value: VaryColors) -> &mut Self {
90        self.vary_colors = value;
91        self
92    }
93
94    #[must_use]
95    pub fn area_chart_series_list(&self) -> &AreaChartSeriesList {
96        &self.area_chart_series_list
97    }
98
99    #[must_use]
100    #[deprecated(since = "3.0.0", note = "Use area_chart_series_list()")]
101    pub fn get_area_chart_series_list(&self) -> &AreaChartSeriesList {
102        self.area_chart_series_list()
103    }
104
105    pub fn area_chart_series_list_mut(&mut self) -> &mut AreaChartSeriesList {
106        &mut self.area_chart_series_list
107    }
108
109    #[deprecated(since = "3.0.0", note = "Use area_chart_series_list_mut()")]
110    pub fn get_area_chart_series_list_mut(&mut self) -> &mut AreaChartSeriesList {
111        self.area_chart_series_list_mut()
112    }
113
114    pub fn set_area_chart_series_list(&mut self, value: AreaChartSeriesList) -> &mut Self {
115        self.area_chart_series_list = value;
116        self
117    }
118
119    #[must_use]
120    pub fn data_labels(&self) -> &DataLabels {
121        &self.data_labels
122    }
123
124    #[must_use]
125    #[deprecated(since = "3.0.0", note = "Use data_labels()")]
126    pub fn get_data_labels(&self) -> &DataLabels {
127        self.data_labels()
128    }
129
130    pub fn data_labels_mut(&mut self) -> &mut DataLabels {
131        &mut self.data_labels
132    }
133
134    #[deprecated(since = "3.0.0", note = "Use data_labels_mut()")]
135    pub fn get_data_labels_mut(&mut self) -> &mut DataLabels {
136        self.data_labels_mut()
137    }
138
139    pub fn set_data_labels(&mut self, value: DataLabels) -> &mut Self {
140        self.data_labels = value;
141        self
142    }
143
144    #[must_use]
145    pub fn show_marker(&self) -> &ShowMarker {
146        &self.show_marker
147    }
148
149    #[must_use]
150    #[deprecated(since = "3.0.0", note = "Use show_marker()")]
151    pub fn get_show_marker(&self) -> &ShowMarker {
152        self.show_marker()
153    }
154
155    pub fn show_marker_mut(&mut self) -> &mut ShowMarker {
156        &mut self.show_marker
157    }
158
159    #[deprecated(since = "3.0.0", note = "Use show_marker_mut()")]
160    pub fn get_show_marker_mut(&mut self) -> &mut ShowMarker {
161        self.show_marker_mut()
162    }
163
164    pub fn set_show_marker(&mut self, value: ShowMarker) -> &mut Self {
165        self.show_marker = value;
166        self
167    }
168
169    #[must_use]
170    pub fn smooth(&self) -> &Smooth {
171        &self.smooth
172    }
173
174    #[must_use]
175    #[deprecated(since = "3.0.0", note = "Use smooth()")]
176    pub fn get_smooth(&self) -> &Smooth {
177        self.smooth()
178    }
179
180    pub fn smooth_mut(&mut self) -> &mut Smooth {
181        &mut self.smooth
182    }
183
184    #[deprecated(since = "3.0.0", note = "Use smooth_mut()")]
185    pub fn get_smooth_mut(&mut self) -> &mut Smooth {
186        self.smooth_mut()
187    }
188
189    pub fn set_smooth(&mut self, value: Smooth) -> &mut Self {
190        self.smooth = value;
191        self
192    }
193
194    #[must_use]
195    pub fn axis_id(&self) -> &[AxisId] {
196        &self.axis_id
197    }
198
199    #[must_use]
200    #[deprecated(since = "3.0.0", note = "Use axis_id()")]
201    pub fn get_axis_id(&self) -> &[AxisId] {
202        self.axis_id()
203    }
204
205    pub fn axis_id_mut(&mut self) -> &mut Vec<AxisId> {
206        &mut self.axis_id
207    }
208
209    #[deprecated(since = "3.0.0", note = "Use axis_id_mut()")]
210    pub fn get_axis_id_mut(&mut self) -> &mut Vec<AxisId> {
211        self.axis_id_mut()
212    }
213
214    pub fn set_axis_id(&mut self, value: impl Into<Vec<AxisId>>) -> &mut Self {
215        self.axis_id = value.into();
216        self
217    }
218
219    pub fn add_axis_id(&mut self, value: AxisId) -> &mut Self {
220        self.axis_id.push(value);
221        self
222    }
223
224    pub(crate) fn set_attributes<R: std::io::BufRead>(
225        &mut self,
226        reader: &mut Reader<R>,
227        _e: &BytesStart,
228    ) {
229        xml_read_loop!(
230            reader,
231            Event::Start(ref e) => match e.name().into_inner() {
232                b"c:ser" => {
233                    let mut obj = AreaChartSeries::default();
234                    obj.set_attributes(reader, e);
235                    self.area_chart_series_list_mut()
236                        .add_area_chart_series(obj);
237                }
238                b"c:dLbls" => {
239                    self.data_labels.set_attributes(reader, e);
240                }
241                _ => (),
242            },
243            Event::Empty(ref e) => match e.name().into_inner() {
244                b"c:grouping" => {
245                    self.grouping.set_attributes(reader, e);
246                }
247                b"c:varyColors" => {
248                    self.vary_colors.set_attributes(reader, e);
249                }
250                b"c:marker" => {
251                    self.show_marker.set_attributes(reader, e);
252                }
253                b"c:smooth" => {
254                    self.smooth.set_attributes(reader, e);
255                }
256                b"c:axId" => {
257                    let mut obj = AxisId::default();
258                    obj.set_attributes(reader, e);
259                    self.add_axis_id(obj);
260                }
261                _ => (),
262            },
263            Event::End(ref e) => {
264                if e.name().into_inner() == b"c:lineChart" {
265                    return;
266                }
267            },
268            Event::Eof => panic!("Error: Could not find {} end element", "c:lineChart"),
269        );
270    }
271
272    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, wb: &Workbook) {
273        // c:lineChart
274        write_start_tag(writer, "c:lineChart", vec![], false);
275
276        // c:grouping
277        self.grouping.write_to(writer);
278
279        // c:varyColors
280        self.vary_colors.write_to(writer);
281
282        // c:ser
283        for v in self.area_chart_series_list.area_chart_series() {
284            v.write_to(writer, wb);
285        }
286
287        // c:dLbls
288        self.data_labels.write_to(writer);
289
290        // c:marker
291        self.show_marker.write_to(writer);
292
293        // c:smooth
294        self.smooth.write_to(writer);
295
296        // c:axId
297        for v in &self.axis_id {
298            v.write_to(writer);
299        }
300
301        write_end_tag(writer, "c:lineChart");
302    }
303}