class Dogviz::GraphvizRenderer

Attributes

graph[R]

Public Class Methods

new(title, hints) click to toggle source
# File lib/dogviz/graphviz_renderer.rb, line 8
def initialize(title, hints)
  construction_hints = {}
  after_hints = hints.clone
  if hints.has_key?(:use)
    construction_hints[:use] = hints[:use]
    after_hints.delete :use
  end
  @graph = GraphViz.digraph(title, construction_hints)
  @graph[after_hints]
  @subgraphs = {}
  @nodes = {}
  @rendered_subgraph_ids = {}
end

Public Instance Methods

render_edge(from, other, options) click to toggle source
# File lib/dogviz/graphviz_renderer.rb, line 22
def render_edge(from, other, options)
  edge = graph.add_edges from.id, other.id
  options.each { |key, value|
    edge[key] = value unless value.nil?
  }
  edge
end
render_node(parent, id, attributes) click to toggle source
# File lib/dogviz/graphviz_renderer.rb, line 30
def render_node(parent, id, attributes)
  clean_node_attributes attributes
  default_attributes = {:shape => 'box', :style => ''}
  merged_attributes = default_attributes.merge(attributes)
  parent_node(parent).add_nodes(id, merged_attributes)
end
render_subgraph(parent, id, attributes) click to toggle source
# File lib/dogviz/graphviz_renderer.rb, line 37
def render_subgraph(parent, id, attributes)
  if (attributes[:bounded] == true) then
    rendered_id = 'cluster_' + id
  else
    rendered_id = id
  end
  @rendered_subgraph_ids[id] = rendered_id

  subgraph = parent_node(parent).add_graph(rendered_id, clean_subgraph_attributes(attributes.clone))
  @subgraphs[id] = subgraph
  subgraph
end

Private Instance Methods

apply_render_attributes(node, attributes) click to toggle source
# File lib/dogviz/graphviz_renderer.rb, line 72
def apply_render_attributes(node, attributes)
  attributes.each do |key, value|
    node[key] = value
  end
end
clean_node_attributes(attributes) click to toggle source
# File lib/dogviz/graphviz_renderer.rb, line 52
def clean_node_attributes(attributes)
  attributes.delete(:rank)
  attributes.delete(:bounded)
  attributes
end
clean_subgraph_attributes(attributes) click to toggle source
# File lib/dogviz/graphviz_renderer.rb, line 58
def clean_subgraph_attributes(attributes)
  attributes.delete(:bounded)
  attributes
end
parent_node(parent) click to toggle source
# File lib/dogviz/graphviz_renderer.rb, line 63
def parent_node(parent)
  return graph if parent.root?
  node = graph.search_node(parent.id)
  return node unless node.nil?
  subgraph = @subgraphs[parent.id]
  raise "couldn't find node or graph: #{parent.id}, out of graphs: #{graph_ids}" if subgraph.nil?
  subgraph
end