StealThis .dev

Treemap

A proportional treemap that visualizes hierarchical data as nested rectangles. Implements a squarified layout algorithm, color-coded groups, hover tooltips, and animated entrance.

Open in Lab
vanilla-js css react tailwind vue svelte
Targets: TS JS HTML React Vue Svelte

Code

Features

  • Squarified layout — minimizes tile aspect ratio for readability
  • Hierarchical groups — group labels rendered over child tiles
  • Hover tooltip — name, value, and % of total on hover
  • Color-coded groups — consistent group hue with value-based lightness
  • Animated entrance — tiles fade and scale in on mount
  • Responsive — recalculates layout on container resize

How it works

  1. The squarified treemap algorithm recursively divides the container rectangle
  2. Each node’s area is proportional to its normalized value
  3. Tiles are CSS-positioned <div> elements overlaid on the container
  4. Group borders use a slightly lighter shade for clear hierarchy