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

StreakSpark collapses a sequence of pass/fail outcomes 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 accent
bar at the right. The record streak carries a small triangle tick, so "are we near our best" reads without counting.
Height and opacity encode run type, never magnitude, which leaves width as the only channel answering how long a run is.

```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.

## Try it

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

<StreakSpark
  data={[1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1]}
/>
```

## When to use it

Use it for pass/fail run histories, uptime and incident-free streaks, and the current run against a record. A continuous
magnitude belongs in SparkBar and a single completion ratio in Progress.

## Sizing

**default**

```tsx
// data alone → an intrinsic 96×20 box
<StreakSpark data={[1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1]} />
```

**fixed size**

```tsx
// width & height are viewBox units — they also set the pixel box
<StreakSpark data={[1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1]} width={200} height={48} label="both" />
```

**responsive**

```tsx
// omit width/height, let CSS drive the width — the viewBox keeps the ratio
<div style={{ width: "100%", maxWidth: 320 }}>
  <StreakSpark data={[1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1]} style={{ width: "100%", height: "auto" }} />
</div>
```

## 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 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."**

## Four homes

**In a sentence**

```tsx
<p>
  Deploy streak{" "}
  <span className="mc-inline">
    <StreakSpark data={data}${size} summary={false} />
  </span>{" "}
  — 7 greens in a row, last fail 3 days ago.
</p>
```

**In a table cell**

```tsx
<td>
  <StreakSpark data={data}${size} />
</td>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">7</span>
  <span className="unit">consecutive passes</span>
  <StreakSpark data={data}${size} />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  prod <StreakSpark data={data}${size} />
</button>
```

## 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, press `Escape`, or
press outside the chart. 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).
