Treemap

Sizes of many parts of a whole as nested rectangles, grouped and colored by category.

Status: beta. Category: Data display.

import { Treemap } from '@glyphui/ui/chart'

Exports: Treemap.

Notes

  • Tiles too small for text show it in the tooltip and the accessible table instead.
  • Each group gets one palette color; after five groups, colors are blended rather than repeated.

Treemap props

PropTypeDefaultDescription
category (required)stringField naming each rectangle.
data (required)readonly T[]One row per rectangle. Rows sharing a group are colored and nested together.
title (required)string
value (required)stringField holding each rectangle's size.
classNamestring
colorsreadonly ChartColorValue[]
descriptionReactNode
emptyReactNodeShown when there is no data. Defaults to a short "No data" message.
errorunknownShows an error message in place of the plot, with a retry button when onRetry is set.
groupstringField grouping rectangles, e.g. a team or product line. Each group gets one color.
heightnumberPlot height in pixels. Default 280.
hideTitleboolean
loadingbooleanShows a skeleton in place of the plot.
onRetry(() => unknown)
showLegendboolean
valueFormatter((value: number) => string)

Example: Cloud spend

Vendors grouped by team.

import { Treemap } from '@glyphui/ui/chart'

const spend = [
  { vendor: 'AWS', team: 'Platform', cost: 42800 },
  { vendor: 'Datadog', team: 'Platform', cost: 9400 },
  { vendor: 'Cloudflare', team: 'Platform', cost: 3100 },
  { vendor: 'Snowflake', team: 'Data', cost: 18600 },
  { vendor: 'Fivetran', team: 'Data', cost: 5200 },
  { vendor: 'Figma', team: 'Design', cost: 2900 },
  { vendor: 'Linear', team: 'Product', cost: 1400 },
  { vendor: 'Notion', team: 'Product', cost: 1100 },
]

const usd = (v: number) => `${(v / 1000).toFixed(1)}k`

export default function Example() {
  return (
    <Treemap
      className="w-full"
      title="Software spend by team"
      description="October, USD"
      data={spend}
      category="vendor"
      value="cost"
      group="team"
      valueFormatter={usd}
    />
  )
}

Live page: https://glyphui.xyz/components/treemap