Repository navigation
Commit cfc83c0
fix(web): metrics dashboard SoC chart text freezes on first-load value
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 #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>1 parent 378066d commit cfc83c0
3 files changed
Lines changed: 58 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
277 | 278 | | |
278 | 279 | | |
279 | 280 | | |
| 281 | + | |
280 | 282 | | |
281 | 283 | | |
282 | 284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
212 | 216 | | |
213 | 217 | | |
| 218 | + | |
214 | 219 | | |
215 | 220 | | |
216 | 221 | | |
217 | 222 | | |
218 | | - | |
| 223 | + | |
219 | 224 | | |
220 | 225 | | |
221 | | - | |
| 226 | + | |
222 | 227 | | |
223 | 228 | | |
224 | 229 | | |
| |||
0 commit comments