ruby-graphviz 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +9 -1
- data/README.rdoc +67 -0
- data/examples/dot/cluster.dot +31 -0
- data/examples/dot/fsm.dot +20 -0
- data/examples/dot/genetic.dot +118 -0
- data/examples/dot/hello.dot +1 -0
- data/examples/dot/hello_test.rb +14 -0
- data/examples/dot/lion_share.dot +103 -0
- data/examples/dot/prof.dot +150 -0
- data/examples/dot/psg.dot +28 -0
- data/examples/dot/sdh.dot +284 -0
- data/examples/dot/siblings.dot +492 -0
- data/examples/dot/test.dot +17 -0
- data/examples/dot/unix.dot +104 -0
- data/examples/graphviz.org/TrafficLights.rb +62 -0
- data/examples/graphviz.org/cluster.rb +62 -0
- data/examples/graphviz.org/hello_world.rb +10 -0
- data/examples/graphviz.org/lion_share.rb +215 -0
- data/examples/graphviz.org/process.rb +37 -0
- data/examples/maketest.sh +0 -0
- data/examples/sample01.rb +1 -1
- data/examples/sample02.rb +3 -3
- data/examples/sample03.rb +3 -3
- data/examples/sample04.rb +3 -3
- data/examples/sample05.rb +1 -1
- data/examples/sample06.rb +46 -0
- data/examples/sample07.rb +2 -2
- data/examples/sample08.rb +3 -3
- data/examples/sample09.rb +3 -3
- data/examples/sample10.rb +3 -3
- data/examples/sample21.rb +12 -0
- data/examples/sample22.rb +10 -0
- data/lib/graphviz.rb +91 -16
- data/lib/graphviz/attrs.rb +2 -2
- data/lib/graphviz/constants.rb +1 -1
- data/lib/graphviz/dot.treetop +93 -0
- data/lib/graphviz/edge.rb +13 -1
- data/lib/graphviz/node.rb +5 -1
- data/lib/graphviz/parser.rb +244 -0
- metadata +42 -10
- data/README +0 -13
@@ -0,0 +1,37 @@
|
|
1
|
+
# http://www.graphviz.org/Gallery/undirected/process.html
|
2
|
+
#
|
3
|
+
# graph G {
|
4
|
+
# run -- intr;
|
5
|
+
# intr -- runbl;
|
6
|
+
# runbl -- run;
|
7
|
+
# run -- kernel;
|
8
|
+
# kernel -- zombie;
|
9
|
+
# kernel -- sleep;
|
10
|
+
# kernel -- runmem;
|
11
|
+
# sleep -- swap;
|
12
|
+
# swap -- runswap;
|
13
|
+
# runswap -- new;
|
14
|
+
# runswap -- runmem;
|
15
|
+
# new -- runmem;
|
16
|
+
# sleep -- runmem;
|
17
|
+
# }
|
18
|
+
|
19
|
+
$:.unshift( "../../lib" );
|
20
|
+
require "graphviz"
|
21
|
+
|
22
|
+
GraphViz::new( :G, :type => :graph ) { |g|
|
23
|
+
g._new[:label] = "new"
|
24
|
+
g.run << g.intr
|
25
|
+
g.intr << g.runbl
|
26
|
+
g.runbl << g.run
|
27
|
+
g.run << g.kernel
|
28
|
+
g.kernel << g.zombie
|
29
|
+
g.kernel << g.sleep
|
30
|
+
g.kernel << g.runmem
|
31
|
+
g.sleep << g.swap
|
32
|
+
g.swap << g.runswap
|
33
|
+
g.runswap << g._new
|
34
|
+
g.runswap << g.runmem
|
35
|
+
g._new << g.runmem
|
36
|
+
g.sleep << g.runmem
|
37
|
+
}.output( :output => :png, :file => "process.png", :use => :fdp )
|
data/examples/maketest.sh
CHANGED
File without changes
|
data/examples/sample01.rb
CHANGED
data/examples/sample02.rb
CHANGED
@@ -5,9 +5,9 @@ require "graphviz"
|
|
5
5
|
|
6
6
|
g = nil
|
7
7
|
if ARGV[0]
|
8
|
-
g = GraphViz::new( "G", :
|
8
|
+
g = GraphViz::new( "G", :path => ARGV[0] )
|
9
9
|
else
|
10
|
-
g = GraphViz::new( "G"
|
10
|
+
g = GraphViz::new( "G" )
|
11
11
|
end
|
12
12
|
|
13
13
|
g.node[:shape] = "ellipse"
|
@@ -39,4 +39,4 @@ g.add_edge( init, make_string )
|
|
39
39
|
g.add_edge( main, printf, :color => "red", :style => "bold", :label => "100 times" )
|
40
40
|
g.add_edge( execute, compare, :color => "red" )
|
41
41
|
|
42
|
-
g.output( :
|
42
|
+
g.output( :png => "#{$0}.png" )
|
data/examples/sample03.rb
CHANGED
@@ -5,9 +5,9 @@ require "graphviz"
|
|
5
5
|
|
6
6
|
g = nil
|
7
7
|
if ARGV[0]
|
8
|
-
g = GraphViz::new( "G", "
|
8
|
+
g = GraphViz::new( "G", "path" => ARGV[0] )
|
9
9
|
else
|
10
|
-
g = GraphViz::new( "G"
|
10
|
+
g = GraphViz::new( "G" )
|
11
11
|
end
|
12
12
|
|
13
13
|
g.node["shape"] = "ellipse"
|
@@ -28,4 +28,4 @@ g.add_edge( a, b )
|
|
28
28
|
g.add_edge( b, c )
|
29
29
|
g.add_edge( b, d )
|
30
30
|
|
31
|
-
g.output( :
|
31
|
+
g.output( :png => "#{$0}.png" )
|
data/examples/sample04.rb
CHANGED
@@ -5,9 +5,9 @@ require "graphviz"
|
|
5
5
|
|
6
6
|
g = nil
|
7
7
|
if ARGV[0]
|
8
|
-
g = GraphViz::new( "structs", "
|
8
|
+
g = GraphViz::new( "structs", "path" => ARGV[0] )
|
9
9
|
else
|
10
|
-
g = GraphViz::new( "structs"
|
10
|
+
g = GraphViz::new( "structs" )
|
11
11
|
end
|
12
12
|
|
13
13
|
g.node["shape"] = "record"
|
@@ -19,4 +19,4 @@ struct3 = g.add_node( "struct3", "shape" => "record", "label" => 'hello\nworld |
|
|
19
19
|
g.add_edge( struct1, struct2 )
|
20
20
|
g.add_edge( struct1, struct3 )
|
21
21
|
|
22
|
-
g.output( :
|
22
|
+
g.output( :png => "#{$0}.png" )
|
data/examples/sample05.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
$:.unshift( "../lib" );
|
2
|
+
require "graphviz"
|
3
|
+
|
4
|
+
GraphViz::new( "G", :rankdir => "LR", :type => "graph" ) { |graph|
|
5
|
+
graph.cluster0 { |cluster|
|
6
|
+
cluster[:label] = "Back Office"
|
7
|
+
|
8
|
+
cluster.fatman.set { |n|
|
9
|
+
n.label = "FatMan"
|
10
|
+
n.shape = "rect"
|
11
|
+
}
|
12
|
+
cluster.grobil.set { |n|
|
13
|
+
n.label = "GroBil"
|
14
|
+
n.shape = "rect"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
graph.cluster1 { |cluster|
|
19
|
+
cluster[:label] = "DMZ"
|
20
|
+
|
21
|
+
cluster.dupont.set { |n|
|
22
|
+
n.label = "Dupont"
|
23
|
+
n.shape = "rect"
|
24
|
+
}
|
25
|
+
cluster.dupond.set { |n|
|
26
|
+
n.label = "Dupond"
|
27
|
+
n.shape = "rect"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
graph.cluster2() { |cluster|
|
32
|
+
cluster[:label] = "Front Office"
|
33
|
+
|
34
|
+
cluster.door.set { |n|
|
35
|
+
n.label = "Door"
|
36
|
+
n.shape = "rect"
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
graph.cluster0.fatman << graph.cluster1.dupont
|
41
|
+
graph.cluster0.fatman << graph.cluster1.dupond
|
42
|
+
graph.cluster0.grobil << graph.cluster1.dupont
|
43
|
+
graph.cluster0.grobil << graph.cluster1.dupond
|
44
|
+
graph.cluster1.dupont << graph.cluster2.door
|
45
|
+
graph.cluster1.dupond << graph.cluster2.door
|
46
|
+
}.output( :path => '/usr/local/bin/', :png => "#{$0}.png" )
|
data/examples/sample07.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
$:.unshift( "../lib" );
|
4
4
|
require "graphviz"
|
5
5
|
|
6
|
-
GraphViz::options( :
|
6
|
+
GraphViz::options( :use => "dot" )
|
7
7
|
|
8
8
|
if ARGV[0]
|
9
9
|
GraphViz::options( :path => ARGV[0] )
|
@@ -20,4 +20,4 @@ g.add_node( "struct3", "shape" => "record", "label" => 'hello\nworld |{ b |{c|<h
|
|
20
20
|
g.add_edge( "struct1:f1", "struct2:f0" )
|
21
21
|
g.add_edge( "struct1:f2", "struct3:here" )
|
22
22
|
|
23
|
-
g.output( :
|
23
|
+
g.output( :png => "#{$0}.png" )
|
data/examples/sample08.rb
CHANGED
@@ -5,9 +5,9 @@ require "graphviz"
|
|
5
5
|
|
6
6
|
g = nil
|
7
7
|
if ARGV[0]
|
8
|
-
g = GraphViz::new( "G"
|
8
|
+
g = GraphViz::new( "G" "nodesep" => ".05", "rankdir" => "LR", "path" => ARGV[0] )
|
9
9
|
else
|
10
|
-
g = GraphViz::new( "G", "
|
10
|
+
g = GraphViz::new( "G", "nodesep" => ".05", "rankdir" => "LR" )
|
11
11
|
end
|
12
12
|
|
13
13
|
g.node["shape"] = "record"
|
@@ -31,4 +31,4 @@ g.add_edge( "node0:f6", "node5:n" )
|
|
31
31
|
g.add_edge( "node2:p", "node6:n" )
|
32
32
|
g.add_edge( "node4:p", "node7:n" )
|
33
33
|
|
34
|
-
g.output( :
|
34
|
+
g.output( :png => "#{$0}.png" )
|
data/examples/sample09.rb
CHANGED
@@ -5,9 +5,9 @@ require "graphviz"
|
|
5
5
|
|
6
6
|
g = nil
|
7
7
|
if ARGV[0]
|
8
|
-
g = GraphViz::new( "G", "
|
8
|
+
g = GraphViz::new( "G", "path" => ARGV[0] )
|
9
9
|
else
|
10
|
-
g = GraphViz::new( "G"
|
10
|
+
g = GraphViz::new( "G" )
|
11
11
|
end
|
12
12
|
|
13
13
|
g.node["shape"] = "ellipse"
|
@@ -47,4 +47,4 @@ g.add_edge( a3, a0 )
|
|
47
47
|
g.add_edge( a3, endn )
|
48
48
|
g.add_edge( b3, endn )
|
49
49
|
|
50
|
-
g.output( :
|
50
|
+
g.output( :png => "#{$0}.png" )
|
data/examples/sample10.rb
CHANGED
@@ -5,9 +5,9 @@ require "graphviz"
|
|
5
5
|
|
6
6
|
g = nil
|
7
7
|
if ARGV[0]
|
8
|
-
g = GraphViz::new( "G", "
|
8
|
+
g = GraphViz::new( "G", "path" => ARGV[0] )
|
9
9
|
else
|
10
|
-
g = GraphViz::new( "G"
|
10
|
+
g = GraphViz::new( "G" )
|
11
11
|
end
|
12
12
|
|
13
13
|
g.node["shape"] = "ellipse"
|
@@ -47,4 +47,4 @@ g.add_edge( a3, a0 )
|
|
47
47
|
g.add_edge( a3, endn )
|
48
48
|
g.add_edge( b3, endn )
|
49
49
|
|
50
|
-
g.output( :
|
50
|
+
g.output( :png => "#{$0}.png" )
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift( "../lib" );
|
4
|
+
require "graphviz"
|
5
|
+
|
6
|
+
{"png" => "#{$0}.png", "imap" => "#{$0}.html"}.each do |format, file|
|
7
|
+
GraphViz::new( "G", :output => format ) { |g|
|
8
|
+
g.command #(:URL => "http://www.research.att.com/base.html")
|
9
|
+
g._output(:label => "output") #(:URL => "colors.html")
|
10
|
+
g.command << g._output
|
11
|
+
}.output( :file => file )
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift( "../lib" );
|
4
|
+
require "graphviz"
|
5
|
+
|
6
|
+
GraphViz::new( "mainmap" ) { |graph|
|
7
|
+
graph[:URL] = "http://www.research.att.com/base.html"
|
8
|
+
graph.command( :URL => "http://www.research.att.com/command.html" )
|
9
|
+
(graph.command << graph._output( :label => "output" ))[:URL] = "colors.html"
|
10
|
+
}.output( :canon => nil, :cmapx => "#{$0}.html", :png => "#{$0}.png" )
|
data/lib/graphviz.rb
CHANGED
@@ -21,6 +21,7 @@ require 'graphviz/node'
|
|
21
21
|
require 'graphviz/edge'
|
22
22
|
require 'graphviz/attrs'
|
23
23
|
require 'graphviz/constants'
|
24
|
+
require 'graphviz/parser'
|
24
25
|
|
25
26
|
class GraphViz
|
26
27
|
include Constants
|
@@ -28,10 +29,12 @@ class GraphViz
|
|
28
29
|
public
|
29
30
|
|
30
31
|
## Var: Output format (dot, png, jpeg, ...)
|
31
|
-
@@format = "canon"
|
32
|
+
@@format = nil #"canon"
|
32
33
|
@format
|
33
34
|
## Var: Output file name
|
34
35
|
@filename
|
36
|
+
## Var: Output format and file
|
37
|
+
@output
|
35
38
|
## Var: program to use (dot|twopi)
|
36
39
|
@@prog = "dot"
|
37
40
|
@prog
|
@@ -46,7 +49,12 @@ class GraphViz
|
|
46
49
|
@graph
|
47
50
|
@node
|
48
51
|
@edge
|
49
|
-
|
52
|
+
|
53
|
+
# This accessor allow you to set global nodes attributs
|
54
|
+
attr_accessor :node
|
55
|
+
|
56
|
+
# This accessor allow you to set global edges attributs
|
57
|
+
attr_accessor :edge
|
50
58
|
|
51
59
|
@elements_order
|
52
60
|
|
@@ -77,6 +85,17 @@ class GraphViz
|
|
77
85
|
return( @hoNodes[xNodeName] )
|
78
86
|
end
|
79
87
|
|
88
|
+
#
|
89
|
+
# Return the node object for the given name (or nil)
|
90
|
+
#
|
91
|
+
def get_node( xNodeName, &block )
|
92
|
+
node = @hoNodes[xNodeName] || nil
|
93
|
+
|
94
|
+
yield( node ) if( block and node.nil? == false )
|
95
|
+
|
96
|
+
return node
|
97
|
+
end
|
98
|
+
|
80
99
|
##
|
81
100
|
# Create a new edge
|
82
101
|
#
|
@@ -142,6 +161,17 @@ class GraphViz
|
|
142
161
|
return( @hoGraphs[xGraphName] )
|
143
162
|
end
|
144
163
|
|
164
|
+
#
|
165
|
+
# Return the graph object for the given name (or nil)
|
166
|
+
#
|
167
|
+
def get_graph( xGraphName, &block )
|
168
|
+
graph = @hoGraphs[xGraphName] || nil
|
169
|
+
|
170
|
+
yield( graph ) if( block and graph.nil? == false )
|
171
|
+
|
172
|
+
return graph
|
173
|
+
end
|
174
|
+
|
145
175
|
#
|
146
176
|
# Get the number of nodes
|
147
177
|
#
|
@@ -186,6 +216,7 @@ class GraphViz
|
|
186
216
|
# Set value +xValue+ to the graph attribut +xAttrName+
|
187
217
|
#
|
188
218
|
def []=( xAttrName, xValue )
|
219
|
+
xValue = xValue.to_s if xValue.class == Symbol
|
189
220
|
@graph[xAttrName] = xValue
|
190
221
|
end
|
191
222
|
|
@@ -204,6 +235,7 @@ class GraphViz
|
|
204
235
|
# :file : Output file name
|
205
236
|
# :use : Program to use (Constants::PROGRAMS)
|
206
237
|
# :path : Program PATH
|
238
|
+
# :<format> => :<file>
|
207
239
|
#
|
208
240
|
def output( *hOpt )
|
209
241
|
xDOTScript = ""
|
@@ -288,13 +320,16 @@ class GraphViz
|
|
288
320
|
else
|
289
321
|
if hOpt.nil? == false and hOpt[0].nil? == false
|
290
322
|
hOpt[0].each do |xKey, xValue|
|
323
|
+
xValue = xValue.to_s unless xValue.nil?
|
291
324
|
case xKey.to_s
|
292
325
|
when "output"
|
326
|
+
warn ":output option is deprecated, please use :<format> => :<file>"
|
293
327
|
if FORMATS.index( xValue ).nil? == true
|
294
328
|
raise ArgumentError, "output format '#{xValue}' invalid"
|
295
329
|
end
|
296
330
|
@format = xValue
|
297
331
|
when "file"
|
332
|
+
warn ":file option is deprecated, please use :<format> => :<file>"
|
298
333
|
@filename = xValue
|
299
334
|
when "use"
|
300
335
|
if PROGRAMS.index( xValue ).nil? == true
|
@@ -304,7 +339,10 @@ class GraphViz
|
|
304
339
|
when "path"
|
305
340
|
@path = xValue
|
306
341
|
else
|
307
|
-
|
342
|
+
if FORMATS.index( xKey.to_s ).nil? == true
|
343
|
+
raise ArgumentError, "output format '#{xValue}' invalid"
|
344
|
+
end
|
345
|
+
@output[xKey.to_s] = xValue
|
308
346
|
end
|
309
347
|
end
|
310
348
|
end
|
@@ -324,9 +362,24 @@ class GraphViz
|
|
324
362
|
raise StandardError, "GraphViz not installed or #{@prog} not in PATH. Install GraphViz or use the 'path' option"
|
325
363
|
end
|
326
364
|
|
327
|
-
|
328
|
-
|
329
|
-
|
365
|
+
xOutputWithFile = ""
|
366
|
+
xOutputWithoutFile = ""
|
367
|
+
unless @format.nil?
|
368
|
+
if @filename.nil?
|
369
|
+
xOutputWithoutFile = "-T#{@format} "
|
370
|
+
else
|
371
|
+
xOutputWithFile = "-T#{@format} -o#{@filename} "
|
372
|
+
end
|
373
|
+
end
|
374
|
+
@output.each do |format, file|
|
375
|
+
if file.nil?
|
376
|
+
xOutputWithoutFile << "-T#{format} "
|
377
|
+
else
|
378
|
+
xOutputWithFile << "-T#{format} -o#{file} "
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
xCmd = "#{cmd} #{xOutputWithFile} #{xOutputWithoutFile} #{t.path}"
|
330
383
|
|
331
384
|
f = IO.popen( xCmd )
|
332
385
|
print f.readlines
|
@@ -398,6 +451,7 @@ class GraphViz
|
|
398
451
|
when "path"
|
399
452
|
@@path = v
|
400
453
|
when "output"
|
454
|
+
warn ":output option is deprecated!"
|
401
455
|
@@format = v
|
402
456
|
else
|
403
457
|
warn "Invalide option #{k}!"
|
@@ -409,6 +463,24 @@ class GraphViz
|
|
409
463
|
GraphViz::default( hOpts )
|
410
464
|
end
|
411
465
|
|
466
|
+
## ----------------------------------------------------------------------------
|
467
|
+
|
468
|
+
#
|
469
|
+
# Create a new graph from a GraphViz File
|
470
|
+
#
|
471
|
+
# Options :
|
472
|
+
# :output : Output format (Constants::FORMATS) (default : dot)
|
473
|
+
# :file : Output file name (default : none)
|
474
|
+
# :use : Program to use (Constants::PROGRAMS) (default : dot)
|
475
|
+
# :path : Program PATH
|
476
|
+
# :parent : Parent graph (default : none)
|
477
|
+
# :type : Graph type (Constants::GRAPHTYPE) (default : digraph)
|
478
|
+
#
|
479
|
+
def self.parse( xFile, *hOpts, &block )
|
480
|
+
g = GraphViz::Parser.parse( xFile, hOpts[0], &block )
|
481
|
+
return g
|
482
|
+
end
|
483
|
+
|
412
484
|
## ----------------------------------------------------------------------------
|
413
485
|
|
414
486
|
private
|
@@ -437,10 +509,11 @@ class GraphViz
|
|
437
509
|
#
|
438
510
|
def initialize( xGraphName, *hOpt, &block )
|
439
511
|
@filename = nil
|
440
|
-
@name = xGraphName
|
512
|
+
@name = xGraphName.to_s
|
441
513
|
@format = @@format
|
442
514
|
@prog = @@prog
|
443
515
|
@path = @@path
|
516
|
+
@output = {}
|
444
517
|
|
445
518
|
@elements_order = Array::new()
|
446
519
|
|
@@ -459,28 +532,30 @@ class GraphViz
|
|
459
532
|
hOpt[0].each do |xKey, xValue|
|
460
533
|
case xKey.to_s
|
461
534
|
when "output"
|
462
|
-
|
535
|
+
warn ":output option is deprecated, please use :<format> => :<file>"
|
536
|
+
if FORMATS.index( xValue.to_s ).nil? == true
|
463
537
|
raise ArgumentError, "output format '#{xValue}' invalid"
|
464
538
|
end
|
465
|
-
@format = xValue
|
539
|
+
@format = xValue.to_s
|
466
540
|
when "use"
|
467
|
-
if PROGRAMS.index( xValue ).nil? == true
|
541
|
+
if PROGRAMS.index( xValue.to_s ).nil? == true
|
468
542
|
raise ArgumentError, "can't use '#{xValue}'"
|
469
543
|
end
|
470
|
-
@prog = xValue
|
544
|
+
@prog = xValue.to_s
|
471
545
|
when "file"
|
472
|
-
|
546
|
+
warn ":file option is deprecated, please use :<format> => :<file>"
|
547
|
+
@filename = xValue.to_s
|
473
548
|
when "parent"
|
474
549
|
@oParentGraph = xValue
|
475
550
|
when "type"
|
476
|
-
if GRAPHTYPE.index( xValue ).nil? == true
|
551
|
+
if GRAPHTYPE.index( xValue.to_s ).nil? == true
|
477
552
|
raise ArgumentError, "graph type '#{xValue}' unknow"
|
478
553
|
end
|
479
|
-
@oGraphType = xValue
|
554
|
+
@oGraphType = xValue.to_s
|
480
555
|
when "path"
|
481
|
-
@path = xValue
|
556
|
+
@path = xValue.to_s
|
482
557
|
else
|
483
|
-
self[xKey.to_s] = xValue
|
558
|
+
self[xKey.to_s] = xValue.to_s
|
484
559
|
end
|
485
560
|
end
|
486
561
|
end
|