Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Gregoire Lejeune
Sources : github.com/glejeune/Ruby-Graphviz
NEW - Mailing List : groups.google.com/group/ruby-graphviz
Interface to the GraphViz graphing tool
New FamilyTree
We are close to the 1.0 version... So if you use one of the following method or attribut, please update your code because they will be remove.
GraphViz::Node#name must be replaced by GraphViz::Node#id
A html attribut must be replaced by a label attribut (:label => '<<html/>>')
:output option must be replaced by :<format> => :<file>
:file option must be replaced by :<format> => :<file>
Add attributs "label_scheme" and "rotation"
Add missing options :
:scale => v : Scale input by 'v' (=72)
:inverty => [true|false] : Invert y coordinate in output
:no_layout => v : No layout mode 'v' (=1) -- neato only
:reduce => [true|false] : Reduce graph -- neato only
:Lg => [true|false] : Don't use grid -- fdp only
:LO => [true|false] : Use old attractive force -- fdp only
:Ln => i : Set number of iterations to i -- fdp only
:LU => i : Set unscaled factor to i -- fdp only
:LC => v : Set overlap expansion factor to v -- fdp only
:LT => [*]v : Set temperature (temperature factor) to v -- fdp only
Add GraphViz#each_attribut, Node#each_attribut and Edge#each_attribut
Bugs corrections in tests (by oupo)
Major bug correction in GraphViz#output for subgraphs
Update GraphViz.escape
Add strict digraph support (by Jonas Elfström) (see sample58.rb)
g = GraphViz.new(:G, :type => "strict digraph") # or g = GraphViz.new(:G, :type => "digraph", :strict => true) # or g = GraphViz.digraph(:G, :strict => true) # or g = GraphViz.strict_digraph(:G)
Add GraphViz#root_graph, Node#root_graph, Edge#root_graph
The GraphML parser now accept a graphml file or string
JRuby bug correction (by Nigel Thorne)
Fix autoload problem for Rubinius (by Rolf Timmermans)
Bugs corrections
GraphViz::Edge#node_one and GraphViz::Edge#node_one now have un optional parameter to indicate if you want to (or not) get the port in the name (default: true)
GraphViz#each_node now returns the Hash of nodes if there is no block given.
GraphViz#each_edge now returns the list of edges if there is no block given.
GraphViz#each_graph now returns the Hash of graphs if there is no block given.
Add GraphViz::Node#index : return the node index
Add GraphViz::Edge#index : return the edge index
Add GraphViz#type : return the graph type (graph or digraph)
Add GraphViz#get_edge_at_index and GraphViz#get_node_at_index
Add GvDouble
Add GraphViz::Theory (see examples/theory/tests.rb)
Add GraphML support (see sample57.rb)
fixed "edge attribut 'to_ary' invalid" on mri 1.9.2 (by Stefan Huber)
Add xml2gv
Rename GraphViz.parser2 to GraphViz.parser
Remove treetop dependency
Ruby 1.9 (and MacRuby) compatibility -- Issue #12: see sample38.rb
Add GraphViz.parser2. WARNING this method will replace GraphViz.parser. So please don't use it, or only for testing.
Bug correction in dot2ruby
Add --output-format option to dot2ruby
Add git2gv
Issue #16 : escape graph ID
Add dot2ruby script
Remove NULL character in the DOT script
WARNING : FamilyTree is (still) broken in this version !
Add dot2ruby.g
Bug correction with HTML label
The html attribut is deprecated. You can use the label attribut, as dot do it : :label => '<<html/>>'
Issue #15 : Thin server
WARNING : FamilyTree is (still) broken in this version !
GraphViz::Node#name is deprecated, you must use GraphViz::Node#id (issue #14)
Add :nothugly option to GraphViz#output (see sample41.rb and www.hokstad.com/making-graphviz-output-pretty-with-xsl.html)
Issue #13 : you must now specify a port in GraphViz::Edge.new with a syntax like this :
GraphViz::Edge.new( {nodeOne => :port}, {nodeTwo => :other} )
Issue #12 : UTF8 support (see sample38.rb)
Move and rename examples + remove maketest.
WARNING : FamilyTree is broken in this version !
Issue #11 : Cygwin PATH
Major bugs correction in output
Bug correction in find_executable
Add tests (by Chip Malice : github.com/hipe)
Move ChangeLog in README
Add GraphViz::FamilyTree (alpha). See examples/sample33.rb
Major bugs corrections in GraphViz::Parser
Issue #10 : Anonymous graph (see Subgraphs and Clusters at www.graphviz.org/doc/info/lang.html). See examples/sample34.rb
GraphViz#add_graph can now take a block parameter. See example/sample34.rb
Add GraphViz.digraph and GraphViz.graph (same as GraphViz.new( ..., :type => "digraph" ) and GraphViz.new( ..., :type => "graph" )). See examples/sample35.rb
Add GraphViz#subgraph. See examples/sample35.rb
GraphViz::Parser support anonymous graph
Add lage node example. See examples/sample36.rb
Add graph as an accessor to allow you to set global graph attributs (like edge and node)
Add each_node, each_edge, each_graph (thanks to @metellius) and graph_count
Issue #9 (partial) - Solution : by default, a node will have his label set with the node ID)
Update graph and node posibility to set properties (see sample28.rb)
Issue #7: Path option is never being used to find the executable
Adding classes to check if the attributes are in the correct type
Issue #8: dots in href are escaped with backslash, which corrupts the URL (see sample29.rb)
Add posibility to use external libraries (see sample30.rb)
Add options -u and -s to ruby2gv
Add gem2gv
Issue #2: Small bug correction in escape_path_containing_blanks (by Andreas Ronge)
Issue #4: New find_executable (by reactive)
Issue #3: Tempfiles created in current working directory only in Windows
Issue #6: Respect "none" format in output options hash and respect String output-filename when the "none" format is selected. See examples/sample27.rb (by Dave Burt)
jRuby support (by obruening)
Issue #1 : STDOUT in binmode
Remove 'mkmf' dependency
GraphViz::Edge#[] modification
Small correction to escape the dot ('.') character (by Miguel Cabrera)
Escape nodes and edges attributs
GraphViz::escape corrections (by Dave Burt)
Add :errors option to set level of message suppression (default : suppress warning messages)
Minor bug correction for Windows
Use Open3.popen3 if installed, else use IO.popen (by Dave Burt)
Add '-', '>' and '>>' has aliases of '<<' to create an edge.
Escape nodes (by Dave Burt)
Handle errors from graphviz command (by Dave Burt)
Output as string (if String class is passed as file i.e. output(:pdf => String)) (by Dave Burt)
Bugs corrections
Add the ability to create edge like that : node1 << node2 << node3 ...
Complete README
Add a DOT parser. This parser has a lot of limitations. So don't use it in a production context !
:output and :file options are deprecated, please use :<format> => :<file>
You can now specify multiple outputs via :<format> => :<file> (see sample 22).
Add fdp example (sample 15)
Add edge between cluster and node and cluster and cluster support
GraphViz.add_node now support array (sample 16)
Bug correction in GraphViz.output (sample 19)
Add GraphViz#default to set default options (:use, :path and :output)
Add possibility to set node or edge attribut via :
node.<attribut>=<value> or node.<attribut>( <value> ) edge.<attribut>=<value> or edge.<attribut>( <value> )
Add GraphViz::Edge.set and GraphViz::Node.set
Add sample 20
Add GraphViz.node_count and GraphViz.edge_count by Daniel Cadenas Nión
Update Node, Edge and Graph Attributes (see www.graphviz.org/doc/info/attrs.html)
Bugs corrections
Documentation
Add all the features of the current graphviz version
Add option "path" to output
Add undirected graph support
Preserve the original order of creation of nodes and edges
Add HTML-Labels
Bugs corrections
Pure ruby
Initial version
A basic example
require 'graphviz' # Create a new graph g = GraphViz.new( :G, :type => :digraph ) # Create two nodes hello = g.add_node( "Hello" ) world = g.add_node( "World" ) # Create an edge between the two nodes g.add_edge( hello, world ) # Generate output image g.output( :png => "hello_world.png" )
The same but with a block
require 'graphviz' GraphViz::new( :G, :type => :digraph ) { |g| g.world( :label => "World" ) << g.hello( :label => "Hello" ) }.output( :png => "hello_world.png" )
Create a graph from a file
require 'graphviz' # In this example, hello.dot is : # digraph G {Hello->World;} GraphViz.parse( "hello.dot", :path => "/usr/local/bin" ) { |g| g.get_node("Hello") { |n| n[:label] = "Bonjour" } g.get_node("World") { |n| n[:label] = "Le Monde" } }.output(:png => "sample.png")
GraphML support
require 'graphviz/graphml' g = GraphViz::GraphML.new( "graphml/cluster.graphml" ) g.graph.output( :path => "/usr/local/bin", :png => "#{$0}.png" )
At last, you can create familly tree with GraphViz::FamilyTree (beta) :
require 'graphviz/family_tree' tree = GraphViz::FamilyTree.new do generation do benoist.is_a_man( "Benoist" ) nathalie.is_a_woman( "Nathalie" ) benoist.is_maried_with nathalie end generation do charlotte.is_a_woman( "Charlotte" ) amelie.is_a_woman( "Amelie" ) clement.is_a_man( "Clement" ) gregoire.is_a_man( "Gregoire" ) muriel.is_a_woman( "Muriel" ) gregoire.is_maried_with muriel end couple( benoist, nathalie ).kids( charlotte, amelie, clement, gregoire ) end tree.graph.save( :png => "#{$0}.png" )
Ruby/GraphViz also include :
ruby2gv, a simple tool that's allow you to create a dependency graph from a ruby script. Example : drp.ly/dShaZ
ruby2gv -Tpng -oruby2gv.png ruby2gv
gem2gv, a tools that's allow you to create a dependency graph between gems. Example : drp.ly/dSj9Y
gem2gv -Tpng -oruby-graphviz.png ruby-graphviz
dot2ruby, a tools that's allow you to create a ruby script from a graphviz script
$ cat hello.dot digraph G {Hello->World;} $ dot2ruby hello.dot # This code was generated by dot2ruby.g require 'rubygems' require 'graphviz' graph_g = GraphViz.digraph( "G" ) { |graph_g| graph_g[:bb] = '0,0,70,108' node_hello = graph_g.add_node( "Hello", :height => '0.5', :label => '\N', :pos => '35,90', :width => '0.88889' ) graph_g.add_edge( "Hello", "World", :pos => 'e,35,36.413 35,71.831 35,64.131 35,54.974 35,46.417' ) node_world = graph_g.add_node( "World", :height => '0.5', :label => '\N', :pos => '35,18', :width => '0.97222' ) } puts graph_g.output( :canon => String )
git2gv, a tools that's allow you to show your git commits : dl.dropbox.com/u/72629/ruby-graphviz-git.svg
xml2gv, a tools that's allow you to show a xml file as graph.
require 'graphviz' require 'graphviz/theory' g = GraphViz.new( :G ) { ... } t = GraphViz::Theory.new( g ) puts "Adjancy matrix : " puts t.adjancy_matrix puts "Symmetric ? #{t.symmetric?}" puts "Incidence matrix :" puts t.incidence_matrix g.each_node do |name, node| puts "Degree of node `#{name}' = #{t.degree(node)}" end puts "Laplacian matrix :" puts t.laplacian_matrix puts "Dijkstra between a and f" r = t.moore_dijkstra(g.a, g.f) if r.nil? puts "No way !" else print "\tPath : "; p r[:path] puts "\tDistance : #{r[:distance]}" end print "Ranges : " rr = t.range p rr puts "Your graph contains circuits" if rr.include?(nil) puts "Critical path : " rrr = t.critical_path print "\tPath "; p rrr[:path] puts "\tDistance : #{rrr[:distance]}"
sudo gem install ruby-graphviz
You also need to install GraphViz and Treetop
On Windows you also need to install win32-open3. This is not an absolute requirement.
Ruby/GraphViz is freely distributable according to the terms of the GNU General Public License (see the file 'COPYING').
This program is distributed without any warranty. See the file 'COPYING' for details.
GNU General Public Licence: en.wikipedia.org/wiki/Gpl
By Vidar Hokstad and Ryan Shea; Contributions by Jonas Tingborn, Earl Cummings, Michael Kennedy (Graphviz 2.20.2 compatibility, bug fixes, testing, lots of gradients)
Copyright (c) 2009 Vidar Hokstad
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MIT license: en.wikipedia.org/wiki/MIT_License
Generated with the Darkfish Rdoc Generator 2.