clumpy 1.0.0 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c54e552fb799c83627510c3743f36d36682a955f
4
- data.tar.gz: b153298fb72ae0ad278fce078aa85a52c9b18f5a
3
+ metadata.gz: 08e7eff2f7ea8e5cbfdfaeaf08844d831bb331d0
4
+ data.tar.gz: 906992f3fb8f0807b8f8e4a7637c5704ff56615e
5
5
  SHA512:
6
- metadata.gz: 41ce0b359bdef855b1674e50eebb1798be6f5245446b8686a4bb8f7deb1e9a4311a33fbb3892b060297698591059686cd34bf465ea761c783d0e6797402a5fb3
7
- data.tar.gz: afa4c35a0d83673e7de4daa6bd7025d257c9707b40a94356236d890b3084baa43f1bb9580f3e741911cefcaa2ca20ac9dab6aaa526b7e86ce66b7a25b6445434
6
+ metadata.gz: 1dd17137418eebd0270b3f8f8f97b99c2b98b6d574d50b54462c37b952f070c6a085a63e69337187736d07f3febe846955d3223a7f01e306c890591ccd3cc6af
7
+ data.tar.gz: 72ed5212c54be152b171a9067a57c3df44f8b8c1c3af54a6ac49aa22adc472dc0c89a727d32d9680ea1a7e4249d4c2becd1f4bcf5fcb57b6fe485371ce876ac9
@@ -1 +1 @@
1
- 2.1.4
1
+ 2.2.3
@@ -0,0 +1,13 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - 2.1.5
6
+ - 2.2.0
7
+
8
+ script: "bundle exec rake spec"
9
+
10
+ notifications:
11
+ disabled: false
12
+ recipients:
13
+ - johannes.opper@gmail.com
@@ -1,3 +1,8 @@
1
+ # 1.1.0
2
+ ## 2015-10-08
3
+ - Respect map aspect ratio
4
+ - Shrink cluster bounds to improve zooming behavior
5
+
1
6
  # 1.0.0
2
7
  ## 2014-10-30
3
8
  - Remove hit extensions, please provide a matching interface for hits by your own.
@@ -1,9 +1,10 @@
1
1
  module Clumpy
2
2
  class Bounds
3
- def initialize(latitude, longitude, side_length)
4
- side_length ||= 10
5
- @latitude = (latitude - side_length)..(latitude + side_length)
6
- @longitude = (longitude - side_length*2)..(longitude + side_length*2)
3
+ def initialize(latitude, longitude, width, length)
4
+ l = length / 2
5
+ w = width / 2
6
+ @latitude = (latitude - l)..(latitude + l)
7
+ @longitude = (longitude - w)..(longitude + w)
7
8
  end
8
9
 
9
10
  attr_reader :latitude
@@ -42,15 +42,20 @@ module Clumpy
42
42
  clusters.find { |c| c.contains?(point) }
43
43
  end
44
44
 
45
- def cluster_side_length
46
- @cluster_size ||= (latitude_distance + longitude_distance) / @distance_modifier
45
+ def cluster_width
46
+ @cluster_width ||= longitude_distance / @distance_modifier
47
+ end
48
+
49
+ def cluster_length
50
+ @cluster_length ||= latitude_distance / @distance_modifier
47
51
  end
48
52
 
49
53
  def cluster_options
50
54
  {
51
55
  values_threshold: options[:values_threshold],
52
56
  include_values: options[:include_values],
53
- side_length: cluster_side_length
57
+ width: cluster_width,
58
+ length: cluster_length,
54
59
  }
55
60
  end
56
61
 
@@ -8,7 +8,7 @@ module Clumpy
8
8
  @points = [point]
9
9
  @options = options
10
10
 
11
- @bounds = Bounds.new(@latitude, @longitude, options[:side_length])
11
+ @bounds = Bounds.new(@latitude, @longitude, options[:width], options[:length])
12
12
  end
13
13
 
14
14
  def contains?(point)
@@ -22,11 +22,22 @@ module Clumpy
22
22
  end
23
23
 
24
24
  def as_json(*)
25
+ bounds = {
26
+ northeast: {
27
+ latitude: @points.map(&:latitude).max,
28
+ longitude: @points.map(&:longitude).max,
29
+ },
30
+ southwest: {
31
+ latitude: @points.map(&:latitude).min,
32
+ longitude: @points.map(&:longitude).min,
33
+ }
34
+ }
35
+
25
36
  {
26
37
  latitude: latitude,
27
38
  longitude: longitude,
28
39
  size: @points.size,
29
- bounds: @bounds.as_json,
40
+ bounds: bounds,
30
41
  values: value_list,
31
42
  }
32
43
  end
@@ -1,3 +1,3 @@
1
1
  module Clumpy
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -10,66 +10,66 @@ describe Clumpy::Builder do
10
10
 
11
11
  it "takes points and options" do
12
12
  builder = Clumpy::Builder.new(points, { foo: :bar })
13
- builder.points.should eq points
14
- builder.options.should eq({ foo: :bar })
13
+ expect(builder.points).to eq points
14
+ expect(builder.options).to eq({ foo: :bar })
15
15
  end
16
16
 
17
17
  it "initializes the distance_modifier is none was given" do
18
18
  builder = Clumpy::Builder.new([])
19
- builder.instance_variable_get(:@distance_modifier).should_not be_nil
19
+ expect(builder.instance_variable_get(:@distance_modifier)).not_to be_nil
20
20
  end
21
21
 
22
22
  it 'takes the given distance modifier' do
23
23
  builder = Clumpy::Builder.new([], distance_modifier: 12)
24
- builder.instance_variable_get(:@distance_modifier).should eq 12
24
+ expect(builder.instance_variable_get(:@distance_modifier)).to eq 12
25
25
  end
26
26
 
27
27
  context "#cluster" do
28
28
  it "creates clusters from points" do
29
29
  clusters = builder.cluster
30
- clusters.size.should eq 2
31
- clusters.first.points.should eq [point1, point2]
32
- clusters.last.points.should eq [point3]
30
+ expect(clusters.size).to eq 2
31
+ expect(clusters.first.points).to eq [point1, point2]
32
+ expect(clusters.last.points).to eq [point3]
33
33
  end
34
34
  end
35
35
 
36
36
  it "passes the values threshold through to the cluster" do
37
37
  builder = Clumpy::Builder.new([point1], values_threshold: 100, include_values: true)
38
- builder.cluster_options.should eq({ values_threshold: 100, include_values: true, side_length: 33.128196875 })
38
+ expect(builder.cluster_options).to eq({ values_threshold: 100, include_values: true, width: 22, length: 10.628196875 })
39
39
  clusters = builder.cluster
40
- clusters.first.instance_variable_get(:@options).should eq builder.cluster_options
40
+ expect(clusters.first.instance_variable_get(:@options)).to eq builder.cluster_options
41
41
  end
42
42
 
43
43
  context "#add_to_cluster" do
44
44
  it "creates a new cluster if there is no matching" do
45
- builder.clusters.should be_empty
45
+ expect(builder.clusters).to be_empty
46
46
  builder.add_to_cluster(point1)
47
- builder.clusters.size.should eq 1
47
+ expect(builder.clusters.size).to eq 1
48
48
  end
49
49
 
50
50
  it "will not create a cluster if the given value is not a true point" do
51
- builder.clusters.should be_empty
51
+ expect(builder.clusters).to be_empty
52
52
  builder.add_to_cluster(:foo)
53
- builder.clusters.should be_empty
53
+ expect(builder.clusters).to be_empty
54
54
  end
55
55
 
56
56
  it "appends markers to a existing cluster if they match" do
57
57
  builder.clusters << Clumpy::Cluster.new(point1, builder.cluster_options)
58
- builder.clusters.size.should eq 1
59
- builder.clusters.first.points.size.should eq 1
58
+ expect(builder.clusters.size).to eq 1
59
+ expect(builder.clusters.first.points.size).to eq 1
60
60
  builder.add_to_cluster(point2)
61
- builder.clusters.size.should eq 1
62
- builder.clusters.first.points.size.should eq 2
61
+ expect(builder.clusters.size).to eq 1
62
+ expect(builder.clusters.first.points.size).to eq 2
63
63
  end
64
64
  end
65
65
 
66
66
  it "calculates the latitude distance" do
67
- builder.latitude_distance.should eq Clumpy::Builder::MAX_LATITUDE_DISTANCE
67
+ expect(builder.latitude_distance).to eq Clumpy::Builder::MAX_LATITUDE_DISTANCE
68
68
  builder.options = { nelat: -30, swlat: 40 }
69
- builder.latitude_distance.should eq 70
69
+ expect(builder.latitude_distance).to eq 70
70
70
  builder.options = { nelat: -30, swlat: -35 }
71
- builder.latitude_distance.should eq 5
71
+ expect(builder.latitude_distance).to eq 5
72
72
  builder.options = { nelat: 20, swlat: 35 }
73
- builder.latitude_distance.should eq 15
73
+ expect(builder.latitude_distance).to eq 15
74
74
  end
75
75
  end
@@ -3,58 +3,58 @@ 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, side_length: 10) }
6
+ let(:cluster) { Clumpy::Cluster.new(point, width: 20, length: 10) }
7
7
 
8
8
  it "has a nicish to_s representation" do
9
- cluster.to_s.should include '# size: 1'
9
+ expect(cluster.to_s).to include '# size: 1'
10
10
  end
11
11
 
12
12
  it "has a json represtation as well" do
13
- cluster.as_json.should have_key :size
14
- cluster.as_json.should have_key :latitude
15
- cluster.as_json.should have_key :longitude
16
- cluster.as_json.should have_key :bounds
13
+ expect(cluster.as_json).to have_key :size
14
+ expect(cluster.as_json).to have_key :latitude
15
+ expect(cluster.as_json).to have_key :longitude
16
+ expect(cluster.as_json).to have_key :bounds
17
17
  end
18
18
 
19
19
  context "#reposition" do
20
20
  it "calculates new latitude and longitude values" do
21
21
  cluster.points << other_point
22
22
  cluster.reposition
23
- cluster.latitude.should eq (15.0+40.0)/2.0
24
- cluster.longitude.should eq (20.0+40.0)/2.0
23
+ expect(cluster.latitude).to eq (15.0+40.0)/2.0
24
+ expect(cluster.longitude).to eq (20.0+40.0)/2.0
25
25
  end
26
26
  end
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, values_threshold: 1)
30
+ cluster = Clumpy::Cluster.new(point, values_threshold: 1, width: 20, length: 10)
31
31
  cluster.points << other_point
32
- cluster.value_list.should eq []
32
+ expect(cluster.value_list).to 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, values_threshold: 1)
37
- cluster.value_list.should eq [point]
36
+ cluster = Clumpy::Cluster.new(point, values_threshold: 1, width: 20, length: 10)
37
+ expect(cluster.value_list).to 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, values_threshold: 0, include_values: true)
42
- cluster.value_list.should eq [point]
41
+ cluster = Clumpy::Cluster.new(point, values_threshold: 0, include_values: true, width: 20, length: 10)
42
+ expect(cluster.value_list).to 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, values_threshold: 10, include_values: false)
47
- cluster.value_list.should eq []
46
+ cluster = Clumpy::Cluster.new(point, values_threshold: 10, include_values: false, width: 20, length: 10)
47
+ expect(cluster.value_list).to eq []
48
48
  end
49
49
  end
50
50
 
51
51
  context "#contains" do
52
52
  it "returns true if the given point is within the bounds" do
53
- cluster.contains?(point).should eq true
53
+ expect(cluster.contains?(point)).to eq true
54
54
  end
55
55
 
56
56
  it "returns false for a points that isn't contained" do
57
- cluster.contains?(other_point).should eq false
57
+ expect(cluster.contains?(other_point)).to eq false
58
58
  end
59
59
  end
60
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clumpy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Opper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-30 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -77,6 +77,7 @@ files:
77
77
  - ".rspec"
78
78
  - ".ruby-gemset"
79
79
  - ".ruby-version"
80
+ - ".travis.yml"
80
81
  - CHANGELOG.md
81
82
  - Gemfile
82
83
  - LICENSE.txt
@@ -112,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
113
  version: '0'
113
114
  requirements: []
114
115
  rubyforge_project:
115
- rubygems_version: 2.2.2
116
+ rubygems_version: 2.4.5.1
116
117
  signing_key:
117
118
  specification_version: 4
118
119
  summary: Cluster a bunch of points
@@ -120,3 +121,4 @@ test_files:
120
121
  - spec/builder_spec.rb
121
122
  - spec/cluster_behavior_spec.rb
122
123
  - spec/spec_helper.rb
124
+ has_rdoc: