Realtime stream
Live scrolling time-series line that trails incoming readings by one interval, rolls the current value, pauses on inspection, and marks anomalies.
import { RealtimeStream } from '@uthereal/ui/realtime-stream'Realtime stream playground
| Time | Value | Note |
|---|---|---|
| 12:00:10 | 82 ms | |
| 12:00:11 | 91 ms | |
| 12:00:12 | 186 ms | Spike |
| 12:00:13 | 134 ms | |
| 12:00:14 | 96 ms | |
| 12:00:15 | 81 ms | |
| 12:00:16 | 76 ms | |
| 12:00:17 | 73 ms | |
| 12:00:18 | 69 ms | |
| 12:00:19 | 74 ms | |
| 12:00:20 | 79 ms | |
| 12:00:21 | 85 ms | |
| 12:00:22 | 88 ms | |
| 12:00:23 | 94 ms | |
| 12:00:24 | 164 ms | GC pause |
| 12:00:25 | 118 ms | |
| 12:00:26 | 89 ms | |
| 12:00:27 | 77 ms | |
| 12:00:28 | 72 ms | |
| 12:00:29 | 75 ms |
Overview
A realtime stream monitors one continuous live metric where recent seconds or minutes matter more than long history. The line scrolls smoothly at 60 fps one interval behind the newest reading so each incoming point slides in rather than popping. The current value rolls in large display type beside a Live/Paused toggle pill. Hovering, focusing, or dragging holds the view while incoming readings queue up, and resuming glides back to the live edge. Flagged anomalies pop a marker, hairline, and pill tag as the head reaches them. A native data table exposes the latest 20 readings and their notes.
Use a realtime stream for live telemetry such as p95 latency, request throughput, queue depth, or CPU utilization. For static or multi-series time series, use a line chart. For long histories that readers zoom into, use a brush chart. For a compact inline trend beside a KPI, use Metric.
Usage
import { useEffect, useState } from 'react'
import {
RealtimeStream,
type RealtimeStreamPoint,
} from '@uthereal/ui/realtime-stream'
export function LatencyMonitor({ socket }: { socket: WebSocket }) {
const [data, setData] = useState<RealtimeStreamPoint[]>([])
useEffect(() => {
const onMessage = (event: MessageEvent) => {
const { t, p95 } = JSON.parse(String(event.data)) as {
t: number
p95: number
}
setData((list) => [
...list.slice(-199),
{ t, value: p95, anomaly: p95 > 160 ? 'Spike' : undefined },
])
}
socket.addEventListener('message', onMessage)
return () => socket.removeEventListener('message', onMessage)
}, [socket])
return (
<RealtimeStream
label="p95 latency"
unit="ms"
data={data}
interval={1000}
windowMs={30000}
/>
)
}Pass data as an append-only array of up to 600 readings in strictly ascending epoch milliseconds ({ t, value, anomaly? }), trimmed to a few windows. Flag anomalies directly on incoming points with true or a short tag string; the chart does not detect anomalies on its own. Pair paused with onPausedChange to synchronize pause state across multiple charts.
Examples
Fixed axis bounds and anomaly tags
Omit min and max to let the value axis ease smoothly with visible readings. Set explicit min and max bounds for percentages or fixed SLA ranges so vertical movement reflects absolute capacity, and pass string anomaly values to label spikes or throttling events inline.
| Time | Value | Note |
|---|---|---|
| 12:00:00 | 38 % | |
| 12:00:01 | 41 % | |
| 12:00:02 | 44 % | |
| 12:00:03 | 42 % | |
| 12:00:04 | 47 % | |
| 12:00:05 | 53 % | |
| 12:00:06 | 89 % | Spike |
| 12:00:07 | 76 % | |
| 12:00:08 | 62 % | |
| 12:00:09 | 55 % | |
| 12:00:10 | 51 % | |
| 12:00:11 | 49 % | |
| 12:00:12 | 54 % | |
| 12:00:13 | 61 % | |
| 12:00:14 | 94 % | Throttled |
| 12:00:15 | 78 % | |
| 12:00:16 | 59 % | |
| 12:00:17 | 48 % | |
| 12:00:18 | 45 % | |
| 12:00:19 | 43 % |
Paused and empty states
Set defaultPaused to mount the stream held at the latest reading while incoming updates wait in the queue. Pass an empty data array with a custom emptyLabel to display a centered waiting message before the first reading arrives.
| Time | Value | Note |
|---|---|---|
| 12:00:00 | 420 req/s | |
| 12:00:01 | 438 req/s | |
| 12:00:02 | 452 req/s | |
| 12:00:03 | 446 req/s | |
| 12:00:04 | 468 req/s | |
| 12:00:05 | 491 req/s | |
| 12:00:06 | 479 req/s | |
| 12:00:07 | 464 req/s |
| Time | Value | Note |
|---|
Behavior
The live edge trails the newest reading by interval milliseconds and stops at the newest timestamp if the feed stalls, so the line never runs off into empty space. Match interval to the feed cadence and windowMs to a few dozen points. Neighboring anomalies that would collide share a single top pill tag, keeping tags legible during bursts.
Hovering with a mouse (when pauseOnHover is enabled), focusing the plot with the keyboard, pressing and dragging on touch, or toggling the status pill holds the scrolling window and counts incoming readings (Paused, 3 new). The animation loop stops automatically when the figure scrolls off screen or the browser tab is hidden. Default timestamps format in UTC (HH:MM:SS) so server rendering and client hydration match identically.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
label | stringDefault: "Realtime stream" | What is measured, such as "p95 latency". Names the chart for assistive technology, the rolling current value, and the data table. |
title | string— | Optional visible figure heading above the live readout and status button. Omit to keep only the accessible label. |
description | string— | One or two sentences on what the chart shows, below the title; omit it when the title says enough. |
data | RealtimeStreamPoint[]Default: [{"t":1793534400000,"value":64},{"t":1793534401000,"value":68},{"t":1793534402000,"value":62},{"t":1793534403000,"value":71},{"t":1793534404000,"value":69},{"t":1793534405000,"value":74},{"t":1793534406000,"value":78},{"t":1793534407000,"value":72},{"t":1793534408000,"value":67},{"t":1793534409000,"value":75},{"t":1793534410000,"value":82},{"t":1793534411000,"value":91},{"t":1793534412000,"value":186,"anomaly":"Spike"},{"t":1793534413000,"value":134},{"t":1793534414000,"value":96},{"t":1793534415000,"value":81},{"t":1793534416000,"value":76},{"t":1793534417000,"value":73},{"t":1793534418000,"value":69},{"t":1793534419000,"value":74},{"t":1793534420000,"value":79},{"t":1793534421000,"value":85},{"t":1793534422000,"value":88},{"t":1793534423000,"value":94},{"t":1793534424000,"value":164,"anomaly":"GC pause"},{"t":1793534425000,"value":118},{"t":1793534426000,"value":89},{"t":1793534427000,"value":77},{"t":1793534428000,"value":72},{"t":1793534429000,"value":75},{"t":1793534430000,"value":71},{"t":1793534431000,"value":68}] | Append-only feed of up to 600 readings in strictly ascending epoch milliseconds ({ t, value, anomaly? }). A string anomaly becomes the marker tag. |
unit | stringDefault: "" | Optional unit suffix appended after values, such as "ms", "MB/s", or "req/s". |
valueFormat | NumberFormat— | How values appear in the tooltip, table and axis: decimal, percent or currency, with fraction digits. Axis ticks are compacted (12.9K). |
windowMs | integerDefault: 30000 | Visible span of time in milliseconds (1000–3600000). Set to cover a few dozen readings. |
interval | integerDefault: 1000 | Typical milliseconds between readings (50–60000). The view trails the newest point by one interval so readings slide in smoothly. |
height | integerDefault: 200 | Plot height in pixels (100–520). |
defaultPaused | booleanDefault: false | Initial paused state when uncontrolled. Later argument edits do not reset a mounted instance. |
pauseOnHover | booleanDefault: true | Hold the scrolling view while a fine pointer hovers over the plot so moving points stay readable. |
min | number— | Fixed lower bound of the value axis. Omit to ease smoothly with visible readings. |
max | number— | Fixed upper bound of the value axis. Omit to ease smoothly with visible readings. |
emptyLabel | stringDefault: "Waiting for data" | Message shown centered over the plot before the first reading arrives. |
tableToggle | booleanDefault: false | Show a button that reveals the data table. The table is always available to assistive technology. |
tableLabel | stringDefault: "Data table" | Name of the data table button. |
locale | string— | BCP 47 locale for numbers and dates. Omit it to inherit the application locale (en-US by default). |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | RealtimeStreamTheme— | Color mode, accent, and semantic tokens including series1 (live line), series2 (anomaly markers), hairline borders, and display font family. See Theming. |
motion | none | subtle | expressiveDefault: "subtle" | Scrolling, rolling readout, anomaly pop, and tooltip glide preset. System reduced-motion preferences take precedence. |
motionOptions | RealtimeStreamMotionOptions— | Chart transition overrides. |
dir | ltr | rtl— | Reading direction for the readout, status button, plot progression, value axis, and tooltip. Omit to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
paused | Controlled pause state; holds the scrolling view while new readings queue |
onPausedChange | Fires with the next boolean pause state when the status button, Space/Enter, or Escape fires |
formatValue | Custom formatter (value: number) => string for the readout, axis ticks, tooltip, and data table |
formatTime | Custom formatter (t: number) => string for timestamps in the tooltip, live region, and data table |
preset | Application defaults, overridden by explicit instance props |
tokens | CSS variables applied after the typed theme |
ref | Ref forwarded to the root <figure> |
className, style | Applied to the root <figure> |
| Native attributes | id, data-*, and remaining <figure> attributes forwarded to the root |
Keyboard & accessibility
| Key | Interaction |
|---|---|
Tab | Focus the status toggle pill or the plot (focusing the plot holds reading) |
ArrowLeft, ArrowRight | Step backward or forward one visible reading (mirrored in dir="rtl") |
PageUp, PageDown | Jump ten readings backward or forward |
Home, End | Jump to the oldest or newest visible reading |
Space, Enter | Pause or resume the live stream |
Escape | Clear the active reading and resume the stream |
The component renders a <figure> named by title (or visually hidden label when title is omitted), described by description, and linked via aria-details to a native data table containing the latest 20 readings with their timestamps, formatted values, and anomaly notes. The current value readout exposes its full text through aria-label while hiding the rolling digits from assistive technology.
The Live/Paused control is a native toggle button with aria-pressed that pairs a morphing icon shape (filled circle when live, twin vertical bars when paused) with a text label so state never relies on color alone. Incoming anomalies announce once in a polite role="status" live region, and scrubbing points announces each reading in a separate polite live region. Layout, time progression, axis gutter, and keyboard direction mirror cleanly in dir="rtl". Under forced-colors: active, system colors (Canvas, CanvasText, Highlight, ButtonFace, ButtonText) replace tinted fills and borders.
Motion and theming
The plot updates pooled SVG primitives in a single requestAnimationFrame loop with zero per-frame React re-renders. Incoming points slide smoothly across the window, the value axis eases toward visible bounds, anomalies pop in with a single overshoot, the current value rolls on a critically damped smooth spring (0.4 s, zero bounce), the status pill width morphs on a spring as queued counts change, and the tooltip glides on a responsive spring.
Under prefers-reduced-motion: reduce or motion="none", continuous scrolling, axis easing, anomaly pops, rolling digits, pill width morphing, and tooltip glides stop. The chart redraws only when data, container width, or the active reading changes, and all transitions resolve immediately (0 ms).
theme accepts a mode, an accent, and semantic tokens across the core, control, and chart groups (using series1 for the live line and head dot and series2 for anomaly markers) plus borderSubtle and fontFamilyDisplay. An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, RealtimeStream is a leaf with no actions. onPausedChange is a transient UI control bound to paused. The host appends readings to data through composition updates. See Building with agents.
{
"type": "RealtimeStream",
"props": {
"label": "p95 latency",
"unit": "ms",
"windowMs": 30000,
"interval": 1000,
"data": [
{ "t": 1793534400000, "value": 68 },
{ "t": 1793534401000, "value": 74 },
{ "t": 1793534402000, "value": 182, "anomaly": "Spike" },
{ "t": 1793534403000, "value": 92 }
]
},
"children": []
}