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/lib/graphviz/attrs.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Copyright (C) 2004 - 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
|
@@ -44,9 +44,6 @@ class GraphViz
|
|
44
44
|
self[k] = v
|
45
45
|
end
|
46
46
|
else
|
47
|
-
if @data.key?( key.to_s ) == false
|
48
|
-
nil
|
49
|
-
end
|
50
47
|
@data[key.to_s]
|
51
48
|
end
|
52
49
|
end
|
@@ -66,12 +63,10 @@ class GraphViz
|
|
66
63
|
rescue => e
|
67
64
|
raise AttributeException, "Invalide value `#{value}` for attribute `#{key}` : #{e}"
|
68
65
|
end
|
69
|
-
unless value.nil?
|
70
|
-
@data[key.to_s] = value
|
71
66
|
|
72
|
-
|
73
|
-
|
74
|
-
|
67
|
+
if value
|
68
|
+
@data[key.to_s] = value
|
69
|
+
@graphviz.set_position( @name, key.to_s, @data[key.to_s] ) if @graphviz
|
75
70
|
end
|
76
71
|
end
|
77
72
|
end
|
data/lib/graphviz/constants.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
# Copyright (C) 2004 - 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
|
16
16
|
|
17
17
|
# Constants for ruby-graphviz
|
18
|
-
#
|
18
|
+
#
|
19
19
|
# Constants::FORMATS: the possible output formats
|
20
|
-
# "bmp", "canon", "dot", "xdot", "cmap", "dia", "eps",
|
20
|
+
# "bmp", "canon", "dot", "xdot", "cmap", "dia", "eps",
|
21
21
|
# "fig", "gd", "gd2", "gif", "gtk", "hpgl", "ico", "imap",
|
22
22
|
# "cmapx", "imap_np", "cmapx_np", "ismap", "jpeg", "jpg",
|
23
23
|
# "jpe", "mif", "mp", "pcl", "pdf", "pic", "plain",
|
24
24
|
# "plain-ext", "png", "ps", "ps2", "svg", "svgz", "tga",
|
25
25
|
# "tiff", "tif", "vml", "vmlz", "vrml", "vtx", "wbmp",
|
26
|
-
# "xlib", "none"
|
27
|
-
#
|
26
|
+
# "xlib", "none"
|
27
|
+
#
|
28
28
|
# Constants::PROGRAMS: The possible programs
|
29
29
|
# "dot", "neato", "twopi", "fdp", "circo"
|
30
30
|
#
|
@@ -33,22 +33,22 @@
|
|
33
33
|
#
|
34
34
|
#
|
35
35
|
# The single letter codes used in constructors map as follows:
|
36
|
-
# G => The root graph, with GRAPHATTRS
|
36
|
+
# G => The root graph, with GRAPHATTRS
|
37
37
|
# E => Edge, with EDGESATTRS
|
38
38
|
# N => Node, with NODESATTRS
|
39
39
|
# S => subgraph
|
40
40
|
# C => cluster
|
41
41
|
#
|
42
42
|
module Constants
|
43
|
-
RGV_VERSION = "1.0.
|
44
|
-
|
43
|
+
RGV_VERSION = "1.0.8"
|
44
|
+
|
45
45
|
## Const: Output formats
|
46
46
|
FORMATS = [
|
47
47
|
"bmp",
|
48
48
|
"canon",
|
49
|
-
"dot",
|
49
|
+
"dot",
|
50
50
|
"xdot",
|
51
|
-
"cmap",
|
51
|
+
"cmap",
|
52
52
|
"dia",
|
53
53
|
"eps",
|
54
54
|
"fig",
|
@@ -56,37 +56,37 @@ module Constants
|
|
56
56
|
"gd2",
|
57
57
|
"gif",
|
58
58
|
"gtk",
|
59
|
-
"hpgl",
|
59
|
+
"hpgl",
|
60
60
|
"ico",
|
61
|
-
"imap",
|
61
|
+
"imap",
|
62
62
|
"cmapx",
|
63
|
-
"imap_np",
|
63
|
+
"imap_np",
|
64
64
|
"cmapx_np",
|
65
|
-
"ismap",
|
66
|
-
"jpeg",
|
67
|
-
"jpg",
|
68
|
-
"jpe",
|
69
|
-
"mif",
|
65
|
+
"ismap",
|
66
|
+
"jpeg",
|
67
|
+
"jpg",
|
68
|
+
"jpe",
|
69
|
+
"mif",
|
70
70
|
"mp",
|
71
|
-
"pcl",
|
71
|
+
"pcl",
|
72
72
|
"pdf",
|
73
|
-
"pic",
|
74
|
-
"plain",
|
73
|
+
"pic",
|
74
|
+
"plain",
|
75
75
|
"plain-ext",
|
76
|
-
"png",
|
77
|
-
"ps",
|
76
|
+
"png",
|
77
|
+
"ps",
|
78
78
|
"ps2",
|
79
|
-
"svg",
|
79
|
+
"svg",
|
80
80
|
"svgz",
|
81
81
|
"tga",
|
82
82
|
"tiff",
|
83
83
|
"tif",
|
84
84
|
"vml",
|
85
85
|
"vmlz",
|
86
|
-
"vrml",
|
87
|
-
"vtx",
|
88
|
-
"wbmp",
|
89
|
-
"xlib",
|
86
|
+
"vrml",
|
87
|
+
"vtx",
|
88
|
+
"wbmp",
|
89
|
+
"xlib",
|
90
90
|
"none"
|
91
91
|
]
|
92
92
|
|
@@ -114,7 +114,7 @@ module Constants
|
|
114
114
|
}
|
115
115
|
list
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
# E, N, G, S and C represent edges, nodes, the root graph, subgraphs and cluster subgraphs, respectively
|
119
119
|
GENCS_ATTRS = {
|
120
120
|
"Damping" => { :usedBy => "G", :type => :GvDouble },
|
@@ -142,8 +142,8 @@ module Constants
|
|
142
142
|
"dimen" => { :usedBy => "G", :type => :EscString }, # int
|
143
143
|
"dir" => { :usedBy => "E", :type => :EscString }, # dirType
|
144
144
|
"diredgeconstraints" => { :usedBy => "G", :type => :EscString }, # string, bool
|
145
|
-
"distortion" => { :usedBy => "N", :type => :GvDouble },
|
146
|
-
"dpi" => { :usedBy => "G", :type => :GvDouble },
|
145
|
+
"distortion" => { :usedBy => "N", :type => :GvDouble },
|
146
|
+
"dpi" => { :usedBy => "G", :type => :GvDouble },
|
147
147
|
"edgeURL" => { :usedBy => "E", :type => :EscString },
|
148
148
|
"edgehref" => { :usedBy => "E", :type => :EscString },
|
149
149
|
"edgetarget" => { :usedBy => "E", :type => :EscString },
|
@@ -161,7 +161,7 @@ module Constants
|
|
161
161
|
"headURL" => { :usedBy => "E", :type => :EscString },
|
162
162
|
"headclip" => { :usedBy => "E", :type => :GvBool }, # bool
|
163
163
|
"headhref" => { :usedBy => "E", :type => :EscString },
|
164
|
-
"headlabel" => { :usedBy => "E", :type => :EscString }, # LblString
|
164
|
+
"headlabel" => { :usedBy => "E", :type => :EscString }, # LblString
|
165
165
|
"headport" => { :usedBy => "E", :type => :EscString }, # portPos
|
166
166
|
"headtarget" => { :usedBy => "E", :type => :EscString },
|
167
167
|
"headtooltip" => { :usedBy => "E", :type => :EscString },
|
@@ -189,7 +189,7 @@ module Constants
|
|
189
189
|
"layers" => { :usedBy => "G", :type => :EscString }, # layerList
|
190
190
|
"layersep" => { :usedBy => "G", :type => :EscString }, # string
|
191
191
|
"layout" => { :usedBy => "G", :type => :EscString }, # string
|
192
|
-
"len" => { :usedBy => "E", :type => :GvDouble },
|
192
|
+
"len" => { :usedBy => "E", :type => :GvDouble },
|
193
193
|
"levels" => { :usedBy => "G", :type => :EscString }, # int
|
194
194
|
"levelsgap" => { :usedBy => "G", :type => :GvDouble },
|
195
195
|
"lhead" => { :usedBy => "E", :type => :EscString }, # string
|
data/lib/graphviz/core_ext.rb
CHANGED
data/lib/graphviz/dot2ruby.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# Copyright (C) 2010 Gregoire Lejeune <gregoire.lejeune@free.fr>
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# This program is free software; you can redistribute it and/or modify
|
5
5
|
# it under the terms of the GNU General Public License as published by
|
6
6
|
# the Free Software Foundation; either version 2 of the License, or
|
7
7
|
# (at your option) any later version.
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# This program is distributed in the hope that it will be useful,
|
10
10
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
11
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
12
|
# GNU General Public License for more details.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# You should have received a copy of the GNU General Public License
|
15
15
|
# along with this program; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
@@ -20,7 +20,7 @@ require 'graphviz/utils'
|
|
20
20
|
|
21
21
|
class Dot2Ruby #:nodoc:
|
22
22
|
include GVUtils
|
23
|
-
|
23
|
+
|
24
24
|
def initialize( xGVPath, xOutFile, xOutFormat = nil ) #:nodoc:
|
25
25
|
paths = (xGVPath.nil?) ? [] : [xGVPath]
|
26
26
|
@xGvprPath = find_executable( 'gvpr', paths )
|
@@ -28,7 +28,7 @@ class Dot2Ruby #:nodoc:
|
|
28
28
|
@xOutFormat = xOutFormat || "_"
|
29
29
|
@gvprScript = GraphViz::Ext.find( "dot2ruby.g" )
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def run( xFile ) #:nodoc:
|
33
33
|
xCmd = "#{@xGvprPath} -f #{@gvprScript} -a #{@xOutFormat} #{xFile}"
|
34
34
|
xOutput = output_from_command( xCmd )
|
@@ -38,9 +38,9 @@ class Dot2Ruby #:nodoc:
|
|
38
38
|
File.open( @xOutFile, "w" ) do |io|
|
39
39
|
io.print xOutput
|
40
40
|
end
|
41
|
-
end
|
41
|
+
end
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def eval( xFile ) #:nodoc:
|
45
45
|
xCmd = "#{@xGvprPath} -f #{@gvprScript} -a \"-\" #{xFile}"
|
46
46
|
xOutput = output_from_command( xCmd )
|
data/lib/graphviz/dsl.rb
CHANGED
@@ -39,29 +39,29 @@ class GraphViz::DSL
|
|
39
39
|
end
|
40
40
|
|
41
41
|
# Add a subgraph
|
42
|
-
def subgraph(name, &block)
|
42
|
+
def subgraph(name, &block)
|
43
43
|
@graph.add_graph(GraphViz::DSL.new(name, { :parent => @graph, :type => @graph.type }, &block).graph)
|
44
44
|
end
|
45
45
|
alias :cluster :subgraph
|
46
46
|
|
47
47
|
# Generate output
|
48
|
-
def output(options = {})
|
48
|
+
def output(options = {})
|
49
49
|
@graph.output(options)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
# Create a new undirected graph
|
54
|
-
def graph(name, options = {}, &block)
|
54
|
+
def graph(name, options = {}, &block)
|
55
55
|
GraphViz::DSL.new(name, options.merge( { :type => "graph" } ), &block).graph
|
56
56
|
end
|
57
57
|
|
58
58
|
# Create a new directed graph
|
59
|
-
def digraph(name, options = {}, &block)
|
59
|
+
def digraph(name, options = {}, &block)
|
60
60
|
GraphViz::DSL.new(name, options.merge( { :type => "digraph" } ), &block).graph
|
61
61
|
end
|
62
62
|
|
63
63
|
# Create a new strict directed graph
|
64
|
-
def strict(name, options = {}, &block)
|
64
|
+
def strict(name, options = {}, &block)
|
65
65
|
GraphViz::DSL.new(name, options.merge( { :type => "strict digraph" } ), &block).graph
|
66
66
|
end
|
67
67
|
|
data/lib/graphviz/edge.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Copyright (C) 2004 - 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
|
@@ -22,11 +22,11 @@ class GraphViz
|
|
22
22
|
include Constants
|
23
23
|
|
24
24
|
# Create a new edge
|
25
|
-
#
|
25
|
+
#
|
26
26
|
# In:
|
27
27
|
# * vNodeOne : First node (can be a GraphViz::Node or a node ID)
|
28
28
|
# * vNodeTwo : Second node (can be a GraphViz::Node or a node ID)
|
29
|
-
# * parent_graph : Graph
|
29
|
+
# * parent_graph : Graph
|
30
30
|
def initialize( vNodeOne, vNodeTwo, parent_graph )
|
31
31
|
@node_one_id, @node_one_port = getNodeNameAndPort( vNodeOne )
|
32
32
|
@node_two_id, @node_two_port = getNodeNameAndPort( vNodeTwo )
|
@@ -35,7 +35,7 @@ class GraphViz
|
|
35
35
|
@edge_attributes = GraphViz::Attrs::new( nil, "edge", EDGESATTRS )
|
36
36
|
@index = nil
|
37
37
|
|
38
|
-
unless @parent_graph.directed?
|
38
|
+
unless @parent_graph.directed?
|
39
39
|
(@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id)).incidents << (@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id))
|
40
40
|
(@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id)).neighbors << (@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id))
|
41
41
|
end
|
@@ -45,7 +45,7 @@ class GraphViz
|
|
45
45
|
|
46
46
|
# Return the node one as string (so with port if any)
|
47
47
|
def node_one( with_port = true )
|
48
|
-
if @node_one_port
|
48
|
+
if not (@node_one_port and with_port)
|
49
49
|
GraphViz.escape(@node_one_id)
|
50
50
|
else
|
51
51
|
GraphViz.escape(@node_one_id, :force => true) + ":#{@node_one_port}"
|
@@ -55,9 +55,9 @@ class GraphViz
|
|
55
55
|
|
56
56
|
# Return the node two as string (so with port if any)
|
57
57
|
def node_two( with_port = true )
|
58
|
-
if @node_two_port
|
59
|
-
GraphViz.escape(@node_two_id)
|
60
|
-
else
|
58
|
+
if not (@node_two_port and with_port)
|
59
|
+
GraphViz.escape(@node_two_id)
|
60
|
+
else
|
61
61
|
GraphViz.escape(@node_two_id, :force => true) + ":#{@node_two_port}"
|
62
62
|
end
|
63
63
|
end
|
@@ -77,7 +77,7 @@ class GraphViz
|
|
77
77
|
@edge_attributes[attribute_name.to_s] = attribute_value
|
78
78
|
end
|
79
79
|
|
80
|
-
# Set values for edge attributes or
|
80
|
+
# Set values for edge attributes or
|
81
81
|
# get the value of the given edge attribute +attribute_name+
|
82
82
|
def []( attribute_name )
|
83
83
|
# Modification by axgle (http://github.com/axgle)
|
@@ -87,7 +87,7 @@ class GraphViz
|
|
87
87
|
end
|
88
88
|
else
|
89
89
|
if @edge_attributes[attribute_name.to_s]
|
90
|
-
@edge_attributes[attribute_name.to_s].clone
|
90
|
+
@edge_attributes[attribute_name.to_s].clone
|
91
91
|
else
|
92
92
|
nil
|
93
93
|
end
|
@@ -95,7 +95,7 @@ class GraphViz
|
|
95
95
|
end
|
96
96
|
|
97
97
|
#
|
98
|
-
# Calls block once for each attribute of the edge, passing the name and value to the
|
98
|
+
# Calls block once for each attribute of the edge, passing the name and value to the
|
99
99
|
# block as a two-element array.
|
100
100
|
#
|
101
101
|
# If global is set to false, the block does not receive the attributes set globally
|
data/lib/graphviz/elements.rb
CHANGED
@@ -4,22 +4,22 @@ class GraphViz
|
|
4
4
|
@elements = Array.new
|
5
5
|
@elements_hash_by_type = Hash.new
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def push( obj )
|
9
9
|
@elements.push( obj )
|
10
10
|
if @elements_hash_by_type[obj['type']].nil?
|
11
11
|
@elements_hash_by_type[obj['type']] = Array.new
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
@elements_hash_by_type[obj['type']].push( obj )
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def each( &b )
|
18
18
|
@elements.each do |e|
|
19
19
|
yield( e )
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def size_of( type )
|
24
24
|
if @elements_hash_by_type[type].nil?
|
25
25
|
return 0
|
@@ -27,7 +27,7 @@ class GraphViz
|
|
27
27
|
return @elements_hash_by_type[type].size
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def []( index, type = nil )
|
32
32
|
if type.nil?
|
33
33
|
return @elements[index]
|
data/lib/graphviz/ext.rb
CHANGED
data/lib/graphviz/family_tree.rb
CHANGED
@@ -21,10 +21,10 @@ class GraphViz
|
|
21
21
|
@generation_number = 0
|
22
22
|
@generations = []
|
23
23
|
@couples = {}
|
24
|
-
|
24
|
+
|
25
25
|
instance_eval(&block) if block
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
# Add a new generation in the tree
|
29
29
|
#
|
30
30
|
# require 'graphviz/family_tree'
|
@@ -42,47 +42,47 @@ class GraphViz
|
|
42
42
|
@generations << gen
|
43
43
|
@generation_number += 1
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def persons #:nodoc:
|
47
47
|
@persons ||= {}
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def add_couple( x, y, node ) #:nodoc:
|
51
51
|
@couples[x] = {} if @couples[x].nil?
|
52
52
|
@couples[x][y] = GraphViz::FamilyTree::Couple.new( @graph, node, [x, y] )
|
53
53
|
@couples[y] = {} if @couples[y].nil?
|
54
54
|
@couples[y][x] = @couples[x][y]
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
# Get a couple (GraphViz::FamilyTree::Couple)
|
58
|
-
def couple( x, y )
|
58
|
+
def couple( x, y )
|
59
59
|
@couples[x][y]
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def method_missing(sym, *args, &block) #:nodoc:
|
63
63
|
persons[sym.to_s]
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
# Family size
|
67
67
|
def size
|
68
68
|
@persons.size
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
# Get the graph
|
72
72
|
def graph
|
73
73
|
maxY = @generations.size
|
74
74
|
biggestGen, maxX = biggestGenerationNumberAndSize
|
75
|
-
|
75
|
+
|
76
76
|
puts "#{maxY} generations"
|
77
77
|
puts "Plus grosse generation : ##{biggestGen} avec #{maxX} personnes"
|
78
|
-
|
78
|
+
|
79
79
|
puts "traitement des générations..."
|
80
|
-
|
80
|
+
|
81
81
|
puts " #{biggestGen}:"
|
82
82
|
@generations[biggestGen].persons.each do |id, person|
|
83
83
|
puts " - #{id} : #{person.class}"
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
puts " Up..."
|
87
87
|
(0...biggestGen).reverse_each do |genNumber|
|
88
88
|
puts " #{genNumber}:"
|
@@ -98,10 +98,10 @@ class GraphViz
|
|
98
98
|
puts " - #{id} : #{person.class}"
|
99
99
|
end
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
@graph
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
private
|
106
106
|
def biggestGenerationNumberAndSize
|
107
107
|
size = 0
|