Permalink
Browse files

Merge branch 'azimuthal'

  • Loading branch information...
2 parents 15d7569 + a1cc8cb commit 204e00efde1b2813dae62fc1fe595d6f179146d5 @mbostock mbostock committed May 30, 2011
Showing with 251 additions and 4 deletions.
  1. +1 −0 Makefile
  2. +57 −0 d3.geo.js
  3. +1 −1 d3.geo.min.js
  4. +1 −1 d3.js
  5. +1 −1 d3.min.js
  6. +21 −0 examples/azimuthal/azimuthal.css
  7. +84 −0 examples/azimuthal/azimuthal.html
  8. +27 −0 examples/azimuthal/azimuthal.js
  9. +1 −1 src/core/core.js
  10. +57 −0 src/geo/azimuthal.js
View
@@ -127,6 +127,7 @@ d3.layout.js: \
d3.geo.js: \
src/start.js \
src/geo/geo.js \
+ src/geo/azimuthal.js \
src/geo/albers.js \
src/geo/mercator.js \
src/geo/path.js \
View
@@ -1,4 +1,61 @@
(function(){d3.geo = {};
+// TODO clip input coordinates on opposite hemisphere
+d3.geo.azimuthal = function() {
+ var mode = "orthographic", // or stereographic
+ origin,
+ scale = 200,
+ translate = [480, 250],
+ x0,
+ y0,
+ cy0,
+ sy0;
+
+ function azimuthal(coordinates) {
+ var x1 = coordinates[0] * d3_radians - x0,
+ y1 = coordinates[1] * d3_radians,
+ cx1 = Math.cos(x1),
+ sx1 = Math.sin(x1),
+ cy1 = Math.cos(y1),
+ sy1 = Math.sin(y1),
+ k = mode == "stereographic" ? 1 / (1 + sy0 * sy1 + cy0 * cy1 * cx1) : 1,
+ x = k * cy1 * sx1,
+ y = k * (sy0 * cy1 * cx1 - cy0 * sy1);
+ return [
+ scale * x + translate[0],
+ scale * y + translate[1]
+ ];
+ }
+
+ azimuthal.mode = function(x) {
+ if (!arguments.length) return mode;
+ mode = x;
+ return azimuthal;
+ };
+
+ azimuthal.origin = function(x) {
+ if (!arguments.length) return origin;
+ origin = x;
+ x0 = origin[0] * d3_radians;
+ y0 = origin[1] * d3_radians;
+ cy0 = Math.cos(y0);
+ sy0 = Math.sin(y0);
+ return azimuthal;
+ };
+
+ azimuthal.scale = function(x) {
+ if (!arguments.length) return scale;
+ scale = +x;
+ return azimuthal;
+ };
+
+ azimuthal.translate = function(x) {
+ if (!arguments.length) return translate;
+ translate = [+x[0], +x[1]];
+ return azimuthal;
+ };
+
+ return azimuthal.origin([0, 0]);
+};
// Derived from Tom Carden's Albers implementation for Protovis.
// http://gist.github.com/476238
// http://mathworld.wolfram.com/AlbersEqual-AreaConicProjection.html
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
2 d3.js
@@ -1,4 +1,4 @@
-(function(){d3 = {version: "1.18.0"}; // semver
+(function(){d3 = {version: "1.19.0"}; // semver
if (!Date.now) Date.now = function() {
return +new Date;
};
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,21 @@
+@import url("../../lib/jquery-ui/jquery-ui.css");
+
+body, .ui-widget {
+ font: 14px Helvetica Neue;
+}
+
+svg {
+ width: 960px;
+ height: 500px;
+ border: solid 1px #ccc;
+ background: #eee;
+}
+
+path {
+ fill: #ccc;
+ stroke: #fff;
+}
+
+div {
+ width: 960px;
+}
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+ <title>Polar Stereographic Projection</title>
+ <script type="text/javascript" src="../../d3.js"></script>
+ <script type="text/javascript" src="../../d3.geo.js"></script>
+ <script type="text/javascript" src="../../lib/jquery/jquery.min.js"></script>
+ <script type="text/javascript" src="../../lib/jquery-ui/jquery-ui.min.js"></script>
+ <link type="text/css" rel="stylesheet" href="azimuthal.css"/>
+ </head>
+ <body>
+ <h3>Azimuthal Projection</h3>
+ <script type="text/javascript" src="azimuthal.js"></script><p>
+ <div id="lon">origin.longitude: <span>0</span></div>
+ <div id="lat">origin.latitude: <span>0</span></div><p>
+ <div id="scale">scale: <span>240</span></div><p>
+ <div id="translate-x">translate.x: <span>480</span></div>
+ <div id="translate-y">translate.y: <span>250</span></div>
+ <script type="text/javascript">
+
+$("#lon").slider({
+ min: -180,
+ max: 180,
+ step: 1e-1,
+ value: 0,
+ slide: function(event, ui) {
+ var origin = xy.origin();
+ origin[0] = ui.value;
+ xy.origin(origin);
+ refresh();
+ }
+});
+
+$("#lat").slider({
+ min: -90,
+ max: 90,
+ step: 1e-1,
+ value: 0,
+ slide: function(event, ui) {
+ var origin = xy.origin();
+ origin[1] = ui.value;
+ xy.origin(origin);
+ refresh();
+ }
+});
+
+$("#scale").slider({
+ min: 0,
+ max: 3000,
+ value: 240,
+ slide: function(event, ui) {
+ xy.scale(ui.value);
+ refresh();
+ }
+});
+
+$("#translate-x").slider({
+ min: -2000,
+ max: 2000,
+ value: 480,
+ slide: function(event, ui) {
+ var translate = xy.translate();
+ translate[0] = ui.value;
+ xy.translate(translate);
+ refresh();
+ }
+});
+
+$("#translate-y").slider({
+ min: -2000,
+ max: 2000,
+ value: 250,
+ slide: function(event, ui) {
+ var translate = xy.translate();
+ translate[1] = ui.value;
+ xy.translate(translate);
+ refresh();
+ }
+});
+
+ </script>
+ </body>
+</html>
@@ -0,0 +1,27 @@
+var xy = d3.geo.azimuthal().scale(240).mode("stereographic"),
+ path = d3.geo.path().projection(xy),
+ svg = d3.select("body").append("svg:svg");
+
+d3.json("../../data/world-countries.json", function(collection) {
+ svg.selectAll("path")
+ .data(collection.features)
+ .enter().append("svg:path")
+ .attr("d", path)
+ .append("svg:title")
+ .text(function(d) { return d.properties.name; });
+});
+
+function refresh() {
+ svg.selectAll("path")
+ .attr("d", path);
+ d3.select("#lon span")
+ .text(xy.origin()[0]);
+ d3.select("#lat span")
+ .text(xy.origin()[1]);
+ d3.select("#scale span")
+ .text(xy.scale());
+ d3.select("#translate-x span")
+ .text(xy.translate()[0]);
+ d3.select("#translate-y span")
+ .text(xy.translate()[1]);
+}
View
@@ -1 +1 @@
-d3 = {version: "1.18.0"}; // semver
+d3 = {version: "1.19.0"}; // semver
View
@@ -0,0 +1,57 @@
+// TODO clip input coordinates on opposite hemisphere
+d3.geo.azimuthal = function() {
+ var mode = "orthographic", // or stereographic
+ origin,
+ scale = 200,
+ translate = [480, 250],
+ x0,
+ y0,
+ cy0,
+ sy0;
+
+ function azimuthal(coordinates) {
+ var x1 = coordinates[0] * d3_radians - x0,
+ y1 = coordinates[1] * d3_radians,
+ cx1 = Math.cos(x1),
+ sx1 = Math.sin(x1),
+ cy1 = Math.cos(y1),
+ sy1 = Math.sin(y1),
+ k = mode == "stereographic" ? 1 / (1 + sy0 * sy1 + cy0 * cy1 * cx1) : 1,
+ x = k * cy1 * sx1,
+ y = k * (sy0 * cy1 * cx1 - cy0 * sy1);
+ return [
+ scale * x + translate[0],
+ scale * y + translate[1]
+ ];
+ }
+
+ azimuthal.mode = function(x) {
+ if (!arguments.length) return mode;
+ mode = x;
+ return azimuthal;
+ };
+
+ azimuthal.origin = function(x) {
+ if (!arguments.length) return origin;
+ origin = x;
+ x0 = origin[0] * d3_radians;
+ y0 = origin[1] * d3_radians;
+ cy0 = Math.cos(y0);
+ sy0 = Math.sin(y0);
+ return azimuthal;
+ };
+
+ azimuthal.scale = function(x) {
+ if (!arguments.length) return scale;
+ scale = +x;
+ return azimuthal;
+ };
+
+ azimuthal.translate = function(x) {
+ if (!arguments.length) return translate;
+ translate = [+x[0], +x[1]];
+ return azimuthal;
+ };
+
+ return azimuthal.origin([0, 0]);
+};

0 comments on commit 204e00e

Please sign in to comment.