graph 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,3 +1,15 @@
1
+ === 2.3.0 / 2011-10-04
2
+
3
+ * 7 minor enhancements:
4
+
5
+ * Added CompoundAttribute
6
+ * Added arrowhead, arrowtail, and arrowsize attribute methods.
7
+ * Added default arrowhead attribute helpers (vee, box, dot, etc)..
8
+ * Added fontsize
9
+ * Attribute#+ now returns a CompoundAttribute
10
+ * Colorscheme is now passed down to subgraphs.
11
+ * font shortcut no longer takes optional fontsize.
12
+
1
13
  === 2.2.0 / 2011-08-12
2
14
 
3
15
  * 3 minor enhancements:
data/gallery/cluster.rb CHANGED
@@ -1,33 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
2
 
3
- # digraph G {
4
- #
5
- # subgraph cluster_0 {
6
- # style=filled;
7
- # color=lightgrey;
8
- # node [style=filled,color=white];
9
- # a0 -> a1 -> a2 -> a3;
10
- # label = "process #1";
11
- # }
12
- #
13
- # subgraph cluster_1 {
14
- # node [style=filled];
15
- # b0 -> b1 -> b2 -> b3;
16
- # label = "process #2";
17
- # color=blue
18
- # }
19
- # start -> a0;
20
- # start -> b0;
21
- # a1 -> b3;
22
- # b2 -> a3;
23
- # a3 -> a0;
24
- # a3 -> end;
25
- # b3 -> end;
26
- #
27
- # start [shape=Mdiamond];
28
- # end [shape=Msquare];
29
- # }
30
-
31
3
  require "graph"
32
4
 
33
5
  digraph do
data/gallery/fsm.rb CHANGED
@@ -1,26 +1,5 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- # digraph finite_state_machine {
4
- # rankdir=LR;
5
- # size="8,5"
6
- # node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8;
7
- # node [shape = circle];
8
- # LR_0 -> LR_2 [ label = "SS(B)" ];
9
- # LR_0 -> LR_1 [ label = "SS(S)" ];
10
- # LR_1 -> LR_3 [ label = "S($end)" ];
11
- # LR_2 -> LR_6 [ label = "SS(b)" ];
12
- # LR_2 -> LR_5 [ label = "SS(a)" ];
13
- # LR_2 -> LR_4 [ label = "S(A)" ];
14
- # LR_5 -> LR_7 [ label = "S(b)" ];
15
- # LR_5 -> LR_5 [ label = "S(a)" ];
16
- # LR_6 -> LR_6 [ label = "S(b)" ];
17
- # LR_6 -> LR_5 [ label = "S(a)" ];
18
- # LR_7 -> LR_8 [ label = "S(b)" ];
19
- # LR_7 -> LR_5 [ label = "S(a)" ];
20
- # LR_8 -> LR_6 [ label = "S(b)" ];
21
- # LR_8 -> LR_5 [ label = "S(a)" ];
22
- # }
23
-
24
3
  require "graph"
25
4
 
26
5
  digraph do
data/gallery/unix.rb CHANGED
@@ -1,60 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
2
 
3
- # /* courtesy Ian Darwin and Geoff Collyer, Softquad Inc. */
4
- # digraph unix {
5
- # size="6,6";
6
- # node [color=lightblue2, style=filled];
7
- # "5th Edition" -> "6th Edition";
8
- # "5th Edition" -> "PWB 1.0";
9
- # "6th Edition" -> "LSX";
10
- # "6th Edition" -> "1 BSD";
11
- # "6th Edition" -> "Mini Unix";
12
- # "6th Edition" -> "Wollongong";
13
- # "6th Edition" -> "Interdata";
14
- # "Interdata" -> "Unix/TS 3.0";
15
- # "Interdata" -> "PWB 2.0";
16
- # "Interdata" -> "7th Edition";
17
- # "7th Edition" -> "8th Edition";
18
- # "7th Edition" -> "32V";
19
- # "7th Edition" -> "V7M";
20
- # "7th Edition" -> "Ultrix-11";
21
- # "7th Edition" -> "Xenix";
22
- # "7th Edition" -> "UniPlus+";
23
- # "V7M" -> "Ultrix-11";
24
- # "8th Edition" -> "9th Edition";
25
- # "1 BSD" -> "2 BSD";
26
- # "2 BSD" -> "2.8 BSD";
27
- # "2.8 BSD" -> "Ultrix-11";
28
- # "2.8 BSD" -> "2.9 BSD";
29
- # "32V" -> "3 BSD";
30
- # "3 BSD" -> "4 BSD";
31
- # "4 BSD" -> "4.1 BSD";
32
- # "4.1 BSD" -> "4.2 BSD";
33
- # "4.1 BSD" -> "2.8 BSD";
34
- # "4.1 BSD" -> "8th Edition";
35
- # "4.2 BSD" -> "4.3 BSD";
36
- # "4.2 BSD" -> "Ultrix-32";
37
- # "PWB 1.0" -> "PWB 1.2";
38
- # "PWB 1.0" -> "USG 1.0";
39
- # "PWB 1.2" -> "PWB 2.0";
40
- # "USG 1.0" -> "CB Unix 1";
41
- # "USG 1.0" -> "USG 2.0";
42
- # "CB Unix 1" -> "CB Unix 2";
43
- # "CB Unix 2" -> "CB Unix 3";
44
- # "CB Unix 3" -> "Unix/TS++";
45
- # "CB Unix 3" -> "PDP-11 Sys V";
46
- # "USG 2.0" -> "USG 3.0";
47
- # "USG 3.0" -> "Unix/TS 3.0";
48
- # "PWB 2.0" -> "Unix/TS 3.0";
49
- # "Unix/TS 1.0" -> "Unix/TS 3.0";
50
- # "Unix/TS 3.0" -> "TS 4.0";
51
- # "Unix/TS++" -> "TS 4.0";
52
- # "CB Unix 3" -> "TS 4.0";
53
- # "TS 4.0" -> "System V.0";
54
- # "System V.0" -> "System V.2";
55
- # "System V.2" -> "System V.3";
56
- # }
57
-
58
3
  require "graph"
59
4
 
60
5
  digraph "unix" do
data/lib/graph.rb CHANGED
@@ -7,7 +7,7 @@ require "enumerator"
7
7
  # dot format.
8
8
 
9
9
  class Graph
10
- VERSION = "2.2.0" # :nodoc:
10
+ VERSION = "2.3.0" # :nodoc:
11
11
 
12
12
  LIGHT_COLORS = %w(gray lightblue lightcyan lightgray lightpink
13
13
  lightslategray lightsteelblue white)
@@ -52,6 +52,10 @@ class Graph
52
52
 
53
53
  STYLES = %w(dashed dotted solid invis bold filled diagonals rounded)
54
54
 
55
+ ARROW_RE = /(?:o?[lr]?(?:box|crow|diamond|dot|inv|none|normal|tee|vee)){1,4}/
56
+
57
+ ARROWS = %w(box crow diamond dot inv none normal tee vee)
58
+
55
59
  STYLES.each do |name|
56
60
  define_method(name) { style name }
57
61
  end
@@ -61,7 +65,13 @@ class Graph
61
65
  end
62
66
 
63
67
  SHAPES.each do |name|
64
- define_method(name.downcase) { shape name }
68
+ method_name = name.downcase.sub(/none/, 'shape_none')
69
+ define_method(method_name) { shape name }
70
+ end
71
+
72
+ ARROWS.each do |name|
73
+ method_name = name.sub(/none/, 'arrow_none')
74
+ define_method(method_name) { arrowhead name }
65
75
  end
66
76
 
67
77
  ##
@@ -122,6 +132,9 @@ class Graph
122
132
  @edge_attribs = []
123
133
  @subgraphs = []
124
134
 
135
+ self.scheme = graph.scheme if graph
136
+ node_attribs << scheme if scheme
137
+
125
138
  instance_eval(&block) if block
126
139
  end
127
140
 
@@ -140,6 +153,20 @@ class Graph
140
153
  nodes[name]
141
154
  end
142
155
 
156
+ def arrowhead shape
157
+ raise ArgumentError, "Bad arrow shape: #{shape}" unless shape =~ ARROW_RE
158
+ Attribute.new "arrowhead = #{shape}"
159
+ end
160
+
161
+ def arrowtail shape
162
+ raise ArgumentError, "Bad arrow shape: #{shape}" unless shape =~ ARROW_RE
163
+ Attribute.new "arrowtail = #{shape}"
164
+ end
165
+
166
+ def arrowsize size
167
+ Attribute.new "arrowsize = #{size}"
168
+ end
169
+
143
170
  ##
144
171
  # A convenience method to set the global node attributes to use boxes.
145
172
 
@@ -160,24 +187,23 @@ class Graph
160
187
  # and it will generate accessors for each fillcolor as well as push
161
188
  # the colorscheme onto the node_attribs.
162
189
 
190
+ attr_accessor :scheme
191
+
163
192
  def colorscheme name, n = nil
164
- scheme = Attribute.new "colorscheme = #{name}#{n}"
193
+ self.scheme = Attribute.new "colorscheme = #{name}#{n}"
165
194
  max = COLOR_SCHEME_MAX[name.to_sym]
166
195
 
167
- if max then
168
- node_attribs << scheme
169
-
170
- mc = (class << self; self; end)
171
-
172
- (1..n).map { |m|
173
- mc.send :attr_accessor, "c#{m}"
174
- self.send "c#{m}=", Graph::Attribute.new("fillcolor = #{m}")
175
- }
176
- end
196
+ node_attribs << scheme if max
177
197
 
178
198
  scheme
179
199
  end
180
200
 
201
+ (1..COLOR_SCHEME_MAX.values.max).map { |m|
202
+ define_method "c#{m}" do
203
+ Graph::Attribute.new("fillcolor = #{m}")
204
+ end
205
+ }
206
+
181
207
  ##
182
208
  # Define one or more edges.
183
209
  #
@@ -221,9 +247,12 @@ class Graph
221
247
  # Shortcut method to create a new font Attribute instance. You can
222
248
  # pass in both the name and an optional font size.
223
249
 
224
- def font name, size=nil
225
- Attribute.new "fontname = #{name.inspect}" +
226
- (size ? ", fontsize = #{size}" : "")
250
+ def font name
251
+ Attribute.new "fontname = #{name.inspect}"
252
+ end
253
+
254
+ def fontsize size
255
+ Attribute.new "fontsize = #{size}"
227
256
  end
228
257
 
229
258
  ##
@@ -372,7 +401,31 @@ class Graph
372
401
  # bad_nodes = red + filled + diamond
373
402
 
374
403
  def + style
375
- Attribute.new "#{self}, #{style}"
404
+ c = CompoundAttribute.new
405
+ c.push self
406
+ c.push style
407
+ c
408
+ end
409
+ end
410
+
411
+ class CompoundAttribute < Attribute
412
+ def initialize attr = []
413
+ super
414
+ end
415
+
416
+ def push attrib
417
+ attr.push attrib
418
+ end
419
+
420
+ def << thing
421
+ attr.each do |subattr|
422
+ subattr << thing # allows for recursive compound attributes
423
+ end
424
+ self
425
+ end
426
+
427
+ def to_s
428
+ attr.join ", "
376
429
  end
377
430
  end
378
431
 
data/test/test_graph.rb CHANGED
@@ -39,7 +39,6 @@ class TestGraph < MiniTest::Unit::TestCase
39
39
  def test_colorscheme
40
40
  assert_attribute "colorscheme", "blah", graph.colorscheme("blah")
41
41
  assert_empty graph.node_attribs
42
- refute_respond_to graph, :c1
43
42
  end
44
43
 
45
44
  def test_colorscheme_n
@@ -63,7 +62,8 @@ class TestGraph < MiniTest::Unit::TestCase
63
62
 
64
63
  def test_font_size
65
64
  # cheating... but I didn't want to write a more complex assertion
66
- assert_attribute "fontname", '"blah", fontsize = 12', graph.font("blah", 12)
65
+ assert_attribute "fontname", '"blah"', graph.font("blah")
66
+ assert_attribute "fontsize", '12', graph.fontsize(12)
67
67
  end
68
68
 
69
69
  def test_digraph
@@ -278,7 +278,8 @@ class TestAttribute < MiniTest::Unit::TestCase
278
278
 
279
279
  c = a + b
280
280
 
281
- assert_equal "blah, halb", c.attr
281
+ assert_equal [a, b], c.attr
282
+ assert_equal "blah, halb", c.to_s
282
283
  end
283
284
 
284
285
  def test_to_s
@@ -286,6 +287,19 @@ class TestAttribute < MiniTest::Unit::TestCase
286
287
  end
287
288
  end
288
289
 
290
+ class TestCompoundAttribute < TestAttribute
291
+ def test_lshift
292
+ b = Graph::Attribute.new "halb"
293
+ n = Graph::Node.new nil, nil
294
+
295
+ c = a + b
296
+
297
+ c << n # paint the node with a + b
298
+
299
+ assert_equal [a, b], n.attributes
300
+ end
301
+ end
302
+
289
303
  class TestNode < MiniTest::Unit::TestCase
290
304
  attr_accessor :n
291
305
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graph
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 2.2.0
10
+ version: 2.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Davis
@@ -36,7 +36,7 @@ cert_chain:
36
36
  FBHgymkyj/AOSqKRIpXPhjC6
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2011-08-13 00:00:00 Z
39
+ date: 2011-10-04 00:00:00 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
@@ -44,14 +44,13 @@ dependencies:
44
44
  requirement: &id001 !ruby/object:Gem::Requirement
45
45
  none: false
46
46
  requirements:
47
- - - ">="
47
+ - - ~>
48
48
  - !ruby/object:Gem::Version
49
- hash: 31
49
+ hash: 9
50
50
  segments:
51
51
  - 2
52
- - 4
53
- - 0
54
- version: 2.4.0
52
+ - 5
53
+ version: "2.5"
55
54
  type: :development
56
55
  version_requirements: *id001
57
56
  - !ruby/object:Gem::Dependency
@@ -62,11 +61,11 @@ dependencies:
62
61
  requirements:
63
62
  - - ~>
64
63
  - !ruby/object:Gem::Version
65
- hash: 21
64
+ hash: 27
66
65
  segments:
67
66
  - 2
68
- - 11
69
- version: "2.11"
67
+ - 12
68
+ version: "2.12"
70
69
  type: :development
71
70
  version_requirements: *id002
72
71
  description: |-
@@ -149,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
148
  requirements: []
150
149
 
151
150
  rubyforge_project: seattlerb
152
- rubygems_version: 1.8.8
151
+ rubygems_version: 1.8.10
153
152
  signing_key:
154
153
  specification_version: 3
155
154
  summary: Graph is a type of hash that outputs in graphviz's dot format
metadata.gz.sig CHANGED
Binary file