betteroffice-drawingml 0.5.1

Shared DrawingML colors, themes, shape models, and preset geometry.
Documentation
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
use serde::{Deserialize, Serialize};

/// A parsed `c:chartSpace`, free of any host-package metadata.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChartSpace {
    pub chart_type: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub legend: Option<ChartLegend>,
    pub series: Vec<ChartSeries>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub axes: Option<ChartAxes>,
    pub plot_groups: Vec<ChartPlotGroup>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub axis_list: Option<Vec<ChartAxis>>,
    /// `c:txPr` on `c:chartSpace`: the root of chart text inheritance.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub text: Option<ChartTextProperties>,
    /// `c:txPr` on `c:title`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub title_text: Option<ChartTextProperties>,
    /// `c:chartSpace/c:spPr`: the chart's own background paint.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fill: Option<ChartFill>,
    /// `c:plotArea/c:layout/c:manualLayout`, when it places the inner plot.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub plot_layout: Option<ChartManualLayout>,
}

/// A `c:manualLayout` that places a chart part as fractions of the frame.
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChartManualLayout {
    pub x: f64,
    pub y: f64,
    pub w: f64,
    pub h: f64,
}

/// The fill of a `c:spPr`. Absent means the host paints its own default.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(
    tag = "kind",
    rename_all = "camelCase",
    rename_all_fields = "camelCase"
)]
pub enum ChartFill {
    /// `a:noFill`: nothing is painted, so whatever sits behind shows through.
    None,
    Solid {
        color: String,
    },
    /// `a:pattFill`, kept as its two colours: no host paints a hatch yet.
    Pattern {
        #[serde(default, skip_serializing_if = "Option::is_none")]
        foreground: Option<String>,
        #[serde(default, skip_serializing_if = "Option::is_none")]
        background: Option<String>,
    },
    /// `a:gradFill`, kept as its stop colours.
    Gradient {
        colors: Vec<String>,
    },
    /// Another fill, such as `a:blipFill`, painted in the host's default.
    Unsupported,
}

/// The `a:ln` of a `c:spPr`.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChartLine {
    /// `a:ln/a:noFill`: the outline is declared and switched off.
    pub none: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub color: Option<String>,
    /// `a:ln/@w`, in EMU.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub width_emu: Option<f64>,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct ChartLegend {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub position: Option<String>,
    pub visible: bool,
    /// `c:overlay`: the legend sits on the plot instead of taking a band of it.
    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
    pub overlay: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub text: Option<ChartTextProperties>,
}

/// Run properties read off a `c:txPr`, all optional so an absent one inherits.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChartTextProperties {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub font: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub size_pt: Option<f64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub bold: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub italic: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub color: Option<String>,
    /// `a:defRPr/@spc`, in points: tracking added after every cluster.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub spacing_pt: Option<f64>,
}

impl ChartTextProperties {
    pub fn is_empty(&self) -> bool {
        *self == Self::default()
    }

    /// `self` over `base`, field by field.
    pub fn over(self, base: &Self) -> Self {
        Self {
            font: self.font.or_else(|| base.font.clone()),
            size_pt: self.size_pt.or(base.size_pt),
            bold: self.bold.or(base.bold),
            italic: self.italic.or(base.italic),
            color: self.color.or_else(|| base.color.clone()),
            spacing_pt: self.spacing_pt.or(base.spacing_pt),
        }
    }
}

/// A cell the sheet left blank has no number. It travels as `null`, because
/// JSON has no NaN and the plot has to keep the blank in place to line the
/// values up with their categories.
pub mod blank_numbers {
    use serde::{Deserialize, Deserializer, Serialize, Serializer};

    pub fn serialize<S: Serializer>(values: &[f64], serializer: S) -> Result<S::Ok, S::Error> {
        values
            .iter()
            .map(|value| value.is_finite().then_some(*value))
            .collect::<Vec<_>>()
            .serialize(serializer)
    }

    pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Vec<f64>, D::Error> {
        Ok(Vec::<Option<f64>>::deserialize(deserializer)?
            .into_iter()
            .map(|value| value.unwrap_or(f64::NAN))
            .collect())
    }

    pub mod optional {
        use serde::{Deserialize, Deserializer, Serialize, Serializer};

        pub fn serialize<S: Serializer>(
            values: &Option<Vec<f64>>,
            serializer: S,
        ) -> Result<S::Ok, S::Error> {
            values
                .as_ref()
                .map(|values| {
                    values
                        .iter()
                        .map(|value| value.is_finite().then_some(*value))
                        .collect::<Vec<_>>()
                })
                .serialize(serializer)
        }

        pub fn deserialize<'de, D: Deserializer<'de>>(
            deserializer: D,
        ) -> Result<Option<Vec<f64>>, D::Error> {
            Ok(
                Option::<Vec<Option<f64>>>::deserialize(deserializer)?.map(|values| {
                    values
                        .into_iter()
                        .map(|value| value.unwrap_or(f64::NAN))
                        .collect()
                }),
            )
        }
    }
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChartSeries {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    pub categories: Vec<String>,
    #[serde(with = "blank_numbers")]
    pub values: Vec<f64>,
    pub color: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub index: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub category_formula: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub value_formula: Option<String>,
    /// `c:val/c:numRef/c:numCache/c:formatCode`: the format the values were
    /// cached with, which source-linked data labels read.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub value_format: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub axis_ids: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub points: Option<Vec<ChartPoint>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub grouping: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub marker: Option<ChartMarker>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub smooth: Option<bool>,
    /// `c:xVal` of a scatter or bubble series.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        with = "blank_numbers::optional"
    )]
    pub x_values: Option<Vec<f64>>,
    /// `c:bubbleSize` of a bubble series.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        with = "blank_numbers::optional"
    )]
    pub bubble_sizes: Option<Vec<f64>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data_labels: Option<ChartDataLabels>,
    /// `c:ser/c:spPr/a:ln`: the stroke of this series' own line.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub line: Option<ChartLine>,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct ChartMarker {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub symbol: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub size: Option<f64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub color: Option<String>,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct ChartPoint {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub index: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub explosion: Option<f64>,
    pub color: String,
}

/// A `c:dLbls`, every switch optional so an unset one inherits its parent.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChartDataLabels {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub delete: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub show_value: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub show_category_name: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub show_series_name: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub show_percent: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub show_legend_key: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub show_bubble_size: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub separator: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub position: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub number_format: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub text: Option<ChartTextProperties>,
    /// Per-point `c:dLbl` overrides; never nested further.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub points: Option<Vec<ChartPointLabel>>,
}

/// One `c:dLbl`: an index plus the switches that override the series default.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChartPointLabel {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub index: Option<f64>,
    /// Literal `c:tx` text, which replaces every composed field.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub text: Option<String>,
    /// `c:tx` split at its `a:fld` boundaries, when it has any.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub runs: Option<Vec<ChartLabelRun>>,
    pub labels: ChartDataLabels,
}

/// A piece of a `c:tx` label: text the deck wrote, or a field PowerPoint
/// recomputes from the point every time it draws.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum ChartLabelRun {
    Text(String),
    /// `a:fld/@type`, e.g. `VALUE` or `CATEGORYNAME`.
    Field(String),
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChartPlotGroup {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub chart_type: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub grouping: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub overlap: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub gap_width: Option<f64>,
    pub axis_ids: Vec<String>,
    pub series: Vec<ChartSeries>,
    pub vary_colors: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub first_slice_angle: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub hole_size: Option<f64>,
    pub show_data_labels: bool,
    /// `c:scatterStyle`: `lineMarker`, `marker`, `smoothMarker`, `line`, `smooth`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub scatter_style: Option<String>,
    /// `c:radarStyle`: `standard`, `marker`, `filled`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub radar_style: Option<String>,
    /// `c:bubbleScale`, a percentage of the default bubble size.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub bubble_scale: Option<f64>,
    /// `c:sizeRepresents`: `area` or `w`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub size_represents: Option<String>,
    /// `c:wireframe` of a surface chart.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub wireframe: Option<bool>,
    /// `c:hiLowLines` of a stock or line chart.
    #[serde(default)]
    pub hi_low_lines: bool,
    /// `c:upDownBars` of a stock or line chart.
    #[serde(default)]
    pub up_down_bars: bool,
    /// `c:marker` of a line chart, which switches every series marker off.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub marker: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data_labels: Option<ChartDataLabels>,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct ChartAxes {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub category: Option<ChartAxis>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub value: Option<ChartAxis>,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChartAxis {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub labels: Option<Vec<String>>,
    pub axis_type: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub position: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cross_axis_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub crosses: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub crosses_at: Option<f64>,
    /// `c:crossBetween`: `midCat` puts the points on the category ticks.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cross_between: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub major_unit: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub minor_unit: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub logarithmic_base: Option<f64>,
    pub reversed: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub number_format: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub major_tick_mark: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub minor_tick_mark: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tick_label_position: Option<String>,
    pub hidden: bool,
    #[serde(default)]
    pub major_gridlines: bool,
    #[serde(default)]
    pub minor_gridlines: bool,
    /// `c:majorGridlines/c:spPr/a:ln`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub major_gridline_line: Option<ChartLine>,
    /// `c:minorGridlines/c:spPr/a:ln`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub minor_gridline_line: Option<ChartLine>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub text: Option<ChartTextProperties>,
    /// `c:spPr/a:ln` of this axis: the rule drawn along the plot's edge.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub line: Option<ChartLine>,
}