umya_spreadsheet/structs/drawing/
graphic_data.rs1use super::charts::ChartSpace;
3use crate::helper::const_str::*;
4use crate::reader::driver::*;
5use crate::reader::xlsx::chart;
6use crate::structs::raw::RawRelationships;
7use crate::traits::AdjustmentCoordinateWithSheet;
8use crate::writer::driver::*;
9use quick_xml::events::{BytesStart, Event};
10use quick_xml::Reader;
11use quick_xml::Writer;
12use std::io::Cursor;
13
14#[derive(Clone, Default, Debug)]
15pub struct GraphicData {
16 chart_space: ChartSpace,
17}
18
19impl GraphicData {
20 #[inline]
21 pub fn get_chart_space(&self) -> &ChartSpace {
22 &self.chart_space
23 }
24
25 #[inline]
26 pub fn get_chart_space_mut(&mut self) -> &mut ChartSpace {
27 &mut self.chart_space
28 }
29
30 #[inline]
31 pub fn set_chart_space(&mut self, value: ChartSpace) -> &GraphicData {
32 self.chart_space = value;
33 self
34 }
35
36 pub(crate) fn set_attributes<R: std::io::BufRead>(
37 &mut self,
38 reader: &mut Reader<R>,
39 _e: &BytesStart,
40 drawing_relationships: Option<&RawRelationships>,
41 ) {
42 xml_read_loop!(
43 reader,
44 Event::Empty(ref e) => {
45 if e.name().into_inner() == b"c:chart" {
46 let chart_id = get_attribute(e, b"r:id").unwrap();
47 let relationship = drawing_relationships
48 .unwrap()
49 .get_relationship_by_rid(&chart_id);
50 chart::read(relationship.get_raw_file(), &mut self.chart_space);
51 }
52 },
53 Event::End(ref e) => {
54 if e.name().into_inner() == b"a:graphicData" {
55 return;
56 }
57 },
58 Event::Eof => panic!("Error: Could not find {} end element", "a:graphicData")
59 );
60 }
61
62 pub(crate) fn write_to(
63 &self,
64 writer: &mut Writer<Cursor<Vec<u8>>>,
65 rel_list: &mut Vec<(String, String)>,
66 ) {
67 write_start_tag(
69 writer,
70 "a:graphicData",
71 vec![("uri", DRAWINGML_CHART_NS)],
72 false,
73 );
74
75 rel_list.push((String::from("CHART"), String::new()));
77 write_start_tag(
78 writer,
79 "c:chart",
80 vec![
81 ("xmlns:c", DRAWINGML_CHART_NS),
82 ("xmlns:r", REL_OFC_NS),
83 ("r:id", format!("rId{}", rel_list.len()).as_str()),
84 ],
85 true,
86 );
87
88 write_end_tag(writer, "a:graphicData");
89 }
90}
91impl AdjustmentCoordinateWithSheet for GraphicData {
92 #[inline]
93 fn adjustment_insert_coordinate_with_sheet(
94 &mut self,
95 sheet_name: &str,
96 root_col_num: &u32,
97 offset_col_num: &u32,
98 root_row_num: &u32,
99 offset_row_num: &u32,
100 ) {
101 self.chart_space.adjustment_insert_coordinate_with_sheet(
102 sheet_name,
103 root_col_num,
104 offset_col_num,
105 root_row_num,
106 offset_row_num,
107 );
108 }
109
110 #[inline]
111 fn adjustment_remove_coordinate_with_sheet(
112 &mut self,
113 sheet_name: &str,
114 root_col_num: &u32,
115 offset_col_num: &u32,
116 root_row_num: &u32,
117 offset_row_num: &u32,
118 ) {
119 self.chart_space.adjustment_remove_coordinate_with_sheet(
120 sheet_name,
121 root_col_num,
122 offset_col_num,
123 root_row_num,
124 offset_row_num,
125 );
126 }
127}