Co-AuthorCitationNetwork
by gauravameta
CSS
.node {
stroke: #fff;
stroke-width: .5px;
}
.link {
stroke: #999;
stroke-opacity: .6;
}
JavaScript
var width = 600,
height = 400;
var color = d3.scale.category20();
var force = d3.layout.force()
.charge(function(d){return -10*d.weight})
.linkDistance(function(d) {return 10*d.weight})
.size([width, height]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
function update (graph) {
force
.nodes(graph.nodes)
.links(graph.links)
.start();
var link = svg.selectAll(".link")
.data(graph.links)
//.filter(function(d){if(d.weight>3) return d;
//else return "";}))
.enter().append("line")
.attr("class", "link")
.attr("stroke-width", function(d) {return (d.weight*0.25);});
var node = svg.selectAll(".node")
.data(graph.nodes)
//.filter(function(d){
//d.weight = link.filter(function(l) {
// return l.source.index == d.index || l.target.index == d.index
//}).size();
//if(d.weight > 9) return d;
//else return "";}))
.enter().append("circle")
.attr("class", "node")
.attr("r", function(d){
var minRadius = 2;
return minRadius + (d.weight/10)})
.style("fill", function(d){var color1; if (d.weight<10) color1="blue"; else color1="red"; return color1;}) //"#708284"})
// .style("stroke", function(d) {
// return d3.rgb(fill(d.weight)).darker();})
.call(force.drag).on("mouseover", fade(.1)).on("mouseout", fade(1));
var texts = svg.selectAll(".text")
.data(graph.nodes)
.enter()
.append("text")
.attr("x", 10)
.attr("y", 10)
.attr("fill","black")
.attr("font-family","sans-serif")
.attr("font-size","15px")
.text(function (d) { if(d.weight<10) return "";
else return d.id;});
force.on("tick",...