Merge pull request #637 from MarekSpodBiedry:issue-518

This commit is contained in:
Brandon Thomas 2026-10-12 23:21:59 -04:00
commit e5071f382b
3 changed files with 35 additions and 2 deletions

View File

@ -106,7 +106,7 @@ fn read_series(s: &El) -> Series {
color,
secondary: false,
kind: None,
smooth: s.child("smooth").and_then(|e| e.attr("val")).and_then(|v| v.parse::<u8>().ok()).is_some_and(|v| v != 0),
smooth: bool_val(s, "smooth"),
trendlines: s.kids("trendline").filter_map(read_trendline).collect(),
}
}
@ -201,7 +201,7 @@ pub fn read_chart(root: &El) -> Option<Chart> {
}
}
let kind = if groups.len() > 1 { ChartKind::Combo } else { first_kind };
let show_val = |e: &El| e.child("dLbls").and_then(|d| d.child_val("showVal")).is_some_and(|v| v == "1" || v == "true");
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();
let cat_ax = plot.child("catAx").or_else(|| plot.child("dateAx"));

View File

@ -0,0 +1,32 @@
//! A `CT_Boolean` chart flag with no `val` attribute is on (ECMA-376), for series smoothing and value labels.
use crate::chart::read_chart;
use crate::xml::parse;
/// Reads a line chart with `ser` appended to its one series and `group` inside the group's `<c:dLbls>`.
fn flags(ser: &str, group: &str) -> (bool, bool) {
let xml = format!(
"<c:chartSpace xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\"><c:chart><c:plotArea><c:lineChart>\
<c:grouping val=\"standard\"/><c:ser><c:idx val=\"0\"/><c:order val=\"0\"/>\
<c:val><c:numRef><c:f>Data!$A$1:$A$5</c:f></c:numRef></c:val>{ser}</c:ser><c:dLbls>{group}</c:dLbls>\
<c:axId val=\"1\"/><c:axId val=\"2\"/></c:lineChart><c:catAx><c:axId val=\"1\"/></c:catAx><c:valAx><c:axId val=\"2\"/></c:valAx>\
</c:plotArea></c:chart></c:chartSpace>"
);
let root = parse(xml.as_bytes()).unwrap();
let ch = read_chart(&root).unwrap();
(ch.series[0].smooth, ch.data_labels)
}
#[test]
fn omitted_val_means_on() {
assert_eq!(flags("<c:smooth/>", "<c:showVal/>"), (true, true));
assert_eq!(flags("<c:dLbls><c:showVal/></c:dLbls>", ""), (false, true), "series-level value labels");
}
#[test]
fn explicit_values_are_honoured() {
assert_eq!(flags("<c:smooth val=\"1\"/>", "<c:showVal val=\"1\"/>"), (true, true));
assert_eq!(flags("<c:smooth val=\"true\"/>", "<c:showVal val=\"true\"/>"), (true, true));
assert_eq!(flags("<c:smooth val=\"0\"/>", "<c:showVal val=\"0\"/>"), (false, false));
assert_eq!(flags("", ""), (false, false));
}

View File

@ -1,6 +1,7 @@
//! Integration-style tests: round trips, hand-written fixtures, hostile input and CSV.
mod array_export;
mod chart_bool_default;
mod csv_tests;
mod encrypted_tests;
mod fixtures;