Navigation

v2.1.0
Parts of a whole

Treemap

Many parts of a whole as tiles, each as large as its share.

On this page

A treemap shows the parts of a whole as tiles whose areas are their shares. It holds more parts than a pie can, and a small part is still a tile a reader can point at. The tiles are laid out largest first and kept as near to squares as their sizes allow, since a square's area is easier to judge than a sliver's.

Treemap

<div class="card max-w(560) mx-auto">  <div class="card-header">    <h3 class="card-title">Bundle</h3>    <p class="card-description">Kilobytes by package</p>  </div>  <figure class="chart" id="bundle"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('bundle'), {  type: 'treemap',  label: 'Bundle size by package, in kilobytes',  format: function (value) { return value + ' kB' },  series: [    { name: 'react-dom', value: 132 },    { name: 'editor', value: 96 },    { name: 'charts', value: 58 },    { name: 'router', value: 34 },    { name: 'icons', value: 28 },    { name: 'date', value: 19 },    { name: 'state', value: 12 },    { name: 'utils', value: 8 },    { name: 'polyfill', value: 5 }  ]})})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { Chart } from './ui/chart'<div className="card max-w(560) mx-auto">  <div className="card-header">    <h3 className="card-title">Bundle</h3>    <p className="card-description">Kilobytes by package</p>  </div>  <Chart    id="bundle"    type="treemap"    label="Bundle size by package, in kilobytes"    format={function (value) { return value + ' kB' }}    series={[      { name: 'react-dom', value: 132 },      { name: 'editor', value: 96 },      { name: 'charts', value: 58 },      { name: 'router', value: 34 },      { name: 'icons', value: 28 },      { name: 'date', value: 19 },      { name: 'state', value: 12 },      { name: 'utils', value: 8 },      { name: 'polyfill', value: 5 }    ]}  /></div>
<script>  import Chart from './ui/Chart.svelte'</script><div class="card max-w(560) mx-auto">  <div class="card-header">    <h3 class="card-title">Bundle</h3>    <p class="card-description">Kilobytes by package</p>  </div>  <Chart    id="bundle"    type="treemap"    label="Bundle size by package, in kilobytes"    format={function (value) { return value + ' kB' }}    series={[      { name: 'react-dom', value: 132 },      { name: 'editor', value: 96 },      { name: 'charts', value: 58 },      { name: 'router', value: 34 },      { name: 'icons', value: 28 },      { name: 'date', value: 19 },      { name: 'state', value: 12 },      { name: 'utils', value: 8 },      { name: 'polyfill', value: 5 }    ]}  /></div>
<script setup>import Chart from './ui/Chart.vue'</script><template>  <div class="card max-w(560) mx-auto">    <div class="card-header">      <h3 class="card-title">Bundle</h3>      <p class="card-description">Kilobytes by package</p>    </div>    <Chart      id="bundle"      type="treemap"      label="Bundle size by package, in kilobytes"      :format="function (value) { return value + ' kB' }"      :series="[        { name: 'react-dom', value: 132 },        { name: 'editor', value: 96 },        { name: 'charts', value: 58 },        { name: 'router', value: 34 },        { name: 'icons', value: 28 },        { name: 'date', value: 19 },        { name: 'state', value: 12 },        { name: 'utils', value: 8 },        { name: 'polyfill', value: 5 }      ]"    />  </div></template>

A tile says its name where it has room for it, and its value under the name where it has room for both; every tile says both in the readout and in its point's name, so nothing is lost on a small tile. Tiles are a wash of ink. A series that names a category takes that category's surface, for parts a product already colors.

In categories

<div class="card max-w(560) mx-auto">  <div class="card-header">    <h3 class="card-title">Storage</h3>    <p class="card-description">Gigabytes by kind</p>  </div>  <figure class="chart" id="storage-tiles"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('storage-tiles'), {  type: 'treemap',  label: 'Storage used by kind, in gigabytes',  format: function (value) { return value + ' GB' },  series: [    { name: 'Photos', value: 112, category: 'blue' },    { name: 'Video', value: 74, category: 'orange' },    { name: 'Documents', value: 38, category: 'teal' },    { name: 'Mail', value: 24, category: 'violet' },    { name: 'Other', value: 12, category: 'amber' }  ]})})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { Chart } from './ui/chart'<div className="card max-w(560) mx-auto">  <div className="card-header">    <h3 className="card-title">Storage</h3>    <p className="card-description">Gigabytes by kind</p>  </div>  <Chart    id="storage-tiles"    type="treemap"    label="Storage used by kind, in gigabytes"    format={function (value) { return value + ' GB' }}    series={[      { name: 'Photos', value: 112, category: 'blue' },      { name: 'Video', value: 74, category: 'orange' },      { name: 'Documents', value: 38, category: 'teal' },      { name: 'Mail', value: 24, category: 'violet' },      { name: 'Other', value: 12, category: 'amber' }    ]}  /></div>
<script>  import Chart from './ui/Chart.svelte'</script><div class="card max-w(560) mx-auto">  <div class="card-header">    <h3 class="card-title">Storage</h3>    <p class="card-description">Gigabytes by kind</p>  </div>  <Chart    id="storage-tiles"    type="treemap"    label="Storage used by kind, in gigabytes"    format={function (value) { return value + ' GB' }}    series={[      { name: 'Photos', value: 112, category: 'blue' },      { name: 'Video', value: 74, category: 'orange' },      { name: 'Documents', value: 38, category: 'teal' },      { name: 'Mail', value: 24, category: 'violet' },      { name: 'Other', value: 12, category: 'amber' }    ]}  /></div>
<script setup>import Chart from './ui/Chart.vue'</script><template>  <div class="card max-w(560) mx-auto">    <div class="card-header">      <h3 class="card-title">Storage</h3>      <p class="card-description">Gigabytes by kind</p>    </div>    <Chart      id="storage-tiles"      type="treemap"      label="Storage used by kind, in gigabytes"      :format="function (value) { return value + ' GB' }"      :series="[        { name: 'Photos', value: 112, category: 'blue' },        { name: 'Video', value: 74, category: 'orange' },        { name: 'Documents', value: 38, category: 'teal' },        { name: 'Mail', value: 24, category: 'violet' },        { name: 'Other', value: 12, category: 'amber' }      ]"    />  </div></template>

#Options

OptionDefault
labelnoneWhat the chart shows and in what unit: the plot's accessible name
series[]Each with a name and what its form reads: values, a value, points, ranges or children; optionally a category, a type, low and high, and a ring's max
format, tickFormatthe locale'sHow a value and a tick are written; xFormat for a scatter's scale across
currentnoneThe index of the point marked aria-current

The readout, the keys, the legend, the colors and the scale are the same in every form: Chart holds them, with every option, class and custom property.