forked from mikedewar/d3talk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout_1.html
91 lines (70 loc) · 3.12 KB
/
layout_1.html
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.js"></script>
<link type="text/css" rel="stylesheet" href="prettify.css">
<script type="text/javascript" src="prettify.js"></script>
<link type="text/css" rel="stylesheet" href="style.css">
<title>egovis</title>
</head>
<body onload="prettyPrint()">
<div id="body">
<div style="height:300px; width:750px; margin-left:auto; margin-right:auto; margin-top:1em" id="graph">
</div>
<pre style="font-size:0.7em" class="prettyprint">
node.append('svg:image')
.attr('x', 0).attr('y', 0)
.attr('width', 40).attr('height', 40)
.attr('xlink:href', function(d){return d.photo_url})
force.on("tick", function() {
node.attr("transform",
function(d){return "translate(" + d.x + "," + d.y + ")";});
});
</pre>
<script>
var w = 750,
h = 300,
fill = d3.scale.category20();
vis = d3.select("#graph")
.append("svg")
d3.json(
'http://localhost:8000/data/hackr_event.json',
function(json){
var force = d3.layout.force()
.charge(-50)
.nodes(json.nodes)
.size([w, h])
.start();
var node = vis.selectAll("g")
.data(json.nodes)
.enter().append("g")
.attr("id", function(d){ return d.name;})
.attr("class", "node")
.attr("x", function(d) { return d.x; })
.attr("y", function(d) { return d.y; })
.call(force.drag);
node.append('svg:image')
.attr('x', 0)
.attr('y', 0)
.attr('width', 40)
.attr('height', 40)
.attr('xlink:href', function(d){return d.photo_url})
force.on("tick", function() {
node.attr(
"transform",
function(d) { return "translate(" + d.x + "," + d.y + ")"; }
);
});
d3.select("#chart").on("click", function() {
console.log('click')
json.nodes.forEach(function(o, i) {
o.x += (Math.random() - .5) * 50;
o.y += (Math.random() - .5) * 50;
});
force.resume();
});
})
</script>
</div>
</body>
</html>