ruby-graphviz 0.9.10 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/AUTHORS +1 -0
  2. data/README.rdoc +5 -0
  3. data/examples/maketest.bat +6 -0
  4. data/examples/maketest.sh +6 -0
  5. data/examples/sample30.rb.ps +923 -0
  6. data/examples/sample37.rb +87 -0
  7. data/examples/sample37.rb.dot +50 -0
  8. data/examples/sample37.rb.png +0 -0
  9. data/examples/sample38.rb +11 -0
  10. data/lib/graphviz.rb +34 -17
  11. data/lib/graphviz/constants.rb +1 -1
  12. data/lib/graphviz/core_ext.rb +23 -0
  13. data/lib/graphviz/family_tree.rb +23 -4
  14. data/lib/graphviz/family_tree/couple.rb +3 -2
  15. data/lib/graphviz/family_tree/generation.rb +4 -4
  16. data/lib/graphviz/family_tree/person.rb +27 -3
  17. data/test/output/sample01.rb.png +0 -0
  18. data/test/output/sample02.rb.png +0 -0
  19. data/test/output/sample03.rb.png +0 -0
  20. data/test/output/sample04.rb.png +0 -0
  21. data/test/output/sample05.rb.png +0 -0
  22. data/test/output/sample06.rb.png +0 -0
  23. data/test/output/sample07.rb.png +0 -0
  24. data/test/output/sample08.rb.png +0 -0
  25. data/test/output/sample09.rb.png +0 -0
  26. data/test/output/sample10.rb.png +0 -0
  27. data/test/output/sample11.rb.png +0 -0
  28. data/test/output/sample12.rb.png +0 -0
  29. data/test/output/sample13.rb.png +0 -0
  30. data/test/output/sample14.rb.png +0 -0
  31. data/test/output/sample15.rb.png +0 -0
  32. data/test/output/sample16.rb.png +0 -0
  33. data/test/output/sample17.rb.png +0 -0
  34. data/test/output/sample18.rb.png +0 -0
  35. data/test/output/sample19.rb.png +0 -0
  36. data/test/output/sample20.rb.png +0 -0
  37. data/test/output/sample21.rb.html +3 -0
  38. data/test/output/sample21.rb.png +0 -0
  39. data/test/output/sample22.rb.html +5 -0
  40. data/test/output/sample22.rb.png +0 -0
  41. data/test/output/sample23.rb.png +0 -0
  42. data/test/output/sample24.rb.png +0 -0
  43. data/test/output/sample25.rb.png +0 -0
  44. data/test/output/sample26.rb.png +0 -0
  45. data/test/output/sample28.rb.png +0 -0
  46. data/test/output/sample29.rb.svg +21 -0
  47. data/test/output/sample30.rb.ps +268 -0
  48. data/test/output/sample31.rb.png +0 -0
  49. data/test/output/sample32.rb.png +0 -0
  50. data/test/output/sample37.rb.dot +50 -0
  51. data/test/output/sample37.rb.png +0 -0
  52. data/test/output/sample38.rb.png +0 -0
  53. data/test/output/sample40.rb.png +0 -0
  54. data/test/support.rb +100 -0
  55. data/test/test_examples.rb +130 -0
  56. metadata +47 -5
  57. data/examples/sample13b.rb +0 -48
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,3 @@
1
+ base referer
2
+ poly http://www.research.att.com/base.html 133,29 130,22 121,15 107,10 89,7 69,5 50,7 32,10 17,15 8,22 5,29 8,37 17,43 32,49 50,52 69,53 89,52 107,49 121,43 130,37
3
+ poly colors.html 114,125 112,118 106,111 96,106 83,103 69,101 55,103 43,106 33,111 26,118 24,125 26,133 33,139 43,145 55,148 69,149 83,148 96,145 106,139 112,133
Binary file
@@ -0,0 +1,5 @@
1
+ <map id="mainmap" name="mainmap">
2
+ <area shape="poly" id="node1" href="http://www.research.att.com/command.html" title="command" alt="" coords="133,29 130,22 121,15 107,10 89,7 69,5 50,7 32,10 17,15 8,22 5,29 8,37 17,43 32,49 50,52 69,53 89,52 107,49 121,43 130,37"/>
3
+ <area shape="poly" id="edge2" href="colors.html" alt="" coords="72,54 72,87 67,87 67,54"/>
4
+ <area shape="rect" id="graph1" href="http://www.research.att.com/base.html" alt="" coords="0,0,139,155"/>
5
+ </map>
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
3
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <!-- Generated by graphviz version 2.26.3 (20100126.1600)
5
+ -->
6
+ <!-- Title: G Pages: 1 -->
7
+ <svg width="150pt" height="62pt"
8
+ viewBox="0.00 0.00 150.00 62.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
9
+ <g id="graph1" class="graph" transform="scale(1 1) rotate(0) translate(4 58)">
10
+ <title>G</title>
11
+ <polygon fill="white" stroke="white" points="-4,5 -4,-58 147,-58 147,5 -4,5"/>
12
+ <!-- &quot;Hello\.&quot;\nHow are you ? -->
13
+ <g id="node1" class="node"><title>&quot;Hello\.&quot;\nHow are you ?</title>
14
+ <a xlink:href="http://www.website.com" xlink:title="&quot;Hello.&quot;\nHow are you ?">
15
+ <ellipse fill="none" stroke="#ff0000" cx="71" cy="-27" rx="70.9184" ry="26.8701"/>
16
+ <text text-anchor="middle" x="71" y="-29.4" font-family="Times,serif" font-size="14.00">&quot;Hello.&quot;</text>
17
+ <text text-anchor="middle" x="71" y="-14.4" font-family="Times,serif" font-size="14.00">How are you ?</text>
18
+ </a>
19
+ </g>
20
+ </g>
21
+ </svg>
@@ -0,0 +1,268 @@
1
+ %!PS-Adobe-3.0
2
+ %%Creator: graphviz version 2.26.3 (20100126.1600)
3
+ %%Title: g
4
+ %%Pages: (atend)
5
+ %%BoundingBox: (atend)
6
+ %%EndComments
7
+ save
8
+ %%BeginProlog
9
+ /DotDict 200 dict def
10
+ DotDict begin
11
+
12
+ /setupLatin1 {
13
+ mark
14
+ /EncodingVector 256 array def
15
+ EncodingVector 0
16
+
17
+ ISOLatin1Encoding 0 255 getinterval putinterval
18
+ EncodingVector 45 /hyphen put
19
+
20
+ % Set up ISO Latin 1 character encoding
21
+ /starnetISO {
22
+ dup dup findfont dup length dict begin
23
+ { 1 index /FID ne { def }{ pop pop } ifelse
24
+ } forall
25
+ /Encoding EncodingVector def
26
+ currentdict end definefont
27
+ } def
28
+ /Times-Roman starnetISO def
29
+ /Times-Italic starnetISO def
30
+ /Times-Bold starnetISO def
31
+ /Times-BoldItalic starnetISO def
32
+ /Helvetica starnetISO def
33
+ /Helvetica-Oblique starnetISO def
34
+ /Helvetica-Bold starnetISO def
35
+ /Helvetica-BoldOblique starnetISO def
36
+ /Courier starnetISO def
37
+ /Courier-Oblique starnetISO def
38
+ /Courier-Bold starnetISO def
39
+ /Courier-BoldOblique starnetISO def
40
+ cleartomark
41
+ } bind def
42
+
43
+ %%BeginResource: procset graphviz 0 0
44
+ /coord-font-family /Times-Roman def
45
+ /default-font-family /Times-Roman def
46
+ /coordfont coord-font-family findfont 8 scalefont def
47
+
48
+ /InvScaleFactor 1.0 def
49
+ /set_scale {
50
+ dup 1 exch div /InvScaleFactor exch def
51
+ scale
52
+ } bind def
53
+
54
+ % styles
55
+ /solid { [] 0 setdash } bind def
56
+ /dashed { [9 InvScaleFactor mul dup ] 0 setdash } bind def
57
+ /dotted { [1 InvScaleFactor mul 6 InvScaleFactor mul] 0 setdash } bind def
58
+ /invis {/fill {newpath} def /stroke {newpath} def /show {pop newpath} def} bind def
59
+ /bold { 2 setlinewidth } bind def
60
+ /filled { } bind def
61
+ /unfilled { } bind def
62
+ /rounded { } bind def
63
+ /diagonals { } bind def
64
+
65
+ % hooks for setting color
66
+ /nodecolor { sethsbcolor } bind def
67
+ /edgecolor { sethsbcolor } bind def
68
+ /graphcolor { sethsbcolor } bind def
69
+ /nopcolor {pop pop pop} bind def
70
+
71
+ /beginpage { % i j npages
72
+ /npages exch def
73
+ /j exch def
74
+ /i exch def
75
+ /str 10 string def
76
+ npages 1 gt {
77
+ gsave
78
+ coordfont setfont
79
+ 0 0 moveto
80
+ (\() show i str cvs show (,) show j str cvs show (\)) show
81
+ grestore
82
+ } if
83
+ } bind def
84
+
85
+ /set_font {
86
+ findfont exch
87
+ scalefont setfont
88
+ } def
89
+
90
+ % draw text fitted to its expected width
91
+ /alignedtext { % width text
92
+ /text exch def
93
+ /width exch def
94
+ gsave
95
+ width 0 gt {
96
+ [] 0 setdash
97
+ text stringwidth pop width exch sub text length div 0 text ashow
98
+ } if
99
+ grestore
100
+ } def
101
+
102
+ /boxprim { % xcorner ycorner xsize ysize
103
+ 4 2 roll
104
+ moveto
105
+ 2 copy
106
+ exch 0 rlineto
107
+ 0 exch rlineto
108
+ pop neg 0 rlineto
109
+ closepath
110
+ } bind def
111
+
112
+ /ellipse_path {
113
+ /ry exch def
114
+ /rx exch def
115
+ /y exch def
116
+ /x exch def
117
+ matrix currentmatrix
118
+ newpath
119
+ x y translate
120
+ rx ry scale
121
+ 0 0 1 0 360 arc
122
+ setmatrix
123
+ } bind def
124
+
125
+ /endpage { showpage } bind def
126
+ /showpage { } def
127
+
128
+ /layercolorseq
129
+ [ % layer color sequence - darkest to lightest
130
+ [0 0 0]
131
+ [.2 .8 .8]
132
+ [.4 .8 .8]
133
+ [.6 .8 .8]
134
+ [.8 .8 .8]
135
+ ]
136
+ def
137
+
138
+ /layerlen layercolorseq length def
139
+
140
+ /setlayer {/maxlayer exch def /curlayer exch def
141
+ layercolorseq curlayer 1 sub layerlen mod get
142
+ aload pop sethsbcolor
143
+ /nodecolor {nopcolor} def
144
+ /edgecolor {nopcolor} def
145
+ /graphcolor {nopcolor} def
146
+ } bind def
147
+
148
+ /onlayer { curlayer ne {invis} if } def
149
+
150
+ /onlayers {
151
+ /myupper exch def
152
+ /mylower exch def
153
+ curlayer mylower lt
154
+ curlayer myupper gt
155
+ or
156
+ {invis} if
157
+ } def
158
+
159
+ /curlayer 0 def
160
+
161
+ %%EndResource
162
+ %%EndProlog
163
+ %%BeginSetup
164
+ 14 default-font-family set_font
165
+ 1 setmiterlimit
166
+ % /arrowlength 10 def
167
+ % /arrowwidth 5 def
168
+
169
+ % make sure pdfmark is harmless for PS-interpreters other than Distiller
170
+ /pdfmark where {pop} {userdict /pdfmark /cleartomark load put} ifelse
171
+ % make '<<' and '>>' safe on PS Level 1 devices
172
+ /languagelevel where {pop languagelevel}{1} ifelse
173
+ 2 lt {
174
+ userdict (<<) cvn ([) cvn load put
175
+ userdict (>>) cvn ([) cvn load put
176
+ } if
177
+
178
+ %%EndSetup
179
+ setupLatin1
180
+ %%Page: 1 1
181
+ %%PageBoundingBox: 275 302 337 490
182
+ %%PageOrientation: Portrait
183
+ 0 0 1 beginpage
184
+ gsave
185
+ 275 302 62 188 boxprim clip newpath
186
+ 1 1 set_scale 0 rotate 279 307 translate
187
+ % A
188
+ gsave
189
+ 1 setlinewidth
190
+ 0 0 0 nodecolor
191
+ [ 54 180 0 180 0 144 54 144 54 180 ] 4 false sdl_procedure_start
192
+ 0 0 0 nodecolor
193
+ 14 /Times-Roman set_font
194
+ 21.5 156.9 moveto 11 (A) alignedtext
195
+ grestore
196
+ % B
197
+ gsave
198
+ 1 setlinewidth
199
+ 0 0 0 nodecolor
200
+ [ 54 108 0 108 0 72 54 72 54 108 ] 4 false sdl_save
201
+ 0 0 0 nodecolor
202
+ 14 /Times-Roman set_font
203
+ 22 84.9 moveto 10 (B) alignedtext
204
+ grestore
205
+ % A->B
206
+ gsave
207
+ 1 setlinewidth
208
+ 0 0 0 edgecolor
209
+ newpath 27 143.83 moveto
210
+ 27 136.13 27 126.97 27 118.42 curveto
211
+ stroke
212
+ 0 0 0 edgecolor
213
+ newpath 30.5 118.41 moveto
214
+ 27 108.41 lineto
215
+ 23.5 118.41 lineto
216
+ closepath fill
217
+ 1 setlinewidth
218
+ solid
219
+ 0 0 0 edgecolor
220
+ newpath 30.5 118.41 moveto
221
+ 27 108.41 lineto
222
+ 23.5 118.41 lineto
223
+ closepath stroke
224
+ grestore
225
+ % n
226
+ gsave
227
+ 1 setlinewidth
228
+ 0 0 0 nodecolor
229
+ newpath 54 36 moveto
230
+ 0 36 lineto
231
+ 0 0 lineto
232
+ 54 0 lineto
233
+ closepath stroke
234
+ 0 0 0 nodecolor
235
+ 14 /Times-Roman set_font
236
+ 25 12.9 moveto 21 (g::n) alignedtext
237
+ grestore
238
+ % B->n
239
+ gsave
240
+ 1 setlinewidth
241
+ 0 0 0 edgecolor
242
+ newpath 27 71.83 moveto
243
+ 27 64.13 27 54.97 27 46.42 curveto
244
+ stroke
245
+ 0 0 0 edgecolor
246
+ newpath 30.5 46.41 moveto
247
+ 27 36.41 lineto
248
+ 23.5 46.41 lineto
249
+ closepath fill
250
+ 1 setlinewidth
251
+ solid
252
+ 0 0 0 edgecolor
253
+ newpath 30.5 46.41 moveto
254
+ 27 36.41 lineto
255
+ 23.5 46.41 lineto
256
+ closepath stroke
257
+ grestore
258
+ endpage
259
+ showpage
260
+ grestore
261
+ %%PageTrailer
262
+ %%EndPage: 1
263
+ %%Trailer
264
+ %%Pages: 1
265
+ %%BoundingBox: 275 302 337 490
266
+ end
267
+ restore
268
+ %%EOF
Binary file
Binary file
@@ -0,0 +1,50 @@
1
+ digraph Solarsys {
2
+ Sun [label = "Sun\n", penwidth = "2", fillcolor = "orange", shape = "circle", fontsize = "12", style = "filled"];
3
+ subgraph {
4
+ rank = "same";
5
+ Moon [label = "Moon\n", penwidth = "2", fillcolor = "red", shape = "circle", fontsize = "12", style = "filled"];
6
+ Earth [label = "Earth\n", penwidth = "2", fillcolor = "blue", shape = "circle", fontsize = "12", style = "filled"];
7
+ Moon -> Earth [penwidth = "2", color = "black", labeltooltip = "distance"]
8
+ }
9
+ Sun -> Earth [penwidth = "2", color = "black", labeltooltip = "distance"]
10
+ subgraph {
11
+ rank = "same";
12
+ Mercury [label = "Mercury\n", penwidth = "2", fillcolor = "green", shape = "circle", fontsize = "12", style = "filled"];
13
+ Sun -> Mercury [label = "distance", penwidth = "2", color = "black"]
14
+ }
15
+ subgraph {
16
+ rank = "same";
17
+ Venus [label = "Venus\n", penwidth = "2", fillcolor = "green", shape = "circle", fontsize = "12", style = "filled"];
18
+ Sun -> Venus [label = "distance", penwidth = "2", color = "black"]
19
+ }
20
+ subgraph {
21
+ rank = "same";
22
+ Mars [label = "Mars\n", penwidth = "2", fillcolor = "green", shape = "circle", fontsize = "12", style = "filled"];
23
+ Sun -> Mars [label = "distance", penwidth = "2", color = "black"]
24
+ }
25
+ subgraph {
26
+ rank = "same";
27
+ Jupiter [label = "Jupiter\n", penwidth = "2", fillcolor = "green", shape = "circle", fontsize = "12", style = "filled"];
28
+ Sun -> Jupiter [label = "distance", penwidth = "2", color = "black"]
29
+ }
30
+ subgraph {
31
+ rank = "same";
32
+ Saturn [label = "Saturn\n", penwidth = "2", fillcolor = "green", shape = "circle", fontsize = "12", style = "filled"];
33
+ Sun -> Saturn [label = "distance", penwidth = "2", color = "black"]
34
+ }
35
+ subgraph {
36
+ rank = "same";
37
+ Uranus [label = "Uranus\n", penwidth = "2", fillcolor = "green", shape = "circle", fontsize = "12", style = "filled"];
38
+ Sun -> Uranus [label = "distance", penwidth = "2", color = "black"]
39
+ }
40
+ subgraph {
41
+ rank = "same";
42
+ Neptune [label = "Neptune\n", penwidth = "2", fillcolor = "green", shape = "circle", fontsize = "12", style = "filled"];
43
+ Sun -> Neptune [label = "distance", penwidth = "2", color = "black"]
44
+ }
45
+ subgraph {
46
+ rank = "same";
47
+ Pluto [label = "Pluto\n", penwidth = "2", fillcolor = "green", shape = "circle", fontsize = "12", style = "filled"];
48
+ Sun -> Pluto [label = "distance", penwidth = "2", color = "black"]
49
+ }
50
+ }
Binary file
Binary file
Binary file
data/test/support.rb ADDED
@@ -0,0 +1,100 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'ruby-debug'
4
+
5
+ root = File.expand_path('../..',__FILE__)
6
+ $:.unshift(root) unless $:.include?(root)
7
+
8
+ require 'graphviz'
9
+
10
+ # hack so that the example scripts don't unnecessarily unshift @todo
11
+ class << $:
12
+ def unshift path
13
+ include?(path) ? self : super # super will return self, too
14
+ end
15
+ end
16
+
17
+ module TestSupport
18
+ extend self
19
+
20
+ # @todo move to app?
21
+ def windows?
22
+ /Windows/ =~ ENV['OS']
23
+ end
24
+
25
+ def dev_null
26
+ windows? ? 'NUL' : '/dev/null'
27
+ end
28
+ end
29
+
30
+ module IoHack
31
+
32
+ #
33
+ # this is a ridiculous hack to capture what was written to $stdout/$stderr for testing
34
+ # an alternative is to use Open3.popen3 on external calls which has overhead
35
+ # and OS dependencies.
36
+ #
37
+ # This hack would apparently not be as bad on 1.9, which would allow you to simply
38
+ # set $stdout and $stderr to instances of StringIO
39
+ #
40
+ # I don't know what is the 'right way' to test this kind of thing
41
+ #
42
+
43
+ class IoHackStream < File
44
+ #
45
+ # pre 1.9 you can't assign $stdout and $stderr to anything other than
46
+ # an IO::File instance. what we *want* is to have them be StringIOs that
47
+ # we can read from like strings for testing. So this is a crazy proxy
48
+ # around StringIO. Note it makes *all* methods except a few protected,
49
+ # which for me was failing silently when i forgot to make the appropriate
50
+ # ones public. hack!
51
+ #
52
+
53
+ except = %w(inspect kind_of?)
54
+ these = ancestors[0].instance_methods
55
+ # these = [1,2,3].map{|x| ancestors[x].instance_methods(false)}.flatten
56
+ eraseme = (these - except)
57
+ eraseme.each{ |name| protected name }
58
+ attr_reader :io
59
+ def initialize()
60
+ @io = StringIO.new
61
+ super(TestSupport.dev_null, 'r+') # probably doesn't matter the mode
62
+ end
63
+ these = %w(write << puts)
64
+ these.each do |name|
65
+ define_method(name) do |*a|
66
+ @io.send(name, *a)
67
+ end
68
+ end
69
+ end
70
+
71
+ def fake_popen2 path
72
+ push_io
73
+ require path # caller assumes responsibility for exceptions vis-a-vis stack
74
+ pop_io
75
+ end
76
+
77
+ def io_stack
78
+ @io_stack ||= []
79
+ end
80
+
81
+ def push_io
82
+ io_stack.push [$stdout, $stderr]
83
+ $stdout = IoHackStream.new
84
+ $stderr = IoHackStream.new
85
+ nil
86
+ end
87
+
88
+ def pop_io
89
+ fail('stack empty') unless io_stack.any?
90
+ result = [$stdout, $stderr]
91
+ $stdout, $stderr = io_stack.pop
92
+ result.each_with_index do |io,idx|
93
+ if io.kind_of? IoHackStream
94
+ io.io.seek(0)
95
+ result[idx] = io.io.read
96
+ end
97
+ end
98
+ result
99
+ end
100
+ end