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.

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ GraphvizWriter

Returns a new instance of GraphvizWriter.



5
6
7
# File 'lib/seafoam/graphviz_writer.rb', line 5

def initialize(stream)
  @stream = stream
end

Instance Method Details

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

Write a graph.



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

def write_graph(graph, hidpi = false, draw_blocks = false)
  inline_attrs = {}
  attrs = {}
  attrs[:dpi] = 200 if hidpi
  attrs[:bgcolor] = 'white'
  @stream.puts 'digraph G {'
  @stream.puts "  graph #{write_attrs(attrs)};"
  write_nodes inline_attrs, graph
  write_edges inline_attrs, graph
  write_blocks graph if draw_blocks
  @stream.puts '}'
end