Le repo des sources pour le site web des JM2L
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

9470 lines
328 KiB

  1. !function() {
  2. var d3 = {
  3. version: "3.5.2"
  4. };
  5. if (!Date.now) Date.now = function() {
  6. return +new Date();
  7. };
  8. var d3_arraySlice = [].slice, d3_array = function(list) {
  9. return d3_arraySlice.call(list);
  10. };
  11. var d3_document = document, d3_documentElement = d3_document.documentElement, d3_window = window;
  12. try {
  13. d3_array(d3_documentElement.childNodes)[0].nodeType;
  14. } catch (e) {
  15. d3_array = function(list) {
  16. var i = list.length, array = new Array(i);
  17. while (i--) array[i] = list[i];
  18. return array;
  19. };
  20. }
  21. try {
  22. d3_document.createElement("div").style.setProperty("opacity", 0, "");
  23. } catch (error) {
  24. var d3_element_prototype = d3_window.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = d3_window.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
  25. d3_element_prototype.setAttribute = function(name, value) {
  26. d3_element_setAttribute.call(this, name, value + "");
  27. };
  28. d3_element_prototype.setAttributeNS = function(space, local, value) {
  29. d3_element_setAttributeNS.call(this, space, local, value + "");
  30. };
  31. d3_style_prototype.setProperty = function(name, value, priority) {
  32. d3_style_setProperty.call(this, name, value + "", priority);
  33. };
  34. }
  35. d3.ascending = d3_ascending;
  36. function d3_ascending(a, b) {
  37. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  38. }
  39. d3.descending = function(a, b) {
  40. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  41. };
  42. d3.min = function(array, f) {
  43. var i = -1, n = array.length, a, b;
  44. if (arguments.length === 1) {
  45. while (++i < n) if ((b = array[i]) != null && b >= b) {
  46. a = b;
  47. break;
  48. }
  49. while (++i < n) if ((b = array[i]) != null && a > b) a = b;
  50. } else {
  51. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  52. a = b;
  53. break;
  54. }
  55. while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
  56. }
  57. return a;
  58. };
  59. d3.max = function(array, f) {
  60. var i = -1, n = array.length, a, b;
  61. if (arguments.length === 1) {
  62. while (++i < n) if ((b = array[i]) != null && b >= b) {
  63. a = b;
  64. break;
  65. }
  66. while (++i < n) if ((b = array[i]) != null && b > a) a = b;
  67. } else {
  68. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  69. a = b;
  70. break;
  71. }
  72. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
  73. }
  74. return a;
  75. };
  76. d3.extent = function(array, f) {
  77. var i = -1, n = array.length, a, b, c;
  78. if (arguments.length === 1) {
  79. while (++i < n) if ((b = array[i]) != null && b >= b) {
  80. a = c = b;
  81. break;
  82. }
  83. while (++i < n) if ((b = array[i]) != null) {
  84. if (a > b) a = b;
  85. if (c < b) c = b;
  86. }
  87. } else {
  88. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  89. a = c = b;
  90. break;
  91. }
  92. while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
  93. if (a > b) a = b;
  94. if (c < b) c = b;
  95. }
  96. }
  97. return [ a, c ];
  98. };
  99. function d3_number(x) {
  100. return x === null ? NaN : +x;
  101. }
  102. function d3_numeric(x) {
  103. return !isNaN(x);
  104. }
  105. d3.sum = function(array, f) {
  106. var s = 0, n = array.length, a, i = -1;
  107. if (arguments.length === 1) {
  108. while (++i < n) if (d3_numeric(a = +array[i])) s += a;
  109. } else {
  110. while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
  111. }
  112. return s;
  113. };
  114. d3.mean = function(array, f) {
  115. var s = 0, n = array.length, a, i = -1, j = n;
  116. if (arguments.length === 1) {
  117. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
  118. } else {
  119. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
  120. }
  121. if (j) return s / j;
  122. };
  123. d3.quantile = function(values, p) {
  124. var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
  125. return e ? v + e * (values[h] - v) : v;
  126. };
  127. d3.median = function(array, f) {
  128. var numbers = [], n = array.length, a, i = -1;
  129. if (arguments.length === 1) {
  130. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
  131. } else {
  132. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
  133. }
  134. if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
  135. };
  136. d3.variance = function(array, f) {
  137. var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
  138. if (arguments.length === 1) {
  139. while (++i < n) {
  140. if (d3_numeric(a = d3_number(array[i]))) {
  141. d = a - m;
  142. m += d / ++j;
  143. s += d * (a - m);
  144. }
  145. }
  146. } else {
  147. while (++i < n) {
  148. if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
  149. d = a - m;
  150. m += d / ++j;
  151. s += d * (a - m);
  152. }
  153. }
  154. }
  155. if (j > 1) return s / (j - 1);
  156. };
  157. d3.deviation = function() {
  158. var v = d3.variance.apply(this, arguments);
  159. return v ? Math.sqrt(v) : v;
  160. };
  161. function d3_bisector(compare) {
  162. return {
  163. left: function(a, x, lo, hi) {
  164. if (arguments.length < 3) lo = 0;
  165. if (arguments.length < 4) hi = a.length;
  166. while (lo < hi) {
  167. var mid = lo + hi >>> 1;
  168. if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
  169. }
  170. return lo;
  171. },
  172. right: function(a, x, lo, hi) {
  173. if (arguments.length < 3) lo = 0;
  174. if (arguments.length < 4) hi = a.length;
  175. while (lo < hi) {
  176. var mid = lo + hi >>> 1;
  177. if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
  178. }
  179. return lo;
  180. }
  181. };
  182. }
  183. var d3_bisect = d3_bisector(d3_ascending);
  184. d3.bisectLeft = d3_bisect.left;
  185. d3.bisect = d3.bisectRight = d3_bisect.right;
  186. d3.bisector = function(f) {
  187. return d3_bisector(f.length === 1 ? function(d, x) {
  188. return d3_ascending(f(d), x);
  189. } : f);
  190. };
  191. d3.shuffle = function(array, i0, i1) {
  192. if ((m = arguments.length) < 3) {
  193. i1 = array.length;
  194. if (m < 2) i0 = 0;
  195. }
  196. var m = i1 - i0, t, i;
  197. while (m) {
  198. i = Math.random() * m-- | 0;
  199. t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
  200. }
  201. return array;
  202. };
  203. d3.permute = function(array, indexes) {
  204. var i = indexes.length, permutes = new Array(i);
  205. while (i--) permutes[i] = array[indexes[i]];
  206. return permutes;
  207. };
  208. d3.pairs = function(array) {
  209. var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
  210. while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
  211. return pairs;
  212. };
  213. d3.zip = function() {
  214. if (!(n = arguments.length)) return [];
  215. for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
  216. for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
  217. zip[j] = arguments[j][i];
  218. }
  219. }
  220. return zips;
  221. };
  222. function d3_zipLength(d) {
  223. return d.length;
  224. }
  225. d3.transpose = function(matrix) {
  226. return d3.zip.apply(d3, matrix);
  227. };
  228. d3.keys = function(map) {
  229. var keys = [];
  230. for (var key in map) keys.push(key);
  231. return keys;
  232. };
  233. d3.values = function(map) {
  234. var values = [];
  235. for (var key in map) values.push(map[key]);
  236. return values;
  237. };
  238. d3.entries = function(map) {
  239. var entries = [];
  240. for (var key in map) entries.push({
  241. key: key,
  242. value: map[key]
  243. });
  244. return entries;
  245. };
  246. d3.merge = function(arrays) {
  247. var n = arrays.length, m, i = -1, j = 0, merged, array;
  248. while (++i < n) j += arrays[i].length;
  249. merged = new Array(j);
  250. while (--n >= 0) {
  251. array = arrays[n];
  252. m = array.length;
  253. while (--m >= 0) {
  254. merged[--j] = array[m];
  255. }
  256. }
  257. return merged;
  258. };
  259. var abs = Math.abs;
  260. d3.range = function(start, stop, step) {
  261. if (arguments.length < 3) {
  262. step = 1;
  263. if (arguments.length < 2) {
  264. stop = start;
  265. start = 0;
  266. }
  267. }
  268. if ((stop - start) / step === Infinity) throw new Error("infinite range");
  269. var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
  270. start *= k, stop *= k, step *= k;
  271. if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
  272. return range;
  273. };
  274. function d3_range_integerScale(x) {
  275. var k = 1;
  276. while (x * k % 1) k *= 10;
  277. return k;
  278. }
  279. function d3_class(ctor, properties) {
  280. for (var key in properties) {
  281. Object.defineProperty(ctor.prototype, key, {
  282. value: properties[key],
  283. enumerable: false
  284. });
  285. }
  286. }
  287. d3.map = function(object, f) {
  288. var map = new d3_Map();
  289. if (object instanceof d3_Map) {
  290. object.forEach(function(key, value) {
  291. map.set(key, value);
  292. });
  293. } else if (Array.isArray(object)) {
  294. var i = -1, n = object.length, o;
  295. if (arguments.length === 1) while (++i < n) map.set(i, object[i]); else while (++i < n) map.set(f.call(object, o = object[i], i), o);
  296. } else {
  297. for (var key in object) map.set(key, object[key]);
  298. }
  299. return map;
  300. };
  301. function d3_Map() {
  302. this._ = Object.create(null);
  303. }
  304. var d3_map_proto = "__proto__", d3_map_zero = "\x00";
  305. d3_class(d3_Map, {
  306. has: d3_map_has,
  307. get: function(key) {
  308. return this._[d3_map_escape(key)];
  309. },
  310. set: function(key, value) {
  311. return this._[d3_map_escape(key)] = value;
  312. },
  313. remove: d3_map_remove,
  314. keys: d3_map_keys,
  315. values: function() {
  316. var values = [];
  317. for (var key in this._) values.push(this._[key]);
  318. return values;
  319. },
  320. entries: function() {
  321. var entries = [];
  322. for (var key in this._) entries.push({
  323. key: d3_map_unescape(key),
  324. value: this._[key]
  325. });
  326. return entries;
  327. },
  328. size: d3_map_size,
  329. empty: d3_map_empty,
  330. forEach: function(f) {
  331. for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
  332. }
  333. });
  334. function d3_map_escape(key) {
  335. return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
  336. }
  337. function d3_map_unescape(key) {
  338. return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
  339. }
  340. function d3_map_has(key) {
  341. return d3_map_escape(key) in this._;
  342. }
  343. function d3_map_remove(key) {
  344. return (key = d3_map_escape(key)) in this._ && delete this._[key];
  345. }
  346. function d3_map_keys() {
  347. var keys = [];
  348. for (var key in this._) keys.push(d3_map_unescape(key));
  349. return keys;
  350. }
  351. function d3_map_size() {
  352. var size = 0;
  353. for (var key in this._) ++size;
  354. return size;
  355. }
  356. function d3_map_empty() {
  357. for (var key in this._) return false;
  358. return true;
  359. }
  360. d3.nest = function() {
  361. var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
  362. function map(mapType, array, depth) {
  363. if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
  364. var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
  365. while (++i < n) {
  366. if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
  367. values.push(object);
  368. } else {
  369. valuesByKey.set(keyValue, [ object ]);
  370. }
  371. }
  372. if (mapType) {
  373. object = mapType();
  374. setter = function(keyValue, values) {
  375. object.set(keyValue, map(mapType, values, depth));
  376. };
  377. } else {
  378. object = {};
  379. setter = function(keyValue, values) {
  380. object[keyValue] = map(mapType, values, depth);
  381. };
  382. }
  383. valuesByKey.forEach(setter);
  384. return object;
  385. }
  386. function entries(map, depth) {
  387. if (depth >= keys.length) return map;
  388. var array = [], sortKey = sortKeys[depth++];
  389. map.forEach(function(key, keyMap) {
  390. array.push({
  391. key: key,
  392. values: entries(keyMap, depth)
  393. });
  394. });
  395. return sortKey ? array.sort(function(a, b) {
  396. return sortKey(a.key, b.key);
  397. }) : array;
  398. }
  399. nest.map = function(array, mapType) {
  400. return map(mapType, array, 0);
  401. };
  402. nest.entries = function(array) {
  403. return entries(map(d3.map, array, 0), 0);
  404. };
  405. nest.key = function(d) {
  406. keys.push(d);
  407. return nest;
  408. };
  409. nest.sortKeys = function(order) {
  410. sortKeys[keys.length - 1] = order;
  411. return nest;
  412. };
  413. nest.sortValues = function(order) {
  414. sortValues = order;
  415. return nest;
  416. };
  417. nest.rollup = function(f) {
  418. rollup = f;
  419. return nest;
  420. };
  421. return nest;
  422. };
  423. d3.set = function(array) {
  424. var set = new d3_Set();
  425. if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
  426. return set;
  427. };
  428. function d3_Set() {
  429. this._ = Object.create(null);
  430. }
  431. d3_class(d3_Set, {
  432. has: d3_map_has,
  433. add: function(key) {
  434. this._[d3_map_escape(key += "")] = true;
  435. return key;
  436. },
  437. remove: d3_map_remove,
  438. values: d3_map_keys,
  439. size: d3_map_size,
  440. empty: d3_map_empty,
  441. forEach: function(f) {
  442. for (var key in this._) f.call(this, d3_map_unescape(key));
  443. }
  444. });
  445. d3.behavior = {};
  446. d3.rebind = function(target, source) {
  447. var i = 1, n = arguments.length, method;
  448. while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
  449. return target;
  450. };
  451. function d3_rebind(target, source, method) {
  452. return function() {
  453. var value = method.apply(source, arguments);
  454. return value === source ? target : value;
  455. };
  456. }
  457. function d3_vendorSymbol(object, name) {
  458. if (name in object) return name;
  459. name = name.charAt(0).toUpperCase() + name.slice(1);
  460. for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
  461. var prefixName = d3_vendorPrefixes[i] + name;
  462. if (prefixName in object) return prefixName;
  463. }
  464. }
  465. var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
  466. function d3_noop() {}
  467. d3.dispatch = function() {
  468. var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
  469. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  470. return dispatch;
  471. };
  472. function d3_dispatch() {}
  473. d3_dispatch.prototype.on = function(type, listener) {
  474. var i = type.indexOf("."), name = "";
  475. if (i >= 0) {
  476. name = type.slice(i + 1);
  477. type = type.slice(0, i);
  478. }
  479. if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
  480. if (arguments.length === 2) {
  481. if (listener == null) for (type in this) {
  482. if (this.hasOwnProperty(type)) this[type].on(name, null);
  483. }
  484. return this;
  485. }
  486. };
  487. function d3_dispatch_event(dispatch) {
  488. var listeners = [], listenerByName = new d3_Map();
  489. function event() {
  490. var z = listeners, i = -1, n = z.length, l;
  491. while (++i < n) if (l = z[i].on) l.apply(this, arguments);
  492. return dispatch;
  493. }
  494. event.on = function(name, listener) {
  495. var l = listenerByName.get(name), i;
  496. if (arguments.length < 2) return l && l.on;
  497. if (l) {
  498. l.on = null;
  499. listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
  500. listenerByName.remove(name);
  501. }
  502. if (listener) listeners.push(listenerByName.set(name, {
  503. on: listener
  504. }));
  505. return dispatch;
  506. };
  507. return event;
  508. }
  509. d3.event = null;
  510. function d3_eventPreventDefault() {
  511. d3.event.preventDefault();
  512. }
  513. function d3_eventSource() {
  514. var e = d3.event, s;
  515. while (s = e.sourceEvent) e = s;
  516. return e;
  517. }
  518. function d3_eventDispatch(target) {
  519. var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
  520. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  521. dispatch.of = function(thiz, argumentz) {
  522. return function(e1) {
  523. try {
  524. var e0 = e1.sourceEvent = d3.event;
  525. e1.target = target;
  526. d3.event = e1;
  527. dispatch[e1.type].apply(thiz, argumentz);
  528. } finally {
  529. d3.event = e0;
  530. }
  531. };
  532. };
  533. return dispatch;
  534. }
  535. d3.requote = function(s) {
  536. return s.replace(d3_requote_re, "\\$&");
  537. };
  538. var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  539. var d3_subclass = {}.__proto__ ? function(object, prototype) {
  540. object.__proto__ = prototype;
  541. } : function(object, prototype) {
  542. for (var property in prototype) object[property] = prototype[property];
  543. };
  544. function d3_selection(groups) {
  545. d3_subclass(groups, d3_selectionPrototype);
  546. return groups;
  547. }
  548. var d3_select = function(s, n) {
  549. return n.querySelector(s);
  550. }, d3_selectAll = function(s, n) {
  551. return n.querySelectorAll(s);
  552. }, d3_selectMatcher = d3_documentElement.matches || d3_documentElement[d3_vendorSymbol(d3_documentElement, "matchesSelector")], d3_selectMatches = function(n, s) {
  553. return d3_selectMatcher.call(n, s);
  554. };
  555. if (typeof Sizzle === "function") {
  556. d3_select = function(s, n) {
  557. return Sizzle(s, n)[0] || null;
  558. };
  559. d3_selectAll = Sizzle;
  560. d3_selectMatches = Sizzle.matchesSelector;
  561. }
  562. d3.selection = function() {
  563. return d3_selectionRoot;
  564. };
  565. var d3_selectionPrototype = d3.selection.prototype = [];
  566. d3_selectionPrototype.select = function(selector) {
  567. var subgroups = [], subgroup, subnode, group, node;
  568. selector = d3_selection_selector(selector);
  569. for (var j = -1, m = this.length; ++j < m; ) {
  570. subgroups.push(subgroup = []);
  571. subgroup.parentNode = (group = this[j]).parentNode;
  572. for (var i = -1, n = group.length; ++i < n; ) {
  573. if (node = group[i]) {
  574. subgroup.push(subnode = selector.call(node, node.__data__, i, j));
  575. if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
  576. } else {
  577. subgroup.push(null);
  578. }
  579. }
  580. }
  581. return d3_selection(subgroups);
  582. };
  583. function d3_selection_selector(selector) {
  584. return typeof selector === "function" ? selector : function() {
  585. return d3_select(selector, this);
  586. };
  587. }
  588. d3_selectionPrototype.selectAll = function(selector) {
  589. var subgroups = [], subgroup, node;
  590. selector = d3_selection_selectorAll(selector);
  591. for (var j = -1, m = this.length; ++j < m; ) {
  592. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  593. if (node = group[i]) {
  594. subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
  595. subgroup.parentNode = node;
  596. }
  597. }
  598. }
  599. return d3_selection(subgroups);
  600. };
  601. function d3_selection_selectorAll(selector) {
  602. return typeof selector === "function" ? selector : function() {
  603. return d3_selectAll(selector, this);
  604. };
  605. }
  606. var d3_nsPrefix = {
  607. svg: "http://www.w3.org/2000/svg",
  608. xhtml: "http://www.w3.org/1999/xhtml",
  609. xlink: "http://www.w3.org/1999/xlink",
  610. xml: "http://www.w3.org/XML/1998/namespace",
  611. xmlns: "http://www.w3.org/2000/xmlns/"
  612. };
  613. d3.ns = {
  614. prefix: d3_nsPrefix,
  615. qualify: function(name) {
  616. var i = name.indexOf(":"), prefix = name;
  617. if (i >= 0) {
  618. prefix = name.slice(0, i);
  619. name = name.slice(i + 1);
  620. }
  621. return d3_nsPrefix.hasOwnProperty(prefix) ? {
  622. space: d3_nsPrefix[prefix],
  623. local: name
  624. } : name;
  625. }
  626. };
  627. d3_selectionPrototype.attr = function(name, value) {
  628. if (arguments.length < 2) {
  629. if (typeof name === "string") {
  630. var node = this.node();
  631. name = d3.ns.qualify(name);
  632. return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
  633. }
  634. for (value in name) this.each(d3_selection_attr(value, name[value]));
  635. return this;
  636. }
  637. return this.each(d3_selection_attr(name, value));
  638. };
  639. function d3_selection_attr(name, value) {
  640. name = d3.ns.qualify(name);
  641. function attrNull() {
  642. this.removeAttribute(name);
  643. }
  644. function attrNullNS() {
  645. this.removeAttributeNS(name.space, name.local);
  646. }
  647. function attrConstant() {
  648. this.setAttribute(name, value);
  649. }
  650. function attrConstantNS() {
  651. this.setAttributeNS(name.space, name.local, value);
  652. }
  653. function attrFunction() {
  654. var x = value.apply(this, arguments);
  655. if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
  656. }
  657. function attrFunctionNS() {
  658. var x = value.apply(this, arguments);
  659. if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
  660. }
  661. return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
  662. }
  663. function d3_collapse(s) {
  664. return s.trim().replace(/\s+/g, " ");
  665. }
  666. d3_selectionPrototype.classed = function(name, value) {
  667. if (arguments.length < 2) {
  668. if (typeof name === "string") {
  669. var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
  670. if (value = node.classList) {
  671. while (++i < n) if (!value.contains(name[i])) return false;
  672. } else {
  673. value = node.getAttribute("class");
  674. while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
  675. }
  676. return true;
  677. }
  678. for (value in name) this.each(d3_selection_classed(value, name[value]));
  679. return this;
  680. }
  681. return this.each(d3_selection_classed(name, value));
  682. };
  683. function d3_selection_classedRe(name) {
  684. return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
  685. }
  686. function d3_selection_classes(name) {
  687. return (name + "").trim().split(/^|\s+/);
  688. }
  689. function d3_selection_classed(name, value) {
  690. name = d3_selection_classes(name).map(d3_selection_classedName);
  691. var n = name.length;
  692. function classedConstant() {
  693. var i = -1;
  694. while (++i < n) name[i](this, value);
  695. }
  696. function classedFunction() {
  697. var i = -1, x = value.apply(this, arguments);
  698. while (++i < n) name[i](this, x);
  699. }
  700. return typeof value === "function" ? classedFunction : classedConstant;
  701. }
  702. function d3_selection_classedName(name) {
  703. var re = d3_selection_classedRe(name);
  704. return function(node, value) {
  705. if (c = node.classList) return value ? c.add(name) : c.remove(name);
  706. var c = node.getAttribute("class") || "";
  707. if (value) {
  708. re.lastIndex = 0;
  709. if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
  710. } else {
  711. node.setAttribute("class", d3_collapse(c.replace(re, " ")));
  712. }
  713. };
  714. }
  715. d3_selectionPrototype.style = function(name, value, priority) {
  716. var n = arguments.length;
  717. if (n < 3) {
  718. if (typeof name !== "string") {
  719. if (n < 2) value = "";
  720. for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
  721. return this;
  722. }
  723. if (n < 2) return d3_window.getComputedStyle(this.node(), null).getPropertyValue(name);
  724. priority = "";
  725. }
  726. return this.each(d3_selection_style(name, value, priority));
  727. };
  728. function d3_selection_style(name, value, priority) {
  729. function styleNull() {
  730. this.style.removeProperty(name);
  731. }
  732. function styleConstant() {
  733. this.style.setProperty(name, value, priority);
  734. }
  735. function styleFunction() {
  736. var x = value.apply(this, arguments);
  737. if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
  738. }
  739. return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
  740. }
  741. d3_selectionPrototype.property = function(name, value) {
  742. if (arguments.length < 2) {
  743. if (typeof name === "string") return this.node()[name];
  744. for (value in name) this.each(d3_selection_property(value, name[value]));
  745. return this;
  746. }
  747. return this.each(d3_selection_property(name, value));
  748. };
  749. function d3_selection_property(name, value) {
  750. function propertyNull() {
  751. delete this[name];
  752. }
  753. function propertyConstant() {
  754. this[name] = value;
  755. }
  756. function propertyFunction() {
  757. var x = value.apply(this, arguments);
  758. if (x == null) delete this[name]; else this[name] = x;
  759. }
  760. return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
  761. }
  762. d3_selectionPrototype.text = function(value) {
  763. return arguments.length ? this.each(typeof value === "function" ? function() {
  764. var v = value.apply(this, arguments);
  765. this.textContent = v == null ? "" : v;
  766. } : value == null ? function() {
  767. this.textContent = "";
  768. } : function() {
  769. this.textContent = value;
  770. }) : this.node().textContent;
  771. };
  772. d3_selectionPrototype.html = function(value) {
  773. return arguments.length ? this.each(typeof value === "function" ? function() {
  774. var v = value.apply(this, arguments);
  775. this.innerHTML = v == null ? "" : v;
  776. } : value == null ? function() {
  777. this.innerHTML = "";
  778. } : function() {
  779. this.innerHTML = value;
  780. }) : this.node().innerHTML;
  781. };
  782. d3_selectionPrototype.append = function(name) {
  783. name = d3_selection_creator(name);
  784. return this.select(function() {
  785. return this.appendChild(name.apply(this, arguments));
  786. });
  787. };
  788. function d3_selection_creator(name) {
  789. return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? function() {
  790. return this.ownerDocument.createElementNS(name.space, name.local);
  791. } : function() {
  792. return this.ownerDocument.createElementNS(this.namespaceURI, name);
  793. };
  794. }
  795. d3_selectionPrototype.insert = function(name, before) {
  796. name = d3_selection_creator(name);
  797. before = d3_selection_selector(before);
  798. return this.select(function() {
  799. return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
  800. });
  801. };
  802. d3_selectionPrototype.remove = function() {
  803. return this.each(d3_selectionRemove);
  804. };
  805. function d3_selectionRemove() {
  806. var parent = this.parentNode;
  807. if (parent) parent.removeChild(this);
  808. }
  809. d3_selectionPrototype.data = function(value, key) {
  810. var i = -1, n = this.length, group, node;
  811. if (!arguments.length) {
  812. value = new Array(n = (group = this[0]).length);
  813. while (++i < n) {
  814. if (node = group[i]) {
  815. value[i] = node.__data__;
  816. }
  817. }
  818. return value;
  819. }
  820. function bind(group, groupData) {
  821. var i, n = group.length, m = groupData.length, n0 = Math.min(n, m), updateNodes = new Array(m), enterNodes = new Array(m), exitNodes = new Array(n), node, nodeData;
  822. if (key) {
  823. var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
  824. for (i = -1; ++i < n; ) {
  825. if (nodeByKeyValue.has(keyValue = key.call(node = group[i], node.__data__, i))) {
  826. exitNodes[i] = node;
  827. } else {
  828. nodeByKeyValue.set(keyValue, node);
  829. }
  830. keyValues[i] = keyValue;
  831. }
  832. for (i = -1; ++i < m; ) {
  833. if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
  834. enterNodes[i] = d3_selection_dataNode(nodeData);
  835. } else if (node !== true) {
  836. updateNodes[i] = node;
  837. node.__data__ = nodeData;
  838. }
  839. nodeByKeyValue.set(keyValue, true);
  840. }
  841. for (i = -1; ++i < n; ) {
  842. if (nodeByKeyValue.get(keyValues[i]) !== true) {
  843. exitNodes[i] = group[i];
  844. }
  845. }
  846. } else {
  847. for (i = -1; ++i < n0; ) {
  848. node = group[i];
  849. nodeData = groupData[i];
  850. if (node) {
  851. node.__data__ = nodeData;
  852. updateNodes[i] = node;
  853. } else {
  854. enterNodes[i] = d3_selection_dataNode(nodeData);
  855. }
  856. }
  857. for (;i < m; ++i) {
  858. enterNodes[i] = d3_selection_dataNode(groupData[i]);
  859. }
  860. for (;i < n; ++i) {
  861. exitNodes[i] = group[i];
  862. }
  863. }
  864. enterNodes.update = updateNodes;
  865. enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
  866. enter.push(enterNodes);
  867. update.push(updateNodes);
  868. exit.push(exitNodes);
  869. }
  870. var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
  871. if (typeof value === "function") {
  872. while (++i < n) {
  873. bind(group = this[i], value.call(group, group.parentNode.__data__, i));
  874. }
  875. } else {
  876. while (++i < n) {
  877. bind(group = this[i], value);
  878. }
  879. }
  880. update.enter = function() {
  881. return enter;
  882. };
  883. update.exit = function() {
  884. return exit;
  885. };
  886. return update;
  887. };
  888. function d3_selection_dataNode(data) {
  889. return {
  890. __data__: data
  891. };
  892. }
  893. d3_selectionPrototype.datum = function(value) {
  894. return arguments.length ? this.property("__data__", value) : this.property("__data__");
  895. };
  896. d3_selectionPrototype.filter = function(filter) {
  897. var subgroups = [], subgroup, group, node;
  898. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  899. for (var j = 0, m = this.length; j < m; j++) {
  900. subgroups.push(subgroup = []);
  901. subgroup.parentNode = (group = this[j]).parentNode;
  902. for (var i = 0, n = group.length; i < n; i++) {
  903. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  904. subgroup.push(node);
  905. }
  906. }
  907. }
  908. return d3_selection(subgroups);
  909. };
  910. function d3_selection_filter(selector) {
  911. return function() {
  912. return d3_selectMatches(this, selector);
  913. };
  914. }
  915. d3_selectionPrototype.order = function() {
  916. for (var j = -1, m = this.length; ++j < m; ) {
  917. for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
  918. if (node = group[i]) {
  919. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  920. next = node;
  921. }
  922. }
  923. }
  924. return this;
  925. };
  926. d3_selectionPrototype.sort = function(comparator) {
  927. comparator = d3_selection_sortComparator.apply(this, arguments);
  928. for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
  929. return this.order();
  930. };
  931. function d3_selection_sortComparator(comparator) {
  932. if (!arguments.length) comparator = d3_ascending;
  933. return function(a, b) {
  934. return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
  935. };
  936. }
  937. d3_selectionPrototype.each = function(callback) {
  938. return d3_selection_each(this, function(node, i, j) {
  939. callback.call(node, node.__data__, i, j);
  940. });
  941. };
  942. function d3_selection_each(groups, callback) {
  943. for (var j = 0, m = groups.length; j < m; j++) {
  944. for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
  945. if (node = group[i]) callback(node, i, j);
  946. }
  947. }
  948. return groups;
  949. }
  950. d3_selectionPrototype.call = function(callback) {
  951. var args = d3_array(arguments);
  952. callback.apply(args[0] = this, args);
  953. return this;
  954. };
  955. d3_selectionPrototype.empty = function() {
  956. return !this.node();
  957. };
  958. d3_selectionPrototype.node = function() {
  959. for (var j = 0, m = this.length; j < m; j++) {
  960. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  961. var node = group[i];
  962. if (node) return node;
  963. }
  964. }
  965. return null;
  966. };
  967. d3_selectionPrototype.size = function() {
  968. var n = 0;
  969. d3_selection_each(this, function() {
  970. ++n;
  971. });
  972. return n;
  973. };
  974. function d3_selection_enter(selection) {
  975. d3_subclass(selection, d3_selection_enterPrototype);
  976. return selection;
  977. }
  978. var d3_selection_enterPrototype = [];
  979. d3.selection.enter = d3_selection_enter;
  980. d3.selection.enter.prototype = d3_selection_enterPrototype;
  981. d3_selection_enterPrototype.append = d3_selectionPrototype.append;
  982. d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
  983. d3_selection_enterPrototype.node = d3_selectionPrototype.node;
  984. d3_selection_enterPrototype.call = d3_selectionPrototype.call;
  985. d3_selection_enterPrototype.size = d3_selectionPrototype.size;
  986. d3_selection_enterPrototype.select = function(selector) {
  987. var subgroups = [], subgroup, subnode, upgroup, group, node;
  988. for (var j = -1, m = this.length; ++j < m; ) {
  989. upgroup = (group = this[j]).update;
  990. subgroups.push(subgroup = []);
  991. subgroup.parentNode = group.parentNode;
  992. for (var i = -1, n = group.length; ++i < n; ) {
  993. if (node = group[i]) {
  994. subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
  995. subnode.__data__ = node.__data__;
  996. } else {
  997. subgroup.push(null);
  998. }
  999. }
  1000. }
  1001. return d3_selection(subgroups);
  1002. };
  1003. d3_selection_enterPrototype.insert = function(name, before) {
  1004. if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
  1005. return d3_selectionPrototype.insert.call(this, name, before);
  1006. };
  1007. function d3_selection_enterInsertBefore(enter) {
  1008. var i0, j0;
  1009. return function(d, i, j) {
  1010. var group = enter[j].update, n = group.length, node;
  1011. if (j != j0) j0 = j, i0 = 0;
  1012. if (i >= i0) i0 = i + 1;
  1013. while (!(node = group[i0]) && ++i0 < n) ;
  1014. return node;
  1015. };
  1016. }
  1017. d3.select = function(node) {
  1018. var group = [ typeof node === "string" ? d3_select(node, d3_document) : node ];
  1019. group.parentNode = d3_documentElement;
  1020. return d3_selection([ group ]);
  1021. };
  1022. d3.selectAll = function(nodes) {
  1023. var group = d3_array(typeof nodes === "string" ? d3_selectAll(nodes, d3_document) : nodes);
  1024. group.parentNode = d3_documentElement;
  1025. return d3_selection([ group ]);
  1026. };
  1027. var d3_selectionRoot = d3.select(d3_documentElement);
  1028. d3_selectionPrototype.on = function(type, listener, capture) {
  1029. var n = arguments.length;
  1030. if (n < 3) {
  1031. if (typeof type !== "string") {
  1032. if (n < 2) listener = false;
  1033. for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
  1034. return this;
  1035. }
  1036. if (n < 2) return (n = this.node()["__on" + type]) && n._;
  1037. capture = false;
  1038. }
  1039. return this.each(d3_selection_on(type, listener, capture));
  1040. };
  1041. function d3_selection_on(type, listener, capture) {
  1042. var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
  1043. if (i > 0) type = type.slice(0, i);
  1044. var filter = d3_selection_onFilters.get(type);
  1045. if (filter) type = filter, wrap = d3_selection_onFilter;
  1046. function onRemove() {
  1047. var l = this[name];
  1048. if (l) {
  1049. this.removeEventListener(type, l, l.$);
  1050. delete this[name];
  1051. }
  1052. }
  1053. function onAdd() {
  1054. var l = wrap(listener, d3_array(arguments));
  1055. onRemove.call(this);
  1056. this.addEventListener(type, this[name] = l, l.$ = capture);
  1057. l._ = listener;
  1058. }
  1059. function removeAll() {
  1060. var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
  1061. for (var name in this) {
  1062. if (match = name.match(re)) {
  1063. var l = this[name];
  1064. this.removeEventListener(match[1], l, l.$);
  1065. delete this[name];
  1066. }
  1067. }
  1068. }
  1069. return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
  1070. }
  1071. var d3_selection_onFilters = d3.map({
  1072. mouseenter: "mouseover",
  1073. mouseleave: "mouseout"
  1074. });
  1075. d3_selection_onFilters.forEach(function(k) {
  1076. if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
  1077. });
  1078. function d3_selection_onListener(listener, argumentz) {
  1079. return function(e) {
  1080. var o = d3.event;
  1081. d3.event = e;
  1082. argumentz[0] = this.__data__;
  1083. try {
  1084. listener.apply(this, argumentz);
  1085. } finally {
  1086. d3.event = o;
  1087. }
  1088. };
  1089. }
  1090. function d3_selection_onFilter(listener, argumentz) {
  1091. var l = d3_selection_onListener(listener, argumentz);
  1092. return function(e) {
  1093. var target = this, related = e.relatedTarget;
  1094. if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
  1095. l.call(target, e);
  1096. }
  1097. };
  1098. }
  1099. var d3_event_dragSelect = "onselectstart" in d3_document ? null : d3_vendorSymbol(d3_documentElement.style, "userSelect"), d3_event_dragId = 0;
  1100. function d3_event_dragSuppress() {
  1101. var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
  1102. if (d3_event_dragSelect) {
  1103. var style = d3_documentElement.style, select = style[d3_event_dragSelect];
  1104. style[d3_event_dragSelect] = "none";
  1105. }
  1106. return function(suppressClick) {
  1107. w.on(name, null);
  1108. if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
  1109. if (suppressClick) {
  1110. var off = function() {
  1111. w.on(click, null);
  1112. };
  1113. w.on(click, function() {
  1114. d3_eventPreventDefault();
  1115. off();
  1116. }, true);
  1117. setTimeout(off, 0);
  1118. }
  1119. };
  1120. }
  1121. d3.mouse = function(container) {
  1122. return d3_mousePoint(container, d3_eventSource());
  1123. };
  1124. var d3_mouse_bug44083 = /WebKit/.test(d3_window.navigator.userAgent) ? -1 : 0;
  1125. function d3_mousePoint(container, e) {
  1126. if (e.changedTouches) e = e.changedTouches[0];
  1127. var svg = container.ownerSVGElement || container;
  1128. if (svg.createSVGPoint) {
  1129. var point = svg.createSVGPoint();
  1130. if (d3_mouse_bug44083 < 0 && (d3_window.scrollX || d3_window.scrollY)) {
  1131. svg = d3.select("body").append("svg").style({
  1132. position: "absolute",
  1133. top: 0,
  1134. left: 0,
  1135. margin: 0,
  1136. padding: 0,
  1137. border: "none"
  1138. }, "important");
  1139. var ctm = svg[0][0].getScreenCTM();
  1140. d3_mouse_bug44083 = !(ctm.f || ctm.e);
  1141. svg.remove();
  1142. }
  1143. if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
  1144. point.y = e.clientY;
  1145. point = point.matrixTransform(container.getScreenCTM().inverse());
  1146. return [ point.x, point.y ];
  1147. }
  1148. var rect = container.getBoundingClientRect();
  1149. return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
  1150. }
  1151. d3.touch = function(container, touches, identifier) {
  1152. if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
  1153. if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
  1154. if ((touch = touches[i]).identifier === identifier) {
  1155. return d3_mousePoint(container, touch);
  1156. }
  1157. }
  1158. };
  1159. d3.behavior.drag = function() {
  1160. var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_behavior_dragMouseSubject, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_behavior_dragTouchSubject, "touchmove", "touchend");
  1161. function drag() {
  1162. this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
  1163. }
  1164. function dragstart(id, position, subject, move, end) {
  1165. return function() {
  1166. var that = this, target = d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject()).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(), position0 = position(parent, dragId);
  1167. if (origin) {
  1168. dragOffset = origin.apply(that, arguments);
  1169. dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
  1170. } else {
  1171. dragOffset = [ 0, 0 ];
  1172. }
  1173. dispatch({
  1174. type: "dragstart"
  1175. });
  1176. function moved() {
  1177. var position1 = position(parent, dragId), dx, dy;
  1178. if (!position1) return;
  1179. dx = position1[0] - position0[0];
  1180. dy = position1[1] - position0[1];
  1181. dragged |= dx | dy;
  1182. position0 = position1;
  1183. dispatch({
  1184. type: "drag",
  1185. x: position1[0] + dragOffset[0],
  1186. y: position1[1] + dragOffset[1],
  1187. dx: dx,
  1188. dy: dy
  1189. });
  1190. }
  1191. function ended() {
  1192. if (!position(parent, dragId)) return;
  1193. dragSubject.on(move + dragName, null).on(end + dragName, null);
  1194. dragRestore(dragged && d3.event.target === target);
  1195. dispatch({
  1196. type: "dragend"
  1197. });
  1198. }
  1199. };
  1200. }
  1201. drag.origin = function(x) {
  1202. if (!arguments.length) return origin;
  1203. origin = x;
  1204. return drag;
  1205. };
  1206. return d3.rebind(drag, event, "on");
  1207. };
  1208. function d3_behavior_dragTouchId() {
  1209. return d3.event.changedTouches[0].identifier;
  1210. }
  1211. function d3_behavior_dragTouchSubject() {
  1212. return d3.event.target;
  1213. }
  1214. function d3_behavior_dragMouseSubject() {
  1215. return d3_window;
  1216. }
  1217. d3.touches = function(container, touches) {
  1218. if (arguments.length < 2) touches = d3_eventSource().touches;
  1219. return touches ? d3_array(touches).map(function(touch) {
  1220. var point = d3_mousePoint(container, touch);
  1221. point.identifier = touch.identifier;
  1222. return point;
  1223. }) : [];
  1224. };
  1225. var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
  1226. function d3_sgn(x) {
  1227. return x > 0 ? 1 : x < 0 ? -1 : 0;
  1228. }
  1229. function d3_cross2d(a, b, c) {
  1230. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  1231. }
  1232. function d3_acos(x) {
  1233. return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
  1234. }
  1235. function d3_asin(x) {
  1236. return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
  1237. }
  1238. function d3_sinh(x) {
  1239. return ((x = Math.exp(x)) - 1 / x) / 2;
  1240. }
  1241. function d3_cosh(x) {
  1242. return ((x = Math.exp(x)) + 1 / x) / 2;
  1243. }
  1244. function d3_tanh(x) {
  1245. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  1246. }
  1247. function d3_haversin(x) {
  1248. return (x = Math.sin(x / 2)) * x;
  1249. }
  1250. var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
  1251. d3.interpolateZoom = function(p0, p1) {
  1252. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2];
  1253. var dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, d1 = Math.sqrt(d2), b0 = (w1 * w1 - w0 * w0 + ρ4 * d2) / (2 * w0 * ρ2 * d1), b1 = (w1 * w1 - w0 * w0 - ρ4 * d2) / (2 * w1 * ρ2 * d1), r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0), r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1), dr = r1 - r0, S = (dr || Math.log(w1 / w0)) / ρ;
  1254. function interpolate(t) {
  1255. var s = t * S;
  1256. if (dr) {
  1257. var coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
  1258. return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
  1259. }
  1260. return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * s) ];
  1261. }
  1262. interpolate.duration = S * 1e3;
  1263. return interpolate;
  1264. };
  1265. d3.behavior.zoom = function() {
  1266. var view = {
  1267. x: 0,
  1268. y: 0,
  1269. k: 1
  1270. }, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, duration = 250, zooming = 0, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
  1271. function zoom(g) {
  1272. g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
  1273. }
  1274. zoom.event = function(g) {
  1275. g.each(function() {
  1276. var dispatch = event.of(this, arguments), view1 = view;
  1277. if (d3_transitionInheritId) {
  1278. d3.select(this).transition().each("start.zoom", function() {
  1279. view = this.__chart__ || {
  1280. x: 0,
  1281. y: 0,
  1282. k: 1
  1283. };
  1284. zoomstarted(dispatch);
  1285. }).tween("zoom:zoom", function() {
  1286. var dx = size[0], dy = size[1], cx = center0 ? center0[0] : dx / 2, cy = center0 ? center0[1] : dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]);
  1287. return function(t) {
  1288. var l = i(t), k = dx / l[2];
  1289. this.__chart__ = view = {
  1290. x: cx - l[0] * k,
  1291. y: cy - l[1] * k,
  1292. k: k
  1293. };
  1294. zoomed(dispatch);
  1295. };
  1296. }).each("interrupt.zoom", function() {
  1297. zoomended(dispatch);
  1298. }).each("end.zoom", function() {
  1299. zoomended(dispatch);
  1300. });
  1301. } else {
  1302. this.__chart__ = view;
  1303. zoomstarted(dispatch);
  1304. zoomed(dispatch);
  1305. zoomended(dispatch);
  1306. }
  1307. });
  1308. };
  1309. zoom.translate = function(_) {
  1310. if (!arguments.length) return [ view.x, view.y ];
  1311. view = {
  1312. x: +_[0],
  1313. y: +_[1],
  1314. k: view.k
  1315. };
  1316. rescale();
  1317. return zoom;
  1318. };
  1319. zoom.scale = function(_) {
  1320. if (!arguments.length) return view.k;
  1321. view = {
  1322. x: view.x,
  1323. y: view.y,
  1324. k: +_
  1325. };
  1326. rescale();
  1327. return zoom;
  1328. };
  1329. zoom.scaleExtent = function(_) {
  1330. if (!arguments.length) return scaleExtent;
  1331. scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
  1332. return zoom;
  1333. };
  1334. zoom.center = function(_) {
  1335. if (!arguments.length) return center;
  1336. center = _ && [ +_[0], +_[1] ];
  1337. return zoom;
  1338. };
  1339. zoom.size = function(_) {
  1340. if (!arguments.length) return size;
  1341. size = _ && [ +_[0], +_[1] ];
  1342. return zoom;
  1343. };
  1344. zoom.duration = function(_) {
  1345. if (!arguments.length) return duration;
  1346. duration = +_;
  1347. return zoom;
  1348. };
  1349. zoom.x = function(z) {
  1350. if (!arguments.length) return x1;
  1351. x1 = z;
  1352. x0 = z.copy();
  1353. view = {
  1354. x: 0,
  1355. y: 0,
  1356. k: 1
  1357. };
  1358. return zoom;
  1359. };
  1360. zoom.y = function(z) {
  1361. if (!arguments.length) return y1;
  1362. y1 = z;
  1363. y0 = z.copy();
  1364. view = {
  1365. x: 0,
  1366. y: 0,
  1367. k: 1
  1368. };
  1369. return zoom;
  1370. };
  1371. function location(p) {
  1372. return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
  1373. }
  1374. function point(l) {
  1375. return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
  1376. }
  1377. function scaleTo(s) {
  1378. view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
  1379. }
  1380. function translateTo(p, l) {
  1381. l = point(l);
  1382. view.x += p[0] - l[0];
  1383. view.y += p[1] - l[1];
  1384. }
  1385. function zoomTo(that, p, l, k) {
  1386. that.__chart__ = {
  1387. x: view.x,
  1388. y: view.y,
  1389. k: view.k
  1390. };
  1391. scaleTo(Math.pow(2, k));
  1392. translateTo(center0 = p, l);
  1393. that = d3.select(that);
  1394. if (duration > 0) that = that.transition().duration(duration);
  1395. that.call(zoom.event);
  1396. }
  1397. function rescale() {
  1398. if (x1) x1.domain(x0.range().map(function(x) {
  1399. return (x - view.x) / view.k;
  1400. }).map(x0.invert));
  1401. if (y1) y1.domain(y0.range().map(function(y) {
  1402. return (y - view.y) / view.k;
  1403. }).map(y0.invert));
  1404. }
  1405. function zoomstarted(dispatch) {
  1406. if (!zooming++) dispatch({
  1407. type: "zoomstart"
  1408. });
  1409. }
  1410. function zoomed(dispatch) {
  1411. rescale();
  1412. dispatch({
  1413. type: "zoom",
  1414. scale: view.k,
  1415. translate: [ view.x, view.y ]
  1416. });
  1417. }
  1418. function zoomended(dispatch) {
  1419. if (!--zooming) dispatch({
  1420. type: "zoomend"
  1421. });
  1422. center0 = null;
  1423. }
  1424. function mousedowned() {
  1425. var that = this, target = d3.event.target, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress();
  1426. d3_selection_interrupt.call(that);
  1427. zoomstarted(dispatch);
  1428. function moved() {
  1429. dragged = 1;
  1430. translateTo(d3.mouse(that), location0);
  1431. zoomed(dispatch);
  1432. }
  1433. function ended() {
  1434. subject.on(mousemove, null).on(mouseup, null);
  1435. dragRestore(dragged && d3.event.target === target);
  1436. zoomended(dispatch);
  1437. }
  1438. }
  1439. function touchstarted() {
  1440. var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, targets = [], subject = d3.select(that), dragRestore = d3_event_dragSuppress();
  1441. started();
  1442. zoomstarted(dispatch);
  1443. subject.on(mousedown, null).on(touchstart, started);
  1444. function relocate() {
  1445. var touches = d3.touches(that);
  1446. scale0 = view.k;
  1447. touches.forEach(function(t) {
  1448. if (t.identifier in locations0) locations0[t.identifier] = location(t);
  1449. });
  1450. return touches;
  1451. }
  1452. function started() {
  1453. var target = d3.event.target;
  1454. d3.select(target).on(touchmove, moved).on(touchend, ended);
  1455. targets.push(target);
  1456. var changed = d3.event.changedTouches;
  1457. for (var i = 0, n = changed.length; i < n; ++i) {
  1458. locations0[changed[i].identifier] = null;
  1459. }
  1460. var touches = relocate(), now = Date.now();
  1461. if (touches.length === 1) {
  1462. if (now - touchtime < 500) {
  1463. var p = touches[0];
  1464. zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
  1465. d3_eventPreventDefault();
  1466. }
  1467. touchtime = now;
  1468. } else if (touches.length > 1) {
  1469. var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
  1470. distance0 = dx * dx + dy * dy;
  1471. }
  1472. }
  1473. function moved() {
  1474. var touches = d3.touches(that), p0, l0, p1, l1;
  1475. d3_selection_interrupt.call(that);
  1476. for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
  1477. p1 = touches[i];
  1478. if (l1 = locations0[p1.identifier]) {
  1479. if (l0) break;
  1480. p0 = p1, l0 = l1;
  1481. }
  1482. }
  1483. if (l1) {
  1484. var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
  1485. p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
  1486. l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
  1487. scaleTo(scale1 * scale0);
  1488. }
  1489. touchtime = null;
  1490. translateTo(p0, l0);
  1491. zoomed(dispatch);
  1492. }
  1493. function ended() {
  1494. if (d3.event.touches.length) {
  1495. var changed = d3.event.changedTouches;
  1496. for (var i = 0, n = changed.length; i < n; ++i) {
  1497. delete locations0[changed[i].identifier];
  1498. }
  1499. for (var identifier in locations0) {
  1500. return void relocate();
  1501. }
  1502. }
  1503. d3.selectAll(targets).on(zoomName, null);
  1504. subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
  1505. dragRestore();
  1506. zoomended(dispatch);
  1507. }
  1508. }
  1509. function mousewheeled() {
  1510. var dispatch = event.of(this, arguments);
  1511. if (mousewheelTimer) clearTimeout(mousewheelTimer); else translate0 = location(center0 = center || d3.mouse(this)),
  1512. d3_selection_interrupt.call(this), zoomstarted(dispatch);
  1513. mousewheelTimer = setTimeout(function() {
  1514. mousewheelTimer = null;
  1515. zoomended(dispatch);
  1516. }, 50);
  1517. d3_eventPreventDefault();
  1518. scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
  1519. translateTo(center0, translate0);
  1520. zoomed(dispatch);
  1521. }
  1522. function dblclicked() {
  1523. var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
  1524. zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
  1525. }
  1526. return d3.rebind(zoom, event, "on");
  1527. };
  1528. var d3_behavior_zoomInfinity = [ 0, Infinity ];
  1529. var d3_behavior_zoomDelta, d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1530. return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
  1531. }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1532. return d3.event.wheelDelta;
  1533. }, "mousewheel") : (d3_behavior_zoomDelta = function() {
  1534. return -d3.event.detail;
  1535. }, "MozMousePixelScroll");
  1536. d3.color = d3_color;
  1537. function d3_color() {}
  1538. d3_color.prototype.toString = function() {
  1539. return this.rgb() + "";
  1540. };
  1541. d3.hsl = d3_hsl;
  1542. function d3_hsl(h, s, l) {
  1543. return this instanceof d3_hsl ? void (this.h = +h, this.s = +s, this.l = +l) : arguments.length < 2 ? h instanceof d3_hsl ? new d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : new d3_hsl(h, s, l);
  1544. }
  1545. var d3_hslPrototype = d3_hsl.prototype = new d3_color();
  1546. d3_hslPrototype.brighter = function(k) {
  1547. k = Math.pow(.7, arguments.length ? k : 1);
  1548. return new d3_hsl(this.h, this.s, this.l / k);
  1549. };
  1550. d3_hslPrototype.darker = function(k) {
  1551. k = Math.pow(.7, arguments.length ? k : 1);
  1552. return new d3_hsl(this.h, this.s, k * this.l);
  1553. };
  1554. d3_hslPrototype.rgb = function() {
  1555. return d3_hsl_rgb(this.h, this.s, this.l);
  1556. };
  1557. function d3_hsl_rgb(h, s, l) {
  1558. var m1, m2;
  1559. h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
  1560. s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
  1561. l = l < 0 ? 0 : l > 1 ? 1 : l;
  1562. m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
  1563. m1 = 2 * l - m2;
  1564. function v(h) {
  1565. if (h > 360) h -= 360; else if (h < 0) h += 360;
  1566. if (h < 60) return m1 + (m2 - m1) * h / 60;
  1567. if (h < 180) return m2;
  1568. if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
  1569. return m1;
  1570. }
  1571. function vv(h) {
  1572. return Math.round(v(h) * 255);
  1573. }
  1574. return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
  1575. }
  1576. d3.hcl = d3_hcl;
  1577. function d3_hcl(h, c, l) {
  1578. return this instanceof d3_hcl ? void (this.h = +h, this.c = +c, this.l = +l) : arguments.length < 2 ? h instanceof d3_hcl ? new d3_hcl(h.h, h.c, h.l) : h instanceof d3_lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : new d3_hcl(h, c, l);
  1579. }
  1580. var d3_hclPrototype = d3_hcl.prototype = new d3_color();
  1581. d3_hclPrototype.brighter = function(k) {
  1582. return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
  1583. };
  1584. d3_hclPrototype.darker = function(k) {
  1585. return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
  1586. };
  1587. d3_hclPrototype.rgb = function() {
  1588. return d3_hcl_lab(this.h, this.c, this.l).rgb();
  1589. };
  1590. function d3_hcl_lab(h, c, l) {
  1591. if (isNaN(h)) h = 0;
  1592. if (isNaN(c)) c = 0;
  1593. return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
  1594. }
  1595. d3.lab = d3_lab;
  1596. function d3_lab(l, a, b) {
  1597. return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) : arguments.length < 2 ? l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) : l instanceof d3_hcl ? d3_hcl_lab(l.h, l.c, l.l) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b);
  1598. }
  1599. var d3_lab_K = 18;
  1600. var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
  1601. var d3_labPrototype = d3_lab.prototype = new d3_color();
  1602. d3_labPrototype.brighter = function(k) {
  1603. return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1604. };
  1605. d3_labPrototype.darker = function(k) {
  1606. return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1607. };
  1608. d3_labPrototype.rgb = function() {
  1609. return d3_lab_rgb(this.l, this.a, this.b);
  1610. };
  1611. function d3_lab_rgb(l, a, b) {
  1612. var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
  1613. x = d3_lab_xyz(x) * d3_lab_X;
  1614. y = d3_lab_xyz(y) * d3_lab_Y;
  1615. z = d3_lab_xyz(z) * d3_lab_Z;
  1616. return new d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
  1617. }
  1618. function d3_lab_hcl(l, a, b) {
  1619. return l > 0 ? new d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : new d3_hcl(NaN, NaN, l);
  1620. }
  1621. function d3_lab_xyz(x) {
  1622. return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
  1623. }
  1624. function d3_xyz_lab(x) {
  1625. return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
  1626. }
  1627. function d3_xyz_rgb(r) {
  1628. return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
  1629. }
  1630. d3.rgb = d3_rgb;
  1631. function d3_rgb(r, g, b) {
  1632. return this instanceof d3_rgb ? void (this.r = ~~r, this.g = ~~g, this.b = ~~b) : arguments.length < 2 ? r instanceof d3_rgb ? new d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : new d3_rgb(r, g, b);
  1633. }
  1634. function d3_rgbNumber(value) {
  1635. return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
  1636. }
  1637. function d3_rgbString(value) {
  1638. return d3_rgbNumber(value) + "";
  1639. }
  1640. var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
  1641. d3_rgbPrototype.brighter = function(k) {
  1642. k = Math.pow(.7, arguments.length ? k : 1);
  1643. var r = this.r, g = this.g, b = this.b, i = 30;
  1644. if (!r && !g && !b) return new d3_rgb(i, i, i);
  1645. if (r && r < i) r = i;
  1646. if (g && g < i) g = i;
  1647. if (b && b < i) b = i;
  1648. return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
  1649. };
  1650. d3_rgbPrototype.darker = function(k) {
  1651. k = Math.pow(.7, arguments.length ? k : 1);
  1652. return new d3_rgb(k * this.r, k * this.g, k * this.b);
  1653. };
  1654. d3_rgbPrototype.hsl = function() {
  1655. return d3_rgb_hsl(this.r, this.g, this.b);
  1656. };
  1657. d3_rgbPrototype.toString = function() {
  1658. return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
  1659. };
  1660. function d3_rgb_hex(v) {
  1661. return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
  1662. }
  1663. function d3_rgb_parse(format, rgb, hsl) {
  1664. var r = 0, g = 0, b = 0, m1, m2, color;
  1665. m1 = /([a-z]+)\((.*)\)/i.exec(format);
  1666. if (m1) {
  1667. m2 = m1[2].split(",");
  1668. switch (m1[1]) {
  1669. case "hsl":
  1670. {
  1671. return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
  1672. }
  1673. case "rgb":
  1674. {
  1675. return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
  1676. }
  1677. }
  1678. }
  1679. if (color = d3_rgb_names.get(format)) return rgb(color.r, color.g, color.b);
  1680. if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
  1681. if (format.length === 4) {
  1682. r = (color & 3840) >> 4;
  1683. r = r >> 4 | r;
  1684. g = color & 240;
  1685. g = g >> 4 | g;
  1686. b = color & 15;
  1687. b = b << 4 | b;
  1688. } else if (format.length === 7) {
  1689. r = (color & 16711680) >> 16;
  1690. g = (color & 65280) >> 8;
  1691. b = color & 255;
  1692. }
  1693. }
  1694. return rgb(r, g, b);
  1695. }
  1696. function d3_rgb_hsl(r, g, b) {
  1697. var min = Math.min(r /= 255, g /= 255, b /= 255), max = Math.max(r, g, b), d = max - min, h, s, l = (max + min) / 2;
  1698. if (d) {
  1699. s = l < .5 ? d / (max + min) : d / (2 - max - min);
  1700. if (r == max) h = (g - b) / d + (g < b ? 6 : 0); else if (g == max) h = (b - r) / d + 2; else h = (r - g) / d + 4;
  1701. h *= 60;
  1702. } else {
  1703. h = NaN;
  1704. s = l > 0 && l < 1 ? 0 : h;
  1705. }
  1706. return new d3_hsl(h, s, l);
  1707. }
  1708. function d3_rgb_lab(r, g, b) {
  1709. r = d3_rgb_xyz(r);
  1710. g = d3_rgb_xyz(g);
  1711. b = d3_rgb_xyz(b);
  1712. var x = d3_xyz_lab((.4124564 * r + .3575761 * g + .1804375 * b) / d3_lab_X), y = d3_xyz_lab((.2126729 * r + .7151522 * g + .072175 * b) / d3_lab_Y), z = d3_xyz_lab((.0193339 * r + .119192 * g + .9503041 * b) / d3_lab_Z);
  1713. return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
  1714. }
  1715. function d3_rgb_xyz(r) {
  1716. return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
  1717. }
  1718. function d3_rgb_parseNumber(c) {
  1719. var f = parseFloat(c);
  1720. return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
  1721. }
  1722. var d3_rgb_names = d3.map({
  1723. aliceblue: 15792383,
  1724. antiquewhite: 16444375,
  1725. aqua: 65535,
  1726. aquamarine: 8388564,
  1727. azure: 15794175,
  1728. beige: 16119260,
  1729. bisque: 16770244,
  1730. black: 0,
  1731. blanchedalmond: 16772045,
  1732. blue: 255,
  1733. blueviolet: 9055202,
  1734. brown: 10824234,
  1735. burlywood: 14596231,
  1736. cadetblue: 6266528,
  1737. chartreuse: 8388352,
  1738. chocolate: 13789470,
  1739. coral: 16744272,
  1740. cornflowerblue: 6591981,
  1741. cornsilk: 16775388,
  1742. crimson: 14423100,
  1743. cyan: 65535,
  1744. darkblue: 139,
  1745. darkcyan: 35723,
  1746. darkgoldenrod: 12092939,
  1747. darkgray: 11119017,
  1748. darkgreen: 25600,
  1749. darkgrey: 11119017,
  1750. darkkhaki: 12433259,
  1751. darkmagenta: 9109643,
  1752. darkolivegreen: 5597999,
  1753. darkorange: 16747520,
  1754. darkorchid: 10040012,
  1755. darkred: 9109504,
  1756. darksalmon: 15308410,
  1757. darkseagreen: 9419919,
  1758. darkslateblue: 4734347,
  1759. darkslategray: 3100495,
  1760. darkslategrey: 3100495,
  1761. darkturquoise: 52945,
  1762. darkviolet: 9699539,
  1763. deeppink: 16716947,
  1764. deepskyblue: 49151,
  1765. dimgray: 6908265,
  1766. dimgrey: 6908265,
  1767. dodgerblue: 2003199,
  1768. firebrick: 11674146,
  1769. floralwhite: 16775920,
  1770. forestgreen: 2263842,
  1771. fuchsia: 16711935,
  1772. gainsboro: 14474460,
  1773. ghostwhite: 16316671,
  1774. gold: 16766720,
  1775. goldenrod: 14329120,
  1776. gray: 8421504,
  1777. green: 32768,
  1778. greenyellow: 11403055,
  1779. grey: 8421504,
  1780. honeydew: 15794160,
  1781. hotpink: 16738740,
  1782. indianred: 13458524,
  1783. indigo: 4915330,
  1784. ivory: 16777200,
  1785. khaki: 15787660,
  1786. lavender: 15132410,
  1787. lavenderblush: 16773365,
  1788. lawngreen: 8190976,
  1789. lemonchiffon: 16775885,
  1790. lightblue: 11393254,
  1791. lightcoral: 15761536,
  1792. lightcyan: 14745599,
  1793. lightgoldenrodyellow: 16448210,
  1794. lightgray: 13882323,
  1795. lightgreen: 9498256,
  1796. lightgrey: 13882323,
  1797. lightpink: 16758465,
  1798. lightsalmon: 16752762,
  1799. lightseagreen: 2142890,
  1800. lightskyblue: 8900346,
  1801. lightslategray: 7833753,
  1802. lightslategrey: 7833753,
  1803. lightsteelblue: 11584734,
  1804. lightyellow: 16777184,
  1805. lime: 65280,
  1806. limegreen: 3329330,
  1807. linen: 16445670,
  1808. magenta: 16711935,
  1809. maroon: 8388608,
  1810. mediumaquamarine: 6737322,
  1811. mediumblue: 205,
  1812. mediumorchid: 12211667,
  1813. mediumpurple: 9662683,
  1814. mediumseagreen: 3978097,
  1815. mediumslateblue: 8087790,
  1816. mediumspringgreen: 64154,
  1817. mediumturquoise: 4772300,
  1818. mediumvioletred: 13047173,
  1819. midnightblue: 1644912,
  1820. mintcream: 16121850,
  1821. mistyrose: 16770273,
  1822. moccasin: 16770229,
  1823. navajowhite: 16768685,
  1824. navy: 128,
  1825. oldlace: 16643558,
  1826. olive: 8421376,
  1827. olivedrab: 7048739,
  1828. orange: 16753920,
  1829. orangered: 16729344,
  1830. orchid: 14315734,
  1831. palegoldenrod: 15657130,
  1832. palegreen: 10025880,
  1833. paleturquoise: 11529966,
  1834. palevioletred: 14381203,
  1835. papayawhip: 16773077,
  1836. peachpuff: 16767673,
  1837. peru: 13468991,
  1838. pink: 16761035,
  1839. plum: 14524637,
  1840. powderblue: 11591910,
  1841. purple: 8388736,
  1842. red: 16711680,
  1843. rosybrown: 12357519,
  1844. royalblue: 4286945,
  1845. saddlebrown: 9127187,
  1846. salmon: 16416882,
  1847. sandybrown: 16032864,
  1848. seagreen: 3050327,
  1849. seashell: 16774638,
  1850. sienna: 10506797,
  1851. silver: 12632256,
  1852. skyblue: 8900331,
  1853. slateblue: 6970061,
  1854. slategray: 7372944,
  1855. slategrey: 7372944,
  1856. snow: 16775930,
  1857. springgreen: 65407,
  1858. steelblue: 4620980,
  1859. tan: 13808780,
  1860. teal: 32896,
  1861. thistle: 14204888,
  1862. tomato: 16737095,
  1863. turquoise: 4251856,
  1864. violet: 15631086,
  1865. wheat: 16113331,
  1866. white: 16777215,
  1867. whitesmoke: 16119285,
  1868. yellow: 16776960,
  1869. yellowgreen: 10145074
  1870. });
  1871. d3_rgb_names.forEach(function(key, value) {
  1872. d3_rgb_names.set(key, d3_rgbNumber(value));
  1873. });
  1874. function d3_functor(v) {
  1875. return typeof v === "function" ? v : function() {
  1876. return v;
  1877. };
  1878. }
  1879. d3.functor = d3_functor;
  1880. function d3_identity(d) {
  1881. return d;
  1882. }
  1883. d3.xhr = d3_xhrType(d3_identity);
  1884. function d3_xhrType(response) {
  1885. return function(url, mimeType, callback) {
  1886. if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
  1887. mimeType = null;
  1888. return d3_xhr(url, mimeType, response, callback);
  1889. };
  1890. }
  1891. function d3_xhr(url, mimeType, response, callback) {
  1892. var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
  1893. if (d3_window.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
  1894. "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
  1895. request.readyState > 3 && respond();
  1896. };
  1897. function respond() {
  1898. var status = request.status, result;
  1899. if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
  1900. try {
  1901. result = response.call(xhr, request);
  1902. } catch (e) {
  1903. dispatch.error.call(xhr, e);
  1904. return;
  1905. }
  1906. dispatch.load.call(xhr, result);
  1907. } else {
  1908. dispatch.error.call(xhr, request);
  1909. }
  1910. }
  1911. request.onprogress = function(event) {
  1912. var o = d3.event;
  1913. d3.event = event;
  1914. try {
  1915. dispatch.progress.call(xhr, request);
  1916. } finally {
  1917. d3.event = o;
  1918. }
  1919. };
  1920. xhr.header = function(name, value) {
  1921. name = (name + "").toLowerCase();
  1922. if (arguments.length < 2) return headers[name];
  1923. if (value == null) delete headers[name]; else headers[name] = value + "";
  1924. return xhr;
  1925. };
  1926. xhr.mimeType = function(value) {
  1927. if (!arguments.length) return mimeType;
  1928. mimeType = value == null ? null : value + "";
  1929. return xhr;
  1930. };
  1931. xhr.responseType = function(value) {
  1932. if (!arguments.length) return responseType;
  1933. responseType = value;
  1934. return xhr;
  1935. };
  1936. xhr.response = function(value) {
  1937. response = value;
  1938. return xhr;
  1939. };
  1940. [ "get", "post" ].forEach(function(method) {
  1941. xhr[method] = function() {
  1942. return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
  1943. };
  1944. });
  1945. xhr.send = function(method, data, callback) {
  1946. if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
  1947. request.open(method, url, true);
  1948. if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
  1949. if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
  1950. if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
  1951. if (responseType != null) request.responseType = responseType;
  1952. if (callback != null) xhr.on("error", callback).on("load", function(request) {
  1953. callback(null, request);
  1954. });
  1955. dispatch.beforesend.call(xhr, request);
  1956. request.send(data == null ? null : data);
  1957. return xhr;
  1958. };
  1959. xhr.abort = function() {
  1960. request.abort();
  1961. return xhr;
  1962. };
  1963. d3.rebind(xhr, dispatch, "on");
  1964. return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
  1965. }
  1966. function d3_xhr_fixCallback(callback) {
  1967. return callback.length === 1 ? function(error, request) {
  1968. callback(error == null ? request : null);
  1969. } : callback;
  1970. }
  1971. function d3_xhrHasResponse(request) {
  1972. var type = request.responseType;
  1973. return type && type !== "text" ? request.response : request.responseText;
  1974. }
  1975. d3.dsv = function(delimiter, mimeType) {
  1976. var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
  1977. function dsv(url, row, callback) {
  1978. if (arguments.length < 3) callback = row, row = null;
  1979. var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
  1980. xhr.row = function(_) {
  1981. return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
  1982. };
  1983. return xhr;
  1984. }
  1985. function response(request) {
  1986. return dsv.parse(request.responseText);
  1987. }
  1988. function typedResponse(f) {
  1989. return function(request) {
  1990. return dsv.parse(request.responseText, f);
  1991. };
  1992. }
  1993. dsv.parse = function(text, f) {
  1994. var o;
  1995. return dsv.parseRows(text, function(row, i) {
  1996. if (o) return o(row, i - 1);
  1997. var a = new Function("d", "return {" + row.map(function(name, i) {
  1998. return JSON.stringify(name) + ": d[" + i + "]";
  1999. }).join(",") + "}");
  2000. o = f ? function(row, i) {
  2001. return f(a(row), i);
  2002. } : a;
  2003. });
  2004. };
  2005. dsv.parseRows = function(text, f) {
  2006. var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
  2007. function token() {
  2008. if (I >= N) return EOF;
  2009. if (eol) return eol = false, EOL;
  2010. var j = I;
  2011. if (text.charCodeAt(j) === 34) {
  2012. var i = j;
  2013. while (i++ < N) {
  2014. if (text.charCodeAt(i) === 34) {
  2015. if (text.charCodeAt(i + 1) !== 34) break;
  2016. ++i;
  2017. }
  2018. }
  2019. I = i + 2;
  2020. var c = text.charCodeAt(i + 1);
  2021. if (c === 13) {
  2022. eol = true;
  2023. if (text.charCodeAt(i + 2) === 10) ++I;
  2024. } else if (c === 10) {
  2025. eol = true;
  2026. }
  2027. return text.slice(j + 1, i).replace(/""/g, '"');
  2028. }
  2029. while (I < N) {
  2030. var c = text.charCodeAt(I++), k = 1;
  2031. if (c === 10) eol = true; else if (c === 13) {
  2032. eol = true;
  2033. if (text.charCodeAt(I) === 10) ++I, ++k;
  2034. } else if (c !== delimiterCode) continue;
  2035. return text.slice(j, I - k);
  2036. }
  2037. return text.slice(j);
  2038. }
  2039. while ((t = token()) !== EOF) {
  2040. var a = [];
  2041. while (t !== EOL && t !== EOF) {
  2042. a.push(t);
  2043. t = token();
  2044. }
  2045. if (f && (a = f(a, n++)) == null) continue;
  2046. rows.push(a);
  2047. }
  2048. return rows;
  2049. };
  2050. dsv.format = function(rows) {
  2051. if (Array.isArray(rows[0])) return dsv.formatRows(rows);
  2052. var fieldSet = new d3_Set(), fields = [];
  2053. rows.forEach(function(row) {
  2054. for (var field in row) {
  2055. if (!fieldSet.has(field)) {
  2056. fields.push(fieldSet.add(field));
  2057. }
  2058. }
  2059. });
  2060. return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
  2061. return fields.map(function(field) {
  2062. return formatValue(row[field]);
  2063. }).join(delimiter);
  2064. })).join("\n");
  2065. };
  2066. dsv.formatRows = function(rows) {
  2067. return rows.map(formatRow).join("\n");
  2068. };
  2069. function formatRow(row) {
  2070. return row.map(formatValue).join(delimiter);
  2071. }
  2072. function formatValue(text) {
  2073. return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
  2074. }
  2075. return dsv;
  2076. };
  2077. d3.csv = d3.dsv(",", "text/csv");
  2078. d3.tsv = d3.dsv(" ", "text/tab-separated-values");
  2079. var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_active, d3_timer_frame = d3_window[d3_vendorSymbol(d3_window, "requestAnimationFrame")] || function(callback) {
  2080. setTimeout(callback, 17);
  2081. };
  2082. d3.timer = function(callback, delay, then) {
  2083. var n = arguments.length;
  2084. if (n < 2) delay = 0;
  2085. if (n < 3) then = Date.now();
  2086. var time = then + delay, timer = {
  2087. c: callback,
  2088. t: time,
  2089. f: false,
  2090. n: null
  2091. };
  2092. if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
  2093. d3_timer_queueTail = timer;
  2094. if (!d3_timer_interval) {
  2095. d3_timer_timeout = clearTimeout(d3_timer_timeout);
  2096. d3_timer_interval = 1;
  2097. d3_timer_frame(d3_timer_step);
  2098. }
  2099. };
  2100. function d3_timer_step() {
  2101. var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
  2102. if (delay > 24) {
  2103. if (isFinite(delay)) {
  2104. clearTimeout(d3_timer_timeout);
  2105. d3_timer_timeout = setTimeout(d3_timer_step, delay);
  2106. }
  2107. d3_timer_interval = 0;
  2108. } else {
  2109. d3_timer_interval = 1;
  2110. d3_timer_frame(d3_timer_step);
  2111. }
  2112. }
  2113. d3.timer.flush = function() {
  2114. d3_timer_mark();
  2115. d3_timer_sweep();
  2116. };
  2117. function d3_timer_mark() {
  2118. var now = Date.now();
  2119. d3_timer_active = d3_timer_queueHead;
  2120. while (d3_timer_active) {
  2121. if (now >= d3_timer_active.t) d3_timer_active.f = d3_timer_active.c(now - d3_timer_active.t);
  2122. d3_timer_active = d3_timer_active.n;
  2123. }
  2124. return now;
  2125. }
  2126. function d3_timer_sweep() {
  2127. var t0, t1 = d3_timer_queueHead, time = Infinity;
  2128. while (t1) {
  2129. if (t1.f) {
  2130. t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
  2131. } else {
  2132. if (t1.t < time) time = t1.t;
  2133. t1 = (t0 = t1).n;
  2134. }
  2135. }
  2136. d3_timer_queueTail = t0;
  2137. return time;
  2138. }
  2139. function d3_format_precision(x, p) {
  2140. return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
  2141. }
  2142. d3.round = function(x, n) {
  2143. return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
  2144. };
  2145. var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
  2146. d3.formatPrefix = function(value, precision) {
  2147. var i = 0;
  2148. if (value) {
  2149. if (value < 0) value *= -1;
  2150. if (precision) value = d3.round(value, d3_format_precision(value, precision));
  2151. i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
  2152. i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
  2153. }
  2154. return d3_formatPrefixes[8 + i / 3];
  2155. };
  2156. function d3_formatPrefix(d, i) {
  2157. var k = Math.pow(10, abs(8 - i) * 3);
  2158. return {
  2159. scale: i > 8 ? function(d) {
  2160. return d / k;
  2161. } : function(d) {
  2162. return d * k;
  2163. },
  2164. symbol: d
  2165. };
  2166. }
  2167. function d3_locale_numberFormat(locale) {
  2168. var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping && locale_thousands ? function(value, width) {
  2169. var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
  2170. while (i > 0 && g > 0) {
  2171. if (length + g + 1 > width) g = Math.max(1, width - length);
  2172. t.push(value.substring(i -= g, i + g));
  2173. if ((length += g + 1) > width) break;
  2174. g = locale_grouping[j = (j + 1) % locale_grouping.length];
  2175. }
  2176. return t.reverse().join(locale_thousands);
  2177. } : d3_identity;
  2178. return function(specifier) {
  2179. var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "-", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false, exponent = true;
  2180. if (precision) precision = +precision.substring(1);
  2181. if (zfill || fill === "0" && align === "=") {
  2182. zfill = fill = "0";
  2183. align = "=";
  2184. }
  2185. switch (type) {
  2186. case "n":
  2187. comma = true;
  2188. type = "g";
  2189. break;
  2190. case "%":
  2191. scale = 100;
  2192. suffix = "%";
  2193. type = "f";
  2194. break;
  2195. case "p":
  2196. scale = 100;
  2197. suffix = "%";
  2198. type = "r";
  2199. break;
  2200. case "b":
  2201. case "o":
  2202. case "x":
  2203. case "X":
  2204. if (symbol === "#") prefix = "0" + type.toLowerCase();
  2205. case "c":
  2206. exponent = false;
  2207. case "d":
  2208. integer = true;
  2209. precision = 0;
  2210. break;
  2211. case "s":
  2212. scale = -1;
  2213. type = "r";
  2214. break;
  2215. }
  2216. if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
  2217. if (type == "r" && !precision) type = "g";
  2218. if (precision != null) {
  2219. if (type == "g") precision = Math.max(1, Math.min(21, precision)); else if (type == "e" || type == "f") precision = Math.max(0, Math.min(20, precision));
  2220. }
  2221. type = d3_format_types.get(type) || d3_format_typeDefault;
  2222. var zcomma = zfill && comma;
  2223. return function(value) {
  2224. var fullSuffix = suffix;
  2225. if (integer && value % 1) return "";
  2226. var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
  2227. if (scale < 0) {
  2228. var unit = d3.formatPrefix(value, precision);
  2229. value = unit.scale(value);
  2230. fullSuffix = unit.symbol + suffix;
  2231. } else {
  2232. value *= scale;
  2233. }
  2234. value = type(value, precision);
  2235. var i = value.lastIndexOf("."), before, after;
  2236. if (i < 0) {
  2237. var j = exponent ? value.lastIndexOf("e") : -1;
  2238. if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
  2239. } else {
  2240. before = value.substring(0, i);
  2241. after = locale_decimal + value.substring(i + 1);
  2242. }
  2243. if (!zfill && comma) before = formatGroup(before, Infinity);
  2244. var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
  2245. if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
  2246. negative += prefix;
  2247. value = before + after;
  2248. return (align === "<" ? negative + value + padding : align === ">" ? padding + negative + value : align === "^" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length) : negative + (zcomma ? value : padding + value)) + fullSuffix;
  2249. };
  2250. };
  2251. }
  2252. var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
  2253. var d3_format_types = d3.map({
  2254. b: function(x) {
  2255. return x.toString(2);
  2256. },
  2257. c: function(x) {
  2258. return String.fromCharCode(x);
  2259. },
  2260. o: function(x) {
  2261. return x.toString(8);
  2262. },
  2263. x: function(x) {
  2264. return x.toString(16);
  2265. },
  2266. X: function(x) {
  2267. return x.toString(16).toUpperCase();
  2268. },
  2269. g: function(x, p) {
  2270. return x.toPrecision(p);
  2271. },
  2272. e: function(x, p) {
  2273. return x.toExponential(p);
  2274. },
  2275. f: function(x, p) {
  2276. return x.toFixed(p);
  2277. },
  2278. r: function(x, p) {
  2279. return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + 1e-15), p))));
  2280. }
  2281. });
  2282. function d3_format_typeDefault(x) {
  2283. return x + "";
  2284. }
  2285. var d3_time = d3.time = {}, d3_date = Date;
  2286. function d3_date_utc() {
  2287. this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
  2288. }
  2289. d3_date_utc.prototype = {
  2290. getDate: function() {
  2291. return this._.getUTCDate();
  2292. },
  2293. getDay: function() {
  2294. return this._.getUTCDay();
  2295. },
  2296. getFullYear: function() {
  2297. return this._.getUTCFullYear();
  2298. },
  2299. getHours: function() {
  2300. return this._.getUTCHours();
  2301. },
  2302. getMilliseconds: function() {
  2303. return this._.getUTCMilliseconds();
  2304. },
  2305. getMinutes: function() {
  2306. return this._.getUTCMinutes();
  2307. },
  2308. getMonth: function() {
  2309. return this._.getUTCMonth();
  2310. },
  2311. getSeconds: function() {
  2312. return this._.getUTCSeconds();
  2313. },
  2314. getTime: function() {
  2315. return this._.getTime();
  2316. },
  2317. getTimezoneOffset: function() {
  2318. return 0;
  2319. },
  2320. valueOf: function() {
  2321. return this._.valueOf();
  2322. },
  2323. setDate: function() {
  2324. d3_time_prototype.setUTCDate.apply(this._, arguments);
  2325. },
  2326. setDay: function() {
  2327. d3_time_prototype.setUTCDay.apply(this._, arguments);
  2328. },
  2329. setFullYear: function() {
  2330. d3_time_prototype.setUTCFullYear.apply(this._, arguments);
  2331. },
  2332. setHours: function() {
  2333. d3_time_prototype.setUTCHours.apply(this._, arguments);
  2334. },
  2335. setMilliseconds: function() {
  2336. d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
  2337. },
  2338. setMinutes: function() {
  2339. d3_time_prototype.setUTCMinutes.apply(this._, arguments);
  2340. },
  2341. setMonth: function() {
  2342. d3_time_prototype.setUTCMonth.apply(this._, arguments);
  2343. },
  2344. setSeconds: function() {
  2345. d3_time_prototype.setUTCSeconds.apply(this._, arguments);
  2346. },
  2347. setTime: function() {
  2348. d3_time_prototype.setTime.apply(this._, arguments);
  2349. }
  2350. };
  2351. var d3_time_prototype = Date.prototype;
  2352. function d3_time_interval(local, step, number) {
  2353. function round(date) {
  2354. var d0 = local(date), d1 = offset(d0, 1);
  2355. return date - d0 < d1 - date ? d0 : d1;
  2356. }
  2357. function ceil(date) {
  2358. step(date = local(new d3_date(date - 1)), 1);
  2359. return date;
  2360. }
  2361. function offset(date, k) {
  2362. step(date = new d3_date(+date), k);
  2363. return date;
  2364. }
  2365. function range(t0, t1, dt) {
  2366. var time = ceil(t0), times = [];
  2367. if (dt > 1) {
  2368. while (time < t1) {
  2369. if (!(number(time) % dt)) times.push(new Date(+time));
  2370. step(time, 1);
  2371. }
  2372. } else {
  2373. while (time < t1) times.push(new Date(+time)), step(time, 1);
  2374. }
  2375. return times;
  2376. }
  2377. function range_utc(t0, t1, dt) {
  2378. try {
  2379. d3_date = d3_date_utc;
  2380. var utc = new d3_date_utc();
  2381. utc._ = t0;
  2382. return range(utc, t1, dt);
  2383. } finally {
  2384. d3_date = Date;
  2385. }
  2386. }
  2387. local.floor = local;
  2388. local.round = round;
  2389. local.ceil = ceil;
  2390. local.offset = offset;
  2391. local.range = range;
  2392. var utc = local.utc = d3_time_interval_utc(local);
  2393. utc.floor = utc;
  2394. utc.round = d3_time_interval_utc(round);
  2395. utc.ceil = d3_time_interval_utc(ceil);
  2396. utc.offset = d3_time_interval_utc(offset);
  2397. utc.range = range_utc;
  2398. return local;
  2399. }
  2400. function d3_time_interval_utc(method) {
  2401. return function(date, k) {
  2402. try {
  2403. d3_date = d3_date_utc;
  2404. var utc = new d3_date_utc();
  2405. utc._ = date;
  2406. return method(utc, k)._;
  2407. } finally {
  2408. d3_date = Date;
  2409. }
  2410. };
  2411. }
  2412. d3_time.year = d3_time_interval(function(date) {
  2413. date = d3_time.day(date);
  2414. date.setMonth(0, 1);
  2415. return date;
  2416. }, function(date, offset) {
  2417. date.setFullYear(date.getFullYear() + offset);
  2418. }, function(date) {
  2419. return date.getFullYear();
  2420. });
  2421. d3_time.years = d3_time.year.range;
  2422. d3_time.years.utc = d3_time.year.utc.range;
  2423. d3_time.day = d3_time_interval(function(date) {
  2424. var day = new d3_date(2e3, 0);
  2425. day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
  2426. return day;
  2427. }, function(date, offset) {
  2428. date.setDate(date.getDate() + offset);
  2429. }, function(date) {
  2430. return date.getDate() - 1;
  2431. });
  2432. d3_time.days = d3_time.day.range;
  2433. d3_time.days.utc = d3_time.day.utc.range;
  2434. d3_time.dayOfYear = function(date) {
  2435. var year = d3_time.year(date);
  2436. return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
  2437. };
  2438. [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
  2439. i = 7 - i;
  2440. var interval = d3_time[day] = d3_time_interval(function(date) {
  2441. (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
  2442. return date;
  2443. }, function(date, offset) {
  2444. date.setDate(date.getDate() + Math.floor(offset) * 7);
  2445. }, function(date) {
  2446. var day = d3_time.year(date).getDay();
  2447. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
  2448. });
  2449. d3_time[day + "s"] = interval.range;
  2450. d3_time[day + "s"].utc = interval.utc.range;
  2451. d3_time[day + "OfYear"] = function(date) {
  2452. var day = d3_time.year(date).getDay();
  2453. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
  2454. };
  2455. });
  2456. d3_time.week = d3_time.sunday;
  2457. d3_time.weeks = d3_time.sunday.range;
  2458. d3_time.weeks.utc = d3_time.sunday.utc.range;
  2459. d3_time.weekOfYear = d3_time.sundayOfYear;
  2460. function d3_locale_timeFormat(locale) {
  2461. var locale_dateTime = locale.dateTime, locale_date = locale.date, locale_time = locale.time, locale_periods = locale.periods, locale_days = locale.days, locale_shortDays = locale.shortDays, locale_months = locale.months, locale_shortMonths = locale.shortMonths;
  2462. function d3_time_format(template) {
  2463. var n = template.length;
  2464. function format(date) {
  2465. var string = [], i = -1, j = 0, c, p, f;
  2466. while (++i < n) {
  2467. if (template.charCodeAt(i) === 37) {
  2468. string.push(template.slice(j, i));
  2469. if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
  2470. if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
  2471. string.push(c);
  2472. j = i + 1;
  2473. }
  2474. }
  2475. string.push(template.slice(j, i));
  2476. return string.join("");
  2477. }
  2478. format.parse = function(string) {
  2479. var d = {
  2480. y: 1900,
  2481. m: 0,
  2482. d: 1,
  2483. H: 0,
  2484. M: 0,
  2485. S: 0,
  2486. L: 0,
  2487. Z: null
  2488. }, i = d3_time_parse(d, template, string, 0);
  2489. if (i != string.length) return null;
  2490. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  2491. var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
  2492. if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
  2493. date.setFullYear(d.y, 0, 1);
  2494. 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);
  2495. } else date.setFullYear(d.y, d.m, d.d);
  2496. date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
  2497. return localZ ? date._ : date;
  2498. };
  2499. format.toString = function() {
  2500. return template;
  2501. };
  2502. return format;
  2503. }
  2504. function d3_time_parse(date, template, string, j) {
  2505. var c, p, t, i = 0, n = template.length, m = string.length;
  2506. while (i < n) {
  2507. if (j >= m) return -1;
  2508. c = template.charCodeAt(i++);
  2509. if (c === 37) {
  2510. t = template.charAt(i++);
  2511. p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
  2512. if (!p || (j = p(date, string, j)) < 0) return -1;
  2513. } else if (c != string.charCodeAt(j++)) {
  2514. return -1;
  2515. }
  2516. }
  2517. return j;
  2518. }
  2519. d3_time_format.utc = function(template) {
  2520. var local = d3_time_format(template);
  2521. function format(date) {
  2522. try {
  2523. d3_date = d3_date_utc;
  2524. var utc = new d3_date();
  2525. utc._ = date;
  2526. return local(utc);
  2527. } finally {
  2528. d3_date = Date;
  2529. }
  2530. }
  2531. format.parse = function(string) {
  2532. try {
  2533. d3_date = d3_date_utc;
  2534. var date = local.parse(string);
  2535. return date && date._;
  2536. } finally {
  2537. d3_date = Date;
  2538. }
  2539. };
  2540. format.toString = local.toString;
  2541. return format;
  2542. };
  2543. d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
  2544. var d3_time_periodLookup = d3.map(), d3_time_dayRe = d3_time_formatRe(locale_days), d3_time_dayLookup = d3_time_formatLookup(locale_days), d3_time_dayAbbrevRe = d3_time_formatRe(locale_shortDays), d3_time_dayAbbrevLookup = d3_time_formatLookup(locale_shortDays), d3_time_monthRe = d3_time_formatRe(locale_months), d3_time_monthLookup = d3_time_formatLookup(locale_months), d3_time_monthAbbrevRe = d3_time_formatRe(locale_shortMonths), d3_time_monthAbbrevLookup = d3_time_formatLookup(locale_shortMonths);
  2545. locale_periods.forEach(function(p, i) {
  2546. d3_time_periodLookup.set(p.toLowerCase(), i);
  2547. });
  2548. var d3_time_formats = {
  2549. a: function(d) {
  2550. return locale_shortDays[d.getDay()];
  2551. },
  2552. A: function(d) {
  2553. return locale_days[d.getDay()];
  2554. },
  2555. b: function(d) {
  2556. return locale_shortMonths[d.getMonth()];
  2557. },
  2558. B: function(d) {
  2559. return locale_months[d.getMonth()];
  2560. },
  2561. c: d3_time_format(locale_dateTime),
  2562. d: function(d, p) {
  2563. return d3_time_formatPad(d.getDate(), p, 2);
  2564. },
  2565. e: function(d, p) {
  2566. return d3_time_formatPad(d.getDate(), p, 2);
  2567. },
  2568. H: function(d, p) {
  2569. return d3_time_formatPad(d.getHours(), p, 2);
  2570. },
  2571. I: function(d, p) {
  2572. return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
  2573. },
  2574. j: function(d, p) {
  2575. return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
  2576. },
  2577. L: function(d, p) {
  2578. return d3_time_formatPad(d.getMilliseconds(), p, 3);
  2579. },
  2580. m: function(d, p) {
  2581. return d3_time_formatPad(d.getMonth() + 1, p, 2);
  2582. },
  2583. M: function(d, p) {
  2584. return d3_time_formatPad(d.getMinutes(), p, 2);
  2585. },
  2586. p: function(d) {
  2587. return locale_periods[+(d.getHours() >= 12)];
  2588. },
  2589. S: function(d, p) {
  2590. return d3_time_formatPad(d.getSeconds(), p, 2);
  2591. },
  2592. U: function(d, p) {
  2593. return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
  2594. },
  2595. w: function(d) {
  2596. return d.getDay();
  2597. },
  2598. W: function(d, p) {
  2599. return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
  2600. },
  2601. x: d3_time_format(locale_date),
  2602. X: d3_time_format(locale_time),
  2603. y: function(d, p) {
  2604. return d3_time_formatPad(d.getFullYear() % 100, p, 2);
  2605. },
  2606. Y: function(d, p) {
  2607. return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
  2608. },
  2609. Z: d3_time_zone,
  2610. "%": function() {
  2611. return "%";
  2612. }
  2613. };
  2614. var d3_time_parsers = {
  2615. a: d3_time_parseWeekdayAbbrev,
  2616. A: d3_time_parseWeekday,
  2617. b: d3_time_parseMonthAbbrev,
  2618. B: d3_time_parseMonth,
  2619. c: d3_time_parseLocaleFull,
  2620. d: d3_time_parseDay,
  2621. e: d3_time_parseDay,
  2622. H: d3_time_parseHour24,
  2623. I: d3_time_parseHour24,
  2624. j: d3_time_parseDayOfYear,
  2625. L: d3_time_parseMilliseconds,
  2626. m: d3_time_parseMonthNumber,
  2627. M: d3_time_parseMinutes,
  2628. p: d3_time_parseAmPm,
  2629. S: d3_time_parseSeconds,
  2630. U: d3_time_parseWeekNumberSunday,
  2631. w: d3_time_parseWeekdayNumber,
  2632. W: d3_time_parseWeekNumberMonday,
  2633. x: d3_time_parseLocaleDate,
  2634. X: d3_time_parseLocaleTime,
  2635. y: d3_time_parseYear,
  2636. Y: d3_time_parseFullYear,
  2637. Z: d3_time_parseZone,
  2638. "%": d3_time_parseLiteralPercent
  2639. };
  2640. function d3_time_parseWeekdayAbbrev(date, string, i) {
  2641. d3_time_dayAbbrevRe.lastIndex = 0;
  2642. var n = d3_time_dayAbbrevRe.exec(string.slice(i));
  2643. return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2644. }
  2645. function d3_time_parseWeekday(date, string, i) {
  2646. d3_time_dayRe.lastIndex = 0;
  2647. var n = d3_time_dayRe.exec(string.slice(i));
  2648. return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2649. }
  2650. function d3_time_parseMonthAbbrev(date, string, i) {
  2651. d3_time_monthAbbrevRe.lastIndex = 0;
  2652. var n = d3_time_monthAbbrevRe.exec(string.slice(i));
  2653. return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2654. }
  2655. function d3_time_parseMonth(date, string, i) {
  2656. d3_time_monthRe.lastIndex = 0;
  2657. var n = d3_time_monthRe.exec(string.slice(i));
  2658. return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2659. }
  2660. function d3_time_parseLocaleFull(date, string, i) {
  2661. return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
  2662. }
  2663. function d3_time_parseLocaleDate(date, string, i) {
  2664. return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
  2665. }
  2666. function d3_time_parseLocaleTime(date, string, i) {
  2667. return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
  2668. }
  2669. function d3_time_parseAmPm(date, string, i) {
  2670. var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
  2671. return n == null ? -1 : (date.p = n, i);
  2672. }
  2673. return d3_time_format;
  2674. }
  2675. var d3_time_formatPads = {
  2676. "-": "",
  2677. _: " ",
  2678. "0": "0"
  2679. }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
  2680. function d3_time_formatPad(value, fill, width) {
  2681. var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
  2682. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  2683. }
  2684. function d3_time_formatRe(names) {
  2685. return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
  2686. }
  2687. function d3_time_formatLookup(names) {
  2688. var map = new d3_Map(), i = -1, n = names.length;
  2689. while (++i < n) map.set(names[i].toLowerCase(), i);
  2690. return map;
  2691. }
  2692. function d3_time_parseWeekdayNumber(date, string, i) {
  2693. d3_time_numberRe.lastIndex = 0;
  2694. var n = d3_time_numberRe.exec(string.slice(i, i + 1));
  2695. return n ? (date.w = +n[0], i + n[0].length) : -1;
  2696. }
  2697. function d3_time_parseWeekNumberSunday(date, string, i) {
  2698. d3_time_numberRe.lastIndex = 0;
  2699. var n = d3_time_numberRe.exec(string.slice(i));
  2700. return n ? (date.U = +n[0], i + n[0].length) : -1;
  2701. }
  2702. function d3_time_parseWeekNumberMonday(date, string, i) {
  2703. d3_time_numberRe.lastIndex = 0;
  2704. var n = d3_time_numberRe.exec(string.slice(i));
  2705. return n ? (date.W = +n[0], i + n[0].length) : -1;
  2706. }
  2707. function d3_time_parseFullYear(date, string, i) {
  2708. d3_time_numberRe.lastIndex = 0;
  2709. var n = d3_time_numberRe.exec(string.slice(i, i + 4));
  2710. return n ? (date.y = +n[0], i + n[0].length) : -1;
  2711. }
  2712. function d3_time_parseYear(date, string, i) {
  2713. d3_time_numberRe.lastIndex = 0;
  2714. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2715. return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
  2716. }
  2717. function d3_time_parseZone(date, string, i) {
  2718. return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
  2719. i + 5) : -1;
  2720. }
  2721. function d3_time_expandYear(d) {
  2722. return d + (d > 68 ? 1900 : 2e3);
  2723. }
  2724. function d3_time_parseMonthNumber(date, string, i) {
  2725. d3_time_numberRe.lastIndex = 0;
  2726. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2727. return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
  2728. }
  2729. function d3_time_parseDay(date, string, i) {
  2730. d3_time_numberRe.lastIndex = 0;
  2731. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2732. return n ? (date.d = +n[0], i + n[0].length) : -1;
  2733. }
  2734. function d3_time_parseDayOfYear(date, string, i) {
  2735. d3_time_numberRe.lastIndex = 0;
  2736. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  2737. return n ? (date.j = +n[0], i + n[0].length) : -1;
  2738. }
  2739. function d3_time_parseHour24(date, string, i) {
  2740. d3_time_numberRe.lastIndex = 0;
  2741. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2742. return n ? (date.H = +n[0], i + n[0].length) : -1;
  2743. }
  2744. function d3_time_parseMinutes(date, string, i) {
  2745. d3_time_numberRe.lastIndex = 0;
  2746. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2747. return n ? (date.M = +n[0], i + n[0].length) : -1;
  2748. }
  2749. function d3_time_parseSeconds(date, string, i) {
  2750. d3_time_numberRe.lastIndex = 0;
  2751. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2752. return n ? (date.S = +n[0], i + n[0].length) : -1;
  2753. }
  2754. function d3_time_parseMilliseconds(date, string, i) {
  2755. d3_time_numberRe.lastIndex = 0;
  2756. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  2757. return n ? (date.L = +n[0], i + n[0].length) : -1;
  2758. }
  2759. function d3_time_zone(d) {
  2760. var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
  2761. return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
  2762. }
  2763. function d3_time_parseLiteralPercent(date, string, i) {
  2764. d3_time_percentRe.lastIndex = 0;
  2765. var n = d3_time_percentRe.exec(string.slice(i, i + 1));
  2766. return n ? i + n[0].length : -1;
  2767. }
  2768. function d3_time_formatMulti(formats) {
  2769. var n = formats.length, i = -1;
  2770. while (++i < n) formats[i][0] = this(formats[i][0]);
  2771. return function(date) {
  2772. var i = 0, f = formats[i];
  2773. while (!f[1](date)) f = formats[++i];
  2774. return f[0](date);
  2775. };
  2776. }
  2777. d3.locale = function(locale) {
  2778. return {
  2779. numberFormat: d3_locale_numberFormat(locale),
  2780. timeFormat: d3_locale_timeFormat(locale)
  2781. };
  2782. };
  2783. var d3_locale_enUS = d3.locale({
  2784. decimal: ".",
  2785. thousands: ",",
  2786. grouping: [ 3 ],
  2787. currency: [ "$", "" ],
  2788. dateTime: "%a %b %e %X %Y",
  2789. date: "%m/%d/%Y",
  2790. time: "%H:%M:%S",
  2791. periods: [ "AM", "PM" ],
  2792. days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
  2793. shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
  2794. months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
  2795. shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
  2796. });
  2797. d3.format = d3_locale_enUS.numberFormat;
  2798. d3.geo = {};
  2799. function d3_adder() {}
  2800. d3_adder.prototype = {
  2801. s: 0,
  2802. t: 0,
  2803. add: function(y) {
  2804. d3_adderSum(y, this.t, d3_adderTemp);
  2805. d3_adderSum(d3_adderTemp.s, this.s, this);
  2806. if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
  2807. },
  2808. reset: function() {
  2809. this.s = this.t = 0;
  2810. },
  2811. valueOf: function() {
  2812. return this.s;
  2813. }
  2814. };
  2815. var d3_adderTemp = new d3_adder();
  2816. function d3_adderSum(a, b, o) {
  2817. var x = o.s = a + b, bv = x - a, av = x - bv;
  2818. o.t = a - av + (b - bv);
  2819. }
  2820. d3.geo.stream = function(object, listener) {
  2821. if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
  2822. d3_geo_streamObjectType[object.type](object, listener);
  2823. } else {
  2824. d3_geo_streamGeometry(object, listener);
  2825. }
  2826. };
  2827. function d3_geo_streamGeometry(geometry, listener) {
  2828. if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
  2829. d3_geo_streamGeometryType[geometry.type](geometry, listener);
  2830. }
  2831. }
  2832. var d3_geo_streamObjectType = {
  2833. Feature: function(feature, listener) {
  2834. d3_geo_streamGeometry(feature.geometry, listener);
  2835. },
  2836. FeatureCollection: function(object, listener) {
  2837. var features = object.features, i = -1, n = features.length;
  2838. while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
  2839. }
  2840. };
  2841. var d3_geo_streamGeometryType = {
  2842. Sphere: function(object, listener) {
  2843. listener.sphere();
  2844. },
  2845. Point: function(object, listener) {
  2846. object = object.coordinates;
  2847. listener.point(object[0], object[1], object[2]);
  2848. },
  2849. MultiPoint: function(object, listener) {
  2850. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2851. while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
  2852. },
  2853. LineString: function(object, listener) {
  2854. d3_geo_streamLine(object.coordinates, listener, 0);
  2855. },
  2856. MultiLineString: function(object, listener) {
  2857. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2858. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
  2859. },
  2860. Polygon: function(object, listener) {
  2861. d3_geo_streamPolygon(object.coordinates, listener);
  2862. },
  2863. MultiPolygon: function(object, listener) {
  2864. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2865. while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
  2866. },
  2867. GeometryCollection: function(object, listener) {
  2868. var geometries = object.geometries, i = -1, n = geometries.length;
  2869. while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
  2870. }
  2871. };
  2872. function d3_geo_streamLine(coordinates, listener, closed) {
  2873. var i = -1, n = coordinates.length - closed, coordinate;
  2874. listener.lineStart();
  2875. while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
  2876. listener.lineEnd();
  2877. }
  2878. function d3_geo_streamPolygon(coordinates, listener) {
  2879. var i = -1, n = coordinates.length;
  2880. listener.polygonStart();
  2881. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
  2882. listener.polygonEnd();
  2883. }
  2884. d3.geo.area = function(object) {
  2885. d3_geo_areaSum = 0;
  2886. d3.geo.stream(object, d3_geo_area);
  2887. return d3_geo_areaSum;
  2888. };
  2889. var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
  2890. var d3_geo_area = {
  2891. sphere: function() {
  2892. d3_geo_areaSum += 4 * π;
  2893. },
  2894. point: d3_noop,
  2895. lineStart: d3_noop,
  2896. lineEnd: d3_noop,
  2897. polygonStart: function() {
  2898. d3_geo_areaRingSum.reset();
  2899. d3_geo_area.lineStart = d3_geo_areaRingStart;
  2900. },
  2901. polygonEnd: function() {
  2902. var area = 2 * d3_geo_areaRingSum;
  2903. d3_geo_areaSum += area < 0 ? 4 * π + area : area;
  2904. d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
  2905. }
  2906. };
  2907. function d3_geo_areaRingStart() {
  2908. var λ00, φ00, λ0, cosφ0, sinφ0;
  2909. d3_geo_area.point = function(λ, φ) {
  2910. d3_geo_area.point = nextPoint;
  2911. λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
  2912. sinφ0 = Math.sin(φ);
  2913. };
  2914. function nextPoint(λ, φ) {
  2915. λ *= d3_radians;
  2916. φ = φ * d3_radians / 2 + π / 4;
  2917. var dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(adλ), v = k * sdλ * Math.sin(adλ);
  2918. d3_geo_areaRingSum.add(Math.atan2(v, u));
  2919. λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
  2920. }
  2921. d3_geo_area.lineEnd = function() {
  2922. nextPoint(λ00, φ00);
  2923. };
  2924. }
  2925. function d3_geo_cartesian(spherical) {
  2926. var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
  2927. return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
  2928. }
  2929. function d3_geo_cartesianDot(a, b) {
  2930. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  2931. }
  2932. function d3_geo_cartesianCross(a, b) {
  2933. return [ a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0] ];
  2934. }
  2935. function d3_geo_cartesianAdd(a, b) {
  2936. a[0] += b[0];
  2937. a[1] += b[1];
  2938. a[2] += b[2];
  2939. }
  2940. function d3_geo_cartesianScale(vector, k) {
  2941. return [ vector[0] * k, vector[1] * k, vector[2] * k ];
  2942. }
  2943. function d3_geo_cartesianNormalize(d) {
  2944. var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  2945. d[0] /= l;
  2946. d[1] /= l;
  2947. d[2] /= l;
  2948. }
  2949. function d3_geo_spherical(cartesian) {
  2950. return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
  2951. }
  2952. function d3_geo_sphericalEqual(a, b) {
  2953. return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
  2954. }
  2955. d3.geo.bounds = function() {
  2956. var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
  2957. var bound = {
  2958. point: point,
  2959. lineStart: lineStart,
  2960. lineEnd: lineEnd,
  2961. polygonStart: function() {
  2962. bound.point = ringPoint;
  2963. bound.lineStart = ringStart;
  2964. bound.lineEnd = ringEnd;
  2965. dλSum = 0;
  2966. d3_geo_area.polygonStart();
  2967. },
  2968. polygonEnd: function() {
  2969. d3_geo_area.polygonEnd();
  2970. bound.point = point;
  2971. bound.lineStart = lineStart;
  2972. bound.lineEnd = lineEnd;
  2973. if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
  2974. range[0] = λ0, range[1] = λ1;
  2975. }
  2976. };
  2977. function point(λ, φ) {
  2978. ranges.push(range = [ λ0 = λ, λ1 = λ ]);
  2979. if (φ < φ0) φ0 = φ;
  2980. if (φ > φ1) φ1 = φ;
  2981. }
  2982. function linePoint(λ, φ) {
  2983. var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
  2984. if (p0) {
  2985. var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
  2986. d3_geo_cartesianNormalize(inflection);
  2987. inflection = d3_geo_spherical(inflection);
  2988. var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
  2989. if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  2990. var φi = inflection[1] * d3_degrees;
  2991. if (φi > φ1) φ1 = φi;
  2992. } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  2993. var φi = -inflection[1] * d3_degrees;
  2994. if (φi < φ0) φ0 = φi;
  2995. } else {
  2996. if (φ < φ0) φ0 = φ;
  2997. if (φ > φ1) φ1 = φ;
  2998. }
  2999. if (antimeridian) {
  3000. if (λ < λ_) {
  3001. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3002. } else {
  3003. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3004. }
  3005. } else {
  3006. if (λ1 >= λ0) {
  3007. if (λ < λ0) λ0 = λ;
  3008. if (λ > λ1) λ1 = λ;
  3009. } else {
  3010. if (λ > λ_) {
  3011. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3012. } else {
  3013. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3014. }
  3015. }
  3016. }
  3017. } else {
  3018. point(λ, φ);
  3019. }
  3020. p0 = p, λ_ = λ;
  3021. }
  3022. function lineStart() {
  3023. bound.point = linePoint;
  3024. }
  3025. function lineEnd() {
  3026. range[0] = λ0, range[1] = λ1;
  3027. bound.point = point;
  3028. p0 = null;
  3029. }
  3030. function ringPoint(λ, φ) {
  3031. if (p0) {
  3032. var dλ = λ - λ_;
  3033. dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
  3034. } else λ__ = λ, φ__ = φ;
  3035. d3_geo_area.point(λ, φ);
  3036. linePoint(λ, φ);
  3037. }
  3038. function ringStart() {
  3039. d3_geo_area.lineStart();
  3040. }
  3041. function ringEnd() {
  3042. ringPoint(λ__, φ__);
  3043. d3_geo_area.lineEnd();
  3044. if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
  3045. range[0] = λ0, range[1] = λ1;
  3046. p0 = null;
  3047. }
  3048. function angle(λ0, λ1) {
  3049. return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
  3050. }
  3051. function compareRanges(a, b) {
  3052. return a[0] - b[0];
  3053. }
  3054. function withinRange(x, range) {
  3055. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  3056. }
  3057. return function(feature) {
  3058. φ1 = λ1 = -(λ0 = φ0 = Infinity);
  3059. ranges = [];
  3060. d3.geo.stream(feature, bound);
  3061. var n = ranges.length;
  3062. if (n) {
  3063. ranges.sort(compareRanges);
  3064. for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
  3065. b = ranges[i];
  3066. if (withinRange(b[0], a) || withinRange(b[1], a)) {
  3067. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  3068. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  3069. } else {
  3070. merged.push(a = b);
  3071. }
  3072. }
  3073. var best = -Infinity, dλ;
  3074. for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
  3075. b = merged[i];
  3076. if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
  3077. }
  3078. }
  3079. ranges = range = null;
  3080. return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
  3081. };
  3082. }();
  3083. d3.geo.centroid = function(object) {
  3084. 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;
  3085. d3.geo.stream(object, d3_geo_centroid);
  3086. var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
  3087. if (m < ε2) {
  3088. x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
  3089. if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
  3090. m = x * x + y * y + z * z;
  3091. if (m < ε2) return [ NaN, NaN ];
  3092. }
  3093. return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
  3094. };
  3095. 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;
  3096. var d3_geo_centroid = {
  3097. sphere: d3_noop,
  3098. point: d3_geo_centroidPoint,
  3099. lineStart: d3_geo_centroidLineStart,
  3100. lineEnd: d3_geo_centroidLineEnd,
  3101. polygonStart: function() {
  3102. d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
  3103. },
  3104. polygonEnd: function() {
  3105. d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
  3106. }
  3107. };
  3108. function d3_geo_centroidPoint(λ, φ) {
  3109. λ *= d3_radians;
  3110. var cosφ = Math.cos(φ *= d3_radians);
  3111. d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
  3112. }
  3113. function d3_geo_centroidPointXYZ(x, y, z) {
  3114. ++d3_geo_centroidW0;
  3115. d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
  3116. d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
  3117. d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
  3118. }
  3119. function d3_geo_centroidLineStart() {
  3120. var x0, y0, z0;
  3121. d3_geo_centroid.point = function(λ, φ) {
  3122. λ *= d3_radians;
  3123. var cosφ = Math.cos(φ *= d3_radians);
  3124. x0 = cosφ * Math.cos(λ);
  3125. y0 = cosφ * Math.sin(λ);
  3126. z0 = Math.sin(φ);
  3127. d3_geo_centroid.point = nextPoint;
  3128. d3_geo_centroidPointXYZ(x0, y0, z0);
  3129. };
  3130. function nextPoint(λ, φ) {
  3131. λ *= d3_radians;
  3132. 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);
  3133. d3_geo_centroidW1 += w;
  3134. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3135. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3136. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3137. d3_geo_centroidPointXYZ(x0, y0, z0);
  3138. }
  3139. }
  3140. function d3_geo_centroidLineEnd() {
  3141. d3_geo_centroid.point = d3_geo_centroidPoint;
  3142. }
  3143. function d3_geo_centroidRingStart() {
  3144. var λ00, φ00, x0, y0, z0;
  3145. d3_geo_centroid.point = function(λ, φ) {
  3146. λ00 = λ, φ00 = φ;
  3147. d3_geo_centroid.point = nextPoint;
  3148. λ *= d3_radians;
  3149. var cosφ = Math.cos(φ *= d3_radians);
  3150. x0 = cosφ * Math.cos(λ);
  3151. y0 = cosφ * Math.sin(λ);
  3152. z0 = Math.sin(φ);
  3153. d3_geo_centroidPointXYZ(x0, y0, z0);
  3154. };
  3155. d3_geo_centroid.lineEnd = function() {
  3156. nextPoint(λ00, φ00);
  3157. d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
  3158. d3_geo_centroid.point = d3_geo_centroidPoint;
  3159. };
  3160. function nextPoint(λ, φ) {
  3161. λ *= d3_radians;
  3162. 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);
  3163. d3_geo_centroidX2 += v * cx;
  3164. d3_geo_centroidY2 += v * cy;
  3165. d3_geo_centroidZ2 += v * cz;
  3166. d3_geo_centroidW1 += w;
  3167. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3168. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3169. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3170. d3_geo_centroidPointXYZ(x0, y0, z0);
  3171. }
  3172. }
  3173. function d3_geo_compose(a, b) {
  3174. function compose(x, y) {
  3175. return x = a(x, y), b(x[0], x[1]);
  3176. }
  3177. if (a.invert && b.invert) compose.invert = function(x, y) {
  3178. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  3179. };
  3180. return compose;
  3181. }
  3182. function d3_true() {
  3183. return true;
  3184. }
  3185. function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
  3186. var subject = [], clip = [];
  3187. segments.forEach(function(segment) {
  3188. if ((n = segment.length - 1) <= 0) return;
  3189. var n, p0 = segment[0], p1 = segment[n];
  3190. if (d3_geo_sphericalEqual(p0, p1)) {
  3191. listener.lineStart();
  3192. for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
  3193. listener.lineEnd();
  3194. return;
  3195. }
  3196. var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
  3197. a.o = b;
  3198. subject.push(a);
  3199. clip.push(b);
  3200. a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
  3201. b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
  3202. a.o = b;
  3203. subject.push(a);
  3204. clip.push(b);
  3205. });
  3206. clip.sort(compare);
  3207. d3_geo_clipPolygonLinkCircular(subject);
  3208. d3_geo_clipPolygonLinkCircular(clip);
  3209. if (!subject.length) return;
  3210. for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
  3211. clip[i].e = entry = !entry;
  3212. }
  3213. var start = subject[0], points, point;
  3214. while (1) {
  3215. var current = start, isSubject = true;
  3216. while (current.v) if ((current = current.n) === start) return;
  3217. points = current.z;
  3218. listener.lineStart();
  3219. do {
  3220. current.v = current.o.v = true;
  3221. if (current.e) {
  3222. if (isSubject) {
  3223. for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
  3224. } else {
  3225. interpolate(current.x, current.n.x, 1, listener);
  3226. }
  3227. current = current.n;
  3228. } else {
  3229. if (isSubject) {
  3230. points = current.p.z;
  3231. for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
  3232. } else {
  3233. interpolate(current.x, current.p.x, -1, listener);
  3234. }
  3235. current = current.p;
  3236. }
  3237. current = current.o;
  3238. points = current.z;
  3239. isSubject = !isSubject;
  3240. } while (!current.v);
  3241. listener.lineEnd();
  3242. }
  3243. }
  3244. function d3_geo_clipPolygonLinkCircular(array) {
  3245. if (!(n = array.length)) return;
  3246. var n, i = 0, a = array[0], b;
  3247. while (++i < n) {
  3248. a.n = b = array[i];
  3249. b.p = a;
  3250. a = b;
  3251. }
  3252. a.n = b = array[0];
  3253. b.p = a;
  3254. }
  3255. function d3_geo_clipPolygonIntersection(point, points, other, entry) {
  3256. this.x = point;
  3257. this.z = points;
  3258. this.o = other;
  3259. this.e = entry;
  3260. this.v = false;
  3261. this.n = this.p = null;
  3262. }
  3263. function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
  3264. return function(rotate, listener) {
  3265. var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
  3266. var clip = {
  3267. point: point,
  3268. lineStart: lineStart,
  3269. lineEnd: lineEnd,
  3270. polygonStart: function() {
  3271. clip.point = pointRing;
  3272. clip.lineStart = ringStart;
  3273. clip.lineEnd = ringEnd;
  3274. segments = [];
  3275. polygon = [];
  3276. },
  3277. polygonEnd: function() {
  3278. clip.point = point;
  3279. clip.lineStart = lineStart;
  3280. clip.lineEnd = lineEnd;
  3281. segments = d3.merge(segments);
  3282. var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
  3283. if (segments.length) {
  3284. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3285. d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
  3286. } else if (clipStartInside) {
  3287. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3288. listener.lineStart();
  3289. interpolate(null, null, 1, listener);
  3290. listener.lineEnd();
  3291. }
  3292. if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
  3293. segments = polygon = null;
  3294. },
  3295. sphere: function() {
  3296. listener.polygonStart();
  3297. listener.lineStart();
  3298. interpolate(null, null, 1, listener);
  3299. listener.lineEnd();
  3300. listener.polygonEnd();
  3301. }
  3302. };
  3303. function point(λ, φ) {
  3304. var point = rotate(λ, φ);
  3305. if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
  3306. }
  3307. function pointLine(λ, φ) {
  3308. var point = rotate(λ, φ);
  3309. line.point(point[0], point[1]);
  3310. }
  3311. function lineStart() {
  3312. clip.point = pointLine;
  3313. line.lineStart();
  3314. }
  3315. function lineEnd() {
  3316. clip.point = point;
  3317. line.lineEnd();
  3318. }
  3319. var segments;
  3320. var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
  3321. function pointRing(λ, φ) {
  3322. ring.push([ λ, φ ]);
  3323. var point = rotate(λ, φ);
  3324. ringListener.point(point[0], point[1]);
  3325. }
  3326. function ringStart() {
  3327. ringListener.lineStart();
  3328. ring = [];
  3329. }
  3330. function ringEnd() {
  3331. pointRing(ring[0][0], ring[0][1]);
  3332. ringListener.lineEnd();
  3333. var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
  3334. ring.pop();
  3335. polygon.push(ring);
  3336. ring = null;
  3337. if (!n) return;
  3338. if (clean & 1) {
  3339. segment = ringSegments[0];
  3340. var n = segment.length - 1, i = -1, point;
  3341. if (n > 0) {
  3342. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3343. listener.lineStart();
  3344. while (++i < n) listener.point((point = segment[i])[0], point[1]);
  3345. listener.lineEnd();
  3346. }
  3347. return;
  3348. }
  3349. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  3350. segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
  3351. }
  3352. return clip;
  3353. };
  3354. }
  3355. function d3_geo_clipSegmentLength1(segment) {
  3356. return segment.length > 1;
  3357. }
  3358. function d3_geo_clipBufferListener() {
  3359. var lines = [], line;
  3360. return {
  3361. lineStart: function() {
  3362. lines.push(line = []);
  3363. },
  3364. point: function(λ, φ) {
  3365. line.push([ λ, φ ]);
  3366. },
  3367. lineEnd: d3_noop,
  3368. buffer: function() {
  3369. var buffer = lines;
  3370. lines = [];
  3371. line = null;
  3372. return buffer;
  3373. },
  3374. rejoin: function() {
  3375. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  3376. }
  3377. };
  3378. }
  3379. function d3_geo_clipSort(a, b) {
  3380. return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
  3381. }
  3382. var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
  3383. function d3_geo_clipAntimeridianLine(listener) {
  3384. var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
  3385. return {
  3386. lineStart: function() {
  3387. listener.lineStart();
  3388. clean = 1;
  3389. },
  3390. point: function(λ1, φ1) {
  3391. var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
  3392. if (abs(dλ - π) < ε) {
  3393. listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
  3394. listener.point(sλ0, φ0);
  3395. listener.lineEnd();
  3396. listener.lineStart();
  3397. listener.point(sλ1, φ0);
  3398. listener.point(λ1, φ0);
  3399. clean = 0;
  3400. } else if (sλ0 !== sλ1 && dλ >= π) {
  3401. if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
  3402. if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
  3403. φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
  3404. listener.point(sλ0, φ0);
  3405. listener.lineEnd();
  3406. listener.lineStart();
  3407. listener.point(sλ1, φ0);
  3408. clean = 0;
  3409. }
  3410. listener.point(λ0 = λ1, φ0 = φ1);
  3411. sλ0 = sλ1;
  3412. },
  3413. lineEnd: function() {
  3414. listener.lineEnd();
  3415. λ0 = φ0 = NaN;
  3416. },
  3417. clean: function() {
  3418. return 2 - clean;
  3419. }
  3420. };
  3421. }
  3422. function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
  3423. var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
  3424. return abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2;
  3425. }
  3426. function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
  3427. var φ;
  3428. if (from == null) {
  3429. φ = direction * halfπ;
  3430. listener.point(-π, φ);
  3431. listener.point(0, φ);
  3432. listener.point(π, φ);
  3433. listener.point(π, 0);
  3434. listener.point(π, -φ);
  3435. listener.point(0, -φ);
  3436. listener.point(-π, -φ);
  3437. listener.point(-π, 0);
  3438. listener.point(-π, φ);
  3439. } else if (abs(from[0] - to[0]) > ε) {
  3440. var s = from[0] < to[0] ? π : -π;
  3441. φ = direction * s / 2;
  3442. listener.point(-s, φ);
  3443. listener.point(0, φ);
  3444. listener.point(s, φ);
  3445. } else {
  3446. listener.point(to[0], to[1]);
  3447. }
  3448. }
  3449. function d3_geo_pointInPolygon(point, polygon) {
  3450. var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
  3451. d3_geo_areaRingSum.reset();
  3452. for (var i = 0, n = polygon.length; i < n; ++i) {
  3453. var ring = polygon[i], m = ring.length;
  3454. if (!m) continue;
  3455. var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
  3456. while (true) {
  3457. if (j === m) j = 0;
  3458. point = ring[j];
  3459. var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, antimeridian = adλ > π, k = sinφ0 * sinφ;
  3460. d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
  3461. polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
  3462. if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
  3463. var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
  3464. d3_geo_cartesianNormalize(arc);
  3465. var intersection = d3_geo_cartesianCross(meridianNormal, arc);
  3466. d3_geo_cartesianNormalize(intersection);
  3467. var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
  3468. if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
  3469. winding += antimeridian ^ dλ >= 0 ? 1 : -1;
  3470. }
  3471. }
  3472. if (!j++) break;
  3473. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
  3474. }
  3475. }
  3476. return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
  3477. }
  3478. function d3_geo_clipCircle(radius) {
  3479. var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
  3480. return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
  3481. function visible(λ, φ) {
  3482. return Math.cos(λ) * Math.cos(φ) > cr;
  3483. }
  3484. function clipLine(listener) {
  3485. var point0, c0, v0, v00, clean;
  3486. return {
  3487. lineStart: function() {
  3488. v00 = v0 = false;
  3489. clean = 1;
  3490. },
  3491. point: function(λ, φ) {
  3492. var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
  3493. if (!point0 && (v00 = v0 = v)) listener.lineStart();
  3494. if (v !== v0) {
  3495. point2 = intersect(point0, point1);
  3496. if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
  3497. point1[0] += ε;
  3498. point1[1] += ε;
  3499. v = visible(point1[0], point1[1]);
  3500. }
  3501. }
  3502. if (v !== v0) {
  3503. clean = 0;
  3504. if (v) {
  3505. listener.lineStart();
  3506. point2 = intersect(point1, point0);
  3507. listener.point(point2[0], point2[1]);
  3508. } else {
  3509. point2 = intersect(point0, point1);
  3510. listener.point(point2[0], point2[1]);
  3511. listener.lineEnd();
  3512. }
  3513. point0 = point2;
  3514. } else if (notHemisphere && point0 && smallRadius ^ v) {
  3515. var t;
  3516. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  3517. clean = 0;
  3518. if (smallRadius) {
  3519. listener.lineStart();
  3520. listener.point(t[0][0], t[0][1]);
  3521. listener.point(t[1][0], t[1][1]);
  3522. listener.lineEnd();
  3523. } else {
  3524. listener.point(t[1][0], t[1][1]);
  3525. listener.lineEnd();
  3526. listener.lineStart();
  3527. listener.point(t[0][0], t[0][1]);
  3528. }
  3529. }
  3530. }
  3531. if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
  3532. listener.point(point1[0], point1[1]);
  3533. }
  3534. point0 = point1, v0 = v, c0 = c;
  3535. },
  3536. lineEnd: function() {
  3537. if (v0) listener.lineEnd();
  3538. point0 = null;
  3539. },
  3540. clean: function() {
  3541. return clean | (v00 && v0) << 1;
  3542. }
  3543. };
  3544. }
  3545. function intersect(a, b, two) {
  3546. var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
  3547. var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
  3548. if (!determinant) return !two && a;
  3549. var c1 = cr * n2n2 / determinant, c2 = -cr * n1n2 / determinant, n1xn2 = d3_geo_cartesianCross(n1, n2), A = d3_geo_cartesianScale(n1, c1), B = d3_geo_cartesianScale(n2, c2);
  3550. d3_geo_cartesianAdd(A, B);
  3551. var u = n1xn2, w = d3_geo_cartesianDot(A, u), uu = d3_geo_cartesianDot(u, u), t2 = w * w - uu * (d3_geo_cartesianDot(A, A) - 1);
  3552. if (t2 < 0) return;
  3553. var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
  3554. d3_geo_cartesianAdd(q, A);
  3555. q = d3_geo_spherical(q);
  3556. if (!two) return q;
  3557. var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
  3558. if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
  3559. var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
  3560. if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
  3561. if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
  3562. var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
  3563. d3_geo_cartesianAdd(q1, A);
  3564. return [ q, d3_geo_spherical(q1) ];
  3565. }
  3566. }
  3567. function code(λ, φ) {
  3568. var r = smallRadius ? radius : π - radius, code = 0;
  3569. if (λ < -r) code |= 1; else if (λ > r) code |= 2;
  3570. if (φ < -r) code |= 4; else if (φ > r) code |= 8;
  3571. return code;
  3572. }
  3573. }
  3574. function d3_geom_clipLine(x0, y0, x1, y1) {
  3575. return function(line) {
  3576. var a = line.a, b = line.b, ax = a.x, ay = a.y, bx = b.x, by = b.y, t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay, r;
  3577. r = x0 - ax;
  3578. if (!dx && r > 0) return;
  3579. r /= dx;
  3580. if (dx < 0) {
  3581. if (r < t0) return;
  3582. if (r < t1) t1 = r;
  3583. } else if (dx > 0) {
  3584. if (r > t1) return;
  3585. if (r > t0) t0 = r;
  3586. }
  3587. r = x1 - ax;
  3588. if (!dx && r < 0) return;
  3589. r /= dx;
  3590. if (dx < 0) {
  3591. if (r > t1) return;
  3592. if (r > t0) t0 = r;
  3593. } else if (dx > 0) {
  3594. if (r < t0) return;
  3595. if (r < t1) t1 = r;
  3596. }
  3597. r = y0 - ay;
  3598. if (!dy && r > 0) return;
  3599. r /= dy;
  3600. if (dy < 0) {
  3601. if (r < t0) return;
  3602. if (r < t1) t1 = r;
  3603. } else if (dy > 0) {
  3604. if (r > t1) return;
  3605. if (r > t0) t0 = r;
  3606. }
  3607. r = y1 - ay;
  3608. if (!dy && r < 0) return;
  3609. r /= dy;
  3610. if (dy < 0) {
  3611. if (r > t1) return;
  3612. if (r > t0) t0 = r;
  3613. } else if (dy > 0) {
  3614. if (r < t0) return;
  3615. if (r < t1) t1 = r;
  3616. }
  3617. if (t0 > 0) line.a = {
  3618. x: ax + t0 * dx,
  3619. y: ay + t0 * dy
  3620. };
  3621. if (t1 < 1) line.b = {
  3622. x: ax + t1 * dx,
  3623. y: ay + t1 * dy
  3624. };
  3625. return line;
  3626. };
  3627. }
  3628. var d3_geo_clipExtentMAX = 1e9;
  3629. d3.geo.clipExtent = function() {
  3630. var x0, y0, x1, y1, stream, clip, clipExtent = {
  3631. stream: function(output) {
  3632. if (stream) stream.valid = false;
  3633. stream = clip(output);
  3634. stream.valid = true;
  3635. return stream;
  3636. },
  3637. extent: function(_) {
  3638. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  3639. clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
  3640. if (stream) stream.valid = false, stream = null;
  3641. return clipExtent;
  3642. }
  3643. };
  3644. return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
  3645. };
  3646. function d3_geo_clipExtent(x0, y0, x1, y1) {
  3647. return function(listener) {
  3648. var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
  3649. var clip = {
  3650. point: point,
  3651. lineStart: lineStart,
  3652. lineEnd: lineEnd,
  3653. polygonStart: function() {
  3654. listener = bufferListener;
  3655. segments = [];
  3656. polygon = [];
  3657. clean = true;
  3658. },
  3659. polygonEnd: function() {
  3660. listener = listener_;
  3661. segments = d3.merge(segments);
  3662. var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
  3663. if (inside || visible) {
  3664. listener.polygonStart();
  3665. if (inside) {
  3666. listener.lineStart();
  3667. interpolate(null, null, 1, listener);
  3668. listener.lineEnd();
  3669. }
  3670. if (visible) {
  3671. d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
  3672. }
  3673. listener.polygonEnd();
  3674. }
  3675. segments = polygon = ring = null;
  3676. }
  3677. };
  3678. function insidePolygon(p) {
  3679. var wn = 0, n = polygon.length, y = p[1];
  3680. for (var i = 0; i < n; ++i) {
  3681. for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
  3682. b = v[j];
  3683. if (a[1] <= y) {
  3684. if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
  3685. } else {
  3686. if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
  3687. }
  3688. a = b;
  3689. }
  3690. }
  3691. return wn !== 0;
  3692. }
  3693. function interpolate(from, to, direction, listener) {
  3694. var a = 0, a1 = 0;
  3695. if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
  3696. do {
  3697. listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  3698. } while ((a = (a + direction + 4) % 4) !== a1);
  3699. } else {
  3700. listener.point(to[0], to[1]);
  3701. }
  3702. }
  3703. function pointVisible(x, y) {
  3704. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  3705. }
  3706. function point(x, y) {
  3707. if (pointVisible(x, y)) listener.point(x, y);
  3708. }
  3709. var x__, y__, v__, x_, y_, v_, first, clean;
  3710. function lineStart() {
  3711. clip.point = linePoint;
  3712. if (polygon) polygon.push(ring = []);
  3713. first = true;
  3714. v_ = false;
  3715. x_ = y_ = NaN;
  3716. }
  3717. function lineEnd() {
  3718. if (segments) {
  3719. linePoint(x__, y__);
  3720. if (v__ && v_) bufferListener.rejoin();
  3721. segments.push(bufferListener.buffer());
  3722. }
  3723. clip.point = point;
  3724. if (v_) listener.lineEnd();
  3725. }
  3726. function linePoint(x, y) {
  3727. x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
  3728. y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
  3729. var v = pointVisible(x, y);
  3730. if (polygon) ring.push([ x, y ]);
  3731. if (first) {
  3732. x__ = x, y__ = y, v__ = v;
  3733. first = false;
  3734. if (v) {
  3735. listener.lineStart();
  3736. listener.point(x, y);
  3737. }
  3738. } else {
  3739. if (v && v_) listener.point(x, y); else {
  3740. var l = {
  3741. a: {
  3742. x: x_,
  3743. y: y_
  3744. },
  3745. b: {
  3746. x: x,
  3747. y: y
  3748. }
  3749. };
  3750. if (clipLine(l)) {
  3751. if (!v_) {
  3752. listener.lineStart();
  3753. listener.point(l.a.x, l.a.y);
  3754. }
  3755. listener.point(l.b.x, l.b.y);
  3756. if (!v) listener.lineEnd();
  3757. clean = false;
  3758. } else if (v) {
  3759. listener.lineStart();
  3760. listener.point(x, y);
  3761. clean = false;
  3762. }
  3763. }
  3764. }
  3765. x_ = x, y_ = y, v_ = v;
  3766. }
  3767. return clip;
  3768. };
  3769. function corner(p, direction) {
  3770. return abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;
  3771. }
  3772. function compare(a, b) {
  3773. return comparePoints(a.x, b.x);
  3774. }
  3775. function comparePoints(a, b) {
  3776. var ca = corner(a, 1), cb = corner(b, 1);
  3777. return ca !== cb ? ca - cb : ca === 0 ? b[1] - a[1] : ca === 1 ? a[0] - b[0] : ca === 2 ? a[1] - b[1] : b[0] - a[0];
  3778. }
  3779. }
  3780. function d3_geo_conic(projectAt) {
  3781. var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
  3782. p.parallels = function(_) {
  3783. if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
  3784. return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
  3785. };
  3786. return p;
  3787. }
  3788. function d3_geo_conicEqualArea(φ0, φ1) {
  3789. 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;
  3790. function forward(λ, φ) {
  3791. var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
  3792. return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
  3793. }
  3794. forward.invert = function(x, y) {
  3795. var ρ0_y = ρ0 - y;
  3796. return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
  3797. };
  3798. return forward;
  3799. }
  3800. (d3.geo.conicEqualArea = function() {
  3801. return d3_geo_conic(d3_geo_conicEqualArea);
  3802. }).raw = d3_geo_conicEqualArea;
  3803. d3.geo.albers = function() {
  3804. return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
  3805. };
  3806. d3.geo.albersUsa = function() {
  3807. var lower48 = d3.geo.albers();
  3808. var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
  3809. var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
  3810. var point, pointStream = {
  3811. point: function(x, y) {
  3812. point = [ x, y ];
  3813. }
  3814. }, lower48Point, alaskaPoint, hawaiiPoint;
  3815. function albersUsa(coordinates) {
  3816. var x = coordinates[0], y = coordinates[1];
  3817. point = null;
  3818. (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
  3819. return point;
  3820. }
  3821. albersUsa.invert = function(coordinates) {
  3822. var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
  3823. return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
  3824. };
  3825. albersUsa.stream = function(stream) {
  3826. var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
  3827. return {
  3828. point: function(x, y) {
  3829. lower48Stream.point(x, y);
  3830. alaskaStream.point(x, y);
  3831. hawaiiStream.point(x, y);
  3832. },
  3833. sphere: function() {
  3834. lower48Stream.sphere();
  3835. alaskaStream.sphere();
  3836. hawaiiStream.sphere();
  3837. },
  3838. lineStart: function() {
  3839. lower48Stream.lineStart();
  3840. alaskaStream.lineStart();
  3841. hawaiiStream.lineStart();
  3842. },
  3843. lineEnd: function() {
  3844. lower48Stream.lineEnd();
  3845. alaskaStream.lineEnd();
  3846. hawaiiStream.lineEnd();
  3847. },
  3848. polygonStart: function() {
  3849. lower48Stream.polygonStart();
  3850. alaskaStream.polygonStart();
  3851. hawaiiStream.polygonStart();
  3852. },
  3853. polygonEnd: function() {
  3854. lower48Stream.polygonEnd();
  3855. alaskaStream.polygonEnd();
  3856. hawaiiStream.polygonEnd();
  3857. }
  3858. };
  3859. };
  3860. albersUsa.precision = function(_) {
  3861. if (!arguments.length) return lower48.precision();
  3862. lower48.precision(_);
  3863. alaska.precision(_);
  3864. hawaii.precision(_);
  3865. return albersUsa;
  3866. };
  3867. albersUsa.scale = function(_) {
  3868. if (!arguments.length) return lower48.scale();
  3869. lower48.scale(_);
  3870. alaska.scale(_ * .35);
  3871. hawaii.scale(_);
  3872. return albersUsa.translate(lower48.translate());
  3873. };
  3874. albersUsa.translate = function(_) {
  3875. if (!arguments.length) return lower48.translate();
  3876. var k = lower48.scale(), x = +_[0], y = +_[1];
  3877. lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
  3878. 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;
  3879. 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;
  3880. return albersUsa;
  3881. };
  3882. return albersUsa.scale(1070);
  3883. };
  3884. var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
  3885. point: d3_noop,
  3886. lineStart: d3_noop,
  3887. lineEnd: d3_noop,
  3888. polygonStart: function() {
  3889. d3_geo_pathAreaPolygon = 0;
  3890. d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
  3891. },
  3892. polygonEnd: function() {
  3893. d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
  3894. d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
  3895. }
  3896. };
  3897. function d3_geo_pathAreaRingStart() {
  3898. var x00, y00, x0, y0;
  3899. d3_geo_pathArea.point = function(x, y) {
  3900. d3_geo_pathArea.point = nextPoint;
  3901. x00 = x0 = x, y00 = y0 = y;
  3902. };
  3903. function nextPoint(x, y) {
  3904. d3_geo_pathAreaPolygon += y0 * x - x0 * y;
  3905. x0 = x, y0 = y;
  3906. }
  3907. d3_geo_pathArea.lineEnd = function() {
  3908. nextPoint(x00, y00);
  3909. };
  3910. }
  3911. var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
  3912. var d3_geo_pathBounds = {
  3913. point: d3_geo_pathBoundsPoint,
  3914. lineStart: d3_noop,
  3915. lineEnd: d3_noop,
  3916. polygonStart: d3_noop,
  3917. polygonEnd: d3_noop
  3918. };
  3919. function d3_geo_pathBoundsPoint(x, y) {
  3920. if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
  3921. if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
  3922. if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
  3923. if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
  3924. }
  3925. function d3_geo_pathBuffer() {
  3926. var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
  3927. var stream = {
  3928. point: point,
  3929. lineStart: function() {
  3930. stream.point = pointLineStart;
  3931. },
  3932. lineEnd: lineEnd,
  3933. polygonStart: function() {
  3934. stream.lineEnd = lineEndPolygon;
  3935. },
  3936. polygonEnd: function() {
  3937. stream.lineEnd = lineEnd;
  3938. stream.point = point;
  3939. },
  3940. pointRadius: function(_) {
  3941. pointCircle = d3_geo_pathBufferCircle(_);
  3942. return stream;
  3943. },
  3944. result: function() {
  3945. if (buffer.length) {
  3946. var result = buffer.join("");
  3947. buffer = [];
  3948. return result;
  3949. }
  3950. }
  3951. };
  3952. function point(x, y) {
  3953. buffer.push("M", x, ",", y, pointCircle);
  3954. }
  3955. function pointLineStart(x, y) {
  3956. buffer.push("M", x, ",", y);
  3957. stream.point = pointLine;
  3958. }
  3959. function pointLine(x, y) {
  3960. buffer.push("L", x, ",", y);
  3961. }
  3962. function lineEnd() {
  3963. stream.point = point;
  3964. }
  3965. function lineEndPolygon() {
  3966. buffer.push("Z");
  3967. }
  3968. return stream;
  3969. }
  3970. function d3_geo_pathBufferCircle(radius) {
  3971. return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
  3972. }
  3973. var d3_geo_pathCentroid = {
  3974. point: d3_geo_pathCentroidPoint,
  3975. lineStart: d3_geo_pathCentroidLineStart,
  3976. lineEnd: d3_geo_pathCentroidLineEnd,
  3977. polygonStart: function() {
  3978. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
  3979. },
  3980. polygonEnd: function() {
  3981. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  3982. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
  3983. d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
  3984. }
  3985. };
  3986. function d3_geo_pathCentroidPoint(x, y) {
  3987. d3_geo_centroidX0 += x;
  3988. d3_geo_centroidY0 += y;
  3989. ++d3_geo_centroidZ0;
  3990. }
  3991. function d3_geo_pathCentroidLineStart() {
  3992. var x0, y0;
  3993. d3_geo_pathCentroid.point = function(x, y) {
  3994. d3_geo_pathCentroid.point = nextPoint;
  3995. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  3996. };
  3997. function nextPoint(x, y) {
  3998. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  3999. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4000. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4001. d3_geo_centroidZ1 += z;
  4002. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4003. }
  4004. }
  4005. function d3_geo_pathCentroidLineEnd() {
  4006. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  4007. }
  4008. function d3_geo_pathCentroidRingStart() {
  4009. var x00, y00, x0, y0;
  4010. d3_geo_pathCentroid.point = function(x, y) {
  4011. d3_geo_pathCentroid.point = nextPoint;
  4012. d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
  4013. };
  4014. function nextPoint(x, y) {
  4015. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  4016. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4017. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4018. d3_geo_centroidZ1 += z;
  4019. z = y0 * x - x0 * y;
  4020. d3_geo_centroidX2 += z * (x0 + x);
  4021. d3_geo_centroidY2 += z * (y0 + y);
  4022. d3_geo_centroidZ2 += z * 3;
  4023. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4024. }
  4025. d3_geo_pathCentroid.lineEnd = function() {
  4026. nextPoint(x00, y00);
  4027. };
  4028. }
  4029. function d3_geo_pathContext(context) {
  4030. var pointRadius = 4.5;
  4031. var stream = {
  4032. point: point,
  4033. lineStart: function() {
  4034. stream.point = pointLineStart;
  4035. },
  4036. lineEnd: lineEnd,
  4037. polygonStart: function() {
  4038. stream.lineEnd = lineEndPolygon;
  4039. },
  4040. polygonEnd: function() {
  4041. stream.lineEnd = lineEnd;
  4042. stream.point = point;
  4043. },
  4044. pointRadius: function(_) {
  4045. pointRadius = _;
  4046. return stream;
  4047. },
  4048. result: d3_noop
  4049. };
  4050. function point(x, y) {
  4051. context.moveTo(x + pointRadius, y);
  4052. context.arc(x, y, pointRadius, 0, τ);
  4053. }
  4054. function pointLineStart(x, y) {
  4055. context.moveTo(x, y);
  4056. stream.point = pointLine;
  4057. }
  4058. function pointLine(x, y) {
  4059. context.lineTo(x, y);
  4060. }
  4061. function lineEnd() {
  4062. stream.point = point;
  4063. }
  4064. function lineEndPolygon() {
  4065. context.closePath();
  4066. }
  4067. return stream;
  4068. }
  4069. function d3_geo_resample(project) {
  4070. var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
  4071. function resample(stream) {
  4072. return (maxDepth ? resampleRecursive : resampleNone)(stream);
  4073. }
  4074. function resampleNone(stream) {
  4075. return d3_geo_transformPoint(stream, function(x, y) {
  4076. x = project(x, y);
  4077. stream.point(x[0], x[1]);
  4078. });
  4079. }
  4080. function resampleRecursive(stream) {
  4081. var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
  4082. var resample = {
  4083. point: point,
  4084. lineStart: lineStart,
  4085. lineEnd: lineEnd,
  4086. polygonStart: function() {
  4087. stream.polygonStart();
  4088. resample.lineStart = ringStart;
  4089. },
  4090. polygonEnd: function() {
  4091. stream.polygonEnd();
  4092. resample.lineStart = lineStart;
  4093. }
  4094. };
  4095. function point(x, y) {
  4096. x = project(x, y);
  4097. stream.point(x[0], x[1]);
  4098. }
  4099. function lineStart() {
  4100. x0 = NaN;
  4101. resample.point = linePoint;
  4102. stream.lineStart();
  4103. }
  4104. function linePoint(λ, φ) {
  4105. var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
  4106. 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);
  4107. stream.point(x0, y0);
  4108. }
  4109. function lineEnd() {
  4110. resample.point = point;
  4111. stream.lineEnd();
  4112. }
  4113. function ringStart() {
  4114. lineStart();
  4115. resample.point = ringPoint;
  4116. resample.lineEnd = ringEnd;
  4117. }
  4118. function ringPoint(λ, φ) {
  4119. linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  4120. resample.point = linePoint;
  4121. }
  4122. function ringEnd() {
  4123. resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
  4124. resample.lineEnd = lineEnd;
  4125. lineEnd();
  4126. }
  4127. return resample;
  4128. }
  4129. function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
  4130. var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
  4131. if (d2 > 4 * δ2 && depth--) {
  4132. 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 = abs(abs(c) - 1) < ε || abs(λ0 - λ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;
  4133. if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
  4134. resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
  4135. stream.point(x2, y2);
  4136. resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
  4137. }
  4138. }
  4139. }
  4140. resample.precision = function(_) {
  4141. if (!arguments.length) return Math.sqrt(δ2);
  4142. maxDepth = (δ2 = _ * _) > 0 && 16;
  4143. return resample;
  4144. };
  4145. return resample;
  4146. }
  4147. d3.geo.path = function() {
  4148. var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
  4149. function path(object) {
  4150. if (object) {
  4151. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  4152. if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
  4153. d3.geo.stream(object, cacheStream);
  4154. }
  4155. return contextStream.result();
  4156. }
  4157. path.area = function(object) {
  4158. d3_geo_pathAreaSum = 0;
  4159. d3.geo.stream(object, projectStream(d3_geo_pathArea));
  4160. return d3_geo_pathAreaSum;
  4161. };
  4162. path.centroid = function(object) {
  4163. 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;
  4164. d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
  4165. 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 ];
  4166. };
  4167. path.bounds = function(object) {
  4168. d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
  4169. d3.geo.stream(object, projectStream(d3_geo_pathBounds));
  4170. return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
  4171. };
  4172. path.projection = function(_) {
  4173. if (!arguments.length) return projection;
  4174. projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
  4175. return reset();
  4176. };
  4177. path.context = function(_) {
  4178. if (!arguments.length) return context;
  4179. contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
  4180. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  4181. return reset();
  4182. };
  4183. path.pointRadius = function(_) {
  4184. if (!arguments.length) return pointRadius;
  4185. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  4186. return path;
  4187. };
  4188. function reset() {
  4189. cacheStream = null;
  4190. return path;
  4191. }
  4192. return path.projection(d3.geo.albersUsa()).context(null);
  4193. };
  4194. function d3_geo_pathProjectStream(project) {
  4195. var resample = d3_geo_resample(function(x, y) {
  4196. return project([ x * d3_degrees, y * d3_degrees ]);
  4197. });
  4198. return function(stream) {
  4199. return d3_geo_projectionRadians(resample(stream));
  4200. };
  4201. }
  4202. d3.geo.transform = function(methods) {
  4203. return {
  4204. stream: function(stream) {
  4205. var transform = new d3_geo_transform(stream);
  4206. for (var k in methods) transform[k] = methods[k];
  4207. return transform;
  4208. }
  4209. };
  4210. };
  4211. function d3_geo_transform(stream) {
  4212. this.stream = stream;
  4213. }
  4214. d3_geo_transform.prototype = {
  4215. point: function(x, y) {
  4216. this.stream.point(x, y);
  4217. },
  4218. sphere: function() {
  4219. this.stream.sphere();
  4220. },
  4221. lineStart: function() {
  4222. this.stream.lineStart();
  4223. },
  4224. lineEnd: function() {
  4225. this.stream.lineEnd();
  4226. },
  4227. polygonStart: function() {
  4228. this.stream.polygonStart();
  4229. },
  4230. polygonEnd: function() {
  4231. this.stream.polygonEnd();
  4232. }
  4233. };
  4234. function d3_geo_transformPoint(stream, point) {
  4235. return {
  4236. point: point,
  4237. sphere: function() {
  4238. stream.sphere();
  4239. },
  4240. lineStart: function() {
  4241. stream.lineStart();
  4242. },
  4243. lineEnd: function() {
  4244. stream.lineEnd();
  4245. },
  4246. polygonStart: function() {
  4247. stream.polygonStart();
  4248. },
  4249. polygonEnd: function() {
  4250. stream.polygonEnd();
  4251. }
  4252. };
  4253. }
  4254. d3.geo.projection = d3_geo_projection;
  4255. d3.geo.projectionMutator = d3_geo_projectionMutator;
  4256. function d3_geo_projection(project) {
  4257. return d3_geo_projectionMutator(function() {
  4258. return project;
  4259. })();
  4260. }
  4261. function d3_geo_projectionMutator(projectAt) {
  4262. var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
  4263. x = project(x, y);
  4264. return [ x[0] * k + δx, δy - x[1] * k ];
  4265. }), 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;
  4266. function projection(point) {
  4267. point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
  4268. return [ point[0] * k + δx, δy - point[1] * k ];
  4269. }
  4270. function invert(point) {
  4271. point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
  4272. return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
  4273. }
  4274. projection.stream = function(output) {
  4275. if (stream) stream.valid = false;
  4276. stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
  4277. stream.valid = true;
  4278. return stream;
  4279. };
  4280. projection.clipAngle = function(_) {
  4281. if (!arguments.length) return clipAngle;
  4282. preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
  4283. return invalidate();
  4284. };
  4285. projection.clipExtent = function(_) {
  4286. if (!arguments.length) return clipExtent;
  4287. clipExtent = _;
  4288. postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
  4289. return invalidate();
  4290. };
  4291. projection.scale = function(_) {
  4292. if (!arguments.length) return k;
  4293. k = +_;
  4294. return reset();
  4295. };
  4296. projection.translate = function(_) {
  4297. if (!arguments.length) return [ x, y ];
  4298. x = +_[0];
  4299. y = +_[1];
  4300. return reset();
  4301. };
  4302. projection.center = function(_) {
  4303. if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
  4304. λ = _[0] % 360 * d3_radians;
  4305. φ = _[1] % 360 * d3_radians;
  4306. return reset();
  4307. };
  4308. projection.rotate = function(_) {
  4309. if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
  4310. δλ = _[0] % 360 * d3_radians;
  4311. δφ = _[1] % 360 * d3_radians;
  4312. δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
  4313. return reset();
  4314. };
  4315. d3.rebind(projection, projectResample, "precision");
  4316. function reset() {
  4317. projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
  4318. var center = project(λ, φ);
  4319. δx = x - center[0] * k;
  4320. δy = y + center[1] * k;
  4321. return invalidate();
  4322. }
  4323. function invalidate() {
  4324. if (stream) stream.valid = false, stream = null;
  4325. return projection;
  4326. }
  4327. return function() {
  4328. project = projectAt.apply(this, arguments);
  4329. projection.invert = project.invert && invert;
  4330. return reset();
  4331. };
  4332. }
  4333. function d3_geo_projectionRadians(stream) {
  4334. return d3_geo_transformPoint(stream, function(x, y) {
  4335. stream.point(x * d3_radians, y * d3_radians);
  4336. });
  4337. }
  4338. function d3_geo_equirectangular(λ, φ) {
  4339. return [ λ, φ ];
  4340. }
  4341. (d3.geo.equirectangular = function() {
  4342. return d3_geo_projection(d3_geo_equirectangular);
  4343. }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
  4344. d3.geo.rotation = function(rotate) {
  4345. rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
  4346. function forward(coordinates) {
  4347. coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4348. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4349. }
  4350. forward.invert = function(coordinates) {
  4351. coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4352. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4353. };
  4354. return forward;
  4355. };
  4356. function d3_geo_identityRotation(λ, φ) {
  4357. return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4358. }
  4359. d3_geo_identityRotation.invert = d3_geo_equirectangular;
  4360. function d3_geo_rotation(δλ, δφ, δγ) {
  4361. return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
  4362. }
  4363. function d3_geo_forwardRotationλ(δλ) {
  4364. return function(λ, φ) {
  4365. return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4366. };
  4367. }
  4368. function d3_geo_rotationλ(δλ) {
  4369. var rotation = d3_geo_forwardRotationλ(δλ);
  4370. rotation.invert = d3_geo_forwardRotationλ(-δλ);
  4371. return rotation;
  4372. }
  4373. function d3_geo_rotationφγ(δφ, δγ) {
  4374. var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
  4375. function rotation(λ, φ) {
  4376. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
  4377. return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
  4378. }
  4379. rotation.invert = function(λ, φ) {
  4380. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
  4381. return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
  4382. };
  4383. return rotation;
  4384. }
  4385. d3.geo.circle = function() {
  4386. var origin = [ 0, 0 ], angle, precision = 6, interpolate;
  4387. function circle() {
  4388. 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 = [];
  4389. interpolate(null, null, 1, {
  4390. point: function(x, y) {
  4391. ring.push(x = rotate(x, y));
  4392. x[0] *= d3_degrees, x[1] *= d3_degrees;
  4393. }
  4394. });
  4395. return {
  4396. type: "Polygon",
  4397. coordinates: [ ring ]
  4398. };
  4399. }
  4400. circle.origin = function(x) {
  4401. if (!arguments.length) return origin;
  4402. origin = x;
  4403. return circle;
  4404. };
  4405. circle.angle = function(x) {
  4406. if (!arguments.length) return angle;
  4407. interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
  4408. return circle;
  4409. };
  4410. circle.precision = function(_) {
  4411. if (!arguments.length) return precision;
  4412. interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
  4413. return circle;
  4414. };
  4415. return circle.angle(90);
  4416. };
  4417. function d3_geo_circleInterpolate(radius, precision) {
  4418. var cr = Math.cos(radius), sr = Math.sin(radius);
  4419. return function(from, to, direction, listener) {
  4420. var step = direction * precision;
  4421. if (from != null) {
  4422. from = d3_geo_circleAngle(cr, from);
  4423. to = d3_geo_circleAngle(cr, to);
  4424. if (direction > 0 ? from < to : from > to) from += direction * τ;
  4425. } else {
  4426. from = radius + direction * τ;
  4427. to = radius - .5 * step;
  4428. }
  4429. for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
  4430. listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
  4431. }
  4432. };
  4433. }
  4434. function d3_geo_circleAngle(cr, point) {
  4435. var a = d3_geo_cartesian(point);
  4436. a[0] -= cr;
  4437. d3_geo_cartesianNormalize(a);
  4438. var angle = d3_acos(-a[1]);
  4439. return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
  4440. }
  4441. d3.geo.distance = function(a, b) {
  4442. 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;
  4443. 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Δλ);
  4444. };
  4445. d3.geo.graticule = function() {
  4446. var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
  4447. function graticule() {
  4448. return {
  4449. type: "MultiLineString",
  4450. coordinates: lines()
  4451. };
  4452. }
  4453. function lines() {
  4454. 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) {
  4455. return abs(x % DX) > ε;
  4456. }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
  4457. return abs(y % DY) > ε;
  4458. }).map(y));
  4459. }
  4460. graticule.lines = function() {
  4461. return lines().map(function(coordinates) {
  4462. return {
  4463. type: "LineString",
  4464. coordinates: coordinates
  4465. };
  4466. });
  4467. };
  4468. graticule.outline = function() {
  4469. return {
  4470. type: "Polygon",
  4471. coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
  4472. };
  4473. };
  4474. graticule.extent = function(_) {
  4475. if (!arguments.length) return graticule.minorExtent();
  4476. return graticule.majorExtent(_).minorExtent(_);
  4477. };
  4478. graticule.majorExtent = function(_) {
  4479. if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
  4480. X0 = +_[0][0], X1 = +_[1][0];
  4481. Y0 = +_[0][1], Y1 = +_[1][1];
  4482. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  4483. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  4484. return graticule.precision(precision);
  4485. };
  4486. graticule.minorExtent = function(_) {
  4487. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  4488. x0 = +_[0][0], x1 = +_[1][0];
  4489. y0 = +_[0][1], y1 = +_[1][1];
  4490. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  4491. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  4492. return graticule.precision(precision);
  4493. };
  4494. graticule.step = function(_) {
  4495. if (!arguments.length) return graticule.minorStep();
  4496. return graticule.majorStep(_).minorStep(_);
  4497. };
  4498. graticule.majorStep = function(_) {
  4499. if (!arguments.length) return [ DX, DY ];
  4500. DX = +_[0], DY = +_[1];
  4501. return graticule;
  4502. };
  4503. graticule.minorStep = function(_) {
  4504. if (!arguments.length) return [ dx, dy ];
  4505. dx = +_[0], dy = +_[1];
  4506. return graticule;
  4507. };
  4508. graticule.precision = function(_) {
  4509. if (!arguments.length) return precision;
  4510. precision = +_;
  4511. x = d3_geo_graticuleX(y0, y1, 90);
  4512. y = d3_geo_graticuleY(x0, x1, precision);
  4513. X = d3_geo_graticuleX(Y0, Y1, 90);
  4514. Y = d3_geo_graticuleY(X0, X1, precision);
  4515. return graticule;
  4516. };
  4517. return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
  4518. };
  4519. function d3_geo_graticuleX(y0, y1, dy) {
  4520. var y = d3.range(y0, y1 - ε, dy).concat(y1);
  4521. return function(x) {
  4522. return y.map(function(y) {
  4523. return [ x, y ];
  4524. });
  4525. };
  4526. }
  4527. function d3_geo_graticuleY(x0, x1, dx) {
  4528. var x = d3.range(x0, x1 - ε, dx).concat(x1);
  4529. return function(y) {
  4530. return x.map(function(x) {
  4531. return [ x, y ];
  4532. });
  4533. };
  4534. }
  4535. function d3_source(d) {
  4536. return d.source;
  4537. }
  4538. function d3_target(d) {
  4539. return d.target;
  4540. }
  4541. d3.geo.greatArc = function() {
  4542. var source = d3_source, source_, target = d3_target, target_;
  4543. function greatArc() {
  4544. return {
  4545. type: "LineString",
  4546. coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
  4547. };
  4548. }
  4549. greatArc.distance = function() {
  4550. return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
  4551. };
  4552. greatArc.source = function(_) {
  4553. if (!arguments.length) return source;
  4554. source = _, source_ = typeof _ === "function" ? null : _;
  4555. return greatArc;
  4556. };
  4557. greatArc.target = function(_) {
  4558. if (!arguments.length) return target;
  4559. target = _, target_ = typeof _ === "function" ? null : _;
  4560. return greatArc;
  4561. };
  4562. greatArc.precision = function() {
  4563. return arguments.length ? greatArc : 0;
  4564. };
  4565. return greatArc;
  4566. };
  4567. d3.geo.interpolate = function(source, target) {
  4568. return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
  4569. };
  4570. function d3_geo_interpolate(x0, y0, x1, y1) {
  4571. 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);
  4572. var interpolate = d ? function(t) {
  4573. 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;
  4574. return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
  4575. } : function() {
  4576. return [ x0 * d3_degrees, y0 * d3_degrees ];
  4577. };
  4578. interpolate.distance = d;
  4579. return interpolate;
  4580. }
  4581. d3.geo.length = function(object) {
  4582. d3_geo_lengthSum = 0;
  4583. d3.geo.stream(object, d3_geo_length);
  4584. return d3_geo_lengthSum;
  4585. };
  4586. var d3_geo_lengthSum;
  4587. var d3_geo_length = {
  4588. sphere: d3_noop,
  4589. point: d3_noop,
  4590. lineStart: d3_geo_lengthLineStart,
  4591. lineEnd: d3_noop,
  4592. polygonStart: d3_noop,
  4593. polygonEnd: d3_noop
  4594. };
  4595. function d3_geo_lengthLineStart() {
  4596. var λ0, sinφ0, cosφ0;
  4597. d3_geo_length.point = function(λ, φ) {
  4598. λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
  4599. d3_geo_length.point = nextPoint;
  4600. };
  4601. d3_geo_length.lineEnd = function() {
  4602. d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
  4603. };
  4604. function nextPoint(λ, φ) {
  4605. var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
  4606. 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Δλ);
  4607. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
  4608. }
  4609. }
  4610. function d3_geo_azimuthal(scale, angle) {
  4611. function azimuthal(λ, φ) {
  4612. var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
  4613. return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
  4614. }
  4615. azimuthal.invert = function(x, y) {
  4616. var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
  4617. return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
  4618. };
  4619. return azimuthal;
  4620. }
  4621. var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
  4622. return Math.sqrt(2 / (1 + cosλcosφ));
  4623. }, function(ρ) {
  4624. return 2 * Math.asin(ρ / 2);
  4625. });
  4626. (d3.geo.azimuthalEqualArea = function() {
  4627. return d3_geo_projection(d3_geo_azimuthalEqualArea);
  4628. }).raw = d3_geo_azimuthalEqualArea;
  4629. var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
  4630. var c = Math.acos(cosλcosφ);
  4631. return c && c / Math.sin(c);
  4632. }, d3_identity);
  4633. (d3.geo.azimuthalEquidistant = function() {
  4634. return d3_geo_projection(d3_geo_azimuthalEquidistant);
  4635. }).raw = d3_geo_azimuthalEquidistant;
  4636. function d3_geo_conicConformal(φ0, φ1) {
  4637. var cosφ0 = Math.cos(φ0), t = function(φ) {
  4638. return Math.tan(π / 4 + φ / 2);
  4639. }, n = φ0 === φ1 ? Math.sin(φ0) : Math.log(cosφ0 / Math.cos(φ1)) / Math.log(t(φ1) / t(φ0)), F = cosφ0 * Math.pow(t(φ0), n) / n;
  4640. if (!n) return d3_geo_mercator;
  4641. function forward(λ, φ) {
  4642. if (F > 0) {
  4643. if (φ < -halfπ + ε) φ = -halfπ + ε;
  4644. } else {
  4645. if (φ > halfπ - ε) φ = halfπ - ε;
  4646. }
  4647. var ρ = F / Math.pow(t(φ), n);
  4648. return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
  4649. }
  4650. forward.invert = function(x, y) {
  4651. var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
  4652. return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
  4653. };
  4654. return forward;
  4655. }
  4656. (d3.geo.conicConformal = function() {
  4657. return d3_geo_conic(d3_geo_conicConformal);
  4658. }).raw = d3_geo_conicConformal;
  4659. function d3_geo_conicEquidistant(φ0, φ1) {
  4660. var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
  4661. if (abs(n) < ε) return d3_geo_equirectangular;
  4662. function forward(λ, φ) {
  4663. var ρ = G - φ;
  4664. return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
  4665. }
  4666. forward.invert = function(x, y) {
  4667. var ρ0_y = G - y;
  4668. return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
  4669. };
  4670. return forward;
  4671. }
  4672. (d3.geo.conicEquidistant = function() {
  4673. return d3_geo_conic(d3_geo_conicEquidistant);
  4674. }).raw = d3_geo_conicEquidistant;
  4675. var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
  4676. return 1 / cosλcosφ;
  4677. }, Math.atan);
  4678. (d3.geo.gnomonic = function() {
  4679. return d3_geo_projection(d3_geo_gnomonic);
  4680. }).raw = d3_geo_gnomonic;
  4681. function d3_geo_mercator(λ, φ) {
  4682. return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
  4683. }
  4684. d3_geo_mercator.invert = function(x, y) {
  4685. return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
  4686. };
  4687. function d3_geo_mercatorProjection(project) {
  4688. var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
  4689. m.scale = function() {
  4690. var v = scale.apply(m, arguments);
  4691. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4692. };
  4693. m.translate = function() {
  4694. var v = translate.apply(m, arguments);
  4695. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4696. };
  4697. m.clipExtent = function(_) {
  4698. var v = clipExtent.apply(m, arguments);
  4699. if (v === m) {
  4700. if (clipAuto = _ == null) {
  4701. var k = π * scale(), t = translate();
  4702. clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
  4703. }
  4704. } else if (clipAuto) {
  4705. v = null;
  4706. }
  4707. return v;
  4708. };
  4709. return m.clipExtent(null);
  4710. }
  4711. (d3.geo.mercator = function() {
  4712. return d3_geo_mercatorProjection(d3_geo_mercator);
  4713. }).raw = d3_geo_mercator;
  4714. var d3_geo_orthographic = d3_geo_azimuthal(function() {
  4715. return 1;
  4716. }, Math.asin);
  4717. (d3.geo.orthographic = function() {
  4718. return d3_geo_projection(d3_geo_orthographic);
  4719. }).raw = d3_geo_orthographic;
  4720. var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
  4721. return 1 / (1 + cosλcosφ);
  4722. }, function(ρ) {
  4723. return 2 * Math.atan(ρ);
  4724. });
  4725. (d3.geo.stereographic = function() {
  4726. return d3_geo_projection(d3_geo_stereographic);
  4727. }).raw = d3_geo_stereographic;
  4728. function d3_geo_transverseMercator(λ, φ) {
  4729. return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
  4730. }
  4731. d3_geo_transverseMercator.invert = function(x, y) {
  4732. return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
  4733. };
  4734. (d3.geo.transverseMercator = function() {
  4735. var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
  4736. projection.center = function(_) {
  4737. return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
  4738. };
  4739. projection.rotate = function(_) {
  4740. return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
  4741. [ _[0], _[1], _[2] - 90 ]);
  4742. };
  4743. return rotate([ 0, 0, 90 ]);
  4744. }).raw = d3_geo_transverseMercator;
  4745. d3.geom = {};
  4746. function d3_geom_pointX(d) {
  4747. return d[0];
  4748. }
  4749. function d3_geom_pointY(d) {
  4750. return d[1];
  4751. }
  4752. d3.geom.hull = function(vertices) {
  4753. var x = d3_geom_pointX, y = d3_geom_pointY;
  4754. if (arguments.length) return hull(vertices);
  4755. function hull(data) {
  4756. if (data.length < 3) return [];
  4757. var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
  4758. for (i = 0; i < n; i++) {
  4759. points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
  4760. }
  4761. points.sort(d3_geom_hullOrder);
  4762. for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
  4763. var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
  4764. var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
  4765. for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
  4766. for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
  4767. return polygon;
  4768. }
  4769. hull.x = function(_) {
  4770. return arguments.length ? (x = _, hull) : x;
  4771. };
  4772. hull.y = function(_) {
  4773. return arguments.length ? (y = _, hull) : y;
  4774. };
  4775. return hull;
  4776. };
  4777. function d3_geom_hullUpper(points) {
  4778. var n = points.length, hull = [ 0, 1 ], hs = 2;
  4779. for (var i = 2; i < n; i++) {
  4780. while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
  4781. hull[hs++] = i;
  4782. }
  4783. return hull.slice(0, hs);
  4784. }
  4785. function d3_geom_hullOrder(a, b) {
  4786. return a[0] - b[0] || a[1] - b[1];
  4787. }
  4788. d3.geom.polygon = function(coordinates) {
  4789. d3_subclass(coordinates, d3_geom_polygonPrototype);
  4790. return coordinates;
  4791. };
  4792. var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
  4793. d3_geom_polygonPrototype.area = function() {
  4794. var i = -1, n = this.length, a, b = this[n - 1], area = 0;
  4795. while (++i < n) {
  4796. a = b;
  4797. b = this[i];
  4798. area += a[1] * b[0] - a[0] * b[1];
  4799. }
  4800. return area * .5;
  4801. };
  4802. d3_geom_polygonPrototype.centroid = function(k) {
  4803. var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
  4804. if (!arguments.length) k = -1 / (6 * this.area());
  4805. while (++i < n) {
  4806. a = b;
  4807. b = this[i];
  4808. c = a[0] * b[1] - b[0] * a[1];
  4809. x += (a[0] + b[0]) * c;
  4810. y += (a[1] + b[1]) * c;
  4811. }
  4812. return [ x * k, y * k ];
  4813. };
  4814. d3_geom_polygonPrototype.clip = function(subject) {
  4815. var input, closed = d3_geom_polygonClosed(subject), i = -1, n = this.length - d3_geom_polygonClosed(this), j, m, a = this[n - 1], b, c, d;
  4816. while (++i < n) {
  4817. input = subject.slice();
  4818. subject.length = 0;
  4819. b = this[i];
  4820. c = input[(m = input.length - closed) - 1];
  4821. j = -1;
  4822. while (++j < m) {
  4823. d = input[j];
  4824. if (d3_geom_polygonInside(d, a, b)) {
  4825. if (!d3_geom_polygonInside(c, a, b)) {
  4826. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4827. }
  4828. subject.push(d);
  4829. } else if (d3_geom_polygonInside(c, a, b)) {
  4830. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4831. }
  4832. c = d;
  4833. }
  4834. if (closed) subject.push(subject[0]);
  4835. a = b;
  4836. }
  4837. return subject;
  4838. };
  4839. function d3_geom_polygonInside(p, a, b) {
  4840. return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
  4841. }
  4842. function d3_geom_polygonIntersect(c, d, a, b) {
  4843. var x1 = c[0], x3 = a[0], x21 = d[0] - x1, x43 = b[0] - x3, y1 = c[1], y3 = a[1], y21 = d[1] - y1, y43 = b[1] - y3, ua = (x43 * (y1 - y3) - y43 * (x1 - x3)) / (y43 * x21 - x43 * y21);
  4844. return [ x1 + ua * x21, y1 + ua * y21 ];
  4845. }
  4846. function d3_geom_polygonClosed(coordinates) {
  4847. var a = coordinates[0], b = coordinates[coordinates.length - 1];
  4848. return !(a[0] - b[0] || a[1] - b[1]);
  4849. }
  4850. var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
  4851. function d3_geom_voronoiBeach() {
  4852. d3_geom_voronoiRedBlackNode(this);
  4853. this.edge = this.site = this.circle = null;
  4854. }
  4855. function d3_geom_voronoiCreateBeach(site) {
  4856. var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
  4857. beach.site = site;
  4858. return beach;
  4859. }
  4860. function d3_geom_voronoiDetachBeach(beach) {
  4861. d3_geom_voronoiDetachCircle(beach);
  4862. d3_geom_voronoiBeaches.remove(beach);
  4863. d3_geom_voronoiBeachPool.push(beach);
  4864. d3_geom_voronoiRedBlackNode(beach);
  4865. }
  4866. function d3_geom_voronoiRemoveBeach(beach) {
  4867. var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
  4868. x: x,
  4869. y: y
  4870. }, previous = beach.P, next = beach.N, disappearing = [ beach ];
  4871. d3_geom_voronoiDetachBeach(beach);
  4872. var lArc = previous;
  4873. while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
  4874. previous = lArc.P;
  4875. disappearing.unshift(lArc);
  4876. d3_geom_voronoiDetachBeach(lArc);
  4877. lArc = previous;
  4878. }
  4879. disappearing.unshift(lArc);
  4880. d3_geom_voronoiDetachCircle(lArc);
  4881. var rArc = next;
  4882. while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
  4883. next = rArc.N;
  4884. disappearing.push(rArc);
  4885. d3_geom_voronoiDetachBeach(rArc);
  4886. rArc = next;
  4887. }
  4888. disappearing.push(rArc);
  4889. d3_geom_voronoiDetachCircle(rArc);
  4890. var nArcs = disappearing.length, iArc;
  4891. for (iArc = 1; iArc < nArcs; ++iArc) {
  4892. rArc = disappearing[iArc];
  4893. lArc = disappearing[iArc - 1];
  4894. d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  4895. }
  4896. lArc = disappearing[0];
  4897. rArc = disappearing[nArcs - 1];
  4898. rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
  4899. d3_geom_voronoiAttachCircle(lArc);
  4900. d3_geom_voronoiAttachCircle(rArc);
  4901. }
  4902. function d3_geom_voronoiAddBeach(site) {
  4903. var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
  4904. while (node) {
  4905. dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
  4906. if (dxl > ε) node = node.L; else {
  4907. dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
  4908. if (dxr > ε) {
  4909. if (!node.R) {
  4910. lArc = node;
  4911. break;
  4912. }
  4913. node = node.R;
  4914. } else {
  4915. if (dxl > -ε) {
  4916. lArc = node.P;
  4917. rArc = node;
  4918. } else if (dxr > -ε) {
  4919. lArc = node;
  4920. rArc = node.N;
  4921. } else {
  4922. lArc = rArc = node;
  4923. }
  4924. break;
  4925. }
  4926. }
  4927. }
  4928. var newArc = d3_geom_voronoiCreateBeach(site);
  4929. d3_geom_voronoiBeaches.insert(lArc, newArc);
  4930. if (!lArc && !rArc) return;
  4931. if (lArc === rArc) {
  4932. d3_geom_voronoiDetachCircle(lArc);
  4933. rArc = d3_geom_voronoiCreateBeach(lArc.site);
  4934. d3_geom_voronoiBeaches.insert(newArc, rArc);
  4935. newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  4936. d3_geom_voronoiAttachCircle(lArc);
  4937. d3_geom_voronoiAttachCircle(rArc);
  4938. return;
  4939. }
  4940. if (!rArc) {
  4941. newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  4942. return;
  4943. }
  4944. d3_geom_voronoiDetachCircle(lArc);
  4945. d3_geom_voronoiDetachCircle(rArc);
  4946. var lSite = lArc.site, ax = lSite.x, ay = lSite.y, bx = site.x - ax, by = site.y - ay, rSite = rArc.site, cx = rSite.x - ax, cy = rSite.y - ay, d = 2 * (bx * cy - by * cx), hb = bx * bx + by * by, hc = cx * cx + cy * cy, vertex = {
  4947. x: (cy * hb - by * hc) / d + ax,
  4948. y: (bx * hc - cx * hb) / d + ay
  4949. };
  4950. d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
  4951. newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
  4952. rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
  4953. d3_geom_voronoiAttachCircle(lArc);
  4954. d3_geom_voronoiAttachCircle(rArc);
  4955. }
  4956. function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
  4957. var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
  4958. if (!pby2) return rfocx;
  4959. var lArc = arc.P;
  4960. if (!lArc) return -Infinity;
  4961. site = lArc.site;
  4962. var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
  4963. if (!plby2) return lfocx;
  4964. var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
  4965. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  4966. return (rfocx + lfocx) / 2;
  4967. }
  4968. function d3_geom_voronoiRightBreakPoint(arc, directrix) {
  4969. var rArc = arc.N;
  4970. if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
  4971. var site = arc.site;
  4972. return site.y === directrix ? site.x : Infinity;
  4973. }
  4974. function d3_geom_voronoiCell(site) {
  4975. this.site = site;
  4976. this.edges = [];
  4977. }
  4978. d3_geom_voronoiCell.prototype.prepare = function() {
  4979. var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
  4980. while (iHalfEdge--) {
  4981. edge = halfEdges[iHalfEdge].edge;
  4982. if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
  4983. }
  4984. halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
  4985. return halfEdges.length;
  4986. };
  4987. function d3_geom_voronoiCloseCells(extent) {
  4988. var x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], x2, y2, x3, y3, cells = d3_geom_voronoiCells, iCell = cells.length, cell, iHalfEdge, halfEdges, nHalfEdges, start, end;
  4989. while (iCell--) {
  4990. cell = cells[iCell];
  4991. if (!cell || !cell.prepare()) continue;
  4992. halfEdges = cell.edges;
  4993. nHalfEdges = halfEdges.length;
  4994. iHalfEdge = 0;
  4995. while (iHalfEdge < nHalfEdges) {
  4996. end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
  4997. start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
  4998. if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
  4999. halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
  5000. x: x0,
  5001. y: abs(x2 - x0) < ε ? y2 : y1
  5002. } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
  5003. x: abs(y2 - y1) < ε ? x2 : x1,
  5004. y: y1
  5005. } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
  5006. x: x1,
  5007. y: abs(x2 - x1) < ε ? y2 : y0
  5008. } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
  5009. x: abs(y2 - y0) < ε ? x2 : x0,
  5010. y: y0
  5011. } : null), cell.site, null));
  5012. ++nHalfEdges;
  5013. }
  5014. }
  5015. }
  5016. }
  5017. function d3_geom_voronoiHalfEdgeOrder(a, b) {
  5018. return b.angle - a.angle;
  5019. }
  5020. function d3_geom_voronoiCircle() {
  5021. d3_geom_voronoiRedBlackNode(this);
  5022. this.x = this.y = this.arc = this.site = this.cy = null;
  5023. }
  5024. function d3_geom_voronoiAttachCircle(arc) {
  5025. var lArc = arc.P, rArc = arc.N;
  5026. if (!lArc || !rArc) return;
  5027. var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
  5028. if (lSite === rSite) return;
  5029. var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
  5030. var d = 2 * (ax * cy - ay * cx);
  5031. if (d >= -ε2) return;
  5032. var ha = ax * ax + ay * ay, hc = cx * cx + cy * cy, x = (cy * ha - ay * hc) / d, y = (ax * hc - cx * ha) / d, cy = y + by;
  5033. var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
  5034. circle.arc = arc;
  5035. circle.site = cSite;
  5036. circle.x = x + bx;
  5037. circle.y = cy + Math.sqrt(x * x + y * y);
  5038. circle.cy = cy;
  5039. arc.circle = circle;
  5040. var before = null, node = d3_geom_voronoiCircles._;
  5041. while (node) {
  5042. if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
  5043. if (node.L) node = node.L; else {
  5044. before = node.P;
  5045. break;
  5046. }
  5047. } else {
  5048. if (node.R) node = node.R; else {
  5049. before = node;
  5050. break;
  5051. }
  5052. }
  5053. }
  5054. d3_geom_voronoiCircles.insert(before, circle);
  5055. if (!before) d3_geom_voronoiFirstCircle = circle;
  5056. }
  5057. function d3_geom_voronoiDetachCircle(arc) {
  5058. var circle = arc.circle;
  5059. if (circle) {
  5060. if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
  5061. d3_geom_voronoiCircles.remove(circle);
  5062. d3_geom_voronoiCirclePool.push(circle);
  5063. d3_geom_voronoiRedBlackNode(circle);
  5064. arc.circle = null;
  5065. }
  5066. }
  5067. function d3_geom_voronoiClipEdges(extent) {
  5068. var edges = d3_geom_voronoiEdges, clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), i = edges.length, e;
  5069. while (i--) {
  5070. e = edges[i];
  5071. if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
  5072. e.a = e.b = null;
  5073. edges.splice(i, 1);
  5074. }
  5075. }
  5076. }
  5077. function d3_geom_voronoiConnectEdge(edge, extent) {
  5078. var vb = edge.b;
  5079. if (vb) return true;
  5080. var va = edge.a, x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], lSite = edge.l, rSite = edge.r, lx = lSite.x, ly = lSite.y, rx = rSite.x, ry = rSite.y, fx = (lx + rx) / 2, fy = (ly + ry) / 2, fm, fb;
  5081. if (ry === ly) {
  5082. if (fx < x0 || fx >= x1) return;
  5083. if (lx > rx) {
  5084. if (!va) va = {
  5085. x: fx,
  5086. y: y0
  5087. }; else if (va.y >= y1) return;
  5088. vb = {
  5089. x: fx,
  5090. y: y1
  5091. };
  5092. } else {
  5093. if (!va) va = {
  5094. x: fx,
  5095. y: y1
  5096. }; else if (va.y < y0) return;
  5097. vb = {
  5098. x: fx,
  5099. y: y0
  5100. };
  5101. }
  5102. } else {
  5103. fm = (lx - rx) / (ry - ly);
  5104. fb = fy - fm * fx;
  5105. if (fm < -1 || fm > 1) {
  5106. if (lx > rx) {
  5107. if (!va) va = {
  5108. x: (y0 - fb) / fm,
  5109. y: y0
  5110. }; else if (va.y >= y1) return;
  5111. vb = {
  5112. x: (y1 - fb) / fm,
  5113. y: y1
  5114. };
  5115. } else {
  5116. if (!va) va = {
  5117. x: (y1 - fb) / fm,
  5118. y: y1
  5119. }; else if (va.y < y0) return;
  5120. vb = {
  5121. x: (y0 - fb) / fm,
  5122. y: y0
  5123. };
  5124. }
  5125. } else {
  5126. if (ly < ry) {
  5127. if (!va) va = {
  5128. x: x0,
  5129. y: fm * x0 + fb
  5130. }; else if (va.x >= x1) return;
  5131. vb = {
  5132. x: x1,
  5133. y: fm * x1 + fb
  5134. };
  5135. } else {
  5136. if (!va) va = {
  5137. x: x1,
  5138. y: fm * x1 + fb
  5139. }; else if (va.x < x0) return;
  5140. vb = {
  5141. x: x0,
  5142. y: fm * x0 + fb
  5143. };
  5144. }
  5145. }
  5146. }
  5147. edge.a = va;
  5148. edge.b = vb;
  5149. return true;
  5150. }
  5151. function d3_geom_voronoiEdge(lSite, rSite) {
  5152. this.l = lSite;
  5153. this.r = rSite;
  5154. this.a = this.b = null;
  5155. }
  5156. function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
  5157. var edge = new d3_geom_voronoiEdge(lSite, rSite);
  5158. d3_geom_voronoiEdges.push(edge);
  5159. if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
  5160. if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
  5161. d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
  5162. d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
  5163. return edge;
  5164. }
  5165. function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
  5166. var edge = new d3_geom_voronoiEdge(lSite, null);
  5167. edge.a = va;
  5168. edge.b = vb;
  5169. d3_geom_voronoiEdges.push(edge);
  5170. return edge;
  5171. }
  5172. function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
  5173. if (!edge.a && !edge.b) {
  5174. edge.a = vertex;
  5175. edge.l = lSite;
  5176. edge.r = rSite;
  5177. } else if (edge.l === rSite) {
  5178. edge.b = vertex;
  5179. } else {
  5180. edge.a = vertex;
  5181. }
  5182. }
  5183. function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
  5184. var va = edge.a, vb = edge.b;
  5185. this.edge = edge;
  5186. this.site = lSite;
  5187. this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) : Math.atan2(va.x - vb.x, vb.y - va.y);
  5188. }
  5189. d3_geom_voronoiHalfEdge.prototype = {
  5190. start: function() {
  5191. return this.edge.l === this.site ? this.edge.a : this.edge.b;
  5192. },
  5193. end: function() {
  5194. return this.edge.l === this.site ? this.edge.b : this.edge.a;
  5195. }
  5196. };
  5197. function d3_geom_voronoiRedBlackTree() {
  5198. this._ = null;
  5199. }
  5200. function d3_geom_voronoiRedBlackNode(node) {
  5201. node.U = node.C = node.L = node.R = node.P = node.N = null;
  5202. }
  5203. d3_geom_voronoiRedBlackTree.prototype = {
  5204. insert: function(after, node) {
  5205. var parent, grandpa, uncle;
  5206. if (after) {
  5207. node.P = after;
  5208. node.N = after.N;
  5209. if (after.N) after.N.P = node;
  5210. after.N = node;
  5211. if (after.R) {
  5212. after = after.R;
  5213. while (after.L) after = after.L;
  5214. after.L = node;
  5215. } else {
  5216. after.R = node;
  5217. }
  5218. parent = after;
  5219. } else if (this._) {
  5220. after = d3_geom_voronoiRedBlackFirst(this._);
  5221. node.P = null;
  5222. node.N = after;
  5223. after.P = after.L = node;
  5224. parent = after;
  5225. } else {
  5226. node.P = node.N = null;
  5227. this._ = node;
  5228. parent = null;
  5229. }
  5230. node.L = node.R = null;
  5231. node.U = parent;
  5232. node.C = true;
  5233. after = node;
  5234. while (parent && parent.C) {
  5235. grandpa = parent.U;
  5236. if (parent === grandpa.L) {
  5237. uncle = grandpa.R;
  5238. if (uncle && uncle.C) {
  5239. parent.C = uncle.C = false;
  5240. grandpa.C = true;
  5241. after = grandpa;
  5242. } else {
  5243. if (after === parent.R) {
  5244. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5245. after = parent;
  5246. parent = after.U;
  5247. }
  5248. parent.C = false;
  5249. grandpa.C = true;
  5250. d3_geom_voronoiRedBlackRotateRight(this, grandpa);
  5251. }
  5252. } else {
  5253. uncle = grandpa.L;
  5254. if (uncle && uncle.C) {
  5255. parent.C = uncle.C = false;
  5256. grandpa.C = true;
  5257. after = grandpa;
  5258. } else {
  5259. if (after === parent.L) {
  5260. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5261. after = parent;
  5262. parent = after.U;
  5263. }
  5264. parent.C = false;
  5265. grandpa.C = true;
  5266. d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
  5267. }
  5268. }
  5269. parent = after.U;
  5270. }
  5271. this._.C = false;
  5272. },
  5273. remove: function(node) {
  5274. if (node.N) node.N.P = node.P;
  5275. if (node.P) node.P.N = node.N;
  5276. node.N = node.P = null;
  5277. var parent = node.U, sibling, left = node.L, right = node.R, next, red;
  5278. if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
  5279. if (parent) {
  5280. if (parent.L === node) parent.L = next; else parent.R = next;
  5281. } else {
  5282. this._ = next;
  5283. }
  5284. if (left && right) {
  5285. red = next.C;
  5286. next.C = node.C;
  5287. next.L = left;
  5288. left.U = next;
  5289. if (next !== right) {
  5290. parent = next.U;
  5291. next.U = node.U;
  5292. node = next.R;
  5293. parent.L = node;
  5294. next.R = right;
  5295. right.U = next;
  5296. } else {
  5297. next.U = parent;
  5298. parent = next;
  5299. node = next.R;
  5300. }
  5301. } else {
  5302. red = node.C;
  5303. node = next;
  5304. }
  5305. if (node) node.U = parent;
  5306. if (red) return;
  5307. if (node && node.C) {
  5308. node.C = false;
  5309. return;
  5310. }
  5311. do {
  5312. if (node === this._) break;
  5313. if (node === parent.L) {
  5314. sibling = parent.R;
  5315. if (sibling.C) {
  5316. sibling.C = false;
  5317. parent.C = true;
  5318. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5319. sibling = parent.R;
  5320. }
  5321. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5322. if (!sibling.R || !sibling.R.C) {
  5323. sibling.L.C = false;
  5324. sibling.C = true;
  5325. d3_geom_voronoiRedBlackRotateRight(this, sibling);
  5326. sibling = parent.R;
  5327. }
  5328. sibling.C = parent.C;
  5329. parent.C = sibling.R.C = false;
  5330. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5331. node = this._;
  5332. break;
  5333. }
  5334. } else {
  5335. sibling = parent.L;
  5336. if (sibling.C) {
  5337. sibling.C = false;
  5338. parent.C = true;
  5339. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5340. sibling = parent.L;
  5341. }
  5342. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5343. if (!sibling.L || !sibling.L.C) {
  5344. sibling.R.C = false;
  5345. sibling.C = true;
  5346. d3_geom_voronoiRedBlackRotateLeft(this, sibling);
  5347. sibling = parent.L;
  5348. }
  5349. sibling.C = parent.C;
  5350. parent.C = sibling.L.C = false;
  5351. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5352. node = this._;
  5353. break;
  5354. }
  5355. }
  5356. sibling.C = true;
  5357. node = parent;
  5358. parent = parent.U;
  5359. } while (!node.C);
  5360. if (node) node.C = false;
  5361. }
  5362. };
  5363. function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
  5364. var p = node, q = node.R, parent = p.U;
  5365. if (parent) {
  5366. if (parent.L === p) parent.L = q; else parent.R = q;
  5367. } else {
  5368. tree._ = q;
  5369. }
  5370. q.U = parent;
  5371. p.U = q;
  5372. p.R = q.L;
  5373. if (p.R) p.R.U = p;
  5374. q.L = p;
  5375. }
  5376. function d3_geom_voronoiRedBlackRotateRight(tree, node) {
  5377. var p = node, q = node.L, parent = p.U;
  5378. if (parent) {
  5379. if (parent.L === p) parent.L = q; else parent.R = q;
  5380. } else {
  5381. tree._ = q;
  5382. }
  5383. q.U = parent;
  5384. p.U = q;
  5385. p.L = q.R;
  5386. if (p.L) p.L.U = p;
  5387. q.R = p;
  5388. }
  5389. function d3_geom_voronoiRedBlackFirst(node) {
  5390. while (node.L) node = node.L;
  5391. return node;
  5392. }
  5393. function d3_geom_voronoi(sites, bbox) {
  5394. var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
  5395. d3_geom_voronoiEdges = [];
  5396. d3_geom_voronoiCells = new Array(sites.length);
  5397. d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
  5398. d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
  5399. while (true) {
  5400. circle = d3_geom_voronoiFirstCircle;
  5401. if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
  5402. if (site.x !== x0 || site.y !== y0) {
  5403. d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
  5404. d3_geom_voronoiAddBeach(site);
  5405. x0 = site.x, y0 = site.y;
  5406. }
  5407. site = sites.pop();
  5408. } else if (circle) {
  5409. d3_geom_voronoiRemoveBeach(circle.arc);
  5410. } else {
  5411. break;
  5412. }
  5413. }
  5414. if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
  5415. var diagram = {
  5416. cells: d3_geom_voronoiCells,
  5417. edges: d3_geom_voronoiEdges
  5418. };
  5419. d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
  5420. return diagram;
  5421. }
  5422. function d3_geom_voronoiVertexOrder(a, b) {
  5423. return b.y - a.y || b.x - a.x;
  5424. }
  5425. d3.geom.voronoi = function(points) {
  5426. var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
  5427. if (points) return voronoi(points);
  5428. function voronoi(data) {
  5429. var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
  5430. d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
  5431. var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
  5432. var s = e.start();
  5433. return [ s.x, s.y ];
  5434. }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
  5435. polygon.point = data[i];
  5436. });
  5437. return polygons;
  5438. }
  5439. function sites(data) {
  5440. return data.map(function(d, i) {
  5441. return {
  5442. x: Math.round(fx(d, i) / ε) * ε,
  5443. y: Math.round(fy(d, i) / ε) * ε,
  5444. i: i
  5445. };
  5446. });
  5447. }
  5448. voronoi.links = function(data) {
  5449. return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
  5450. return edge.l && edge.r;
  5451. }).map(function(edge) {
  5452. return {
  5453. source: data[edge.l.i],
  5454. target: data[edge.r.i]
  5455. };
  5456. });
  5457. };
  5458. voronoi.triangles = function(data) {
  5459. var triangles = [];
  5460. d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
  5461. var site = cell.site, edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), j = -1, m = edges.length, e0, s0, e1 = edges[m - 1].edge, s1 = e1.l === site ? e1.r : e1.l;
  5462. while (++j < m) {
  5463. e0 = e1;
  5464. s0 = s1;
  5465. e1 = edges[j].edge;
  5466. s1 = e1.l === site ? e1.r : e1.l;
  5467. if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
  5468. triangles.push([ data[i], data[s0.i], data[s1.i] ]);
  5469. }
  5470. }
  5471. });
  5472. return triangles;
  5473. };
  5474. voronoi.x = function(_) {
  5475. return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
  5476. };
  5477. voronoi.y = function(_) {
  5478. return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
  5479. };
  5480. voronoi.clipExtent = function(_) {
  5481. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
  5482. clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
  5483. return voronoi;
  5484. };
  5485. voronoi.size = function(_) {
  5486. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
  5487. return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
  5488. };
  5489. return voronoi;
  5490. };
  5491. var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
  5492. function d3_geom_voronoiTriangleArea(a, b, c) {
  5493. return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
  5494. }
  5495. d3.geom.delaunay = function(vertices) {
  5496. return d3.geom.voronoi().triangles(vertices);
  5497. };
  5498. d3.geom.quadtree = function(points, x1, y1, x2, y2) {
  5499. var x = d3_geom_pointX, y = d3_geom_pointY, compat;
  5500. if (compat = arguments.length) {
  5501. x = d3_geom_quadtreeCompatX;
  5502. y = d3_geom_quadtreeCompatY;
  5503. if (compat === 3) {
  5504. y2 = y1;
  5505. x2 = x1;
  5506. y1 = x1 = 0;
  5507. }
  5508. return quadtree(points);
  5509. }
  5510. function quadtree(data) {
  5511. var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
  5512. if (x1 != null) {
  5513. x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
  5514. } else {
  5515. x2_ = y2_ = -(x1_ = y1_ = Infinity);
  5516. xs = [], ys = [];
  5517. n = data.length;
  5518. if (compat) for (i = 0; i < n; ++i) {
  5519. d = data[i];
  5520. if (d.x < x1_) x1_ = d.x;
  5521. if (d.y < y1_) y1_ = d.y;
  5522. if (d.x > x2_) x2_ = d.x;
  5523. if (d.y > y2_) y2_ = d.y;
  5524. xs.push(d.x);
  5525. ys.push(d.y);
  5526. } else for (i = 0; i < n; ++i) {
  5527. var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
  5528. if (x_ < x1_) x1_ = x_;
  5529. if (y_ < y1_) y1_ = y_;
  5530. if (x_ > x2_) x2_ = x_;
  5531. if (y_ > y2_) y2_ = y_;
  5532. xs.push(x_);
  5533. ys.push(y_);
  5534. }
  5535. }
  5536. var dx = x2_ - x1_, dy = y2_ - y1_;
  5537. if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
  5538. function insert(n, d, x, y, x1, y1, x2, y2) {
  5539. if (isNaN(x) || isNaN(y)) return;
  5540. if (n.leaf) {
  5541. var nx = n.x, ny = n.y;
  5542. if (nx != null) {
  5543. if (abs(nx - x) + abs(ny - y) < .01) {
  5544. insertChild(n, d, x, y, x1, y1, x2, y2);
  5545. } else {
  5546. var nPoint = n.point;
  5547. n.x = n.y = n.point = null;
  5548. insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
  5549. insertChild(n, d, x, y, x1, y1, x2, y2);
  5550. }
  5551. } else {
  5552. n.x = x, n.y = y, n.point = d;
  5553. }
  5554. } else {
  5555. insertChild(n, d, x, y, x1, y1, x2, y2);
  5556. }
  5557. }
  5558. function insertChild(n, d, x, y, x1, y1, x2, y2) {
  5559. var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
  5560. n.leaf = false;
  5561. n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
  5562. if (right) x1 = xm; else x2 = xm;
  5563. if (below) y1 = ym; else y2 = ym;
  5564. insert(n, d, x, y, x1, y1, x2, y2);
  5565. }
  5566. var root = d3_geom_quadtreeNode();
  5567. root.add = function(d) {
  5568. insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
  5569. };
  5570. root.visit = function(f) {
  5571. d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
  5572. };
  5573. root.find = function(point) {
  5574. return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
  5575. };
  5576. i = -1;
  5577. if (x1 == null) {
  5578. while (++i < n) {
  5579. insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
  5580. }
  5581. --i;
  5582. } else data.forEach(root.add);
  5583. xs = ys = data = d = null;
  5584. return root;
  5585. }
  5586. quadtree.x = function(_) {
  5587. return arguments.length ? (x = _, quadtree) : x;
  5588. };
  5589. quadtree.y = function(_) {
  5590. return arguments.length ? (y = _, quadtree) : y;
  5591. };
  5592. quadtree.extent = function(_) {
  5593. if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
  5594. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
  5595. y2 = +_[1][1];
  5596. return quadtree;
  5597. };
  5598. quadtree.size = function(_) {
  5599. if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
  5600. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
  5601. return quadtree;
  5602. };
  5603. return quadtree;
  5604. };
  5605. function d3_geom_quadtreeCompatX(d) {
  5606. return d.x;
  5607. }
  5608. function d3_geom_quadtreeCompatY(d) {
  5609. return d.y;
  5610. }
  5611. function d3_geom_quadtreeNode() {
  5612. return {
  5613. leaf: true,
  5614. nodes: [],
  5615. point: null,
  5616. x: null,
  5617. y: null
  5618. };
  5619. }
  5620. function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
  5621. if (!f(node, x1, y1, x2, y2)) {
  5622. var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
  5623. if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
  5624. if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
  5625. if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
  5626. if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
  5627. }
  5628. }
  5629. function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
  5630. var minDistance2 = Infinity, closestPoint;
  5631. (function find(node, x1, y1, x2, y2) {
  5632. if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
  5633. if (point = node.point) {
  5634. var point, dx = x - point[0], dy = y - point[1], distance2 = dx * dx + dy * dy;
  5635. if (distance2 < minDistance2) {
  5636. var distance = Math.sqrt(minDistance2 = distance2);
  5637. x0 = x - distance, y0 = y - distance;
  5638. x3 = x + distance, y3 = y + distance;
  5639. closestPoint = point;
  5640. }
  5641. }
  5642. var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
  5643. for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
  5644. if (node = children[i & 3]) switch (i & 3) {
  5645. case 0:
  5646. find(node, x1, y1, xm, ym);
  5647. break;
  5648. case 1:
  5649. find(node, xm, y1, x2, ym);
  5650. break;
  5651. case 2:
  5652. find(node, x1, ym, xm, y2);
  5653. break;
  5654. case 3:
  5655. find(node, xm, ym, x2, y2);
  5656. break;
  5657. }
  5658. }
  5659. })(root, x0, y0, x3, y3);
  5660. return closestPoint;
  5661. }
  5662. d3.interpolateRgb = d3_interpolateRgb;
  5663. function d3_interpolateRgb(a, b) {
  5664. a = d3.rgb(a);
  5665. b = d3.rgb(b);
  5666. var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
  5667. return function(t) {
  5668. return "#" + d3_rgb_hex(Math.round(ar + br * t)) + d3_rgb_hex(Math.round(ag + bg * t)) + d3_rgb_hex(Math.round(ab + bb * t));
  5669. };
  5670. }
  5671. d3.interpolateObject = d3_interpolateObject;
  5672. function d3_interpolateObject(a, b) {
  5673. var i = {}, c = {}, k;
  5674. for (k in a) {
  5675. if (k in b) {
  5676. i[k] = d3_interpolate(a[k], b[k]);
  5677. } else {
  5678. c[k] = a[k];
  5679. }
  5680. }
  5681. for (k in b) {
  5682. if (!(k in a)) {
  5683. c[k] = b[k];
  5684. }
  5685. }
  5686. return function(t) {
  5687. for (k in i) c[k] = i[k](t);
  5688. return c;
  5689. };
  5690. }
  5691. d3.interpolateNumber = d3_interpolateNumber;
  5692. function d3_interpolateNumber(a, b) {
  5693. a = +a, b = +b;
  5694. return function(t) {
  5695. return a * (1 - t) + b * t;
  5696. };
  5697. }
  5698. d3.interpolateString = d3_interpolateString;
  5699. function d3_interpolateString(a, b) {
  5700. var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
  5701. a = a + "", b = b + "";
  5702. while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
  5703. if ((bs = bm.index) > bi) {
  5704. bs = b.slice(bi, bs);
  5705. if (s[i]) s[i] += bs; else s[++i] = bs;
  5706. }
  5707. if ((am = am[0]) === (bm = bm[0])) {
  5708. if (s[i]) s[i] += bm; else s[++i] = bm;
  5709. } else {
  5710. s[++i] = null;
  5711. q.push({
  5712. i: i,
  5713. x: d3_interpolateNumber(am, bm)
  5714. });
  5715. }
  5716. bi = d3_interpolate_numberB.lastIndex;
  5717. }
  5718. if (bi < b.length) {
  5719. bs = b.slice(bi);
  5720. if (s[i]) s[i] += bs; else s[++i] = bs;
  5721. }
  5722. return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
  5723. return b(t) + "";
  5724. }) : function() {
  5725. return b;
  5726. } : (b = q.length, function(t) {
  5727. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  5728. return s.join("");
  5729. });
  5730. }
  5731. var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
  5732. d3.interpolate = d3_interpolate;
  5733. function d3_interpolate(a, b) {
  5734. var i = d3.interpolators.length, f;
  5735. while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
  5736. return f;
  5737. }
  5738. d3.interpolators = [ function(a, b) {
  5739. var t = typeof b;
  5740. return (t === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b);
  5741. } ];
  5742. d3.interpolateArray = d3_interpolateArray;
  5743. function d3_interpolateArray(a, b) {
  5744. var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
  5745. for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
  5746. for (;i < na; ++i) c[i] = a[i];
  5747. for (;i < nb; ++i) c[i] = b[i];
  5748. return function(t) {
  5749. for (i = 0; i < n0; ++i) c[i] = x[i](t);
  5750. return c;
  5751. };
  5752. }
  5753. var d3_ease_default = function() {
  5754. return d3_identity;
  5755. };
  5756. var d3_ease = d3.map({
  5757. linear: d3_ease_default,
  5758. poly: d3_ease_poly,
  5759. quad: function() {
  5760. return d3_ease_quad;
  5761. },
  5762. cubic: function() {
  5763. return d3_ease_cubic;
  5764. },
  5765. sin: function() {
  5766. return d3_ease_sin;
  5767. },
  5768. exp: function() {
  5769. return d3_ease_exp;
  5770. },
  5771. circle: function() {
  5772. return d3_ease_circle;
  5773. },
  5774. elastic: d3_ease_elastic,
  5775. back: d3_ease_back,
  5776. bounce: function() {
  5777. return d3_ease_bounce;
  5778. }
  5779. });
  5780. var d3_ease_mode = d3.map({
  5781. "in": d3_identity,
  5782. out: d3_ease_reverse,
  5783. "in-out": d3_ease_reflect,
  5784. "out-in": function(f) {
  5785. return d3_ease_reflect(d3_ease_reverse(f));
  5786. }
  5787. });
  5788. d3.ease = function(name) {
  5789. var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
  5790. t = d3_ease.get(t) || d3_ease_default;
  5791. m = d3_ease_mode.get(m) || d3_identity;
  5792. return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
  5793. };
  5794. function d3_ease_clamp(f) {
  5795. return function(t) {
  5796. return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
  5797. };
  5798. }
  5799. function d3_ease_reverse(f) {
  5800. return function(t) {
  5801. return 1 - f(1 - t);
  5802. };
  5803. }
  5804. function d3_ease_reflect(f) {
  5805. return function(t) {
  5806. return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
  5807. };
  5808. }
  5809. function d3_ease_quad(t) {
  5810. return t * t;
  5811. }
  5812. function d3_ease_cubic(t) {
  5813. return t * t * t;
  5814. }
  5815. function d3_ease_cubicInOut(t) {
  5816. if (t <= 0) return 0;
  5817. if (t >= 1) return 1;
  5818. var t2 = t * t, t3 = t2 * t;
  5819. return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
  5820. }
  5821. function d3_ease_poly(e) {
  5822. return function(t) {
  5823. return Math.pow(t, e);
  5824. };
  5825. }
  5826. function d3_ease_sin(t) {
  5827. return 1 - Math.cos(t * halfπ);
  5828. }
  5829. function d3_ease_exp(t) {
  5830. return Math.pow(2, 10 * (t - 1));
  5831. }
  5832. function d3_ease_circle(t) {
  5833. return 1 - Math.sqrt(1 - t * t);
  5834. }
  5835. function d3_ease_elastic(a, p) {
  5836. var s;
  5837. if (arguments.length < 2) p = .45;
  5838. if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
  5839. return function(t) {
  5840. return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
  5841. };
  5842. }
  5843. function d3_ease_back(s) {
  5844. if (!s) s = 1.70158;
  5845. return function(t) {
  5846. return t * t * ((s + 1) * t - s);
  5847. };
  5848. }
  5849. function d3_ease_bounce(t) {
  5850. return t < 1 / 2.75 ? 7.5625 * t * t : t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + .75 : t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + .9375 : 7.5625 * (t -= 2.625 / 2.75) * t + .984375;
  5851. }
  5852. d3.interpolateHcl = d3_interpolateHcl;
  5853. function d3_interpolateHcl(a, b) {
  5854. a = d3.hcl(a);
  5855. b = d3.hcl(b);
  5856. var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
  5857. if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
  5858. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5859. return function(t) {
  5860. return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
  5861. };
  5862. }
  5863. d3.interpolateHsl = d3_interpolateHsl;
  5864. function d3_interpolateHsl(a, b) {
  5865. a = d3.hsl(a);
  5866. b = d3.hsl(b);
  5867. var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
  5868. if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
  5869. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5870. return function(t) {
  5871. return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
  5872. };
  5873. }
  5874. d3.interpolateLab = d3_interpolateLab;
  5875. function d3_interpolateLab(a, b) {
  5876. a = d3.lab(a);
  5877. b = d3.lab(b);
  5878. var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
  5879. return function(t) {
  5880. return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
  5881. };
  5882. }
  5883. d3.interpolateRound = d3_interpolateRound;
  5884. function d3_interpolateRound(a, b) {
  5885. b -= a;
  5886. return function(t) {
  5887. return Math.round(a + b * t);
  5888. };
  5889. }
  5890. d3.transform = function(string) {
  5891. var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
  5892. return (d3.transform = function(string) {
  5893. if (string != null) {
  5894. g.setAttribute("transform", string);
  5895. var t = g.transform.baseVal.consolidate();
  5896. }
  5897. return new d3_transform(t ? t.matrix : d3_transformIdentity);
  5898. })(string);
  5899. };
  5900. function d3_transform(m) {
  5901. var r0 = [ m.a, m.b ], r1 = [ m.c, m.d ], kx = d3_transformNormalize(r0), kz = d3_transformDot(r0, r1), ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz)) || 0;
  5902. if (r0[0] * r1[1] < r1[0] * r0[1]) {
  5903. r0[0] *= -1;
  5904. r0[1] *= -1;
  5905. kx *= -1;
  5906. kz *= -1;
  5907. }
  5908. this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
  5909. this.translate = [ m.e, m.f ];
  5910. this.scale = [ kx, ky ];
  5911. this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
  5912. }
  5913. d3_transform.prototype.toString = function() {
  5914. return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
  5915. };
  5916. function d3_transformDot(a, b) {
  5917. return a[0] * b[0] + a[1] * b[1];
  5918. }
  5919. function d3_transformNormalize(a) {
  5920. var k = Math.sqrt(d3_transformDot(a, a));
  5921. if (k) {
  5922. a[0] /= k;
  5923. a[1] /= k;
  5924. }
  5925. return k;
  5926. }
  5927. function d3_transformCombine(a, b, k) {
  5928. a[0] += k * b[0];
  5929. a[1] += k * b[1];
  5930. return a;
  5931. }
  5932. var d3_transformIdentity = {
  5933. a: 1,
  5934. b: 0,
  5935. c: 0,
  5936. d: 1,
  5937. e: 0,
  5938. f: 0
  5939. };
  5940. d3.interpolateTransform = d3_interpolateTransform;
  5941. function d3_interpolateTransform(a, b) {
  5942. var s = [], q = [], n, A = d3.transform(a), B = d3.transform(b), ta = A.translate, tb = B.translate, ra = A.rotate, rb = B.rotate, wa = A.skew, wb = B.skew, ka = A.scale, kb = B.scale;
  5943. if (ta[0] != tb[0] || ta[1] != tb[1]) {
  5944. s.push("translate(", null, ",", null, ")");
  5945. q.push({
  5946. i: 1,
  5947. x: d3_interpolateNumber(ta[0], tb[0])
  5948. }, {
  5949. i: 3,
  5950. x: d3_interpolateNumber(ta[1], tb[1])
  5951. });
  5952. } else if (tb[0] || tb[1]) {
  5953. s.push("translate(" + tb + ")");
  5954. } else {
  5955. s.push("");
  5956. }
  5957. if (ra != rb) {
  5958. if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
  5959. q.push({
  5960. i: s.push(s.pop() + "rotate(", null, ")") - 2,
  5961. x: d3_interpolateNumber(ra, rb)
  5962. });
  5963. } else if (rb) {
  5964. s.push(s.pop() + "rotate(" + rb + ")");
  5965. }
  5966. if (wa != wb) {
  5967. q.push({
  5968. i: s.push(s.pop() + "skewX(", null, ")") - 2,
  5969. x: d3_interpolateNumber(wa, wb)
  5970. });
  5971. } else if (wb) {
  5972. s.push(s.pop() + "skewX(" + wb + ")");
  5973. }
  5974. if (ka[0] != kb[0] || ka[1] != kb[1]) {
  5975. n = s.push(s.pop() + "scale(", null, ",", null, ")");
  5976. q.push({
  5977. i: n - 4,
  5978. x: d3_interpolateNumber(ka[0], kb[0])
  5979. }, {
  5980. i: n - 2,
  5981. x: d3_interpolateNumber(ka[1], kb[1])
  5982. });
  5983. } else if (kb[0] != 1 || kb[1] != 1) {
  5984. s.push(s.pop() + "scale(" + kb + ")");
  5985. }
  5986. n = q.length;
  5987. return function(t) {
  5988. var i = -1, o;
  5989. while (++i < n) s[(o = q[i]).i] = o.x(t);
  5990. return s.join("");
  5991. };
  5992. }
  5993. function d3_uninterpolateNumber(a, b) {
  5994. b = (b -= a = +a) || 1 / b;
  5995. return function(x) {
  5996. return (x - a) / b;
  5997. };
  5998. }
  5999. function d3_uninterpolateClamp(a, b) {
  6000. b = (b -= a = +a) || 1 / b;
  6001. return function(x) {
  6002. return Math.max(0, Math.min(1, (x - a) / b));
  6003. };
  6004. }
  6005. d3.layout = {};
  6006. d3.layout.bundle = function() {
  6007. return function(links) {
  6008. var paths = [], i = -1, n = links.length;
  6009. while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
  6010. return paths;
  6011. };
  6012. };
  6013. function d3_layout_bundlePath(link) {
  6014. var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
  6015. while (start !== lca) {
  6016. start = start.parent;
  6017. points.push(start);
  6018. }
  6019. var k = points.length;
  6020. while (end !== lca) {
  6021. points.splice(k, 0, end);
  6022. end = end.parent;
  6023. }
  6024. return points;
  6025. }
  6026. function d3_layout_bundleAncestors(node) {
  6027. var ancestors = [], parent = node.parent;
  6028. while (parent != null) {
  6029. ancestors.push(node);
  6030. node = parent;
  6031. parent = parent.parent;
  6032. }
  6033. ancestors.push(node);
  6034. return ancestors;
  6035. }
  6036. function d3_layout_bundleLeastCommonAncestor(a, b) {
  6037. if (a === b) return a;
  6038. var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
  6039. while (aNode === bNode) {
  6040. sharedNode = aNode;
  6041. aNode = aNodes.pop();
  6042. bNode = bNodes.pop();
  6043. }
  6044. return sharedNode;
  6045. }
  6046. d3.layout.chord = function() {
  6047. var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
  6048. function relayout() {
  6049. var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
  6050. chords = [];
  6051. groups = [];
  6052. k = 0, i = -1;
  6053. while (++i < n) {
  6054. x = 0, j = -1;
  6055. while (++j < n) {
  6056. x += matrix[i][j];
  6057. }
  6058. groupSums.push(x);
  6059. subgroupIndex.push(d3.range(n));
  6060. k += x;
  6061. }
  6062. if (sortGroups) {
  6063. groupIndex.sort(function(a, b) {
  6064. return sortGroups(groupSums[a], groupSums[b]);
  6065. });
  6066. }
  6067. if (sortSubgroups) {
  6068. subgroupIndex.forEach(function(d, i) {
  6069. d.sort(function(a, b) {
  6070. return sortSubgroups(matrix[i][a], matrix[i][b]);
  6071. });
  6072. });
  6073. }
  6074. k = (τ - padding * n) / k;
  6075. x = 0, i = -1;
  6076. while (++i < n) {
  6077. x0 = x, j = -1;
  6078. while (++j < n) {
  6079. var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
  6080. subgroups[di + "-" + dj] = {
  6081. index: di,
  6082. subindex: dj,
  6083. startAngle: a0,
  6084. endAngle: a1,
  6085. value: v
  6086. };
  6087. }
  6088. groups[di] = {
  6089. index: di,
  6090. startAngle: x0,
  6091. endAngle: x,
  6092. value: (x - x0) / k
  6093. };
  6094. x += padding;
  6095. }
  6096. i = -1;
  6097. while (++i < n) {
  6098. j = i - 1;
  6099. while (++j < n) {
  6100. var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
  6101. if (source.value || target.value) {
  6102. chords.push(source.value < target.value ? {
  6103. source: target,
  6104. target: source
  6105. } : {
  6106. source: source,
  6107. target: target
  6108. });
  6109. }
  6110. }
  6111. }
  6112. if (sortChords) resort();
  6113. }
  6114. function resort() {
  6115. chords.sort(function(a, b) {
  6116. return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
  6117. });
  6118. }
  6119. chord.matrix = function(x) {
  6120. if (!arguments.length) return matrix;
  6121. n = (matrix = x) && matrix.length;
  6122. chords = groups = null;
  6123. return chord;
  6124. };
  6125. chord.padding = function(x) {
  6126. if (!arguments.length) return padding;
  6127. padding = x;
  6128. chords = groups = null;
  6129. return chord;
  6130. };
  6131. chord.sortGroups = function(x) {
  6132. if (!arguments.length) return sortGroups;
  6133. sortGroups = x;
  6134. chords = groups = null;
  6135. return chord;
  6136. };
  6137. chord.sortSubgroups = function(x) {
  6138. if (!arguments.length) return sortSubgroups;
  6139. sortSubgroups = x;
  6140. chords = null;
  6141. return chord;
  6142. };
  6143. chord.sortChords = function(x) {
  6144. if (!arguments.length) return sortChords;
  6145. sortChords = x;
  6146. if (chords) resort();
  6147. return chord;
  6148. };
  6149. chord.chords = function() {
  6150. if (!chords) relayout();
  6151. return chords;
  6152. };
  6153. chord.groups = function() {
  6154. if (!groups) relayout();
  6155. return groups;
  6156. };
  6157. return chord;
  6158. };
  6159. d3.layout.force = function() {
  6160. var force = {}, event = d3.dispatch("start", "tick", "end"), size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges;
  6161. function repulse(node) {
  6162. return function(quad, x1, _, x2) {
  6163. if (quad.point !== node) {
  6164. var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
  6165. if (dw * dw / theta2 < dn) {
  6166. if (dn < chargeDistance2) {
  6167. var k = quad.charge / dn;
  6168. node.px -= dx * k;
  6169. node.py -= dy * k;
  6170. }
  6171. return true;
  6172. }
  6173. if (quad.point && dn && dn < chargeDistance2) {
  6174. var k = quad.pointCharge / dn;
  6175. node.px -= dx * k;
  6176. node.py -= dy * k;
  6177. }
  6178. }
  6179. return !quad.charge;
  6180. };
  6181. }
  6182. force.tick = function() {
  6183. if ((alpha *= .99) < .005) {
  6184. event.end({
  6185. type: "end",
  6186. alpha: alpha = 0
  6187. });
  6188. return true;
  6189. }
  6190. var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
  6191. for (i = 0; i < m; ++i) {
  6192. o = links[i];
  6193. s = o.source;
  6194. t = o.target;
  6195. x = t.x - s.x;
  6196. y = t.y - s.y;
  6197. if (l = x * x + y * y) {
  6198. l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
  6199. x *= l;
  6200. y *= l;
  6201. t.x -= x * (k = s.weight / (t.weight + s.weight));
  6202. t.y -= y * k;
  6203. s.x += x * (k = 1 - k);
  6204. s.y += y * k;
  6205. }
  6206. }
  6207. if (k = alpha * gravity) {
  6208. x = size[0] / 2;
  6209. y = size[1] / 2;
  6210. i = -1;
  6211. if (k) while (++i < n) {
  6212. o = nodes[i];
  6213. o.x += (x - o.x) * k;
  6214. o.y += (y - o.y) * k;
  6215. }
  6216. }
  6217. if (charge) {
  6218. d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
  6219. i = -1;
  6220. while (++i < n) {
  6221. if (!(o = nodes[i]).fixed) {
  6222. q.visit(repulse(o));
  6223. }
  6224. }
  6225. }
  6226. i = -1;
  6227. while (++i < n) {
  6228. o = nodes[i];
  6229. if (o.fixed) {
  6230. o.x = o.px;
  6231. o.y = o.py;
  6232. } else {
  6233. o.x -= (o.px - (o.px = o.x)) * friction;
  6234. o.y -= (o.py - (o.py = o.y)) * friction;
  6235. }
  6236. }
  6237. event.tick({
  6238. type: "tick",
  6239. alpha: alpha
  6240. });
  6241. };
  6242. force.nodes = function(x) {
  6243. if (!arguments.length) return nodes;
  6244. nodes = x;
  6245. return force;
  6246. };
  6247. force.links = function(x) {
  6248. if (!arguments.length) return links;
  6249. links = x;
  6250. return force;
  6251. };
  6252. force.size = function(x) {
  6253. if (!arguments.length) return size;
  6254. size = x;
  6255. return force;
  6256. };
  6257. force.linkDistance = function(x) {
  6258. if (!arguments.length) return linkDistance;
  6259. linkDistance = typeof x === "function" ? x : +x;
  6260. return force;
  6261. };
  6262. force.distance = force.linkDistance;
  6263. force.linkStrength = function(x) {
  6264. if (!arguments.length) return linkStrength;
  6265. linkStrength = typeof x === "function" ? x : +x;
  6266. return force;
  6267. };
  6268. force.friction = function(x) {
  6269. if (!arguments.length) return friction;
  6270. friction = +x;
  6271. return force;
  6272. };
  6273. force.charge = function(x) {
  6274. if (!arguments.length) return charge;
  6275. charge = typeof x === "function" ? x : +x;
  6276. return force;
  6277. };
  6278. force.chargeDistance = function(x) {
  6279. if (!arguments.length) return Math.sqrt(chargeDistance2);
  6280. chargeDistance2 = x * x;
  6281. return force;
  6282. };
  6283. force.gravity = function(x) {
  6284. if (!arguments.length) return gravity;
  6285. gravity = +x;
  6286. return force;
  6287. };
  6288. force.theta = function(x) {
  6289. if (!arguments.length) return Math.sqrt(theta2);
  6290. theta2 = x * x;
  6291. return force;
  6292. };
  6293. force.alpha = function(x) {
  6294. if (!arguments.length) return alpha;
  6295. x = +x;
  6296. if (alpha) {
  6297. if (x > 0) alpha = x; else alpha = 0;
  6298. } else if (x > 0) {
  6299. event.start({
  6300. type: "start",
  6301. alpha: alpha = x
  6302. });
  6303. d3.timer(force.tick);
  6304. }
  6305. return force;
  6306. };
  6307. force.start = function() {
  6308. var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
  6309. for (i = 0; i < n; ++i) {
  6310. (o = nodes[i]).index = i;
  6311. o.weight = 0;
  6312. }
  6313. for (i = 0; i < m; ++i) {
  6314. o = links[i];
  6315. if (typeof o.source == "number") o.source = nodes[o.source];
  6316. if (typeof o.target == "number") o.target = nodes[o.target];
  6317. ++o.source.weight;
  6318. ++o.target.weight;
  6319. }
  6320. for (i = 0; i < n; ++i) {
  6321. o = nodes[i];
  6322. if (isNaN(o.x)) o.x = position("x", w);
  6323. if (isNaN(o.y)) o.y = position("y", h);
  6324. if (isNaN(o.px)) o.px = o.x;
  6325. if (isNaN(o.py)) o.py = o.y;
  6326. }
  6327. distances = [];
  6328. if (typeof linkDistance === "function") for (i = 0; i < m; ++i) distances[i] = +linkDistance.call(this, links[i], i); else for (i = 0; i < m; ++i) distances[i] = linkDistance;
  6329. strengths = [];
  6330. if (typeof linkStrength === "function") for (i = 0; i < m; ++i) strengths[i] = +linkStrength.call(this, links[i], i); else for (i = 0; i < m; ++i) strengths[i] = linkStrength;
  6331. charges = [];
  6332. if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i); else for (i = 0; i < n; ++i) charges[i] = charge;
  6333. function position(dimension, size) {
  6334. if (!neighbors) {
  6335. neighbors = new Array(n);
  6336. for (j = 0; j < n; ++j) {
  6337. neighbors[j] = [];
  6338. }
  6339. for (j = 0; j < m; ++j) {
  6340. var o = links[j];
  6341. neighbors[o.source.index].push(o.target);
  6342. neighbors[o.target.index].push(o.source);
  6343. }
  6344. }
  6345. var candidates = neighbors[i], j = -1, m = candidates.length, x;
  6346. while (++j < m) if (!isNaN(x = candidates[j][dimension])) return x;
  6347. return Math.random() * size;
  6348. }
  6349. return force.resume();
  6350. };
  6351. force.resume = function() {
  6352. return force.alpha(.1);
  6353. };
  6354. force.stop = function() {
  6355. return force.alpha(0);
  6356. };
  6357. force.drag = function() {
  6358. if (!drag) drag = d3.behavior.drag().origin(d3_identity).on("dragstart.force", d3_layout_forceDragstart).on("drag.force", dragmove).on("dragend.force", d3_layout_forceDragend);
  6359. if (!arguments.length) return drag;
  6360. this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
  6361. };
  6362. function dragmove(d) {
  6363. d.px = d3.event.x, d.py = d3.event.y;
  6364. force.resume();
  6365. }
  6366. return d3.rebind(force, event, "on");
  6367. };
  6368. function d3_layout_forceDragstart(d) {
  6369. d.fixed |= 2;
  6370. }
  6371. function d3_layout_forceDragend(d) {
  6372. d.fixed &= ~6;
  6373. }
  6374. function d3_layout_forceMouseover(d) {
  6375. d.fixed |= 4;
  6376. d.px = d.x, d.py = d.y;
  6377. }
  6378. function d3_layout_forceMouseout(d) {
  6379. d.fixed &= ~4;
  6380. }
  6381. function d3_layout_forceAccumulate(quad, alpha, charges) {
  6382. var cx = 0, cy = 0;
  6383. quad.charge = 0;
  6384. if (!quad.leaf) {
  6385. var nodes = quad.nodes, n = nodes.length, i = -1, c;
  6386. while (++i < n) {
  6387. c = nodes[i];
  6388. if (c == null) continue;
  6389. d3_layout_forceAccumulate(c, alpha, charges);
  6390. quad.charge += c.charge;
  6391. cx += c.charge * c.cx;
  6392. cy += c.charge * c.cy;
  6393. }
  6394. }
  6395. if (quad.point) {
  6396. if (!quad.leaf) {
  6397. quad.point.x += Math.random() - .5;
  6398. quad.point.y += Math.random() - .5;
  6399. }
  6400. var k = alpha * charges[quad.point.index];
  6401. quad.charge += quad.pointCharge = k;
  6402. cx += k * quad.point.x;
  6403. cy += k * quad.point.y;
  6404. }
  6405. quad.cx = cx / quad.charge;
  6406. quad.cy = cy / quad.charge;
  6407. }
  6408. var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
  6409. d3.layout.hierarchy = function() {
  6410. var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
  6411. function hierarchy(root) {
  6412. var stack = [ root ], nodes = [], node;
  6413. root.depth = 0;
  6414. while ((node = stack.pop()) != null) {
  6415. nodes.push(node);
  6416. if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
  6417. var n, childs, child;
  6418. while (--n >= 0) {
  6419. stack.push(child = childs[n]);
  6420. child.parent = node;
  6421. child.depth = node.depth + 1;
  6422. }
  6423. if (value) node.value = 0;
  6424. node.children = childs;
  6425. } else {
  6426. if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6427. delete node.children;
  6428. }
  6429. }
  6430. d3_layout_hierarchyVisitAfter(root, function(node) {
  6431. var childs, parent;
  6432. if (sort && (childs = node.children)) childs.sort(sort);
  6433. if (value && (parent = node.parent)) parent.value += node.value;
  6434. });
  6435. return nodes;
  6436. }
  6437. hierarchy.sort = function(x) {
  6438. if (!arguments.length) return sort;
  6439. sort = x;
  6440. return hierarchy;
  6441. };
  6442. hierarchy.children = function(x) {
  6443. if (!arguments.length) return children;
  6444. children = x;
  6445. return hierarchy;
  6446. };
  6447. hierarchy.value = function(x) {
  6448. if (!arguments.length) return value;
  6449. value = x;
  6450. return hierarchy;
  6451. };
  6452. hierarchy.revalue = function(root) {
  6453. if (value) {
  6454. d3_layout_hierarchyVisitBefore(root, function(node) {
  6455. if (node.children) node.value = 0;
  6456. });
  6457. d3_layout_hierarchyVisitAfter(root, function(node) {
  6458. var parent;
  6459. if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6460. if (parent = node.parent) parent.value += node.value;
  6461. });
  6462. }
  6463. return root;
  6464. };
  6465. return hierarchy;
  6466. };
  6467. function d3_layout_hierarchyRebind(object, hierarchy) {
  6468. d3.rebind(object, hierarchy, "sort", "children", "value");
  6469. object.nodes = object;
  6470. object.links = d3_layout_hierarchyLinks;
  6471. return object;
  6472. }
  6473. function d3_layout_hierarchyVisitBefore(node, callback) {
  6474. var nodes = [ node ];
  6475. while ((node = nodes.pop()) != null) {
  6476. callback(node);
  6477. if ((children = node.children) && (n = children.length)) {
  6478. var n, children;
  6479. while (--n >= 0) nodes.push(children[n]);
  6480. }
  6481. }
  6482. }
  6483. function d3_layout_hierarchyVisitAfter(node, callback) {
  6484. var nodes = [ node ], nodes2 = [];
  6485. while ((node = nodes.pop()) != null) {
  6486. nodes2.push(node);
  6487. if ((children = node.children) && (n = children.length)) {
  6488. var i = -1, n, children;
  6489. while (++i < n) nodes.push(children[i]);
  6490. }
  6491. }
  6492. while ((node = nodes2.pop()) != null) {
  6493. callback(node);
  6494. }
  6495. }
  6496. function d3_layout_hierarchyChildren(d) {
  6497. return d.children;
  6498. }
  6499. function d3_layout_hierarchyValue(d) {
  6500. return d.value;
  6501. }
  6502. function d3_layout_hierarchySort(a, b) {
  6503. return b.value - a.value;
  6504. }
  6505. function d3_layout_hierarchyLinks(nodes) {
  6506. return d3.merge(nodes.map(function(parent) {
  6507. return (parent.children || []).map(function(child) {
  6508. return {
  6509. source: parent,
  6510. target: child
  6511. };
  6512. });
  6513. }));
  6514. }
  6515. d3.layout.partition = function() {
  6516. var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
  6517. function position(node, x, dx, dy) {
  6518. var children = node.children;
  6519. node.x = x;
  6520. node.y = node.depth * dy;
  6521. node.dx = dx;
  6522. node.dy = dy;
  6523. if (children && (n = children.length)) {
  6524. var i = -1, n, c, d;
  6525. dx = node.value ? dx / node.value : 0;
  6526. while (++i < n) {
  6527. position(c = children[i], x, d = c.value * dx, dy);
  6528. x += d;
  6529. }
  6530. }
  6531. }
  6532. function depth(node) {
  6533. var children = node.children, d = 0;
  6534. if (children && (n = children.length)) {
  6535. var i = -1, n;
  6536. while (++i < n) d = Math.max(d, depth(children[i]));
  6537. }
  6538. return 1 + d;
  6539. }
  6540. function partition(d, i) {
  6541. var nodes = hierarchy.call(this, d, i);
  6542. position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
  6543. return nodes;
  6544. }
  6545. partition.size = function(x) {
  6546. if (!arguments.length) return size;
  6547. size = x;
  6548. return partition;
  6549. };
  6550. return d3_layout_hierarchyRebind(partition, hierarchy);
  6551. };
  6552. d3.layout.pie = function() {
  6553. var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
  6554. function pie(data) {
  6555. var n = data.length, values = data.map(function(d, i) {
  6556. return +value.call(pie, d, i);
  6557. }), a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), k = (da - n * pa) / d3.sum(values), index = d3.range(n), arcs = [], v;
  6558. if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
  6559. return values[j] - values[i];
  6560. } : function(i, j) {
  6561. return sort(data[i], data[j]);
  6562. });
  6563. index.forEach(function(i) {
  6564. arcs[i] = {
  6565. data: data[i],
  6566. value: v = values[i],
  6567. startAngle: a,
  6568. endAngle: a += v * k + pa,
  6569. padAngle: p
  6570. };
  6571. });
  6572. return arcs;
  6573. }
  6574. pie.value = function(_) {
  6575. if (!arguments.length) return value;
  6576. value = _;
  6577. return pie;
  6578. };
  6579. pie.sort = function(_) {
  6580. if (!arguments.length) return sort;
  6581. sort = _;
  6582. return pie;
  6583. };
  6584. pie.startAngle = function(_) {
  6585. if (!arguments.length) return startAngle;
  6586. startAngle = _;
  6587. return pie;
  6588. };
  6589. pie.endAngle = function(_) {
  6590. if (!arguments.length) return endAngle;
  6591. endAngle = _;
  6592. return pie;
  6593. };
  6594. pie.padAngle = function(_) {
  6595. if (!arguments.length) return padAngle;
  6596. padAngle = _;
  6597. return pie;
  6598. };
  6599. return pie;
  6600. };
  6601. var d3_layout_pieSortByValue = {};
  6602. d3.layout.stack = function() {
  6603. var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
  6604. function stack(data, index) {
  6605. if (!(n = data.length)) return data;
  6606. var series = data.map(function(d, i) {
  6607. return values.call(stack, d, i);
  6608. });
  6609. var points = series.map(function(d) {
  6610. return d.map(function(v, i) {
  6611. return [ x.call(stack, v, i), y.call(stack, v, i) ];
  6612. });
  6613. });
  6614. var orders = order.call(stack, points, index);
  6615. series = d3.permute(series, orders);
  6616. points = d3.permute(points, orders);
  6617. var offsets = offset.call(stack, points, index);
  6618. var m = series[0].length, n, i, j, o;
  6619. for (j = 0; j < m; ++j) {
  6620. out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
  6621. for (i = 1; i < n; ++i) {
  6622. out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
  6623. }
  6624. }
  6625. return data;
  6626. }
  6627. stack.values = function(x) {
  6628. if (!arguments.length) return values;
  6629. values = x;
  6630. return stack;
  6631. };
  6632. stack.order = function(x) {
  6633. if (!arguments.length) return order;
  6634. order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
  6635. return stack;
  6636. };
  6637. stack.offset = function(x) {
  6638. if (!arguments.length) return offset;
  6639. offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
  6640. return stack;
  6641. };
  6642. stack.x = function(z) {
  6643. if (!arguments.length) return x;
  6644. x = z;
  6645. return stack;
  6646. };
  6647. stack.y = function(z) {
  6648. if (!arguments.length) return y;
  6649. y = z;
  6650. return stack;
  6651. };
  6652. stack.out = function(z) {
  6653. if (!arguments.length) return out;
  6654. out = z;
  6655. return stack;
  6656. };
  6657. return stack;
  6658. };
  6659. function d3_layout_stackX(d) {
  6660. return d.x;
  6661. }
  6662. function d3_layout_stackY(d) {
  6663. return d.y;
  6664. }
  6665. function d3_layout_stackOut(d, y0, y) {
  6666. d.y0 = y0;
  6667. d.y = y;
  6668. }
  6669. var d3_layout_stackOrders = d3.map({
  6670. "inside-out": function(data) {
  6671. var n = data.length, i, j, max = data.map(d3_layout_stackMaxIndex), sums = data.map(d3_layout_stackReduceSum), index = d3.range(n).sort(function(a, b) {
  6672. return max[a] - max[b];
  6673. }), top = 0, bottom = 0, tops = [], bottoms = [];
  6674. for (i = 0; i < n; ++i) {
  6675. j = index[i];
  6676. if (top < bottom) {
  6677. top += sums[j];
  6678. tops.push(j);
  6679. } else {
  6680. bottom += sums[j];
  6681. bottoms.push(j);
  6682. }
  6683. }
  6684. return bottoms.reverse().concat(tops);
  6685. },
  6686. reverse: function(data) {
  6687. return d3.range(data.length).reverse();
  6688. },
  6689. "default": d3_layout_stackOrderDefault
  6690. });
  6691. var d3_layout_stackOffsets = d3.map({
  6692. silhouette: function(data) {
  6693. var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
  6694. for (j = 0; j < m; ++j) {
  6695. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6696. if (o > max) max = o;
  6697. sums.push(o);
  6698. }
  6699. for (j = 0; j < m; ++j) {
  6700. y0[j] = (max - sums[j]) / 2;
  6701. }
  6702. return y0;
  6703. },
  6704. wiggle: function(data) {
  6705. var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
  6706. y0[0] = o = o0 = 0;
  6707. for (j = 1; j < m; ++j) {
  6708. for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
  6709. for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
  6710. for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
  6711. s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
  6712. }
  6713. s2 += s3 * data[i][j][1];
  6714. }
  6715. y0[j] = o -= s1 ? s2 / s1 * dx : 0;
  6716. if (o < o0) o0 = o;
  6717. }
  6718. for (j = 0; j < m; ++j) y0[j] -= o0;
  6719. return y0;
  6720. },
  6721. expand: function(data) {
  6722. var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
  6723. for (j = 0; j < m; ++j) {
  6724. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6725. if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; else for (i = 0; i < n; i++) data[i][j][1] = k;
  6726. }
  6727. for (j = 0; j < m; ++j) y0[j] = 0;
  6728. return y0;
  6729. },
  6730. zero: d3_layout_stackOffsetZero
  6731. });
  6732. function d3_layout_stackOrderDefault(data) {
  6733. return d3.range(data.length);
  6734. }
  6735. function d3_layout_stackOffsetZero(data) {
  6736. var j = -1, m = data[0].length, y0 = [];
  6737. while (++j < m) y0[j] = 0;
  6738. return y0;
  6739. }
  6740. function d3_layout_stackMaxIndex(array) {
  6741. var i = 1, j = 0, v = array[0][1], k, n = array.length;
  6742. for (;i < n; ++i) {
  6743. if ((k = array[i][1]) > v) {
  6744. j = i;
  6745. v = k;
  6746. }
  6747. }
  6748. return j;
  6749. }
  6750. function d3_layout_stackReduceSum(d) {
  6751. return d.reduce(d3_layout_stackSum, 0);
  6752. }
  6753. function d3_layout_stackSum(p, d) {
  6754. return p + d[1];
  6755. }
  6756. d3.layout.histogram = function() {
  6757. var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
  6758. function histogram(data, i) {
  6759. var bins = [], values = data.map(valuer, this), range = ranger.call(this, values, i), thresholds = binner.call(this, range, values, i), bin, i = -1, n = values.length, m = thresholds.length - 1, k = frequency ? 1 : 1 / n, x;
  6760. while (++i < m) {
  6761. bin = bins[i] = [];
  6762. bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
  6763. bin.y = 0;
  6764. }
  6765. if (m > 0) {
  6766. i = -1;
  6767. while (++i < n) {
  6768. x = values[i];
  6769. if (x >= range[0] && x <= range[1]) {
  6770. bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
  6771. bin.y += k;
  6772. bin.push(data[i]);
  6773. }
  6774. }
  6775. }
  6776. return bins;
  6777. }
  6778. histogram.value = function(x) {
  6779. if (!arguments.length) return valuer;
  6780. valuer = x;
  6781. return histogram;
  6782. };
  6783. histogram.range = function(x) {
  6784. if (!arguments.length) return ranger;
  6785. ranger = d3_functor(x);
  6786. return histogram;
  6787. };
  6788. histogram.bins = function(x) {
  6789. if (!arguments.length) return binner;
  6790. binner = typeof x === "number" ? function(range) {
  6791. return d3_layout_histogramBinFixed(range, x);
  6792. } : d3_functor(x);
  6793. return histogram;
  6794. };
  6795. histogram.frequency = function(x) {
  6796. if (!arguments.length) return frequency;
  6797. frequency = !!x;
  6798. return histogram;
  6799. };
  6800. return histogram;
  6801. };
  6802. function d3_layout_histogramBinSturges(range, values) {
  6803. return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
  6804. }
  6805. function d3_layout_histogramBinFixed(range, n) {
  6806. var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
  6807. while (++x <= n) f[x] = m * x + b;
  6808. return f;
  6809. }
  6810. function d3_layout_histogramRange(values) {
  6811. return [ d3.min(values), d3.max(values) ];
  6812. }
  6813. d3.layout.pack = function() {
  6814. var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
  6815. function pack(d, i) {
  6816. var nodes = hierarchy.call(this, d, i), root = nodes[0], w = size[0], h = size[1], r = radius == null ? Math.sqrt : typeof radius === "function" ? radius : function() {
  6817. return radius;
  6818. };
  6819. root.x = root.y = 0;
  6820. d3_layout_hierarchyVisitAfter(root, function(d) {
  6821. d.r = +r(d.value);
  6822. });
  6823. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6824. if (padding) {
  6825. var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
  6826. d3_layout_hierarchyVisitAfter(root, function(d) {
  6827. d.r += dr;
  6828. });
  6829. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6830. d3_layout_hierarchyVisitAfter(root, function(d) {
  6831. d.r -= dr;
  6832. });
  6833. }
  6834. d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
  6835. return nodes;
  6836. }
  6837. pack.size = function(_) {
  6838. if (!arguments.length) return size;
  6839. size = _;
  6840. return pack;
  6841. };
  6842. pack.radius = function(_) {
  6843. if (!arguments.length) return radius;
  6844. radius = _ == null || typeof _ === "function" ? _ : +_;
  6845. return pack;
  6846. };
  6847. pack.padding = function(_) {
  6848. if (!arguments.length) return padding;
  6849. padding = +_;
  6850. return pack;
  6851. };
  6852. return d3_layout_hierarchyRebind(pack, hierarchy);
  6853. };
  6854. function d3_layout_packSort(a, b) {
  6855. return a.value - b.value;
  6856. }
  6857. function d3_layout_packInsert(a, b) {
  6858. var c = a._pack_next;
  6859. a._pack_next = b;
  6860. b._pack_prev = a;
  6861. b._pack_next = c;
  6862. c._pack_prev = b;
  6863. }
  6864. function d3_layout_packSplice(a, b) {
  6865. a._pack_next = b;
  6866. b._pack_prev = a;
  6867. }
  6868. function d3_layout_packIntersects(a, b) {
  6869. var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
  6870. return .999 * dr * dr > dx * dx + dy * dy;
  6871. }
  6872. function d3_layout_packSiblings(node) {
  6873. if (!(nodes = node.children) || !(n = nodes.length)) return;
  6874. var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
  6875. function bound(node) {
  6876. xMin = Math.min(node.x - node.r, xMin);
  6877. xMax = Math.max(node.x + node.r, xMax);
  6878. yMin = Math.min(node.y - node.r, yMin);
  6879. yMax = Math.max(node.y + node.r, yMax);
  6880. }
  6881. nodes.forEach(d3_layout_packLink);
  6882. a = nodes[0];
  6883. a.x = -a.r;
  6884. a.y = 0;
  6885. bound(a);
  6886. if (n > 1) {
  6887. b = nodes[1];
  6888. b.x = b.r;
  6889. b.y = 0;
  6890. bound(b);
  6891. if (n > 2) {
  6892. c = nodes[2];
  6893. d3_layout_packPlace(a, b, c);
  6894. bound(c);
  6895. d3_layout_packInsert(a, c);
  6896. a._pack_prev = c;
  6897. d3_layout_packInsert(c, b);
  6898. b = a._pack_next;
  6899. for (i = 3; i < n; i++) {
  6900. d3_layout_packPlace(a, b, c = nodes[i]);
  6901. var isect = 0, s1 = 1, s2 = 1;
  6902. for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
  6903. if (d3_layout_packIntersects(j, c)) {
  6904. isect = 1;
  6905. break;
  6906. }
  6907. }
  6908. if (isect == 1) {
  6909. for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
  6910. if (d3_layout_packIntersects(k, c)) {
  6911. break;
  6912. }
  6913. }
  6914. }
  6915. if (isect) {
  6916. if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
  6917. i--;
  6918. } else {
  6919. d3_layout_packInsert(a, c);
  6920. b = c;
  6921. bound(c);
  6922. }
  6923. }
  6924. }
  6925. }
  6926. var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
  6927. for (i = 0; i < n; i++) {
  6928. c = nodes[i];
  6929. c.x -= cx;
  6930. c.y -= cy;
  6931. cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
  6932. }
  6933. node.r = cr;
  6934. nodes.forEach(d3_layout_packUnlink);
  6935. }
  6936. function d3_layout_packLink(node) {
  6937. node._pack_next = node._pack_prev = node;
  6938. }
  6939. function d3_layout_packUnlink(node) {
  6940. delete node._pack_next;
  6941. delete node._pack_prev;
  6942. }
  6943. function d3_layout_packTransform(node, x, y, k) {
  6944. var children = node.children;
  6945. node.x = x += k * node.x;
  6946. node.y = y += k * node.y;
  6947. node.r *= k;
  6948. if (children) {
  6949. var i = -1, n = children.length;
  6950. while (++i < n) d3_layout_packTransform(children[i], x, y, k);
  6951. }
  6952. }
  6953. function d3_layout_packPlace(a, b, c) {
  6954. var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
  6955. if (db && (dx || dy)) {
  6956. var da = b.r + c.r, dc = dx * dx + dy * dy;
  6957. da *= da;
  6958. db *= db;
  6959. var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  6960. c.x = a.x + x * dx + y * dy;
  6961. c.y = a.y + x * dy - y * dx;
  6962. } else {
  6963. c.x = a.x + db;
  6964. c.y = a.y;
  6965. }
  6966. }
  6967. d3.layout.tree = function() {
  6968. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
  6969. function tree(d, i) {
  6970. var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
  6971. d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
  6972. d3_layout_hierarchyVisitBefore(root1, secondWalk);
  6973. if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
  6974. var left = root0, right = root0, bottom = root0;
  6975. d3_layout_hierarchyVisitBefore(root0, function(node) {
  6976. if (node.x < left.x) left = node;
  6977. if (node.x > right.x) right = node;
  6978. if (node.depth > bottom.depth) bottom = node;
  6979. });
  6980. var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
  6981. d3_layout_hierarchyVisitBefore(root0, function(node) {
  6982. node.x = (node.x + tx) * kx;
  6983. node.y = node.depth * ky;
  6984. });
  6985. }
  6986. return nodes;
  6987. }
  6988. function wrapTree(root0) {
  6989. var root1 = {
  6990. A: null,
  6991. children: [ root0 ]
  6992. }, queue = [ root1 ], node1;
  6993. while ((node1 = queue.pop()) != null) {
  6994. for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
  6995. queue.push((children[i] = child = {
  6996. _: children[i],
  6997. parent: node1,
  6998. children: (child = children[i].children) && child.slice() || [],
  6999. A: null,
  7000. a: null,
  7001. z: 0,
  7002. m: 0,
  7003. c: 0,
  7004. s: 0,
  7005. t: null,
  7006. i: i
  7007. }).a = child);
  7008. }
  7009. }
  7010. return root1.children[0];
  7011. }
  7012. function firstWalk(v) {
  7013. var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
  7014. if (children.length) {
  7015. d3_layout_treeShift(v);
  7016. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  7017. if (w) {
  7018. v.z = w.z + separation(v._, w._);
  7019. v.m = v.z - midpoint;
  7020. } else {
  7021. v.z = midpoint;
  7022. }
  7023. } else if (w) {
  7024. v.z = w.z + separation(v._, w._);
  7025. }
  7026. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  7027. }
  7028. function secondWalk(v) {
  7029. v._.x = v.z + v.parent.m;
  7030. v.m += v.parent.m;
  7031. }
  7032. function apportion(v, w, ancestor) {
  7033. if (w) {
  7034. var vip = v, vop = v, vim = w, vom = vip.parent.children[0], sip = vip.m, sop = vop.m, sim = vim.m, som = vom.m, shift;
  7035. while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
  7036. vom = d3_layout_treeLeft(vom);
  7037. vop = d3_layout_treeRight(vop);
  7038. vop.a = v;
  7039. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  7040. if (shift > 0) {
  7041. d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
  7042. sip += shift;
  7043. sop += shift;
  7044. }
  7045. sim += vim.m;
  7046. sip += vip.m;
  7047. som += vom.m;
  7048. sop += vop.m;
  7049. }
  7050. if (vim && !d3_layout_treeRight(vop)) {
  7051. vop.t = vim;
  7052. vop.m += sim - sop;
  7053. }
  7054. if (vip && !d3_layout_treeLeft(vom)) {
  7055. vom.t = vip;
  7056. vom.m += sip - som;
  7057. ancestor = v;
  7058. }
  7059. }
  7060. return ancestor;
  7061. }
  7062. function sizeNode(node) {
  7063. node.x *= size[0];
  7064. node.y = node.depth * size[1];
  7065. }
  7066. tree.separation = function(x) {
  7067. if (!arguments.length) return separation;
  7068. separation = x;
  7069. return tree;
  7070. };
  7071. tree.size = function(x) {
  7072. if (!arguments.length) return nodeSize ? null : size;
  7073. nodeSize = (size = x) == null ? sizeNode : null;
  7074. return tree;
  7075. };
  7076. tree.nodeSize = function(x) {
  7077. if (!arguments.length) return nodeSize ? size : null;
  7078. nodeSize = (size = x) == null ? null : sizeNode;
  7079. return tree;
  7080. };
  7081. return d3_layout_hierarchyRebind(tree, hierarchy);
  7082. };
  7083. function d3_layout_treeSeparation(a, b) {
  7084. return a.parent == b.parent ? 1 : 2;
  7085. }
  7086. function d3_layout_treeLeft(v) {
  7087. var children = v.children;
  7088. return children.length ? children[0] : v.t;
  7089. }
  7090. function d3_layout_treeRight(v) {
  7091. var children = v.children, n;
  7092. return (n = children.length) ? children[n - 1] : v.t;
  7093. }
  7094. function d3_layout_treeMove(wm, wp, shift) {
  7095. var change = shift / (wp.i - wm.i);
  7096. wp.c -= change;
  7097. wp.s += shift;
  7098. wm.c += change;
  7099. wp.z += shift;
  7100. wp.m += shift;
  7101. }
  7102. function d3_layout_treeShift(v) {
  7103. var shift = 0, change = 0, children = v.children, i = children.length, w;
  7104. while (--i >= 0) {
  7105. w = children[i];
  7106. w.z += shift;
  7107. w.m += shift;
  7108. shift += w.s + (change += w.c);
  7109. }
  7110. }
  7111. function d3_layout_treeAncestor(vim, v, ancestor) {
  7112. return vim.a.parent === v.parent ? vim.a : ancestor;
  7113. }
  7114. d3.layout.cluster = function() {
  7115. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
  7116. function cluster(d, i) {
  7117. var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
  7118. d3_layout_hierarchyVisitAfter(root, function(node) {
  7119. var children = node.children;
  7120. if (children && children.length) {
  7121. node.x = d3_layout_clusterX(children);
  7122. node.y = d3_layout_clusterY(children);
  7123. } else {
  7124. node.x = previousNode ? x += separation(node, previousNode) : 0;
  7125. node.y = 0;
  7126. previousNode = node;
  7127. }
  7128. });
  7129. 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;
  7130. d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
  7131. node.x = (node.x - root.x) * size[0];
  7132. node.y = (root.y - node.y) * size[1];
  7133. } : function(node) {
  7134. node.x = (node.x - x0) / (x1 - x0) * size[0];
  7135. node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
  7136. });
  7137. return nodes;
  7138. }
  7139. cluster.separation = function(x) {
  7140. if (!arguments.length) return separation;
  7141. separation = x;
  7142. return cluster;
  7143. };
  7144. cluster.size = function(x) {
  7145. if (!arguments.length) return nodeSize ? null : size;
  7146. nodeSize = (size = x) == null;
  7147. return cluster;
  7148. };
  7149. cluster.nodeSize = function(x) {
  7150. if (!arguments.length) return nodeSize ? size : null;
  7151. nodeSize = (size = x) != null;
  7152. return cluster;
  7153. };
  7154. return d3_layout_hierarchyRebind(cluster, hierarchy);
  7155. };
  7156. function d3_layout_clusterY(children) {
  7157. return 1 + d3.max(children, function(child) {
  7158. return child.y;
  7159. });
  7160. }
  7161. function d3_layout_clusterX(children) {
  7162. return children.reduce(function(x, child) {
  7163. return x + child.x;
  7164. }, 0) / children.length;
  7165. }
  7166. function d3_layout_clusterLeft(node) {
  7167. var children = node.children;
  7168. return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
  7169. }
  7170. function d3_layout_clusterRight(node) {
  7171. var children = node.children, n;
  7172. return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
  7173. }
  7174. d3.layout.treemap = function() {
  7175. var hierarchy = d3.layout.hierarchy(), round = Math.round, size = [ 1, 1 ], padding = null, pad = d3_layout_treemapPadNull, sticky = false, stickies, mode = "squarify", ratio = .5 * (1 + Math.sqrt(5));
  7176. function scale(children, k) {
  7177. var i = -1, n = children.length, child, area;
  7178. while (++i < n) {
  7179. area = (child = children[i]).value * (k < 0 ? 0 : k);
  7180. child.area = isNaN(area) || area <= 0 ? 0 : area;
  7181. }
  7182. }
  7183. function squarify(node) {
  7184. var children = node.children;
  7185. if (children && children.length) {
  7186. var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "slice" ? rect.dx : mode === "dice" ? rect.dy : mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx : Math.min(rect.dx, rect.dy), n;
  7187. scale(remaining, rect.dx * rect.dy / node.value);
  7188. row.area = 0;
  7189. while ((n = remaining.length) > 0) {
  7190. row.push(child = remaining[n - 1]);
  7191. row.area += child.area;
  7192. if (mode !== "squarify" || (score = worst(row, u)) <= best) {
  7193. remaining.pop();
  7194. best = score;
  7195. } else {
  7196. row.area -= row.pop().area;
  7197. position(row, u, rect, false);
  7198. u = Math.min(rect.dx, rect.dy);
  7199. row.length = row.area = 0;
  7200. best = Infinity;
  7201. }
  7202. }
  7203. if (row.length) {
  7204. position(row, u, rect, true);
  7205. row.length = row.area = 0;
  7206. }
  7207. children.forEach(squarify);
  7208. }
  7209. }
  7210. function stickify(node) {
  7211. var children = node.children;
  7212. if (children && children.length) {
  7213. var rect = pad(node), remaining = children.slice(), child, row = [];
  7214. scale(remaining, rect.dx * rect.dy / node.value);
  7215. row.area = 0;
  7216. while (child = remaining.pop()) {
  7217. row.push(child);
  7218. row.area += child.area;
  7219. if (child.z != null) {
  7220. position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
  7221. row.length = row.area = 0;
  7222. }
  7223. }
  7224. children.forEach(stickify);
  7225. }
  7226. }
  7227. function worst(row, u) {
  7228. var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
  7229. while (++i < n) {
  7230. if (!(r = row[i].area)) continue;
  7231. if (r < rmin) rmin = r;
  7232. if (r > rmax) rmax = r;
  7233. }
  7234. s *= s;
  7235. u *= u;
  7236. return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
  7237. }
  7238. function position(row, u, rect, flush) {
  7239. var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
  7240. if (u == rect.dx) {
  7241. if (flush || v > rect.dy) v = rect.dy;
  7242. while (++i < n) {
  7243. o = row[i];
  7244. o.x = x;
  7245. o.y = y;
  7246. o.dy = v;
  7247. x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
  7248. }
  7249. o.z = true;
  7250. o.dx += rect.x + rect.dx - x;
  7251. rect.y += v;
  7252. rect.dy -= v;
  7253. } else {
  7254. if (flush || v > rect.dx) v = rect.dx;
  7255. while (++i < n) {
  7256. o = row[i];
  7257. o.x = x;
  7258. o.y = y;
  7259. o.dx = v;
  7260. y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
  7261. }
  7262. o.z = false;
  7263. o.dy += rect.y + rect.dy - y;
  7264. rect.x += v;
  7265. rect.dx -= v;
  7266. }
  7267. }
  7268. function treemap(d) {
  7269. var nodes = stickies || hierarchy(d), root = nodes[0];
  7270. root.x = 0;
  7271. root.y = 0;
  7272. root.dx = size[0];
  7273. root.dy = size[1];
  7274. if (stickies) hierarchy.revalue(root);
  7275. scale([ root ], root.dx * root.dy / root.value);
  7276. (stickies ? stickify : squarify)(root);
  7277. if (sticky) stickies = nodes;
  7278. return nodes;
  7279. }
  7280. treemap.size = function(x) {
  7281. if (!arguments.length) return size;
  7282. size = x;
  7283. return treemap;
  7284. };
  7285. treemap.padding = function(x) {
  7286. if (!arguments.length) return padding;
  7287. function padFunction(node) {
  7288. var p = x.call(treemap, node, node.depth);
  7289. return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
  7290. }
  7291. function padConstant(node) {
  7292. return d3_layout_treemapPad(node, x);
  7293. }
  7294. var type;
  7295. pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
  7296. padConstant) : padConstant;
  7297. return treemap;
  7298. };
  7299. treemap.round = function(x) {
  7300. if (!arguments.length) return round != Number;
  7301. round = x ? Math.round : Number;
  7302. return treemap;
  7303. };
  7304. treemap.sticky = function(x) {
  7305. if (!arguments.length) return sticky;
  7306. sticky = x;
  7307. stickies = null;
  7308. return treemap;
  7309. };
  7310. treemap.ratio = function(x) {
  7311. if (!arguments.length) return ratio;
  7312. ratio = x;
  7313. return treemap;
  7314. };
  7315. treemap.mode = function(x) {
  7316. if (!arguments.length) return mode;
  7317. mode = x + "";
  7318. return treemap;
  7319. };
  7320. return d3_layout_hierarchyRebind(treemap, hierarchy);
  7321. };
  7322. function d3_layout_treemapPadNull(node) {
  7323. return {
  7324. x: node.x,
  7325. y: node.y,
  7326. dx: node.dx,
  7327. dy: node.dy
  7328. };
  7329. }
  7330. function d3_layout_treemapPad(node, padding) {
  7331. var x = node.x + padding[3], y = node.y + padding[0], dx = node.dx - padding[1] - padding[3], dy = node.dy - padding[0] - padding[2];
  7332. if (dx < 0) {
  7333. x += dx / 2;
  7334. dx = 0;
  7335. }
  7336. if (dy < 0) {
  7337. y += dy / 2;
  7338. dy = 0;
  7339. }
  7340. return {
  7341. x: x,
  7342. y: y,
  7343. dx: dx,
  7344. dy: dy
  7345. };
  7346. }
  7347. d3.random = {
  7348. normal: function(µ, σ) {
  7349. var n = arguments.length;
  7350. if (n < 2) σ = 1;
  7351. if (n < 1) µ = 0;
  7352. return function() {
  7353. var x, y, r;
  7354. do {
  7355. x = Math.random() * 2 - 1;
  7356. y = Math.random() * 2 - 1;
  7357. r = x * x + y * y;
  7358. } while (!r || r > 1);
  7359. return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
  7360. };
  7361. },
  7362. logNormal: function() {
  7363. var random = d3.random.normal.apply(d3, arguments);
  7364. return function() {
  7365. return Math.exp(random());
  7366. };
  7367. },
  7368. bates: function(m) {
  7369. var random = d3.random.irwinHall(m);
  7370. return function() {
  7371. return random() / m;
  7372. };
  7373. },
  7374. irwinHall: function(m) {
  7375. return function() {
  7376. for (var s = 0, j = 0; j < m; j++) s += Math.random();
  7377. return s;
  7378. };
  7379. }
  7380. };
  7381. d3.scale = {};
  7382. function d3_scaleExtent(domain) {
  7383. var start = domain[0], stop = domain[domain.length - 1];
  7384. return start < stop ? [ start, stop ] : [ stop, start ];
  7385. }
  7386. function d3_scaleRange(scale) {
  7387. return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
  7388. }
  7389. function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
  7390. var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
  7391. return function(x) {
  7392. return i(u(x));
  7393. };
  7394. }
  7395. function d3_scale_nice(domain, nice) {
  7396. var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
  7397. if (x1 < x0) {
  7398. dx = i0, i0 = i1, i1 = dx;
  7399. dx = x0, x0 = x1, x1 = dx;
  7400. }
  7401. domain[i0] = nice.floor(x0);
  7402. domain[i1] = nice.ceil(x1);
  7403. return domain;
  7404. }
  7405. function d3_scale_niceStep(step) {
  7406. return step ? {
  7407. floor: function(x) {
  7408. return Math.floor(x / step) * step;
  7409. },
  7410. ceil: function(x) {
  7411. return Math.ceil(x / step) * step;
  7412. }
  7413. } : d3_scale_niceIdentity;
  7414. }
  7415. var d3_scale_niceIdentity = {
  7416. floor: d3_identity,
  7417. ceil: d3_identity
  7418. };
  7419. function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
  7420. var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
  7421. if (domain[k] < domain[0]) {
  7422. domain = domain.slice().reverse();
  7423. range = range.slice().reverse();
  7424. }
  7425. while (++j <= k) {
  7426. u.push(uninterpolate(domain[j - 1], domain[j]));
  7427. i.push(interpolate(range[j - 1], range[j]));
  7428. }
  7429. return function(x) {
  7430. var j = d3.bisect(domain, x, 1, k) - 1;
  7431. return i[j](u[j](x));
  7432. };
  7433. }
  7434. d3.scale.linear = function() {
  7435. return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
  7436. };
  7437. function d3_scale_linear(domain, range, interpolate, clamp) {
  7438. var output, input;
  7439. function rescale() {
  7440. var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
  7441. output = linear(domain, range, uninterpolate, interpolate);
  7442. input = linear(range, domain, uninterpolate, d3_interpolate);
  7443. return scale;
  7444. }
  7445. function scale(x) {
  7446. return output(x);
  7447. }
  7448. scale.invert = function(y) {
  7449. return input(y);
  7450. };
  7451. scale.domain = function(x) {
  7452. if (!arguments.length) return domain;
  7453. domain = x.map(Number);
  7454. return rescale();
  7455. };
  7456. scale.range = function(x) {
  7457. if (!arguments.length) return range;
  7458. range = x;
  7459. return rescale();
  7460. };
  7461. scale.rangeRound = function(x) {
  7462. return scale.range(x).interpolate(d3_interpolateRound);
  7463. };
  7464. scale.clamp = function(x) {
  7465. if (!arguments.length) return clamp;
  7466. clamp = x;
  7467. return rescale();
  7468. };
  7469. scale.interpolate = function(x) {
  7470. if (!arguments.length) return interpolate;
  7471. interpolate = x;
  7472. return rescale();
  7473. };
  7474. scale.ticks = function(m) {
  7475. return d3_scale_linearTicks(domain, m);
  7476. };
  7477. scale.tickFormat = function(m, format) {
  7478. return d3_scale_linearTickFormat(domain, m, format);
  7479. };
  7480. scale.nice = function(m) {
  7481. d3_scale_linearNice(domain, m);
  7482. return rescale();
  7483. };
  7484. scale.copy = function() {
  7485. return d3_scale_linear(domain, range, interpolate, clamp);
  7486. };
  7487. return rescale();
  7488. }
  7489. function d3_scale_linearRebind(scale, linear) {
  7490. return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
  7491. }
  7492. function d3_scale_linearNice(domain, m) {
  7493. return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
  7494. }
  7495. function d3_scale_linearTickRange(domain, m) {
  7496. if (m == null) m = 10;
  7497. 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;
  7498. if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
  7499. extent[0] = Math.ceil(extent[0] / step) * step;
  7500. extent[1] = Math.floor(extent[1] / step) * step + step * .5;
  7501. extent[2] = step;
  7502. return extent;
  7503. }
  7504. function d3_scale_linearTicks(domain, m) {
  7505. return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
  7506. }
  7507. function d3_scale_linearTickFormat(domain, m, format) {
  7508. var range = d3_scale_linearTickRange(domain, m);
  7509. if (format) {
  7510. var match = d3_format_re.exec(format);
  7511. match.shift();
  7512. if (match[8] === "s") {
  7513. var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
  7514. if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
  7515. match[8] = "f";
  7516. format = d3.format(match.join(""));
  7517. return function(d) {
  7518. return format(prefix.scale(d)) + prefix.symbol;
  7519. };
  7520. }
  7521. if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
  7522. format = match.join("");
  7523. } else {
  7524. format = ",." + d3_scale_linearPrecision(range[2]) + "f";
  7525. }
  7526. return d3.format(format);
  7527. }
  7528. var d3_scale_linearFormatSignificant = {
  7529. s: 1,
  7530. g: 1,
  7531. p: 1,
  7532. r: 1,
  7533. e: 1
  7534. };
  7535. function d3_scale_linearPrecision(value) {
  7536. return -Math.floor(Math.log(value) / Math.LN10 + .01);
  7537. }
  7538. function d3_scale_linearFormatPrecision(type, range) {
  7539. var p = d3_scale_linearPrecision(range[2]);
  7540. return type in d3_scale_linearFormatSignificant ? Math.abs(p - d3_scale_linearPrecision(Math.max(abs(range[0]), abs(range[1])))) + +(type !== "e") : p - (type === "%") * 2;
  7541. }
  7542. d3.scale.log = function() {
  7543. return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
  7544. };
  7545. function d3_scale_log(linear, base, positive, domain) {
  7546. function log(x) {
  7547. return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
  7548. }
  7549. function pow(x) {
  7550. return positive ? Math.pow(base, x) : -Math.pow(base, -x);
  7551. }
  7552. function scale(x) {
  7553. return linear(log(x));
  7554. }
  7555. scale.invert = function(x) {
  7556. return pow(linear.invert(x));
  7557. };
  7558. scale.domain = function(x) {
  7559. if (!arguments.length) return domain;
  7560. positive = x[0] >= 0;
  7561. linear.domain((domain = x.map(Number)).map(log));
  7562. return scale;
  7563. };
  7564. scale.base = function(_) {
  7565. if (!arguments.length) return base;
  7566. base = +_;
  7567. linear.domain(domain.map(log));
  7568. return scale;
  7569. };
  7570. scale.nice = function() {
  7571. var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
  7572. linear.domain(niced);
  7573. domain = niced.map(pow);
  7574. return scale;
  7575. };
  7576. scale.ticks = function() {
  7577. var extent = d3_scaleExtent(domain), ticks = [], u = extent[0], v = extent[1], i = Math.floor(log(u)), j = Math.ceil(log(v)), n = base % 1 ? 2 : base;
  7578. if (isFinite(j - i)) {
  7579. if (positive) {
  7580. for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
  7581. ticks.push(pow(i));
  7582. } else {
  7583. ticks.push(pow(i));
  7584. for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
  7585. }
  7586. for (i = 0; ticks[i] < u; i++) {}
  7587. for (j = ticks.length; ticks[j - 1] > v; j--) {}
  7588. ticks = ticks.slice(i, j);
  7589. }
  7590. return ticks;
  7591. };
  7592. scale.tickFormat = function(n, format) {
  7593. if (!arguments.length) return d3_scale_logFormat;
  7594. if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
  7595. var k = Math.max(.1, n / scale.ticks().length), f = positive ? (e = 1e-12, Math.ceil) : (e = -1e-12,
  7596. Math.floor), e;
  7597. return function(d) {
  7598. return d / pow(f(log(d) + e)) <= k ? format(d) : "";
  7599. };
  7600. };
  7601. scale.copy = function() {
  7602. return d3_scale_log(linear.copy(), base, positive, domain);
  7603. };
  7604. return d3_scale_linearRebind(scale, linear);
  7605. }
  7606. var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
  7607. floor: function(x) {
  7608. return -Math.ceil(-x);
  7609. },
  7610. ceil: function(x) {
  7611. return -Math.floor(-x);
  7612. }
  7613. };
  7614. d3.scale.pow = function() {
  7615. return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
  7616. };
  7617. function d3_scale_pow(linear, exponent, domain) {
  7618. var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
  7619. function scale(x) {
  7620. return linear(powp(x));
  7621. }
  7622. scale.invert = function(x) {
  7623. return powb(linear.invert(x));
  7624. };
  7625. scale.domain = function(x) {
  7626. if (!arguments.length) return domain;
  7627. linear.domain((domain = x.map(Number)).map(powp));
  7628. return scale;
  7629. };
  7630. scale.ticks = function(m) {
  7631. return d3_scale_linearTicks(domain, m);
  7632. };
  7633. scale.tickFormat = function(m, format) {
  7634. return d3_scale_linearTickFormat(domain, m, format);
  7635. };
  7636. scale.nice = function(m) {
  7637. return scale.domain(d3_scale_linearNice(domain, m));
  7638. };
  7639. scale.exponent = function(x) {
  7640. if (!arguments.length) return exponent;
  7641. powp = d3_scale_powPow(exponent = x);
  7642. powb = d3_scale_powPow(1 / exponent);
  7643. linear.domain(domain.map(powp));
  7644. return scale;
  7645. };
  7646. scale.copy = function() {
  7647. return d3_scale_pow(linear.copy(), exponent, domain);
  7648. };
  7649. return d3_scale_linearRebind(scale, linear);
  7650. }
  7651. function d3_scale_powPow(e) {
  7652. return function(x) {
  7653. return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
  7654. };
  7655. }
  7656. d3.scale.sqrt = function() {
  7657. return d3.scale.pow().exponent(.5);
  7658. };
  7659. d3.scale.ordinal = function() {
  7660. return d3_scale_ordinal([], {
  7661. t: "range",
  7662. a: [ [] ]
  7663. });
  7664. };
  7665. function d3_scale_ordinal(domain, ranger) {
  7666. var index, range, rangeBand;
  7667. function scale(x) {
  7668. return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
  7669. }
  7670. function steps(start, step) {
  7671. return d3.range(domain.length).map(function(i) {
  7672. return start + step * i;
  7673. });
  7674. }
  7675. scale.domain = function(x) {
  7676. if (!arguments.length) return domain;
  7677. domain = [];
  7678. index = new d3_Map();
  7679. var i = -1, n = x.length, xi;
  7680. while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
  7681. return scale[ranger.t].apply(scale, ranger.a);
  7682. };
  7683. scale.range = function(x) {
  7684. if (!arguments.length) return range;
  7685. range = x;
  7686. rangeBand = 0;
  7687. ranger = {
  7688. t: "range",
  7689. a: arguments
  7690. };
  7691. return scale;
  7692. };
  7693. scale.rangePoints = function(x, padding) {
  7694. if (arguments.length < 2) padding = 0;
  7695. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
  7696. 0) : (stop - start) / (domain.length - 1 + padding);
  7697. range = steps(start + step * padding / 2, step);
  7698. rangeBand = 0;
  7699. ranger = {
  7700. t: "rangePoints",
  7701. a: arguments
  7702. };
  7703. return scale;
  7704. };
  7705. scale.rangeRoundPoints = function(x, padding) {
  7706. if (arguments.length < 2) padding = 0;
  7707. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
  7708. 0) : (stop - start) / (domain.length - 1 + padding) | 0;
  7709. range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
  7710. rangeBand = 0;
  7711. ranger = {
  7712. t: "rangeRoundPoints",
  7713. a: arguments
  7714. };
  7715. return scale;
  7716. };
  7717. scale.rangeBands = function(x, padding, outerPadding) {
  7718. if (arguments.length < 2) padding = 0;
  7719. if (arguments.length < 3) outerPadding = padding;
  7720. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
  7721. range = steps(start + step * outerPadding, step);
  7722. if (reverse) range.reverse();
  7723. rangeBand = step * (1 - padding);
  7724. ranger = {
  7725. t: "rangeBands",
  7726. a: arguments
  7727. };
  7728. return scale;
  7729. };
  7730. scale.rangeRoundBands = function(x, padding, outerPadding) {
  7731. if (arguments.length < 2) padding = 0;
  7732. if (arguments.length < 3) outerPadding = padding;
  7733. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
  7734. range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
  7735. if (reverse) range.reverse();
  7736. rangeBand = Math.round(step * (1 - padding));
  7737. ranger = {
  7738. t: "rangeRoundBands",
  7739. a: arguments
  7740. };
  7741. return scale;
  7742. };
  7743. scale.rangeBand = function() {
  7744. return rangeBand;
  7745. };
  7746. scale.rangeExtent = function() {
  7747. return d3_scaleExtent(ranger.a[0]);
  7748. };
  7749. scale.copy = function() {
  7750. return d3_scale_ordinal(domain, ranger);
  7751. };
  7752. return scale.domain(domain);
  7753. }
  7754. d3.scale.category10 = function() {
  7755. return d3.scale.ordinal().range(d3_category10);
  7756. };
  7757. d3.scale.category20 = function() {
  7758. return d3.scale.ordinal().range(d3_category20);
  7759. };
  7760. d3.scale.category20b = function() {
  7761. return d3.scale.ordinal().range(d3_category20b);
  7762. };
  7763. d3.scale.category20c = function() {
  7764. return d3.scale.ordinal().range(d3_category20c);
  7765. };
  7766. var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
  7767. var d3_category20 = [ 2062260, 11454440, 16744206, 16759672, 2924588, 10018698, 14034728, 16750742, 9725885, 12955861, 9197131, 12885140, 14907330, 16234194, 8355711, 13092807, 12369186, 14408589, 1556175, 10410725 ].map(d3_rgbString);
  7768. var d3_category20b = [ 3750777, 5395619, 7040719, 10264286, 6519097, 9216594, 11915115, 13556636, 9202993, 12426809, 15186514, 15190932, 8666169, 11356490, 14049643, 15177372, 8077683, 10834324, 13528509, 14589654 ].map(d3_rgbString);
  7769. var d3_category20c = [ 3244733, 7057110, 10406625, 13032431, 15095053, 16616764, 16625259, 16634018, 3253076, 7652470, 10607003, 13101504, 7695281, 10394312, 12369372, 14342891, 6513507, 9868950, 12434877, 14277081 ].map(d3_rgbString);
  7770. d3.scale.quantile = function() {
  7771. return d3_scale_quantile([], []);
  7772. };
  7773. function d3_scale_quantile(domain, range) {
  7774. var thresholds;
  7775. function rescale() {
  7776. var k = 0, q = range.length;
  7777. thresholds = [];
  7778. while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
  7779. return scale;
  7780. }
  7781. function scale(x) {
  7782. if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
  7783. }
  7784. scale.domain = function(x) {
  7785. if (!arguments.length) return domain;
  7786. domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
  7787. return rescale();
  7788. };
  7789. scale.range = function(x) {
  7790. if (!arguments.length) return range;
  7791. range = x;
  7792. return rescale();
  7793. };
  7794. scale.quantiles = function() {
  7795. return thresholds;
  7796. };
  7797. scale.invertExtent = function(y) {
  7798. y = range.indexOf(y);
  7799. return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
  7800. };
  7801. scale.copy = function() {
  7802. return d3_scale_quantile(domain, range);
  7803. };
  7804. return rescale();
  7805. }
  7806. d3.scale.quantize = function() {
  7807. return d3_scale_quantize(0, 1, [ 0, 1 ]);
  7808. };
  7809. function d3_scale_quantize(x0, x1, range) {
  7810. var kx, i;
  7811. function scale(x) {
  7812. return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
  7813. }
  7814. function rescale() {
  7815. kx = range.length / (x1 - x0);
  7816. i = range.length - 1;
  7817. return scale;
  7818. }
  7819. scale.domain = function(x) {
  7820. if (!arguments.length) return [ x0, x1 ];
  7821. x0 = +x[0];
  7822. x1 = +x[x.length - 1];
  7823. return rescale();
  7824. };
  7825. scale.range = function(x) {
  7826. if (!arguments.length) return range;
  7827. range = x;
  7828. return rescale();
  7829. };
  7830. scale.invertExtent = function(y) {
  7831. y = range.indexOf(y);
  7832. y = y < 0 ? NaN : y / kx + x0;
  7833. return [ y, y + 1 / kx ];
  7834. };
  7835. scale.copy = function() {
  7836. return d3_scale_quantize(x0, x1, range);
  7837. };
  7838. return rescale();
  7839. }
  7840. d3.scale.threshold = function() {
  7841. return d3_scale_threshold([ .5 ], [ 0, 1 ]);
  7842. };
  7843. function d3_scale_threshold(domain, range) {
  7844. function scale(x) {
  7845. if (x <= x) return range[d3.bisect(domain, x)];
  7846. }
  7847. scale.domain = function(_) {
  7848. if (!arguments.length) return domain;
  7849. domain = _;
  7850. return scale;
  7851. };
  7852. scale.range = function(_) {
  7853. if (!arguments.length) return range;
  7854. range = _;
  7855. return scale;
  7856. };
  7857. scale.invertExtent = function(y) {
  7858. y = range.indexOf(y);
  7859. return [ domain[y - 1], domain[y] ];
  7860. };
  7861. scale.copy = function() {
  7862. return d3_scale_threshold(domain, range);
  7863. };
  7864. return scale;
  7865. }
  7866. d3.scale.identity = function() {
  7867. return d3_scale_identity([ 0, 1 ]);
  7868. };
  7869. function d3_scale_identity(domain) {
  7870. function identity(x) {
  7871. return +x;
  7872. }
  7873. identity.invert = identity;
  7874. identity.domain = identity.range = function(x) {
  7875. if (!arguments.length) return domain;
  7876. domain = x.map(identity);
  7877. return identity;
  7878. };
  7879. identity.ticks = function(m) {
  7880. return d3_scale_linearTicks(domain, m);
  7881. };
  7882. identity.tickFormat = function(m, format) {
  7883. return d3_scale_linearTickFormat(domain, m, format);
  7884. };
  7885. identity.copy = function() {
  7886. return d3_scale_identity(domain);
  7887. };
  7888. return identity;
  7889. }
  7890. d3.svg = {};
  7891. function d3_zero() {
  7892. return 0;
  7893. }
  7894. d3.svg.arc = function() {
  7895. var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, cornerRadius = d3_zero, padRadius = d3_svg_arcAuto, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle, padAngle = d3_svg_arcPadAngle;
  7896. function arc() {
  7897. var r0 = Math.max(0, +innerRadius.apply(this, arguments)), r1 = Math.max(0, +outerRadius.apply(this, arguments)), a0 = startAngle.apply(this, arguments) - halfπ, a1 = endAngle.apply(this, arguments) - halfπ, da = Math.abs(a1 - a0), cw = a0 > a1 ? 0 : 1;
  7898. if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
  7899. if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
  7900. var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
  7901. if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
  7902. rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
  7903. if (!cw) p1 *= -1;
  7904. if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
  7905. if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
  7906. }
  7907. if (r1) {
  7908. x0 = r1 * Math.cos(a0 + p1);
  7909. y0 = r1 * Math.sin(a0 + p1);
  7910. x1 = r1 * Math.cos(a1 - p1);
  7911. y1 = r1 * Math.sin(a1 - p1);
  7912. var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
  7913. if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
  7914. var h1 = (a0 + a1) / 2;
  7915. x0 = r1 * Math.cos(h1);
  7916. y0 = r1 * Math.sin(h1);
  7917. x1 = y1 = null;
  7918. }
  7919. } else {
  7920. x0 = y0 = 0;
  7921. }
  7922. if (r0) {
  7923. x2 = r0 * Math.cos(a1 - p0);
  7924. y2 = r0 * Math.sin(a1 - p0);
  7925. x3 = r0 * Math.cos(a0 + p0);
  7926. y3 = r0 * Math.sin(a0 + p0);
  7927. var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
  7928. if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
  7929. var h0 = (a0 + a1) / 2;
  7930. x2 = r0 * Math.cos(h0);
  7931. y2 = r0 * Math.sin(h0);
  7932. x3 = y3 = null;
  7933. }
  7934. } else {
  7935. x2 = y2 = 0;
  7936. }
  7937. if ((rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
  7938. cr = r0 < r1 ^ cw ? 0 : 1;
  7939. var oc = x3 == null ? [ x2, y2 ] : x1 == null ? [ x0, y0 ] : d3_geom_polygonIntersect([ x0, y0 ], [ x3, y3 ], [ x1, y1 ], [ x2, y2 ]), ax = x0 - oc[0], ay = y0 - oc[1], bx = x1 - oc[0], by = y1 - oc[1], kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2), lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
  7940. if (x1 != null) {
  7941. var rc1 = Math.min(rc, (r1 - lc) / (kc + 1)), t30 = d3_svg_arcCornerTangents(x3 == null ? [ x2, y2 ] : [ x3, y3 ], [ x0, y0 ], r1, rc1, cw), t12 = d3_svg_arcCornerTangents([ x1, y1 ], [ x2, y2 ], r1, rc1, cw);
  7942. if (rc === rc1) {
  7943. path.push("M", t30[0], "A", rc1, ",", rc1, " 0 0,", cr, " ", t30[1], "A", r1, ",", r1, " 0 ", 1 - cw ^ d3_svg_arcSweep(t30[1][0], t30[1][1], t12[1][0], t12[1][1]), ",", cw, " ", t12[1], "A", rc1, ",", rc1, " 0 0,", cr, " ", t12[0]);
  7944. } else {
  7945. path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
  7946. }
  7947. } else {
  7948. path.push("M", x0, ",", y0);
  7949. }
  7950. if (x3 != null) {
  7951. var rc0 = Math.min(rc, (r0 - lc) / (kc - 1)), t03 = d3_svg_arcCornerTangents([ x0, y0 ], [ x3, y3 ], r0, -rc0, cw), t21 = d3_svg_arcCornerTangents([ x2, y2 ], x1 == null ? [ x0, y0 ] : [ x1, y1 ], r0, -rc0, cw);
  7952. if (rc === rc0) {
  7953. path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t21[1], "A", r0, ",", r0, " 0 ", cw ^ d3_svg_arcSweep(t21[1][0], t21[1][1], t03[1][0], t03[1][1]), ",", 1 - cw, " ", t03[1], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
  7954. } else {
  7955. path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
  7956. }
  7957. } else {
  7958. path.push("L", x2, ",", y2);
  7959. }
  7960. } else {
  7961. path.push("M", x0, ",", y0);
  7962. if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
  7963. path.push("L", x2, ",", y2);
  7964. if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
  7965. }
  7966. path.push("Z");
  7967. return path.join("");
  7968. }
  7969. function circleSegment(r1, cw) {
  7970. return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
  7971. }
  7972. arc.innerRadius = function(v) {
  7973. if (!arguments.length) return innerRadius;
  7974. innerRadius = d3_functor(v);
  7975. return arc;
  7976. };
  7977. arc.outerRadius = function(v) {
  7978. if (!arguments.length) return outerRadius;
  7979. outerRadius = d3_functor(v);
  7980. return arc;
  7981. };
  7982. arc.cornerRadius = function(v) {
  7983. if (!arguments.length) return cornerRadius;
  7984. cornerRadius = d3_functor(v);
  7985. return arc;
  7986. };
  7987. arc.padRadius = function(v) {
  7988. if (!arguments.length) return padRadius;
  7989. padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
  7990. return arc;
  7991. };
  7992. arc.startAngle = function(v) {
  7993. if (!arguments.length) return startAngle;
  7994. startAngle = d3_functor(v);
  7995. return arc;
  7996. };
  7997. arc.endAngle = function(v) {
  7998. if (!arguments.length) return endAngle;
  7999. endAngle = d3_functor(v);
  8000. return arc;
  8001. };
  8002. arc.padAngle = function(v) {
  8003. if (!arguments.length) return padAngle;
  8004. padAngle = d3_functor(v);
  8005. return arc;
  8006. };
  8007. arc.centroid = function() {
  8008. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
  8009. return [ Math.cos(a) * r, Math.sin(a) * r ];
  8010. };
  8011. return arc;
  8012. };
  8013. var d3_svg_arcAuto = "auto";
  8014. function d3_svg_arcInnerRadius(d) {
  8015. return d.innerRadius;
  8016. }
  8017. function d3_svg_arcOuterRadius(d) {
  8018. return d.outerRadius;
  8019. }
  8020. function d3_svg_arcStartAngle(d) {
  8021. return d.startAngle;
  8022. }
  8023. function d3_svg_arcEndAngle(d) {
  8024. return d.endAngle;
  8025. }
  8026. function d3_svg_arcPadAngle(d) {
  8027. return d && d.padAngle;
  8028. }
  8029. function d3_svg_arcSweep(x0, y0, x1, y1) {
  8030. return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
  8031. }
  8032. function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
  8033. var x01 = p0[0] - p1[0], y01 = p0[1] - p1[1], lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01), ox = lo * y01, oy = -lo * x01, x1 = p0[0] + ox, y1 = p0[1] + oy, x2 = p1[0] + ox, y2 = p1[1] + oy, x3 = (x1 + x2) / 2, y3 = (y1 + y2) / 2, dx = x2 - x1, dy = y2 - y1, d2 = dx * dx + dy * dy, r = r1 - rc, D = x1 * y2 - x2 * y1, d = (dy < 0 ? -1 : 1) * Math.sqrt(r * r * d2 - D * D), cx0 = (D * dy - dx * d) / d2, cy0 = (-D * dx - dy * d) / d2, cx1 = (D * dy + dx * d) / d2, cy1 = (-D * dx + dy * d) / d2, dx0 = cx0 - x3, dy0 = cy0 - y3, dx1 = cx1 - x3, dy1 = cy1 - y3;
  8034. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  8035. return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
  8036. }
  8037. function d3_svg_line(projection) {
  8038. var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
  8039. function line(data) {
  8040. var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
  8041. function segment() {
  8042. segments.push("M", interpolate(projection(points), tension));
  8043. }
  8044. while (++i < n) {
  8045. if (defined.call(this, d = data[i], i)) {
  8046. points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
  8047. } else if (points.length) {
  8048. segment();
  8049. points = [];
  8050. }
  8051. }
  8052. if (points.length) segment();
  8053. return segments.length ? segments.join("") : null;
  8054. }
  8055. line.x = function(_) {
  8056. if (!arguments.length) return x;
  8057. x = _;
  8058. return line;
  8059. };
  8060. line.y = function(_) {
  8061. if (!arguments.length) return y;
  8062. y = _;
  8063. return line;
  8064. };
  8065. line.defined = function(_) {
  8066. if (!arguments.length) return defined;
  8067. defined = _;
  8068. return line;
  8069. };
  8070. line.interpolate = function(_) {
  8071. if (!arguments.length) return interpolateKey;
  8072. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8073. return line;
  8074. };
  8075. line.tension = function(_) {
  8076. if (!arguments.length) return tension;
  8077. tension = _;
  8078. return line;
  8079. };
  8080. return line;
  8081. }
  8082. d3.svg.line = function() {
  8083. return d3_svg_line(d3_identity);
  8084. };
  8085. var d3_svg_lineInterpolators = d3.map({
  8086. linear: d3_svg_lineLinear,
  8087. "linear-closed": d3_svg_lineLinearClosed,
  8088. step: d3_svg_lineStep,
  8089. "step-before": d3_svg_lineStepBefore,
  8090. "step-after": d3_svg_lineStepAfter,
  8091. basis: d3_svg_lineBasis,
  8092. "basis-open": d3_svg_lineBasisOpen,
  8093. "basis-closed": d3_svg_lineBasisClosed,
  8094. bundle: d3_svg_lineBundle,
  8095. cardinal: d3_svg_lineCardinal,
  8096. "cardinal-open": d3_svg_lineCardinalOpen,
  8097. "cardinal-closed": d3_svg_lineCardinalClosed,
  8098. monotone: d3_svg_lineMonotone
  8099. });
  8100. d3_svg_lineInterpolators.forEach(function(key, value) {
  8101. value.key = key;
  8102. value.closed = /-closed$/.test(key);
  8103. });
  8104. function d3_svg_lineLinear(points) {
  8105. return points.join("L");
  8106. }
  8107. function d3_svg_lineLinearClosed(points) {
  8108. return d3_svg_lineLinear(points) + "Z";
  8109. }
  8110. function d3_svg_lineStep(points) {
  8111. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8112. while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
  8113. if (n > 1) path.push("H", p[0]);
  8114. return path.join("");
  8115. }
  8116. function d3_svg_lineStepBefore(points) {
  8117. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8118. while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
  8119. return path.join("");
  8120. }
  8121. function d3_svg_lineStepAfter(points) {
  8122. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8123. while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
  8124. return path.join("");
  8125. }
  8126. function d3_svg_lineCardinalOpen(points, tension) {
  8127. return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
  8128. }
  8129. function d3_svg_lineCardinalClosed(points, tension) {
  8130. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
  8131. points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
  8132. }
  8133. function d3_svg_lineCardinal(points, tension) {
  8134. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
  8135. }
  8136. function d3_svg_lineHermite(points, tangents) {
  8137. if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
  8138. return d3_svg_lineLinear(points);
  8139. }
  8140. var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
  8141. if (quad) {
  8142. path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
  8143. p0 = points[1];
  8144. pi = 2;
  8145. }
  8146. if (tangents.length > 1) {
  8147. t = tangents[1];
  8148. p = points[pi];
  8149. pi++;
  8150. path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  8151. for (var i = 2; i < tangents.length; i++, pi++) {
  8152. p = points[pi];
  8153. t = tangents[i];
  8154. path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  8155. }
  8156. }
  8157. if (quad) {
  8158. var lp = points[pi];
  8159. path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
  8160. }
  8161. return path;
  8162. }
  8163. function d3_svg_lineCardinalTangents(points, tension) {
  8164. var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
  8165. while (++i < n) {
  8166. p0 = p1;
  8167. p1 = p2;
  8168. p2 = points[i];
  8169. tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
  8170. }
  8171. return tangents;
  8172. }
  8173. function d3_svg_lineBasis(points) {
  8174. if (points.length < 3) return d3_svg_lineLinear(points);
  8175. var i = 1, n = points.length, pi = points[0], x0 = pi[0], y0 = pi[1], px = [ x0, x0, x0, (pi = points[1])[0] ], py = [ y0, y0, y0, pi[1] ], path = [ x0, ",", y0, "L", d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  8176. points.push(points[n - 1]);
  8177. while (++i <= n) {
  8178. pi = points[i];
  8179. px.shift();
  8180. px.push(pi[0]);
  8181. py.shift();
  8182. py.push(pi[1]);
  8183. d3_svg_lineBasisBezier(path, px, py);
  8184. }
  8185. points.pop();
  8186. path.push("L", pi);
  8187. return path.join("");
  8188. }
  8189. function d3_svg_lineBasisOpen(points) {
  8190. if (points.length < 4) return d3_svg_lineLinear(points);
  8191. var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
  8192. while (++i < 3) {
  8193. pi = points[i];
  8194. px.push(pi[0]);
  8195. py.push(pi[1]);
  8196. }
  8197. path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
  8198. --i;
  8199. while (++i < n) {
  8200. pi = points[i];
  8201. px.shift();
  8202. px.push(pi[0]);
  8203. py.shift();
  8204. py.push(pi[1]);
  8205. d3_svg_lineBasisBezier(path, px, py);
  8206. }
  8207. return path.join("");
  8208. }
  8209. function d3_svg_lineBasisClosed(points) {
  8210. var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
  8211. while (++i < 4) {
  8212. pi = points[i % n];
  8213. px.push(pi[0]);
  8214. py.push(pi[1]);
  8215. }
  8216. path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  8217. --i;
  8218. while (++i < m) {
  8219. pi = points[i % n];
  8220. px.shift();
  8221. px.push(pi[0]);
  8222. py.shift();
  8223. py.push(pi[1]);
  8224. d3_svg_lineBasisBezier(path, px, py);
  8225. }
  8226. return path.join("");
  8227. }
  8228. function d3_svg_lineBundle(points, tension) {
  8229. var n = points.length - 1;
  8230. if (n) {
  8231. var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
  8232. while (++i <= n) {
  8233. p = points[i];
  8234. t = i / n;
  8235. p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
  8236. p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
  8237. }
  8238. }
  8239. return d3_svg_lineBasis(points);
  8240. }
  8241. function d3_svg_lineDot4(a, b) {
  8242. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
  8243. }
  8244. var d3_svg_lineBasisBezier1 = [ 0, 2 / 3, 1 / 3, 0 ], d3_svg_lineBasisBezier2 = [ 0, 1 / 3, 2 / 3, 0 ], d3_svg_lineBasisBezier3 = [ 0, 1 / 6, 2 / 3, 1 / 6 ];
  8245. function d3_svg_lineBasisBezier(path, x, y) {
  8246. path.push("C", d3_svg_lineDot4(d3_svg_lineBasisBezier1, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier1, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, y));
  8247. }
  8248. function d3_svg_lineSlope(p0, p1) {
  8249. return (p1[1] - p0[1]) / (p1[0] - p0[0]);
  8250. }
  8251. function d3_svg_lineFiniteDifferences(points) {
  8252. var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
  8253. while (++i < j) {
  8254. m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
  8255. }
  8256. m[i] = d;
  8257. return m;
  8258. }
  8259. function d3_svg_lineMonotoneTangents(points) {
  8260. var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
  8261. while (++i < j) {
  8262. d = d3_svg_lineSlope(points[i], points[i + 1]);
  8263. if (abs(d) < ε) {
  8264. m[i] = m[i + 1] = 0;
  8265. } else {
  8266. a = m[i] / d;
  8267. b = m[i + 1] / d;
  8268. s = a * a + b * b;
  8269. if (s > 9) {
  8270. s = d * 3 / Math.sqrt(s);
  8271. m[i] = s * a;
  8272. m[i + 1] = s * b;
  8273. }
  8274. }
  8275. }
  8276. i = -1;
  8277. while (++i <= j) {
  8278. s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
  8279. tangents.push([ s || 0, m[i] * s || 0 ]);
  8280. }
  8281. return tangents;
  8282. }
  8283. function d3_svg_lineMonotone(points) {
  8284. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
  8285. }
  8286. d3.svg.line.radial = function() {
  8287. var line = d3_svg_line(d3_svg_lineRadial);
  8288. line.radius = line.x, delete line.x;
  8289. line.angle = line.y, delete line.y;
  8290. return line;
  8291. };
  8292. function d3_svg_lineRadial(points) {
  8293. var point, i = -1, n = points.length, r, a;
  8294. while (++i < n) {
  8295. point = points[i];
  8296. r = point[0];
  8297. a = point[1] - halfπ;
  8298. point[0] = r * Math.cos(a);
  8299. point[1] = r * Math.sin(a);
  8300. }
  8301. return points;
  8302. }
  8303. function d3_svg_area(projection) {
  8304. var x0 = d3_geom_pointX, x1 = d3_geom_pointX, y0 = 0, y1 = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
  8305. function area(data) {
  8306. var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
  8307. return x;
  8308. } : d3_functor(x1), fy1 = y0 === y1 ? function() {
  8309. return y;
  8310. } : d3_functor(y1), x, y;
  8311. function segment() {
  8312. segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
  8313. }
  8314. while (++i < n) {
  8315. if (defined.call(this, d = data[i], i)) {
  8316. points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
  8317. points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
  8318. } else if (points0.length) {
  8319. segment();
  8320. points0 = [];
  8321. points1 = [];
  8322. }
  8323. }
  8324. if (points0.length) segment();
  8325. return segments.length ? segments.join("") : null;
  8326. }
  8327. area.x = function(_) {
  8328. if (!arguments.length) return x1;
  8329. x0 = x1 = _;
  8330. return area;
  8331. };
  8332. area.x0 = function(_) {
  8333. if (!arguments.length) return x0;
  8334. x0 = _;
  8335. return area;
  8336. };
  8337. area.x1 = function(_) {
  8338. if (!arguments.length) return x1;
  8339. x1 = _;
  8340. return area;
  8341. };
  8342. area.y = function(_) {
  8343. if (!arguments.length) return y1;
  8344. y0 = y1 = _;
  8345. return area;
  8346. };
  8347. area.y0 = function(_) {
  8348. if (!arguments.length) return y0;
  8349. y0 = _;
  8350. return area;
  8351. };
  8352. area.y1 = function(_) {
  8353. if (!arguments.length) return y1;
  8354. y1 = _;
  8355. return area;
  8356. };
  8357. area.defined = function(_) {
  8358. if (!arguments.length) return defined;
  8359. defined = _;
  8360. return area;
  8361. };
  8362. area.interpolate = function(_) {
  8363. if (!arguments.length) return interpolateKey;
  8364. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8365. interpolateReverse = interpolate.reverse || interpolate;
  8366. L = interpolate.closed ? "M" : "L";
  8367. return area;
  8368. };
  8369. area.tension = function(_) {
  8370. if (!arguments.length) return tension;
  8371. tension = _;
  8372. return area;
  8373. };
  8374. return area;
  8375. }
  8376. d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
  8377. d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
  8378. d3.svg.area = function() {
  8379. return d3_svg_area(d3_identity);
  8380. };
  8381. d3.svg.area.radial = function() {
  8382. var area = d3_svg_area(d3_svg_lineRadial);
  8383. area.radius = area.x, delete area.x;
  8384. area.innerRadius = area.x0, delete area.x0;
  8385. area.outerRadius = area.x1, delete area.x1;
  8386. area.angle = area.y, delete area.y;
  8387. area.startAngle = area.y0, delete area.y0;
  8388. area.endAngle = area.y1, delete area.y1;
  8389. return area;
  8390. };
  8391. d3.svg.chord = function() {
  8392. var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
  8393. function chord(d, i) {
  8394. var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
  8395. return "M" + s.p0 + arc(s.r, s.p1, s.a1 - s.a0) + (equals(s, t) ? curve(s.r, s.p1, s.r, s.p0) : curve(s.r, s.p1, t.r, t.p0) + arc(t.r, t.p1, t.a1 - t.a0) + curve(t.r, t.p1, s.r, s.p0)) + "Z";
  8396. }
  8397. function subgroup(self, f, d, i) {
  8398. var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) - halfπ, a1 = endAngle.call(self, subgroup, i) - halfπ;
  8399. return {
  8400. r: r,
  8401. a0: a0,
  8402. a1: a1,
  8403. p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
  8404. p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
  8405. };
  8406. }
  8407. function equals(a, b) {
  8408. return a.a0 == b.a0 && a.a1 == b.a1;
  8409. }
  8410. function arc(r, p, a) {
  8411. return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
  8412. }
  8413. function curve(r0, p0, r1, p1) {
  8414. return "Q 0,0 " + p1;
  8415. }
  8416. chord.radius = function(v) {
  8417. if (!arguments.length) return radius;
  8418. radius = d3_functor(v);
  8419. return chord;
  8420. };
  8421. chord.source = function(v) {
  8422. if (!arguments.length) return source;
  8423. source = d3_functor(v);
  8424. return chord;
  8425. };
  8426. chord.target = function(v) {
  8427. if (!arguments.length) return target;
  8428. target = d3_functor(v);
  8429. return chord;
  8430. };
  8431. chord.startAngle = function(v) {
  8432. if (!arguments.length) return startAngle;
  8433. startAngle = d3_functor(v);
  8434. return chord;
  8435. };
  8436. chord.endAngle = function(v) {
  8437. if (!arguments.length) return endAngle;
  8438. endAngle = d3_functor(v);
  8439. return chord;
  8440. };
  8441. return chord;
  8442. };
  8443. function d3_svg_chordRadius(d) {
  8444. return d.radius;
  8445. }
  8446. d3.svg.diagonal = function() {
  8447. var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
  8448. function diagonal(d, i) {
  8449. var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
  8450. x: p0.x,
  8451. y: m
  8452. }, {
  8453. x: p3.x,
  8454. y: m
  8455. }, p3 ];
  8456. p = p.map(projection);
  8457. return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
  8458. }
  8459. diagonal.source = function(x) {
  8460. if (!arguments.length) return source;
  8461. source = d3_functor(x);
  8462. return diagonal;
  8463. };
  8464. diagonal.target = function(x) {
  8465. if (!arguments.length) return target;
  8466. target = d3_functor(x);
  8467. return diagonal;
  8468. };
  8469. diagonal.projection = function(x) {
  8470. if (!arguments.length) return projection;
  8471. projection = x;
  8472. return diagonal;
  8473. };
  8474. return diagonal;
  8475. };
  8476. function d3_svg_diagonalProjection(d) {
  8477. return [ d.x, d.y ];
  8478. }
  8479. d3.svg.diagonal.radial = function() {
  8480. var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
  8481. diagonal.projection = function(x) {
  8482. return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
  8483. };
  8484. return diagonal;
  8485. };
  8486. function d3_svg_diagonalRadialProjection(projection) {
  8487. return function() {
  8488. var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
  8489. return [ r * Math.cos(a), r * Math.sin(a) ];
  8490. };
  8491. }
  8492. d3.svg.symbol = function() {
  8493. var type = d3_svg_symbolType, size = d3_svg_symbolSize;
  8494. function symbol(d, i) {
  8495. return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
  8496. }
  8497. symbol.type = function(x) {
  8498. if (!arguments.length) return type;
  8499. type = d3_functor(x);
  8500. return symbol;
  8501. };
  8502. symbol.size = function(x) {
  8503. if (!arguments.length) return size;
  8504. size = d3_functor(x);
  8505. return symbol;
  8506. };
  8507. return symbol;
  8508. };
  8509. function d3_svg_symbolSize() {
  8510. return 64;
  8511. }
  8512. function d3_svg_symbolType() {
  8513. return "circle";
  8514. }
  8515. function d3_svg_symbolCircle(size) {
  8516. var r = Math.sqrt(size / π);
  8517. return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
  8518. }
  8519. var d3_svg_symbols = d3.map({
  8520. circle: d3_svg_symbolCircle,
  8521. cross: function(size) {
  8522. var r = Math.sqrt(size / 5) / 2;
  8523. return "M" + -3 * r + "," + -r + "H" + -r + "V" + -3 * r + "H" + r + "V" + -r + "H" + 3 * r + "V" + r + "H" + r + "V" + 3 * r + "H" + -r + "V" + r + "H" + -3 * r + "Z";
  8524. },
  8525. diamond: function(size) {
  8526. var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
  8527. return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
  8528. },
  8529. square: function(size) {
  8530. var r = Math.sqrt(size) / 2;
  8531. return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
  8532. },
  8533. "triangle-down": function(size) {
  8534. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8535. return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
  8536. },
  8537. "triangle-up": function(size) {
  8538. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8539. return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
  8540. }
  8541. });
  8542. d3.svg.symbolTypes = d3_svg_symbols.keys();
  8543. var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
  8544. d3_selectionPrototype.transition = function(name) {
  8545. var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
  8546. time: Date.now(),
  8547. ease: d3_ease_cubicInOut,
  8548. delay: 0,
  8549. duration: 250
  8550. };
  8551. for (var j = -1, m = this.length; ++j < m; ) {
  8552. subgroups.push(subgroup = []);
  8553. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8554. if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
  8555. subgroup.push(node);
  8556. }
  8557. }
  8558. return d3_transition(subgroups, ns, id);
  8559. };
  8560. d3_selectionPrototype.interrupt = function(name) {
  8561. return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
  8562. };
  8563. var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
  8564. function d3_selection_interruptNS(ns) {
  8565. return function() {
  8566. var lock, active;
  8567. if ((lock = this[ns]) && (active = lock[lock.active])) {
  8568. if (--lock.count) {
  8569. delete lock[lock.active];
  8570. lock.active += .5;
  8571. } else {
  8572. delete this[ns];
  8573. }
  8574. active.event && active.event.interrupt.call(this, this.__data__, active.index);
  8575. }
  8576. };
  8577. }
  8578. function d3_transition(groups, ns, id) {
  8579. d3_subclass(groups, d3_transitionPrototype);
  8580. groups.namespace = ns;
  8581. groups.id = id;
  8582. return groups;
  8583. }
  8584. var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
  8585. d3_transitionPrototype.call = d3_selectionPrototype.call;
  8586. d3_transitionPrototype.empty = d3_selectionPrototype.empty;
  8587. d3_transitionPrototype.node = d3_selectionPrototype.node;
  8588. d3_transitionPrototype.size = d3_selectionPrototype.size;
  8589. d3.transition = function(selection, name) {
  8590. return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3_selectionRoot.transition(selection);
  8591. };
  8592. d3.transition.prototype = d3_transitionPrototype;
  8593. d3_transitionPrototype.select = function(selector) {
  8594. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
  8595. selector = d3_selection_selector(selector);
  8596. for (var j = -1, m = this.length; ++j < m; ) {
  8597. subgroups.push(subgroup = []);
  8598. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8599. if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
  8600. if ("__data__" in node) subnode.__data__ = node.__data__;
  8601. d3_transitionNode(subnode, i, ns, id, node[ns][id]);
  8602. subgroup.push(subnode);
  8603. } else {
  8604. subgroup.push(null);
  8605. }
  8606. }
  8607. }
  8608. return d3_transition(subgroups, ns, id);
  8609. };
  8610. d3_transitionPrototype.selectAll = function(selector) {
  8611. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
  8612. selector = d3_selection_selectorAll(selector);
  8613. for (var j = -1, m = this.length; ++j < m; ) {
  8614. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8615. if (node = group[i]) {
  8616. transition = node[ns][id];
  8617. subnodes = selector.call(node, node.__data__, i, j);
  8618. subgroups.push(subgroup = []);
  8619. for (var k = -1, o = subnodes.length; ++k < o; ) {
  8620. if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
  8621. subgroup.push(subnode);
  8622. }
  8623. }
  8624. }
  8625. }
  8626. return d3_transition(subgroups, ns, id);
  8627. };
  8628. d3_transitionPrototype.filter = function(filter) {
  8629. var subgroups = [], subgroup, group, node;
  8630. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  8631. for (var j = 0, m = this.length; j < m; j++) {
  8632. subgroups.push(subgroup = []);
  8633. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8634. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  8635. subgroup.push(node);
  8636. }
  8637. }
  8638. }
  8639. return d3_transition(subgroups, this.namespace, this.id);
  8640. };
  8641. d3_transitionPrototype.tween = function(name, tween) {
  8642. var id = this.id, ns = this.namespace;
  8643. if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
  8644. return d3_selection_each(this, tween == null ? function(node) {
  8645. node[ns][id].tween.remove(name);
  8646. } : function(node) {
  8647. node[ns][id].tween.set(name, tween);
  8648. });
  8649. };
  8650. function d3_transition_tween(groups, name, value, tween) {
  8651. var id = groups.id, ns = groups.namespace;
  8652. return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
  8653. node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
  8654. } : (value = tween(value), function(node) {
  8655. node[ns][id].tween.set(name, value);
  8656. }));
  8657. }
  8658. d3_transitionPrototype.attr = function(nameNS, value) {
  8659. if (arguments.length < 2) {
  8660. for (value in nameNS) this.attr(value, nameNS[value]);
  8661. return this;
  8662. }
  8663. var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
  8664. function attrNull() {
  8665. this.removeAttribute(name);
  8666. }
  8667. function attrNullNS() {
  8668. this.removeAttributeNS(name.space, name.local);
  8669. }
  8670. function attrTween(b) {
  8671. return b == null ? attrNull : (b += "", function() {
  8672. var a = this.getAttribute(name), i;
  8673. return a !== b && (i = interpolate(a, b), function(t) {
  8674. this.setAttribute(name, i(t));
  8675. });
  8676. });
  8677. }
  8678. function attrTweenNS(b) {
  8679. return b == null ? attrNullNS : (b += "", function() {
  8680. var a = this.getAttributeNS(name.space, name.local), i;
  8681. return a !== b && (i = interpolate(a, b), function(t) {
  8682. this.setAttributeNS(name.space, name.local, i(t));
  8683. });
  8684. });
  8685. }
  8686. return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
  8687. };
  8688. d3_transitionPrototype.attrTween = function(nameNS, tween) {
  8689. var name = d3.ns.qualify(nameNS);
  8690. function attrTween(d, i) {
  8691. var f = tween.call(this, d, i, this.getAttribute(name));
  8692. return f && function(t) {
  8693. this.setAttribute(name, f(t));
  8694. };
  8695. }
  8696. function attrTweenNS(d, i) {
  8697. var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
  8698. return f && function(t) {
  8699. this.setAttributeNS(name.space, name.local, f(t));
  8700. };
  8701. }
  8702. return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
  8703. };
  8704. d3_transitionPrototype.style = function(name, value, priority) {
  8705. var n = arguments.length;
  8706. if (n < 3) {
  8707. if (typeof name !== "string") {
  8708. if (n < 2) value = "";
  8709. for (priority in name) this.style(priority, name[priority], value);
  8710. return this;
  8711. }
  8712. priority = "";
  8713. }
  8714. function styleNull() {
  8715. this.style.removeProperty(name);
  8716. }
  8717. function styleString(b) {
  8718. return b == null ? styleNull : (b += "", function() {
  8719. var a = d3_window.getComputedStyle(this, null).getPropertyValue(name), i;
  8720. return a !== b && (i = d3_interpolate(a, b), function(t) {
  8721. this.style.setProperty(name, i(t), priority);
  8722. });
  8723. });
  8724. }
  8725. return d3_transition_tween(this, "style." + name, value, styleString);
  8726. };
  8727. d3_transitionPrototype.styleTween = function(name, tween, priority) {
  8728. if (arguments.length < 3) priority = "";
  8729. function styleTween(d, i) {
  8730. var f = tween.call(this, d, i, d3_window.getComputedStyle(this, null).getPropertyValue(name));
  8731. return f && function(t) {
  8732. this.style.setProperty(name, f(t), priority);
  8733. };
  8734. }
  8735. return this.tween("style." + name, styleTween);
  8736. };
  8737. d3_transitionPrototype.text = function(value) {
  8738. return d3_transition_tween(this, "text", value, d3_transition_text);
  8739. };
  8740. function d3_transition_text(b) {
  8741. if (b == null) b = "";
  8742. return function() {
  8743. this.textContent = b;
  8744. };
  8745. }
  8746. d3_transitionPrototype.remove = function() {
  8747. var ns = this.namespace;
  8748. return this.each("end.transition", function() {
  8749. var p;
  8750. if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
  8751. });
  8752. };
  8753. d3_transitionPrototype.ease = function(value) {
  8754. var id = this.id, ns = this.namespace;
  8755. if (arguments.length < 1) return this.node()[ns][id].ease;
  8756. if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
  8757. return d3_selection_each(this, function(node) {
  8758. node[ns][id].ease = value;
  8759. });
  8760. };
  8761. d3_transitionPrototype.delay = function(value) {
  8762. var id = this.id, ns = this.namespace;
  8763. if (arguments.length < 1) return this.node()[ns][id].delay;
  8764. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8765. node[ns][id].delay = +value.call(node, node.__data__, i, j);
  8766. } : (value = +value, function(node) {
  8767. node[ns][id].delay = value;
  8768. }));
  8769. };
  8770. d3_transitionPrototype.duration = function(value) {
  8771. var id = this.id, ns = this.namespace;
  8772. if (arguments.length < 1) return this.node()[ns][id].duration;
  8773. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8774. node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
  8775. } : (value = Math.max(1, value), function(node) {
  8776. node[ns][id].duration = value;
  8777. }));
  8778. };
  8779. d3_transitionPrototype.each = function(type, listener) {
  8780. var id = this.id, ns = this.namespace;
  8781. if (arguments.length < 2) {
  8782. var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
  8783. try {
  8784. d3_transitionInheritId = id;
  8785. d3_selection_each(this, function(node, i, j) {
  8786. d3_transitionInherit = node[ns][id];
  8787. type.call(node, node.__data__, i, j);
  8788. });
  8789. } finally {
  8790. d3_transitionInherit = inherit;
  8791. d3_transitionInheritId = inheritId;
  8792. }
  8793. } else {
  8794. d3_selection_each(this, function(node) {
  8795. var transition = node[ns][id];
  8796. (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
  8797. });
  8798. }
  8799. return this;
  8800. };
  8801. d3_transitionPrototype.transition = function() {
  8802. var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
  8803. for (var j = 0, m = this.length; j < m; j++) {
  8804. subgroups.push(subgroup = []);
  8805. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8806. if (node = group[i]) {
  8807. transition = node[ns][id0];
  8808. d3_transitionNode(node, i, ns, id1, {
  8809. time: transition.time,
  8810. ease: transition.ease,
  8811. delay: transition.delay + transition.duration,
  8812. duration: transition.duration
  8813. });
  8814. }
  8815. subgroup.push(node);
  8816. }
  8817. }
  8818. return d3_transition(subgroups, ns, id1);
  8819. };
  8820. function d3_transitionNamespace(name) {
  8821. return name == null ? "__transition__" : "__transition_" + name + "__";
  8822. }
  8823. function d3_transitionNode(node, i, ns, id, inherit) {
  8824. var lock = node[ns] || (node[ns] = {
  8825. active: 0,
  8826. count: 0
  8827. }), transition = lock[id];
  8828. if (!transition) {
  8829. var time = inherit.time;
  8830. transition = lock[id] = {
  8831. tween: new d3_Map(),
  8832. time: time,
  8833. delay: inherit.delay,
  8834. duration: inherit.duration,
  8835. ease: inherit.ease,
  8836. index: i
  8837. };
  8838. inherit = null;
  8839. ++lock.count;
  8840. d3.timer(function(elapsed) {
  8841. var delay = transition.delay, duration, ease, timer = d3_timer_active, tweened = [];
  8842. timer.t = delay + time;
  8843. if (delay <= elapsed) return start(elapsed - delay);
  8844. timer.c = start;
  8845. function start(elapsed) {
  8846. if (lock.active > id) return stop();
  8847. var active = lock[lock.active];
  8848. if (active) {
  8849. --lock.count;
  8850. delete lock[lock.active];
  8851. active.event && active.event.interrupt.call(node, node.__data__, active.index);
  8852. }
  8853. lock.active = id;
  8854. transition.event && transition.event.start.call(node, node.__data__, i);
  8855. transition.tween.forEach(function(key, value) {
  8856. if (value = value.call(node, node.__data__, i)) {
  8857. tweened.push(value);
  8858. }
  8859. });
  8860. ease = transition.ease;
  8861. duration = transition.duration;
  8862. d3.timer(function() {
  8863. timer.c = tick(elapsed || 1) ? d3_true : tick;
  8864. return 1;
  8865. }, 0, time);
  8866. }
  8867. function tick(elapsed) {
  8868. if (lock.active !== id) return 1;
  8869. var t = elapsed / duration, e = ease(t), n = tweened.length;
  8870. while (n > 0) {
  8871. tweened[--n].call(node, e);
  8872. }
  8873. if (t >= 1) {
  8874. transition.event && transition.event.end.call(node, node.__data__, i);
  8875. return stop();
  8876. }
  8877. }
  8878. function stop() {
  8879. if (--lock.count) delete lock[id]; else delete node[ns];
  8880. return 1;
  8881. }
  8882. }, 0, time);
  8883. }
  8884. }
  8885. d3.svg.axis = function() {
  8886. var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
  8887. function axis(g) {
  8888. g.each(function() {
  8889. var g = d3.select(this);
  8890. var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
  8891. var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick.order()).style("opacity", 1), tickSpacing = Math.max(innerTickSize, 0) + tickPadding, tickTransform;
  8892. var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
  8893. d3.transition(path));
  8894. tickEnter.append("line");
  8895. tickEnter.append("text");
  8896. var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text"), sign = orient === "top" || orient === "left" ? -1 : 1, x1, x2, y1, y2;
  8897. if (orient === "bottom" || orient === "top") {
  8898. tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
  8899. text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
  8900. pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
  8901. } else {
  8902. tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
  8903. text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
  8904. pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
  8905. }
  8906. lineEnter.attr(y2, sign * innerTickSize);
  8907. textEnter.attr(y1, sign * tickSpacing);
  8908. lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
  8909. textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
  8910. if (scale1.rangeBand) {
  8911. var x = scale1, dx = x.rangeBand() / 2;
  8912. scale0 = scale1 = function(d) {
  8913. return x(d) + dx;
  8914. };
  8915. } else if (scale0.rangeBand) {
  8916. scale0 = scale1;
  8917. } else {
  8918. tickExit.call(tickTransform, scale1, scale0);
  8919. }
  8920. tickEnter.call(tickTransform, scale0, scale1);
  8921. tickUpdate.call(tickTransform, scale1, scale1);
  8922. });
  8923. }
  8924. axis.scale = function(x) {
  8925. if (!arguments.length) return scale;
  8926. scale = x;
  8927. return axis;
  8928. };
  8929. axis.orient = function(x) {
  8930. if (!arguments.length) return orient;
  8931. orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
  8932. return axis;
  8933. };
  8934. axis.ticks = function() {
  8935. if (!arguments.length) return tickArguments_;
  8936. tickArguments_ = arguments;
  8937. return axis;
  8938. };
  8939. axis.tickValues = function(x) {
  8940. if (!arguments.length) return tickValues;
  8941. tickValues = x;
  8942. return axis;
  8943. };
  8944. axis.tickFormat = function(x) {
  8945. if (!arguments.length) return tickFormat_;
  8946. tickFormat_ = x;
  8947. return axis;
  8948. };
  8949. axis.tickSize = function(x) {
  8950. var n = arguments.length;
  8951. if (!n) return innerTickSize;
  8952. innerTickSize = +x;
  8953. outerTickSize = +arguments[n - 1];
  8954. return axis;
  8955. };
  8956. axis.innerTickSize = function(x) {
  8957. if (!arguments.length) return innerTickSize;
  8958. innerTickSize = +x;
  8959. return axis;
  8960. };
  8961. axis.outerTickSize = function(x) {
  8962. if (!arguments.length) return outerTickSize;
  8963. outerTickSize = +x;
  8964. return axis;
  8965. };
  8966. axis.tickPadding = function(x) {
  8967. if (!arguments.length) return tickPadding;
  8968. tickPadding = +x;
  8969. return axis;
  8970. };
  8971. axis.tickSubdivide = function() {
  8972. return arguments.length && axis;
  8973. };
  8974. return axis;
  8975. };
  8976. var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
  8977. top: 1,
  8978. right: 1,
  8979. bottom: 1,
  8980. left: 1
  8981. };
  8982. function d3_svg_axisX(selection, x0, x1) {
  8983. selection.attr("transform", function(d) {
  8984. var v0 = x0(d);
  8985. return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
  8986. });
  8987. }
  8988. function d3_svg_axisY(selection, y0, y1) {
  8989. selection.attr("transform", function(d) {
  8990. var v0 = y0(d);
  8991. return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
  8992. });
  8993. }
  8994. d3.svg.brush = function() {
  8995. var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, xExtent = [ 0, 0 ], yExtent = [ 0, 0 ], xExtentDomain, yExtentDomain, xClamp = true, yClamp = true, resizes = d3_svg_brushResizes[0];
  8996. function brush(g) {
  8997. g.each(function() {
  8998. var g = d3.select(this).style("pointer-events", "all").style("-webkit-tap-highlight-color", "rgba(0,0,0,0)").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart);
  8999. var background = g.selectAll(".background").data([ 0 ]);
  9000. background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
  9001. g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
  9002. var resize = g.selectAll(".resize").data(resizes, d3_identity);
  9003. resize.exit().remove();
  9004. resize.enter().append("g").attr("class", function(d) {
  9005. return "resize " + d;
  9006. }).style("cursor", function(d) {
  9007. return d3_svg_brushCursor[d];
  9008. }).append("rect").attr("x", function(d) {
  9009. return /[ew]$/.test(d) ? -3 : null;
  9010. }).attr("y", function(d) {
  9011. return /^[ns]/.test(d) ? -3 : null;
  9012. }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
  9013. resize.style("display", brush.empty() ? "none" : null);
  9014. var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
  9015. if (x) {
  9016. range = d3_scaleRange(x);
  9017. backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
  9018. redrawX(gUpdate);
  9019. }
  9020. if (y) {
  9021. range = d3_scaleRange(y);
  9022. backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
  9023. redrawY(gUpdate);
  9024. }
  9025. redraw(gUpdate);
  9026. });
  9027. }
  9028. brush.event = function(g) {
  9029. g.each(function() {
  9030. var event_ = event.of(this, arguments), extent1 = {
  9031. x: xExtent,
  9032. y: yExtent,
  9033. i: xExtentDomain,
  9034. j: yExtentDomain
  9035. }, extent0 = this.__chart__ || extent1;
  9036. this.__chart__ = extent1;
  9037. if (d3_transitionInheritId) {
  9038. d3.select(this).transition().each("start.brush", function() {
  9039. xExtentDomain = extent0.i;
  9040. yExtentDomain = extent0.j;
  9041. xExtent = extent0.x;
  9042. yExtent = extent0.y;
  9043. event_({
  9044. type: "brushstart"
  9045. });
  9046. }).tween("brush:brush", function() {
  9047. var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
  9048. xExtentDomain = yExtentDomain = null;
  9049. return function(t) {
  9050. xExtent = extent1.x = xi(t);
  9051. yExtent = extent1.y = yi(t);
  9052. event_({
  9053. type: "brush",
  9054. mode: "resize"
  9055. });
  9056. };
  9057. }).each("end.brush", function() {
  9058. xExtentDomain = extent1.i;
  9059. yExtentDomain = extent1.j;
  9060. event_({
  9061. type: "brush",
  9062. mode: "resize"
  9063. });
  9064. event_({
  9065. type: "brushend"
  9066. });
  9067. });
  9068. } else {
  9069. event_({
  9070. type: "brushstart"
  9071. });
  9072. event_({
  9073. type: "brush",
  9074. mode: "resize"
  9075. });
  9076. event_({
  9077. type: "brushend"
  9078. });
  9079. }
  9080. });
  9081. };
  9082. function redraw(g) {
  9083. g.selectAll(".resize").attr("transform", function(d) {
  9084. return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
  9085. });
  9086. }
  9087. function redrawX(g) {
  9088. g.select(".extent").attr("x", xExtent[0]);
  9089. g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
  9090. }
  9091. function redrawY(g) {
  9092. g.select(".extent").attr("y", yExtent[0]);
  9093. g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
  9094. }
  9095. function brushstart() {
  9096. var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), dragRestore = d3_event_dragSuppress(), center, origin = d3.mouse(target), offset;
  9097. var w = d3.select(d3_window).on("keydown.brush", keydown).on("keyup.brush", keyup);
  9098. if (d3.event.changedTouches) {
  9099. w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
  9100. } else {
  9101. w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
  9102. }
  9103. g.interrupt().selectAll("*").interrupt();
  9104. if (dragging) {
  9105. origin[0] = xExtent[0] - origin[0];
  9106. origin[1] = yExtent[0] - origin[1];
  9107. } else if (resizing) {
  9108. var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
  9109. offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
  9110. origin[0] = xExtent[ex];
  9111. origin[1] = yExtent[ey];
  9112. } else if (d3.event.altKey) center = origin.slice();
  9113. g.style("pointer-events", "none").selectAll(".resize").style("display", null);
  9114. d3.select("body").style("cursor", eventTarget.style("cursor"));
  9115. event_({
  9116. type: "brushstart"
  9117. });
  9118. brushmove();
  9119. function keydown() {
  9120. if (d3.event.keyCode == 32) {
  9121. if (!dragging) {
  9122. center = null;
  9123. origin[0] -= xExtent[1];
  9124. origin[1] -= yExtent[1];
  9125. dragging = 2;
  9126. }
  9127. d3_eventPreventDefault();
  9128. }
  9129. }
  9130. function keyup() {
  9131. if (d3.event.keyCode == 32 && dragging == 2) {
  9132. origin[0] += xExtent[1];
  9133. origin[1] += yExtent[1];
  9134. dragging = 0;
  9135. d3_eventPreventDefault();
  9136. }
  9137. }
  9138. function brushmove() {
  9139. var point = d3.mouse(target), moved = false;
  9140. if (offset) {
  9141. point[0] += offset[0];
  9142. point[1] += offset[1];
  9143. }
  9144. if (!dragging) {
  9145. if (d3.event.altKey) {
  9146. if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
  9147. origin[0] = xExtent[+(point[0] < center[0])];
  9148. origin[1] = yExtent[+(point[1] < center[1])];
  9149. } else center = null;
  9150. }
  9151. if (resizingX && move1(point, x, 0)) {
  9152. redrawX(g);
  9153. moved = true;
  9154. }
  9155. if (resizingY && move1(point, y, 1)) {
  9156. redrawY(g);
  9157. moved = true;
  9158. }
  9159. if (moved) {
  9160. redraw(g);
  9161. event_({
  9162. type: "brush",
  9163. mode: dragging ? "move" : "resize"
  9164. });
  9165. }
  9166. }
  9167. function move1(point, scale, i) {
  9168. var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], extent = i ? yExtent : xExtent, size = extent[1] - extent[0], min, max;
  9169. if (dragging) {
  9170. r0 -= position;
  9171. r1 -= size + position;
  9172. }
  9173. min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
  9174. if (dragging) {
  9175. max = (min += position) + size;
  9176. } else {
  9177. if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
  9178. if (position < min) {
  9179. max = min;
  9180. min = position;
  9181. } else {
  9182. max = position;
  9183. }
  9184. }
  9185. if (extent[0] != min || extent[1] != max) {
  9186. if (i) yExtentDomain = null; else xExtentDomain = null;
  9187. extent[0] = min;
  9188. extent[1] = max;
  9189. return true;
  9190. }
  9191. }
  9192. function brushend() {
  9193. brushmove();
  9194. g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
  9195. d3.select("body").style("cursor", null);
  9196. w.on("mousemove.brush", null).on("mouseup.brush", null).on("touchmove.brush", null).on("touchend.brush", null).on("keydown.brush", null).on("keyup.brush", null);
  9197. dragRestore();
  9198. event_({
  9199. type: "brushend"
  9200. });
  9201. }
  9202. }
  9203. brush.x = function(z) {
  9204. if (!arguments.length) return x;
  9205. x = z;
  9206. resizes = d3_svg_brushResizes[!x << 1 | !y];
  9207. return brush;
  9208. };
  9209. brush.y = function(z) {
  9210. if (!arguments.length) return y;
  9211. y = z;
  9212. resizes = d3_svg_brushResizes[!x << 1 | !y];
  9213. return brush;
  9214. };
  9215. brush.clamp = function(z) {
  9216. if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
  9217. if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
  9218. return brush;
  9219. };
  9220. brush.extent = function(z) {
  9221. var x0, x1, y0, y1, t;
  9222. if (!arguments.length) {
  9223. if (x) {
  9224. if (xExtentDomain) {
  9225. x0 = xExtentDomain[0], x1 = xExtentDomain[1];
  9226. } else {
  9227. x0 = xExtent[0], x1 = xExtent[1];
  9228. if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
  9229. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  9230. }
  9231. }
  9232. if (y) {
  9233. if (yExtentDomain) {
  9234. y0 = yExtentDomain[0], y1 = yExtentDomain[1];
  9235. } else {
  9236. y0 = yExtent[0], y1 = yExtent[1];
  9237. if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
  9238. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9239. }
  9240. }
  9241. return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
  9242. }
  9243. if (x) {
  9244. x0 = z[0], x1 = z[1];
  9245. if (y) x0 = x0[0], x1 = x1[0];
  9246. xExtentDomain = [ x0, x1 ];
  9247. if (x.invert) x0 = x(x0), x1 = x(x1);
  9248. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  9249. if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
  9250. }
  9251. if (y) {
  9252. y0 = z[0], y1 = z[1];
  9253. if (x) y0 = y0[1], y1 = y1[1];
  9254. yExtentDomain = [ y0, y1 ];
  9255. if (y.invert) y0 = y(y0), y1 = y(y1);
  9256. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9257. if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
  9258. }
  9259. return brush;
  9260. };
  9261. brush.clear = function() {
  9262. if (!brush.empty()) {
  9263. xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
  9264. xExtentDomain = yExtentDomain = null;
  9265. }
  9266. return brush;
  9267. };
  9268. brush.empty = function() {
  9269. return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
  9270. };
  9271. return d3.rebind(brush, event, "on");
  9272. };
  9273. var d3_svg_brushCursor = {
  9274. n: "ns-resize",
  9275. e: "ew-resize",
  9276. s: "ns-resize",
  9277. w: "ew-resize",
  9278. nw: "nwse-resize",
  9279. ne: "nesw-resize",
  9280. se: "nwse-resize",
  9281. sw: "nesw-resize"
  9282. };
  9283. var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
  9284. var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
  9285. var d3_time_formatUtc = d3_time_format.utc;
  9286. var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
  9287. d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
  9288. function d3_time_formatIsoNative(date) {
  9289. return date.toISOString();
  9290. }
  9291. d3_time_formatIsoNative.parse = function(string) {
  9292. var date = new Date(string);
  9293. return isNaN(date) ? null : date;
  9294. };
  9295. d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
  9296. d3_time.second = d3_time_interval(function(date) {
  9297. return new d3_date(Math.floor(date / 1e3) * 1e3);
  9298. }, function(date, offset) {
  9299. date.setTime(date.getTime() + Math.floor(offset) * 1e3);
  9300. }, function(date) {
  9301. return date.getSeconds();
  9302. });
  9303. d3_time.seconds = d3_time.second.range;
  9304. d3_time.seconds.utc = d3_time.second.utc.range;
  9305. d3_time.minute = d3_time_interval(function(date) {
  9306. return new d3_date(Math.floor(date / 6e4) * 6e4);
  9307. }, function(date, offset) {
  9308. date.setTime(date.getTime() + Math.floor(offset) * 6e4);
  9309. }, function(date) {
  9310. return date.getMinutes();
  9311. });
  9312. d3_time.minutes = d3_time.minute.range;
  9313. d3_time.minutes.utc = d3_time.minute.utc.range;
  9314. d3_time.hour = d3_time_interval(function(date) {
  9315. var timezone = date.getTimezoneOffset() / 60;
  9316. return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
  9317. }, function(date, offset) {
  9318. date.setTime(date.getTime() + Math.floor(offset) * 36e5);
  9319. }, function(date) {
  9320. return date.getHours();
  9321. });
  9322. d3_time.hours = d3_time.hour.range;
  9323. d3_time.hours.utc = d3_time.hour.utc.range;
  9324. d3_time.month = d3_time_interval(function(date) {
  9325. date = d3_time.day(date);
  9326. date.setDate(1);
  9327. return date;
  9328. }, function(date, offset) {
  9329. date.setMonth(date.getMonth() + offset);
  9330. }, function(date) {
  9331. return date.getMonth();
  9332. });
  9333. d3_time.months = d3_time.month.range;
  9334. d3_time.months.utc = d3_time.month.utc.range;
  9335. function d3_time_scale(linear, methods, format) {
  9336. function scale(x) {
  9337. return linear(x);
  9338. }
  9339. scale.invert = function(x) {
  9340. return d3_time_scaleDate(linear.invert(x));
  9341. };
  9342. scale.domain = function(x) {
  9343. if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
  9344. linear.domain(x);
  9345. return scale;
  9346. };
  9347. function tickMethod(extent, count) {
  9348. var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
  9349. return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
  9350. return d / 31536e6;
  9351. }), count)[2] ] : !i ? [ d3_time_scaleMilliseconds, d3_scale_linearTickRange(extent, count)[2] ] : methods[target / d3_time_scaleSteps[i - 1] < d3_time_scaleSteps[i] / target ? i - 1 : i];
  9352. }
  9353. scale.nice = function(interval, skip) {
  9354. var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
  9355. if (method) interval = method[0], skip = method[1];
  9356. function skipped(date) {
  9357. return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
  9358. }
  9359. return scale.domain(d3_scale_nice(domain, skip > 1 ? {
  9360. floor: function(date) {
  9361. while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
  9362. return date;
  9363. },
  9364. ceil: function(date) {
  9365. while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
  9366. return date;
  9367. }
  9368. } : interval));
  9369. };
  9370. scale.ticks = function(interval, skip) {
  9371. var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
  9372. range: interval
  9373. }, skip ];
  9374. if (method) interval = method[0], skip = method[1];
  9375. return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
  9376. };
  9377. scale.tickFormat = function() {
  9378. return format;
  9379. };
  9380. scale.copy = function() {
  9381. return d3_time_scale(linear.copy(), methods, format);
  9382. };
  9383. return d3_scale_linearRebind(scale, linear);
  9384. }
  9385. function d3_time_scaleDate(t) {
  9386. return new Date(t);
  9387. }
  9388. var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
  9389. var d3_time_scaleLocalMethods = [ [ d3_time.second, 1 ], [ d3_time.second, 5 ], [ d3_time.second, 15 ], [ d3_time.second, 30 ], [ d3_time.minute, 1 ], [ d3_time.minute, 5 ], [ d3_time.minute, 15 ], [ d3_time.minute, 30 ], [ d3_time.hour, 1 ], [ d3_time.hour, 3 ], [ d3_time.hour, 6 ], [ d3_time.hour, 12 ], [ d3_time.day, 1 ], [ d3_time.day, 2 ], [ d3_time.week, 1 ], [ d3_time.month, 1 ], [ d3_time.month, 3 ], [ d3_time.year, 1 ] ];
  9390. var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
  9391. return d.getMilliseconds();
  9392. } ], [ ":%S", function(d) {
  9393. return d.getSeconds();
  9394. } ], [ "%I:%M", function(d) {
  9395. return d.getMinutes();
  9396. } ], [ "%I %p", function(d) {
  9397. return d.getHours();
  9398. } ], [ "%a %d", function(d) {
  9399. return d.getDay() && d.getDate() != 1;
  9400. } ], [ "%b %d", function(d) {
  9401. return d.getDate() != 1;
  9402. } ], [ "%B", function(d) {
  9403. return d.getMonth();
  9404. } ], [ "%Y", d3_true ] ]);
  9405. var d3_time_scaleMilliseconds = {
  9406. range: function(start, stop, step) {
  9407. return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
  9408. },
  9409. floor: d3_identity,
  9410. ceil: d3_identity
  9411. };
  9412. d3_time_scaleLocalMethods.year = d3_time.year;
  9413. d3_time.scale = function() {
  9414. return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
  9415. };
  9416. var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
  9417. return [ m[0].utc, m[1] ];
  9418. });
  9419. var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
  9420. return d.getUTCMilliseconds();
  9421. } ], [ ":%S", function(d) {
  9422. return d.getUTCSeconds();
  9423. } ], [ "%I:%M", function(d) {
  9424. return d.getUTCMinutes();
  9425. } ], [ "%I %p", function(d) {
  9426. return d.getUTCHours();
  9427. } ], [ "%a %d", function(d) {
  9428. return d.getUTCDay() && d.getUTCDate() != 1;
  9429. } ], [ "%b %d", function(d) {
  9430. return d.getUTCDate() != 1;
  9431. } ], [ "%B", function(d) {
  9432. return d.getUTCMonth();
  9433. } ], [ "%Y", d3_true ] ]);
  9434. d3_time_scaleUtcMethods.year = d3_time.year.utc;
  9435. d3_time.scale.utc = function() {
  9436. return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
  9437. };
  9438. d3.text = d3_xhrType(function(request) {
  9439. return request.responseText;
  9440. });
  9441. d3.json = function(url, callback) {
  9442. return d3_xhr(url, "application/json", d3_json, callback);
  9443. };
  9444. function d3_json(request) {
  9445. return JSON.parse(request.responseText);
  9446. }
  9447. d3.html = function(url, callback) {
  9448. return d3_xhr(url, "text/html", d3_html, callback);
  9449. };
  9450. function d3_html(request) {
  9451. var range = d3_document.createRange();
  9452. range.selectNode(d3_document.body);
  9453. return range.createContextualFragment(request.responseText);
  9454. }
  9455. d3.xml = d3_xhrType(function(request) {
  9456. return request.responseXML;
  9457. });
  9458. if (typeof define === "function" && define.amd) define(d3); else if (typeof module === "object" && module.exports) module.exports = d3;
  9459. this.d3 = d3;
  9460. }();