diff --git a/crates/xlsx/src/chart.rs b/crates/xlsx/src/chart.rs index dee33c83d..cbe8a1eb1 100644 --- a/crates/xlsx/src/chart.rs +++ b/crates/xlsx/src/chart.rs @@ -193,8 +193,11 @@ pub fn read_chart(root: &El) -> Option { for (gi, (g, k)) in groups.iter().enumerate() { for s in g.kids("ser") { let mut ser = read_series(s); - if gi > 0 { + if groups.len() > 1 { + // Every series of a combo chart keeps its own group's kind, the first group's included. ser.kind = Some(*k); + } + if gi > 0 { ser.secondary = axis_ids(g) != first_axes; } series.push(ser); diff --git a/crates/xlsx/src/tests/chart_combo_kinds.rs b/crates/xlsx/src/tests/chart_combo_kinds.rs new file mode 100644 index 000000000..6857683ad --- /dev/null +++ b/crates/xlsx/src/tests/chart_combo_kinds.rs @@ -0,0 +1,46 @@ +//! Importing a combination chart keeps each series' own group kind, the first group's included. + +use gridcraft_model::ChartKind; + +use crate::chart::read_chart; +use crate::xml::parse; + +fn ser(i: usize) -> String { + format!("Data!$A$1:$A$5") +} + +const AX: &str = ""; + +fn bar(sers: &str) -> String { + format!("{sers}{AX}") +} + +fn line(sers: &str) -> String { + format!("{sers}{AX}") +} + +fn kinds(first: &str, second: &str) -> Vec> { + let xml = format!( + "\ + {first}{second}" + ); + let root = parse(xml.as_bytes()).unwrap(); + let ch = read_chart(&root).unwrap(); + assert_eq!(ch.kind, ChartKind::Combo); + ch.series.iter().map(|s| s.kind).collect() +} + +#[test] +fn first_group_with_two_columns_stays_columns() { + let k = kinds(&bar(&(ser(0) + &ser(1))), &line(&ser(2))); + assert_eq!(k[0], Some(ChartKind::ColumnClustered)); + assert_eq!(k[1], Some(ChartKind::ColumnClustered)); + assert!(matches!(k[2], Some(ChartKind::Line | ChartKind::LineMarkers))); +} + +#[test] +fn line_first_group_stays_a_line() { + let k = kinds(&line(&ser(0)), &bar(&ser(1))); + assert!(matches!(k[0], Some(ChartKind::Line | ChartKind::LineMarkers))); + assert_eq!(k[1], Some(ChartKind::ColumnClustered)); +} diff --git a/crates/xlsx/src/tests/mod.rs b/crates/xlsx/src/tests/mod.rs index bdbd66e05..37ce246c1 100644 --- a/crates/xlsx/src/tests/mod.rs +++ b/crates/xlsx/src/tests/mod.rs @@ -2,6 +2,7 @@ mod array_export; mod chart_bool_default; +mod chart_combo_kinds; mod csv_tests; mod encrypted_tests; mod fixtures;