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
@@ -7,17 +7,17 @@ class GraphViz
|
|
7
7
|
@kids = []
|
8
8
|
@persons = persons
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def node #:nodoc:
|
12
12
|
@node
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
# Add kids to a couple
|
16
16
|
def kids( *z )
|
17
17
|
@kids = GraphViz::FamilyTree::Sibling.new( z, @persons )
|
18
|
-
|
18
|
+
|
19
19
|
return
|
20
|
-
|
20
|
+
|
21
21
|
if z.size == 1
|
22
22
|
@graph.add_edges( @node, z[0].node, "dir" => "none" )
|
23
23
|
else
|
@@ -27,7 +27,7 @@ class GraphViz
|
|
27
27
|
last = nil
|
28
28
|
count = 0
|
29
29
|
add = (z.size-1)%2 * z.size/2 + (z.size-1)%2
|
30
|
-
link = (z.size/2)+1
|
30
|
+
link = (z.size/2)+1
|
31
31
|
|
32
32
|
z.each do |person|
|
33
33
|
count = count + 1
|
@@ -36,25 +36,25 @@ class GraphViz
|
|
36
36
|
@graph.add_edges( @node, middle, "dir" => "none" )
|
37
37
|
unless last.nil?
|
38
38
|
cluster.add_edges( last, middle, "dir" => "none" )
|
39
|
-
end
|
39
|
+
end
|
40
40
|
last = middle
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
kid = cluster.add_nodes( "#{person.node.id}Kid", "shape" => "point" )
|
44
44
|
@graph.add_edges( kid, person.node, "dir" => "none" )
|
45
|
-
|
45
|
+
|
46
46
|
if add == 0 and count == link
|
47
47
|
@graph.add_edges( @node, kid, "dir" => "none" )
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
unless last.nil?
|
51
51
|
cluster.add_edges( last, kid, "dir" => "none" )
|
52
52
|
end
|
53
53
|
last = kid
|
54
54
|
end
|
55
|
-
end
|
55
|
+
end
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def getKids
|
59
59
|
@kids
|
60
60
|
end
|
@@ -8,28 +8,28 @@ class GraphViz
|
|
8
8
|
@tree = tree
|
9
9
|
@gen_number = gen_number
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def all_persons #:nodoc:
|
13
13
|
@all_persons
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def persons
|
17
17
|
@persons
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def make( &block ) #:nodoc:
|
21
21
|
instance_eval(&block) if block
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def method_missing(sym, *args, &block) #:nodoc:
|
25
25
|
all_persons[sym.to_s] ||= (persons[sym.to_s] ||= GraphViz::FamilyTree::Person.new( @graph, @tree, self, sym.to_s ))
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
# Generation number
|
29
29
|
def number
|
30
30
|
@gen_number
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
# Generation size
|
34
34
|
def size
|
35
35
|
@persons.size
|
@@ -13,31 +13,31 @@ class GraphViz
|
|
13
13
|
@x, @y = 0, 0
|
14
14
|
@sibling = nil
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def id
|
18
18
|
@node.id
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def name
|
22
22
|
@node.label || @node.id
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def sibling
|
26
26
|
@sibling
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def sibling=(x)
|
30
30
|
@sibling=x
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def couples #:nodoc:
|
34
34
|
@couples
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def node #:nodoc:
|
38
38
|
@node
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
# Define the current person as a man
|
42
42
|
#
|
43
43
|
# greg.is_a_man( "Greg" )
|
@@ -45,14 +45,14 @@ class GraphViz
|
|
45
45
|
@node["label"] = name
|
46
46
|
@node["color"] = "blue"
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
# Define the current person as a boy
|
50
50
|
#
|
51
51
|
# greg.is_a_boy( "Greg" )
|
52
52
|
def is_a_boy( name )
|
53
53
|
is_a_man( name )
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
# Define the current perdon as a woman
|
57
57
|
#
|
58
58
|
# mu.is_a_woman( "Muriel" )
|
@@ -66,7 +66,7 @@ class GraphViz
|
|
66
66
|
def is_a_girl( name )
|
67
67
|
is_a_woman( name )
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
# Define that's two persons are maried
|
71
71
|
#
|
72
72
|
# mu.is_maried_with greg
|
@@ -77,7 +77,7 @@ class GraphViz
|
|
77
77
|
@graph.add_edges( node, x.node, "dir" => "none" )
|
78
78
|
@tree.add_couple( self, x, node )
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
# Define that's two persons are divorced
|
82
82
|
#
|
83
83
|
# sophie.is_divorced_with john
|
@@ -89,7 +89,7 @@ class GraphViz
|
|
89
89
|
@graph.add_edges( node, x.node, "dir" => "none", "color" => "red" )
|
90
90
|
@tree.add_couple( self, x, node )
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
# Define that's a person is widower of another
|
94
94
|
#
|
95
95
|
# simon.is_widower_of elisa
|
@@ -108,7 +108,7 @@ class GraphViz
|
|
108
108
|
def is_dead
|
109
109
|
@node["style"] = "filled"
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
# Define the kids of a single person
|
113
113
|
#
|
114
114
|
# alice.kids( john, jack, julie )
|
data/lib/graphviz/graphml.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
|
@@ -28,10 +28,10 @@ class GraphViz
|
|
28
28
|
warn "`GraphViz::GraphML#attributs` is deprecated, please, use `GraphViz::GraphML#attributes`"
|
29
29
|
return @attributes
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# The GraphViz object
|
33
33
|
attr_accessor :graph
|
34
|
-
|
34
|
+
|
35
35
|
DEST = {
|
36
36
|
'node' => [:nodes],
|
37
37
|
'edge' => [:edges],
|
@@ -42,15 +42,15 @@ class GraphViz
|
|
42
42
|
'endpoint' => [:endpoint],
|
43
43
|
'all' => [:nodes, :edges, :graphs, :graphml, :hyperedge, :port, :endpoint]
|
44
44
|
}
|
45
|
-
|
45
|
+
|
46
46
|
GTYPE = {
|
47
47
|
'directed' => :digraph,
|
48
48
|
'undirected' => :graph
|
49
49
|
}
|
50
|
-
|
50
|
+
|
51
51
|
# Create a new GraphViz object from a GraphML file of string
|
52
52
|
def initialize( file_or_str )
|
53
|
-
data = ((File.file?( file_or_str )) ? File::new(file_or_str) : file_or_str)
|
53
|
+
data = ((File.file?( file_or_str )) ? File::new(file_or_str) : file_or_str)
|
54
54
|
@xmlDoc = REXML::Document::new( data )
|
55
55
|
@attributes = {
|
56
56
|
:nodes => {},
|
@@ -67,14 +67,14 @@ class GraphViz
|
|
67
67
|
@current_node = nil
|
68
68
|
@current_edge = nil
|
69
69
|
@current_graph = nil
|
70
|
-
|
70
|
+
|
71
71
|
parse( @xmlDoc.root )
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def parse( node ) #:nodoc:
|
75
75
|
send( node.name.to_sym, node )
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def graphml( node ) #:nodoc:
|
79
79
|
node.each_element( ) do |child|
|
80
80
|
begin
|
@@ -85,23 +85,23 @@ class GraphViz
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
def graphml_data(node)
|
88
|
+
def graphml_data(node)
|
89
89
|
warn "graphml/data not supported!"
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def graphml_key( node ) #:nodoc:
|
93
93
|
id = node.attributes['id']
|
94
94
|
@current_attr = {
|
95
95
|
:name => node.attributes['attr.name'],
|
96
96
|
:type => node.attributes['attr.type']
|
97
|
-
}
|
97
|
+
}
|
98
98
|
if @current_attr[:name].nil?
|
99
99
|
@ignored_keys << id
|
100
100
|
else
|
101
101
|
DEST[node.attributes['for']].each do |d|
|
102
102
|
@attributes[d][id] = @current_attr
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
node.each_element( ) do |child|
|
106
106
|
begin
|
107
107
|
send( "graphml_key_#{child.name}".to_sym, child )
|
@@ -110,26 +110,26 @@ class GraphViz
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
@current_attr = nil
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
def graphml_key_default( node ) #:nodoc:
|
118
118
|
@current_attr[:default] = node.texts().join('\n')
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
def graphml_graph( node ) #:nodoc:
|
122
122
|
@current_node = nil
|
123
|
-
|
123
|
+
|
124
124
|
if @current_graph.nil?
|
125
125
|
@graph = GraphViz.new( node.attributes['id'], :type => GTYPE[node.attributes['edgedefault']] )
|
126
126
|
@current_graph = @graph
|
127
127
|
previous_graph = @graph
|
128
128
|
else
|
129
|
-
previous_graph = @current_graph
|
129
|
+
previous_graph = @current_graph
|
130
130
|
@current_graph = previous_graph.add_graph( node.attributes['id'] )
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
@attributes[:graphs].each do |id, data|
|
134
134
|
begin
|
135
135
|
@current_graph.graph[data[:name]] = data[:default] if data.has_key?(:default)
|
@@ -151,14 +151,14 @@ class GraphViz
|
|
151
151
|
warn e
|
152
152
|
end
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
node.each_element( ) do |child|
|
156
156
|
send( "graphml_graph_#{child.name}".to_sym, child )
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
@current_graph = previous_graph
|
160
160
|
end
|
161
|
-
|
161
|
+
|
162
162
|
def graphml_graph_data( node ) #:nodoc:
|
163
163
|
begin
|
164
164
|
@current_graph[@attributes[:graphs][node.attributes['key']][:name]] = node.texts().join('\n')
|
@@ -166,10 +166,10 @@ class GraphViz
|
|
166
166
|
warn e
|
167
167
|
end
|
168
168
|
end
|
169
|
-
|
169
|
+
|
170
170
|
def graphml_graph_node( node ) #:nodoc:
|
171
171
|
@current_node = {}
|
172
|
-
|
172
|
+
|
173
173
|
node.each_element( ) do |child|
|
174
174
|
case child.name
|
175
175
|
when "graph"
|
@@ -182,7 +182,7 @@ class GraphViz
|
|
182
182
|
end
|
183
183
|
end
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
unless @current_node.nil?
|
187
187
|
node = @current_graph.add_nodes( node.attributes['id'] )
|
188
188
|
@current_node.each do |k, v|
|
@@ -193,10 +193,10 @@ class GraphViz
|
|
193
193
|
end
|
194
194
|
end
|
195
195
|
end
|
196
|
-
|
196
|
+
|
197
197
|
@current_node = nil
|
198
198
|
end
|
199
|
-
|
199
|
+
|
200
200
|
def graphml_graph_node_data( node ) #:nodoc:
|
201
201
|
return if @ignored_keys.include?(node.attributes['key'])
|
202
202
|
begin
|
@@ -205,7 +205,7 @@ class GraphViz
|
|
205
205
|
warn e
|
206
206
|
end
|
207
207
|
end
|
208
|
-
|
208
|
+
|
209
209
|
def graphml_graph_node_port( node ) #:nodoc:
|
210
210
|
@current_node[:shape] = :record
|
211
211
|
port = node.attributes['name']
|
@@ -216,15 +216,15 @@ class GraphViz
|
|
216
216
|
@current_node[:label] = "<#{port}> #{port}"
|
217
217
|
end
|
218
218
|
end
|
219
|
-
|
219
|
+
|
220
220
|
def graphml_graph_edge( node ) #:nodoc:
|
221
221
|
source = node.attributes['source']
|
222
222
|
source = {source => node.attributes['sourceport']} if node.attributes['sourceport']
|
223
223
|
target = node.attributes['target']
|
224
224
|
target = {target => node.attributes['targetport']} if node.attributes['targetport']
|
225
|
-
|
225
|
+
|
226
226
|
@current_edge = @current_graph.add_edges( source, target )
|
227
|
-
|
227
|
+
|
228
228
|
node.each_element( ) do |child|
|
229
229
|
begin
|
230
230
|
send( "graphml_graph_edge_#{child.name}".to_sym, child )
|
@@ -232,10 +232,10 @@ class GraphViz
|
|
232
232
|
raise GraphMLError, "node #{child.name} can be child of edge"
|
233
233
|
end
|
234
234
|
end
|
235
|
-
|
235
|
+
|
236
236
|
@current_edge = nil
|
237
237
|
end
|
238
|
-
|
238
|
+
|
239
239
|
def graphml_graph_edge_data( node ) #:nodoc:
|
240
240
|
return if @ignored_keys.include?(node.attributes['key'])
|
241
241
|
begin
|
@@ -244,10 +244,10 @@ class GraphViz
|
|
244
244
|
warn e
|
245
245
|
end
|
246
246
|
end
|
247
|
-
|
247
|
+
|
248
248
|
def graphml_graph_hyperedge( node ) #:nodoc:
|
249
249
|
list = []
|
250
|
-
|
250
|
+
|
251
251
|
node.each_element( ) do |child|
|
252
252
|
if child.name == "endpoint"
|
253
253
|
if child.attributes['port']
|
@@ -257,12 +257,12 @@ class GraphViz
|
|
257
257
|
end
|
258
258
|
end
|
259
259
|
end
|
260
|
-
|
260
|
+
|
261
261
|
list.each { |s|
|
262
262
|
list.each { |t|
|
263
263
|
@current_graph.add_edges( s, t ) unless s == t
|
264
264
|
}
|
265
|
-
}
|
265
|
+
}
|
266
266
|
end
|
267
267
|
end
|
268
268
|
end
|
data/lib/graphviz/math/matrix.rb
CHANGED
@@ -3,12 +3,12 @@ class GraphViz
|
|
3
3
|
def self.Matrix( line, column = 0, val = 0 )
|
4
4
|
GraphViz::Math::Matrix.new(line, column, val)
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
class CoordinateError < RuntimeError
|
8
8
|
end
|
9
9
|
class ValueError < RuntimeError
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
class Matrix
|
13
13
|
def initialize( line_or_array, column = 0, val = 0 )
|
14
14
|
if line_or_array.kind_of?(Array)
|
@@ -27,7 +27,7 @@ class GraphViz
|
|
27
27
|
raise ValueError, "Element at [#{l+1}, #{c+1}] is not a number"
|
28
28
|
end
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
31
31
|
|
32
32
|
@matrix = line_or_array
|
33
33
|
@line = line
|
@@ -45,8 +45,8 @@ class GraphViz
|
|
45
45
|
else
|
46
46
|
raise ArgumentError, "Wrong matrix definition"
|
47
47
|
end
|
48
|
-
end
|
49
|
-
|
48
|
+
end
|
49
|
+
|
50
50
|
def [](line, column)
|
51
51
|
unless (0...@line).to_a.include?(line-1)
|
52
52
|
raise CoordinateError, "Line out of range (#{line} for 1..#{@line})!"
|
@@ -56,7 +56,7 @@ class GraphViz
|
|
56
56
|
end
|
57
57
|
@matrix[line-1][column-1]
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def []=( line, column, val )
|
61
61
|
unless (0...@line).to_a.include?(line-1)
|
62
62
|
raise CoordinateError, "Line out of range (#{line} for 1..#{@line})!"
|
@@ -66,20 +66,20 @@ class GraphViz
|
|
66
66
|
end
|
67
67
|
@matrix[line-1][column-1] = val
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def matrix
|
71
71
|
@matrix
|
72
72
|
end
|
73
73
|
alias :to_a :matrix
|
74
|
-
|
74
|
+
|
75
75
|
def columns
|
76
76
|
@column
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def lines
|
80
80
|
@line
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
def to_s
|
84
84
|
size = bigger
|
85
85
|
out = ""
|
@@ -92,7 +92,7 @@ class GraphViz
|
|
92
92
|
end
|
93
93
|
return out
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
def -(m)
|
97
97
|
matrix = GraphViz::Math::Matrix.new( @line, @column )
|
98
98
|
@line.times do |line|
|
@@ -102,10 +102,10 @@ class GraphViz
|
|
102
102
|
end
|
103
103
|
return matrix
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
def *(m)
|
107
107
|
matrix = GraphViz::Math::Matrix.new( @line, @line )
|
108
|
-
|
108
|
+
|
109
109
|
@line.times do |line|
|
110
110
|
@line.times do |column|
|
111
111
|
l = self.line(line+1)
|
@@ -117,17 +117,17 @@ class GraphViz
|
|
117
117
|
matrix[line+1,column+1] = v
|
118
118
|
end
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
return matrix
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
def line( line )
|
125
125
|
unless (0...@line).to_a.include?(line-1)
|
126
126
|
raise CoordinateError, "Line out of range (#{line} for 1..#{@line})!"
|
127
127
|
end
|
128
128
|
@matrix[line-1]
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
def column( column )
|
132
132
|
col = []
|
133
133
|
unless (0...@column).to_a.include?(column-1)
|
@@ -136,10 +136,10 @@ class GraphViz
|
|
136
136
|
@line.times do |line|
|
137
137
|
col << self[line+1, column]
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
return col
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
def transpose
|
144
144
|
matrix = GraphViz::Math::Matrix.new( @column, @line )
|
145
145
|
@line.times do |line|
|
@@ -149,7 +149,7 @@ class GraphViz
|
|
149
149
|
end
|
150
150
|
return matrix
|
151
151
|
end
|
152
|
-
|
152
|
+
|
153
153
|
def ==(m)
|
154
154
|
equal = true
|
155
155
|
@line.times do |line|
|
@@ -159,7 +159,7 @@ class GraphViz
|
|
159
159
|
end
|
160
160
|
return equal
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
def remove_line(n)
|
164
164
|
unless (0...@line).to_a.include?(n-1)
|
165
165
|
raise CoordinateError, "Line out of range (#{n} for 1..#{@line})!"
|
@@ -176,7 +176,7 @@ class GraphViz
|
|
176
176
|
end
|
177
177
|
return matrix
|
178
178
|
end
|
179
|
-
|
179
|
+
|
180
180
|
def remove_column(n)
|
181
181
|
unless (0...@column).to_a.include?(n-1)
|
182
182
|
raise CoordinateError, "Column out of range (#{n} for 1..#{@column})!"
|
@@ -193,11 +193,11 @@ class GraphViz
|
|
193
193
|
end
|
194
194
|
return matrix
|
195
195
|
end
|
196
|
-
|
196
|
+
|
197
197
|
def sum_of_column(n)
|
198
198
|
column(n).inject(0){|sum,item| sum + item}
|
199
199
|
end
|
200
|
-
|
200
|
+
|
201
201
|
def sum_of_line(n)
|
202
202
|
line(n).inject(0){|sum,item| sum + item}
|
203
203
|
end
|