Results 1 to 2 of 2

Thread: GraphViz and Ruby in Eclipse

  1. #1
    Join Date
    Feb 2008
    Ubuntu 7.10 Gutsy Gibbon

    GraphViz and Ruby in Eclipse

    Hi All,

    for school i have to output a tree within a ruby application. I found out that graphviz is a suited toolkit for this task.

    I've installed Eclipse (with ruby), GraphViz, libgraphviz4 and libgv-ruby. When I use
    require 'graphviz'
    the console shows:
    no such file to load -- graphviz (LoadError)
    I think i need to add the graphviz library to my project, but i can't figure out how to add the graphviz library to a ruby project.
    Can someone help me out?

  2. #2
    Join Date
    Feb 2008
    Ubuntu 7.10 Gutsy Gibbon

    Re: GraphViz and Ruby in Eclipse

    I found the answer myself. After installing the graphviz package go to and download the tarball package

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

    Drag the 'graph' folder into the eclipse project.
            # 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("public/img/g.png", "png") # Generate png file
    <img src="/img/g.png" />
    The output is a png image.



Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts