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
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.
Something that might be easier than trying to forcefully repel the edges is to wiggle the nodes around until the amount of crossing lines in the system is lower.
http://en.wikipedia.org/wiki/Simulated_annealing
Start with the nodes with the least amount of connections and wiggle down.
If you try and use the edges as nodes I suspect you're just going to get the same spatial locking problems. The solution is in figuring out where there are edge intersections and if they can be resolved. You might find that resolving many of the edge crossings is not possible
A more lateral approach to the visualization is to animate it such that it only shows a subset of the nodes and connections at a time. Or to make the edges transparent until the user places mouse focus over a node, which point the associated edges become more visible.
Unfortunately, the answer to your question does not exist.
There is no built-in mechanism in D3 that repels edges or minimizes edge crossings. You would think it wouldn't be that hard to implement a charge on an edge, but here we are.
Furthermore, there doesn't seem to be any mechanism anywhere that reduces edge crossings in general. I've looked through dozens of visualization libraries and layout algorithms, and none of them deal with reducing edge crossings on a generic undirected graph.
There are a number of algorithms that work well for planar graphs, or 2-level graphs, or other simplifications. dagre works well in theory for 2-level graphs, although the utter lack of documentation makes it almost impossible to work with.
Part of the reason for this is that laying out graphs is hard. In particular, minimizing edge crossings is NP-hard, so I suspect that most layout designers hit that problem, bang their head against the keyboard a few times, and give up.
If anyone does come up with a good library for this, please publish it for the rest of us :)
I followed the Force Editor example and I saw that setting charge
and linkDistance
values solves the problem.
...
.charge(-200)
.linkDistance(50)
...
Screenshot: