Skip to content

Extract buildDisplaySeries from rCpnlChart into 05b-pnl.js#65

Merged
heyitsStylez merged 1 commit into
mainfrom
extract-build-display-series
May 16, 2026
Merged

Extract buildDisplaySeries from rCpnlChart into 05b-pnl.js#65
heyitsStylez merged 1 commit into
mainfrom
extract-build-display-series

Conversation

@heyitsStylez
Copy link
Copy Markdown
Owner

Summary

Extracts the three inline series-preparation steps from rCpnlChart in 07-render-charts.js into a standalone pure function buildDisplaySeries in 05b-pnl.js, alongside computePnl. rCpnlChart is now a single call site.

The three absorbed steps:

  • Zero-baseline prepend — anchors the chart at 0 on the first trade date
  • Period-filter slice — cuts to 1M / 3M window with carry-forward baseline from the last point before the cutoff
  • Today-extension — appends today's date as the final point so the line reaches now

Dead variable removed: cutoff (Date object), allSeries, lastBefore, inPeriod, todayStr — all absorbed into the function. The today Date object is replaced by today() (the existing util that returns an ISO string).

Interface:

buildDisplaySeries(series, period, today)  [{date, val}]
// series: realisedSeries from computePnl (raw cumulative, no baseline yet)
// period: '1M' | '3M' | 'ALL'
// today:  ISO date string e.g. '2026-05-16'

buildDisplaySeries added to the dual-export footer in 05b-pnl.js and to the 05b-pnl.js node in docs/architecture.md.

Test plan

4 new unit tests appended to test/unit/pnl.test.js:

  • empty input returns empty — guard case

  • ALL prepends zero-baseline and appends today — full happy path

  • 1M with no in-range points returns flat [{cutoff,lastVal},{today,lastVal}] — all trades before window

  • baseline carry-forward is last point before the cutoff — correct baseline selection when some trades are in-window

  • npm test — 108/108 pass

  • python3 build.py --check — passes

  • Cumulative Realised P&L hero chart renders correctly for all three period toggles (1M / 3M / ALL) — behaviour unchanged, logic only moved

Closes #57

🤖 Generated with Claude Code

Moves the inline zero-baseline prepend, period-filter slice, and
today-extension logic out of rCpnlChart into a pure, dual-exported
function. rCpnlChart is now a single call site. Adds 4 unit tests.
Updates architecture diagram. Closes #57.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hyperwheel Ready Ready Preview, Comment May 16, 2026 2:44am

@heyitsStylez heyitsStylez merged commit 7e3ade7 into main May 16, 2026
4 checks passed
@heyitsStylez heyitsStylez deleted the extract-build-display-series branch May 16, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract buildDisplaySeries from rCpnlChart into 05b-pnl.js

1 participant