2361e0d7f99df63f1ba1ff9c3ecef40e1f4eb7a9
[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
17 import dot
18
19 var graph = new DotGraph("G", "digraph")
20
21 var cl0 = new DotGraph("cluster_0", "subgraph")
22 cl0["label"] = "process #1"
23 cl0["style"] = "filled"
24 cl0["color"] = "lightgrey"
25 cl0.nodes_attrs["style"] = "filled"
26 cl0.nodes_attrs["color"] = "white"
27
28 var a0 = cl0.add_node("a0")
29 var a1 = cl0.add_node("a1")
30 var a2 = cl0.add_node("a2")
31 var a3 = cl0.add_node("a3")
32 cl0.add_edge(a0, a1)
33 cl0.add_edge(a1, a2)
34 cl0.add_edge(a2, a3)
35
36 graph.add cl0
37
38 var cl1 = new DotGraph("cluster_1", "subgraph")
39 cl1["label"] = "process #2"
40 cl1["color"] = "blue"
41 cl1.nodes_attrs["style"] = "filled"
42
43 var b0 = cl1.add_node("b0")
44 var b1 = cl1.add_node("b1")
45 var b2 = cl1.add_node("b2")
46 var b3 = cl1.add_node("b3")
47 cl1.add_edge(b0, b1)
48 cl1.add_edge(b1, b2)
49 cl1.add_edge(b2, b3)
50
51 graph.add cl1
52
53 var start = graph.add_node("start")
54 start["shape"] = "Mdiamond"
55
56 var nend = graph.add_node("end")
57 nend["shape"] = "Msquare"
58
59 graph.add_edge(start, a0)
60 graph.add_edge(start, b0)
61 graph.add_edge(a1, b3)
62 graph.add_edge(b2, a3)
63 graph.add_edge(a3, a0)
64 graph.add_edge(a3, nend)
65 graph.add_edge(b3, nend)
66
67 if args.is_empty then
68 print graph.to_dot
69 # graph.show
70 else
71 graph.to_dot.write_to_file args.first
72 end