Skip to content

fix(kpi_grid): show decimal KPI values at their own precision - #921

Open
executorrr86 wants to merge 1 commit into
OpenMontageInc:mainfrom
executorrr86:fix/kpi-grid-decimal-values
Open

executorrr86 wants to merge 1 commit into
OpenMontageInc:mainfrom
executorrr86:fix/kpi-grid-decimal-values

Conversation

@executorrr86

Copy link
Copy Markdown
Contributor

Summary

KPIGrid shows decimal values wrong. The count-up does Math.round(metric.value * countProgress), so 1.76 shows "2", 0.72 shows "1" and 0.4 shows "0". remotion's spring() also settles just under 1 (0.9999999999999998 and 0.9999999999999999 for the two configs KPIGrid uses), so 12.5 stays at "12" on every frame. A KPI card with 12.5 / 1.76 / 0.72 renders pixel-identical to one with 12 / 2 / 1.

The counter now keeps the precision the value was written with, in line with the precise-label approach of #656.

Related issue

None. Refs #518, which sees the same Math.round and adds an opt-in decimals field. Without that field it keeps rounding, so 12.5 still shows "12".

Changes

  • New charts/format.ts:
    • decimalsOf(n) gives the decimal places of a value, as written.
    • formatKpiValue(target, progress) gives the animated counter. Scale (K/M) and digits come from the target, so they never jump mid-animation.
  • KPIGrid.tsx uses formatKpiValue in place of Math.round + formatDisplayValue, which is removed.
  • Not changed: the change indicator keeps toFixed(1). Happy to cover it in a follow-up if you want it at full precision too.

Testing

  • npx tsc --noEmit: clean.
  • Full pytest tests: 2926 passed, 17 skipped.
  • tests/contracts/test_kpi_grid_value_format_contract.py runs the production format.ts in Node:
    • 12.5, 1.76, 0.72, 0.4, 42, 14000 and 2500000 at both spring end values and at 1.
    • Mid-count values: 1.76 at 0.5 → "0.88", 14000 → "7.0K", 2500000 → "1.3M".
    • A rendered check (remotion still) that a 12.5 / 1.76 / 0.72 card no longer matches the 12 / 2 / 1 card. It fails on main and passes here. It is skipped when Remotion is not installed, so it does not run in the current CI job.
  • Integers and K/M values do not change: a card with 42, 14000, 2500000 and 7 renders pixel-identical to main at frames 20, 40 and 120 (mid count-up and final).
  • Rendered at frame 120, before → after: "12, 2, 1" → "12.5, 1.76, 0.72".

Checklist

  • The change is focused on a single logical concern.
  • I ran the relevant tests locally (make test-contracts / make test) where applicable.
  • I updated docs/README if behavior or usage changed. (No docs change needed.)
  • No unrelated files (build artifacts, local config) are included in the diff.

🤖 Generated with Claude Code

The count-up rounded every value to an integer, so 1.76 showed "2" and 0.4
showed "0". remotion's spring also settles just under 1, so 12.5 stayed at
"12" on every frame. The counter now keeps the target's decimal places.
Integers and K/M values render exactly as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

1 participant