Petr Baudis >
Graph-Layderer >
Graph::Layouter::Spring

Module Version: 0.03
Graph::Layouter::Spring - spring graph drawing algorithm implementation

use Graph::Layouter::Spring; Graph::Layouter::Spring::layout($graph);

This module provides the famous spring graph drawing algorithm implementation. See the `Graph::Layouter`

class documentation for usage description.

The algorithm is principially simple, simulating a space of electrically charged particles. Basically, each node is thought of as a particle with the same charge, therefore they all try to get as far of each other as possible. On the other hand, though, there are the edges, which keep nodes together; higher weight the edges have, stronger are they in pulling nodes near each other.

So to recapitulate, we have *repulsive force* pushing nodes from each other and *attractive force* pushing connected nodes near each other. We then just apply the repulsive force between each two nodes and the attractive force between each two connected nodes; each node will have a resulting movement force, which we will apply to the node's position (initially randomzero-zero) after the forces calculation is finished.

However, we need to let this repeat for several times in order for the positions to stabilize. In fact, a lot of iterations is needed; higher the better, but also higher the slower, you can very easily get to tens of seconds here so beware. Currently, the number of iterations is hardcoded to 500, but this is expected to get configurable soon.

`Graph`

, `Graph::Layouter`

, `Graph::Renderer`

The object-oriented interface is missing as well as some more universal layout calling interface (hash parameters).

It should all be configurable.

Copyright 2004 by Petr Baudis <pasky@ucw.cz>.

This code is distributed under the same copyright terms as Perl itself.

The algorithm is based on a spring-style layouter of a Java-based social network tracker PieSpy written by Paul Mutton <paul@jibble.org>.

Version 0.03

$Id: Spring.pm,v 1.8 2006/02/11 17:11:39 pasky Exp $

syntax highlighting: