Circle Packing Example
A circle packing layout uses containment to convey hierarchical relationships. The layout is computed using Vega’s pack transform. This example shows the software class hierarchy of the Flare visualization toolkit; node areas are proportional to the file size in bytes of each source code file.
Vega JSON Specification <>
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "An example of a circle packing layout for hierarchical data.",
"width": 600,
"height": 600,
"padding": 5,
"autosize": "none",
"data": [
{
"name": "tree",
"url": "data/flare.json",
"transform": [
{
"type": "stratify",
"key": "id",
"parentKey": "parent"
},
{
"type": "pack",
"field": "size",
"sort": {"field": "value"},
"size": [{"signal": "width"}, {"signal": "height"}]
}
]
}
],
"scales": [
{
"name": "color",
"type": "ordinal",
"domain": {"data": "tree", "field": "depth"},
"range": {"scheme": "category20"}
}
],
"marks": [
{
"type": "symbol",
"from": {"data": "tree"},
"encode": {
"enter": {
"shape": {"value": "circle"},
"fill": {"scale": "color", "field": "depth"},
"tooltip": {"signal": "datum.name + (datum.size ? ', ' + datum.size + ' bytes' : '')"}
},
"update": {
"x": {"field": "x"},
"y": {"field": "y"},
"size": {"signal": "4 * datum.r * datum.r"},
"stroke": {"value": "white"},
"strokeWidth": {"value": 0.5}
},
"hover": {
"stroke": {"value": "red"},
"strokeWidth": {"value": 2}
}
}
}
]
}