Skip to content

Commit

Permalink
Add DOT Parser\nAdd treetop dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
greg committed Oct 5, 2009
1 parent 49081ba commit 831a0cd
Show file tree
Hide file tree
Showing 20 changed files with 1,767 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -2,6 +2,7 @@
* 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 !

0.9.0 :
* Add fdp example (sample 15)
Expand Down
17 changes: 17 additions & 0 deletions README.rdoc
Expand Up @@ -30,10 +30,27 @@ A basic example

The same but with a block

require 'graphviz'

GraphViz::new( :G, :type => :digraph ) { |g|
g.world( :label => "World" ) << g.hello( :label => Hello )
}.output( :output => :png, :file => "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(:output => "png", :file => "sample.png")

== INSTALLATION

Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Expand Up @@ -60,6 +60,8 @@ spec =
s.require_path = "lib"
s.bindir = "bin"
s.executables = ['ruby2gv']

s.add_dependency('treetop')

s.rubyforge_project = 'ruby-asp'
s.has_rdoc = true
Expand Down
31 changes: 31 additions & 0 deletions examples/dot/cluster.dot
@@ -0,0 +1,31 @@
digraph G {

subgraph cluster_0 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
a0 -> a1;
a1 -> a2;
a2 -> a3;
label = "process #1";
}

subgraph cluster_1 {
node [style=filled];
b0 -> b1;
b1 -> b2;
b2 -> b3;
label = "process #2";
color=blue;
}
start -> a0;
start -> b0;
a1 -> b3;
b2 -> a3;
a3 -> a0;
a3 -> end;
b3 -> end;

start [shape=Mdiamond];
end [shape=Msquare];
}
20 changes: 20 additions & 0 deletions examples/dot/fsm.dot
@@ -0,0 +1,20 @@
digraph finite_state_machine {
rankdir=LR;
size="8,5";
node [shape = doublecircle]; LR_0; LR_3; LR_4; LR_8;
node [shape = circle];
LR_0 -> LR_2 [ label = "SS(B)" ];
LR_0 -> LR_1 [ label = "SS(S)" ];
LR_1 -> LR_3 [ label = "S($end)" ];
LR_2 -> LR_6 [ label = "SS(b)" ];
LR_2 -> LR_5 [ label = "SS(a)" ];
LR_2 -> LR_4 [ label = "S(A)" ];
LR_5 -> LR_7 [ label = "S(b)" ];
LR_5 -> LR_5 [ label = "S(a)" ];
LR_6 -> LR_6 [ label = "S(b)" ];
LR_6 -> LR_5 [ label = "S(a)" ];
LR_7 -> LR_8 [ label = "S(b)" ];
LR_7 -> LR_5 [ label = "S(a)" ];
LR_8 -> LR_6 [ label = "S(b)" ];
LR_8 -> LR_5 [ label = "S(a)" ];
}
118 changes: 118 additions & 0 deletions examples/dot/genetic.dot
@@ -0,0 +1,118 @@
graph ""
{
label="((+ (* (X) (- (- (X) (X)) (X))) (% (+ (X) (X)) (COS (- (X) (X))))) (EXP (* (X) (X))) (+ (% (EXP (SIN (+ (X) (X)))) (SIN (* (X) (EXP (* (X) (X)))))) (* (X) (X))) (% (EXP (% (X) (% (X) (X)))) (EXP (SIN (X)))))";

subgraph cluster01
{
label="(+ (* (X) (- (- (X) (X)) (X))) (% (+ (X) (X)) (COS (- (X) (X)))))";
n002 ;
n002 [label="+"] ;
n002 -- n003 ;
n003 [label="*"] ;
n003 -- n004 ;
n004 [label="X"] ;
n003 -- n005 ;
n005 [label="-"] ;
n005 -- n006 ;
n006 [label="-"] ;
n006 -- n007 ;
n007 [label="X"] ;
n006 -- n008 ;
n008 [label="X"] ;
n005 -- n009 ;
n009 [label="X"] ;
n002 -- n010 ;
n010 [label="%"] ;
n010 -- n011 ;
n011 [label="+"] ;
n011 -- n012 ;
n012 [label="X"] ;
n011 -- n013 ;
n013 [label="X"] ;
n010 -- n014 ;
n014 [label="COS"] ;
n014 -- n015 ;
n015 [label="-"] ;
n015 -- n016 ;
n016 [label="X"] ;
n015 -- n017 ;
n017 [label="X"] ;
}

subgraph cluster17
{
label="(EXP (* (X) (X)))";
n018 ;
n018 [label="EXP"] ;
n018 -- n019 ;
n019 [label="*"] ;
n019 -- n020 ;
n020 [label="X"] ;
n019 -- n021 ;
n021 [label="X"] ;
}

subgraph cluster21
{
label="(+ (% (EXP (SIN (+ (X) (X)))) (SIN (* (X) (EXP (* (X) (X)))))) (* (X) (X)))";
n022 ;
n022 [label="+"] ;
n022 -- n023 ;
n023 [label="%"] ;
n023 -- n024 ;
n024 [label="EXP"] ;
n024 -- n025 ;
n025 [label="SIN"] ;
n025 -- n026 ;
n026 [label="+"] ;
n026 -- n027 ;
n027 [label="X"] ;
n026 -- n028 ;
n028 [label="X"] ;
n023 -- n029 ;
n029 [label="SIN"] ;
n029 -- n030 ;
n030 [label="*"] ;
n030 -- n031 ;
n031 [label="X"] ;
n030 -- n032 ;
n032 [label="EXP"] ;
n032 -- n033 ;
n033 [label="*"] ;
n033 -- n034 ;
n034 [label="X"] ;
n033 -- n035 ;
n035 [label="X"] ;
n022 -- n036 ;
n036 [label="*"] ;
n036 -- n037 ;
n037 [label="X"] ;
n036 -- n038 ;
n038 [label="X"] ;
}

subgraph cluster38
{
label="(% (EXP (% (X) (% (X) (X)))) (EXP (SIN (X))))";
n039 ;
n039 [label="%"] ;
n039 -- n040 ;
n040 [label="EXP"] ;
n040 -- n041 ;
n041 [label="%"] ;
n041 -- n042 ;
n042 [label="X"] ;
n041 -- n043 ;
n043 [label="%"] ;
n043 -- n044 ;
n044 [label="X"] ;
n043 -- n045 ;
n045 [label="X"] ;
n039 -- n046 ;
n046 [label="EXP"] ;
n046 -- n047 ;
n047 [label="SIN"] ;
n047 -- n048 ;
n048 [label="X"] ;
}
}
1 change: 1 addition & 0 deletions examples/dot/hello.dot
@@ -0,0 +1 @@
digraph G {Hello->World;}
14 changes: 14 additions & 0 deletions examples/dot/hello_test.rb
@@ -0,0 +1,14 @@
#!/usr/bin/ruby

$:.unshift( "../../lib" );
require "graphviz"

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(:output => "png", :file => "sample.png")

103 changes: 103 additions & 0 deletions examples/dot/lion_share.dot
@@ -0,0 +1,103 @@
digraph Ped_Lion_Share {
ratio = "auto" ;
label = "Pedigree Lion_Share" ;

"001" [shape=box , regular=1,style=filled,fillcolor=white ] ;
"002" [shape=box , regular=1,style=filled,fillcolor=white ] ;
"003" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"004" [shape=box , regular=1,style=filled,fillcolor=white ] ;
"005" [shape=box , regular=1,style=filled,fillcolor=white ] ;
"006" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"007" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"009" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"014" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"015" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"016" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"ZZ01" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"ZZ02" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"017" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"012" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"008" [shape=box , regular=1,style=filled,fillcolor=white ] ;
"011" [shape=box , regular=1,style=filled,fillcolor=white ] ;
"013" [shape=box , regular=1,style=filled,fillcolor=white ] ;
"010" [shape=box , regular=1,style=filled,fillcolor=white ] ;
"023" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"020" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"021" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"018" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"025" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"019" [shape=box , regular=1,style=filled,fillcolor=white ] ;
"022" [shape=box , regular=1,style=filled,fillcolor=white ] ;
"024" [shape=box , regular=1,style=filled,fillcolor=white ] ;
"027" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
"026" [shape=box , regular=1,style=filled,fillcolor=white ] ;
"028" [shape=box , regular=1,style=filled,fillcolor=grey ] ;
"marr0001" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"001" -> "marr0001" [dir=none,weight=1] ;
"007" -> "marr0001" [dir=none,weight=1] ;
"marr0001" -> "017" [dir=none, weight=2] ;
"marr0002" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"001" -> "marr0002" [dir=none,weight=1] ;
"ZZ02" -> "marr0002" [dir=none,weight=1] ;
"marr0002" -> "012" [dir=none, weight=2] ;
"marr0003" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"002" -> "marr0003" [dir=none,weight=1] ;
"003" -> "marr0003" [dir=none,weight=1] ;
"marr0003" -> "008" [dir=none, weight=2] ;
"marr0004" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"002" -> "marr0004" [dir=none,weight=1] ;
"006" -> "marr0004" [dir=none,weight=1] ;
"marr0004" -> "011" [dir=none, weight=2] ;
"marr0005" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"002" -> "marr0005" [dir=none,weight=1] ;
"ZZ01" -> "marr0005" [dir=none,weight=1] ;
"marr0005" -> "013" [dir=none, weight=2] ;
"marr0006" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"004" -> "marr0006" [dir=none,weight=1] ;
"009" -> "marr0006" [dir=none,weight=1] ;
"marr0006" -> "010" [dir=none, weight=2] ;
"marr0007" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"005" -> "marr0007" [dir=none,weight=1] ;
"015" -> "marr0007" [dir=none,weight=1] ;
"marr0007" -> "023" [dir=none, weight=2] ;
"marr0008" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"005" -> "marr0008" [dir=none,weight=1] ;
"016" -> "marr0008" [dir=none,weight=1] ;
"marr0008" -> "020" [dir=none, weight=2] ;
"marr0009" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"005" -> "marr0009" [dir=none,weight=1] ;
"012" -> "marr0009" [dir=none,weight=1] ;
"marr0009" -> "021" [dir=none, weight=2] ;
"marr0010" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"008" -> "marr0010" [dir=none,weight=1] ;
"017" -> "marr0010" [dir=none,weight=1] ;
"marr0010" -> "018" [dir=none, weight=2] ;
"marr0011" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"011" -> "marr0011" [dir=none,weight=1] ;
"023" -> "marr0011" [dir=none,weight=1] ;
"marr0011" -> "025" [dir=none, weight=2] ;
"marr0012" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"013" -> "marr0012" [dir=none,weight=1] ;
"014" -> "marr0012" [dir=none,weight=1] ;
"marr0012" -> "019" [dir=none, weight=2] ;
"marr0013" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"010" -> "marr0013" [dir=none,weight=1] ;
"021" -> "marr0013" [dir=none,weight=1] ;
"marr0013" -> "022" [dir=none, weight=2] ;
"marr0014" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"019" -> "marr0014" [dir=none,weight=1] ;
"020" -> "marr0014" [dir=none,weight=1] ;
"marr0014" -> "024" [dir=none, weight=2] ;
"marr0015" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"022" -> "marr0015" [dir=none,weight=1] ;
"025" -> "marr0015" [dir=none,weight=1] ;
"marr0015" -> "027" [dir=none, weight=2] ;
"marr0016" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"024" -> "marr0016" [dir=none,weight=1] ;
"018" -> "marr0016" [dir=none,weight=1] ;
"marr0016" -> "026" [dir=none, weight=2] ;
"marr0017" [shape=diamond,style=filled,label="",height=.1,width=.1] ;
"026" -> "marr0017" [dir=none,weight=1] ;
"027" -> "marr0017" [dir=none,weight=1] ;
"marr0017" -> "028" [dir=none, weight=2] ;
}

0 comments on commit 831a0cd

Please sign in to comment.