Module: Rubyvis::Layout::NodeLink

Included in:
Partition
Defined in:
lib/rubyvis/layout/hierarchy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_hObject

Returns the value of attribute _h.



68
69
70
# File 'lib/rubyvis/layout/hierarchy.rb', line 68

def _h
  @_h
end

#_irObject

Returns the value of attribute _ir.



68
69
70
# File 'lib/rubyvis/layout/hierarchy.rb', line 68

def _ir
  @_ir
end

#_orObject

Returns the value of attribute _or.



68
69
70
# File 'lib/rubyvis/layout/hierarchy.rb', line 68

def _or
  @_or
end

#_orientObject

Returns the value of attribute _orient.



68
69
70
# File 'lib/rubyvis/layout/hierarchy.rb', line 68

def _orient
  @_orient
end

#_wObject

Returns the value of attribute _w.



68
69
70
# File 'lib/rubyvis/layout/hierarchy.rb', line 68

def _w
  @_w
end

Instance Method Details

#mid_angle(n) ⇒ Object



95
96
97
# File 'lib/rubyvis/layout/hierarchy.rb', line 95

def mid_angle(n)
  n.parent_node ? ((n.breadth - 0.25) * 2 * Math::PI ) : 0
end


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rubyvis/layout/hierarchy.rb', line 69

def node_link_build_implied(s)
  nodes = s.nodes
  @_orient= s.orient
  @_orient=~/^(top|bottom)$/
  
  horizontal = !$1.nil?
  @_w = s.width
  @_h = s.height
  # /* Compute default inner and outer radius. */
  if (@_orient == "radial") 
    @_ir = s.inner_radius
    @_or = s.outer_radius
    @_ir||=0
    @_or||=[@_w,@_h].min / 2.0
  end
  nodes.each_with_index{|n,i|
    n.mid_angle = (@_orient == "radial") ? mid_angle(n) : (horizontal ? Math::PI / 2.0 : 0)
    n.x = node_link_x(n)
    n.y = node_link_y(n)
    n.mid_angle+=Math::PI if (n.first_child)
  }
  false
end


98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/rubyvis/layout/hierarchy.rb', line 98

def node_link_x(n)
  case @_orient
    when "left"
      n.depth*@_w
    when "right"
      @_w-n.depth*@_w
    when "top"
      n.breadth*@_w
    when "bottom"
      @_w-n.breath*@_w
    when "radial"
      @_w/2.0+radius(n)*Math.cos(n.mid_angle)
  end
end


112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rubyvis/layout/hierarchy.rb', line 112

def node_link_y(n)
  case @_orient
    when "left"
      n.breadth*@_h
    when "right"
      @_h-n.depth*@_h
    when "top"
      n.depth*@_h            
    when "bottom"
      @_h-n.breath*@_h
    when "radial"
      @_h / 2.0 + radius(n) * Math.sin(n.mid_angle)
  end # end case
end

#radius(n) ⇒ Object



92
93
94
# File 'lib/rubyvis/layout/hierarchy.rb', line 92

def radius(n)
  n.parent_node ? (n.depth * (@_or-@_ir)+@_ir) : 0
end