module Rubyvis::Layout::Fill

Attributes

_h[RW]
_or[RW]
_orient[RW]
_w[RW]
ir[RW]

Public Instance Methods

angle(n) click to toggle source
# File lib/rubyvis/layout/hierarchy.rb, line 244
def angle(n)
  (n.parent_node ? n.max_breadth - n.min_breadth : 1 ) * 2 * Math::PI
end
dx(n) click to toggle source
# File lib/rubyvis/layout/hierarchy.rb, line 213
def dx(n)
  if @_orient=='left' or @_orient=='right'
    (n.max_depth - n.min_depth) / (1.0 + @_depth) * @_w
  elsif @_orient=='top' or @_orient=='bottom'
    (n.max_breadth - n.min_breadth) * @_w
  elsif @_orient=='radial'
    n.parent_node ? (n.inner_radius + n.outer_radius) * Math.cos(n.mid_angle) : 0
  end          
end
dy(n) click to toggle source
# File lib/rubyvis/layout/hierarchy.rb, line 223
def dy(n)
  if @_orient=='left' or @_orient=='right'
    (n.max_breadth - n.min_breadth) * @_h
  elsif @_orient=='top' or @_orient=='bottom'
    (n.max_depth - n.min_depth) / (1.0 + @_depth) * @_h
  elsif orient=='radial'
    n.parent_node ? (n.inner_radius + n.outer_radius) * Math.sin(n.mid_angle) : 0
  end        
end
fill_build_implied(s) click to toggle source
# File lib/rubyvis/layout/hierarchy.rb, line 148
def fill_build_implied(s)
  nodes = s.nodes
  @_orient= s.orient
  @_orient=~%r^(top|bottom)$/
  horizontal = !$1.nil?
  @_w = s.width
  @_h = s.height
  @_depth = -nodes[0].min_depth
  if @_orient == "radial"
    @_ir = s.inner_radius
    @_or = s.outer_radius
    @_ir||=0
    @_depth = @_depth * 2 if @_ir!=0
    @_or||=[@_w,@_h].min / 2.0
  end
  nodes.each_with_index {|n,i|
    n.x = fill_x(n)
    n.y = fill_y(n)
    if @_orient == "radial"
      n.inner_radius = inner_radius(n);
      n.outer_radius = outer_radius(n);
      n.start_angle = start_angle(n);
      n.angle = angle(n);
      n.mid_angle = n.start_angle + n.angle / 2.0
    else 
      n.mid_angle = horizontal ? -Math::PI / 2.0 : 0
    end
    n.dx = dx(n)
    n.dy = dy(n)
  }
  false
end
fill_constructor() click to toggle source
# File lib/rubyvis/layout/hierarchy.rb, line 130
def fill_constructor
  @node.stroke_style("#fff").
    fill_style("#ccc").
    width(lambda {|n| n.dx}).
    height(lambda {|n| n.dy}).
    inner_radius(lambda {|n| n.inner_radius}).
    outer_radius(lambda {|n| n.outer_radius}).
    start_angle(lambda {|n| n.start_angle}).
    angle(lambda {|n| n.angle})
  
    @node_label.
      text_align("center").
      left(lambda {|n| n.x+ (n.dx / 2.0) }).
      top(lambda {|n| n.y+(n.dy / 2.0)})
    @link=nil
  
end
fill_scale(d, depth) click to toggle source
# File lib/rubyvis/layout/hierarchy.rb, line 181
def fill_scale(d, depth)
  (d + depth) / (1 + depth).to_f
end
fill_x(n) click to toggle source
# File lib/rubyvis/layout/hierarchy.rb, line 184
def fill_x(n)
  case @_orient
    when "left"
      fill_scale(n.min_depth,@_depth)*@_w
    when "right"
      (1-fill_scale(n.max_depth,@_depth))*@_w
    when "top"
      n.min_breadth*@_w
    when "bottom"
      (1-n.max_breath)*@_w
    when "radial"
      @_w / 2.0
  end
end
fill_y(n) click to toggle source
# File lib/rubyvis/layout/hierarchy.rb, line 198
def fill_y(n)
  case @_orient
    when "left"
      n.min_breadth*@_h
    when "right"
      (1-n.max_breadth)*@_h
    when "top"
      fill_scale(n.min_depth, @_depth) * @_h            
    when "bottom"
      (1-fill_scale(n.max_depth, @_depth)) * @_h
    when "radial"
      @_h / 2.0
  end # end case
end
inner_radius(n) click to toggle source
# File lib/rubyvis/layout/hierarchy.rb, line 233
def inner_radius(n)
  [0, fill_scale(n.min_depth, @_depth/2.0)].max * (@_or - @_ir) + @_ir
end
outer_radius(n) click to toggle source
# File lib/rubyvis/layout/hierarchy.rb, line 237
def outer_radius(n)
  fill_scale(n.max_depth, @_depth / 2.0) * (@_or - @_ir) + @_ir
end
start_angle(n) click to toggle source
# File lib/rubyvis/layout/hierarchy.rb, line 241
def start_angle(n)
  (n.parent_node ? n.min_breadth - 0.25 : 0) * 2 * Math::PI
end