Published
Edited
Feb 21, 2018
Insert cell
Insert cell
bboxMonkeyPatch = {
const __getBBox = window.SVGGraphicsElement.prototype.getBBox;
window.SVGGraphicsElement.prototype.getBBox = function getBBox () {
try {
return __getBBox.call(this);
} catch (e) {
return new window.DOMRect();
}
}
return md`So ... we monkey-patch it :)`;
}
Insert cell
function myFunction(selection) {
var bbox = selection.node().getBBox(); // This line errors on Firefox.
selection.text(`${bbox} width: ${bbox.width}, height: ${bbox.height}`);
}
Insert cell
svg = {
var svg = d3.select(DOM.svg(width, height));
svg.append("text")
.attr("y", height / 2)
.call(myFunction);

return svg.node();
}
Insert cell
Insert cell
d3.select(svg).select("text").node().getBBox().width
Insert cell
d3.select(svg).select("text").node().getBBox().height
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more