snapa 0.0.5 → 0.0.7

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: e782328109d352dfaddf33fb93c7896200058afd
4
- data.tar.gz: f8ece8508d685e8e59782c90bb5a9fa4e0fb98be
3
+ metadata.gz: 4b1a3768a78b868e91084f933b59e48436ff6c91
4
+ data.tar.gz: f44e8582e8efb09956c0bd184c52ed19b1917c3b
5
5
  SHA512:
6
- metadata.gz: a3955e764eb1e524191beac8b5eb1bb89277ec71a3b4cbfa7431bc65b0d154e2bb02861047c4e3f59d217d7a7ce9b7897f1c8d95e83721fa21395923bdb7bfeb
7
- data.tar.gz: f3820c4d9e0a72ddd15525b4541c52da8a63dcf1ac47f1f88f0c601e4ff0fd1a9119c0a8599491b11a1245ee29e0e2fc28add8d294c709c60633cd691d38278c
6
+ metadata.gz: 87d9d709b8338f8a604c06d4ab4bb7b2f600a4d7f3f9ef9974791fafcaa3f918c44d5c97541af51a848ccefe107a798066e8729c5358733dc98ba68d6058989d
7
+ data.tar.gz: a9b9818d79b03e81dfbbd9e5d6c936281fe47b7a7081308ba136eb74022dd0a1c0fb8b499a3a9cab1a8184684e5b82011754216f8565ef0c589855884a9fc561
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- snapa (0.0.2)
4
+ snapa (0.0.6)
5
5
  rack
6
6
 
7
7
  GEM
@@ -1,6 +1,6 @@
1
1
  require 'snapa/version'
2
2
  require 'rack/file'
3
- require 'digest'
3
+ require 'digest/md5'
4
4
 
5
5
  module Snapa
6
6
  class File < Rack::File
@@ -22,7 +22,7 @@ module Snapa
22
22
  end
23
23
 
24
24
  def path(request)
25
- @path ||= F.join('/tmp/snapa', ::Digest.hexencode(request.query_string) + '.png')
25
+ @path ||= F.join('/tmp/snapa', ::Digest::MD5.hexdigest(request.query_string) + '.png')
26
26
  end
27
27
 
28
28
  def _call(env)
@@ -1,3 +1,3 @@
1
1
  module Snapa
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -32,6 +32,14 @@ function getParameterByName(name) {
32
32
  return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
33
33
  }
34
34
 
35
+ function mergeGeometry(a, b) {
36
+ if (b.type === 'MultiPolygon') {
37
+ a.coordinates = a.coordinates.concat(b.coordinates)
38
+ } else {
39
+ a.coordinates.push(b.coordinates)
40
+ }
41
+ }
42
+
35
43
  var countries = (getParameterByName('c') || 'TZ').toUpperCase().split(','),
36
44
  width = getParameterByName('w') || 400,
37
45
  height = getParameterByName('h') || 230,
@@ -51,25 +59,17 @@ var path = d3.geo.path()
51
59
  .projection(projection);
52
60
 
53
61
  d3.json("countries.json", function(error, world) {
54
- var features = topojson.feature(world, world.objects.countries).features;
62
+ var features = topojson.feature(world, world.objects.countries).features,
63
+ highlight = {type: 'Feature', geometry: {type: 'MultiPolygon', coordinates: []}};
55
64
 
56
65
  for (var i = 0; i < features.length; i++) {
57
66
  if (countries.indexOf(features[i].id) !== -1) {
58
- if (highlight === undefined) {
59
- highlight = JSON.parse(JSON.stringify(features[i]));
60
- } else {
61
- highlight.geometry.coordinates = d3.merge([highlight.geometry.coordinates, features[i].geometry.coordinates])
62
- }
67
+ mergeGeometry(highlight.geometry, features[i].geometry)
63
68
  }
64
69
  }
65
70
 
66
- if (highlight === undefined) {
67
- projection
68
- .scale(50)
69
- .translate([width / 2], [height / 2]);
70
-
71
- } else {
72
- var centroid = d3.geo.centroid(highlight);
71
+ var centroid = d3.geo.centroid(highlight);
72
+ if (!isNaN(centroid[0])) {
73
73
  if (rotation[0] === '') {
74
74
  rotation = [-centroid[0], 0, 0];
75
75
  }
@@ -86,6 +86,12 @@ d3.json("countries.json", function(error, world) {
86
86
  projection
87
87
  .scale(scale)
88
88
  .translate([width / 2, (height / 2) + centroid[1] * 2.77]);
89
+
90
+ } else {
91
+
92
+ projection
93
+ .scale(50)
94
+ .translate([width / 2, height / 2]);
89
95
  }
90
96
 
91
97
  svg.selectAll("path")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Tillman