Gallery / Relationships and patterns /
Product portfolio
Two numeric variables and a third as the size of each bubble.
75.6 KB of code · core 29.5 + 12 blocks 46.1
Where the revenue grows, and what it earns
Harbor grows fastest, 42%, but keeps the smallest margin, 8%; Beacon, the largest product, keeps the most, 51%.
How it is made: mark.point with a size channel on a scale.size: the area of each circle, not its radius, follows the value, so a product twice the revenue is a bubble twice the area. Big bubbles are drawn first, so small ones stay visible on top; an outline in the card color and some transparency separate the overlaps. The size key is a guide.legend on the size scale.
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: 12 of the 59, 75.6 KB of code, minified, which is 35% of the 215.9 KB that the core and every block weigh together. The report file is 83.1 KB: that code, the data, the styles and the page around them.
| Block | What it does | Share of the code | KB |
|---|---|---|---|
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 | |
scale.size Numbers to circle sizes, by area: bubble charts. | Numbers to circle sizes, by area: bubble charts. | 1.6 | |
mark.point Dots, bubbles and beeswarms. | Dots, bubbles and beeswarms. | 3.9 | |
guide.axis Axes: formatted labels, a title, long categories wrapped. | Axes: formatted labels, a title, long categories wrapped. | 11.7 | |
guide.grid Grid lines at the ticks. | Grid lines at the ticks. | 0.6 | |
guide.legend Legends: categories, a color bar, bubble sizes. | Legends: categories, a color bar, bubble sizes. | 6.0 | |
interaction.legend-filter Click a legend item to hide or show its series. | Click a legend item to hide or show its series. | 3.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 | |
| Total | The core 29.5 and 12 blocks 46.1 | 75.6 |
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/bubble.json report.html.
Saved as page.json, it composes the same with the skill's own runtime/compose.js.
bubble.json
{
"title": "Product portfolio",
"subtitle": "Growth against margin; the area of a bubble is the revenue",
"data": {
"products": [
{ "product": "Atlas", "segment": "Enterprise", "growth": 0.18, "margin": 0.42, "revenue": 48.2 },
{ "product": "Beacon", "segment": "Enterprise", "growth": 0.07, "margin": 0.51, "revenue": 71.5 },
{ "product": "Cobalt", "segment": "Enterprise", "growth": -0.03, "margin": 0.38, "revenue": 36.9 },
{ "product": "Delta", "segment": "SMB", "growth": 0.31, "margin": 0.22, "revenue": 12.4 },
{ "product": "Ember", "segment": "SMB", "growth": 0.24, "margin": 0.27, "revenue": 18.8 },
{ "product": "Flint", "segment": "SMB", "growth": 0.12, "margin": 0.19, "revenue": 9.6 },
{ "product": "Garnet", "segment": "SMB", "growth": -0.08, "margin": 0.15, "revenue": 6.1 },
{ "product": "Harbor", "segment": "Consumer", "growth": 0.42, "margin": 0.08, "revenue": 4.3 },
{ "product": "Iris", "segment": "Consumer", "growth": 0.15, "margin": 0.12, "revenue": 22.7 },
{ "product": "Juniper", "segment": "Consumer", "growth": 0.02, "margin": 0.17, "revenue": 29.4 },
{ "product": "Kestrel", "segment": "Consumer", "growth": 0.27, "margin": 0.31, "revenue": 15.2 }
]
},
"charts": [
{
"title": "Where the revenue grows, and what it earns",
"note": "Harbor grows fastest, 42%, but keeps the smallest margin, 8%; Beacon, the largest product, keeps the most, 51%.",
"how": "mark.point with a `size` channel on a scale.size: the area of each circle, not its radius, follows the value, so a product twice the revenue is a bubble twice the area. Big bubbles are drawn first, so small ones stay visible on top; an outline in the card color and some transparency separate the overlaps. The size key is a guide.legend on the size scale.",
"spec": {
"data": "products",
"size": [640, 420],
"scales": {
"x": { "type": "linear", "padding": 0.1 },
"y": { "type": "linear", "padding": 0.1, "zero": true },
"size": { "type": "size", "range": [3, 30] },
"color": { "type": "color" }
},
"guides": [
{ "type": "grid", "scale": "x" },
{ "type": "grid", "scale": "y" },
{ "type": "axis", "scale": "x", "format": "percent", "title": "Revenue growth, year on year" },
{ "type": "axis", "scale": "y", "format": "percent", "title": "Operating margin" },
{ "type": "legend", "scale": "color" },
{ "type": "legend", "scale": "size", "position": "bottom", "format": { "prefix": "$", "suffix": "M" } }
],
"marks": [
{ "type": "point", "x": "growth", "y": "margin", "size": "revenue", "color": "segment", "opacity": 0.75, "stroke": "var(--bc-tooltip-bg, #fff)" }
],
"interaction": [
{
"type": "tooltip",
"fields": ["product", "segment", "growth", "margin", "revenue"],
"formats": { "growth": "percent", "margin": "percent", "revenue": { "prefix": "$", "suffix": "M", "maximumFractionDigits": 1 } }
},
{ "type": "legend-filter" }
]
}
}
]
}
The report the composer makes from it is one standalone file (83.1 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, scale.size, mark.point, guide.axis, guide.grid, guide.legend, interaction.legend-filter, 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">
{"products":[{"product":"Atlas","segment":"Enterprise","growth":0.18,"margin":0.42,"revenue":48.2},{"product":"Beacon","segment":"Enterprise","growth":0.07,"margin":0.51,"revenue":71.5},{"product":"Cobalt","segment":"Enterprise","growth":-0.03,"margin":0.38,"revenue":36.9},{"product":"Delta","segment":"SMB","growth":0.31,"margin":0.22,"revenue":12.4},{"product":"Ember","segment":"SMB","growth":0.24,"margin":0.27,"revenue":18.8},{"product":"Flint","segment":"SMB","growth":0.12,"margin":0.19,"revenue":9.6},{"product":"Garnet","segment":"SMB","growth":-0.08,"margin":0.15,"revenue":6.1},{"product":"Harbor","segment":"Consumer","growth":0.42,"margin":0.08,"revenue":4.3},{"product":"Iris","segment":"Consumer","growth":0.15,"margin":0.12,"revenue":22.7},{"product":"Juniper","segment":"Consumer","growth":0.02,"margin":0.17,"revenue":29.4},{"product":"Kestrel","segment":"Consumer","growth":0.27,"margin":0.31,"revenue":15.2}]}
</script>
<script type="application/json" data-bc-chart>
{
"data": "products",
"size": [
640,
420
],
"scales": {
"x": {
"type": "linear",
"padding": 0.1
},
"y": {
"type": "linear",
"padding": 0.1,
"zero": true
},
"size": {
"type": "size",
"range": [
3,
30
]
},
"color": {
"type": "color"
}
},
"guides": [
{
"type": "grid",
"scale": "x"
},
{
"type": "grid",
"scale": "y"
},
{
"type": "axis",
"scale": "x",
"format": "percent",
"title": "Revenue growth, year on year"
},
{
"type": "axis",
"scale": "y",
"format": "percent",
"title": "Operating margin"
},
{
"type": "legend",
"scale": "color"
},
{
"type": "legend",
"scale": "size",
"position": "bottom",
"format": {
"prefix": "$",
"suffix": "M"
}
}
],
"marks": [
{
"type": "point",
"x": "growth",
"y": "margin",
"size": "revenue",
"color": "segment",
"opacity": 0.75,
"stroke": "var(--bc-tooltip-bg, #fff)"
}
],
"interaction": [
{
"type": "tooltip",
"fields": [
"product",
"segment",
"growth",
"margin",
"revenue"
],
"formats": {
"growth": "percent",
"margin": "percent",
"revenue": {
"prefix": "$",
"suffix": "M",
"maximumFractionDigits": 1
}
}
},
{
"type": "legend-filter"
}
],
"alt": "Where the revenue grows, and what it earns"
}
</script>