GraphR - Graph-related Ruby classes

Version:          0.1.9
Release date:     2001-11-16
Home page:
Author:           Robert Feldt

What is it?

Graph-related classes:

GraphR is very simple but is growing to support additional features of dot. A larger, "full" graph package is now being developed together with Horst Duchene so expect more features in the future...

GraphViz is an open source graph drawing software from AT&T (see


Graphs can be handy (;-)) and dot is a great visualization tool for graphs.


  1. unpack tarball (if you haven't already)
  2. Run tests: ruby -I./lib tests/runtests.rb (OPTIONAL)
  3. Install: ruby install.rb

You can uninstall with: ruby install.rb --uninstall

Example of use?

        # Lets crank out a simple graph...
        require 'graph/graphviz_dot'

        # We create a DotGraphPrinter from some links.
        # In this simple example we don't even have a "real" graph
        # just an Array with the links. The optional third
        # element of a link is link information. The nodes in this graph
        # are implicit in the links. If we had additional nodes that were
        # not linked we would supply them in an array as 2nd parameter to new.
        links = [[:start, 1, "*"], [1, 1, "a"], [1, 2, "~a"], [2, :stop, "*"]]
        dgp =

        # We specialize the printer to change the shape of nodes
        # based on their names.
        dgp.node_shaper = proc{|n|
          ["start", "stop"].include?(n.to_s) ? "doublecircle" : "box"

        # We can also set the attributes on individual nodes and edges.
        # These settings override the default shapers and labelers.
        dgp.set_node_attributes(2, :shape => "diamond")

        # Add URL link from node (this only work in some output formats?)
        # Note the extra quotes needed!
        dgp.set_node_attributes(2, :URL => '"node2.html"')

        # And now output to files
        dgp.write_to_file("g.png", "png") # Generate png file
        dgp.orientation = "landscape"      # Dot problem with PS orientation
        dgp.write_to_file("")          # Generate postscript file


Ruby and dot.

Dot is only a part of GraphViz. Download at and make sure dot can be run from Ruby by doing

system "dot"

ie. that dot is installed somewhere in the PATH.

NOTE THAT THIS IS AN ALPHA RELEASE SO THERE WILL LIKELY BE BUGS. And the API will probably change in future versions.


None yet. But you can look at the tests.

CVS archives?

License and legal issues?

GraphR is

Copyright (c) 2001 Robert Feldt, All rights reserved.

and is distributed under GPL. See LICENSE.


Thanks to matz for Ruby.

Thanks for Tanaka Akira for the code for strongly connected components and to Johan Holmberg for a patch.

Thanks to Sean Russell, Tobias Reif and Horst Duchene for feedback on and ideas for GraphR.

Special things to note?

0.1.10 changed so that the size attribute by default uses dot's default: the output grows when the graph grows. If you want to get a specific output size you must now explicitly set the size attribute. "9,11" was the previous default size and give roughly an A4.

Do you have comments or questions?

I'd appreciate if you drop me a note if you're successfully using GraphR. If there are some known users I'll be more motivated to packing up additions / new versions and post them to RAA.

Happy coding!

Robert Feldt,