d3_rails 3.1.10 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NTA3M2VjN2E0MDQyMmMyYmY1YjQ5OTUwMjI2N2QzNDQ4YTg1NGM4NA==
5
- data.tar.gz: !binary |-
6
- NDlhMDcwZmJjOTE1ZmQ1MzE3ZDg4MmQwYzJlN2NhNjZkODZjMGUyZA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YzY2ZmNjNTBmMmMzZWYwZTQyZjFkNTkyZmVkOGNlNTcxNTBkNThhZGQyMGQ3
10
- OGZjZDFiMjM4ZjFkNzU1YjllMjgwZTY2MzY1NDJkMjlhZTg5NjcxYjI4YzE1
11
- N2UwMmM3MjQyOTQ3ZTEzYzg1N2M3NTk4ZWI3ODE3NTNlYjcyMDY=
12
- data.tar.gz: !binary |-
13
- YmE5YjEzODA5ZDk5ZjU5YTBlYzNiNGYwY2RhMDI5ODRmMWJmNmE2ZjBhMjMz
14
- MGVmMjc4MjkxZDY2MDE2Yzc3OTQ1NTc5NjM4OGJmMWJmNzNmNjFjN2Y1YzFl
15
- ZGM0YWU1NmM4N2QzNTVmNGVkZThjNDM4YmE5MDBjZTQ0N2QzZGI=
2
+ SHA1:
3
+ metadata.gz: 52c1827f8a1ceb8e39b78c5b08b5b9cf6fdd2c23
4
+ data.tar.gz: 6ce9930ed1275fb7052bdd7afae54e6e9d6a6beb
5
+ SHA512:
6
+ metadata.gz: 0cb0f283fc524b0dbb54bfb90244e1b9f1df7db98013145f5994973189e50a76ab69fc9f3053ecbd1aa8e5980cb80533ade43e99882757a733cdd7a2fc1c206a
7
+ data.tar.gz: 5f9260692d5ca1cc7b3d1ce8325816c909098d547756cc0f460d88ebff6ad40c514933f52c6957d4ea24bb749f9fa67d638b8b4d31732f77a01bf4936e5c3a1f
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  D3 is a javascript framework created by Michael Bostock
2
2
  ------------------------------------------------------------------------
3
- Copyright (c) 2010, Michael Bostock
3
+ Copyright (c) 2013, Michael Bostock
4
4
  All rights reserved.
5
5
 
6
6
  Redistribution and use in source and binary forms, with or without
@@ -26,4 +26,4 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26
26
  OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
27
  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
28
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
- -----------------------------------------------------------------------------
29
+ -----------------------------------------------------------------------------
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # D3_Rails
2
- ## Version 3.1.10 (of d3 in most current gem)
2
+ ## Version 3.2.0 (of d3 in most current gem)
3
3
 
4
4
  **D3_Rails** is a small, lightweight gem which allows you to include any
5
5
  and all of D3 Javascripts into your 3.1 Rails application, merely by
@@ -1,3 +1,3 @@
1
1
  module D3Rails
2
- VERSION = "3.1.10"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -1,11 +1,11 @@
1
1
  d3 = function() {
2
2
  var d3 = {
3
- version: "3.1.10"
3
+ version: "3.2.0"
4
4
  };
5
5
  if (!Date.now) Date.now = function() {
6
6
  return +new Date();
7
7
  };
8
- var d3_document = document, d3_window = window;
8
+ var d3_document = document, d3_documentElement = d3_document.documentElement, d3_window = window;
9
9
  try {
10
10
  d3_document.createElement("div").style.setProperty("opacity", 0, "");
11
11
  } catch (error) {
@@ -445,7 +445,14 @@ d3 = function() {
445
445
  if (svg.createSVGPoint) {
446
446
  var point = svg.createSVGPoint();
447
447
  if (d3_mouse_bug44083 < 0 && (d3_window.scrollX || d3_window.scrollY)) {
448
- svg = d3.select(d3_document.body).append("svg").style("position", "absolute").style("top", 0).style("left", 0);
448
+ svg = d3.select("body").append("svg").style({
449
+ position: "absolute",
450
+ top: 0,
451
+ left: 0,
452
+ margin: 0,
453
+ padding: 0,
454
+ border: "none"
455
+ }, "important");
449
456
  var ctm = svg[0][0].getScreenCTM();
450
457
  d3_mouse_bug44083 = !(ctm.f || ctm.e);
451
458
  svg.remove();
@@ -473,7 +480,7 @@ d3 = function() {
473
480
  return Array.prototype.slice.call(pseudoarray);
474
481
  }
475
482
  try {
476
- d3_array(d3_document.documentElement.childNodes)[0].nodeType;
483
+ d3_array(d3_documentElement.childNodes)[0].nodeType;
477
484
  } catch (e) {
478
485
  d3_array = d3_arrayCopy;
479
486
  }
@@ -490,13 +497,34 @@ d3 = function() {
490
497
  return point;
491
498
  }) : [];
492
499
  };
500
+ function d3_vendorSymbol(object, name) {
501
+ if (name in object) return name;
502
+ name = name.charAt(0).toUpperCase() + name.substring(1);
503
+ for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
504
+ var prefixName = d3_vendorPrefixes[i] + name;
505
+ if (prefixName in object) return prefixName;
506
+ }
507
+ }
508
+ var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
509
+ var d3_event_userSelectProperty = d3_vendorSymbol(d3_documentElement.style, "userSelect"), d3_event_userSelectSuppress = d3_event_userSelectProperty ? function() {
510
+ var style = d3_documentElement.style, select = style[d3_event_userSelectProperty];
511
+ style[d3_event_userSelectProperty] = "none";
512
+ return function() {
513
+ style[d3_event_userSelectProperty] = select;
514
+ };
515
+ } : function(type) {
516
+ var w = d3.select(d3_window).on("selectstart." + type, d3_eventCancel);
517
+ return function() {
518
+ w.on("selectstart." + type, null);
519
+ };
520
+ };
493
521
  d3.behavior.drag = function() {
494
522
  var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null;
495
523
  function drag() {
496
524
  this.on("mousedown.drag", mousedown).on("touchstart.drag", mousedown);
497
525
  }
498
526
  function mousedown() {
499
- var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, touchId = d3.event.touches ? d3.event.changedTouches[0].identifier : null, offset, origin_ = point(), moved = 0;
527
+ var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, touchId = d3.event.touches ? d3.event.changedTouches[0].identifier : null, offset, origin_ = point(), moved = 0, selectEnable = d3_event_userSelectSuppress(touchId != null ? "drag-" + touchId : "drag");
500
528
  var w = d3.select(d3_window).on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", dragmove).on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", dragend, true);
501
529
  if (origin) {
502
530
  offset = origin.apply(target, arguments);
@@ -504,7 +532,6 @@ d3 = function() {
504
532
  } else {
505
533
  offset = [ 0, 0 ];
506
534
  }
507
- if (touchId == null) d3_eventCancel();
508
535
  event_({
509
536
  type: "dragstart"
510
537
  });
@@ -537,6 +564,7 @@ d3 = function() {
537
564
  if (d3.event.target === eventTarget) d3_eventSuppress(w, "click");
538
565
  }
539
566
  w.on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", null).on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", null);
567
+ selectEnable();
540
568
  }
541
569
  }
542
570
  drag.origin = function(x) {
@@ -554,7 +582,7 @@ d3 = function() {
554
582
  return n.querySelector(s);
555
583
  }, d3_selectAll = function(s, n) {
556
584
  return n.querySelectorAll(s);
557
- }, d3_selectRoot = d3_document.documentElement, d3_selectMatcher = d3_selectRoot.matchesSelector || d3_selectRoot.webkitMatchesSelector || d3_selectRoot.mozMatchesSelector || d3_selectRoot.msMatchesSelector || d3_selectRoot.oMatchesSelector, d3_selectMatches = function(n, s) {
585
+ }, d3_selectMatcher = d3_documentElement[d3_vendorSymbol(d3_documentElement, "matchesSelector")], d3_selectMatches = function(n, s) {
558
586
  return d3_selectMatcher.call(n, s);
559
587
  };
560
588
  if (typeof Sizzle === "function") {
@@ -1047,6 +1075,13 @@ d3 = function() {
1047
1075
  }
1048
1076
  return null;
1049
1077
  };
1078
+ d3_selectionPrototype.size = function() {
1079
+ var n = 0;
1080
+ this.each(function() {
1081
+ ++n;
1082
+ });
1083
+ return n;
1084
+ };
1050
1085
  function d3_selection_enter(selection) {
1051
1086
  d3_arraySubclass(selection, d3_selection_enterPrototype);
1052
1087
  return selection;
@@ -1058,6 +1093,8 @@ d3 = function() {
1058
1093
  d3_selection_enterPrototype.insert = d3_selectionPrototype.insert;
1059
1094
  d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
1060
1095
  d3_selection_enterPrototype.node = d3_selectionPrototype.node;
1096
+ d3_selection_enterPrototype.call = d3_selectionPrototype.call;
1097
+ d3_selection_enterPrototype.size = d3_selectionPrototype.size;
1061
1098
  d3_selection_enterPrototype.select = function(selector) {
1062
1099
  var subgroups = [], subgroup, subnode, upgroup, group, node;
1063
1100
  for (var j = -1, m = this.length; ++j < m; ) {
@@ -1089,15 +1126,15 @@ d3 = function() {
1089
1126
  };
1090
1127
  d3.select = function(node) {
1091
1128
  var group = [ typeof node === "string" ? d3_select(node, d3_document) : node ];
1092
- group.parentNode = d3_selectRoot;
1129
+ group.parentNode = d3_documentElement;
1093
1130
  return d3_selection([ group ]);
1094
1131
  };
1095
1132
  d3.selectAll = function(nodes) {
1096
1133
  var group = d3_array(typeof nodes === "string" ? d3_selectAll(nodes, d3_document) : nodes);
1097
- group.parentNode = d3_selectRoot;
1134
+ group.parentNode = d3_documentElement;
1098
1135
  return d3_selection([ group ]);
1099
1136
  };
1100
- var d3_selectionRoot = d3.select(d3_selectRoot);
1137
+ var d3_selectionRoot = d3.select(d3_documentElement);
1101
1138
  d3.behavior.zoom = function() {
1102
1139
  var translate = [ 0, 0 ], translate0, scale = 1, scale0, scaleExtent = d3_behavior_zoomInfinity, event = d3_eventDispatch(zoom, "zoom"), x0, x1, y0, y1, touchtime;
1103
1140
  function zoom() {
@@ -1168,9 +1205,7 @@ d3 = function() {
1168
1205
  });
1169
1206
  }
1170
1207
  function mousedown() {
1171
- var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, moved = 0, w = d3.select(d3_window).on("mousemove.zoom", mousemove).on("mouseup.zoom", mouseup), l = location(d3.mouse(target));
1172
- d3_window.focus();
1173
- d3_eventCancel();
1208
+ var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, moved = 0, w = d3.select(d3_window).on("mousemove.zoom", mousemove).on("mouseup.zoom", mouseup), l = location(d3.mouse(target)), selectEnable = d3_event_userSelectSuppress("zoom");
1174
1209
  function mousemove() {
1175
1210
  moved = 1;
1176
1211
  translateTo(d3.mouse(target), l);
@@ -1179,6 +1214,7 @@ d3 = function() {
1179
1214
  function mouseup() {
1180
1215
  if (moved) d3_eventCancel();
1181
1216
  w.on("mousemove.zoom", null).on("mouseup.zoom", null);
1217
+ selectEnable();
1182
1218
  if (moved && d3.event.target === eventTarget) d3_eventSuppress(w, "click.zoom");
1183
1219
  }
1184
1220
  }
@@ -1204,7 +1240,6 @@ d3 = function() {
1204
1240
  touches.forEach(function(t) {
1205
1241
  translate0[t.identifier] = location(t);
1206
1242
  });
1207
- d3_eventCancel();
1208
1243
  if (touches.length === 1) {
1209
1244
  if (now - touchtime < 500) {
1210
1245
  var p = touches[0], l = location(touches[0]);
@@ -1283,12 +1318,12 @@ d3 = function() {
1283
1318
  }
1284
1319
  return d3_rgb(vv(h + 120), vv(h), vv(h - 120));
1285
1320
  }
1286
- var π = Math.PI, ε = 1e-6, d3_radians = π / 180, d3_degrees = 180 / π;
1321
+ var π = Math.PI, ε = 1e-6, ε2 = ε * ε, d3_radians = π / 180, d3_degrees = 180 / π;
1287
1322
  function d3_sgn(x) {
1288
1323
  return x > 0 ? 1 : x < 0 ? -1 : 0;
1289
1324
  }
1290
1325
  function d3_acos(x) {
1291
- return Math.acos(Math.max(-1, Math.min(1, x)));
1326
+ return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
1292
1327
  }
1293
1328
  function d3_asin(x) {
1294
1329
  return x > 1 ? π / 2 : x < -1 ? -π / 2 : Math.asin(x);
@@ -1637,7 +1672,8 @@ d3 = function() {
1637
1672
  };
1638
1673
  }
1639
1674
  function d3_xhr(url, mimeType, response, callback) {
1640
- var xhr = {}, dispatch = d3.dispatch("progress", "load", "error"), headers = {}, request = new (d3_window.XDomainRequest && /^(http(s)?:)?\/\//.test(url) ? XDomainRequest : XMLHttpRequest)();
1675
+ var xhr = {}, dispatch = d3.dispatch("progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
1676
+ if (d3_window.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
1641
1677
  "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
1642
1678
  request.readyState > 3 && respond();
1643
1679
  };
@@ -1675,6 +1711,11 @@ d3 = function() {
1675
1711
  mimeType = value == null ? null : value + "";
1676
1712
  return xhr;
1677
1713
  };
1714
+ xhr.responseType = function(value) {
1715
+ if (!arguments.length) return responseType;
1716
+ responseType = value;
1717
+ return xhr;
1718
+ };
1678
1719
  xhr.response = function(value) {
1679
1720
  response = value;
1680
1721
  return xhr;
@@ -1690,6 +1731,7 @@ d3 = function() {
1690
1731
  if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
1691
1732
  if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
1692
1733
  if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
1734
+ if (responseType != null) request.responseType = responseType;
1693
1735
  if (callback != null) xhr.on("error", callback).on("load", function(request) {
1694
1736
  callback(null, request);
1695
1737
  });
@@ -1708,7 +1750,7 @@ d3 = function() {
1708
1750
  callback(error == null ? request : null);
1709
1751
  } : callback;
1710
1752
  }
1711
- function d3_dsv(delimiter, mimeType) {
1753
+ d3.dsv = function(delimiter, mimeType) {
1712
1754
  var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
1713
1755
  function dsv(url, row, callback) {
1714
1756
  if (arguments.length < 3) callback = row, row = null;
@@ -1809,9 +1851,9 @@ d3 = function() {
1809
1851
  return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
1810
1852
  }
1811
1853
  return dsv;
1812
- }
1813
- d3.csv = d3_dsv(",", "text/csv");
1814
- d3.tsv = d3_dsv(" ", "text/tab-separated-values");
1854
+ };
1855
+ d3.csv = d3.dsv(",", "text/csv");
1856
+ d3.tsv = d3.dsv(" ", "text/tab-separated-values");
1815
1857
  var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout;
1816
1858
  d3.timer = function(callback, delay, then) {
1817
1859
  if (arguments.length < 3) {
@@ -1870,7 +1912,7 @@ d3 = function() {
1870
1912
  d3_timer_queueTail = t0;
1871
1913
  return time;
1872
1914
  }
1873
- var d3_timer_frame = d3_window.requestAnimationFrame || d3_window.webkitRequestAnimationFrame || d3_window.mozRequestAnimationFrame || d3_window.oRequestAnimationFrame || d3_window.msRequestAnimationFrame || function(callback) {
1915
+ var d3_timer_frame = d3_window[d3_vendorSymbol(d3_window, "requestAnimationFrame")] || function(callback) {
1874
1916
  setTimeout(callback, 17);
1875
1917
  };
1876
1918
  var d3_format_decimalPoint = ".", d3_format_thousandsSeparator = ",", d3_format_grouping = [ 3, 3 ];
@@ -2018,6 +2060,27 @@ d3 = function() {
2018
2060
  };
2019
2061
  }
2020
2062
  d3.geo = {};
2063
+ function d3_adder() {}
2064
+ d3_adder.prototype = {
2065
+ s: 0,
2066
+ t: 0,
2067
+ add: function(y) {
2068
+ d3_adderSum(y, this.t, d3_adderTemp);
2069
+ d3_adderSum(d3_adderTemp.s, this.s, this);
2070
+ if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
2071
+ },
2072
+ reset: function() {
2073
+ this.s = this.t = 0;
2074
+ },
2075
+ valueOf: function() {
2076
+ return this.s;
2077
+ }
2078
+ };
2079
+ var d3_adderTemp = new d3_adder();
2080
+ function d3_adderSum(a, b, o) {
2081
+ var x = o.s = a + b, bv = x - a, av = x - bv;
2082
+ o.t = a - av + (b - bv);
2083
+ }
2021
2084
  d3.geo.stream = function(object, listener) {
2022
2085
  if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
2023
2086
  d3_geo_streamObjectType[object.type](object, listener);
@@ -2087,7 +2150,7 @@ d3 = function() {
2087
2150
  d3.geo.stream(object, d3_geo_area);
2088
2151
  return d3_geo_areaSum;
2089
2152
  };
2090
- var d3_geo_areaSum, d3_geo_areaRingSum;
2153
+ var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
2091
2154
  var d3_geo_area = {
2092
2155
  sphere: function() {
2093
2156
  d3_geo_areaSum += 4 * π;
@@ -2096,7 +2159,7 @@ d3 = function() {
2096
2159
  lineStart: d3_noop,
2097
2160
  lineEnd: d3_noop,
2098
2161
  polygonStart: function() {
2099
- d3_geo_areaRingSum = 0;
2162
+ d3_geo_areaRingSum.reset();
2100
2163
  d3_geo_area.lineStart = d3_geo_areaRingStart;
2101
2164
  },
2102
2165
  polygonEnd: function() {
@@ -2116,7 +2179,7 @@ d3 = function() {
2116
2179
  λ *= d3_radians;
2117
2180
  φ = φ * d3_radians / 2 + π / 4;
2118
2181
  var dλ = λ - λ0, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(dλ), v = k * Math.sin(dλ);
2119
- d3_geo_areaRingSum += Math.atan2(v, u);
2182
+ d3_geo_areaRingSum.add(Math.atan2(v, u));
2120
2183
  λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
2121
2184
  }
2122
2185
  d3_geo_area.lineEnd = function() {
@@ -2148,7 +2211,7 @@ d3 = function() {
2148
2211
  d[2] /= l;
2149
2212
  }
2150
2213
  function d3_geo_spherical(cartesian) {
2151
- return [ Math.atan2(cartesian[1], cartesian[0]), Math.asin(Math.max(-1, Math.min(1, cartesian[2]))) ];
2214
+ return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
2152
2215
  }
2153
2216
  function d3_geo_sphericalEqual(a, b) {
2154
2217
  return Math.abs(a[0] - b[0]) < ε && Math.abs(a[1] - b[1]) < ε;
@@ -2259,49 +2322,47 @@ d3 = function() {
2259
2322
  φ1 = λ1 = -(λ0 = φ0 = Infinity);
2260
2323
  ranges = [];
2261
2324
  d3.geo.stream(feature, bound);
2262
- ranges.sort(compareRanges);
2263
- for (var i = 1, n = ranges.length, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
2264
- b = ranges[i];
2265
- if (withinRange(b[0], a) || withinRange(b[1], a)) {
2266
- if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
2267
- if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
2268
- } else {
2269
- merged.push(a = b);
2325
+ var n = ranges.length;
2326
+ if (n) {
2327
+ ranges.sort(compareRanges);
2328
+ for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
2329
+ b = ranges[i];
2330
+ if (withinRange(b[0], a) || withinRange(b[1], a)) {
2331
+ if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
2332
+ if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
2333
+ } else {
2334
+ merged.push(a = b);
2335
+ }
2336
+ }
2337
+ var best = -Infinity, dλ;
2338
+ for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
2339
+ b = merged[i];
2340
+ if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
2270
2341
  }
2271
- }
2272
- var best = -Infinity, dλ;
2273
- for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
2274
- b = merged[i];
2275
- if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
2276
2342
  }
2277
2343
  ranges = range = null;
2278
- return [ [ λ0, φ0 ], [ λ1, φ1 ] ];
2344
+ return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
2279
2345
  };
2280
2346
  }();
2281
2347
  d3.geo.centroid = function(object) {
2282
- d3_geo_centroidDimension = d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
2348
+ d3_geo_centroidW0 = d3_geo_centroidW1 = d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
2283
2349
  d3.geo.stream(object, d3_geo_centroid);
2284
- var m;
2285
- if (d3_geo_centroidW && Math.abs(m = Math.sqrt(d3_geo_centroidX * d3_geo_centroidX + d3_geo_centroidY * d3_geo_centroidY + d3_geo_centroidZ * d3_geo_centroidZ)) > ε) {
2286
- return [ Math.atan2(d3_geo_centroidY, d3_geo_centroidX) * d3_degrees, Math.asin(Math.max(-1, Math.min(1, d3_geo_centroidZ / m))) * d3_degrees ];
2350
+ var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
2351
+ if (m < ε2) {
2352
+ x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
2353
+ if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
2354
+ m = x * x + y * y + z * z;
2355
+ if (m < ε2) return [ NaN, NaN ];
2287
2356
  }
2357
+ return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
2288
2358
  };
2289
- var d3_geo_centroidDimension, d3_geo_centroidW, d3_geo_centroidX, d3_geo_centroidY, d3_geo_centroidZ;
2359
+ var d3_geo_centroidW0, d3_geo_centroidW1, d3_geo_centroidX0, d3_geo_centroidY0, d3_geo_centroidZ0, d3_geo_centroidX1, d3_geo_centroidY1, d3_geo_centroidZ1, d3_geo_centroidX2, d3_geo_centroidY2, d3_geo_centroidZ2;
2290
2360
  var d3_geo_centroid = {
2291
- sphere: function() {
2292
- if (d3_geo_centroidDimension < 2) {
2293
- d3_geo_centroidDimension = 2;
2294
- d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
2295
- }
2296
- },
2361
+ sphere: d3_noop,
2297
2362
  point: d3_geo_centroidPoint,
2298
2363
  lineStart: d3_geo_centroidLineStart,
2299
2364
  lineEnd: d3_geo_centroidLineEnd,
2300
2365
  polygonStart: function() {
2301
- if (d3_geo_centroidDimension < 2) {
2302
- d3_geo_centroidDimension = 2;
2303
- d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
2304
- }
2305
2366
  d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
2306
2367
  },
2307
2368
  polygonEnd: function() {
@@ -2309,36 +2370,18 @@ d3 = function() {
2309
2370
  }
2310
2371
  };
2311
2372
  function d3_geo_centroidPoint(λ, φ) {
2312
- if (d3_geo_centroidDimension) return;
2313
- ++d3_geo_centroidW;
2314
2373
  λ *= d3_radians;
2315
2374
  var cosφ = Math.cos(φ *= d3_radians);
2316
- d3_geo_centroidX += (cosφ * Math.cos(λ) - d3_geo_centroidX) / d3_geo_centroidW;
2317
- d3_geo_centroidY += (cosφ * Math.sin(λ) - d3_geo_centroidY) / d3_geo_centroidW;
2318
- d3_geo_centroidZ += (Math.sin(φ) - d3_geo_centroidZ) / d3_geo_centroidW;
2375
+ d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
2319
2376
  }
2320
- function d3_geo_centroidRingStart() {
2321
- var λ00, φ00;
2322
- d3_geo_centroidDimension = 1;
2323
- d3_geo_centroidLineStart();
2324
- d3_geo_centroidDimension = 2;
2325
- var linePoint = d3_geo_centroid.point;
2326
- d3_geo_centroid.point = function(λ, φ) {
2327
- linePoint(λ00 = λ, φ00 = φ);
2328
- };
2329
- d3_geo_centroid.lineEnd = function() {
2330
- d3_geo_centroid.point(λ00, φ00);
2331
- d3_geo_centroidLineEnd();
2332
- d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
2333
- };
2377
+ function d3_geo_centroidPointXYZ(x, y, z) {
2378
+ ++d3_geo_centroidW0;
2379
+ d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
2380
+ d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
2381
+ d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
2334
2382
  }
2335
2383
  function d3_geo_centroidLineStart() {
2336
2384
  var x0, y0, z0;
2337
- if (d3_geo_centroidDimension > 1) return;
2338
- if (d3_geo_centroidDimension < 1) {
2339
- d3_geo_centroidDimension = 1;
2340
- d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
2341
- }
2342
2385
  d3_geo_centroid.point = function(λ, φ) {
2343
2386
  λ *= d3_radians;
2344
2387
  var cosφ = Math.cos(φ *= d3_radians);
@@ -2346,19 +2389,51 @@ d3 = function() {
2346
2389
  y0 = cosφ * Math.sin(λ);
2347
2390
  z0 = Math.sin(φ);
2348
2391
  d3_geo_centroid.point = nextPoint;
2392
+ d3_geo_centroidPointXYZ(x0, y0, z0);
2349
2393
  };
2350
2394
  function nextPoint(λ, φ) {
2351
2395
  λ *= d3_radians;
2352
2396
  var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), w = Math.atan2(Math.sqrt((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);
2353
- d3_geo_centroidW += w;
2354
- d3_geo_centroidX += w * (x0 + (x0 = x));
2355
- d3_geo_centroidY += w * (y0 + (y0 = y));
2356
- d3_geo_centroidZ += w * (z0 + (z0 = z));
2397
+ d3_geo_centroidW1 += w;
2398
+ d3_geo_centroidX1 += w * (x0 + (x0 = x));
2399
+ d3_geo_centroidY1 += w * (y0 + (y0 = y));
2400
+ d3_geo_centroidZ1 += w * (z0 + (z0 = z));
2401
+ d3_geo_centroidPointXYZ(x0, y0, z0);
2357
2402
  }
2358
2403
  }
2359
2404
  function d3_geo_centroidLineEnd() {
2360
2405
  d3_geo_centroid.point = d3_geo_centroidPoint;
2361
2406
  }
2407
+ function d3_geo_centroidRingStart() {
2408
+ var λ00, φ00, x0, y0, z0;
2409
+ d3_geo_centroid.point = function(λ, φ) {
2410
+ λ00 = λ, φ00 = φ;
2411
+ d3_geo_centroid.point = nextPoint;
2412
+ λ *= d3_radians;
2413
+ var cosφ = Math.cos(φ *= d3_radians);
2414
+ x0 = cosφ * Math.cos(λ);
2415
+ y0 = cosφ * Math.sin(λ);
2416
+ z0 = Math.sin(φ);
2417
+ d3_geo_centroidPointXYZ(x0, y0, z0);
2418
+ };
2419
+ d3_geo_centroid.lineEnd = function() {
2420
+ nextPoint(λ00, φ00);
2421
+ d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
2422
+ d3_geo_centroid.point = d3_geo_centroidPoint;
2423
+ };
2424
+ function nextPoint(λ, φ) {
2425
+ λ *= d3_radians;
2426
+ var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), cx = y0 * z - z0 * y, cy = z0 * x - x0 * z, cz = x0 * y - y0 * x, m = Math.sqrt(cx * cx + cy * cy + cz * cz), u = x0 * x + y0 * y + z0 * z, v = m && -d3_acos(u) / m, w = Math.atan2(m, u);
2427
+ d3_geo_centroidX2 += v * cx;
2428
+ d3_geo_centroidY2 += v * cy;
2429
+ d3_geo_centroidZ2 += v * cz;
2430
+ d3_geo_centroidW1 += w;
2431
+ d3_geo_centroidX1 += w * (x0 + (x0 = x));
2432
+ d3_geo_centroidY1 += w * (y0 + (y0 = y));
2433
+ d3_geo_centroidZ1 += w * (z0 + (z0 = z));
2434
+ d3_geo_centroidPointXYZ(x0, y0, z0);
2435
+ }
2436
+ }
2362
2437
  function d3_true() {
2363
2438
  return true;
2364
2439
  }
@@ -2459,7 +2534,7 @@ d3 = function() {
2459
2534
  a.next = b = array[0];
2460
2535
  b.prev = a;
2461
2536
  }
2462
- function d3_geo_clip(pointVisible, clipLine, interpolate) {
2537
+ function d3_geo_clip(pointVisible, clipLine, interpolate, polygonContains) {
2463
2538
  return function(listener) {
2464
2539
  var line = clipLine(listener);
2465
2540
  var clip = {
@@ -2470,9 +2545,8 @@ d3 = function() {
2470
2545
  clip.point = pointRing;
2471
2546
  clip.lineStart = ringStart;
2472
2547
  clip.lineEnd = ringEnd;
2473
- invisible = false;
2474
- invisibleArea = visibleArea = 0;
2475
2548
  segments = [];
2549
+ polygon = [];
2476
2550
  listener.polygonStart();
2477
2551
  },
2478
2552
  polygonEnd: function() {
@@ -2482,13 +2556,13 @@ d3 = function() {
2482
2556
  segments = d3.merge(segments);
2483
2557
  if (segments.length) {
2484
2558
  d3_geo_clipPolygon(segments, d3_geo_clipSort, null, interpolate, listener);
2485
- } else if (visibleArea < -ε || invisible && invisibleArea < -ε) {
2559
+ } else if (polygonContains(polygon)) {
2486
2560
  listener.lineStart();
2487
2561
  interpolate(null, null, 1, listener);
2488
2562
  listener.lineEnd();
2489
2563
  }
2490
2564
  listener.polygonEnd();
2491
- segments = null;
2565
+ segments = polygon = null;
2492
2566
  },
2493
2567
  sphere: function() {
2494
2568
  listener.polygonStart();
@@ -2512,8 +2586,8 @@ d3 = function() {
2512
2586
  clip.point = point;
2513
2587
  line.lineEnd();
2514
2588
  }
2515
- var segments, visibleArea, invisibleArea, invisible;
2516
- var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), ring;
2589
+ var segments;
2590
+ var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygon, ring;
2517
2591
  function pointRing(λ, φ) {
2518
2592
  ringListener.point(λ, φ);
2519
2593
  ring.push([ λ, φ ]);
@@ -2526,16 +2600,12 @@ d3 = function() {
2526
2600
  pointRing(ring[0][0], ring[0][1]);
2527
2601
  ringListener.lineEnd();
2528
2602
  var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
2529
- if (!n) {
2530
- invisible = true;
2531
- invisibleArea += d3_geo_clipAreaRing(ring, -1);
2532
- ring = null;
2533
- return;
2534
- }
2603
+ ring.pop();
2604
+ polygon.push(ring);
2535
2605
  ring = null;
2606
+ if (!n) return;
2536
2607
  if (clean & 1) {
2537
2608
  segment = ringSegments[0];
2538
- visibleArea += d3_geo_clipAreaRing(segment, 1);
2539
2609
  var n = segment.length - 1, i = -1, point;
2540
2610
  listener.lineStart();
2541
2611
  while (++i < n) listener.point((point = segment[i])[0], point[1]);
@@ -2572,26 +2642,41 @@ d3 = function() {
2572
2642
  }
2573
2643
  };
2574
2644
  }
2575
- function d3_geo_clipAreaRing(ring, invisible) {
2576
- if (!(n = ring.length)) return 0;
2577
- var n, i = 0, area = 0, p = ring[0], λ = p[0], φ = p[1], cosφ = Math.cos(φ), x0 = Math.atan2(invisible * Math.sin(λ) * cosφ, Math.sin(φ)), y0 = 1 - invisible * Math.cos(λ) * cosφ, x1 = x0, x, y;
2578
- while (++i < n) {
2579
- p = ring[i];
2580
- cosφ = Math.cos(φ = p[1]);
2581
- x = Math.atan2(invisible * Math.sin(λ = p[0]) * cosφ, Math.sin(φ));
2582
- y = 1 - invisible * Math.cos(λ) * cosφ;
2583
- if (Math.abs(y0 - 2) < ε && Math.abs(y - 2) < ε) continue;
2584
- if (Math.abs(y) < ε || Math.abs(y0) < ε) {} else if (Math.abs(Math.abs(x - x0) - π) < ε) {
2585
- if (y + y0 > 2) area += 4 * (x - x0);
2586
- } else if (Math.abs(y0 - 2) < ε) area += 4 * (x - x1); else area += ((3 * π + x - x0) % (2 * π) - π) * (y0 + y);
2587
- x1 = x0, x0 = x, y0 = y;
2588
- }
2589
- return area;
2590
- }
2591
2645
  function d3_geo_clipSort(a, b) {
2592
2646
  return ((a = a.point)[0] < 0 ? a[1] - π / 2 - ε : π / 2 - a[1]) - ((b = b.point)[0] < 0 ? b[1] - π / 2 - ε : π / 2 - b[1]);
2593
2647
  }
2594
- var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate);
2648
+ function d3_geo_pointInPolygon(point, polygon) {
2649
+ var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, polar = false, southPole = false, winding = 0;
2650
+ d3_geo_areaRingSum.reset();
2651
+ for (var i = 0, n = polygon.length; i < n; ++i) {
2652
+ var ring = polygon[i], m = ring.length;
2653
+ if (!m) continue;
2654
+ var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
2655
+ while (true) {
2656
+ if (j === m) j = 0;
2657
+ point = ring[j];
2658
+ var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, antimeridian = Math.abs(dλ) > π, k = sinφ0 * sinφ;
2659
+ d3_geo_areaRingSum.add(Math.atan2(k * Math.sin(dλ), cosφ0 * cosφ + k * Math.cos(dλ)));
2660
+ if (Math.abs(φ) < ε) southPole = true;
2661
+ polarAngle += antimeridian ? dλ + (dλ >= 0 ? 2 : -2) * π : dλ;
2662
+ if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
2663
+ var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
2664
+ d3_geo_cartesianNormalize(arc);
2665
+ var intersection = d3_geo_cartesianCross(meridianNormal, arc);
2666
+ d3_geo_cartesianNormalize(intersection);
2667
+ var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
2668
+ if (parallel > φarc) {
2669
+ winding += antimeridian ^ dλ >= 0 ? 1 : -1;
2670
+ }
2671
+ }
2672
+ if (!j++) break;
2673
+ λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
2674
+ }
2675
+ if (Math.abs(polarAngle) > ε) polar = true;
2676
+ }
2677
+ return (!southPole && !polar && d3_geo_areaRingSum < 0 || polarAngle < -ε) ^ winding & 1;
2678
+ }
2679
+ var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, d3_geo_clipAntimeridianPolygonContains);
2595
2680
  function d3_geo_clipAntimeridianLine(listener) {
2596
2681
  var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
2597
2682
  return {
@@ -2658,9 +2743,13 @@ d3 = function() {
2658
2743
  listener.point(to[0], to[1]);
2659
2744
  }
2660
2745
  }
2746
+ var d3_geo_clipAntimeridianPoint = [ -π, 0 ];
2747
+ function d3_geo_clipAntimeridianPolygonContains(polygon) {
2748
+ return d3_geo_pointInPolygon(d3_geo_clipAntimeridianPoint, polygon);
2749
+ }
2661
2750
  function d3_geo_clipCircle(radius) {
2662
- var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = Math.abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
2663
- return d3_geo_clip(visible, clipLine, interpolate);
2751
+ var cr = Math.cos(radius), smallRadius = cr > 0, point = [ radius, 0 ], notHemisphere = Math.abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
2752
+ return d3_geo_clip(visible, clipLine, interpolate, polygonContains);
2664
2753
  function visible(λ, φ) {
2665
2754
  return Math.cos(λ) * Math.cos(φ) > cr;
2666
2755
  }
@@ -2753,6 +2842,9 @@ d3 = function() {
2753
2842
  if (φ < -r) code |= 4; else if (φ > r) code |= 8;
2754
2843
  return code;
2755
2844
  }
2845
+ function polygonContains(polygon) {
2846
+ return d3_geo_pointInPolygon(point, polygon);
2847
+ }
2756
2848
  }
2757
2849
  var d3_geo_clipViewMAX = 1e9;
2758
2850
  function d3_geo_clipView(x0, y0, x1, y1) {
@@ -2916,798 +3008,820 @@ d3 = function() {
2916
3008
  };
2917
3009
  return compose;
2918
3010
  }
2919
- function d3_geo_resample(project) {
2920
- var δ2 = .5, maxDepth = 16;
2921
- function resample(stream) {
2922
- var λ0, x0, y0, a0, b0, c0;
2923
- var resample = {
2924
- point: point,
2925
- lineStart: lineStart,
2926
- lineEnd: lineEnd,
3011
+ function d3_geo_conic(projectAt) {
3012
+ var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
3013
+ p.parallels = function(_) {
3014
+ if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
3015
+ return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
3016
+ };
3017
+ return p;
3018
+ }
3019
+ function d3_geo_conicEqualArea(φ0, φ1) {
3020
+ var sinφ0 = Math.sin(φ0), n = (sinφ0 + Math.sin(φ1)) / 2, C = 1 + sinφ0 * (2 * n - sinφ0), ρ0 = Math.sqrt(C) / n;
3021
+ function forward(λ, φ) {
3022
+ var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
3023
+ return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
3024
+ }
3025
+ forward.invert = function(x, y) {
3026
+ var ρ0_y = ρ0 - y;
3027
+ return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
3028
+ };
3029
+ return forward;
3030
+ }
3031
+ (d3.geo.conicEqualArea = function() {
3032
+ return d3_geo_conic(d3_geo_conicEqualArea);
3033
+ }).raw = d3_geo_conicEqualArea;
3034
+ d3.geo.albers = function() {
3035
+ return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
3036
+ };
3037
+ d3.geo.albersUsa = function() {
3038
+ var lower48 = d3.geo.albers();
3039
+ var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
3040
+ var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
3041
+ var point, pointStream = {
3042
+ point: function(x, y) {
3043
+ point = [ x, y ];
3044
+ }
3045
+ }, lower48Point, alaskaPoint, hawaiiPoint;
3046
+ function albersUsa(coordinates) {
3047
+ var x = coordinates[0], y = coordinates[1];
3048
+ point = null;
3049
+ (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
3050
+ return point;
3051
+ }
3052
+ albersUsa.invert = function(coordinates) {
3053
+ var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
3054
+ return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
3055
+ };
3056
+ albersUsa.stream = function(stream) {
3057
+ var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
3058
+ return {
3059
+ point: function(x, y) {
3060
+ lower48Stream.point(x, y);
3061
+ alaskaStream.point(x, y);
3062
+ hawaiiStream.point(x, y);
3063
+ },
3064
+ sphere: function() {
3065
+ lower48Stream.sphere();
3066
+ alaskaStream.sphere();
3067
+ hawaiiStream.sphere();
3068
+ },
3069
+ lineStart: function() {
3070
+ lower48Stream.lineStart();
3071
+ alaskaStream.lineStart();
3072
+ hawaiiStream.lineStart();
3073
+ },
3074
+ lineEnd: function() {
3075
+ lower48Stream.lineEnd();
3076
+ alaskaStream.lineEnd();
3077
+ hawaiiStream.lineEnd();
3078
+ },
2927
3079
  polygonStart: function() {
2928
- stream.polygonStart();
2929
- resample.lineStart = polygonLineStart;
3080
+ lower48Stream.polygonStart();
3081
+ alaskaStream.polygonStart();
3082
+ hawaiiStream.polygonStart();
2930
3083
  },
2931
3084
  polygonEnd: function() {
2932
- stream.polygonEnd();
2933
- resample.lineStart = lineStart;
3085
+ lower48Stream.polygonEnd();
3086
+ alaskaStream.polygonEnd();
3087
+ hawaiiStream.polygonEnd();
2934
3088
  }
2935
3089
  };
2936
- function point(x, y) {
2937
- x = project(x, y);
2938
- stream.point(x[0], x[1]);
2939
- }
2940
- function lineStart() {
2941
- x0 = NaN;
2942
- resample.point = linePoint;
2943
- stream.lineStart();
2944
- }
2945
- function linePoint(λ, φ) {
2946
- var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
2947
- resampleLineTo(x0, y0, λ0, a0, b0, c0, x0 = p[0], y0 = p[1], λ0 = λ, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
2948
- stream.point(x0, y0);
2949
- }
2950
- function lineEnd() {
2951
- resample.point = point;
2952
- stream.lineEnd();
2953
- }
2954
- function polygonLineStart() {
2955
- var λ00, φ00, x00, y00, a00, b00, c00;
2956
- lineStart();
2957
- resample.point = function(λ, φ) {
2958
- linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
2959
- resample.point = linePoint;
2960
- };
2961
- resample.lineEnd = function() {
2962
- resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
2963
- resample.lineEnd = lineEnd;
2964
- lineEnd();
2965
- };
2966
- }
2967
- return resample;
3090
+ };
3091
+ albersUsa.precision = function(_) {
3092
+ if (!arguments.length) return lower48.precision();
3093
+ lower48.precision(_);
3094
+ alaska.precision(_);
3095
+ hawaii.precision(_);
3096
+ return albersUsa;
3097
+ };
3098
+ albersUsa.scale = function(_) {
3099
+ if (!arguments.length) return lower48.scale();
3100
+ lower48.scale(_);
3101
+ alaska.scale(_ * .35);
3102
+ hawaii.scale(_);
3103
+ return albersUsa.translate(lower48.translate());
3104
+ };
3105
+ albersUsa.translate = function(_) {
3106
+ if (!arguments.length) return lower48.translate();
3107
+ var k = lower48.scale(), x = +_[0], y = +_[1];
3108
+ lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
3109
+ alaskaPoint = alaska.translate([ x - .307 * k, y + .201 * k ]).clipExtent([ [ x - .425 * k + ε, y + .12 * k + ε ], [ x - .214 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
3110
+ hawaiiPoint = hawaii.translate([ x - .205 * k, y + .212 * k ]).clipExtent([ [ x - .214 * k + ε, y + .166 * k + ε ], [ x - .115 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
3111
+ return albersUsa;
3112
+ };
3113
+ return albersUsa.scale(1070);
3114
+ };
3115
+ var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
3116
+ point: d3_noop,
3117
+ lineStart: d3_noop,
3118
+ lineEnd: d3_noop,
3119
+ polygonStart: function() {
3120
+ d3_geo_pathAreaPolygon = 0;
3121
+ d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
3122
+ },
3123
+ polygonEnd: function() {
3124
+ d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
3125
+ d3_geo_pathAreaSum += Math.abs(d3_geo_pathAreaPolygon / 2);
2968
3126
  }
2969
- function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
2970
- var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
2971
- if (d2 > 4 * δ2 && depth--) {
2972
- var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = Math.abs(Math.abs(c) - 1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
2973
- if (dz * dz / d2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / d2 - .5) > .3) {
2974
- resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
2975
- stream.point(x2, y2);
2976
- resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
2977
- }
2978
- }
3127
+ };
3128
+ function d3_geo_pathAreaRingStart() {
3129
+ var x00, y00, x0, y0;
3130
+ d3_geo_pathArea.point = function(x, y) {
3131
+ d3_geo_pathArea.point = nextPoint;
3132
+ x00 = x0 = x, y00 = y0 = y;
3133
+ };
3134
+ function nextPoint(x, y) {
3135
+ d3_geo_pathAreaPolygon += y0 * x - x0 * y;
3136
+ x0 = x, y0 = y;
2979
3137
  }
2980
- resample.precision = function(_) {
2981
- if (!arguments.length) return Math.sqrt(δ2);
2982
- maxDepth = (δ2 = _ * _) > 0 && 16;
2983
- return resample;
3138
+ d3_geo_pathArea.lineEnd = function() {
3139
+ nextPoint(x00, y00);
2984
3140
  };
2985
- return resample;
2986
3141
  }
2987
- d3.geo.projection = d3_geo_projection;
2988
- d3.geo.projectionMutator = d3_geo_projectionMutator;
2989
- function d3_geo_projection(project) {
2990
- return d3_geo_projectionMutator(function() {
2991
- return project;
2992
- })();
3142
+ var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
3143
+ var d3_geo_pathBounds = {
3144
+ point: d3_geo_pathBoundsPoint,
3145
+ lineStart: d3_noop,
3146
+ lineEnd: d3_noop,
3147
+ polygonStart: d3_noop,
3148
+ polygonEnd: d3_noop
3149
+ };
3150
+ function d3_geo_pathBoundsPoint(x, y) {
3151
+ if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
3152
+ if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
3153
+ if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
3154
+ if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
2993
3155
  }
2994
- function d3_geo_projectionMutator(projectAt) {
2995
- var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
2996
- x = project(x, y);
2997
- return [ x[0] * k + δx, δy - x[1] * k ];
2998
- }), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, preclip = d3_geo_clipAntimeridian, postclip = d3_identity, clipAngle = null, clipExtent = null;
2999
- function projection(point) {
3000
- point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
3001
- return [ point[0] * k + δx, δy - point[1] * k ];
3002
- }
3003
- function invert(point) {
3004
- point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
3005
- return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
3006
- }
3007
- projection.stream = function(stream) {
3008
- return d3_geo_projectionRadiansRotate(rotate, preclip(projectResample(postclip(stream))));
3009
- };
3010
- projection.clipAngle = function(_) {
3011
- if (!arguments.length) return clipAngle;
3012
- preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
3013
- return projection;
3014
- };
3015
- projection.clipExtent = function(_) {
3016
- if (!arguments.length) return clipExtent;
3017
- clipExtent = _;
3018
- postclip = _ == null ? d3_identity : d3_geo_clipView(_[0][0], _[0][1], _[1][0], _[1][1]);
3019
- return projection;
3020
- };
3021
- projection.scale = function(_) {
3022
- if (!arguments.length) return k;
3023
- k = +_;
3024
- return reset();
3025
- };
3026
- projection.translate = function(_) {
3027
- if (!arguments.length) return [ x, y ];
3028
- x = +_[0];
3029
- y = +_[1];
3030
- return reset();
3031
- };
3032
- projection.center = function(_) {
3033
- if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
3034
- λ = _[0] % 360 * d3_radians;
3035
- φ = _[1] % 360 * d3_radians;
3036
- return reset();
3037
- };
3038
- projection.rotate = function(_) {
3039
- if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
3040
- δλ = _[0] % 360 * d3_radians;
3041
- δφ = _[1] % 360 * d3_radians;
3042
- δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
3043
- return reset();
3044
- };
3045
- d3.rebind(projection, projectResample, "precision");
3046
- function reset() {
3047
- projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
3048
- var center = project(λ, φ);
3049
- δx = x - center[0] * k;
3050
- δy = y + center[1] * k;
3051
- return projection;
3052
- }
3053
- return function() {
3054
- project = projectAt.apply(this, arguments);
3055
- projection.invert = project.invert && invert;
3056
- return reset();
3057
- };
3058
- }
3059
- function d3_geo_projectionRadiansRotate(rotate, stream) {
3060
- return {
3061
- point: function(x, y) {
3062
- y = rotate(x * d3_radians, y * d3_radians), x = y[0];
3063
- stream.point(x > π ? x - 2 * π : x < -π ? x + 2 * π : x, y[1]);
3064
- },
3065
- sphere: function() {
3066
- stream.sphere();
3067
- },
3156
+ function d3_geo_pathBuffer() {
3157
+ var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
3158
+ var stream = {
3159
+ point: point,
3068
3160
  lineStart: function() {
3069
- stream.lineStart();
3070
- },
3071
- lineEnd: function() {
3072
- stream.lineEnd();
3161
+ stream.point = pointLineStart;
3073
3162
  },
3163
+ lineEnd: lineEnd,
3074
3164
  polygonStart: function() {
3075
- stream.polygonStart();
3165
+ stream.lineEnd = lineEndPolygon;
3076
3166
  },
3077
3167
  polygonEnd: function() {
3078
- stream.polygonEnd();
3168
+ stream.lineEnd = lineEnd;
3169
+ stream.point = point;
3170
+ },
3171
+ pointRadius: function(_) {
3172
+ pointCircle = d3_geo_pathBufferCircle(_);
3173
+ return stream;
3174
+ },
3175
+ result: function() {
3176
+ if (buffer.length) {
3177
+ var result = buffer.join("");
3178
+ buffer = [];
3179
+ return result;
3180
+ }
3079
3181
  }
3080
3182
  };
3183
+ function point(x, y) {
3184
+ buffer.push("M", x, ",", y, pointCircle);
3185
+ }
3186
+ function pointLineStart(x, y) {
3187
+ buffer.push("M", x, ",", y);
3188
+ stream.point = pointLine;
3189
+ }
3190
+ function pointLine(x, y) {
3191
+ buffer.push("L", x, ",", y);
3192
+ }
3193
+ function lineEnd() {
3194
+ stream.point = point;
3195
+ }
3196
+ function lineEndPolygon() {
3197
+ buffer.push("Z");
3198
+ }
3199
+ return stream;
3081
3200
  }
3082
- function d3_geo_equirectangular(λ, φ) {
3083
- return [ λ, φ ];
3201
+ function d3_geo_pathBufferCircle(radius) {
3202
+ return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
3084
3203
  }
3085
- (d3.geo.equirectangular = function() {
3086
- return d3_geo_projection(d3_geo_equirectangular);
3087
- }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
3088
- d3.geo.rotation = function(rotate) {
3089
- rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
3090
- function forward(coordinates) {
3091
- coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
3092
- return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
3204
+ var d3_geo_pathCentroid = {
3205
+ point: d3_geo_pathCentroidPoint,
3206
+ lineStart: d3_geo_pathCentroidLineStart,
3207
+ lineEnd: d3_geo_pathCentroidLineEnd,
3208
+ polygonStart: function() {
3209
+ d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
3210
+ },
3211
+ polygonEnd: function() {
3212
+ d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
3213
+ d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
3214
+ d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
3093
3215
  }
3094
- forward.invert = function(coordinates) {
3095
- coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
3096
- return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
3097
- };
3098
- return forward;
3099
3216
  };
3100
- function d3_geo_rotation(δλ, δφ, δγ) {
3101
- return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_equirectangular;
3217
+ function d3_geo_pathCentroidPoint(x, y) {
3218
+ d3_geo_centroidX0 += x;
3219
+ d3_geo_centroidY0 += y;
3220
+ ++d3_geo_centroidZ0;
3102
3221
  }
3103
- function d3_geo_forwardRotationλ(δλ) {
3104
- return function(λ, φ) {
3105
- return λ += δλ, [ λ > π ? λ - 2 * π : λ < -π ? λ + 2 * π : λ, φ ];
3222
+ function d3_geo_pathCentroidLineStart() {
3223
+ var x0, y0;
3224
+ d3_geo_pathCentroid.point = function(x, y) {
3225
+ d3_geo_pathCentroid.point = nextPoint;
3226
+ d3_geo_pathCentroidPoint(x0 = x, y0 = y);
3106
3227
  };
3228
+ function nextPoint(x, y) {
3229
+ var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
3230
+ d3_geo_centroidX1 += z * (x0 + x) / 2;
3231
+ d3_geo_centroidY1 += z * (y0 + y) / 2;
3232
+ d3_geo_centroidZ1 += z;
3233
+ d3_geo_pathCentroidPoint(x0 = x, y0 = y);
3234
+ }
3107
3235
  }
3108
- function d3_geo_rotationλ(δλ) {
3109
- var rotation = d3_geo_forwardRotationλ(δλ);
3110
- rotation.invert = d3_geo_forwardRotationλ(-δλ);
3111
- return rotation;
3236
+ function d3_geo_pathCentroidLineEnd() {
3237
+ d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
3112
3238
  }
3113
- function d3_geo_rotationφγ(δφ, δγ) {
3114
- var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
3115
- function rotation(λ, φ) {
3116
- var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
3117
- return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), Math.asin(Math.max(-1, Math.min(1, k * cosδγ + y * sinδγ))) ];
3118
- }
3119
- rotation.invert = function(λ, φ) {
3120
- var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
3121
- return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), Math.asin(Math.max(-1, Math.min(1, k * cosδφ - x * sinδφ))) ];
3239
+ function d3_geo_pathCentroidRingStart() {
3240
+ var x00, y00, x0, y0;
3241
+ d3_geo_pathCentroid.point = function(x, y) {
3242
+ d3_geo_pathCentroid.point = nextPoint;
3243
+ d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
3122
3244
  };
3123
- return rotation;
3124
- }
3125
- d3.geo.circle = function() {
3126
- var origin = [ 0, 0 ], angle, precision = 6, interpolate;
3127
- function circle() {
3128
- var center = typeof origin === "function" ? origin.apply(this, arguments) : origin, rotate = d3_geo_rotation(-center[0] * d3_radians, -center[1] * d3_radians, 0).invert, ring = [];
3129
- interpolate(null, null, 1, {
3130
- point: function(x, y) {
3131
- ring.push(x = rotate(x, y));
3132
- x[0] *= d3_degrees, x[1] *= d3_degrees;
3133
- }
3134
- });
3135
- return {
3136
- type: "Polygon",
3137
- coordinates: [ ring ]
3138
- };
3245
+ function nextPoint(x, y) {
3246
+ var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
3247
+ d3_geo_centroidX1 += z * (x0 + x) / 2;
3248
+ d3_geo_centroidY1 += z * (y0 + y) / 2;
3249
+ d3_geo_centroidZ1 += z;
3250
+ z = y0 * x - x0 * y;
3251
+ d3_geo_centroidX2 += z * (x0 + x);
3252
+ d3_geo_centroidY2 += z * (y0 + y);
3253
+ d3_geo_centroidZ2 += z * 3;
3254
+ d3_geo_pathCentroidPoint(x0 = x, y0 = y);
3139
3255
  }
3140
- circle.origin = function(x) {
3141
- if (!arguments.length) return origin;
3142
- origin = x;
3143
- return circle;
3144
- };
3145
- circle.angle = function(x) {
3146
- if (!arguments.length) return angle;
3147
- interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
3148
- return circle;
3149
- };
3150
- circle.precision = function(_) {
3151
- if (!arguments.length) return precision;
3152
- interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
3153
- return circle;
3154
- };
3155
- return circle.angle(90);
3156
- };
3157
- function d3_geo_circleInterpolate(radius, precision) {
3158
- var cr = Math.cos(radius), sr = Math.sin(radius);
3159
- return function(from, to, direction, listener) {
3160
- if (from != null) {
3161
- from = d3_geo_circleAngle(cr, from);
3162
- to = d3_geo_circleAngle(cr, to);
3163
- if (direction > 0 ? from < to : from > to) from += direction * 2 * π;
3164
- } else {
3165
- from = radius + direction * 2 * π;
3166
- to = radius;
3167
- }
3168
- var point;
3169
- for (var step = direction * precision, t = from; direction > 0 ? t > to : t < to; t -= step) {
3170
- listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
3171
- }
3256
+ d3_geo_pathCentroid.lineEnd = function() {
3257
+ nextPoint(x00, y00);
3172
3258
  };
3173
3259
  }
3174
- function d3_geo_circleAngle(cr, point) {
3175
- var a = d3_geo_cartesian(point);
3176
- a[0] -= cr;
3177
- d3_geo_cartesianNormalize(a);
3178
- var angle = d3_acos(-a[1]);
3179
- return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
3180
- }
3181
- d3.geo.distance = function(a, b) {
3182
- var Δλ = (b[0] - a[0]) * d3_radians, φ0 = a[1] * d3_radians, φ1 = b[1] * d3_radians, sinΔλ = Math.sin(Δλ), cosΔλ = Math.cos(Δλ), sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1), t;
3183
- return Math.atan2(Math.sqrt((t = cosφ1 * sinΔλ) * t + (t = cosφ0 * sinφ1 - sinφ0 * cosφ1 * cosΔλ) * t), sinφ0 * sinφ1 + cosφ0 * cosφ1 * cosΔλ);
3184
- };
3185
- d3.geo.graticule = function() {
3186
- var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
3187
- function graticule() {
3188
- return {
3189
- type: "MultiLineString",
3190
- coordinates: lines()
3191
- };
3260
+ function d3_geo_pathContext(context) {
3261
+ var pointRadius = 4.5;
3262
+ var stream = {
3263
+ point: point,
3264
+ lineStart: function() {
3265
+ stream.point = pointLineStart;
3266
+ },
3267
+ lineEnd: lineEnd,
3268
+ polygonStart: function() {
3269
+ stream.lineEnd = lineEndPolygon;
3270
+ },
3271
+ polygonEnd: function() {
3272
+ stream.lineEnd = lineEnd;
3273
+ stream.point = point;
3274
+ },
3275
+ pointRadius: function(_) {
3276
+ pointRadius = _;
3277
+ return stream;
3278
+ },
3279
+ result: d3_noop
3280
+ };
3281
+ function point(x, y) {
3282
+ context.moveTo(x, y);
3283
+ context.arc(x, y, pointRadius, 0, 2 * π);
3192
3284
  }
3193
- function lines() {
3194
- return d3.range(Math.ceil(X0 / DX) * DX, X1, DX).map(X).concat(d3.range(Math.ceil(Y0 / DY) * DY, Y1, DY).map(Y)).concat(d3.range(Math.ceil(x0 / dx) * dx, x1, dx).filter(function(x) {
3195
- return Math.abs(x % DX) > ε;
3196
- }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
3197
- return Math.abs(y % DY) > ε;
3198
- }).map(y));
3285
+ function pointLineStart(x, y) {
3286
+ context.moveTo(x, y);
3287
+ stream.point = pointLine;
3199
3288
  }
3200
- graticule.lines = function() {
3201
- return lines().map(function(coordinates) {
3202
- return {
3203
- type: "LineString",
3204
- coordinates: coordinates
3205
- };
3206
- });
3207
- };
3208
- graticule.outline = function() {
3209
- return {
3210
- type: "Polygon",
3211
- coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
3212
- };
3213
- };
3214
- graticule.extent = function(_) {
3215
- if (!arguments.length) return graticule.minorExtent();
3216
- return graticule.majorExtent(_).minorExtent(_);
3217
- };
3218
- graticule.majorExtent = function(_) {
3219
- if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
3220
- X0 = +_[0][0], X1 = +_[1][0];
3221
- Y0 = +_[0][1], Y1 = +_[1][1];
3222
- if (X0 > X1) _ = X0, X0 = X1, X1 = _;
3223
- if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
3224
- return graticule.precision(precision);
3225
- };
3226
- graticule.minorExtent = function(_) {
3227
- if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
3228
- x0 = +_[0][0], x1 = +_[1][0];
3229
- y0 = +_[0][1], y1 = +_[1][1];
3230
- if (x0 > x1) _ = x0, x0 = x1, x1 = _;
3231
- if (y0 > y1) _ = y0, y0 = y1, y1 = _;
3232
- return graticule.precision(precision);
3233
- };
3234
- graticule.step = function(_) {
3235
- if (!arguments.length) return graticule.minorStep();
3236
- return graticule.majorStep(_).minorStep(_);
3237
- };
3238
- graticule.majorStep = function(_) {
3239
- if (!arguments.length) return [ DX, DY ];
3240
- DX = +_[0], DY = +_[1];
3241
- return graticule;
3242
- };
3243
- graticule.minorStep = function(_) {
3244
- if (!arguments.length) return [ dx, dy ];
3245
- dx = +_[0], dy = +_[1];
3246
- return graticule;
3247
- };
3248
- graticule.precision = function(_) {
3249
- if (!arguments.length) return precision;
3250
- precision = +_;
3251
- x = d3_geo_graticuleX(y0, y1, 90);
3252
- y = d3_geo_graticuleY(x0, x1, precision);
3253
- X = d3_geo_graticuleX(Y0, Y1, 90);
3254
- Y = d3_geo_graticuleY(X0, X1, precision);
3255
- return graticule;
3256
- };
3257
- return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
3258
- };
3259
- function d3_geo_graticuleX(y0, y1, dy) {
3260
- var y = d3.range(y0, y1 - ε, dy).concat(y1);
3261
- return function(x) {
3262
- return y.map(function(y) {
3263
- return [ x, y ];
3264
- });
3265
- };
3266
- }
3267
- function d3_geo_graticuleY(x0, x1, dx) {
3268
- var x = d3.range(x0, x1 - ε, dx).concat(x1);
3269
- return function(y) {
3270
- return x.map(function(x) {
3271
- return [ x, y ];
3272
- });
3273
- };
3274
- }
3275
- function d3_source(d) {
3276
- return d.source;
3277
- }
3278
- function d3_target(d) {
3279
- return d.target;
3280
- }
3281
- d3.geo.greatArc = function() {
3282
- var source = d3_source, source_, target = d3_target, target_;
3283
- function greatArc() {
3284
- return {
3285
- type: "LineString",
3286
- coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
3287
- };
3289
+ function pointLine(x, y) {
3290
+ context.lineTo(x, y);
3288
3291
  }
3289
- greatArc.distance = function() {
3290
- return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
3291
- };
3292
- greatArc.source = function(_) {
3293
- if (!arguments.length) return source;
3294
- source = _, source_ = typeof _ === "function" ? null : _;
3295
- return greatArc;
3296
- };
3297
- greatArc.target = function(_) {
3298
- if (!arguments.length) return target;
3299
- target = _, target_ = typeof _ === "function" ? null : _;
3300
- return greatArc;
3301
- };
3302
- greatArc.precision = function() {
3303
- return arguments.length ? greatArc : 0;
3304
- };
3305
- return greatArc;
3306
- };
3307
- d3.geo.interpolate = function(source, target) {
3308
- return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
3309
- };
3310
- function d3_geo_interpolate(x0, y0, x1, y1) {
3311
- var cy0 = Math.cos(y0), sy0 = Math.sin(y0), cy1 = Math.cos(y1), sy1 = Math.sin(y1), kx0 = cy0 * Math.cos(x0), ky0 = cy0 * Math.sin(x0), kx1 = cy1 * Math.cos(x1), ky1 = cy1 * Math.sin(x1), d = 2 * Math.asin(Math.sqrt(d3_haversin(y1 - y0) + cy0 * cy1 * d3_haversin(x1 - x0))), k = 1 / Math.sin(d);
3312
- var interpolate = d ? function(t) {
3313
- var B = Math.sin(t *= d) * k, A = Math.sin(d - t) * k, x = A * kx0 + B * kx1, y = A * ky0 + B * ky1, z = A * sy0 + B * sy1;
3314
- return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
3315
- } : function() {
3316
- return [ x0 * d3_degrees, y0 * d3_degrees ];
3317
- };
3318
- interpolate.distance = d;
3319
- return interpolate;
3292
+ function lineEnd() {
3293
+ stream.point = point;
3294
+ }
3295
+ function lineEndPolygon() {
3296
+ context.closePath();
3297
+ }
3298
+ return stream;
3320
3299
  }
3321
- d3.geo.length = function(object) {
3322
- d3_geo_lengthSum = 0;
3323
- d3.geo.stream(object, d3_geo_length);
3324
- return d3_geo_lengthSum;
3325
- };
3326
- var d3_geo_lengthSum;
3327
- var d3_geo_length = {
3328
- sphere: d3_noop,
3329
- point: d3_noop,
3330
- lineStart: d3_geo_lengthLineStart,
3331
- lineEnd: d3_noop,
3332
- polygonStart: d3_noop,
3333
- polygonEnd: d3_noop
3334
- };
3335
- function d3_geo_lengthLineStart() {
3336
- var λ0, sinφ0, cosφ0;
3337
- d3_geo_length.point = function(λ, φ) {
3338
- λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
3339
- d3_geo_length.point = nextPoint;
3340
- };
3341
- d3_geo_length.lineEnd = function() {
3342
- d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
3343
- };
3344
- function nextPoint(λ, φ) {
3345
- var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = Math.abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
3346
- d3_geo_lengthSum += Math.atan2(Math.sqrt((t = cosφ * Math.sin(t)) * t + (t = cosφ0 * sinφ - sinφ0 * cosφ * cosΔλ) * t), sinφ0 * sinφ + cosφ0 * cosφ * cosΔλ);
3347
- λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
3300
+ function d3_geo_resample(project) {
3301
+ var δ2 = .5, maxDepth = 16;
3302
+ function resample(stream) {
3303
+ var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
3304
+ var resample = {
3305
+ point: point,
3306
+ lineStart: lineStart,
3307
+ lineEnd: lineEnd,
3308
+ polygonStart: function() {
3309
+ stream.polygonStart();
3310
+ resample.lineStart = ringStart;
3311
+ },
3312
+ polygonEnd: function() {
3313
+ stream.polygonEnd();
3314
+ resample.lineStart = lineStart;
3315
+ }
3316
+ };
3317
+ function point(x, y) {
3318
+ x = project(x, y);
3319
+ stream.point(x[0], x[1]);
3320
+ }
3321
+ function lineStart() {
3322
+ x0 = NaN;
3323
+ resample.point = linePoint;
3324
+ stream.lineStart();
3325
+ }
3326
+ function linePoint(λ, φ) {
3327
+ var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ), buffer = [];
3328
+ resampleLineTo(x0, y0, λ0, a0, b0, c0, x0 = p[0], y0 = p[1], λ0 = λ, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, buffer);
3329
+ streamLine(buffer, stream);
3330
+ stream.point(x0, y0);
3331
+ }
3332
+ function lineEnd() {
3333
+ resample.point = point;
3334
+ stream.lineEnd();
3335
+ }
3336
+ function ringStart() {
3337
+ lineStart();
3338
+ resample.point = ringPoint;
3339
+ resample.lineEnd = ringEnd;
3340
+ }
3341
+ function ringPoint(λ, φ) {
3342
+ linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
3343
+ resample.point = linePoint;
3344
+ }
3345
+ function ringEnd() {
3346
+ var buffer = [];
3347
+ resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, buffer);
3348
+ streamLine(buffer, stream);
3349
+ resample.lineEnd = lineEnd;
3350
+ lineEnd();
3351
+ }
3352
+ function streamLine(line, stream) {
3353
+ for (var i = 0, n = line.length, point; i < n; ++i) {
3354
+ stream.point((point = line[i])[0], point[1]);
3355
+ }
3356
+ }
3357
+ return resample;
3348
3358
  }
3349
- }
3350
- function d3_geo_conic(projectAt) {
3351
- var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
3352
- p.parallels = function(_) {
3353
- if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
3354
- return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
3355
- };
3356
- return p;
3357
- }
3358
- function d3_geo_conicEqualArea(φ0, φ1) {
3359
- var sinφ0 = Math.sin(φ0), n = (sinφ0 + Math.sin(φ1)) / 2, C = 1 + sinφ0 * (2 * n - sinφ0), ρ0 = Math.sqrt(C) / n;
3360
- function forward(λ, φ) {
3361
- var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
3362
- return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
3359
+ function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, buffer) {
3360
+ var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
3361
+ if (d2 > 4 * δ2 && depth--) {
3362
+ var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = Math.abs(Math.abs(c) - 1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2, tooFar = false;
3363
+ if (dz * dz / d2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || (tooFar = dx2 * dx2 + dy2 * dy2 > 256 * δ2)) {
3364
+ var s0 = resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, buffer);
3365
+ buffer.push(p);
3366
+ var s1 = resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, buffer);
3367
+ return !tooFar || s0 || s1 || (buffer.pop(), false);
3368
+ }
3369
+ }
3363
3370
  }
3364
- forward.invert = function(x, y) {
3365
- var ρ0_y = ρ0 - y;
3366
- return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
3371
+ resample.precision = function(_) {
3372
+ if (!arguments.length) return Math.sqrt(δ2);
3373
+ maxDepth = (δ2 = _ * _) > 0 && 16;
3374
+ return resample;
3367
3375
  };
3368
- return forward;
3376
+ return resample;
3369
3377
  }
3370
- (d3.geo.conicEqualArea = function() {
3371
- return d3_geo_conic(d3_geo_conicEqualArea);
3372
- }).raw = d3_geo_conicEqualArea;
3373
- d3.geo.albers = function() {
3374
- return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
3375
- };
3376
- d3.geo.albersUsa = function() {
3377
- var lower48 = d3.geo.albers();
3378
- var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
3379
- var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
3380
- var point, pointStream = {
3381
- point: function(x, y) {
3382
- point = [ x, y ];
3378
+ d3.geo.path = function() {
3379
+ var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
3380
+ function path(object) {
3381
+ if (object) {
3382
+ if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
3383
+ if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
3384
+ d3.geo.stream(object, cacheStream);
3383
3385
  }
3384
- }, lower48Point, alaskaPoint, hawaiiPoint;
3385
- function albersUsa(coordinates) {
3386
- var x = coordinates[0], y = coordinates[1];
3387
- point = null;
3388
- (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
3389
- return point;
3386
+ return contextStream.result();
3390
3387
  }
3391
- albersUsa.invert = function(coordinates) {
3392
- var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
3393
- return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
3388
+ path.area = function(object) {
3389
+ d3_geo_pathAreaSum = 0;
3390
+ d3.geo.stream(object, projectStream(d3_geo_pathArea));
3391
+ return d3_geo_pathAreaSum;
3394
3392
  };
3395
- albersUsa.stream = function(stream) {
3396
- var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
3393
+ path.centroid = function(object) {
3394
+ d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
3395
+ d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
3396
+ return d3_geo_centroidZ2 ? [ d3_geo_centroidX2 / d3_geo_centroidZ2, d3_geo_centroidY2 / d3_geo_centroidZ2 ] : d3_geo_centroidZ1 ? [ d3_geo_centroidX1 / d3_geo_centroidZ1, d3_geo_centroidY1 / d3_geo_centroidZ1 ] : d3_geo_centroidZ0 ? [ d3_geo_centroidX0 / d3_geo_centroidZ0, d3_geo_centroidY0 / d3_geo_centroidZ0 ] : [ NaN, NaN ];
3397
+ };
3398
+ path.bounds = function(object) {
3399
+ d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
3400
+ d3.geo.stream(object, projectStream(d3_geo_pathBounds));
3401
+ return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
3402
+ };
3403
+ path.projection = function(_) {
3404
+ if (!arguments.length) return projection;
3405
+ projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
3406
+ return reset();
3407
+ };
3408
+ path.context = function(_) {
3409
+ if (!arguments.length) return context;
3410
+ contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
3411
+ if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
3412
+ return reset();
3413
+ };
3414
+ path.pointRadius = function(_) {
3415
+ if (!arguments.length) return pointRadius;
3416
+ pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
3417
+ return path;
3418
+ };
3419
+ function reset() {
3420
+ cacheStream = null;
3421
+ return path;
3422
+ }
3423
+ return path.projection(d3.geo.albersUsa()).context(null);
3424
+ };
3425
+ function d3_geo_pathProjectStream(project) {
3426
+ var resample = d3_geo_resample(function(λ, φ) {
3427
+ return project([ λ * d3_degrees, φ * d3_degrees ]);
3428
+ });
3429
+ return function(stream) {
3430
+ stream = resample(stream);
3397
3431
  return {
3398
- point: function(x, y) {
3399
- lower48Stream.point(x, y);
3400
- alaskaStream.point(x, y);
3401
- hawaiiStream.point(x, y);
3432
+ point: function(λ, φ) {
3433
+ stream.point(λ * d3_radians, φ * d3_radians);
3402
3434
  },
3403
3435
  sphere: function() {
3404
- lower48Stream.sphere();
3405
- alaskaStream.sphere();
3406
- hawaiiStream.sphere();
3436
+ stream.sphere();
3407
3437
  },
3408
3438
  lineStart: function() {
3409
- lower48Stream.lineStart();
3410
- alaskaStream.lineStart();
3411
- hawaiiStream.lineStart();
3439
+ stream.lineStart();
3412
3440
  },
3413
3441
  lineEnd: function() {
3414
- lower48Stream.lineEnd();
3415
- alaskaStream.lineEnd();
3416
- hawaiiStream.lineEnd();
3442
+ stream.lineEnd();
3417
3443
  },
3418
3444
  polygonStart: function() {
3419
- lower48Stream.polygonStart();
3420
- alaskaStream.polygonStart();
3421
- hawaiiStream.polygonStart();
3445
+ stream.polygonStart();
3422
3446
  },
3423
3447
  polygonEnd: function() {
3424
- lower48Stream.polygonEnd();
3425
- alaskaStream.polygonEnd();
3426
- hawaiiStream.polygonEnd();
3448
+ stream.polygonEnd();
3427
3449
  }
3428
3450
  };
3429
3451
  };
3430
- albersUsa.precision = function(_) {
3431
- if (!arguments.length) return lower48.precision();
3432
- lower48.precision(_);
3433
- alaska.precision(_);
3434
- hawaii.precision(_);
3435
- return albersUsa;
3452
+ }
3453
+ d3.geo.projection = d3_geo_projection;
3454
+ d3.geo.projectionMutator = d3_geo_projectionMutator;
3455
+ function d3_geo_projection(project) {
3456
+ return d3_geo_projectionMutator(function() {
3457
+ return project;
3458
+ })();
3459
+ }
3460
+ function d3_geo_projectionMutator(projectAt) {
3461
+ var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
3462
+ x = project(x, y);
3463
+ return [ x[0] * k + δx, δy - x[1] * k ];
3464
+ }), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, preclip = d3_geo_clipAntimeridian, postclip = d3_identity, clipAngle = null, clipExtent = null, stream;
3465
+ function projection(point) {
3466
+ point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
3467
+ return [ point[0] * k + δx, δy - point[1] * k ];
3468
+ }
3469
+ function invert(point) {
3470
+ point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
3471
+ return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
3472
+ }
3473
+ projection.stream = function(output) {
3474
+ if (stream) stream.valid = false;
3475
+ stream = d3_geo_projectionRadiansRotate(rotate, preclip(projectResample(postclip(output))));
3476
+ stream.valid = true;
3477
+ return stream;
3436
3478
  };
3437
- albersUsa.scale = function(_) {
3438
- if (!arguments.length) return lower48.scale();
3439
- lower48.scale(_);
3440
- alaska.scale(_ * .35);
3441
- hawaii.scale(_);
3442
- return albersUsa.translate(lower48.translate());
3479
+ projection.clipAngle = function(_) {
3480
+ if (!arguments.length) return clipAngle;
3481
+ preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
3482
+ return invalidate();
3443
3483
  };
3444
- albersUsa.translate = function(_) {
3445
- if (!arguments.length) return lower48.translate();
3446
- var k = lower48.scale(), x = +_[0], y = +_[1];
3447
- lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
3448
- alaskaPoint = alaska.translate([ x - .307 * k, y + .201 * k ]).clipExtent([ [ x - .425 * k + ε, y + .12 * k + ε ], [ x - .214 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
3449
- hawaiiPoint = hawaii.translate([ x - .205 * k, y + .212 * k ]).clipExtent([ [ x - .214 * k + ε, y + .166 * k + ε ], [ x - .115 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
3450
- return albersUsa;
3484
+ projection.clipExtent = function(_) {
3485
+ if (!arguments.length) return clipExtent;
3486
+ clipExtent = _;
3487
+ postclip = _ == null ? d3_identity : d3_geo_clipView(_[0][0], _[0][1], _[1][0], _[1][1]);
3488
+ return invalidate();
3451
3489
  };
3452
- return albersUsa.scale(1070);
3453
- };
3454
- var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
3455
- point: d3_noop,
3456
- lineStart: d3_noop,
3457
- lineEnd: d3_noop,
3458
- polygonStart: function() {
3459
- d3_geo_pathAreaPolygon = 0;
3460
- d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
3461
- },
3462
- polygonEnd: function() {
3463
- d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
3464
- d3_geo_pathAreaSum += Math.abs(d3_geo_pathAreaPolygon / 2);
3465
- }
3466
- };
3467
- function d3_geo_pathAreaRingStart() {
3468
- var x00, y00, x0, y0;
3469
- d3_geo_pathArea.point = function(x, y) {
3470
- d3_geo_pathArea.point = nextPoint;
3471
- x00 = x0 = x, y00 = y0 = y;
3490
+ projection.scale = function(_) {
3491
+ if (!arguments.length) return k;
3492
+ k = +_;
3493
+ return reset();
3472
3494
  };
3473
- function nextPoint(x, y) {
3474
- d3_geo_pathAreaPolygon += y0 * x - x0 * y;
3475
- x0 = x, y0 = y;
3476
- }
3477
- d3_geo_pathArea.lineEnd = function() {
3478
- nextPoint(x00, y00);
3495
+ projection.translate = function(_) {
3496
+ if (!arguments.length) return [ x, y ];
3497
+ x = +_[0];
3498
+ y = +_[1];
3499
+ return reset();
3500
+ };
3501
+ projection.center = function(_) {
3502
+ if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
3503
+ λ = _[0] % 360 * d3_radians;
3504
+ φ = _[1] % 360 * d3_radians;
3505
+ return reset();
3506
+ };
3507
+ projection.rotate = function(_) {
3508
+ if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
3509
+ δλ = _[0] % 360 * d3_radians;
3510
+ δφ = _[1] % 360 * d3_radians;
3511
+ δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
3512
+ return reset();
3513
+ };
3514
+ d3.rebind(projection, projectResample, "precision");
3515
+ function reset() {
3516
+ projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
3517
+ var center = project(λ, φ);
3518
+ δx = x - center[0] * k;
3519
+ δy = y + center[1] * k;
3520
+ return invalidate();
3521
+ }
3522
+ function invalidate() {
3523
+ if (stream) {
3524
+ stream.valid = false;
3525
+ stream = null;
3526
+ }
3527
+ return projection;
3528
+ }
3529
+ return function() {
3530
+ project = projectAt.apply(this, arguments);
3531
+ projection.invert = project.invert && invert;
3532
+ return reset();
3479
3533
  };
3480
3534
  }
3481
- var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
3482
- var d3_geo_pathBounds = {
3483
- point: d3_geo_pathBoundsPoint,
3484
- lineStart: d3_noop,
3485
- lineEnd: d3_noop,
3486
- polygonStart: d3_noop,
3487
- polygonEnd: d3_noop
3488
- };
3489
- function d3_geo_pathBoundsPoint(x, y) {
3490
- if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
3491
- if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
3492
- if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
3493
- if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
3494
- }
3495
- function d3_geo_pathBuffer() {
3496
- var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
3497
- var stream = {
3498
- point: point,
3535
+ function d3_geo_projectionRadiansRotate(rotate, stream) {
3536
+ return {
3537
+ point: function(x, y) {
3538
+ y = rotate(x * d3_radians, y * d3_radians), x = y[0];
3539
+ stream.point(x > π ? x - 2 * π : x < -π ? x + 2 * π : x, y[1]);
3540
+ },
3541
+ sphere: function() {
3542
+ stream.sphere();
3543
+ },
3499
3544
  lineStart: function() {
3500
- stream.point = pointLineStart;
3545
+ stream.lineStart();
3546
+ },
3547
+ lineEnd: function() {
3548
+ stream.lineEnd();
3501
3549
  },
3502
- lineEnd: lineEnd,
3503
3550
  polygonStart: function() {
3504
- stream.lineEnd = lineEndPolygon;
3551
+ stream.polygonStart();
3505
3552
  },
3506
3553
  polygonEnd: function() {
3507
- stream.lineEnd = lineEnd;
3508
- stream.point = point;
3509
- },
3510
- pointRadius: function(_) {
3511
- pointCircle = d3_geo_pathBufferCircle(_);
3512
- return stream;
3513
- },
3514
- result: function() {
3515
- if (buffer.length) {
3516
- var result = buffer.join("");
3517
- buffer = [];
3518
- return result;
3519
- }
3554
+ stream.polygonEnd();
3520
3555
  }
3521
3556
  };
3522
- function point(x, y) {
3523
- buffer.push("M", x, ",", y, pointCircle);
3524
- }
3525
- function pointLineStart(x, y) {
3526
- buffer.push("M", x, ",", y);
3527
- stream.point = pointLine;
3528
- }
3529
- function pointLine(x, y) {
3530
- buffer.push("L", x, ",", y);
3531
- }
3532
- function lineEnd() {
3533
- stream.point = point;
3534
- }
3535
- function lineEndPolygon() {
3536
- buffer.push("Z");
3537
- }
3538
- return stream;
3539
3557
  }
3540
- function d3_geo_pathBufferCircle(radius) {
3541
- return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
3558
+ function d3_geo_equirectangular(λ, φ) {
3559
+ return [ λ, φ ];
3542
3560
  }
3543
- var d3_geo_pathCentroid = {
3544
- point: d3_geo_pathCentroidPoint,
3545
- lineStart: d3_geo_pathCentroidLineStart,
3546
- lineEnd: d3_geo_pathCentroidLineEnd,
3547
- polygonStart: function() {
3548
- d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
3549
- },
3550
- polygonEnd: function() {
3551
- d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
3552
- d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
3553
- d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
3561
+ (d3.geo.equirectangular = function() {
3562
+ return d3_geo_projection(d3_geo_equirectangular);
3563
+ }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
3564
+ d3.geo.rotation = function(rotate) {
3565
+ rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
3566
+ function forward(coordinates) {
3567
+ coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
3568
+ return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
3554
3569
  }
3570
+ forward.invert = function(coordinates) {
3571
+ coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
3572
+ return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
3573
+ };
3574
+ return forward;
3555
3575
  };
3556
- function d3_geo_pathCentroidPoint(x, y) {
3557
- if (d3_geo_centroidDimension) return;
3558
- d3_geo_centroidX += x;
3559
- d3_geo_centroidY += y;
3560
- ++d3_geo_centroidZ;
3576
+ function d3_geo_rotation(δλ, δφ, δγ) {
3577
+ return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_equirectangular;
3561
3578
  }
3562
- function d3_geo_pathCentroidLineStart() {
3563
- var x0, y0;
3564
- if (d3_geo_centroidDimension !== 1) {
3565
- if (d3_geo_centroidDimension < 1) {
3566
- d3_geo_centroidDimension = 1;
3567
- d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
3568
- } else return;
3579
+ function d3_geo_forwardRotationλ(δλ) {
3580
+ return function(λ, φ) {
3581
+ return λ += δλ, [ λ > π ? λ - 2 * π : λ < -π ? λ + 2 * π : λ, φ ];
3582
+ };
3583
+ }
3584
+ function d3_geo_rotationλ(δλ) {
3585
+ var rotation = d3_geo_forwardRotationλ(δλ);
3586
+ rotation.invert = d3_geo_forwardRotationλ(-δλ);
3587
+ return rotation;
3588
+ }
3589
+ function d3_geo_rotationφγ(δφ, δγ) {
3590
+ var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
3591
+ function rotation(λ, φ) {
3592
+ var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
3593
+ return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
3569
3594
  }
3570
- d3_geo_pathCentroid.point = function(x, y) {
3571
- d3_geo_pathCentroid.point = nextPoint;
3572
- x0 = x, y0 = y;
3595
+ rotation.invert = function(λ, φ) {
3596
+ var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
3597
+ return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
3573
3598
  };
3574
- function nextPoint(x, y) {
3575
- var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
3576
- d3_geo_centroidX += z * (x0 + x) / 2;
3577
- d3_geo_centroidY += z * (y0 + y) / 2;
3578
- d3_geo_centroidZ += z;
3579
- x0 = x, y0 = y;
3599
+ return rotation;
3600
+ }
3601
+ d3.geo.circle = function() {
3602
+ var origin = [ 0, 0 ], angle, precision = 6, interpolate;
3603
+ function circle() {
3604
+ var center = typeof origin === "function" ? origin.apply(this, arguments) : origin, rotate = d3_geo_rotation(-center[0] * d3_radians, -center[1] * d3_radians, 0).invert, ring = [];
3605
+ interpolate(null, null, 1, {
3606
+ point: function(x, y) {
3607
+ ring.push(x = rotate(x, y));
3608
+ x[0] *= d3_degrees, x[1] *= d3_degrees;
3609
+ }
3610
+ });
3611
+ return {
3612
+ type: "Polygon",
3613
+ coordinates: [ ring ]
3614
+ };
3580
3615
  }
3616
+ circle.origin = function(x) {
3617
+ if (!arguments.length) return origin;
3618
+ origin = x;
3619
+ return circle;
3620
+ };
3621
+ circle.angle = function(x) {
3622
+ if (!arguments.length) return angle;
3623
+ interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
3624
+ return circle;
3625
+ };
3626
+ circle.precision = function(_) {
3627
+ if (!arguments.length) return precision;
3628
+ interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
3629
+ return circle;
3630
+ };
3631
+ return circle.angle(90);
3632
+ };
3633
+ function d3_geo_circleInterpolate(radius, precision) {
3634
+ var cr = Math.cos(radius), sr = Math.sin(radius);
3635
+ return function(from, to, direction, listener) {
3636
+ if (from != null) {
3637
+ from = d3_geo_circleAngle(cr, from);
3638
+ to = d3_geo_circleAngle(cr, to);
3639
+ if (direction > 0 ? from < to : from > to) from += direction * 2 * π;
3640
+ } else {
3641
+ from = radius + direction * 2 * π;
3642
+ to = radius;
3643
+ }
3644
+ var point;
3645
+ for (var step = direction * precision, t = from; direction > 0 ? t > to : t < to; t -= step) {
3646
+ listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
3647
+ }
3648
+ };
3581
3649
  }
3582
- function d3_geo_pathCentroidLineEnd() {
3583
- d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
3650
+ function d3_geo_circleAngle(cr, point) {
3651
+ var a = d3_geo_cartesian(point);
3652
+ a[0] -= cr;
3653
+ d3_geo_cartesianNormalize(a);
3654
+ var angle = d3_acos(-a[1]);
3655
+ return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
3584
3656
  }
3585
- function d3_geo_pathCentroidRingStart() {
3586
- var x00, y00, x0, y0;
3587
- if (d3_geo_centroidDimension < 2) {
3588
- d3_geo_centroidDimension = 2;
3589
- d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
3657
+ d3.geo.distance = function(a, b) {
3658
+ var Δλ = (b[0] - a[0]) * d3_radians, φ0 = a[1] * d3_radians, φ1 = b[1] * d3_radians, sinΔλ = Math.sin(Δλ), cosΔλ = Math.cos(Δλ), sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1), t;
3659
+ return Math.atan2(Math.sqrt((t = cosφ1 * sinΔλ) * t + (t = cosφ0 * sinφ1 - sinφ0 * cosφ1 * cosΔλ) * t), sinφ0 * sinφ1 + cosφ0 * cosφ1 * cosΔλ);
3660
+ };
3661
+ d3.geo.graticule = function() {
3662
+ var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
3663
+ function graticule() {
3664
+ return {
3665
+ type: "MultiLineString",
3666
+ coordinates: lines()
3667
+ };
3590
3668
  }
3591
- d3_geo_pathCentroid.point = function(x, y) {
3592
- d3_geo_pathCentroid.point = nextPoint;
3593
- x00 = x0 = x, y00 = y0 = y;
3594
- };
3595
- function nextPoint(x, y) {
3596
- var z = y0 * x - x0 * y;
3597
- d3_geo_centroidX += z * (x0 + x);
3598
- d3_geo_centroidY += z * (y0 + y);
3599
- d3_geo_centroidZ += z * 3;
3600
- x0 = x, y0 = y;
3669
+ function lines() {
3670
+ return d3.range(Math.ceil(X0 / DX) * DX, X1, DX).map(X).concat(d3.range(Math.ceil(Y0 / DY) * DY, Y1, DY).map(Y)).concat(d3.range(Math.ceil(x0 / dx) * dx, x1, dx).filter(function(x) {
3671
+ return Math.abs(x % DX) > ε;
3672
+ }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
3673
+ return Math.abs(y % DY) > ε;
3674
+ }).map(y));
3601
3675
  }
3602
- d3_geo_pathCentroid.lineEnd = function() {
3603
- nextPoint(x00, y00);
3676
+ graticule.lines = function() {
3677
+ return lines().map(function(coordinates) {
3678
+ return {
3679
+ type: "LineString",
3680
+ coordinates: coordinates
3681
+ };
3682
+ });
3683
+ };
3684
+ graticule.outline = function() {
3685
+ return {
3686
+ type: "Polygon",
3687
+ coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
3688
+ };
3689
+ };
3690
+ graticule.extent = function(_) {
3691
+ if (!arguments.length) return graticule.minorExtent();
3692
+ return graticule.majorExtent(_).minorExtent(_);
3693
+ };
3694
+ graticule.majorExtent = function(_) {
3695
+ if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
3696
+ X0 = +_[0][0], X1 = +_[1][0];
3697
+ Y0 = +_[0][1], Y1 = +_[1][1];
3698
+ if (X0 > X1) _ = X0, X0 = X1, X1 = _;
3699
+ if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
3700
+ return graticule.precision(precision);
3701
+ };
3702
+ graticule.minorExtent = function(_) {
3703
+ if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
3704
+ x0 = +_[0][0], x1 = +_[1][0];
3705
+ y0 = +_[0][1], y1 = +_[1][1];
3706
+ if (x0 > x1) _ = x0, x0 = x1, x1 = _;
3707
+ if (y0 > y1) _ = y0, y0 = y1, y1 = _;
3708
+ return graticule.precision(precision);
3709
+ };
3710
+ graticule.step = function(_) {
3711
+ if (!arguments.length) return graticule.minorStep();
3712
+ return graticule.majorStep(_).minorStep(_);
3713
+ };
3714
+ graticule.majorStep = function(_) {
3715
+ if (!arguments.length) return [ DX, DY ];
3716
+ DX = +_[0], DY = +_[1];
3717
+ return graticule;
3718
+ };
3719
+ graticule.minorStep = function(_) {
3720
+ if (!arguments.length) return [ dx, dy ];
3721
+ dx = +_[0], dy = +_[1];
3722
+ return graticule;
3723
+ };
3724
+ graticule.precision = function(_) {
3725
+ if (!arguments.length) return precision;
3726
+ precision = +_;
3727
+ x = d3_geo_graticuleX(y0, y1, 90);
3728
+ y = d3_geo_graticuleY(x0, x1, precision);
3729
+ X = d3_geo_graticuleX(Y0, Y1, 90);
3730
+ Y = d3_geo_graticuleY(X0, X1, precision);
3731
+ return graticule;
3732
+ };
3733
+ return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
3734
+ };
3735
+ function d3_geo_graticuleX(y0, y1, dy) {
3736
+ var y = d3.range(y0, y1 - ε, dy).concat(y1);
3737
+ return function(x) {
3738
+ return y.map(function(y) {
3739
+ return [ x, y ];
3740
+ });
3604
3741
  };
3605
3742
  }
3606
- function d3_geo_pathContext(context) {
3607
- var pointRadius = 4.5;
3608
- var stream = {
3609
- point: point,
3610
- lineStart: function() {
3611
- stream.point = pointLineStart;
3612
- },
3613
- lineEnd: lineEnd,
3614
- polygonStart: function() {
3615
- stream.lineEnd = lineEndPolygon;
3616
- },
3617
- polygonEnd: function() {
3618
- stream.lineEnd = lineEnd;
3619
- stream.point = point;
3620
- },
3621
- pointRadius: function(_) {
3622
- pointRadius = _;
3623
- return stream;
3624
- },
3625
- result: d3_noop
3743
+ function d3_geo_graticuleY(x0, x1, dx) {
3744
+ var x = d3.range(x0, x1 - ε, dx).concat(x1);
3745
+ return function(y) {
3746
+ return x.map(function(x) {
3747
+ return [ x, y ];
3748
+ });
3626
3749
  };
3627
- function point(x, y) {
3628
- context.moveTo(x, y);
3629
- context.arc(x, y, pointRadius, 0, 2 * π);
3630
- }
3631
- function pointLineStart(x, y) {
3632
- context.moveTo(x, y);
3633
- stream.point = pointLine;
3634
- }
3635
- function pointLine(x, y) {
3636
- context.lineTo(x, y);
3637
- }
3638
- function lineEnd() {
3639
- stream.point = point;
3640
- }
3641
- function lineEndPolygon() {
3642
- context.closePath();
3643
- }
3644
- return stream;
3645
3750
  }
3646
- d3.geo.path = function() {
3647
- var pointRadius = 4.5, projection, context, projectStream, contextStream;
3648
- function path(object) {
3649
- if (object) d3.geo.stream(object, projectStream(contextStream.pointRadius(typeof pointRadius === "function" ? +pointRadius.apply(this, arguments) : pointRadius)));
3650
- return contextStream.result();
3751
+ function d3_source(d) {
3752
+ return d.source;
3753
+ }
3754
+ function d3_target(d) {
3755
+ return d.target;
3756
+ }
3757
+ d3.geo.greatArc = function() {
3758
+ var source = d3_source, source_, target = d3_target, target_;
3759
+ function greatArc() {
3760
+ return {
3761
+ type: "LineString",
3762
+ coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
3763
+ };
3651
3764
  }
3652
- path.area = function(object) {
3653
- d3_geo_pathAreaSum = 0;
3654
- d3.geo.stream(object, projectStream(d3_geo_pathArea));
3655
- return d3_geo_pathAreaSum;
3656
- };
3657
- path.centroid = function(object) {
3658
- d3_geo_centroidDimension = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
3659
- d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
3660
- return d3_geo_centroidZ ? [ d3_geo_centroidX / d3_geo_centroidZ, d3_geo_centroidY / d3_geo_centroidZ ] : undefined;
3765
+ greatArc.distance = function() {
3766
+ return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
3661
3767
  };
3662
- path.bounds = function(object) {
3663
- d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
3664
- d3.geo.stream(object, projectStream(d3_geo_pathBounds));
3665
- return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
3768
+ greatArc.source = function(_) {
3769
+ if (!arguments.length) return source;
3770
+ source = _, source_ = typeof _ === "function" ? null : _;
3771
+ return greatArc;
3666
3772
  };
3667
- path.projection = function(_) {
3668
- if (!arguments.length) return projection;
3669
- projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
3670
- return path;
3773
+ greatArc.target = function(_) {
3774
+ if (!arguments.length) return target;
3775
+ target = _, target_ = typeof _ === "function" ? null : _;
3776
+ return greatArc;
3671
3777
  };
3672
- path.context = function(_) {
3673
- if (!arguments.length) return context;
3674
- contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
3675
- return path;
3778
+ greatArc.precision = function() {
3779
+ return arguments.length ? greatArc : 0;
3676
3780
  };
3677
- path.pointRadius = function(_) {
3678
- if (!arguments.length) return pointRadius;
3679
- pointRadius = typeof _ === "function" ? _ : +_;
3680
- return path;
3781
+ return greatArc;
3782
+ };
3783
+ d3.geo.interpolate = function(source, target) {
3784
+ return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
3785
+ };
3786
+ function d3_geo_interpolate(x0, y0, x1, y1) {
3787
+ var cy0 = Math.cos(y0), sy0 = Math.sin(y0), cy1 = Math.cos(y1), sy1 = Math.sin(y1), kx0 = cy0 * Math.cos(x0), ky0 = cy0 * Math.sin(x0), kx1 = cy1 * Math.cos(x1), ky1 = cy1 * Math.sin(x1), d = 2 * Math.asin(Math.sqrt(d3_haversin(y1 - y0) + cy0 * cy1 * d3_haversin(x1 - x0))), k = 1 / Math.sin(d);
3788
+ var interpolate = d ? function(t) {
3789
+ var B = Math.sin(t *= d) * k, A = Math.sin(d - t) * k, x = A * kx0 + B * kx1, y = A * ky0 + B * ky1, z = A * sy0 + B * sy1;
3790
+ return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
3791
+ } : function() {
3792
+ return [ x0 * d3_degrees, y0 * d3_degrees ];
3681
3793
  };
3682
- return path.projection(d3.geo.albersUsa()).context(null);
3794
+ interpolate.distance = d;
3795
+ return interpolate;
3796
+ }
3797
+ d3.geo.length = function(object) {
3798
+ d3_geo_lengthSum = 0;
3799
+ d3.geo.stream(object, d3_geo_length);
3800
+ return d3_geo_lengthSum;
3683
3801
  };
3684
- function d3_geo_pathProjectStream(project) {
3685
- var resample = d3_geo_resample(function(λ, φ) {
3686
- return project([ λ * d3_degrees, φ * d3_degrees ]);
3687
- });
3688
- return function(stream) {
3689
- stream = resample(stream);
3690
- return {
3691
- point: function(λ, φ) {
3692
- stream.point(λ * d3_radians, φ * d3_radians);
3693
- },
3694
- sphere: function() {
3695
- stream.sphere();
3696
- },
3697
- lineStart: function() {
3698
- stream.lineStart();
3699
- },
3700
- lineEnd: function() {
3701
- stream.lineEnd();
3702
- },
3703
- polygonStart: function() {
3704
- stream.polygonStart();
3705
- },
3706
- polygonEnd: function() {
3707
- stream.polygonEnd();
3708
- }
3709
- };
3802
+ var d3_geo_lengthSum;
3803
+ var d3_geo_length = {
3804
+ sphere: d3_noop,
3805
+ point: d3_noop,
3806
+ lineStart: d3_geo_lengthLineStart,
3807
+ lineEnd: d3_noop,
3808
+ polygonStart: d3_noop,
3809
+ polygonEnd: d3_noop
3810
+ };
3811
+ function d3_geo_lengthLineStart() {
3812
+ var λ0, sinφ0, cosφ0;
3813
+ d3_geo_length.point = function(λ, φ) {
3814
+ λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
3815
+ d3_geo_length.point = nextPoint;
3710
3816
  };
3817
+ d3_geo_length.lineEnd = function() {
3818
+ d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
3819
+ };
3820
+ function nextPoint(λ, φ) {
3821
+ var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = Math.abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
3822
+ d3_geo_lengthSum += Math.atan2(Math.sqrt((t = cosφ * Math.sin(t)) * t + (t = cosφ0 * sinφ - sinφ0 * cosφ * cosΔλ) * t), sinφ0 * sinφ + cosφ0 * cosφ * cosΔλ);
3823
+ λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
3824
+ }
3711
3825
  }
3712
3826
  function d3_geo_azimuthal(scale, angle) {
3713
3827
  function azimuthal(λ, φ) {
@@ -3891,6 +4005,7 @@ d3 = function() {
3891
4005
  var d3_svg_lineInterpolators = d3.map({
3892
4006
  linear: d3_svg_lineLinear,
3893
4007
  "linear-closed": d3_svg_lineLinearClosed,
4008
+ step: d3_svg_lineStep,
3894
4009
  "step-before": d3_svg_lineStepBefore,
3895
4010
  "step-after": d3_svg_lineStepAfter,
3896
4011
  basis: d3_svg_lineBasis,
@@ -3912,6 +4027,12 @@ d3 = function() {
3912
4027
  function d3_svg_lineLinearClosed(points) {
3913
4028
  return d3_svg_lineLinear(points) + "Z";
3914
4029
  }
4030
+ function d3_svg_lineStep(points) {
4031
+ var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
4032
+ while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
4033
+ if (n > 1) path.push("H", p[0]);
4034
+ return path.join("");
4035
+ }
3915
4036
  function d3_svg_lineStepBefore(points) {
3916
4037
  var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
3917
4038
  while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
@@ -4249,15 +4370,15 @@ d3 = function() {
4249
4370
  return triangles;
4250
4371
  };
4251
4372
  d3.geom.voronoi = function(points) {
4252
- var size = null, x = d3_svg_lineX, y = d3_svg_lineY, clip;
4373
+ var x = d3_svg_lineX, y = d3_svg_lineY, clipPolygon = null;
4253
4374
  if (arguments.length) return voronoi(points);
4254
4375
  function voronoi(data) {
4255
4376
  var points, polygons = data.map(function() {
4256
4377
  return [];
4257
4378
  }), fx = d3_functor(x), fy = d3_functor(y), d, i, n = data.length, Z = 1e6;
4258
- if (fx === d3_svg_lineX && fy === d3_svg_lineY) points = data; else for (points = [],
4379
+ if (fx === d3_svg_lineX && fy === d3_svg_lineY) points = data; else for (points = new Array(n),
4259
4380
  i = 0; i < n; ++i) {
4260
- points.push([ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]);
4381
+ points[i] = [ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ];
4261
4382
  }
4262
4383
  d3_geom_voronoiTessellate(points, function(e) {
4263
4384
  var s1, s2, x1, x2, y1, y2;
@@ -4316,7 +4437,7 @@ d3 = function() {
4316
4437
  }
4317
4438
  }
4318
4439
  });
4319
- if (clip) for (i = 0; i < n; ++i) clip(polygons[i]);
4440
+ if (clipPolygon) for (i = 0; i < n; ++i) clipPolygon.clip(polygons[i]);
4320
4441
  for (i = 0; i < n; ++i) polygons[i].point = data[i];
4321
4442
  return polygons;
4322
4443
  }
@@ -4326,22 +4447,25 @@ d3 = function() {
4326
4447
  voronoi.y = function(_) {
4327
4448
  return arguments.length ? (y = _, voronoi) : y;
4328
4449
  };
4329
- voronoi.size = function(_) {
4330
- if (!arguments.length) return size;
4331
- if (_ == null) {
4332
- clip = null;
4333
- } else {
4334
- size = [ +_[0], +_[1] ];
4335
- clip = d3.geom.polygon([ [ 0, 0 ], [ 0, size[1] ], size, [ size[0], 0 ] ]).clip;
4450
+ voronoi.clipExtent = function(_) {
4451
+ if (!arguments.length) return clipPolygon && [ clipPolygon[0], clipPolygon[2] ];
4452
+ if (_ == null) clipPolygon = null; else {
4453
+ var x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0], y2 = +_[1][1];
4454
+ clipPolygon = d3.geom.polygon([ [ x1, y1 ], [ x1, y2 ], [ x2, y2 ], [ x2, y1 ] ]);
4336
4455
  }
4337
4456
  return voronoi;
4338
4457
  };
4458
+ voronoi.size = function(_) {
4459
+ if (!arguments.length) return clipPolygon && clipPolygon[2];
4460
+ return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
4461
+ };
4339
4462
  voronoi.links = function(data) {
4340
4463
  var points, graph = data.map(function() {
4341
4464
  return [];
4342
4465
  }), links = [], fx = d3_functor(x), fy = d3_functor(y), d, i, n = data.length;
4343
- if (fx === d3_svg_lineX && fy === d3_svg_lineY) points = data; else for (i = 0; i < n; ++i) {
4344
- points.push([ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]);
4466
+ if (fx === d3_svg_lineX && fy === d3_svg_lineY) points = data; else for (points = new Array(n),
4467
+ i = 0; i < n; ++i) {
4468
+ points[i] = [ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ];
4345
4469
  }
4346
4470
  d3_geom_voronoiTessellate(points, function(e) {
4347
4471
  var l = e.region.l.index, r = e.region.r.index;
@@ -4356,11 +4480,9 @@ d3 = function() {
4356
4480
  };
4357
4481
  voronoi.triangles = function(data) {
4358
4482
  if (x === d3_svg_lineX && y === d3_svg_lineY) return d3.geom.delaunay(data);
4359
- var points, point, fx = d3_functor(x), fy = d3_functor(y), d, i, n;
4360
- for (i = 0, points = [], n = data.length; i < n; ++i) {
4361
- point = [ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ];
4362
- point.data = d;
4363
- points.push(point);
4483
+ var points = new Array(n), fx = d3_functor(x), fy = d3_functor(y), d, i = -1, n = data.length;
4484
+ while (++i < n) {
4485
+ (points[i] = [ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]).data = d;
4364
4486
  }
4365
4487
  return d3.geom.delaunay(points).map(function(triangle) {
4366
4488
  return triangle.map(function(point) {
@@ -4735,14 +4857,15 @@ d3 = function() {
4735
4857
  quadtree.y = function(_) {
4736
4858
  return arguments.length ? (y = _, quadtree) : y;
4737
4859
  };
4860
+ quadtree.extent = function(_) {
4861
+ if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
4862
+ if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
4863
+ y2 = +_[1][1];
4864
+ return quadtree;
4865
+ };
4738
4866
  quadtree.size = function(_) {
4739
- if (!arguments.length) return x1 == null ? null : [ x2, y2 ];
4740
- if (_ == null) {
4741
- x1 = y1 = x2 = y2 = null;
4742
- } else {
4743
- x1 = y1 = 0;
4744
- x2 = +_[0], y2 = +_[1];
4745
- }
4867
+ if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
4868
+ if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
4746
4869
  return quadtree;
4747
4870
  };
4748
4871
  return quadtree;
@@ -5930,7 +6053,7 @@ d3 = function() {
5930
6053
  return [ d3.min(values), d3.max(values) ];
5931
6054
  }
5932
6055
  d3.layout.tree = function() {
5933
- var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ];
6056
+ var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
5934
6057
  function tree(d, i) {
5935
6058
  var nodes = hierarchy.call(this, d, i), root = nodes[0];
5936
6059
  function firstWalk(node, previousSibling) {
@@ -6011,7 +6134,11 @@ d3 = function() {
6011
6134
  firstWalk(root);
6012
6135
  secondWalk(root, -root._tree.prelim);
6013
6136
  var left = d3_layout_treeSearch(root, d3_layout_treeLeftmost), right = d3_layout_treeSearch(root, d3_layout_treeRightmost), deep = d3_layout_treeSearch(root, d3_layout_treeDeepest), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2, y1 = deep.depth || 1;
6014
- d3_layout_treeVisitAfter(root, function(node) {
6137
+ d3_layout_treeVisitAfter(root, nodeSize ? function(node) {
6138
+ node.x *= size[0];
6139
+ node.y = node.depth * size[1];
6140
+ delete node._tree;
6141
+ } : function(node) {
6015
6142
  node.x = (node.x - x0) / (x1 - x0) * size[0];
6016
6143
  node.y = node.depth / y1 * size[1];
6017
6144
  delete node._tree;
@@ -6024,8 +6151,13 @@ d3 = function() {
6024
6151
  return tree;
6025
6152
  };
6026
6153
  tree.size = function(x) {
6027
- if (!arguments.length) return size;
6028
- size = x;
6154
+ if (!arguments.length) return nodeSize ? null : size;
6155
+ nodeSize = (size = x) == null;
6156
+ return tree;
6157
+ };
6158
+ tree.nodeSize = function(x) {
6159
+ if (!arguments.length) return nodeSize ? size : null;
6160
+ nodeSize = (size = x) != null;
6029
6161
  return tree;
6030
6162
  };
6031
6163
  return d3_layout_hierarchyRebind(tree, hierarchy);
@@ -6100,18 +6232,16 @@ d3 = function() {
6100
6232
  return vim._tree.ancestor.parent == node.parent ? vim._tree.ancestor : ancestor;
6101
6233
  }
6102
6234
  d3.layout.pack = function() {
6103
- var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ];
6235
+ var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
6104
6236
  function pack(d, i) {
6105
- var nodes = hierarchy.call(this, d, i), root = nodes[0];
6106
- root.x = 0;
6107
- root.y = 0;
6237
+ var nodes = hierarchy.call(this, d, i), root = nodes[0], w = size[0], h = size[1], r = radius || Math.sqrt;
6238
+ root.x = root.y = 0;
6108
6239
  d3_layout_treeVisitAfter(root, function(d) {
6109
- d.r = Math.sqrt(d.value);
6240
+ d.r = r(d.value);
6110
6241
  });
6111
6242
  d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
6112
- var w = size[0], h = size[1], k = Math.max(2 * root.r / w, 2 * root.r / h);
6113
- if (padding > 0) {
6114
- var dr = padding * k / 2;
6243
+ if (padding) {
6244
+ var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
6115
6245
  d3_layout_treeVisitAfter(root, function(d) {
6116
6246
  d.r += dr;
6117
6247
  });
@@ -6119,14 +6249,18 @@ d3 = function() {
6119
6249
  d3_layout_treeVisitAfter(root, function(d) {
6120
6250
  d.r -= dr;
6121
6251
  });
6122
- k = Math.max(2 * root.r / w, 2 * root.r / h);
6123
6252
  }
6124
- d3_layout_packTransform(root, w / 2, h / 2, 1 / k);
6253
+ d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
6125
6254
  return nodes;
6126
6255
  }
6127
- pack.size = function(x) {
6256
+ pack.size = function(_) {
6128
6257
  if (!arguments.length) return size;
6129
- size = x;
6258
+ size = _;
6259
+ return pack;
6260
+ };
6261
+ pack.radius = function(_) {
6262
+ if (!arguments.length) return radius;
6263
+ radius = _;
6130
6264
  return pack;
6131
6265
  };
6132
6266
  pack.padding = function(_) {
@@ -6152,7 +6286,7 @@ d3 = function() {
6152
6286
  }
6153
6287
  function d3_layout_packIntersects(a, b) {
6154
6288
  var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
6155
- return dr * dr - dx * dx - dy * dy > .001;
6289
+ return .999 * dr * dr > dx * dx + dy * dy;
6156
6290
  }
6157
6291
  function d3_layout_packSiblings(node) {
6158
6292
  if (!(nodes = node.children) || !(n = nodes.length)) return;
@@ -6250,7 +6384,7 @@ d3 = function() {
6250
6384
  }
6251
6385
  }
6252
6386
  d3.layout.cluster = function() {
6253
- var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ];
6387
+ var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
6254
6388
  function cluster(d, i) {
6255
6389
  var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
6256
6390
  d3_layout_treeVisitAfter(root, function(node) {
@@ -6265,7 +6399,10 @@ d3 = function() {
6265
6399
  }
6266
6400
  });
6267
6401
  var left = d3_layout_clusterLeft(root), right = d3_layout_clusterRight(root), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2;
6268
- d3_layout_treeVisitAfter(root, function(node) {
6402
+ d3_layout_treeVisitAfter(root, nodeSize ? function(node) {
6403
+ node.x = (node.x - root.x) * size[0];
6404
+ node.y = (root.y - node.y) * size[1];
6405
+ } : function(node) {
6269
6406
  node.x = (node.x - x0) / (x1 - x0) * size[0];
6270
6407
  node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
6271
6408
  });
@@ -6277,8 +6414,13 @@ d3 = function() {
6277
6414
  return cluster;
6278
6415
  };
6279
6416
  cluster.size = function(x) {
6280
- if (!arguments.length) return size;
6281
- size = x;
6417
+ if (!arguments.length) return nodeSize ? null : size;
6418
+ nodeSize = (size = x) == null;
6419
+ return cluster;
6420
+ };
6421
+ cluster.nodeSize = function(x) {
6422
+ if (!arguments.length) return nodeSize ? size : null;
6423
+ nodeSize = (size = x) != null;
6282
6424
  return cluster;
6283
6425
  };
6284
6426
  return d3_layout_hierarchyRebind(cluster, hierarchy);
@@ -6522,12 +6664,24 @@ d3 = function() {
6522
6664
  dx = i0, i0 = i1, i1 = dx;
6523
6665
  dx = x0, x0 = x1, x1 = dx;
6524
6666
  }
6525
- if (nice = nice(x1 - x0)) {
6526
- domain[i0] = nice.floor(x0);
6527
- domain[i1] = nice.ceil(x1);
6528
- }
6667
+ domain[i0] = nice.floor(x0);
6668
+ domain[i1] = nice.ceil(x1);
6529
6669
  return domain;
6530
6670
  }
6671
+ function d3_scale_niceStep(step) {
6672
+ return step ? {
6673
+ floor: function(x) {
6674
+ return Math.floor(x / step) * step;
6675
+ },
6676
+ ceil: function(x) {
6677
+ return Math.ceil(x / step) * step;
6678
+ }
6679
+ } : d3_scale_niceIdentity;
6680
+ }
6681
+ var d3_scale_niceIdentity = {
6682
+ floor: d3_identity,
6683
+ ceil: d3_identity
6684
+ };
6531
6685
  function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
6532
6686
  var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
6533
6687
  if (domain[k] < domain[0]) {
@@ -6589,8 +6743,8 @@ d3 = function() {
6589
6743
  scale.tickFormat = function(m, format) {
6590
6744
  return d3_scale_linearTickFormat(domain, m, format);
6591
6745
  };
6592
- scale.nice = function() {
6593
- d3_scale_nice(domain, d3_scale_linearNice);
6746
+ scale.nice = function(m) {
6747
+ d3_scale_linearNice(domain, m);
6594
6748
  return rescale();
6595
6749
  };
6596
6750
  scale.copy = function() {
@@ -6601,16 +6755,12 @@ d3 = function() {
6601
6755
  function d3_scale_linearRebind(scale, linear) {
6602
6756
  return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
6603
6757
  }
6604
- function d3_scale_linearNice(dx) {
6605
- dx = Math.pow(10, Math.round(Math.log(dx) / Math.LN10) - 1);
6606
- return dx && {
6607
- floor: function(x) {
6608
- return Math.floor(x / dx) * dx;
6609
- },
6610
- ceil: function(x) {
6611
- return Math.ceil(x / dx) * dx;
6612
- }
6613
- };
6758
+ function d3_scale_linearNice(domain, m) {
6759
+ return d3_scale_nice(domain, d3_scale_niceStep(m ? d3_scale_linearTickRange(domain, m)[2] : d3_scale_linearNiceStep(domain)));
6760
+ }
6761
+ function d3_scale_linearNiceStep(domain) {
6762
+ var extent = d3_scaleExtent(domain), span = extent[1] - extent[0];
6763
+ return Math.pow(10, Math.round(Math.log(span) / Math.LN10) - 1);
6614
6764
  }
6615
6765
  function d3_scale_linearTickRange(domain, m) {
6616
6766
  var extent = d3_scaleExtent(domain), span = extent[1] - extent[0], step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)), err = m / span * step;
@@ -6652,7 +6802,23 @@ d3 = function() {
6652
6802
  return scale;
6653
6803
  };
6654
6804
  scale.nice = function() {
6655
- linear.domain(d3_scale_nice(domain, nice).map(log));
6805
+ function floor(x) {
6806
+ return Math.pow(base, Math.floor(Math.log(x) / Math.log(base)));
6807
+ }
6808
+ function ceil(x) {
6809
+ return Math.pow(base, Math.ceil(Math.log(x) / Math.log(base)));
6810
+ }
6811
+ linear.domain(d3_scale_nice(domain, log === d3_scale_logp ? {
6812
+ floor: floor,
6813
+ ceil: ceil
6814
+ } : {
6815
+ floor: function(x) {
6816
+ return -ceil(-x);
6817
+ },
6818
+ ceil: function(x) {
6819
+ return -floor(-x);
6820
+ }
6821
+ }).map(log));
6656
6822
  return scale;
6657
6823
  };
6658
6824
  scale.ticks = function() {
@@ -6673,8 +6839,8 @@ d3 = function() {
6673
6839
  return ticks;
6674
6840
  };
6675
6841
  scale.tickFormat = function(n, format) {
6676
- if (arguments.length < 2) format = d3_scale_logFormat;
6677
- if (!arguments.length) return format;
6842
+ if (!arguments.length) return d3_scale_logFormat;
6843
+ if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
6678
6844
  var b = Math.log(base), k = Math.max(.1, n / scale.ticks().length), f = log === d3_scale_logn ? (e = -1e-12,
6679
6845
  Math.floor) : (e = 1e-12, Math.ceil), e;
6680
6846
  return function(d) {
@@ -6684,25 +6850,6 @@ d3 = function() {
6684
6850
  scale.copy = function() {
6685
6851
  return d3_scale_log(linear.copy(), base, log, pow, domain);
6686
6852
  };
6687
- function nice() {
6688
- return log === d3_scale_logp ? {
6689
- floor: floor,
6690
- ceil: ceil
6691
- } : {
6692
- floor: function(x) {
6693
- return -ceil(-x);
6694
- },
6695
- ceil: function(x) {
6696
- return -floor(-x);
6697
- }
6698
- };
6699
- }
6700
- function floor(x) {
6701
- return Math.pow(base, Math.floor(Math.log(x) / Math.log(base)));
6702
- }
6703
- function ceil(x) {
6704
- return Math.pow(base, Math.ceil(Math.log(x) / Math.log(base)));
6705
- }
6706
6853
  return d3_scale_linearRebind(scale, linear);
6707
6854
  }
6708
6855
  var d3_scale_logFormat = d3.format(".0e");
@@ -6740,8 +6887,8 @@ d3 = function() {
6740
6887
  scale.tickFormat = function(m, format) {
6741
6888
  return d3_scale_linearTickFormat(domain, m, format);
6742
6889
  };
6743
- scale.nice = function() {
6744
- return scale.domain(d3_scale_nice(domain, d3_scale_linearNice));
6890
+ scale.nice = function(m) {
6891
+ return scale.domain(d3_scale_linearNice(domain, m));
6745
6892
  };
6746
6893
  scale.exponent = function(x) {
6747
6894
  if (!arguments.length) return exponent;
@@ -6923,6 +7070,11 @@ d3 = function() {
6923
7070
  scale.copy = function() {
6924
7071
  return d3_scale_quantize(x0, x1, range);
6925
7072
  };
7073
+ scale.invertExtent = function(y) {
7074
+ y = range.indexOf(y);
7075
+ y = y < 0 ? NaN : y / kx + x0;
7076
+ return [ y, y + 1 / kx ];
7077
+ };
6926
7078
  return rescale();
6927
7079
  }
6928
7080
  d3.scale.threshold = function() {
@@ -6942,6 +7094,10 @@ d3 = function() {
6942
7094
  range = _;
6943
7095
  return scale;
6944
7096
  };
7097
+ scale.invertExtent = function(y) {
7098
+ y = range.indexOf(y);
7099
+ return [ domain[y - 1], domain[y] ];
7100
+ };
6945
7101
  scale.copy = function() {
6946
7102
  return d3_scale_threshold(domain, range);
6947
7103
  };
@@ -7567,7 +7723,7 @@ d3 = function() {
7567
7723
  var g = d3.select(this);
7568
7724
  var ticks = tickValues == null ? scale.ticks ? scale.ticks.apply(scale, tickArguments_) : scale.domain() : tickValues, tickFormat = tickFormat_ == null ? scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments_) : String : tickFormat_;
7569
7725
  var subticks = d3_svg_axisSubdivide(scale, ticks, tickSubdivide), subtick = g.selectAll(".tick.minor").data(subticks, String), subtickEnter = subtick.enter().insert("line", ".tick").attr("class", "tick minor").style("opacity", 1e-6), subtickExit = d3.transition(subtick.exit()).style("opacity", 1e-6).remove(), subtickUpdate = d3.transition(subtick).style("opacity", 1);
7570
- var tick = g.selectAll(".tick.major").data(ticks, String), tickEnter = tick.enter().insert("g", "path").attr("class", "tick major").style("opacity", 1e-6), tickExit = d3.transition(tick.exit()).style("opacity", 1e-6).remove(), tickUpdate = d3.transition(tick).style("opacity", 1), tickTransform;
7726
+ var tick = g.selectAll(".tick.major").data(ticks, String), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick major").style("opacity", 1e-6), tickExit = d3.transition(tick.exit()).style("opacity", 1e-6).remove(), tickUpdate = d3.transition(tick).style("opacity", 1), tickTransform;
7571
7727
  var range = d3_scaleRange(scale), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
7572
7728
  d3.transition(path));
7573
7729
  var scale1 = scale.copy(), scale0 = this.__chart__ || scale1;
@@ -7727,7 +7883,7 @@ d3 = function() {
7727
7883
  return subticks;
7728
7884
  }
7729
7885
  d3.svg.brush = function() {
7730
- var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, resizes = d3_svg_brushResizes[0], extent = [ [ 0, 0 ], [ 0, 0 ] ], extentDomain;
7886
+ var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, resizes = d3_svg_brushResizes[0], extent = [ [ 0, 0 ], [ 0, 0 ] ], clamp = [ true, true ], extentDomain;
7731
7887
  function brush(g) {
7732
7888
  g.each(function() {
7733
7889
  var g = d3.select(this), bg = g.selectAll(".background").data([ 0 ]), fg = g.selectAll(".extent").data([ 0 ]), tz = g.selectAll(".resize").data(resizes, String), e;
@@ -7848,7 +8004,7 @@ d3 = function() {
7848
8004
  r0 -= position;
7849
8005
  r1 -= size + position;
7850
8006
  }
7851
- min = Math.max(r0, Math.min(r1, point[i]));
8007
+ min = clamp[i] ? Math.max(r0, Math.min(r1, point[i])) : point[i];
7852
8008
  if (dragging) {
7853
8009
  max = (min += position) + size;
7854
8010
  } else {
@@ -7890,6 +8046,11 @@ d3 = function() {
7890
8046
  resizes = d3_svg_brushResizes[!x << 1 | !y];
7891
8047
  return brush;
7892
8048
  };
8049
+ brush.clamp = function(z) {
8050
+ if (!arguments.length) return x && y ? clamp : clamp[+!x];
8051
+ if (x && y) clamp = [ !!z[0], !!z[1] ]; else clamp[+!x] = !!z;
8052
+ return brush;
8053
+ };
7893
8054
  brush.extent = function(z) {
7894
8055
  var x0, x1, y0, y1, t;
7895
8056
  if (!arguments.length) {
@@ -8094,7 +8255,7 @@ d3 = function() {
8094
8255
  d3.time.years = d3.time.year.range;
8095
8256
  d3.time.years.utc = d3.time.year.utc.range;
8096
8257
  d3.time.day = d3_time_interval(function(date) {
8097
- var day = new d3_time(1970, 0);
8258
+ var day = new d3_time(2e3, 0);
8098
8259
  day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
8099
8260
  return day;
8100
8261
  }, function(date, offset) {
@@ -8160,7 +8321,10 @@ d3 = function() {
8160
8321
  if (i != string.length) return null;
8161
8322
  if ("p" in d) d.H = d.H % 12 + d.p * 12;
8162
8323
  var date = new d3_time();
8163
- date.setFullYear(d.y, d.m, d.d);
8324
+ if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
8325
+ date.setFullYear(d.y, 0, 1);
8326
+ date.setFullYear(d.y, 0, "W" in d ? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7 : d.w + d.U * 7 - (date.getDay() + 6) % 7);
8327
+ } else date.setFullYear(d.y, d.m, d.d);
8164
8328
  date.setHours(d.H, d.M, d.S, d.L);
8165
8329
  return date;
8166
8330
  };
@@ -8192,11 +8356,10 @@ d3 = function() {
8192
8356
  return map;
8193
8357
  }
8194
8358
  function d3_time_formatPad(value, fill, width) {
8195
- value += "";
8196
- var length = value.length;
8197
- return length < width ? new Array(width - length + 1).join(fill) + value : value;
8359
+ var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
8360
+ return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
8198
8361
  }
8199
- var d3_time_dayRe = d3_time_formatRe(d3_time_days), d3_time_dayAbbrevRe = d3_time_formatRe(d3_time_dayAbbreviations), d3_time_monthRe = d3_time_formatRe(d3_time_months), d3_time_monthLookup = d3_time_formatLookup(d3_time_months), d3_time_monthAbbrevRe = d3_time_formatRe(d3_time_monthAbbreviations), d3_time_monthAbbrevLookup = d3_time_formatLookup(d3_time_monthAbbreviations);
8362
+ var d3_time_dayRe = d3_time_formatRe(d3_time_days), d3_time_dayLookup = d3_time_formatLookup(d3_time_days), d3_time_dayAbbrevRe = d3_time_formatRe(d3_time_dayAbbreviations), d3_time_dayAbbrevLookup = d3_time_formatLookup(d3_time_dayAbbreviations), d3_time_monthRe = d3_time_formatRe(d3_time_months), d3_time_monthLookup = d3_time_formatLookup(d3_time_months), d3_time_monthAbbrevRe = d3_time_formatRe(d3_time_monthAbbreviations), d3_time_monthAbbrevLookup = d3_time_formatLookup(d3_time_monthAbbreviations), d3_time_percentRe = /^%/;
8200
8363
  var d3_time_formatPads = {
8201
8364
  "-": "",
8202
8365
  _: " ",
@@ -8278,35 +8441,55 @@ d3 = function() {
8278
8441
  e: d3_time_parseDay,
8279
8442
  H: d3_time_parseHour24,
8280
8443
  I: d3_time_parseHour24,
8444
+ j: d3_time_parseDayOfYear,
8281
8445
  L: d3_time_parseMilliseconds,
8282
8446
  m: d3_time_parseMonthNumber,
8283
8447
  M: d3_time_parseMinutes,
8284
8448
  p: d3_time_parseAmPm,
8285
8449
  S: d3_time_parseSeconds,
8450
+ U: d3_time_parseWeekNumberSunday,
8451
+ w: d3_time_parseWeekdayNumber,
8452
+ W: d3_time_parseWeekNumberMonday,
8286
8453
  x: d3_time_parseLocaleDate,
8287
8454
  X: d3_time_parseLocaleTime,
8288
8455
  y: d3_time_parseYear,
8289
- Y: d3_time_parseFullYear
8456
+ Y: d3_time_parseFullYear,
8457
+ "%": d3_time_parseLiteralPercent
8290
8458
  };
8291
8459
  function d3_time_parseWeekdayAbbrev(date, string, i) {
8292
8460
  d3_time_dayAbbrevRe.lastIndex = 0;
8293
8461
  var n = d3_time_dayAbbrevRe.exec(string.substring(i));
8294
- return n ? i += n[0].length : -1;
8462
+ return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
8295
8463
  }
8296
8464
  function d3_time_parseWeekday(date, string, i) {
8297
8465
  d3_time_dayRe.lastIndex = 0;
8298
8466
  var n = d3_time_dayRe.exec(string.substring(i));
8299
- return n ? i += n[0].length : -1;
8467
+ return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
8468
+ }
8469
+ function d3_time_parseWeekdayNumber(date, string, i) {
8470
+ d3_time_numberRe.lastIndex = 0;
8471
+ var n = d3_time_numberRe.exec(string.substring(i, i + 1));
8472
+ return n ? (date.w = +n[0], i + n[0].length) : -1;
8473
+ }
8474
+ function d3_time_parseWeekNumberSunday(date, string, i) {
8475
+ d3_time_numberRe.lastIndex = 0;
8476
+ var n = d3_time_numberRe.exec(string.substring(i));
8477
+ return n ? (date.U = +n[0], i + n[0].length) : -1;
8478
+ }
8479
+ function d3_time_parseWeekNumberMonday(date, string, i) {
8480
+ d3_time_numberRe.lastIndex = 0;
8481
+ var n = d3_time_numberRe.exec(string.substring(i));
8482
+ return n ? (date.W = +n[0], i + n[0].length) : -1;
8300
8483
  }
8301
8484
  function d3_time_parseMonthAbbrev(date, string, i) {
8302
8485
  d3_time_monthAbbrevRe.lastIndex = 0;
8303
8486
  var n = d3_time_monthAbbrevRe.exec(string.substring(i));
8304
- return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
8487
+ return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
8305
8488
  }
8306
8489
  function d3_time_parseMonth(date, string, i) {
8307
8490
  d3_time_monthRe.lastIndex = 0;
8308
8491
  var n = d3_time_monthRe.exec(string.substring(i));
8309
- return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
8492
+ return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
8310
8493
  }
8311
8494
  function d3_time_parseLocaleFull(date, string, i) {
8312
8495
  return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
@@ -8320,12 +8503,12 @@ d3 = function() {
8320
8503
  function d3_time_parseFullYear(date, string, i) {
8321
8504
  d3_time_numberRe.lastIndex = 0;
8322
8505
  var n = d3_time_numberRe.exec(string.substring(i, i + 4));
8323
- return n ? (date.y = +n[0], i += n[0].length) : -1;
8506
+ return n ? (date.y = +n[0], i + n[0].length) : -1;
8324
8507
  }
8325
8508
  function d3_time_parseYear(date, string, i) {
8326
8509
  d3_time_numberRe.lastIndex = 0;
8327
8510
  var n = d3_time_numberRe.exec(string.substring(i, i + 2));
8328
- return n ? (date.y = d3_time_expandYear(+n[0]), i += n[0].length) : -1;
8511
+ return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
8329
8512
  }
8330
8513
  function d3_time_expandYear(d) {
8331
8514
  return d + (d > 68 ? 1900 : 2e3);
@@ -8333,32 +8516,37 @@ d3 = function() {
8333
8516
  function d3_time_parseMonthNumber(date, string, i) {
8334
8517
  d3_time_numberRe.lastIndex = 0;
8335
8518
  var n = d3_time_numberRe.exec(string.substring(i, i + 2));
8336
- return n ? (date.m = n[0] - 1, i += n[0].length) : -1;
8519
+ return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
8337
8520
  }
8338
8521
  function d3_time_parseDay(date, string, i) {
8339
8522
  d3_time_numberRe.lastIndex = 0;
8340
8523
  var n = d3_time_numberRe.exec(string.substring(i, i + 2));
8341
- return n ? (date.d = +n[0], i += n[0].length) : -1;
8524
+ return n ? (date.d = +n[0], i + n[0].length) : -1;
8525
+ }
8526
+ function d3_time_parseDayOfYear(date, string, i) {
8527
+ d3_time_numberRe.lastIndex = 0;
8528
+ var n = d3_time_numberRe.exec(string.substring(i, i + 3));
8529
+ return n ? (date.j = +n[0], i + n[0].length) : -1;
8342
8530
  }
8343
8531
  function d3_time_parseHour24(date, string, i) {
8344
8532
  d3_time_numberRe.lastIndex = 0;
8345
8533
  var n = d3_time_numberRe.exec(string.substring(i, i + 2));
8346
- return n ? (date.H = +n[0], i += n[0].length) : -1;
8534
+ return n ? (date.H = +n[0], i + n[0].length) : -1;
8347
8535
  }
8348
8536
  function d3_time_parseMinutes(date, string, i) {
8349
8537
  d3_time_numberRe.lastIndex = 0;
8350
8538
  var n = d3_time_numberRe.exec(string.substring(i, i + 2));
8351
- return n ? (date.M = +n[0], i += n[0].length) : -1;
8539
+ return n ? (date.M = +n[0], i + n[0].length) : -1;
8352
8540
  }
8353
8541
  function d3_time_parseSeconds(date, string, i) {
8354
8542
  d3_time_numberRe.lastIndex = 0;
8355
8543
  var n = d3_time_numberRe.exec(string.substring(i, i + 2));
8356
- return n ? (date.S = +n[0], i += n[0].length) : -1;
8544
+ return n ? (date.S = +n[0], i + n[0].length) : -1;
8357
8545
  }
8358
8546
  function d3_time_parseMilliseconds(date, string, i) {
8359
8547
  d3_time_numberRe.lastIndex = 0;
8360
8548
  var n = d3_time_numberRe.exec(string.substring(i, i + 3));
8361
- return n ? (date.L = +n[0], i += n[0].length) : -1;
8549
+ return n ? (date.L = +n[0], i + n[0].length) : -1;
8362
8550
  }
8363
8551
  var d3_time_numberRe = /^\s*\d+/;
8364
8552
  function d3_time_parseAmPm(date, string, i) {
@@ -8373,6 +8561,11 @@ d3 = function() {
8373
8561
  var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = ~~(Math.abs(z) / 60), zm = Math.abs(z) % 60;
8374
8562
  return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
8375
8563
  }
8564
+ function d3_time_parseLiteralPercent(date, string, i) {
8565
+ d3_time_percentRe.lastIndex = 0;
8566
+ var n = d3_time_percentRe.exec(string.substring(i, i + 1));
8567
+ return n ? i + n[0].length : -1;
8568
+ }
8376
8569
  d3.time.format.utc = function(template) {
8377
8570
  var local = d3.time.format(template);
8378
8571
  function format(date) {
@@ -8459,9 +8652,7 @@ d3 = function() {
8459
8652
  return scale;
8460
8653
  };
8461
8654
  scale.nice = function(m) {
8462
- return scale.domain(d3_scale_nice(scale.domain(), function() {
8463
- return m;
8464
- }));
8655
+ return scale.domain(d3_scale_nice(scale.domain(), m));
8465
8656
  };
8466
8657
  scale.ticks = function(m, k) {
8467
8658
  var extent = d3_scaleExtent(scale.domain());