# @salmonui/charts/tree-map API reference

> 16 exported symbols of @salmonui/charts/tree-map: 1 component, 1 function, 9 interfaces and 5 types.

Canonical: https://salmonui.dev/docs/reference/charts/tree-map

```ts
import { … } from '@salmonui/charts/tree-map';
```

## Components

### TreeMap

Kind: component

Page: https://salmonui.dev/docs/reference/charts/tree-map/TreeMap

```ts
function TreeMap(props: TreeMapProps): ReactNode;
```

Props: [`TreeMapProps`](https://salmonui.dev/docs/reference/charts/tree-map/TreeMapProps) (its members are the props)

## Interfaces

### TreeMapColorScale

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/tree-map/TreeMapColorScale

```ts
interface TreeMapColorScale {
    readonly kind: 'range' | 'value' | 'opacity';
    readonly field?: string | undefined;
    readonly stops: readonly TreeMapColorStop[];
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `kind` | `readonly kind: 'range' \| 'value' \| 'opacity';` |  |  |
| `field` | `readonly field?: string \| undefined;` | optional | Record field the scale reads; default the weight. |
| `stops` | `readonly stops: readonly TreeMapColorStop[];` |  |  |

### TreeMapColorStop

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/tree-map/TreeMapColorStop

```ts
interface TreeMapColorStop {
    readonly value: number | string;
    readonly color: string;
}
```

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `value` | `readonly value: number \| string;` |  | Range start (`range`), the exact value (`value`) or the opacity end (`opacity`). |
| `color` | `readonly color: string;` |  |  |

### TreeMapHeaderOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/tree-map/TreeMapHeaderOptions

```ts
interface TreeMapHeaderOptions {
    readonly format?: ((item: TreeMapItem) => string) | undefined;
    readonly render?: ((item: TreeMapItem) => ReactNode) | undefined;
    readonly align?: 'start' | 'center' | 'end' | undefined;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `format` | `readonly format?: ((item: TreeMapItem) => string) \| undefined;` | optional |  |
| `render` | `readonly render?: ((item: TreeMapItem) => ReactNode) \| undefined;` | optional |  |
| `align` | `readonly align?: 'start' \| 'center' \| 'end' \| undefined;` | optional |  |

### TreeMapItem

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/tree-map/TreeMapItem

```ts
interface TreeMapItem {
    readonly path: TreeMapPath;
    readonly label: string;
    readonly value: number;
    readonly depth: number;
    readonly leaf: boolean;
    readonly datum: unknown;
    readonly color: string;
}
```

Members (7):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `path` | `readonly path: TreeMapPath;` |  |  |
| `label` | `readonly label: string;` |  |  |
| `value` | `readonly value: number;` |  |  |
| `depth` | `readonly depth: number;` |  | Depth below the root (1 = top level). |
| `leaf` | `readonly leaf: boolean;` |  |  |
| `datum` | `readonly datum: unknown;` |  | The record for leaves and hierarchical groups; null for groups built by `levels`. |
| `color` | `readonly color: string;` |  |  |

### TreeMapLeaves

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/tree-map/TreeMapLeaves

```ts
interface TreeMapLeaves {
    readonly labelField?: string | undefined;
    readonly format?: Intl.NumberFormatOptions | ((value: number) => string) | undefined;
    readonly labelPosition?: TreeMapLabelPosition | undefined;
    readonly labelOverflow?: 'trim' | 'hide' | 'wrapWord' | 'wrap' | undefined;
    readonly render?: ((item: TreeMapItem) => ReactNode) | undefined;
    readonly gap?: number | undefined;
    readonly showValue?: boolean | undefined;
}
```

Members (7):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `labelField` | `readonly labelField?: string \| undefined;` | optional |  |
| `format` | `readonly format?: Intl.NumberFormatOptions \| ((value: number) => string) \| undefined;` | optional | Value format in the label and tooltip. |
| `labelPosition` | `readonly labelPosition?: TreeMapLabelPosition \| undefined;` | optional |  |
| `labelOverflow` | `readonly labelOverflow?: 'trim' \| 'hide' \| 'wrapWord' \| 'wrap' \| undefined;` | optional |  |
| `render` | `readonly render?: ((item: TreeMapItem) => ReactNode) \| undefined;` | optional | HTML content laid over the leaf instead of the drawn label. |
| `gap` | `readonly gap?: number \| undefined;` | optional | Gap between leaves, px. Default 1. |
| `showValue` | `readonly showValue?: boolean \| undefined;` | optional | Show `label value` instead of the label alone. |

### TreeMapLevel

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/tree-map/TreeMapLevel

```ts
interface TreeMapLevel {
    readonly groupBy?: string | ((datum: unknown) => string) | undefined;
    readonly gap?: number | undefined;
    readonly header?: boolean | TreeMapHeaderOptions | undefined;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `groupBy` | `readonly groupBy?: string \| ((datum: unknown) => string) \| undefined;` | optional | Group flat data by this field (or accessor). |
| `gap` | `readonly gap?: number \| undefined;` | optional | Gap between the groups of this level, px. Default 2. |
| `header` | `readonly header?: boolean \| TreeMapHeaderOptions \| undefined;` | optional | Header band with the group label. Default true. |

### TreeMapProps

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/tree-map/TreeMapProps

```ts
interface TreeMapProps extends TreeMapRootHandlers {
    readonly data: readonly unknown[];
    readonly weightField?: string | undefined;
    readonly childrenField?: string | undefined;
    readonly levels?: readonly TreeMapLevel[] | undefined;
    readonly layout?: 'squarified' | 'sliceHorizontal' | 'sliceVertical' | 'sliceAuto' | undefined;
    readonly direction?: 'topStart' | 'topEnd' | 'bottomStart' | 'bottomEnd' | undefined;
    readonly leaves?: TreeMapLeaves | undefined;
    readonly colorField?: string | undefined;
    readonly colorScale?: TreeMapColorScale | undefined;
    readonly palette?: readonly string[] | undefined;
    readonly path?: TreeMapPath | undefined;
    readonly defaultPath?: TreeMapPath | undefined;
    readonly onPathChange?: ((path: TreeMapPath, event: TreeMapChangeEvent) => void) | undefined;
    readonly drill?: 'click' | false | undefined;
    readonly breadcrumbs?: boolean | undefined;
    readonly showParentLevels?: boolean | undefined;
    readonly selection?: boolean | {
        readonly mode?: 'item' | 'group' | undefined;
        readonly multiple?: boolean | undefined;
    } | undefined;
    readonly selectedItems?: readonly TreeMapPath[] | undefined;
    readonly defaultSelectedItems?: readonly TreeMapPath[] | undefined;
    readonly onSelectedItemsChange?: ((items: readonly TreeMapPath[], event: TreeMapChangeEvent) => void) | undefined;
    readonly highlight?: boolean | undefined;
    readonly onItemHover?: ((item: TreeMapItem | null) => void) | undefined;
    readonly onItemClick?: ((item: TreeMapItem, event: TreeMapChangeEvent) => void) | undefined;
    readonly getItemStyle?: ((item: TreeMapItem) => {
        readonly color?: string | undefined;
    } | undefined) | undefined;
    readonly legend?: boolean | {
        readonly mode?: 'list' | 'interactive' | undefined;
        readonly position?: 'top' | 'bottom' | 'start' | 'end' | undefined;
        readonly title?: string | undefined;
    } | undefined;
    readonly tooltip?: boolean | {
        readonly render?: ((item: TreeMapItem) => ReactNode) | undefined;
    } | undefined;
    readonly width?: number | undefined;
    readonly height?: number | undefined;
    readonly title?: string | undefined;
    readonly subtitle?: string | undefined;
    readonly description?: string | undefined;
    readonly locale?: string | undefined;
    readonly text?: Partial<TreeMapText> | undefined;
    readonly rootLabel?: string | undefined;
    readonly className?: string | undefined;
    readonly style?: CSSProperties | undefined;
    readonly id?: string | undefined;
    readonly ref?: Ref<TreeMapApi> | undefined;
    readonly onResize?: ((size: {
        readonly width: number;
        readonly height: number;
    }) => void) | undefined;
    readonly animated?: boolean | undefined;
}
```

Members (40):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `data` | `readonly data: readonly unknown[];` |  |  |
| `weightField` | `readonly weightField?: string \| undefined;` | optional |  |
| `childrenField` | `readonly childrenField?: string \| undefined;` | optional | Hierarchical data: children of a record. |
| `levels` | `readonly levels?: readonly TreeMapLevel[] \| undefined;` | optional |  |
| `layout` | `readonly layout?: 'squarified' \| 'sliceHorizontal' \| 'sliceVertical' \| 'sliceAuto' \| undefined;` | optional |  |
| `direction` | `readonly direction?: 'topStart' \| 'topEnd' \| 'bottomStart' \| 'bottomEnd' \| undefined;` | optional |  |
| `leaves` | `readonly leaves?: TreeMapLeaves \| undefined;` | optional |  |
| `colorField` | `readonly colorField?: string \| undefined;` | optional | Data color field of a record. |
| `colorScale` | `readonly colorScale?: TreeMapColorScale \| undefined;` | optional |  |
| `palette` | `readonly palette?: readonly string[] \| undefined;` | optional | Data colors per top-level group; default the derived palette. |
| `path` | `readonly path?: TreeMapPath \| undefined;` | optional |  |
| `defaultPath` | `readonly defaultPath?: TreeMapPath \| undefined;` | optional |  |
| `onPathChange` | `readonly onPathChange?: ((path: TreeMapPath, event: TreeMapChangeEvent) => void) \| undefined;` | optional |  |
| `drill` | `readonly drill?: 'click' \| false \| undefined;` | optional | Clicking a group drills into it. Default `'click'`. |
| `breadcrumbs` | `readonly breadcrumbs?: boolean \| undefined;` | optional |  |
| `showParentLevels` | `readonly showParentLevels?: boolean \| undefined;` | optional | Keep the ancestors of the drilled node as header bands. |
| `selection` | `readonly selection?: boolean \| {     readonly mode?: 'item' \| 'group' \| undefined;     readonly multiple?: boolean \| undefined; } \| undefined;` | optional |  |
| `selectedItems` | `readonly selectedItems?: readonly TreeMapPath[] \| undefined;` | optional |  |
| `defaultSelectedItems` | `readonly defaultSelectedItems?: readonly TreeMapPath[] \| undefined;` | optional |  |
| `onSelectedItemsChange` | `readonly onSelectedItemsChange?: ((items: readonly TreeMapPath[], event: TreeMapChangeEvent) => void) \| undefined;` | optional |  |
| `highlight` | `readonly highlight?: boolean \| undefined;` | optional | Outline the hovered item. Default true. |
| `onItemHover` | `readonly onItemHover?: ((item: TreeMapItem \| null) => void) \| undefined;` | optional |  |
| `onItemClick` | `readonly onItemClick?: ((item: TreeMapItem, event: TreeMapChangeEvent) => void) \| undefined;` | optional |  |
| `getItemStyle` | `readonly getItemStyle?: ((item: TreeMapItem) => {     readonly color?: string \| undefined; } \| undefined) \| undefined;` | optional |  |
| `legend` | `readonly legend?: boolean \| {     readonly mode?: 'list' \| 'interactive' \| undefined;     readonly position?: 'top' \| 'bottom' \| 'start' \| 'end' \| undefined;     readonly title?: string \| undefined; } \| undefined;` | optional | Legend of the top-level groups; `interactive` highlights a group on hover. |
| `tooltip` | `readonly tooltip?: boolean \| {     readonly render?: ((item: TreeMapItem) => ReactNode) \| undefined; } \| undefined;` | optional |  |
| `width` | `readonly width?: number \| undefined;` | optional |  |
| `height` | `readonly height?: number \| undefined;` | optional |  |
| `title` | `readonly title?: string \| undefined;` | optional |  |
| `subtitle` | `readonly subtitle?: string \| undefined;` | optional |  |
| `description` | `readonly description?: string \| undefined;` | optional |  |
| `locale` | `readonly locale?: string \| undefined;` | optional |  |
| `text` | `readonly text?: Partial<TreeMapText> \| undefined;` | optional | Built-in text (over the nearest `LocaleProvider`'s `treeMap` entry). |
| `rootLabel` | `readonly rootLabel?: string \| undefined;` | optional | Breadcrumb root label. Default `text.all` ("All"). |
| `className` | `readonly className?: string \| undefined;` | optional |  |
| `style` | `readonly style?: CSSProperties \| undefined;` | optional |  |
| `id` | `readonly id?: string \| undefined;` | optional |  |
| `ref` | `readonly ref?: Ref<TreeMapApi> \| undefined;` | optional |  |
| `onResize` | `readonly onResize?: ((size: {     readonly width: number;     readonly height: number; }) => void) \| undefined;` | optional |  |
| `animated` | `readonly animated?: boolean \| undefined;` | optional | Entrance and update transitions, default `true`: client only (never in server markup), off under `prefers-reduced-motion`. The CSS is the opt-in `@salmonui/charts/viz-animations.css`. |

### TreeMapText

Kind: interface

Page: https://salmonui.dev/docs/reference/charts/tree-map/TreeMapText

```ts
interface TreeMapText {
    readonly treeMap: string;
    readonly path: string;
    readonly all: string;
    readonly legend: string;
}
```

Built-in text of a TreeMap (`text` prop; the `treeMap` entry of a `LocaleProvider` catalog).

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `treeMap` | `readonly treeMap: string;` |  | Name and role description of the map when there is no `title`. Default `"Tree map"`. |
| `path` | `readonly path: string;` |  | Name of the breadcrumb navigation. |
| `all` | `readonly all: string;` |  | Breadcrumb root. |
| `legend` | `readonly legend: string;` |  |  |

## Types

### TreeMapApi

Kind: type

Page: https://salmonui.dev/docs/reference/charts/tree-map/TreeMapApi

```ts
type TreeMapApi = VizInstance;
```

Members (7):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `element` | `element: HTMLElement \| null;` | inherited | The root `<figure>` (null before mount). |
| `export` | `export: (options?: VizExportOptions \| undefined) => Promise<void>;` | inherited | Downloads the visualization; settles after the download starts. |
| `toBlob` | `toBlob: (format?: ImageFormat \| undefined) => Promise<Blob>;` | inherited |  |
| `toDataURL` | `toDataURL: (format?: ImageFormat \| undefined) => Promise<string>;` | inherited |  |
| `toSVGString` | `toSVGString: () => string;` | inherited | The drawn SVG markup with `xmlns`, synchronously; theme colors stay `var(--salmon-*)` references. `toBlob('svg')` is the standalone file with colors resolved. Empty before mount. |
| `print` | `print: () => Promise<void>;` | inherited |  |
| `focus` | `focus: () => void;` | inherited | Focuses the plot (the one tab stop). |

### TreeMapChangeEvent

Kind: type

Page: https://salmonui.dev/docs/reference/charts/tree-map/TreeMapChangeEvent

```ts
type TreeMapChangeEvent = VizChangeEvent<'drill' | 'breadcrumb' | 'keyboard' | 'click'>;
```

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `source` | `source: VizChangeSource;` | inherited |  |
| `reason` | `reason: "breadcrumb" \| "click" \| "drill" \| "keyboard";` | inherited |  |

### TreeMapLabelPosition

Kind: type

Page: https://salmonui.dev/docs/reference/charts/tree-map/TreeMapLabelPosition

```ts
type TreeMapLabelPosition = 'topStart' | 'topCenter' | 'topEnd' | 'centerStart' | 'center' | 'centerEnd' | 'bottomStart' | 'bottomCenter' | 'bottomEnd';
```

### TreeMapPath

Kind: type

Page: https://salmonui.dev/docs/reference/charts/tree-map/TreeMapPath

```ts
type TreeMapPath = readonly string[];
```

Path of group keys and leaf labels from the root (the drill-down address).

## Re-exported entry points

- [@salmonui/charts/chart/export](https://salmonui.dev/docs/reference/charts/chart-export.md): 3 symbols: 1 function, 1 interface and 1 type
  `ExportVisualizationsOptions`, `ExportableVisualization`, `exportVisualizations`
