The PEAK Developers' Center   Diff for "GraphvizTutorial" UserPreferences
 
HelpContents Search Diffs Info Edit Subscribe XML Print View
Ignore changes in the amount of whitespace

Differences between version dated 2003-02-28 14:54:32 and 2007-05-09 18:20:22 (spanning 3 versions)

Deletions are marked like this.
Additions are marked like this.

 
}}} and turns them into pictures that look like this:
 
http://www.research.att.com/sw/tools/graphviz/examples/directed/fsm.gif
http://www.graphviz.org/Gallery/directed/fsm.png
 
Many people have created interesting tools that use GraphViz to draw diagrams of workflow processes, clickpaths through a website, profiler call charts, even UML class diagrams. Most such programs use hardcoded templates for their `.dot` files and can be difficult to change because you have to know both the `dot` language and the application area of the software. In this tutorial, we'll develop a sophisticated framework for creating `.dot` files from application data that will give you flexible, object-oriented control over the visual objects to be rendered by GraphViz. We'll begin with a very simple structure using only three classes, and then, step by step, we'll show you more advanced ways to use the `peak.model` tools as we gradually enhance the framework's power and flexibility. Along the way, we'll share tips and techniques for ways to make the best design decisions for your own applications, in similar situations.
 

        stream.write('}\n')
}}}
 
Let's try it out...
 
{{{
>>> A = Node(name='A')
>>> B = Node(name='B')
>>> g = Graph(
 name='test',
 nodes=[A,B],
        edges=[Edge(fromNode=A, toNode=B)]
    )
 
>>> import sys
 
>>> g.writeDot(sys.stdout)
digraph test {
   A;
   B;
   A -> B;
}
}}}
 
If we had written the output to a file instead of to `sys.stdout`, we could have run `dot` over the file to produce an image like this one:
 
attachment:sample1.gif
 
Not very impressive so far, but it's a start. In principle, we could now generate digraphs of arbitrary complexity by writing code that manipulates `Node`, `Edge`, and `Graph` instances. In practice, they'll be rather ugly. :) That's because at this point, we have no way to specify nice shapes, labels, colors, arrowheads, fonts, and so on for our nodes and edges.
 
But before we start adding all that fancy stuff to the model, let's take a quick break to examine the new feature type we used, `model.Collection`.
 
 
=== Working with Collections ===
 

PythonPowered
ShowText of this page
EditText of this page
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck