
## Usage

Add `<EvilAreaChart.Brush />` as a child of the chart root. Its presence renders the brush footer — a miniature of the **full** dataset with a draggable selection window over it. Narrowing that window filters the main chart to the selected range; the miniature always keeps showing everything, so you never lose your place.

Set `xDataKey` on the root so the handles can label themselves with the value under each edge.

```svelte
<script lang="ts">
	import { EvilAreaChart } from '$lib/components/evilcharts/charts/layerchart-area-chart/index.js';
</script>

<EvilAreaChart {data} config={chartConfig} xDataKey="date">
	<EvilAreaChart.XAxis dataKey="date" />
	<EvilAreaChart.Brush formatLabel={(value) => String(value)} />
	<EvilAreaChart.Area dataKey="desktop" variant="gradient" />
</EvilAreaChart>
```

## Example

### <EvilAreaChart.Brush />

```svelte
<script lang="ts">
	import { EvilAreaChart } from '$lib/components/evilcharts/charts/layerchart-area-chart/index.js';
	import { type ChartConfig } from '$lib/components/evilcharts/ui/layerchart-chart/index.js';

	const data = [
		{ date: 'June 1', desktop: 412, mobile: 268 },
		{ date: 'June 2', desktop: 468, mobile: 301 },
		{ date: 'June 3', desktop: 501, mobile: 334 },
		{ date: 'June 4', desktop: 486, mobile: 312 },
		{ date: 'June 5', desktop: 523, mobile: 349 },
		{ date: 'June 6', desktop: 297, mobile: 198 },
		{ date: 'June 7', desktop: 264, mobile: 173 },
		{ date: 'June 8', desktop: 534, mobile: 356 },
		{ date: 'June 9', desktop: 578, mobile: 384 },
		{ date: 'June 10', desktop: 612, mobile: 402 },
		{ date: 'June 11', desktop: 596, mobile: 391 },
		{ date: 'June 12', desktop: 641, mobile: 428 },
		{ date: 'June 13', desktop: 351, mobile: 236 },
		{ date: 'June 14', desktop: 318, mobile: 211 },
		{ date: 'June 15', desktop: 663, mobile: 441 },
		{ date: 'June 16', desktop: 702, mobile: 467 },
		{ date: 'June 17', desktop: 688, mobile: 452 },
		{ date: 'June 18', desktop: 731, mobile: 489 },
		{ date: 'June 19', desktop: 754, mobile: 503 },
		{ date: 'June 20', desktop: 402, mobile: 271 },
		{ date: 'June 21', desktop: 376, mobile: 249 },
		{ date: 'June 22', desktop: 769, mobile: 512 },
		{ date: 'June 23', desktop: 812, mobile: 538 },
		{ date: 'June 24', desktop: 798, mobile: 524 },
		{ date: 'June 25', desktop: 843, mobile: 561 },
		{ date: 'June 26', desktop: 867, mobile: 579 },
		{ date: 'June 27', desktop: 451, mobile: 302 },
		{ date: 'June 28', desktop: 428, mobile: 287 },
		{ date: 'June 29', desktop: 881, mobile: 594 },
		{ date: 'June 30', desktop: 926, mobile: 618 }
	];

	const chartConfig = {
		desktop: {
			label: 'Desktop',
			colors: {
				light: ['#047857'],
				dark: ['#10b981']
			}
		},
		mobile: {
			label: 'Mobile',
			colors: {
				light: ['#be123c'],
				dark: ['#f43f5e']
			}
		}
	} satisfies ChartConfig;
</script>

<EvilAreaChart
	{data}
	config={chartConfig}
	class="h-full w-full p-4"
	curveType="monotone"
	xDataKey="date"
>
	<EvilAreaChart.Grid />
	<EvilAreaChart.XAxis dataKey="date" tickFormatter={(value) => String(value).split(' ')[1]} />
	<!-- [!code highlight] -->
	<EvilAreaChart.Brush height={56} formatLabel={(value) => String(value)} />
	<EvilAreaChart.Legend isClickable />
	<EvilAreaChart.Tooltip />
	<EvilAreaChart.Area dataKey="desktop" variant="gradient" isClickable />
	<EvilAreaChart.Area dataKey="mobile" variant="gradient" isClickable />
</EvilAreaChart>
```

> 
  

Drag either handle to resize the range, or drag the selected region itself to pan without changing its width. Handle labels fade in while the pointer is over the brush. Mouse, touch, and pen all work.

The same controls are available from the keyboard. Tab to a start or end handle, use the arrow keys to move it by one data point, and use Home or End to reach its valid boundary. Tab to the selected window to shift the complete range with the arrow keys; Home and End move that window to the beginning or end. The handles never cross, and reduced-motion preferences disable the positioning springs.




## Supported Charts

The brush is available on the cartesian charts — `EvilAreaChart`, `EvilLineChart`, `EvilBarChart`, and `EvilComposedChart`. Attach it exactly the same way on each:

```svelte
<EvilLineChart.Brush />
<EvilBarChart.Brush />
<EvilComposedChart.Brush />
```

The miniature mirrors the chart it belongs to. Area and composed charts draw filled areas, line charts draw strokes only, and bar charts draw rounded bars — and it inherits the parent chart's `curveType`, stacking, bar radius, and series colors, so the footer always reads as the same chart in small.

The brush is hidden while the chart is in its loading state, and it never renders for the non-cartesian charts (pie, radar, radial, sankey), which have no continuous axis to zoom.

## Reacting to the Range

Filtering the chart is automatic — the root already slices its data to the selection. Pass `onChange` when something _outside_ the chart needs to follow along, such as a heading that reports the visible window:

```svelte
<script lang="ts">
	let range = $state({ startIndex: 0, endIndex: data.length - 1 });
</script>

<EvilAreaChart {data} config={chartConfig} xDataKey="date">
	<EvilAreaChart.Brush onChange={(next) => (range = next)} />
	<EvilAreaChart.Area dataKey="desktop" variant="gradient" />
</EvilAreaChart>

<!-- data[range.startIndex].date → data[range.endIndex].date -->
```

`onChange` fires with data **indices**, not values, so look the labels up on your own rows.

## API Reference

### Brush

Composed as a child of the chart root. It renders nothing itself — its presence turns the brush footer on, and its props configure it.


  ### `height`

type: `number` · default: `56`

Height of the brush preview strip in pixels.
  ### `formatLabel`

type: `(value: unknown, index: number) => string`

Formats the range-handle labels from the `xDataKey` value under each edge. Defaults to the raw value.
  ### `onChange`

type: `(range: { startIndex: number; endIndex: number }) => void`

Fires as the selection moves, with the inclusive data indices of the visible range.


### Root


  ### `xDataKey`

type: `string`

The data key the handle labels read from. Without it the handles fall back to raw indices.

