gviz 0.0.4 → 0.0.5
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.
- data/README.md +12 -11
- data/lib/gviz/version.rb +1 -1
- data/spec/gviz_spec.rb +453 -283
- metadata +2 -2
data/README.md
CHANGED
@@ -24,19 +24,22 @@ A simple example.
|
|
24
24
|
# save to files with dot and png formats(save method)
|
25
25
|
require "gviz"
|
26
26
|
|
27
|
-
|
28
|
-
gv.graph do
|
27
|
+
Graph do
|
29
28
|
route :main => [:init, :parse, :cleanup, :printf]
|
30
29
|
route :init => :make, :parse => :execute
|
31
30
|
route :execute => [:make, :compare, :printf]
|
31
|
+
|
32
|
+
save(:sample1, :png)
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
+
`Graph` is a shortcut for `Gviz.new.graph`.
|
35
36
|
|
36
37
|
This outputs `sample1.dot` and `sample1.png` files shown as below.
|
37
38
|
|
38
39
|

|
39
40
|
|
41
|
+
|
42
|
+
|
40
43
|
Add some attributes to the graph, nodes, edges.
|
41
44
|
|
42
45
|
## add color to all nodes with color set(nodes, nodeset and node methods)
|
@@ -45,8 +48,7 @@ Add some attributes to the graph, nodes, edges.
|
|
45
48
|
## add bgcolor to a graph(global method)
|
46
49
|
require "gviz"
|
47
50
|
|
48
|
-
|
49
|
-
gv.graph do
|
51
|
+
Graph.graph do
|
50
52
|
route :main => [:init, :parse, :cleanup, :printf]
|
51
53
|
route :init => :make, :parse => :execute
|
52
54
|
route :execute => [:make, :compare, :printf]
|
@@ -56,9 +58,9 @@ Add some attributes to the graph, nodes, edges.
|
|
56
58
|
edges(arrowhead:'onormal', style:'bold', color:'magenta4')
|
57
59
|
edge(:main_printf, arrowtail:'diamond', dir:'both', color:'#3355FF')
|
58
60
|
global(bgcolor:'powderblue')
|
61
|
+
|
62
|
+
save(:sample2, :png)
|
59
63
|
end
|
60
|
-
|
61
|
-
gv.save(:sample2, :png)
|
62
64
|
|
63
65
|
This outputs below.
|
64
66
|
|
@@ -72,8 +74,7 @@ Modify some.
|
|
72
74
|
## define subgraph(subgraph method)
|
73
75
|
require "gviz"
|
74
76
|
|
75
|
-
|
76
|
-
gv.graph do
|
77
|
+
Graph.graph do
|
77
78
|
route :main => [:init, :parse, :cleanup, :printf]
|
78
79
|
route :init => :make, :parse => :execute
|
79
80
|
route :execute => [:make, :compare, :printf]
|
@@ -93,9 +94,9 @@ Modify some.
|
|
93
94
|
node :init
|
94
95
|
node :make
|
95
96
|
end
|
97
|
+
|
98
|
+
save(:sample3, :png)
|
96
99
|
end
|
97
|
-
|
98
|
-
gv.save(:sample3, :png)
|
99
100
|
|
100
101
|
This outputs below.
|
101
102
|
|
data/lib/gviz/version.rb
CHANGED
data/spec/gviz_spec.rb
CHANGED
@@ -1,241 +1,356 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
3
|
|
4
|
-
describe Gviz do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
node = @g.node(:a)
|
12
|
-
node.should be_a_instance_of Gviz::Node
|
13
|
-
node.id.should eql :a
|
14
|
-
node.attrs.should be_empty
|
15
|
-
@g.nodeset.map(&:id).should eql [:a]
|
4
|
+
describe Gviz::Node do
|
5
|
+
describe ".new" do
|
6
|
+
context "when only a symbol passed" do
|
7
|
+
subject { Gviz::Node.new(:a) }
|
8
|
+
it { should be_a_instance_of Gviz::Node }
|
9
|
+
its(:id) { should be :a }
|
10
|
+
its(:attrs) { should be_empty }
|
16
11
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
|
13
|
+
context "when only a string passed" do
|
14
|
+
subject { Gviz::Node.new('a') }
|
15
|
+
it { should be_a_instance_of Gviz::Node }
|
16
|
+
its(:id) { should eq 'a' }
|
17
|
+
its(:attrs) { should be_empty }
|
22
18
|
end
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@g.nodeset.map(&:attrs).should eql [node.attrs]
|
20
|
+
context "when a symbol and hash options passed" do
|
21
|
+
opts = { shape:'circle', style:'filled' }
|
22
|
+
subject { Gviz::Node.new(:a, opts) }
|
23
|
+
its(:id) { should be :a }
|
24
|
+
its(:attrs) { should eq opts }
|
30
25
|
end
|
31
26
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
context "when a symbol with underscore passed" do
|
28
|
+
it "raise an error" do
|
29
|
+
->{ Gviz::Node.new(:a_b) }.should raise_error(ArgumentError)
|
30
|
+
end
|
36
31
|
end
|
32
|
+
end
|
37
33
|
|
38
|
-
|
39
|
-
|
34
|
+
describe "#to_s" do
|
35
|
+
subject { Gviz::Node.new(:a, style:'filled').to_s }
|
36
|
+
it { should eq "a" }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe Gviz::Edge do
|
41
|
+
describe ".new" do
|
42
|
+
context "when a symbol with an underscore passed" do
|
43
|
+
subject { Gviz::Edge.new(:a_b) }
|
44
|
+
it { should be_a_instance_of Gviz::Edge }
|
45
|
+
its(:id) { should be :a_b }
|
46
|
+
its(:st) { should be :a }
|
47
|
+
its(:ed) { should be :b }
|
48
|
+
its(:seq) { should eq 0 }
|
49
|
+
its(:st_port) { should be_nil }
|
50
|
+
its(:ed_port) { should be_nil }
|
51
|
+
its(:to_s) { should eq "a -> b" }
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when a string with an underscore passed" do
|
55
|
+
subject { Gviz::Edge.new('a_b') }
|
56
|
+
it { should be_a_instance_of Gviz::Edge }
|
57
|
+
its(:id) { should be :a_b }
|
58
|
+
its(:st) { should be :a }
|
59
|
+
its(:ed) { should be :b }
|
60
|
+
its(:seq) { should eq 0 }
|
61
|
+
its(:st_port) { should be_nil }
|
62
|
+
its(:ed_port) { should be_nil }
|
63
|
+
its(:to_s) { should eq "a -> b" }
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when a symbol with two underscores passed" do
|
67
|
+
subject { Gviz::Edge.new('a_b_1') }
|
68
|
+
it { should be_a_instance_of Gviz::Edge }
|
69
|
+
its(:id) { should be :a_b_1 }
|
70
|
+
its(:st) { should be :a }
|
71
|
+
its(:ed) { should be :b }
|
72
|
+
its(:seq) { should eq 1 }
|
73
|
+
its(:st_port) { should be_nil }
|
74
|
+
its(:ed_port) { should be_nil }
|
75
|
+
its(:to_s) { should eq "a -> b" }
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when a string with a colon passed" do
|
79
|
+
subject { Gviz::Edge.new('a:x_b:y') }
|
80
|
+
it { should be_a_instance_of Gviz::Edge }
|
81
|
+
its(:id) { should be :a_b }
|
82
|
+
its(:st) { should be :a }
|
83
|
+
its(:ed) { should be :b }
|
84
|
+
its(:seq) { should eq 0 }
|
85
|
+
its(:st_port) { should be :x }
|
86
|
+
its(:ed_port) { should be :y }
|
87
|
+
its(:to_s) { should eq "a:x -> b:y" }
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when a symbol and hash options passed" do
|
91
|
+
opts = { style:'bold', color:'red' }
|
92
|
+
subject { Gviz::Edge.new(:a_b, opts) }
|
93
|
+
its(:id) { should be :a_b }
|
94
|
+
its(:attrs) { should eq opts }
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when a string with other than words or colon passed" do
|
98
|
+
it "raise an error" do
|
99
|
+
->{ Gviz::Edge.new('a!b_c') }.should raise_error(ArgumentError)
|
100
|
+
end
|
40
101
|
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe Gviz do
|
106
|
+
let(:gv) { Gviz.new }
|
41
107
|
|
42
|
-
|
43
|
-
|
108
|
+
describe "#node" do
|
109
|
+
context "define a node" do
|
110
|
+
before { gv.node(:a) }
|
111
|
+
subject { gv.nodeset }
|
112
|
+
its(:size) { should eql 1}
|
113
|
+
its(:first) { should be_a_instance_of Gviz::Node }
|
44
114
|
end
|
45
|
-
end
|
46
115
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
@g.edgeset.map(&:to_s).should eql ["a -> b"]
|
116
|
+
context "define several nodes" do
|
117
|
+
before do
|
118
|
+
gv.node(:a)
|
119
|
+
gv.node(:b)
|
120
|
+
end
|
121
|
+
subject { gv.nodeset }
|
122
|
+
its(:size) { should eql 2 }
|
55
123
|
end
|
56
124
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
edge.ed.should eql :b
|
62
|
-
edge.attrs.should == { color:'red', arrowhead:'none' }
|
63
|
-
@g.edgeset.map(&:to_s).should eql ["a -> b"]
|
125
|
+
context "define a node with attrs" do
|
126
|
+
subject { gv.node(:a, color:'blue', label:'hello') }
|
127
|
+
its(:id) { should eql :a }
|
128
|
+
its(:attrs) { should be { color:'blue', label:'hello' } }
|
64
129
|
end
|
65
130
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
131
|
+
context "update node attrs" do
|
132
|
+
before do
|
133
|
+
gv.node(:a, color:'red', label:'hello')
|
134
|
+
gv.node(:a, color:'blue', shape:'box')
|
135
|
+
end
|
136
|
+
subject { gv.nodeset.first.attrs }
|
137
|
+
it { should be { color:'blue', label:'hello', shape:'box' } }
|
71
138
|
end
|
72
139
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
edge2.seq.should eql 1
|
78
|
-
@g.edgeset.map(&:to_s).should eql ["a -> b", "a -> b"]
|
140
|
+
context "when pass a string" do
|
141
|
+
it "raise an error" do
|
142
|
+
->{ gv.node('a') }.should raise_error(ArgumentError)
|
143
|
+
end
|
79
144
|
end
|
80
145
|
|
81
|
-
|
82
|
-
|
83
|
-
|
146
|
+
context "when pass a symbol with an underscore" do
|
147
|
+
it "raise an error" do
|
148
|
+
->{ gv.node(:a_b) }.should raise_error(ArgumentError)
|
149
|
+
end
|
84
150
|
end
|
151
|
+
end
|
85
152
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
edge.ed_port.should eql :f
|
93
|
-
edge.to_s.should eql "a:n -> b:f"
|
153
|
+
describe "#edge" do
|
154
|
+
context "define a edge" do
|
155
|
+
before { gv.edge(:a_b) }
|
156
|
+
subject { gv.edgeset }
|
157
|
+
its(:size) { should eql 1}
|
158
|
+
its(:first) { should be_a_instance_of Gviz::Edge }
|
94
159
|
end
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
160
|
+
|
161
|
+
context "update edge attrs" do
|
162
|
+
before do
|
163
|
+
gv.edge(:a_b, color:'blue', style:'bold')
|
164
|
+
gv.edge(:a_b, color:'red')
|
165
|
+
end
|
166
|
+
subject { gv.edgeset.first }
|
167
|
+
its(:attrs) { should be { color:'red', style:'bold'} }
|
101
168
|
end
|
102
169
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
170
|
+
context "define different edges with same name" do
|
171
|
+
before do
|
172
|
+
gv.edge(:a_b)
|
173
|
+
gv.edge(:a_b_1)
|
174
|
+
end
|
175
|
+
subject { gv.edgeset }
|
176
|
+
its(:size) { should eql 2 }
|
107
177
|
end
|
108
178
|
end
|
109
179
|
|
110
|
-
|
180
|
+
describe "#add" do
|
111
181
|
context "edges" do
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
182
|
+
context "one to many" do
|
183
|
+
before { gv.add :a => [:b, :c, :d] }
|
184
|
+
subject { gv.edgeset }
|
185
|
+
its(:size) { should eq 3 }
|
186
|
+
describe "nodes" do
|
187
|
+
subject { gv.nodeset }
|
188
|
+
its(:size) { should eq 4 }
|
189
|
+
end
|
116
190
|
end
|
117
191
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
192
|
+
context "many to many" do
|
193
|
+
before { gv.add [:main, :sub] => [:a, :b, :c] }
|
194
|
+
subject { gv.edgeset }
|
195
|
+
its(:size) { should eq 6 }
|
196
|
+
describe "nodes" do
|
197
|
+
subject { gv.nodeset }
|
198
|
+
its(:size) { should eq 5 }
|
199
|
+
end
|
124
200
|
end
|
125
201
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
202
|
+
context "pass two routes" do
|
203
|
+
before { gv.add :main => :sub, :sub => [:a, :b] }
|
204
|
+
subject { gv.edgeset }
|
205
|
+
its(:size) { should eq 3 }
|
206
|
+
describe "nodes" do
|
207
|
+
subject { gv.nodeset }
|
208
|
+
its(:size) { should eq 4 }
|
209
|
+
end
|
131
210
|
end
|
132
211
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
212
|
+
context "when call twice" do
|
213
|
+
before do
|
214
|
+
gv.add :main => :a, :a => [:c, :d]
|
215
|
+
gv.add :main => :b, :b => [:e, :f]
|
216
|
+
end
|
217
|
+
subject { gv.edgeset }
|
218
|
+
its(:size) { should eq 6 }
|
219
|
+
describe "nodes" do
|
220
|
+
subject { gv.nodeset }
|
221
|
+
its(:size) { should eq 7 }
|
222
|
+
end
|
140
223
|
end
|
141
224
|
end
|
142
225
|
|
143
226
|
context "nodes" do
|
144
|
-
|
145
|
-
|
146
|
-
|
227
|
+
context "one" do
|
228
|
+
before { gv.add :a }
|
229
|
+
subject { gv.nodeset }
|
230
|
+
its(:size) { should eql 1 }
|
147
231
|
end
|
148
232
|
|
149
|
-
|
150
|
-
|
151
|
-
|
233
|
+
context "several" do
|
234
|
+
before { gv.add :a, :b, :c }
|
235
|
+
subject { gv.nodeset }
|
236
|
+
its(:size) { should eql 3 }
|
152
237
|
end
|
153
238
|
|
154
|
-
|
155
|
-
|
239
|
+
context "pass a string" do
|
240
|
+
it "raise an error" do
|
241
|
+
->{ gv.add 'a' }.should raise_error(ArgumentError)
|
242
|
+
end
|
156
243
|
end
|
157
244
|
end
|
158
245
|
end
|
159
246
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
247
|
+
describe "#graph" do
|
248
|
+
context "when add routes" do
|
249
|
+
before do
|
250
|
+
gv.graph do
|
251
|
+
add :main => [:a, :b, :c]
|
252
|
+
add :a => [:d, :e]
|
253
|
+
end
|
165
254
|
end
|
166
|
-
|
167
|
-
|
168
|
-
'a -> d', 'a -> e']
|
169
|
-
@g.nodeset.map(&:id).should eql [:main, :a, :b, :c, :d, :e]
|
255
|
+
subject { gv.edgeset }
|
256
|
+
its(:size) { should eq 5 }
|
170
257
|
end
|
171
258
|
end
|
172
259
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
add :main => [:a, :b]
|
260
|
+
describe "#subgraph" do
|
261
|
+
context "when add one" do
|
262
|
+
before do
|
263
|
+
gv.subgraph { add :main => [:a, :b] }
|
177
264
|
end
|
178
|
-
|
265
|
+
subject { gv.subgraphs }
|
266
|
+
its(:size) { should eq 1 }
|
179
267
|
end
|
180
268
|
|
181
|
-
|
182
|
-
|
269
|
+
context "when add one" do
|
270
|
+
before do
|
271
|
+
gv.subgraph { add :main => [:a, :b] }
|
272
|
+
gv.subgraph { add :main => [:a, :b] }
|
273
|
+
end
|
274
|
+
subject { gv.subgraphs }
|
275
|
+
its(:size) { should eq 2 }
|
276
|
+
end
|
277
|
+
|
278
|
+
context "it has a name other than `cluster**`" do
|
279
|
+
it "raise an error" do
|
280
|
+
->{ gv.subgraph(:clu) {} }.should raise_error
|
281
|
+
end
|
183
282
|
end
|
184
283
|
end
|
185
284
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
285
|
+
describe "#nodes" do
|
286
|
+
context "set node attributes" do
|
287
|
+
opts = { style:"filled", color:"purple" }
|
288
|
+
before { gv.nodes(opts) }
|
289
|
+
subject { gv.gnode_attrs }
|
290
|
+
it { should eql opts }
|
191
291
|
end
|
192
292
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
293
|
+
context "update node attributes" do
|
294
|
+
opts1 = { style:"filled", color:"purple" }
|
295
|
+
opts2 = { color:"red", shape:"box" }
|
296
|
+
before do
|
297
|
+
gv.nodes(opts1)
|
298
|
+
gv.nodes(opts2)
|
299
|
+
end
|
300
|
+
subject { gv.gnode_attrs }
|
301
|
+
it { should be { style:"filled", color:"red", shape:"box" } }
|
199
302
|
end
|
200
303
|
end
|
201
304
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
305
|
+
describe "#edges" do
|
306
|
+
context "set edge attributes" do
|
307
|
+
opts = { style:"dotted", color:"purple" }
|
308
|
+
before { gv.edges(opts) }
|
309
|
+
subject { gv.gedge_attrs }
|
310
|
+
it { should eq opts }
|
207
311
|
end
|
208
312
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
313
|
+
context "update edge attributes" do
|
314
|
+
opts = { style:"dotted", color:"purple" }
|
315
|
+
opts2 = { color:"red", arrowhead:"none" }
|
316
|
+
before do
|
317
|
+
gv.edges(opts)
|
318
|
+
gv.edges(opts2)
|
319
|
+
end
|
320
|
+
subject { gv.gedge_attrs }
|
321
|
+
it { should be { style:"dotted", color:"red", arrowhead:"none" } }
|
215
322
|
end
|
216
323
|
end
|
217
324
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
325
|
+
describe "#global" do
|
326
|
+
context "set graph attributes" do
|
327
|
+
opts = { label:"A simple graph", rankdir:"LR" }
|
328
|
+
before { gv.global(opts) }
|
329
|
+
subject { gv.graph_attrs }
|
330
|
+
it { should eq opts }
|
223
331
|
end
|
224
332
|
end
|
225
333
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
334
|
+
describe "#rank" do
|
335
|
+
context "set same" do
|
336
|
+
before do
|
337
|
+
gv.route(:a => [:b, :c], :b => [:d, :e])
|
338
|
+
gv.rank(:same, :b, :d, :e)
|
339
|
+
end
|
340
|
+
subject { gv.ranks.first }
|
341
|
+
it { should eq [:same, [:b, :d, :e]] }
|
231
342
|
end
|
232
343
|
end
|
233
344
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
345
|
+
describe "#to_s" do
|
346
|
+
context "without attrs" do
|
347
|
+
before do
|
348
|
+
gv.add :main => [:init, :parse]
|
349
|
+
gv.add :init => :printf
|
350
|
+
end
|
351
|
+
subject { gv.to_s }
|
352
|
+
it do
|
353
|
+
should eq ~<<-EOS
|
239
354
|
digraph G {
|
240
355
|
main;
|
241
356
|
init;
|
@@ -246,166 +361,221 @@ describe Gviz do
|
|
246
361
|
init -> printf;
|
247
362
|
}
|
248
363
|
EOS
|
364
|
+
end
|
249
365
|
end
|
250
366
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
367
|
+
context "with node attrs" do
|
368
|
+
before do
|
369
|
+
gv.add :a => :b
|
370
|
+
gv.node(:a, color:'red', style:'filled')
|
371
|
+
end
|
372
|
+
subject { gv.to_s }
|
373
|
+
it do
|
374
|
+
should eq ~<<-EOS
|
255
375
|
digraph G {
|
256
376
|
a[color="red",style="filled"];
|
257
377
|
b;
|
258
378
|
a -> b;
|
259
379
|
}
|
260
380
|
EOS
|
381
|
+
end
|
261
382
|
end
|
262
383
|
|
263
|
-
|
264
|
-
|
265
|
-
|
384
|
+
context "with edge attrs" do
|
385
|
+
before do
|
386
|
+
gv.edge(:a_b, color:'red')
|
387
|
+
end
|
388
|
+
subject { gv.to_s }
|
389
|
+
it do
|
390
|
+
should eq ~<<-EOS
|
266
391
|
digraph G {
|
267
392
|
a;
|
268
393
|
b;
|
269
394
|
a -> b[color="red"];
|
270
395
|
}
|
271
396
|
EOS
|
397
|
+
end
|
272
398
|
end
|
273
399
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
400
|
+
context "with 2 edges with different attrs" do
|
401
|
+
before do
|
402
|
+
gv.edge(:a_b, color:'red')
|
403
|
+
gv.edge(:a_b_1, color:'blue')
|
404
|
+
end
|
405
|
+
subject { gv.to_s }
|
406
|
+
it do
|
407
|
+
should eq ~<<-EOS
|
408
|
+
digraph G {
|
409
|
+
a;
|
410
|
+
b;
|
411
|
+
a -> b[color="red"];
|
412
|
+
a -> b[color="blue"];
|
413
|
+
}
|
414
|
+
EOS
|
415
|
+
end
|
285
416
|
end
|
286
417
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
418
|
+
context "with global node attributes" do
|
419
|
+
before do
|
420
|
+
gv.nodes(shape:'box', style:'filled')
|
421
|
+
gv.add(:a => :b)
|
422
|
+
end
|
423
|
+
subject { gv.to_s }
|
424
|
+
it do
|
425
|
+
should eql ~<<-EOS
|
426
|
+
digraph G {
|
427
|
+
node[shape="box",style="filled"];
|
428
|
+
a;
|
429
|
+
b;
|
430
|
+
a -> b;
|
431
|
+
}
|
432
|
+
EOS
|
433
|
+
end
|
298
434
|
end
|
299
435
|
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
436
|
+
context "with global edge attributes" do
|
437
|
+
before do
|
438
|
+
gv.edges(style:'dotted', color:'red')
|
439
|
+
gv.add(:a => :b)
|
440
|
+
end
|
441
|
+
subject { gv.to_s }
|
442
|
+
it do
|
443
|
+
should eql ~<<-EOS
|
444
|
+
digraph G {
|
445
|
+
edge[style="dotted",color="red"];
|
446
|
+
a;
|
447
|
+
b;
|
448
|
+
a -> b;
|
449
|
+
}
|
450
|
+
EOS
|
451
|
+
end
|
311
452
|
end
|
312
453
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
454
|
+
context "with graph attributes" do
|
455
|
+
before do
|
456
|
+
gv.global(label:"A Simple Graph", rankdir:"LR")
|
457
|
+
gv.add(:a => :b)
|
458
|
+
end
|
459
|
+
subject { gv.to_s }
|
460
|
+
it do
|
461
|
+
should eql ~<<-EOS
|
462
|
+
digraph G {
|
463
|
+
label="A Simple Graph";
|
464
|
+
rankdir="LR";
|
465
|
+
a;
|
466
|
+
b;
|
467
|
+
a -> b;
|
468
|
+
}
|
469
|
+
EOS
|
470
|
+
end
|
325
471
|
end
|
326
472
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
473
|
+
context "when a label include `\\n`" do
|
474
|
+
before { gv.node(:a, label:"hello\nworld") }
|
475
|
+
subject { gv.to_s }
|
476
|
+
it do
|
477
|
+
should eql ~<<-EOS
|
478
|
+
digraph G {
|
479
|
+
a[label="hello\\nworld"];
|
480
|
+
}
|
481
|
+
EOS
|
482
|
+
end
|
334
483
|
end
|
335
484
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
485
|
+
context "when a label include unicode" do
|
486
|
+
before { gv.node(:a, label:"こんにちは、世界!") }
|
487
|
+
subject { gv.to_s }
|
488
|
+
it do
|
489
|
+
should eql ~<<-EOS
|
490
|
+
digraph G {
|
491
|
+
a[label="こんにちは、世界!"];
|
492
|
+
}
|
493
|
+
EOS
|
494
|
+
end
|
343
495
|
end
|
344
496
|
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
497
|
+
context "take ports on edges" do
|
498
|
+
before do
|
499
|
+
gv.route(:a => [:b, :c])
|
500
|
+
gv.edge("a:n_c:f")
|
501
|
+
gv.node(:a, label:"<n> a | b |<p> c")
|
502
|
+
gv.node(:c, label:"<o> d | e |<f> f")
|
503
|
+
end
|
504
|
+
subject { gv.to_s }
|
505
|
+
it do
|
506
|
+
should eql ~<<-EOS
|
507
|
+
digraph G {
|
508
|
+
a[label="<n> a | b |<p> c"];
|
509
|
+
b;
|
510
|
+
c[label="<o> d | e |<f> f"];
|
511
|
+
a -> b;
|
512
|
+
a:n -> c:f;
|
513
|
+
}
|
514
|
+
EOS
|
515
|
+
end
|
359
516
|
end
|
360
517
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
route :c => :d
|
518
|
+
context "with subgraph" do
|
519
|
+
before do
|
520
|
+
gv.route(:a => :b)
|
521
|
+
gv.subgraph { route :c => :d }
|
365
522
|
end
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
523
|
+
subject { gv.to_s }
|
524
|
+
it do
|
525
|
+
should eql ~<<-EOS
|
526
|
+
digraph G {
|
527
|
+
a;
|
528
|
+
b;
|
529
|
+
a -> b;
|
530
|
+
subgraph cluster0 {
|
531
|
+
c;
|
532
|
+
d;
|
533
|
+
c -> d;
|
534
|
+
}
|
375
535
|
}
|
376
|
-
|
377
|
-
|
536
|
+
EOS
|
537
|
+
end
|
378
538
|
end
|
379
539
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
540
|
+
context "with ranks" do
|
541
|
+
before do
|
542
|
+
gv.route(:a => [:b, :c], :b => [:d, :e])
|
543
|
+
gv.rank(:same, :b, :d, :e)
|
544
|
+
gv.rank(:min, :c)
|
545
|
+
end
|
546
|
+
subject { gv.to_s }
|
547
|
+
it do
|
548
|
+
should eql ~<<-EOS
|
549
|
+
digraph G {
|
550
|
+
a;
|
551
|
+
b;
|
552
|
+
c;
|
553
|
+
d;
|
554
|
+
e;
|
555
|
+
a -> b;
|
556
|
+
a -> c;
|
557
|
+
b -> d;
|
558
|
+
b -> e;
|
559
|
+
{ rank=same; b; d; e; }
|
560
|
+
{ rank=min; c; }
|
561
|
+
}
|
562
|
+
EOS
|
563
|
+
end
|
399
564
|
end
|
400
565
|
end
|
566
|
+
end
|
401
567
|
|
402
|
-
|
403
|
-
|
404
|
-
|
568
|
+
describe '#Graph' do
|
569
|
+
context "build a shortcut of Gviz.new.graph" do
|
570
|
+
before do
|
571
|
+
@gv = Graph(:X) do
|
405
572
|
add :a => [:b, :c]
|
406
573
|
end
|
407
|
-
|
408
|
-
|
574
|
+
end
|
575
|
+
subject { @gv }
|
576
|
+
it { should be_a_instance_of Gviz }
|
577
|
+
its(:to_s) do
|
578
|
+
should eql ~<<-EOS
|
409
579
|
digraph X {
|
410
580
|
a;
|
411
581
|
b;
|
@@ -416,4 +586,4 @@ describe Gviz do
|
|
416
586
|
EOS
|
417
587
|
end
|
418
588
|
end
|
419
|
-
end
|
589
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gviz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby's interface of graphviz
|
15
15
|
email:
|