class Dogviz::Thing

Attributes

edge_heads[R]
id[R]
name[R]
parent[R]
pointers[R]

Public Class Methods

new(parent, name, options = {}) click to toggle source
# File lib/dogviz/thing.rb, line 16
def initialize(parent, name, options = {})
  @parent = parent
  @name = name
  @id = create_id(name, parent)
  @pointers = []
  @rollup = false
  @skip = false
  @info = {}
  @edge_heads = []

  rollup! if options[:rollup]
  options.delete(:rollup)

  @render_options = options
  setup_render_attributes({label: name}.merge inherited_render_options)

  parent.register name, self
end

Public Instance Methods

points_to(other, options = {}) click to toggle source
# File lib/dogviz/thing.rb, line 41
def points_to(other, options = {})
  setup_render_edge(other, options)
  other
end
Also aliased as: to
points_to_all(*others) click to toggle source
# File lib/dogviz/thing.rb, line 35
def points_to_all(*others)
  others.each { |other|
    points_to other
  }
end
Also aliased as: to_all
render(renderer) click to toggle source
# File lib/dogviz/thing.rb, line 49
def render(renderer)
  do_render_node(renderer) unless in_rollup? || in_skip?
end
render_edges(renderer) click to toggle source
# File lib/dogviz/thing.rb, line 53
def render_edges(renderer)
  pointers.each { |p|
    render_pointer p, renderer
  }
end
to(other, options = {})
Alias for: points_to
to_all(*others)
Alias for: points_to_all

Private Instance Methods

already_added_connection?(other) click to toggle source
# File lib/dogviz/thing.rb, line 121
def already_added_connection?(other)
  edge_heads.include? other
end
do_render_node(renderer) click to toggle source
# File lib/dogviz/thing.rb, line 61
def do_render_node(renderer)
  renderer.render_node(parent, id, @render_options.merge(@attributes))
end
next_colorizer_color() click to toggle source
# File lib/dogviz/thing.rb, line 138
def next_colorizer_color
  @@colorizer.next
end
render_pointer(pointer, renderer) click to toggle source
# File lib/dogviz/thing.rb, line 90
def render_pointer(pointer, renderer)
  other = pointer[:other]
  while (other.in_rollup? && !other.on_top_rollup?) do
    other = other.parent
  end
  return if other.under_rollup?

  from = self
  while (from.in_rollup? && !from.on_top_rollup?) do
    from = from.parent
  end

  return if from.in_skip?

  return if from == self && from.in_rollup?
  return if from == other
  return if already_added_connection?(other)

  if other.in_skip?
    others = resolve_skipped_others other
  else
    others = [other]
  end

  others.each do |other_to_render|
    edge_heads << other_to_render
    render_options = pointer[:options]
    renderer.render_edge(from, other_to_render, render_options)
  end
end
resolve_skipped_others(skipped) click to toggle source
# File lib/dogviz/thing.rb, line 125
def resolve_skipped_others(skipped)
  resolved = []
  skipped.pointers.each { |pointer|
    next_in_line = pointer[:other]
    if next_in_line.in_skip?
      resolved += resolve_skipped_others next_in_line
    else
      resolved << next_in_line
    end
  }
  resolved
end
setup_render_edge(other, options) click to toggle source
# File lib/dogviz/thing.rb, line 65
def setup_render_edge(other, options)
  fontsize = 14
  fontsize += options[:stroke] if options.has_key?(:stroke)
  pointers << {
      other: other,
      options: {
          xlabel: options[:name],
          style: options[:style],
          color: options[:color],
          fontcolor: options[:color],
          penwidth: options[:stroke],
          fontsize: fontsize
      }.merge(inherited_render_options)
  }

  if options[:colorize] || root.colorize_edges?
    edge_color = next_colorizer_color
    pointers.last[:options].merge!({
                                       color: edge_color,
                                       fontcolor: edge_color
                                   })
  end

end