index.html
<!DOCTYPE html>
<meta charset="utf-8">
<title>Network of Sponsors of bills.</title>
<style>
.node {
stroke: #fff;
stroke-width: 1.5px;
}
.link {
stroke: #999;
stroke-opacity: .6;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var width = 600,
height = 400;
var color = Array(
'#000000',
'#FF9933',
'#FF0000',
'#000099',
'#0099FF',
'#CC00CC',
'#888888'
);
var force = d3.layout.force()
.charge(-50)
.size([width, height]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("data5.json", function(error, graph) {
force
.nodes(graph.nodes)
.links(graph.links)
.linkDistance(function (d) {return 15*(Math.log(36+2)-Math.log(d.value))})
.start();
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("line")
.attr("class", "link")
.style("stroke-width", function(d) { return 0.5*Math.sqrt(Math.max(0,d.value-2)) })
.style("display", function(d) { if(d.value<2) return "none"; else return "inline";});
var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("circle")
.attr("class", "node")
.attr("r", 5)
.style("fill", function(d) {return color[d.group]})
.call(force.drag);
node.append("title")
.text(function(d) { return d.name; });
force.on("tick", function() {
link.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
node.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
});
});
</script>
<div id="chart"></div>
<div id="description" style="color:#bbbbbb">
Network of Sponsors of bills. Czech parliament (lower chamber) 2010-2013. Prepared with Kamil Gregor.<br/>
Notes: The links with weight 1 were omitted (more than 7000) and left only with weight 2 and more (more than 6000). MPs with no links are omitted. Links with weight 2 are not shown for clarity reasons.
</div>
</body>