-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook_circle.html
More file actions
54 lines (44 loc) · 1.25 KB
/
book_circle.html
File metadata and controls
54 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<meta charset="UTF-8" />
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = window.innerWidth,
height = window.innerHeight;
var nodes = d3.range(8).map(function() { return { radius: 10 } }),
root = nodes[0];
root.radius = 0;
root.fixed = true;
root.px = width / 2.0;
root.py = height / 2.0;
// use this as the equation for charge
// until we come up with something better
// seems to work ok up until nodes.length == 12
var charge = 1000 * nodes.length - 18500;
var force = d3.layout.force()
.gravity(0.15)
.charge(function(d, i) { return i ? -2055 : charge; })
.nodes(nodes)
.size([width, height]);
force.start();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.selectAll("circle")
.data(nodes.slice(1))
.enter().append("circle")
.attr("r", function(d) { return d.radius; })
.style("fill", "white")
.style("stroke", "lime")
.style("stroke-width", "3")
.call(force.drag);
force.on("tick", function(e) {
var q = d3.geom.quadtree(nodes),
i = 0,
n = nodes.length;
svg.selectAll("circle")
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
});
</script>
</body>