ruby-graphviz_c 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gemrc +0 -0
- data/.gitignore +9 -0
- data/.travis.yml +7 -0
- data/AUTHORS.rdoc +33 -0
- data/CHANGELOG.rdoc +287 -0
- data/COPYING.rdoc +133 -0
- data/Gemfile +4 -0
- data/README.rdoc +206 -0
- data/Rakefile +71 -0
- data/bin/dot2ruby +91 -0
- data/bin/gem2gv +165 -0
- data/bin/git2gv +167 -0
- data/bin/ruby2gv +234 -0
- data/bin/xml2gv +96 -0
- data/examples/dot/JSP.dot +52 -0
- data/examples/dot/balanced.dot +36 -0
- data/examples/dot/cluster.dot +30 -0
- data/examples/dot/dotgraph.dot +28 -0
- data/examples/dot/fsm.dot +20 -0
- data/examples/dot/genetic.dot +118 -0
- data/examples/dot/hello.dot +1 -0
- data/examples/dot/hello_test.rb +33 -0
- data/examples/dot/lion_share.dot +103 -0
- data/examples/dot/prof.dot +150 -0
- data/examples/dot/psg.dot +28 -0
- data/examples/dot/rank.dot +6 -0
- data/examples/dot/sdh.dot +284 -0
- data/examples/dot/siblings.dot +492 -0
- data/examples/dot/so-sample001.gv +30 -0
- data/examples/dot/so-sample002.gv +33 -0
- data/examples/dot/so-sample003.gv +45 -0
- data/examples/dot/test.dot +17 -0
- data/examples/dot/test_parse.rb +13 -0
- data/examples/dot/this_crach_with_dot_2.20.dot +24 -0
- data/examples/dot/unix.dot +104 -0
- data/examples/graphml/attributes.ext.graphml +12 -0
- data/examples/graphml/attributes.graphml +40 -0
- data/examples/graphml/cluster.graphml +75 -0
- data/examples/graphml/failed_graph.graphml +461 -0
- data/examples/graphml/hyper.graphml +29 -0
- data/examples/graphml/nested.graphml +54 -0
- data/examples/graphml/port.graphml +32 -0
- data/examples/graphml/simple.graphml +30 -0
- data/examples/hello.png +0 -0
- data/examples/rgv/rgv.ps +125 -0
- data/examples/rgv/test_rgv.rb +12 -0
- data/examples/sample01.rb +32 -0
- data/examples/sample02.rb +42 -0
- data/examples/sample03.rb +31 -0
- data/examples/sample04.rb +22 -0
- data/examples/sample05.rb +32 -0
- data/examples/sample06.rb +46 -0
- data/examples/sample07.rb +23 -0
- data/examples/sample08.rb +34 -0
- data/examples/sample09.rb +50 -0
- data/examples/sample10.rb +50 -0
- data/examples/sample11.rb +42 -0
- data/examples/sample12.rb +55 -0
- data/examples/sample13.rb +48 -0
- data/examples/sample14.rb +44 -0
- data/examples/sample15.rb +25 -0
- data/examples/sample16.rb +8 -0
- data/examples/sample17.rb +92 -0
- data/examples/sample18.rb +24 -0
- data/examples/sample19.rb +59 -0
- data/examples/sample20.rb +47 -0
- data/examples/sample21.rb +12 -0
- data/examples/sample22.rb +10 -0
- data/examples/sample23.rb +11 -0
- data/examples/sample24.rb +11 -0
- data/examples/sample25.rb +11 -0
- data/examples/sample26.rb +8 -0
- data/examples/sample27.rb +8 -0
- data/examples/sample28.rb +12 -0
- data/examples/sample29.rb +8 -0
- data/examples/sample30.rb +12 -0
- data/examples/sample31.rb +10 -0
- data/examples/sample32.rb +14 -0
- data/examples/sample33.rb +43 -0
- data/examples/sample34.rb +29 -0
- data/examples/sample35.rb +43 -0
- data/examples/sample36.rb +35 -0
- data/examples/sample37.rb +87 -0
- data/examples/sample38.rb +12 -0
- data/examples/sample39.rb +11 -0
- data/examples/sample40.rb +17 -0
- data/examples/sample41.rb +8 -0
- data/examples/sample42.rb +35 -0
- data/examples/sample43.rb +26 -0
- data/examples/sample44.rb +97 -0
- data/examples/sample45.rb +24 -0
- data/examples/sample46.rb +43 -0
- data/examples/sample47.rb +7 -0
- data/examples/sample48.rb +62 -0
- data/examples/sample49.rb +10 -0
- data/examples/sample50.rb +215 -0
- data/examples/sample51.rb +37 -0
- data/examples/sample52.rb +62 -0
- data/examples/sample53.rb +26 -0
- data/examples/sample54.rb +26 -0
- data/examples/sample55.rb +9 -0
- data/examples/sample56.rb +10 -0
- data/examples/sample57.rb +8 -0
- data/examples/sample58.rb +33 -0
- data/examples/sample59.rb +14 -0
- data/examples/sample60.rb +12 -0
- data/examples/sample61.rb +12 -0
- data/examples/sample62.rb +24 -0
- data/examples/sample63.rb +32 -0
- data/examples/sample64.rb +31 -0
- data/examples/sample65.rb +9 -0
- data/examples/sample66.rb +4 -0
- data/examples/sample67.rb +10 -0
- data/examples/sample68.rb +27 -0
- data/examples/sample69.rb +23 -0
- data/examples/sample70.rb +9 -0
- data/examples/sample99.rb +70 -0
- data/examples/sdlshapes/README +2 -0
- data/examples/sdlshapes/sdl.ps +655 -0
- data/examples/sdlshapes/sdlshapes.dot +78 -0
- data/examples/test.xml +26 -0
- data/examples/theory/pert.rb +47 -0
- data/examples/theory/tests.rb +87 -0
- data/lib/ext/gvpr/dot2ruby.g +185 -0
- data/lib/graphviz/attrs.rb +73 -0
- data/lib/graphviz/constants.rb +294 -0
- data/lib/graphviz/core_ext.rb +64 -0
- data/lib/graphviz/dot2ruby.rb +59 -0
- data/lib/graphviz/dot_script.rb +109 -0
- data/lib/graphviz/dsl.rb +67 -0
- data/lib/graphviz/edge.rb +197 -0
- data/lib/graphviz/elements.rb +39 -0
- data/lib/graphviz/ext.rb +17 -0
- data/lib/graphviz/family_tree/couple.rb +63 -0
- data/lib/graphviz/family_tree/generation.rb +39 -0
- data/lib/graphviz/family_tree/person.rb +120 -0
- data/lib/graphviz/family_tree/sibling.rb +13 -0
- data/lib/graphviz/family_tree.rb +118 -0
- data/lib/graphviz/graphml.rb +268 -0
- data/lib/graphviz/math/matrix.rb +221 -0
- data/lib/graphviz/node.rb +160 -0
- data/lib/graphviz/nothugly/nothugly.xsl +321 -0
- data/lib/graphviz/nothugly.rb +63 -0
- data/lib/graphviz/theory.rb +321 -0
- data/lib/graphviz/types/arrow_type.rb +32 -0
- data/lib/graphviz/types/color.rb +58 -0
- data/lib/graphviz/types/color_list.rb +24 -0
- data/lib/graphviz/types/esc_string.rb +20 -0
- data/lib/graphviz/types/gv_bool.rb +49 -0
- data/lib/graphviz/types/gv_double.rb +32 -0
- data/lib/graphviz/types/html_string.rb +18 -0
- data/lib/graphviz/types/lbl_string.rb +22 -0
- data/lib/graphviz/types/rect.rb +35 -0
- data/lib/graphviz/types/spline_type.rb +77 -0
- data/lib/graphviz/types.rb +22 -0
- data/lib/graphviz/utils/colors.rb +1018 -0
- data/lib/graphviz/utils.rb +70 -0
- data/lib/graphviz/xml.rb +119 -0
- data/lib/graphviz.rb +967 -0
- data/lib/ruby-graphviz.rb +1 -0
- data/man/dot2ruby.1 +66 -0
- data/man/dot2ruby.1.ronn +55 -0
- data/man/gem2gv.1 +60 -0
- data/man/gem2gv.1.ronn +47 -0
- data/man/git2gv.1 +48 -0
- data/man/git2gv.1.ronn +40 -0
- data/man/ruby2gv.1 +60 -0
- data/man/ruby2gv.1.ronn +47 -0
- data/man/xml2gv.1 +48 -0
- data/man/xml2gv.1.ronn +39 -0
- data/ruby-graphviz.gemspec +47 -0
- data/setup.rb +1585 -0
- data/test/helper.rb +13 -0
- data/test/support.rb +95 -0
- data/test/test_dot_script.rb +47 -0
- data/test/test_examples.rb +151 -0
- data/test/test_graph.rb +115 -0
- data/test/test_search.rb +29 -0
- data/test/test_subgraph.rb +27 -0
- data/test/test_theory.rb +98 -0
- data/test/test_types.rb +65 -0
- data/test/test_utils_colors.rb +52 -0
- 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
|