mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-30 10:13:56 +01:00
Insert > Line or Area and the All Charts list offer 100% Stacked Line and 100% Stacked Line with Markers, and insert.chart and chart.set take them as type line with subtype stacked100 or stacked100Markers. Each series' line is drawn at the running sum of its share of the category's total and the shares before it, so when no value is negative, the last series reaches the top in every category with a nonzero total. When every series on the value axis is 100% stacked and no value is negative, the axis runs from 0% to 100%. The with-markers kind draws a marker at each point. An XLSX line chart with percentStacked grouping now opens as 100% stacked, with markers unless every series has the marker symbol none or the group turns markers off, and is saved back as percentStacked. It used to open as a stacked line and was saved as stacked. A 100% stacked line series in a combo chart is still saved as a standard line.
39 lines
1.6 KiB
Rust
39 lines
1.6 KiB
Rust
//! The 100% stacked line charts: `insert.chart` and `chart.set` take type `line` with subtype
|
|
//! `stacked100` or `stacked100Markers`.
|
|
|
|
use gridcraft_engine::Session;
|
|
use gridcraft_model::ChartKind;
|
|
use serde_json::json;
|
|
|
|
fn session() -> Session {
|
|
let mut s = Session::new();
|
|
s.new_workbook();
|
|
s.execute("range.setValues", json!({"range": "A1", "values": [["Quarter", "North", "South"], ["Q1", "10", "30"], ["Q2", "30", "10"]]})).unwrap();
|
|
s
|
|
}
|
|
|
|
fn kinds(s: &Session) -> Vec<ChartKind> {
|
|
s.doc().unwrap().wb.sheet(0).unwrap().charts.iter().map(|c| c.kind).collect()
|
|
}
|
|
|
|
#[test]
|
|
fn insert_chart_makes_hundred_percent_stacked_lines() {
|
|
let mut s = session();
|
|
s.execute("insert.chart", json!({"range": "A1:C3", "type": "line", "subtype": "stacked100"})).unwrap();
|
|
s.execute("insert.chart", json!({"range": "A1:C3", "type": "line", "subtype": "stacked100Markers"})).unwrap();
|
|
assert_eq!(kinds(&s), [ChartKind::LineStacked100, ChartKind::LineStacked100Markers]);
|
|
}
|
|
|
|
#[test]
|
|
fn chart_set_changes_a_chart_to_a_hundred_percent_stacked_line_and_back() {
|
|
let mut s = session();
|
|
s.execute("insert.chart", json!({"range": "A1:C3", "type": "line", "subtype": "stacked"})).unwrap();
|
|
assert_eq!(kinds(&s), [ChartKind::LineStacked]);
|
|
s.execute("chart.set", json!({"type": "line", "subtype": "stacked100Markers"})).unwrap();
|
|
assert_eq!(kinds(&s), [ChartKind::LineStacked100Markers]);
|
|
s.execute("chart.set", json!({"type": "line", "subtype": "stacked100"})).unwrap();
|
|
assert_eq!(kinds(&s), [ChartKind::LineStacked100]);
|
|
s.execute("edit.undo", json!({})).unwrap();
|
|
assert_eq!(kinds(&s), [ChartKind::LineStacked100Markers]);
|
|
}
|