Skip to content

fix(AllocationWidget): correct donut SVG strokeDasharray/offset and n… - #989

Open
dmoonventure070-art wants to merge 1 commit into
RevoraOrg:masterfrom
dmoonventure070-art:fix/allocation-widget-donut
Open

dmoonventure070-art wants to merge 1 commit into
RevoraOrg:masterfrom
dmoonventure070-art:fix/allocation-widget-donut

Conversation

@dmoonventure070-art

Copy link
Copy Markdown

Closes #917

Summary

Fixes the SVG donut geometry in AllocationWidget where slices were rendered with strokeDasharray="${len} ${C}" (period len + C instead of C) and strokeDashoffset={C - cumulative}, shifting each slice by its own length and producing negative dash lengths on tiny slices (< 0.56%).

Changes

  • Correct SVG dash period & offset (src/components/AllocationWidget.tsx):
    • Clamp dashLen using Math.max(0, sliceLen - (gap / 360) * circumference) so tiny slices never produce negative dash lengths.
    • Use strokeDasharray={${seg.dashLen} ${circumference - seg.dashLen}} so the dash pattern period is always circumference (C).
    • Use strokeDashoffset={-cumulativeLen} so slice i starts at the cumulative arc length of preceding slices.
  • Normalise slice percentages (normaliseSlices):
    • Ensure both the drawn donut arcs and the legend percentages derive from the same normalised data when input totals do not sum to 100.
  • Unit & regression tests (src/components/AllocationWidget.test.tsx):
    • Assert computed stroke-dasharray and stroke-dashoffset for [50, 50] (two half rings), [70, 20, 10], and [99.7, 0.3].
    • Verify no negative dash values are produced for sub-gap slices.
    • Verify un-normalised slice totals render matching normalised arcs and legend percentages.

Verification

  • npx vitest run src/components/AllocationWidget.test.tsx --coverage (25/25 passing, 100% statement/branch/function/line coverage on AllocationWidget.tsx)
  • npm run lint passes with zero warnings/errors

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.

fix(allocation-widget): donut chart segments are drawn at the wrong positions because of an incorrect strokeDasharray/offset

2 participants