forked from mikedewar/d3talk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
egovis.html
73 lines (62 loc) · 2.63 KB
/
egovis.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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css">
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.js"></script>
<title>egovis</title>
</head>
<body>
<div id="body">
<div id="graph">
</div>
<script>
var w = 900,
h = 650,
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(-200)
.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', 100)
.attr('height', 100)
.attr('xlink:href', function(d){return d.photo_url})
/*
node.append("svg:text")
.text(function(d){return d.name})
*/
force.on("tick", function() {
node.attr(
"transform",
function(d) { return "translate(" + d.x + "," + d.y + ")"; }
);
});
d3.select("#graph").on("click", function() {
console.log('click')
json.nodes.forEach(function(o, i) {
o.x += (Math.random() - .5) * 300;
o.y += (Math.random() - .5) * 300;
});
force.resume();
});
})
</script>
</div>
</body>
</html>