File: sample48.rb

package info (click to toggle)
ruby-graphviz 1.0.8-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,124 kB
  • ctags: 695
  • sloc: ruby: 7,656; xml: 26; makefile: 17
file content (62 lines) | stat: -rw-r--r-- 1,268 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# http://www.graphviz.org/Gallery/directed/cluster.html
#
# digraph G {
#
# 	subgraph cluster_0 {
# 		style=filled;
# 		color=lightgrey;
# 		node [style=filled,color=white];
# 		a0 -> a1 -> a2 -> a3;
# 		label = "process #1";
# 	}
#
# 	subgraph cluster_1 {
# 		node [style=filled];
# 		b0 -> b1 -> b2 -> b3;
# 		label = "process #2";
# 		color=blue
# 	}
# 	start -> a0;
# 	start -> b0;
# 	a1 -> b3;
# 	b2 -> a3;
# 	a3 -> a0;
# 	a3 -> end;
# 	b3 -> end;
#
# 	start [shape=Mdiamond];
# 	end [shape=Msquare];
# }

$:.unshift( "../lib" );
require "graphviz"

GraphViz.new( :G, :type => :digraph ) { |g|
  g.cluster_0 { |c|
    c[:style] = :filled
    c[:color] = :lightgrey
    c.node[:style] = :filled
    c.node[:color] = :white
    c.a0 << c.a1 << c.a2 << c.a3
    c[:label] = "process #1"
  }

  g.cluster_1 { |c|
     c.node[:style] = :filled
     c.b0 << c.b1 << c.b2 << c.b3
     c[:label] = "process #1"
     c[:color] = :blue
  }

  g.start << g.cluster_0.a0
  g.start << g.cluster_1.b0
  g.cluster_0.a1 << g.cluster_1.b3
  g.cluster_1.b2 << g.cluster_0.a3
  g.cluster_0.a3 << g.cluster_0.a0
  g.cluster_0.a3 << g._end
  g.cluster_1.b3 << g._end

  g.start[:shape] = :Mdiamond
  g._end[:label] = "end"
  g._end[:shape] = :Mdiamond
}.output( :png => "#{$0}.png" )