Skip to content

Instantly share code, notes, and snippets.

Last active February 9, 2016 01:01
  • Star 3 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mbostock/1557377 to your computer and use it in GitHub Desktop.
Drag Multiples
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
svg {
float: left;
border-bottom: solid 1px #ccc;
border-right: solid 1px #ccc;
margin-right: -1px;
margin-bottom: -1px;
<script src="//"></script>
var width = 240,
height = 125,
radius = 20;
var drag = d3.behavior.drag()
.origin(function(d) { return d; })
.on("drag", dragmove);
var svg ="body").append("div").selectAll("svg")
.data(d3.range(16).map(function() { return {x: width / 2, y: height / 2}; }))
.attr("width", width)
.attr("height", height);
.attr("r", radius)
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
function dragmove(d) {
.attr("cx", d.x = Math.max(radius, Math.min(width - radius, d3.event.x)))
.attr("cy", d.y = Math.max(radius, Math.min(height - radius, d3.event.y)));
Copy link

adius commented Jan 21, 2013

Why does the document have no header and no closing body tag? ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment