Plot.plot({
marks: [
Plot.rect(leaves, {
x1: "x0",
x2: "x1",
y1: "y0",
y2: "y1",
fill: (d) => d.parent.data.name,
title: (d) => `${d.parent.data.name}: ${d.data.name}`
}),
Plot.text(leaves, {
x: "x0",
y: "y1",
dx: 10,
dy: 10,
text: (d) => {
const v = d.value?.toFixed(1);
const width = (v.length - 1) * 8 + 5;
const height = 15;
return d.x1 - d.x0 > width && d.y1 - d.y0 > height ? v : "";
},
fill: "#fff"
})
],
x: { axis: null },
y: { axis: null },
width: width,
height: height,
marginTop: 20
})