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