clumpy 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/clumpy/builder.rb +17 -3
- data/lib/clumpy/cluster_behavior.rb +7 -4
- data/lib/clumpy/version.rb +1 -1
- data/spec/builder_spec.rb +2 -2
- data/spec/cluster_behavior_spec.rb +5 -5
- metadata +4 -4
data/lib/clumpy/builder.rb
CHANGED
@@ -30,7 +30,7 @@ module Clumpy
|
|
30
30
|
if parent_cluster
|
31
31
|
parent_cluster.points << point
|
32
32
|
else
|
33
|
-
clusters << cluster_class.new(point,
|
33
|
+
clusters << cluster_class.new(point, cluster_options)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -42,14 +42,20 @@ module Clumpy
|
|
42
42
|
clusters.find { |c| c.contains?(point) }
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def cluster_latitude_distance
|
46
46
|
latitude_distance / DISTANCE_MODIFIER
|
47
47
|
end
|
48
48
|
|
49
|
+
def cluster_longitude_distance
|
50
|
+
longitude_distance / (DISTANCE_MODIFIER * 2)
|
51
|
+
end
|
52
|
+
|
49
53
|
def cluster_options
|
50
54
|
{
|
51
55
|
values_threshold: options[:values_threshold],
|
52
|
-
include_values: options[:include_values]
|
56
|
+
include_values: options[:include_values],
|
57
|
+
latitude_distance: cluster_latitude_distance,
|
58
|
+
longitude_distance: cluster_longitude_distance
|
53
59
|
}
|
54
60
|
end
|
55
61
|
|
@@ -64,5 +70,13 @@ module Clumpy
|
|
64
70
|
MAX_LATITUDE_DISTANCE
|
65
71
|
end
|
66
72
|
end
|
73
|
+
|
74
|
+
def longitude_distance
|
75
|
+
if options[:nelng] && options[:swlng]
|
76
|
+
(options[:nelng] - options[:swlng]).abs
|
77
|
+
else
|
78
|
+
MAX_LONGITUDE_DISTANCE
|
79
|
+
end
|
80
|
+
end
|
67
81
|
end
|
68
82
|
end
|
@@ -2,14 +2,17 @@ module Clumpy
|
|
2
2
|
module ClusterBehavior
|
3
3
|
attr_accessor :latitude, :longitude, :points, :bounds
|
4
4
|
|
5
|
-
def initialize(point,
|
5
|
+
def initialize(point, options = {})
|
6
6
|
@latitude = point.latitude
|
7
7
|
@longitude = point.longitude
|
8
8
|
@points = [point]
|
9
9
|
@options = options
|
10
|
+
|
11
|
+
lat_dist = options[:latitude_distance] || 10
|
12
|
+
lng_dist = options[:longitude_distance] || 10
|
10
13
|
@bounds = OpenStruct.new(
|
11
|
-
latitude: (latitude -
|
12
|
-
longitude: (longitude -
|
14
|
+
latitude: (latitude - lat_dist)..(latitude + lat_dist),
|
15
|
+
longitude: (longitude - lng_dist)..(longitude + lng_dist)
|
13
16
|
)
|
14
17
|
end
|
15
18
|
|
@@ -51,7 +54,7 @@ module Clumpy
|
|
51
54
|
},
|
52
55
|
southwest: {
|
53
56
|
latitude: bounds.latitude.min,
|
54
|
-
longitude: bounds.longitude.
|
57
|
+
longitude: bounds.longitude.min
|
55
58
|
}
|
56
59
|
}
|
57
60
|
end
|
data/lib/clumpy/version.rb
CHANGED
data/spec/builder_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe Clumpy::Builder do
|
|
25
25
|
|
26
26
|
it "passes the values threshold through to the cluster" do
|
27
27
|
builder = Clumpy::Builder.new([point1], values_threshold: 100, include_values: true)
|
28
|
-
builder.cluster_options.should eq({ values_threshold: 100, include_values: true })
|
28
|
+
builder.cluster_options.should eq({ values_threshold: 100, include_values: true, latitude_distance: 34.01023, longitude_distance: 36 })
|
29
29
|
clusters = builder.cluster
|
30
30
|
clusters.first.instance_variable_get(:@options).should eq builder.cluster_options
|
31
31
|
end
|
@@ -44,7 +44,7 @@ describe Clumpy::Builder do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "appends markers to a existing cluster if they match" do
|
47
|
-
builder.clusters << Clumpy::Cluster.new(point1, builder.
|
47
|
+
builder.clusters << Clumpy::Cluster.new(point1, builder.cluster_options)
|
48
48
|
builder.clusters.size.should eq 1
|
49
49
|
builder.clusters.first.points.size.should eq 1
|
50
50
|
builder.add_to_cluster(point2)
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Clumpy::ClusterBehavior do
|
4
4
|
let(:point) { OpenStruct.new(latitude: 15, longitude: 20) }
|
5
5
|
let(:other_point) { OpenStruct.new(latitude: 40, longitude: 40) }
|
6
|
-
let(:cluster) { Clumpy::Cluster.new(point, 10) }
|
6
|
+
let(:cluster) { Clumpy::Cluster.new(point, latitude_distance: 10, longitude_distance: 10) }
|
7
7
|
|
8
8
|
it "has a nicish to_s representation" do
|
9
9
|
cluster.to_s.should include '# size: 1'
|
@@ -27,23 +27,23 @@ describe Clumpy::ClusterBehavior do
|
|
27
27
|
|
28
28
|
context "#value_list" do
|
29
29
|
it "returns an empty array if threshold isn't reached" do
|
30
|
-
cluster = Clumpy::Cluster.new(point,
|
30
|
+
cluster = Clumpy::Cluster.new(point, values_threshold: 1)
|
31
31
|
cluster.points << other_point
|
32
32
|
cluster.value_list.should eq []
|
33
33
|
end
|
34
34
|
|
35
35
|
it "returns an array of json points if under threshold" do
|
36
|
-
cluster = Clumpy::Cluster.new(point,
|
36
|
+
cluster = Clumpy::Cluster.new(point, values_threshold: 1)
|
37
37
|
cluster.value_list.should eq [point]
|
38
38
|
end
|
39
39
|
|
40
40
|
it "returns a list of values if include_values is true" do
|
41
|
-
cluster = Clumpy::Cluster.new(point,
|
41
|
+
cluster = Clumpy::Cluster.new(point, values_threshold: 0, include_values: true)
|
42
42
|
cluster.value_list.should eq [point]
|
43
43
|
end
|
44
44
|
|
45
45
|
it "returns a empty list if include_values is false" do
|
46
|
-
cluster = Clumpy::Cluster.new(point,
|
46
|
+
cluster = Clumpy::Cluster.new(point, values_threshold: 10, include_values: false)
|
47
47
|
cluster.value_list.should eq []
|
48
48
|
end
|
49
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clumpy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -113,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
segments:
|
115
115
|
- 0
|
116
|
-
hash:
|
116
|
+
hash: -2427505316629763450
|
117
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
118
|
none: false
|
119
119
|
requirements:
|
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
version: '0'
|
123
123
|
segments:
|
124
124
|
- 0
|
125
|
-
hash:
|
125
|
+
hash: -2427505316629763450
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
128
|
rubygems_version: 1.8.25
|