Class: Doodl::CircleLayout
Instance Attribute Summary
Attributes inherited from Layout
#graph, #iterations, #locations
Instance Method Summary collapse
- #dolayout(graph) ⇒ Object
-
#initialize(view) ⇒ CircleLayout
constructor
A new instance of CircleLayout.
Methods inherited from Layout
#center_x, #center_y, #deep_copy, #finished?, #get_nearest_node, #get_nearest_node_within, #init, #layout, #move, #rotate, #set_location
Constructor Details
#initialize(view) ⇒ CircleLayout
Returns a new instance of CircleLayout.
130 131 132 |
# File 'lib/layout/layout.rb', line 130 def initialize(view) super(view) end |
Instance Method Details
#dolayout(graph) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/layout/layout.rb', line 134 def dolayout(graph) $LOG.info "Started CircleLayout" if $LOG center = @view.center r = [center.x, center.y].min * 0.75 main = 2 * Math::PI / graph.num_nodes graph.each_node_with_index do |node, index| x = center.x + r * Math.sin(index * main) y = center.y + r * Math.cos(index * main) @locations[node] = Location.new(x, y) end $LOG.info "Finished CircleLayout" if $LOG end |