Skip to content

fix(charts): keep pie slices proportional for extreme finite values - #1067

Merged
dovvnloading merged 1 commit into
mainfrom
agent/pie-chart-overflow
Nov 25, 2026
Merged

dovvnloading merged 1 commit into
mainfrom
agent/pie-chart-overflow

Conversation

@dovvnloading

Copy link
Copy Markdown
Owner

Summary

Fixes #1045. Finite positive pie values can have an overflowing sum; Matplotlib also converts inputs to float32, so values well inside the double range can overflow or underflow there. Calculate geometry and percentages from max-scaled weights in both interactive SVG (including the overview) and static publication exports.

What Changed

  • Scale each value before aggregating the top-nine-plus-Other weights; compute proportions from those weights, and close the live SVG sweep at 360 degrees.
  • Use the same shares for tooltips and legends instead of dividing raw values by an overflowing total. Use stable input order for equal values in both renderers.
  • Preserve stored data and original-unit values. Display very large/small finite totals in scientific notation and overflowing raw totals or Other values as the explicit lower bound >1.79e308. Positive shares below 0.1% are labeled <0.1% rather than zero.
  • Add seven focused TypeScript slice cases, two chart component cases, and parameterized SVG/PDF/PNG publication regressions covering equal huge values, overflow in Other, mixed magnitudes, subnormal values and an ordinary chart. Update the existing publication geometry assertion to expect the proportional scaled weights [0.5, 1] for raw [2, 4].

Why

The maximum value is finite and positive for a valid pie, so dividing each value by it makes the geometry bounded before grouping or summing. This avoids both the double-precision sum overflow and Matplotlib's float32 input range problem without changing validation, persisted data or units. Extremely small ratios can still round to zero-width at available numeric/rendering precision; their labels explicitly indicate the small positive share.

Validation

  • Strict TypeScript compilation of the isolated slice builder (Node 22 / TypeScript 5.8); six Node checks passed, and the tested file's Git blob SHA matches the committed file.
  • Isolated Matplotlib 3.10.8 checks of the changed pie-rendering function: 15 render, geometry and legend checks passed (five value cases × SVG/PDF/PNG).
  • Reviewed the committed diff scope: six intended files, one commit ahead of main and zero behind at comparison time.
  • App launches
  • Relevant workflow was exercised manually
  • python -m compileall -q . passes (run from the repo root - matches CI)
  • python -m pytest -q passes (run from the repo root - matches CI)
  • cd web_ui && npm run check passes (matches CI)

Local full checkout is blocked by GitHub DNS resolution. The isolated checks are not a full repo test run; the added Vitest component/geometry and pytest publication tests require CI or a configured checkout (Python 3.12 / Node 24). Focused commands:

python -m pytest -q -n0 backend/tests/test_chart_publication_export.py
npm --prefix web_ui run test -- src/app/canvas/charts/pieSlices.test.ts src/app/canvas/charts/ChartRenderer.test.tsx src/app/canvas/charts/ChartOverview.test.tsx
npm --prefix web_ui run check

Manual verification: generate or load a pie with values [1e308, 1e308]; check the two half-circle wedges, 50% legends and hover values, total lower bound, overview, both themes and publication exports. Repeat with 12 equal values and a very small positive slice.

UI Notes

  • Screenshots included if the change is visual
  • No screenshots needed

No new UI components or styles. Labels and extreme-value geometry change; screenshots, keyboard and both-theme checks remain pending.

Additional Context

No dependency, wire-schema, data migration or CI changes. The overflow label deliberately reports a lower bound instead of fabricating a finite total; raw inputs remain available. Draft pending CI and manual review; do not merge until required checks and manual validation pass.

@dovvnloading dovvnloading left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Reviewed all six changed files at e8d8426. No blocking code findings. Max-scaling occurs before aggregation, the positive/finite canonical input contract and 300-point cap make the normalization safe, both renderers preserve ordering and proportional shares, and original values are not mutated. The existing SVG overview consumes the same helper. No schema/dependency/CI changes.

Validation:

  • GitHub Actions CI run 45595968214: all four required jobs passed (Windows Python including compile, pytest and perf; frontend schema/type/lint/Vitest/build; wheel install/build; POSIX permissions and focused Bash E2E). Nightly-only Playwright boot-smoke was skipped as designed.
  • Independently compiled the exact pieSlices.ts blob and exercised it and the exact PieChartMarks.tsx blob in an isolated Chromium SVG/DOM harness (fixture theme values and lightweight React/JSX adapter, not the full application). Visually inspected light/dark screenshots: equal huge values, 12 huge values including Other, mixed extremes, subnormals, and normal values; legend, tooltip handlers, overview geometry, and 1,000 additional randomized geometry cases passed.
  • Independently exercised the copied _render_pie_chart implementation with Matplotlib 3.10.8: 15 geometry, label, and SVG/PDF/PNG output checks passed.
  • Main has advanced three unrelated commits; compared changed paths, with no overlap with this PR.

Limitation: local GitHub checkout fails DNS, so I could not launch the full desktop app or manually exercise integrated keyboard navigation/theme switching. The targeted browser harness is supplemental, not a replacement for CI. The full CI gates are green; manual focused rendering review is complete. This is a comment review rather than an independent GitHub approval because the connected account is the PR author.

@dovvnloading
dovvnloading marked this pull request as ready for review November 25, 2026 10:58
@dovvnloading
dovvnloading merged commit 08b18d0 into main Nov 25, 2026
5 checks passed
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.

bug(charts): overflow of finite pie values collapses all SVG slices to zero degrees

1 participant