ellington 0.2.0 → 0.2.1

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: 1047c36cb4128e723415dcd5e7b74f00a38da00b
4
- data.tar.gz: 8077a60871b70d5530847a5f78a653ca9236a11e
3
+ metadata.gz: d158926e81d20f91c3db3ae55e8a38731132f403
4
+ data.tar.gz: fb9bbdf73413c8e5cf970b4a741b51d1bdce8196
5
5
  SHA512:
6
- metadata.gz: 5f78a52f1504888e376e61e788eb9bb5ac3aafe5e2b2285ba346bb0d9bfed999ebd1c0c8a860befb9d223520c5adef146852cbd012dc8258aae4079cb4e2d3b9
7
- data.tar.gz: 44c136a470a26cb649a78285d45728eefd5e4d8dd95197beb4f73182f0c106f5364f67442ca9b962b8bf9a07d48c83395b63eef6506a2c0ae22ff079daebfa90
6
+ metadata.gz: e78d31ba43e27ad2e1c964704801e933453be29fb24de15b3bc97a7604d3c7c521e1d604cec4d6758000f7435bb6b4d8d30fc745bfdbea27aeab676d53452646
7
+ data.tar.gz: a5f70a00195b58cceaaba01bb20cce09dd7aac282b0b2d96e3614bdaf9be82a6e1ec3cc4b7556ad72559c9076caa1b3e8a5cfa0ef0f47e8792b63e4c49b33d9c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ellington (0.2.0)
4
+ ellington (0.2.1)
5
5
  hero (~> 0.2.0)
6
6
  ruby-graphviz (~> 1.2.1)
7
7
  state_jacket (~> 0.1.1)
@@ -1,3 +1,3 @@
1
1
  module Ellington
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -33,11 +33,12 @@ module Ellington
33
33
  end
34
34
  end
35
35
 
36
- attr_reader :route, :format
36
+ attr_reader :route, :format, :short_names
37
37
 
38
- def initialize(route, format=:svg)
38
+ def initialize(route, format: :svg, short_names: true)
39
39
  @route = route
40
40
  @format = format
41
+ @short_names = short_names
41
42
  end
42
43
 
43
44
  FONTNAME = "Helvetica"
@@ -63,19 +64,31 @@ module Ellington
63
64
  CLUSTER_FILLCOLOR = "gray70"
64
65
  CLUSTER_PENCOLOR = "gray50"
65
66
 
67
+ def class_label(obj)
68
+ klass = obj
69
+ klass = klass.class unless klass.is_a?(Class)
70
+ return klass.name unless short_names
71
+ klass.name.split("::").last
72
+ end
73
+
74
+ def state_label(state)
75
+ return state unless short_names
76
+ state.split(" ").map { |part| part.split("::").last }.join(" | ")
77
+ end
78
+
66
79
  def graph_lines_basic(passenger=nil)
67
80
  g = Node.new(nil, GraphViz.new("GraphLinesBasic"))
68
81
  set_graph_defaults g.viz
69
- g.viz["label"] = "#{route.name} Lines - basic"
82
+ g.viz[:label] = "#{class_label(route)} Lines - basic"
70
83
 
71
84
  route.lines.each_with_index do |line, index|
72
85
  line_cluster = g.add(Node.new(line, g.viz.add_graph("cluster#{index}")))
73
86
  set_cluster_defaults line_cluster.viz
74
- line_cluster.viz["label"] = line.class.name
87
+ line_cluster.viz[:label] = class_label(line)
75
88
 
76
89
  line.stations.each do |station|
77
90
  states = station.states.keys
78
- station_node = line_cluster.add(Node.new(station, line_cluster.viz.add_nodes(station.class.name)))
91
+ station_node = line_cluster.add(Node.new(station, line_cluster.viz.add_nodes(class_label(station))))
79
92
  style_node_for_line(station_node, line, *states)
80
93
  style_node_for_route(station_node, route, *states)
81
94
  style_node_for_passenger(station_node, passenger, *states)
@@ -88,8 +101,8 @@ module Ellington
88
101
  #next_station = next_node.base
89
102
  edge = line_cluster.viz.add_edges(node.viz, next_node.viz)
90
103
  if passenger
91
- if color_name(node.viz["color"]) == NODE_COLOR_PASSENGER_HIT &&
92
- color_name(next_node.viz["color"]) == NODE_COLOR_PASSENGER_HIT
104
+ if color_name(node.viz[:color]) == NODE_COLOR_PASSENGER_HIT &&
105
+ color_name(next_node.viz[:color]) == NODE_COLOR_PASSENGER_HIT
93
106
  edge["color"] = EDGE_COLOR_PASSENGER_HIT
94
107
  edge["penwidth"] = EDGE_PENWIDTH_PASSENGER_HIT
95
108
  else
@@ -106,12 +119,12 @@ module Ellington
106
119
  def graph_lines(passenger=nil)
107
120
  g = Node.new(nil, GraphViz.new("GraphLines"))
108
121
  set_graph_defaults g.viz
109
- g.viz["label"] = "#{route.name} Lines"
122
+ g.viz[:label] = "#{class_label(route)} Lines"
110
123
 
111
124
  route.lines.each_with_index do |line, index|
112
125
  line_cluster = g.add(Node.new(line, g.viz.add_graph("cluster#{index}")))
113
126
  set_cluster_defaults line_cluster.viz
114
- line_cluster.viz["label"] = line.class.name
127
+ line_cluster.viz[:label] = class_label(line)
115
128
  add_state_nodes_for_line line_cluster, line, passenger
116
129
 
117
130
  line.states.each do |state, transitions|
@@ -137,18 +150,18 @@ module Ellington
137
150
  def graph_route_basic(passenger=nil)
138
151
  g = Node.new(nil, GraphViz.new("GraphRouteBasic"))
139
152
  set_graph_defaults g.viz
140
- g.viz["ranksep"] = 1
141
- g.viz["label"] = "#{route.name} Route - basic"
153
+ g.viz[:ranksep] = 1
154
+ g.viz[:label] = "#{class_label(route)} Route - basic"
142
155
 
143
156
  route.lines.each_with_index do |line, index|
144
157
  line_cluster = g.add(Node.new(line, g.viz.add_graph("cluster#{index}")))
145
158
  set_cluster_defaults line_cluster.viz
146
- line_cluster.viz["label"] = line.class.name
159
+ line_cluster.viz[:label] = class_label(line)
147
160
 
148
161
  passenger_hit = false
149
162
  %w{PASS FAIL ERROR}.each do |state|
150
163
  state_node = line_cluster.add(Node.new(state, line_cluster.viz.add_nodes("#{line.class.name}#{state}", "label" => state)))
151
- states = line.stations.map{ |s| "#{state} #{s.name}" }
164
+ states = line.stations.map{ |s| "#{state} #{class_label(s)}" }
152
165
  style_node_for_line(state_node, line, *states)
153
166
  style_node_for_route(state_node, route, *states)
154
167
  passenger_hit ||= style_node_for_passenger(state_node, passenger, *line.send("#{state.downcase}ed"))
@@ -183,11 +196,11 @@ module Ellington
183
196
  if connection.type == :if_all
184
197
  combos.each do |state, nodes|
185
198
  node_name = nodes.map{ |n| n.base.class.name }.join + state
186
- node_label = nodes.map{ |n| "#{n.base.class.name} #{state}"}.join("\n")
187
- viz = g.viz.add_nodes(node_name, "label" => node_label)
188
- viz["style"] = NODE_STYLE_VIRTUAL
189
- viz["color"] = NODE_COLOR_VIRTUAL
190
- viz["fontcolor"] = NODE_FONTCOLOR_VIRTUAL
199
+ node_label = nodes.map{ |n| state_label(state) }.join("\n")
200
+ viz = g.viz.add_nodes(node_name, :label => node_label)
201
+ viz[:style] = NODE_STYLE_VIRTUAL
202
+ viz[:color] = NODE_COLOR_VIRTUAL
203
+ viz[:fontcolor] = NODE_FONTCOLOR_VIRTUAL
191
204
 
192
205
  nodes.each do |node|
193
206
  from_viz = node.viz.get_node("#{node.base.class.name}#{state}")
@@ -209,23 +222,23 @@ module Ellington
209
222
  def graph_route(passenger=nil)
210
223
  g = Node.new(nil, GraphViz.new("GraphRoute"))
211
224
  set_graph_defaults g.viz
212
- g.viz["label"] = "#{route.name} Lines"
213
- g.viz["ranksep"] = 0.8
225
+ g.viz[:label] = "#{class_label(route)} Lines"
226
+ g.viz[:ranksep] = 0.8
214
227
 
215
228
  route.lines.each_with_index do |line, index|
216
229
  line_cluster = g.add(Node.new(line, g.viz.add_graph("cluster#{index}")))
217
230
  set_cluster_defaults line_cluster.viz
218
- line_cluster.viz["label"] = line.class.name
231
+ line_cluster.viz[:label] = class_label(line)
219
232
  add_state_nodes_for_line line_cluster, line, passenger
220
233
  end
221
234
 
222
- viz = g.viz.add_nodes(route.initial_state)
235
+ viz = g.viz.add_nodes(route.initial_state, :label => state_label(route.initial_state))
223
236
  rendered_edges = {}
224
237
 
225
238
  if passenger
226
239
  passenger_nodes = g.reduce([]) do |memo, line_cluster|
227
240
  line_cluster.children.each do |node|
228
- if node.viz["color"].to_s.gsub(/\W/, "") == NODE_COLOR_PASSENGER_HIT
241
+ if node.viz[:color].to_s.gsub(/\W/, "") == NODE_COLOR_PASSENGER_HIT
229
242
  memo << node
230
243
  end
231
244
  end
@@ -271,7 +284,7 @@ module Ellington
271
284
 
272
285
  def add_state_nodes_for_line(cluster, line, passenger)
273
286
  line.states.keys.each do |state|
274
- node = cluster.add(Node.new(state, cluster.viz.add_nodes(state)))
287
+ node = cluster.add(Node.new(state, cluster.viz.add_nodes(state, :label => state_label(state))))
275
288
  style_node_for_line(node, line, state)
276
289
  style_node_for_route(node, route, state)
277
290
  style_node_for_passenger(node, passenger, state)
@@ -279,8 +292,8 @@ module Ellington
279
292
  end
280
293
 
281
294
  def style_node(node, color)
282
- node.viz["color"] = color
283
- node.viz["fillcolor"] = color
295
+ node.viz[:color] = color
296
+ node.viz[:fillcolor] = color
284
297
  true
285
298
  end
286
299
 
@@ -297,8 +310,8 @@ module Ellington
297
310
  def style_node_for_passenger(node, passenger, *states)
298
311
  return false if passenger.nil?
299
312
  return false if (passenger.state_history & states).empty?
300
- node.viz["color"] = NODE_COLOR_PASSENGER_HIT
301
- node.viz["penwidth"] = NODE_PENWIDTH_PASSENGER_HIT
313
+ node.viz[:color] = NODE_COLOR_PASSENGER_HIT
314
+ node.viz[:penwidth] = NODE_PENWIDTH_PASSENGER_HIT
302
315
  true
303
316
  end
304
317
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ellington
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins