graph 2.1.0 → 2.2.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.2.0 / 2011-08-12
2
+
3
+ * 3 minor enhancements:
4
+
5
+ * Added brewer color scheme support: colorscheme(:reds, 5) creates c1 - c5.
6
+ * Added cluster subgraph shortcut
7
+ * added Node.connected? and Node.orphan?
8
+
9
+ * 1 bug fix:
10
+
11
+ * Fixed output of single node graphs. (aja)
12
+
1
13
  === 2.1.0 / 2011-05-26
2
14
 
3
15
  * 3 minor enhancements:
data/README.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  = graph
2
2
 
3
- * http://rubyforge.org/projects/seattlerb
3
+ home :: https://github.com/seattlerb/graph
4
4
 
5
5
  == DESCRIPTION:
6
6
 
data/lib/graph.rb CHANGED
@@ -7,7 +7,7 @@ require "enumerator"
7
7
  # dot format.
8
8
 
9
9
  class Graph
10
- VERSION = "2.1.0" # :nodoc:
10
+ VERSION = "2.2.0" # :nodoc:
11
11
 
12
12
  LIGHT_COLORS = %w(gray lightblue lightcyan lightgray lightpink
13
13
  lightslategray lightsteelblue white)
@@ -27,6 +27,22 @@ class Graph
27
27
  "dodgerblue", "sienna", "limegreen", "royalblue",
28
28
  "darkorange", "blue"]
29
29
 
30
+ ##
31
+ # Defines the brewer color schemes and the maximum number of colors
32
+ # in each set.
33
+
34
+ COLOR_SCHEME_MAX = {
35
+ :accent => 8, :blues => 9, :brbg => 11, :bugn => 9,
36
+ :dark2 => 8, :gnbu => 9, :greens => 9, :greys => 9,
37
+ :oranges => 9, :orrd => 9, :paired => 12, :pastel1 => 9,
38
+ :pastel2 => 8, :piyg => 11, :prgn => 11, :pubu => 9,
39
+ :pubugn => 9, :puor => 11, :purd => 9, :purples => 9,
40
+ :rdbu => 11, :rdgy => 11, :rdylbu => 11, :rdylgn => 11,
41
+ :reds => 9, :set1 => 9, :set2 => 8, :set3 => 12,
42
+ :spectral => 11, :ylgn => 9, :ylgnbu => 9, :ylorbr => 9,
43
+ :ylorrd => 9
44
+ }
45
+
30
46
  SHAPES = %w(Mcircle Mdiamond Msquare box box3d circle component
31
47
  diamond doublecircle doubleoctagon egg ellipse folder
32
48
  hexagon house invhouse invtrapezium invtriangle none
@@ -139,10 +155,27 @@ class Graph
139
155
  end
140
156
 
141
157
  ##
142
- # Shortcut method to create a new colorscheme Attribute instance.
158
+ # Shortcut method to create a new colorscheme Attribute instance. If
159
+ # passed +n+, +name+ must match one of the brewer color scheme names
160
+ # and it will generate accessors for each fillcolor as well as push
161
+ # the colorscheme onto the node_attribs.
162
+
163
+ def colorscheme name, n = nil
164
+ scheme = Attribute.new "colorscheme = #{name}#{n}"
165
+ max = COLOR_SCHEME_MAX[name.to_sym]
166
+
167
+ if max then
168
+ node_attribs << scheme
143
169
 
144
- def colorscheme name
145
- Attribute.new "colorscheme = #{name}"
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
177
+
178
+ scheme
146
179
  end
147
180
 
148
181
  ##
@@ -257,6 +290,15 @@ class Graph
257
290
  Graph.new name, self, &block
258
291
  end
259
292
 
293
+ ##
294
+ # Shortcut method to create a clustered subgraph in the current
295
+ # graph. Use with the top-level +digraph+ method in block form for a
296
+ # graph DSL.
297
+
298
+ def cluster name, &block
299
+ subgraph "cluster_#{name}", &block
300
+ end
301
+
260
302
  ##
261
303
  # Outputs a graphviz graph.
262
304
 
@@ -284,7 +326,7 @@ class Graph
284
326
  end
285
327
 
286
328
  nodes.each do |name, node|
287
- result << " #{node};" if graph or node.attributes?
329
+ result << " #{node};" if graph or node.attributes? or node.orphan?
288
330
  end
289
331
 
290
332
  edges.each do |from, deps|
@@ -397,6 +439,17 @@ class Graph
397
439
 
398
440
  attr_accessor :name
399
441
 
442
+ def connected?
443
+ node = self.name
444
+ edges = graph.edges
445
+
446
+ edges.include?(name) or edges.any? { |from, deps| deps.include? name }
447
+ end
448
+
449
+ def orphan?
450
+ not connected?
451
+ end
452
+
400
453
  ##
401
454
  # Create a new Node. Takes a parent graph and a name.
402
455
 
data/test/test_graph.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "rubygems"
1
2
  require "minitest/autorun"
2
3
  require "tmpdir"
3
4
  require "graph"
@@ -37,6 +38,19 @@ class TestGraph < MiniTest::Unit::TestCase
37
38
 
38
39
  def test_colorscheme
39
40
  assert_attribute "colorscheme", "blah", graph.colorscheme("blah")
41
+ assert_empty graph.node_attribs
42
+ refute_respond_to graph, :c1
43
+ end
44
+
45
+ def test_colorscheme_n
46
+ cs = graph.colorscheme("reds", 5)
47
+ assert_attribute "colorscheme", "reds5", cs
48
+ assert_equal [cs], graph.node_attribs
49
+ assert_equal "fillcolor = 1", graph.c1.to_s
50
+ assert_equal "fillcolor = 2", graph.c2.to_s
51
+ assert_equal "fillcolor = 3", graph.c3.to_s
52
+ assert_equal "fillcolor = 4", graph.c4.to_s
53
+ assert_equal "fillcolor = 5", graph.c5.to_s
40
54
  end
41
55
 
42
56
  def test_fillcolor
@@ -76,6 +90,19 @@ class TestGraph < MiniTest::Unit::TestCase
76
90
  assert_equal %w(a), invert.edges["c"].keys
77
91
  end
78
92
 
93
+ def test_node_orphan
94
+ exp = 'digraph { "B"; }'
95
+
96
+ y = digraph do node "B" end
97
+
98
+ assert_equal exp, y.to_s.gsub(/\s+/m, " ")
99
+
100
+ z = digraph do self["B"] end
101
+
102
+ assert_equal exp, z.to_s.gsub(/\s+/m, " ")
103
+ end
104
+
105
+
79
106
  def test_label
80
107
  graph.label "blah"
81
108
 
@@ -152,6 +179,17 @@ class TestGraph < MiniTest::Unit::TestCase
152
179
  assert_equal 42, n
153
180
  end
154
181
 
182
+ def test_cluster
183
+ n = nil
184
+ s = graph.cluster "blah" do
185
+ n = 42
186
+ end
187
+
188
+ assert_equal graph, s.graph
189
+ assert_equal "cluster_blah", s.name
190
+ assert_equal 42, n
191
+ end
192
+
155
193
  def test_to_s
156
194
  assert_graph graph, '"a" -> "b"'
157
195
 
@@ -255,6 +293,34 @@ class TestNode < MiniTest::Unit::TestCase
255
293
  self.n = Graph::Node.new :graph, "n"
256
294
  end
257
295
 
296
+ def test_connected_eh
297
+ graph = Graph.new
298
+ self.n = graph.node "n"
299
+ m = graph.node "m"
300
+
301
+ refute n.connected?
302
+ refute m.connected?
303
+
304
+ graph.edge("n", "m")
305
+
306
+ assert n.connected?
307
+ assert m.connected?
308
+ end
309
+
310
+ def test_orphan_eh
311
+ graph = Graph.new
312
+ self.n = graph.node "n"
313
+ m = graph.node "m"
314
+
315
+ assert n.orphan?
316
+ assert m.orphan?
317
+
318
+ graph.edge("n", "m")
319
+
320
+ refute n.orphan?
321
+ refute m.orphan?
322
+ end
323
+
258
324
  def test_rshift
259
325
  graph = Graph.new
260
326
  self.n = graph.node "blah"
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: 11
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 2.1.0
10
+ version: 2.2.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-05-27 00:00:00 Z
39
+ date: 2011-08-13 00:00:00 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
@@ -46,12 +46,12 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- hash: 11
49
+ hash: 31
50
50
  segments:
51
51
  - 2
52
- - 1
52
+ - 4
53
53
  - 0
54
- version: 2.1.0
54
+ version: 2.4.0
55
55
  type: :development
56
56
  version_requirements: *id001
57
57
  - !ruby/object:Gem::Dependency
@@ -60,14 +60,13 @@ dependencies:
60
60
  requirement: &id002 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
- - - ">="
63
+ - - ~>
64
64
  - !ruby/object:Gem::Version
65
- hash: 35
65
+ hash: 21
66
66
  segments:
67
67
  - 2
68
- - 9
69
- - 4
70
- version: 2.9.4
68
+ - 11
69
+ version: "2.11"
71
70
  type: :development
72
71
  version_requirements: *id002
73
72
  description: |-
@@ -120,7 +119,7 @@ files:
120
119
  - lib/rubygems_plugin.rb
121
120
  - test/test_graph.rb
122
121
  - .gemtest
123
- homepage: http://rubyforge.org/projects/seattlerb
122
+ homepage: https://github.com/seattlerb/graph
124
123
  licenses: []
125
124
 
126
125
  post_install_message:
@@ -150,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
149
  requirements: []
151
150
 
152
151
  rubyforge_project: seattlerb
153
- rubygems_version: 1.8.3
152
+ rubygems_version: 1.8.8
154
153
  signing_key:
155
154
  specification_version: 3
156
155
  summary: Graph is a type of hash that outputs in graphviz's dot format
metadata.gz.sig CHANGED
Binary file