Give a colourless goal's ring a real fallback colour
Summary
A goal with no colour now gets a progress ring. Its filled segment used to fall back to a CSS variable that the ring's d3 code can't parse, so the ring drew nothing but its label. The design choice: the fallback is Goal::COLORS.first, the colour Goals::AvatarComponent already uses for a goal without one, so a colourless goal's ring and avatar now match.
Closes #4030
Fork pre-flight PR: jaysbeekay/sure#346 (pull/346). Same branch, same commit; its CI and review history are there.
What changed
Goal#to_donut_segments_json: thesavedsegment's fallback changes from"var(--color-blue-500)"toGoal::COLORS.first. That's the whole code change.- Why that line:
donut_chart_controller#transformRingColorruns every segment exceptunused/overagethroughd3.color(color)and then sets.opacityon the result.d3.color("var(--color-blue-500)")isnull, so the controller threwTypeError: Cannot set properties of null (setting 'opacity')while connecting, and no arc was drawn.
Deliberately not changed:
- The controller. With this fix nothing passes it an unparseable colour: the budget donuts' filled segments use
Category#color, which is required hex, and theirvar(...)colours are the unused and overage segments, which skipd3.color. A guard there would fit better with #1899. - No backfill of existing rows; the fallback is display-only.
coloris not made required on goals; that would be a behaviour change for API and console callers.
Demo data
No demo data needed: Demo::Generator gives every goal a colour (Goal::COLORS.sample), so demo goals draw as before.
Screenshots
A goal saved without a colour ($2,000 of $5,000), captured from a system-test session in headless Chromium.
| Before | After |
|---|---|
![]() | ![]() |
Migration notes
No migration.
Verification
Tests were written first. On main, two of the three new tests in test/models/goal_test.rb failed with Expected: "#e99537", Actual: "var(--color-blue-500)":
- "a goal without a colour gives its ring a real colour": the
savedcolour isGoal::COLORS.firstand a hex string. - "a colourless goal's ring and avatar fall back to the same colour": the ring's colour equals
Goals::AvatarComponent.new(goal:).color.
The third, "a goal with a colour keeps it in its ring, and the remaining track is unchanged", passes before and after, as a guard should.
Breaking the fix on purpose fails a test each time:
| Breakage | Caught by |
|---|---|
| CSS variable put back | both fallback tests |
A different palette entry (COLORS.second) | both fallback tests |
| Fallback used even when the goal has a colour | the keeps-its-colour test |
Commands:
bin/rails testone947ddf3e: 10,798 runs, 46,120 assertions, 0 failures, 0 errors, 33 skips- goal model, goals controller and goal component tests: 192 runs, 0 failures
bin/rubocopon the changed files: no offensesbin/brakeman --no-pager: 0 warningserb_lintandnpm run lint: not applicable, no ERB or JS changed
Blast radius
to_donut_segments_jsonhas one caller,Goals::ProgressRingComponent(progress_ring_component.html.erb).- Only the
savedsegment of a goal with a blank colour changes. A goal with a colour sends exactly what it sent before, and theunusedsegment keepsvar(--budget-unused-fill). Goals::AvatarComponentis unchanged; it's where the fallback comes from, and a test pins the two together.
Summary by CodeRabbit
- Bug Fixes
- Goals without a custom color now use the standard goal color for the saved portion of the progress ring, matching the goal’s avatar color. Custom colors remain unchanged.

