Permalink
Browse files

Separate files for d3.geo.projection plugin.

  • Loading branch information...
1 parent 9fd729f commit 15c7d15f31de59a13d79995b4afe7770276b97bd @mbostock mbostock committed Jan 9, 2013
Showing with 1,790 additions and 1,677 deletions.
  1. +1 −0 .gitignore
  2. +81 −0 Makefile
  3. +40 −0 geo/projection/aitoff.js
  4. +52 −0 geo/projection/armadillo.js
  5. +15 −0 geo/projection/august.js
  6. +28 −0 geo/projection/baker.js
  7. +60 −0 geo/projection/berghaus.js
  8. +27 −0 geo/projection/boggs.js
  9. +29 −0 geo/projection/bonne.js
  10. +5 −0 geo/projection/bromley.js
  11. +17 −0 geo/projection/collignon.js
  12. +29 −0 geo/projection/conic-conformal.js
  13. +27 −0 geo/projection/conic-equidistant.js
  14. +24 −0 geo/projection/craig.js
  15. +18 −0 geo/projection/craster.js
  16. +23 −0 geo/projection/cylindrical-equal-area.js
  17. +18 −0 geo/projection/eckert1.js
  18. +17 −0 geo/projection/eckert2.js
  19. +17 −0 geo/projection/eckert3.js
  20. +24 −0 geo/projection/eckert4.js
  21. +17 −0 geo/projection/eckert5.js
  22. +22 −0 geo/projection/eckert6.js
  23. +16 −0 geo/projection/eisenlohr.js
  24. +1 −0 geo/projection/end.js
  25. +111 −0 geo/projection/gringorten.js
  26. +46 −0 geo/projection/guyou.js
  27. +75 −0 geo/projection/hammer-retroazimuthal.js
  28. +50 −0 geo/projection/hammer.js
  29. +25 −0 geo/projection/hatano.js
  30. +64 −0 geo/projection/healpix.js
  31. +64 −0 geo/projection/hill.js
  32. +17 −0 geo/projection/homolosine.js
  33. +15 −0 geo/projection/kavrayskiy7.js
  34. +27 −0 geo/projection/lagrange.js
  35. +39 −0 geo/projection/larrivee.js
  36. +9 −0 geo/projection/laskowski.js
  37. +8 −0 geo/projection/littrow.js
  38. +29 −0 geo/projection/loximuthal.js
  39. +15 −0 geo/projection/miller.js
  40. +35 −0 geo/projection/mollweide.js
  41. +21 −0 geo/projection/mt-flat-polar-parabolic.js
  42. +23 −0 geo/projection/mt-flat-polar-quartic.js
  43. +25 −0 geo/projection/mt-flat-polar-sinusoidal.js
  44. +22 −0 geo/projection/natural-earth.js
  45. +20 −0 geo/projection/nell-hammer.js
  46. +12 −0 geo/projection/parallel1.js
  47. +13 −0 geo/projection/parallel2.js
  48. +14 −0 geo/projection/peirce-quincuncial.js
  49. +25 −0 geo/projection/polyconic.js
  50. +29 −1,677 geo/projection/projection.js
  51. +83 −0 geo/projection/robinson.js
  52. +68 −0 geo/projection/satellite.js
  53. +19 −0 geo/projection/sinu-mollweide.js
  54. +15 −0 geo/projection/sinusoidal.js
  55. +1 −0 geo/projection/start.js
  56. +41 −0 geo/projection/van-der-grinten.js
  57. +22 −0 geo/projection/van-der-grinten4.js
  58. +9 −0 geo/projection/wagner4.js
  59. +15 −0 geo/projection/wagner6.js
  60. +22 −0 geo/projection/wagner7.js
  61. +14 −0 geo/projection/wiechel.js
  62. +40 −0 geo/projection/winkel3.js
View
@@ -0,0 +1 @@
+d3.*.js
View
@@ -0,0 +1,81 @@
+JS_UGLIFY = uglifyjs
+
+all: \
+ d3.geo.projection.js \
+ d3.geo.projection.min.js
+
+d3.geo.projection.js: \
+ geo/projection/start.js \
+ geo/projection/projection.js \
+ geo/projection/parallel1.js \
+ geo/projection/parallel2.js \
+ geo/projection/aitoff.js \
+ geo/projection/guyou.js \
+ geo/projection/mollweide.js \
+ geo/projection/sinusoidal.js \
+ geo/projection/sinu-mollweide.js \
+ geo/projection/armadillo.js \
+ geo/projection/august.js \
+ geo/projection/baker.js \
+ geo/projection/berghaus.js \
+ geo/projection/boggs.js \
+ geo/projection/bonne.js \
+ geo/projection/bromley.js \
+ geo/projection/collignon.js \
+ geo/projection/conic-conformal.js \
+ geo/projection/conic-equidistant.js \
+ geo/projection/craig.js \
+ geo/projection/craster.js \
+ geo/projection/cylindrical-equal-area.js \
+ geo/projection/eckert1.js \
+ geo/projection/eckert2.js \
+ geo/projection/eckert3.js \
+ geo/projection/eckert4.js \
+ geo/projection/eckert5.js \
+ geo/projection/eckert6.js \
+ geo/projection/eisenlohr.js \
+ geo/projection/gringorten.js \
+ geo/projection/hammer-retroazimuthal.js \
+ geo/projection/hammer.js \
+ geo/projection/hatano.js \
+ geo/projection/healpix.js \
+ geo/projection/hill.js \
+ geo/projection/homolosine.js \
+ geo/projection/kavrayskiy7.js \
+ geo/projection/lagrange.js \
+ geo/projection/larrivee.js \
+ geo/projection/laskowski.js \
+ geo/projection/littrow.js \
+ geo/projection/loximuthal.js \
+ geo/projection/miller.js \
+ geo/projection/mt-flat-polar-parabolic.js \
+ geo/projection/mt-flat-polar-quartic.js \
+ geo/projection/mt-flat-polar-sinusoidal.js \
+ geo/projection/natural-earth.js \
+ geo/projection/nell-hammer.js \
+ geo/projection/peirce-quincuncial.js \
+ geo/projection/polyconic.js \
+ geo/projection/robinson.js \
+ geo/projection/satellite.js \
+ geo/projection/van-der-grinten.js \
+ geo/projection/van-der-grinten4.js \
+ geo/projection/wagner4.js \
+ geo/projection/wagner6.js \
+ geo/projection/wagner7.js \
+ geo/projection/wiechel.js \
+ geo/projection/winkel3.js \
+ geo/projection/end.js
+
+%.min.js: %.js Makefile
+ @rm -f $@
+ $(JS_UGLIFY) $< -c -m -o $@
+
+d3%js: Makefile
+ @rm -f $@
+ @cat $(filter %.js,$^) > $@.tmp
+ $(JS_UGLIFY) $@.tmp -b indent-level=2 -o $@
+ @rm $@.tmp
+ @chmod a-w $@
+
+clean:
+ rm -f d3.*.js
@@ -0,0 +1,40 @@
+function aitoff(λ, φ) {
+ var cosφ = Math.cos(φ),
+ sinciα = sinci(acos(cosφ * Math.cos/= 2)));
+ return [
+ 2 * cosφ * Math.sin(λ) * sinciα,
+ Math.sin(φ) * sinciα
+ ];
+}
+
+aitoff.invert = function(x, y) {
+ var λ = x, φ = y, i = 25;
+ do {
+ var sinλ = Math.sin(λ),
+ sinλ_2 = Math.sin/ 2),
+ cosλ_2 = Math.cos/ 2),
+ sinφ = Math.sin(φ),
+ cosφ = Math.cos(φ),
+ sin_2φ = Math.sin(2 * φ),
+ sin2φ = sinφ * sinφ,
+ cos2φ = cosφ * cosφ,
+ sin2λ_2 = sinλ_2 * sinλ_2,
+ C = 1 - cos2φ * cosλ_2 * cosλ_2,
+ E = C ? acos(cosφ * cosλ_2) * Math.sqrt(F = 1 / C) : F = 0,
+ F,
+ fx = 2 * E * cosφ * sinλ_2 - x,
+ fy = E * sinφ - y,
+ δxδλ = F * (cos2φ * sin2λ_2 + E * cosφ * cosλ_2 * sin2φ),
+ δxδφ = F * (.5 * sinλ * sin_2φ - E * 2 * sinφ * sinλ_2),
+ δyδλ = F * .25 * (sin_2φ * sinλ_2 - E * sinφ * cos2φ * sinλ),
+ δyδφ = F * (sin2φ * cosλ_2 + E * sin2λ_2 * cosφ),
+ denominator = δxδφ * δyδλ - δyδφ * δxδλ;
+ if (!denominator) break;
+ var δλ = (fy * δxδφ - fx * δyδφ) / denominator,
+ δφ = (fx * δyδλ - fy * δxδλ) / denominator;
+ λ -= δλ, φ -= δφ;
+ } while ((Math.abs(δλ) > ε || Math.abs(δφ) > ε) && --i > 0);
+ return [λ, φ];
+};
+
+(d3.geo.aitoff = function() { return projection(aitoff); }).raw = aitoff;
@@ -0,0 +1,52 @@
+function armadillo0) {
+ var sinφ0 = Math.sin0),
+ cosφ0 = Math.cos0),
+ tanφ0 = Math.tan0),
+ k = (1 + sinφ0 - cosφ0) / 2
+
+ function forward(λ, φ) {
+ var cosφ = Math.cos(φ),
+ cosλ = Math.cos/= 2),
+ φ1 = -Math.atan2(cosλ, tanφ0);
+ return [
+ (1 + cosφ) * Math.sin(λ),
+ (φ > φ1 - 1e-3 ? 0 : -1) + // TODO hack
+ k + Math.sin(φ) * cosφ0 - (1 + cosφ) * sinφ0 * cosλ
+ ];
+ }
+
+ return forward;
+}
+
+function armadilloProjection() {
+ var φ0 = π / 9, // 20°
+ tanφ0 = Math.tan0),
+ m = projectionMutator(armadillo),
+ p = m0),
+ stream_ = p.stream;
+
+ p.parallel = function(_) {
+ if (!arguments.length) return φ0 / π * 180;
+ return m0 = _ * π / 180);
+ };
+
+ p.stream = function(stream) {
+ var rotate = p.rotate(),
+ rotateStream = stream_(stream),
+ sphereStream = (p.rotate([0, 0]), stream_(stream));
+ p.rotate(rotate);
+ rotateStream.sphere = function() {
+ sphereStream.polygonStart(), sphereStream.lineStart();
+ for (var λ = -180; λ < 180; λ += 90) sphereStream.point(λ, 90);
+ while (--λ >= -180) { // TODO precision?
+ sphereStream.point(λ, -Math.atan2(Math.cos* radians / 2), tanφ0) * degrees);
+ }
+ sphereStream.lineEnd(), sphereStream.polygonEnd();
+ };
+ return rotateStream;
+ };
+
+ return p;
+}
+
+(d3.geo.armadillo = armadilloProjection).raw = armadillo;
@@ -0,0 +1,15 @@
+function august(λ, φ) {
+ var tanφ = Math.tan/ 2),
+ k = 1 - tanφ * tanφ,
+ c = 1 + k * Math.cos/= 2),
+ x = Math.sin(λ) * k / c,
+ y = tanφ / c,
+ x2 = x * x,
+ y2 = y * y;
+ return [
+ 4 / 3 * x * (3 + x2 - 3 * y2),
+ 4 / 3 * y * (3 + 3 * x2 - y2)
+ ];
+}
+
+(d3.geo.august = function() { return projection(august); }).raw = august;
@@ -0,0 +1,28 @@
+var bakerφ = Math.log(1 + Math.SQRT2);
+
+function baker(λ, φ) {
+ var φ0 = Math.abs(φ);
+ return φ0 < π / 4
+ ? [λ, Math.log(Math.tan/ 4 + φ / 2))]
+ : [
+ λ * Math.cos0) * (2 * Math.SQRT2 - 1 / Math.sin0)),
+ sgn(φ) * (2 * Math.SQRT2 *0 - π / 4) - Math.log(Math.tan0 / 2)))
+ ];
+}
+
+baker.invert = function(x, y) {
+ if ((y0 = Math.abs(y)) < bakerφ) return [x, 2 * Math.atan(Math.exp(y)) - π / 2];
+ var sqrt8 = Math.sqrt(8),
+ φ = π / 4, i = 25, δ, y0;
+ do {
+ var cosφ_2 = Math.cos/ 2),
+ tanφ_2 = Math.tan/ 2);
+ φ -= δ = (sqrt8 *- π / 4) - Math.log(tanφ_2) - y0) / (sqrt8 - .5 * cosφ_2 * cosφ_2 / tanφ_2);
+ } while (Math.abs(δ) > ε2 && --i > 0);
+ return [
+ x / (Math.cos(φ) * (sqrt8 - 1 / Math.sin(φ))),
+ sgn(y) * φ
+ ];
+};
+
+(d3.geo.baker = function() { return projection(baker); }).raw = baker;
@@ -0,0 +1,60 @@
+var berghausAzimuthalEquidistant = d3.geo.azimuthalEquidistant.raw;
+
+function berghaus(n) {
+ var k = 2 * π / n;
+
+ function forward(λ, φ) {
+ var p = berghausAzimuthalEquidistant(λ, φ);
+ if (Math.abs(λ) > π / 2) { // back hemisphere
+ var θ = Math.atan2(p[1], p[0]),
+ r = Math.sqrt(p[0] * p[0] + p[1] * p[1]),
+ θ0 = k * Math.round((θ - π / 2) / k) + π / 2,
+ α = Math.atan2(Math.sin-= θ0), 2 - Math.cos(θ)); // angle relative to lobe end
+ θ = θ0 + asin/ r * Math.sin(α)) - α;
+ p[0] = r * Math.cos(θ);
+ p[1] = r * Math.sin(θ);
+ }
+ return p;
+ }
+
+ return forward;
+}
+
+function berghausProjection() {
+ var n = 5,
+ m = projectionMutator(berghaus),
+ p = m(n),
+ stream_ = p.stream;
+
+ p.lobes = function(_) {
+ if (!arguments.length) return n;
+ return m(n = +_);
+ };
+
+ p.stream = function(stream) {
+ var rotate = p.rotate(),
+ rotateStream = stream_(stream),
+ sphereStream = (p.rotate([0, 0]), stream_(stream));
+ p.rotate(rotate);
+ rotateStream.sphere = function() {
+ sphereStream.polygonStart(), sphereStream.lineStart();
+ var ε = 1e-4;
+ for (var i = 0, δ = 360 / n, φ = 90 - 180 / n; i < n; ++i, φ -= δ) {
+ sphereStream.point(180, 0);
+ if< -90) {
+ sphereStream.point(-90, 180 - φ - ε);
+ sphereStream.point(-90, 180 - φ + ε);
+ } else {
+ sphereStream.point(90, φ + ε);
+ sphereStream.point(90, φ - ε);
+ }
+ }
+ sphereStream.lineEnd(), sphereStream.polygonEnd();
+ };
+ return rotateStream;
+ };
+
+ return p;
+}
+
+(d3.geo.berghaus = berghausProjection).raw = berghaus;
@@ -0,0 +1,27 @@
+// @import mollweide
+
+function boggs(λ, φ) {
+ var k = 2.00276,
+ θ = mollweideθ(φ);
+ return [
+ k * λ / (1 / Math.cos(φ) + 1.11072 / Math.cos(θ)),
+ (φ + Math.SQRT2 * Math.sin(θ)) / k
+ ];
+}
+
+boggs.invert = function(x, y) {
+ var k = 2.00276,
+ ky = k * y,
+ θ = y < 0 ? -π / 4 : π / 4, i = 25, δ, φ;
+ do {
+ φ = ky - Math.SQRT2 * Math.sin(θ);
+ θ -= δ = (Math.sin(2 * θ) + 2 * θ - π * Math.sin(φ)) / (2 * Math.cos(2 * θ) + 2 + π * Math.cos(φ) * Math.SQRT2 * Math.cos(θ));
+ } while (Math.abs(δ) > ε && --i > 0);
+ φ = ky - Math.SQRT2 * Math.sin(θ);
+ return [
+ x * (1 / Math.cos(φ) + 1.11072 / Math.cos(θ)) / k,
+ φ
+ ];
+};
+
+(d3.geo.boggs = function() { return projection(boggs); }).raw = boggs;
@@ -0,0 +1,29 @@
+// @import parallel1
+// @import sinusoidal
+
+function bonne0) {
+ if (!φ0) return sinusoidal;
+ var cotφ0 = 1 / Math.tan0);
+
+ function forward(λ, φ) {
+ var ρ = cotφ0 + φ0 - φ,
+ E = λ * Math.cos(φ) / ρ;
+ return [
+ ρ * Math.sin(E),
+ cotφ0 - ρ * Math.cos(E)
+ ];
+ }
+
+ forward.invert = function(x, y) {
+ var ρ = Math.sqrt(x * x + (y = cotφ0 - y) * y),
+ φ = cotφ0 + φ0 - ρ;
+ return [
+ ρ / Math.cos(φ) * Math.atan2(x, y),
+ φ
+ ];
+ };
+
+ return forward;
+}
+
+(d3.geo.bonne = function() { return parallel1Projection(bonne).parallel(45); }).raw = bonne;
@@ -0,0 +1,5 @@
+// @import mollweide
+
+var bromley = mollweideBromley(1, 4 / π, π);
+
+(d3.geo.bromley = function() { return projection(bromley); }).raw = bromley;
@@ -0,0 +1,17 @@
+function collignon(λ, φ) {
+ var α = asqrt(1 - Math.sin(φ));
+ return [
+ (2 / sqrtπ) * λ * α,
+ sqrtπ * (1 - α)
+ ];
+}
+
+collignon.invert = function(x, y) {
+ var λ == y / sqrtπ - 1) * λ;
+ return [
+ λ > 0 ? x * Math.sqrt/ λ) / 2 : 0,
+ asin(1 - λ)
+ ];
+};
+
+(d3.geo.collignon = function() { return projection(collignon); }).raw = collignon;
@@ -0,0 +1,29 @@
+// @import parallel2
+
+function conicConformal0, φ1) {
+ var cosφ0 = Math.cos0),
+ t = function(φ) { return Math.tan/ 4 + φ / 2); },
+ n = Math.log(cosφ0 / Math.cos1)) / Math.log(t1) / t0)),
+ F = cosφ0 * Math.pow(t0), n) / n;
+
+ function forward(λ, φ) {
+ var ρ = Math.abs(Math.abs(φ) - π / 2) < ε ? 0 : F / Math.pow(t(φ), n);
+ return [
+ ρ * Math.sin(n * λ),
+ F - ρ * Math.cos(n * λ)
+ ];
+ }
+
+ forward.invert = function(x, y) {
+ var ρ0_y = F - y,
+ ρ = sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
+ return [
+ Math.atan2(x, ρ0_y) / n,
+ 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - π / 2
+ ];
+ };
+
+ return forward;
+}
+
+(d3.geo.conicConformal = function() { return parallel2Projection(conicConformal); }).raw = conicConformal;
Oops, something went wrong.

0 comments on commit 15c7d15

Please sign in to comment.