Skip to main content

umya_spreadsheet/structs/drawing/charts/
line_3d_chart.rs

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