diff --git a/app/components/goals/funding_accounts_breakdown_component.html.erb b/app/components/goals/funding_accounts_breakdown_component.html.erb index c67f924e9..95bff4010 100644 --- a/app/components/goals/funding_accounts_breakdown_component.html.erb +++ b/app/components/goals/funding_accounts_breakdown_component.html.erb @@ -39,7 +39,7 @@ <% account = row[:account] %> <% color = Goals::AvatarComponent.color_for(account.name) %> <% spark = row[:sparkline_points] %> - <% spark_max = [ spark.max, 1.0 ].max %> + <% spark_max = shared_spark_max %>
<%= render Goals::AvatarComponent.new(name: account.name, color: color, size: "sm") %> @@ -57,10 +57,12 @@ <% end %>
diff --git a/app/components/goals/funding_accounts_breakdown_component.rb b/app/components/goals/funding_accounts_breakdown_component.rb index 294ff0825..e5a8b80dd 100644 --- a/app/components/goals/funding_accounts_breakdown_component.rb +++ b/app/components/goals/funding_accounts_breakdown_component.rb @@ -29,6 +29,18 @@ class Goals::FundingAccountsBreakdownComponent < ApplicationComponent ((balance.to_d / total) * 100).round end + # Shared Y-max across every account's sparkline so per-row amplitudes + # are comparable at a glance. Without this each row scaled to its own + # max and a $50 bump on an orange account rendered as tall as a $400 + # weekly peak on a pink one — the eye reads them as equal contribution + # when the weight pills already say they aren't. + def shared_spark_max + @shared_spark_max ||= begin + points = rows.flat_map { |r| r[:sparkline_points] } + [ points.max.to_f, 1.0 ].max + end + end + # Label shown beneath the account name. Prefers the depository subtype # ("Savings", "HSA"…) over the bare accountable_type ("Depository") so the # subline carries useful signal. Falls back to the accountable type's i18n