d3js-plugins-rails 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
1
  module D3js
2
2
  module Plugins
3
3
  module Rails
4
- VERSION = "0.0.3"
5
- D3_PLUGINS_VERSION = "c690548cb4173f5edf312133f364e949482c3821"
4
+ VERSION = "0.0.4"
5
+ D3_PLUGINS_VERSION = "a3c809c32282be9980f24a1c7a08f7be6a3460c7"
6
6
  end
7
7
  end
8
8
  end
@@ -11,6 +11,7 @@ d3.geo.projection.js: \
11
11
  geo/projection/projection.js \
12
12
  geo/projection/parallel1.js \
13
13
  geo/projection/parallel2.js \
14
+ geo/projection/quincuncial.js \
14
15
  geo/projection/interrupt.js \
15
16
  geo/projection/elliptic.js \
16
17
  geo/projection/aitoff.js \
@@ -2,76 +2,76 @@
2
2
 
3
3
  Projections:
4
4
 
5
- * d3.geo.aitoff - [Aitoff](http://bl.ocks.org/3682698)
6
- * d3.geo.albers - [Albers equal-area conic](http://bl.ocks.org/3734308)
7
- * d3.geo.armadillo - [Armadillo](http://bl.ocks.org/4463127)
8
- * d3.geo.august - [August conformal](http://bl.ocks.org/3797581)
9
- * d3.geo.azimuthalEqualArea - [Lambert azimuthal equal-area](http://bl.ocks.org/3757101)
10
- * d3.geo.azimuthalEquidistant - [azimuthal equidistant](http://bl.ocks.org/3757110)
11
- * d3.geo.baker - [Baker Dinomic](http://bl.ocks.org/4476279)
12
- * d3.geo.berghaus - [Berghaus Star](http://bl.ocks.org/4463049)
13
- * d3.geo.boggs - [Boggs eumorphic](http://bl.ocks.org/4481220)
14
- * d3.geo.bonne - [Bonne](http://bl.ocks.org/3734313)
15
- * d3.geo.bromley - [Bromley](http://bl.ocks.org/4487695)
16
- * d3.geo.collignon - [Collignon](http://bl.ocks.org/3734316)
17
- * d3.geo.conicConformal - [Lambert conformal conic](http://bl.ocks.org/3734321)
18
- * d3.geo.conicEquidistant - [conic equidistant](http://bl.ocks.org/3734317)
19
- * d3.geo.craig - [Craig retroazimuthal](http://bl.ocks.org/4459466)
20
- * d3.geo.craster - [Craster parabolic](http://bl.ocks.org/4465118)
21
- * d3.geo.cylindricalEqualArea - [cylindrical equal-area](http://bl.ocks.org/3712408), [Gall–Peters](http://bl.ocks.org/3946824), [Hobo–Dyer](http://bl.ocks.org/4476487), [Tobler world-in-a-square](http://bl.ocks.org/4476496)
22
- * d3.geo.eckert1 - [Eckert I](http://bl.ocks.org/3734322)
23
- * d3.geo.eckert2 - [Eckert II](http://bl.ocks.org/3734324)
24
- * d3.geo.eckert3 - [Eckert III](http://bl.ocks.org/3734325)
25
- * d3.geo.eckert4 - [Eckert IV](http://bl.ocks.org/3734327)
26
- * d3.geo.eckert5 - [Eckert V](http://bl.ocks.org/3734328)
27
- * d3.geo.eckert6 - [Eckert VI](http://bl.ocks.org/3734329)
28
- * d3.geo.eisenlohr - [Eisenlohr conformal](http://bl.ocks.org/3797585)
29
- * d3.geo.equirectangular - [Equirectangular (Plate Carrée)](http://bl.ocks.org/3757119)
30
- * d3.geo.fahey - [Fahey](http://bl.ocks.org/4731228)
31
- * d3.geo.gnomonic - [gnomonic](http://bl.ocks.org/3757349)
32
- * d3.geo.gringorten - [Gringorten](http://bl.ocks.org/3796882)
33
- * d3.geo.guyou - [Guyou hemisphere-in-a-square](http://bl.ocks.org/3763867)
34
- * d3.geo.hammer - [Hammer](http://bl.ocks.org/3712397), [Eckert–Greifendorff](http://bl.ocks.org/4496212), [quartic authalic](http://bl.ocks.org/4463175), [Briesemeister](http://bl.ocks.org/4519926)
35
- * d3.geo.hammerRetroazimuthal - [Hammer retroazimuthal](http://bl.ocks.org/4459130)
36
- * d3.geo.healpix - [HEALPix](http://bl.ocks.org/4463237)
37
- * d3.geo.hill - [Hill eucyclic](http://bl.ocks.org/4479513), [Maurer No. 73](http://bl.ocks.org/4479547)
38
- * d3.geo.homolosine - [Goode homolosine](http://bl.ocks.org/3734330)
39
- * d3.geo.kavrayskiy7 - [Kavrayskiy VII](http://bl.ocks.org/3710082)
40
- * d3.geo.lagrange - [Lagrange conformal](http://bl.ocks.org/3797591)
41
- * d3.geo.larrivee - [Larrivée](http://bl.ocks.org/3719042)
42
- * d3.geo.laskowski - [Laskowski tri-optimal](http://bl.ocks.org/4489342)
43
- * d3.geo.littrow - [Littrow](http://bl.ocks.org/4459071)
44
- * d3.geo.loximuthal - [loximuthal](http://bl.ocks.org/3867220)
45
- * d3.geo.mercator - [Mercator](http://bl.ocks.org/3757132)
46
- * d3.geo.miller - [Miller](http://bl.ocks.org/3734333)
5
+ * d3.geo.aitoff - [Aitoff](http://bl.ocks.org/mbostock/3682698)
6
+ * d3.geo.albers - [Albers equal-area conic](http://bl.ocks.org/mbostock/3734308)
7
+ * d3.geo.armadillo - [Armadillo](http://bl.ocks.org/mbostock/4463127)
8
+ * d3.geo.august - [August conformal](http://bl.ocks.org/mbostock/3797581)
9
+ * d3.geo.azimuthalEqualArea - [Lambert azimuthal equal-area](http://bl.ocks.org/mbostock/3757101)
10
+ * d3.geo.azimuthalEquidistant - [azimuthal equidistant](http://bl.ocks.org/mbostock/3757110)
11
+ * d3.geo.baker - [Baker Dinomic](http://bl.ocks.org/mbostock/4476279)
12
+ * d3.geo.berghaus - [Berghaus Star](http://bl.ocks.org/mbostock/4463049)
13
+ * d3.geo.boggs - [Boggs eumorphic](http://bl.ocks.org/mbostock/4481220)
14
+ * d3.geo.bonne - [Bonne](http://bl.ocks.org/mbostock/3734313)
15
+ * d3.geo.bromley - [Bromley](http://bl.ocks.org/mbostock/4487695)
16
+ * d3.geo.collignon - [Collignon](http://bl.ocks.org/mbostock/3734316)
17
+ * d3.geo.conicConformal - [Lambert conformal conic](http://bl.ocks.org/mbostock/3734321)
18
+ * d3.geo.conicEquidistant - [conic equidistant](http://bl.ocks.org/mbostock/3734317)
19
+ * d3.geo.craig - [Craig retroazimuthal](http://bl.ocks.org/mbostock/4459466)
20
+ * d3.geo.craster - [Craster parabolic](http://bl.ocks.org/mbostock/4465118)
21
+ * d3.geo.cylindricalEqualArea - [cylindrical equal-area](http://bl.ocks.org/mbostock/3712408), [Gall–Peters](http://bl.ocks.org/mbostock/3946824), [Hobo–Dyer](http://bl.ocks.org/mbostock/4476487), [Tobler world-in-a-square](http://bl.ocks.org/mbostock/4476496)
22
+ * d3.geo.eckert1 - [Eckert I](http://bl.ocks.org/mbostock/3734322)
23
+ * d3.geo.eckert2 - [Eckert II](http://bl.ocks.org/mbostock/3734324)
24
+ * d3.geo.eckert3 - [Eckert III](http://bl.ocks.org/mbostock/3734325)
25
+ * d3.geo.eckert4 - [Eckert IV](http://bl.ocks.org/mbostock/3734327)
26
+ * d3.geo.eckert5 - [Eckert V](http://bl.ocks.org/mbostock/3734328)
27
+ * d3.geo.eckert6 - [Eckert VI](http://bl.ocks.org/mbostock/3734329)
28
+ * d3.geo.eisenlohr - [Eisenlohr conformal](http://bl.ocks.org/mbostock/3797585)
29
+ * d3.geo.equirectangular - [Equirectangular (Plate Carrée)](http://bl.ocks.org/mbostock/3757119)
30
+ * d3.geo.fahey - [Fahey](http://bl.ocks.org/mbostock/4731228)
31
+ * d3.geo.gnomonic - [gnomonic](http://bl.ocks.org/mbostock/3757349)
32
+ * d3.geo.gringorten - [Gringorten](http://bl.ocks.org/mbostock/4362031)
33
+ * d3.geo.guyou - [Guyou hemisphere-in-a-square](http://bl.ocks.org/mbostock/3763867)
34
+ * d3.geo.hammer - [Hammer](http://bl.ocks.org/mbostock/3712397), [Eckert–Greifendorff](http://bl.ocks.org/mbostock/4496212), [quartic authalic](http://bl.ocks.org/mbostock/4463175), [Briesemeister](http://bl.ocks.org/mbostock/4519926)
35
+ * d3.geo.hammerRetroazimuthal - [Hammer retroazimuthal](http://bl.ocks.org/mbostock/4459130)
36
+ * d3.geo.healpix - [HEALPix](http://bl.ocks.org/mbostock/4463237)
37
+ * d3.geo.hill - [Hill eucyclic](http://bl.ocks.org/mbostock/4479513), [Maurer No. 73](http://bl.ocks.org/mbostock/4479547)
38
+ * d3.geo.homolosine - [Goode homolosine](http://bl.ocks.org/mbostock/3734330)
39
+ * d3.geo.kavrayskiy7 - [Kavrayskiy VII](http://bl.ocks.org/mbostock/3710082)
40
+ * d3.geo.lagrange - [Lagrange conformal](http://bl.ocks.org/mbostock/3797591)
41
+ * d3.geo.larrivee - [Larrivée](http://bl.ocks.org/mbostock/3719042)
42
+ * d3.geo.laskowski - [Laskowski tri-optimal](http://bl.ocks.org/mbostock/4489342)
43
+ * d3.geo.littrow - [Littrow](http://bl.ocks.org/mbostock/4459071)
44
+ * d3.geo.loximuthal - [loximuthal](http://bl.ocks.org/mbostock/3867220)
45
+ * d3.geo.mercator - [Mercator](http://bl.ocks.org/mbostock/3757132)
46
+ * d3.geo.miller - [Miller](http://bl.ocks.org/mbostock/3734333)
47
47
  * d3.geo.modifiedStereographic - Modified Stereographic
48
- * d3.geo.mollweide - [Mollweide](http://bl.ocks.org/3734336), [Atlantis](http://bl.ocks.org/4519975)
49
- * d3.geo.mtFlatPolarParabolic - [McBryde–Thomas flat-polar parabolic](http://bl.ocks.org/4465130)
50
- * d3.geo.mtFlatPolarQuartic - [McBryde–Thomas flat-polar quartic](http://bl.ocks.org/4465137)
51
- * d3.geo.mtFlatPolarSinusoidal - [McBryde–Thomas flat-polar sinusoidal](http://bl.ocks.org/4465140)
52
- * d3.geo.naturalEarth - [Natural Earth](http://bl.ocks.org/4479477)
53
- * d3.geo.nellHammer - [Nell–Hammer](http://bl.ocks.org/3734342)
54
- * d3.geo.orthographic - [orthographic](http://bl.ocks.org/3757125)
55
- * d3.geo.peirceQuincuncial - [Pierce quincuncial](http://bl.ocks.org/4310087)
56
- * d3.geo.polyconic - [Polyconic](http://bl.ocks.org/3734343)
48
+ * d3.geo.mollweide - [Mollweide](http://bl.ocks.org/mbostock/3734336), [Atlantis](http://bl.ocks.org/mbostock/4519975)
49
+ * d3.geo.mtFlatPolarParabolic - [McBryde–Thomas flat-polar parabolic](http://bl.ocks.org/mbostock/4465130)
50
+ * d3.geo.mtFlatPolarQuartic - [McBryde–Thomas flat-polar quartic](http://bl.ocks.org/mbostock/4465137)
51
+ * d3.geo.mtFlatPolarSinusoidal - [McBryde–Thomas flat-polar sinusoidal](http://bl.ocks.org/mbostock/4465140)
52
+ * d3.geo.naturalEarth - [Natural Earth](http://bl.ocks.org/mbostock/4479477)
53
+ * d3.geo.nellHammer - [Nell–Hammer](http://bl.ocks.org/mbostock/3734342)
54
+ * d3.geo.orthographic - [orthographic](http://bl.ocks.org/mbostock/3757125)
55
+ * d3.geo.peirceQuincuncial - [Pierce quincuncial](http://bl.ocks.org/mbostock/4310087)
56
+ * d3.geo.polyconic - [Polyconic](http://bl.ocks.org/mbostock/3734343)
57
57
  * d3.geo.rectangularPolyconic - Rectangular Polyconic
58
- * d3.geo.robinson - [Robinson](http://bl.ocks.org/3710566)
59
- * d3.geo.satellite - [satellite (tilted perpsective)](http://bl.ocks.org/3790444)
60
- * d3.geo.sinusoidal - [sinusoidal](http://bl.ocks.org/3712399)
61
- * d3.geo.sinuMollweide - [Sinu-Mollweide](http://bl.ocks.org/4319903)
62
- * d3.geo.stereographic - [stereographic](http://bl.ocks.org/3757137)
58
+ * d3.geo.robinson - [Robinson](http://bl.ocks.org/mbostock/3710566)
59
+ * d3.geo.satellite - [satellite (tilted perpsective)](http://bl.ocks.org/mbostock/3790444)
60
+ * d3.geo.sinusoidal - [sinusoidal](http://bl.ocks.org/mbostock/3712399)
61
+ * d3.geo.sinuMollweide - [Sinu-Mollweide](http://bl.ocks.org/mbostock/4319903)
62
+ * d3.geo.stereographic - [stereographic](http://bl.ocks.org/mbostock/3757137)
63
63
  * d3.geo.times - Times
64
64
  * d3.geo.twoPointAzimuthal - Two-Point Azimuthal
65
65
  * d3.geo.twoPointEquidistant - Two-Point Equidistant
66
- * d3.geo.vanDerGrinten - [Van der Grinten](http://bl.ocks.org/3796831)
66
+ * d3.geo.vanDerGrinten - [Van der Grinten](http://bl.ocks.org/mbostock/3796831)
67
67
  * d3.geo.vanDerGrinten2 - Van der Grinten II
68
68
  * d3.geo.vanDerGrinten3 - Van der Grinten III
69
- * d3.geo.vanDerGrinten4 - [Van der Grinten IV](http://bl.ocks.org/4489365)
70
- * d3.geo.wagner4 - [Wagner IV, Putniṇš P2´](http://bl.ocks.org/4487674)
71
- * d3.geo.wagner6 - [Wagner VI](http://bl.ocks.org/3710148)
72
- * d3.geo.wagner7 - [Wagner VII](http://bl.ocks.org/4465109)
73
- * d3.geo.wiechel - [Wiechel](http://bl.ocks.org/4463155)
74
- * d3.geo.winkel3 - [Winkel Tripel](http://bl.ocks.org/3682676)
69
+ * d3.geo.vanDerGrinten4 - [Van der Grinten IV](http://bl.ocks.org/mbostock/4489365)
70
+ * d3.geo.wagner4 - [Wagner IV, Putniṇš P2´](http://bl.ocks.org/mbostock/4487674)
71
+ * d3.geo.wagner6 - [Wagner VI](http://bl.ocks.org/mbostock/3710148)
72
+ * d3.geo.wagner7 - [Wagner VII](http://bl.ocks.org/mbostock/4465109)
73
+ * d3.geo.wiechel - [Wiechel](http://bl.ocks.org/mbostock/4463155)
74
+ * d3.geo.winkel3 - [Winkel Tripel](http://bl.ocks.org/mbostock/3682676)
75
75
 
76
76
  This plugin also provides d3.geo.interrupt, which can be used to create arbitrary interrupted projections from a given raw projection. For example, see [Philbrick’s interrupted Sinu-Mollweide](http://bl.ocks.org/4481520).
77
77
 
@@ -1,47 +1,42 @@
1
- function gringortenProjection() {
2
- var quincuncial = false,
3
- m = projectionMutator(gringorten),
4
- p = m(quincuncial);
1
+ // @import quincuncial
5
2
 
6
- p.quincuncial = function(_) {
7
- if (!arguments.length) return quincuncial;
8
- return m(quincuncial = !!_);
9
- };
3
+ function gringorten(λ, φ) {
4
+ var sλ = sgn(λ),
5
+ = sgn(φ),
6
+ cosφ = Math.cos(φ),
7
+ x = Math.cos(λ) * cosφ,
8
+ y = Math.sin(λ) * cosφ,
9
+ z = Math.sin(sφ * φ);
10
10
 
11
- return p;
11
+ λ = Math.abs(Math.atan2(y, z));
12
+ φ = asin(x);
13
+
14
+ if (Math.abs(λ - π / 2) > ε) λ %= π / 2;
15
+ var point = gringortenHexadecant(λ > π / 4 ? π / 2 - λ : λ, φ);
16
+
17
+ if (λ > π / 4) z = point[0], point[0] = -point[1], point[1] = -z;
18
+
19
+ return (point[0] *= sλ, point[1] *= -sφ, point);
12
20
  }
13
21
 
14
- function gringorten(quincuncial) {
15
- return function(λ, φ) {
16
- var cosφ = Math.cos(φ),
17
- x = Math.cos(λ) * cosφ,
18
- y = Math.sin(λ) * cosφ,
19
- z = Math.sin(φ);
20
- if (quincuncial) {
21
- λ = Math.atan2(y, -z) - π / 4;
22
- φ = asin(x);
23
- } else {
24
- λ = Math.atan2(z, x) + π / 2;
25
- φ = asin(-y);
26
- }
27
- while < 0) λ += 2 * π;
28
- var = φ < 0,
29
- df = ~~(λ / (π / 4));
30
- λ %= π / 2;
31
- var point = gringortenHexadecant(df & 1 ? π / 2 - λ : λ, Math.abs(φ)),
32
- x = point[0],
33
- y = point[1],
34
- t;
35
- if (quincuncial && nφ) y = -2 - y;
36
- if (df > 3) x = -x, y = -y;
37
- switch (df % 4) {
38
- case 1: x = -x; // fall through
39
- case 2: t = x; x = -y; y = t; break;
40
- case 3: y = -y; break;
41
- }
42
- if (!quincuncial && nφ) x = 2 - x;
43
- return quincuncial ? [(x - y) / Math.SQRT2, (x + y) / Math.SQRT2] : [x, y];
44
- };
22
+ gringorten.invert = function(x, y) {
23
+ var sx = sgn(x),
24
+ sy = sgn(y),
25
+ x0 = -sx * x,
26
+ y0 = -sy * y,
27
+ t = y0 / x0 < 1,
28
+ p = gringortenHexadecantInvert(t ? y0 : x0, t ? x0 : y0),
29
+ λ = p[0],
30
+ φ = p[1];
31
+
32
+ if (t) λ = / 2 - λ;
33
+
34
+ var cosφ = Math.cos(φ),
35
+ x = Math.cos(λ) * cosφ,
36
+ y = Math.sin(λ) * cosφ,
37
+ z = Math.sin(φ);
38
+
39
+ return [sx * (Math.atan2(y, -z) + π), sy * asin(x)];
45
40
  }
46
41
 
47
42
  function gringortenHexadecant(λ, φ) {
@@ -82,7 +77,7 @@ function gringortenHexadecant(λ, φ) {
82
77
 
83
78
  var x1 = x,
84
79
  x0 = .5 * x,
85
- i = -1;
80
+ i = 50;
86
81
  x = .5 * (x0 + x1);
87
82
  do {
88
83
  var g = Math.sqrt(a2 - x * x),
@@ -91,21 +86,64 @@ function gringortenHexadecant(λ, φ) {
91
86
  if (f < 0) x0 = x;
92
87
  else x1 = x;
93
88
  x = .5 * (x0 + x1);
94
- } while (++i < 50 && Math.abs(x1 - x0) > ε);
89
+ } while (Math.abs(x1 - x0) > ε && --i > 0);
95
90
  } else {
96
91
  // Newton-Raphson.
97
- for (var x = ε, i = 0; i < 25; i++) {
92
+ var x = ε, i = 25, δ;
93
+ do {
98
94
  var x2 = x * x,
99
95
  g = asqrt(a2 - x2),
100
96
  ζμg = ζ + μ * g,
101
97
  f = x * ζμg + ν * asin(x / a) - Λ,
102
- df = ζμg + (ν - μ * x2) / g,
103
- dx = g ? -f / df : 0;
104
- x += dx;
105
- if (Math.abs(dx) < ε) break;
106
- }
98
+ df = ζμg + (ν - μ * x2) / g;
99
+ x -= δ = g ? f / df : 0;
100
+ } while (Math.abs(δ) > ε && --i > 0);
107
101
  }
108
102
  return [x, -h - r * asqrt(a2 - x * x)];
109
103
  }
110
104
 
111
- (d3.geo.gringorten = gringortenProjection).raw = gringorten;
105
+ function gringortenHexadecantInvert(x, y) {
106
+ var x0 = 0,
107
+ x1 = 1,
108
+ r = .5,
109
+ i = 50;
110
+
111
+ while (true) {
112
+ var r2 = r * r,
113
+ sinφ = Math.sqrt(r),
114
+ z = Math.asin(1 / Math.sqrt(1 + r2)),
115
+ v = (1 - r2) + r * (1 + r2) * z,
116
+ p2 = (1 - sinφ) / v,
117
+ p = Math.sqrt(p2),
118
+ a2 = p2 * (1 + r2),
119
+ h = p * (1 - r2),
120
+ g2 = a2 - x * x,
121
+ g = Math.sqrt(g2),
122
+ y0 = y + h + r * g;
123
+
124
+ if (Math.abs(x1 - x0) < ε2 || --i === 0 || y0 === 0) break;
125
+
126
+ if (y0 > 0) x0 = r;
127
+ else x1 = r;
128
+
129
+ r = .5 * (x0 + x1);
130
+ }
131
+
132
+ if (!i) return null;
133
+
134
+ var φ = Math.asin(sinφ),
135
+ cosφ = Math.cos(φ),
136
+ secφ = 1 / cosφ,
137
+ drdφ = 2 * sinφ * cosφ,
138
+ dvdφ = (-3 * r + z * (1 + 3 * r2)) * drdφ,
139
+ dp2dφ = (-v * cosφ - (1 - sinφ) * dvdφ) / (v * v),
140
+ dpdφ = .5 * dp2dφ / p,
141
+ dhdφ = (1 - r2) * dpdφ - 2 * r * p * drdφ,
142
+ ζ = -2 * secφ * dhdφ,
143
+ μ = -secφ * drdφ,
144
+ ν = -secφ * (r * (1 + r2) * dp2dφ + p2 * (1 + 3 * r2) * drdφ);
145
+
146
+ return [π / 4 * (x * (ζ + μ * g) + ν * Math.asin(x / Math.sqrt(a2))), φ];
147
+ }
148
+
149
+ d3.geo.gringorten = quincuncialProjection(gringorten);
@@ -1,4 +1,5 @@
1
1
  // @import elliptic
2
+ // @import quincuncial
2
3
 
3
4
  // √k' tn(½K - w) = exp(-ζ).
4
5
  function guyou(λ, φ) {
@@ -8,15 +9,12 @@ function guyou(λ, φ) {
8
9
  K = ellipticF(π / 2, k * k),
9
10
  f = -1;
10
11
 
11
- var s = λ > 0 ? -1 : 1;
12
- λ += s * π / 2;
13
-
14
12
  var ψ = Math.log(Math.tan(π / 4 + Math.abs(φ) / 2)),
15
13
  r = Math.exp(f * ψ) / Math.sqrt(k_),
16
14
  at = guyouComplexAtan(r * Math.cos(f * λ), r * Math.sin(f * λ)),
17
15
  t = ellipticFi(at[0], at[1], k * k);
18
16
 
19
- return [-s * .5 * K - t[1], sgn(φ) * (.5 * K - t[0])];
17
+ return [-t[1], sgn(φ) * (.5 * K - t[0])];
20
18
  }
21
19
 
22
20
  function guyouComplexAtan(x, y) {
@@ -43,13 +41,9 @@ guyou.invert = function(x, y) {
43
41
  K = ellipticF(π / 2, k * k),
44
42
  f = -1;
45
43
 
46
- var s = x > 0 ? -1 : 1;
47
-
48
- var j = ellipticJi(.5 * K - y, -s * .5 * K - x, k * k),
44
+ var j = ellipticJi(.5 * K - y, -x, k * k),
49
45
  tn = guyouComplexDivide(j[0], j[1]),
50
- λ = Math.atan2(tn[1], tn[0]) / f - s * π / 2;
51
- if (λ < -π) λ += 2 * π;
52
- else if (λ > π) λ -= 2 * π;
46
+ λ = Math.atan2(tn[1], tn[0]) / f;
53
47
 
54
48
  return [
55
49
  λ,
@@ -57,4 +51,4 @@ guyou.invert = function(x, y) {
57
51
  ];
58
52
  };
59
53
 
60
- (d3.geo.guyou = function() { return projection(guyou); }).raw = guyou;
54
+ d3.geo.guyou = quincuncialProjection(guyou);
@@ -3,19 +3,20 @@ var healpixParallel = 41 + 48 / 36 + 37 / 3600; // TODO automate
3
3
  function healpix(h) {
4
4
  var lambert = d3.geo.cylindricalEqualArea.raw(0),
5
5
  φ0 = healpixParallel * π / 180,
6
- dx0 = lambert(π, 0)[0] - lambert(-π, 0)[0],
6
+ dx0 = 2 * π,
7
7
  dx1 = d3.geo.collignon.raw(π, φ0)[0] - d3.geo.collignon.raw(-π, φ0)[0],
8
8
  y0 = lambert(0, φ0)[1],
9
9
  y1 = d3.geo.collignon.raw(0, φ0)[1],
10
10
  dy1 = d3.geo.collignon.raw(0, π / 2)[1] - y1,
11
11
  k = 2 * π / h;
12
12
 
13
- return function(λ, φ) {
14
- var point;
15
- if (Math.abs(φ) > φ0) {
13
+ function forward(λ, φ) {
14
+ var point,
15
+ φ2 = Math.abs(φ);
16
+ if (φ2 > φ0) {
16
17
  var i = Math.min(h - 1, Math.max(0, Math.floor((λ + π) / k)));
17
- λ = λ + π * (h - 1) / h - i * k;
18
- point = d3.geo.collignon.raw(λ, Math.abs(φ));
18
+ λ += π * (h - 1) / h - i * k;
19
+ point = d3.geo.collignon.raw(λ, φ2);
19
20
  point[0] = point[0] * dx0 / dx1 - dx0 * (h - 1) / (2 * h) + i * dx0 / h;
20
21
  point[1] = y0 + (point[1] - y1) * 4 * dy1 / dx0;
21
22
  if (φ < 0) point[1] = -point[1];
@@ -24,7 +25,23 @@ function healpix(h) {
24
25
  }
25
26
  point[0] /= 2;
26
27
  return point;
28
+ }
29
+
30
+ forward.invert = function(x, y) {
31
+ x *= 2;
32
+ var y2 = Math.abs(y);
33
+ if (y2 > y0) {
34
+ var i = Math.min(h - 1, Math.max(0, Math.floor((x + π) / k)));
35
+ x = (x + π * (h - 1) / h - i * k) * dx1 / dx0;
36
+ var point = d3.geo.collignon.raw.invert(x, .25 * (y2 - y0) * dx0 / dy1 + y1);
37
+ point[0] -= π * (h - 1) / h - i * k;
38
+ if (y < 0) point[1] = -point[1];
39
+ return point;
40
+ }
41
+ return lambert.invert(x, y);
27
42
  };
43
+
44
+ return forward;
28
45
  }
29
46
 
30
47
  function healpixProjection() {
@@ -1,50 +1,6 @@
1
1
  // @import guyou
2
+ // @import quincuncial
2
3
 
3
- function peirceQuincuncial(λ, φ) {
4
- var k_ = (Math.SQRT2 - 1) / (Math.SQRT2 + 1),
5
- k = Math.sqrt(1 - k_ * k_),
6
- K = ellipticF(π / 2, k * k);
4
+ var peirceQuincuncialProjection = quincuncialProjection(guyou);
7
5
 
8
- var t = Math.abs(λ) < π / 2,
9
- p = guyou(λ + (λ < -π / 2 ? 1.5 : -.5) * π, φ);
10
-
11
- p[0] += (t ? .5 : -.5) * K;
12
-
13
- var x = (p[0] - p[1]) * Math.SQRT1_2,
14
- y = (p[0] + p[1]) * Math.SQRT1_2;
15
-
16
- if (t) return [x, y];
17
-
18
- var d = K * Math.SQRT1_2,
19
- s = x > 0 ^ y > 0 ? -1 : 1;
20
-
21
- return [s * x - sgn(y) * d, s * y - sgn(x) * d];
22
- }
23
-
24
- peirceQuincuncial.invert = function(x0, y0) {
25
- var k_ = (Math.SQRT2 - 1) / (Math.SQRT2 + 1),
26
- k = Math.sqrt(1 - k_ * k_),
27
- K = ellipticF(π / 2, k * k);
28
-
29
- var x = (x0 + y0) * Math.SQRT1_2,
30
- y = (y0 - x0) * Math.SQRT1_2;
31
-
32
- var t = Math.abs(x) < .5 * K && Math.abs(y) < .5 * K;
33
-
34
- if (!t) {
35
- var d = K * Math.SQRT1_2,
36
- s = x > 0 ^ y > 0 ? -1 : 1,
37
- x1 = -s * (x0 + (y > 0 ? 1 : -1) * d),
38
- y1 = -s * (y0 + (x > 0 ? 1 : -1) * d);
39
- x = (-x1 - y1) * Math.SQRT1_2;
40
- y = (x1 - y1) * Math.SQRT1_2;
41
- }
42
-
43
- x -= (t ? .5 : -.5) * K;
44
-
45
- var p = guyou.invert(x, y);
46
- p[0] += .5 * π;
47
- return p;
48
- };
49
-
50
- (d3.geo.peirceQuincuncial = function() { return projection(peirceQuincuncial).rotate([-90, -90, 45]).clipAngle(180 - 1e-6); }).raw = peirceQuincuncial;
6
+ (d3.geo.peirceQuincuncial = function() { return peirceQuincuncialProjection().quincuncial(true).rotate([-90, -90, 45]).clipAngle(180 - 1e-6); }).raw = peirceQuincuncialProjection.raw;
@@ -0,0 +1,71 @@
1
+ function quincuncialProjection(projectHemisphere) {
2
+ var dx = projectHemisphere(π / 2, 0)[0] - projectHemisphere(-π / 2, 0)[0];
3
+
4
+ function projection() {
5
+ var quincuncial = false,
6
+ m = projectionMutator(projectAt),
7
+ p = m(quincuncial);
8
+
9
+ p.quincuncial = function(_) {
10
+ if (!arguments.length) return quincuncial;
11
+ return m(quincuncial = !!_);
12
+ };
13
+
14
+ return p;
15
+ }
16
+
17
+ function projectAt(quincuncial) {
18
+ var forward = quincuncial ? function(λ, φ) {
19
+ var t = Math.abs(λ) < π / 2,
20
+ p = projectHemisphere(t ? λ : λ > 0 ? λ - π : λ + π, φ);
21
+
22
+ var x = (p[0] - p[1]) * Math.SQRT1_2,
23
+ y = (p[0] + p[1]) * Math.SQRT1_2;
24
+
25
+ if (t) return [x, y];
26
+
27
+ var d = dx * Math.SQRT1_2,
28
+ s = x > 0 ^ y > 0 ? -1 : 1;
29
+
30
+ return [s * x - sgn(y) * d, s * y - sgn(x) * d];
31
+ } : function(λ, φ) {
32
+ var s = λ > 0 ? -.5 : .5,
33
+ point = projectHemisphere(λ + s * π, φ);
34
+ point[0] -= s * dx;
35
+ return point;
36
+ };
37
+
38
+ if (projectHemisphere.invert) forward.invert = quincuncial ? function(x0, y0) {
39
+ var x = (x0 + y0) * Math.SQRT1_2,
40
+ y = (y0 - x0) * Math.SQRT1_2,
41
+ t = Math.abs(x) < .5 * dx && Math.abs(y) < .5 * dx;
42
+
43
+ if (!t) {
44
+ var d = dx * Math.SQRT1_2,
45
+ s = x > 0 ^ y > 0 ? -1 : 1,
46
+ x1 = -s * (x0 + (y > 0 ? 1 : -1) * d),
47
+ y1 = -s * (y0 + (x > 0 ? 1 : -1) * d);
48
+ x = (-x1 - y1) * Math.SQRT1_2;
49
+ y = (x1 - y1) * Math.SQRT1_2;
50
+ }
51
+
52
+ var p = projectHemisphere.invert(x, y);
53
+ if (!t) p[0] += x > 0 ? π : -π;
54
+ return p;
55
+ } : function(x, y) {
56
+ var s = x > 0 ? -.5 : .5,
57
+ location = projectHemisphere.invert(x + s * dx, y),
58
+ λ = location[0] - s * π;
59
+ if (λ < -π) λ += 2 * π;
60
+ else if (λ > π) λ -= 2 * π;
61
+ location[0] = λ;
62
+ return location;
63
+ };
64
+
65
+ return forward;
66
+ }
67
+
68
+ projection.raw = projectAt;
69
+
70
+ return projection;
71
+ }
@@ -0,0 +1,24 @@
1
+ require("./env");
2
+
3
+ var vows = require("vows"),
4
+ assert = require("assert");
5
+
6
+ var suite = vows.describe("d3.geo.gringorten");
7
+
8
+ suite.addBatch({
9
+ "gringorten": {
10
+ topic: d3.geo.gringorten,
11
+ "projections and inverse projections": function(gringorten) {
12
+ assert.equalInverse(gringorten, [120, 30], [687.902966, 184.525491], 1e-5);
13
+ assert.equalInverse(gringorten, [ 90, 80], [630, 112.748374]);
14
+ assert.equalInverse(gringorten, [ 0, 0], [480, 250], 1e-3);
15
+ assert.equalInverse(gringorten, [-80, 15], [350.494657, 218.619874]);
16
+ assert.equalInverse(gringorten, [ 0, -45], [480, 399.999928], 1e-3);
17
+ assert.equalInverse(gringorten, [ 0, 45], [480, 100.000071], 1e-3);
18
+ assert.equalInverse(gringorten, [ 15, 45], [499.360376, 117.149092], 1e-4);
19
+ assert.equalInverse(gringorten, [ 1, 1], [481.304784, 246.646234]);
20
+ }
21
+ }
22
+ });
23
+
24
+ suite.export(module);
@@ -0,0 +1,24 @@
1
+ require("./env");
2
+
3
+ var vows = require("vows"),
4
+ assert = require("assert");
5
+
6
+ var suite = vows.describe("d3.geo.healpix");
7
+
8
+ suite.addBatch({
9
+ "healpix": {
10
+ topic: d3.geo.healpix,
11
+ "projections and inverse projections": function(healpix) {
12
+ assert.equalInverse(healpix, [ 0, 0], [480, 250]);
13
+ assert.equalInverse(healpix, [ 1, -45], [487.454782, 356.202278]);
14
+ assert.equalInverse(healpix, [ 1, 45], [487.454782, 143.797721]);
15
+ assert.equalInverse(healpix, [-90, 0], [362.190275, 250]);
16
+ assert.equalInverse(healpix, [ 90, 0], [597.809724, 250]);
17
+ assert.equalInverse(healpix, [-80, 15], [375.280244, 211.177143]);
18
+ assert.equalInverse(healpix, [ 1, 1], [481.308996, 247.382139]);
19
+ assert.equalInverse(healpix, [ 15, 45], [504.813987, 143.797721]);
20
+ }
21
+ }
22
+ });
23
+
24
+ suite.export(module);
@@ -8,8 +8,10 @@ var suite = vows.describe("d3.geo.vanDerGrinten4");
8
8
  suite.addBatch({
9
9
  "vanDerGrinten4": {
10
10
  topic: d3.geo.vanDerGrinten4,
11
- "doesn't generate NaN": function(vanDerGrinten4) {
11
+ "doesn't generate NaNs": function(vanDerGrinten4) {
12
12
  assert.inDelta(vanDerGrinten4([20, 1e-7]), [532.359877, 250], 1e-6);
13
+ assert.inDelta(vanDerGrinten4([180.0000000000001, -90.00000000000003]), [480, 485.619449], 1e-6);
14
+ assert.inDelta(vanDerGrinten4([-180, -90.00000000000003]), [480, 485.619449], 1e-6);
13
15
  },
14
16
  "projections and inverse projections": function(vanDerGrinten4) {
15
17
  assert.equalInverse(vanDerGrinten4, [ 0, 0], [480, 250]);
@@ -14,7 +14,7 @@ function vanDerGrinten4(λ, φ) {
14
14
  D = sgn(Math.abs(λ) - π / 2) * Math.sqrt(λ1 * λ1 - 4),
15
15
  D2 = D * D,
16
16
  F = B_C2 * (B2 + C2 * D2 - 1) + (1 - B2) * (B2 * (B_3C * B_3C + 4 * C2) + 12 * BC * C2 + 4 * C2 * C2),
17
- x1 = (D * (B_C2 + C2 - 1) + 2 * Math.sqrt(F)) / (4 * B_C2 + D2);
17
+ x1 = (D * (B_C2 + C2 - 1) + 2 * asqrt(F)) / (4 * B_C2 + D2);
18
18
  return [
19
19
  sgn(λ) * π * x1 / 2,
20
20
  sgn(φ) * π / 2 * asqrt(1 + D * Math.abs(x1) - x1 * x1)
@@ -21,5 +21,5 @@ d3.jsonp = function (url, callback) {
21
21
  script = d3.select('head')
22
22
  .append('script')
23
23
  .attr('type', 'text/javascript')
24
- .attr('src', url.replace(/(\{|%7B)callback(\{|%7D)/, cb));
24
+ .attr('src', url.replace(/(\{|%7B)callback(\}|%7D)/, cb));
25
25
  };
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.3
4
+ version: 0.0.4
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-02-26 00:00:00.000000000 Z
12
+ date: 2013-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -118,6 +118,7 @@ files:
118
118
  - vendor/assets/javascripts/d3/plugins/geo/projection/peirce-quincuncial.js
119
119
  - vendor/assets/javascripts/d3/plugins/geo/projection/polyconic.js
120
120
  - vendor/assets/javascripts/d3/plugins/geo/projection/projection.js
121
+ - vendor/assets/javascripts/d3/plugins/geo/projection/quincuncial.js
121
122
  - vendor/assets/javascripts/d3/plugins/geo/projection/rectangular-polyconic.js
122
123
  - vendor/assets/javascripts/d3/plugins/geo/projection/robinson.js
123
124
  - vendor/assets/javascripts/d3/plugins/geo/projection/satellite.js
@@ -137,10 +138,12 @@ files:
137
138
  - vendor/assets/javascripts/d3/plugins/geo/projection/test/env.js
138
139
  - vendor/assets/javascripts/d3/plugins/geo/projection/test/equirectangular-test.js
139
140
  - vendor/assets/javascripts/d3/plugins/geo/projection/test/fahey-test.js
141
+ - vendor/assets/javascripts/d3/plugins/geo/projection/test/gringorten-test.js
140
142
  - vendor/assets/javascripts/d3/plugins/geo/projection/test/guyou-test.js
141
143
  - vendor/assets/javascripts/d3/plugins/geo/projection/test/hammer-retroazimuthal-test.js
142
144
  - vendor/assets/javascripts/d3/plugins/geo/projection/test/hammer-test.js
143
145
  - vendor/assets/javascripts/d3/plugins/geo/projection/test/hatano-test.js
146
+ - vendor/assets/javascripts/d3/plugins/geo/projection/test/healpix-test.js
144
147
  - vendor/assets/javascripts/d3/plugins/geo/projection/test/hill-test.js
145
148
  - vendor/assets/javascripts/d3/plugins/geo/projection/test/lagrange-test.js
146
149
  - vendor/assets/javascripts/d3/plugins/geo/projection/test/larrivee-test.js