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
//! Plot (chart group) within a chart.
use crate::enums::chart::XlChartType;
use super::datalabel::DataLabels;
use super::plot::PlotProperties;
use super::series::SeriesCollection;
/// A single plot (chart group) within a chart.
///
/// A plot represents one chart type element (e.g. `<c:barChart>`) in the
/// plot area. A chart may contain multiple plots to create combo charts.
#[derive(Debug, Clone)]
pub struct Plot {
/// The chart type for this plot.
pub chart_type: XlChartType,
/// The series belonging to this plot.
pub series: SeriesCollection,
/// Plot-level properties (`gap_width`, overlap, etc.).
pub plot_properties: PlotProperties,
/// Data labels for the entire plot (applied to all series unless overridden).
pub data_labels: Option<DataLabels>,
/// Whether the plot has data labels enabled.
pub has_data_labels: bool,
/// Category labels shared by all series in the plot.
pub categories: Option<Vec<String>>,
}
impl Plot {
/// Create a new plot for the given chart type.
#[must_use]
pub const fn new(chart_type: XlChartType) -> Self {
Self {
chart_type,
series: SeriesCollection::new(),
plot_properties: PlotProperties::new(),
data_labels: None,
has_data_labels: false,
categories: None,
}
}
/// The series collection for this plot.
#[must_use]
pub const fn series(&self) -> &SeriesCollection {
&self.series
}
/// Mutable access to the series collection.
pub fn series_mut(&mut self) -> &mut SeriesCollection {
&mut self.series
}
/// The plot-level properties.
#[must_use]
pub const fn plot_properties(&self) -> &PlotProperties {
&self.plot_properties
}
/// Mutable access to plot properties.
pub fn plot_properties_mut(&mut self) -> &mut PlotProperties {
&mut self.plot_properties
}
/// The data labels for this plot, if set.
#[must_use]
pub const fn data_labels(&self) -> Option<&DataLabels> {
self.data_labels.as_ref()
}
/// Mutable access to the data labels. Creates a default if None.
pub fn data_labels_mut(&mut self) -> &mut DataLabels {
self.has_data_labels = true;
self.data_labels.get_or_insert_with(DataLabels::new)
}
/// Set the data labels for this plot.
pub fn set_data_labels(&mut self, data_labels: DataLabels) {
self.has_data_labels = true;
self.data_labels = Some(data_labels);
}
}