mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-23 19:11:46 +01:00
Resolve scatter category axis by position rather than ID order
This commit is contained in:
1 parent
6200c71304
commit
f389c25c23
1 file changed
+16
-1
@@ -518,7 +518,12 @@ fn category_format(pa: &El, group: &El, series: &El) -> Option<String> {
|
||||
matches!(axis.local(), "catAx" | "dateAx")
|
||||
&& axis.child(Local("axId")).and_then(|id| id.attr_local("val")).is_some_and(|id| ids.contains(&id))
|
||||
})
|
||||
.or_else(|| pa.children(Local("valAx")).find(|axis| axis.child(Local("axId")).and_then(|id| id.attr_local("val")) == ids.first().copied()));
|
||||
.or_else(|| {
|
||||
pa.children(Local("valAx")).find(|axis| {
|
||||
matches!(axis.child(Local("axPos")).and_then(|pos| pos.attr_local("val")), Some("b" | "t"))
|
||||
&& axis.child(Local("axId")).and_then(|id| id.attr_local("val")).is_some_and(|id| ids.contains(&id))
|
||||
})
|
||||
});
|
||||
if cat.find(Local("strCache")).or_else(|| cat.find(Local("strLit"))).is_some() {
|
||||
return None;
|
||||
}
|
||||
@@ -1023,6 +1028,16 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scatter_category_format_uses_the_horizontal_axis_regardless_of_id_order() {
|
||||
let xml = format!(
|
||||
r#"<c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"><c:chart><c:plotArea><c:scatterChart><c:ser><c:idx val="0"/><c:xVal>{}</c:xVal></c:ser><c:axId val="4"/><c:axId val="3"/></c:scatterChart><c:valAx><c:axId val="4"/><c:axPos val="l"/><c:numFmt formatCode="0.00" sourceLinked="0"/></c:valAx><c:valAx><c:axId val="3"/><c:axPos val="b"/><c:numFmt formatCode="mmm-yy" sourceLinked="0"/></c:valAx></c:plotArea></c:chart></c:chartSpace>"#,
|
||||
num_cat("m/d/yyyy")
|
||||
);
|
||||
let c = read_chart_xml(xml.as_bytes()).unwrap();
|
||||
assert_eq!(c.category_label(0), "Jan-24");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_categories_ignore_the_axis_number_format() {
|
||||
let strs = r#"<c:strRef><c:strCache><c:ptCount val="2"/><c:pt idx="0"><c:v>2024</c:v></c:pt><c:pt idx="1"><c:v>Q2</c:v></c:pt></c:strCache></c:strRef>"#;
|
||||
|
||||
Reference in new issue
Block a user