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:

treemap
    title Project Structure
    Root
        Frontend : 40
        Backend : 35
        Database : 25

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:

treemap
    title Codebase Structure
    Root
        Frontend : 45
            Components : 20
            Pages : 15
            Utils : 10
        Backend : 35
            API : 15
            Services : 12
            Models : 8
        Tests : 20
            Unit : 12
            Integration : 8

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:

treemap
    title Budget Breakdown
    Total Budget
        Development : 50
            Backend : 25
            Frontend : 20
            DevOps : 5
        Marketing : 30
            Advertising : 15
            Content : 10
            Events : 5
        Operations : 20
            Infrastructure : 12
            Support : 8

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