Class: GraphVizExport

Inherits:
Object
  • Object
show all
Defined in:
lib/lucidMachines/graphviz_export.rb

Instance Method Summary collapse

Constructor Details

#initialize(chart) ⇒ GraphVizExport

Returns a new instance of GraphVizExport.



2
3
4
5
6
7
8
# File 'lib/lucidMachines/graphviz_export.rb', line 2

def initialize(chart)
  @chart = chart
  @g = GraphViz.new( :G, :type => :digraph )

  @node_map = {}
  @edge_map = {}
end

Instance Method Details

#build_graph(output_name) ⇒ Object



10
11
12
13
14
# File 'lib/lucidMachines/graphviz_export.rb', line 10

def build_graph(output_name)
  create_nodes
  create_edges
  @g.output( :png => output_name )
end

#create_edgesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/lucidMachines/graphviz_export.rb', line 31

def create_edges
  @chart.states.each do |b|
    
    src = @node_map[b]

    b.links_to.each do |link, b2|

      next unless b2.is_state?
      
      dst = @node_map[b2]
      next if b2.is_hidden?
      e = @g.add_edges(src, dst)

      # b.add_edge(e)
      @edge_map[b] = [] if @edge_map[b].nil?
      @edge_map[b] << e 
      
      # style
      e[:arrowhead] = get_arrow_style(link.destination_arrow)
      e[:arrowtail] = get_arrow_style(link.source_arrow)
      
      #    if link.source_arrow.eql? "None"
      
      unless link.text.nil?
        e[:label] = link.text
        e[:color] = "red" if link.text.eql? "No"
        e[:color] = "green" if link.text.eql? "Yes"
      end
    end
  end
end

#create_nodesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lucidMachines/graphviz_export.rb', line 16

def create_nodes
  @chart.states.each do |b|
    
    n = @g.add_node(b.id)
    @node_map[b] = n

    n[:label] =  b.text.to_s
    n[:color] = "purple" if b.is_initial?
    n[:shape] = "box" # look like lucid@chart

    n[:shape] = "diamond" if b.type.eql? "event"
    n[:shape] = "circle" if b.type.eql? "transition"
  end
end

#get_arrow_style(lucid_style) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/lucidMachines/graphviz_export.rb', line 63

def get_arrow_style(lucid_style)
  return "none" if lucid_style.eql? "None"
  return "normal" if lucid_style.eql? "Arrow"
  return "empty" if lucid_style.eql? "Hollow Arrow"
  return "open" if lucid_style.eql? "Open Arrow"
  
  return "none"
end