Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
91 lines (71 sloc) 3.3 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.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">
var force = d3.layout.force()
.charge(-50).nodes(json.nodes).size([750, 300]).start();
var node = vis.selectAll("g").data(json.nodes).enter()
.append("g")
.attr("x", function(d) { return d.x; })
.attr("y", function(d) { return d.y; })
.call(force.drag);
</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>