Module: Clumpy::ClusterBehavior
- Included in:
- Cluster
- Defined in:
- lib/clumpy/cluster_behavior.rb
Instance Attribute Summary collapse
-
#bounds ⇒ Object
Returns the value of attribute bounds.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#points ⇒ Object
Returns the value of attribute points.
Instance Method Summary collapse
- #as_json ⇒ Object
- #contains?(point) ⇒ Boolean
- #initialize(point, options = {}) ⇒ Object
- #reposition ⇒ Object
- #value_list ⇒ Object
Instance Attribute Details
#bounds ⇒ Object
Returns the value of attribute bounds.
3 4 5 |
# File 'lib/clumpy/cluster_behavior.rb', line 3 def bounds @bounds end |
#latitude ⇒ Object
Returns the value of attribute latitude.
3 4 5 |
# File 'lib/clumpy/cluster_behavior.rb', line 3 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
3 4 5 |
# File 'lib/clumpy/cluster_behavior.rb', line 3 def longitude @longitude end |
#points ⇒ Object
Returns the value of attribute points.
3 4 5 |
# File 'lib/clumpy/cluster_behavior.rb', line 3 def points @points end |
Instance Method Details
#as_json ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/clumpy/cluster_behavior.rb', line 24 def as_json(*) bounds = { northeast: { latitude: @points.map(&:latitude).max, longitude: @points.map(&:longitude).max, }, southwest: { latitude: @points.map(&:latitude).min, longitude: @points.map(&:longitude).min, } } { latitude: latitude, longitude: longitude, size: @points.size, bounds: bounds, values: value_list, } end |
#contains?(point) ⇒ Boolean
14 15 16 17 |
# File 'lib/clumpy/cluster_behavior.rb', line 14 def contains?(point) @bounds.latitude.include?(point.latitude) && @bounds.longitude.include?(point.longitude) end |
#initialize(point, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/clumpy/cluster_behavior.rb', line 5 def initialize(point, = {}) @latitude = point.latitude @longitude = point.longitude @points = [point] @options = @bounds = Bounds.new(@latitude, @longitude, [:width], [:length]) end |
#reposition ⇒ Object
19 20 21 22 |
# File 'lib/clumpy/cluster_behavior.rb', line 19 def reposition @latitude = @points.inject(0.0) { |m, p| m + p.latitude } / @points.size @longitude = @points.inject(0.0) { |m, p| m + p.longitude } / @points.size end |
#value_list ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/clumpy/cluster_behavior.rb', line 45 def value_list case @options[:include_values] when true then @points when false then [] else values_threshold = @options[:values_threshold] || 10 @points.size <= values_threshold ? @points : [] end end |