PitchKit
API Reference@pitchkit/coreFunctions

computeCumulativeSeries()

function computeCumulativeSeries(events, until?): RaceSeriesData;

Defined in: packages/core/src/race/cumulative.ts:69

Turns events into a running total, in match order: by period, then by minute within it.

What this deliberately does not do is synthesise the kick-off and full-time anchors. Those are a rendering concern (stepPath adds them), and keeping them out of points means every point corresponds to a real datum — so markers and tooltips map one-to-one onto the caller's array and never have to special-case two phantom entries.

Events arrive unsorted often enough to be the default assumption: a StatsBomb feed is in event order, which is chronological per period but interleaves the two teams, and filtering one team out leaves gaps rather than disorder. Sorting anyway costs nothing and removes a class of bug where a late-arriving event draws a step backwards.

Non-finite values are dropped rather than propagated: one NaN in a running sum poisons every point after it, and an xG feed with a missing value should lose that shot, not the rest of the match. So is an event whose period isn't a whole number from 1, which has nowhere to be drawn.

until, when given, is where the chart ends: events after that minute of that period are dropped, so the total is what the chart draws. An event exactly at until is kept.

Parameters

ParameterType
eventsreadonly RaceEvent[]
until?Pick<RaceEvent, "time" | "period">

Returns

RaceSeriesData

On this page