# CyclePlot (/docs/charts/cycle-plot)

Friday peaks at 61, Sunday dips to 38, and slot 2 has been climbing across three cycles. CyclePlot reshapes the series
into `period` slots (7 for weekdays, 12 for months). Each slot shows its own raw values across cycles as a muted
polyline in **time order**, plus a mean tick, and the accent spine connects the slot means. Seasonality is the spine and
drift is the within-slot lines: two questions of the same data, on two marks.

```tsx
import { CyclePlot } from "@microcharts/react/cycle-plot";

<CyclePlot
  data={[
    38, 40, 45, 48, 52, 61, 44, 38, 42, 45, 48, 52, 61, 44, 38, 44, 45, 48, 52, 61, 44, 38, 46, 45,
    48, 52, 61, 44, 38, 48, 45, 48, 52, 61, 44, 38, 50, 45, 48, 52, 61, 44,
  ]}
  period={7}
  slots={["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]}
  cycleUnit="weeks"
  title="Weekly shape"
/>
```

## Install

```tsx
import { CyclePlot } from "@microcharts/react/cycle-plot";

<CyclePlot data={daily} period={7} slots={weekdays} cycleUnit="weeks" title="Weekly shape" />
```

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 { CyclePlot } from "@microcharts/react/cycle-plot/interactive";

<CyclePlot
  data={daily}
  period={7}
/>
```

## When to use it

Use it for a KPI card that says "the week has a shape", for weekday traffic / hourly load / monthly sales seasonality,
or for spotting one slot that is itself drifting. For a plain time series reach for Sparkline; for one composition,
SegmentedBar. A `period` outside 4–12 warns in development: below that there is no cycle to see, above it the slots stop
being separable.

## Sizing

**median center (skewed slots)**

```tsx
<CyclePlot data={daily} period={7} center="median" />
```

**spine only (quiet form)**

```tsx
<CyclePlot data={daily} period={7} trend={false} />
```

## Variants

`center` picks the slot statistic: mean by default, `"median"` when a slot's distribution is skewed. The interactive
per-slot announcement names which one it used. `trend={false}` drops the spine and leaves the within-slot lines. Those
lines are never smoothed and never joined across a slot boundary — each polyline begins and ends inside its own column,
so a Monday trend cannot bleed into Tuesday.

```tsx
<CyclePlot
  data={[38, 40, 45, 48, 52, 61, 44, 38, 42, 45, 48, 52, 61, 44, 38, 44, 45, 48, 52, 61, 44]}
  period={7}
  center="median"
/>
<CyclePlot
  data={[38, 40, 45, 48, 52, 61, 44, 38, 42, 45, 48, 52, 61, 44, 38, 44, 45, 48, 52, 61, 44]}
  period={7}
  trend={false}
/>
```

## Edge cases

```tsx
// slot 0 is null every cycle — that slot gets no mean tick, and the
// spine simply starts at the next non-empty slot
<CyclePlot
  data={[null, 40, 45, 48, 52, 61, null, 42, 45, 48, 52, 61, null, 44, 45, 48, 52, 61]}
  period={6}
/>
```

```tsx
// exactly one pass through the slots — every slot has one point, so no
// within-slot line can draw (it needs ≥ 2); only the spine and dots show
<CyclePlot data={[38, 45, 52, 44, 40, 48, 61]} period={7} />
```

```tsx
<CyclePlot
  data={[3800, 4000, 4500, 4800, 5200, 6100, 4400, 3800, 4200, 4500, 4800, 5200, 6100, 4400]}
  period={7}
  locale="de-DE"
/>
```

A slot with no finite values draws no mean tick and no within-slot line. The spine connects the non-empty slots only,
joining an empty slot's neighbours directly rather than dipping to a made-up center. A single cycle (one value per slot)
draws the spine and dots as usual, but no within-slot polylines, since a line needs at least two observations in a slot.

## Four homes

**In a sentence**

```tsx
<p>
  Weekly traffic shape{" "}
  <span className="mc-inline">
    <CyclePlot data={daily} period={7} summary={false} />
  </span>{" "}
  — weekday peak Wednesday, weekend dip.
</p>
```

**In a table cell**

```tsx
<td>
  <CyclePlot data={daily} period={7} />
</td>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">Wed</span>
  <span className="unit">peak day</span>
  <CyclePlot data={daily} period={7} />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  US <CyclePlot data={daily} period={7} />
</button>
```

Best at KPI/card scale — weekly cycles need width for slot groups.

## Accessibility

The accessible name states the peak and dip slots and any leading drift: **"Peaks slot 6 (61), dips slot 1 (38); slot 2
rising across 3 cycles."** The interactive entry steps the slots (mean, cycle count, drift) with ←/→, and steps the
individual observations within a slot with ↑/↓.

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) | `number[]` | A flat series, reshaped row-major into `period` slots. |
| `period` (required) | `number` | Slots per cycle (4–12) — e.g. 7 for weekdays. |
| `slots` | `string[]` | Slot names for summaries, e.g. weekday labels. |
| `center` | `"mean" \| "median"` | Center statistic — median for skewed slot distributions. |
| `trend` | `boolean` | Within-slot micro-trend line (default true); false = spine + ticks only. |
| `spine` | `boolean` | The slot-center spine (default true); false leaves within-slot drift only. |
| `cycleUnit` | `string` | Cycle noun for the summary, e.g. 'weeks' (default 'cycles'). |
| `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).
