Say what each scheduled payment is made of, in the chart's tooltip

Merged
JA
2mo ago
+129-13

Closes #21. Option A, your decision of 2026-09-21.

The gap

The figures were already on the rows the chart walks. Loan::AmortizationSchedule#display_rows carries principal_payment and interest_payment; the Schedule tab's table prints both (_schedule.html.erb:230-231); and Loan#payoff_chart_payload mapped those same rows to { date:, balance: }, dropping the two payment fields one line before render. loan_payoff_chart_controller.js contained neither word.

So one page rendered the same rows twice, and the half that can actually convey amortisation front-loading — roughly two-thirds of year-one payments being interest on a 30-year loan at 6% — was the half that didn't carry it. A 360-row table cannot make that visible; the chart can.

What changed

  • Payload: principal and interest on each point of scheduled_history and original_projection. No new query, no new model, no new component — the same display_rows call that already produced the balances.
  • Tooltip: a composition row beside the balance it already showed, in secondary styling, so pointing at a date answers "what is this payment actually doing" where the user is already pointing.
  • Labels: reuse loans.tabs.schedule.principal / .interest, the table's own keys. The chart and the table name the same two figures, and a second pair of keys is how they end up calling them different things.

The accelerated series is deliberately not composed. Those figures come from the projection rather than the contracted schedule, and with a what-if active that projection is a scenario — out of scope per #100 decision 10. The tooltip checks for the fields rather than assuming them, so an uncomposed point simply shows no row.

The first version of the test could not fail

Worth stating rather than hiding, since it is the rule #204 is about. build_chart_loan defaults to start_date: Date.current, so every payment date is in the future, scheduled_history is empty, and the test read only the projection. Stripping the composition out of scheduled_history left it green.

The loan now originates five years back, and the test asserts both series are populated before asserting anything about them. After that:

MutationResult
scheduled_history stops carrying the compositionExpected: 806.86, Actual: nil
original_projection stops carrying the compositionExpected: 954.93, Actual: nil

The composition is also asserted against the table's own source rather than against the payload's internal consistency — the point is that the chart and the table cannot disagree, which a self-comparison would not catch — and principal + interest is checked to reconcile to payment_amount, because a split that does not add up is two numbers, not a split.

The front-loading claim is asserted rather than assumed: first payment interest-dominant, last principal-dominant, interest falling across the life of the loan. If that ever fails, the tooltip is telling users a comfortable falsehood.

On the surface this lands in

The fork's chart is on the Schedule tab, and #100 decision 2 retires it once we-promise/sure#3474 syncs. Building here anyway is a deliberate choice, not an oversight: the same two changes apply to the upstream payload class, and fork users get the figure now rather than after an upstream merge that has been open since 16 September.

Verification

Full suite 9985 runs, 0 failures, 0 errors; bin/rubocop and npm run lint clean.