Module: StateMachines::Graphviz::Renderer

Extended by:
Renderer
Included in:
Renderer
Defined in:
lib/state_machines/graphviz/renderer.rb

Instance Method Summary collapse

Instance Method Details

#draw_branch(branch, graph, event, valid_states, io = $stdout) ⇒ Object



49
50
51
52
53
# File 'lib/state_machines/graphviz/renderer.rb', line 49

def draw_branch(branch, graph, event, valid_states, io = $stdout)
  machine = event.machine
  draw_branch_with_label(branch, graph, event.name.to_s, machine, valid_states)
  true
end

#draw_event(event, graph, options = {}, io = $stdout) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/state_machines/graphviz/renderer.rb', line 37

def draw_event(event, graph, options = {}, io = $stdout)
  machine = event.machine
  valid_states = machine.states.by_priority.map(&:name)
  event_label = options[:human_name] ? event.human_name(machine.owner_class) : event.name.to_s

  event.branches.each do |branch|
    draw_branch_with_label(branch, graph, event_label, machine, valid_states)
  end

  true
end

#draw_machine(machine, io: $stdout, **options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/state_machines/graphviz/renderer.rb', line 10

def draw_machine(machine, io: $stdout, **options)
  diagram, builder = StateMachines::Diagram::Renderer.build_state_diagram(machine, options)
  graph_options = options.dup
  name = graph_options.delete(:name) || "#{machine.owner_class.name}_#{machine.name}"

  draw_options = { human_name: false }
  draw_options[:human_name] = graph_options.delete(:human_names) if graph_options.include?(:human_names)

  graph = Graph.new(name, graph_options)
  render_diagram(graph, diagram, builder, draw_options)
  graph.output
  graph
end

#draw_state(state, graph, options = {}, io = $stdout) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/state_machines/graphviz/renderer.rb', line 24

def draw_state(state, graph, options = {}, io = $stdout)
  node = graph.add_nodes(
    state.name ? state.name.to_s : 'nil',
    label: state.description(options),
    width: '1',
    height: '1',
    shape: state.final? ? 'doublecircle' : 'ellipse'
  )

  graph.add_edges(graph.add_nodes('starting_state', shape: 'point'), node) if state.initial?
  true
end