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