Treemap

Charts
Data Visualization

Visualize hierarchical data as nested rectangles proportional to values.

Preview

Treemap card with icons showing file type distribution

Storage Usage

127.8 GB used of 256 GB

Videos
45.2 GB (35.4%)
Photos
32.8 GB (25.7%)
Documents
18.5 GB (14.5%)
Music
Code
Videos35.4%
Photos25.7%
Documents14.5%
Music9.6%
Code6.8%
Archives4.9%
Other3.2%

Custom Keys

Team time distribution with custom value formatting

Time Allocation

Hours by activity this month

Development
850 hrs (36.6%)
Meetings
420 hrs (18.1%)
Planning
380 hrs (16.4%)
Review
280 hrs (12.1%)
Research
180 hrs (7.8%)
Development36.6%
Meetings18.1%
Planning16.4%
Review12.1%
Research7.8%
Documentation5.2%
Admin3.9%

Standalone Treemap

Treemap component without card wrapper

Apple
28.5% (28.5%)
Samsung
22.3% (22.3%)
Others
20.8% (20.8%)
Xiaomi
12.8% (12.8%)

Props

Component API reference

Treemap

PropTypeDefaultDescription
data*TreemapItem[]Array with value, label, color, and optional icon
widthnumber600Chart width in pixels
heightnumber400Chart height in pixels
valueKeystring'value'Data key for values
labelKeystring'label'Data key for labels
gapnumber2Gap between rectangles
borderRadiusnumber4Corner radius
formatValue(v: number) => stringValue formatter
onItemClick(item) => voidClick handler

TreemapCard

PropTypeDefaultDescription
titlestringCard header title
subtitlestringCard header subtitle
showLegendbooleantrueShow legend below treemap
maxLegendItemsnumber8Max items in legend

Usage

Import and implementation examples

import { Treemap, TreemapCard } from '@/blocks/charts/treemap'
import { Video, Image, Music } from 'lucide-react'

// Basic Treemap
<Treemap
  data={[
    { label: 'Category A', value: 45, color: 'var(--color-indigo-500)' },
    { label: 'Category B', value: 30, color: 'var(--color-teal-500)' },
    { label: 'Category C', value: 25, color: 'var(--color-slate-400)' },
  ]}
  width={600}
  height={400}
/>

// With custom keys and formatting
<Treemap
  data={[
    { category: 'Engineering', amount: 850000 },
    { category: 'Marketing', amount: 420000 },
  ]}
  valueKey="amount"
  labelKey="category"
  formatValue={(v) => `$${(v / 1000).toFixed(0)}k`}
/>

// With icons
<Treemap
  data={[
    { label: 'Videos', value: 45, icon: <Video /> },
    { label: 'Photos', value: 32, icon: <Image /> },
    { label: 'Music', value: 12, icon: <Music /> },
  ]}
/>

// Treemap Card with legend
<TreemapCard
  title="Storage Usage"
  subtitle="127.8 GB used"
  data={storageData}
  height={280}
  formatValue={(v) => `${v} GB`}
  showLegend
/>

Features

Built-in functionality

  • Squarified layout: Optimal aspect ratio algorithm
  • Interactive tooltips: Hover for details
  • Icon support: Display icons in cells
  • Auto label sizing: Text scales to fit
  • Custom colors: Per-item color support
  • Legend with percentages: Visual breakdown
  • Click handling: Interactive selection
  • Dark mode: Full dark mode support

Accessibility

Accessibility considerations

ARIA Attributes

Uses role="img" for treemap containeraria-label describes chart contentInteractive cells are focusable

Keyboard Navigation

KeyAction
TabNavigate between cells
EnterSelect cell (triggers onClick)

Notes

  • Legend provides text alternative
  • Tooltips show detailed values
  • Consider data table for complex data

Related Components