Skip to main content
cngx-src documentation

injectChartBuffer

Functioncommon/chart/buffer

projects/common/chart/buffer/inject-chart-buffer.ts

Description#

Bounded, rAF-coalesced realtime feed for <cngx-chart>. Wraps a fixed-capacity ring (createRingBuffer) with an optional LTTB downsample (downsampleLTTB) and exposes the window as a Signal.

Multiple push / pushBatch / clear calls within one animation frame collapse into a single points emission: each mutation writes the ring imperatively and schedules one requestAnimationFrame(flush); the flush bumps a revision signal that points derives from. The flush is a plain callback writing a signal - not an effect() body - so no reactive exception class is involved.

Runs in an injection context; the rAF handle is cancelled via DestroyRef.

export class Telemetry {
  private readonly buffer = injectChartBuffer<Sample>({
    capacity: 1000,
    downsampleTo: 600,
    xAccessor: (s) => s.t,
    yAccessor: (s) => s.value,
  });
  protected readonly points = this.buffer.points; // -> <cngx-chart [data]>
  onSample(s: Sample): void {
    this.buffer.push(s);
  }
}

Signature#

injectChartBuffer(opts: ChartBufferOptions)

Parameters#

Returns#

CngxChartBuffer