Skip to content

feat(xlsx): chart theme color refs (schemeClr) + line cap/compound on all host borders#322

Open
productdevbook wants to merge 1 commit into
mainfrom
feat/chart-theme-colors-line-style
Open

feat(xlsx): chart theme color refs (schemeClr) + line cap/compound on all host borders#322
productdevbook wants to merge 1 commit into
mainfrom
feat/chart-theme-colors-line-style

Conversation

@productdevbook
Copy link
Copy Markdown
Owner

Summary

Two related improvements to the chart fill / line surface:

A. Theme color refs (<a:schemeClr>)

Adds public types ChartThemeColor / ChartColor (= string | ChartThemeColor) and widens every chart fill / line / typography color slot to accept either a literal sRGB hex string or a named theme color reference with optional lumMod / lumOff / tint / shade / alpha modifiers.

  • Reader: parseSpPrFill / parseSpPrBorderColor now walk both <a:srgbClr> and <a:schemeClr> and surface theme references as { theme, lumMod?, lumOff?, tint?, shade?, alpha? } objects. Added parseSchemeClr helper.
  • Writer: New buildColorElement / buildSolidFill / normalizeChartColor helpers. Every emit-color helper now switches on input type — string emits <a:srgbClr>, ChartThemeColor emits <a:schemeClr> with mods in OOXML schema order (tint → shade → alpha → lumMod → lumOff).
  • Clone-through: Standard undefined (inherit) / null (drop) / value (replace) grammar.

Affected fields: chartSpaceFillColor, chartSpaceBorderColor, plotAreaFillColor, plotAreaBorderColor, legendFillColor, legendBorderColor, legendFontColor, titleColor, titleFillColor, titleBorderColor, axis axisTitleColor / axisTitleFillColor / axisTitleBorderColor / labelColor, dataTable fontColor / fillColor / borderColor, dataLabels fontColor / fillColor / borderColor, legendEntries[].color, series color, marker fill / line, dataPoint fillColor / borderColor. Non-breaking: the type widens (stringChartColor), it never narrows.

B. Line cap & compound on every host's <a:ln>

Extends cap (OOXML ST_LineCap) and cmpd (OOXML ST_CompoundLine) beyond the per-series ChartLineStroke to every chart host that owns an <a:ln> slot:

  • SheetChart: chartSpaceBorderCap / chartSpaceBorderCompound, plotAreaBorderCap / plotAreaBorderCompound, legendBorderCap / legendBorderCompound, titleBorderCap / titleBorderCompound
  • SheetChart.axes.x / .y: axisTitleBorderCap / axisTitleBorderCompound
  • ChartDataTable: borderCap / borderCompound
  • ChartDataLabels: borderCap / borderCompound
  • Mirrored on the read-side Chart / ChartAxisInfo / ChartDataLabelsInfo interfaces

OOXML defaults (cap="flat" / cmpd="sng") round-trip as absence — the writer never emits an attribute Excel itself omits on freshly-drawn charts. Reader / writer / clone-through all share the central parseBorderCapFromSpPr / parseBorderCompoundFromSpPr / normalizeLineCap / normalizeLineCompound / resolveLineCap / resolveLineCompound helpers in chart/shape.ts.

Test count delta: +54 tests (7466 → 7520).

Test plan

  • pnpm typecheck passes
  • pnpm build succeeds
  • pnpm test passes — 7520 / 7520
  • Theme name validation, mod combinations, schemeClr ↔ srgbClr round-trips, malformed-mod drops
  • Cap / compound parse, write, clone-through on every host
  • writeXlsx end-to-end round-trip (theme color + cap / compound)

🤖 Generated with Claude Code

… all host borders

Two related improvements to the chart fill / line surface:

A. Theme color refs (`<a:schemeClr>`)

Add `ChartThemeColor` and `ChartColor` (= `string | ChartThemeColor`)
public types and widen every chart fill / line / typography color slot
to accept either a literal sRGB hex string or a named theme color
reference with optional luminance / tint / shade / alpha modifiers.

Reader:
- `parseSpPrFill` / `parseSpPrBorderColor` now walk both `<a:srgbClr>`
  and `<a:schemeClr>` and surface theme references as
  `{ theme, lumMod?, lumOff?, tint?, shade?, alpha? }` objects.
- New helpers: `parseSchemeClr`, `parseBorderCapFromSpPr`,
  `parseBorderCompoundFromSpPr`.

Writer:
- New helpers: `buildColorElement`, `buildSolidFill`,
  `normalizeChartColor`, `resolveChartColor`. Every emit-color helper
  now switches on the input type and emits either `<a:srgbClr>` or
  `<a:schemeClr>` with mods in OOXML schema order
  (tint -> shade -> alpha -> lumMod -> lumOff).

Affected fields (read + write + clone): `chartSpaceFillColor`,
`chartSpaceBorderColor`, `plotAreaFillColor`, `plotAreaBorderColor`,
`legendFillColor`, `legendBorderColor`, `legendFontColor`, `titleColor`,
`titleFillColor`, `titleBorderColor`, axis `axisTitleColor` /
`axisTitleFillColor` / `axisTitleBorderColor` / `labelColor`,
`dataTable` `fontColor` / `fillColor` / `borderColor`, `dataLabels`
`fontColor` / `fillColor` / `borderColor`, `legendEntries[].color`,
series `color`, marker `fill` / `line`, dataPoint `fillColor` /
`borderColor`. The type widens to `ChartColor` everywhere a `string`
was previously accepted — non-breaking.

B. Line cap & compound on every host's `<a:ln>`

Extend cap (`ST_LineCap`) and compound (`ST_CompoundLine`) styling
beyond the per-series `ChartLineStroke` to every chart host that owns
an `<a:ln>` slot:
- `SheetChart`: `chartSpaceBorderCap`, `chartSpaceBorderCompound`,
  `plotAreaBorderCap`, `plotAreaBorderCompound`, `legendBorderCap`,
  `legendBorderCompound`, `titleBorderCap`, `titleBorderCompound`.
- `SheetChart.axes.x` / `.y`: `axisTitleBorderCap`,
  `axisTitleBorderCompound`.
- `ChartDataTable`: `borderCap`, `borderCompound`.
- `ChartDataLabels`: `borderCap`, `borderCompound`.
- Mirrored on the read-side `Chart` / `ChartAxisInfo` /
  `ChartDataLabelsInfo` / `ChartDataTable` interfaces.

OOXML defaults (`cap="flat"` / `cmpd="sng"`) round-trip as absence so
the writer never emits attributes Excel itself omits on freshly-drawn
charts. Clone-through follows the standard `undefined` (inherit) /
`null` (drop) / value (replace) grammar.

54 new tests cover theme name validation, every modifier combination,
schemeClr <-> srgbClr round-trips, malformed mod drops, cap/compound
parse/write/clone-through on every host, and `writeXlsx` round-trip
sanity.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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