feat(xlsx): chart theme color refs (schemeClr) + line cap/compound on all host borders#322
Open
productdevbook wants to merge 1 commit into
Open
feat(xlsx): chart theme color refs (schemeClr) + line cap/compound on all host borders#322productdevbook wants to merge 1 commit into
productdevbook wants to merge 1 commit into
Conversation
… 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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 optionallumMod/lumOff/tint/shade/alphamodifiers.parseSpPrFill/parseSpPrBorderColornow walk both<a:srgbClr>and<a:schemeClr>and surface theme references as{ theme, lumMod?, lumOff?, tint?, shade?, alpha? }objects. AddedparseSchemeClrhelper.buildColorElement/buildSolidFill/normalizeChartColorhelpers. Every emit-color helper now switches on input type —stringemits<a:srgbClr>,ChartThemeColoremits<a:schemeClr>with mods in OOXML schema order (tint → shade → alpha → lumMod → lumOff).undefined(inherit) /null(drop) / value (replace) grammar.Affected fields:
chartSpaceFillColor,chartSpaceBorderColor,plotAreaFillColor,plotAreaBorderColor,legendFillColor,legendBorderColor,legendFontColor,titleColor,titleFillColor,titleBorderColor, axisaxisTitleColor/axisTitleFillColor/axisTitleBorderColor/labelColor,dataTablefontColor/fillColor/borderColor,dataLabelsfontColor/fillColor/borderColor,legendEntries[].color, seriescolor, markerfill/line, dataPointfillColor/borderColor. Non-breaking: the type widens (string→ChartColor), it never narrows.B. Line cap & compound on every host's
<a:ln>Extends
cap(OOXMLST_LineCap) andcmpd(OOXMLST_CompoundLine) beyond the per-seriesChartLineStroketo every chart host that owns an<a:ln>slot:SheetChart:chartSpaceBorderCap/chartSpaceBorderCompound,plotAreaBorderCap/plotAreaBorderCompound,legendBorderCap/legendBorderCompound,titleBorderCap/titleBorderCompoundSheetChart.axes.x/.y:axisTitleBorderCap/axisTitleBorderCompoundChartDataTable:borderCap/borderCompoundChartDataLabels:borderCap/borderCompoundChart/ChartAxisInfo/ChartDataLabelsInfointerfacesOOXML 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 centralparseBorderCapFromSpPr/parseBorderCompoundFromSpPr/normalizeLineCap/normalizeLineCompound/resolveLineCap/resolveLineCompoundhelpers inchart/shape.ts.Test count delta: +54 tests (7466 → 7520).
Test plan
pnpm typecheckpassespnpm buildsucceedspnpm testpasses — 7520 / 7520writeXlsxend-to-end round-trip (theme color + cap / compound)🤖 Generated with Claude Code