mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-29 17:56:18 +01:00
fix(xlsx): preserve explicit and automatic chart title semantics across craft-drawingml
This commit is contained in:
1 parent
ed6ab029e8
commit
b8dcf17039
1 file changed
+27
-8
@@ -419,6 +419,23 @@ const DASHES: [(LineDash, &str); 11] = [
|
||||
|
||||
const EMU_PER_PT: f64 = 12_700.0;
|
||||
|
||||
fn rich_title(t: &El) -> Option<String> {
|
||||
let tx = t.child("tx")?;
|
||||
if let Some(rich) = tx.child("rich") {
|
||||
let paras: Vec<String> =
|
||||
rich.kids("p").map(|p| p.kids("r").filter_map(|r| r.child("t")).map(|t| t.text.as_str()).collect::<String>()).collect();
|
||||
let s = paras.join("\n");
|
||||
return if s.is_empty() { None } else { Some(s) };
|
||||
}
|
||||
if let Some(sr) = tx.child("strRef") {
|
||||
if let Some(v) = sr.path(&["strCache", "pt", "v"]) {
|
||||
return Some(v.text.clone());
|
||||
}
|
||||
return sr.child("f").map(|f| f.text.trim().to_string());
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub(crate) fn from_dml_chart(dc: DmlChart, root: Option<&El>, budget: &mut ChartReadBudget) -> (Chart, Vec<PivotSeriesCache>) {
|
||||
let plot = root.and_then(|r| r.path(&["chart", "plotArea"]));
|
||||
let groups: Vec<&El> = plot.map(|p| p.children.iter().filter(|g| g.name.ends_with("Chart")).collect()).unwrap_or_default();
|
||||
@@ -519,18 +536,20 @@ pub(crate) fn from_dml_chart(dc: DmlChart, root: Option<&El>, budget: &mut Chart
|
||||
};
|
||||
let hole_size =
|
||||
if plot.is_some_and(|p| p.child("doughnutChart").is_some()) { (dc.hole_size * 100.0).round().clamp(10.0, 90.0) as u8 } else { 75 };
|
||||
let auto_title_deleted = root
|
||||
.and_then(|r| r.child("chart"))
|
||||
.is_some_and(|c| c.child("title").is_none() && c.child("autoTitleDeleted").is_some_and(|d| d.flag("val", true)));
|
||||
// No `<c:title>`: an automatic title (a lone series' name), unless the file deleted it.
|
||||
let title = match root.and_then(|r| r.child("chart")) {
|
||||
Some(c) => match c.child("title") {
|
||||
Some(t) => rich_title(t).or(dc.title),
|
||||
None if c.child("autoTitleDeleted").is_some_and(|d| d.flag("val", true)) => Some(String::new()),
|
||||
None => None,
|
||||
},
|
||||
None => dc.title,
|
||||
};
|
||||
let ch = Chart {
|
||||
id: 0,
|
||||
kind,
|
||||
anchor: Default::default(),
|
||||
title: match dc.title {
|
||||
Some(t) => Some(t),
|
||||
None if auto_title_deleted => Some(String::new()),
|
||||
None => None,
|
||||
},
|
||||
title,
|
||||
series,
|
||||
legend,
|
||||
data_labels: dc.data_labels || series_labels,
|
||||
|
||||
Reference in new issue
Block a user