umya_spreadsheet/structs/
data_bar.rs

1use super::Color;
2use super::ConditionalFormatValueObject;
3use crate::reader::driver::*;
4use crate::writer::driver::*;
5use quick_xml::events::BytesStart;
6use quick_xml::events::Event;
7use quick_xml::Reader;
8use quick_xml::Writer;
9use std::io::Cursor;
10use thin_vec::ThinVec;
11
12#[derive(Clone, Default, Debug)]
13pub struct DataBar {
14    cfvo_collection: ThinVec<ConditionalFormatValueObject>,
15    color_collection: ThinVec<Color>,
16}
17
18impl DataBar {
19    #[inline]
20    pub fn get_cfvo_collection(&self) -> &[ConditionalFormatValueObject] {
21        &self.cfvo_collection
22    }
23
24    #[inline]
25    pub fn set_cfvo_collection(
26        &mut self,
27        value: ThinVec<ConditionalFormatValueObject>,
28    ) -> &mut Self {
29        self.cfvo_collection = value;
30        self
31    }
32
33    #[inline]
34    pub fn add_cfvo_collection(&mut self, value: ConditionalFormatValueObject) -> &mut Self {
35        self.cfvo_collection.push(value);
36        self
37    }
38
39    #[inline]
40    pub fn get_color_collection(&self) -> &[Color] {
41        &self.color_collection
42    }
43
44    #[inline]
45    pub fn set_color_collection(&mut self, value: impl Into<ThinVec<Color>>) -> &mut Self {
46        self.color_collection = value.into();
47        self
48    }
49
50    #[inline]
51    pub fn add_color_collection(&mut self, value: Color) -> &mut Self {
52        self.color_collection.push(value);
53        self
54    }
55
56    pub(crate) fn set_attributes<R: std::io::BufRead>(
57        &mut self,
58        reader: &mut Reader<R>,
59        _e: &BytesStart,
60    ) {
61        xml_read_loop!(
62            reader,
63            Event::Empty(ref e) => {
64                match e.name().into_inner() {
65                    b"cfvo" => {
66                        let mut obj = ConditionalFormatValueObject::default();
67                        obj.set_attributes(reader, e, true);
68                        self.cfvo_collection.push(obj);
69                    }
70                    b"color" => {
71                        let mut obj = Color::default();
72                        obj.set_attributes(reader, e, true);
73                        self.color_collection.push(obj);
74                    }
75                    _ => (),
76                }
77            },
78            Event::End(ref e) => {
79                if e.name().into_inner() == b"dataBar" {
80                    return
81                }
82            },
83            Event::Eof => panic!("Error: Could not find {} end element", "dataBar")
84        );
85    }
86
87    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
88        // dataBar
89        write_start_tag(writer, "dataBar", vec![], false);
90
91        // cfvo
92        for v in &self.cfvo_collection {
93            v.write_to(writer);
94        }
95
96        // color
97        for v in &self.color_collection {
98            v.write_to_color(writer);
99        }
100
101        write_end_tag(writer, "dataBar");
102    }
103}