Treemap

Rectangles sized by value, to compare parts of a whole at a glance. Use it when there are many parts and a pie would be unreadable, such as disk usage or sales by product.

Charts need Recharts. Install it once with yarn add recharts, then import from @bolio-ui/core/charts. The package stays out of your bundle until you use a chart.

General

Each item has a name and a value. The area of its rectangle follows the value.

Groups

An item with children is a group. Its children take its color unless they set their own.

APIs

Treemap.Props

AttributeDescriptionTypeAccepted valuesDefault
datathe items, each one may have childrenTreemapNode[]TreemapNode-
heightheight of the chart, in pixelsnumber-300
aspectRatiothe shape the rectangles try to have, width over heightnumber-golden ratio
withTooltipshow the value of a rectangle on hover and focusboolean-true
withLabelswrite the name inside the rectangles that are big enoughboolean-true
labelColorcolor of the namesstring-#fff
valueFormatterhow a number is written(value: number) => string-thousands separators, en-US
...native props, passed to the rootHTMLAttributes'aria-label', 'className', ...-

TreemapNode

type TreemapNode = {
  name: string
  value?: number // a leaf needs a value, a group is the sum of its children
  color?: string // any CSS color, a group passes it to its children
  children?: TreemapNode[]
}

Ref

The ref points at the root div.

Accessibility

Name the chart with aria-label, or with aria-labelledby pointing at a heading. A named chart becomes a group. Names show only inside rectangles that have room, so list the biggest items in text next to the chart or offer a Table.

Edit this page on GitHub