Chart: emit single-level c:strRef categories and relative chart rel targets#1465
Open
eliasaronson wants to merge 1 commit into
Open
Conversation
…argets Bar/line/area charts wrote single-level string categories as c:multiLvlStrRef, and the slide->chart relationship Target as an absolute /ppt/charts/chartN.xml. Both are valid OOXML that PowerPoint tolerates, but they differ from what PowerPoint itself produces (and from the pie/doughnut category code, which already uses c:strRef). Consequences in other consumers: Google Slides and LibreOffice mis-render the category axis, and strict parsers (e.g. pptxtojson) fail to read the labels or drop the chart entirely. - gen-charts.ts: emit single-level c:strRef when there is one category level; fall back to c:multiLvlStrRef only for genuine multi-level categories. - gen-xml.ts: relativize the chart relationship Target in the slide rels to ../charts/chartN.xml, leaving the absolute Content_Types PartName (which requires the absolute form) unchanged. No change to how PowerPoint renders these charts.
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.
Change Summary
Two small changes to how charts are serialized so the output matches what PowerPoint itself writes, improving compatibility with other consumers (Google Slides, LibreOffice, and OOXML parsers) with no change to how PowerPoint renders the charts.
Change Description
src/gen-charts.ts— categories: bar/line/area charts wrote single-level string categories as<c:multiLvlStrRef>(the multi-level form). This now emits the idiomatic single-level<c:strRef>when there is exactly one category level, falling back to<c:multiLvlStrRef>only for genuine multi-level categories. This mirrors the pie/doughnut category code, which already uses<c:strRef>.src/gen-xml.ts— relationship target: the slide→chart relationshipTargetwas written as an absolute/ppt/charts/chartN.xml. PowerPoint writes this relative (../charts/chartN.xml). The target is now relativized in the slide.rels, while the[Content_Types].xmlOverride PartName(which requires the absolute form) is left unchanged.Both prior forms are valid OOXML that PowerPoint tolerates, but they diverge from PowerPoint's own output.
Change Type
No new/changed public properties or APIs, so no
core-interfaces.ts/types/index.d.ts/ demo changes are required.Motivation and Context
Charts produced by pptxgenjs render correctly in PowerPoint but:
multiLvlStrRef).pptxtojson) either can't read the category labels or drop the chart entirely — the latter because they resolve the absolute relationship target to an invalid path.Aligning both to PowerPoint's idiomatic output fixes these while leaving PowerPoint rendering identical.
Verification
npm run buildcompiles cleanly with the changes.<c:cat>is a single-level<c:strRef>, the slide rel target is../charts/chart1.xml, and category labels + values parse correctly.Checklist