From 04f8797ee46597200b9cc0c23da2e9d3d9eb8550 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 28 Oct 2026 08:04:56 -0700 Subject: [PATCH] XLSX: a 100% stacked line group with mixed markers opens with each series' own markers A single percentStacked line group whose series differ in markers opens as a combo chart, so saving it keeps the marked and unmarked series as they were. --- crates/xlsx/src/chart.rs | 13 +++++++----- .../src/tests/chart_line_percent_stacked.rs | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/crates/xlsx/src/chart.rs b/crates/xlsx/src/chart.rs index bc82effe8..3b3409506 100644 --- a/crates/xlsx/src/chart.rs +++ b/crates/xlsx/src/chart.rs @@ -227,15 +227,18 @@ pub fn read_chart(root: &El) -> Option { let groups: Vec<(&El, ChartKind)> = plot.children.iter().filter_map(|g| group_kind(g).map(|k| (g, k))).collect(); let (first, first_kind) = *groups.first()?; let first_axes = axis_ids(first); + let no_marker = |s: &El| s.path(&["marker", "symbol"]).and_then(|m| m.attr("val")) == Some("none"); + // A 100% stacked line group whose series differ in markers opens as a combo chart, so each series keeps its own. + let mixed = first_kind == ChartKind::LineStacked100Markers && first.kids("ser").any(no_marker) && !first.kids("ser").all(no_marker); + let combo = groups.len() > 1 || mixed; let mut series = vec![]; let mut orders = vec![]; for (gi, (g, k)) in groups.iter().enumerate() { for s in g.kids("ser") { let mut ser = read_series(s); - if groups.len() > 1 { + if combo { // Every series of a combo chart keeps its own group's kind, the first group's included. - let no_marker = s.path(&["marker", "symbol"]).and_then(|m| m.attr("val")) == Some("none"); - ser.kind = Some(if *k == ChartKind::LineStacked100Markers && no_marker { ChartKind::LineStacked100 } else { *k }); + ser.kind = Some(if *k == ChartKind::LineStacked100Markers && no_marker(s) { ChartKind::LineStacked100 } else { *k }); } if gi > 0 { ser.secondary = axis_ids(g) != first_axes; @@ -245,12 +248,12 @@ pub fn read_chart(root: &El) -> Option { } } // A combo chart lists its series group by group; `c:order` gives the order they are drawn in. - if groups.len() > 1 && orders.iter().all(Option::is_some) { + if combo && orders.iter().all(Option::is_some) { let mut keyed: Vec<(Option, Series)> = orders.into_iter().zip(series).collect(); keyed.sort_by_key(|(o, _)| *o); series = keyed.into_iter().map(|(_, s)| s).collect(); } - let kind = if groups.len() > 1 { ChartKind::Combo } else { first_kind }; + let kind = if combo { ChartKind::Combo } else { first_kind }; let show_val = |e: &El| e.child("dLbls").is_some_and(|d| bool_val(d, "showVal")); let data_labels = groups.iter().any(|(g, _)| show_val(g) || g.kids("ser").any(show_val)); let val_axes: Vec<&El> = plot.kids("valAx").collect(); diff --git a/crates/xlsx/src/tests/chart_line_percent_stacked.rs b/crates/xlsx/src/tests/chart_line_percent_stacked.rs index 20bdac29e..e9dcaed9d 100644 --- a/crates/xlsx/src/tests/chart_line_percent_stacked.rs +++ b/crates/xlsx/src/tests/chart_line_percent_stacked.rs @@ -131,6 +131,26 @@ fn secondary_columns_lines_and_hundred_percent_stacked_lines_keep_their_kinds_wh assert_eq!(again.series.iter().map(|s| (s.kind, s.secondary)).collect::>(), want, "{saved}"); } +#[test] +fn a_hundred_percent_stacked_line_group_with_mixed_markers_keeps_each_series_markers() { + let ser = |i: usize, marker: &str| { + format!("{marker}Data!$A$1:$A$5") + }; + let xml = format!( + "\ + {}{}\ + ", + ser(0, ""), + ser(1, NO_MARKER) + ); + let want = [Some(ChartKind::LineStacked100Markers), Some(ChartKind::LineStacked100)]; + let ch = read_chart(&parse(xml.as_bytes()).unwrap()).unwrap(); + assert_eq!(ch.series.iter().map(|s| s.kind).collect::>(), want); + let saved = write_chart(&Workbook::default(), 0, &ch, "Book1"); + let again = read_chart(&parse(saved.as_bytes()).unwrap()).unwrap(); + assert_eq!(again.series.iter().map(|s| s.kind).collect::>(), want, "{saved}"); +} + #[test] fn combo_areas_marked_lines_and_mixed_column_groupings_keep_their_kinds_when_saved() { let ser = |i: usize, marker: &str| {