viewof BBoxTest = {
const grid = Grid({divisions: 6, aspect: {tall: 2, wide: 16}, opacity: .2}).sketch();
const {pad, plot, q, M} = grid;
const ƒ = (n) => n.toFixed(1);
const {fontFamily, fontWeight, fontSize} = font;
const g = pad
.append("g")
.style("font-family", fontFamily)
.style("font-weight", fontWeight)
.style("font-size", fontSize)
;
const t = g
.append("g")
.attr("transform", `translate(${M(3)}, ${M(1)})`)
;
t
.append("text")
.text(text)
;
const {x, y, width, height} = getBBox(text, font);
t
.append("rect")
.attr("stroke", "red")
.attr("fill", "transparent")
.attr("width", width)
.attr("height", height)
.attr("x", x)
.attr("y", y)
;
const metrics = [
{label: "x", value: x},
{label: "y", value: y},
{label: "width", value: width},
{label: "height", value: height},
{label: "wide", value: width/q()},
{label: "tall", value: height/q()},
];
const texts = g
.append("g")
.attr("transform", `translate(0, ${q(3)})`)
.attr("font-family", fontFamily)
.attr("font-weight", "normal")
.attr("font-size", "18px")
.attr("fill", "grey")
.attr("text-anchor", "end")
.selectAll("text")
.data(metrics)
;
texts
.join("text")
.text(d => `${d.label}:`)
.attr("dx", q(7))
.attr("dy", (_, i) => q(2 * i - 1))
;
texts
.join("text")
.text(d => `${ƒ(d.value)}`)
.attr("dx", q(13))
.attr("dy", (_, i) => q(2 * i - 1))
;
Object.defineProperty(grid.frame.node(), "value", {get: () => ({x, y, width, height})});
return grid.frame.node();
}