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
- #bounds_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
28 29 30 31 32 33 34 35 36 |
# File 'lib/clumpy/cluster_behavior.rb', line 28 def as_json(*) { latitude: latitude, longitude: longitude, size: points.size, bounds: bounds_as_json, values: value_list } end |
#bounds_as_json ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/clumpy/cluster_behavior.rb', line 48 def bounds_as_json { northeast: { latitude: bounds.latitude.max, longitude: bounds.longitude.max }, southwest: { latitude: bounds.latitude.min, longitude: bounds.longitude.min } } end |
#contains?(point) ⇒ Boolean
18 19 20 21 |
# File 'lib/clumpy/cluster_behavior.rb', line 18 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 13 14 15 16 |
# File 'lib/clumpy/cluster_behavior.rb', line 5 def initialize(point, = {}) @latitude = point.latitude @longitude = point.longitude @points = [point] = side_length = .fetch(:side_length) { 10 } @bounds = OpenStruct.new( latitude: (latitude - side_length)..(latitude + side_length), longitude: (longitude - side_length)..(longitude + side_length) ) end |
#reposition ⇒ Object
23 24 25 26 |
# File 'lib/clumpy/cluster_behavior.rb', line 23 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
38 39 40 41 42 43 44 45 46 |
# File 'lib/clumpy/cluster_behavior.rb', line 38 def value_list case [:include_values] when true then points when false then [] else values_threshold = [:values_threshold] || 10 points.size <= values_threshold ? points : [] end end |