# StreakSpark (/docs/charts/streak-spark)

StreakSpark answers "how long is the current run, and how does it compare to the record?". A sequence of pass/fail
outcomes collapses into **runs** — each run a bar whose width is its length on one shared scale. Streak runs sit low and
translucent, breaks sit thin and saturated, and the **current** run is the loud accent bar at the right. The record
streak wears a small triangle tick, so "are we near our best" reads without counting.

```tsx
import { StreakSpark } from "@microcharts/react/streak-spark";

// 1 = passing build, 0 = failing build

<StreakSpark
  data={[1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1]}
  label="both"
  title="Deploy streak"
/>
```

## Install

```tsx
import { StreakSpark } from "@microcharts/react/streak-spark";

// 1 = passing build, 0 = failing build
<StreakSpark
  data={[1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1]}
  title="Deploy streak"
/>
```

Setup (package + stylesheet): [Quickstart](/docs/quickstart#set-up-with-an-ai-agent) or paste [`/agent-setup.md`](/agent-setup.md) into your agent.


## When to use it

- **Good for** — pass/fail run histories, uptime and incident-free streaks, the current run against a record.
- **Avoid for** — a continuous magnitude (SparkBar) or a single completion ratio (Progress).


## Variants

`data` accepts booleans, `0`/`1`, or any numbers (they pass on `> 0`, or on `>= threshold`). A `null` is a gap: it
breaks the run and starts a fresh one. Everything else is a prop.

```tsx
// label="both" prints the current run's length AND the record's
<StreakSpark
  data={[1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1]}
  label="both"
/>
```

```tsx
// the STREAK is now the failing outcome — e.g. incident-free days
// (0 = quiet day, 1 = incident): the calm runs become the ok streak
<StreakSpark
  data={[0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0]}
  positive="down"
  label="both"
/>
```

```tsx
// numbers pass on >= threshold — e.g. daily uptime %, target 99.5
<StreakSpark
  data={[99.9, 99.8, 99.6, 98.2, 99.7, 99.9, 99.6, 97.0, 99.8, 99.9]}
  threshold={99.5}
  label="both"
/>
```

```tsx
<StreakSpark
  data={Array.from({ length: 1204 }, () => 1)}
  format={{ useGrouping: true }}
  locale="de-DE"
/>
```

With a `locale`, the count label and the accessible summary follow that locale's own grouping — a 1,204-build streak
reads **"1.204"** in German. The outcome words come from `strings`, so the whole summary localizes together.

## Edge cases

```tsx
<StreakSpark data={[1]} title="One build" />
```

A lone outcome is one current run of length 1, and it is trivially its own record — the summary reads **"Current run 1
passing, unbroken."**

```tsx
<StreakSpark data={[0, 0, 0, 0, 0]} title="Rough week" />
```

When nothing passes there is no completed streak: the strip is one saturated break run, no triangle tick, and the
summary reads **"Current run 5 failing; no completed streak."**


## Why this default

Runs, not per-outcome ticks, because the decision is about _length_ — "how long have we held" and "how does that compare
to our best". Width encodes run length on one shared scale, so a wide bar is a genuinely long run and the eye compares
them honestly. Height and opacity encode run _type_ (streak, break, current) — never magnitude — so the ribbon never
implies a size it doesn't have. The record tick and the accented current bar answer the two questions the raw list
can't, at a glance.

## Accessibility

The accessible name states the current run, the record, and how often the streak broke — **"Current run 3 passing;
record 9; broke 2 times."** The interactive entry roves runs with ← →, announcing each run's length, outcome, and
whether it is the record (**"Run 3 of 5: 4 passing."**). Direction is carried by height, opacity, and color together,
never color alone.

The interactive entry follows the shared [interaction contract](/docs/accessibility#one-interaction-contract):
arrow keys rove between units on both axes, `Home` and `End` jump to the ends, and a click, tap, `Enter` or
`Space` selects a unit — pinning its readout so it survives blur, until you select it again or press `Escape`.
On touch, a tap pins and a drag scrubs.

## Props

| Prop | Type | Description |
| --- | --- | --- |
| `data` (required) | `(boolean \| number \| null)[]` | Outcomes; null is a gap that breaks the run. Numbers pass on > 0. |
| `positive` | `"up" \| "down"` | Which outcome is the streak: pass (up) or fail (down). |
| `threshold` | `number` | With numeric data, values ≥ threshold pass. |
| `label` | `"current" \| "both" \| "none"` | Count labels: the current run, the record too, or neither. |
| `title` | `string` | Accessible name; joins the auto summary. |
| `summary` | `string \| false` | Override or disable the auto summary. |
| `animate` | `boolean` | (interactive) Opt-in entrance motion when the chart mounts client-side — add `import "@microcharts/react/motion"` once. Inert on the server, on hydrated server HTML, and under `prefers-reduced-motion`. |

Plus the shared grammar — `data`, `domain`, `color`, `title`, `summary`, `format` — and the layout props (`width`, `height`, `className`, `style`) that every chart accepts. Interactive entries also share `animate` and `live`, and — wherever a chart has more than one navigable unit — `onActive`, `onSelect`, `selectedIndex` and `defaultSelectedIndex`; and — wherever the chart shows a hover value — `readout`. See [the shared grammar](/docs/quickstart#the-shared-grammar).
