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
3    title Project Structure
4    Root
5        Frontend : 40
6        Backend : 35
7        Database : 25
8```

Result:

Examples

Example 1: Project Structure

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

Result:

Example 2: Budget Allocation

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

Result:

Notes

  • title - Optional treemap title
  • Indentation creates hierarchy
  • Values determine rectangle size
  • Can nest multiple levels

Gotchas/Warnings

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

Related Snippets