d3js-plugins-rails 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module D3js
2
2
  module Plugins
3
3
  module Rails
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -60,6 +60,7 @@ d3.geo.projection.js: \
60
60
  geo/projection/polyconic.js \
61
61
  geo/projection/robinson.js \
62
62
  geo/projection/satellite.js \
63
+ geo/projection/two-point-equidistant.js \
63
64
  geo/projection/van-der-grinten.js \
64
65
  geo/projection/van-der-grinten4.js \
65
66
  geo/projection/wagner4.js \
@@ -0,0 +1,63 @@
1
+ // TODO clip to ellipse
2
+ // TODO expose d3.geo.rotation?
3
+
4
+ function twoPointEquidistant(z0) {
5
+ if (!z0) return d3.geo.azimuthalEquidistant.raw;
6
+ var λa = -z0 / 2,
7
+ λb = -λa,
8
+ z02 = z0 * z0;
9
+ return function(λ, φ) {
10
+ var za = acos(Math.cos(φ) * Math.cos(λ - λa)),
11
+ zb = acos(Math.cos(φ) * Math.cos(λ - λb)),
12
+ ys = φ < 0 ? -1 : 1;
13
+ za *= za, zb *= zb;
14
+ return [
15
+ (za - zb) / (2 * z0),
16
+ ys * asqrt(4 * z02 * zb - (z02 - za + zb) * (z02 - za + zb)) / (2 * z0)
17
+ ];
18
+ };
19
+ }
20
+
21
+ function twoPointEquidistantProjection() {
22
+ var points = [[0, 0], [0, 0]],
23
+ m = projectionMutator(twoPointEquidistant),
24
+ p = m(0),
25
+ rotate = p.rotate;
26
+
27
+ delete p.rotate;
28
+
29
+ p.points = function(_) {
30
+ if (!arguments.length) return points;
31
+ points = _;
32
+
33
+ // Compute the origin as the midpoint of the two reference points.
34
+ // Rotate one of the reference points by the origin.
35
+ // Apply the spherical law of sines to compute γ rotation.
36
+ var origin = d3.geo.interpolate(_[0], _[1])(.5),
37
+ p = twoPointEquidistant_rotate(-origin[0] * radians, -origin[1] * radians, _[0][0] * radians, _[0][1] * radians),
38
+ b = acos(Math.cos(p[1]) * Math.cos(p[0])), // |[0, 0] - p|
39
+ c = (p[0] < 0 ? -1 : +1) * p[1], // |[p[0], 0] - p|
40
+ γ = asin(Math.sin(c) / Math.sin(b));
41
+
42
+ rotate.call(p, [-origin[0], -origin[1], -γ * degrees]);
43
+
44
+ return m(b * 2);
45
+ };
46
+
47
+ return p
48
+ }
49
+
50
+ function twoPointEquidistant_rotate(δλ, δφ, λ, φ) {
51
+ var cosδφ = Math.cos(δφ),
52
+ sinδφ = Math.sin(δφ),
53
+ cosφ = Math.cos(φ),
54
+ x = Math.cos(λ += δλ) * cosφ,
55
+ y = Math.sin(λ) * cosφ,
56
+ z = Math.sin(φ);
57
+ return [
58
+ Math.atan2(y, x * cosδφ - z * sinδφ),
59
+ asin(z * cosδφ + x * sinδφ)
60
+ ];
61
+ }
62
+
63
+ (d3.geo.twoPointEquidistant = twoPointEquidistantProjection).raw = twoPointEquidistant;
@@ -37,6 +37,18 @@ d3.hexbin = function() {
37
37
  return d3.values(binsById);
38
38
  }
39
39
 
40
+ function hexagon(radius) {
41
+ var x0 = 0, y0 = 0;
42
+ return d3_hexbinAngles.map(function(angle) {
43
+ var x1 = Math.sin(angle) * radius,
44
+ y1 = -Math.cos(angle) * radius,
45
+ dx = x1 - x0,
46
+ dy = y1 - y0;
47
+ x0 = x1, y0 = y1;
48
+ return [dx, dy];
49
+ });
50
+ }
51
+
40
52
  hexbin.x = function(_) {
41
53
  if (!arguments.length) return x;
42
54
  x = _;
@@ -50,20 +62,12 @@ d3.hexbin = function() {
50
62
  };
51
63
 
52
64
  hexbin.hexagon = function(radius) {
53
- var x0 = 0, y0 = 0;
54
65
  if (arguments.length < 1) radius = r;
55
- return "m" + d3_hexbinAngles.map(function(angle) {
56
- var x1 = Math.sin(angle) * radius,
57
- y1 = -Math.cos(angle) * radius,
58
- dx = x1 - x0,
59
- dy = y1 - y0;
60
- x0 = x1, y0 = y1;
61
- return [dx, dy];
62
- }).join("l") + "z";
66
+ return "m" + hexagon(radius).join("l") + "z";
63
67
  };
64
68
 
65
69
  hexbin.mesh = function() {
66
- var path = [], mesh = hexbin.hexagon().slice(0, 4).join("l");
70
+ var path = [], mesh = hexagon(r).slice(0, 4).join("l");
67
71
  for (var y = 0, odd = false; y < height + r; y += dy, odd = !odd) {
68
72
  for (var x = odd ? dx / 2 : 0; x < width; x += dx) {
69
73
  path.push("M", x, ",", y, "m", mesh);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: d3js-plugins-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-18 00:00:00.000000000 Z
12
+ date: 2013-01-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -145,6 +145,7 @@ files:
145
145
  - vendor/assets/javascripts/d3/plugins/geo/projection/test/robinson-test.js
146
146
  - vendor/assets/javascripts/d3/plugins/geo/projection/test/wagner6-test.js
147
147
  - vendor/assets/javascripts/d3/plugins/geo/projection/test/winkel3-test.js
148
+ - vendor/assets/javascripts/d3/plugins/geo/projection/two-point-equidistant.js
148
149
  - vendor/assets/javascripts/d3/plugins/geo/projection/van-der-grinten.js
149
150
  - vendor/assets/javascripts/d3/plugins/geo/projection/van-der-grinten4.js
150
151
  - vendor/assets/javascripts/d3/plugins/geo/projection/wagner4.js
@@ -211,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
212
  version: '0'
212
213
  requirements: []
213
214
  rubyforge_project:
214
- rubygems_version: 1.8.24
215
+ rubygems_version: 1.8.23
215
216
  signing_key:
216
217
  specification_version: 3
217
218
  summary: Gemified d3js-plugins asset for Rails