title: Hide all but selected connected nodes in D3 (v4) force graph
body: <p>I have created a dynamically built force graph in D3. When I click on one of the links I want to only show that and all the connected links/nodes.</p>
  
  <p>This Plunkr is a simplified version of what I have: <a href="http://plnkr.co/edit/TiKKmvydqXNipe103juL?p=preview" rel="nofollow noreferrer">http://plnkr.co/edit/TiKKmvydqXNipe103juL?p=preview</a> (EDIT: I have updated this and is now a complete solution).</p>
  
  <p>As you can see there are 3 separate 'groups' of connected nodes, in my real data set there are several hundred nodes and I want to be able to isolate an individual 'group' and only show that when the link which is part of that group is clicked on (it can't be the node that is clicked on as this shows a pop-up with more info).</p>
  
  <p>I have been able to colour/hide connected links by pre-processing my data and using a rather complicated and long winded algorithm to determine whether the links are in the same connected group.</p>
  
  <p>I have also been able to change the node that is clicked on or all the nodes/links by changing the dragstart function, this feels like I am getting close, but I don't think it recognises any link relationships.</p>
  
  <pre><code>function dragstarted(d) {
    if (!d3.event.active) simulation.alphaTarget(0.3).restart();
      // Changes all nodes/links
      d3.select("circle").classed("others",true).style("display","none"); 
      // Trying different ways to hide only 'other' nodes
      d3.selectAll("circle").classed("others",true).style("display","none"); 
      d3.selectAll("line").classed("others",true).style("display","none");
  
      d.fx = d.x;
      d.fy = d.y;
  }
  </code></pre>
  
  <p>(I am aware of this question/answer <a href="https://stackoverflow.com/questions/18020985/how-to-highlightchange-color-of-all-connectedneighbours-nodes-and-links-in-a">how to highlight(change color) of all connected(neighbours) nodes and links in a d3 force directed graph</a> but I don't think it really helps).</p>
  
  <p>Any help would be appreciated.</p>