Graph auto-layout algorithm

AlgorithmLayoutGraphNodesEdges

Algorithm Problem Overview


To simplify the problem, I have a graph that contains nodes and edges which are on a 2D plane.

What I want to be able to do is click a button and it make the automatically layout the graph to look clean. By that I mean minimal crossing of edges, nice space between nodes, maybe even represent the graph scale (weighted edges).

I know this is completely subjective of what is a clean looking graph, but does anyone know of an algorithm to start with, rather than reinventing the wheel?

Thanks.

Algorithm Solutions


Solution 1 - Algorithm

You will find http://graphdrawing.org/ and this tutorial, by Roberto Tamassia, professor at Brown University, quite helpful.

I like a lot Force-Directed Techniques (pp. 66-72 in the tutorial) like the Spring Embedder.

You assume there is a spring or other force between any two adjacent nodes and let nature (simulation) do the work :)

Solution 2 - Algorithm

I would suggest that you take a look at at graphviz. The dot program can take a specification of a graph and generate an image of the network for you somewhat "cleanly". I've linked to the "theory" page that gives you some links that might be relevant if you're interested in the theoretical background. The library and tools themselves are mature enough if you simply want a solution to a problem with layout that you're facing.

Solution 3 - Algorithm

Also JGraph if you want the layouts in Java (I work on the project).

Solution 4 - Algorithm

I would say as Noufal Ibrahim, but you could also look more precisely at the C API of the graphviz project. It includes a lib to build your graph (libgraph.pdf) with all the nodes and edges, and a lib to layout the graph (libgvc.pdf) (just compute each nodes position), so you can then display it in your own UI for example.

Solution 5 - Algorithm

A good visual guide how the most popular layouts actually look: follow the link

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCheetahView Question on Stackoverflow
Solution 1 - AlgorithmypercubeᵀᴹView Answer on Stackoverflow
Solution 2 - AlgorithmNoufal IbrahimView Answer on Stackoverflow
Solution 3 - AlgorithmFrodo BagginsView Answer on Stackoverflow
Solution 4 - AlgorithmjslapView Answer on Stackoverflow
Solution 5 - AlgorithmDiana JobsView Answer on Stackoverflow