ruby-graphviz 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +4 -0
- data/bin/dot2ruby +5 -5
- data/bin/gem2gv +18 -18
- data/bin/git2gv +20 -20
- data/bin/ruby2gv +26 -26
- data/bin/xml2gv +5 -5
- data/examples/sample06.rb +5 -5
- data/examples/sample12.rb +3 -3
- data/examples/sample13.rb +8 -8
- data/examples/sample14.rb +8 -8
- data/examples/sample15.rb +1 -1
- data/examples/sample17.rb +7 -7
- data/examples/sample19.rb +10 -10
- data/examples/sample20.rb +2 -2
- data/examples/sample21.rb +1 -1
- data/examples/sample28.rb +1 -1
- data/examples/sample31.rb +1 -1
- data/examples/sample33.rb +10 -10
- data/examples/sample34.rb +1 -1
- data/examples/sample35.rb +7 -7
- data/examples/sample36.rb +2 -2
- data/examples/sample40.rb +4 -4
- data/examples/sample44.rb +72 -72
- data/examples/sample45.rb +4 -4
- data/examples/sample48.rb +7 -7
- data/examples/sample50.rb +1 -1
- data/examples/sample52.rb +2 -2
- data/examples/sample53.rb +2 -2
- data/examples/sample54.rb +3 -3
- data/examples/sample60.rb +2 -2
- data/examples/sample61.rb +2 -2
- data/examples/sample62.rb +2 -2
- data/examples/sample99.rb +15 -15
- data/examples/theory/pert.rb +2 -2
- data/examples/theory/tests.rb +2 -2
- data/lib/graphviz.rb +140 -140
- data/lib/graphviz/attrs.rb +6 -11
- data/lib/graphviz/constants.rb +35 -35
- data/lib/graphviz/core_ext.rb +1 -1
- data/lib/graphviz/dot2ruby.rb +7 -7
- data/lib/graphviz/dsl.rb +5 -5
- data/lib/graphviz/edge.rb +13 -13
- data/lib/graphviz/elements.rb +5 -5
- data/lib/graphviz/ext.rb +1 -1
- data/lib/graphviz/family_tree.rb +15 -15
- data/lib/graphviz/family_tree/couple.rb +11 -11
- data/lib/graphviz/family_tree/generation.rb +6 -6
- data/lib/graphviz/family_tree/person.rb +13 -13
- data/lib/graphviz/graphml.rb +39 -39
- data/lib/graphviz/math/matrix.rb +23 -23
- data/lib/graphviz/node.rb +8 -8
- data/lib/graphviz/nothugly.rb +3 -3
- data/lib/graphviz/theory.rb +8 -8
- data/lib/graphviz/types.rb +3 -3
- data/lib/graphviz/types/arrow_type.rb +3 -3
- data/lib/graphviz/types/color.rb +2 -2
- data/lib/graphviz/types/color_list.rb +2 -2
- data/lib/graphviz/types/esc_string.rb +2 -2
- data/lib/graphviz/types/gv_bool.rb +3 -3
- data/lib/graphviz/types/gv_double.rb +3 -3
- data/lib/graphviz/types/html_string.rb +2 -2
- data/lib/graphviz/types/lbl_string.rb +2 -2
- data/lib/graphviz/types/rect.rb +2 -2
- data/lib/graphviz/types/spline_type.rb +9 -9
- data/lib/graphviz/utils.rb +13 -13
- data/lib/graphviz/utils/colors.rb +35 -35
- data/lib/graphviz/xml.rb +24 -24
- data/setup.rb +4 -4
- data/test/test_graph.rb +9 -9
- data/test/test_subgraph.rb +1 -1
- data/test/test_theory.rb +4 -4
- data/test/test_utils_colors.rb +4 -4
- metadata +2 -2
data/examples/sample45.rb
CHANGED
@@ -12,10 +12,10 @@ end
|
|
12
12
|
|
13
13
|
g.node["shape"] = "ellipse"
|
14
14
|
|
15
|
-
[ "box", "polygon", "ellipse", "circle", "point",
|
16
|
-
"egg", "triangle", "plaintext", "diamond", "trapezium",
|
17
|
-
"parallelogram", "house", "pentagon", "hexagon", "septagon", "octagon", "doublecircle",
|
18
|
-
"doubleoctagon", "tripleoctagon", "invtriangle", "invtrapezium", "invhouse",
|
15
|
+
[ "box", "polygon", "ellipse", "circle", "point",
|
16
|
+
"egg", "triangle", "plaintext", "diamond", "trapezium",
|
17
|
+
"parallelogram", "house", "pentagon", "hexagon", "septagon", "octagon", "doublecircle",
|
18
|
+
"doubleoctagon", "tripleoctagon", "invtriangle", "invtrapezium", "invhouse",
|
19
19
|
"Mdiamond", "Msquare", "Mcircle", "rect", "rectangle", "none", "note", "tab", "folder",
|
20
20
|
"box3d", "component" ].each { |s|
|
21
21
|
g.add_nodes( s, "shape" => s )
|
data/examples/sample48.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# http://www.graphviz.org/Gallery/directed/cluster.html
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# digraph G {
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# subgraph cluster_0 {
|
6
6
|
# style=filled;
|
7
7
|
# color=lightgrey;
|
@@ -9,7 +9,7 @@
|
|
9
9
|
# a0 -> a1 -> a2 -> a3;
|
10
10
|
# label = "process #1";
|
11
11
|
# }
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# subgraph cluster_1 {
|
14
14
|
# node [style=filled];
|
15
15
|
# b0 -> b1 -> b2 -> b3;
|
@@ -23,7 +23,7 @@
|
|
23
23
|
# a3 -> a0;
|
24
24
|
# a3 -> end;
|
25
25
|
# b3 -> end;
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# start [shape=Mdiamond];
|
28
28
|
# end [shape=Msquare];
|
29
29
|
# }
|
@@ -40,14 +40,14 @@ GraphViz.new( :G, :type => :digraph ) { |g|
|
|
40
40
|
c.a0 << c.a1 << c.a2 << c.a3
|
41
41
|
c[:label] = "process #1"
|
42
42
|
}
|
43
|
-
|
43
|
+
|
44
44
|
g.cluster_1 { |c|
|
45
45
|
c.node[:style] = :filled
|
46
46
|
c.b0 << c.b1 << c.b2 << c.b3
|
47
47
|
c[:label] = "process #1"
|
48
48
|
c[:color] = :blue
|
49
49
|
}
|
50
|
-
|
50
|
+
|
51
51
|
g.start << g.cluster_0.a0
|
52
52
|
g.start << g.cluster_1.b0
|
53
53
|
g.cluster_0.a1 << g.cluster_1.b3
|
@@ -55,7 +55,7 @@ GraphViz.new( :G, :type => :digraph ) { |g|
|
|
55
55
|
g.cluster_0.a3 << g.cluster_0.a0
|
56
56
|
g.cluster_0.a3 << g._end
|
57
57
|
g.cluster_1.b3 << g._end
|
58
|
-
|
58
|
+
|
59
59
|
g.start[:shape] = :Mdiamond
|
60
60
|
g._end[:label] = "end"
|
61
61
|
g._end[:shape] = :Mdiamond
|
data/examples/sample50.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# ratio = "auto" ;
|
6
6
|
# mincross = 2.0 ;
|
7
7
|
# label = "Pedigree Lion_Share" ;
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# "001" [shape=box , regular=1,style=filled,fillcolor=white ] ;
|
10
10
|
# "002" [shape=box , regular=1,style=filled,fillcolor=white ] ;
|
11
11
|
# "003" [shape=circle , regular=1,style=filled,fillcolor=white ] ;
|
data/examples/sample52.rb
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
# green1->gy1;
|
20
20
|
# yellow1->yr1;
|
21
21
|
# red1->rg1;
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# overlap=false
|
24
24
|
# label="PetriNet Model TrafficLights\nExtracted from ConceptBase and layed out by Graphviz"
|
25
25
|
# fontsize=12;
|
@@ -38,7 +38,7 @@ GraphViz::new( "TrafficLights", :type => :digraph ) { |g|
|
|
38
38
|
g.green1.set { |n| n[:shape] = :circle; n[:fixedsize] = :true; n[:width] = 0.9 }
|
39
39
|
g.yellow1.set { |n| n[:shape] = :circle; n[:fixedsize] = :true; n[:width] = 0.9 }
|
40
40
|
g.red1.set { |n| n[:shape] = :circle; n[:fixedsize] = :true; n[:width] = 0.9 }
|
41
|
-
|
41
|
+
|
42
42
|
g.gy2 << g.yellow2
|
43
43
|
g.rg2 << g.green2
|
44
44
|
g.yr2 << g.safe1
|
data/examples/sample53.rb
CHANGED
@@ -5,7 +5,7 @@ tree = GraphViz::FamilyTree.new do
|
|
5
5
|
generation do
|
6
6
|
benoist.is_a_man( "Benoist" )
|
7
7
|
nathalie.is_a_woman( "Nathalie" )
|
8
|
-
|
8
|
+
|
9
9
|
benoist.is_maried_with nathalie
|
10
10
|
end
|
11
11
|
|
@@ -14,7 +14,7 @@ tree = GraphViz::FamilyTree.new do
|
|
14
14
|
amelie.is_a_woman( "Amelie" )
|
15
15
|
clement.is_a_man( "Clement" )
|
16
16
|
gregoire.is_a_man( "Gregoire" )
|
17
|
-
|
17
|
+
|
18
18
|
muriel.is_a_woman( "Muriel" )
|
19
19
|
|
20
20
|
gregoire.is_maried_with muriel
|
data/examples/sample54.rb
CHANGED
@@ -6,10 +6,10 @@ class Array
|
|
6
6
|
## Solution #1 by greg
|
7
7
|
# self.push(r = self.shift)
|
8
8
|
# return r
|
9
|
-
|
9
|
+
|
10
10
|
## Solution #2 by madx
|
11
11
|
# shift.tap {|e| push e }
|
12
|
-
|
12
|
+
|
13
13
|
## Solution #3 by greg
|
14
14
|
push(shift)[-1]
|
15
15
|
end
|
@@ -22,5 +22,5 @@ GraphViz.graph( :G, :use => :neato ) { |g|
|
|
22
22
|
(1..5).each do |y|
|
23
23
|
g.add_nodes( "n#{x}x#{y}", :pos => "#{x},#{y}!", :shape => type.rotate )
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
26
26
|
}.output( :png => "#{$0}.png" )
|
data/examples/sample60.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
$:.unshift( "../lib" );
|
4
4
|
require "graphviz"
|
5
5
|
|
6
|
-
asm = GraphViz::new( "My ASM" )
|
6
|
+
asm = GraphViz::new( "My ASM" )
|
7
7
|
|
8
8
|
my = asm.add_nodes("My")
|
9
9
|
asmn = asm.add_nodes("ASM")
|
10
|
-
asm.add_edges(my, asmn)
|
10
|
+
asm.add_edges(my, asmn)
|
11
11
|
|
12
12
|
asm.output( :png => "#{$0}.png" )
|
data/examples/sample61.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
$:.unshift( "../lib" );
|
4
4
|
require "graphviz"
|
5
5
|
|
6
|
-
asm = GraphViz::new( "" )
|
6
|
+
asm = GraphViz::new( "" )
|
7
7
|
|
8
8
|
my = asm.add_nodes("My")
|
9
9
|
asmn = asm.add_nodes("ASM")
|
10
|
-
asm.add_edges(my, asmn)
|
10
|
+
asm.add_edges(my, asmn)
|
11
11
|
|
12
12
|
asm.output( :png => "#{$0}.png" )
|
data/examples/sample62.rb
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
$:.unshift( "../lib" );
|
4
4
|
require "graphviz"
|
5
5
|
|
6
|
-
hello_world = GraphViz::new( "" )
|
6
|
+
hello_world = GraphViz::new( "" )
|
7
7
|
|
8
8
|
hello = hello_world.add_nodes("Hello")
|
9
9
|
world = hello_world.add_nodes("World")
|
10
|
-
hello_world.add_edges(hello, world)
|
10
|
+
hello_world.add_edges(hello, world)
|
11
11
|
|
12
12
|
# final_graph = GraphViz.parse_string( hello_world.output( :dot => String ) )
|
13
13
|
# final_graph.each_node do |_, node|
|
data/examples/sample99.rb
CHANGED
@@ -5,53 +5,53 @@ tree = GraphViz::FamilyTree.new do
|
|
5
5
|
generation do
|
6
6
|
chantale.is_a_woman( "Chantale" )
|
7
7
|
jacques.is_a_man( "Jacques" )
|
8
|
-
|
8
|
+
|
9
9
|
jacques.is_dead
|
10
10
|
jacques.is_maried_with chantale
|
11
|
-
|
11
|
+
|
12
12
|
rose.is_a_woman( "Rose Marie" )
|
13
13
|
andre.is_a_man( "Andre" )
|
14
|
-
|
14
|
+
|
15
15
|
andre.is_maried_with rose
|
16
16
|
andre.is_dead
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
generation do
|
20
20
|
benoist.is_a_man( "Benoist" )
|
21
21
|
nathalie.is_a_woman( "Nathalie" )
|
22
|
-
|
22
|
+
|
23
23
|
benoist.is_maried_with nathalie
|
24
|
-
|
24
|
+
|
25
25
|
michel.is_a_man( "Michel" )
|
26
26
|
brigitte.is_a_woman( "Brigitte" )
|
27
|
-
|
27
|
+
|
28
28
|
michel.is_maried_with brigitte
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
couple( chantale, jacques ).kids( nathalie )
|
32
32
|
couple( rose, andre ).kids( benoist )
|
33
|
-
|
33
|
+
|
34
34
|
generation do
|
35
35
|
charlotte.is_a_woman( "Charlotte" )
|
36
36
|
amelie.is_a_woman( "Amelie" )
|
37
37
|
clement.is_a_man( "Clement" )
|
38
38
|
gregoire.is_a_man( "Gregoire" )
|
39
|
-
|
39
|
+
|
40
40
|
muriel.is_a_woman( "Muriel" )
|
41
41
|
gilles.is_a_man( "Gilles" )
|
42
|
-
|
42
|
+
|
43
43
|
morgane.is_a_woman( "Morgane" )
|
44
44
|
gregoire.is_divorced_with morgane
|
45
45
|
|
46
46
|
pascal.is_a_man( "Pascal" )
|
47
47
|
muriel.is_divorced_with pascal
|
48
48
|
|
49
|
-
gregoire.is_maried_with muriel
|
49
|
+
gregoire.is_maried_with muriel
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
couple( michel, brigitte ).kids( muriel, gilles )
|
53
53
|
couple( benoist, nathalie ).kids( charlotte, amelie, clement, gregoire )
|
54
|
-
|
54
|
+
|
55
55
|
generation do
|
56
56
|
arthur.is_a_boy( "Arthur" )
|
57
57
|
colyne.is_a_girl( "Colyne" )
|
@@ -60,7 +60,7 @@ tree = GraphViz::FamilyTree.new do
|
|
60
60
|
enaitz.is_a_boy( "Enaitz" )
|
61
61
|
milo.is_a_boy( "Milo" )
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
couple( gregoire, morgane ).kids( arthur, colyne, benedict )
|
65
65
|
couple( gregoire, muriel ).kids( maia )
|
66
66
|
couple( muriel, pascal ).kids( milo )
|
data/examples/theory/pert.rb
CHANGED
@@ -4,7 +4,7 @@ require 'graphviz/theory'
|
|
4
4
|
|
5
5
|
g = GraphViz.digraph( "G", :path => "/usr/local/bin", :use => "fdp" ) do |g|
|
6
6
|
g.node[:shape => "record"]
|
7
|
-
|
7
|
+
|
8
8
|
g.start[:label => "Start"]
|
9
9
|
g.task_1[:label => "Task #1 - Duration : 4d"]
|
10
10
|
g.task_2[:label => "Task #2 - Duration : 5.25d"]
|
@@ -14,7 +14,7 @@ g = GraphViz.digraph( "G", :path => "/usr/local/bin", :use => "fdp" ) do |g|
|
|
14
14
|
g.task_6[:label => "Task #6 - Duration : 4.5d"]
|
15
15
|
g.task_7[:label => "Task #7 - Duration : 5.17d"]
|
16
16
|
g.finish[:label => "End"]
|
17
|
-
|
17
|
+
|
18
18
|
(g.start << g.task_1)[:weight => 0.0]
|
19
19
|
(g.start << g.task_2)[:weight => 0.0]
|
20
20
|
(g.task_1 << g.task_3)[:weight => 4.0]
|
data/examples/theory/tests.rb
CHANGED
@@ -9,7 +9,7 @@ g = GraphViz.digraph( "G", :path => "/usr/local/bin" ) do |g|
|
|
9
9
|
g.d[:label => "4"]
|
10
10
|
g.e[:label => "5"]
|
11
11
|
g.f[:label => "6"]
|
12
|
-
|
12
|
+
|
13
13
|
# g.a << g.a
|
14
14
|
g.a << g.b
|
15
15
|
g.a << g.d
|
@@ -82,6 +82,6 @@ rrr = t.critical_path
|
|
82
82
|
print "\tPath "; p rrr[:path]
|
83
83
|
puts "\tDistance : #{rrr[:distance]}"
|
84
84
|
|
85
|
-
t.pagerank.each { |node, rank|
|
85
|
+
t.pagerank.each { |node, rank|
|
86
86
|
puts "Pagerank for node #{node.id} = #{rank}"
|
87
87
|
}
|
data/lib/graphviz.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Copyright (C) 2003 - 2012 Gregoire Lejeune <gregoire.lejeune@free.fr>
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# This program is free software; you can redistribute it and/or modify
|
4
4
|
# it under the terms of the GNU General Public License as published by
|
5
5
|
# the Free Software Foundation; either version 2 of the License, or
|
6
6
|
# (at your option) any later version.
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# This program is distributed in the hope that it will be useful,
|
9
9
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
10
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
11
|
# GNU General Public License for more details.
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# You should have received a copy of the GNU General Public License
|
14
14
|
# along with this program; if not, write to the Free Software
|
15
15
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
@@ -35,7 +35,7 @@ if /^1.8/.match RUBY_VERSION
|
|
35
35
|
$KCODE = "UTF8"
|
36
36
|
end
|
37
37
|
|
38
|
-
class GraphViz
|
38
|
+
class GraphViz
|
39
39
|
include Constants
|
40
40
|
include GVUtils
|
41
41
|
|
@@ -60,7 +60,7 @@ class GraphViz
|
|
60
60
|
## Var: External libraries
|
61
61
|
@@extlibs = []
|
62
62
|
@extlibs
|
63
|
-
|
63
|
+
|
64
64
|
## Var: Graph name
|
65
65
|
@name
|
66
66
|
|
@@ -72,7 +72,7 @@ class GraphViz
|
|
72
72
|
# This accessor allow you to set global graph attributes
|
73
73
|
attr_accessor :graph
|
74
74
|
alias_method :graph_attrs, :graph
|
75
|
-
|
75
|
+
|
76
76
|
# This accessor allow you to set global nodes attributes
|
77
77
|
attr_accessor :node
|
78
78
|
alias_method :node_attrs, :node
|
@@ -82,7 +82,7 @@ class GraphViz
|
|
82
82
|
alias_method :edge_attrs, :edge
|
83
83
|
|
84
84
|
@elements_order
|
85
|
-
|
85
|
+
|
86
86
|
#<b>DEPRECATED</b> please use GraphViz#add_nodes
|
87
87
|
def add_node( xNodeName, hOpts = {} )
|
88
88
|
warn "GraphViz#add_node is deprecated, please use GraphViz#add_nodes"
|
@@ -94,7 +94,7 @@ class GraphViz
|
|
94
94
|
# In:
|
95
95
|
# * xNodeName : Name of the new node
|
96
96
|
# * hOpts : Node attributes
|
97
|
-
#
|
97
|
+
#
|
98
98
|
# Return the GraphViz::Node object created
|
99
99
|
def add_nodes(node_name, options = {})
|
100
100
|
if node_name.kind_of? Array
|
@@ -110,10 +110,10 @@ class GraphViz
|
|
110
110
|
options[:label] = node_name
|
111
111
|
end
|
112
112
|
|
113
|
-
@elements_order.push( {
|
114
|
-
"type" => "node",
|
113
|
+
@elements_order.push( {
|
114
|
+
"type" => "node",
|
115
115
|
"name" => node_name,
|
116
|
-
"value" => @hoNodes[node_name]
|
116
|
+
"value" => @hoNodes[node_name]
|
117
117
|
} )
|
118
118
|
|
119
119
|
node = @hoNodes[node_name]
|
@@ -130,14 +130,14 @@ class GraphViz
|
|
130
130
|
# Return the node object for the given name (or nil) in the current graph
|
131
131
|
def get_node( xNodeName, &block )
|
132
132
|
node = @hoNodes[xNodeName] || nil
|
133
|
-
|
134
|
-
yield( node ) if( block and node
|
135
|
-
|
133
|
+
|
134
|
+
yield( node ) if( block and node )
|
135
|
+
|
136
136
|
return node
|
137
137
|
end
|
138
138
|
|
139
139
|
# Returns the first node found in the entire graph, starting from the root graph
|
140
|
-
def find_node(name)
|
140
|
+
def find_node(name)
|
141
141
|
root = root_graph
|
142
142
|
return root.search_node(name)
|
143
143
|
end
|
@@ -152,7 +152,7 @@ class GraphViz
|
|
152
152
|
}
|
153
153
|
return nil
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
#
|
157
157
|
# Return the node object for the given index
|
158
158
|
#
|
@@ -160,7 +160,7 @@ class GraphViz
|
|
160
160
|
element = @elements_order[index, "node"]
|
161
161
|
(element.nil?) ? nil : element["value"]
|
162
162
|
end
|
163
|
-
|
163
|
+
|
164
164
|
#
|
165
165
|
# Allow you to traverse nodes
|
166
166
|
#
|
@@ -173,12 +173,12 @@ class GraphViz
|
|
173
173
|
return( @hoNodes )
|
174
174
|
end
|
175
175
|
end
|
176
|
-
|
176
|
+
|
177
177
|
# Get the number of nodes
|
178
178
|
def node_count
|
179
179
|
@hoNodes.size
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
#<b>DEPRECATED</b> please use GraphViz#add_edges
|
183
183
|
def add_edge( oNodeOne, oNodeTwo, hOpts = {} )
|
184
184
|
warn "GraphViz#add_edge is deprecated, please use GraphViz#add_edges"
|
@@ -186,14 +186,14 @@ class GraphViz
|
|
186
186
|
end
|
187
187
|
|
188
188
|
# Create a new edge
|
189
|
-
#
|
189
|
+
#
|
190
190
|
# In:
|
191
191
|
# * node_one : First node (or node list)
|
192
192
|
# * node_two : Second Node (or node list)
|
193
193
|
# * options : Edge attributes
|
194
194
|
def add_edges( node_one, node_two, options = {} )
|
195
|
-
|
196
|
-
if( node_one.class == Array )
|
195
|
+
|
196
|
+
if( node_one.class == Array )
|
197
197
|
node_one.each do |no|
|
198
198
|
add_edges( no, node_two, options )
|
199
199
|
end
|
@@ -205,17 +205,17 @@ class GraphViz
|
|
205
205
|
else
|
206
206
|
edge = GraphViz::Edge::new( node_one, node_two, self )
|
207
207
|
edge.index = @elements_order.size_of( "edge" )
|
208
|
-
|
208
|
+
|
209
209
|
options.each do |xKey, xValue|
|
210
210
|
edge[xKey.to_s] = xValue
|
211
211
|
end
|
212
|
-
|
213
|
-
@elements_order.push( {
|
214
|
-
"type" => "edge",
|
212
|
+
|
213
|
+
@elements_order.push( {
|
214
|
+
"type" => "edge",
|
215
215
|
"value" => edge
|
216
216
|
} )
|
217
217
|
@loEdges.push( edge )
|
218
|
-
|
218
|
+
|
219
219
|
return( edge )
|
220
220
|
end
|
221
221
|
end
|
@@ -233,14 +233,14 @@ class GraphViz
|
|
233
233
|
return @loEdges
|
234
234
|
end
|
235
235
|
end
|
236
|
-
|
236
|
+
|
237
237
|
#
|
238
238
|
# Get the number of edges
|
239
239
|
#
|
240
240
|
def edge_count
|
241
241
|
@loEdges.size
|
242
242
|
end
|
243
|
-
|
243
|
+
|
244
244
|
#
|
245
245
|
# Return the edge object for the given index
|
246
246
|
#
|
@@ -248,21 +248,21 @@ class GraphViz
|
|
248
248
|
element = @elements_order[index, "edge"]
|
249
249
|
(element.nil?) ? nil : element["value"]
|
250
250
|
end
|
251
|
-
|
252
|
-
#
|
251
|
+
|
252
|
+
#
|
253
253
|
# Create a new graph
|
254
|
-
#
|
254
|
+
#
|
255
255
|
# In:
|
256
256
|
# * xGraphName : Graph name
|
257
257
|
# * hOpts : Graph attributes
|
258
258
|
#
|
259
259
|
def add_graph( xGraphName = nil, hOpts = {}, &block )
|
260
|
-
if xGraphName.kind_of?(GraphViz)
|
260
|
+
if xGraphName.kind_of?(GraphViz)
|
261
261
|
xGraphID = xGraphName.id
|
262
262
|
@hoGraphs[xGraphID] = xGraphName.clone
|
263
263
|
@hoGraphs[xGraphID].type = @oGraphType
|
264
264
|
@hoGraphs[xGraphID].pg = self
|
265
|
-
xGraphName = xGraphID
|
265
|
+
xGraphName = xGraphID
|
266
266
|
else
|
267
267
|
if xGraphName.kind_of?(Hash)
|
268
268
|
hOpts = xGraphName
|
@@ -283,10 +283,10 @@ class GraphViz
|
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
286
|
-
@elements_order.push( {
|
287
|
-
"type" => "graph",
|
286
|
+
@elements_order.push( {
|
287
|
+
"type" => "graph",
|
288
288
|
"name" => xGraphName,
|
289
|
-
"value" => @hoGraphs[xGraphID]
|
289
|
+
"value" => @hoGraphs[xGraphID]
|
290
290
|
} )
|
291
291
|
|
292
292
|
return( @hoGraphs[xGraphID] )
|
@@ -297,12 +297,12 @@ class GraphViz
|
|
297
297
|
#
|
298
298
|
def get_graph( xGraphName, &block )
|
299
299
|
graph = @hoGraphs[xGraphName] || nil
|
300
|
-
|
301
|
-
yield( graph ) if( block and graph
|
302
|
-
|
300
|
+
|
301
|
+
yield( graph ) if( block and graph )
|
302
|
+
|
303
303
|
return graph
|
304
304
|
end
|
305
|
-
|
305
|
+
|
306
306
|
#
|
307
307
|
# Allow you to traverse graphs
|
308
308
|
#
|
@@ -315,7 +315,7 @@ class GraphViz
|
|
315
315
|
return @hoGraphs
|
316
316
|
end
|
317
317
|
end
|
318
|
-
|
318
|
+
|
319
319
|
#
|
320
320
|
# Add nodes and edges defined by a Hash
|
321
321
|
#
|
@@ -324,9 +324,9 @@ class GraphViz
|
|
324
324
|
h.each do |node, data|
|
325
325
|
add_hash_edge(node, data)
|
326
326
|
end
|
327
|
-
end
|
327
|
+
end
|
328
328
|
end
|
329
|
-
|
329
|
+
|
330
330
|
#
|
331
331
|
# Return the graph type (graph digraph)
|
332
332
|
#
|
@@ -336,51 +336,51 @@ class GraphViz
|
|
336
336
|
def type=(x) #:nodoc:
|
337
337
|
@oGraphType = x
|
338
338
|
end
|
339
|
-
|
339
|
+
|
340
340
|
#
|
341
341
|
# Get the number of graphs
|
342
342
|
#
|
343
343
|
def graph_count
|
344
344
|
@hoGraphs.size
|
345
345
|
end
|
346
|
-
|
346
|
+
|
347
347
|
def method_missing( idName, *args, &block ) #:nodoc:
|
348
348
|
xName = idName.id2name
|
349
|
-
|
349
|
+
|
350
350
|
rCod = nil
|
351
|
-
|
351
|
+
|
352
352
|
if block
|
353
353
|
# Creating a cluster named '#{xName}'
|
354
354
|
rCod = add_graph( xName, args[0]||{} )
|
355
355
|
yield( rCod )
|
356
356
|
else
|
357
|
-
# Create a node named '#{xName}' or search for a node, edge or cluster
|
357
|
+
# Create a node named '#{xName}' or search for a node, edge or cluster
|
358
358
|
if @hoNodes.keys.include?( xName )
|
359
359
|
if( args[0] )
|
360
360
|
return { xName => args[0] }
|
361
361
|
else
|
362
|
-
return( @hoNodes[xName] )
|
362
|
+
return( @hoNodes[xName] )
|
363
363
|
end
|
364
364
|
end
|
365
365
|
return( @hoGraphs[xName] ) if @hoGraphs.keys.include?( xName )
|
366
|
-
|
366
|
+
|
367
367
|
rCod = add_nodes( xName, args[0]||{} )
|
368
368
|
end
|
369
369
|
|
370
370
|
return rCod
|
371
371
|
end
|
372
|
-
|
373
|
-
#
|
372
|
+
|
373
|
+
#
|
374
374
|
# Set value +xValue+ to the graph attribute +xAttrName+
|
375
|
-
#
|
375
|
+
#
|
376
376
|
def []=( xAttrName, xValue )
|
377
377
|
xValue = xValue.to_s if xValue.class == Symbol
|
378
378
|
@graph[xAttrName] = xValue
|
379
379
|
end
|
380
380
|
|
381
|
-
#
|
381
|
+
#
|
382
382
|
# Get the value of the graph attribute +xAttrName+
|
383
|
-
#
|
383
|
+
#
|
384
384
|
def []( xAttrName )
|
385
385
|
if Hash === xAttrName
|
386
386
|
xAttrName.each do |key, value|
|
@@ -390,9 +390,9 @@ class GraphViz
|
|
390
390
|
return( @graph[xAttrName].clone )
|
391
391
|
end
|
392
392
|
end
|
393
|
-
|
393
|
+
|
394
394
|
#
|
395
|
-
# Calls block once for each attribute of the graph, passing the name and value to the
|
395
|
+
# Calls block once for each attribute of the graph, passing the name and value to the
|
396
396
|
# block as a two-element array.
|
397
397
|
#
|
398
398
|
def each_attribute(&b)
|
@@ -404,10 +404,10 @@ class GraphViz
|
|
404
404
|
warn "`GraphViz#each_attribut` is deprecated, please use `GraphViz#each_attribute`"
|
405
405
|
each_attribute(&b)
|
406
406
|
end
|
407
|
-
|
408
|
-
#
|
407
|
+
|
408
|
+
#
|
409
409
|
# Generate the graph
|
410
|
-
#
|
410
|
+
#
|
411
411
|
# Options :
|
412
412
|
# * :output : Output format (Constants::FORMATS)
|
413
413
|
# * :file : Output file name
|
@@ -421,7 +421,7 @@ class GraphViz
|
|
421
421
|
# * 0 = Error + Warning
|
422
422
|
# * 1 = Error
|
423
423
|
# * 2 = none
|
424
|
-
#
|
424
|
+
#
|
425
425
|
def output( hOpts = {} )
|
426
426
|
xDOTScript = ""
|
427
427
|
xLastType = nil
|
@@ -430,21 +430,21 @@ class GraphViz
|
|
430
430
|
lNotHugly = []
|
431
431
|
|
432
432
|
@elements_order.each { |kElement|
|
433
|
-
if xLastType.nil?
|
434
|
-
|
435
|
-
if xData.length > 0
|
433
|
+
if xLastType.nil? or xLastType != kElement["type"]
|
434
|
+
|
435
|
+
if xData.length > 0
|
436
436
|
case xLastType
|
437
437
|
when "graph_attr"
|
438
438
|
xDOTScript << " " + xData + ";\n"
|
439
|
-
|
439
|
+
|
440
440
|
when "node_attr"
|
441
441
|
xDOTScript << " node [" + xData + "];\n"
|
442
|
-
|
442
|
+
|
443
443
|
when "edge_attr"
|
444
444
|
xDOTScript << " edge [" + xData + "];\n"
|
445
445
|
end
|
446
446
|
end
|
447
|
-
|
447
|
+
|
448
448
|
xSeparator = ""
|
449
449
|
xData = ""
|
450
450
|
end
|
@@ -452,7 +452,7 @@ class GraphViz
|
|
452
452
|
xLastType = kElement["type"]
|
453
453
|
|
454
454
|
#Modified by
|
455
|
-
#Brandon Coleman
|
455
|
+
#Brandon Coleman
|
456
456
|
#verify value is NOT NULL
|
457
457
|
if kElement["value"] == nil then
|
458
458
|
raise ArgumentError, "#{kElement["name"]} has a nil value!"
|
@@ -484,33 +484,33 @@ class GraphViz
|
|
484
484
|
raise ArgumentError, "Don't know what to do with element type '#{kElement['type']}'"
|
485
485
|
end
|
486
486
|
}
|
487
|
-
|
488
|
-
if xData.length > 0
|
487
|
+
|
488
|
+
if xData.length > 0
|
489
489
|
case xLastType
|
490
490
|
when "graph_attr"
|
491
491
|
xDOTScript << " " + xData + ";\n"
|
492
492
|
|
493
493
|
when "node_attr"
|
494
494
|
xDOTScript << " node [" + xData + "];\n"
|
495
|
-
|
495
|
+
|
496
496
|
when "edge_attr"
|
497
497
|
xDOTScript << " edge [" + xData + "];\n"
|
498
498
|
end
|
499
499
|
end
|
500
500
|
xDOTScript << "}"
|
501
501
|
|
502
|
-
if @oParentGraph
|
502
|
+
if @oParentGraph
|
503
503
|
xDOTScript = "subgraph #{GraphViz.escape(@name, :unquote_empty => true)} {\n" << xDOTScript
|
504
504
|
|
505
505
|
return( xDOTScript )
|
506
506
|
else
|
507
507
|
hOutput = {}
|
508
|
-
|
508
|
+
|
509
509
|
hOpts.each do |xKey, xValue|
|
510
510
|
xValue = xValue.to_s unless xValue.nil? or [Class, TrueClass, FalseClass].include?(xValue.class)
|
511
511
|
case xKey.to_s
|
512
512
|
when "use"
|
513
|
-
if PROGRAMS.index( xValue ).nil?
|
513
|
+
if PROGRAMS.index( xValue ).nil?
|
514
514
|
raise ArgumentError, "can't use '#{xValue}'"
|
515
515
|
end
|
516
516
|
@prog = xValue
|
@@ -559,21 +559,21 @@ class GraphViz
|
|
559
559
|
@nothugly = false
|
560
560
|
end
|
561
561
|
else
|
562
|
-
if FORMATS.index( xKey.to_s ).nil?
|
562
|
+
if FORMATS.index( xKey.to_s ).nil?
|
563
563
|
raise ArgumentError, "output format '#{xValue}' invalid"
|
564
564
|
end
|
565
565
|
hOutput[xKey.to_s] = xValue
|
566
566
|
end
|
567
567
|
end
|
568
|
-
|
568
|
+
|
569
569
|
@output = hOutput if hOutput.size > 0
|
570
|
-
|
570
|
+
|
571
571
|
xStict = ((@strict && @oGraphType == "digraph") ? "strict " : "")
|
572
572
|
xDOTScript = ("#{xStict}#{@oGraphType} #{GraphViz.escape(@name, :unquote_empty => true)} {\n" << xDOTScript).gsub( "\0", "" )
|
573
573
|
|
574
574
|
xOutputString = (@filename == String ||
|
575
575
|
@output.any? {|format, file| file == String })
|
576
|
-
|
576
|
+
|
577
577
|
xOutput = ""
|
578
578
|
if @format.to_s == "none" or @output.any? {|fmt, fn| fmt.to_s == "none"}
|
579
579
|
if xOutputString
|
@@ -585,13 +585,13 @@ class GraphViz
|
|
585
585
|
end
|
586
586
|
end
|
587
587
|
end
|
588
|
-
|
588
|
+
|
589
589
|
if (@format.to_s != "none" and not @format.nil?) or (@output.any? {|format, file| format != "none" } and @output.size > 0)
|
590
590
|
## Act: Save script and send it to dot
|
591
591
|
t = Tempfile::open( File.basename(__FILE__) )
|
592
592
|
t.print( xDOTScript )
|
593
593
|
t.close
|
594
|
-
|
594
|
+
|
595
595
|
cmd = find_executable( @prog, @path )
|
596
596
|
if cmd == nil
|
597
597
|
raise StandardError, "GraphViz not installed or #{@prog} not in PATH. Install GraphViz or use the 'path' option"
|
@@ -617,27 +617,27 @@ class GraphViz
|
|
617
617
|
xOutputWithFile << "-T#{format} -o#{file} "
|
618
618
|
end
|
619
619
|
end
|
620
|
-
|
620
|
+
|
621
621
|
xExternalLibraries = ""
|
622
622
|
@extlibs.each do |lib|
|
623
623
|
xExternalLibraries << "-l#{lib} "
|
624
624
|
end
|
625
|
-
|
626
|
-
xOtherOptions = ""
|
625
|
+
|
626
|
+
xOtherOptions = ""
|
627
627
|
xOtherOptions += " -s#{@scale}" unless @scale.nil?
|
628
|
-
xOtherOptions += " -y" if @inverty
|
628
|
+
xOtherOptions += " -y" if @inverty
|
629
629
|
unless @no_layout.nil?
|
630
630
|
xOtherOptions += " -n"
|
631
631
|
xOtherOptions += "2" if @no_layout.to_i == 2
|
632
632
|
end
|
633
|
-
xOtherOptions += " -x" if @reduce_graph
|
634
|
-
xOtherOptions += " -Lg" if @Lg
|
635
|
-
xOtherOptions += " -LO" if @LO
|
633
|
+
xOtherOptions += " -x" if @reduce_graph
|
634
|
+
xOtherOptions += " -Lg" if @Lg
|
635
|
+
xOtherOptions += " -LO" if @LO
|
636
636
|
xOtherOptions += " -Ln#{@Ln}" unless @LN.nil?
|
637
637
|
xOtherOptions += " -LU#{@LU}" unless @LU.nil?
|
638
638
|
xOtherOptions += " -LC#{@LC}" unless @LC.nil?
|
639
639
|
xOtherOptions += " -LT#{@LT}" unless @LT.nil?
|
640
|
-
|
640
|
+
|
641
641
|
if IS_JRUBY
|
642
642
|
xCmd = "#{cmd} -q#{@errors} #{xExternalLibraries} #{xOtherOptions} #{xOutputWithFile} #{xOutputWithoutFile} #{t.path}"
|
643
643
|
elsif IS_CYGWIN
|
@@ -654,7 +654,7 @@ class GraphViz
|
|
654
654
|
|
655
655
|
xOutput << output_from_command( xCmd )
|
656
656
|
end
|
657
|
-
|
657
|
+
|
658
658
|
# Not Hugly
|
659
659
|
lNotHugly.each do |f|
|
660
660
|
if f.nil? or f == String
|
@@ -663,7 +663,7 @@ class GraphViz
|
|
663
663
|
GraphViz.nothugly( f, true )
|
664
664
|
end
|
665
665
|
end
|
666
|
-
|
666
|
+
|
667
667
|
if xOutputString
|
668
668
|
xOutput
|
669
669
|
else
|
@@ -671,28 +671,28 @@ class GraphViz
|
|
671
671
|
end
|
672
672
|
end
|
673
673
|
end
|
674
|
-
|
674
|
+
|
675
675
|
alias :save :output
|
676
|
-
|
676
|
+
|
677
677
|
def to_s
|
678
678
|
self.output(:none => String)
|
679
679
|
end
|
680
|
-
|
681
|
-
#
|
680
|
+
|
681
|
+
#
|
682
682
|
# Get the graph name
|
683
683
|
#
|
684
|
-
def name
|
684
|
+
def name
|
685
685
|
@name.clone
|
686
686
|
end
|
687
687
|
alias :id :name
|
688
|
-
|
689
|
-
#
|
688
|
+
|
689
|
+
#
|
690
690
|
# Create an edge between the current cluster and the node or cluster +oNode+
|
691
|
-
#
|
691
|
+
#
|
692
692
|
def <<( oNode )
|
693
693
|
raise( ArgumentError, "Edge between root graph and node or cluster not allowed!" ) if self.pg.nil?
|
694
694
|
|
695
|
-
if( oNode.class == Array )
|
695
|
+
if( oNode.class == Array )
|
696
696
|
oNode.each do |no|
|
697
697
|
self << no
|
698
698
|
end
|
@@ -703,46 +703,46 @@ class GraphViz
|
|
703
703
|
alias :> :<<
|
704
704
|
alias :- :<<
|
705
705
|
alias :>> :<<
|
706
|
-
|
706
|
+
|
707
707
|
def pg #:nodoc:
|
708
708
|
@oParentGraph
|
709
709
|
end
|
710
710
|
def pg=(x) #:nodoc:
|
711
711
|
@oParentGraph = x
|
712
712
|
end
|
713
|
-
|
713
|
+
|
714
714
|
#
|
715
715
|
# Return the root graph
|
716
716
|
#
|
717
717
|
def root_graph
|
718
718
|
return( (self.pg.nil?) ? self : self.pg.root_graph )
|
719
719
|
end
|
720
|
-
|
720
|
+
|
721
721
|
def self.commonGraph( o1, o2 ) #:nodoc:
|
722
722
|
g1 = o1.pg
|
723
723
|
g2 = o2.pg
|
724
724
|
|
725
725
|
return o1 if g1.nil?
|
726
726
|
return o2 if g2.nil?
|
727
|
-
|
727
|
+
|
728
728
|
return g1 if g1.object_id == g2.object_id
|
729
|
-
|
729
|
+
|
730
730
|
return GraphViz::commonGraph( g1, g2 )
|
731
731
|
end
|
732
|
-
|
732
|
+
|
733
733
|
def set_position( xType, xKey, xValue ) #:nodoc:
|
734
|
-
@elements_order.push( {
|
735
|
-
"type" => "#{xType}_attr",
|
734
|
+
@elements_order.push( {
|
735
|
+
"type" => "#{xType}_attr",
|
736
736
|
"name" => xKey,
|
737
|
-
"value" => xValue
|
737
|
+
"value" => xValue
|
738
738
|
} )
|
739
739
|
end
|
740
|
-
|
740
|
+
|
741
741
|
## ----------------------------------------------------------------------------
|
742
742
|
|
743
743
|
#
|
744
744
|
# Change default options (:use, :path, :errors and :output)
|
745
|
-
#
|
745
|
+
#
|
746
746
|
def self.default( hOpts )
|
747
747
|
hOpts.each do |k, v|
|
748
748
|
case k.to_s
|
@@ -759,29 +759,29 @@ class GraphViz
|
|
759
759
|
end
|
760
760
|
end
|
761
761
|
end
|
762
|
-
|
762
|
+
|
763
763
|
def self.options( hOpts )
|
764
764
|
GraphViz::default( hOpts )
|
765
765
|
end
|
766
|
-
|
766
|
+
|
767
767
|
## ----------------------------------------------------------------------------
|
768
768
|
|
769
769
|
# Create a new graph from a GraphViz File
|
770
|
-
#
|
770
|
+
#
|
771
771
|
# Options :
|
772
772
|
# * :output : Output format (Constants::FORMATS) (default : dot)
|
773
773
|
# * :file : Output file name (default : none)
|
774
774
|
# * :use : Program to use (Constants::PROGRAMS) (default : dot)
|
775
775
|
# * :path : Program PATH
|
776
776
|
#
|
777
|
-
def self.parse( xFile, hOpts = {}, &block )
|
777
|
+
def self.parse( xFile, hOpts = {}, &block )
|
778
778
|
graph = Dot2Ruby::new( hOpts[:path], nil, nil ).eval( xFile )
|
779
|
-
yield( graph ) if( block and graph
|
779
|
+
yield( graph ) if( block and graph )
|
780
780
|
return graph
|
781
781
|
end
|
782
782
|
|
783
783
|
# Create a new graph from a GraphViz File
|
784
|
-
#
|
784
|
+
#
|
785
785
|
# Options :
|
786
786
|
# * :output : Output format (Constants::FORMATS) (default : dot)
|
787
787
|
# * :file : Output file name (default : none)
|
@@ -790,11 +790,11 @@ class GraphViz
|
|
790
790
|
#
|
791
791
|
def self.parse_string( str, hOpts = {}, &block )
|
792
792
|
graph = Dot2Ruby::new( hOpts[:path], nil, nil ).eval_string( str )
|
793
|
-
yield( graph ) if( block and graph
|
793
|
+
yield( graph ) if( block and graph )
|
794
794
|
return graph
|
795
795
|
end
|
796
796
|
|
797
|
-
# Return a new completed graph
|
797
|
+
# Return a new completed graph
|
798
798
|
def complete
|
799
799
|
GraphViz.parse_string( root_graph.output( :dot => String ) )
|
800
800
|
end
|
@@ -811,7 +811,7 @@ class GraphViz
|
|
811
811
|
end
|
812
812
|
## ----------------------------------------------------------------------------
|
813
813
|
|
814
|
-
private
|
814
|
+
private
|
815
815
|
|
816
816
|
## Var: Nodes, Edges and Graphs tables
|
817
817
|
@hoNodes
|
@@ -823,10 +823,10 @@ class GraphViz
|
|
823
823
|
|
824
824
|
## Var: Type de graphe (orienté ou non)
|
825
825
|
@oGraphType
|
826
|
-
|
827
|
-
#
|
826
|
+
|
827
|
+
#
|
828
828
|
# Create a new graph object
|
829
|
-
#
|
829
|
+
#
|
830
830
|
# Options :
|
831
831
|
# * :output : Output format (Constants::FORMATS) (default : dot)
|
832
832
|
# * :file : Output file name (default : nil)
|
@@ -838,7 +838,7 @@ class GraphViz
|
|
838
838
|
# * 0 = Error + Warning
|
839
839
|
# * 1 = Error
|
840
840
|
# * 2 = none
|
841
|
-
#
|
841
|
+
#
|
842
842
|
def initialize( xGraphName, hOpts = {}, &block )
|
843
843
|
@filename = nil
|
844
844
|
@name = xGraphName.to_s
|
@@ -850,7 +850,7 @@ class GraphViz
|
|
850
850
|
@output = {}
|
851
851
|
@nothugly = false
|
852
852
|
@strict = false
|
853
|
-
|
853
|
+
|
854
854
|
@scale = nil
|
855
855
|
@inverty = nil
|
856
856
|
@no_layout = nil
|
@@ -861,16 +861,16 @@ class GraphViz
|
|
861
861
|
@LU = nil
|
862
862
|
@LC = nil
|
863
863
|
@LT = nil
|
864
|
-
|
864
|
+
|
865
865
|
@elements_order = GraphViz::Elements::new()
|
866
866
|
|
867
867
|
@oParentGraph = nil
|
868
868
|
@oGraphType = "digraph"
|
869
|
-
|
869
|
+
|
870
870
|
@hoNodes = Hash::new()
|
871
871
|
@loEdges = Array::new()
|
872
872
|
@hoGraphs = Hash::new()
|
873
|
-
|
873
|
+
|
874
874
|
@node = GraphViz::Attrs::new( self, "node", NODESATTRS )
|
875
875
|
@edge = GraphViz::Attrs::new( self, "edge", EDGESATTRS )
|
876
876
|
@graph = GraphViz::Attrs::new( self, "graph", GRAPHSATTRS )
|
@@ -878,14 +878,14 @@ class GraphViz
|
|
878
878
|
hOpts.each do |xKey, xValue|
|
879
879
|
case xKey.to_s
|
880
880
|
when "use"
|
881
|
-
if PROGRAMS.index( xValue.to_s ).nil?
|
881
|
+
if PROGRAMS.index( xValue.to_s ).nil?
|
882
882
|
raise ArgumentError, "can't use '#{xValue}'"
|
883
883
|
end
|
884
884
|
@prog = xValue.to_s
|
885
885
|
when "parent"
|
886
886
|
@oParentGraph = xValue
|
887
887
|
when "type"
|
888
|
-
if GRAPHTYPE.index( xValue.to_s ).nil?
|
888
|
+
if GRAPHTYPE.index( xValue.to_s ).nil?
|
889
889
|
raise ArgumentError, "graph type '#{xValue}' unknow"
|
890
890
|
end
|
891
891
|
@oGraphType = xValue.to_s
|
@@ -901,10 +901,10 @@ class GraphViz
|
|
901
901
|
self[xKey.to_s] = xValue.to_s
|
902
902
|
end
|
903
903
|
end
|
904
|
-
|
904
|
+
|
905
905
|
yield( self ) if( block )
|
906
906
|
end
|
907
|
-
|
907
|
+
|
908
908
|
# Edge between a node and a Hash
|
909
909
|
# Used by GraphViz#add
|
910
910
|
def add_hash_edge(node, hash)
|
@@ -917,7 +917,7 @@ class GraphViz
|
|
917
917
|
add_edges(node, hash)
|
918
918
|
end
|
919
919
|
end
|
920
|
-
|
920
|
+
|
921
921
|
#
|
922
922
|
# Create a new undirected graph
|
923
923
|
#
|
@@ -935,14 +935,14 @@ class GraphViz
|
|
935
935
|
def self.digraph( xGraphName, hOpts = {}, &block )
|
936
936
|
new( xGraphName, hOpts.symbolize_keys.merge( {:type => "digraph"} ), &block )
|
937
937
|
end
|
938
|
-
|
938
|
+
|
939
939
|
# Create a new strict directed graph
|
940
940
|
#
|
941
941
|
# See also GraphViz::new
|
942
942
|
def self.strict_digraph( xGraphName, hOpts = {}, &block )
|
943
943
|
new( xGraphName, hOpts.symbolize_keys.merge( {:type => "digraph", :strict => true} ), &block )
|
944
944
|
end
|
945
|
-
|
945
|
+
|
946
946
|
# Create a random graph.
|
947
947
|
def self.generate(num_nodes, num_edges, directed = false, weight_range = (1..1))
|
948
948
|
g = nil
|
@@ -980,13 +980,13 @@ class GraphViz
|
|
980
980
|
:force => false,
|
981
981
|
:unquote_empty => false,
|
982
982
|
}.merge(opts)
|
983
|
-
|
984
|
-
if (options[:force] or str.match( /\A[a-zA-Z_]+[a-zA-Z0-9_]*\Z/ ).nil?)
|
985
|
-
unless options[:unquote_empty]
|
986
|
-
'"' + str.gsub('"', '\\"').gsub("\n", '\\\\n') + '"'
|
983
|
+
|
984
|
+
if (options[:force] or str.match( /\A[a-zA-Z_]+[a-zA-Z0-9_]*\Z/ ).nil?)
|
985
|
+
unless options[:unquote_empty] and str.size == 0
|
986
|
+
'"' + str.gsub('"', '\\"').gsub("\n", '\\\\n') + '"'
|
987
987
|
end
|
988
988
|
else
|
989
989
|
str
|
990
990
|
end
|
991
|
-
end
|
991
|
+
end
|
992
992
|
end
|