umya_spreadsheet/structs/drawing/charts/
chart.rs1use super::AutoTitleDeleted;
2use super::BackWall;
3use super::DisplayBlanksAs;
4use super::Floor;
5use super::Formula;
6use super::Legend;
7use super::PlotArea;
8use super::PlotVisibleOnly;
9use super::ShowDataLabelsOverMaximum;
10use super::SideWall;
11use super::Title;
12use super::View3D;
13use crate::structs::Spreadsheet;
14use crate::traits::AdjustmentCoordinateWithSheet;
15use crate::writer::driver::*;
16use crate::xml_read_loop;
17use quick_xml::events::{BytesStart, Event};
18use quick_xml::Reader;
19use quick_xml::Writer;
20use std::io::Cursor;
21
22#[derive(Clone, Default, Debug)]
23pub struct Chart {
24 title: Option<Title>,
25 auto_title_deleted: AutoTitleDeleted,
26 view_3d: Option<View3D>,
27 floor: Option<Floor>,
28 side_wall: Option<SideWall>,
29 back_wall: Option<BackWall>,
30 plot_area: PlotArea,
31 legend: Legend,
32 plot_visible_only: PlotVisibleOnly,
33 display_blanks_as: DisplayBlanksAs,
34 show_data_labels_over_maximum: ShowDataLabelsOverMaximum,
35}
36
37impl Chart {
38 pub const LANG_EN_GB: &'static str = "en_GB";
39 pub const LANG_JA_JP: &'static str = "ja-JP";
40
41 pub fn get_title(&self) -> Option<&Title> {
42 self.title.as_ref()
43 }
44
45 pub fn get_title_mut(&mut self) -> Option<&mut Title> {
46 self.title.as_mut()
47 }
48
49 pub fn set_title(&mut self, value: Title) -> &mut Self {
50 self.title = Some(value);
51 self
52 }
53
54 pub fn get_auto_title_deleted(&self) -> &AutoTitleDeleted {
55 &self.auto_title_deleted
56 }
57
58 pub fn get_auto_title_deleted_mut(&mut self) -> &mut AutoTitleDeleted {
59 &mut self.auto_title_deleted
60 }
61
62 pub fn set_auto_title_deleted(&mut self, value: AutoTitleDeleted) -> &mut Self {
63 self.auto_title_deleted = value;
64 self
65 }
66
67 pub fn get_view_3d(&self) -> Option<&View3D> {
68 self.view_3d.as_ref()
69 }
70
71 pub fn get_view_3d_mut(&mut self) -> Option<&mut View3D> {
72 self.view_3d.as_mut()
73 }
74
75 pub fn set_view_3d(&mut self, value: View3D) -> &mut Self {
76 self.view_3d = Some(value);
77 self
78 }
79
80 pub fn get_floor(&self) -> Option<&Floor> {
81 self.floor.as_ref()
82 }
83
84 pub fn get_floor_mut(&mut self) -> Option<&mut Floor> {
85 self.floor.as_mut()
86 }
87
88 pub fn set_floor(&mut self, value: Floor) -> &mut Self {
89 self.floor = Some(value);
90 self
91 }
92
93 pub fn get_side_wall(&self) -> Option<&SideWall> {
94 self.side_wall.as_ref()
95 }
96
97 pub fn get_side_wall_mut(&mut self) -> Option<&mut SideWall> {
98 self.side_wall.as_mut()
99 }
100
101 pub fn set_side_wall(&mut self, value: SideWall) -> &mut Self {
102 self.side_wall = Some(value);
103 self
104 }
105
106 pub fn get_back_wall(&self) -> Option<&BackWall> {
107 self.back_wall.as_ref()
108 }
109
110 pub fn get_back_wall_mut(&mut self) -> Option<&mut BackWall> {
111 self.back_wall.as_mut()
112 }
113
114 pub fn set_back_wall(&mut self, value: BackWall) -> &mut Self {
115 self.back_wall = Some(value);
116 self
117 }
118
119 pub fn get_plot_area(&self) -> &PlotArea {
120 &self.plot_area
121 }
122
123 pub fn get_plot_area_mut(&mut self) -> &mut PlotArea {
124 &mut self.plot_area
125 }
126
127 pub fn set_plot_area(&mut self, value: PlotArea) -> &mut Self {
128 self.plot_area = value;
129 self
130 }
131
132 pub fn get_legend(&self) -> &Legend {
133 &self.legend
134 }
135
136 pub fn get_legend_mut(&mut self) -> &mut Legend {
137 &mut self.legend
138 }
139
140 pub fn set_legend(&mut self, value: Legend) -> &mut Self {
141 self.legend = value;
142 self
143 }
144
145 pub fn get_plot_visible_only(&self) -> &PlotVisibleOnly {
146 &self.plot_visible_only
147 }
148
149 pub fn get_plot_visible_only_mut(&mut self) -> &mut PlotVisibleOnly {
150 &mut self.plot_visible_only
151 }
152
153 pub fn set_plot_visible_only(&mut self, value: PlotVisibleOnly) -> &mut Self {
154 self.plot_visible_only = value;
155 self
156 }
157
158 pub fn get_display_blanks_as(&self) -> &DisplayBlanksAs {
159 &self.display_blanks_as
160 }
161
162 pub fn get_display_blanks_as_mut(&mut self) -> &mut DisplayBlanksAs {
163 &mut self.display_blanks_as
164 }
165
166 pub fn set_display_blanks_as(&mut self, value: DisplayBlanksAs) -> &mut Self {
167 self.display_blanks_as = value;
168 self
169 }
170
171 pub fn get_show_data_labels_over_maximum(&self) -> &ShowDataLabelsOverMaximum {
172 &self.show_data_labels_over_maximum
173 }
174
175 pub fn get_show_data_labels_over_maximum_mut(&mut self) -> &mut ShowDataLabelsOverMaximum {
176 &mut self.show_data_labels_over_maximum
177 }
178
179 pub fn set_show_data_labels_over_maximum(
180 &mut self,
181 value: ShowDataLabelsOverMaximum,
182 ) -> &mut Chart {
183 self.show_data_labels_over_maximum = value;
184 self
185 }
186
187 pub fn get_formula_mut(&mut self) -> Vec<&mut Formula> {
188 self.get_plot_area_mut().get_formula_mut()
189 }
190
191 pub(crate) fn set_attributes<R: std::io::BufRead>(
192 &mut self,
193 reader: &mut Reader<R>,
194 _e: &BytesStart,
195 ) {
196 xml_read_loop!(
197 reader,
198 Event::Start(ref e) => match e.name().into_inner() {
199 b"c:title" => {
200 let mut obj = Title::default();
201 obj.set_attributes(reader, e);
202 self.set_title(obj);
203 }
204 b"c:view3D" => {
205 let mut obj = View3D::default();
206 obj.set_attributes(reader, e);
207 self.set_view_3d(obj);
208 }
209 b"c:floor" => {
210 let mut obj = Floor::default();
211 obj.set_attributes(reader, e);
212 self.set_floor(obj);
213 }
214 b"c:sideWall" => {
215 let mut obj = SideWall::default();
216 obj.set_attributes(reader, e);
217 self.set_side_wall(obj);
218 }
219 b"c:backWall" => {
220 let mut obj = BackWall::default();
221 obj.set_attributes(reader, e);
222 self.set_back_wall(obj);
223 }
224 b"c:plotArea" => {
225 self.plot_area.set_attributes(reader, e);
226 }
227 b"c:legend" => {
228 self.legend.set_attributes(reader, e);
229 }
230 _ => (),
231 },
232 Event::Empty(ref e) => match e.name().into_inner() {
233 b"c:autoTitleDeleted" => {
234 self.auto_title_deleted.set_attributes(reader, e);
235 }
236 b"c:plotVisOnly" => {
237 self.plot_visible_only.set_attributes(reader, e);
238 }
239 b"c:dispBlanksAs" => {
240 self.display_blanks_as.set_attributes(reader, e);
241 }
242 b"c:showDLblsOverMax" => {
243 self.show_data_labels_over_maximum.set_attributes(reader, e);
244 }
245 _ => (),
246 },
247 Event::End(ref e) => {
248 if e.name().into_inner() == b"c:chart" {
249 return;
250 }
251 },
252 Event::Eof => panic!("Error: Could not find {} end element", "c:chart"),
253 );
254 }
255
256 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, spreadsheet: &Spreadsheet) {
257 write_start_tag(writer, "c:chart", vec![], false);
259
260 if let Some(v) = &self.title {
262 v.write_to(writer, spreadsheet);
263 }
264
265 self.auto_title_deleted.write_to(writer);
267
268 if let Some(v) = &self.view_3d {
270 v.write_to(writer);
271 }
272
273 if let Some(v) = &self.floor {
275 v.write_to(writer);
276 }
277
278 if let Some(v) = &self.side_wall {
280 v.write_to(writer);
281 }
282
283 if let Some(v) = &self.back_wall {
285 v.write_to(writer);
286 }
287
288 self.plot_area.write_to(writer, spreadsheet);
290
291 self.legend.write_to(writer);
293
294 self.plot_visible_only.write_to(writer);
296
297 self.display_blanks_as.write_to(writer);
299
300 self.show_data_labels_over_maximum.write_to(writer);
302
303 write_end_tag(writer, "c:chart");
304 }
305}
306impl AdjustmentCoordinateWithSheet for Chart {
307 fn adjustment_insert_coordinate_with_sheet(
308 &mut self,
309 sheet_name: &str,
310 root_col_num: &u32,
311 offset_col_num: &u32,
312 root_row_num: &u32,
313 offset_row_num: &u32,
314 ) {
315 self.plot_area.adjustment_insert_coordinate_with_sheet(
316 sheet_name,
317 root_col_num,
318 offset_col_num,
319 root_row_num,
320 offset_row_num,
321 );
322 }
323
324 fn adjustment_remove_coordinate_with_sheet(
325 &mut self,
326 sheet_name: &str,
327 root_col_num: &u32,
328 offset_col_num: &u32,
329 root_row_num: &u32,
330 offset_row_num: &u32,
331 ) {
332 self.plot_area.adjustment_remove_coordinate_with_sheet(
333 sheet_name,
334 root_col_num,
335 offset_col_num,
336 root_row_num,
337 offset_row_num,
338 );
339 }
340}