clumpy 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +29 -10
- data/lib/clumpy/builder.rb +6 -6
- data/lib/clumpy/version.rb +1 -1
- data/spec/builder_spec.rb +10 -0
- metadata +15 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2c9b3590d403a8d17022234a9c010d77afb868ba
|
4
|
+
data.tar.gz: 2c6c5d30ecaab4b5e7b9860da3503a26cd7e4376
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa62267024945a10872876e7051bc1c7d5323c7fcb0434cb05255366e59e8ba639e5a96845c090106475f90bd576c584728c5641c5d9a6cc479ff15cd13b6d51
|
7
|
+
data.tar.gz: 86aab5b639351c14244a2ec557e5f387efabbbefeff727131c615035e6290284ce9e9bcaf93c8cc9a7f1b6475807ff37bbcb4b0b1bdc317b29db19209d977de1
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
clumpy
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0
|
data/README.md
CHANGED
@@ -1,30 +1,49 @@
|
|
1
1
|
# Clumpy
|
2
2
|
|
3
|
-
|
3
|
+
Cluster markers, geocoordinates or anything that responds to `latitude` and `longitude`.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Why serverside clustering
|
6
6
|
|
7
|
-
|
7
|
+
Of cause there are lots of libs to cluster large amounts of markers in the frontend, but the expensive part is to
|
8
|
+
transfer all those markers to the client. In my case it was the difference between sending 10_000 markers - or 20.
|
8
9
|
|
9
|
-
|
10
|
+
## Installation
|
10
11
|
|
11
|
-
|
12
|
+
As part of the Gemfile or by hand, nothing unusual here.
|
12
13
|
|
13
|
-
|
14
|
+
## Usage
|
14
15
|
|
15
|
-
|
16
|
+
Clumpy takes points, typically geocoordinates, and puts them together into clusters.
|
16
17
|
|
17
|
-
|
18
|
+
It requires the given points to be ruby objects, responding to `latitude` and `longitude` methods.
|
18
19
|
|
19
|
-
|
20
|
+
```ruby
|
21
|
+
require 'ostruct'
|
22
|
+
|
23
|
+
Point = Struct.new(:latitude, :longitude)
|
24
|
+
points = [
|
25
|
+
Point.new(latitude: 101, longitude: 11),
|
26
|
+
Point.new(latitude: 102, longitude: 12),
|
27
|
+
Point.new(latitude: 201, longitude: 21)
|
28
|
+
]
|
29
|
+
```
|
20
30
|
|
21
|
-
|
31
|
+
Now those points may be clustered easily:
|
22
32
|
|
23
33
|
```ruby
|
24
34
|
builder = Clumpy::Builder.new(points)
|
25
35
|
clusters = builder.cluster
|
36
|
+
|
37
|
+
cluster = clusters.first
|
38
|
+
cluster.size # => 2
|
39
|
+
cluster.latitude # => 101.5
|
40
|
+
cluster.longitude # => 11.5
|
41
|
+
cluster.points # => points 1 and 2 from above
|
42
|
+
cluster.bounds # => represents the area this cluster covers
|
43
|
+
cluster.to_json # => well, json representation of that.
|
26
44
|
```
|
27
45
|
|
46
|
+
|
28
47
|
Optionally you could add a `precision: :high` option to the builder initialization to move the cluster a little bit after all points were assigned.
|
29
48
|
|
30
49
|
## Contributing
|
data/lib/clumpy/builder.rb
CHANGED
@@ -2,14 +2,14 @@ module Clumpy
|
|
2
2
|
class Builder
|
3
3
|
MAX_LATITUDE_DISTANCE = 170.05115
|
4
4
|
MAX_LONGITUDE_DISTANCE = 360
|
5
|
-
DISTANCE_MODIFIER = 5
|
6
5
|
|
7
6
|
attr_accessor :points, :options, :clusters
|
8
7
|
|
9
8
|
def initialize(points, options = {})
|
10
|
-
@points
|
11
|
-
@options
|
12
|
-
@
|
9
|
+
@points = points
|
10
|
+
@options = options || {}
|
11
|
+
@distance_modifier = options.fetch(:distance_modifier) { 5 }
|
12
|
+
@clusters = []
|
13
13
|
end
|
14
14
|
|
15
15
|
# Clusters the given points
|
@@ -43,11 +43,11 @@ module Clumpy
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def cluster_latitude_distance
|
46
|
-
latitude_distance /
|
46
|
+
latitude_distance / @distance_modifier
|
47
47
|
end
|
48
48
|
|
49
49
|
def cluster_longitude_distance
|
50
|
-
longitude_distance / (
|
50
|
+
longitude_distance / (@distance_modifier * 2)
|
51
51
|
end
|
52
52
|
|
53
53
|
def cluster_options
|
data/lib/clumpy/version.rb
CHANGED
data/spec/builder_spec.rb
CHANGED
@@ -14,6 +14,16 @@ describe Clumpy::Builder do
|
|
14
14
|
builder.options.should eq({ foo: :bar })
|
15
15
|
end
|
16
16
|
|
17
|
+
it "initializes the distance_modifier is none was given" do
|
18
|
+
builder = Clumpy::Builder.new([])
|
19
|
+
builder.instance_variable_get(:@distance_modifier).should_not be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'takes the given distance modifier' do
|
23
|
+
builder = Clumpy::Builder.new([], distance_modifier: 12)
|
24
|
+
builder.instance_variable_get(:@distance_modifier).should eq 12
|
25
|
+
end
|
26
|
+
|
17
27
|
context "#cluster" do
|
18
28
|
it "creates clusters from points" do
|
19
29
|
clusters = builder.cluster
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clumpy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Johannes Opper
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,49 +27,43 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: simplecov
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: Cluster points e.g. for a map
|
@@ -83,6 +74,8 @@ extensions: []
|
|
83
74
|
extra_rdoc_files: []
|
84
75
|
files:
|
85
76
|
- .gitignore
|
77
|
+
- .ruby-gemset
|
78
|
+
- .ruby-version
|
86
79
|
- Gemfile
|
87
80
|
- LICENSE.txt
|
88
81
|
- README.md
|
@@ -101,33 +94,26 @@ files:
|
|
101
94
|
homepage: http://github.com/xijo/clumpy
|
102
95
|
licenses:
|
103
96
|
- WTFPL
|
97
|
+
metadata: {}
|
104
98
|
post_install_message:
|
105
99
|
rdoc_options: []
|
106
100
|
require_paths:
|
107
101
|
- lib
|
108
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
-
none: false
|
110
103
|
requirements:
|
111
|
-
- -
|
104
|
+
- - '>='
|
112
105
|
- !ruby/object:Gem::Version
|
113
106
|
version: '0'
|
114
|
-
segments:
|
115
|
-
- 0
|
116
|
-
hash: -2427505316629763450
|
117
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
-
none: false
|
119
108
|
requirements:
|
120
|
-
- -
|
109
|
+
- - '>='
|
121
110
|
- !ruby/object:Gem::Version
|
122
111
|
version: '0'
|
123
|
-
segments:
|
124
|
-
- 0
|
125
|
-
hash: -2427505316629763450
|
126
112
|
requirements: []
|
127
113
|
rubyforge_project:
|
128
|
-
rubygems_version: 1.
|
114
|
+
rubygems_version: 2.1.11
|
129
115
|
signing_key:
|
130
|
-
specification_version:
|
116
|
+
specification_version: 4
|
131
117
|
summary: Cluster a bunch of points
|
132
118
|
test_files:
|
133
119
|
- spec/builder_spec.rb
|