macro_rules! write_str {
($dst:expr, $($arg:tt)*) => {
write!($dst, $($arg)*).unwrap_or_else(|_| unreachable!("fmt::Write for String is infallible"))
};
}
mod category_area_radar;
mod category_bar_line;
mod category_pie;
mod category_tests;
mod category_tests_3d;
mod combo;
mod helpers;
mod stock;
mod surface;
mod xy_bubble;
use crate::enums::chart::XlChartType;
use crate::error::PptxResult;
use crate::xml_util::write_xml_escaped;
use super::data::CategoryChartData;
pub struct ChartXmlWriter;
fn xml_escape_to(w: &mut String, s: &str) {
write_xml_escaped(w, s).unwrap_or_else(|_| unreachable!("write to String should not fail"));
}
impl ChartXmlWriter {
pub fn write_category(data: &CategoryChartData, chart_type: XlChartType) -> PptxResult<String> {
match chart_type {
ct if ct.is_combo_type() => Err(crate::error::PptxError::InvalidXml(
"combo charts require ComboChartData; use ComboChartData::to_xml() instead"
.to_string(),
)),
ct if ct.is_stock_type() => Ok(Self::write_stock_chart(data, chart_type)),
ct if ct.is_surface_type() => Ok(Self::write_surface_chart(data, chart_type)),
ct if ct.is_bar_or_column() => Ok(Self::write_bar_chart(data, chart_type)),
ct if ct.is_line_type() => Ok(Self::write_line_chart(data, chart_type)),
ct if ct.is_pie_type() => Ok(Self::write_pie_chart(data, chart_type)),
ct if ct.is_doughnut_type() => Ok(Self::write_doughnut_chart(data, chart_type)),
ct if ct.is_area_type() => Ok(Self::write_area_chart(data, chart_type)),
ct if ct.is_radar_type() => Ok(Self::write_radar_chart(data, chart_type)),
_ => Err(crate::error::PptxError::InvalidXml(format!(
"unsupported category chart type: {chart_type:?}"
))),
}
}
pub fn write_xy(
data: &super::data::XyChartData,
chart_type: XlChartType,
) -> PptxResult<String> {
Ok(Self::write_scatter_chart(data, chart_type))
}
pub fn write_bubble(
data: &super::data::BubbleChartData,
chart_type: XlChartType,
) -> PptxResult<String> {
Ok(Self::write_bubble_chart(data, chart_type))
}
}