Draw a card's credit limit as a line on its balance chart
Part of #4356
Fork pre-flight: jaysbeekay/sure#1021 (same commits)
Stacked on up/card-credit-limit.
Verified on the stack's top commit 6f85ab855 (up/card-next-statement, with current main merged in at the bottom and each slice merged up the chain): full unit suite 19760 runs, 0 failures, 8 errors, 9 skips (the 8 are ReleaseNotesWorkflowTest, no node in the test container); the card system test credit_card_limit_chart_test 8 runs, 0 failures.
Summary
A card with a credit limit now shows the limit on its balance chart: a solid line that joins the chart's y-domain (so it is always on the plot), and, once the balance reaches 80% of the limit, a tinted band between the 80% level and the line. The card chart gets a legend. Every other account, and a card without a limit, gets exactly the chart payload it had before.
What changed
UI::Account::Chart#chart_data: the series JSON, plusreference_line: { value, threshold, tinted, token, band_opacity }only for aCreditCardwith a positivecredit_limit.tintedcompares the last plotted balance withlimit × CARD_LIMIT_ALERT_SHARE(0.8) directly, so 4,799.99 of 6,000 (79.9998%, which rounds to 80.0) does not tint and 4,800 does. The band describes the line it sits on, so a past range tints from its own last point, not from today's balance.CARD_LIMIT_TOKEN(--color-warning) andCARD_LIMIT_BAND_OPACITY(0.12). The line uses warning, not destructive, because the balance line itself turns red as debt grows (screenshot below). The chart's band and the legend swatch share the one opacity. Solid, because the limit is a fact (dashed stays "forecast", perLOAN_SERIES_STYLES).chart.html.erb: the time-series mount readschart_data. Under a card chart that has a limit there is a legend: the balance swatch in the trend colour, the limit line, and the band only when tinted. The legend shows only when the series has two or more points, which is when the controller draws the line. The loan and card legends share two component-local helpers,legend_line_itemandlegend_swatch_item. They are not aDS::*primitive, because only this component uses them. The band swatch has a full-strength border, and its fill is at the band's opacity.time_series_chart_controller.js:_referenceLinefrom the payload._d3YScaleincludes the limit in the domain, and the scale is built once per draw (memoised, cleared at the start of_draw)._drawReferenceLinedraws the band (when tinted) and then the line, before the trendline. Flatness is still judged from the balance points only, so an unchanged balance keeps its faint hairline with the limit above it.components/en.yml: legend labels; the band label is "%{share} or more of the limit", with the share taken fromCARD_LIMIT_ALERT_SHARE.
Tests
test/components/UI/account/chart_test.rb (red on up/card-credit-limit: 2 errors, undefined method '[]' for nil — no reference_line)
- 533.10 of 6,000 →
reference_linevalue 6000.0, threshold 4800.0, tinted false; legend lists "Credit limit" - 4,800 → tinted; 4,799.99 → not tinted (balances set on the series)
- no limit and limit 0 → no
reference_linekey, no legend; a depository's payload is byte-identical toseries.as_json
Added after review (each failed first as noted):
- "a card whose series has one point shows no limit legend": before,
expected not to find ul[aria-label='Chart series'], found 1 - "the band is tinted from the last plotted balance, not the account balance": before,
Expected false, Actual true - "the band legend names the alert share it is tinted from": with the share swapped to 0.9 the legend reads 90%; before, it still read 80%
- "a card with a limit and no balance points is not tinted": before,
NoMethodErroron a nil last value
test/system/credit_card_limit_chart_test.rb (new, browser)
- limit far above the balance: the line's y is inside the plot (≥ 0, < height) and above the balance line; no band
- balance at 80% → band drawn, its top equal to the line's
y1(within 1px), its height positive, its fill the line's stroke - new "a balance at the limit meets the limit line": the line sits on the trendline's top (within 1px)
- new "the legend swatch tints its fill like the band and borders it like the line": opacity 1, border = the line's stroke, fill alpha = the band opacity
- new "an unchanged balance under a limit stays a hairline, with the limit on the chart": stroke-opacity 0.4, limit inside the plot and above the balance
- new "the chart builds its y-scale once per draw" and "a draw builds its own y-scale without a teardown first"
- no limit → no reference elements
Mutations (each alone)
| # | Mutation | Caught by |
|---|---|---|
| M1 | tint on > not >= | 80% boundary |
| M2 | tint on rounded utilization_percent >= 80 | 80% boundary (4,799.99) |
| M3 | reference_line always merged (nil) | no-limit/depository payload |
| M4 | non-positive limit accepted | limit 0 |
| M5 | legend removed | legend test |
| M6 | threshold 85% | threshold + boundary tests |
| J1 | limit not in the y-domain | system: line inside the plot (y was negative) |
| J2 | band always drawn | system: no band below 80% |
| J3 | reference never drawn | system: both line tests |
| J4 | line drawn at ref.threshold instead of ref.value | system: band top = line, balance at the limit |
| R1 | legend guard back to series.any? | one-point legend test |
| R2 | tint from account.balance | last-plotted-balance test |
| R3 | flatness judged with the limit included | hairline test |
| R4 | limit dropped from the y-domain | 4 system tests |
| R5 | y-scale memo not cleared in _draw | both y-scale tests |
| R6 | swatch at element opacity, no border, or half the fill | swatch test |
| R7 | share hard-coded as "80%" (method or view) | alert-share test |
| R8 | nil-safe last value removed | no-points test |
Verification
- Head 9e00509e9 changes only
reference_line_geometryintest/system/credit_card_limit_chart_test.rb, which now checks the line against the plot height from the controller. That file ran 8 runs, 0 failures on it. The previous head, 7100fedfa, was a merge of base 787be900 that changed no file this PR owns, and its CI was green. CI on 9e00509e9: all 12 runs pass. - Full unit suite on b304ea7b2:
19502 runs, 0 failures, 8 errors, 9 skips(the 8ReleaseNotesWorkflowTesterrors, nonode). After merging the updatedup/card-credit-limitandup/card-daily-interest(7b72b7b0d), the targeted card and chart files ran508 runs, 0 failures, 0 errors. - System tests:
credit_card_limit_chart_test,loan_payoff_chart_test,account_chart_drag_select_test,dashboard_chart_drag_select_test,chart_sidebar_resize_test,chart_touch_test: 54 runs, 0 failures. bin/rubocop: no offenses.erb_lint: no errors.biome lint(chart controller): clean.bin/brakeman: 0 warnings.
Screenshots
Seeded card: balance $5,100 of a $6,000 limit (85%, so the band is tinted). Before = up/card-credit-limit.
| View | Before | After |
|---|---|---|
| Card page (chart + Overview) — light, desktop | ![]() | ![]() |
| Card page (chart + Overview) — light, phone | ![]() | ![]() |
| Card page (chart + Overview) — dark, desktop | ![]() | ![]() |
| Card page (chart + Overview) — dark, phone | ![]() | ![]() |
After the review fixes (b304ea7b2). "High" is 85% of the limit (band tinted; the swatch is bordered like the line and filled like the band). "Low" is 8.9% of the limit, showing how the limit in the y-range lowers a small balance. "Flat" is an unchanged balance, which keeps its hairline under the limit.
| View | Light | Dark |
|---|---|---|
| High, desktop | ![]() | ![]() |
| High, phone | ![]() | ![]() |
| Low, desktop | ![]() | ![]() |
| Low, phone | ![]() | ![]() |
| Flat, desktop | ![]() | ![]() |
Design system
The legend's line and swatch items are defined once in this diff: the loan legend's two inline <li> shapes (upstream chart.html.erb:95 and :101) become legend_line_item and legend_swatch_item, and the card legend calls the same helpers. The same line-swatch-beside-a-label shape is also hand-built upstream in app/components/goals/lifecycle_panel_component.html.erb:134-150. A DS::ChartLegend primitive (line and swatch items) covering the account chart and the goals panel is offered as a follow-up proposal upstream. It is not part of this PR.
Migration notes
No migration.
Blast radius
chart.html.erb's time-series mount is shared by every non-loan account.chart_datareturnsseries.as_jsonunchanged unless the account is a card with a positive limit (pinned by the depository byte-equality test);series.to_jsonandseries.as_json.to_jsonare the same string.- The limit stays in the y-domain on purpose: a line that slips off the top of the chart would be worse than a compressed low balance (see the "Low" screenshots).
time_series_chart_controller.jsalso draws sidebar sparklines, the dashboard net-worth chart and investment charts._referenceLineis null for all of them, so_d3YScaleand_drawCharttake their old paths (chart system tests above green).- Overlap: open upstream PRs #5297, #5624 (investment net contributions), #3973, #5270, #3709 touch
UI::Account::Chart; textual only.
Summary by cubic
Adds a card’s credit limit as a line on its balance chart, part of #4356. A card with a positive limit now draws the limit as a solid line that joins the chart’s y-domain, tints the band between 80% of the limit and the line once the balance reaches it, and shows a legend; cards without a limit and all other account types keep the exact same chart payload.
- Tinting is decided by the last plotted balance against the raw limit, so 4,799.99 of 6,000 doesn’t tint while 4,800 does.
- The tinted band is clamped to the plot’s bottom edge when the 80% threshold falls below the plot.
- The legend shows only when the chart draws (two or more points); loan and card legends share two component-local helpers.
- System tests now check the limit line against the plot’s own height, not the svg’s.
Summary by CodeRabbit
- New Features
- Credit-card charts with a positive limit now show the credit limit alongside the balance.
- When the latest charted balance reaches the alert threshold (80% by default), the chart highlights the near-limit range and shows the balance as a percentage of the limit in the legend.
- Loan chart legends distinguish actual amounts from scheduled amounts with solid and dashed swatches, respectively.

















