Skip to content Skip to sidebar Skip to footer

D3js - Force Directed Graph - Advanced Highlighting Of Neigbour Nodes And Links, Is It Possible?

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, I'm litt

Solution 1:

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.

functionfade(opacity,color) {
    returnfunction(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.

Post a Comment for "D3js - Force Directed Graph - Advanced Highlighting Of Neigbour Nodes And Links, Is It Possible?"