Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3js How to gather nodes by cluster un force layout?

I have network and each node has a property group obtained by a clustering method. I would like to know what is the best method to render a network with the force layout where nodes belonging to the same group are gathered in space?

One way, but i don't know how to implement it, would be to add a attractive force between nodes of the same group (little compared to the repulsive force applied to all nodes).

like image 541
Mermoz Avatar asked Dec 14 '25 17:12

Mermoz


1 Answers

one possibility is to devide space in nb_group directions and push nodes in the direction allocated to their group:

   var angle = 2*Math.PI/nb_group;
   var intensity = 500;

    var updateNode = function() {
    this.attr("transform", function(d) {
        var xm = d.x + intensity*Math.cos(angle*d.group);
        var ym = d.y + intensity*Math.sin(angle*d.group);
        return "translate(" + xm + "," + ym + ")";
    });
    }

my intensity is hugh because I have charge of 1000 enter image description here

like image 118
Mermoz Avatar answered Dec 18 '25 02:12

Mermoz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!