#609 Balance charts and readouts follow the view on servers and desktop files
–
- github
- github/openchronology/timeline-app
- github/openchronology/timeline-app#609
- pull request
- state:merged
Fixes two bugs that made the balance chart and the balance readouts wrong on server timelines (#595), seen on timescale.info's United States national debt timeline. ## 1. Merged summaries lost their balance When the editor merges summaries that draw too close together (`regroup` → `coalesceGroups`), it built the merged summary without its `balanceAfter`. - **When it happens:** the editor merges when zooming, and when a server answer comes at a finer grouping than the one drawn. - **Chart:** the balance chart skips a summary without a balance. It stayed at the earlier level until the view's right edge, then jumped to the closing balance. That's the stair that stopped short in the screenshots where the last circle was a merge (97 = 62 + 35, 164 = 109 + 55). It's also the chart that stayed flat across a whole view. - **Tooltips:** a merged summary's tooltip showed its balance as unchanged (before → before). - **Fix:** balances run in time order, so a merged summary keeps the later one's balance. A summary without a balance, such as a resolved ongoing duration's, leaves the earlier one's. ## 2. The readouts showed the fetched window's balances, not the view's The corner readouts and the balance chart's start used `frame.balances`. On a server or desktop file, that's the balance at the edges of the window the editor fetched, not the view. - **Why they differ:** the fetched window is a quarter wider than the view on each side. While you zoom or pan, the editor also shows cached windows from other zoom levels. - **Effect:** the opening balance could be decades early. A view starting in December 2020 opened at $6.4T, and one starting in July 2019 at $2.1T. - **Fix:** the new `viewBalances` takes the view's balances from the summaries' running balances. - **Before:** the last balance whose span ends by the view's start, else the window's. - **After:** the last balance whose span starts by the view's end. - **Exactness:** a summary's totals span to the next summary (`partitionTotals`), so both are exact at span boundaries. - **Unaffected:** the browser-only editor computes for the exact view, so it was already right. ## Tests - **`test/measure-balance.test.mjs`:** every window of the randomized index is regrouped within 5, 50 and 400. Each merged summary's balance must equal the running balance. This check fails without the fix. - **View edges:** for narrower views starting at a summary's first time, `viewBalances` gives the exact balance before, checked against the changes summed by hand. - **The real timeline:** I asked timescale.info for wide windows of the national debt timeline, then for views inside them starting at a summary boundary. `viewBalances` matched the server's own balances for the exact view in 4 of 4 views. The old readout was $0, the window's edge, in all 4. - **Other checks:** `checkMeasures` in the browser and the unit suite pass. The type check is clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_011fFY8eruEi1xAkkMBni13B https://github.com/circagraph/timeline-app/pull/609
Related
Open #609 Balance charts and readouts follow the view on servers and desktop files in the timeline