Skip to content

Implement Charts - #683

Open
ddimaria wants to merge 1 commit into
tafia:masterfrom
ddimaria:implement-charts
Open

ddimaria wants to merge 1 commit into
tafia:masterfrom
ddimaria:implement-charts

Conversation

@ddimaria

@ddimaria ddimaria commented Jul 16, 2026

Copy link
Copy Markdown

Summary

Adds chart reading to the XLSX reader via two new methods:

let charts: Vec<Chart> = workbook.worksheet_charts("Sheet1")?;
let charts = workbook.worksheet_charts_at(0);

The reader walks the worksheet (or chartsheet) relationships to the drawing part, collects the anchored chart frames (two-cell, one-cell and absolute anchors, including their positions), and parses each chart part into a public Chart data model in the new chart module. The API is modelled after rust_xlsxwriter's chart types so the two crates feel symmetrical (write with rust_xlsxwriter, read back with calamine).

Also exposes the workbook theme palette:

let theme: ThemeColors = workbook.theme_colors();
let series_color = theme.accents()[0]; // Excel's default color for an unstyled first series

ThemeColors has named slots (dark1/light1/dark2/light2, accent1accent6, hyperlink, followed_hyperlink), parsed once from xl/theme/theme1.xml, cached and reused by chart/style/conditional-formatting parsing, and falling back to the default Office palette (never errors). Consumers need it to color unstyled chart series the way Excel does (the theme accent cycle) without re-opening the package themselves.

Supported

  • All classic ECMA-376 chart families: bar, column, line, pie, doughnut, pie-of-pie/bar-of-pie, area, scatter, radar, stock, bubble and surface — including stacked, percent-stacked and 3D variants (with standard vs clustered 3D grouping distinguished), wireframe/contour surfaces, and combo charts (multiple plot groups per chart).
  • Excel 2016+ chart-ex parts (xl/charts/chartExN.xml): funnel, treemap, sunburst, histogram, pareto, box & whisker, waterfall and filled map, including the mc:AlternateContent drawing anchors, the chartEx relationship type, and per-series layout options (ChartExLayout: histogram binning, waterfall subtotals/connector lines, box & whisker statistics and element visibility, treemap parent label layout).
  • Series: range formulas plus cached values, multi-level (hierarchical) category caches with all levels preserved, names, per-point formatting, markers, smoothing, pie explosion, data labels (including per-point c:dLbl overrides with delete/custom text/position), trendlines (all six types), error bars, invert-if-negative.
  • Axes: category/value/date/series types, position, min/max, log base, reversed, units, tick marks, tick-label position, crossing, crossing partner (c:crossAx), cross-between, display units, gridlines, number formats, titles, fonts and label text rotation.
  • Chart/group options: titles (rich text and formula-linked), legends, 3D view settings (rotX/rotY/perspective/depth, per Correct MBSC to MBCS in vba.rs #180 in rust_xlsxwriter), gap/overlap, hole size, first slice angle, bubble scale/size-represents, pie-of-pie split settings (including c:custSplit point lists), up/down bars, drop lines, high-low lines, series lines, data tables, dispBlanksAs, and the chart-space flags autoTitleDeleted/plotVisOnly/showDLblsOverMax/date1904.
  • Formatting: solid/gradient/pattern fills (with linear gradient angle), line width/dash/color, fonts, with DrawingML scheme-color resolution against the workbook theme (including lum/tint/shade modifiers).
  • Anchors: ChartPosition carries the anchor cells/extents plus editAs (move/size behavior) and the absolute anchor x/y position.

Not read (documented in the module docs)

Pivot chart sources, manual plot-area layouts, and surface band formats.

Test plan

  • tests/charts.xlsx fixture (pre-generated, committed to tests/ per the feedback on feat(xlsx): implement cell style extraction with rich text and worksheet layout #653 — no generator or dev-dependency added) with 18 classic charts + 5 chart-ex charts exercising every family and the options above.
  • 36 chart integration/unit tests, including exhaustive resolve_chart_type mapping tests, theme palette tests against both a default-theme and a real Excel theme, and a real Excel-generated chartsheet (tests/issue438.xlsx).
  • Full suite passes with --all-features; clippy and rustdoc clean.

Notes

Stacked on #653 (styles) and #628 (conditional formatting); the first two commits here are those PRs. Only the feat(xlsx): implement chart reading commit is new — happy to rebase once the parents land.

@ddimaria ddimaria changed the title feat(xlsx): implement chart reading Implement Charts Jul 16, 2026
@ddimaria
ddimaria force-pushed the implement-charts branch 3 times, most recently from 09469f1 to 8c4c572 Compare September 17, 2026 13:29
Add three related xlsx reading features in a single commit.

Cell styles and worksheet layout:
- `Xlsx::worksheet_style(sheet)` returns a row x col grid of cell styles
  using run-length encoding for memory efficiency on large workbooks.
- `Xlsx::worksheet_layout(sheet)` returns column widths and row heights.
- Style types in `src/style.rs`: `Style` with optional Font / Fill /
  Borders / Alignment / NumberFormat / Protection, `Color` with theme +
  tint resolution and indexed-color fallback, `RichText` / `TextRun`
  for cells with mixed inline formatting, and `StyleRange` with RLE
  storage and a `cells()` iterator.
- Parser in `src/xlsx/style_parser.rs` handles fonts, fills, borders,
  number formats (built-in + custom), alignment, protection, theme
  colors with tint, and sysClr lastClr fallback.
- Shared-string reader now decodes rich text runs and preserves their
  formatting, while also handling plain text that precedes rich runs
  (consistent with upstream PR tafia#637).

Conditional formatting:
- `Xlsx::worksheet_conditional_formatting(sheet)` parses
  `<conditionalFormatting>` blocks including rule types, operators,
  cfvo thresholds, dxf styles, color scales, data bars, and icon sets.

Charts:
- `Xlsx::worksheet_charts(sheet)` reads chart definitions from
  drawing relationships (`src/chart.rs`, `src/xlsx/chart_parser.rs`),
  covering bar, line, pie, area, scatter, radar, and combo charts,
  including series ranges, titles, axes, legends, and styling.

Includes benchmarks in `benches/style.rs` and test fixtures covering
the various code paths.
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.

1 participant