Class: Doodl::FRLayout

Inherits:
Layout
  • Object
show all
Defined in:
lib/layout/fr_layout.rb

Instance Attribute Summary

Attributes inherited from Layout

#graph, #iterations, #locations

Instance Method Summary collapse

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) ⇒ FRLayout

Returns a new instance of FRLayout.



9
10
11
12
13
# File 'lib/layout/fr_layout.rb', line 9

def initialize(view)
  super(view)
  @max_iterations = 500
  @max_dimension = [view.width, view.height].max
end

Instance Method Details

#dolayout(graph) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/layout/fr_layout.rb', line 15

def dolayout(graph)
  setup(graph)
  while  (@iterations < @max_iterations and @temperature > 1.0/@max_dimension )
    step(graph)
    changed
    notify_observers(self)
  end
end

#setup(graph) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/layout/fr_layout.rb', line 24

def setup(graph)
  @temperature = @max_dimension / 10.0
  @force_constant = Math.sqrt(@view.width * @view.height / graph.num_nodes) * 0.75
  @disp = Hash.new
  graph.each_node { |n| @disp[n] = Location.new(0, 0) }

  randomize_locations(graph)
end