ruby-graphviz 1.0.2 → 1.0.3

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.
Files changed (53) hide show
  1. data/README.rdoc +9 -0
  2. data/examples/sample01.rb +17 -17
  3. data/examples/sample02.rb +18 -18
  4. data/examples/sample03.rb +8 -8
  5. data/examples/sample04.rb +5 -5
  6. data/examples/sample05.rb +17 -17
  7. data/examples/sample07.rb +5 -5
  8. data/examples/sample08.rb +15 -15
  9. data/examples/sample09.rb +25 -25
  10. data/examples/sample10.rb +25 -25
  11. data/examples/sample11.rb +21 -21
  12. data/examples/sample16.rb +2 -2
  13. data/examples/sample17.rb +5 -5
  14. data/examples/sample20.rb +18 -18
  15. data/examples/sample29.rb +2 -2
  16. data/examples/sample30.rb +4 -4
  17. data/examples/sample31.rb +3 -3
  18. data/examples/sample36.rb +5 -5
  19. data/examples/sample37.rb +8 -8
  20. data/examples/sample38.rb +2 -2
  21. data/examples/sample39.rb +6 -6
  22. data/examples/sample40.rb +4 -4
  23. data/examples/sample42.rb +14 -14
  24. data/examples/sample43.rb +7 -7
  25. data/examples/sample44.rb +3 -3
  26. data/examples/sample45.rb +1 -1
  27. data/examples/sample46.rb +18 -18
  28. data/examples/sample54.rb +2 -2
  29. data/examples/sample55.rb +4 -4
  30. data/examples/sample58.rb +7 -7
  31. data/examples/sample60.rb +3 -3
  32. data/examples/sample61.rb +3 -3
  33. data/examples/sample62.rb +3 -3
  34. data/examples/sample66.rb +4 -0
  35. data/examples/sample67.rb +10 -0
  36. data/examples/sample68.rb +27 -0
  37. data/lib/ext/gvpr/dot2ruby.g +2 -2
  38. data/lib/graphviz.rb +91 -27
  39. data/lib/graphviz/constants.rb +1 -1
  40. data/lib/graphviz/core_ext.rb +0 -9
  41. data/lib/graphviz/dsl.rb +3 -3
  42. data/lib/graphviz/edge.rb +6 -6
  43. data/lib/graphviz/family_tree/couple.rb +8 -8
  44. data/lib/graphviz/family_tree/person.rb +10 -10
  45. data/lib/graphviz/graphml.rb +3 -3
  46. data/lib/graphviz/node.rb +2 -2
  47. data/lib/graphviz/theory.rb +37 -2
  48. data/lib/graphviz/xml.rb +4 -4
  49. data/ruby-graphviz.gemspec +2 -13
  50. data/test/test_graph.rb +25 -25
  51. data/test/test_search.rb +32 -0
  52. data/test/test_theory.rb +1 -1
  53. metadata +11 -13
data/lib/graphviz/node.rb CHANGED
@@ -96,7 +96,7 @@ class GraphViz
96
96
  self << no
97
97
  end
98
98
  else
99
- return GraphViz::commonGraph( node, self ).add_edge( self, node )
99
+ return GraphViz::commonGraph( node, self ).add_edges( self, node )
100
100
  end
101
101
  end
102
102
  alias :> :<<
@@ -106,7 +106,7 @@ class GraphViz
106
106
  # Set node attributs
107
107
  #
108
108
  # Example :
109
- # n = graph.add_node( ... )
109
+ # n = graph.add_nodes( ... )
110
110
  # ...
111
111
  # n.set { |_n|
112
112
  # _n.color = "blue"
@@ -116,10 +116,10 @@ class GraphViz
116
116
  ch = []
117
117
  k = arv
118
118
  while k.index != dep.index
119
- ch.unshift(k.id)
119
+ ch.unshift(k)
120
120
  k = pred[k.index]
121
121
  end
122
- ch.unshift(dep.id)
122
+ ch.unshift(dep)
123
123
 
124
124
  if d[arv.index].to_f.infinite?
125
125
  return nil
@@ -205,7 +205,42 @@ class GraphViz
205
205
  end
206
206
  end
207
207
 
208
+ # Breadth First Search
209
+ def bfs(node, &b)
210
+ queue = []
211
+ visited_nodes = []
212
+ node = @graph.get_node(node) if node.kind_of? String
213
+ queue << node
214
+ visited_nodes << node
215
+
216
+ while not queue.empty?
217
+ node = queue.shift
218
+ b.call(node)
219
+ neighbors(node).each do |n|
220
+ unless visited_nodes.include?(n)
221
+ visited_nodes << n
222
+ queue << n
223
+ end
224
+ end
225
+ end
226
+ end
227
+
228
+ # Depth First Search
229
+ def dfs(node, &b)
230
+ visited_nodes = []
231
+ recursive_dfs(node, visited_nodes, &b)
232
+ end
233
+
208
234
  private
235
+ def recursive_dfs(node, visited_nodes, &b)
236
+ node = @graph.get_node(node) if node.kind_of? String
237
+ b.call(node)
238
+ visited_nodes << node
239
+ neighbors(node).each do |n|
240
+ recursive_dfs(n, visited_nodes, &b) unless visited_nodes.include?(n)
241
+ end
242
+ end
243
+
209
244
  def distance_matrix
210
245
  type = @graph.type
211
246
  matrix = GraphViz::Math::Matrix.new( @graph.node_count, @graph.node_count, (1.0/0.0) )
data/lib/graphviz/xml.rb CHANGED
@@ -81,7 +81,7 @@ class GraphViz
81
81
 
82
82
  label << "}"
83
83
  end
84
- @graph.add_node( local_node_name, "label" => label, "color" => "blue", "shape" => "record" )
84
+ @graph.add_nodes( local_node_name, "label" => label, "color" => "blue", "shape" => "record" )
85
85
 
86
86
  ## Act: Search and add Text nodes
87
87
  if xml_node.has_text? == true and @show_text == true
@@ -99,8 +99,8 @@ class GraphViz
99
99
  end
100
100
 
101
101
  if xText.length > 0
102
- @graph.add_node( text_node_name, "label" => xText, "color" => "black", "shape" => "ellipse" )
103
- @graph.add_edge( local_node_name, text_node_name )
102
+ @graph.add_nodes( text_node_name, "label" => xText, "color" => "black", "shape" => "ellipse" )
103
+ @graph.add_edges( local_node_name, text_node_name )
104
104
  end
105
105
  end
106
106
 
@@ -109,7 +109,7 @@ class GraphViz
109
109
 
110
110
  xml_node.each_element( ) do |xml_child_node|
111
111
  child_node_name = parse_xml_node( xml_child_node )
112
- @graph.add_edge( local_node_name, child_node_name )
112
+ @graph.add_edges( local_node_name, child_node_name )
113
113
  end
114
114
 
115
115
  return( local_node_name )
@@ -34,19 +34,8 @@ For more information about Ruby-Graphviz :
34
34
  * Sources : http://github.com/glejeune/Ruby-Graphviz
35
35
  * NEW - Mailing List : http://groups.google.com/group/ruby-graphviz
36
36
 
37
- /!\\ Version 0.9.12 introduce a new solution to connect edges to node ports
38
- For more information, see http://github.com/glejeune/Ruby-Graphviz/issues/#issue/13
39
- So if you use node ports, maybe you need to change your code.
40
-
41
- /!\\ GraphViz::Node#name has been removed!
42
-
43
- /!\\ :output and :file options have been removed!
44
-
45
- /!\\ The html attribut has been removed!
46
- You can use the label attribut, as dot do it : :label => '<<html/>>'
47
-
48
- /!\\ Version 0.9.17 introduce GraphML (http://graphml.graphdrawing.org/) support and
49
- graph theory !
37
+ /!\\ GraphViz#add_edge is deprecated, use GraphViz#add_edges
38
+ /!\\ GraphViz#add_node is deprecated, use GraphViz#add_nodes
50
39
  }
51
40
 
52
41
  # s.add_runtime_dependency("middleman", "~>2.0.0.3")
data/test/test_graph.rb CHANGED
@@ -23,7 +23,7 @@ class GraphVizTest < Test::Unit::TestCase
23
23
  n, m = nil, nil
24
24
 
25
25
  assert_block 'Create node failed.' do
26
- n = @graph.add_node( "n1" )
26
+ n = @graph.add_nodes( "n1" )
27
27
  end
28
28
 
29
29
  assert_block 'Get node failed.' do
@@ -52,32 +52,32 @@ class GraphVizTest < Test::Unit::TestCase
52
52
  c0["label"] = "process #1"
53
53
  c0["style"] = "filled"
54
54
  c0["color"] = "lightgrey"
55
- a0 = c0.add_node( "a0", "style" => "filled", "color" => "white" )
56
- a1 = c0.add_node( "a1", "style" => "filled", "color" => "white" )
57
- a2 = c0.add_node( "a2", "style" => "filled", "color" => "white" )
58
- a3 = c0.add_node( "a3", "style" => "filled", "color" => "white" )
59
- c0.add_edge( a0, a1 )
60
- c0.add_edge( a1, a2 )
61
- c0.add_edge( a2, a3 )
55
+ a0 = c0.add_nodes( "a0", "style" => "filled", "color" => "white" )
56
+ a1 = c0.add_nodes( "a1", "style" => "filled", "color" => "white" )
57
+ a2 = c0.add_nodes( "a2", "style" => "filled", "color" => "white" )
58
+ a3 = c0.add_nodes( "a3", "style" => "filled", "color" => "white" )
59
+ c0.add_edges( a0, a1 )
60
+ c0.add_edges( a1, a2 )
61
+ c0.add_edges( a2, a3 )
62
62
 
63
63
  c1 = g.add_graph( "cluster1", "label" => "process #2" )
64
- b0 = c1.add_node( "b0", "style" => "filled", "color" => "blue" )
65
- b1 = c1.add_node( "b1", "style" => "filled", "color" => "blue" )
66
- b2 = c1.add_node( "b2", "style" => "filled", "color" => "blue" )
67
- b3 = c1.add_node( "b3", "style" => "filled", "color" => "blue" )
68
- c1.add_edge( b0, b1 )
69
- c1.add_edge( b1, b2 )
70
- c1.add_edge( b2, b3 )
71
-
72
- start = g.add_node( "start", "shape" => "Mdiamond" )
73
- endn = g.add_node( "end", "shape" => "Msquare" )
74
-
75
- g.add_edge( start, a0 )
76
- g.add_edge( start, b0 )
77
- g.add_edge( a1, b3 )
78
- g.add_edge( b2, a3 )
79
- g.add_edge( a3, a0 )
80
- g.add_edge( a3, endn )
64
+ b0 = c1.add_nodes( "b0", "style" => "filled", "color" => "blue" )
65
+ b1 = c1.add_nodes( "b1", "style" => "filled", "color" => "blue" )
66
+ b2 = c1.add_nodes( "b2", "style" => "filled", "color" => "blue" )
67
+ b3 = c1.add_nodes( "b3", "style" => "filled", "color" => "blue" )
68
+ c1.add_edges( b0, b1 )
69
+ c1.add_edges( b1, b2 )
70
+ c1.add_edges( b2, b3 )
71
+
72
+ start = g.add_nodes( "start", "shape" => "Mdiamond" )
73
+ endn = g.add_nodes( "end", "shape" => "Msquare" )
74
+
75
+ g.add_edges( start, a0 )
76
+ g.add_edges( start, b0 )
77
+ g.add_edges( a1, b3 )
78
+ g.add_edges( b2, a3 )
79
+ g.add_edges( a3, a0 )
80
+ g.add_edges( a3, endn )
81
81
 
82
82
  assert g
83
83
 
@@ -0,0 +1,32 @@
1
+ require 'test/unit'
2
+ $:.unshift(File.expand_path('../../lib',__FILE__))
3
+ require 'graphviz'
4
+ require 'graphviz/theory'
5
+
6
+ class GraphVizSearch < Test::Unit::TestCase
7
+ def setup
8
+ @graph = GraphViz.graph(:G)
9
+ @graph.add_nodes(["A", "B", "C", "D", "E", "F", "G"])
10
+ @graph.add_edges("A", ["B", "C", "E"])
11
+ @graph.add_edges("B", ["D", "F"])
12
+ @graph.add_edges("C", "G")
13
+ @graph.add_edges("F", "E")
14
+ @theory = GraphViz::Theory.new(@graph)
15
+ end
16
+
17
+ def test_dfs
18
+ order = []
19
+ @theory.dfs("A") { |node|
20
+ order << node.id
21
+ }
22
+ assert_equal order, ["A", "B", "D", "F", "E", "C", "G"]
23
+ end
24
+
25
+ def test_bfs
26
+ order = []
27
+ @theory.bfs("A") { |node|
28
+ order << node.id
29
+ }
30
+ assert_equal order, ["A", "B", "C", "E", "D", "F", "G"]
31
+ end
32
+ end
data/test/test_theory.rb CHANGED
@@ -85,7 +85,7 @@ class GraphVizTheoryTest < Test::Unit::TestCase
85
85
  def test_dijkstra_a_f
86
86
  r = @t.moore_dijkstra(@g.a, @g.f)
87
87
  assert r
88
- assert_equal ["a", "b", "c", "f"], r[:path]
88
+ assert_equal ["a", "b", "c", "f"], r[:path].map{|n| n.id}
89
89
  assert_equal 4.0, r[:distance]
90
90
  end
91
91
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-graphviz
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gregoire Lejeune
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-11 00:00:00 Z
18
+ date: 2011-12-17 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake
@@ -181,6 +181,9 @@ files:
181
181
  - examples/sample63.rb
182
182
  - examples/sample64.rb
183
183
  - examples/sample65.rb
184
+ - examples/sample66.rb
185
+ - examples/sample67.rb
186
+ - examples/sample68.rb
184
187
  - examples/sample99.rb
185
188
  - examples/sdlshapes/README
186
189
  - examples/sdlshapes/sdl.ps
@@ -228,6 +231,7 @@ files:
228
231
  - test/support.rb
229
232
  - test/test_examples.rb
230
233
  - test/test_graph.rb
234
+ - test/test_search.rb
231
235
  - test/test_theory.rb
232
236
  - test/test_types.rb
233
237
  - test/test_utils_colors.rb
@@ -242,15 +246,8 @@ post_install_message: "\n\
242
246
  * Doc : http://rdoc.info/projects/glejeune/Ruby-Graphviz\n\
243
247
  * Sources : http://github.com/glejeune/Ruby-Graphviz\n\
244
248
  * NEW - Mailing List : http://groups.google.com/group/ruby-graphviz\n\n\
245
- /!\\ Version 0.9.12 introduce a new solution to connect edges to node ports\n\
246
- For more information, see http://github.com/glejeune/Ruby-Graphviz/issues/#issue/13\n\
247
- So if you use node ports, maybe you need to change your code.\n\n\
248
- /!\\ GraphViz::Node#name has been removed!\n\n\
249
- /!\\ :output and :file options have been removed!\n\n\
250
- /!\\ The html attribut has been removed!\n\
251
- You can use the label attribut, as dot do it : :label => '<<html/>>'\n\n\
252
- /!\\ Version 0.9.17 introduce GraphML (http://graphml.graphdrawing.org/) support and\n\
253
- graph theory !\n "
249
+ /!\\ GraphViz#add_edge is deprecated, use GraphViz#add_edges\n\
250
+ /!\\ GraphViz#add_node is deprecated, use GraphViz#add_nodes\n "
254
251
  rdoc_options:
255
252
  - --title
256
253
  - Ruby/GraphViz
@@ -287,6 +284,7 @@ test_files:
287
284
  - test/support.rb
288
285
  - test/test_examples.rb
289
286
  - test/test_graph.rb
287
+ - test/test_search.rb
290
288
  - test/test_theory.rb
291
289
  - test/test_types.rb
292
290
  - test/test_utils_colors.rb