Repository navigation
fix(web): metrics dashboard SoC chart text freezes on first-load value - #4308
Merged
springfall2008 merged 2 commits intoJul 26, 2026
Merged
springfall2008 merged 2 commits into
springfall2008 merged 2 commits into
Conversation
The battery SoC doughnut chart's center text (percentage and kWh figures) is drawn by a Chart.js afterDraw plugin registered once in mdInitSOCChart. That plugin closed over the pct/d values from the moment the chart was first created. On each 30s refresh, mdUpdateSOCChart only mutates the existing chart's data array and calls .update() - it never recreates the chart (mdRenderAll only calls mdInitSOCChart again if mdSocChart doesn't exist yet) - so the doughnut ring's fill proportion updated correctly but the on-screen number text stayed frozen at the first-load reading, while every other card on the page (Health, Cost, API, Solar) re-renders fresh from the latest data on every refresh. Fixes springfall2008#4151. The afterDraw plugin now reads chart.data.datasets[0].data[0] for the percentage (already correctly updated by mdUpdateSOCChart) and the MD_DATA global for the kWh figures (already correctly reassigned on every refresh), instead of the stale closed-over values. No JS execution/browser test infra exists in this codebase, so this can't run the embedded JavaScript and check actual canvas output. Added a structural test instead, checking the generated JS source itself reads from chart.data/MD_DATA rather than the closure parameters, to catch a regression back to the same bug shape. 🤖 Implemented with Claude Code, disclosed per repo convention. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This was referenced Jul 25, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes the Metrics Dashboard battery SoC doughnut chart center text not updating on periodic refresh by removing stale closure-captured values in the Chart.js afterDraw plugin and instead reading live values from the chart dataset and current MD_DATA. Adds a regression test that inspects the generated JS source to ensure the live-data reads are present, and wires the test into the unit test runner.
Changes:
- Update the Chart.js
afterDrawplugin to read the live percentage fromchart.data.datasets[0].data[0]and kWh figures fromMD_DATA. - Add a unit test that validates the generated dashboard JS references live data sources (rather than closure variables).
- Register the new test in
apps/predbat/unit_test.py.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/predbat/web_metrics_dashboard.py | Updates the SoC chart center-text drawing logic to read live values on refresh. |
| apps/predbat/unit_test.py | Registers the new metrics-dashboard SoC refresh regression test. |
| apps/predbat/tests/test_metrics_dashboard_soc_refresh.py | Adds a source-based regression test to prevent reintroducing the stale-closure bug shape. |
…the new reads present Copilot review on springfall2008#4308: the test only checked the new live-data reads (chart.data.datasets[0].data[0], MD_DATA.battery_soc_kwh) were present, not that the old closed-over reads (pct, d.battery_soc_kwh/battery_max_kwh) were actually removed - a partial revert of either half would still pass. Verified by temporarily reintroducing just the pct half of the original bug: the new assertion catches it, the old test wouldn't have. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4151. The battery SoC doughnut chart's center text (percentage and kWh figures) is drawn by a Chart.js
afterDrawplugin registered once inmdInitSOCChart. That plugin closed over thepct/dvalues from the moment the chart was first created. On each 30s refresh,mdUpdateSOCChartonly mutates the existing chart's data array and calls.update()- it never recreates the chart (mdRenderAllonly callsmdInitSOCChartagain ifmdSocChartdoesn't exist yet) - so the doughnut ring's fill proportion updated correctly but the on-screen number text stayed frozen at the first-load reading, while every other card on the page (Health, Cost, API, Solar) re-renders fresh from the latest data on every refresh.Split out from #4288, which originally bundled this with two unrelated fixes.
Changes
apps/predbat/web_metrics_dashboard.py: theafterDrawplugin now readschart.data.datasets[0].data[0]for the percentage (already correctly updated bymdUpdateSOCChart) and theMD_DATAglobal for the kWh figures (already correctly reassigned on every refresh), instead of the stale closed-over values.apps/predbat/tests/test_metrics_dashboard_soc_refresh.py: no JS execution/browser test infra exists in this codebase, so this checks the generated JS source itself reads fromchart.data/MD_DATArather than the closure parameters, to catch a regression back to the same bug shape.Test plan
./run_all --test metrics_dashboard_soc_refresh- new test passes./run_all --quick- full quick suite passes (611 tests, 0 failures)./run_pre_commit- clean (ruff, black, cspell, markdownlint)🤖 Implemented with Claude Code, disclosed per repo convention.