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 +4 -4
- data/.buildpacks +2 -0
- data/.gitignore +0 -1
- data/Gemfile +3 -0
- data/Gemfile.lock +26 -0
- data/Procfile +1 -0
- data/config.ru +8 -2
- data/lib/snapa.rb +10 -15
- data/lib/snapa/version.rb +1 -1
- data/public/favicon.ico +0 -0
- data/public/map.html +25 -18
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 246b9ac64748bb2d3558fc97f747f0643d44338e
|
4
|
+
data.tar.gz: 884e28a1fe988ed530b6fae5645081d0f81ee051
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf6e5d6b3b8bbad94e662b7aa555e5dd7175edd576365cb3a351d1bdfdfe2eda628a310e03066d28cdb9b0af6cfcfad645d9b54c8aa461170936a372e042ca50
|
7
|
+
data.tar.gz: 9bdaaa489cba4b16d04969b00a8e52cb257d20d0b52462958799117a7bb18c6eda20ac53d2dfff876f6f7f001365ad318d087807809a3c675e7d824ee476fc7b
|
data/.buildpacks
ADDED
data/.gitignore
CHANGED
data/Gemfile
CHANGED
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
|
-
|
2
|
-
|
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
|
-
|
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(
|
23
|
-
[@root
|
15
|
+
def url(request)
|
16
|
+
[@root, request.query_string].join('?')
|
24
17
|
end
|
25
18
|
|
26
|
-
def build(
|
27
|
-
system [cmd, script, "'#{url(
|
19
|
+
def build(request)
|
20
|
+
system [cmd, script, "'#{url(request)}'", "'#{@path}'"].join(' ')
|
28
21
|
end
|
29
22
|
|
30
|
-
def path(
|
31
|
-
@path ||=
|
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
|
-
|
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
data/public/favicon.ico
ADDED
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:
|
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')
|
36
|
-
|
37
|
-
|
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
|
-
.
|
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
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
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.
|
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-
|
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
|