Skip to content

Charts: multi-level category axes (year beside month) read, drawn and written back - #1088

Merged
aiongg merged 1 commit into
storytold:mainfrom
Lexx143:feat/multi-level-categories
Oct 22, 2026
Merged

aiongg merged 1 commit into
storytold:mainfrom
Lexx143:feat/multi-level-categories

Conversation

@Lexx143

@Lexx143 Lexx143 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

A category range two or more columns wide beside a column of values (year beside month, what Excel saves as multiLvlStrRef) was read as one flat list: a 36-row, 2-column range became 72 categories, so the series were squeezed into the left half of the plot with the years and months mixed on one row. Saving wrote the range back as a plain strRef with the flattened cache, so the two-level axis was lost for Excel too. This is the "multi-level categories" item of docs/chart-parity.md § Work.

What changes

  • gridcraft_core::category_levels: the shape of a category range beside its values (levels are the columns when the points run down the rows, the rows when they run along the columns; the innermost level is the column or row nearest the values, up to three outer levels are kept). Shared by the chart and xlsx crates.
  • ChartData.category_levels (serde default): the outer levels, nearest the labels first, one entry per category, non-empty where a group starts, as the cells are. resolve fills it from the range; a plain column is unchanged.
  • Rendering: the outer levels are drawn in rows under the labels, each group's name centred under its categories with a separator at every group boundary, as Excel draws them; in bar charts they stand in columns beside the labels. Forecast slots stay in the last group.
  • XLSX: <c:cat> is written as multiLvlStrRef with multiLvlStrCache (innermost level first, outer levels with only the cells that start a group), so the axis survives a round trip; reading already kept the reference.

Tests

  • category_level_tests (core): wide and tall ranges, the cap, whole columns, literal values.
  • two_level_categories_resolve_and_draw (chart): six evenly spaced labels across the plot instead of twelve slots, the years in a row below them under their own groups, the column-beside-labels layout for bars, a row of values, and a plain column staying flat.
  • multilevel_category_roundtrip (xlsx): the written XML, level caches, a row-of-values layout, read-back of the reference, stability across saves, and a single column staying strRef.
  • Checked on a real monthly report (36 months, a line chart with four series): the lines now span the plot with the years under the months.

cargo test -p gridcraft-core -p gridcraft-chart -p gridcraft-xlsx, cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --check. docs/chart-parity.md, docs/gaps.md § 4 and the ROADMAP.md progress log updated.

🤖 Generated with Claude Code

A category range two or more columns wide beside a column of values (year beside month, Excel's
multiLvlStrRef) was read as one flat list: 36 rows in two columns became 72 categories, the
series sat in the left half of the plot and the years and months shared one row of labels.
Saving wrote the range as a plain strRef, so Excel lost the two-level axis too.

- gridcraft_core::category_levels: the shape of a category range beside its values (levels are
  columns when the points run down the rows, rows when they run along the columns; up to three
  outer levels), shared by the chart and xlsx crates.
- ChartData.category_levels: the outer levels, nearest the labels first, one entry per category,
  non-empty where a group starts. resolve fills it; a single column is unchanged.
- render: the outer levels in rows under the labels, a group's name centred under its categories
  with a separator at each boundary; in bar charts in columns beside the labels.
- xlsx: <c:cat> written as multiLvlStrRef with the level caches (innermost first), so the axis
  survives a round trip.

Tests in core (shapes), chart (resolve and layout for columns, bars and a row of values) and
xlsx (written XML, read-back, stability, a single column stays strRef). chart-parity, gaps § 4
and the ROADMAP progress log updated.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants