From 6254a0260201e9f4eaa9474702c7e91f6c7eacfb Mon Sep 17 00:00:00 2001 From: Guillem Arias Date: Mon, 11 May 2026 16:49:47 +0200 Subject: [PATCH] fix(savings_goals/show): chart axis includes backdated contributions, legend uses real colors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit projection_payload's start_date was created_at, but demo seeds (and manual imports) can have contributions backdated before created_at — those points were getting clipped/pushed left of the chart's x-domain and the saved-series line couldn't render. Use min(created_at, earliest contribution date) so the axis spans the full history. Legend "saved" line stroke was var(--text-primary) which doesn't resolve (Tailwind utility, not CSS var) → invisible swatch. Wrap in text-primary span + stroke="currentColor". Legend "projection" line was hardcoded yellow — chart paints green for on_track goals → mismatch. Pick legend color based on goal status so it matches what the chart actually draws. --- app/models/savings_goal.rb | 4 +++- app/views/savings_goals/show.html.erb | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/savings_goal.rb b/app/models/savings_goal.rb index 723b479bf..53141e5e0 100644 --- a/app/models/savings_goal.rb +++ b/app/models/savings_goal.rb @@ -146,9 +146,11 @@ class SavingsGoal < ApplicationRecord { date: c.contributed_at.to_s, value: running.to_f } end + earliest = [ created_at.to_date, sorted.first&.contributed_at ].compact.min + { saved_series: saved_series, - start_date: created_at.to_date.to_s, + start_date: earliest.to_s, today: Date.current.to_s, target_date: target_date&.to_s, target_amount: target_amount.to_f, diff --git a/app/views/savings_goals/show.html.erb b/app/views/savings_goals/show.html.erb index f77d75421..89e20d5c7 100644 --- a/app/views/savings_goals/show.html.erb +++ b/app/views/savings_goals/show.html.erb @@ -182,13 +182,14 @@

<%= t(".projection.heading") %>

<%= @stats[:projection_summary].html_safe %>

+ <% projection_color = @savings_goal.status == :on_track ? "var(--color-green-600)" : "var(--color-yellow-600)" %>
- + <%= t(".projection.legend_saved") %> - + <%= t(".projection.legend_projection") %>