D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
mforando
Full window
Github gist
bbBox vs. getBoundingClientRect
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <div id="headerDiv"> <h1>Mouse Coords: <span id="mouse" style="color:red"></span></h1> <h1>bbBox Coords: <span id="bbBox" style="color:red"></span></h1> <h1>getBoundingClientRect Coords: <span id="clientRect" style="color:red"></span></h1> </div> <body> <script> d3.select("body").on("mousemove",function(){ console.log(d3.event) d3.select("#mouse").text("x: " + d3.event.clientX + ", y:" + d3.event.clientY) }) var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500) .style("border","1px solid black") var circle = svg.append("circle") .attr("cy", 200) .attr("cx", 120) .attr("r",10) .attr("font-size", 36) .attr("font-family", "monospace") d3.select("#bbBox").text("x: " + circle.node().getBBox().x + ", y:" + circle.node().getBBox().y) d3.select("#clientRect").text("x: " + circle.node().getBoundingClientRect().x + ", y:" + circle.node().getBoundingClientRect().y) console.log(circle.node().getBBox()) </script> </body>
https://d3js.org/d3.v4.min.js