Graph::Easy - Manual

Tutorials - Bypass (or How to Define The Layout Order)

The goal

The goal of that tutorial is to show you how to create the following layout:

+------+     +---------+                   +-----------+     +---------+
| Bonn | --> | Koblenz | ----------------> | Frankfurt | --> | Dresden |
+------+     +---------+                   +-----------+     +---------+
               |                             ^
               |                             |
               |                             |
               |             +-------+       |
               +-----------> | Trier | ------+
                             +-------+

Solution

[ Bonn ] --> [ Koblenz ] --> { minlen: 3; } [ Frankfurt ]
  --> [ Dresden ]

[ Koblenz ] --> [ Trier ] { origin: Koblenz; offset: 2, 2; }
  --> [ Frankfurt ]

Explanation

Imagine you have a row of nodes like this:

[ Bonn ] --> [ Koblenz ] --> [ Frankfurt ] --> [ Dresden ]

This would be rendered like this:

+------+     +---------+     +-----------+     +---------+
| Bonn | --> | Koblenz | --> | Frankfurt | --> | Dresden |
+------+     +---------+     +-----------+     +---------+

Now you want to show that there is an alternative route via 'Trier':

[ Bonn ] --> [ Koblenz ] --> [ Frankfurt ] --> [ Dresden ]

[ Koblenz ] --> [ Trier ] --> [ Frankfurt ]

Unfortunately, this doesn't render quite right, instead of showing the route via 'Trier' being a bypass, it shows it as the normal route and the route via Frankfurt as a shortcut:

               +-----------------------------+
               |                             v
+------+     +---------+     +-------+     +-----------+     +---------+
| Bonn | --> | Koblenz | --> | Trier | --> | Frankfurt | --> | Dresden |
+------+     +---------+     +-------+     +-----------+     +---------+

The first idea would be to route the edge to 'Trier' to the right:

[ Bonn ] --> [ Koblenz ] --> [ Frankfurt ] --> [ Dresden ]

[ Koblenz ] --> { start: right; } [ Trier ] --> [ Frankfurt ]

Unfortunately, the layouter is not so easily defeated:

+------+     +---------+
| Bonn | --> | Koblenz | ------+
+------+     +---------+       |
               |               |
               |               |
               v               v
             +---------+     +-----------+     +---------+
             |  Trier  | --> | Frankfurt | --> | Dresden |
             +---------+     +-----------+     +---------+

So lets put the node 'Trier' at a certain offset from Koblenz:

[ Bonn ] --> [ Koblenz ] --> [ Frankfurt ] --> [ Dresden ]

[ Koblenz ] --> [ Trier ] { origin: Koblenz; offset: 2, 2; }
  --> [ Frankfurt ]

This looks almost right:

+------+     +---------+     +-----------+     +---------+
| Bonn | --> | Koblenz | --> | Frankfurt | --> | Dresden |
+------+     +---------+     +-----------+     +---------+
               |               ^
               |               |
               |               |
               |             +-----------+
               +-----------> |   Trier   |
                             +-----------+

So in addition, we make the edge from 'Koblenz' to 'Frankfurt' longer via the minlen-attribute:

[ Bonn ] --> [ Koblenz ] --> { minlen: 3; } [ Frankfurt ]
  --> [ Dresden ]

[ Koblenz ] --> [ Trier ] { origin: Koblenz; offset: 2, 2; }
  --> [ Frankfurt ]
+------+     +---------+                   +-----------+     +---------+
| Bonn | --> | Koblenz | ----------------> | Frankfurt | --> | Dresden |
+------+     +---------+                   +-----------+     +---------+
               |                             ^
               |                             |
               |                             |
               |             +-------+       |
               +-----------> | Trier | ------+
                             +-------+

Et voila! Here is the same graph rendered as SVG:

If you read this text, your browser does not yet support Scalable Vector graphics (SVG).

Contact and Bugreports

If you have questions, feel free to send me an email (Gnupg key). Bugreports should go to rt.cpan.org.