umya_spreadsheet/structs/drawing/charts/
line_chart.rs1use crate::xml_read_loop;
2
3use super::AreaChartSeries;
5use super::AreaChartSeriesList;
6use super::AxisId;
7use super::DataLabels;
8use super::Grouping;
9use super::ShowMarker;
10use super::Smooth;
11use super::VaryColors;
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 LineChart {
22 grouping: Grouping,
23 vary_colors: VaryColors,
24 area_chart_series_list: AreaChartSeriesList,
25 data_labels: DataLabels,
26 show_marker: ShowMarker,
27 smooth: Smooth,
28 axis_id: ThinVec<AxisId>,
29}
30
31impl LineChart {
32 pub fn get_grouping(&self) -> &Grouping {
33 &self.grouping
34 }
35
36 pub fn get_grouping_mut(&mut self) -> &mut Grouping {
37 &mut self.grouping
38 }
39
40 pub fn set_grouping(&mut self, value: Grouping) -> &mut Self {
41 self.grouping = value;
42 self
43 }
44
45 pub fn get_vary_colors(&self) -> &VaryColors {
46 &self.vary_colors
47 }
48
49 pub fn get_vary_colors_mut(&mut self) -> &mut VaryColors {
50 &mut self.vary_colors
51 }
52
53 pub fn set_vary_colors(&mut self, value: VaryColors) -> &mut Self {
54 self.vary_colors = value;
55 self
56 }
57
58 pub fn get_area_chart_series_list(&self) -> &AreaChartSeriesList {
59 &self.area_chart_series_list
60 }
61
62 pub fn get_area_chart_series_list_mut(&mut self) -> &mut AreaChartSeriesList {
63 &mut self.area_chart_series_list
64 }
65
66 pub fn set_area_chart_series_list(&mut self, value: AreaChartSeriesList) -> &mut Self {
67 self.area_chart_series_list = value;
68 self
69 }
70
71 pub fn get_data_labels(&self) -> &DataLabels {
72 &self.data_labels
73 }
74
75 pub fn get_data_labels_mut(&mut self) -> &mut DataLabels {
76 &mut self.data_labels
77 }
78
79 pub fn set_data_labels(&mut self, value: DataLabels) -> &mut Self {
80 self.data_labels = value;
81 self
82 }
83
84 pub fn get_show_marker(&self) -> &ShowMarker {
85 &self.show_marker
86 }
87
88 pub fn get_show_marker_mut(&mut self) -> &mut ShowMarker {
89 &mut self.show_marker
90 }
91
92 pub fn set_show_marker(&mut self, value: ShowMarker) -> &mut Self {
93 self.show_marker = value;
94 self
95 }
96
97 pub fn get_smooth(&self) -> &Smooth {
98 &self.smooth
99 }
100
101 pub fn get_smooth_mut(&mut self) -> &mut Smooth {
102 &mut self.smooth
103 }
104
105 pub fn set_smooth(&mut self, value: Smooth) -> &mut Self {
106 self.smooth = value;
107 self
108 }
109
110 pub fn get_axis_id(&self) -> &[AxisId] {
111 &self.axis_id
112 }
113
114 pub fn get_axis_id_mut(&mut self) -> &mut ThinVec<AxisId> {
115 &mut self.axis_id
116 }
117
118 pub fn set_axis_id(&mut self, value: impl Into<ThinVec<AxisId>>) -> &mut Self {
119 self.axis_id = value.into();
120 self
121 }
122
123 pub fn add_axis_id(&mut self, value: AxisId) -> &mut Self {
124 self.axis_id.push(value);
125 self
126 }
127
128 pub(crate) fn set_attributes<R: std::io::BufRead>(
129 &mut self,
130 reader: &mut Reader<R>,
131 _e: &BytesStart,
132 ) {
133 xml_read_loop!(
134 reader,
135 Event::Start(ref e) => match e.name().into_inner() {
136 b"c:ser" => {
137 let mut obj = AreaChartSeries::default();
138 obj.set_attributes(reader, e);
139 self.get_area_chart_series_list_mut()
140 .add_area_chart_series(obj);
141 }
142 b"c:dLbls" => {
143 self.data_labels.set_attributes(reader, e);
144 }
145 _ => (),
146 },
147 Event::Empty(ref e) => match e.name().into_inner() {
148 b"c:grouping" => {
149 self.grouping.set_attributes(reader, e);
150 }
151 b"c:varyColors" => {
152 self.vary_colors.set_attributes(reader, e);
153 }
154 b"c:marker" => {
155 self.show_marker.set_attributes(reader, e);
156 }
157 b"c:smooth" => {
158 self.smooth.set_attributes(reader, e);
159 }
160 b"c:axId" => {
161 let mut obj = AxisId::default();
162 obj.set_attributes(reader, e);
163 self.add_axis_id(obj);
164 }
165 _ => (),
166 },
167 Event::End(ref e) => {
168 if e.name().into_inner() == b"c:lineChart" {
169 return;
170 }
171 },
172 Event::Eof => panic!("Error: Could not find {} end element", "c:lineChart"),
173 );
174 }
175
176 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, spreadsheet: &Spreadsheet) {
177 write_start_tag(writer, "c:lineChart", vec![], false);
179
180 self.grouping.write_to(writer);
182
183 self.vary_colors.write_to(writer);
185
186 for v in self.area_chart_series_list.get_area_chart_series() {
188 v.write_to(writer, spreadsheet);
189 }
190
191 self.data_labels.write_to(writer);
193
194 self.show_marker.write_to(writer);
196
197 self.smooth.write_to(writer);
199
200 for v in &self.axis_id {
202 v.write_to(writer);
203 }
204
205 write_end_tag(writer, "c:lineChart");
206 }
207}