score:1

Accepted answer

Just create a reference to the variables you care about at a scope outside your .json callback. In this case it's probably link and node:

var link, node;
d3.json('map2.json', function(error, graph) { 

   ...

   link = container.append("g")
    .attr("class", "links")

   ...

   node = container.append("g")
    .attr("class", "nodes")

   ...

});

You can then use these is your change event of your radio buttons:

d3.selectAll("input[name=filter]").on("change", function(d){

  // value of selected radio
  var value = this.value;
  // everybody
  node.style("opacity", 1);
  // those that aren't dim
  if (value !== "all"){
    value = +this.value;
    node.filter(function(d){
      return d.rating != value;
    })
    .style("opacity", "0.5");
  }

});

Running code here.


Related Query