Skip to content

fix(preview): lay out chart plot areas and line labels as LibreOffice does - #482

Merged
baseballyama merged 4 commits into
mainfrom
fix/preview-combo-plot-area
Oct 25, 2026
Merged

baseballyama merged 4 commits into
mainfrom
fix/preview-combo-plot-area

Conversation

@baseballyama

@baseballyama baseballyama commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Summary

The preview drew cartesian charts with a taller plot area than LibreOffice and put line labels on top of their markers, so labels that collide in the real chart (a bar's inEnd value label against a secondary-axis line label) looked separate in the preview. The automatic layout now follows LibreOffice's chart2 rules.

Motivation

A deck generator reviews preview PNGs to fix overlapping chart labels. On a combo chart (columns + a secondary-axis line, bottom legend, 12 pt labels) LibreOffice shows 13,150/51.0%, 14,020/52.0% and 15,640/53.4% overlapping; the preview showed none of them.

Measured plot areas (axis spines, 1280 px wide) for four charts of the same deck:

chart frame top–bottom LibreOffice plot preview before preview after
combo, legend b 182–614 199–547 190–570 200–545
column, legend b 197–653 214–585 204–609 215–583
line, legend b 211–571 226–499 219–526 227–502
bar, no legend 211–648 220–638 219–621 220–620

Line label glyph rows above a 7 pt marker with a 12 pt label: LibreOffice 349–359, before 357–368 (on the marker), after 349–359.

The inset comes from LibreOffice's source (chart2/source/view/main/ChartView.cxx): constPageLayoutDistancePercentage = 0.02 applied to each side of the diagram space.

The "after" column above is from the first revision, which also reserved a bottom legend box with 1.85 mm gaps (VLegend.cxx) and half a value-label line above the plot. Those two rules come from a newer LibreOffice than the fidelity gate's reference (24.2): against it they moved the legend and plot top away and regressed three sample slides (31-2, 37-1, 40-1). They are dropped; the legend strip and plot top stay as on main. With the remaining changes every slide is within the gate's tolerance (31-2 0.8371, 37-1 0.8997, 40-1 0.7828 against the CI ground truth).

The reference desktop app could not be used as ground truth here: its scripted PDF export timed out on this machine, so the numbers are LibreOffice only.

Changes

  • Bar, column, line, area and combo charts with automatic layout: 2% of the frame width / height per side instead of a fixed 8 px.
  • Column-style charts size the category-label row from the label font (was a fixed 18 px, too short for 12 pt labels).
  • Line labels at t / b keep their line box 1 mm clear of the marker (was a fixed 5 px / 13 px offset from the point).
  • Unchanged: pie / doughnut / radar / scatter frames, manual inner plot-area layouts, horizontal gutters for axis labels (still fixed widths), legend placement and its strip.

Testing

  • New test/preview-chart-auto-layout.test.ts covers the insets, the font-sized category row, and line label clearance.
  • Updated the hard-coded plot geometry in preview-chart-axis-controls, preview-chart-fill-opacity and preview-chart-inner-layout to the new layout.
  • npx vitest run test/preview- passes (1155 tests).
  • CI's fidelity job compares against LibreOffice and is the gate for the chart samples.

Breaking changes

None in the API. Chart previews render with a slightly smaller plot area.

Checklist

  • I have read CLAUDE.md and followed the project's conventions.
  • I have added or updated tests for the change.
  • I have added or updated documentation where user-visible behavior changed.
  • If this is a breaking change, I have added a changeset / CHANGELOG entry and
    flagged it above.

Copilot AI balanced review requested due to automatic review settings October 25, 2026 02:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@baseballyama
baseballyama force-pushed the fix/preview-combo-plot-area branch from 0177f5d to e1b1f45 Compare October 25, 2026 05:36
… does

The plot area kept a fixed 8 px margin and an 18 px legend strip, so a
chart with a bottom legend drew its plot about 30 px taller than
LibreOffice, and line labels above a point sat on the marker. Use
LibreOffice's chart2 rules: 2% of the frame per side, a bottom legend
box 1.85 mm from the edge and from the plot, half a value-label line
above the plot, a category-label row sized to its font, and line labels
1 mm clear of the marker.
The legend band and the half line above the plot followed a newer LibreOffice
than the fidelity reference and drew three sample slides further from it.
@baseballyama
baseballyama force-pushed the fix/preview-combo-plot-area branch from e1b1f45 to 9d406d3 Compare October 25, 2026 06:02
@baseballyama
baseballyama merged commit baf373a into main Oct 25, 2026
16 checks passed
@baseballyama
baseballyama deleted the fix/preview-combo-plot-area branch October 25, 2026 07:54
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