umya_spreadsheet/structs/drawing/charts/
radar_chart.rs

1// c:radarChart
2use super::AreaChartSeries;
3use super::AreaChartSeriesList;
4use super::AxisId;
5use super::DataLabels;
6use super::RadarStyle;
7use super::VaryColors;
8use crate::reader::driver::*;
9use crate::structs::Spreadsheet;
10use crate::writer::driver::*;
11use quick_xml::events::{BytesStart, Event};
12use quick_xml::Reader;
13use quick_xml::Writer;
14use std::io::Cursor;
15use thin_vec::ThinVec;
16
17#[derive(Clone, Default, Debug)]
18pub struct RadarChart {
19    radar_style: RadarStyle,
20    vary_colors: VaryColors,
21    area_chart_series_list: AreaChartSeriesList,
22    data_labels: DataLabels,
23    axis_id: ThinVec<AxisId>,
24}
25
26impl RadarChart {
27    pub fn get_radar_style(&self) -> &RadarStyle {
28        &self.radar_style
29    }
30
31    pub fn get_radar_style_mut(&mut self) -> &mut RadarStyle {
32        &mut self.radar_style
33    }
34
35    pub fn set_radar_style(&mut self, value: RadarStyle) -> &mut RadarChart {
36        self.radar_style = value;
37        self
38    }
39
40    pub fn get_vary_colors(&self) -> &VaryColors {
41        &self.vary_colors
42    }
43
44    pub fn get_vary_colors_mut(&mut self) -> &mut VaryColors {
45        &mut self.vary_colors
46    }
47
48    pub fn set_vary_colors(&mut self, value: VaryColors) -> &mut RadarChart {
49        self.vary_colors = value;
50        self
51    }
52
53    pub fn get_area_chart_series_list(&self) -> &AreaChartSeriesList {
54        &self.area_chart_series_list
55    }
56
57    pub fn get_area_chart_series_list_mut(&mut self) -> &mut AreaChartSeriesList {
58        &mut self.area_chart_series_list
59    }
60
61    pub fn set_area_chart_series_list(&mut self, value: AreaChartSeriesList) -> &mut Self {
62        self.area_chart_series_list = value;
63        self
64    }
65
66    pub fn get_data_labels(&self) -> &DataLabels {
67        &self.data_labels
68    }
69
70    pub fn get_data_labels_mut(&mut self) -> &mut DataLabels {
71        &mut self.data_labels
72    }
73
74    pub fn set_data_labels(&mut self, value: DataLabels) -> &mut RadarChart {
75        self.data_labels = value;
76        self
77    }
78
79    pub fn get_axis_id(&self) -> &[AxisId] {
80        &self.axis_id
81    }
82
83    pub fn get_axis_id_mut(&mut self) -> &mut ThinVec<AxisId> {
84        &mut self.axis_id
85    }
86
87    pub fn set_axis_id(&mut self, value: impl Into<ThinVec<AxisId>>) -> &mut RadarChart {
88        self.axis_id = value.into();
89        self
90    }
91
92    pub fn add_axis_id(&mut self, value: AxisId) -> &mut RadarChart {
93        self.axis_id.push(value);
94        self
95    }
96
97    pub(crate) fn set_attributes<R: std::io::BufRead>(
98        &mut self,
99        reader: &mut Reader<R>,
100        _e: &BytesStart,
101    ) {
102        xml_read_loop!(
103            reader,
104            Event::Start(ref e) => {
105                match e.name().0 {
106                    b"c:ser" => {
107                        let mut obj = AreaChartSeries::default();
108                        obj.set_attributes(reader, e);
109                        self.get_area_chart_series_list_mut()
110                            .add_area_chart_series(obj);
111                        }
112                    b"c:dLbls" => {
113                        self.data_labels.set_attributes(reader, e);
114                    }
115                    _ => (),
116                }
117            },
118            Event::Empty(ref e) => {
119                match e.name().0 {
120                    b"c:radarStyle" => {
121                        self.radar_style.set_attributes(reader, e);
122                    }
123                    b"c:varyColors" => {
124                        self.vary_colors.set_attributes(reader, e);
125                    }
126                    b"c:axId" => {
127                        let mut obj = AxisId::default();
128                        obj.set_attributes(reader, e);
129                        self.add_axis_id(obj);
130                    }
131                    _ => (),
132                }
133            },
134            Event::End(ref e) => {
135                if e.name().0 == b"c:radarChart" {
136                    return;
137                }
138            },
139            Event::Eof => panic!("Error: Could not find {} end element", "c:radarChart")
140        );
141    }
142
143    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, spreadsheet: &Spreadsheet) {
144        // c:radarChart
145        write_start_tag(writer, "c:radarChart", vec![], false);
146
147        // c:radarStyle
148        self.radar_style.write_to(writer);
149
150        // c:varyColors
151        self.vary_colors.write_to(writer);
152
153        // c:ser
154        for v in self.area_chart_series_list.get_area_chart_series() {
155            v.write_to(writer, spreadsheet);
156        }
157
158        // c:dLbls
159        self.data_labels.write_to(writer);
160
161        // c:axId
162        for v in &self.axis_id {
163            v.write_to(writer);
164        }
165
166        write_end_tag(writer, "c:radarChart");
167    }
168}