Visualizing complex structures using Graphviz

Slashdot it! Delicious Share on Facebook Tweet! Digg!

Data Structures as Hashes

In programming, data structures often come in the form of hashes, such as associative arrays [7]. Graphviz builds these structures without much fuss if you use the correct syntax. Line 2 in Listing 4 specifies that you want a directed graph – the LR determines the direction from left to right.

Listing 4

Create a Data Structure

01 digraph G {
02 rankdir=LR;
03 node [shape=record, width=0.1, height=0.1];
04
05 node0 [label = "<f0> | <f1> | <f2>", height=1.5];
06 node [width=1.5];
07 node1 [label = "{<n> n14 | 719 | <p>}"];
08 node2 [label = "{<n> k71 | 216 | <p>}"];
09 node3 [label = "{<n> n39 | 771 | <p>}"];
10 node4 [label = "{<n> k56 | 250 | <p>}"];
11 node5 [label = "{<n> a34 | 125 | <p>}"];
12
13 node0:f0 -> node1:n;
14 node1:p -> node2:n;
15 node0:f1 -> node3:n;
16 node0:f2 -> node4:n;
17 node4:p -> node5:n;
18 }

Lines 5 through 11 define the content of the nodes as additional structures and later access the separate elements by name. The node0 in line 5 has three elements (f0 , f1 , and f2 ), whereas node1 through node5 in lines 7 through 11 each have the two elements n and p . The middle element has no identifier, only the assigned value. Linking the nodes occurs in lines 3 through 17, and Graphviz takes over from there (Figure 4).

Figure 4: If you want to see the relationship of hash tables when programming, Graphviz helps with the necessary functions.

Dependencies

The next example comes directly from the engine room of a Linux system. With the Debtree [8] program, you can explore the dependencies between packages on a Debian-based system (e.g., Ubuntu). The parameters are the names of one or more packages – for simplicity's sake, I'll use names like sqlite3 for the SQLite3 [9] database.

The program provides the result in dot format. The call in Listing 5 creates the listing on the command line and passes the results to the sqlite3.dot file (Figure 5). From this, you generate an image file with dot (Figure 6).

Listing 5

Generate an Image File

01 $ debtree sqlite3 > sqlite3.dot
02 $ dot -Tpng sqlite3.dot > sqlite3.png
Figure 5: The dot description of the sqlite3 package dependencies on a Debian-based system.
Figure 6: With Debtree and Graphviz, you can see in an instant what kind of a rat tail an installation drags behind it.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $0.99
(incl. VAT)

Buy Ubuntu User

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Graphviz calculates flexible graphs

    Instead of toiling over a graphics layout, you can use Graphviz to concentrate on the essential content and let the software do the design.

  • Video compositing with Natron

    The Natron video program intends to compete with larger, commercial programs, such as AfterEffects and Nuke. At first, the controls may appear cumbersome and confusing, but with a little guidance and practice, everything becomes clear.

  • Video effects and compositing with Natron

    Elaborate video compositing, blue screen tricks, and other complex video effects normally only appear in high-priced programs like Adobe After Effects, Nuke, or Fusion. Natron is open source, free, and gives high-priced alternatives a run for their money.