blockcharts alpha

Gallery / Parts of a whole /

Marimekko

Market size and share at once: how big each column is, and who holds it.

73.0 KB of code · core 29.5 + 10 blocks 43.5

Who sells how much, and where

Asia is nearly half the market, and Refiner A leads there; Refiner B leads in Europe, and smaller suppliers hold half of the Americas and two thirds of Africa.

How it is made: transform.marimekko makes each region as wide as its share of the market, and each supplier as tall as its share of the region. The area of a cell is its share of the whole. Both axes are in percent: x of the market, y of the region. A second x axis with text, from and to names the columns over them, each over its own middle however narrow it is.

What the report is made of

The composer reads the JSON below and puts into the page the core and only the blocks its chart uses: 10 of the 59, 73.0 KB of code, minified, which is 34% of the 215.9 KB that the core and every block weigh together. The report file is 80.0 KB: that code, the data, the styles and the page around them.

BlockWhat it doesShare of the codeKB
core.composed-plain
A report with plain data: no checks, no decoder. Most reports.
A report with plain data: no checks, no decoder. Most reports. 29.5
lib.pointer
Where the pointer is on the chart, and following a mouse or a finger once a frame. Shared by tooltip, crosshair, zoom and brush.
Where the pointer is on the chart, and following a mouse or a finger once a frame. Shared by tooltip, crosshair, zoom and brush. 1.7
lib.ticks
Round steps and ticks (1, 2 or 5 × 10ⁿ). Shared by the number scales and the histogram bins.
Round steps and ticks (1, 2 or 5 × 10ⁿ). Shared by the number scales and the histogram bins. 0.7
scale.color
A color per category, from the theme palette.
A color per category, from the theme palette. 0.8
scale.linear
Numbers to positions, with round ticks.
Numbers to positions, with round ticks. 1.6
transform.marimekko
Columns as wide as their share, cells as tall as theirs.
Columns as wide as their share, cells as tall as theirs. 2.0
mark.rect
Rectangles: bars, grouped bars, ranges, heatmap cells; the hexagons of a hexbin.
Rectangles: bars, grouped bars, ranges, heatmap cells; the hexagons of a hexbin. 4.5
guide.axis
Axes: formatted labels, a title, long categories wrapped.
Axes: formatted labels, a title, long categories wrapped. 11.7
guide.legend
Legends: categories, a color bar, bubble sizes.
Legends: categories, a color bar, bubble sizes. 6.0
interaction.tooltip
The values under the pointer.
The values under the pointer. 10.7
renderer.svg
Draws into SVG: sharp, selectable, prints well. The default.
Draws into SVG: sharp, selectable, prints well. The default. 3.9
TotalThe core 29.5 and 10 blocks 43.573.0

The JSON

This is the whole input. data holds the datasets, each chart is a spec that names one. In a checkout of the repository: node scripts/compose.js skills/blockcharts/recipes/marimekko.json report.html. Saved as page.json, it composes the same with the skill's own runtime/compose.js.

marimekko.json

{
  "title": "Marimekko",
  "data": {
    "market": [
      { "region": "Asia", "supplier": "Refiner A", "sales": 420 },
      { "region": "Asia", "supplier": "Refiner B", "sales": 310 },
      { "region": "Asia", "supplier": "Others", "sales": 270 },
      { "region": "Europe", "supplier": "Refiner A", "sales": 150 },
      { "region": "Europe", "supplier": "Refiner B", "sales": 240 },
      { "region": "Europe", "supplier": "Others", "sales": 110 },
      { "region": "Americas", "supplier": "Refiner A", "sales": 90 },
      { "region": "Americas", "supplier": "Refiner B", "sales": 160 },
      { "region": "Americas", "supplier": "Others", "sales": 250 },
      { "region": "Africa", "supplier": "Refiner A", "sales": 30 },
      { "region": "Africa", "supplier": "Refiner B", "sales": 20 },
      { "region": "Africa", "supplier": "Others", "sales": 100 }
    ]
  },
  "charts": [
    {
      "title": "Who sells how much, and where",
      "note": "Asia is nearly half the market, and Refiner A leads there; Refiner B leads in Europe, and smaller suppliers hold half of the Americas and two thirds of Africa.",
      "how": "transform.marimekko makes each region as wide as its share of the market, and each supplier as tall as its share of the region. The area of a cell is its share of the whole. Both axes are in percent: x of the market, y of the region. A second x axis with `text`, `from` and `to` names the columns over them, each over its own middle however narrow it is.",
      "spec": {
        "data": "market",
        "size": [720, 380],
        "padding": { "top": 8, "right": 8, "bottom": 8, "left": 8 },
        "transforms": [{ "type": "marimekko", "field": "sales", "category": "region" }],
        "scales": {
          "x": { "type": "linear", "domain": [0, 1], "nice": false },
          "y": { "type": "linear", "domain": [0, 1], "nice": false },
          "color": { "type": "color" }
        },
        "guides": [
          { "type": "axis", "scale": "x", "position": "top", "text": "label", "from": "x0", "to": "x1", "line": "off" },
          { "type": "axis", "scale": "x", "format": "percent" },
          { "type": "axis", "scale": "y", "format": "percent" },
          { "type": "legend", "scale": "color", "position": "bottom" }
        ],
        "marks": [{ "type": "rect", "x": "x0", "x2": "x1", "y": "y1", "y2": "y0", "color": "supplier" }],
        "interaction": [
          {
            "type": "tooltip",
            "heading": "region",
            "fields": ["supplier", "sales", "share"],
            "labels": { "supplier": "Supplier", "sales": "Sales", "share": "Share of the region" },
            "formats": { "share": "percent" }
          }
        ]
      }
    }
  ]
}

The report the composer makes from it is one standalone file (80.0 KB): open it from disk, mail it, print it.

In a page of your own

The charts above use the full kit (81.8 KB gzipped), the smallest one that has the blocks this example needs: lib.pointer, lib.ticks, scale.color, scale.linear, transform.marimekko, mark.rect, guide.axis, guide.legend, interaction.tooltip, renderer.svg. The HTML below loads it from the jsDelivr CDN, pinned to version 0.0.5; to serve it from your own site, put its file there (the files of a release) and change the address.

HTML

<script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.5/release/kits/full.js"></script>

<script type="application/json" id="bc-data">
{"market":[{"region":"Asia","supplier":"Refiner A","sales":420},{"region":"Asia","supplier":"Refiner B","sales":310},{"region":"Asia","supplier":"Others","sales":270},{"region":"Europe","supplier":"Refiner A","sales":150},{"region":"Europe","supplier":"Refiner B","sales":240},{"region":"Europe","supplier":"Others","sales":110},{"region":"Americas","supplier":"Refiner A","sales":90},{"region":"Americas","supplier":"Refiner B","sales":160},{"region":"Americas","supplier":"Others","sales":250},{"region":"Africa","supplier":"Refiner A","sales":30},{"region":"Africa","supplier":"Refiner B","sales":20},{"region":"Africa","supplier":"Others","sales":100}]}
</script>

<script type="application/json" data-bc-chart>
{
  "data": "market",
  "size": [
    720,
    380
  ],
  "padding": {
    "top": 8,
    "right": 8,
    "bottom": 8,
    "left": 8
  },
  "transforms": [
    {
      "type": "marimekko",
      "field": "sales",
      "category": "region"
    }
  ],
  "scales": {
    "x": {
      "type": "linear",
      "domain": [
        0,
        1
      ],
      "nice": false
    },
    "y": {
      "type": "linear",
      "domain": [
        0,
        1
      ],
      "nice": false
    },
    "color": {
      "type": "color"
    }
  },
  "guides": [
    {
      "type": "axis",
      "scale": "x",
      "position": "top",
      "text": "label",
      "from": "x0",
      "to": "x1",
      "line": "off"
    },
    {
      "type": "axis",
      "scale": "x",
      "format": "percent"
    },
    {
      "type": "axis",
      "scale": "y",
      "format": "percent"
    },
    {
      "type": "legend",
      "scale": "color",
      "position": "bottom"
    }
  ],
  "marks": [
    {
      "type": "rect",
      "x": "x0",
      "x2": "x1",
      "y": "y1",
      "y2": "y0",
      "color": "supplier"
    }
  ],
  "interaction": [
    {
      "type": "tooltip",
      "heading": "region",
      "fields": [
        "supplier",
        "sales",
        "share"
      ],
      "labels": {
        "supplier": "Supplier",
        "sales": "Sales",
        "share": "Share of the region"
      },
      "formats": {
        "share": "percent"
      }
    }
  ],
  "alt": "Who sells how much, and where"
}
</script>