ruby-graphviz_c 1.1.0

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 (184) hide show
  1. checksums.yaml +7 -0
  2. data/.gemrc +0 -0
  3. data/.gitignore +9 -0
  4. data/.travis.yml +7 -0
  5. data/AUTHORS.rdoc +33 -0
  6. data/CHANGELOG.rdoc +287 -0
  7. data/COPYING.rdoc +133 -0
  8. data/Gemfile +4 -0
  9. data/README.rdoc +206 -0
  10. data/Rakefile +71 -0
  11. data/bin/dot2ruby +91 -0
  12. data/bin/gem2gv +165 -0
  13. data/bin/git2gv +167 -0
  14. data/bin/ruby2gv +234 -0
  15. data/bin/xml2gv +96 -0
  16. data/examples/dot/JSP.dot +52 -0
  17. data/examples/dot/balanced.dot +36 -0
  18. data/examples/dot/cluster.dot +30 -0
  19. data/examples/dot/dotgraph.dot +28 -0
  20. data/examples/dot/fsm.dot +20 -0
  21. data/examples/dot/genetic.dot +118 -0
  22. data/examples/dot/hello.dot +1 -0
  23. data/examples/dot/hello_test.rb +33 -0
  24. data/examples/dot/lion_share.dot +103 -0
  25. data/examples/dot/prof.dot +150 -0
  26. data/examples/dot/psg.dot +28 -0
  27. data/examples/dot/rank.dot +6 -0
  28. data/examples/dot/sdh.dot +284 -0
  29. data/examples/dot/siblings.dot +492 -0
  30. data/examples/dot/so-sample001.gv +30 -0
  31. data/examples/dot/so-sample002.gv +33 -0
  32. data/examples/dot/so-sample003.gv +45 -0
  33. data/examples/dot/test.dot +17 -0
  34. data/examples/dot/test_parse.rb +13 -0
  35. data/examples/dot/this_crach_with_dot_2.20.dot +24 -0
  36. data/examples/dot/unix.dot +104 -0
  37. data/examples/graphml/attributes.ext.graphml +12 -0
  38. data/examples/graphml/attributes.graphml +40 -0
  39. data/examples/graphml/cluster.graphml +75 -0
  40. data/examples/graphml/failed_graph.graphml +461 -0
  41. data/examples/graphml/hyper.graphml +29 -0
  42. data/examples/graphml/nested.graphml +54 -0
  43. data/examples/graphml/port.graphml +32 -0
  44. data/examples/graphml/simple.graphml +30 -0
  45. data/examples/hello.png +0 -0
  46. data/examples/rgv/rgv.ps +125 -0
  47. data/examples/rgv/test_rgv.rb +12 -0
  48. data/examples/sample01.rb +32 -0
  49. data/examples/sample02.rb +42 -0
  50. data/examples/sample03.rb +31 -0
  51. data/examples/sample04.rb +22 -0
  52. data/examples/sample05.rb +32 -0
  53. data/examples/sample06.rb +46 -0
  54. data/examples/sample07.rb +23 -0
  55. data/examples/sample08.rb +34 -0
  56. data/examples/sample09.rb +50 -0
  57. data/examples/sample10.rb +50 -0
  58. data/examples/sample11.rb +42 -0
  59. data/examples/sample12.rb +55 -0
  60. data/examples/sample13.rb +48 -0
  61. data/examples/sample14.rb +44 -0
  62. data/examples/sample15.rb +25 -0
  63. data/examples/sample16.rb +8 -0
  64. data/examples/sample17.rb +92 -0
  65. data/examples/sample18.rb +24 -0
  66. data/examples/sample19.rb +59 -0
  67. data/examples/sample20.rb +47 -0
  68. data/examples/sample21.rb +12 -0
  69. data/examples/sample22.rb +10 -0
  70. data/examples/sample23.rb +11 -0
  71. data/examples/sample24.rb +11 -0
  72. data/examples/sample25.rb +11 -0
  73. data/examples/sample26.rb +8 -0
  74. data/examples/sample27.rb +8 -0
  75. data/examples/sample28.rb +12 -0
  76. data/examples/sample29.rb +8 -0
  77. data/examples/sample30.rb +12 -0
  78. data/examples/sample31.rb +10 -0
  79. data/examples/sample32.rb +14 -0
  80. data/examples/sample33.rb +43 -0
  81. data/examples/sample34.rb +29 -0
  82. data/examples/sample35.rb +43 -0
  83. data/examples/sample36.rb +35 -0
  84. data/examples/sample37.rb +87 -0
  85. data/examples/sample38.rb +12 -0
  86. data/examples/sample39.rb +11 -0
  87. data/examples/sample40.rb +17 -0
  88. data/examples/sample41.rb +8 -0
  89. data/examples/sample42.rb +35 -0
  90. data/examples/sample43.rb +26 -0
  91. data/examples/sample44.rb +97 -0
  92. data/examples/sample45.rb +24 -0
  93. data/examples/sample46.rb +43 -0
  94. data/examples/sample47.rb +7 -0
  95. data/examples/sample48.rb +62 -0
  96. data/examples/sample49.rb +10 -0
  97. data/examples/sample50.rb +215 -0
  98. data/examples/sample51.rb +37 -0
  99. data/examples/sample52.rb +62 -0
  100. data/examples/sample53.rb +26 -0
  101. data/examples/sample54.rb +26 -0
  102. data/examples/sample55.rb +9 -0
  103. data/examples/sample56.rb +10 -0
  104. data/examples/sample57.rb +8 -0
  105. data/examples/sample58.rb +33 -0
  106. data/examples/sample59.rb +14 -0
  107. data/examples/sample60.rb +12 -0
  108. data/examples/sample61.rb +12 -0
  109. data/examples/sample62.rb +24 -0
  110. data/examples/sample63.rb +32 -0
  111. data/examples/sample64.rb +31 -0
  112. data/examples/sample65.rb +9 -0
  113. data/examples/sample66.rb +4 -0
  114. data/examples/sample67.rb +10 -0
  115. data/examples/sample68.rb +27 -0
  116. data/examples/sample69.rb +23 -0
  117. data/examples/sample70.rb +9 -0
  118. data/examples/sample99.rb +70 -0
  119. data/examples/sdlshapes/README +2 -0
  120. data/examples/sdlshapes/sdl.ps +655 -0
  121. data/examples/sdlshapes/sdlshapes.dot +78 -0
  122. data/examples/test.xml +26 -0
  123. data/examples/theory/pert.rb +47 -0
  124. data/examples/theory/tests.rb +87 -0
  125. data/lib/ext/gvpr/dot2ruby.g +185 -0
  126. data/lib/graphviz/attrs.rb +73 -0
  127. data/lib/graphviz/constants.rb +294 -0
  128. data/lib/graphviz/core_ext.rb +64 -0
  129. data/lib/graphviz/dot2ruby.rb +59 -0
  130. data/lib/graphviz/dot_script.rb +109 -0
  131. data/lib/graphviz/dsl.rb +67 -0
  132. data/lib/graphviz/edge.rb +197 -0
  133. data/lib/graphviz/elements.rb +39 -0
  134. data/lib/graphviz/ext.rb +17 -0
  135. data/lib/graphviz/family_tree/couple.rb +63 -0
  136. data/lib/graphviz/family_tree/generation.rb +39 -0
  137. data/lib/graphviz/family_tree/person.rb +120 -0
  138. data/lib/graphviz/family_tree/sibling.rb +13 -0
  139. data/lib/graphviz/family_tree.rb +118 -0
  140. data/lib/graphviz/graphml.rb +268 -0
  141. data/lib/graphviz/math/matrix.rb +221 -0
  142. data/lib/graphviz/node.rb +160 -0
  143. data/lib/graphviz/nothugly/nothugly.xsl +321 -0
  144. data/lib/graphviz/nothugly.rb +63 -0
  145. data/lib/graphviz/theory.rb +321 -0
  146. data/lib/graphviz/types/arrow_type.rb +32 -0
  147. data/lib/graphviz/types/color.rb +58 -0
  148. data/lib/graphviz/types/color_list.rb +24 -0
  149. data/lib/graphviz/types/esc_string.rb +20 -0
  150. data/lib/graphviz/types/gv_bool.rb +49 -0
  151. data/lib/graphviz/types/gv_double.rb +32 -0
  152. data/lib/graphviz/types/html_string.rb +18 -0
  153. data/lib/graphviz/types/lbl_string.rb +22 -0
  154. data/lib/graphviz/types/rect.rb +35 -0
  155. data/lib/graphviz/types/spline_type.rb +77 -0
  156. data/lib/graphviz/types.rb +22 -0
  157. data/lib/graphviz/utils/colors.rb +1018 -0
  158. data/lib/graphviz/utils.rb +70 -0
  159. data/lib/graphviz/xml.rb +119 -0
  160. data/lib/graphviz.rb +967 -0
  161. data/lib/ruby-graphviz.rb +1 -0
  162. data/man/dot2ruby.1 +66 -0
  163. data/man/dot2ruby.1.ronn +55 -0
  164. data/man/gem2gv.1 +60 -0
  165. data/man/gem2gv.1.ronn +47 -0
  166. data/man/git2gv.1 +48 -0
  167. data/man/git2gv.1.ronn +40 -0
  168. data/man/ruby2gv.1 +60 -0
  169. data/man/ruby2gv.1.ronn +47 -0
  170. data/man/xml2gv.1 +48 -0
  171. data/man/xml2gv.1.ronn +39 -0
  172. data/ruby-graphviz.gemspec +47 -0
  173. data/setup.rb +1585 -0
  174. data/test/helper.rb +13 -0
  175. data/test/support.rb +95 -0
  176. data/test/test_dot_script.rb +47 -0
  177. data/test/test_examples.rb +151 -0
  178. data/test/test_graph.rb +115 -0
  179. data/test/test_search.rb +29 -0
  180. data/test/test_subgraph.rb +27 -0
  181. data/test/test_theory.rb +98 -0
  182. data/test/test_types.rb +65 -0
  183. data/test/test_utils_colors.rb +52 -0
  184. metadata +301 -0
@@ -0,0 +1,78 @@
1
+ digraph test
2
+ {
3
+ sdl_task [shape=sdl_task, color=red, fillcolor=cyan, style=filled, peripheries=0];
4
+ sdl_task2 [shape=sdl_task, label="sdl_task", peripheries=0];
5
+ sdl_task -> sdl_task2;
6
+ sdl_input_from_right [shape=sdl_input_from_right, color=red, fillcolor=cyan, style=filled, peripheries=0];
7
+ sdl_input_from_right2 [shape=sdl_input_from_right, label="sdl_input_from_right ", peripheries=0];
8
+ sdl_input_from_right -> sdl_input_from_right2;
9
+ sdl_input_from_left [shape=sdl_input_from_left, color=red, fillcolor=cyan, style=filled, peripheries=0];
10
+ sdl_input_from_left2 [shape=sdl_input_from_left, label=" sdl_input_from_left", peripheries=0];
11
+ sdl_input_from_left -> sdl_input_from_left2;
12
+ sdl_priority_input_from_right [shape=sdl_priority_input_from_right, color=red, fillcolor=cyan, style=filled, peripheries=0];
13
+ sdl_priority_input_from_right2 [shape=sdl_priority_input_from_right, label="sdl_priority_input_from_right ", peripheries=0];
14
+ sdl_priority_input_from_right -> sdl_priority_input_from_right2;
15
+ sdl_priority_input_from_left [shape=sdl_priority_input_from_left, color=red, fillcolor=cyan, style=filled, peripheries=0];
16
+ sdl_priority_input_from_left2 [shape=sdl_priority_input_from_left, label=" sdl_priority_input_from_left", peripheries=0];
17
+ sdl_priority_input_from_left -> sdl_priority_input_from_left2;
18
+ sdl_start [shape=sdl_start, color=red, fillcolor=cyan, style=filled, peripheries=0];
19
+ sdl_start2 [shape=sdl_start, label=" ", peripheries=0];
20
+ sdl_start -> sdl_start2;
21
+ sdl_procedure_start [shape=sdl_procedure_start, color=red, fillcolor=cyan, style=filled, peripheries=0];
22
+ sdl_procedure_start2 [shape=sdl_procedure_start, label=" ", peripheries=0];
23
+ sdl_procedure_start -> sdl_procedure_start2;
24
+ sdl_state [shape=sdl_state, color=red, fillcolor=cyan, style=filled, peripheries=0];
25
+ sdl_state2 [shape=sdl_state, peripheries=0];
26
+ sdl_state -> sdl_state2;
27
+ sdl_output_to_right [shape=sdl_output_to_right, color=red, fillcolor=cyan, style=filled, peripheries=0];
28
+ sdl_output_to_right2 [shape=sdl_output_to_right, label="sdl_output_to_right ", peripheries=0];
29
+ sdl_output_to_right -> sdl_output_to_right2;
30
+ sdl_output_to_left [shape=sdl_output_to_left, color=red, fillcolor=cyan, style=filled, peripheries=0];
31
+ sdl_output_to_left2 [shape=sdl_output_to_left, label=" sdl_output_to_left", peripheries=0];
32
+ sdl_output_to_left -> sdl_output_to_left2;
33
+ sdl_condition [shape=sdl_condition, color=red, fillcolor=cyan, style=filled, peripheries=0];
34
+ sdl_condition2 [shape=sdl_condition, label=" sdl_condition ", peripheries=0];
35
+ sdl_condition -> sdl_condition2;
36
+ sdl_save [shape=sdl_save, color=red, fillcolor=cyan, style=filled, peripheries=0];
37
+ sdl_save2 [shape=sdl_save, label=" sdl_save ", peripheries=0];
38
+ sdl_save -> sdl_save2;
39
+ sdl_stop [shape=sdl_stop, peripheries=0];
40
+ sdl_stop2 [shape=sdl_stop, label="", peripheries=0];
41
+ sdl_stop -> sdl_stop2 [arrowhead=none, headclip=false];
42
+ sdl_return [shape=sdl_return, color=red, fillcolor=cyan, style=filled, peripheries=0];
43
+ sdl_return2 [shape=sdl_return, label="", peripheries=0];
44
+ sdl_return -> sdl_return2;
45
+ sdl_create [shape=sdl_create, color=red, fillcolor=cyan, style=filled, peripheries=0];
46
+ sdl_create2 [shape=sdl_create, peripheries=0];
47
+ sdl_create -> sdl_create2;
48
+ sdl_call [shape=sdl_call, color=red, fillcolor=cyan, style=filled, peripheries=0];
49
+ sdl_call2 [shape=sdl_call, label=" sdl_call ", peripheries=0];
50
+ sdl_call -> sdl_call2;
51
+ sdl_text [shape=sdl_text, color=red, fillcolor=cyan, style=filled, peripheries=0];
52
+ sdl_text2 [shape=sdl_text, peripheries=0];
53
+ sdl_text -> sdl_text2;
54
+ sdl_text_extension_from_left [shape=sdl_text_extension_from_left, color=red, fillcolor=cyan, style=filled, peripheries=0];
55
+ sdl_text_extension_from_left2 [shape=sdl_text_extension_from_left, peripheries=0];
56
+ sdl_text_extension_from_left -> sdl_text_extension_from_left2;
57
+ sdl_text_extension_from_right [shape=sdl_text_extension_from_right, color=red, fillcolor=cyan, style=filled, peripheries=0];
58
+ sdl_text_extension_from_right2 [shape=sdl_text_extension_from_right, peripheries=0];
59
+ sdl_text_extension_from_right -> sdl_text_extension_from_right2;
60
+ sdl_comment_from_left [shape=sdl_comment_from_left, color=red, fillcolor=cyan, style=filled, peripheries=0];
61
+ sdl_comment_from_left2 [shape=sdl_comment_from_left, style=dashed, peripheries=0];
62
+ sdl_comment_from_left -> sdl_comment_from_left2;
63
+ sdl_comment_from_right [shape=sdl_comment_from_right, color=red, fillcolor=cyan, style=filled, peripheries=0];
64
+ sdl_comment_from_right2 [shape=sdl_comment_from_right, style=dashed, peripheries=0];
65
+ sdl_comment_from_right -> sdl_comment_from_right2;
66
+ sdl_connector [shape=sdl_connector, color=red, fillcolor=cyan, style=filled, peripheries=0];
67
+ sdl_connector2 [shape=sdl_connector, peripheries=0];
68
+ sdl_connector -> sdl_connector2;
69
+ sdl_set [shape=sdl_set, color=red, fillcolor=cyan, style=filled, peripheries=0];
70
+ sdl_set2 [shape=sdl_set, label=" sdl_set2", peripheries=0];
71
+ sdl_set -> sdl_set2;
72
+ sdl_reset [shape=sdl_reset, color=red, fillcolor=cyan, style=filled, peripheries=0];
73
+ sdl_reset2 [shape=sdl_reset, label=" sdl_reset2", peripheries=0];
74
+ sdl_reset -> sdl_reset2;
75
+ sdl_export [shape=sdl_export, color=red, fillcolor=cyan, style=filled, peripheries=0];
76
+ sdl_export2 [shape=sdl_export, label=" sdl_export", peripheries=0];
77
+ sdl_export -> sdl_export2;
78
+ }
data/examples/test.xml ADDED
@@ -0,0 +1,26 @@
1
+ <inventory title="OmniCorp Store #45x10^3">
2
+ <section name="health">
3
+ <item upc="123456789" stock="12">
4
+ <name>Invisibility Cream</name>
5
+ <price>14.50</price>
6
+ <description>Makes you invisible</description>
7
+ </item>
8
+ <item upc="445322344" stock="18">
9
+ <name>Levitation Salve</name>
10
+ <price>23.99</price>
11
+ <description>Levitate yourself for up to 3 hours per application</description>
12
+ </item>
13
+ </section>
14
+ <section name="food">
15
+ <item upc="485672034" stock="653">
16
+ <name>Blork and Freen Instameal</name>
17
+ <price>4.95</price>
18
+ <description>A tasty meal in a tablet; just add water</description>
19
+ </item>
20
+ <item upc="132957764" stock="44">
21
+ <name>Grob winglets</name>
22
+ <price>3.56</price>
23
+ <description>Tender winglets of Grob. Just add water</description>
24
+ </item>
25
+ </section>
26
+ </inventory>
@@ -0,0 +1,47 @@
1
+ $:.unshift( "../../lib" )
2
+ require 'graphviz'
3
+ require 'graphviz/theory'
4
+
5
+ g = GraphViz.digraph( "G", :path => "/usr/local/bin", :use => "fdp" ) do |g|
6
+ g.node[:shape => "record"]
7
+
8
+ g.start[:label => "Start"]
9
+ g.task_1[:label => "Task #1 - Duration : 4d"]
10
+ g.task_2[:label => "Task #2 - Duration : 5.25d"]
11
+ g.task_3[:label => "Task #3 - Duration : 5.17d"]
12
+ g.task_4[:label => "Task #4 - Duration : 6.33d"]
13
+ g.task_5[:label => "Task #5 - Duration : 5.17d"]
14
+ g.task_6[:label => "Task #6 - Duration : 4.5d"]
15
+ g.task_7[:label => "Task #7 - Duration : 5.17d"]
16
+ g.finish[:label => "End"]
17
+
18
+ (g.start << g.task_1)[:weight => 0.0]
19
+ (g.start << g.task_2)[:weight => 0.0]
20
+ (g.task_1 << g.task_3)[:weight => 4.0]
21
+ (g.task_1 << g.task_4)[:weight => 4.0]
22
+ (g.task_2 << g.task_5)[:weight => 5.25]
23
+ (g.task_3 << g.task_5)[:weight => 5.17]
24
+ (g.task_4 << g.task_6)[:weight => 6.33]
25
+ (g.task_5 << g.task_7)[:weight => 5.17]
26
+ (g.task_6 << g.finish)[:weight => 4.5]
27
+ (g.task_7 << g.finish)[:weight => 5.17]
28
+ end
29
+ g.output( :png => "PERT.png" )
30
+
31
+ t = GraphViz::Theory.new( g )
32
+
33
+ print "Ranges : "
34
+ rr = t.range
35
+ p rr
36
+ puts "Your graph contains circuits" if rr.include?(nil)
37
+
38
+ puts "Critical path : "
39
+ rrr = t.critical_path
40
+ print "\tPath :"
41
+ _ = ""
42
+ rrr[:path].each do |i|
43
+ print _ + g.get_node_at_index(i-1).id
44
+ _ = " -> "
45
+ end
46
+ puts
47
+ puts "\tDistance : #{rrr[:distance]}"
@@ -0,0 +1,87 @@
1
+ $:.unshift( "../../lib" )
2
+ require 'graphviz'
3
+ require 'graphviz/theory'
4
+
5
+ g = GraphViz.digraph( "G", :path => "/usr/local/bin" ) do |g|
6
+ g.a[:label => "1"]
7
+ g.b[:label => "2"]
8
+ g.c[:label => "3"]
9
+ g.d[:label => "4"]
10
+ g.e[:label => "5"]
11
+ g.f[:label => "6"]
12
+
13
+ # g.a << g.a
14
+ g.a << g.b
15
+ g.a << g.d
16
+ (g.a << g.f)[:weight => 6, :label => "6"]
17
+ g.b << g.c
18
+ g.b << g.d
19
+ g.b << g.e
20
+ g.c << g.d
21
+ (g.c << g.f)[:weight => 2, :label => "2"]
22
+ g.d << g.e
23
+ # g.e << g.c
24
+ end
25
+ g.output( :png => "matrix.png" )
26
+
27
+ t = GraphViz::Theory.new( g )
28
+
29
+ puts "Adjancy matrix : "
30
+ puts t.adjancy_matrix
31
+ # => [ 0 1 0 1 0 1]
32
+ # [ 0 0 1 1 1 0]
33
+ # [ 0 0 0 1 0 1]
34
+ # [ 0 0 0 0 1 0]
35
+ # [ 0 0 0 0 0 0]
36
+ # [ 0 0 0 0 0 0]
37
+
38
+ puts "Symmetric ? #{t.symmetric?}"
39
+
40
+ puts "Incidence matrix :"
41
+ puts t.incidence_matrix
42
+ # => [ 1 1 1 0 0 0 0 0 0]
43
+ # [ -1 0 0 1 1 1 0 0 0]
44
+ # [ 0 0 0 -1 0 0 1 1 0]
45
+ # [ 0 -1 0 0 -1 0 -1 0 1]
46
+ # [ 0 0 0 0 0 -1 0 0 -1]
47
+ # [ 0 0 -1 0 0 0 0 -1 0]
48
+
49
+ g.each_node do |name, node|
50
+ puts "Degree of node `#{name}' = #{t.degree(node)}"
51
+ print "neighbors : "; p t.neighbors(name).map{ |e| e.id } # = node.neighbors.map { |e| e.id }
52
+ print "incidents : "; p t.incidents(name).map{ |e| e.id } # = node.incidents.map { |e| e.id }
53
+ end
54
+
55
+ puts "Laplacian matrix :"
56
+ puts t.laplacian_matrix
57
+ # => [ 3 -1 0 -1 0 -1]
58
+ # [ 0 4 -1 -1 -1 0]
59
+ # [ 0 0 3 -1 0 -1]
60
+ # [ 0 0 0 4 -1 0]
61
+ # [ 0 0 0 0 2 0]
62
+ # [ 0 0 0 0 0 2]
63
+
64
+ puts "Dijkstra between a and f"
65
+ r = t.moore_dijkstra(g.a, g.f)
66
+ if r.nil?
67
+ puts "No way !"
68
+ else
69
+ print "\tPath : "; p r[:path]
70
+ puts "\tDistance : #{r[:distance]}"
71
+ end
72
+ # => Path : ["a", "b", "c", "f"]
73
+ # Distance : 4.0
74
+
75
+ print "Ranges : "
76
+ rr = t.range
77
+ p rr
78
+ puts "Your graph contains circuits" if rr.include?(nil)
79
+
80
+ puts "Critical path : "
81
+ rrr = t.critical_path
82
+ print "\tPath "; p rrr[:path]
83
+ puts "\tDistance : #{rrr[:distance]}"
84
+
85
+ t.pagerank.each { |node, rank|
86
+ puts "Pagerank for node #{node.id} = #{rank}"
87
+ }
@@ -0,0 +1,185 @@
1
+ // Copyright (c) 2010 Gregoire Lejeune <gregoire.lejeune@free.fr>
2
+ //
3
+ // This program is free software; you can redistribute it and/or modify
4
+ // it under the terms of the GNU General Public License as published by
5
+ // the Free Software Foundation; either version 2 of the License, or
6
+ // (at your option) any later version.
7
+ //
8
+ // This program is distributed in the hope that it will be useful,
9
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ // GNU General Public License for more details.
12
+ //
13
+ // You should have received a copy of the GNU General Public License
14
+ // along with this program; if not, write to the Free Software
15
+ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
+ //
17
+ // Usage :
18
+ // gvpr -f dot2ruby.g [-a <output type>] <dot script>
19
+
20
+ BEGIN {
21
+ int g_strict; int g_direct;
22
+ graph_t cluster;
23
+ node_t cnode;
24
+ edge_t cedge;
25
+ string attr; string attrv;
26
+ graph_t subgraph; graph_t pgraph;
27
+ graph_t ofgraph;
28
+ graph_t sub_graph;
29
+ graph_t tmp_g;
30
+
31
+ string xOut;
32
+ if( ARGC == 0 ) {
33
+ xOut = "_";
34
+ } else {
35
+ xOut = tolower(ARGV[0]);
36
+ }
37
+
38
+ printf( "# This code was generated by dot2ruby.g\n\n" );
39
+
40
+ string rubyfy( string s ) {
41
+ string out;
42
+ out = tolower( s );
43
+ out = gsub( out, "[!a-zA-Z0-9_]", "_" );
44
+ return( out );
45
+ }
46
+
47
+ string stringify( string s ) {
48
+ string sout;
49
+ sout = gsub(s, "\"", "\\\"");
50
+ sout = gsub(sout, "@", "\\@");
51
+ sout = gsub(sout, "$", "\\$");
52
+ return( sout );
53
+ }
54
+
55
+ void load_sub_graph( graph_t p ) {
56
+ if(p == NULL) {
57
+ return;
58
+ }
59
+ sub_graph = fstsubg(p);
60
+ while( sub_graph != NULL ) {
61
+ pgraph = sub_graph.parent;
62
+ printf ( " graph_%s = graph_%s.add_graph( \"%s\" )\n", rubyfy(sub_graph.name), rubyfy(pgraph.name), rubyfy(sub_graph.name) );
63
+
64
+ // ATTRS
65
+ attr = fstAttr(sub_graph, "G");
66
+ while( attr != "" ) {
67
+ attrv = aget( sub_graph, attr );
68
+ if( attrv != "" ) {
69
+ printf( " graph_%s[:%s] = '%s'\n", rubyfy(sub_graph.name), attr, attrv );
70
+ }
71
+ attr = nxtAttr( sub_graph, "G", attr );
72
+ }
73
+ tmp_g = sub_graph;
74
+ load_sub_graph(sub_graph);
75
+ sub_graph = nxtsubg( tmp_g );
76
+
77
+ }
78
+ }
79
+
80
+ graph_t get_node_graph(node_t n, graph_t p) {
81
+ sub_graph = fstsubg(p);
82
+ while( sub_graph != NULL ) {
83
+ if( isSubnode( sub_graph, n) != 0 ) {
84
+ return get_node_graph(n, sub_graph);
85
+ }
86
+ sub_graph = nxtsubg( sub_graph );
87
+ }
88
+ return p;
89
+ }
90
+
91
+ graph_t get_edge_graph(edge_t e, graph_t p) {
92
+ sub_graph = fstsubg(p);
93
+ while( sub_graph != NULL ) {
94
+ if( isSubedge( sub_graph, e) != 0 ) {
95
+ return get_edge_graph(e, sub_graph);
96
+ }
97
+ sub_graph = nxtsubg( sub_graph );
98
+ }
99
+ return p;
100
+ }
101
+
102
+
103
+ }
104
+
105
+ BEG_G {
106
+ printf( "require 'rubygems'\nrequire 'graphviz'\n");
107
+ // Directed
108
+ g_direct = isDirect($);
109
+ if( g_direct == 0 ) {
110
+ printf( "graph_%s = GraphViz.graph( \"%s\"", rubyfy($.name), stringify($.name) );
111
+ } else {
112
+ printf( "graph_%s = GraphViz.digraph( \"%s\"", rubyfy($.name), stringify($.name) );
113
+ }
114
+ // Strict
115
+ g_strict = isStrict($);
116
+ if( g_strict != 0 ) {
117
+ printf( ", :strict => true" );
118
+ }
119
+ printf( " ) { |graph_%s|\n", rubyfy($.name) );
120
+
121
+ // Attributs of G
122
+ attr = fstAttr($, "G");
123
+ while( attr != "" ) {
124
+ attrv = aget( $, attr );
125
+ if( attrv != "" ) {
126
+ printf( " graph_%s[:%s] = '%s'\n", rubyfy($.name), attr, attrv );
127
+ }
128
+ attr = nxtAttr( $, "G", attr );
129
+ }
130
+
131
+ load_sub_graph($);
132
+ }
133
+
134
+ N {
135
+ pgraph = $.root;
136
+ ofgraph = get_node_graph($, pgraph);
137
+
138
+ printf( " node_%s = graph_%s.add_nodes( \"%s\"", rubyfy($.name), rubyfy(ofgraph.name), stringify($.name) );
139
+
140
+ // Attributs of N
141
+ attr = fstAttr($G, "N");
142
+ while( attr != "" ) {
143
+ attrv = aget( $, attr );
144
+ if( attrv != "" ) {
145
+ printf( ", :%s => '%s'", attr, gsub( attrv, "'", "\\'" ) );
146
+ } else {
147
+ printf( ", :%s => ''", attr );
148
+ }
149
+ attr = nxtAttr( $G, "N", attr );
150
+ }
151
+
152
+ printf( " )\n");
153
+ }
154
+
155
+ E {
156
+ pgraph = $.root;
157
+ ofgraph = get_edge_graph($, $.root);
158
+
159
+ printf( " graph_%s.add_edges( \"%s\", \"%s\"", rubyfy(ofgraph.name), stringify($.tail.name), stringify($.head.name) );
160
+
161
+ // Attributs of E
162
+ attr = fstAttr($G, "E");
163
+ while( attr != "" ) {
164
+ attrv = aget( $, attr );
165
+ if( attrv != "" ) {
166
+ printf( ", :%s => '%s'", attr, gsub( attrv, "'", "\\'" ) );
167
+ } else {
168
+ printf( ", :%s => ''", attr );
169
+ }
170
+ attr = nxtAttr( $G, "E", attr );
171
+ }
172
+
173
+ printf( " )\n" );
174
+ }
175
+
176
+ END_G {
177
+ printf( "}\n" );
178
+ if( xOut != "_" ) {
179
+ if( xOut == "-" ) {
180
+ printf( "@_graph_eval = graph_%s\n", rubyfy($.name) );
181
+ } else {
182
+ printf( "graph_%s.output( :%s => \"%s.%s\" )\n", rubyfy($.name), xOut, gsub($F, ".*/", ""), xOut );
183
+ }
184
+ }
185
+ }
@@ -0,0 +1,73 @@
1
+ # Copyright (C) 2004 - 2012 Gregoire Lejeune <gregoire.lejeune@free.fr>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
+
17
+ class AttributeException < RuntimeError
18
+ end
19
+
20
+ class GraphViz
21
+ class Attrs
22
+ attr_accessor :data
23
+
24
+ def initialize( gviz, name, attributes )
25
+ @name = name
26
+ @attributes = attributes
27
+ @data = Hash::new( )
28
+ @graphviz = gviz
29
+ end
30
+
31
+ def each
32
+ @data.each do |k, v|
33
+ yield(k, v)
34
+ end
35
+ end
36
+
37
+ def to_h
38
+ @data.clone
39
+ end
40
+
41
+ def []( key )
42
+ if key.class == Hash
43
+ key.each do |k, v|
44
+ self[k] = v
45
+ end
46
+ else
47
+ @data[key.to_s]
48
+ end
49
+ end
50
+
51
+ def []=( key, value )
52
+ unless @attributes.keys.include?( key.to_s )
53
+ raise ArgumentError, "#{@name} attribute '#{key.to_s}' invalid"
54
+ end
55
+
56
+ if value.nil?
57
+ warn "Value for attribute `#{key}` can't be null"
58
+ return
59
+ end
60
+
61
+ begin
62
+ value = GraphViz::Types.const_get(@attributes[key.to_s]).new( value )
63
+ rescue => e
64
+ raise AttributeException, "Invalid value `#{value}` for attribute `#{key}` : #{e}"
65
+ end
66
+
67
+ if value
68
+ @data[key.to_s] = value
69
+ @graphviz.set_position( @name, key.to_s, @data[key.to_s] ) if @graphviz
70
+ end
71
+ end
72
+ end
73
+ end