Skip to content

Instantly share code, notes, and snippets.

@mbostock mbostock/.block
Last active Aug 30, 2017

What would you like to do?
SVG Semantic 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 circle = svg.selectAll("circle")
.attr("r", 2.5)
.attr("transform", transform(d3.zoomIdentity));
.attr("fill", "none")
.attr("pointer-events", "all")
.attr("width", width)
.attr("height", height)
.scaleExtent([1, 8])
.on("zoom", zoom));
function zoom() {
circle.attr("transform", transform(d3.event.transform));
function transform(t) {
return function(d) {
return "translate(" + t.apply(d) + ")";

This comment has been minimized.

Copy link

devwolf75 commented Jun 29, 2017

Are there any relevant changes one needs to do in order to migrate this code to v4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.