Draw net contributions beside total value on the account chart
Updated 2026-11-15: rebased onto the new portfolio stack. #4197 and #4198 were replaced by #5088 and #5089 (native stack #5133; fork pre-flights jaysbeekay/sure#707 and jaysbeekay/sure#708). This branch is now one commit, d8b2cb6e5, on top of #4028's rebuilt commit 91375e09d, which sits on #5089. Its content equals the previous head (6bcda368b) with main merged in, exactly; the earlier commit subjects are listed in its message. Its own diff is unchanged. It stays a PR against main, so until #5088, #5089 and #4028 merge its diff includes them. To review this slice alone: up/net-contributions-model...up/net-contributions-chart. Full suite on d8b2cb6e5: 16,371 runs, 0 failures; the 8 errors are ReleaseNotesWorkflowTest, which needs node, missing in the test image. Rubocop, erb_lint and Brakeman are clean. Older notes below refer to #4197 and #4198, which are superseded.
Updated 2026-11-05. #4028's head is merged down, bringing #4197's bound-value marker fix (11bb8a1bd, 0e334559a) and upstream main (529d7de76). No change to this PR's own files. To review this slice alone: up/net-contributions-model...up/net-contributions-chart. Merge bottom-up; main is merged down after each one. Full suite on 2ce4a46d2: 14,808 runs, 0 failures, 0 errors.
Rebuilt on 2026-10-08, together with #4028. It's the same chart, now drawing #4028's series, which reads Portfolio::DailyReturns. The previous version (64899409d) had no reviews.
This PR is the last of a stack:
- #3557 added the flow classifier (merged).
- #5088 adds
Portfolio::DailyReturns, and #5089 values a journalled security at its position (native stack #5133; they replace #4197 and #4198). Their fork pre-flights are jaysbeekay/sure#707 and jaysbeekay/sure#708. - #4028 adds the net contributions series, read from those daily returns.
- This PR draws the series. It is built on #4028's branch (
up/net-contributions-model).
Rebased onto main (3e35aaa07) on 2026-10-13, on top of #4028's rebased branch. GitHub still shows the parents' commits here. This PR's own commits:
21e209447Draw net contributions beside total value on the account chartecffa0d03Say net contributions may be incomplete, not understated0bfec27e4Pin the null percent for zero net contributions08f400b76Test the net contributions line in the browser
6b9fff8ef merges #4028's branch down to bring its 0ca4e5360. It is a merge, not a rebase, so the branch fast-forwarded.
Updated 2026-10-14. fdf6e2322 merges #4028 at 8e5c9266c (a clean merge), bringing the returns-engine review fixes (one row per entry, flow FX, excluded entries, the journal carry). No chart code changes.
Updated 2026-10-23. b6b9791da merges #4028 at 2ca797345, bringing #4198 at fc400f58f and #4197 at c285e4a49. The one overlap, config/locales/views/components/fr.yml, keeps upstream's new French wording and this PR's net_contributions keys. No chart code changed. Full suite on b6b9791da: 13,082 runs, 60,102 assertions, 0 failures, 0 errors, 36 skips.
Updated 2026-10-15. 87cdb576e merges #4028 at f41a201b4, bringing the returns engine's 2026-10-15 review fixes (excluded transfer legs, the transfer ordering, the liability refusal, and a journal dated before the period carried to its first priced day inside it). No chart code changes.
21e209447 is the first version's commit (64899409d), cherry-picked without conflicts and rebased unchanged. The only edits from the first version are the note's wording, its key and hook names, and one comment, because the rule for "understated" changed with the model (see below).
Closes #4008
Fork pre-flight PR: jaysbeekay/sure#344 (pull/344), same branch, same commit (up/net-contributions-chart at b6b9791da)
#4009 is in. The opening-day fix is on #4028 (jaysbeekay/sure#382), and this chart draws that series unchanged. ecffa0d03 replaces "understated" (jaysbeekay/sure#383): an unvalued withdrawal pushes the line up, not down. The note now reads "Net contributions may be incomplete: a deposit or withdrawal could not be valued."
Summary
On an investment account, and on a Crypto exchange account, the Total value chart now draws a second, dashed line: Net contributions. That is the money put in, net of the money taken out. The gap between the two lines is how the account has actually performed, and because the line is now built from the same daily returns as the portfolio's return figures, the gap agrees with them. The tooltip adds net contributions and the signed difference, with the difference as a percentage of net contributions. A legend under the chart names both lines.
What changed
UI::Account::Chartpasses the model PR's series totime_series_chart_controlleras a new optionalcomparisonvalue. Each point carries its difference from total value. The figures are rounded the same way as the value line's points, so the three numbers in the tooltip agree.time_series_chart_controller.js:- When
comparisonis present, the controller draws a dashedtext-secondaryline on the same scales. Both lines' points set the y domain. - It adds two rows to the tooltip: Net contributions and Difference. The rows are built as DOM nodes with d3's
.text(), not as an HTML string, so no label or amount is parsed as markup. When net contributions are zero the percentage is left off rather than shown as infinity. - Without
comparison, the controller takes exactly the path it took before.
- When
- The legend follows the shape the loan chart's legend already uses: a
ulwith anaria-labelandaria-hiddenswatches. The lines differ in style (solid and dashed) as well as colour. - When a flow the line counts could not be valued (a currency with no rate at all, or a journalled position with no price that day), a note under the legend says net contributions may be incomplete, because a deposit or withdrawal could not be valued. It names no direction: an unvalued deposit leaves the line too low, an unvalued withdrawal too high.
- Four strings added to
config/locales/views/components/en.ymlunderUI.account.chart.net_contributions.
Unchanged: the Holdings, Cash and Gains views, accounts that don't hold trades, and every other caller of the controller.
Changed from the first version: the note now reads "Net contributions may be incomplete: a deposit or withdrawal could not be valued." Its key is UI.account.chart.net_contributions.incomplete and its hook data-net-contributions-incomplete. The first version's wording ("has no exchange rate for its date") no longer describes the rule: the model now carries the last known rate to a date with none, and also flags an unpriced journal. An interim wording said "understated", which is wrong for a withdrawal.
How flows are valued (from the model PR):
- A security moved in or out counts at the position's value that day. One moved in on a day with no price counts on the first later day in the period on which its holding has a price, and its own day still reads as incomplete. One moved in before the period and first priced inside it counts on that first priced day.
- A flow in another currency converts as the balance took it: into the account's currency on its own date (the entry's own rate first), then into the family's currency at the previous day's rate.
- A flow that cannot be valued counts as nothing, never at 1:1, and the incomplete note appears.
Demo data
No demo data change needed. From the generator's code, the demo Fidelity HSA Investment account's quarterly transfers from checking should step the line up, and the other demo investment accounts, which only record buys, should keep it flat at the opening value. I haven't checked this on a running demo instance.
Screenshots
Taken on 2026-11-05: Before is upstream main at 529d7de76, After is this branch at 2ce4a46d2. Both are the same 90-day view of the same test account:
- opened with $10,000 four months ago
- $2,500 deposited 65, 40 and 15 days ago
- the market value reconciled upward five times along the way (no flows of its own)
The tooltip is on 5 October: value $16,400 against $15,000 put in ($10,000 plus the first two deposits), so the difference is $1,400.
Total value, light
| Before | After |
|---|---|
![]() | ![]() |
Total value, dark
| Before | After |
|---|---|
![]() | ![]() |
Tooltip, light
| Before | After |
|---|---|
![]() | ![]() |
Tooltip, dark
| Before | After |
|---|---|
![]() | ![]() |
Migration notes
No migration.
Verification
Tests in test/components/UI/account/chart_test.rb, running against the daily-returns model:
- the Total value view of an investment account carries net contributions and a legend. The test checks the serialized difference: $400, +2.7% of $15,000.
- zero net contributions serialize a null percent the browser can parse. The account opens at $0, takes $5,000 in and $5,000 out, and is worth $400, so the difference's percentage is infinite. The test parses the attribute strictly (Ruby's
JSON.parserefuses a bareInfinity, as the browser's does) and asserts the percentage isnull, which the controller then leaves off. ActiveSupport writes a non-finite Float asnull, so this pins existing behaviour rather than fixing a defect. - the line isn't drawn on the Holdings, Cash or Gains views
- the line is drawn only for accounts that hold trades: an exchange Crypto account does, a wallet Crypto account and a Depository account don't
- the chart says when net contributions are incomplete. It also asserts that the note says "incomplete" and names no direction.
A system test, test/system/account_chart_net_contributions_test.rb, checks the drawing in a browser:
- an investment account draws the dashed net contributions line and its legend
- a depository account draws neither
I broke each part on purpose and reran the tests. A test caught every break:
| Breakage | Caught by |
|---|---|
Component drops the supports_trades? check | account-type test, the existing build-once test, and the depository system test |
Component drops the balance view check | views test |
| Difference computed the wrong way round | serialized-difference test |
Comparison attribute written with a bare Infinity (JSON.generate(..., allow_nan: true)) | zero-contributions test (JSON::ParserError) |
| Controller never draws the comparison line | investment system test |
| Incomplete note never shown | incomplete test |
| Incomplete note always shown | incomplete test + total value test |
| Comparison drawn from the value line's own series | total value test |
| Legend removed | total value test + incomplete test |
| Old "understated" copy restored | incomplete test |
| Component returns false | incomplete test |
The tooltip rows are not asserted in a browser: the drawn line and legend are, and the tooltip's figures come from the same serialized payload the component tests pin. The tooltip is shown in the screenshots.
Commands, on 08f400b76:
bin/rails test:11880 runs, 54663 assertions, 0 failures, 0 errors, 34 skipsDISABLE_PARALLELIZATION=true bin/rails test test/system/account_chart_net_contributions_test.rb test/system/account_chart_drag_select_test.rb: 3 runs, 0 failuresbin/rubocopon the changed Ruby: no offensesbundle exec erb_lint app/components/UI/account/chart.html.erb: no errorsbundle exec i18n-tasks unused/missing -l en: neither the old nor the new key reportedbiome linton the controller: clean.biome checkreports one formatting difference, at the_yAxisPadding/_yAxisMinRelSpancomments (lines 41-43), which aremain's own (#3906) and outside this diff.bin/brakeman: no warnings
Commands, on fdf6e2322 (2026-10-14):
bin/rails test:11932 runs, 54863 assertions, 0 failures, 0 errors, 34 skips
Commands, on 87cdb576e (2026-10-15):
bin/rails test:11939 runs, 54892 assertions, 0 failures, 0 errors, 34 skipsbin/brakeman: no warnings- system tests not re-run (no UI change)
Blast radius
Who else hits these lines, and what do they pass?
-
time_series_chart_controlleris shared by the dashboard net worth chart, the sparkline partial and the onboarding preferences preview, as well as the account chart. The newcomparisonvalue is optional. When it is absent,_comparisonPointsis empty, so:- no extra line is drawn
- the tooltip has no extra rows
- the y-scale domain is computed from the same points as before (an empty array is concatenated)
Only
UI::Account::Chartpasses the value (grep -rn "comparison-value" app), and only for the Total value view of an account that holds trades. -
UI::Account::Chart: the series is still built once per render, and the existing "builds its balance series once per render" test passes. The net contributions series is a second call, made only when the line is shown.
What else reads what this changes the reading of? The incomplete note's string is read only by this template. git grep for the old method, key and hook names is empty. The model PR lists the other "net contributions" measures (InvestmentStatement#net_contributions, Goal#net_contributed_for), which this chart doesn't use.
Rebased onto main. #3906 rewrote the body of _d3YScale. This PR's change, the method's first two lines, applied on top of the new scale logic without conflicts, so both lines' points set the domain.
Updated 2026-10-25. This branch's own commit messages were rewritten to drop references to the fork's issues and reviews, and comments that cited issue history now describe behaviour instead. No code changed apart from those comments. Commit SHAs quoted above predate the rewrite. The branch also merges current main.
Summary by CodeRabbit
- New Features
- Balance charts for eligible investment accounts compare total value with net contributions, helping distinguish account growth from money added or withdrawn.
- Chart tooltips show net contributions and the difference from total value, including a percentage when available.
- A notice appears when contributions may be incomplete because a deposit or withdrawal could not be valued.
- Chart labels, legends, and notices are available in multiple languages.







