vispan 0.17.1 → 0.17.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/generate +1 -1
- data/lib/vispan.rb +12 -15
- data/lib/vispan/config.rb +12 -13
- data/lib/vispan/graphwriter.rb +12 -13
- data/lib/vispan/node.rb +5 -6
- data/lib/vispan/output_graphic.rb +3 -4
- data/lib/vispan/relation.rb +12 -14
- data/lib/vispan/szenario.rb +11 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d650155aa24bb681618252607555d22859de0d3f
|
4
|
+
data.tar.gz: 9e918172c689334f92152a2408ac026dd13a060e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93c57ab536887aabe9f761789aa3666224ecad84cb9baf066c726204b5580f66d64a4e50640e26bc8674a68df301505366e02e953140425ab856e059222cb386
|
7
|
+
data.tar.gz: 2d2d89ba5bb82f39104f385bc03b2eb32552061f40804736f6b6bbabcfc991378be3be30110d00dc2401614a9dd58fe09dbb68c3e1167c721465cccc09a38e0c
|
data/bin/generate
CHANGED
data/lib/vispan.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'vispan/szenario.rb'
|
2
|
+
require 'vispan/relation.rb'
|
3
|
+
require 'vispan/node.rb'
|
4
|
+
require 'vispan/output_graphic.rb'
|
5
5
|
require 'fileutils'
|
6
6
|
|
7
7
|
module Vispan
|
@@ -12,13 +12,11 @@ module Vispan
|
|
12
12
|
@szenarios = []
|
13
13
|
separate_szenarios(@input)
|
14
14
|
|
15
|
-
@szenarios.each
|
16
|
-
szenario.assign_ranks
|
17
|
-
end
|
15
|
+
@szenarios.each(&:assign_ranks)
|
18
16
|
|
19
|
-
|
20
|
-
file_ending = File.extname(@output).delete(
|
21
|
-
[200, {
|
17
|
+
visualize(@output)
|
18
|
+
file_ending = File.extname(@output).delete('.')
|
19
|
+
[200, { 'Content-Type' => "image/#{file_ending}" }, [IO.read(@output)]]
|
22
20
|
end
|
23
21
|
|
24
22
|
def initialize(files)
|
@@ -27,14 +25,13 @@ module Vispan
|
|
27
25
|
end
|
28
26
|
|
29
27
|
def separate_szenarios(input_file)
|
30
|
-
@single_szenario = Szenario.new
|
28
|
+
@single_szenario = Szenario.new
|
31
29
|
@relation_lines = []
|
32
30
|
@lines = File.readlines(input_file)
|
33
31
|
@lines.each_with_index do |line, index|
|
34
|
-
|
35
|
-
if line[0] == "-"
|
32
|
+
if line[0] == '-'
|
36
33
|
create_new_szenario(line)
|
37
|
-
elsif (line == "\n" && !@relation_lines.empty?) || (index == @lines.length-1)
|
34
|
+
elsif (line == "\n" && !@relation_lines.empty?) || (index == @lines.length - 1)
|
38
35
|
create_new_relation(line)
|
39
36
|
elsif line != "\n"
|
40
37
|
@relation_lines << line
|
@@ -44,7 +41,7 @@ module Vispan
|
|
44
41
|
end
|
45
42
|
|
46
43
|
def create_new_szenario(line)
|
47
|
-
if @single_szenario.title ==
|
44
|
+
if @single_szenario.title == ''
|
48
45
|
@single_szenario.set_title(line)
|
49
46
|
else
|
50
47
|
@szenarios << @single_szenario
|
data/lib/vispan/config.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
NODE_WIDTH = 3.3
|
2
2
|
NODE_MARGIN = 0.2
|
3
3
|
|
4
|
-
GENERAL_SETTINGS = {graph:{rankdir:
|
5
|
-
|
6
|
-
|
4
|
+
GENERAL_SETTINGS = { graph: { rankdir: 'LR', labeljust: 'l', splines: 'true', concentrate: 'true', ranksep: '2', nodesep: '0.1' },
|
5
|
+
node: { shape: 'rect', color: 'none', style: 'rounded, filled', margin: NODE_MARGIN.to_s, width: NODE_WIDTH.to_s },
|
6
|
+
edge: {}, }
|
7
7
|
|
8
|
-
SZENARIO = {szenario:{bgcolor:
|
8
|
+
SZENARIO = { szenario: { bgcolor: 'mintcream:lightcyan', margin: 60, fontsize: 18 } }
|
9
9
|
|
10
|
-
NODE = {screen:{fillcolor:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
RELATION = {event:{color:
|
17
|
-
|
18
|
-
}
|
10
|
+
NODE = { screen: { fillcolor: 'yellowgreen:lemonchiffon' },
|
11
|
+
email: { fillcolor: 'grey:ghostwhite' },
|
12
|
+
pdf: { fillcolor: 'gold:orange' },
|
13
|
+
command: { fillcolor: 'lightblue:steelblue' },
|
14
|
+
helper: { shape: 'plaintext', fillcolor: 'none', width: '0', height: '0', margin: '0.15' }, }
|
15
|
+
|
16
|
+
RELATION = { event: { color: 'red', penwidth: '2' },
|
17
|
+
link: { arrowhead: 'vee', style: 'dashed' }, }
|
data/lib/vispan/graphwriter.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require 'vispan/config.rb'
|
2
2
|
|
3
3
|
class GraphWriter
|
4
|
-
|
5
4
|
def build_string(szenarios)
|
6
|
-
"Digraph G{ #{get_general_settings}#{szenarios.map.with_index {|szenario, index| build_szenario(szenario, index)}.join(
|
5
|
+
"Digraph G{ #{get_general_settings}#{szenarios.map.with_index {|szenario, index| build_szenario(szenario, index)}.join('')}}"
|
7
6
|
end
|
8
7
|
|
9
8
|
def build_szenario(szenario, index)
|
10
|
-
node_definitions = szenario.nodes.map{|node| write_node(node)}.join(
|
11
|
-
relation_definitions = szenario.relations.map{|relation| write_relations(relation, szenario)}.join(
|
12
|
-
effect_definitions = szenario.relations.map {|relation| write_effects(relation)}.join(
|
9
|
+
node_definitions = szenario.nodes.map {|node| write_node(node)}.join('')
|
10
|
+
relation_definitions = szenario.relations.map {|relation| write_relations(relation, szenario)}.join('')
|
11
|
+
effect_definitions = szenario.relations.map {|relation| write_effects(relation)}.join('')
|
13
12
|
|
14
13
|
"\n\nsubgraph cluster#{index.to_s} {label=\"#{szenario.title}\"#{find_attributes(szenario)};\n#{node_definitions}\n#{relation_definitions}#{effect_definitions}}"
|
15
14
|
end
|
@@ -19,14 +18,14 @@ class GraphWriter
|
|
19
18
|
end
|
20
19
|
|
21
20
|
def write_relations(relation, szenario)
|
22
|
-
output_port =
|
23
|
-
input_port =
|
24
|
-
sorting_order =
|
21
|
+
output_port = 'e'
|
22
|
+
input_port = 'w'
|
23
|
+
sorting_order = ''
|
25
24
|
|
26
25
|
if relation.get_direction < 0
|
27
26
|
previous_node_name = szenario.get_previous_helper_node(relation)
|
28
|
-
output_port =
|
29
|
-
input_port =
|
27
|
+
output_port = 'w'
|
28
|
+
input_port = 'e'
|
30
29
|
sorting_order = "{rank = same; #{previous_node_name}; #{relation.helper.name};}"
|
31
30
|
end
|
32
31
|
|
@@ -41,10 +40,10 @@ class GraphWriter
|
|
41
40
|
|
42
41
|
def find_attributes(element)
|
43
42
|
type = element.class.to_s.upcase
|
44
|
-
GraphWriter.const_get(type)[element.type.to_sym].map{|attribute| "; #{attribute[0]}=\"#{attribute[1]}\""}.join(
|
43
|
+
GraphWriter.const_get(type)[element.type.to_sym].map {|attribute| "; #{attribute[0]}=\"#{attribute[1]}\""}.join('')
|
45
44
|
end
|
46
45
|
|
47
46
|
def get_general_settings
|
48
|
-
GraphWriter.const_get(
|
47
|
+
GraphWriter.const_get('GENERAL_SETTINGS').map {|attribute| "#{attribute[0]} [#{attribute[1].map {|attri| "#{attri[0]}=\"#{attri[1]}\""}.join(';')}]"}.join(';')
|
49
48
|
end
|
50
49
|
end
|
data/lib/vispan/node.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
|
3
3
|
class Node
|
4
|
-
|
5
4
|
attr_accessor :name, :type, :label, :rank
|
6
|
-
NODE_TYPES = [
|
5
|
+
NODE_TYPES = ['screen', 'email', 'pdf', 'command', 'helper']
|
7
6
|
|
8
7
|
def initialize(type, label, index, effect_flag)
|
9
8
|
@name = transform_to_name(type, label, index, effect_flag)
|
10
|
-
@type = NODE_TYPES.include?(type)? type :
|
9
|
+
@type = NODE_TYPES.include?(type) ? type : ''
|
11
10
|
@label = label
|
12
11
|
@rank = 0
|
13
12
|
end
|
14
13
|
|
15
14
|
def transform_to_name(type, label, index, effect_flag)
|
16
|
-
label =
|
17
|
-
label = label.gsub(/[-\s.]/,
|
18
|
-
label.gsub(/[\/\'|\"|\*|\\]/,
|
15
|
+
label = 'node_' + SecureRandom.uuid if effect_flag
|
16
|
+
label = label.gsub(/[-\s.]/, '') + index.to_s
|
17
|
+
label.gsub(/[\/\'|\"|\*|\\]/, '_')
|
19
18
|
end
|
20
19
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
require 'tempfile'
|
2
2
|
|
3
3
|
class OutputGraphic
|
4
|
-
|
5
4
|
def initialize(szenarios, output_file)
|
6
5
|
@file = Tempfile.new(['processed', '.dot'])
|
7
6
|
@szenarios = szenarios
|
8
|
-
@processed_string =
|
7
|
+
@processed_string = ''
|
9
8
|
@output_file = output_file
|
10
9
|
end
|
11
10
|
|
@@ -16,7 +15,7 @@ class OutputGraphic
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def build_graph
|
19
|
-
graph = GraphWriter.new
|
18
|
+
graph = GraphWriter.new
|
20
19
|
@processed_string = graph.build_string(@szenarios.reverse)
|
21
20
|
end
|
22
21
|
|
@@ -27,7 +26,7 @@ class OutputGraphic
|
|
27
26
|
|
28
27
|
def generate_graph(output_file)
|
29
28
|
FileUtils.mkdir_p File.dirname(output_file)
|
30
|
-
file_ending = File.extname(output_file).delete(
|
29
|
+
file_ending = File.extname(output_file).delete('.')
|
31
30
|
cmd = "dot -T#{file_ending} #{@file.path} -o #{output_file}"
|
32
31
|
system(cmd)
|
33
32
|
@file.unlink
|
data/lib/vispan/relation.rb
CHANGED
@@ -3,7 +3,7 @@ class Relation
|
|
3
3
|
|
4
4
|
def initialize(relation_array, index)
|
5
5
|
@effects = []
|
6
|
-
@label =
|
6
|
+
@label = ''
|
7
7
|
|
8
8
|
extract(relation_array, index)
|
9
9
|
set_helper(index)
|
@@ -13,32 +13,30 @@ class Relation
|
|
13
13
|
@start = set_node(relation_array.shift, index, false)
|
14
14
|
set_connection(relation_array.shift)
|
15
15
|
@stop = set_node(relation_array.shift, index, false)
|
16
|
-
@effects = relation_array.map{|effect| set_node(effect, index, true)}
|
16
|
+
@effects = relation_array.map {|effect| set_node(effect, index, true)}
|
17
17
|
end
|
18
18
|
|
19
19
|
def set_connection(label_string)
|
20
|
-
label = label_string.split(
|
20
|
+
label = label_string.split(':')
|
21
21
|
@type = label.shift.strip.downcase
|
22
|
-
@label = label.join(
|
22
|
+
@label = label.join(':').strip if @type.include? 'event'
|
23
23
|
adjust_length(@label)
|
24
24
|
end
|
25
25
|
|
26
26
|
def set_node(node_string, index, effect_flag)
|
27
|
-
node_array = node_string.split(
|
27
|
+
node_array = node_string.split(':')
|
28
28
|
type = node_array.shift.strip.downcase
|
29
|
-
label = node_array.join(
|
29
|
+
label = node_array.join(':').strip
|
30
30
|
adjust_length(label)
|
31
31
|
Node.new(type, label, index, effect_flag)
|
32
32
|
end
|
33
33
|
|
34
34
|
def adjust_length(string)
|
35
|
-
|
36
35
|
if string.length > 30
|
37
|
-
(20..string.length).step(20){ |limit|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
string[limit+empty] = "\n"
|
36
|
+
(20..string.length).step(20) { |limit|
|
37
|
+
if string[limit, string.length - limit].include?(' ')
|
38
|
+
empty = string[limit, string.length - limit].index(' ')
|
39
|
+
string[limit + empty] = "\n"
|
42
40
|
end
|
43
41
|
}
|
44
42
|
end
|
@@ -49,7 +47,7 @@ class Relation
|
|
49
47
|
end
|
50
48
|
|
51
49
|
def set_helper(index)
|
52
|
-
@helper = Node.new(
|
53
|
-
@helper.name =
|
50
|
+
@helper = Node.new('helper', @label, index, false)
|
51
|
+
@helper.name = 'helper_' + @helper.name + @stop.name
|
54
52
|
end
|
55
53
|
end
|
data/lib/vispan/szenario.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
require
|
1
|
+
require 'vispan/graphwriter.rb'
|
2
2
|
|
3
3
|
class Szenario
|
4
4
|
attr_accessor :title, :relations, :nodes, :type
|
5
5
|
|
6
|
-
def initialize(line =
|
7
|
-
@title = line.gsub(/--/,
|
6
|
+
def initialize(line = '')
|
7
|
+
@title = line.gsub(/--/, '').strip
|
8
8
|
@relations = []
|
9
9
|
@nodes = []
|
10
|
-
@type =
|
10
|
+
@type = 'szenario'
|
11
11
|
end
|
12
12
|
|
13
13
|
def build_szenario(index)
|
14
|
-
graph = GraphWriter.new
|
15
|
-
node_definitions = @nodes.map{|node| graph.write_node(node)}.join(
|
16
|
-
relation_definitions = @relations.map{|relation| graph.write_relations(relation)}.join(
|
17
|
-
effect_definitions = @relations.map {|relation| graph.write_effects(relation)}.join(
|
14
|
+
graph = GraphWriter.new
|
15
|
+
node_definitions = @nodes.map {|node| graph.write_node(node)}.join('')
|
16
|
+
relation_definitions = @relations.map {|relation| graph.write_relations(relation)}.join('')
|
17
|
+
effect_definitions = @relations.map {|relation| graph.write_effects(relation)}.join('')
|
18
18
|
|
19
19
|
"\n\nsubgraph cluster#{index.to_s} {bgcolor=aliceblue; label=\"#{title}\";\n#{node_definitions}\n#{relation_definitions}#{effect_definitions}}"
|
20
20
|
end
|
21
21
|
|
22
22
|
def set_title(line)
|
23
|
-
@title = line.gsub(/--/,
|
23
|
+
@title = line.gsub(/--/, '').strip
|
24
24
|
end
|
25
25
|
|
26
26
|
def add_relation(relation)
|
@@ -31,7 +31,7 @@ class Szenario
|
|
31
31
|
|
32
32
|
def add_nodes(nodes_array)
|
33
33
|
nodes_array = nodes_array.flatten
|
34
|
-
nodes_array.map{|node| @nodes << node if is_not_saved(node, @nodes)}
|
34
|
+
nodes_array.map {|node| @nodes << node if is_not_saved(node, @nodes)}
|
35
35
|
end
|
36
36
|
|
37
37
|
def is_not_saved(node, szenario_nodes)
|
@@ -48,8 +48,7 @@ class Szenario
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def assign_ranks
|
51
|
-
rank = @relations.map{|relation|
|
52
|
-
|
51
|
+
rank = @relations.map {|relation|
|
53
52
|
if relation.start.rank == 0
|
54
53
|
relation.start.rank = 1
|
55
54
|
relation.stop.rank = 2 unless relation.stop.rank > 0
|
@@ -61,11 +60,9 @@ class Szenario
|
|
61
60
|
|
62
61
|
def get_previous_helper_node(relation2)
|
63
62
|
@relations.each do |relation|
|
64
|
-
|
65
63
|
if relation2.start.name == relation.stop.name
|
66
64
|
return relation.helper.name
|
67
65
|
end
|
68
66
|
end
|
69
67
|
end
|
70
|
-
|
71
68
|
end
|