Co-AuthorCitationNetwork
by gauravameta
CSS
.node {
stroke: #fff;
stroke-width: .5px;
}
.link {
stroke: #999;
stroke-opacity: 1;
}
JavaScript
var width = 600,
height = 400;
var color = d3.scale.category20();
var force = d3.layout.force()
.gravity(0.2)
.charge(function(d){return -75;})
.linkDistance(function(d) {return Math.sqrt(d.source.size+d.target.size);})
.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 path = svg.selectAll("path")
.data(force.links())
.enter().append("path")
.attr('fill','none')
.attr('stroke','#708284')
.style('opacity', '0.3')
.attr("class", "path");
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 (Math.sqrt(d.size));})
.style("fill", function(d){return d.color})
// .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("opacity","0.5")
...