use crate::enums::chart::XlChartType;
use crate::error::PptxResult;
use super::super::xmlwriter::ChartXmlWriter;
#[derive(Debug, Clone)]
pub struct BubbleChartData {
series: Vec<BubbleSeriesData>,
number_format: String,
}
impl BubbleChartData {
#[must_use]
pub fn new() -> Self {
Self {
series: Vec::new(),
number_format: "General".to_string(),
}
}
pub fn add_series(&mut self, name: &str) -> &mut BubbleSeriesData {
let index = self.series.len();
self.series.push(BubbleSeriesData {
name: name.to_string(),
data_points: Vec::new(),
number_format: None,
index,
});
let idx = self.series.len() - 1;
&mut self.series[idx]
}
#[must_use]
pub fn series(&self) -> &[BubbleSeriesData] {
&self.series
}
#[must_use]
pub fn number_format(&self) -> &str {
&self.number_format
}
pub fn to_xml(&self, chart_type: XlChartType) -> PptxResult<String> {
ChartXmlWriter::write_bubble(self, chart_type)
}
}
impl Default for BubbleChartData {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct BubbleSeriesData {
name: String,
data_points: Vec<BubbleDataPoint>,
number_format: Option<String>,
index: usize,
}
impl BubbleSeriesData {
pub fn add_data_point(&mut self, x: f64, y: f64, size: f64) {
self.data_points.push(BubbleDataPoint { x, y, size });
}
#[must_use]
pub fn name(&self) -> &str {
&self.name
}
#[must_use]
pub fn data_points(&self) -> &[BubbleDataPoint] {
&self.data_points
}
#[must_use]
pub fn x_values(&self) -> Vec<f64> {
self.data_points.iter().map(|dp| dp.x).collect()
}
#[must_use]
pub fn y_values(&self) -> Vec<f64> {
self.data_points.iter().map(|dp| dp.y).collect()
}
#[must_use]
pub fn bubble_sizes(&self) -> Vec<f64> {
self.data_points.iter().map(|dp| dp.size).collect()
}
#[must_use]
pub const fn index(&self) -> usize {
self.index
}
#[must_use]
pub fn number_format(&self) -> Option<&str> {
self.number_format.as_deref()
}
}
#[derive(Debug, Clone, Copy)]
pub struct BubbleDataPoint {
pub x: f64,
pub y: f64,
pub size: f64,
}