Module: Rubyvis::Layout::Fill
- Defined in:
- lib/rubyvis/layout/hierarchy.rb
Overview
end class
Instance Attribute Summary collapse
-
#_h ⇒ Object
Returns the value of attribute _h.
-
#_or ⇒ Object
Returns the value of attribute _or.
-
#_orient ⇒ Object
Returns the value of attribute _orient.
-
#_w ⇒ Object
Returns the value of attribute _w.
-
#ir ⇒ Object
Returns the value of attribute ir.
Instance Method Summary collapse
- #angle(n) ⇒ Object
-
#dx(n) ⇒ Object
end method.
- #dy(n) ⇒ Object
- #fill_build_implied(s) ⇒ Object
- #fill_constructor ⇒ Object
- #fill_scale(d, depth) ⇒ Object
- #fill_x(n) ⇒ Object
- #fill_y(n) ⇒ Object
- #inner_radius(n) ⇒ Object
- #outer_radius(n) ⇒ Object
- #start_angle(n) ⇒ Object
Instance Attribute Details
#_h ⇒ Object
Returns the value of attribute _h.
129 130 131 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 129 def _h @_h end |
#_or ⇒ Object
Returns the value of attribute _or.
129 130 131 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 129 def _or @_or end |
#_orient ⇒ Object
Returns the value of attribute _orient.
129 130 131 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 129 def _orient @_orient end |
#_w ⇒ Object
Returns the value of attribute _w.
129 130 131 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 129 def _w @_w end |
#ir ⇒ Object
Returns the value of attribute ir.
129 130 131 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 129 def ir @ir end |
Instance Method Details
#angle(n) ⇒ Object
239 240 241 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 239 def angle(n) (n.parent_node ? n.max_breadth - n.min_breadth : 1 ) * 2 * Math::PI end |
#dx(n) ⇒ Object
end method
212 213 214 215 216 217 218 219 220 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 212 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) ⇒ Object
221 222 223 224 225 226 227 228 229 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 221 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) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 148 def fill_build_implied(s) nodes = s.nodes @_orient= s.orient @_orient=~/^(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 ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# 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) ⇒ Object
181 182 183 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 181 def fill_scale(d, depth) (d+depth) / (1.0+depth) end |
#fill_x(n) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# 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) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# 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) ⇒ Object
230 231 232 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 230 def inner_radius(n) [0, fill_scale(n.min_depth, @_depth/2.0)].max * (@_or - @_ir) + @_ir end |
#outer_radius(n) ⇒ Object
233 234 235 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 233 def outer_radius(n) fill_scale(n.max_depth, @_depth / 2.0) * (@_or - @_ir) + @_ir end |
#start_angle(n) ⇒ Object
236 237 238 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 236 def start_angle(n) (n.parent_node ? n.min_breadth - 0.25 : 0) * 2 * Math::PI end |