Mermaid Treemap Diagrams

Treemaps visualize hierarchical data as nested rectangles, with size proportional to value. Perfect for showing proportions, file sizes, and hierarchical structures.

Use Case

Use treemaps when you need to:

  • Show hierarchical proportions
  • Visualize file/directory sizes
  • Display category breakdowns
  • Show nested data structures
  • Compare relative sizes

Code

1```mermaid
2treemap-beta
3"Project Structure"
4    "Frontend": 40
5    "Backend": 35
6    "Database": 25
7```

Result:

treemap-beta
"Project Structure"
    "Frontend": 40
    "Backend": 35
    "Database": 25

Examples

Example 1: Project Structure

 1```mermaid
 2treemap-beta
 3"Codebase Structure"
 4    "Frontend"
 5        "Components": 20
 6        "Pages": 15
 7        "Utils": 10
 8    "Backend"
 9        "API": 15
10        "Services": 12
11        "Models": 8
12    "Tests"
13        "Unit": 12
14        "Integration": 8
15```

Result:

treemap-beta
"Codebase Structure"
    "Frontend"
        "Components": 20
        "Pages": 15
        "Utils": 10
    "Backend"
        "API": 15
        "Services": 12
        "Models": 8
    "Tests"
        "Unit": 12
        "Integration": 8

Example 2: Budget Allocation

 1```mermaid
 2treemap-beta
 3"Total Budget"
 4    "Development"
 5        "Backend": 25
 6        "Frontend": 20
 7        "DevOps": 5
 8    "Marketing"
 9        "Advertising": 15
10        "Content": 10
11        "Events": 5
12    "Operations"
13        "Infrastructure": 12
14        "Support": 8
15```

Result:

treemap-beta
"Total Budget"
    "Development"
        "Backend": 25
        "Frontend": 20
        "DevOps": 5
    "Marketing"
        "Advertising": 15
        "Content": 10
        "Events": 5
    "Operations"
        "Infrastructure": 12
        "Support": 8

Notes

  • Keyword is treemap-beta (Mermaid 11.8.0+)
  • Every label is double-quoted; leaves are "Label": value
  • Indentation creates hierarchy; parents carry no value (their size is the sum of children)
  • Can nest multiple levels

Gotchas/Warnings

  • ⚠️ Indentation: Must be consistent for hierarchy
  • ⚠️ Values: Only on leaves, positive numbers
  • ⚠️ Nesting: Can nest multiple levels deep
  • ⚠️ Proportions: Rectangle sizes proportional to values

Related Snippets