Permalink
Browse files

Add interactive Albers projection explorer.

  • Loading branch information...
1 parent 4c1fd11 commit a54574bcf99230a52acb44776a0382c623525e26 @mbostock mbostock committed Nov 3, 2010
View
44 d3.js
@@ -1,4 +1,4 @@
-d3 = {version: "0.7.0"}; // semver
+d3 = {version: "0.8.0"}; // semver
if (!Date.now) Date.now = function() {
return +new Date();
};
@@ -1753,10 +1753,10 @@ d3.geo = {};
// http://mathworld.wolfram.com/AlbersEqual-AreaConicProjection.html
d3.geo.albers = function() {
- var origin = [-96, 23],
+ var origin = [-98, 38],
parallels = [29.5, 45.5],
scale = 1000,
- translate = [520, 510],
+ translate = [480, 250],
lng0, // d3_radians * origin[0]
n,
C,
@@ -1784,23 +1784,27 @@ d3.geo.albers = function() {
return albers;
}
- albers.origin = function(x, y) {
- origin = [+x, +y];
+ albers.origin = function(x) {
+ if (!arguments.length) return origin;
+ origin = [+x[0], +x[1]];
return reload();
};
- albers.parallels = function(x, y) {
- parallels = [+x, +y];
+ albers.parallels = function(x) {
+ if (!arguments.length) return parallels;
+ parallels = [+x[0], +x[1]];
return reload();
};
albers.scale = function(x) {
+ if (!arguments.length) return scale;
scale = +x;
return albers;
};
- albers.translate = function(x, y) {
- translate = [+x, +y];
+ albers.translate = function(x) {
+ if (!arguments.length) return translate;
+ translate = [+x[0], +x[1]];
return albers;
};
@@ -1813,21 +1817,21 @@ d3.geo.albersUsa = function() {
var lower48 = d3.geo.albers();
var alaska = d3.geo.albers()
- .origin(-160, 60)
- .parallels(55, 65)
- .scale(600)
- .translate(80, 420);
+ .origin([-160, 60])
+ .parallels([55, 65])
+ .scale([600])
+ .translate([80, 420]);
var hawaii = d3.geo.albers()
- .origin(-160, 20)
- .parallels(10, 30)
- .translate(290, 450);
+ .origin([-160, 20])
+ .parallels([10, 30])
+ .translate([290, 450]);
var puertoRico = d3.geo.albers()
- .origin(-60, 10)
- .parallels(0, 20)
- .scale(1500)
- .translate(1060, 680);
+ .origin([-60, 10])
+ .parallels([0, 20])
+ .scale([1500])
+ .translate([1060, 680]);
return function(coordinates) {
var lon = coordinates[0],
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,167 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+ <title>Albers Projection</title>
+ <script type="text/javascript" src="../../d3.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>
+ <style type="text/css">
+
+@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;
+}
+
+#states path {
+ fill: #ccc;
+ stroke: #fff;
+}
+
+#states circle {
+ fill: #fcc;
+ stroke: #000;
+}
+
+div {
+ width: 960px;
+}
+
+ </style>
+ </head>
+ <body>
+ <h3>Albers Projection</h3>
+ <script type="text/javascript">
+
+// Our projection.
+var xy = d3.geo.albers(),
+ path = d3.geo.path().projection(xy);
+
+d3.select("body")
+ .append("svg:svg")
+ .append("svg:g")
+ .attr("id", "states");
+
+d3.json("../../data/us-states.json", function(collection) {
+ d3.select("#states")
+ .selectAll("path")
+ .data(collection.features)
+ .enter("svg:path")
+ .attr("d", path);
+ d3.select("#states")
+ .append("svg:circle")
+ .attr("r", 10)
+ .attr("transform", "translate(" + xy(xy.origin()).join(",") + ")")
+});
+
+function refresh() {
+ d3.selectAll("#states path")
+ .attr("d", path);
+ d3.select("#states circle")
+ .attr("transform", "translate(" + xy(xy.origin()).join(",") + ")")
+ d3.select("#parallels span")
+ .text(xy.parallels());
+ 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]);
+}
+
+ </script><p>
+ <div id="lon">origin.longitude: <span>-98</span></div>
+ <div id="lat">origin.latitude: <span>38</span></div><p>
+ <div id="parallels">parallels: <span>29.5,45.5</span></div><p>
+ <div id="scale">scale: <span>1000</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">
+
+$("#parallels").slider({
+ range: true,
+ min: -180,
+ max: 180,
+ step: 1e-1,
+ values: [29.5, 45.5],
+ slide: function(event, ui) {
+ xy.parallels(ui.values);
+ refresh();
+ }
+});
+
+$("#lon").slider({
+ min: -180,
+ max: 180,
+ step: 1e-1,
+ value: -98,
+ slide: function(event, ui) {
+ var origin = xy.origin();
+ origin[0] = ui.value;
+ xy.origin(origin);
+ refresh();
+ }
+});
+
+$("#lat").slider({
+ min: -180,
+ max: 180,
+ step: 1e-1,
+ value: 38,
+ slide: function(event, ui) {
+ var origin = xy.origin();
+ origin[1] = ui.value;
+ xy.origin(origin);
+ refresh();
+ }
+});
+
+$("#scale").slider({
+ min: 0,
+ max: 3000,
+ value: 1000,
+ 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>
View
@@ -0,0 +1,25 @@
+Copyright (c) 2010 Paul Bakaus, http://jqueryui.com/
+
+This software consists of voluntary contributions made by many
+individuals (AUTHORS.txt, http://jqueryui.com/about) For exact
+contribution history, see the revision history and logs, available
+at http://jquery-ui.googlecode.com/svn/
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit a54574b

Please sign in to comment.