# @salmonui/charts/sparkline API reference

> 11 exported symbols of @salmonui/charts/sparkline: 1 component, 6 interfaces and 4 types.

Canonical: https://salmonui.dev/docs/reference/charts/sparkline

```ts
import { … } from '@salmonui/charts/sparkline';
```

## Components

### Sparkline

Kind: component

Page: https://salmonui.dev/docs/reference/charts/sparkline/Sparkline

```ts
function Sparkline(props: SparklineProps): ReactNode;
```

Props: [`SparklineProps`](https://salmonui.dev/docs/reference/charts/sparkline/SparklineProps) (its members are the props)

## Interfaces

### SparklineBand

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/sparkline/SparklineBand

```ts
interface SparklineBand {
    readonly from: number;
    readonly to: number;
    readonly color?: string | undefined;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `from` | `readonly from: number;` |  |  |
| `to` | `readonly to: number;` |  |  |
| `color` | `readonly color?: string \| undefined;` | optional | Data color; default the neutral band color. |

### SparklinePoint

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/sparkline/SparklinePoint

```ts
interface SparklinePoint {
    readonly index: number;
    readonly x: number;
    readonly y: number;
    readonly datum: unknown;
    readonly kinds: readonly SparklinePointKind[];
}
```

Members (5):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `index` | `readonly index: number;` |  |  |
| `x` | `readonly x: number;` |  | The x value (index, category position or epoch ms). |
| `y` | `readonly y: number;` |  |  |
| `datum` | `readonly datum: unknown;` |  | The record (or the number) at this index. |
| `kinds` | `readonly kinds: readonly SparklinePointKind[];` |  | Highlight kinds this point carries. |

### SparklinePointEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/sparkline/SparklinePointEvent

```ts
interface SparklinePointEvent {
    readonly point: SparklinePoint;
    readonly source: 'pointer' | 'keyboard';
    readonly nativeEvent: MouseEvent | KeyboardEvent | PointerEvent;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `point` | `readonly point: SparklinePoint;` |  |  |
| `source` | `readonly source: 'pointer' \| 'keyboard';` |  |  |
| `nativeEvent` | `readonly nativeEvent: MouseEvent \| KeyboardEvent \| PointerEvent;` |  |  |

### SparklinePointStyle

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/sparkline/SparklinePointStyle

```ts
interface SparklinePointStyle {
    readonly color?: string | undefined;
    readonly hidden?: boolean | undefined;
}
```

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `color` | `readonly color?: string \| undefined;` | optional | Data color of the point (column, win-loss bar or marker). |
| `hidden` | `readonly hidden?: boolean \| undefined;` | optional |  |

### SparklineProps

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/sparkline/SparklineProps

```ts
interface SparklineProps {
    readonly data: readonly unknown[];
    readonly xField?: string | undefined;
    readonly yField?: string | undefined;
    readonly scale?: 'linear' | 'category' | 'time' | undefined;
    readonly type?: SparklineType | undefined;
    readonly width?: number | undefined;
    readonly height?: number | undefined;
    readonly color?: string | undefined;
    readonly palette?: readonly string[] | undefined;
    readonly tieColor?: string | undefined;
    readonly highlights?: Partial<Record<SparklinePointKind, SparklineHighlight>> | undefined;
    readonly markers?: 'all' | readonly SparklinePointKind[] | undefined;
    readonly labels?: 'all' | readonly SparklinePointKind[] | undefined;
    readonly format?: Intl.NumberFormatOptions | ((value: number) => string) | undefined;
    readonly locale?: string | undefined;
    readonly bands?: readonly SparklineBand[] | undefined;
    readonly domain?: {
        readonly x?: readonly [
            number,
            number
        ] | undefined;
        readonly y?: readonly [
            number,
            number
        ] | undefined;
    } | undefined;
    readonly baseline?: number | undefined;
    readonly padding?: 'none' | 'normal' | 'additional' | undefined;
    readonly tooltip?: boolean | SparklineTooltipOptions | undefined;
    readonly getPointStyle?: ((point: SparklinePoint) => SparklinePointStyle | undefined) | undefined;
    readonly onPointClick?: ((event: SparklinePointEvent) => void) | undefined;
    readonly onPointHover?: ((event: SparklinePointEvent | null) => void) | undefined;
    readonly animated?: boolean | undefined;
    readonly renderer?: 'svg' | 'canvas' | 'auto' | undefined;
    readonly canvasRenderer?: SparklineCanvasRenderer | undefined;
    readonly label?: string | undefined;
    readonly className?: string | undefined;
    readonly style?: CSSProperties | undefined;
    readonly ref?: Ref<SVGSVGElement> | undefined;
    readonly id?: string | undefined;
}
```

Members (31):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `data` | `readonly data: readonly unknown[];` |  | Numbers, or records read through `xField` / `yField`. |
| `xField` | `readonly xField?: string \| undefined;` | optional |  |
| `yField` | `readonly yField?: string \| undefined;` | optional |  |
| `scale` | `readonly scale?: 'linear' \| 'category' \| 'time' \| undefined;` | optional | How x values are read: data index / category order (`linear` without `xField`, `category`) or epoch ms (`time`). |
| `type` | `readonly type?: SparklineType \| undefined;` | optional |  |
| `width` | `readonly width?: number \| undefined;` | optional | Drawing size in px; the SVG scales to its box through `viewBox`. Default 100 x 24. |
| `height` | `readonly height?: number \| undefined;` | optional |  |
| `color` | `readonly color?: string \| undefined;` | optional | Series data color. Default the primary seed. |
| `palette` | `readonly palette?: readonly string[] \| undefined;` | optional | Data colors for column and win-loss bars, by index. |
| `tieColor` | `readonly tieColor?: string \| undefined;` | optional | Win-loss tie color (data color). |
| `highlights` | `readonly highlights?: Partial<Record<SparklinePointKind, SparklineHighlight>> \| undefined;` | optional |  |
| `markers` | `readonly markers?: 'all' \| readonly SparklinePointKind[] \| undefined;` | optional |  |
| `labels` | `readonly labels?: 'all' \| readonly SparklinePointKind[] \| undefined;` | optional |  |
| `format` | `readonly format?: Intl.NumberFormatOptions \| ((value: number) => string) \| undefined;` | optional | Label and tooltip number format. |
| `locale` | `readonly locale?: string \| undefined;` | optional |  |
| `bands` | `readonly bands?: readonly SparklineBand[] \| undefined;` | optional |  |
| `domain` | `readonly domain?: {     readonly x?: readonly [         number,         number     ] \| undefined;     readonly y?: readonly [         number,         number     ] \| undefined; } \| undefined;` | optional |  |
| `baseline` | `readonly baseline?: number \| undefined;` | optional | Value of the axis line (and the column / area base). Default 0 when the data crosses it, else none. |
| `padding` | `readonly padding?: 'none' \| 'normal' \| 'additional' \| undefined;` | optional | Range padding around the y extent. Default `normal` (half a marker). |
| `tooltip` | `readonly tooltip?: boolean \| SparklineTooltipOptions \| undefined;` | optional |  |
| `getPointStyle` | `readonly getPointStyle?: ((point: SparklinePoint) => SparklinePointStyle \| undefined) \| undefined;` | optional |  |
| `onPointClick` | `readonly onPointClick?: ((event: SparklinePointEvent) => void) \| undefined;` | optional |  |
| `onPointHover` | `readonly onPointHover?: ((event: SparklinePointEvent \| null) => void) \| undefined;` | optional |  |
| `animated` | `readonly animated?: boolean \| undefined;` | optional | Entrance transition, default `true`: set on commit (never in server markup), off under `prefers-reduced-motion`; the CSS is the opt-in `@salmonui/charts/viz-animations.css`. |
| `renderer` | `readonly renderer?: 'svg' \| 'canvas' \| 'auto' \| undefined;` | optional | Mark renderer, default `'svg'`. `'canvas'` draws the line, area, bars and markers on a canvas (bands, the axis line and labels stay SVG); `'auto'` switches at 20,000 points. Canvas needs `canvasRenderer`, else the marks stay SVG. |
| `canvasRenderer` | `readonly canvasRenderer?: SparklineCanvasRenderer \| undefined;` | optional | The canvas mark layer: `sparklineCanvas` from `@salmonui/charts/sparkline/canvas` (opt-in, so `/sparkline` stays small). |
| `label` | `readonly label?: string \| undefined;` | optional | Accessible name; default the automatic summary. |
| `className` | `readonly className?: string \| undefined;` | optional |  |
| `style` | `readonly style?: CSSProperties \| undefined;` | optional |  |
| `ref` | `readonly ref?: Ref<SVGSVGElement> \| undefined;` | optional | The root `<svg>`. |
| `id` | `readonly id?: string \| undefined;` | optional |  |

### SparklineTooltipOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/sparkline/SparklineTooltipOptions

```ts
interface SparklineTooltipOptions {
    readonly format?: ((point: SparklinePoint) => string) | undefined;
    readonly render?: ((point: SparklinePoint) => ReactNode) | undefined;
    readonly trackLine?: boolean | undefined;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `format` | `readonly format?: ((point: SparklinePoint) => string) \| undefined;` | optional |  |
| `render` | `readonly render?: ((point: SparklinePoint) => ReactNode) \| undefined;` | optional |  |
| `trackLine` | `readonly trackLine?: boolean \| undefined;` | optional | Vertical track line at the hovered point. Default true. |

## Types

### SparklineCanvasRenderer

Kind: type

Page: https://salmonui.dev/docs/reference/charts/sparkline/SparklineCanvasRenderer

```ts
type SparklineCanvasRenderer = (canvas: HTMLCanvasElement, marks: readonly ReactElement[], width: number, height: number) => void;
```

Draws the mark elements (`<path>`, `<rect>`, `<circle>`) on a canvas of `width` x `height` drawing px.

### SparklineHighlight

Kind: type

Page: https://salmonui.dev/docs/reference/charts/sparkline/SparklineHighlight

```ts
type SparklineHighlight = boolean | string;
```

A highlight: `true` uses the semantic seed color, a string is a data color.

### SparklinePointKind

Kind: type

Page: https://salmonui.dev/docs/reference/charts/sparkline/SparklinePointKind

```ts
type SparklinePointKind = 'high' | 'low' | 'first' | 'last' | 'negative';
```

### SparklineType

Kind: type

Page: https://salmonui.dev/docs/reference/charts/sparkline/SparklineType

```ts
type SparklineType = 'line' | 'area' | 'column' | 'winLoss';
```
