snapa 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77360d09b9abb1525c943151e0bfa58f3920311e
4
- data.tar.gz: 260ce2e0c9ef71ec8456344b95ed8243ef2e760c
3
+ metadata.gz: 246b9ac64748bb2d3558fc97f747f0643d44338e
4
+ data.tar.gz: 884e28a1fe988ed530b6fae5645081d0f81ee051
5
5
  SHA512:
6
- metadata.gz: 12be7dc97c63d0d7ab31b10c36e254f8db982cbdf9ed1f2b636d8c3fccfb330f0d772c9f5209617c704178c5c09330695b3992849afe01d801fa3542615d1910
7
- data.tar.gz: 99c7b6b2959403c6400d7ba5bf3a2f5ea98a6db48d95fbbdee50042ea6a19ca61e1fd95dfc6750133d631c96cbf868c36357bc9aa7ee8b349459f1e1956b1192
6
+ metadata.gz: bf6e5d6b3b8bbad94e662b7aa555e5dd7175edd576365cb3a351d1bdfdfe2eda628a310e03066d28cdb9b0af6cfcfad645d9b54c8aa461170936a372e042ca50
7
+ data.tar.gz: 9bdaaa489cba4b16d04969b00a8e52cb257d20d0b52462958799117a7bb18c6eda20ac53d2dfff876f6f7f001365ad318d087807809a3c675e7d824ee476fc7b
data/.buildpacks ADDED
@@ -0,0 +1,2 @@
1
+ https://github.com/heroku/heroku-buildpack-ruby.git
2
+ https://github.com/stomita/heroku-buildpack-phantomjs.git
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
1
  source 'https://rubygems.org'
2
+ ruby '2.0.0'
2
3
 
3
4
  # Specify your gem's dependencies in snapa.gemspec
4
5
  gemspec
6
+
7
+ gem 'thin'
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ snapa (0.0.2)
5
+ rack
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ daemons (1.1.9)
11
+ eventmachine (1.0.3)
12
+ rack (1.5.2)
13
+ rake (10.1.0)
14
+ thin (1.5.1)
15
+ daemons (>= 1.0.9)
16
+ eventmachine (>= 0.12.6)
17
+ rack (>= 1.0.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.3)
24
+ rake
25
+ snapa!
26
+ thin
data/Procfile ADDED
@@ -0,0 +1 @@
1
+ web: bundle exec rackup -p $PORT
data/config.ru CHANGED
@@ -1,2 +1,8 @@
1
- require ::File.expand_path('../lib/snapa', __FILE__)
2
- run Snapa::File.new(:map)
1
+ $:.unshift ::File.expand_path('../lib', __FILE__)
2
+
3
+ use Rack::Static,
4
+ :urls => ['/countries.json', '/d3.v3.min.js', '/favicon.ico', '/map.html', '/topojson.v1.min.js'],
5
+ :root => 'public'
6
+
7
+ require 'snapa'
8
+ run Snapa::File.new('public/map.html')
data/lib/snapa.rb CHANGED
@@ -3,36 +3,31 @@ require 'rack/file'
3
3
 
4
4
  module Snapa
5
5
  class File < Rack::File
6
- def query_string(env)
7
- env["QUERY_STRING"].to_s
8
- end
9
6
 
10
7
  def cmd
11
8
  'phantomjs'
12
9
  end
13
10
 
14
11
  def script
15
- ::File.expand_path('../snapa.js', __FILE__)
16
- end
17
-
18
- def map
19
- ::File.expand_path('../../public/map.html', __FILE__)
12
+ F.expand_path('../snapa.js', __FILE__)
20
13
  end
21
14
 
22
- def url(env)
23
- [@root === :map ? map : @root, query_string(env)].join('?')
15
+ def url(request)
16
+ [@root, request.query_string].join('?')
24
17
  end
25
18
 
26
- def build(env)
27
- system [cmd, script, "'#{url(env)}'", "'#{@path}'"].join(' ')
19
+ def build(request)
20
+ system [cmd, script, "'#{url(request)}'", "'#{@path}'"].join(' ')
28
21
  end
29
22
 
30
- def path(env)
31
- @path ||= ::File.join('tmp', query_string(env) + '.png')
23
+ def path(request)
24
+ @path ||= F.join('/tmp/snapa', request.query_string + '.png')
32
25
  end
33
26
 
34
27
  def _call(env)
35
- build(env) unless F.file?(path(env))
28
+ request = ::Rack::Request.new(env)
29
+
30
+ build(request) unless F.file?(path(request))
36
31
 
37
32
  serving(env)
38
33
  end
data/lib/snapa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Snapa
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
Binary file
data/public/map.html CHANGED
@@ -9,7 +9,7 @@ body {
9
9
  .subunit {
10
10
  fill: #D7D7D7;
11
11
  stroke: #F2F2F2;
12
- stroke-width: 2;
12
+ stroke-width: 1.5;
13
13
  }
14
14
  .subunit.highlight {
15
15
  fill: #658436;
@@ -32,9 +32,10 @@ function getParameterByName(name) {
32
32
  var countries = (getParameterByName('c') || 'TZ').toUpperCase().split(','),
33
33
  width = getParameterByName('w') || 380,
34
34
  height = getParameterByName('h') || 230,
35
- rotation = getParameterByName('r') || 0,
36
- percent = getParameterByName('p') || .95,
37
- maxScale = getParameterByName('m') || 300;
35
+ rotation = getParameterByName('r').split(','),
36
+ scale = getParameterByName('s'),
37
+ percent = getParameterByName('p') || .80,
38
+ highlight;
38
39
 
39
40
  var svg = d3.select("body").append("svg")
40
41
  .attr("width", width)
@@ -42,33 +43,39 @@ var svg = d3.select("body").append("svg")
42
43
 
43
44
  var projection = d3.geo.mercator()
44
45
  .scale(1)
45
- .rotate(rotation)
46
- .translate([0, 0]);
46
+ .translate([width / 2, height / 2]);
47
47
 
48
48
  var path = d3.geo.path()
49
49
  .projection(projection);
50
50
 
51
51
  d3.json("countries.json", function(error, world) {
52
- var bounds = [[Number.MAX_VALUE, Number.MAX_VALUE], [Number.MIN_VALUE, Number.MIN_VALUE]],
53
- features = topojson.feature(world, world.objects.countries).features;
52
+ var features = topojson.feature(world, world.objects.countries).features;
54
53
 
55
54
  for (var i = 0; i < features.length; i++) {
56
55
  if (countries.indexOf(features[i].id) !== -1) {
57
- var b = path.bounds(features[i]);
58
- bounds = [
59
- [Math.min(bounds[0][0], b[0][0]), Math.min(bounds[0][1], b[0][1])],
60
- [Math.max(bounds[1][0], b[1][0]), Math.max(bounds[1][1], b[1][1])]
61
- ];
56
+ if (highlight === undefined) {
57
+ highlight = JSON.parse(JSON.stringify(features[i]));
58
+ } else {
59
+ highlight.geometry.coordinates = d3.merge([highlight.geometry.coordinates, features[i].geometry.coordinates])
60
+ }
62
61
  }
63
62
  }
64
63
 
65
- var scale = percent / Math.max((bounds[1][0] - bounds[0][0]) / width, (bounds[1][1] - bounds[0][1]) / height),
66
- scale = Math.min(scale, maxScale),
67
- translate = [(width - scale * (bounds[1][0] + bounds[0][0])) / 2, (height - scale * (bounds[1][1] + bounds[0][1])) / 2];
64
+ if (rotation[0] === '') {
65
+ var centroid = d3.geo.centroid(highlight);
66
+ rotation = [-centroid[0], -centroid[1]]
67
+ }
68
+
69
+ projection
70
+ .rotate(rotation);
71
+
72
+ if (scale === '') {
73
+ var bounds = path.bounds(highlight);
74
+ scale = percent / Math.max((bounds[1][0] - bounds[0][0]) / width, (bounds[1][1] - bounds[0][1]) / height);
75
+ }
68
76
 
69
77
  projection
70
- .scale(scale)
71
- .translate(translate);
78
+ .scale(scale);
72
79
 
73
80
  svg.selectAll("path")
74
81
  .data(features)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Tillman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-07 00:00:00.000000000 Z
11
+ date: 2013-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -59,9 +59,12 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - .buildpacks
62
63
  - .gitignore
63
64
  - Gemfile
65
+ - Gemfile.lock
64
66
  - LICENSE.txt
67
+ - Procfile
65
68
  - README.md
66
69
  - Rakefile
67
70
  - config.ru
@@ -70,6 +73,7 @@ files:
70
73
  - lib/snapa/version.rb
71
74
  - public/countries.json
72
75
  - public/d3.v3.min.js
76
+ - public/favicon.ico
73
77
  - public/map.html
74
78
  - public/topojson.v1.min.js
75
79
  - snapa.gemspec