1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
// c:valAx
use super::AxisId;
use super::AxisPosition;
use super::CrossBetween;
use super::Crosses;
use super::CrossingAxis;
use super::Delete;
use super::MajorGridlines;
use super::MajorTickMark;
use super::MinorTickMark;
use super::NumberingFormat;
use super::Scaling;
use super::ShapeProperties;
use super::TextProperties;
use super::TickLabelPosition;
use super::Title;
use quick_xml::events::{BytesStart, Event};
use quick_xml::Reader;
use quick_xml::Writer;
use reader::driver::*;
use std::io::Cursor;
use writer::driver::*;

#[derive(Clone, Default, Debug)]
pub struct ValueAxis {
    axis_id: AxisId,
    scaling: Scaling,
    delete: Delete,
    axis_position: AxisPosition,
    major_gridlines: Option<MajorGridlines>,
    title: Option<Title>,
    numbering_format: NumberingFormat,
    major_tick_mark: MajorTickMark,
    minor_tick_mark: MinorTickMark,
    tick_label_position: TickLabelPosition,
    crossing_axis: CrossingAxis,
    crosses: Crosses,
    cross_between: CrossBetween,
    shape_properties: Option<ShapeProperties>,
    text_properties: Option<TextProperties>,
}

impl ValueAxis {
    pub fn get_axis_id(&self) -> &AxisId {
        &self.axis_id
    }

    pub fn get_axis_id_mut(&mut self) -> &mut AxisId {
        &mut self.axis_id
    }

    pub fn set_axis_id(&mut self, value: AxisId) -> &mut Self {
        self.axis_id = value;
        self
    }

    pub fn get_scaling(&self) -> &Scaling {
        &self.scaling
    }

    pub fn get_scaling_mut(&mut self) -> &mut Scaling {
        &mut self.scaling
    }

    pub fn set_scaling(&mut self, value: Scaling) -> &mut Self {
        self.scaling = value;
        self
    }

    pub fn get_delete(&self) -> &Delete {
        &self.delete
    }

    pub fn get_delete_mut(&mut self) -> &mut Delete {
        &mut self.delete
    }

    pub fn set_delete(&mut self, value: Delete) -> &mut Self {
        self.delete = value;
        self
    }

    pub fn get_axis_position(&self) -> &AxisPosition {
        &self.axis_position
    }

    pub fn get_axis_position_mut(&mut self) -> &mut AxisPosition {
        &mut self.axis_position
    }

    pub fn set_axis_position(&mut self, value: AxisPosition) -> &mut Self {
        self.axis_position = value;
        self
    }

    pub fn get_major_gridlines(&self) -> Option<&MajorGridlines> {
        self.major_gridlines.as_ref()
    }

    pub fn get_major_gridlines_mut(&mut self) -> Option<&mut MajorGridlines> {
        self.major_gridlines.as_mut()
    }

    pub fn set_major_gridlines(&mut self, value: MajorGridlines) -> &mut Self {
        self.major_gridlines = Some(value);
        self
    }

    pub fn get_title(&self) -> Option<&Title> {
        self.title.as_ref()
    }

    pub fn get_title_mut(&mut self) -> Option<&mut Title> {
        self.title.as_mut()
    }

    pub fn set_title(&mut self, value: Title) -> &mut Self {
        self.title = Some(value);
        self
    }

    pub fn get_numbering_format(&self) -> &NumberingFormat {
        &self.numbering_format
    }

    pub fn get_numbering_format_mut(&mut self) -> &mut NumberingFormat {
        &mut self.numbering_format
    }

    pub fn set_numbering_format(&mut self, value: NumberingFormat) -> &mut Self {
        self.numbering_format = value;
        self
    }

    pub fn get_major_tick_mark(&self) -> &MajorTickMark {
        &self.major_tick_mark
    }

    pub fn get_major_tick_mark_mut(&mut self) -> &mut MajorTickMark {
        &mut self.major_tick_mark
    }

    pub fn set_major_tick_mark(&mut self, value: MajorTickMark) -> &mut Self {
        self.major_tick_mark = value;
        self
    }

    pub fn get_minor_tick_mark(&self) -> &MinorTickMark {
        &self.minor_tick_mark
    }

    pub fn get_minor_tick_mark_mut(&mut self) -> &mut MinorTickMark {
        &mut self.minor_tick_mark
    }

    pub fn set_minor_tick_mark(&mut self, value: MinorTickMark) -> &mut Self {
        self.minor_tick_mark = value;
        self
    }

    pub fn get_tick_label_position(&self) -> &TickLabelPosition {
        &self.tick_label_position
    }

    pub fn get_tick_label_position_mut(&mut self) -> &mut TickLabelPosition {
        &mut self.tick_label_position
    }

    pub fn set_tick_label_position(&mut self, value: TickLabelPosition) -> &mut Self {
        self.tick_label_position = value;
        self
    }

    pub fn get_tick_crossing_axis(&self) -> &CrossingAxis {
        &self.crossing_axis
    }

    pub fn get_tick_crossing_axis_mut(&mut self) -> &mut CrossingAxis {
        &mut self.crossing_axis
    }

    pub fn set_tick_crossing_axis(&mut self, value: CrossingAxis) -> &mut Self {
        self.crossing_axis = value;
        self
    }

    pub fn get_crosses(&self) -> &Crosses {
        &self.crosses
    }

    pub fn get_crosses_mut(&mut self) -> &mut Crosses {
        &mut self.crosses
    }

    pub fn set_crosses(&mut self, value: Crosses) -> &mut Self {
        self.crosses = value;
        self
    }

    pub fn get_cross_between(&self) -> &CrossBetween {
        &self.cross_between
    }

    pub fn get_cross_between_mut(&mut self) -> &mut CrossBetween {
        &mut self.cross_between
    }

    pub fn set_cross_between(&mut self, value: CrossBetween) -> &mut Self {
        self.cross_between = value;
        self
    }

    pub fn get_shape_properties(&self) -> Option<&ShapeProperties> {
        self.shape_properties.as_ref()
    }

    pub fn get_shape_properties_mut(&mut self) -> Option<&mut ShapeProperties> {
        self.shape_properties.as_mut()
    }

    pub fn set_shape_properties(&mut self, value: ShapeProperties) -> &mut Self {
        self.shape_properties = Some(value);
        self
    }

    pub fn get_text_properties(&self) -> Option<&TextProperties> {
        self.text_properties.as_ref()
    }

    pub fn get_text_properties_mut(&mut self) -> Option<&mut TextProperties> {
        self.text_properties.as_mut()
    }

    pub fn set_text_properties(&mut self, value: TextProperties) -> &mut Self {
        self.text_properties = Some(value);
        self
    }

    pub(crate) fn set_attributes<R: std::io::BufRead>(
        &mut self,
        reader: &mut Reader<R>,
        _e: &BytesStart,
    ) {
        xml_read_loop!(
            reader,
            Event::Start(ref e) => match e.name().0 {
                b"c:scaling" => {
                    self.scaling.set_attributes(reader, e);
                }
                b"c:title" => {
                    let mut obj = Title::default();
                    obj.set_attributes(reader, e);
                    self.set_title(obj);
                }
                b"c:spPr" => {
                    let mut obj = ShapeProperties::default();
                    obj.set_attributes(reader, e);
                    self.set_shape_properties(obj);
                }
                b"c:txPr" => {
                    let mut obj = TextProperties::default();
                    obj.set_attributes(reader, e);
                    self.set_text_properties(obj);
                }
                b"c:majorGridlines" => {
                    let mut obj = MajorGridlines::default();
                    obj.set_attributes(reader, e, false);
                    self.set_major_gridlines(obj);
                }
                _ => (),
            },
            Event::Empty(ref e) => match e.name().0 {
                b"c:axId" => {
                    self.axis_id.set_attributes(reader, e);
                }
                b"c:delete" => {
                    self.delete.set_attributes(reader, e);
                }
                b"c:axPos" => {
                    self.axis_position.set_attributes(reader, e);
                }
                b"c:majorGridlines" => {
                    let mut obj = MajorGridlines::default();
                    obj.set_attributes(reader, e, true);
                    self.set_major_gridlines(obj);
                }
                b"c:numFmt" => {
                    self.numbering_format.set_attributes(reader, e);
                }
                b"c:majorTickMark" => {
                    self.major_tick_mark.set_attributes(reader, e);
                }
                b"c:minorTickMark" => {
                    self.minor_tick_mark.set_attributes(reader, e);
                }
                b"c:tickLblPos" => {
                    self.tick_label_position.set_attributes(reader, e);
                }
                b"c:crossAx" => {
                    self.crossing_axis.set_attributes(reader, e);
                }
                b"c:crosses" => {
                    self.crosses.set_attributes(reader, e);
                }
                b"c:crossBetween" => {
                    self.cross_between.set_attributes(reader, e);
                }
                _ => (),
            },
            Event::End(ref e) => {
                if e.name().0 == b"c:valAx" {
                    return;
                }
            },
            Event::Eof => panic!("Error not find {} end element", "c:valAx")
        );
    }

    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
        // c:valAx
        write_start_tag(writer, "c:valAx", vec![], false);

        // c:axId
        self.axis_id.write_to(writer);

        // c:scaling
        self.scaling.write_to(writer);

        // c:delete
        self.delete.write_to(writer);

        // c:axPos
        self.axis_position.write_to(writer);

        // c:majorGridlines
        if let Some(v) = &self.major_gridlines {
            v.write_to(writer);
        }

        // c:title
        if let Some(v) = &self.title {
            v.write_to(writer);
        }

        // c:numFmt
        self.numbering_format.write_to(writer);

        // c:majorTickMark
        self.major_tick_mark.write_to(writer);

        // c:minorTickMark
        self.minor_tick_mark.write_to(writer);

        // c:tickLblPos
        self.tick_label_position.write_to(writer);

        // c:spPr
        if let Some(v) = &self.shape_properties {
            v.write_to(writer);
        }

        // c:txPr
        if let Some(v) = &self.text_properties {
            v.write_to(writer);
        }

        // c:crossAx
        self.crossing_axis.write_to(writer);

        // c:crosses
        self.crosses.write_to(writer);

        // c:crossBetween
        self.cross_between.write_to(writer);

        write_end_tag(writer, "c:valAx");
    }
}