Class: Seafoam::GraphvizWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/seafoam/graphviz_writer.rb

Overview

A writer from graphs to the Graphviz DOT format, including all the formatting.

Direct Known Subclasses

MermaidWriter

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ GraphvizWriter

Returns a new instance of GraphvizWriter.



7
8
9
# File 'lib/seafoam/graphviz_writer.rb', line 7

def initialize(stream)
  @stream = stream
end

Instance Method Details

#end_graphObject



28
29
30
# File 'lib/seafoam/graphviz_writer.rb', line 28

def end_graph
  @stream.puts "}"
end

#start_graph(attrs) ⇒ Object



23
24
25
26
# File 'lib/seafoam/graphviz_writer.rb', line 23

def start_graph(attrs)
  @stream.puts "digraph G {"
  @stream.puts "  graph #{write_attrs(attrs)};"
end

#write_graph(graph, hidpi = false, draw_blocks = false) ⇒ Object

Write a graph.



12
13
14
15
16
17
18
19
20
21
# File 'lib/seafoam/graphviz_writer.rb', line 12

def write_graph(graph, hidpi = false, draw_blocks = false)
  inline_attrs = {}
  attrs = {}
  attrs[:dpi] = 200 if hidpi
  attrs[:bgcolor] = "white"
  start_graph(attrs)
  write_nodes(inline_attrs, graph, draw_blocks)
  write_edges(inline_attrs, graph)
  end_graph
end