Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xijo/clumpy
Put points into clusters
https://github.com/xijo/clumpy
Last synced: about 2 months ago
JSON representation
Put points into clusters
- Host: GitHub
- URL: https://github.com/xijo/clumpy
- Owner: xijo
- License: wtfpl
- Created: 2013-03-11T23:15:23.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2017-04-06T09:22:22.000Z (over 7 years ago)
- Last Synced: 2024-04-24T20:14:54.286Z (8 months ago)
- Language: Ruby
- Size: 25.4 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Clumpy
Cluster markers, geocoordinates or anything that responds to `latitude` and `longitude`.
## Why serverside clustering
Of cause there are lots of libs to cluster large amounts of markers in the frontend, but the expensive part is to
transfer all those markers to the client. In my case it was the difference between sending 10_000 markers - or 20.## Installation
As part of the Gemfile or by hand, nothing unusual here.
## Usage
Clumpy takes points, typically geocoordinates, and puts them together into clusters.
It requires the given points to be ruby objects, responding to `#latitude` and `#longitude` methods.
```ruby
require 'ostruct'Point = Struct.new(:latitude, :longitude)
points = [
Point.new(latitude: 101, longitude: 11),
Point.new(latitude: 102, longitude: 12),
Point.new(latitude: 201, longitude: 21)
]
```Now those points may be clustered easily:
```ruby
builder = Clumpy::Builder.new(points)
clusters = builder.clustercluster = clusters.first
cluster.size # => 2
cluster.latitude # => 101.5
cluster.longitude # => 11.5
cluster.points # => points 1 and 2 from above
cluster.bounds # => represents the area this cluster covers
cluster.to_json # => well, json representation of that.
```Optionally you could add a `precision: :high` option to the builder initialization to move the cluster a little bit after all points were assigned.
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request## License
WTFPL - What The Fuck You Want To Public License
Read more at [http://www.wtfpl.net](http://www.wtfpl.net)