fix(ui): F8-08 unified number format — mono, fixed 3-decimal, no separators
Tests · UI / test (push) Waiting to run
Tests · UI / test (pull_request) Waiting to run

Engine emits Floats at Fixed3 quantisation; UI now renders them as 3-decimal
fixed-point strings without thousand separators, monospaced via var(--font-mono)
on .numeric cells, and right-aligned in tables so columns line up on the
decimal point. Integer counts render with 0 decimals and no separators;
science fractions render as 1-decimal percent (matches the engine's third
decimal of precision).

Bug fixes from #51 (umbrella #43):
  - Player Status drive/weapons/shields/cargo: were tech LEVELS rendered
    through formatPercent (x100) — now use formatFloat (raw level).
  - Races table: same bug, same fix.

Style/UX cleanups:
  - Inspector field labels lose "stockpile" word ($ / M suffix carries it).
  - Coordinates drop the parentheses (just "x, y").
  - Inspector + report tables unify font sizes with calculator-tab
    (values 0.85rem mono, labels 0.8rem).

Files:
  - new util: ui/frontend/src/lib/util/number-format.ts
  - report/format.ts becomes a thin re-export to keep section imports compact
  - inspector planet / ship-group / actions: drop inline formatNumber,
    mark numeric <dd> with class="numeric"
  - table-races (+ bug fix), table-sciences, table-ship-classes,
    designer-science: drop inline formatters, switch to util, add
    class="numeric" on numeric <th>/<td>
  - 17 report section files: class="numeric" on numeric th/td +
    scoped CSS rule for mono+right-align
  - i18n en/ru: drop "stockpile" word, drop "%" from tech-level column
    headers in races + player_status (the "%" was the misleading bit
    from the bug)
  - tests/inspector-planet + tests/table-races: update assertions to
    match the new format

Verification: pnpm test (814 passed), pnpm check (0 errors/warnings),
pnpm build clean.

Refs: #51 (#43 umbrella).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilia Denisov
2026-05-27 11:08:22 +02:00
parent 208d30073b
commit b31d9f4c45
33 changed files with 484 additions and 379 deletions
+40
View File
@@ -0,0 +1,40 @@
// Shared numeric formatters for inspector and report views.
//
// Engine wire-format for floats is `Fixed3` quantised
// (pkg/model/report/report.go). The UI renders them as a fixed 3-decimal
// string with neither thousand separators nor locale-aware grouping —
// values stay column-aligned across rows and never reflow when the locale
// switches mid-session. Integer counts (planet count, ship `count`) are
// rendered with zero fractional digits to match their wire shape
// (uint16 / uint64). The convention mirrors the calculator-tab view
// (`useGrouping: false`, 3 decimals) so inspector and report tables read
// the same way as the calculator panel.
/**
* formatFloat renders an engine-emitted `Float` with three fractional
* digits and no thousand separators. Used for tech levels, stockpiles,
* coordinates, range, mass, votes — every report payload that is not
* an integer count or a `[0, 1]` fraction.
*/
export function formatFloat(value: number): string {
return value.toFixed(3);
}
/**
* formatInt renders an integer-ish count (planet count, ship count,
* etc.) with zero fractional digits and no thousand separators.
*/
export function formatInt(value: number): string {
return value.toFixed(0);
}
/**
* formatPercent renders a `[0, 1]` fraction as a one-decimal percent
* without a `%` suffix — the column header carries the unit. 0.1 %
* precision (the third decimal of the underlying float) matches the
* project-wide "three decimal digits" convention used elsewhere by
* `formatFloat`.
*/
export function formatPercent(fraction: number): string {
return (fraction * 100).toFixed(1);
}