Class: Mermaid::FlowchartDiagram

Inherits:
BaseDiagram
  • Object
show all
Includes:
Parser
Defined in:
lib/mermaid/flowchart_diagram.rb

Defined Under Namespace

Modules: Parser Classes: Link, Node

Constant Summary collapse

NAME =
'flowchart'
Direction =
Types::String.default('LR').enum('LR', 'RL', 'TB', 'BT')

Instance Method Summary collapse

Methods included from Parser

included

Methods inherited from BaseDiagram

#to_s

Instance Method Details

#generateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mermaid/flowchart_diagram.rb', line 13

def generate
  diagram = "#{NAME} #{direction}\n"
  labeled_nodes = Set.new
  links.each do |link|
    from_node = nodes.find { |node| node.id == link.from }
    to_node = nodes.find { |node| node.id == link.to }
    from_node_already_labeled = !labeled_nodes.include?(from_node)
    to_node_already_labeled = !labeled_nodes.include?(to_node)
    diagram += "  #{from_node.to_s(from_node_already_labeled)} -->#{link.label ? "|#{link.label}|" : ''} #{to_node.to_s(to_node_already_labeled)}\n"
    labeled_nodes << from_node if from_node.label
    labeled_nodes << to_node if to_node.label
  end
  diagram
end

#inspectObject



28
29
30
# File 'lib/mermaid/flowchart_diagram.rb', line 28

def inspect
  "#<#{self.class.name}: Nodes: #{nodes.size}, Links: #{links.size}>"
end