Skip to content

Instantly share code, notes, and snippets.

Forked from mbostock/.block
Last active February 1, 2023 08:35
  • Star 1 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mbostock/3680999 to your computer and use it in GitHub Desktop.
SVG Geometric Zooming
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<svg width="960" height="500"></svg>
<script src=""></script>
var svg ="svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var randomX = d3.randomNormal(width / 2, 80),
randomY = d3.randomNormal(height / 2, 80),
data = d3.range(2000).map(function() { return [randomX(), randomY()]; });
var g = svg.append("g");
var circle = g.selectAll("circle")
.attr("r", 2.5)
.attr("transform", function(d) { return "translate(" + d + ")"; });
.attr("fill", "none")
.attr("pointer-events", "all")
.attr("width", width)
.attr("height", height)
.scaleExtent([1, 8])
.on("zoom", zoom));
function zoom() {
g.attr("transform", d3.event.transform);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment