D3.js force directed graph, reduce edge crossings by making edges repel each other

后端 未结 4 1461
你的背包
你的背包 2020-12-25 09:33

So i have a page already which draws a force directed graph, like the one shown here.

And that works fine. I\'m using the JS from here, with a few tweaks to spread o

4条回答
  •  醉梦人生
    2020-12-25 10:14

    I have 'solved' the problem with this:

    nodes[0].x = width / 2;
    nodes[0].y = 100;
    nodes[0].fixed = true;
    force.on("tick", function(e) {
    
        var kx = .4 * e.alpha, ky = 1.4 * e.alpha;
        links.forEach(function(d, i) {
          d.target.x += (d.source.x - d.target.x) * kx;
          d.target.y += (d.source.y + 80 - d.target.y) * ky;
        });
        [...]
     }
    

    http://mbostock.github.io/d3/talk/20110921/parent-foci.html

    It's not exactly what we wanted but better as before. Importend is, that you define a "root"-Node and fixed it.

    nodes[0].fixed = true;
    

    It look like more as a tree but so it is clearer.

提交回复
热议问题