Anomaly Chart

A metric against its expected range, with outliers marked. The band is the point — 400ms at 03:00 may be an incident while 400ms at peak is Tuesday.

src/components/ui/anomaly-chart.tsx

About

From the component's own source, where it was written.

A metric plotted against its expected range, with outliers marked.

The band is the point. A spike means nothing without knowing what normal looked like at that moment — 400ms at 03:00 may be an incident while 400ms at peak is Tuesday. Detection stays outside this component: it renders the expected range you give it and marks whatever falls outside, rather than inventing a threshold of its own.

Points are drawn in a second, unstretched layer. The plot is stretched to fit its container, and a circle inside that stretch would render as an ellipse.

Install

npx astralyx-ui add anomaly-chart

Usage

import { AnomalyChart } from '@/components/ui/anomaly-chart'

<AnomalyChart points={points} labels={hours} />

Composer

Change the props and the source below follows.

Metric against expected range, 2 outside the band
ObservedExpected range2 anomalies
Props
tsx
<AnomalyChart points={points} labels={hours} />

Examples

Latency with band

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

AnomalyChart

Extends Omit<ComponentProps<'figure'>, 'height'>.

PropTypeDefaultDescription
colorstring'var(--blue)'Any CSS colour.
pointsAnomalyPoint[]required{ value, expected?, label? } where expected is a [low, high] pair for that moment.
heightnumber160—
bandColorstring'var(--blue)'Any CSS colour.
anomalyColorstring'var(--destructive)'Any CSS colour.
labelsstring[]——
observedLabelReactNode'Observed'Legend entries.
expectedLabelReactNode'Expected range'—

Types

AnomalyPoint

A metric plotted against its expected range, with outliers marked.

FieldTypeDescription
valuenumber—
expected?[number, number]Expected [low, high] at this moment.
label?string—

Behaviour

TopicDetailDescription
detectioncaller-ownedThe component marks what falls outside the range you give it. It never invents a threshold of its own.
renderingtwo layersThe plot is stretched to fit its container; anomaly dots are drawn in a second, unstretched layer, since a circle inside that stretch would render as an ellipse.