I\'ve managed to get highlight working on my force directed graph, with help of this tutorial from Mike Bostock. Now for further procedure in my idea and needs of my graph,
To identify your "special" nodes, you could add another attribute to the data that identifies them. Then you can check this in your highlighting function and get second-degree neighbours if necessary. The code would look something like this.
function fade(opacity,color) {
return function(d) {
var connected = [d];
if(d.isAuxiliary) {
node.each(function(o) { if(isConnected(d, o)) { connected.push(o); } });
}
node.style("stroke-opacity", function(o) {
thisOpacity = opacity;
connected.forEach(function(e) {
if(isConnected(e, o)) { thisOpacity = 1; }
});
this.setAttribute('fill-opacity', thisOpacity);
return thisOpacity;
});
// similar for links
}
}
You can adapt this code to do an arbitrary level of neighbours.