public
Description: simple library for writing graphviz .dot files in ruby
Homepage:
Clone URL: git://github.com/davidlee/vizier.git
vizier /
name age message
file README Loading commit data...
file t.dot
file t.dot.png
file vizier.rb
README
This is a simple library I wrote to provide some minimal conveniences
to generate graphviz diagrams programmatically in ruby.

I find it useful. If you don't mind the lack of tests or
documentation, you might too.

Its aims not to do anything which has a non-obvious effect on the
outputted .dot file, nor to do anything on your behalf you don't tell
it to, and to generate output you can easily read and understand.

i.e., if you can understand graphviz, this should't get in your way.

I aim to add a few little comforts for dealing with ActiveRecord
objects in the future, assuming I have a need.

Here's a poorly contrived example:

graph = Vizier::Graph.new(:state_machine) do |g|
  g.node :shape => 'doublecircle'

  # there are a few ways to do things:
  init = g.add_node( "initial" )
  fine = g.add_node( "final" );
  g.connect( "initial", fine);       # connect can take a node or a node name
  e = g.connect( g.nodes["initial"], # and you can retrieve nodes like this
                 g.add_node( "alternate" ),
                 :label => "sneaky", :color => "blue");

  # use .graph[:attr] = value or add values in the constructor - they're equivalent
  g.cluster( 0, :style => "filled") do |sg|  # eg style is added as an option
    sg.graph[:bgcolor] = "#999999"           # bgcolour is added later via .graph
    sg.graph[:color]   = "#ffeedd"
    sg.graph[:label]   = "stick"

    sg.node[:color] = "#ff0000"

    alive = sg.add_node("alive");
    dead  = sg.add_node("dead");
    sg.connect( alive, dead, :label => "die" );
  end

  # these are all equivalent ways to get at a the subgraph / cluster we just defined
  s = g.subgraphs[:cluster_0]
  s = g.clusters[:cluster_0]
  s = g.cluster[0]

  g.connect(g.nodes[:initial],   s.nodes['dead'], :label => "inevitably");
  g.connect(g.nodes[:alternate], s.nodes['dead'], :label => "eventually");
  g.connect(g.nodes[:final],     s.nodes['dead'], :label => "no doubt");
end

puts graph.generate!

# generates this =>

digraph state_machine {

    /***********************************
    ** global options                 **
    ***********************************/
    graph [];
    node [ shape = doublecircle ];
    edge [];

    /***********************************
    ** nodes                          **
    ***********************************/
    initial [];
    final [];
    alternate [];

    /***********************************
    ** links                          **
    ***********************************/
    initial -> final [];
    initial -> alternate [ label = sneaky color = blue ];
    initial -> dead [ label = inevitably ];
    alternate -> dead [ label = eventually ];
    final -> dead [ label = "no doubt" ];

    /***********************************
    ** subgraphs                      **
    ***********************************/
    subgraph cluster_0 {
        graph [ style = filled ];
        node [ color = "#ff0000" ];
        edge [];
        alive [];
        dead [];
        alive -> dead [ label = die ];
    }
}