From aed303e504d9cb07f62c12ebd440efcef1746951 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 24 Oct 2026 06:15:41 +0000 Subject: [PATCH] Integration: #956 chart.options dataLabels resets the series' own settings Without it, turning Data Labels on did nothing for an imported chart whose series read showVal 0. --- crates/engine/src/cmd/insert.rs | 4 ++++ crates/pptx/tests/chart_data_labels.rs | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/crates/engine/src/cmd/insert.rs b/crates/engine/src/cmd/insert.rs index 4f28ddef..c0966f99 100644 --- a/crates/engine/src/cmd/insert.rs +++ b/crates/engine/src/cmd/insert.rs @@ -1818,6 +1818,10 @@ fn chart_options(s: &mut Session, p: &Value) -> Result { } if let Some(v) = bool_param(p, "dataLabels") { c.data_labels = v; + // A series' own setting would otherwise keep overriding the chart-wide switch. + for series in &mut c.series { + series.data_labels = None; + } } if let Some(v) = bool_param(p, "gridlines") { c.gridlines = v; diff --git a/crates/pptx/tests/chart_data_labels.rs b/crates/pptx/tests/chart_data_labels.rs index d89fae53..09e35cca 100644 --- a/crates/pptx/tests/chart_data_labels.rs +++ b/crates/pptx/tests/chart_data_labels.rs @@ -152,3 +152,24 @@ fn a_combo_chart_keeps_each_groups_own_label_setting() { assert!(!c.series_data_labels(&c.series[0]), "so the bars stay quiet"); assert!(c.series_data_labels(&c.series[1]), "the line takes the chart-wide on"); } + +/// Turning Data Labels on through `chart.options` shows the labels of series that the file +/// switched off one by one. +#[test] +fn chart_options_data_labels_on_overrides_series_off() { + use deckcraft_engine::Session; + let p = reimport(&bar_chart_pptx(), |xml| xml.replace("", r#""#)); + assert!(chart_of(&p).series.iter().all(|s| !chart_of(&p).series_data_labels(s)), "every series starts quiet"); + let path = std::env::temp_dir().join("deckcraft_series_labels_off.pptx"); + std::fs::write(&path, deckcraft_pptx::export(&p).expect("export")).expect("write"); + let mut s = Session::with_new(); + s.execute("file.open", &serde_json::json!({"path": path.to_string_lossy()})).expect("open"); + let doc = s.doc().unwrap().doc.clone(); + let id = doc.slides[0].shapes.iter().find(|sh| matches!(sh.kind, ShapeKind::Chart(_))).expect("chart").id.0; + assert!(chart_of(&doc).series.iter().all(|x| !chart_of(&doc).series_data_labels(x))); + s.execute("chart.options", &serde_json::json!({"id": id, "dataLabels": true})).expect("options"); + let doc = s.doc().unwrap().doc.clone(); + let c = chart_of(&doc); + assert!(c.series.iter().all(|x| c.series_data_labels(x)), "every series shows its labels"); + let _ = std::fs::remove_file(path); +}