examples: annotate examples
[nit.git] / lib / dot / examples / clusters.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Example from http://www.graphviz.org/content/cluster
16 module clusters is example
17
18 import dot
19
20 var graph = new DotGraph("G", "digraph")
21
22 var cl0 = new DotGraph("cluster_0", "subgraph")
23 cl0["label"] = "process #1"
24 cl0["style"] = "filled"
25 cl0["color"] = "lightgrey"
26 cl0.nodes_attrs["style"] = "filled"
27 cl0.nodes_attrs["color"] = "white"
28
29 var a0 = cl0.add_node("a0")
30 var a1 = cl0.add_node("a1")
31 var a2 = cl0.add_node("a2")
32 var a3 = cl0.add_node("a3")
33 cl0.add_edge(a0, a1)
34 cl0.add_edge(a1, a2)
35 cl0.add_edge(a2, a3)
36
37 graph.add cl0
38
39 var cl1 = new DotGraph("cluster_1", "subgraph")
40 cl1["label"] = "process #2"
41 cl1["color"] = "blue"
42 cl1.nodes_attrs["style"] = "filled"
43
44 var b0 = cl1.add_node("b0")
45 var b1 = cl1.add_node("b1")
46 var b2 = cl1.add_node("b2")
47 var b3 = cl1.add_node("b3")
48 cl1.add_edge(b0, b1)
49 cl1.add_edge(b1, b2)
50 cl1.add_edge(b2, b3)
51
52 graph.add cl1
53
54 var start = graph.add_node("start")
55 start["shape"] = "Mdiamond"
56
57 var nend = graph.add_node("end")
58 nend["shape"] = "Msquare"
59
60 graph.add_edge(start, a0)
61 graph.add_edge(start, b0)
62 graph.add_edge(a1, b3)
63 graph.add_edge(b2, a3)
64 graph.add_edge(a3, a0)
65 graph.add_edge(a3, nend)
66 graph.add_edge(b3, nend)
67
68 if args.is_empty then
69 print graph.to_dot
70 # graph.show
71 else
72 graph.to_dot.write_to_file args.first
73 end