class GraphWriter

Public Instance Methods

build_string(szenarios) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_settings() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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