Skip to content

Add a weekly net worth graph to the finances tab#8948

Open
AlexOldenburger wants to merge 9 commits into
MegaMek:mainfrom
AlexOldenburger:feature/NetWorthOverTime
Open

Add a weekly net worth graph to the finances tab#8948
AlexOldenburger wants to merge 9 commits into
MegaMek:mainfrom
AlexOldenburger:feature/NetWorthOverTime

Conversation

@AlexOldenburger
Copy link
Copy Markdown
Collaborator

@AlexOldenburger AlexOldenburger commented May 12, 2026

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.

FinanceGraphFinal

@AlexOldenburger AlexOldenburger requested a review from a team as a code owner May 12, 2026 14:09
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 0.74627% with 133 lines in your changes missing coverage. Please review.
✅ Project coverage is 14.07%. Comparing base (b84c72a) to head (7c10ae2).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
MekHQ/src/mekhq/gui/FinancesTab.java 0.00% 80 Missing ⚠️
...HQ/src/mekhq/campaign/finances/WeeklyNetWorth.java 0.00% 36 Missing ⚠️
MekHQ/src/mekhq/campaign/finances/Finances.java 5.55% 17 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@rjhancock rjhancock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright and code quality requests.

Comment thread MekHQ/src/mekhq/campaign/finances/WeeklyNetWorth.java Outdated
Comment thread MekHQ/src/mekhq/campaign/finances/WeeklyNetWorth.java Outdated
Comment thread MekHQ/src/mekhq/gui/FinancesTab.java Outdated
@AlexOldenburger
Copy link
Copy Markdown
Collaborator Author

Copyright and code quality requests.

A bit too much copy-and-paste and too little use of braincells.

@AlexOldenburger AlexOldenburger marked this pull request as draft May 14, 2026 06:09
@AlexOldenburger AlexOldenburger marked this pull request as ready for review May 14, 2026 06:59
@AlexOldenburger AlexOldenburger marked this pull request as draft May 14, 2026 07:05
@AlexOldenburger AlexOldenburger marked this pull request as ready for review May 14, 2026 07:45
Copy link
Copy Markdown
Collaborator

@IllianiBird IllianiBird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@IllianiBird
Copy link
Copy Markdown
Collaborator

@rjhancock we need you to approve this PR before it can be merged. By the looks, your requests have been actioned :)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 WeeklyNetWorth value class with XML read/write, and a netWorthOverTime list (with getter/setter/add and XML I/O) on Finances populated weekly in newDay.
  • New NETWORTH_OVER_TIME graph and tab in FinancesTab, with shared updateCharts() invoked from refreshFinancialTransactions, and L&F-aware chart coloring in createAmountChart / createMonthlyChart plus an updateUI override.
  • New localized tab label weeklyNetWorth.text and 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

  • isMonday is derived from the today parameter, but the date stored with the weekly net worth is read via campaign.getLocalDate(). Within newDay these are normally the same, but mixing the two is fragile and inconsistent with how the rest of this method uses today for date-stamping (e.g. contract payments, debt detection). Pass today to setWeeklyNetWorth for 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 over Color.LIGHT_GRAY background. Previously these gridlines were Color.WHITE to 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.

Comment thread MekHQ/src/mekhq/campaign/finances/WeeklyNetWorth.java Outdated
Comment thread MekHQ/src/mekhq/gui/FinancesTab.java
Comment thread MekHQ/src/mekhq/campaign/finances/Finances.java
Comment thread MekHQ/src/mekhq/gui/FinancesTab.java
Comment thread MekHQ/src/mekhq/gui/FinancesTab.java
Comment thread MekHQ/src/mekhq/campaign/finances/Finances.java
Comment thread MekHQ/src/mekhq/gui/FinancesTab.java
Comment thread MekHQ/src/mekhq/gui/FinancesTab.java
Comment thread MekHQ/src/mekhq/campaign/finances/Finances.java
Comment thread MekHQ/src/mekhq/gui/FinancesTab.java
Copy link
Copy Markdown
Collaborator

@rjhancock rjhancock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants