var width = 960,
    height = 500;

var color = d3.scale.category20();

var force = d3.layout.force()
    .charge(-120)
    .linkDistance(200)
    .size([width, height]);

var forceSvg = d3.select("div#chord_chart").append("svg")
    .attr("width", width)
    .attr("height", height);

d3.json("newsGraph.json", function(error, graph) {
  testGraph = JSON.parse(JSON.stringify(graph))

  selectedList = [0,10,2,3,4,50,60,75,18];
  selectedData1 = $.map(graph.nodes, function(element){
      return ($.inArray(element.id,selectedList)>-1?element:null);
    });
  selectedData2 = $.map(graph.links, function(element){
      return ($.inArray(element.source,selectedList)>-1?element:null);
    });

  selectedData3 = $.map(selectedData2, function(element){
      return ($.inArray(element.target,selectedList)>-1?element:null);
    });
  new_graph = {};
  new_graph['nodes'] = selectedData1;
  new_graph['links'] = selectedData3;
  console.log(new_graph);

  drawGraph(new_graph);

  function drawGraph(graph){
    force
      .nodes(graph.nodes)
      .links(graph.links)
      .start();

  var graphMin = d3.min(graph.links, function(d){ return d.size; });
  var graphMax = d3.max(graph.links, function(d){ return d.size; });

  var fill = d3.scale.ordinal()
      .domain([graphMin, graphMax])
      .range(["#DB704D", "#D2D0C6", "#ECD08D", "#F8EDD3"]);

  var link = forceSvg.selectAll(".link")
      .data(graph.links)
    .enter().append("line")
      .attr("class", "link")
      .style('stroke-width', 1)
      .style('stroke', function(d){ return fill(d.value); })
      //.style("stroke-width", function(d) { return Math.sqrt(d.value); });

  var node = forceSvg.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; });
  }

  
  });
});
@@ -1076,24 +1076,26 @@
  .start();%0A%0A
+  
   var graphM
@@ -1151,16 +1151,18 @@
 ze; %7D);%0A
+  
   var gr
@@ -1219,24 +1219,26 @@
 .size; %7D);%0A%0A
+  
   var fill =
@@ -1257,16 +1257,18 @@
 dinal()%0A
+  
       .d
@@ -1301,16 +1301,18 @@
 )%0A      
+  
 .range(%5B
@@ -1354,24 +1354,26 @@
 F8EDD3%22%5D);%0A%0A
+  
   var link =
@@ -1399,32 +1399,34 @@
 (%22.link%22)%0A      
+  
 .data(graph.link
@@ -1428,24 +1428,26 @@
 .links)%0A    
+ 
+ 
 .enter().app
@@ -1456,32 +1456,34 @@
 d(%22line%22)%0A      
+  
 .attr(%22class%22, %22
@@ -1487,32 +1487,34 @@
 , %22link%22)%0A      
+ 
+ 
 .style('stroke-w
@@ -1523,16 +1523,18 @@
 th', 1)%0A
+  
       .s
@@ -1592,16 +1592,18 @@
 )%0A      
+ 
+ 
 //.style
@@ -1665,16 +1665,18 @@
 ); %7D);%0A%0A
+  
   var no
@@ -1710,24 +1710,26 @@
 ode%22)%0A      
+  
 .data(graph.
@@ -1731,24 +1731,26 @@
 raph.nodes)%0A
+  
     .enter()
@@ -1769,24 +1769,26 @@
 cle%22)%0A      
+  
 .attr(%22class
@@ -1800,24 +1800,26 @@
 ode%22)%0A      
+  
 .attr(%22r%22, 5
@@ -1820,16 +1820,18 @@
 %22r%22, 5)%0A
+  
       .s
@@ -1879,24 +1879,26 @@
 .group); %7D)%0A
+  
       .call(
@@ -1911,16 +1911,18 @@
 drag);%0A%0A
+  
   node.a
@@ -1932,24 +1932,26 @@
 nd(%22title%22)%0A
+  
       .text(
@@ -1984,16 +1984,18 @@
 e; %7D);%0A%0A
+  
   force.
@@ -2022,16 +2022,18 @@
 ) %7B%0A    
+ 
+ 
 link.att
@@ -2076,32 +2076,34 @@
 e.x; %7D)%0A        
+  
 .attr(%22y1%22, func
@@ -2138,24 +2138,26 @@
  %7D)%0A        
+ 
+ 
 .attr(%22x2%22, 
@@ -2188,24 +2188,26 @@
 arget.x; %7D)%0A
+  
         .att
@@ -2252,24 +2252,26 @@
 y; %7D);%0A%0A    
+  
 node.attr(%22c
@@ -2299,24 +2299,26 @@
 urn d.x; %7D)%0A
+  
         .att
@@ -2355,16 +2355,18 @@
 .y; %7D);%0A
+  
   %7D%0A%0A  %0A
@@ -2368,14 +2368,13 @@
 %0A%0A  %0A  %7D
-)
 ;%0A%7D);

update data