{
const hierarchy = createHierarchy(data);
const width = 800;
const height = 800;
const pack = d3.pack().size([width, height]).padding(3);
const root = pack(hierarchy);
const circles = root.descendants().map((d) => ({
x: d.x,
y: d.y,
r: d.r,
depth: d.depth,
data: d.data
}));
return Plot.plot({
width,
height,
margin: 1,
style: {
fontFamily: "sans-serif",
fontSize: 10
},
marks: [
Plot.dot(circles, {
x: "x",
y: "y",
r: "r",
fill: (d) => d3.schemeCategory10[d.depth],
fillOpacity: 0.7,
stroke: "#ccc",
title: (d) =>
`${d.data.domain}\nSOC: ${d.data.soc}\nJobs: ${d.data.jobs}`
}),
Plot.text(circles, {
x: "x",
y: "y",
text: (d) => d.data.domain,
fontSize: (d) => Math.max(8, Math.min(2 * d.r, 24)),
clip: true,
overflow: "hidden",
width: (d) => d.r * 2,
height: (d) => d.r * 2
})
]
});
}