On this page:
make-chart-series
chart-series?
chart-series-append!
chart-series-window
chart-series-drain-batch!
chart-series-latest
chart-series-count
chart-series-capacity
chart-series-appended
chart-series-dropped
chart-series-id
chart-series-reset!
chart-batch-encode
chart-batch-decode
chart-batch-sample-count
chart-batch-first-index
chart-batch-magic

5 Real-Time Chart Series🔗ℹ

 (require rivet/chart) package: rivet

The chart data plane keeps time-series state on the Racket side and exports it in the two shapes native chart widgets consume: the recent-window pull (an ordinary typed RPC built from chart-series-window) and the high-rate append push (a bytes? batch carried by an application event). Samples are (cons timestamp-nanoseconds value) pairs of exact integers; Rivet’s typed surface is integer-native by design, and measurement domains (ns offsets, ps offsets, ppm drift) stay exact instead of losing precision to floating point.

The batch layout is a cross-language contract with the portable C++ decoder in "runtime/include/rivet/chart_batch.hpp" and the Swift decoder in RivetUI; the three implementations are pinned by shared golden bytes in their test suites. Rivet: First-Party Native Desktop Applications with Racket links the full convention guide.

procedure

(make-chart-series id [#:capacity capacity]) → chart-series?

  id : string?
  capacity : exact-positive-integer? = 16384
Creates a series ring buffer. Capacity is the retained sample count; when the ring overflows, the oldest samples are evicted and the drop is reported through chart-series-dropped and through the next batch’s absolute first index.

procedure

(chart-series? value) → boolean?

  value : any/c
Predicate for chart series values.

procedure

(chart-series-append! series samples) → void?

  series : chart-series?
  samples : 
(listof (cons/c exact-nonnegative-integer?
                exact-integer?))
Appends (ts . value) samples in order. Timestamps must be strictly increasing within the call and against the series tail; a reordered feed corrupts window slicing and host index accounting, so it raises instead of silently reordering.

procedure

(chart-series-window series span-ns)

 → (listof (cons/c exact-nonnegative-integer? exact-integer?))
  series : chart-series?
  span-ns : (or/c #f exact-nonnegative-integer?)
Newest-last list of live samples no older than the newest timestamp minus span-ns; #f returns the whole live ring. This is the initial-paint and gap-recovery pull behind an ordinary typed RPC.

procedure

(chart-series-drain-batch! series) → bytes?

  series : chart-series?
Returns one batch with every sample appended since the previous drain. The header’s absolute first index lets a host that fell behind detect ring eviction and re-pull the window.

procedure

(chart-series-latest series)

 → (or/c #f (cons/c exact-nonnegative-integer? exact-integer?))
  series : chart-series?
The newest sample, or #f when the series is empty.

procedure

(chart-series-count series) → exact-nonnegative-integer?

  series : chart-series?
Number of live samples retained by the ring.

procedure

(chart-series-capacity series) → exact-positive-integer?

  series : chart-series?
The ring capacity fixed at creation.

procedure

(chart-series-appended series) → exact-nonnegative-integer?

  series : chart-series?
Total samples ever appended; the absolute index space hosts track.

procedure

(chart-series-dropped series) → exact-nonnegative-integer?

  series : chart-series?
Live samples evicted from the ring before being drained.

procedure

(chart-series-id series) → string?

  series : chart-series?
The series identifier hosts render against.

procedure

(chart-series-reset! series) → void?

  series : chart-series?
Clears samples and the absolute index space.

procedure

(chart-batch-encode samples [first-index]) → bytes?

  samples : (listof (cons/c exact-nonnegative-integer? exact-integer?))
  first-index : exact-nonnegative-integer? = 0
Encodes samples as a chart batch: little-endian u32 magic, u32 count, i64 absolute first index, then count times (i64 timestamp-ns, i64 value).

procedure

(chart-batch-decode batch)

 → 
(listof (cons/c exact-nonnegative-integer? exact-integer?))
exact-nonnegative-integer?
  batch : bytes?
Decodes a chart batch, validating magic and declared lengths. Raises on malformed input.

procedure

(chart-batch-sample-count batch) → exact-nonnegative-integer?

  batch : bytes?
The sample count declared in the batch header.

procedure

(chart-batch-first-index batch) → exact-nonnegative-integer?

  batch : bytes?
The absolute first index declared in the batch header.

value

chart-batch-magic : exact-nonnegative-integer?

The RVC1 magic a decoder must verify before trusting a batch (1381385009).