getBoundingClientRect
✓ Published0🌍 Public
PPhilippe Rivière
Last edited Nov 4, 2016
Created on Nov 3, 2016
This example demonstrates how to use the browser's `getBoundingClientRect` method to retrieve the exact screen-space bounding box of an SVG text element, and then draws a semi-transparent rectangle over that area. The text is positioned using a grouped `<g>` element with translation and scaling transforms, along with `dx` and `dy` offsets. The code uses D3 v3 to select and append SVG elements, computing the rectangle’s coordinates by subtracting the SVG’s own client rect from the text’s client rect. The final rectangle is styled with a gray fill and stroke, visually highlighting the text’s bounds.
AI-generated descriptionforked from <a href='http://bl.ocks.org/mbostock/'>mbostock</a>'s block: <a href='http://bl.ocks.org/mbostock/1160929'>getBBox</a>
gpl-3.0 Licensed