flight-control-tower 0.0.1 → 0.1.0

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: 31757e5119a7e7aa71852e298066e77057562439
4
- data.tar.gz: 2bf445545edc584f69fbbda114fc6302e33870ad
3
+ metadata.gz: 9ff77e43632ab3cee6e00728ddb4990d5bace85b
4
+ data.tar.gz: 2dc85203164407617485aeb0b25922662e4e0fc0
5
5
  SHA512:
6
- metadata.gz: 50adacd51473f19a5845e4102f5dafef87fefa1e9b281b3a2508df1a887b90e27a47854ac1e7eebf82d2cfe7121a1a5e6aaffaf3ae764cfcde499d4043fd9cc9
7
- data.tar.gz: 0ffc519f9b9ef55d96d4afae2bd9ba5ae61bff0b72f3778fc6a2d77c9b2681d25cf4e35bdab6c33b8856f82bbd7c725f497a52bdeaf820aefb9c0055a1f165a1
6
+ metadata.gz: 7e66c3002098f0172db37a52020358426ad43c4af0fb623277bd02b26973c155896dc77e3eda581029ede47cb7b59e03f4bdfef7ad3c3009983685c6f2c0e4e1
7
+ data.tar.gz: a482d508ba75af0165c0facdd96fee482f6bd3544d261b06a07081129eb92fd4f0d30257ea6c18b1eb6bed8a1eb7d76298db7d161c77a56f3ea61a666e3d0fcf
@@ -1,4 +1,5 @@
1
1
  require 'flight-control-tower/parser'
2
+ require 'flight-control-tower/view'
2
3
  require 'yaml'
3
4
 
4
5
  module FlightControlTower
@@ -10,7 +11,8 @@ module FlightControlTower
10
11
  def report_traffic
11
12
  config = YAML.load_file(@config_file)
12
13
  files_to_parse = Dir[config["include_pattern"]] - Dir[config["exclude_pattern"]]
13
- Parser.parse(files_to_parse)
14
+ graph = Parser.parse(files_to_parse)
15
+ View.new(graph).build
14
16
  end
15
17
  end
16
18
  end
@@ -4,12 +4,11 @@ module FlightControlTower
4
4
  class Parser
5
5
 
6
6
  def self.parse files_to_parse
7
- connections = create_connections(files_to_parse)
8
- puts create_graph(connections).to_json
7
+ create_graph(create_connections(files_to_parse)).to_json
9
8
  end
10
9
 
11
10
  private
12
- def create_connections(files_to_parse)
11
+ def self.create_connections(files_to_parse)
13
12
  results = {}
14
13
  results['document'] = { outbound: [], inbound: [] }
15
14
  files_to_parse.each do |f|
@@ -36,7 +35,7 @@ module FlightControlTower
36
35
  results
37
36
  end
38
37
 
39
- def create_grap(results)
38
+ def self.create_graph(results)
40
39
  graph = []
41
40
  results.each_pair do |component_name, component_events|
42
41
  component_events[:inbound].each do |event|
@@ -0,0 +1,18 @@
1
+ require 'erb'
2
+
3
+ module FlightControlTower
4
+ class View
5
+ def initialize graph
6
+ @graph = graph
7
+ end
8
+
9
+ def build
10
+ b = binding
11
+ File.open('control_tower.html', 'w') do |f|
12
+ erb = File.read(File.dirname(__FILE__) + '/../views/control_tower.erb')
13
+ f.puts(ERB.new(erb).result(b))
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,143 @@
1
+ <!DOCTYPE HTML>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <title></title>
7
+ <script src="http://d3js.org/d3.v2.js"></script>
8
+ <style>
9
+ .link {
10
+ fill: none;
11
+ stroke: #666;
12
+ stroke-width: 1.5px;
13
+ }
14
+
15
+ .link.outbound {
16
+ stroke: #0aa;
17
+ }
18
+
19
+ .link.inbound {
20
+ stroke: #aa0;
21
+ }
22
+
23
+ circle {
24
+ stroke: #333;
25
+ stroke-width: 1.5px;
26
+ }
27
+
28
+ circle.component {
29
+ fill: #0ee;
30
+ }
31
+ circle.event {
32
+ fill: #ee0;
33
+ }
34
+
35
+ text {
36
+ font: 10px sans-serif;
37
+ pointer-events: none;
38
+ text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, 0 -1px 0 #fff, -1px 0 0 #fff;
39
+ }
40
+
41
+ </style>
42
+ </head>
43
+
44
+ <body>
45
+ <script>
46
+ var callMap = <%= @graph %>;
47
+ var nodes = {};
48
+ links = [];
49
+
50
+ // Compute the distinct nodes from the links.
51
+ callMap.forEach(function(call) {
52
+ nodes[call.source] = nodes[call.source] || {name: call.source, type: 'component'};
53
+ nodes[call.target] = nodes[call.target] || {name: call.target, type: 'component'};
54
+ nodes[call.eventName] = nodes[call.eventName] || {name: call.eventName, type: 'event'};
55
+
56
+ links.push({
57
+ source: nodes[call.source],
58
+ target: nodes[call.eventName],
59
+ type: 'outbound',
60
+ eventName: call.eventName
61
+ });
62
+ links.push({
63
+ source: nodes[call.eventName],
64
+ target: nodes[call.target],
65
+ type: 'inbound',
66
+ eventName: call.eventName
67
+ });
68
+ });
69
+
70
+ var width = window.innerWidth,
71
+ height = window.innerHeight;
72
+
73
+ var force = d3.layout.force()
74
+ .nodes(d3.values(nodes))
75
+ .links(links)
76
+ .size([width, height])
77
+ .linkDistance(100)
78
+ .linkStrength(0.1)
79
+ .charge(-600)
80
+ .on("tick", tick)
81
+ .start();
82
+
83
+ var svg = d3.select("body").append("svg")
84
+ .attr("width", width)
85
+ .attr("height", height);
86
+
87
+ // Per-type markers, as they don't inherit styles.
88
+ svg.append("defs").selectAll("marker")
89
+ .data(["inbound", "outbound"])
90
+ .enter().append("marker")
91
+ .attr("id", function(d) { return d; })
92
+ .attr("viewBox", "0 -5 10 10")
93
+ .attr("refX", 15)
94
+ .attr("refY", -1.5)
95
+ .attr("markerWidth", 6)
96
+ .attr("markerHeight", 6)
97
+ .attr("orient", "auto")
98
+ .append("path")
99
+ .attr("d", "M0,-5L10,0L0,5");
100
+
101
+ var path = svg.append("g").selectAll("path")
102
+ .data(force.links())
103
+ .enter().append("path")
104
+ .attr("class", function(d) { return "link " + d.type; })
105
+ .attr("marker-end", function(d) { return "url(#" + d.type + ")"; });
106
+
107
+ var circle = svg.append("g").selectAll("circle")
108
+ .data(force.nodes())
109
+ .enter().append("circle")
110
+ .attr("r", 6)
111
+ .attr('class', function(d) { return d.type; })
112
+ .call(force.drag);
113
+
114
+ var text = svg.append("g").selectAll("text.component")
115
+ .data(force.nodes())
116
+ .enter().append("text")
117
+ .attr("x", 8)
118
+ .attr("y", ".31em")
119
+ .attr("class", "component")
120
+ .text(function(d) { return d.name; });
121
+
122
+ // Use elliptical arc path segments to doubly-encode directionality.
123
+ function tick() {
124
+ path.attr("d", linkArc);
125
+ circle.attr("transform", transform);
126
+ text.attr("transform", transform);
127
+ }
128
+
129
+ function linkArc(d) {
130
+ var dx = d.target.x - d.source.x,
131
+ dy = d.target.y - d.source.y,
132
+ dr = Math.sqrt(dx * dx + dy * dy);
133
+ return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
134
+ }
135
+
136
+ function transform(d) {
137
+ return "translate(" + d.x + "," + d.y + ")";
138
+ }
139
+ </script>
140
+ </body>
141
+
142
+ </html>
143
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flight-control-tower
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duda Dornelles
@@ -22,6 +22,8 @@ files:
22
22
  - bin/flight-control-tower
23
23
  - lib/flight-control-tower.rb
24
24
  - lib/flight-control-tower/parser.rb
25
+ - lib/flight-control-tower/view.rb
26
+ - lib/views/control_tower.erb
25
27
  homepage:
26
28
  licenses: []
27
29
  metadata: {}