The personal finance app for everyone (by everyone)
Ruby
<div id="<%= dom_id(account, :chart) %>" class="bg-container shadow-border-xs rounded-xl space-y-2">
<div class="flex justify-between flex-col-reverse lg:flex-row gap-2 px-4 pt-4 mb-2">
<div class="space-y-2 w-full">
<div class="flex items-center gap-1">
<%= tag.p title, class: "text-sm font-medium text-secondary" %>
<% if account.supports_trades? %>
<% has_scheduled = account.scheduled_entries_total_money.amount.abs.round.nonzero? %>
<%= render "investments/value_tooltip",
balance: account.balance_money,
holdings: holdings_value_money,
cash: account.cash_balance_money,
scheduled: (account.scheduled_entries_total_money if has_scheduled),
projected: (account.projected_balance_money if has_scheduled) %>
<% elsif account.scheduled_entries_total_money.amount.abs.round.nonzero? %>
<%= render "accounts/scheduled_balance_tooltip", account: account %>
<% end %>
</div>
<div class="flex flex-row gap-2 items-baseline">
<%= tag.p view_balance_display, class: "text-primary text-3xl font-medium truncate privacy-sensitive" %>
<% if converted_balance_display %>
<%= tag.p converted_balance_display, class: "text-sm font-medium text-secondary privacy-sensitive" %>
<% end %>
</div>
</div>
<div class="flex items-center gap-2">
<% if account.supports_trades? %>
<%= form_with url: account_path(account), method: :get, data: { controller: "auto-submit-form" } do |form| %>
<% chart_view_hidden_fields.each do |name, value| %>
<%= hidden_field_tag name, value, id: nil %>
<% end %>
<%= form.select :chart_view,
[[t("UI.account.chart.views.total_value"), "balance"], [t("UI.account.chart.views.holdings"), "holdings_balance"], [t("UI.account.chart.views.cash"), "cash_balance"], [t("UI.account.chart.views.gains"), "gains"]],
{ selected: view },
class: "bg-container border border-secondary rounded-lg text-sm pr-7 cursor-pointer text-primary focus:outline-hidden focus:ring-0",
autocomplete: "off",
data: { "auto-submit-form-target": "auto" } %>
<% end %>
<% end %>
<%= render UI::PeriodPicker.new(
selected: period_picker_selected,
url: account_path(account),
extra_params: period_picker_extra_params,
custom_extra_params: period_picker_custom_extra_params,
options: period_picker_options
) %>
</div>
</div>
<%= turbo_frame_tag dom_id(@account, :chart_details) do %>
<div class="px-4">
<%= render partial: "shared/trend_change", locals: { trend: trend, comparison_label: comparison_label } %>
</div>
<% if loan_chart? %>
<%# The loan balance chart: recorded balance, original schedule and
projection on one axis, with the figures the projection produces beside
it. Everything in this branch is loan-only; the else branch below is the
chart every other account type has always had. %>
<div class="px-4 mb-2 grid grid-cols-2 gap-2">
<% if loan_projected_payoff_date %>
<%= render "accounts/summary_card", title: t("UI.account.chart.loan.projected_payoff"), content: capture { %>
<%= I18n.l(loan_projected_payoff_date, format: :long) %>
<span class="block text-xs text-secondary mt-1"><%= loan_schedule_comparison %></span>
<% } %>
<%= render "accounts/summary_card", title: t("UI.account.chart.loan.interest_saved"), content: capture { %>
<%= loan_interest_saved_money.format %>
<% } %>
<%# The basis of the comparison, beside the figures it governs: the
schedule's dates are anniversaries of origination, not the
lender's posting dates, so a payment posted before its date
reads as ahead until that date and one posted after as behind. %>
<p class="col-span-2 text-xs text-secondary"><%= t("UI.account.chart.loan.projection_basis") %></p>
<% elsif loan_projection_not_converged? %>
<p class="col-span-2 text-sm text-secondary"><%= t("UI.account.chart.loan.not_converged", balloon: loan_balloon_money.format) %></p>
<% end %>
</div>
<div class="h-64 px-4">
<%# privacy-sensitive: the axis, the lines and the tooltip are all
balances, and Privacy Mode blurs balances everywhere else here.
text-primary so the axis can draw in currentColor. %>
<div id="<%= loan_chart_id %>"
class="w-full h-full privacy-sensitive text-primary"
data-controller="loan-payoff-chart"
data-loan-payoff-chart-data-value="<%= loan_chart.to_json %>"></div>
</div>
<ul class="flex flex-wrap gap-x-4 gap-y-1 px-4 pt-2 pb-4 text-xs text-secondary" aria-label="<%= t("UI.account.chart.loan.legend") %>">
<% loan_legend.each do |key, style| %>
<li class="flex items-center gap-1.5">
<span class="inline-block w-4 h-0 border-t-2 <%= "border-dashed" if style[:dashed] %>" style="border-color: var(<%= style[:token] %>);" aria-hidden="true"></span>
<%= loan_chart[:labels][key.to_sym] %>
</li>
<% end %>
<% loan_share_legend.each do |key, style| %>
<li class="flex items-center gap-1.5">
<span class="inline-block w-3 h-3 rounded-sm border" style="<%= loan_share_swatch_style(style) %>" aria-hidden="true"></span>
<%= loan_chart[:labels][key.to_sym] %>
</li>
<% end %>
</ul>
<%# Real DOM text, not only the SVG's aria-label. The chart has no data
table of its own: the Schedule tab carries the figures. It quotes the
balance, so it is privacy-sensitive like every other balance here. %>
<p class="sr-only privacy-sensitive"><%= loan_chart[:aria_description] %></p>
<% else %>
<div class="h-64 pb-4">
<% if series.any? %>
<div
id="lineChart"
class="w-full h-full privacy-sensitive"
data-controller="time-series-chart"
data-time-series-chart-selectable-value="true"
data-time-series-chart-linked-range-params-value="<%= ACTIVITY_RANGE_PARAMS.to_json %>"
data-time-series-chart-reset-params-value="<%= ACTIVITY_RESET_PARAMS.to_json %>"
data-time-series-chart-data-value="<%= series.to_json %>"></div>
<% else %>
<div class="w-full h-full flex items-center justify-center">
<p class="text-secondary text-sm"><%= t("UI.account.chart.no_data_available") %></p>
</div>
<% end %>
</div>
<% end %>
<% end %>
</div>