Class: GraphWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/vispan/graphwriter.rb

Instance Method Summary collapse

Instance Method Details

#build_string(szenarios) ⇒ Object



4
5
6
# File 'lib/vispan/graphwriter.rb', line 4

def build_string(szenarios)
  "Digraph G{ #{get_general_settings}#{szenarios.map.with_index {|szenario, index| build_szenario(szenario, index)}.join('')}}"
end

#build_szenario(szenario, index) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/vispan/graphwriter.rb', line 8

def build_szenario(szenario, index)
  node_definitions = szenario.nodes.map {|node| write_node(node)}.join('')
  relation_definitions = szenario.relations.map {|relation| write_relations(relation, szenario)}.join('')
  effect_definitions = szenario.relations.map {|relation| write_effects(relation)}.join('')

  "\n\nsubgraph cluster#{index.to_s} {label=\"#{szenario.title}\"#{find_attributes(szenario)};\n#{node_definitions}\n#{relation_definitions}#{effect_definitions}}"
end

#find_attributes(element) ⇒ Object



41
42
43
44
# File 'lib/vispan/graphwriter.rb', line 41

def find_attributes(element)
  type = element.class.to_s.upcase
  GraphWriter.const_get(type)[element.type.to_sym].map {|attribute| "; #{attribute[0]}=\"#{attribute[1]}\""}.join('')
end

#get_general_settingsObject



46
47
48
# File 'lib/vispan/graphwriter.rb', line 46

def get_general_settings
  GraphWriter.const_get('GENERAL_SETTINGS').map {|attribute| "#{attribute[0]} [#{attribute[1].map {|attri| "#{attri[0]}=\"#{attri[1]}\""}.join(';')}]"}.join(';')
end

#write_effects(relation) ⇒ Object



37
38
39
# File 'lib/vispan/graphwriter.rb', line 37

def write_effects(relation)
  "subgraph cluster#{relation.start.name} {label = \"Side effects\"; labeljust = \"c\"; style=\"rounded\"; {rank = same; #{relation.helper.name}; #{relation.effects.map(&:name).join(';')};};}" unless relation.effects.empty?
end

#write_node(node) ⇒ Object



16
17
18
# File 'lib/vispan/graphwriter.rb', line 16

def write_node(node)
  "#{node.name} [label=\"#{node.label}\" #{find_attributes(node)}]\n"
end

#write_relations(relation, szenario) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vispan/graphwriter.rb', line 20

def write_relations(relation, szenario)
  output_port = 'e'
  input_port = 'w'
  sorting_order = ''

  if relation.get_direction < 0
    previous_node_name = szenario.get_previous_helper_node(relation)
    output_port = 'w'
    input_port = 'e'
    sorting_order = "{rank = same; #{previous_node_name}; #{relation.helper.name};}"
  end

  "#{relation.start.name}:#{output_port} -> #{relation.helper.name}:#{input_port} [dir=\"none\" #{find_attributes(relation)}];
   #{relation.helper.name}:#{output_port} -> #{relation.stop.name}:#{input_port} [dir=\"forward\" #{find_attributes(relation)}];
   #{sorting_order}"
end