network_drawer 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/README.md +83 -53
- data/Rakefile +2 -2
- data/examples/simple.json +0 -18
- data/examples/simple.png +0 -0
- data/examples/simple.svg +92 -118
- data/examples/simple.yml +0 -9
- data/examples/simple_style.yml +11 -0
- data/lib/network_drawer/diagram.rb +11 -6
- data/lib/network_drawer/element/node.rb +66 -6
- data/lib/network_drawer/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55149d158ff78d750aafb07313075edf0d391d71
|
4
|
+
data.tar.gz: 8fbd393d42398a4720b42748dd60487c4e7c5134
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64f3e725c69bc36abd67ee79a80621a2f6e5521fb368c2024d392f6482a6170f816ca6b4ec2c9a5d9c514ec6f3f01de2753f26e3aff13bb68d9ef98675ecc1c1
|
7
|
+
data.tar.gz: 2125777d7dc29d5524626fb7e74ab87b7315c06af793033a30e6b6fde052cfbbeeba669e73d96dbc0448857a22cc5c312e3394201dd0b97ef9a339e564f1d818
|
data/README.md
CHANGED
@@ -70,67 +70,97 @@ You can describe diagram with JSON.
|
|
70
70
|
|
71
71
|
You can describe diagram as follows:
|
72
72
|
|
73
|
-
|
74
|
-
```
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
73
|
+
[simple.yml](examples/simple.yml)
|
74
|
+
```yaml
|
75
|
+
layers:
|
76
|
+
- Web:
|
77
|
+
nodes:
|
78
|
+
- WebLB:
|
79
|
+
ports:
|
80
|
+
- 80/tcp
|
81
|
+
- 443/tcp
|
82
|
+
type: LB
|
83
|
+
url: https://github.com/otahi/network_drawer/
|
84
|
+
- Web001:
|
85
|
+
ports:
|
86
|
+
- 80/tcp
|
87
|
+
- Web002:
|
88
|
+
ports:
|
89
|
+
- 80/tcp
|
90
|
+
- App:
|
91
|
+
nodes:
|
92
|
+
- AppLB:
|
93
|
+
ports:
|
94
|
+
- 80/tcp
|
95
|
+
- 25/tcp
|
96
|
+
type: LB
|
97
|
+
- App001:
|
98
|
+
ports:
|
99
|
+
- 80/tcp
|
100
|
+
- 25/tcp
|
101
|
+
- App002:
|
102
|
+
ports:
|
103
|
+
- 80/tcp
|
104
|
+
- 25/tcp
|
105
|
+
nodes:
|
106
|
+
- Browser:
|
107
|
+
type: Client
|
108
|
+
- Mail Server:
|
109
|
+
type: Client
|
110
|
+
connections:
|
111
|
+
- from: Browser
|
112
|
+
to: WebLB:80/tcp
|
113
|
+
type: HTTP
|
114
|
+
- from: Browser
|
115
|
+
to: WebLB:443/tcp
|
116
|
+
- from: Mail Server
|
117
|
+
to: AppLB:25/tcp
|
118
|
+
type: SMTP
|
119
|
+
- from: WebLB
|
120
|
+
to: Web001:80/tcp
|
121
|
+
type: HTTP
|
122
|
+
- from: WebLB
|
123
|
+
to: Web002:80/tcp
|
124
|
+
type: HTTP
|
125
|
+
- from: Web001
|
126
|
+
to: AppLB:80/tcp
|
127
|
+
type: HTTP
|
128
|
+
- from: Web002
|
129
|
+
to: AppLB:80/tcp
|
130
|
+
type: HTTP
|
131
|
+
- from: AppLB
|
132
|
+
to: App001:25/tcp
|
133
|
+
type: SMTP
|
134
|
+
- from: AppLB
|
135
|
+
to: App001:80/tcp
|
136
|
+
type: HTTP
|
137
|
+
- from: AppLB
|
138
|
+
to: App002:25/tcp
|
139
|
+
type: SMTP
|
140
|
+
- from: AppLB
|
141
|
+
to: App002:80/tcp
|
142
|
+
type: HTTP
|
117
143
|
```
|
118
144
|
|
119
145
|
### Style
|
120
146
|
|
121
147
|
You can specify your style for nodes or edges with [Graphviz attributes](http://www.graphviz.org/content/attrs).
|
122
148
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
149
|
+
[simple_style.yml](examples/simple_style.yml)
|
150
|
+
```yaml
|
151
|
+
types:
|
152
|
+
WEB:
|
153
|
+
style: rounded,filled,dotted
|
154
|
+
fillcolor: azure
|
155
|
+
LB:
|
156
|
+
style: rounded,filled,dotted
|
157
|
+
fillcolor: azure
|
158
|
+
HTTP:
|
159
|
+
color: blue
|
160
|
+
SMTP:
|
161
|
+
color: green
|
131
162
|
```
|
132
163
|
|
133
|
-
|
134
164
|
## Contributing
|
135
165
|
|
136
166
|
1. Fork it ( https://github.com/otahi/network_drawer/fork )
|
data/Rakefile
CHANGED
@@ -10,8 +10,8 @@ task :update do
|
|
10
10
|
|
11
11
|
%w(png svg).each do |f|
|
12
12
|
command = 'bundle exec bin/network_drawer '
|
13
|
-
command << 'draw examples/simple.
|
14
|
-
command << "-s examples/simple_style.
|
13
|
+
command << 'draw examples/simple.yml '
|
14
|
+
command << "-s examples/simple_style.yml -f #{f}"
|
15
15
|
|
16
16
|
system(env, command)
|
17
17
|
end
|
data/examples/simple.json
CHANGED
@@ -12,24 +12,6 @@
|
|
12
12
|
},
|
13
13
|
{ "Web001": { "ports": ["80/tcp"] } },
|
14
14
|
{ "Web002": { "ports": ["80/tcp"] } }
|
15
|
-
],
|
16
|
-
"layers": [
|
17
|
-
{
|
18
|
-
"Image": {
|
19
|
-
"nodes": [
|
20
|
-
{
|
21
|
-
"ImageWeb001": {
|
22
|
-
"ports": ["80/tcp"]
|
23
|
-
}
|
24
|
-
},
|
25
|
-
{
|
26
|
-
"ImageWeb002": {
|
27
|
-
"ports": ["80/tcp"]
|
28
|
-
}
|
29
|
-
}
|
30
|
-
]
|
31
|
-
}
|
32
|
-
}
|
33
15
|
]
|
34
16
|
}
|
35
17
|
},
|
data/examples/simple.png
CHANGED
Binary file
|
data/examples/simple.svg
CHANGED
@@ -4,61 +4,35 @@
|
|
4
4
|
<!-- Generated by graphviz version 2.34.0 (20140129.0153)
|
5
5
|
-->
|
6
6
|
<!-- Title: simple Pages: 1 -->
|
7
|
-
<svg width="
|
8
|
-
viewBox="0.00 0.00
|
9
|
-
<g id="0" class="graph" transform="scale(1 1) rotate(0) translate(4
|
7
|
+
<svg width="336pt" height="460pt"
|
8
|
+
viewBox="0.00 0.00 336.00 460.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
9
|
+
<g id="0" class="graph" transform="scale(1 1) rotate(0) translate(4 456)">
|
10
10
|
<title>simple</title>
|
11
|
-
<polygon fill="white" stroke="white" points="-4,4 -4,-
|
11
|
+
<polygon fill="white" stroke="white" points="-4,4 -4,-456 332,-456 332,4 -4,4"/>
|
12
12
|
<g id="1" class="cluster"><title>cluster_Web</title>
|
13
|
-
<polygon fill="none" stroke="black" points="
|
14
|
-
<text text-anchor="middle" x="
|
13
|
+
<polygon fill="none" stroke="black" points="105,-212 105,-408 295,-408 295,-212 105,-212"/>
|
14
|
+
<text text-anchor="middle" x="200" y="-390" font-family="Helvetica,sans-Serif" font-size="14.00">Web</text>
|
15
15
|
</g>
|
16
|
-
<g id="2" class="cluster"><title>
|
17
|
-
<polygon fill="none" stroke="black" points="
|
18
|
-
<text text-anchor="middle" x="
|
19
|
-
</g>
|
20
|
-
<g id="3" class="cluster"><title>cluster_App</title>
|
21
|
-
<polygon fill="none" stroke="black" points="46,-8 46,-204 303,-204 303,-8 46,-8"/>
|
22
|
-
<text text-anchor="middle" x="174.5" y="-186" font-family="Helvetica,sans-Serif" font-size="14.00">App</text>
|
16
|
+
<g id="2" class="cluster"><title>cluster_App</title>
|
17
|
+
<polygon fill="none" stroke="black" points="63,-8 63,-204 320,-204 320,-8 63,-8"/>
|
18
|
+
<text text-anchor="middle" x="191.5" y="-186" font-family="Helvetica,sans-Serif" font-size="14.00">App</text>
|
23
19
|
</g>
|
24
20
|
<!-- 0 -->
|
25
21
|
<g id="0" class="node"><title>0</title>
|
26
|
-
<g id="a_0"><a xlink:title="
|
27
|
-
<
|
28
|
-
<polygon fill="none" stroke="black" points="
|
29
|
-
<text text-anchor="start" x="
|
30
|
-
<polygon fill="none" stroke="black" points="
|
31
|
-
<text text-anchor="start" x="
|
22
|
+
<g id="a_0"><a xlink:href="https://github.com/otahi/network_drawer/" xlink:title="WebLB">
|
23
|
+
<path fill="azure" stroke="black" stroke-dasharray="1,5" d="M247,-375.5C247,-375.5 153,-375.5 153,-375.5 147,-375.5 141,-369.5 141,-363.5 141,-363.5 141,-328.5 141,-328.5 141,-322.5 147,-316.5 153,-316.5 153,-316.5 247,-316.5 247,-316.5 253,-316.5 259,-322.5 259,-328.5 259,-328.5 259,-363.5 259,-363.5 259,-369.5 253,-375.5 247,-375.5"/>
|
24
|
+
<polygon fill="none" stroke="black" points="151,-346 151,-369 196,-369 196,-346 151,-346"/>
|
25
|
+
<text text-anchor="start" x="154.431" y="-351.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
|
26
|
+
<polygon fill="none" stroke="black" points="198,-346 198,-369 249,-369 249,-346 198,-346"/>
|
27
|
+
<text text-anchor="start" x="200.538" y="-351.9" font-family="Helvetica,sans-Serif" font-size="14.00">443/tcp</text>
|
28
|
+
<polygon fill="none" stroke="black" points="151,-322 151,-344 249,-344 249,-322 151,-322"/>
|
29
|
+
<text text-anchor="start" x="177.168" y="-327" font-family="Helvetica,sans-Serif" font-size="14.00">WebLB</text>
|
32
30
|
</a>
|
33
31
|
</g>
|
34
32
|
</g>
|
35
33
|
<!-- 1 -->
|
36
34
|
<g id="1" class="node"><title>1</title>
|
37
|
-
<g id="a_1"><a xlink:title="
|
38
|
-
<polygon fill="none" stroke="black" points="365.25,-375.5 248.75,-375.5 248.75,-316.5 365.25,-316.5 365.25,-375.5"/>
|
39
|
-
<polygon fill="none" stroke="black" points="259,-346 259,-369 356,-369 356,-346 259,-346"/>
|
40
|
-
<text text-anchor="start" x="288.431" y="-351.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
|
41
|
-
<polygon fill="none" stroke="black" points="259,-322 259,-344 356,-344 356,-322 259,-322"/>
|
42
|
-
<text text-anchor="start" x="262.096" y="-327" font-family="Helvetica,sans-Serif" font-size="14.00">ImageWeb002</text>
|
43
|
-
</a>
|
44
|
-
</g>
|
45
|
-
</g>
|
46
|
-
<!-- 2 -->
|
47
|
-
<g id="2" class="node"><title>2</title>
|
48
|
-
<g id="a_2"><a xlink:href="https://github.com/otahi/network_drawer/" xlink:title="WebLB">
|
49
|
-
<path fill="azure" stroke="black" stroke-dasharray="1,5" d="M218,-375.5C218,-375.5 124,-375.5 124,-375.5 118,-375.5 112,-369.5 112,-363.5 112,-363.5 112,-328.5 112,-328.5 112,-322.5 118,-316.5 124,-316.5 124,-316.5 218,-316.5 218,-316.5 224,-316.5 230,-322.5 230,-328.5 230,-328.5 230,-363.5 230,-363.5 230,-369.5 224,-375.5 218,-375.5"/>
|
50
|
-
<polygon fill="none" stroke="black" points="122,-346 122,-369 167,-369 167,-346 122,-346"/>
|
51
|
-
<text text-anchor="start" x="125.431" y="-351.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
|
52
|
-
<polygon fill="none" stroke="black" points="169,-346 169,-369 220,-369 220,-346 169,-346"/>
|
53
|
-
<text text-anchor="start" x="171.538" y="-351.9" font-family="Helvetica,sans-Serif" font-size="14.00">443/tcp</text>
|
54
|
-
<polygon fill="none" stroke="black" points="122,-322 122,-344 220,-344 220,-322 122,-322"/>
|
55
|
-
<text text-anchor="start" x="148.168" y="-327" font-family="Helvetica,sans-Serif" font-size="14.00">WebLB</text>
|
56
|
-
</a>
|
57
|
-
</g>
|
58
|
-
</g>
|
59
|
-
<!-- 3 -->
|
60
|
-
<g id="3" class="node"><title>3</title>
|
61
|
-
<g id="a_3"><a xlink:title="Web001">
|
35
|
+
<g id="a_1"><a xlink:title="Web001">
|
62
36
|
<polygon fill="none" stroke="black" points="191,-279.5 113,-279.5 113,-220.5 191,-220.5 191,-279.5"/>
|
63
37
|
<polygon fill="none" stroke="black" points="123,-250 123,-273 181,-273 181,-250 123,-250"/>
|
64
38
|
<text text-anchor="start" x="132.931" y="-255.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
|
@@ -67,14 +41,14 @@
|
|
67
41
|
</a>
|
68
42
|
</g>
|
69
43
|
</g>
|
70
|
-
<!--
|
71
|
-
<g id="3" class="edge"><title>
|
72
|
-
<path fill="none" stroke="blue" d="
|
73
|
-
<polygon fill="blue" stroke="blue" points="
|
44
|
+
<!-- 0->1 -->
|
45
|
+
<g id="3" class="edge"><title>0->1:p80tcp</title>
|
46
|
+
<path fill="none" stroke="blue" d="M199.141,-316.436C198.045,-299.18 195.572,-278.608 190.026,-268.401"/>
|
47
|
+
<polygon fill="blue" stroke="blue" points="192,-265.499 182,-262 187.636,-270.972 192,-265.499"/>
|
74
48
|
</g>
|
75
|
-
<!--
|
76
|
-
<g id="
|
77
|
-
<g id="
|
49
|
+
<!-- 2 -->
|
50
|
+
<g id="2" class="node"><title>2</title>
|
51
|
+
<g id="a_2"><a xlink:title="Web002">
|
78
52
|
<polygon fill="none" stroke="black" points="287,-279.5 209,-279.5 209,-220.5 287,-220.5 287,-279.5"/>
|
79
53
|
<polygon fill="none" stroke="black" points="219,-250 219,-273 277,-273 277,-250 219,-250"/>
|
80
54
|
<text text-anchor="start" x="228.931" y="-255.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
|
@@ -83,14 +57,14 @@
|
|
83
57
|
</a>
|
84
58
|
</g>
|
85
59
|
</g>
|
86
|
-
<!--
|
87
|
-
<g id="4" class="edge"><title>
|
88
|
-
<path fill="none" stroke="blue" d="
|
89
|
-
<polygon fill="blue" stroke="blue" points="212.
|
60
|
+
<!-- 0->2 -->
|
61
|
+
<g id="4" class="edge"><title>0->2:p80tcp</title>
|
62
|
+
<path fill="none" stroke="blue" d="M200.859,-316.436C201.955,-299.18 204.428,-278.608 209.974,-268.401"/>
|
63
|
+
<polygon fill="blue" stroke="blue" points="212.364,-270.972 218,-262 208,-265.499 212.364,-270.972"/>
|
90
64
|
</g>
|
91
|
-
<!--
|
92
|
-
<g id="
|
93
|
-
<g id="
|
65
|
+
<!-- 3 -->
|
66
|
+
<g id="3" class="node"><title>3</title>
|
67
|
+
<g id="a_3"><a xlink:title="AppLB">
|
94
68
|
<path fill="azure" stroke="black" stroke-dasharray="1,5" d="M218.25,-171.5C218.25,-171.5 131.75,-171.5 131.75,-171.5 125.75,-171.5 119.75,-165.5 119.75,-159.5 119.75,-159.5 119.75,-124.5 119.75,-124.5 119.75,-118.5 125.75,-112.5 131.75,-112.5 131.75,-112.5 218.25,-112.5 218.25,-112.5 224.25,-112.5 230.25,-118.5 230.25,-124.5 230.25,-124.5 230.25,-159.5 230.25,-159.5 230.25,-165.5 224.25,-171.5 218.25,-171.5"/>
|
95
69
|
<polygon fill="none" stroke="black" points="130,-142 130,-165 175,-165 175,-142 130,-142"/>
|
96
70
|
<text text-anchor="start" x="133.431" y="-147.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
|
@@ -101,92 +75,92 @@
|
|
101
75
|
</a>
|
102
76
|
</g>
|
103
77
|
</g>
|
104
|
-
<!--
|
105
|
-
<g id="5" class="edge"><title>
|
78
|
+
<!-- 1->3 -->
|
79
|
+
<g id="5" class="edge"><title>1->3:p80tcp</title>
|
106
80
|
<path fill="none" stroke="blue" d="M152,-220.191C152,-207.217 152,-191.442 152,-176.321"/>
|
107
81
|
<polygon fill="blue" stroke="blue" points="155.5,-176 152,-166 148.5,-176 155.5,-176"/>
|
108
82
|
</g>
|
109
|
-
<!--
|
110
|
-
<g id="6" class="edge"><title>
|
83
|
+
<!-- 2->3 -->
|
84
|
+
<g id="6" class="edge"><title>2->3:p80tcp</title>
|
111
85
|
<path fill="none" stroke="blue" d="M212.526,-220.441C192.443,-204.036 169.215,-184.601 158.292,-173.792"/>
|
112
86
|
<polygon fill="blue" stroke="blue" points="161.006,-171.581 152,-166 155.559,-175.979 161.006,-171.581"/>
|
113
87
|
</g>
|
114
|
-
<!--
|
115
|
-
<g id="
|
116
|
-
<g id="
|
117
|
-
<polygon fill="none" stroke="black" points="
|
118
|
-
<polygon fill="none" stroke="black" points="
|
119
|
-
<text text-anchor="start" x="
|
120
|
-
<polygon fill="none" stroke="black" points="
|
121
|
-
<text text-anchor="start" x="
|
122
|
-
<polygon fill="none" stroke="black" points="
|
123
|
-
<text text-anchor="start" x="
|
88
|
+
<!-- 4 -->
|
89
|
+
<g id="4" class="node"><title>4</title>
|
90
|
+
<g id="a_4"><a xlink:title="App001">
|
91
|
+
<polygon fill="none" stroke="black" points="182.25,-75.5 71.75,-75.5 71.75,-16.5 182.25,-16.5 182.25,-75.5"/>
|
92
|
+
<polygon fill="none" stroke="black" points="82,-46 82,-69 127,-69 127,-46 82,-46"/>
|
93
|
+
<text text-anchor="start" x="85.4312" y="-51.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
|
94
|
+
<polygon fill="none" stroke="black" points="129,-46 129,-69 173,-69 173,-46 129,-46"/>
|
95
|
+
<text text-anchor="start" x="131.931" y="-51.9" font-family="Helvetica,sans-Serif" font-size="14.00">25/tcp</text>
|
96
|
+
<polygon fill="none" stroke="black" points="82,-22 82,-44 173,-44 173,-22 82,-22"/>
|
97
|
+
<text text-anchor="start" x="103.366" y="-27" font-family="Helvetica,sans-Serif" font-size="14.00">App001</text>
|
124
98
|
</a>
|
125
99
|
</g>
|
126
100
|
</g>
|
127
|
-
<!--
|
128
|
-
<g id="7" class="edge"><title>
|
129
|
-
<path fill="none" stroke="green" d="
|
130
|
-
<polygon fill="green" stroke="green" points="
|
101
|
+
<!-- 3->4 -->
|
102
|
+
<g id="7" class="edge"><title>3->4:p25tcp</title>
|
103
|
+
<path fill="none" stroke="green" d="M160.623,-112.37C156.71,-102.677 153.148,-91.4558 151.693,-80.2467"/>
|
104
|
+
<polygon fill="green" stroke="green" points="155.167,-79.7409 151,-70 148.183,-80.2135 155.167,-79.7409"/>
|
131
105
|
</g>
|
132
|
-
<!--
|
133
|
-
<g id="8" class="edge"><title>
|
134
|
-
<path fill="none" stroke="blue" d="
|
135
|
-
<polygon fill="blue" stroke="blue" points="
|
106
|
+
<!-- 3->4 -->
|
107
|
+
<g id="8" class="edge"><title>3->4:p80tcp</title>
|
108
|
+
<path fill="none" stroke="blue" d="M126.856,-112.424C116.765,-103.478 108.243,-92.5876 105.197,-79.976"/>
|
109
|
+
<polygon fill="blue" stroke="blue" points="108.667,-79.5118 104,-70 101.716,-80.3458 108.667,-79.5118"/>
|
136
110
|
</g>
|
137
|
-
<!--
|
138
|
-
<g id="
|
139
|
-
<g id="
|
140
|
-
<polygon fill="none" stroke="black" points="
|
141
|
-
<polygon fill="none" stroke="black" points="
|
142
|
-
<text text-anchor="start" x="
|
143
|
-
<polygon fill="none" stroke="black" points="
|
144
|
-
<text text-anchor="start" x="
|
145
|
-
<polygon fill="none" stroke="black" points="
|
146
|
-
<text text-anchor="start" x="
|
111
|
+
<!-- 5 -->
|
112
|
+
<g id="5" class="node"><title>5</title>
|
113
|
+
<g id="a_5"><a xlink:title="App002">
|
114
|
+
<polygon fill="none" stroke="black" points="311.25,-75.5 200.75,-75.5 200.75,-16.5 311.25,-16.5 311.25,-75.5"/>
|
115
|
+
<polygon fill="none" stroke="black" points="211,-46 211,-69 256,-69 256,-46 211,-46"/>
|
116
|
+
<text text-anchor="start" x="214.431" y="-51.9" font-family="Helvetica,sans-Serif" font-size="14.00">80/tcp</text>
|
117
|
+
<polygon fill="none" stroke="black" points="258,-46 258,-69 302,-69 302,-46 258,-46"/>
|
118
|
+
<text text-anchor="start" x="260.931" y="-51.9" font-family="Helvetica,sans-Serif" font-size="14.00">25/tcp</text>
|
119
|
+
<polygon fill="none" stroke="black" points="211,-22 211,-44 302,-44 302,-22 211,-22"/>
|
120
|
+
<text text-anchor="start" x="232.366" y="-27" font-family="Helvetica,sans-Serif" font-size="14.00">App002</text>
|
147
121
|
</a>
|
148
122
|
</g>
|
149
123
|
</g>
|
150
|
-
<!--
|
151
|
-
<g id="9" class="edge"><title>
|
152
|
-
<path fill="none" stroke="green" d="M230.
|
153
|
-
<polygon fill="green" stroke="green" points="
|
124
|
+
<!-- 3->5 -->
|
125
|
+
<g id="9" class="edge"><title>3->5:p25tcp</title>
|
126
|
+
<path fill="none" stroke="green" d="M230.267,-125.47C252.302,-116.05 273.686,-101.572 278.832,-80.0328"/>
|
127
|
+
<polygon fill="green" stroke="green" points="282.32,-80.3376 280,-70 275.367,-79.5283 282.32,-80.3376"/>
|
154
128
|
</g>
|
155
|
-
<!--
|
156
|
-
<g id="10" class="edge"><title>
|
157
|
-
<path fill="none" stroke="blue" d="
|
158
|
-
<polygon fill="blue" stroke="blue" points="
|
129
|
+
<!-- 3->5 -->
|
130
|
+
<g id="10" class="edge"><title>3->5:p80tcp</title>
|
131
|
+
<path fill="none" stroke="blue" d="M181.385,-112.436C186.051,-94.4294 192.996,-72.8124 201.291,-63.1294"/>
|
132
|
+
<polygon fill="blue" stroke="blue" points="203.16,-66.0907 210,-58 199.607,-60.059 203.16,-66.0907"/>
|
159
133
|
</g>
|
160
|
-
<!--
|
161
|
-
<g id="
|
162
|
-
<g id="
|
163
|
-
<polygon fill="none" stroke="black" points="
|
164
|
-
<text text-anchor="start" x="
|
134
|
+
<!-- 6 -->
|
135
|
+
<g id="6" class="node"><title>6</title>
|
136
|
+
<g id="a_6"><a xlink:title="Browser">
|
137
|
+
<polygon fill="none" stroke="black" points="237,-452 161,-452 161,-416 237,-416 237,-452"/>
|
138
|
+
<text text-anchor="start" x="173.328" y="-427.9" font-family="Helvetica,sans-Serif" font-size="14.00">Browser</text>
|
165
139
|
</a>
|
166
140
|
</g>
|
167
141
|
</g>
|
168
|
-
<!--
|
169
|
-
<g id="0" class="edge"><title>
|
170
|
-
<path fill="none" stroke="blue" d="
|
171
|
-
<polygon fill="blue" stroke="blue" points="
|
142
|
+
<!-- 6->0 -->
|
143
|
+
<g id="0" class="edge"><title>6->0:p80tcp</title>
|
144
|
+
<path fill="none" stroke="blue" d="M187.672,-415.857C182.088,-406.095 176.087,-393.216 173.879,-380.063"/>
|
145
|
+
<polygon fill="blue" stroke="blue" points="177.357,-379.657 173,-370 170.384,-380.267 177.357,-379.657"/>
|
172
146
|
</g>
|
173
|
-
<!--
|
174
|
-
<g id="1" class="edge"><title>
|
175
|
-
<path fill="none" stroke="black" d="
|
176
|
-
<polygon fill="black" stroke="black" points="
|
147
|
+
<!-- 6->0 -->
|
148
|
+
<g id="1" class="edge"><title>6->0:p443tcp</title>
|
149
|
+
<path fill="none" stroke="black" d="M209.893,-415.8C215.261,-406.018 221.032,-393.129 223.155,-380.02"/>
|
150
|
+
<polygon fill="black" stroke="black" points="226.647,-380.259 224,-370 219.672,-379.67 226.647,-380.259"/>
|
177
151
|
</g>
|
178
|
-
<!--
|
179
|
-
<g id="
|
180
|
-
<g id="
|
152
|
+
<!-- 7 -->
|
153
|
+
<g id="7" class="node"><title>7</title>
|
154
|
+
<g id="a_7"><a xlink:title="Mail Server">
|
181
155
|
<polygon fill="none" stroke="black" points="94.25,-268 -0.25,-268 -0.25,-232 94.25,-232 94.25,-268"/>
|
182
156
|
<text text-anchor="start" x="12.1035" y="-243.9" font-family="Helvetica,sans-Serif" font-size="14.00">Mail Server</text>
|
183
157
|
</a>
|
184
158
|
</g>
|
185
159
|
</g>
|
186
|
-
<!--
|
187
|
-
<g id="2" class="edge"><title>
|
188
|
-
<path fill="none" stroke="green" d="
|
189
|
-
<polygon fill="green" stroke="green" points="201.
|
160
|
+
<!-- 7->3 -->
|
161
|
+
<g id="2" class="edge"><title>7->3:p25tcp</title>
|
162
|
+
<path fill="none" stroke="green" d="M70.1237,-231.94C79.4894,-225.355 90.5446,-217.983 101,-212 139.498,-189.969 190.301,-210.355 198.004,-175.979"/>
|
163
|
+
<polygon fill="green" stroke="green" points="201.489,-176.298 199,-166 194.524,-175.603 201.489,-176.298"/>
|
190
164
|
</g>
|
191
165
|
</g>
|
192
166
|
</svg>
|
data/examples/simple.yml
CHANGED
@@ -5,6 +5,7 @@ module NetworkDrawer
|
|
5
5
|
class Diagram
|
6
6
|
TOP_LAYER = :networkdrawertop
|
7
7
|
DEFAULT_OPTIONS = {}
|
8
|
+
ELELMENT_KEYS = [:layers, :nodes, :connections]
|
8
9
|
|
9
10
|
def self.draw(source, dest_file, options = {})
|
10
11
|
diagram = new(source, dest_file, options)
|
@@ -12,7 +13,7 @@ module NetworkDrawer
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def initialize(source, dest_file, options = {})
|
15
|
-
@source = source
|
16
|
+
@source = source ? source : {}
|
16
17
|
@dest_file = dest_file
|
17
18
|
@options = DEFAULT_OPTIONS.merge(options)
|
18
19
|
@title = @options[:title] ? @options[:title] :
|
@@ -30,6 +31,7 @@ module NetworkDrawer
|
|
30
31
|
draw_elements
|
31
32
|
|
32
33
|
@gv.global(layout: @options[:layout] ? @options[:layout] : :dot)
|
34
|
+
@gv.global(@source.dup.delete_if { |k, _| ELELMENT_KEYS.include?(k) })
|
33
35
|
@gv.save @dest_file, @options[:format]
|
34
36
|
end
|
35
37
|
|
@@ -72,7 +74,7 @@ module NetworkDrawer
|
|
72
74
|
return nil unless n.is_a?(Hash)
|
73
75
|
node = Element::Node.new(n.values.first, @style[:types])
|
74
76
|
node.name = n.keys.first
|
75
|
-
@nodes[node.name] = node.id
|
77
|
+
@nodes[node.name] = { id: node.id }
|
76
78
|
nodes << node
|
77
79
|
end
|
78
80
|
nodes
|
@@ -92,8 +94,11 @@ module NetworkDrawer
|
|
92
94
|
connection = Element::Connection.new({}, @style[:types])
|
93
95
|
c.each_pair { |k, v| connection[k.to_sym] = v }
|
94
96
|
|
95
|
-
|
96
|
-
|
97
|
+
from_name = @nodes[from_name][:id] if @nodes[from_name]
|
98
|
+
to_name = @nodes[to_name][:id] if @nodes[to_name]
|
99
|
+
|
100
|
+
from = from_port ? "#{from_name}:p#{from_port}" : from_name
|
101
|
+
to = to_port ? "#{to_name}:p#{to_port}" : to_name
|
97
102
|
|
98
103
|
connection.from = from
|
99
104
|
connection.to = to
|
@@ -104,7 +109,7 @@ module NetworkDrawer
|
|
104
109
|
|
105
110
|
def node_exist?(name)
|
106
111
|
return false unless name
|
107
|
-
if @nodes[name]
|
112
|
+
if @nodes[name] && @nodes[name][:id]
|
108
113
|
true
|
109
114
|
else
|
110
115
|
puts "No #{name} exists"
|
@@ -114,7 +119,7 @@ module NetworkDrawer
|
|
114
119
|
|
115
120
|
def node_id(name)
|
116
121
|
return nil unless node_exist?(name)
|
117
|
-
@nodes[name.to_sym]
|
122
|
+
@nodes[name.to_sym][:id]
|
118
123
|
end
|
119
124
|
end
|
120
125
|
end
|
@@ -22,17 +22,77 @@ module NetworkDrawer
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def build_label
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
label = ''
|
26
|
+
|
27
|
+
label << port_label
|
28
|
+
if [num_ports, num_modules].max > 0
|
29
|
+
label << "<tr border='1'><td border='1'"
|
30
|
+
label << " colspan=\"#{num_columns}\">#{self.name}</td></tr>"
|
31
|
+
else
|
32
|
+
label << "<tr border='0'><td border='0'>#{self.name}</td></tr>"
|
33
|
+
end
|
34
|
+
label << module_label
|
35
|
+
|
36
|
+
"<table border='0'>#{label}</table>"
|
37
|
+
end
|
38
|
+
|
39
|
+
def port_label
|
40
|
+
label = ''
|
41
|
+
if num_ports > 0
|
42
|
+
label << "<tr border='1'>"
|
43
|
+
self.ports.each_with_index do |p, i|
|
28
44
|
label << "<td border='1' port=\"p#{p.gsub('/', '')}\">#{p}</td>"
|
45
|
+
label << row_separator(i, num_ports)
|
29
46
|
end
|
30
47
|
label << '</tr>'
|
31
|
-
|
48
|
+
end
|
49
|
+
label
|
50
|
+
end
|
51
|
+
|
52
|
+
def module_label
|
53
|
+
label = ''
|
54
|
+
if num_modules > 0
|
55
|
+
label << "<tr border='1'>"
|
56
|
+
self.modules.each_with_index do |p, i|
|
57
|
+
label << "<td border='1' port=\"p#{p.gsub('/', '')}\">#{p}</td>"
|
58
|
+
label << row_separator(i, num_modules)
|
59
|
+
end
|
60
|
+
label << '</tr>'
|
61
|
+
end
|
62
|
+
label
|
63
|
+
end
|
64
|
+
|
65
|
+
def row_separator(index, size)
|
66
|
+
return '' unless self.max_column && self.max_column.respond_to?(:to_i)
|
67
|
+
if ((index + 1) % self.max_column == 0) && index + 1 < size
|
68
|
+
"</tr><tr border='1'>"
|
32
69
|
else
|
33
|
-
|
70
|
+
''
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def num_columns
|
75
|
+
number = [num_ports, num_modules, 1].max
|
76
|
+
if self.max_column && self.max_column.respond_to?(:to_i)
|
77
|
+
number = [self.max_column, number].min
|
78
|
+
end
|
79
|
+
number
|
80
|
+
end
|
81
|
+
|
82
|
+
def num_ports
|
83
|
+
if self.ports && self.ports.respond_to?(:size)
|
84
|
+
self.ports.size
|
85
|
+
else
|
86
|
+
0
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def num_modules
|
91
|
+
if self.modules && self.modules.respond_to?(:size)
|
92
|
+
self.modules.size
|
93
|
+
else
|
94
|
+
0
|
34
95
|
end
|
35
|
-
"<table border='0'>#{label}</table>"
|
36
96
|
end
|
37
97
|
end
|
38
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: network_drawer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroshi Ota
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gviz
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- examples/simple.svg
|
114
114
|
- examples/simple.yml
|
115
115
|
- examples/simple_style.json
|
116
|
+
- examples/simple_style.yml
|
116
117
|
- lib/network_drawer.rb
|
117
118
|
- lib/network_drawer/cli.rb
|
118
119
|
- lib/network_drawer/diagram.rb
|