Graph auto-layout algorithm
Asked Answered
F

6

80

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.

Fie answered 17/2, 2011 at 11:39 Comment(0)
E
29

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.

Epaulet answered 17/2, 2011 at 11:46 Comment(4)
The question is about an Algorithm for graph layout, not application.Estrous
That's why I specifically mentioned the theory link on that page.Epaulet
The answer isn't explicitly referring to the theory link. It's more of an "if you are interested in theory". It would've been better to refer to the theory link and "if you are interested in an application" instead.Estrous
Fair enough. I understood the OP as wanting to solve the layout problem (rather than reimplement a solution) and based my answer on that (a well tested, production quality "wheel" that he or she didn't have to reinvent).Epaulet
F
89

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 :)

Formwork answered 17/2, 2011 at 15:0 Comment(1)
@xhg thnx! I edited the link, to Roberto Tamassia' pages, in Brown University.Agio
E
29

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.

Epaulet answered 17/2, 2011 at 11:46 Comment(4)
The question is about an Algorithm for graph layout, not application.Estrous
That's why I specifically mentioned the theory link on that page.Epaulet
The answer isn't explicitly referring to the theory link. It's more of an "if you are interested in theory". It would've been better to refer to the theory link and "if you are interested in an application" instead.Estrous
Fair enough. I understood the OP as wanting to solve the layout problem (rather than reimplement a solution) and based my answer on that (a well tested, production quality "wheel" that he or she didn't have to reinvent).Epaulet
S
4

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

Scoutmaster answered 17/2, 2011 at 12:1 Comment(0)
D
4

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.

Discontinue answered 17/2, 2011 at 15:56 Comment(0)
O
3

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

Operative answered 18/7, 2016 at 12:12 Comment(1)
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.Tenerife
I
1

For javascript I recommend this library from Microsoft: https://microsoft.github.io/msagljs/

Illuminometer answered 29/6, 2023 at 3:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.