Co-AuthorCitationNetwork

by gauravameta

CSS

.node {
  stroke: #fff;
  stroke-width: .5px;
}

.link {
  stroke: #999;
  stroke-opacity: 1;
}

JavaScript

var width = 600,
    height = 400;
		minyr = 2003;
    ybound=height*0.05;
var color = d3.scale.category20();

var force = d3.layout.force()
    //.gravity(0.1)
    .charge(function(d){return -75;})
    .linkDistance(function(d) {return 1.1*width*(1/(2017-minyr))*Math.sqrt((d.source.yr-d.target.yr)*(d.source.yr-d.target.yr));})
    .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.1')
    .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 minRadius+(Math.sqrt(d.size-15))})
      .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)
                      ...