network_drawer 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bdae0066e1c9e98f383b63504202190aa1703c40
4
- data.tar.gz: a9b63ca0011cf232fac4e66418a39d801fd6202e
3
+ metadata.gz: b86cbd64c0fcd6709e3be20664cafeccbf3c0ac2
4
+ data.tar.gz: e67f543a968a926d165a64659ad668866906c558
5
5
  SHA512:
6
- metadata.gz: 133763e20719c88b3df6e7f4e5a5797d34a608bc329f5572ada358c47bd6f683e28b80f0d2151f693871f80fff121c715eee0d3b20670b99c05d4401e59117ca
7
- data.tar.gz: cc58257792de05ee0b9d092935f02f7ebc83f3679e76c241b4c68de9c6fd784956d0517d1183503ee648e002d968b13b2f102d55a084c24e79a92c6f8c771b67
6
+ metadata.gz: edf53346f68b4e10c776fbe95fdbe99aa2d15f5a4e638c1f07fc3d9f06fc944d110262a4599b4e3f6944bf9bc33fa40e155354bf124f8d0e2b8c79db5a9acd5b
7
+ data.tar.gz: 0cad7acdcebbac503d91209c7712dc9a5693870981f7ef809747240662c9ab6a661b57e6e2729524b4a255d394394b0c04b378fbdc60ca75163bb70d0c395b23
@@ -0,0 +1,14 @@
1
+ # Network Drawer Gallery
2
+
3
+ ## Simple
4
+
5
+ [simple.yml](examples/simple.yml)/[simple_style.yml](examples/simple_style.yml)
6
+
7
+ ![sample diagram(PNG)](examples/simple.png)
8
+
9
+ ## Rank
10
+
11
+ [rank.yml](examples/rank.yml)
12
+
13
+ ![rank diagram(PNG)](examples/rank.png)
14
+
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # NetworkDrawer
2
2
 
3
- A network diagram drawer with json or yaml.
3
+ A network diagram drawer with YAML or JSON.
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/network_drawer.svg)](http://badge.fury.io/rb/network_drawer)
6
6
 
@@ -36,27 +36,27 @@ Or install it yourself as:
36
36
 
37
37
  ## Usage
38
38
 
39
- You can draw a network diagram with a JSON or YAML file with SVG format:
40
-
41
- $ bundle exec network_drawer draw examples/simple.json
39
+ You can draw a network diagram with a YAML or JSONfile with SVG format:
42
40
 
43
41
  $ bundle exec network_drawer draw examples/simple.yml
44
42
 
45
- You can draw a network diagram with specified style:
43
+ $ bundle exec network_drawer draw examples/simple.json
46
44
 
47
- $ bundle exec network_drawer draw examples/simple.json -s examples/simple_style.json
45
+ You can draw a network diagram with specified style:
48
46
 
49
47
  $ bundle exec network_drawer draw examples/simple.yml -s examples/simple_style.yml
50
48
 
49
+ $ bundle exec network_drawer draw examples/simple.json -s examples/simple_style.json
50
+
51
51
  You can draw a network diagram with specified layout(dot, fdp..):
52
52
 
53
- $ bundle exec network_drawer draw examples/simple.json -l fdp
53
+ $ bundle exec network_drawer draw examples/simple.yml -l fdp
54
54
 
55
55
  You can draw a network diagram with png format:
56
56
 
57
- $ bundle exec network_drawer draw examples/simple.json -f png
57
+ $ bundle exec network_drawer draw examples/simple.yml -f png
58
58
 
59
- Then You will get a network diagram.
59
+ Then You will get a network diagram. See more [Gallery](GALLERY.md)
60
60
 
61
61
  [sample diagram(SVG)](examples/simple.svg)
62
62
 
@@ -64,7 +64,7 @@ Then You will get a network diagram.
64
64
 
65
65
  ## How to describe
66
66
 
67
- You can describe diagram with JSON.
67
+ You can describe diagram with YAML or JSON.
68
68
 
69
69
  ### Network diagram
70
70
 
data/Rakefile CHANGED
@@ -8,11 +8,13 @@ task :update do
8
8
  'GEM_HOME' => nil
9
9
  }
10
10
 
11
- %w(png svg).each do |f|
12
- command = 'bundle exec bin/network_drawer '
13
- command << 'draw examples/simple.yml '
14
- command << "-s examples/simple_style.yml -f #{f}"
11
+ %w(simple rank).each do |name|
12
+ %w(png svg).each do |f|
13
+ command = 'bundle exec bin/network_drawer '
14
+ command << "draw examples/#{name}.yml "
15
+ command << "-s examples/#{name}_style.yml -f #{f}"
15
16
 
16
- system(env, command)
17
+ system(env, command)
18
+ end
17
19
  end
18
20
  end
Binary file
@@ -0,0 +1,116 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
3
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <!-- Generated by graphviz version 2.34.0 (20140129.0153)
5
+ -->
6
+ <!-- Title: rank Pages: 1 -->
7
+ <svg width="292pt" height="292pt"
8
+ viewBox="0.00 0.00 292.00 292.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 288)">
10
+ <title>rank</title>
11
+ <polygon fill="white" stroke="white" points="-4,4 -4,-288 288,-288 288,4 -4,4"/>
12
+ <g id="1" class="cluster"><title>cluster_1</title>
13
+ <polygon fill="none" stroke="black" points="108,-164 108,-240 194,-240 194,-164 108,-164"/>
14
+ <text text-anchor="middle" x="151" y="-222" font-family="Helvetica,sans-Serif" font-size="14.00">Web</text>
15
+ </g>
16
+ <g id="2" class="cluster"><title>cluster_2</title>
17
+ <polygon fill="none" stroke="black" points="38,-8 38,-156 219,-156 219,-8 38,-8"/>
18
+ <text text-anchor="middle" x="128.5" y="-138" font-family="Helvetica,sans-Serif" font-size="14.00">App</text>
19
+ </g>
20
+ <!-- 0 -->
21
+ <g id="0" class="node"><title>0</title>
22
+ <g id="a_0"><a xlink:title="WebLB">
23
+ <polygon fill="none" stroke="black" points="186,-208 116,-208 116,-172 186,-172 186,-208"/>
24
+ <text text-anchor="start" x="128.168" y="-183.9" font-family="Helvetica,sans-Serif" font-size="14.00">WebLB</text>
25
+ </a>
26
+ </g>
27
+ </g>
28
+ <!-- 1 -->
29
+ <g id="1" class="node"><title>1</title>
30
+ <g id="a_1"><a xlink:title="AppLB">
31
+ <polygon fill="none" stroke="black" points="161.25,-124 94.75,-124 94.75,-88 161.25,-88 161.25,-124"/>
32
+ <text text-anchor="start" x="107.483" y="-99.9" font-family="Helvetica,sans-Serif" font-size="14.00">AppLB</text>
33
+ </a>
34
+ </g>
35
+ </g>
36
+ <!-- 0&#45;&gt;1 -->
37
+ <g id="3" class="edge"><title>0&#45;&gt;1</title>
38
+ <path fill="none" stroke="black" d="M146.122,-171.61C143.052,-160.665 139.027,-146.315 135.55,-133.919"/>
39
+ <polygon fill="black" stroke="black" points="138.862,-132.767 132.792,-124.084 132.123,-134.658 138.862,-132.767"/>
40
+ </g>
41
+ <!-- 2 -->
42
+ <g id="2" class="node"><title>2</title>
43
+ <g id="a_2"><a xlink:title="App001">
44
+ <polygon fill="none" stroke="black" points="119.25,-52 46.75,-52 46.75,-16 119.25,-16 119.25,-52"/>
45
+ <text text-anchor="start" x="59.3657" y="-27.9" font-family="Helvetica,sans-Serif" font-size="14.00">App001</text>
46
+ </a>
47
+ </g>
48
+ </g>
49
+ <!-- 1&#45;&gt;2 -->
50
+ <g id="4" class="edge"><title>1&#45;&gt;2</title>
51
+ <path fill="none" stroke="black" d="M110.961,-87.6966C104.953,-79.6436 98.4754,-69.8945 93.1562,-60.9824"/>
52
+ <polygon fill="black" stroke="black" points="96.0905,-59.0622 88.1006,-52.1043 90.0076,-62.5261 96.0905,-59.0622"/>
53
+ </g>
54
+ <!-- 1&#45;&gt;2 -->
55
+ <g id="5" class="edge"><title>1&#45;&gt;2</title>
56
+ <path fill="none" stroke="black" d="M122.792,-87.6966C118.354,-79.4741 112.133,-69.4832 105.862,-60.4207"/>
57
+ <polygon fill="black" stroke="black" points="108.566,-58.186 99.8907,-52.1043 102.88,-62.2687 108.566,-58.186"/>
58
+ </g>
59
+ <!-- 3 -->
60
+ <g id="3" class="node"><title>3</title>
61
+ <g id="a_3"><a xlink:title="App002">
62
+ <polygon fill="none" stroke="black" points="210.25,-52 137.75,-52 137.75,-16 210.25,-16 210.25,-52"/>
63
+ <text text-anchor="start" x="150.366" y="-27.9" font-family="Helvetica,sans-Serif" font-size="14.00">App002</text>
64
+ </a>
65
+ </g>
66
+ </g>
67
+ <!-- 1&#45;&gt;3 -->
68
+ <g id="6" class="edge"><title>1&#45;&gt;3</title>
69
+ <path fill="none" stroke="black" d="M133.455,-87.6966C138.01,-79.4741 144.374,-69.4832 150.775,-60.4207"/>
70
+ <polygon fill="black" stroke="black" points="153.781,-62.2403 156.865,-52.1043 148.133,-58.1045 153.781,-62.2403"/>
71
+ </g>
72
+ <!-- 1&#45;&gt;3 -->
73
+ <g id="7" class="edge"><title>1&#45;&gt;3</title>
74
+ <path fill="none" stroke="black" d="M145.287,-87.6966C151.409,-79.6436 158.026,-69.8945 163.473,-60.9824"/>
75
+ <polygon fill="black" stroke="black" points="166.636,-62.5051 168.655,-52.1043 160.591,-58.9762 166.636,-62.5051"/>
76
+ </g>
77
+ <!-- 6 -->
78
+ <!-- 7 -->
79
+ <!-- 6&#45;&gt;7 -->
80
+ <!-- 8 -->
81
+ <!-- 7&#45;&gt;8 -->
82
+ <!-- 9 -->
83
+ <!-- 8&#45;&gt;9 -->
84
+ <!-- 4 -->
85
+ <g id="4" class="node"><title>4</title>
86
+ <g id="a_4"><a xlink:title="Browser">
87
+ <polygon fill="none" stroke="black" points="189,-284 113,-284 113,-248 189,-248 189,-284"/>
88
+ <text text-anchor="start" x="125.328" y="-259.9" font-family="Helvetica,sans-Serif" font-size="14.00">Browser</text>
89
+ </a>
90
+ </g>
91
+ </g>
92
+ <!-- 4&#45;&gt;0 -->
93
+ <g id="0" class="edge"><title>4&#45;&gt;0</title>
94
+ <path fill="none" stroke="black" d="M145.199,-247.837C144.267,-239.058 144.022,-228.163 144.462,-218.267"/>
95
+ <polygon fill="black" stroke="black" points="147.969,-218.299 145.209,-208.07 140.988,-217.787 147.969,-218.299"/>
96
+ </g>
97
+ <!-- 4&#45;&gt;0 -->
98
+ <g id="1" class="edge"><title>4&#45;&gt;0</title>
99
+ <path fill="none" stroke="black" d="M156.801,-247.837C157.733,-239.058 157.978,-228.163 157.538,-218.267"/>
100
+ <polygon fill="black" stroke="black" points="161.012,-217.787 156.791,-208.07 154.031,-218.299 161.012,-217.787"/>
101
+ </g>
102
+ <!-- 5 -->
103
+ <g id="5" class="node"><title>5</title>
104
+ <g id="a_5"><a xlink:title="Mail Server">
105
+ <polygon fill="none" stroke="black" points="94.25,-284 -0.25,-284 -0.25,-248 94.25,-248 94.25,-284"/>
106
+ <text text-anchor="start" x="12.1035" y="-259.9" font-family="Helvetica,sans-Serif" font-size="14.00">Mail Server</text>
107
+ </a>
108
+ </g>
109
+ </g>
110
+ <!-- 5&#45;&gt;1 -->
111
+ <g id="2" class="edge"><title>5&#45;&gt;1</title>
112
+ <path fill="none" stroke="black" d="M55.8226,-247.79C70.0038,-220.128 97.9612,-165.594 114.612,-133.115"/>
113
+ <polygon fill="black" stroke="black" points="117.741,-134.684 119.188,-124.188 111.512,-131.49 117.741,-134.684"/>
114
+ </g>
115
+ </g>
116
+ </svg>
@@ -0,0 +1,35 @@
1
+ layers:
2
+ - Web:
3
+ nodes:
4
+ - WebLB:
5
+ ranking: 1
6
+ - App:
7
+ nodes:
8
+ - AppLB:
9
+ ranking: 3
10
+ - App001:
11
+ ranking: 4
12
+ - App002:
13
+ ranking: 4
14
+ nodes:
15
+ - Browser:
16
+ ranking: 0
17
+ - Mail Server:
18
+ ranking: 0
19
+ connections:
20
+ - from: Browser
21
+ to: WebLB
22
+ - from: Browser
23
+ to: WebLB
24
+ - from: Mail Server
25
+ to: AppLB
26
+ - from: WebLB
27
+ to: AppLB
28
+ - from: AppLB
29
+ to: App001
30
+ - from: AppLB
31
+ to: App001
32
+ - from: AppLB
33
+ to: App002
34
+ - from: AppLB
35
+ to: App002
File without changes
@@ -21,6 +21,7 @@ module NetworkDrawer
21
21
  @nodes = {}
22
22
  @layers = {}
23
23
  @connections = []
24
+ @rankings = {}
24
25
  @style = options[:style] ? options[:style] : {}
25
26
  @gv = Gviz.new(@title)
26
27
  end
@@ -31,6 +32,7 @@ module NetworkDrawer
31
32
  draw_elements
32
33
 
33
34
  @gv.global(layout: @options[:layout] ? @options[:layout] : :dot)
35
+ @gv.global(newrank: true) if @rankings.size > 0
34
36
  @gv.global(@source.dup.delete_if { |k, _| ELELMENT_KEYS.include?(k) })
35
37
  @gv.save @dest_file, @options[:format]
36
38
  end
@@ -42,6 +44,9 @@ module NetworkDrawer
42
44
  @connections.each do |c|
43
45
  code << c.to_code
44
46
  end if @connections
47
+
48
+ rank_nodes
49
+
45
50
  @gv.graph(&eval("proc {#{code}}"))
46
51
  end
47
52
 
@@ -75,6 +80,14 @@ module NetworkDrawer
75
80
  node = Element::Node.new(n.values.first, @style[:types])
76
81
  node.name = n.keys.first
77
82
  @nodes[node.name] = { id: node.id }
83
+ ranking = node.ranking.to_i
84
+ unless node.ranking.nil?
85
+ if @rankings[ranking]
86
+ @rankings[ranking] += [node.id]
87
+ else
88
+ @rankings[ranking] = [node.id]
89
+ end
90
+ end
78
91
  nodes << node
79
92
  end
80
93
  nodes
@@ -107,6 +120,22 @@ module NetworkDrawer
107
120
  connections
108
121
  end
109
122
 
123
+ def rank_nodes
124
+ return if @rankings.size == 0
125
+ sorted_rankings = @rankings.sort
126
+ rank_ids = []
127
+ sorted_rankings.each_with_index do |r, i|
128
+ rank_id = (@nodes.size + i)
129
+ rank_ids << rank_id
130
+ @gv.rank(:same, *([rank_id] + r[1]))
131
+ end
132
+ rank_ids.each_with_index do |r, i|
133
+ @gv.node(r.to_s.to_sym, style: :invis)
134
+ edge_id = "#{rank_ids[i]}_#{rank_ids[i + 1]}".to_sym
135
+ @gv.edge(edge_id, style: :invis) if i < rank_ids.size - 1
136
+ end
137
+ end
138
+
110
139
  def node_exist?(name)
111
140
  return false unless name
112
141
  if @nodes[name] && @nodes[name][:id]
@@ -14,8 +14,10 @@ module NetworkDrawer
14
14
  def to_code
15
15
  style = style(self.type).dup
16
16
  style.merge!(self.to_hash)
17
+ self.max_column = style[:max_column]
17
18
  style.merge!(label: build_label, tooltip: self.name, URL: self.url )
18
- style.merge!(ports: nil)
19
+ style.delete(:ports)
20
+ style.delete(:modules)
19
21
  "node(:\"#{self.id}\", #{style})"
20
22
  end
21
23
 
@@ -41,7 +43,7 @@ module NetworkDrawer
41
43
  if num_ports > 0
42
44
  label << "<tr border='1'>"
43
45
  self.ports.each_with_index do |p, i|
44
- label << "<td border='1' port=\"p#{p.gsub('/', '')}\">#{p}</td>"
46
+ label << "<td border='1' port=\"p#{p.to_s.gsub('/', '')}\">#{p}</td>"
45
47
  label << row_separator(i, num_ports)
46
48
  end
47
49
  label << '</tr>'
@@ -54,7 +56,7 @@ module NetworkDrawer
54
56
  if num_modules > 0
55
57
  label << "<tr border='1'>"
56
58
  self.modules.each_with_index do |p, i|
57
- label << "<td border='1' port=\"p#{p.gsub('/', '')}\">#{p}</td>"
59
+ label << "<td border='1' port=\"p#{p.to_s.gsub('/', '')}\">#{p}</td>"
58
60
  label << row_separator(i, num_modules)
59
61
  end
60
62
  label << '</tr>'
@@ -1,3 +1,3 @@
1
1
  module NetworkDrawer
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  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
4
+ version: 0.1.5
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-23 00:00:00.000000000 Z
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gviz
@@ -103,11 +103,16 @@ extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
105
  - ".gitignore"
106
+ - GALLERY.md
106
107
  - Gemfile
107
108
  - LICENSE.txt
108
109
  - README.md
109
110
  - Rakefile
110
111
  - bin/network_drawer
112
+ - examples/rank.png
113
+ - examples/rank.svg
114
+ - examples/rank.yml
115
+ - examples/rank_style.yml
111
116
  - examples/simple.json
112
117
  - examples/simple.png
113
118
  - examples/simple.svg