mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-25 19:26:50 -06:00
This commit is contained in:
@@ -193,8 +193,11 @@ pub fn read_chart(root: &El) -> Option<Chart> {
|
||||
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);
|
||||
|
||||
@@ -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!("<c:ser><c:idx val=\"{i}\"/><c:order val=\"{i}\"/><c:val><c:numRef><c:f>Data!$A$1:$A$5</c:f></c:numRef></c:val></c:ser>")
|
||||
}
|
||||
|
||||
const AX: &str = "<c:axId val=\"1\"/><c:axId val=\"2\"/>";
|
||||
|
||||
fn bar(sers: &str) -> String {
|
||||
format!("<c:barChart><c:barDir val=\"col\"/><c:grouping val=\"clustered\"/>{sers}{AX}</c:barChart>")
|
||||
}
|
||||
|
||||
fn line(sers: &str) -> String {
|
||||
format!("<c:lineChart><c:grouping val=\"standard\"/>{sers}{AX}</c:lineChart>")
|
||||
}
|
||||
|
||||
fn kinds(first: &str, second: &str) -> Vec<Option<ChartKind>> {
|
||||
let xml = format!(
|
||||
"<c:chartSpace xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\">\
|
||||
<c:chart><c:plotArea>{first}{second}</c:plotArea></c:chart></c:chartSpace>"
|
||||
);
|
||||
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));
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
mod array_export;
|
||||
mod chart_bool_default;
|
||||
mod chart_combo_kinds;
|
||||
mod csv_tests;
|
||||
mod encrypted_tests;
|
||||
mod fixtures;
|
||||
|
||||
Reference in New Issue
Block a user