Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

OUPS

  • Loading branch information...
commit 4d9044326dfe4354df4f193f906bc8c1839d232f 1 parent ae737b0
Gregoire Lejeune authored
Showing with 93 additions and 110 deletions.
  1. +93 −110 README.rdoc
203 README.rdoc
View
@@ -18,68 +18,61 @@ Interface to the GraphViz graphing tool
A basic example
-```ruby
-require 'graphviz'
+ require 'graphviz'
-# Create a new graph
-g = GraphViz.new( :G, :type => :digraph )
+ # Create a new graph
+ g = GraphViz.new( :G, :type => :digraph )
-# Create two nodes
-hello = g.add_nodes( "Hello" )
-world = g.add_nodes( "World" )
+ # Create two nodes
+ hello = g.add_nodes( "Hello" )
+ world = g.add_nodes( "World" )
-# Create an edge between the two nodes
-g.add_edges( hello, world )
+ # Create an edge between the two nodes
+ g.add_edges( hello, world )
-# Generate output image
-g.output( :png => "hello_world.png" )
-```
+ # Generate output image
+ g.output( :png => "hello_world.png" )
The same but with a block
-```ruby
-require 'graphviz'
+ require 'graphviz'
-GraphViz::new( :G, :type => :digraph ) { |g|
- g.world( :label => "World" ) << g.hello( :label => "Hello" )
-}.output( :png => "hello_world.png" )
+ GraphViz::new( :G, :type => :digraph ) { |g|
+ g.world( :label => "World" ) << g.hello( :label => "Hello" )
+ }.output( :png => "hello_world.png" )
- with the DSL
+Or with the DSL
-require 'graphviz/dsl'
-digraph :G do
- world[:label => "World"] << hello[:label => "Hello"]
+ require 'graphviz/dsl'
+ digraph :G do
+ world[:label => "World"] << hello[:label => "Hello"]
- output :png => "hello_world.png"
-end
-```
+ output :png => "hello_world.png"
+ end
Create a graph from a file
-```ruby
-require 'graphviz'
+ require 'graphviz'
-# In this example, hello.dot is :
-# digraph G {Hello->World;}
+ # 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")
-```
+ 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[http://graphml.graphdrawing.org/] support
-```ruby
-require 'graphviz/graphml'
+ require 'graphviz/graphml'
+
+ g = GraphViz::GraphML.new( "graphml/cluster.graphml" )
+ g.graph.output( :path => "/usr/local/bin", :png => "#{$0}.png" )
-g = GraphViz::GraphML.new( "graphml/cluster.graphml" )
-g.graph.output( :path => "/usr/local/bin", :png => "#{$0}.png" )
-```
== TOOLS
@@ -87,35 +80,29 @@ Ruby/GraphViz also includes :
* <tt>ruby2gv</tt>, a simple tool that allows you to create a dependency graph from a ruby script. Example : http://drp.ly/dShaZ
-```
-ruby2gv -Tpng -oruby2gv.png ruby2gv
-```
+ ruby2gv -Tpng -oruby2gv.png ruby2gv
* <tt>gem2gv</tt>, a tool that allows you to create a dependency graph between gems. Example : http://drp.ly/dSj9Y
-```
-gem2gv -Tpng -oruby-graphviz.png ruby-graphviz
-```
+ gem2gv -Tpng -oruby-graphviz.png ruby-graphviz
* <tt>dot2ruby</tt>, a tool that allows 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_nodes( "Hello", :height => '0.5', :label => '\N', :pos => '35,90', :width => '0.88889' )
- graph_g.add_edges( "Hello", "World", :pos => 'e,35,36.413 35,71.831 35,64.131 35,54.974 35,46.417' )
- node_world = graph_g.add_nodes( "World", :height => '0.5', :label => '\N', :pos => '35,18', :width => '0.97222' )
-}
-puts graph_g.output( :canon => String )
-```
+ $ 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_nodes( "Hello", :height => '0.5', :label => '\N', :pos => '35,90', :width => '0.88889' )
+ graph_g.add_edges( "Hello", "World", :pos => 'e,35,36.413 35,71.831 35,64.131 35,54.974 35,46.417' )
+ node_world = graph_g.add_nodes( "World", :height => '0.5', :label => '\N', :pos => '35,18', :width => '0.97222' )
+ }
+ puts graph_g.output( :canon => String )
* <tt>git2gv</tt>, a tool that allows you to show your git commits : http://dl.dropbox.com/u/72629/ruby-graphviz-git.svg
@@ -123,54 +110,50 @@ puts graph_g.output( :canon => String )
== GRAPH THEORY
-```ruby
-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]}"
-```
+ 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]}"
== INSTALLATION
-```
-sudo gem install ruby-graphviz
-```
+ sudo gem install ruby-graphviz
You also need to install GraphViz[http://www.graphviz.org]
Please sign in to comment.
Something went wrong with that request. Please try again.