Skip to content

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

@heyitsStylez

Description

@heyitsStylez

What to build

Extract the inline buildDisplaySeries series preparation logic from rCpnlChart in src/js/07-render-charts.js into a pure function buildDisplaySeries in src/js/05b-pnl.js, alongside the existing computePnl export.

The function absorbs all three preparation steps that currently live inline in the renderer:

  1. Zero-baseline prepend — a { date, val: 0 } point anchoring the chart at zero
  2. Period-filter slice — cutoff at 1M / 3M with baseline carry-forward from the last point before the cutoff
  3. Today-extension — appending today's date as the final point to extend the line to now

rCpnlChart is reduced to a single call: const dispSeries = buildDisplaySeries(realisedSeries, sCpnlPeriod, today());

The function is added to the dual-export footer in 05b-pnl.js.

Interface:

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

Acceptance criteria

  • buildDisplaySeries exported from src/js/05b-pnl.js
  • rCpnlChart no longer contains inline period-filter, baseline-prepend, or today-extension logic
  • Cumulative Realised P&L hero chart renders correctly for all three period toggles (1M / 3M / ALL)
  • New tests appended to test/unit/pnl.test.js covering: 'ALL' returns series with zero-baseline prepended and today appended; '1M' with no in-range points returns a flat [{cutoff, lastVal}, {today, lastVal}] pair; baseline carry-forward is the last point before the cutoff; empty input returns empty
  • python3 build.py --check passes
  • npm test passes
  • Update the core data flow diagram in docs/architecture.md: add buildDisplaySeries to the 05b-pnl.js node alongside computePnl (both are now exports from that file that feed into rCharts)

Blocked by

None — can start immediately.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions