Add a weekly net worth graph to the finances tab#8948
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #8948 +/- ##
============================================
+ Coverage 14.00% 14.07% +0.07%
- Complexity 8317 8337 +20
============================================
Files 1285 1286 +1
Lines 167972 168175 +203
Branches 25422 25442 +20
============================================
+ Hits 23518 23673 +155
- Misses 141977 142012 +35
- Partials 2477 2490 +13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rjhancock
left a comment
There was a problem hiding this comment.
Copyright and code quality requests.
A bit too much copy-and-paste and too little use of braincells. |
|
@rjhancock we need you to approve this PR before it can be merged. By the looks, your requests have been actioned :) |
There was a problem hiding this comment.
Pull request overview
Adds a "Net Worth Over Time" line chart to the Finances tab. On each in-game Monday, the campaign computes the current net worth via FinancialReport and appends a WeeklyNetWorth record into Finances; these records are persisted to the save file and rendered as a third chart in the Finances tab. The PR also rewires chart refresh on financial events, themes chart colors with the active L&F, and tweaks a minor text-alignment fix in the report panel.
Changes:
- New
WeeklyNetWorthvalue class with XML read/write, and anetWorthOverTimelist (with getter/setter/add and XML I/O) onFinancespopulated weekly innewDay. - New
NETWORTH_OVER_TIMEgraph and tab inFinancesTab, with sharedupdateCharts()invoked fromrefreshFinancialTransactions, and L&F-aware chart coloring increateAmountChart/createMonthlyChartplus anupdateUIoverride. - New localized tab label
weeklyNetWorth.textand copyright-year bumps.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| MekHQ/src/mekhq/campaign/finances/WeeklyNetWorth.java | New persisted record (date + Money) with XML serialization helpers. |
| MekHQ/src/mekhq/campaign/finances/Finances.java | Stores weekly net-worth snapshots on Mondays during newDay and serializes them in save XML. |
| MekHQ/src/mekhq/gui/FinancesTab.java | Adds the third chart tab, dataset builder, dynamic chart refresh, L&F-themed colors and updateUI override; minor label-alignment fix. |
| MekHQ/resources/mekhq/resources/FinancesTab.properties | Adds weeklyNetWorth.text resource string. |
Comments suppressed due to low confidence (2)
MekHQ/src/mekhq/campaign/finances/Finances.java:542
isMondayis derived from thetodayparameter, but the date stored with the weekly net worth is read viacampaign.getLocalDate(). WithinnewDaythese are normally the same, but mixing the two is fragile and inconsistent with how the rest of this method usestodayfor date-stamping (e.g. contract payments, debt detection). PasstodaytosetWeeklyNetWorthfor consistency and to guarantee the stored date matches the day that triggered the Monday check.
if (isMonday) {
FinancialReport financialReport = FinancialReport.calculate(campaign);
setWeeklyNetWorth(campaign.getLocalDate(), financialReport.getNetWorth());
}
MekHQ/src/mekhq/gui/FinancesTab.java:390
- The domain/range gridline paint is set to
textColor(a foreground color), drawn overColor.LIGHT_GRAYbackground. Previously these gridlines wereColor.WHITEto be subtle on the light gray plot background; using foreground text color makes the gridlines a high-contrast color (black on default L&Fs), which visually competes with the data series. Consider using a contrast-aware gridline color rather than the button foreground.
plot.setDomainGridlinePaint(textColor);
plot.setRangeGridlinePaint(textColor);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rjhancock
left a comment
There was a problem hiding this comment.
Deal with the CoPilot comments and I'll be satisfied with it. There are a few good ones in there that I do suggest giving serious consideration with.
Done Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…feature/NetWorthOverTime
…NetWorthOverTime
This PR adds a new graph to the Finances tab that shows the Net Worth of the unit over time.
Each week on Monday, the actual Net Worth is calculated and stored for that date. These data points are used to show a new graph in the Finances tab. Much of the relevant code is very alike the existing code for the current graphs, some parts are reused. The collected data is stored (and loaded from) the save file. With around 50 data points for each year, this is sizable, and for very long running campaigns, this may be too many. In that case, a system would need to be added to truncate the oldest values, maybe with a retention span (like 5 years/10 years/50 years) that can be set in the preferences.
Net Worth is (IMHO) a better indicator of how the unit is doing financially than just the amount of C-Bills. Gaining good salvage or loosing valuable Meks or other units in a battle does not affect your C-Bills, at least not right away. But it does have an impact (positive or negative) on the Net Worth. And taking out a loan will boost your C-Bills, but will be actually not very good for your Net Worth, as paying off that loan will cost more than the C-Bills you gained.
This PR also includes some modifications (AI-inspired) to make the charts update automatically and to align the chart colours with the theme of the UI (light/dark).
And there is a tiny fix to align the "Meks ..." value in the panel on the right hand side with the other entries.