Skip to content

Charts: value axes start above zero when the values sit high, as in Office - #157

Merged
h-a-n-a-s-h-i merged 2 commits into
storytold:mainfrom
LloydNicholson:fix/chart-auto-axis
Oct 14, 2026
Merged

h-a-n-a-s-h-i merged 2 commits into
storytold:mainfrom
LloydNicholson:fix/chart-auto-axis

Conversation

@LloydNicholson

@LloydNicholson LloydNicholson commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Related to #144.

Context

This PR first fixed #144: the issue's data (42.1, 18.7, 6.3) drew 0–50 in steps of 10, where PowerPoint and LibreOffice draw 0–45 in steps of 5. Upstream ce1c7b7 ("Charts: axis number formats, automatic major unit, hidden axes") has since rewritten the value-axis scaling, and main now draws the issue's chart as 0–45 in steps of 5. So the branch now merges main and keeps upstream's structure and API as they are: axis_scale(lo, hi, fmin, fmax, major, max_intervals, headroom), Chart::axis_scale(secondary, max_intervals), axis_range, combo charts with a secondary axis, the room-based major unit, number formats and hidden axes. This PR's own auto_scale and its fixed "at most 10 intervals" unit rule are gone.

What this adds on top of upstream

These are the documented rules for automatic axis limits (Microsoft's "How chart axis limits are determined", summarised by Jon Peltier) that main doesn't follow yet:

  • Automatic minimum: main always starts the axis at zero. Office starts at zero only when every value is ≥ 0 and the smallest is below 5/6 of the largest. Otherwise the axis starts at the first major unit at or below min − (max − min)/20. Values of 85, 92 and 97 now get an 84–98 axis instead of bars that all look the same height.
  • All-negative data mirrors it: the axis ends at zero only when the largest value is above 5/6 of the smallest. Otherwise it ends at the first major unit at or above max + (max − min)/20. (main didn't pad the top of an all-negative axis.) Mixed signs keep headroom at both ends, as on main.
  • Headroom is 5 % of the data range (max − min), as documented, not of the range from zero. A single value is measured from zero, so it still gets headroom.
  • Values outside the axis limits stop at the plot edge (to_v and to_axis in the renderer). This covers values past a fixed <c:max>/<c:min>, and bars that start at zero on an axis that now starts above zero. On main they drew outside the plot area.
  • A fixed limit beyond the data: the automatic end gives way (e.g. a fixed max of 50 with data at 85–97 gives 0–50) instead of producing an inverted axis.

How it fits in:

  • Chart::axis_scale now feeds axis_scale the plotted extremes. Plain values are used as they are, stacked series as running sums from zero (so stacked axes still start at zero), and 100% series as 0–1.
  • axis_range and value_range behave as before (zero-inclusive), and all upstream tests pass unchanged.
  • 100% stacked charts stay 0–1 (0–100%), with upstream's room-based unit.
  • Upstream's robustness guards (±1e100 clamp, non-finite fixed limits ignored, bounded unit search) already cover what this PR's guards did. The new branches add no casts or indexing.

Testing

  • New model tests in crates/model/src/chart.rs, run with room for 10 intervals:
    • The issue's data gives 0–45 / 5.
    • PowerPoint's default chart data gives 0–6 / 1.
    • A max of 100 gives 0–120 / 20, and a max of 10 gives 0–12 / 2.
    • Peltier's example (2.95) gives 0–3.5 / 0.5.
    • The 5/6 threshold on both sides (59/49 starts at 0, 59/50 gives 48–60 / 2). The same for 85/92/97, which gives 84–98 / 2.
    • Mirrored negative cases: −45–0 / 5 and −60–−48 / 2. Mixed signs give −30–50 / 10.
    • Stacked charts keep zero. A combo chart's secondary axis follows the same rule.
    • Fixed min and max are kept. Fixed limits beyond the data give way.
    • 100% charts give 0–1 / 0.1 (0.2 with room for 5).
    • Degenerate and extreme inputs (all zero, single value, NaN/∞, ±f64::MAX, denormals, inverted or non-finite fixed limits) always give a finite, non-empty axis.
  • deckcraft-cli render on synthetic decks:
    • The issue's python-pptx chart still renders 0, 5 … 45.
    • The same chart with values 85/92/97 renders 84, 86 … 98.
    • With a fixed <c:max val="90"/>, it renders 84–90 and the 92 and 97 bars stop at the top of the plot.
  • cargo xtask ci: fmt and clippy pass. cargo test --workspace --no-fail-fast has three failures, and all three also fail on unmodified main on the test machine. Two are ime_tests::korean_composes_in_the_notes_pane and ime_tests::cjk_text_in_the_interface_is_drawn_with_real_glyphs in deckcraft-ui-egui. The third is tests::symbol_font_characters_draw_in_the_sym_font in deckcraft-text, re-run separately on main 7d8bb05. The assets, layers and wasm steps pass.

PowerPoint and LibreOffice weren't available on the test machine. The expected values come from the documented rule and the issue's reference images, not from a new Office export.

Source: Jon Peltier, How Excel Calculates Automatic Chart Axis Limits.

🤖 Generated with Claude Code

The value axis used a generic "nice" scale: about five intervals and no
headroom, so data with a maximum of 42.1 got 0-50 in steps of 10, while
PowerPoint and LibreOffice draw 0-45 in steps of 5.

`auto_scale` now follows the rule Office documents for automatic limits:
the maximum is the first major unit at or above max + (max - min)/20, the
minimum is zero when all values are positive and the smallest is below 5/6
of the largest (otherwise the first major unit at or below min - the same
headroom), and all-negative data mirrors that. The major unit is the
smallest 1, 2 or 5 x 10^n that gives at most 10 intervals. Fixed
`<c:min>`/`<c:max>` limits are kept as they are and no longer get rounded
or padded; values beyond them stop at the plot edge. 100% charts get
0-1 in steps of 0.1.

Fixes storytold#144

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream ce1c7b7 ("Charts: axis number formats, automatic major unit,
hidden axes") replaced the value-axis scaling this branch changed, and
already draws storytold#144's chart as 0-45 in steps of 5. Take its structure and
API as they are (axis_scale with fixed bounds/unit and a room-based
interval count, Chart::axis_scale(secondary, max_intervals), axis_range,
combo charts' secondary axis) and drop this branch's auto_scale.

On top of it, the Office rules upstream lacked:

- Automatic minimum: zero only when every value is >= 0 and the smallest
  is below 5/6 of the largest; otherwise the first major unit at or below
  min - (max - min)/20. All-negative data mirrors it (the axis ends at
  zero only when the largest is above 5/6 of the smallest). Headroom is
  5 % of the data range, as documented. Chart::axis_scale feeds it the
  plotted extremes (stacked sums still count from zero, 100 % series are
  0-1); axis_range and value_range keep returning zero-inclusive ranges.
- A fixed limit beyond the data makes the automatic end give way instead
  of producing an inverted axis.
- The renderer stops values past the axis limits at the plot edge, on
  both value axes.

The model tests from this branch are ported to the new signature with
ten intervals of room.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LloydNicholson LloydNicholson changed the title Issue #144: automatic value axes scale like Office Charts: value axes start above zero when the values sit high, as in Office Oct 13, 2026
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 9fab337 into storytold:main Oct 14, 2026
1 check passed
@echelon

echelon commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thank you for this contribution, @LloydNicholson! It has landed on main and will ship in the next DeckCraft release.

If you haven't already, please come join us on Discord: https://discord.gg/artcraft

anishguduru pushed a commit to anishguduru/deckcraft that referenced this pull request Oct 16, 2026
…d recovery beside pdfcraft.exe (storytold#325)

* Issue storytold#157: the Windows portable zip keeps settings, logs and recovery beside pdfcraft.exe

The portable zip had no portable.txt, and the app had no portable mode: it always wrote %APPDATA%\PdfCraft and %LOCALAPPDATA%\PdfCraft. Now portable.txt (or PdfCraft.portable) beside the executable puts the settings, log files, crash recovery and new digital IDs in PdfCraftData next to it, as PhotoCraft does, and the zip ships portable.txt. An unwritable PdfCraftData falls back to the per-user folders and says so.

* Issue storytold#157: update ATTRIBUTION.toml SHA-256 for the translation catalogs this PR changes

---------

Co-authored-by: Brandon Thomas <echelon@gmail.com>
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.

Chart render: automatic value-axis scale differs from Office (0-50 step 10 vs 0-45 step 5)

4 participants