collab/mermaid/docs/syntax/treemap.mdblame
View source
6dd74de1> **Warning**
6dd74de2>
6dd74de3> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
6dd74de4>
6dd74de5> ## Please edit the corresponding file in [/packages/mermaid/src/docs/syntax/treemap.md](../../packages/mermaid/src/docs/syntax/treemap.md).
6dd74de6
6dd74de7# Treemap Diagram
6dd74de8
6dd74de9> A treemap diagram displays hierarchical data as a set of nested rectangles. Each branch of the tree is represented by a rectangle, which is then tiled with smaller rectangles representing sub-branches.
6dd74de10
6dd74de11> **Warning**
6dd74de12> This is a new diagram type in Mermaid. Its syntax may evolve in future versions.
6dd74de13
6dd74de14## Introduction
6dd74de15
6dd74de16Treemap diagrams are an effective way to visualize hierarchical data and show proportions between categories and subcategories. The size of each rectangle is proportional to the value it represents, making it easy to compare different parts of a hierarchy.
6dd74de17
6dd74de18Treemap diagrams are particularly useful for:
6dd74de19
6dd74de20- Visualizing hierarchical data structures
6dd74de21- Comparing proportions between categories
6dd74de22- Displaying large amounts of hierarchical data in a limited space
6dd74de23- Identifying patterns and outliers in hierarchical data
6dd74de24
6dd74de25## Syntax
6dd74de26
6dd74de27```
6dd74de28treemap-beta
6dd74de29"Section 1"
6dd74de30 "Leaf 1.1": 12
6dd74de31 "Section 1.2"
6dd74de32 "Leaf 1.2.1": 12
6dd74de33"Section 2"
6dd74de34 "Leaf 2.1": 20
6dd74de35 "Leaf 2.2": 25
6dd74de36```
6dd74de37
6dd74de38### Node Definition
6dd74de39
6dd74de40Nodes in a treemap are defined using the following syntax:
6dd74de41
6dd74de42- **Section/Parent nodes**: Defined with quoted text `"Section Name"`
6dd74de43- **Leaf nodes with values**: Defined with quoted text followed by a colon and value `"Leaf Name": value`
6dd74de44- **Hierarchy**: Created using indentation (spaces or tabs)
6dd74de45- **Styling**: Nodes can be styled using the `:::class` syntax
6dd74de46
6dd74de47## Examples
6dd74de48
6dd74de49### Basic Treemap
6dd74de50
6dd74de51```mermaid-example
6dd74de52treemap-beta
6dd74de53"Category A"
6dd74de54 "Item A1": 10
6dd74de55 "Item A2": 20
6dd74de56"Category B"
6dd74de57 "Item B1": 15
6dd74de58 "Item B2": 25
6dd74de59```
6dd74de60
6dd74de61```mermaid
6dd74de62treemap-beta
6dd74de63"Category A"
6dd74de64 "Item A1": 10
6dd74de65 "Item A2": 20
6dd74de66"Category B"
6dd74de67 "Item B1": 15
6dd74de68 "Item B2": 25
6dd74de69```
6dd74de70
6dd74de71### Hierarchical Treemap
6dd74de72
6dd74de73```mermaid-example
6dd74de74treemap-beta
6dd74de75"Products"
6dd74de76 "Electronics"
6dd74de77 "Phones": 50
6dd74de78 "Computers": 30
6dd74de79 "Accessories": 20
6dd74de80 "Clothing"
6dd74de81 "Men's": 40
6dd74de82 "Women's": 40
6dd74de83```
6dd74de84
6dd74de85```mermaid
6dd74de86treemap-beta
6dd74de87"Products"
6dd74de88 "Electronics"
6dd74de89 "Phones": 50
6dd74de90 "Computers": 30
6dd74de91 "Accessories": 20
6dd74de92 "Clothing"
6dd74de93 "Men's": 40
6dd74de94 "Women's": 40
6dd74de95```
6dd74de96
6dd74de97### Treemap with Styling
6dd74de98
6dd74de99```mermaid-example
6dd74de100treemap-beta
6dd74de101"Section 1"
6dd74de102 "Leaf 1.1": 12
6dd74de103 "Section 1.2":::class1
6dd74de104 "Leaf 1.2.1": 12
6dd74de105"Section 2"
6dd74de106 "Leaf 2.1": 20:::class1
6dd74de107 "Leaf 2.2": 25
6dd74de108 "Leaf 2.3": 12
6dd74de109
6dd74de110classDef class1 fill:red,color:blue,stroke:#FFD600;
6dd74de111```
6dd74de112
6dd74de113```mermaid
6dd74de114treemap-beta
6dd74de115"Section 1"
6dd74de116 "Leaf 1.1": 12
6dd74de117 "Section 1.2":::class1
6dd74de118 "Leaf 1.2.1": 12
6dd74de119"Section 2"
6dd74de120 "Leaf 2.1": 20:::class1
6dd74de121 "Leaf 2.2": 25
6dd74de122 "Leaf 2.3": 12
6dd74de123
6dd74de124classDef class1 fill:red,color:blue,stroke:#FFD600;
6dd74de125```
6dd74de126
6dd74de127## Styling and Configuration
6dd74de128
6dd74de129Treemap diagrams can be customized using Mermaid's styling and configuration options.
6dd74de130
6dd74de131### Using classDef for Styling
6dd74de132
6dd74de133You can define custom styles for nodes using the `classDef` syntax, which is a standard feature across many Mermaid diagram types:
6dd74de134
6dd74de135```mermaid-example
6dd74de136treemap-beta
6dd74de137"Main"
6dd74de138 "A": 20
6dd74de139 "B":::important
6dd74de140 "B1": 10
6dd74de141 "B2": 15
6dd74de142 "C": 5
6dd74de143
6dd74de144classDef important fill:#f96,stroke:#333,stroke-width:2px;
6dd74de145```
6dd74de146
6dd74de147```mermaid
6dd74de148treemap-beta
6dd74de149"Main"
6dd74de150 "A": 20
6dd74de151 "B":::important
6dd74de152 "B1": 10
6dd74de153 "B2": 15
6dd74de154 "C": 5
6dd74de155
6dd74de156classDef important fill:#f96,stroke:#333,stroke-width:2px;
6dd74de157```
6dd74de158
6dd74de159### Theme Configuration
6dd74de160
6dd74de161You can customize the colors of your treemap using the theme configuration:
6dd74de162
6dd74de163```mermaid-example
6dd74de164---
6dd74de165config:
6dd74de166 theme: 'forest'
6dd74de167---
6dd74de168treemap-beta
6dd74de169"Category A"
6dd74de170 "Item A1": 10
6dd74de171 "Item A2": 20
6dd74de172"Category B"
6dd74de173 "Item B1": 15
6dd74de174 "Item B2": 25
6dd74de175```
6dd74de176
6dd74de177```mermaid
6dd74de178---
6dd74de179config:
6dd74de180 theme: 'forest'
6dd74de181---
6dd74de182treemap-beta
6dd74de183"Category A"
6dd74de184 "Item A1": 10
6dd74de185 "Item A2": 20
6dd74de186"Category B"
6dd74de187 "Item B1": 15
6dd74de188 "Item B2": 25
6dd74de189```
6dd74de190
6dd74de191### Diagram Padding
6dd74de192
6dd74de193You can adjust the padding around the treemap diagram using the `diagramPadding` configuration option:
6dd74de194
6dd74de195```mermaid-example
6dd74de196---
6dd74de197config:
6dd74de198 treemap:
6dd74de199 diagramPadding: 200
6dd74de200---
6dd74de201treemap-beta
6dd74de202"Category A"
6dd74de203 "Item A1": 10
6dd74de204 "Item A2": 20
6dd74de205"Category B"
6dd74de206 "Item B1": 15
6dd74de207 "Item B2": 25
6dd74de208```
6dd74de209
6dd74de210```mermaid
6dd74de211---
6dd74de212config:
6dd74de213 treemap:
6dd74de214 diagramPadding: 200
6dd74de215---
6dd74de216treemap-beta
6dd74de217"Category A"
6dd74de218 "Item A1": 10
6dd74de219 "Item A2": 20
6dd74de220"Category B"
6dd74de221 "Item B1": 15
6dd74de222 "Item B2": 25
6dd74de223```
6dd74de224
6dd74de225## Configuration Options
6dd74de226
6dd74de227The treemap diagram supports the following configuration options:
6dd74de228
6dd74de229| Option | Description | Default |
6dd74de230| -------------- | --------------------------------------------------------------------------- | ------- |
6dd74de231| useMaxWidth | When true, the diagram width is set to 100% and scales with available space | true |
6dd74de232| padding | Internal padding between nodes | 10 |
6dd74de233| diagramPadding | Padding around the entire diagram | 8 |
6dd74de234| showValues | Whether to show values in the treemap | true |
6dd74de235| nodeWidth | Width of nodes | 100 |
6dd74de236| nodeHeight | Height of nodes | 40 |
6dd74de237| borderWidth | Width of borders | 1 |
6dd74de238| valueFontSize | Font size for values | 12 |
6dd74de239| labelFontSize | Font size for labels | 14 |
6dd74de240| valueFormat | Format for values (see Value Formatting section) | ',' |
6dd74de241
6dd74de242## Advanced Features
6dd74de243
6dd74de244### Value Formatting
6dd74de245
6dd74de246Values in treemap diagrams can be formatted to display in different ways using the `valueFormat` configuration option. This option primarily uses [D3's format specifiers](https://github.com/d3/d3-format#locale_format) to control how numbers are displayed, with some additional special cases for common formats.
6dd74de247
6dd74de248Some common format patterns:
6dd74de249
6dd74de250- `,` - Thousands separator (default)
6dd74de251- `$` - Add dollar sign
6dd74de252- `.1f` - Show one decimal place
6dd74de253- `.1%` - Show as percentage with one decimal place
6dd74de254- `$0,0` - Dollar sign with thousands separator
6dd74de255- `$.2f` - Dollar sign with 2 decimal places
6dd74de256- `$,.2f` - Dollar sign with thousands separator and 2 decimal places
6dd74de257
6dd74de258The treemap diagram supports both standard D3 format specifiers and some common currency formats that combine the dollar sign with other formatting options.
6dd74de259
6dd74de260Example with currency formatting:
6dd74de261
6dd74de262```mermaid-example
6dd74de263---
6dd74de264config:
6dd74de265 treemap:
6dd74de266 valueFormat: '$0,0'
6dd74de267---
6dd74de268treemap-beta
6dd74de269"Budget"
6dd74de270 "Operations"
6dd74de271 "Salaries": 700000
6dd74de272 "Equipment": 200000
6dd74de273 "Supplies": 100000
6dd74de274 "Marketing"
6dd74de275 "Advertising": 400000
6dd74de276 "Events": 100000
6dd74de277```
6dd74de278
6dd74de279```mermaid
6dd74de280---
6dd74de281config:
6dd74de282 treemap:
6dd74de283 valueFormat: '$0,0'
6dd74de284---
6dd74de285treemap-beta
6dd74de286"Budget"
6dd74de287 "Operations"
6dd74de288 "Salaries": 700000
6dd74de289 "Equipment": 200000
6dd74de290 "Supplies": 100000
6dd74de291 "Marketing"
6dd74de292 "Advertising": 400000
6dd74de293 "Events": 100000
6dd74de294```
6dd74de295
6dd74de296Example with percentage formatting:
6dd74de297
6dd74de298```mermaid-example
6dd74de299---
6dd74de300config:
6dd74de301 treemap:
6dd74de302 valueFormat: '$.1%'
6dd74de303---
6dd74de304treemap-beta
6dd74de305"Market Share"
6dd74de306 "Company A": 0.35
6dd74de307 "Company B": 0.25
6dd74de308 "Company C": 0.15
6dd74de309 "Others": 0.25
6dd74de310```
6dd74de311
6dd74de312```mermaid
6dd74de313---
6dd74de314config:
6dd74de315 treemap:
6dd74de316 valueFormat: '$.1%'
6dd74de317---
6dd74de318treemap-beta
6dd74de319"Market Share"
6dd74de320 "Company A": 0.35
6dd74de321 "Company B": 0.25
6dd74de322 "Company C": 0.15
6dd74de323 "Others": 0.25
6dd74de324```
6dd74de325
6dd74de326## Common Use Cases
6dd74de327
6dd74de328Treemap diagrams are commonly used for:
6dd74de329
6dd74de3301. **Financial Data**: Visualizing budget allocations, market shares, or portfolio compositions
6dd74de3312. **File System Analysis**: Showing disk space usage by folders and files
6dd74de3323. **Population Demographics**: Displaying population distribution across regions and subregions
6dd74de3334. **Product Hierarchies**: Visualizing product categories and their sales volumes
6dd74de3345. **Organizational Structures**: Representing departments and team sizes in a company
6dd74de335
6dd74de336## Limitations
6dd74de337
6dd74de338- Treemap diagrams work best when the data has a natural hierarchy
6dd74de339- Very small values may be difficult to see or label in a treemap diagram
6dd74de340- Deep hierarchies (many levels) can be challenging to represent clearly
6dd74de341- Treemap diagrams are not well suited for representing data with negative values
6dd74de342
6dd74de343## Related Diagrams
6dd74de344
6dd74de345If treemap diagrams don't suit your needs, consider these alternatives:
6dd74de346
6dd74de347- [**Pie Charts**](./pie.md): For simple proportion comparisons without hierarchy
6dd74de348- **Sunburst Diagrams**: For hierarchical data with a radial layout (yet to be released in Mermaid).
6dd74de349- [**Sankey Diagrams**](./sankey.md): For flow-based hierarchical data
6dd74de350
6dd74de351## Notes
6dd74de352
6dd74de353The treemap diagram implementation in Mermaid is designed to be simple to use while providing powerful visualization capabilities. As this is a newer diagram type, feedback and feature requests are welcome through the Mermaid GitHub repository.