# Beeswarm

> Every item as a dot, packed without overlap, that flows to its new place when the metric or rows change, with a brush to select a range.

- Type: Component (data)
- Access: Arc Pro
- Page: https://uiarc.dev/components/beeswarm
- Markdown: https://uiarc.dev/components/beeswarm/markdown
- Source file: `registry/components/beeswarm/beeswarm.tsx`
- Dependencies: motion
- Keywords: data, chart, new, beeswarm chart, swarm plot, dot plot react, strip plot, customer distribution chart, brushable scatter, jitter plot, animated beeswarm

## When to use

- Showing all customers, deals, or requests by one measure, with the option to split into rows.
- Finding outliers and selecting a band of items to act on.
- Explaining how a population re-sorts when the lens changes.

## When not to use

- Use bar-chart when only the aggregate per group matters.
- Use a histogram for tens of thousands of items; dots stop being individually visible.
- Use data-grid when people need to compare several fields at once.

## Installation

Beeswarm is part of Arc Pro. The live preview is public; the source and install command need Pro.

### CLI with a Pro token

1. Create a token in your account and set it in the environment (or `.env.local`). Never commit it.

```bash
export ARC_PRO_TOKEN=arc_pro_...
```

2. Add the Pro registry to `components.json`:

```json
{
  "registries": {
    "@uiarc": "https://uiarc.dev/r/{name}.json",
    "@uiarc-pro": {
      "url": "https://uiarc.dev/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${ARC_PRO_TOKEN}"
      }
    }
  }
}
```

3. Install:

```bash
npx shadcn@latest add @uiarc-pro/beeswarm
```

### Manual

Signed-in Pro members can copy the source from the Manual tab on the docs page.

- Plans: https://uiarc.dev/pricing
- Create a Pro token: https://uiarc.dev/account#pro-access
- Setup guide: https://uiarc.dev/docs/ai#pro-access

## Usage

```tsx
import { useState } from "react";
import { Beeswarm } from "@/components/arc/beeswarm/beeswarm";

const metrics = [{ key: "mrr", label: "MRR", scale: "log" as const, format: (v: number) => `$${v.toLocaleString()}` }, { key: "seats", label: "Seats", scale: "log" as const }];
const categories = [{ key: "enterprise", label: "Enterprise" }, { key: "mid", label: "Mid-market" }, { key: "self", label: "Self-serve" }];

export function Customers({ customers }: { customers: { id: string; name: string; plan: string; mrr: number; seats: number; region: string }[] }) {
  const [metric, setMetric] = useState("mrr");
  const data = customers.map(c => ({ id: c.id, label: c.name, category: c.plan, values: { mrr: c.mrr, seats: c.seats }, groups: { region: c.region } }));
  return <Beeswarm data={data} metrics={metrics} metric={metric} categories={categories} groupBy="region" label="Customers by MRR" />;
}
```

## API reference

### Beeswarm

Every item as a dot, packed without overlap along one axis. Switching the metric or the rows sends each dot on its own spring to its new place in one sweeping wave. Drag to brush a range.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `data` (required) | `{ id: string; label: string; category: string; values: Record<string, number>; groups?: Record<string, string> }[]` | – | One entry per dot. Stable ids let dots flow between layouts. |
| `metrics` (required) | `{ key: string; label: string; scale?: "linear" \| "log"; format?; formatTick? }[]` | – | The measures the x axis can show. |
| `metric` (required) | `string` | – | Key of the metric on the x axis. |
| `categories` (required) | `{ key: string; label: string; color?: string }[]` | – | Legend entries and dot colors. Colors follow the category, never its rank. |
| `groupBy` | `string \| null` | `null` | Attribute key in groups to split the swarm into rows. |
| `groupOrder` | `Record<string, string[]>` | – | Row order per attribute; unlisted values follow in order of appearance. |
| `label` (required) | `string` | – | Names the chart for assistive technology. |
| `brush` | `[number, number] \| null` | – | Controlled selection in metric units. |
| `defaultBrush` | `[number, number] \| null` | `null` | Initial selection when uncontrolled. |
| `onBrushChange` | `(range, selected) => void` | – | Called while brushing and with null when cleared. Changing the metric clears it. |
| `hiddenCategories` | `string[]` | – | Controlled hidden categories. Hidden dots shrink away and the rest re-pack. |
| `defaultHiddenCategories` | `string[]` | – | Initial hidden categories when uncontrolled. |
| `onHiddenCategoriesChange` | `(hidden: string[]) => void` | – | Called when a legend toggle is pressed. |
| `summarize` | `(items, brushed) => string` | – | The live line above the plot. Receives the brushed items, or every shown item. |
| `height` | `number` | `340` | Plot height in pixels, shared by the rows. |
| `emptyLabel` | `string` | `"Nothing to show"` | Shown when every category is hidden. |
| `className` | `string` | – | Extra class on the figure. |

## Keyboard interactions

| Keys | Action |
| --- | --- |
| Tab | Focuses the plot. |
| ArrowLeft / ArrowRight | Moves to the previous or next dot in value order. |
| ArrowUp / ArrowDown | Moves to the nearest dot in the row above or below. |
| Shift + ArrowLeft / ArrowRight | Extends a brush from where the selection started. |
| Home / End | Jumps to the lowest or highest value. |
| Escape | Clears the highlighted dot and the brush. |

## Accessibility

- The plot is a focusable group; the dot in focus is announced with its name, value, category, and row.
- The summary line above the plot is a polite live region, so brushing reads its count and total.
- Legend toggles are buttons with aria-pressed and a count; hovering or focusing one isolates its dots.
- A visually hidden table lists every item with all metrics, in value order.

## Motion

- On first view the dots unfurl from each row's centre line, left to right.
- Every dot runs its own interruptible spring, released left to right by its new x so a re-sort reads as one wave.
- Hidden categories shrink away while the rest re-pack; the tooltip glides between dots.
- Reduced motion places dots directly and swaps the summary with a fade.

## Responsive behavior

- The dot radius follows the width and shrinks until the densest row fits its band, down to 1.4px.
- Hover targets are the nearest dot within 24px, so small dots stay easy to hit.
- Touch taps a dot for details and drags horizontally to brush, while vertical page scroll stays free.

## Performance

- Packing runs once per metric, grouping, filter, and width change, scanning only neighbours within a diameter.
- One requestAnimationFrame loop integrates every dot's spring and stops when all settle.
- Dots are plain SVG circles updated by attribute; about 1,000 stay smooth on laptops.

## Notes for AI

- Choose it to show every item in a distribution, up to about 1,000 dots, when outliers and clusters matter.
- Use a log scale for money and counts that span orders of magnitude.
- Pass summarize to make the live line speak your domain, such as count and total revenue.
- Keep categories to three; each takes a series hue derived from the accent, and a ring in the same hue marks the dot in focus.

## Related

- [Range histogram slider](https://uiarc.dev/components/range-histogram-slider/markdown): A price range over a live histogram of the data, lighting the bars inside the range and settling on bar edges.
- [Data grid](https://uiarc.dev/components/data-grid/markdown): A spreadsheet grid with range selection, inline editing, a fill handle, and animated sorting.
- [Bar chart](https://uiarc.dev/components/bar-chart/markdown): Compare one measure across days and scrub any bar for its value.
- [Brush chart](https://uiarc.dev/components/brush-chart/markdown): A dense time series with an overview strip: drag a window to zoom, resize it by its handles, and read events in place.

## Also in advanced charts

- [Sunburst](https://uiarc.dev/components/sunburst/markdown): A hierarchy in rings: click a segment and every arc swings around it as the new centre, with a breadcrumb back and a rolling total.
- [Sankey flow](https://uiarc.dev/components/sankey-flow/markdown): Flows between stages as ribbons with drifting particles; hover any node or ribbon to pour its share through the whole journey.
- [Funnel chart](https://uiarc.dev/components/funnel-chart/markdown): A tapered conversion funnel with drop-off at every step, a device split that morphs the band, and dots that stream through it.
- [Radar chart](https://uiarc.dev/components/radar-chart/markdown): Two or three profiles on one web: shapes morph when you swap a profile, and a sweep across the axes compares values in place.
- [Realtime stream](https://uiarc.dev/components/realtime-stream/markdown): A live line that scrolls at 60fps as readings arrive, holds still on hover to read, and pops a marker on every anomaly.
- [Race bar chart](https://uiarc.dev/components/race-bar-chart/markdown): A ranking over time: bars overtake each other on springs, values count up, and a timeline you can play or scrub.

## Guidance for AI tools

Beeswarm: Every item as a dot, packed without overlap, that flows to its new place when the metric or rows change, with a brush to select a range. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://uiarc.dev/llms.txt
