class SyntaxTree::Mermaid::FlowChart
of its nodes and links and renders them according to the mermaid syntax.
This is the main class that handles rendering a flowchart. It keeps track
def fetch(id)
def fetch(id) nodes.fetch(id) end
def initialize
def initialize @output = StringIO.new @output.puts("flowchart TD") @prefix = " " @nodes = {} @links = [] end
def link(from, to, label = nil, type: :directed, color: nil)
def link(from, to, label = nil, type: :directed, color: nil) link = Link.new(from, to, label, type, color) links << link output.puts("#{prefix}#{link.render}") link end
def node(id, label = " ", shape: :rectangle)
def node(id, label = " ", shape: :rectangle) node = Node.new(id, label, shape) nodes[id] = node output.puts("#{prefix}#{nodes[id].render}") node end
def render
def render links.each_with_index do |link, index| if link.color output.puts("#{prefix}linkStyle #{index} stroke:#{link.color}") end end output.string end
def subgraph(label)
Add a subgraph to the flowchart. Within the given block, all of the
def subgraph(label) output.puts("#{prefix}subgraph #{Mermaid.escape(label)}") previous = prefix @prefix = "#{prefix} " begin yield ensure @prefix = previous output.puts("#{prefix}end") end end