Skip to content

feat(charts): 3D charts, Word and PowerPoint charts, closer to Excel (follow-up to #12) - #51

Merged
pierreneter merged 25 commits into
p10node:mainfrom
mkroemer:xlsx-charts-fidelity
Nov 23, 2026
Merged

pierreneter merged 25 commits into
p10node:mainfrom
mkroemer:xlsx-charts-fidelity

Conversation

@mkroemer

Copy link
Copy Markdown
Contributor

Follow-up to #12 (XLSX charts drawn as SVG). It builds on #12's branch: until #12 is merged this diff also shows #12's commits. The new work is the last 10 commits, from 01338e3 on. I'll rebase onto main once #12 is in.

What changes

3D charts (src/core/xlsx/chart-3d.ts, new). 3D charts were drawn as their flat form. A 3D line chart came out empty, because its ribbons have no line of their own, and series standing one behind another hid each other. They are now drawn in the view the file gives (c:view3D: rotX, rotY, right-angle axes or perspective, depth and height), inside their walls and floor, with gridlines along the back and side walls and labelled category, value and series axes:

  • columns and bars: clustered, stacked, 100 % or one behind another; as boxes, cylinders, cones and pyramids, including the …ToMax shapes and stacks narrowing to one tip; negative values go down from the floor
  • lines as ribbons in their fill; areas as slabs
  • pies as thick tilted disks, with exploded slices and data labels
  • surfaces as shaded meshes, each cell cut along the band bounds; or as a wireframe

Every mark is a convex solid. Faces turned away are left out, the others are shaded by how squarely they face the light, and solids are drawn from far to near. Round sides are drawn as one shape with a gradient, so no seams show.

Charts in Word documents and on slides. They were a box saying "Chart". Their chart parts are the same DrawingML charts, with their values saved in them, so the XLSX reader and renderer now draw them from those values (readSavedChart).

  • DOCX: the inline carries the chart model.
  • PPTX: a chart frame becomes a chart slide element that keeps its id, so selecting and moving it still work.
  • The three views share one chart picture cache (src/react/common/chart.ts).

Closer to Excel (XLSX, and DOCX/PPTX with it):

  • Automatic value axes: 5 % of the span is left past the values, and the step is the smallest of 1, 2 or 5 that fits the labels' room, at most 10 intervals. Values 1…4 now get 0…4.5 by 0.5 instead of 0…5 by 1.
  • Pattern fills: drawn from Office's 8 × 8 preset bitmaps (8 pt tiles). The diagonal hatches had a notch in every tile and were drawn twice as heavy.
  • Titles: they take size, weight and colour from their paragraph defaults (a:pPr/a:defRPr). A white title on a dark chart used to be drawn grey. An unnamed lone series gets "Chart Title".
  • Data labels: a point's own label (c:dLbl) is honoured, and bar labels sit where dLblPos says (outside the end, inside the end, inside the base, or centred).
  • Horizontal clustered bars: they run bottom-up, with the first series lowest.
  • Category labels: they take the axis' fixed angle (bodyPr rot); when the angle is left automatic, they wrap at spaces before tilting. The axis' own number format applies. In a combination chart they come from the category axis that is shown.
  • Scatter charts with text X values: points are numbered 1, 2, 3 as in Excel; they used to draw nothing.
  • Date axes: a band per day, month or year, following baseTimeUnit or Excel's own choice. Yearly dates had been hairline columns.

How it was checked

  • Reference renderer: I compared side by side with an independent Office chart renderer that is measured against Excel. It was used only as a visual reference: nothing was copied and no dependency was added. The test material:
    • 191 charts from the LibreOffice (chart2/qa/extras/data/xlsx) and Apache POI test workbooks
    • 24 generated 3D cases
    • the 134 charts in LibreOffice's DOCX and PPTX chart test files: 133 are drawn, and the other is a chartex funnel that stays a placeholder
  • Unit tests: test/xlsx-chart.test.ts has 17 new tests (3D, labels, axes, dates, titles), and test/office-charts.test.ts is new (DOCX and PPTX charts from the files).
  • Browser tests: e2e/charts.spec.ts checks that slide and Word charts show as pictures in the views.
  • Checks run:

Not done

  • Data tables, trendlines and error bars are still not drawn.
  • Chartex charts (waterfall, funnel, …) keep their placeholder.
  • 3D bars have no data labels.
  • A surface wireframe colours each cell's lines by the cell's average value.
  • Axis steps follow the reference renderer's Excel measurements; they were not compared with Excel exports directly.

🤖 Generated with Claude Code

markus-kroemer and others added 25 commits November 14, 2026 09:51
A sheet's charts were placeholders. Now src/core/xlsx/chart.ts reads a
chart part into a model in the worker, and src/core/xlsx/chart-svg.ts
draws it as a self-contained SVG (DOM-free), shown over the cells like a
picture.

- Kinds: bar and column (clustered, stacked, 100%, upright or
  horizontal), line (markers, smoothing, gaps for empty cells), area,
  pie and doughnut (exploded slices, first-slice angle), scatter, and
  combinations on primary and secondary axes; 3D charts as their flat
  form. Radar, bubble, stock, surface and chartex keep the placeholder.
- Values: series references are read from the workbook's cells, loading
  a sheet not shown yet, so charts follow edits (the view reads them
  again after an edit result). A defined name, another workbook or an
  unreadable reference falls back to the chart's numCache / strCache.
  Hidden rows and columns are left out when plotVisOnly is set.
- Look: Excel-like automatic axis bounds (zero kept, steps of 1/2/5),
  fixed min/max/major unit, reversed and log axes, gridlines, tick and
  data labels in their number formats, tilted category labels where they
  do not fit flat, title (Excel's automatic one included), legend
  (positions, overlay, deleted entries), theme accents for series
  without colors of their own, manual plot layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pie negatives, cell titles

- scatter: a point whose X value is missing is not drawn (it was placed at
  its ordinal position); value labels follow their own points when a Y
  value is missing
- bars, areas, lines and points are clipped to the plot area, so a fixed
  axis range does not let them run over the title and legend
- pie and doughnut: a negative value is a slice of its magnitude, as in
  Excel; its value label keeps the sign
- a title whose text is a cell (`c:tx/c:strRef`) shows that cell's text,
  else its cached text, before the automatic title

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… row stays in it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The automatic bounds add a step above a maximum that falls on a
gridline, so a 100% stacked axis ran to 120%. An axis carrying only
100% stacks now ends at 100% (and -100% with negatives), as Excel's does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- gradient fills (linear and radial) and pattern fills (DrawingML presets)
  for series, points, the chart area and the plot area
- the text size, weight and color of axis labels, legend and data labels
- gridline and axis lines: color, width, dash, or none
- the plot area's fill and border
- the built-in chart style (c:style, c14:style): gray, accent and
  one-accent palettes, tinted plot areas, dark backgrounds
- default grays (text, gridlines, axis lines) as shades of the theme's
  text color rather than fixed values

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kinds that were placeholders until now:
- radar: lines, lines with markers, filled; a spoke per category, rings
  at the value axis' ticks
- bubble: sizes read from the cells, by area or by width, scaled by
  bubbleScale; negative bubbles as outlines where the chart shows them;
  the axes leave the bubbles room
- stock: high-low lines and up-down bars, the series over them
- surface (2D and 3D): seen from above as Excel's contour chart, its
  value bands in the legend; or the wireframe

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Charts are read again after an edit beside upstream's sheet size limits for drawings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The features table keeps upstream's function count and this branch's charts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… values, scatter without X, doughnut rings, negative axes

- A chart's saved point count (`ptCount`) is capped before an array is
  made for it, so a small file cannot ask for a huge allocation.
- Charts read their cells once the values computed after loading are in,
  and read them again when a recalculation reports new values.
- Date cells are plotted by their serial, not as NaN from their ISO text.
- A scatter series without X values numbers its points again instead of
  drawing none.
- A doughnut draws a ring per series, the first innermost, as Excel does.
- Bars and areas on an axis that does not reach zero start at the bound
  nearest to it, so a value nearer zero is a shorter bar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ints with their own look, chart-level markers

- Extremes of a chart's values are found by a loop, not by spreading tens
  of thousands of values into Math.min / Math.max, which exceeded the
  engine's argument limit and stopped the sheet from rendering.
- Each scatter or bubble group is placed on its own X axis's scale, and a
  log X axis is a log scale.
- Log axes take their bounds from the positive values; zero and negative
  values, which a log axis cannot place, are left out.
- With hidden rows left out, a point's own color or explosion follows
  its point; a hidden point's goes with it.
- A line chart that turns markers off, and a scatter chart of style line
  or smooth, have no markers on series without a symbol of their own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… axes and axis crossings

- A scatter or bubble X axis linked to its source is written in the X
  values' number format, not the Y values'.
- Data labels are drawn above the clipped series, so a label beside a
  point on the plot's edge stays whole.
- Lines show empty cells as the chart says (`dispBlanksAs`): a gap, zero,
  or spanned by the line.
- A date axis places its points by date, a day to a band, within its
  minimum and maximum where the file fixes them.
- The category axis crosses the value axis where the file says
  (`crosses`, `crossesAt`), and bars and areas grow from there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…shown as zero are in the axis range

A range given in full (B2:B6) keeps its size where the sheet is filled less far, so its points line up with categories read from elsewhere; only a whole column or row is cut to the filled cells. The automatic axis bounds take in the zeros a line or scatter chart draws for empty cells.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cel 2010 style numbers

- Values all alike keep zero in view, so columns of them have a height
  instead of none.
- A minimum or maximum fixed past all the values moves the other bound to
  give the axis a span, instead of a scale with no ticks.
- A c14 style number (101-148) the XML reader has already taken out of
  its AlternateContent is read as the style it stands for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- drawings.tsx: chart placeholders take #6's translated names; the chart's
  alt text too
- XlsxView.tsx: the chart re-read counter kept beside #8's history
- docs/features.md: main's table (p10node#42 rows) with the XLSX row for charts,
  columns aligned again

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on series and points; a chart part read once

- dash, group and chart-kind tables are dict()s: "constructor" in
  prstDash or as a plot-area element is unknown, not an inherited function
- groups without series are dropped by the reader and by renderChart, so an
  empty pieChart beside a bar group draws the bars
- a chart reads at most 255 series and 250,000 points from cells and saved
  values together; past that it is shown as its placeholder
- a reference counts the cells of all its areas against MAX_POINTS
- a chart part shown by several anchors is read once, each anchor gets its
  own model
- ptCount is read as a whole number; gapWidth, overlap, holeSize,
  firstSliceAng and bubbleScale are kept to Excel's ranges
- niceScale ignores bounds and steps that are not numbers, and a fixed
  maximum at or below the fixed minimum
- SVG text drops characters XML 1.0 does not allow (a control character in
  a title broke the picture)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The diagonal presets were drawn as lines that missed one offset per tile, leaving a notch in every tile, and their
width was measured across the line, so dkDnDiag came out twice as heavy. Each preset is now its bitmap, a cell a
point, as Office draws it; the presets not drawn before (confetti, bricks, plaid, weave, wave, ...) get theirs too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ar order

Measured against the same 191 charts drawn by another Office chart renderer.

- Automatic value axes leave 5 % of the span past the values and take the smallest step of 1, 2 or 5 that keeps
  the axis to the intervals its labels have room for (at most 10), as Excel does: 1…4 gives 0…4.5 by 0.5, not
  0…5 by 1. Values close together far from zero start half their spread below them.
- A title's size, weight and color come from its paragraph's defaults (a:pPr/a:defRPr) under the run's own: a
  white title on a dark chart was drawn in the chart's gray.
- The automatic title of a lone series without a name of its own is "Chart Title", and there is none without a
  title element.
- A scatter series whose X values are text is numbered 1, 2, 3, as Excel does, instead of drawing nothing.
- A point's own data label (c:dLbl) is shown, placed or hidden as it says; bar labels sit past the end, inside
  the end, inside the base or in the middle as their position says.
- A horizontal bar chart's clusters run from the bottom up, the first series lowest.
- Category labels take the angle the file fixes (a:bodyPr rot); left to Excel, labels that do not fit flat are
  wrapped at their spaces before they are tilted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3D charts were drawn as their flat form, which lost what made them readable: a 3D line chart's ribbons have no line
of their own and came out empty, and series one behind another hid each other.

chart-3d.ts draws them in the view the file gives (c:view3D: tipped by rotX, turned by rotY, with right-angle axes
or in perspective, depth and height in proportion), inside the chart's walls and floor (their own fills where the
file gives them), with the value axis' gridlines along the back and side walls and the category, value and series
axes labeled:

- columns and bars, clustered, stacked, 100 % or one behind another, as boxes, cylinders, cones and pyramids (also
  narrowing to the axis' end, and stacks narrowing to their tip), negative ones down from the floor;
- lines as ribbons in their fill; areas as slabs, stacked or one behind another;
- pies as thick disks tipped toward the viewer, slices exploded and labeled;
- surfaces as shaded meshes, each cell cut along the bands' bounds, or as a wireframe.

Every mark is a convex solid: faces turned away are left out, the others shaded by how squarely they face the
light, solids drawn far to near; round sides are one shape with a gradient, so no seams show between their faces.
Compared with another Office chart renderer on 24 generated 3D cases and the 16 3D charts of the LibreOffice and
Apache POI test files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s base unit says

A date axis spaced its points by days alone, so yearly dates left each column a 365th of the space it had: a hairline.
It now counts in its base unit (c:baseTimeUnit), or the one Excel picks where the file leaves it: years where the
dates all fall on one day of the year, months where they fall on one day of the month, else days.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… workbook's

Word and PowerPoint charts were a box saying "Chart". Their chart parts are the same DrawingML charts a workbook has,
with the values they show saved in them (the workbook they come from is embedded in the file), so the XLSX chart
reader and renderer draw them too, from those values (readSavedChart):

- DOCX: the body's chart parts are read when the document opens; a chart's inline carries its model and the view
  draws it at the inline's size (and keeps the labeled box while measuring, or where the part cannot be read).
- PPTX: a slide's chart frames are read after its shapes, a chart part once however many slides show it; a frame
  whose chart is read becomes a chart element at its place (it keeps its id for selection and moves), else it stays
  a placeholder.

The views share the chart picture cache (react/common/chart.ts) with the spreadsheet. Checked against the
LibreOffice DOCX and PPTX chart test files: 133 of 134 charts drawn, the other a chartex funnel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A slice was drawn in pieces of a quarter turn, each with its own shading, and their meeting edges showed as faint
seams across the top and a step in the rim. A piece needs to be convex, which a slice of half the pie or less is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ry axis a chart shows

- A category axis with a number format of its own (not linked to the source) labels date and number categories in
  it: a date axis set to "dd" showed the cells' "yy/mm/dd/".
- A combination chart whose first group's category axis is deleted labels its categories from the next group's,
  where that one is shown; they were left out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pierreneter
pierreneter merged commit 7cb6a5d into p10node:main Nov 23, 2026
2 checks passed
pierreneter added a commit that referenced this pull request Nov 23, 2026
A series that only claims its points (`c:ptCount`, or a range of empty cells)
is a few bytes of a file and megabytes once read and drawn. Found with a
fuzzer and in Chromium while reviewing #12 and #51: a 4 KB workbook gave a
296 MB picture (a radar's 200 rings, each with a corner per claimed point),
a line of 100,000 labelled empty points held the page for seven seconds, a
3D surface of 250 × 1,000 claimed points was cut into its bands for four.

The picture
- a chart's picture is at most 8 MB (`MAX_CHART_SVG`): `Svg` takes the most
  characters it may hold and throws `PictureTooLarge` past them; the view
  shows the chart's placeholder
- the chart pictures of a page hold 16 MB together; one given up for its
  size holds its room until it is let go, so a page of such charts is not
  drawn one after another; an ordinary chart (up to 256 KB) is always drawn
- a 3D chart is drawn with at most 20,000 marks, refused before its solids
  are built
- a radar of more than 360 points has circles for rings, no spoke per point
  and every k-th category label
- at most 2,000 series data labels and 20,000 markers a chart: of more, every
  k-th point shows its own (a point's own `c:dLbl` always); a legend lists at
  most 500 entries, its deleted ones looked up in a set
- category labels are thinned by the band's true width (it was taken as one
  pixel at least, so 100,000 categories kept some 4,000 labels)
- a tick or category that is not a finite number is not formatted (the
  scientific format threw on Infinity, and the chart was lost)
- a 3D surface whose axis has no band draws no cell instead of throwing

The points
- the charts of a sheet, a document or a presentation read 1,000,000 points
  together (`MAX_READ_POINTS`); a chart that is not read gives its share back
- in Word and PowerPoint a chart's model is posted with every place that
  shows it: the places share that budget too (a chart on a master is on
  every slide), and a slide read again does not count twice

The pictures kept
- charts of Word documents and slides have a key; copies of one model (a
  slide read again after an edit) share one picture instead of each drawing
  and keeping its own, and a model that is collected lets go of its picture
  (`FinalizationRegistry`): the object URLs were never revoked there

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@pierreneter

Copy link
Copy Markdown
Member

Thanks, this reads well and the 3D module is easy to follow. I reviewed the ten commits from 01338e3, and merged it together with #12. The conflict with main was one import line in src/core/pptx/parser.ts.

What I checked

On main + #12 + this branch: tsc --noEmit passes, bun test 1,611 pass, and e2e charts, pptx, pptx-save, pptx-qa3, docx, docx-qa3 and legacy 56 pass. The 19 unit failures you saw do not happen on the Linux VM I test on.

The fuzzer I describe in #12 also drew 3D charts and read charts through readSavedChart. Nothing gets past chartUrl, and the pictures stay well-formed. PATTERNS is a dict(), and the view3D values are kept to their ranges.

What I changed on top (b80881a, with the limits described in #12)

  • 3D marks. A 3D chart is drawn with at most 20,000 marks. Every bar, ribbon stretch and mesh cell is a solid that is built, cut and sorted before anything is drawn: a surface of 250 × 1,000 claimed points took 3.8 s, and 100,000 cylinders 3.5 s for a picture too large to show.
  • A surface with no bands. bandOf returned undefined when the value axis had no step between its bounds (max 1, majorUnit 1000), and b.fill threw. It draws no cell now.
  • A chart shown in many places. A chart part is read once, but its model is posted with every slide and every batch of paragraphs that shows it. One part of 400,000 points on a slide master would be held once per cached slide. The places now share the budget of 1,000,000 points; a slide read again does not count twice.
  • Object URLs. releaseChart was only called by the spreadsheet view, so a slide read again after an edit drew its chart again and left the old picture behind. Charts of documents and slides now carry a key; copies of one model share one picture, and a model that is collected lets go of it (FinalizationRegistry).

Tests for these are in test/chart-limits.test.ts and test/office-charts.test.ts.

Not blocking, worth a look

  • Perspective. turnedView takes c:perspective as the field of view in degrees. ST_Perspective runs to 240, twice the 120° of Excel's dialog, so I think the file holds twice the angle. As it is, Math.tan(rad(perspective / 2)) is negative past 180 and the projection breaks. I did not change it, because I could not compare with Excel here.
  • Charts outside the body. readCharts reads the main part's relationships, so a chart in a header, a footer or a text box part keeps its label.
  • One theme per chart part. PptxPresentation.chart caches by part, so a chart shown on slides of two masters takes the first one's theme.
  • Dates out of range. On a date axis of months or years, unitOf is NaN for a serial Date cannot hold, and units with it: the categories are drawn at NaN. A check on unitOf(d0) and unitOf(d1) would do.

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.

3 participants