luquet-ruby-graphviz 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/AUTHORS +7 -0
  2. data/COPYING +340 -0
  3. data/ChangeLog +66 -0
  4. data/README.rdoc +69 -0
  5. data/bin/ruby2gv +194 -0
  6. data/examples/HTML-Labels.rb +20 -0
  7. data/examples/arrowhead.rb +97 -0
  8. data/examples/dot/cluster.dot +31 -0
  9. data/examples/dot/fsm.dot +20 -0
  10. data/examples/dot/genetic.dot +118 -0
  11. data/examples/dot/hello.dot +1 -0
  12. data/examples/dot/hello_test.rb +14 -0
  13. data/examples/dot/lion_share.dot +103 -0
  14. data/examples/dot/prof.dot +150 -0
  15. data/examples/dot/psg.dot +28 -0
  16. data/examples/dot/sdh.dot +284 -0
  17. data/examples/dot/siblings.dot +492 -0
  18. data/examples/dot/test.dot +17 -0
  19. data/examples/dot/unix.dot +104 -0
  20. data/examples/graphviz.org/TrafficLights.rb +62 -0
  21. data/examples/graphviz.org/cluster.rb +62 -0
  22. data/examples/graphviz.org/hello_world.rb +10 -0
  23. data/examples/graphviz.org/lion_share.rb +215 -0
  24. data/examples/graphviz.org/process.rb +37 -0
  25. data/examples/maketest.sh +85 -0
  26. data/examples/p2p.rb +35 -0
  27. data/examples/sample01.rb +32 -0
  28. data/examples/sample02.rb +42 -0
  29. data/examples/sample03.rb +31 -0
  30. data/examples/sample04.rb +22 -0
  31. data/examples/sample05.rb +32 -0
  32. data/examples/sample06.rb +46 -0
  33. data/examples/sample07.rb +23 -0
  34. data/examples/sample08.rb +34 -0
  35. data/examples/sample09.rb +50 -0
  36. data/examples/sample10.rb +50 -0
  37. data/examples/sample11.rb +42 -0
  38. data/examples/sample12.rb +55 -0
  39. data/examples/sample13.rb +48 -0
  40. data/examples/sample14.rb +44 -0
  41. data/examples/sample15.rb +23 -0
  42. data/examples/sample16.rb +8 -0
  43. data/examples/sample17.rb +92 -0
  44. data/examples/sample18.rb +24 -0
  45. data/examples/sample19.rb +59 -0
  46. data/examples/sample20.rb +47 -0
  47. data/examples/sample21.rb +12 -0
  48. data/examples/sample22.rb +10 -0
  49. data/examples/sample23.rb +11 -0
  50. data/examples/sample24.rb +11 -0
  51. data/examples/sample25.rb +11 -0
  52. data/examples/shapes.rb +24 -0
  53. data/examples/test.xml +26 -0
  54. data/examples/testorder.rb +43 -0
  55. data/examples/testxml.rb +7 -0
  56. data/lib/graphviz.rb +655 -0
  57. data/lib/graphviz/attrs.rb +51 -0
  58. data/lib/graphviz/constants.rb +246 -0
  59. data/lib/graphviz/dot.treetop +97 -0
  60. data/lib/graphviz/edge.rb +130 -0
  61. data/lib/graphviz/node.rb +129 -0
  62. data/lib/graphviz/parser.rb +249 -0
  63. data/lib/graphviz/xml.rb +131 -0
  64. data/setup.rb +1585 -0
  65. metadata +176 -0
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (C) 2005, 2006, 2007 Gregoire Lejeune <gregoire.lejeune@free.fr>
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ require 'getoptlong'
19
+ require 'graphviz'
20
+ require "graphviz/constants"
21
+ require 'rbconfig'
22
+
23
+ DEBUG = false
24
+
25
+ class Rb2Gv
26
+ REQUIRE = /^\s*require\s*("|')([^\1]*)(\1)/
27
+
28
+ def initialize( xGVPath )
29
+ @oGraph = GraphViz::new( "G", :path => xGVPath )
30
+ @oGraph['size'] = '10,10'
31
+ @hxNodes = Hash::new( )
32
+ @hxEdge = Hash::new( )
33
+ end
34
+
35
+ public
36
+ def parse( xFile )
37
+ @hxNodes[xFile] = gv_newNode( xFile )
38
+ puts "+ Node #{xFile}" if DEBUG
39
+
40
+ parseFile( xFile, nil, xFile )
41
+ end
42
+
43
+ def out( xFormat = "dot", xFile = nil )
44
+ if xFile.nil? == true
45
+ @oGraph.output( "output" => xFormat )
46
+ else
47
+ @oGraph.output( "output" => xFormat, "file" => xFile )
48
+ end
49
+ end
50
+
51
+ private
52
+ def gv_newNode( xNode, xShape = "box", xColor = nil )
53
+ xNodeName = xNode.gsub( /[^a-zA-Z0-9]/, "_" )
54
+ if xColor.nil? == true
55
+ @oGraph.add_node( xNodeName, "label" => xNode, "shape" => xShape )
56
+ else
57
+ @oGraph.add_node( xNodeName, "label" => xNode, "shape" => xShape, "style" => "filled", "color" => xColor )
58
+ end
59
+ end
60
+
61
+ def getLibraryPath( xLib, xExt = "rb" )
62
+ xPath = [ "libexecdir", "libdir", "sitedir", "rubylibdir", "sitelibdir", "archdir", "sitedir", "sitearchdir" ]
63
+ xRbLib = with_config( xLib+'lib', xLib)
64
+ if /\.(rb|so)$/.match( xRbLib )
65
+ xRbFile = xRbLib
66
+ else
67
+ xRbFile = xRbLib + "." + xExt
68
+ end
69
+
70
+ xPath.each do |xDir|
71
+ xCurrentPath = Config::expand( Config::CONFIG[xDir] )
72
+ xFileFound = File.join( xCurrentPath, xRbFile )
73
+ if File.exist?( xFileFound )
74
+ return xFileFound
75
+ end
76
+ end
77
+
78
+ return nil
79
+ end
80
+
81
+ def parseFile( xFile, xFromFile = nil, xLib = nil )
82
+
83
+ if xFromFile.nil? == false
84
+ puts "Parse #{xFile} required in #{xFromFile} :" if DEBUG
85
+ else
86
+ puts "Parse #{xFile} :" if DEBUG
87
+ end
88
+
89
+ fp = open( xFile, 'r' )
90
+ xData = fp.read()
91
+ fp.close
92
+
93
+ xData.each do |xLine|
94
+ if lxLineMatch = REQUIRE.match( xLine )
95
+ xRequiredLib = lxLineMatch[2]
96
+
97
+ if @hxNodes.has_key?( xRequiredLib ) == false
98
+ puts " + Node #{xRequiredLib}" if DEBUG
99
+
100
+ xRequiredFile = getLibraryPath( xRequiredLib )
101
+ if xRequiredFile.nil? == false
102
+ @hxNodes[xRequiredLib] = gv_newNode( xRequiredLib )
103
+ parseFile( xRequiredFile, xFile, xRequiredLib )
104
+ else
105
+ if getLibraryPath( xRequiredLib, "so" ).nil? == false
106
+ @hxNodes[xRequiredLib] = gv_newNode( xRequiredLib, "ellipse" )
107
+ else
108
+ @hxNodes[xRequiredLib] = gv_newNode( xRequiredLib, "ellipse", "red" )
109
+ end
110
+ end
111
+
112
+ end
113
+
114
+ puts " + Edge #{xLib} -> #{xRequiredLib}" if DEBUG
115
+ @oGraph.add_edge( @hxNodes[xLib], @hxNodes[xRequiredLib] )
116
+
117
+ end
118
+ end
119
+
120
+ end
121
+
122
+ end
123
+
124
+ def usage
125
+ puts "usage: ruby2gv.rb [-Tformat] [-ofile] [-h] [-V] script"
126
+ puts "-T, --output-format format Output format (default: PNG)"
127
+ puts "-o, --output-file file Output file (default: STDOUT)"
128
+ puts "-p, --path Graphviz path"
129
+ puts "-V, --version Show version"
130
+ puts "-h, --help Show this usage message"
131
+ end
132
+
133
+ def version
134
+ puts "Ruby2GraphViz v#{Constants::RGV_VERSION}, (c)2005 Gregoire Lejeune <gregoire.lejeune@free.fr>"
135
+ puts ""
136
+ puts "This program is free software; you can redistribute it and/or modify"
137
+ puts "it under the terms of the GNU General Public License as published by"
138
+ puts "the Free Software Foundation; either version 2 of the License, or"
139
+ puts "(at your option) any later version."
140
+ puts ""
141
+ puts "This program is distributed in the hope that it will be useful,"
142
+ puts "but WITHOUT ANY WARRANTY; without even the implied warranty of"
143
+ puts "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
144
+ puts "GNU General Public License for more details."
145
+ puts ""
146
+ puts "You should have received a copy of the GNU General Public License"
147
+ puts "along with this program; if not, write to the Free Software"
148
+ puts "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
149
+ end
150
+
151
+ xOutFormat = "png"
152
+ xOutFile = nil
153
+ xGVPath = nil
154
+
155
+ oOpt = GetoptLong.new(
156
+ ['--output-format', '-T', GetoptLong::REQUIRED_ARGUMENT],
157
+ ['--output-file', '-o', GetoptLong::REQUIRED_ARGUMENT],
158
+ ['--path', '-p', GetoptLong::REQUIRED_ARGUMENT],
159
+ ['--help', '-h', GetoptLong::NO_ARGUMENT],
160
+ ['--version', '-V', GetoptLong::NO_ARGUMENT]
161
+ )
162
+
163
+ begin
164
+ oOpt.each_option do |xOpt, xValue|
165
+ case xOpt
166
+ when '--output-format'
167
+ xOutFormat = xValue
168
+ when '--output-file'
169
+ xOutFile = xValue
170
+ when '--path'
171
+ xGVPath = xValue
172
+ when '--help'
173
+ usage( )
174
+ exit
175
+ when '--version'
176
+ version( )
177
+ exit
178
+ end
179
+ end
180
+ rescue GetoptLong::InvalidOption => e
181
+ usage( )
182
+ exit
183
+ end
184
+
185
+ xFile = ARGV[0]
186
+
187
+ if xFile.nil? == true
188
+ usage( )
189
+ exit
190
+ end
191
+
192
+ o = Rb2Gv::new( xGVPath )
193
+ o.parse( xFile )
194
+ o.out( xOutFormat, xOutFile )
@@ -0,0 +1,20 @@
1
+ $:.unshift( "../lib" );
2
+ require "graphviz"
3
+
4
+ g = GraphViz::new( "structs" )
5
+
6
+ g.node["shape"] = "plaintext"
7
+
8
+ g.add_node( "HTML" )
9
+
10
+ g.add_node( "struct1", "html" => '<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR><TD>left</TD><TD PORT="f1">mid dle</TD><TD PORT="f2">right</TD></TR> </TABLE>>]; struct2 [label=< <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR><TD PORT="f0">one</TD><TD>two</TD></TR> </TABLE>')
11
+
12
+ g.add_node( "struct2", "html" => '<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR><TD PORT="f0">one</TD><TD>two</TD></TR> </TABLE>' )
13
+ g.add_node( "struct3", "html" => '<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR> <TD ROWSPAN="3">hello<BR/>world</TD> <TD COLSPAN="3">b</TD> <TD ROWSPAN="3">g</TD> <TD ROWSPAN="3">h</TD> </TR> <TR> <TD>c</TD><TD PORT="here">d</TD><TD>e</TD> </TR> <TR> <TD COLSPAN="3">f</TD> </TR> </TABLE>' )
14
+
15
+ g.add_edge( "struct1:f1", "struct2:f0" )
16
+ g.add_edge( "struct1:f2", "struct3:here" )
17
+
18
+ g.add_edge( "HTML", "struct1" )
19
+
20
+ g.output( :path => '/usr/local/bin/', :png => "#{$0}.png" )
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift( "../lib" );
4
+ require "graphviz"
5
+
6
+ g = nil
7
+ if ARGV[0]
8
+ g = GraphViz::new( "G", "path" => ARGV[0] )
9
+ else
10
+ g = GraphViz::new( "G" )
11
+ end
12
+
13
+ g["rankdir"] = "LR"
14
+ g.node["shape"] = "ellipse"
15
+ g.edge["arrowhead"] = "normal"
16
+
17
+ [
18
+ "box",
19
+ "boxbox",
20
+ "lbox",
21
+ "lboxlbox",
22
+ "rbox",
23
+ "rboxrbox",
24
+ "olbox",
25
+ "olboxolbox",
26
+ "orbox",
27
+ "orboxorbox",
28
+ "obox",
29
+ "oboxobox",
30
+ "crow",
31
+ "crowcrow",
32
+ "lcrow",
33
+ "lcrowlcrow",
34
+ "rcrow",
35
+ "rcrowrcrow",
36
+ "diamond",
37
+ "diamonddiamond",
38
+ "ldiamond",
39
+ "ldiamondldiamond",
40
+ "rdiamond",
41
+ "rdiamondrdiamond",
42
+ "oldiamond",
43
+ "oldiamondoldiamond",
44
+ "ordiamond",
45
+ "ordiamondordiamond",
46
+ "odiamond",
47
+ "odiamondodiamond",
48
+ "dot",
49
+ "dotdot",
50
+ "odot",
51
+ "odotodot",
52
+ "inv",
53
+ "invinv",
54
+ "linv",
55
+ "linvlinv",
56
+ "rinv",
57
+ "rinvrinv",
58
+ "olinv",
59
+ "olinvolinv",
60
+ "orinv",
61
+ "orinvorinv",
62
+ "oinv",
63
+ "oinvoinv",
64
+ "none",
65
+ "nonenone",
66
+ "normal",
67
+ "normalnormal",
68
+ "lnormal",
69
+ "lnormallnormal",
70
+ "rnormal",
71
+ "rnormalrnormal",
72
+ "olnormal",
73
+ "olnormalolnormal",
74
+ "ornormal",
75
+ "ornormalornormal",
76
+ "onormal",
77
+ "onormalonormal",
78
+ "tee",
79
+ "teetee",
80
+ "ltee",
81
+ "lteeltee",
82
+ "rtee",
83
+ "rteertee",
84
+ "vee",
85
+ "veevee",
86
+ "lvee",
87
+ "lveelvee",
88
+ "rvee",
89
+ "rveervee"
90
+ ].each { |s|
91
+ p = "p_" << s
92
+ g.add_node( p, "shape" => "point" )
93
+ g.add_node( s )
94
+ g.add_edge( p, s, "arrowhead" => s )
95
+ }
96
+
97
+ g.output( :png => "#{$0}.png" )
@@ -0,0 +1,31 @@
1
+ digraph G {
2
+
3
+ subgraph cluster_0 {
4
+ style=filled;
5
+ color=lightgrey;
6
+ node [style=filled,color=white];
7
+ a0 -> a1;
8
+ a1 -> a2;
9
+ a2 -> a3;
10
+ label = "process #1";
11
+ }
12
+
13
+ subgraph cluster_1 {
14
+ node [style=filled];
15
+ b0 -> b1;
16
+ b1 -> b2;
17
+ b2 -> b3;
18
+ label = "process #2";
19
+ color=blue;
20
+ }
21
+ start -> a0;
22
+ start -> b0;
23
+ a1 -> b3;
24
+ b2 -> a3;
25
+ a3 -> a0;
26
+ a3 -> end;
27
+ b3 -> end;
28
+
29
+ start [shape=Mdiamond];
30
+ end [shape=Msquare];
31
+ }
@@ -0,0 +1,20 @@
1
+ digraph finite_state_machine {
2
+ rankdir=LR;
3
+ size="8,5";
4
+ node [shape = doublecircle]; LR_0; LR_3; LR_4; LR_8;
5
+ node [shape = circle];
6
+ LR_0 -> LR_2 [ label = "SS(B)" ];
7
+ LR_0 -> LR_1 [ label = "SS(S)" ];
8
+ LR_1 -> LR_3 [ label = "S($end)" ];
9
+ LR_2 -> LR_6 [ label = "SS(b)" ];
10
+ LR_2 -> LR_5 [ label = "SS(a)" ];
11
+ LR_2 -> LR_4 [ label = "S(A)" ];
12
+ LR_5 -> LR_7 [ label = "S(b)" ];
13
+ LR_5 -> LR_5 [ label = "S(a)" ];
14
+ LR_6 -> LR_6 [ label = "S(b)" ];
15
+ LR_6 -> LR_5 [ label = "S(a)" ];
16
+ LR_7 -> LR_8 [ label = "S(b)" ];
17
+ LR_7 -> LR_5 [ label = "S(a)" ];
18
+ LR_8 -> LR_6 [ label = "S(b)" ];
19
+ LR_8 -> LR_5 [ label = "S(a)" ];
20
+ }
@@ -0,0 +1,118 @@
1
+ graph ""
2
+ {
3
+ 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)))))";
4
+
5
+ subgraph cluster01
6
+ {
7
+ label="(+ (* (X) (- (- (X) (X)) (X))) (% (+ (X) (X)) (COS (- (X) (X)))))";
8
+ n002 ;
9
+ n002 [label="+"] ;
10
+ n002 -- n003 ;
11
+ n003 [label="*"] ;
12
+ n003 -- n004 ;
13
+ n004 [label="X"] ;
14
+ n003 -- n005 ;
15
+ n005 [label="-"] ;
16
+ n005 -- n006 ;
17
+ n006 [label="-"] ;
18
+ n006 -- n007 ;
19
+ n007 [label="X"] ;
20
+ n006 -- n008 ;
21
+ n008 [label="X"] ;
22
+ n005 -- n009 ;
23
+ n009 [label="X"] ;
24
+ n002 -- n010 ;
25
+ n010 [label="%"] ;
26
+ n010 -- n011 ;
27
+ n011 [label="+"] ;
28
+ n011 -- n012 ;
29
+ n012 [label="X"] ;
30
+ n011 -- n013 ;
31
+ n013 [label="X"] ;
32
+ n010 -- n014 ;
33
+ n014 [label="COS"] ;
34
+ n014 -- n015 ;
35
+ n015 [label="-"] ;
36
+ n015 -- n016 ;
37
+ n016 [label="X"] ;
38
+ n015 -- n017 ;
39
+ n017 [label="X"] ;
40
+ }
41
+
42
+ subgraph cluster17
43
+ {
44
+ label="(EXP (* (X) (X)))";
45
+ n018 ;
46
+ n018 [label="EXP"] ;
47
+ n018 -- n019 ;
48
+ n019 [label="*"] ;
49
+ n019 -- n020 ;
50
+ n020 [label="X"] ;
51
+ n019 -- n021 ;
52
+ n021 [label="X"] ;
53
+ }
54
+
55
+ subgraph cluster21
56
+ {
57
+ label="(+ (% (EXP (SIN (+ (X) (X)))) (SIN (* (X) (EXP (* (X) (X)))))) (* (X) (X)))";
58
+ n022 ;
59
+ n022 [label="+"] ;
60
+ n022 -- n023 ;
61
+ n023 [label="%"] ;
62
+ n023 -- n024 ;
63
+ n024 [label="EXP"] ;
64
+ n024 -- n025 ;
65
+ n025 [label="SIN"] ;
66
+ n025 -- n026 ;
67
+ n026 [label="+"] ;
68
+ n026 -- n027 ;
69
+ n027 [label="X"] ;
70
+ n026 -- n028 ;
71
+ n028 [label="X"] ;
72
+ n023 -- n029 ;
73
+ n029 [label="SIN"] ;
74
+ n029 -- n030 ;
75
+ n030 [label="*"] ;
76
+ n030 -- n031 ;
77
+ n031 [label="X"] ;
78
+ n030 -- n032 ;
79
+ n032 [label="EXP"] ;
80
+ n032 -- n033 ;
81
+ n033 [label="*"] ;
82
+ n033 -- n034 ;
83
+ n034 [label="X"] ;
84
+ n033 -- n035 ;
85
+ n035 [label="X"] ;
86
+ n022 -- n036 ;
87
+ n036 [label="*"] ;
88
+ n036 -- n037 ;
89
+ n037 [label="X"] ;
90
+ n036 -- n038 ;
91
+ n038 [label="X"] ;
92
+ }
93
+
94
+ subgraph cluster38
95
+ {
96
+ label="(% (EXP (% (X) (% (X) (X)))) (EXP (SIN (X))))";
97
+ n039 ;
98
+ n039 [label="%"] ;
99
+ n039 -- n040 ;
100
+ n040 [label="EXP"] ;
101
+ n040 -- n041 ;
102
+ n041 [label="%"] ;
103
+ n041 -- n042 ;
104
+ n042 [label="X"] ;
105
+ n041 -- n043 ;
106
+ n043 [label="%"] ;
107
+ n043 -- n044 ;
108
+ n044 [label="X"] ;
109
+ n043 -- n045 ;
110
+ n045 [label="X"] ;
111
+ n039 -- n046 ;
112
+ n046 [label="EXP"] ;
113
+ n046 -- n047 ;
114
+ n047 [label="SIN"] ;
115
+ n047 -- n048 ;
116
+ n048 [label="X"] ;
117
+ }
118
+ }