OCA reporting engine fork for dev and update.
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.

9502 lines
328 KiB

  1. !function() {
  2. var d3 = {
  3. version: "3.5.6"
  4. };
  5. var d3_arraySlice = [].slice, d3_array = function(list) {
  6. return d3_arraySlice.call(list);
  7. };
  8. var d3_document = this.document;
  9. function d3_documentElement(node) {
  10. return node && (node.ownerDocument || node.document || node).documentElement;
  11. }
  12. function d3_window(node) {
  13. return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
  14. }
  15. if (d3_document) {
  16. try {
  17. d3_array(d3_document.documentElement.childNodes)[0].nodeType;
  18. } catch (e) {
  19. d3_array = function(list) {
  20. var i = list.length, array = new Array(i);
  21. while (i--) array[i] = list[i];
  22. return array;
  23. };
  24. }
  25. }
  26. if (!Date.now) Date.now = function() {
  27. return +new Date();
  28. };
  29. if (d3_document) {
  30. try {
  31. d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
  32. } catch (error) {
  33. var d3_element_prototype = this.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = this.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
  34. d3_element_prototype.setAttribute = function(name, value) {
  35. d3_element_setAttribute.call(this, name, value + "");
  36. };
  37. d3_element_prototype.setAttributeNS = function(space, local, value) {
  38. d3_element_setAttributeNS.call(this, space, local, value + "");
  39. };
  40. d3_style_prototype.setProperty = function(name, value, priority) {
  41. d3_style_setProperty.call(this, name, value + "", priority);
  42. };
  43. }
  44. }
  45. d3.ascending = d3_ascending;
  46. function d3_ascending(a, b) {
  47. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  48. }
  49. d3.descending = function(a, b) {
  50. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  51. };
  52. d3.min = function(array, f) {
  53. var i = -1, n = array.length, a, b;
  54. if (arguments.length === 1) {
  55. while (++i < n) if ((b = array[i]) != null && b >= b) {
  56. a = b;
  57. break;
  58. }
  59. while (++i < n) if ((b = array[i]) != null && a > b) a = b;
  60. } else {
  61. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  62. a = b;
  63. break;
  64. }
  65. while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
  66. }
  67. return a;
  68. };
  69. d3.max = function(array, f) {
  70. var i = -1, n = array.length, a, b;
  71. if (arguments.length === 1) {
  72. while (++i < n) if ((b = array[i]) != null && b >= b) {
  73. a = b;
  74. break;
  75. }
  76. while (++i < n) if ((b = array[i]) != null && b > a) a = b;
  77. } else {
  78. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  79. a = b;
  80. break;
  81. }
  82. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
  83. }
  84. return a;
  85. };
  86. d3.extent = function(array, f) {
  87. var i = -1, n = array.length, a, b, c;
  88. if (arguments.length === 1) {
  89. while (++i < n) if ((b = array[i]) != null && b >= b) {
  90. a = c = b;
  91. break;
  92. }
  93. while (++i < n) if ((b = array[i]) != null) {
  94. if (a > b) a = b;
  95. if (c < b) c = b;
  96. }
  97. } else {
  98. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  99. a = c = b;
  100. break;
  101. }
  102. while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
  103. if (a > b) a = b;
  104. if (c < b) c = b;
  105. }
  106. }
  107. return [ a, c ];
  108. };
  109. function d3_number(x) {
  110. return x === null ? NaN : +x;
  111. }
  112. function d3_numeric(x) {
  113. return !isNaN(x);
  114. }
  115. d3.sum = function(array, f) {
  116. var s = 0, n = array.length, a, i = -1;
  117. if (arguments.length === 1) {
  118. while (++i < n) if (d3_numeric(a = +array[i])) s += a;
  119. } else {
  120. while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
  121. }
  122. return s;
  123. };
  124. d3.mean = function(array, f) {
  125. var s = 0, n = array.length, a, i = -1, j = n;
  126. if (arguments.length === 1) {
  127. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
  128. } else {
  129. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
  130. }
  131. if (j) return s / j;
  132. };
  133. d3.quantile = function(values, p) {
  134. var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
  135. return e ? v + e * (values[h] - v) : v;
  136. };
  137. d3.median = function(array, f) {
  138. var numbers = [], n = array.length, a, i = -1;
  139. if (arguments.length === 1) {
  140. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
  141. } else {
  142. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
  143. }
  144. if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
  145. };
  146. d3.variance = function(array, f) {
  147. var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
  148. if (arguments.length === 1) {
  149. while (++i < n) {
  150. if (d3_numeric(a = d3_number(array[i]))) {
  151. d = a - m;
  152. m += d / ++j;
  153. s += d * (a - m);
  154. }
  155. }
  156. } else {
  157. while (++i < n) {
  158. if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
  159. d = a - m;
  160. m += d / ++j;
  161. s += d * (a - m);
  162. }
  163. }
  164. }
  165. if (j > 1) return s / (j - 1);
  166. };
  167. d3.deviation = function() {
  168. var v = d3.variance.apply(this, arguments);
  169. return v ? Math.sqrt(v) : v;
  170. };
  171. function d3_bisector(compare) {
  172. return {
  173. left: function(a, x, lo, hi) {
  174. if (arguments.length < 3) lo = 0;
  175. if (arguments.length < 4) hi = a.length;
  176. while (lo < hi) {
  177. var mid = lo + hi >>> 1;
  178. if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
  179. }
  180. return lo;
  181. },
  182. right: function(a, x, lo, hi) {
  183. if (arguments.length < 3) lo = 0;
  184. if (arguments.length < 4) hi = a.length;
  185. while (lo < hi) {
  186. var mid = lo + hi >>> 1;
  187. if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
  188. }
  189. return lo;
  190. }
  191. };
  192. }
  193. var d3_bisect = d3_bisector(d3_ascending);
  194. d3.bisectLeft = d3_bisect.left;
  195. d3.bisect = d3.bisectRight = d3_bisect.right;
  196. d3.bisector = function(f) {
  197. return d3_bisector(f.length === 1 ? function(d, x) {
  198. return d3_ascending(f(d), x);
  199. } : f);
  200. };
  201. d3.shuffle = function(array, i0, i1) {
  202. if ((m = arguments.length) < 3) {
  203. i1 = array.length;
  204. if (m < 2) i0 = 0;
  205. }
  206. var m = i1 - i0, t, i;
  207. while (m) {
  208. i = Math.random() * m-- | 0;
  209. t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
  210. }
  211. return array;
  212. };
  213. d3.permute = function(array, indexes) {
  214. var i = indexes.length, permutes = new Array(i);
  215. while (i--) permutes[i] = array[indexes[i]];
  216. return permutes;
  217. };
  218. d3.pairs = function(array) {
  219. var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
  220. while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
  221. return pairs;
  222. };
  223. d3.zip = function() {
  224. if (!(n = arguments.length)) return [];
  225. for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
  226. for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
  227. zip[j] = arguments[j][i];
  228. }
  229. }
  230. return zips;
  231. };
  232. function d3_zipLength(d) {
  233. return d.length;
  234. }
  235. d3.transpose = function(matrix) {
  236. return d3.zip.apply(d3, matrix);
  237. };
  238. d3.keys = function(map) {
  239. var keys = [];
  240. for (var key in map) keys.push(key);
  241. return keys;
  242. };
  243. d3.values = function(map) {
  244. var values = [];
  245. for (var key in map) values.push(map[key]);
  246. return values;
  247. };
  248. d3.entries = function(map) {
  249. var entries = [];
  250. for (var key in map) entries.push({
  251. key: key,
  252. value: map[key]
  253. });
  254. return entries;
  255. };
  256. d3.merge = function(arrays) {
  257. var n = arrays.length, m, i = -1, j = 0, merged, array;
  258. while (++i < n) j += arrays[i].length;
  259. merged = new Array(j);
  260. while (--n >= 0) {
  261. array = arrays[n];
  262. m = array.length;
  263. while (--m >= 0) {
  264. merged[--j] = array[m];
  265. }
  266. }
  267. return merged;
  268. };
  269. var abs = Math.abs;
  270. d3.range = function(start, stop, step) {
  271. if (arguments.length < 3) {
  272. step = 1;
  273. if (arguments.length < 2) {
  274. stop = start;
  275. start = 0;
  276. }
  277. }
  278. if ((stop - start) / step === Infinity) throw new Error("infinite range");
  279. var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
  280. start *= k, stop *= k, step *= k;
  281. if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
  282. return range;
  283. };
  284. function d3_range_integerScale(x) {
  285. var k = 1;
  286. while (x * k % 1) k *= 10;
  287. return k;
  288. }
  289. function d3_class(ctor, properties) {
  290. for (var key in properties) {
  291. Object.defineProperty(ctor.prototype, key, {
  292. value: properties[key],
  293. enumerable: false
  294. });
  295. }
  296. }
  297. d3.map = function(object, f) {
  298. var map = new d3_Map();
  299. if (object instanceof d3_Map) {
  300. object.forEach(function(key, value) {
  301. map.set(key, value);
  302. });
  303. } else if (Array.isArray(object)) {
  304. var i = -1, n = object.length, o;
  305. 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);
  306. } else {
  307. for (var key in object) map.set(key, object[key]);
  308. }
  309. return map;
  310. };
  311. function d3_Map() {
  312. this._ = Object.create(null);
  313. }
  314. var d3_map_proto = "__proto__", d3_map_zero = "\x00";
  315. d3_class(d3_Map, {
  316. has: d3_map_has,
  317. get: function(key) {
  318. return this._[d3_map_escape(key)];
  319. },
  320. set: function(key, value) {
  321. return this._[d3_map_escape(key)] = value;
  322. },
  323. remove: d3_map_remove,
  324. keys: d3_map_keys,
  325. values: function() {
  326. var values = [];
  327. for (var key in this._) values.push(this._[key]);
  328. return values;
  329. },
  330. entries: function() {
  331. var entries = [];
  332. for (var key in this._) entries.push({
  333. key: d3_map_unescape(key),
  334. value: this._[key]
  335. });
  336. return entries;
  337. },
  338. size: d3_map_size,
  339. empty: d3_map_empty,
  340. forEach: function(f) {
  341. for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
  342. }
  343. });
  344. function d3_map_escape(key) {
  345. return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
  346. }
  347. function d3_map_unescape(key) {
  348. return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
  349. }
  350. function d3_map_has(key) {
  351. return d3_map_escape(key) in this._;
  352. }
  353. function d3_map_remove(key) {
  354. return (key = d3_map_escape(key)) in this._ && delete this._[key];
  355. }
  356. function d3_map_keys() {
  357. var keys = [];
  358. for (var key in this._) keys.push(d3_map_unescape(key));
  359. return keys;
  360. }
  361. function d3_map_size() {
  362. var size = 0;
  363. for (var key in this._) ++size;
  364. return size;
  365. }
  366. function d3_map_empty() {
  367. for (var key in this._) return false;
  368. return true;
  369. }
  370. d3.nest = function() {
  371. var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
  372. function map(mapType, array, depth) {
  373. if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
  374. var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
  375. while (++i < n) {
  376. if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
  377. values.push(object);
  378. } else {
  379. valuesByKey.set(keyValue, [ object ]);
  380. }
  381. }
  382. if (mapType) {
  383. object = mapType();
  384. setter = function(keyValue, values) {
  385. object.set(keyValue, map(mapType, values, depth));
  386. };
  387. } else {
  388. object = {};
  389. setter = function(keyValue, values) {
  390. object[keyValue] = map(mapType, values, depth);
  391. };
  392. }
  393. valuesByKey.forEach(setter);
  394. return object;
  395. }
  396. function entries(map, depth) {
  397. if (depth >= keys.length) return map;
  398. var array = [], sortKey = sortKeys[depth++];
  399. map.forEach(function(key, keyMap) {
  400. array.push({
  401. key: key,
  402. values: entries(keyMap, depth)
  403. });
  404. });
  405. return sortKey ? array.sort(function(a, b) {
  406. return sortKey(a.key, b.key);
  407. }) : array;
  408. }
  409. nest.map = function(array, mapType) {
  410. return map(mapType, array, 0);
  411. };
  412. nest.entries = function(array) {
  413. return entries(map(d3.map, array, 0), 0);
  414. };
  415. nest.key = function(d) {
  416. keys.push(d);
  417. return nest;
  418. };
  419. nest.sortKeys = function(order) {
  420. sortKeys[keys.length - 1] = order;
  421. return nest;
  422. };
  423. nest.sortValues = function(order) {
  424. sortValues = order;
  425. return nest;
  426. };
  427. nest.rollup = function(f) {
  428. rollup = f;
  429. return nest;
  430. };
  431. return nest;
  432. };
  433. d3.set = function(array) {
  434. var set = new d3_Set();
  435. if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
  436. return set;
  437. };
  438. function d3_Set() {
  439. this._ = Object.create(null);
  440. }
  441. d3_class(d3_Set, {
  442. has: d3_map_has,
  443. add: function(key) {
  444. this._[d3_map_escape(key += "")] = true;
  445. return key;
  446. },
  447. remove: d3_map_remove,
  448. values: d3_map_keys,
  449. size: d3_map_size,
  450. empty: d3_map_empty,
  451. forEach: function(f) {
  452. for (var key in this._) f.call(this, d3_map_unescape(key));
  453. }
  454. });
  455. d3.behavior = {};
  456. function d3_identity(d) {
  457. return d;
  458. }
  459. d3.rebind = function(target, source) {
  460. var i = 1, n = arguments.length, method;
  461. while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
  462. return target;
  463. };
  464. function d3_rebind(target, source, method) {
  465. return function() {
  466. var value = method.apply(source, arguments);
  467. return value === source ? target : value;
  468. };
  469. }
  470. function d3_vendorSymbol(object, name) {
  471. if (name in object) return name;
  472. name = name.charAt(0).toUpperCase() + name.slice(1);
  473. for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
  474. var prefixName = d3_vendorPrefixes[i] + name;
  475. if (prefixName in object) return prefixName;
  476. }
  477. }
  478. var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
  479. function d3_noop() {}
  480. d3.dispatch = function() {
  481. var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
  482. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  483. return dispatch;
  484. };
  485. function d3_dispatch() {}
  486. d3_dispatch.prototype.on = function(type, listener) {
  487. var i = type.indexOf("."), name = "";
  488. if (i >= 0) {
  489. name = type.slice(i + 1);
  490. type = type.slice(0, i);
  491. }
  492. if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
  493. if (arguments.length === 2) {
  494. if (listener == null) for (type in this) {
  495. if (this.hasOwnProperty(type)) this[type].on(name, null);
  496. }
  497. return this;
  498. }
  499. };
  500. function d3_dispatch_event(dispatch) {
  501. var listeners = [], listenerByName = new d3_Map();
  502. function event() {
  503. var z = listeners, i = -1, n = z.length, l;
  504. while (++i < n) if (l = z[i].on) l.apply(this, arguments);
  505. return dispatch;
  506. }
  507. event.on = function(name, listener) {
  508. var l = listenerByName.get(name), i;
  509. if (arguments.length < 2) return l && l.on;
  510. if (l) {
  511. l.on = null;
  512. listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
  513. listenerByName.remove(name);
  514. }
  515. if (listener) listeners.push(listenerByName.set(name, {
  516. on: listener
  517. }));
  518. return dispatch;
  519. };
  520. return event;
  521. }
  522. d3.event = null;
  523. function d3_eventPreventDefault() {
  524. d3.event.preventDefault();
  525. }
  526. function d3_eventSource() {
  527. var e = d3.event, s;
  528. while (s = e.sourceEvent) e = s;
  529. return e;
  530. }
  531. function d3_eventDispatch(target) {
  532. var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
  533. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  534. dispatch.of = function(thiz, argumentz) {
  535. return function(e1) {
  536. try {
  537. var e0 = e1.sourceEvent = d3.event;
  538. e1.target = target;
  539. d3.event = e1;
  540. dispatch[e1.type].apply(thiz, argumentz);
  541. } finally {
  542. d3.event = e0;
  543. }
  544. };
  545. };
  546. return dispatch;
  547. }
  548. d3.requote = function(s) {
  549. return s.replace(d3_requote_re, "\\$&");
  550. };
  551. var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  552. var d3_subclass = {}.__proto__ ? function(object, prototype) {
  553. object.__proto__ = prototype;
  554. } : function(object, prototype) {
  555. for (var property in prototype) object[property] = prototype[property];
  556. };
  557. function d3_selection(groups) {
  558. d3_subclass(groups, d3_selectionPrototype);
  559. return groups;
  560. }
  561. var d3_select = function(s, n) {
  562. return n.querySelector(s);
  563. }, d3_selectAll = function(s, n) {
  564. return n.querySelectorAll(s);
  565. }, d3_selectMatches = function(n, s) {
  566. var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")];
  567. d3_selectMatches = function(n, s) {
  568. return d3_selectMatcher.call(n, s);
  569. };
  570. return d3_selectMatches(n, s);
  571. };
  572. if (typeof Sizzle === "function") {
  573. d3_select = function(s, n) {
  574. return Sizzle(s, n)[0] || null;
  575. };
  576. d3_selectAll = Sizzle;
  577. d3_selectMatches = Sizzle.matchesSelector;
  578. }
  579. d3.selection = function() {
  580. return d3.select(d3_document.documentElement);
  581. };
  582. var d3_selectionPrototype = d3.selection.prototype = [];
  583. d3_selectionPrototype.select = function(selector) {
  584. var subgroups = [], subgroup, subnode, group, node;
  585. selector = d3_selection_selector(selector);
  586. for (var j = -1, m = this.length; ++j < m; ) {
  587. subgroups.push(subgroup = []);
  588. subgroup.parentNode = (group = this[j]).parentNode;
  589. for (var i = -1, n = group.length; ++i < n; ) {
  590. if (node = group[i]) {
  591. subgroup.push(subnode = selector.call(node, node.__data__, i, j));
  592. if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
  593. } else {
  594. subgroup.push(null);
  595. }
  596. }
  597. }
  598. return d3_selection(subgroups);
  599. };
  600. function d3_selection_selector(selector) {
  601. return typeof selector === "function" ? selector : function() {
  602. return d3_select(selector, this);
  603. };
  604. }
  605. d3_selectionPrototype.selectAll = function(selector) {
  606. var subgroups = [], subgroup, node;
  607. selector = d3_selection_selectorAll(selector);
  608. for (var j = -1, m = this.length; ++j < m; ) {
  609. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  610. if (node = group[i]) {
  611. subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
  612. subgroup.parentNode = node;
  613. }
  614. }
  615. }
  616. return d3_selection(subgroups);
  617. };
  618. function d3_selection_selectorAll(selector) {
  619. return typeof selector === "function" ? selector : function() {
  620. return d3_selectAll(selector, this);
  621. };
  622. }
  623. var d3_nsPrefix = {
  624. svg: "http://www.w3.org/2000/svg",
  625. xhtml: "http://www.w3.org/1999/xhtml",
  626. xlink: "http://www.w3.org/1999/xlink",
  627. xml: "http://www.w3.org/XML/1998/namespace",
  628. xmlns: "http://www.w3.org/2000/xmlns/"
  629. };
  630. d3.ns = {
  631. prefix: d3_nsPrefix,
  632. qualify: function(name) {
  633. var i = name.indexOf(":"), prefix = name;
  634. if (i >= 0) {
  635. prefix = name.slice(0, i);
  636. name = name.slice(i + 1);
  637. }
  638. return d3_nsPrefix.hasOwnProperty(prefix) ? {
  639. space: d3_nsPrefix[prefix],
  640. local: name
  641. } : name;
  642. }
  643. };
  644. d3_selectionPrototype.attr = function(name, value) {
  645. if (arguments.length < 2) {
  646. if (typeof name === "string") {
  647. var node = this.node();
  648. name = d3.ns.qualify(name);
  649. return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
  650. }
  651. for (value in name) this.each(d3_selection_attr(value, name[value]));
  652. return this;
  653. }
  654. return this.each(d3_selection_attr(name, value));
  655. };
  656. function d3_selection_attr(name, value) {
  657. name = d3.ns.qualify(name);
  658. function attrNull() {
  659. this.removeAttribute(name);
  660. }
  661. function attrNullNS() {
  662. this.removeAttributeNS(name.space, name.local);
  663. }
  664. function attrConstant() {
  665. this.setAttribute(name, value);
  666. }
  667. function attrConstantNS() {
  668. this.setAttributeNS(name.space, name.local, value);
  669. }
  670. function attrFunction() {
  671. var x = value.apply(this, arguments);
  672. if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
  673. }
  674. function attrFunctionNS() {
  675. var x = value.apply(this, arguments);
  676. if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
  677. }
  678. return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
  679. }
  680. function d3_collapse(s) {
  681. return s.trim().replace(/\s+/g, " ");
  682. }
  683. d3_selectionPrototype.classed = function(name, value) {
  684. if (arguments.length < 2) {
  685. if (typeof name === "string") {
  686. var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
  687. if (value = node.classList) {
  688. while (++i < n) if (!value.contains(name[i])) return false;
  689. } else {
  690. value = node.getAttribute("class");
  691. while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
  692. }
  693. return true;
  694. }
  695. for (value in name) this.each(d3_selection_classed(value, name[value]));
  696. return this;
  697. }
  698. return this.each(d3_selection_classed(name, value));
  699. };
  700. function d3_selection_classedRe(name) {
  701. return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
  702. }
  703. function d3_selection_classes(name) {
  704. return (name + "").trim().split(/^|\s+/);
  705. }
  706. function d3_selection_classed(name, value) {
  707. name = d3_selection_classes(name).map(d3_selection_classedName);
  708. var n = name.length;
  709. function classedConstant() {
  710. var i = -1;
  711. while (++i < n) name[i](this, value);
  712. }
  713. function classedFunction() {
  714. var i = -1, x = value.apply(this, arguments);
  715. while (++i < n) name[i](this, x);
  716. }
  717. return typeof value === "function" ? classedFunction : classedConstant;
  718. }
  719. function d3_selection_classedName(name) {
  720. var re = d3_selection_classedRe(name);
  721. return function(node, value) {
  722. if (c = node.classList) return value ? c.add(name) : c.remove(name);
  723. var c = node.getAttribute("class") || "";
  724. if (value) {
  725. re.lastIndex = 0;
  726. if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
  727. } else {
  728. node.setAttribute("class", d3_collapse(c.replace(re, " ")));
  729. }
  730. };
  731. }
  732. d3_selectionPrototype.style = function(name, value, priority) {
  733. var n = arguments.length;
  734. if (n < 3) {
  735. if (typeof name !== "string") {
  736. if (n < 2) value = "";
  737. for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
  738. return this;
  739. }
  740. if (n < 2) {
  741. var node = this.node();
  742. return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
  743. }
  744. priority = "";
  745. }
  746. return this.each(d3_selection_style(name, value, priority));
  747. };
  748. function d3_selection_style(name, value, priority) {
  749. function styleNull() {
  750. this.style.removeProperty(name);
  751. }
  752. function styleConstant() {
  753. this.style.setProperty(name, value, priority);
  754. }
  755. function styleFunction() {
  756. var x = value.apply(this, arguments);
  757. if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
  758. }
  759. return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
  760. }
  761. d3_selectionPrototype.property = function(name, value) {
  762. if (arguments.length < 2) {
  763. if (typeof name === "string") return this.node()[name];
  764. for (value in name) this.each(d3_selection_property(value, name[value]));
  765. return this;
  766. }
  767. return this.each(d3_selection_property(name, value));
  768. };
  769. function d3_selection_property(name, value) {
  770. function propertyNull() {
  771. delete this[name];
  772. }
  773. function propertyConstant() {
  774. this[name] = value;
  775. }
  776. function propertyFunction() {
  777. var x = value.apply(this, arguments);
  778. if (x == null) delete this[name]; else this[name] = x;
  779. }
  780. return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
  781. }
  782. d3_selectionPrototype.text = function(value) {
  783. return arguments.length ? this.each(typeof value === "function" ? function() {
  784. var v = value.apply(this, arguments);
  785. this.textContent = v == null ? "" : v;
  786. } : value == null ? function() {
  787. this.textContent = "";
  788. } : function() {
  789. this.textContent = value;
  790. }) : this.node().textContent;
  791. };
  792. d3_selectionPrototype.html = function(value) {
  793. return arguments.length ? this.each(typeof value === "function" ? function() {
  794. var v = value.apply(this, arguments);
  795. this.innerHTML = v == null ? "" : v;
  796. } : value == null ? function() {
  797. this.innerHTML = "";
  798. } : function() {
  799. this.innerHTML = value;
  800. }) : this.node().innerHTML;
  801. };
  802. d3_selectionPrototype.append = function(name) {
  803. name = d3_selection_creator(name);
  804. return this.select(function() {
  805. return this.appendChild(name.apply(this, arguments));
  806. });
  807. };
  808. function d3_selection_creator(name) {
  809. function create() {
  810. var document = this.ownerDocument, namespace = this.namespaceURI;
  811. return namespace ? document.createElementNS(namespace, name) : document.createElement(name);
  812. }
  813. function createNS() {
  814. return this.ownerDocument.createElementNS(name.space, name.local);
  815. }
  816. return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
  817. }
  818. d3_selectionPrototype.insert = function(name, before) {
  819. name = d3_selection_creator(name);
  820. before = d3_selection_selector(before);
  821. return this.select(function() {
  822. return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
  823. });
  824. };
  825. d3_selectionPrototype.remove = function() {
  826. return this.each(d3_selectionRemove);
  827. };
  828. function d3_selectionRemove() {
  829. var parent = this.parentNode;
  830. if (parent) parent.removeChild(this);
  831. }
  832. d3_selectionPrototype.data = function(value, key) {
  833. var i = -1, n = this.length, group, node;
  834. if (!arguments.length) {
  835. value = new Array(n = (group = this[0]).length);
  836. while (++i < n) {
  837. if (node = group[i]) {
  838. value[i] = node.__data__;
  839. }
  840. }
  841. return value;
  842. }
  843. function bind(group, groupData) {
  844. 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;
  845. if (key) {
  846. var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
  847. for (i = -1; ++i < n; ) {
  848. if (nodeByKeyValue.has(keyValue = key.call(node = group[i], node.__data__, i))) {
  849. exitNodes[i] = node;
  850. } else {
  851. nodeByKeyValue.set(keyValue, node);
  852. }
  853. keyValues[i] = keyValue;
  854. }
  855. for (i = -1; ++i < m; ) {
  856. if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
  857. enterNodes[i] = d3_selection_dataNode(nodeData);
  858. } else if (node !== true) {
  859. updateNodes[i] = node;
  860. node.__data__ = nodeData;
  861. }
  862. nodeByKeyValue.set(keyValue, true);
  863. }
  864. for (i = -1; ++i < n; ) {
  865. if (nodeByKeyValue.get(keyValues[i]) !== true) {
  866. exitNodes[i] = group[i];
  867. }
  868. }
  869. } else {
  870. for (i = -1; ++i < n0; ) {
  871. node = group[i];
  872. nodeData = groupData[i];
  873. if (node) {
  874. node.__data__ = nodeData;
  875. updateNodes[i] = node;
  876. } else {
  877. enterNodes[i] = d3_selection_dataNode(nodeData);
  878. }
  879. }
  880. for (;i < m; ++i) {
  881. enterNodes[i] = d3_selection_dataNode(groupData[i]);
  882. }
  883. for (;i < n; ++i) {
  884. exitNodes[i] = group[i];
  885. }
  886. }
  887. enterNodes.update = updateNodes;
  888. enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
  889. enter.push(enterNodes);
  890. update.push(updateNodes);
  891. exit.push(exitNodes);
  892. }
  893. var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
  894. if (typeof value === "function") {
  895. while (++i < n) {
  896. bind(group = this[i], value.call(group, group.parentNode.__data__, i));
  897. }
  898. } else {
  899. while (++i < n) {
  900. bind(group = this[i], value);
  901. }
  902. }
  903. update.enter = function() {
  904. return enter;
  905. };
  906. update.exit = function() {
  907. return exit;
  908. };
  909. return update;
  910. };
  911. function d3_selection_dataNode(data) {
  912. return {
  913. __data__: data
  914. };
  915. }
  916. d3_selectionPrototype.datum = function(value) {
  917. return arguments.length ? this.property("__data__", value) : this.property("__data__");
  918. };
  919. d3_selectionPrototype.filter = function(filter) {
  920. var subgroups = [], subgroup, group, node;
  921. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  922. for (var j = 0, m = this.length; j < m; j++) {
  923. subgroups.push(subgroup = []);
  924. subgroup.parentNode = (group = this[j]).parentNode;
  925. for (var i = 0, n = group.length; i < n; i++) {
  926. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  927. subgroup.push(node);
  928. }
  929. }
  930. }
  931. return d3_selection(subgroups);
  932. };
  933. function d3_selection_filter(selector) {
  934. return function() {
  935. return d3_selectMatches(this, selector);
  936. };
  937. }
  938. d3_selectionPrototype.order = function() {
  939. for (var j = -1, m = this.length; ++j < m; ) {
  940. for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
  941. if (node = group[i]) {
  942. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  943. next = node;
  944. }
  945. }
  946. }
  947. return this;
  948. };
  949. d3_selectionPrototype.sort = function(comparator) {
  950. comparator = d3_selection_sortComparator.apply(this, arguments);
  951. for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
  952. return this.order();
  953. };
  954. function d3_selection_sortComparator(comparator) {
  955. if (!arguments.length) comparator = d3_ascending;
  956. return function(a, b) {
  957. return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
  958. };
  959. }
  960. d3_selectionPrototype.each = function(callback) {
  961. return d3_selection_each(this, function(node, i, j) {
  962. callback.call(node, node.__data__, i, j);
  963. });
  964. };
  965. function d3_selection_each(groups, callback) {
  966. for (var j = 0, m = groups.length; j < m; j++) {
  967. for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
  968. if (node = group[i]) callback(node, i, j);
  969. }
  970. }
  971. return groups;
  972. }
  973. d3_selectionPrototype.call = function(callback) {
  974. var args = d3_array(arguments);
  975. callback.apply(args[0] = this, args);
  976. return this;
  977. };
  978. d3_selectionPrototype.empty = function() {
  979. return !this.node();
  980. };
  981. d3_selectionPrototype.node = function() {
  982. for (var j = 0, m = this.length; j < m; j++) {
  983. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  984. var node = group[i];
  985. if (node) return node;
  986. }
  987. }
  988. return null;
  989. };
  990. d3_selectionPrototype.size = function() {
  991. var n = 0;
  992. d3_selection_each(this, function() {
  993. ++n;
  994. });
  995. return n;
  996. };
  997. function d3_selection_enter(selection) {
  998. d3_subclass(selection, d3_selection_enterPrototype);
  999. return selection;
  1000. }
  1001. var d3_selection_enterPrototype = [];
  1002. d3.selection.enter = d3_selection_enter;
  1003. d3.selection.enter.prototype = d3_selection_enterPrototype;
  1004. d3_selection_enterPrototype.append = d3_selectionPrototype.append;
  1005. d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
  1006. d3_selection_enterPrototype.node = d3_selectionPrototype.node;
  1007. d3_selection_enterPrototype.call = d3_selectionPrototype.call;
  1008. d3_selection_enterPrototype.size = d3_selectionPrototype.size;
  1009. d3_selection_enterPrototype.select = function(selector) {
  1010. var subgroups = [], subgroup, subnode, upgroup, group, node;
  1011. for (var j = -1, m = this.length; ++j < m; ) {
  1012. upgroup = (group = this[j]).update;
  1013. subgroups.push(subgroup = []);
  1014. subgroup.parentNode = group.parentNode;
  1015. for (var i = -1, n = group.length; ++i < n; ) {
  1016. if (node = group[i]) {
  1017. subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
  1018. subnode.__data__ = node.__data__;
  1019. } else {
  1020. subgroup.push(null);
  1021. }
  1022. }
  1023. }
  1024. return d3_selection(subgroups);
  1025. };
  1026. d3_selection_enterPrototype.insert = function(name, before) {
  1027. if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
  1028. return d3_selectionPrototype.insert.call(this, name, before);
  1029. };
  1030. function d3_selection_enterInsertBefore(enter) {
  1031. var i0, j0;
  1032. return function(d, i, j) {
  1033. var group = enter[j].update, n = group.length, node;
  1034. if (j != j0) j0 = j, i0 = 0;
  1035. if (i >= i0) i0 = i + 1;
  1036. while (!(node = group[i0]) && ++i0 < n) ;
  1037. return node;
  1038. };
  1039. }
  1040. d3.select = function(node) {
  1041. var group;
  1042. if (typeof node === "string") {
  1043. group = [ d3_select(node, d3_document) ];
  1044. group.parentNode = d3_document.documentElement;
  1045. } else {
  1046. group = [ node ];
  1047. group.parentNode = d3_documentElement(node);
  1048. }
  1049. return d3_selection([ group ]);
  1050. };
  1051. d3.selectAll = function(nodes) {
  1052. var group;
  1053. if (typeof nodes === "string") {
  1054. group = d3_array(d3_selectAll(nodes, d3_document));
  1055. group.parentNode = d3_document.documentElement;
  1056. } else {
  1057. group = nodes;
  1058. group.parentNode = null;
  1059. }
  1060. return d3_selection([ group ]);
  1061. };
  1062. d3_selectionPrototype.on = function(type, listener, capture) {
  1063. var n = arguments.length;
  1064. if (n < 3) {
  1065. if (typeof type !== "string") {
  1066. if (n < 2) listener = false;
  1067. for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
  1068. return this;
  1069. }
  1070. if (n < 2) return (n = this.node()["__on" + type]) && n._;
  1071. capture = false;
  1072. }
  1073. return this.each(d3_selection_on(type, listener, capture));
  1074. };
  1075. function d3_selection_on(type, listener, capture) {
  1076. var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
  1077. if (i > 0) type = type.slice(0, i);
  1078. var filter = d3_selection_onFilters.get(type);
  1079. if (filter) type = filter, wrap = d3_selection_onFilter;
  1080. function onRemove() {
  1081. var l = this[name];
  1082. if (l) {
  1083. this.removeEventListener(type, l, l.$);
  1084. delete this[name];
  1085. }
  1086. }
  1087. function onAdd() {
  1088. var l = wrap(listener, d3_array(arguments));
  1089. onRemove.call(this);
  1090. this.addEventListener(type, this[name] = l, l.$ = capture);
  1091. l._ = listener;
  1092. }
  1093. function removeAll() {
  1094. var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
  1095. for (var name in this) {
  1096. if (match = name.match(re)) {
  1097. var l = this[name];
  1098. this.removeEventListener(match[1], l, l.$);
  1099. delete this[name];
  1100. }
  1101. }
  1102. }
  1103. return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
  1104. }
  1105. var d3_selection_onFilters = d3.map({
  1106. mouseenter: "mouseover",
  1107. mouseleave: "mouseout"
  1108. });
  1109. if (d3_document) {
  1110. d3_selection_onFilters.forEach(function(k) {
  1111. if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
  1112. });
  1113. }
  1114. function d3_selection_onListener(listener, argumentz) {
  1115. return function(e) {
  1116. var o = d3.event;
  1117. d3.event = e;
  1118. argumentz[0] = this.__data__;
  1119. try {
  1120. listener.apply(this, argumentz);
  1121. } finally {
  1122. d3.event = o;
  1123. }
  1124. };
  1125. }
  1126. function d3_selection_onFilter(listener, argumentz) {
  1127. var l = d3_selection_onListener(listener, argumentz);
  1128. return function(e) {
  1129. var target = this, related = e.relatedTarget;
  1130. if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
  1131. l.call(target, e);
  1132. }
  1133. };
  1134. }
  1135. var d3_event_dragSelect, d3_event_dragId = 0;
  1136. function d3_event_dragSuppress(node) {
  1137. var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window(node)).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
  1138. if (d3_event_dragSelect == null) {
  1139. d3_event_dragSelect = "onselectstart" in node ? false : d3_vendorSymbol(node.style, "userSelect");
  1140. }
  1141. if (d3_event_dragSelect) {
  1142. var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
  1143. style[d3_event_dragSelect] = "none";
  1144. }
  1145. return function(suppressClick) {
  1146. w.on(name, null);
  1147. if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
  1148. if (suppressClick) {
  1149. var off = function() {
  1150. w.on(click, null);
  1151. };
  1152. w.on(click, function() {
  1153. d3_eventPreventDefault();
  1154. off();
  1155. }, true);
  1156. setTimeout(off, 0);
  1157. }
  1158. };
  1159. }
  1160. d3.mouse = function(container) {
  1161. return d3_mousePoint(container, d3_eventSource());
  1162. };
  1163. var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
  1164. function d3_mousePoint(container, e) {
  1165. if (e.changedTouches) e = e.changedTouches[0];
  1166. var svg = container.ownerSVGElement || container;
  1167. if (svg.createSVGPoint) {
  1168. var point = svg.createSVGPoint();
  1169. if (d3_mouse_bug44083 < 0) {
  1170. var window = d3_window(container);
  1171. if (window.scrollX || window.scrollY) {
  1172. svg = d3.select("body").append("svg").style({
  1173. position: "absolute",
  1174. top: 0,
  1175. left: 0,
  1176. margin: 0,
  1177. padding: 0,
  1178. border: "none"
  1179. }, "important");
  1180. var ctm = svg[0][0].getScreenCTM();
  1181. d3_mouse_bug44083 = !(ctm.f || ctm.e);
  1182. svg.remove();
  1183. }
  1184. }
  1185. if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
  1186. point.y = e.clientY;
  1187. point = point.matrixTransform(container.getScreenCTM().inverse());
  1188. return [ point.x, point.y ];
  1189. }
  1190. var rect = container.getBoundingClientRect();
  1191. return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
  1192. }
  1193. d3.touch = function(container, touches, identifier) {
  1194. if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
  1195. if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
  1196. if ((touch = touches[i]).identifier === identifier) {
  1197. return d3_mousePoint(container, touch);
  1198. }
  1199. }
  1200. };
  1201. d3.behavior.drag = function() {
  1202. var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_window, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_identity, "touchmove", "touchend");
  1203. function drag() {
  1204. this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
  1205. }
  1206. function dragstart(id, position, subject, move, end) {
  1207. return function() {
  1208. 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(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
  1209. if (origin) {
  1210. dragOffset = origin.apply(that, arguments);
  1211. dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
  1212. } else {
  1213. dragOffset = [ 0, 0 ];
  1214. }
  1215. dispatch({
  1216. type: "dragstart"
  1217. });
  1218. function moved() {
  1219. var position1 = position(parent, dragId), dx, dy;
  1220. if (!position1) return;
  1221. dx = position1[0] - position0[0];
  1222. dy = position1[1] - position0[1];
  1223. dragged |= dx | dy;
  1224. position0 = position1;
  1225. dispatch({
  1226. type: "drag",
  1227. x: position1[0] + dragOffset[0],
  1228. y: position1[1] + dragOffset[1],
  1229. dx: dx,
  1230. dy: dy
  1231. });
  1232. }
  1233. function ended() {
  1234. if (!position(parent, dragId)) return;
  1235. dragSubject.on(move + dragName, null).on(end + dragName, null);
  1236. dragRestore(dragged && d3.event.target === target);
  1237. dispatch({
  1238. type: "dragend"
  1239. });
  1240. }
  1241. };
  1242. }
  1243. drag.origin = function(x) {
  1244. if (!arguments.length) return origin;
  1245. origin = x;
  1246. return drag;
  1247. };
  1248. return d3.rebind(drag, event, "on");
  1249. };
  1250. function d3_behavior_dragTouchId() {
  1251. return d3.event.changedTouches[0].identifier;
  1252. }
  1253. d3.touches = function(container, touches) {
  1254. if (arguments.length < 2) touches = d3_eventSource().touches;
  1255. return touches ? d3_array(touches).map(function(touch) {
  1256. var point = d3_mousePoint(container, touch);
  1257. point.identifier = touch.identifier;
  1258. return point;
  1259. }) : [];
  1260. };
  1261. var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
  1262. function d3_sgn(x) {
  1263. return x > 0 ? 1 : x < 0 ? -1 : 0;
  1264. }
  1265. function d3_cross2d(a, b, c) {
  1266. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  1267. }
  1268. function d3_acos(x) {
  1269. return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
  1270. }
  1271. function d3_asin(x) {
  1272. return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
  1273. }
  1274. function d3_sinh(x) {
  1275. return ((x = Math.exp(x)) - 1 / x) / 2;
  1276. }
  1277. function d3_cosh(x) {
  1278. return ((x = Math.exp(x)) + 1 / x) / 2;
  1279. }
  1280. function d3_tanh(x) {
  1281. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  1282. }
  1283. function d3_haversin(x) {
  1284. return (x = Math.sin(x / 2)) * x;
  1285. }
  1286. var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
  1287. d3.interpolateZoom = function(p0, p1) {
  1288. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2];
  1289. 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)) / ρ;
  1290. function interpolate(t) {
  1291. var s = t * S;
  1292. if (dr) {
  1293. var coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
  1294. return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
  1295. }
  1296. return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * s) ];
  1297. }
  1298. interpolate.duration = S * 1e3;
  1299. return interpolate;
  1300. };
  1301. d3.behavior.zoom = function() {
  1302. var view = {
  1303. x: 0,
  1304. y: 0,
  1305. k: 1
  1306. }, 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;
  1307. if (!d3_behavior_zoomWheel) {
  1308. d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1309. return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
  1310. }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  1311. return d3.event.wheelDelta;
  1312. }, "mousewheel") : (d3_behavior_zoomDelta = function() {
  1313. return -d3.event.detail;
  1314. }, "MozMousePixelScroll");
  1315. }
  1316. function zoom(g) {
  1317. g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
  1318. }
  1319. zoom.event = function(g) {
  1320. g.each(function() {
  1321. var dispatch = event.of(this, arguments), view1 = view;
  1322. if (d3_transitionInheritId) {
  1323. d3.select(this).transition().each("start.zoom", function() {
  1324. view = this.__chart__ || {
  1325. x: 0,
  1326. y: 0,
  1327. k: 1
  1328. };
  1329. zoomstarted(dispatch);
  1330. }).tween("zoom:zoom", function() {
  1331. 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 ]);
  1332. return function(t) {
  1333. var l = i(t), k = dx / l[2];
  1334. this.__chart__ = view = {
  1335. x: cx - l[0] * k,
  1336. y: cy - l[1] * k,
  1337. k: k
  1338. };
  1339. zoomed(dispatch);
  1340. };
  1341. }).each("interrupt.zoom", function() {
  1342. zoomended(dispatch);
  1343. }).each("end.zoom", function() {
  1344. zoomended(dispatch);
  1345. });
  1346. } else {
  1347. this.__chart__ = view;
  1348. zoomstarted(dispatch);
  1349. zoomed(dispatch);
  1350. zoomended(dispatch);
  1351. }
  1352. });
  1353. };
  1354. zoom.translate = function(_) {
  1355. if (!arguments.length) return [ view.x, view.y ];
  1356. view = {
  1357. x: +_[0],
  1358. y: +_[1],
  1359. k: view.k
  1360. };
  1361. rescale();
  1362. return zoom;
  1363. };
  1364. zoom.scale = function(_) {
  1365. if (!arguments.length) return view.k;
  1366. view = {
  1367. x: view.x,
  1368. y: view.y,
  1369. k: +_
  1370. };
  1371. rescale();
  1372. return zoom;
  1373. };
  1374. zoom.scaleExtent = function(_) {
  1375. if (!arguments.length) return scaleExtent;
  1376. scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
  1377. return zoom;
  1378. };
  1379. zoom.center = function(_) {
  1380. if (!arguments.length) return center;
  1381. center = _ && [ +_[0], +_[1] ];
  1382. return zoom;
  1383. };
  1384. zoom.size = function(_) {
  1385. if (!arguments.length) return size;
  1386. size = _ && [ +_[0], +_[1] ];
  1387. return zoom;
  1388. };
  1389. zoom.duration = function(_) {
  1390. if (!arguments.length) return duration;
  1391. duration = +_;
  1392. return zoom;
  1393. };
  1394. zoom.x = function(z) {
  1395. if (!arguments.length) return x1;
  1396. x1 = z;
  1397. x0 = z.copy();
  1398. view = {
  1399. x: 0,
  1400. y: 0,
  1401. k: 1
  1402. };
  1403. return zoom;
  1404. };
  1405. zoom.y = function(z) {
  1406. if (!arguments.length) return y1;
  1407. y1 = z;
  1408. y0 = z.copy();
  1409. view = {
  1410. x: 0,
  1411. y: 0,
  1412. k: 1
  1413. };
  1414. return zoom;
  1415. };
  1416. function location(p) {
  1417. return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
  1418. }
  1419. function point(l) {
  1420. return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
  1421. }
  1422. function scaleTo(s) {
  1423. view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
  1424. }
  1425. function translateTo(p, l) {
  1426. l = point(l);
  1427. view.x += p[0] - l[0];
  1428. view.y += p[1] - l[1];
  1429. }
  1430. function zoomTo(that, p, l, k) {
  1431. that.__chart__ = {
  1432. x: view.x,
  1433. y: view.y,
  1434. k: view.k
  1435. };
  1436. scaleTo(Math.pow(2, k));
  1437. translateTo(center0 = p, l);
  1438. that = d3.select(that);
  1439. if (duration > 0) that = that.transition().duration(duration);
  1440. that.call(zoom.event);
  1441. }
  1442. function rescale() {
  1443. if (x1) x1.domain(x0.range().map(function(x) {
  1444. return (x - view.x) / view.k;
  1445. }).map(x0.invert));
  1446. if (y1) y1.domain(y0.range().map(function(y) {
  1447. return (y - view.y) / view.k;
  1448. }).map(y0.invert));
  1449. }
  1450. function zoomstarted(dispatch) {
  1451. if (!zooming++) dispatch({
  1452. type: "zoomstart"
  1453. });
  1454. }
  1455. function zoomed(dispatch) {
  1456. rescale();
  1457. dispatch({
  1458. type: "zoom",
  1459. scale: view.k,
  1460. translate: [ view.x, view.y ]
  1461. });
  1462. }
  1463. function zoomended(dispatch) {
  1464. if (!--zooming) dispatch({
  1465. type: "zoomend"
  1466. }), center0 = null;
  1467. }
  1468. function mousedowned() {
  1469. var that = this, target = d3.event.target, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress(that);
  1470. d3_selection_interrupt.call(that);
  1471. zoomstarted(dispatch);
  1472. function moved() {
  1473. dragged = 1;
  1474. translateTo(d3.mouse(that), location0);
  1475. zoomed(dispatch);
  1476. }
  1477. function ended() {
  1478. subject.on(mousemove, null).on(mouseup, null);
  1479. dragRestore(dragged && d3.event.target === target);
  1480. zoomended(dispatch);
  1481. }
  1482. }
  1483. function touchstarted() {
  1484. 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(that);
  1485. started();
  1486. zoomstarted(dispatch);
  1487. subject.on(mousedown, null).on(touchstart, started);
  1488. function relocate() {
  1489. var touches = d3.touches(that);
  1490. scale0 = view.k;
  1491. touches.forEach(function(t) {
  1492. if (t.identifier in locations0) locations0[t.identifier] = location(t);
  1493. });
  1494. return touches;
  1495. }
  1496. function started() {
  1497. var target = d3.event.target;
  1498. d3.select(target).on(touchmove, moved).on(touchend, ended);
  1499. targets.push(target);
  1500. var changed = d3.event.changedTouches;
  1501. for (var i = 0, n = changed.length; i < n; ++i) {
  1502. locations0[changed[i].identifier] = null;
  1503. }
  1504. var touches = relocate(), now = Date.now();
  1505. if (touches.length === 1) {
  1506. if (now - touchtime < 500) {
  1507. var p = touches[0];
  1508. zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
  1509. d3_eventPreventDefault();
  1510. }
  1511. touchtime = now;
  1512. } else if (touches.length > 1) {
  1513. var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
  1514. distance0 = dx * dx + dy * dy;
  1515. }
  1516. }
  1517. function moved() {
  1518. var touches = d3.touches(that), p0, l0, p1, l1;
  1519. d3_selection_interrupt.call(that);
  1520. for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
  1521. p1 = touches[i];
  1522. if (l1 = locations0[p1.identifier]) {
  1523. if (l0) break;
  1524. p0 = p1, l0 = l1;
  1525. }
  1526. }
  1527. if (l1) {
  1528. var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
  1529. p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
  1530. l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
  1531. scaleTo(scale1 * scale0);
  1532. }
  1533. touchtime = null;
  1534. translateTo(p0, l0);
  1535. zoomed(dispatch);
  1536. }
  1537. function ended() {
  1538. if (d3.event.touches.length) {
  1539. var changed = d3.event.changedTouches;
  1540. for (var i = 0, n = changed.length; i < n; ++i) {
  1541. delete locations0[changed[i].identifier];
  1542. }
  1543. for (var identifier in locations0) {
  1544. return void relocate();
  1545. }
  1546. }
  1547. d3.selectAll(targets).on(zoomName, null);
  1548. subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
  1549. dragRestore();
  1550. zoomended(dispatch);
  1551. }
  1552. }
  1553. function mousewheeled() {
  1554. var dispatch = event.of(this, arguments);
  1555. if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
  1556. translate0 = location(center0 = center || d3.mouse(this)), zoomstarted(dispatch);
  1557. mousewheelTimer = setTimeout(function() {
  1558. mousewheelTimer = null;
  1559. zoomended(dispatch);
  1560. }, 50);
  1561. d3_eventPreventDefault();
  1562. scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
  1563. translateTo(center0, translate0);
  1564. zoomed(dispatch);
  1565. }
  1566. function dblclicked() {
  1567. var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
  1568. zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
  1569. }
  1570. return d3.rebind(zoom, event, "on");
  1571. };
  1572. var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
  1573. d3.color = d3_color;
  1574. function d3_color() {}
  1575. d3_color.prototype.toString = function() {
  1576. return this.rgb() + "";
  1577. };
  1578. d3.hsl = d3_hsl;
  1579. function d3_hsl(h, s, l) {
  1580. 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);
  1581. }
  1582. var d3_hslPrototype = d3_hsl.prototype = new d3_color();
  1583. d3_hslPrototype.brighter = function(k) {
  1584. k = Math.pow(.7, arguments.length ? k : 1);
  1585. return new d3_hsl(this.h, this.s, this.l / k);
  1586. };
  1587. d3_hslPrototype.darker = function(k) {
  1588. k = Math.pow(.7, arguments.length ? k : 1);
  1589. return new d3_hsl(this.h, this.s, k * this.l);
  1590. };
  1591. d3_hslPrototype.rgb = function() {
  1592. return d3_hsl_rgb(this.h, this.s, this.l);
  1593. };
  1594. function d3_hsl_rgb(h, s, l) {
  1595. var m1, m2;
  1596. h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
  1597. s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
  1598. l = l < 0 ? 0 : l > 1 ? 1 : l;
  1599. m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
  1600. m1 = 2 * l - m2;
  1601. function v(h) {
  1602. if (h > 360) h -= 360; else if (h < 0) h += 360;
  1603. if (h < 60) return m1 + (m2 - m1) * h / 60;
  1604. if (h < 180) return m2;
  1605. if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
  1606. return m1;
  1607. }
  1608. function vv(h) {
  1609. return Math.round(v(h) * 255);
  1610. }
  1611. return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
  1612. }
  1613. d3.hcl = d3_hcl;
  1614. function d3_hcl(h, c, l) {
  1615. 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);
  1616. }
  1617. var d3_hclPrototype = d3_hcl.prototype = new d3_color();
  1618. d3_hclPrototype.brighter = function(k) {
  1619. return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
  1620. };
  1621. d3_hclPrototype.darker = function(k) {
  1622. return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
  1623. };
  1624. d3_hclPrototype.rgb = function() {
  1625. return d3_hcl_lab(this.h, this.c, this.l).rgb();
  1626. };
  1627. function d3_hcl_lab(h, c, l) {
  1628. if (isNaN(h)) h = 0;
  1629. if (isNaN(c)) c = 0;
  1630. return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
  1631. }
  1632. d3.lab = d3_lab;
  1633. function d3_lab(l, a, b) {
  1634. 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);
  1635. }
  1636. var d3_lab_K = 18;
  1637. var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
  1638. var d3_labPrototype = d3_lab.prototype = new d3_color();
  1639. d3_labPrototype.brighter = function(k) {
  1640. return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1641. };
  1642. d3_labPrototype.darker = function(k) {
  1643. return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  1644. };
  1645. d3_labPrototype.rgb = function() {
  1646. return d3_lab_rgb(this.l, this.a, this.b);
  1647. };
  1648. function d3_lab_rgb(l, a, b) {
  1649. var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
  1650. x = d3_lab_xyz(x) * d3_lab_X;
  1651. y = d3_lab_xyz(y) * d3_lab_Y;
  1652. z = d3_lab_xyz(z) * d3_lab_Z;
  1653. 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));
  1654. }
  1655. function d3_lab_hcl(l, a, b) {
  1656. 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);
  1657. }
  1658. function d3_lab_xyz(x) {
  1659. return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
  1660. }
  1661. function d3_xyz_lab(x) {
  1662. return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
  1663. }
  1664. function d3_xyz_rgb(r) {
  1665. return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
  1666. }
  1667. d3.rgb = d3_rgb;
  1668. function d3_rgb(r, g, b) {
  1669. 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);
  1670. }
  1671. function d3_rgbNumber(value) {
  1672. return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
  1673. }
  1674. function d3_rgbString(value) {
  1675. return d3_rgbNumber(value) + "";
  1676. }
  1677. var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
  1678. d3_rgbPrototype.brighter = function(k) {
  1679. k = Math.pow(.7, arguments.length ? k : 1);
  1680. var r = this.r, g = this.g, b = this.b, i = 30;
  1681. if (!r && !g && !b) return new d3_rgb(i, i, i);
  1682. if (r && r < i) r = i;
  1683. if (g && g < i) g = i;
  1684. if (b && b < i) b = i;
  1685. return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
  1686. };
  1687. d3_rgbPrototype.darker = function(k) {
  1688. k = Math.pow(.7, arguments.length ? k : 1);
  1689. return new d3_rgb(k * this.r, k * this.g, k * this.b);
  1690. };
  1691. d3_rgbPrototype.hsl = function() {
  1692. return d3_rgb_hsl(this.r, this.g, this.b);
  1693. };
  1694. d3_rgbPrototype.toString = function() {
  1695. return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
  1696. };
  1697. function d3_rgb_hex(v) {
  1698. return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
  1699. }
  1700. function d3_rgb_parse(format, rgb, hsl) {
  1701. var r = 0, g = 0, b = 0, m1, m2, color;
  1702. m1 = /([a-z]+)\((.*)\)/.exec(format = format.toLowerCase());
  1703. if (m1) {
  1704. m2 = m1[2].split(",");
  1705. switch (m1[1]) {
  1706. case "hsl":
  1707. {
  1708. return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
  1709. }
  1710. case "rgb":
  1711. {
  1712. return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
  1713. }
  1714. }
  1715. }
  1716. if (color = d3_rgb_names.get(format)) {
  1717. return rgb(color.r, color.g, color.b);
  1718. }
  1719. if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
  1720. if (format.length === 4) {
  1721. r = (color & 3840) >> 4;
  1722. r = r >> 4 | r;
  1723. g = color & 240;
  1724. g = g >> 4 | g;
  1725. b = color & 15;
  1726. b = b << 4 | b;
  1727. } else if (format.length === 7) {
  1728. r = (color & 16711680) >> 16;
  1729. g = (color & 65280) >> 8;
  1730. b = color & 255;
  1731. }
  1732. }
  1733. return rgb(r, g, b);
  1734. }
  1735. function d3_rgb_hsl(r, g, b) {
  1736. 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;
  1737. if (d) {
  1738. s = l < .5 ? d / (max + min) : d / (2 - max - min);
  1739. 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;
  1740. h *= 60;
  1741. } else {
  1742. h = NaN;
  1743. s = l > 0 && l < 1 ? 0 : h;
  1744. }
  1745. return new d3_hsl(h, s, l);
  1746. }
  1747. function d3_rgb_lab(r, g, b) {
  1748. r = d3_rgb_xyz(r);
  1749. g = d3_rgb_xyz(g);
  1750. b = d3_rgb_xyz(b);
  1751. 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);
  1752. return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
  1753. }
  1754. function d3_rgb_xyz(r) {
  1755. return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
  1756. }
  1757. function d3_rgb_parseNumber(c) {
  1758. var f = parseFloat(c);
  1759. return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
  1760. }
  1761. var d3_rgb_names = d3.map({
  1762. aliceblue: 15792383,
  1763. antiquewhite: 16444375,
  1764. aqua: 65535,
  1765. aquamarine: 8388564,
  1766. azure: 15794175,
  1767. beige: 16119260,
  1768. bisque: 16770244,
  1769. black: 0,
  1770. blanchedalmond: 16772045,
  1771. blue: 255,
  1772. blueviolet: 9055202,
  1773. brown: 10824234,
  1774. burlywood: 14596231,
  1775. cadetblue: 6266528,
  1776. chartreuse: 8388352,
  1777. chocolate: 13789470,
  1778. coral: 16744272,
  1779. cornflowerblue: 6591981,
  1780. cornsilk: 16775388,
  1781. crimson: 14423100,
  1782. cyan: 65535,
  1783. darkblue: 139,
  1784. darkcyan: 35723,
  1785. darkgoldenrod: 12092939,
  1786. darkgray: 11119017,
  1787. darkgreen: 25600,
  1788. darkgrey: 11119017,
  1789. darkkhaki: 12433259,
  1790. darkmagenta: 9109643,
  1791. darkolivegreen: 5597999,
  1792. darkorange: 16747520,
  1793. darkorchid: 10040012,
  1794. darkred: 9109504,
  1795. darksalmon: 15308410,
  1796. darkseagreen: 9419919,
  1797. darkslateblue: 4734347,
  1798. darkslategray: 3100495,
  1799. darkslategrey: 3100495,
  1800. darkturquoise: 52945,
  1801. darkviolet: 9699539,
  1802. deeppink: 16716947,
  1803. deepskyblue: 49151,
  1804. dimgray: 6908265,
  1805. dimgrey: 6908265,
  1806. dodgerblue: 2003199,
  1807. firebrick: 11674146,
  1808. floralwhite: 16775920,
  1809. forestgreen: 2263842,
  1810. fuchsia: 16711935,
  1811. gainsboro: 14474460,
  1812. ghostwhite: 16316671,
  1813. gold: 16766720,
  1814. goldenrod: 14329120,
  1815. gray: 8421504,
  1816. green: 32768,
  1817. greenyellow: 11403055,
  1818. grey: 8421504,
  1819. honeydew: 15794160,
  1820. hotpink: 16738740,
  1821. indianred: 13458524,
  1822. indigo: 4915330,
  1823. ivory: 16777200,
  1824. khaki: 15787660,
  1825. lavender: 15132410,
  1826. lavenderblush: 16773365,
  1827. lawngreen: 8190976,
  1828. lemonchiffon: 16775885,
  1829. lightblue: 11393254,
  1830. lightcoral: 15761536,
  1831. lightcyan: 14745599,
  1832. lightgoldenrodyellow: 16448210,
  1833. lightgray: 13882323,
  1834. lightgreen: 9498256,
  1835. lightgrey: 13882323,
  1836. lightpink: 16758465,
  1837. lightsalmon: 16752762,
  1838. lightseagreen: 2142890,
  1839. lightskyblue: 8900346,
  1840. lightslategray: 7833753,
  1841. lightslategrey: 7833753,
  1842. lightsteelblue: 11584734,
  1843. lightyellow: 16777184,
  1844. lime: 65280,
  1845. limegreen: 3329330,
  1846. linen: 16445670,
  1847. magenta: 16711935,
  1848. maroon: 8388608,
  1849. mediumaquamarine: 6737322,
  1850. mediumblue: 205,
  1851. mediumorchid: 12211667,
  1852. mediumpurple: 9662683,
  1853. mediumseagreen: 3978097,
  1854. mediumslateblue: 8087790,
  1855. mediumspringgreen: 64154,
  1856. mediumturquoise: 4772300,
  1857. mediumvioletred: 13047173,
  1858. midnightblue: 1644912,
  1859. mintcream: 16121850,
  1860. mistyrose: 16770273,
  1861. moccasin: 16770229,
  1862. navajowhite: 16768685,
  1863. navy: 128,
  1864. oldlace: 16643558,
  1865. olive: 8421376,
  1866. olivedrab: 7048739,
  1867. orange: 16753920,
  1868. orangered: 16729344,
  1869. orchid: 14315734,
  1870. palegoldenrod: 15657130,
  1871. palegreen: 10025880,
  1872. paleturquoise: 11529966,
  1873. palevioletred: 14381203,
  1874. papayawhip: 16773077,
  1875. peachpuff: 16767673,
  1876. peru: 13468991,
  1877. pink: 16761035,
  1878. plum: 14524637,
  1879. powderblue: 11591910,
  1880. purple: 8388736,
  1881. rebeccapurple: 6697881,
  1882. red: 16711680,
  1883. rosybrown: 12357519,
  1884. royalblue: 4286945,
  1885. saddlebrown: 9127187,
  1886. salmon: 16416882,
  1887. sandybrown: 16032864,
  1888. seagreen: 3050327,
  1889. seashell: 16774638,
  1890. sienna: 10506797,
  1891. silver: 12632256,
  1892. skyblue: 8900331,
  1893. slateblue: 6970061,
  1894. slategray: 7372944,
  1895. slategrey: 7372944,
  1896. snow: 16775930,
  1897. springgreen: 65407,
  1898. steelblue: 4620980,
  1899. tan: 13808780,
  1900. teal: 32896,
  1901. thistle: 14204888,
  1902. tomato: 16737095,
  1903. turquoise: 4251856,
  1904. violet: 15631086,
  1905. wheat: 16113331,
  1906. white: 16777215,
  1907. whitesmoke: 16119285,
  1908. yellow: 16776960,
  1909. yellowgreen: 10145074
  1910. });
  1911. d3_rgb_names.forEach(function(key, value) {
  1912. d3_rgb_names.set(key, d3_rgbNumber(value));
  1913. });
  1914. function d3_functor(v) {
  1915. return typeof v === "function" ? v : function() {
  1916. return v;
  1917. };
  1918. }
  1919. d3.functor = d3_functor;
  1920. d3.xhr = d3_xhrType(d3_identity);
  1921. function d3_xhrType(response) {
  1922. return function(url, mimeType, callback) {
  1923. if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
  1924. mimeType = null;
  1925. return d3_xhr(url, mimeType, response, callback);
  1926. };
  1927. }
  1928. function d3_xhr(url, mimeType, response, callback) {
  1929. var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
  1930. if (this.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
  1931. "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
  1932. request.readyState > 3 && respond();
  1933. };
  1934. function respond() {
  1935. var status = request.status, result;
  1936. if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
  1937. try {
  1938. result = response.call(xhr, request);
  1939. } catch (e) {
  1940. dispatch.error.call(xhr, e);
  1941. return;
  1942. }
  1943. dispatch.load.call(xhr, result);
  1944. } else {
  1945. dispatch.error.call(xhr, request);
  1946. }
  1947. }
  1948. request.onprogress = function(event) {
  1949. var o = d3.event;
  1950. d3.event = event;
  1951. try {
  1952. dispatch.progress.call(xhr, request);
  1953. } finally {
  1954. d3.event = o;
  1955. }
  1956. };
  1957. xhr.header = function(name, value) {
  1958. name = (name + "").toLowerCase();
  1959. if (arguments.length < 2) return headers[name];
  1960. if (value == null) delete headers[name]; else headers[name] = value + "";
  1961. return xhr;
  1962. };
  1963. xhr.mimeType = function(value) {
  1964. if (!arguments.length) return mimeType;
  1965. mimeType = value == null ? null : value + "";
  1966. return xhr;
  1967. };
  1968. xhr.responseType = function(value) {
  1969. if (!arguments.length) return responseType;
  1970. responseType = value;
  1971. return xhr;
  1972. };
  1973. xhr.response = function(value) {
  1974. response = value;
  1975. return xhr;
  1976. };
  1977. [ "get", "post" ].forEach(function(method) {
  1978. xhr[method] = function() {
  1979. return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
  1980. };
  1981. });
  1982. xhr.send = function(method, data, callback) {
  1983. if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
  1984. request.open(method, url, true);
  1985. if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
  1986. if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
  1987. if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
  1988. if (responseType != null) request.responseType = responseType;
  1989. if (callback != null) xhr.on("error", callback).on("load", function(request) {
  1990. callback(null, request);
  1991. });
  1992. dispatch.beforesend.call(xhr, request);
  1993. request.send(data == null ? null : data);
  1994. return xhr;
  1995. };
  1996. xhr.abort = function() {
  1997. request.abort();
  1998. return xhr;
  1999. };
  2000. d3.rebind(xhr, dispatch, "on");
  2001. return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
  2002. }
  2003. function d3_xhr_fixCallback(callback) {
  2004. return callback.length === 1 ? function(error, request) {
  2005. callback(error == null ? request : null);
  2006. } : callback;
  2007. }
  2008. function d3_xhrHasResponse(request) {
  2009. var type = request.responseType;
  2010. return type && type !== "text" ? request.response : request.responseText;
  2011. }
  2012. d3.dsv = function(delimiter, mimeType) {
  2013. var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
  2014. function dsv(url, row, callback) {
  2015. if (arguments.length < 3) callback = row, row = null;
  2016. var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
  2017. xhr.row = function(_) {
  2018. return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
  2019. };
  2020. return xhr;
  2021. }
  2022. function response(request) {
  2023. return dsv.parse(request.responseText);
  2024. }
  2025. function typedResponse(f) {
  2026. return function(request) {
  2027. return dsv.parse(request.responseText, f);
  2028. };
  2029. }
  2030. dsv.parse = function(text, f) {
  2031. var o;
  2032. return dsv.parseRows(text, function(row, i) {
  2033. if (o) return o(row, i - 1);
  2034. var a = new Function("d", "return {" + row.map(function(name, i) {
  2035. return JSON.stringify(name) + ": d[" + i + "]";
  2036. }).join(",") + "}");
  2037. o = f ? function(row, i) {
  2038. return f(a(row), i);
  2039. } : a;
  2040. });
  2041. };
  2042. dsv.parseRows = function(text, f) {
  2043. var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
  2044. function token() {
  2045. if (I >= N) return EOF;
  2046. if (eol) return eol = false, EOL;
  2047. var j = I;
  2048. if (text.charCodeAt(j) === 34) {
  2049. var i = j;
  2050. while (i++ < N) {
  2051. if (text.charCodeAt(i) === 34) {
  2052. if (text.charCodeAt(i + 1) !== 34) break;
  2053. ++i;
  2054. }
  2055. }
  2056. I = i + 2;
  2057. var c = text.charCodeAt(i + 1);
  2058. if (c === 13) {
  2059. eol = true;
  2060. if (text.charCodeAt(i + 2) === 10) ++I;
  2061. } else if (c === 10) {
  2062. eol = true;
  2063. }
  2064. return text.slice(j + 1, i).replace(/""/g, '"');
  2065. }
  2066. while (I < N) {
  2067. var c = text.charCodeAt(I++), k = 1;
  2068. if (c === 10) eol = true; else if (c === 13) {
  2069. eol = true;
  2070. if (text.charCodeAt(I) === 10) ++I, ++k;
  2071. } else if (c !== delimiterCode) continue;
  2072. return text.slice(j, I - k);
  2073. }
  2074. return text.slice(j);
  2075. }
  2076. while ((t = token()) !== EOF) {
  2077. var a = [];
  2078. while (t !== EOL && t !== EOF) {
  2079. a.push(t);
  2080. t = token();
  2081. }
  2082. if (f && (a = f(a, n++)) == null) continue;
  2083. rows.push(a);
  2084. }
  2085. return rows;
  2086. };
  2087. dsv.format = function(rows) {
  2088. if (Array.isArray(rows[0])) return dsv.formatRows(rows);
  2089. var fieldSet = new d3_Set(), fields = [];
  2090. rows.forEach(function(row) {
  2091. for (var field in row) {
  2092. if (!fieldSet.has(field)) {
  2093. fields.push(fieldSet.add(field));
  2094. }
  2095. }
  2096. });
  2097. return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
  2098. return fields.map(function(field) {
  2099. return formatValue(row[field]);
  2100. }).join(delimiter);
  2101. })).join("\n");
  2102. };
  2103. dsv.formatRows = function(rows) {
  2104. return rows.map(formatRow).join("\n");
  2105. };
  2106. function formatRow(row) {
  2107. return row.map(formatValue).join(delimiter);
  2108. }
  2109. function formatValue(text) {
  2110. return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
  2111. }
  2112. return dsv;
  2113. };
  2114. d3.csv = d3.dsv(",", "text/csv");
  2115. d3.tsv = d3.dsv(" ", "text/tab-separated-values");
  2116. var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_active, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
  2117. setTimeout(callback, 17);
  2118. };
  2119. d3.timer = function(callback, delay, then) {
  2120. var n = arguments.length;
  2121. if (n < 2) delay = 0;
  2122. if (n < 3) then = Date.now();
  2123. var time = then + delay, timer = {
  2124. c: callback,
  2125. t: time,
  2126. f: false,
  2127. n: null
  2128. };
  2129. if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
  2130. d3_timer_queueTail = timer;
  2131. if (!d3_timer_interval) {
  2132. d3_timer_timeout = clearTimeout(d3_timer_timeout);
  2133. d3_timer_interval = 1;
  2134. d3_timer_frame(d3_timer_step);
  2135. }
  2136. };
  2137. function d3_timer_step() {
  2138. var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
  2139. if (delay > 24) {
  2140. if (isFinite(delay)) {
  2141. clearTimeout(d3_timer_timeout);
  2142. d3_timer_timeout = setTimeout(d3_timer_step, delay);
  2143. }
  2144. d3_timer_interval = 0;
  2145. } else {
  2146. d3_timer_interval = 1;
  2147. d3_timer_frame(d3_timer_step);
  2148. }
  2149. }
  2150. d3.timer.flush = function() {
  2151. d3_timer_mark();
  2152. d3_timer_sweep();
  2153. };
  2154. function d3_timer_mark() {
  2155. var now = Date.now();
  2156. d3_timer_active = d3_timer_queueHead;
  2157. while (d3_timer_active) {
  2158. if (now >= d3_timer_active.t) d3_timer_active.f = d3_timer_active.c(now - d3_timer_active.t);
  2159. d3_timer_active = d3_timer_active.n;
  2160. }
  2161. return now;
  2162. }
  2163. function d3_timer_sweep() {
  2164. var t0, t1 = d3_timer_queueHead, time = Infinity;
  2165. while (t1) {
  2166. if (t1.f) {
  2167. t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
  2168. } else {
  2169. if (t1.t < time) time = t1.t;
  2170. t1 = (t0 = t1).n;
  2171. }
  2172. }
  2173. d3_timer_queueTail = t0;
  2174. return time;
  2175. }
  2176. function d3_format_precision(x, p) {
  2177. return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
  2178. }
  2179. d3.round = function(x, n) {
  2180. return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
  2181. };
  2182. var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
  2183. d3.formatPrefix = function(value, precision) {
  2184. var i = 0;
  2185. if (value) {
  2186. if (value < 0) value *= -1;
  2187. if (precision) value = d3.round(value, d3_format_precision(value, precision));
  2188. i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
  2189. i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
  2190. }
  2191. return d3_formatPrefixes[8 + i / 3];
  2192. };
  2193. function d3_formatPrefix(d, i) {
  2194. var k = Math.pow(10, abs(8 - i) * 3);
  2195. return {
  2196. scale: i > 8 ? function(d) {
  2197. return d / k;
  2198. } : function(d) {
  2199. return d * k;
  2200. },
  2201. symbol: d
  2202. };
  2203. }
  2204. function d3_locale_numberFormat(locale) {
  2205. 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) {
  2206. var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
  2207. while (i > 0 && g > 0) {
  2208. if (length + g + 1 > width) g = Math.max(1, width - length);
  2209. t.push(value.substring(i -= g, i + g));
  2210. if ((length += g + 1) > width) break;
  2211. g = locale_grouping[j = (j + 1) % locale_grouping.length];
  2212. }
  2213. return t.reverse().join(locale_thousands);
  2214. } : d3_identity;
  2215. return function(specifier) {
  2216. 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;
  2217. if (precision) precision = +precision.substring(1);
  2218. if (zfill || fill === "0" && align === "=") {
  2219. zfill = fill = "0";
  2220. align = "=";
  2221. }
  2222. switch (type) {
  2223. case "n":
  2224. comma = true;
  2225. type = "g";
  2226. break;
  2227. case "%":
  2228. scale = 100;
  2229. suffix = "%";
  2230. type = "f";
  2231. break;
  2232. case "p":
  2233. scale = 100;
  2234. suffix = "%";
  2235. type = "r";
  2236. break;
  2237. case "b":
  2238. case "o":
  2239. case "x":
  2240. case "X":
  2241. if (symbol === "#") prefix = "0" + type.toLowerCase();
  2242. case "c":
  2243. exponent = false;
  2244. case "d":
  2245. integer = true;
  2246. precision = 0;
  2247. break;
  2248. case "s":
  2249. scale = -1;
  2250. type = "r";
  2251. break;
  2252. }
  2253. if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
  2254. if (type == "r" && !precision) type = "g";
  2255. if (precision != null) {
  2256. 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));
  2257. }
  2258. type = d3_format_types.get(type) || d3_format_typeDefault;
  2259. var zcomma = zfill && comma;
  2260. return function(value) {
  2261. var fullSuffix = suffix;
  2262. if (integer && value % 1) return "";
  2263. var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
  2264. if (scale < 0) {
  2265. var unit = d3.formatPrefix(value, precision);
  2266. value = unit.scale(value);
  2267. fullSuffix = unit.symbol + suffix;
  2268. } else {
  2269. value *= scale;
  2270. }
  2271. value = type(value, precision);
  2272. var i = value.lastIndexOf("."), before, after;
  2273. if (i < 0) {
  2274. var j = exponent ? value.lastIndexOf("e") : -1;
  2275. if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
  2276. } else {
  2277. before = value.substring(0, i);
  2278. after = locale_decimal + value.substring(i + 1);
  2279. }
  2280. if (!zfill && comma) before = formatGroup(before, Infinity);
  2281. var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
  2282. if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
  2283. negative += prefix;
  2284. value = before + after;
  2285. 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;
  2286. };
  2287. };
  2288. }
  2289. var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
  2290. var d3_format_types = d3.map({
  2291. b: function(x) {
  2292. return x.toString(2);
  2293. },
  2294. c: function(x) {
  2295. return String.fromCharCode(x);
  2296. },
  2297. o: function(x) {
  2298. return x.toString(8);
  2299. },
  2300. x: function(x) {
  2301. return x.toString(16);
  2302. },
  2303. X: function(x) {
  2304. return x.toString(16).toUpperCase();
  2305. },
  2306. g: function(x, p) {
  2307. return x.toPrecision(p);
  2308. },
  2309. e: function(x, p) {
  2310. return x.toExponential(p);
  2311. },
  2312. f: function(x, p) {
  2313. return x.toFixed(p);
  2314. },
  2315. r: function(x, p) {
  2316. 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))));
  2317. }
  2318. });
  2319. function d3_format_typeDefault(x) {
  2320. return x + "";
  2321. }
  2322. var d3_time = d3.time = {}, d3_date = Date;
  2323. function d3_date_utc() {
  2324. this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
  2325. }
  2326. d3_date_utc.prototype = {
  2327. getDate: function() {
  2328. return this._.getUTCDate();
  2329. },
  2330. getDay: function() {
  2331. return this._.getUTCDay();
  2332. },
  2333. getFullYear: function() {
  2334. return this._.getUTCFullYear();
  2335. },
  2336. getHours: function() {
  2337. return this._.getUTCHours();
  2338. },
  2339. getMilliseconds: function() {
  2340. return this._.getUTCMilliseconds();
  2341. },
  2342. getMinutes: function() {
  2343. return this._.getUTCMinutes();
  2344. },
  2345. getMonth: function() {
  2346. return this._.getUTCMonth();
  2347. },
  2348. getSeconds: function() {
  2349. return this._.getUTCSeconds();
  2350. },
  2351. getTime: function() {
  2352. return this._.getTime();
  2353. },
  2354. getTimezoneOffset: function() {
  2355. return 0;
  2356. },
  2357. valueOf: function() {
  2358. return this._.valueOf();
  2359. },
  2360. setDate: function() {
  2361. d3_time_prototype.setUTCDate.apply(this._, arguments);
  2362. },
  2363. setDay: function() {
  2364. d3_time_prototype.setUTCDay.apply(this._, arguments);
  2365. },
  2366. setFullYear: function() {
  2367. d3_time_prototype.setUTCFullYear.apply(this._, arguments);
  2368. },
  2369. setHours: function() {
  2370. d3_time_prototype.setUTCHours.apply(this._, arguments);
  2371. },
  2372. setMilliseconds: function() {
  2373. d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
  2374. },
  2375. setMinutes: function() {
  2376. d3_time_prototype.setUTCMinutes.apply(this._, arguments);
  2377. },
  2378. setMonth: function() {
  2379. d3_time_prototype.setUTCMonth.apply(this._, arguments);
  2380. },
  2381. setSeconds: function() {
  2382. d3_time_prototype.setUTCSeconds.apply(this._, arguments);
  2383. },
  2384. setTime: function() {
  2385. d3_time_prototype.setTime.apply(this._, arguments);
  2386. }
  2387. };
  2388. var d3_time_prototype = Date.prototype;
  2389. function d3_time_interval(local, step, number) {
  2390. function round(date) {
  2391. var d0 = local(date), d1 = offset(d0, 1);
  2392. return date - d0 < d1 - date ? d0 : d1;
  2393. }
  2394. function ceil(date) {
  2395. step(date = local(new d3_date(date - 1)), 1);
  2396. return date;
  2397. }
  2398. function offset(date, k) {
  2399. step(date = new d3_date(+date), k);
  2400. return date;
  2401. }
  2402. function range(t0, t1, dt) {
  2403. var time = ceil(t0), times = [];
  2404. if (dt > 1) {
  2405. while (time < t1) {
  2406. if (!(number(time) % dt)) times.push(new Date(+time));
  2407. step(time, 1);
  2408. }
  2409. } else {
  2410. while (time < t1) times.push(new Date(+time)), step(time, 1);
  2411. }
  2412. return times;
  2413. }
  2414. function range_utc(t0, t1, dt) {
  2415. try {
  2416. d3_date = d3_date_utc;
  2417. var utc = new d3_date_utc();
  2418. utc._ = t0;
  2419. return range(utc, t1, dt);
  2420. } finally {
  2421. d3_date = Date;
  2422. }
  2423. }
  2424. local.floor = local;
  2425. local.round = round;
  2426. local.ceil = ceil;
  2427. local.offset = offset;
  2428. local.range = range;
  2429. var utc = local.utc = d3_time_interval_utc(local);
  2430. utc.floor = utc;
  2431. utc.round = d3_time_interval_utc(round);
  2432. utc.ceil = d3_time_interval_utc(ceil);
  2433. utc.offset = d3_time_interval_utc(offset);
  2434. utc.range = range_utc;
  2435. return local;
  2436. }
  2437. function d3_time_interval_utc(method) {
  2438. return function(date, k) {
  2439. try {
  2440. d3_date = d3_date_utc;
  2441. var utc = new d3_date_utc();
  2442. utc._ = date;
  2443. return method(utc, k)._;
  2444. } finally {
  2445. d3_date = Date;
  2446. }
  2447. };
  2448. }
  2449. d3_time.year = d3_time_interval(function(date) {
  2450. date = d3_time.day(date);
  2451. date.setMonth(0, 1);
  2452. return date;
  2453. }, function(date, offset) {
  2454. date.setFullYear(date.getFullYear() + offset);
  2455. }, function(date) {
  2456. return date.getFullYear();
  2457. });
  2458. d3_time.years = d3_time.year.range;
  2459. d3_time.years.utc = d3_time.year.utc.range;
  2460. d3_time.day = d3_time_interval(function(date) {
  2461. var day = new d3_date(2e3, 0);
  2462. day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
  2463. return day;
  2464. }, function(date, offset) {
  2465. date.setDate(date.getDate() + offset);
  2466. }, function(date) {
  2467. return date.getDate() - 1;
  2468. });
  2469. d3_time.days = d3_time.day.range;
  2470. d3_time.days.utc = d3_time.day.utc.range;
  2471. d3_time.dayOfYear = function(date) {
  2472. var year = d3_time.year(date);
  2473. return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
  2474. };
  2475. [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
  2476. i = 7 - i;
  2477. var interval = d3_time[day] = d3_time_interval(function(date) {
  2478. (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
  2479. return date;
  2480. }, function(date, offset) {
  2481. date.setDate(date.getDate() + Math.floor(offset) * 7);
  2482. }, function(date) {
  2483. var day = d3_time.year(date).getDay();
  2484. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
  2485. });
  2486. d3_time[day + "s"] = interval.range;
  2487. d3_time[day + "s"].utc = interval.utc.range;
  2488. d3_time[day + "OfYear"] = function(date) {
  2489. var day = d3_time.year(date).getDay();
  2490. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
  2491. };
  2492. });
  2493. d3_time.week = d3_time.sunday;
  2494. d3_time.weeks = d3_time.sunday.range;
  2495. d3_time.weeks.utc = d3_time.sunday.utc.range;
  2496. d3_time.weekOfYear = d3_time.sundayOfYear;
  2497. function d3_locale_timeFormat(locale) {
  2498. 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;
  2499. function d3_time_format(template) {
  2500. var n = template.length;
  2501. function format(date) {
  2502. var string = [], i = -1, j = 0, c, p, f;
  2503. while (++i < n) {
  2504. if (template.charCodeAt(i) === 37) {
  2505. string.push(template.slice(j, i));
  2506. if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
  2507. if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
  2508. string.push(c);
  2509. j = i + 1;
  2510. }
  2511. }
  2512. string.push(template.slice(j, i));
  2513. return string.join("");
  2514. }
  2515. format.parse = function(string) {
  2516. var d = {
  2517. y: 1900,
  2518. m: 0,
  2519. d: 1,
  2520. H: 0,
  2521. M: 0,
  2522. S: 0,
  2523. L: 0,
  2524. Z: null
  2525. }, i = d3_time_parse(d, template, string, 0);
  2526. if (i != string.length) return null;
  2527. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  2528. var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
  2529. if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
  2530. date.setFullYear(d.y, 0, 1);
  2531. 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);
  2532. } else date.setFullYear(d.y, d.m, d.d);
  2533. date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
  2534. return localZ ? date._ : date;
  2535. };
  2536. format.toString = function() {
  2537. return template;
  2538. };
  2539. return format;
  2540. }
  2541. function d3_time_parse(date, template, string, j) {
  2542. var c, p, t, i = 0, n = template.length, m = string.length;
  2543. while (i < n) {
  2544. if (j >= m) return -1;
  2545. c = template.charCodeAt(i++);
  2546. if (c === 37) {
  2547. t = template.charAt(i++);
  2548. p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
  2549. if (!p || (j = p(date, string, j)) < 0) return -1;
  2550. } else if (c != string.charCodeAt(j++)) {
  2551. return -1;
  2552. }
  2553. }
  2554. return j;
  2555. }
  2556. d3_time_format.utc = function(template) {
  2557. var local = d3_time_format(template);
  2558. function format(date) {
  2559. try {
  2560. d3_date = d3_date_utc;
  2561. var utc = new d3_date();
  2562. utc._ = date;
  2563. return local(utc);
  2564. } finally {
  2565. d3_date = Date;
  2566. }
  2567. }
  2568. format.parse = function(string) {
  2569. try {
  2570. d3_date = d3_date_utc;
  2571. var date = local.parse(string);
  2572. return date && date._;
  2573. } finally {
  2574. d3_date = Date;
  2575. }
  2576. };
  2577. format.toString = local.toString;
  2578. return format;
  2579. };
  2580. d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
  2581. 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);
  2582. locale_periods.forEach(function(p, i) {
  2583. d3_time_periodLookup.set(p.toLowerCase(), i);
  2584. });
  2585. var d3_time_formats = {
  2586. a: function(d) {
  2587. return locale_shortDays[d.getDay()];
  2588. },
  2589. A: function(d) {
  2590. return locale_days[d.getDay()];
  2591. },
  2592. b: function(d) {
  2593. return locale_shortMonths[d.getMonth()];
  2594. },
  2595. B: function(d) {
  2596. return locale_months[d.getMonth()];
  2597. },
  2598. c: d3_time_format(locale_dateTime),
  2599. d: function(d, p) {
  2600. return d3_time_formatPad(d.getDate(), p, 2);
  2601. },
  2602. e: function(d, p) {
  2603. return d3_time_formatPad(d.getDate(), p, 2);
  2604. },
  2605. H: function(d, p) {
  2606. return d3_time_formatPad(d.getHours(), p, 2);
  2607. },
  2608. I: function(d, p) {
  2609. return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
  2610. },
  2611. j: function(d, p) {
  2612. return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
  2613. },
  2614. L: function(d, p) {
  2615. return d3_time_formatPad(d.getMilliseconds(), p, 3);
  2616. },
  2617. m: function(d, p) {
  2618. return d3_time_formatPad(d.getMonth() + 1, p, 2);
  2619. },
  2620. M: function(d, p) {
  2621. return d3_time_formatPad(d.getMinutes(), p, 2);
  2622. },
  2623. p: function(d) {
  2624. return locale_periods[+(d.getHours() >= 12)];
  2625. },
  2626. S: function(d, p) {
  2627. return d3_time_formatPad(d.getSeconds(), p, 2);
  2628. },
  2629. U: function(d, p) {
  2630. return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
  2631. },
  2632. w: function(d) {
  2633. return d.getDay();
  2634. },
  2635. W: function(d, p) {
  2636. return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
  2637. },
  2638. x: d3_time_format(locale_date),
  2639. X: d3_time_format(locale_time),
  2640. y: function(d, p) {
  2641. return d3_time_formatPad(d.getFullYear() % 100, p, 2);
  2642. },
  2643. Y: function(d, p) {
  2644. return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
  2645. },
  2646. Z: d3_time_zone,
  2647. "%": function() {
  2648. return "%";
  2649. }
  2650. };
  2651. var d3_time_parsers = {
  2652. a: d3_time_parseWeekdayAbbrev,
  2653. A: d3_time_parseWeekday,
  2654. b: d3_time_parseMonthAbbrev,
  2655. B: d3_time_parseMonth,
  2656. c: d3_time_parseLocaleFull,
  2657. d: d3_time_parseDay,
  2658. e: d3_time_parseDay,
  2659. H: d3_time_parseHour24,
  2660. I: d3_time_parseHour24,
  2661. j: d3_time_parseDayOfYear,
  2662. L: d3_time_parseMilliseconds,
  2663. m: d3_time_parseMonthNumber,
  2664. M: d3_time_parseMinutes,
  2665. p: d3_time_parseAmPm,
  2666. S: d3_time_parseSeconds,
  2667. U: d3_time_parseWeekNumberSunday,
  2668. w: d3_time_parseWeekdayNumber,
  2669. W: d3_time_parseWeekNumberMonday,
  2670. x: d3_time_parseLocaleDate,
  2671. X: d3_time_parseLocaleTime,
  2672. y: d3_time_parseYear,
  2673. Y: d3_time_parseFullYear,
  2674. Z: d3_time_parseZone,
  2675. "%": d3_time_parseLiteralPercent
  2676. };
  2677. function d3_time_parseWeekdayAbbrev(date, string, i) {
  2678. d3_time_dayAbbrevRe.lastIndex = 0;
  2679. var n = d3_time_dayAbbrevRe.exec(string.slice(i));
  2680. return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2681. }
  2682. function d3_time_parseWeekday(date, string, i) {
  2683. d3_time_dayRe.lastIndex = 0;
  2684. var n = d3_time_dayRe.exec(string.slice(i));
  2685. return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2686. }
  2687. function d3_time_parseMonthAbbrev(date, string, i) {
  2688. d3_time_monthAbbrevRe.lastIndex = 0;
  2689. var n = d3_time_monthAbbrevRe.exec(string.slice(i));
  2690. return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2691. }
  2692. function d3_time_parseMonth(date, string, i) {
  2693. d3_time_monthRe.lastIndex = 0;
  2694. var n = d3_time_monthRe.exec(string.slice(i));
  2695. return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  2696. }
  2697. function d3_time_parseLocaleFull(date, string, i) {
  2698. return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
  2699. }
  2700. function d3_time_parseLocaleDate(date, string, i) {
  2701. return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
  2702. }
  2703. function d3_time_parseLocaleTime(date, string, i) {
  2704. return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
  2705. }
  2706. function d3_time_parseAmPm(date, string, i) {
  2707. var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
  2708. return n == null ? -1 : (date.p = n, i);
  2709. }
  2710. return d3_time_format;
  2711. }
  2712. var d3_time_formatPads = {
  2713. "-": "",
  2714. _: " ",
  2715. "0": "0"
  2716. }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
  2717. function d3_time_formatPad(value, fill, width) {
  2718. var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
  2719. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  2720. }
  2721. function d3_time_formatRe(names) {
  2722. return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
  2723. }
  2724. function d3_time_formatLookup(names) {
  2725. var map = new d3_Map(), i = -1, n = names.length;
  2726. while (++i < n) map.set(names[i].toLowerCase(), i);
  2727. return map;
  2728. }
  2729. function d3_time_parseWeekdayNumber(date, string, i) {
  2730. d3_time_numberRe.lastIndex = 0;
  2731. var n = d3_time_numberRe.exec(string.slice(i, i + 1));
  2732. return n ? (date.w = +n[0], i + n[0].length) : -1;
  2733. }
  2734. function d3_time_parseWeekNumberSunday(date, string, i) {
  2735. d3_time_numberRe.lastIndex = 0;
  2736. var n = d3_time_numberRe.exec(string.slice(i));
  2737. return n ? (date.U = +n[0], i + n[0].length) : -1;
  2738. }
  2739. function d3_time_parseWeekNumberMonday(date, string, i) {
  2740. d3_time_numberRe.lastIndex = 0;
  2741. var n = d3_time_numberRe.exec(string.slice(i));
  2742. return n ? (date.W = +n[0], i + n[0].length) : -1;
  2743. }
  2744. function d3_time_parseFullYear(date, string, i) {
  2745. d3_time_numberRe.lastIndex = 0;
  2746. var n = d3_time_numberRe.exec(string.slice(i, i + 4));
  2747. return n ? (date.y = +n[0], i + n[0].length) : -1;
  2748. }
  2749. function d3_time_parseYear(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.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
  2753. }
  2754. function d3_time_parseZone(date, string, i) {
  2755. return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
  2756. i + 5) : -1;
  2757. }
  2758. function d3_time_expandYear(d) {
  2759. return d + (d > 68 ? 1900 : 2e3);
  2760. }
  2761. function d3_time_parseMonthNumber(date, string, i) {
  2762. d3_time_numberRe.lastIndex = 0;
  2763. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2764. return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
  2765. }
  2766. function d3_time_parseDay(date, string, i) {
  2767. d3_time_numberRe.lastIndex = 0;
  2768. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2769. return n ? (date.d = +n[0], i + n[0].length) : -1;
  2770. }
  2771. function d3_time_parseDayOfYear(date, string, i) {
  2772. d3_time_numberRe.lastIndex = 0;
  2773. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  2774. return n ? (date.j = +n[0], i + n[0].length) : -1;
  2775. }
  2776. function d3_time_parseHour24(date, string, i) {
  2777. d3_time_numberRe.lastIndex = 0;
  2778. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2779. return n ? (date.H = +n[0], i + n[0].length) : -1;
  2780. }
  2781. function d3_time_parseMinutes(date, string, i) {
  2782. d3_time_numberRe.lastIndex = 0;
  2783. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2784. return n ? (date.M = +n[0], i + n[0].length) : -1;
  2785. }
  2786. function d3_time_parseSeconds(date, string, i) {
  2787. d3_time_numberRe.lastIndex = 0;
  2788. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  2789. return n ? (date.S = +n[0], i + n[0].length) : -1;
  2790. }
  2791. function d3_time_parseMilliseconds(date, string, i) {
  2792. d3_time_numberRe.lastIndex = 0;
  2793. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  2794. return n ? (date.L = +n[0], i + n[0].length) : -1;
  2795. }
  2796. function d3_time_zone(d) {
  2797. var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
  2798. return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
  2799. }
  2800. function d3_time_parseLiteralPercent(date, string, i) {
  2801. d3_time_percentRe.lastIndex = 0;
  2802. var n = d3_time_percentRe.exec(string.slice(i, i + 1));
  2803. return n ? i + n[0].length : -1;
  2804. }
  2805. function d3_time_formatMulti(formats) {
  2806. var n = formats.length, i = -1;
  2807. while (++i < n) formats[i][0] = this(formats[i][0]);
  2808. return function(date) {
  2809. var i = 0, f = formats[i];
  2810. while (!f[1](date)) f = formats[++i];
  2811. return f[0](date);
  2812. };
  2813. }
  2814. d3.locale = function(locale) {
  2815. return {
  2816. numberFormat: d3_locale_numberFormat(locale),
  2817. timeFormat: d3_locale_timeFormat(locale)
  2818. };
  2819. };
  2820. var d3_locale_enUS = d3.locale({
  2821. decimal: ".",
  2822. thousands: ",",
  2823. grouping: [ 3 ],
  2824. currency: [ "$", "" ],
  2825. dateTime: "%a %b %e %X %Y",
  2826. date: "%m/%d/%Y",
  2827. time: "%H:%M:%S",
  2828. periods: [ "AM", "PM" ],
  2829. days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
  2830. shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
  2831. months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
  2832. shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
  2833. });
  2834. d3.format = d3_locale_enUS.numberFormat;
  2835. d3.geo = {};
  2836. function d3_adder() {}
  2837. d3_adder.prototype = {
  2838. s: 0,
  2839. t: 0,
  2840. add: function(y) {
  2841. d3_adderSum(y, this.t, d3_adderTemp);
  2842. d3_adderSum(d3_adderTemp.s, this.s, this);
  2843. if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
  2844. },
  2845. reset: function() {
  2846. this.s = this.t = 0;
  2847. },
  2848. valueOf: function() {
  2849. return this.s;
  2850. }
  2851. };
  2852. var d3_adderTemp = new d3_adder();
  2853. function d3_adderSum(a, b, o) {
  2854. var x = o.s = a + b, bv = x - a, av = x - bv;
  2855. o.t = a - av + (b - bv);
  2856. }
  2857. d3.geo.stream = function(object, listener) {
  2858. if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
  2859. d3_geo_streamObjectType[object.type](object, listener);
  2860. } else {
  2861. d3_geo_streamGeometry(object, listener);
  2862. }
  2863. };
  2864. function d3_geo_streamGeometry(geometry, listener) {
  2865. if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
  2866. d3_geo_streamGeometryType[geometry.type](geometry, listener);
  2867. }
  2868. }
  2869. var d3_geo_streamObjectType = {
  2870. Feature: function(feature, listener) {
  2871. d3_geo_streamGeometry(feature.geometry, listener);
  2872. },
  2873. FeatureCollection: function(object, listener) {
  2874. var features = object.features, i = -1, n = features.length;
  2875. while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
  2876. }
  2877. };
  2878. var d3_geo_streamGeometryType = {
  2879. Sphere: function(object, listener) {
  2880. listener.sphere();
  2881. },
  2882. Point: function(object, listener) {
  2883. object = object.coordinates;
  2884. listener.point(object[0], object[1], object[2]);
  2885. },
  2886. MultiPoint: function(object, listener) {
  2887. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2888. while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
  2889. },
  2890. LineString: function(object, listener) {
  2891. d3_geo_streamLine(object.coordinates, listener, 0);
  2892. },
  2893. MultiLineString: function(object, listener) {
  2894. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2895. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
  2896. },
  2897. Polygon: function(object, listener) {
  2898. d3_geo_streamPolygon(object.coordinates, listener);
  2899. },
  2900. MultiPolygon: function(object, listener) {
  2901. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  2902. while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
  2903. },
  2904. GeometryCollection: function(object, listener) {
  2905. var geometries = object.geometries, i = -1, n = geometries.length;
  2906. while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
  2907. }
  2908. };
  2909. function d3_geo_streamLine(coordinates, listener, closed) {
  2910. var i = -1, n = coordinates.length - closed, coordinate;
  2911. listener.lineStart();
  2912. while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
  2913. listener.lineEnd();
  2914. }
  2915. function d3_geo_streamPolygon(coordinates, listener) {
  2916. var i = -1, n = coordinates.length;
  2917. listener.polygonStart();
  2918. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
  2919. listener.polygonEnd();
  2920. }
  2921. d3.geo.area = function(object) {
  2922. d3_geo_areaSum = 0;
  2923. d3.geo.stream(object, d3_geo_area);
  2924. return d3_geo_areaSum;
  2925. };
  2926. var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
  2927. var d3_geo_area = {
  2928. sphere: function() {
  2929. d3_geo_areaSum += 4 * π;
  2930. },
  2931. point: d3_noop,
  2932. lineStart: d3_noop,
  2933. lineEnd: d3_noop,
  2934. polygonStart: function() {
  2935. d3_geo_areaRingSum.reset();
  2936. d3_geo_area.lineStart = d3_geo_areaRingStart;
  2937. },
  2938. polygonEnd: function() {
  2939. var area = 2 * d3_geo_areaRingSum;
  2940. d3_geo_areaSum += area < 0 ? 4 * π + area : area;
  2941. d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
  2942. }
  2943. };
  2944. function d3_geo_areaRingStart() {
  2945. var λ00, φ00, λ0, cosφ0, sinφ0;
  2946. d3_geo_area.point = function(λ, φ) {
  2947. d3_geo_area.point = nextPoint;
  2948. λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
  2949. sinφ0 = Math.sin(φ);
  2950. };
  2951. function nextPoint(λ, φ) {
  2952. λ *= d3_radians;
  2953. φ = φ * d3_radians / 2 + π / 4;
  2954. var = λ - λ0, sdλ = >= 0 ? 1 : -1, adλ = sdλ * , cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(adλ), v = k * sdλ * Math.sin(adλ);
  2955. d3_geo_areaRingSum.add(Math.atan2(v, u));
  2956. λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
  2957. }
  2958. d3_geo_area.lineEnd = function() {
  2959. nextPoint(λ00, φ00);
  2960. };
  2961. }
  2962. function d3_geo_cartesian(spherical) {
  2963. var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
  2964. return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
  2965. }
  2966. function d3_geo_cartesianDot(a, b) {
  2967. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  2968. }
  2969. function d3_geo_cartesianCross(a, b) {
  2970. 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] ];
  2971. }
  2972. function d3_geo_cartesianAdd(a, b) {
  2973. a[0] += b[0];
  2974. a[1] += b[1];
  2975. a[2] += b[2];
  2976. }
  2977. function d3_geo_cartesianScale(vector, k) {
  2978. return [ vector[0] * k, vector[1] * k, vector[2] * k ];
  2979. }
  2980. function d3_geo_cartesianNormalize(d) {
  2981. var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  2982. d[0] /= l;
  2983. d[1] /= l;
  2984. d[2] /= l;
  2985. }
  2986. function d3_geo_spherical(cartesian) {
  2987. return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
  2988. }
  2989. function d3_geo_sphericalEqual(a, b) {
  2990. return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
  2991. }
  2992. d3.geo.bounds = function() {
  2993. var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
  2994. var bound = {
  2995. point: point,
  2996. lineStart: lineStart,
  2997. lineEnd: lineEnd,
  2998. polygonStart: function() {
  2999. bound.point = ringPoint;
  3000. bound.lineStart = ringStart;
  3001. bound.lineEnd = ringEnd;
  3002. dλSum = 0;
  3003. d3_geo_area.polygonStart();
  3004. },
  3005. polygonEnd: function() {
  3006. d3_geo_area.polygonEnd();
  3007. bound.point = point;
  3008. bound.lineStart = lineStart;
  3009. bound.lineEnd = lineEnd;
  3010. if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
  3011. range[0] = λ0, range[1] = λ1;
  3012. }
  3013. };
  3014. function point(λ, φ) {
  3015. ranges.push(range = [ λ0 = λ, λ1 = λ ]);
  3016. if (φ < φ0) φ0 = φ;
  3017. if (φ > φ1) φ1 = φ;
  3018. }
  3019. function linePoint(λ, φ) {
  3020. var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
  3021. if (p0) {
  3022. var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
  3023. d3_geo_cartesianNormalize(inflection);
  3024. inflection = d3_geo_spherical(inflection);
  3025. var = λ - λ_, s = > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs() > 180;
  3026. if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  3027. var φi = inflection[1] * d3_degrees;
  3028. if (φi > φ1) φ1 = φi;
  3029. } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  3030. var φi = -inflection[1] * d3_degrees;
  3031. if (φi < φ0) φ0 = φi;
  3032. } else {
  3033. if (φ < φ0) φ0 = φ;
  3034. if (φ > φ1) φ1 = φ;
  3035. }
  3036. if (antimeridian) {
  3037. if (λ < λ_) {
  3038. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3039. } else {
  3040. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3041. }
  3042. } else {
  3043. if (λ1 >= λ0) {
  3044. if (λ < λ0) λ0 = λ;
  3045. if (λ > λ1) λ1 = λ;
  3046. } else {
  3047. if (λ > λ_) {
  3048. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3049. } else {
  3050. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3051. }
  3052. }
  3053. }
  3054. } else {
  3055. point(λ, φ);
  3056. }
  3057. p0 = p, λ_ = λ;
  3058. }
  3059. function lineStart() {
  3060. bound.point = linePoint;
  3061. }
  3062. function lineEnd() {
  3063. range[0] = λ0, range[1] = λ1;
  3064. bound.point = point;
  3065. p0 = null;
  3066. }
  3067. function ringPoint(λ, φ) {
  3068. if (p0) {
  3069. var = λ - λ_;
  3070. dλSum += abs() > 180 ? + ( > 0 ? 360 : -360) : ;
  3071. } else λ__ = λ, φ__ = φ;
  3072. d3_geo_area.point(λ, φ);
  3073. linePoint(λ, φ);
  3074. }
  3075. function ringStart() {
  3076. d3_geo_area.lineStart();
  3077. }
  3078. function ringEnd() {
  3079. ringPoint(λ__, φ__);
  3080. d3_geo_area.lineEnd();
  3081. if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
  3082. range[0] = λ0, range[1] = λ1;
  3083. p0 = null;
  3084. }
  3085. function angle(λ0, λ1) {
  3086. return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
  3087. }
  3088. function compareRanges(a, b) {
  3089. return a[0] - b[0];
  3090. }
  3091. function withinRange(x, range) {
  3092. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  3093. }
  3094. return function(feature) {
  3095. φ1 = λ1 = -(λ0 = φ0 = Infinity);
  3096. ranges = [];
  3097. d3.geo.stream(feature, bound);
  3098. var n = ranges.length;
  3099. if (n) {
  3100. ranges.sort(compareRanges);
  3101. for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
  3102. b = ranges[i];
  3103. if (withinRange(b[0], a) || withinRange(b[1], a)) {
  3104. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  3105. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  3106. } else {
  3107. merged.push(a = b);
  3108. }
  3109. }
  3110. var best = -Infinity, ;
  3111. for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
  3112. b = merged[i];
  3113. if (( = angle(a[1], b[0])) > best) best = , λ0 = b[0], λ1 = a[1];
  3114. }
  3115. }
  3116. ranges = range = null;
  3117. return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
  3118. };
  3119. }();
  3120. d3.geo.centroid = function(object) {
  3121. 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;
  3122. d3.geo.stream(object, d3_geo_centroid);
  3123. var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
  3124. if (m < ε2) {
  3125. x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
  3126. if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
  3127. m = x * x + y * y + z * z;
  3128. if (m < ε2) return [ NaN, NaN ];
  3129. }
  3130. return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
  3131. };
  3132. 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;
  3133. var d3_geo_centroid = {
  3134. sphere: d3_noop,
  3135. point: d3_geo_centroidPoint,
  3136. lineStart: d3_geo_centroidLineStart,
  3137. lineEnd: d3_geo_centroidLineEnd,
  3138. polygonStart: function() {
  3139. d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
  3140. },
  3141. polygonEnd: function() {
  3142. d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
  3143. }
  3144. };
  3145. function d3_geo_centroidPoint(λ, φ) {
  3146. λ *= d3_radians;
  3147. var cosφ = Math.cos(φ *= d3_radians);
  3148. d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
  3149. }
  3150. function d3_geo_centroidPointXYZ(x, y, z) {
  3151. ++d3_geo_centroidW0;
  3152. d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
  3153. d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
  3154. d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
  3155. }
  3156. function d3_geo_centroidLineStart() {
  3157. var x0, y0, z0;
  3158. d3_geo_centroid.point = function(λ, φ) {
  3159. λ *= d3_radians;
  3160. var cosφ = Math.cos(φ *= d3_radians);
  3161. x0 = cosφ * Math.cos(λ);
  3162. y0 = cosφ * Math.sin(λ);
  3163. z0 = Math.sin(φ);
  3164. d3_geo_centroid.point = nextPoint;
  3165. d3_geo_centroidPointXYZ(x0, y0, z0);
  3166. };
  3167. function nextPoint(λ, φ) {
  3168. λ *= d3_radians;
  3169. 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);
  3170. d3_geo_centroidW1 += w;
  3171. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3172. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3173. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3174. d3_geo_centroidPointXYZ(x0, y0, z0);
  3175. }
  3176. }
  3177. function d3_geo_centroidLineEnd() {
  3178. d3_geo_centroid.point = d3_geo_centroidPoint;
  3179. }
  3180. function d3_geo_centroidRingStart() {
  3181. var λ00, φ00, x0, y0, z0;
  3182. d3_geo_centroid.point = function(λ, φ) {
  3183. λ00 = λ, φ00 = φ;
  3184. d3_geo_centroid.point = nextPoint;
  3185. λ *= d3_radians;
  3186. var cosφ = Math.cos(φ *= d3_radians);
  3187. x0 = cosφ * Math.cos(λ);
  3188. y0 = cosφ * Math.sin(λ);
  3189. z0 = Math.sin(φ);
  3190. d3_geo_centroidPointXYZ(x0, y0, z0);
  3191. };
  3192. d3_geo_centroid.lineEnd = function() {
  3193. nextPoint(λ00, φ00);
  3194. d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
  3195. d3_geo_centroid.point = d3_geo_centroidPoint;
  3196. };
  3197. function nextPoint(λ, φ) {
  3198. λ *= d3_radians;
  3199. 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);
  3200. d3_geo_centroidX2 += v * cx;
  3201. d3_geo_centroidY2 += v * cy;
  3202. d3_geo_centroidZ2 += v * cz;
  3203. d3_geo_centroidW1 += w;
  3204. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3205. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3206. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3207. d3_geo_centroidPointXYZ(x0, y0, z0);
  3208. }
  3209. }
  3210. function d3_geo_compose(a, b) {
  3211. function compose(x, y) {
  3212. return x = a(x, y), b(x[0], x[1]);
  3213. }
  3214. if (a.invert && b.invert) compose.invert = function(x, y) {
  3215. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  3216. };
  3217. return compose;
  3218. }
  3219. function d3_true() {
  3220. return true;
  3221. }
  3222. function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
  3223. var subject = [], clip = [];
  3224. segments.forEach(function(segment) {
  3225. if ((n = segment.length - 1) <= 0) return;
  3226. var n, p0 = segment[0], p1 = segment[n];
  3227. if (d3_geo_sphericalEqual(p0, p1)) {
  3228. listener.lineStart();
  3229. for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
  3230. listener.lineEnd();
  3231. return;
  3232. }
  3233. var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
  3234. a.o = b;
  3235. subject.push(a);
  3236. clip.push(b);
  3237. a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
  3238. b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
  3239. a.o = b;
  3240. subject.push(a);
  3241. clip.push(b);
  3242. });
  3243. clip.sort(compare);
  3244. d3_geo_clipPolygonLinkCircular(subject);
  3245. d3_geo_clipPolygonLinkCircular(clip);
  3246. if (!subject.length) return;
  3247. for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
  3248. clip[i].e = entry = !entry;
  3249. }
  3250. var start = subject[0], points, point;
  3251. while (1) {
  3252. var current = start, isSubject = true;
  3253. while (current.v) if ((current = current.n) === start) return;
  3254. points = current.z;
  3255. listener.lineStart();
  3256. do {
  3257. current.v = current.o.v = true;
  3258. if (current.e) {
  3259. if (isSubject) {
  3260. for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
  3261. } else {
  3262. interpolate(current.x, current.n.x, 1, listener);
  3263. }
  3264. current = current.n;
  3265. } else {
  3266. if (isSubject) {
  3267. points = current.p.z;
  3268. for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
  3269. } else {
  3270. interpolate(current.x, current.p.x, -1, listener);
  3271. }
  3272. current = current.p;
  3273. }
  3274. current = current.o;
  3275. points = current.z;
  3276. isSubject = !isSubject;
  3277. } while (!current.v);
  3278. listener.lineEnd();
  3279. }
  3280. }
  3281. function d3_geo_clipPolygonLinkCircular(array) {
  3282. if (!(n = array.length)) return;
  3283. var n, i = 0, a = array[0], b;
  3284. while (++i < n) {
  3285. a.n = b = array[i];
  3286. b.p = a;
  3287. a = b;
  3288. }
  3289. a.n = b = array[0];
  3290. b.p = a;
  3291. }
  3292. function d3_geo_clipPolygonIntersection(point, points, other, entry) {
  3293. this.x = point;
  3294. this.z = points;
  3295. this.o = other;
  3296. this.e = entry;
  3297. this.v = false;
  3298. this.n = this.p = null;
  3299. }
  3300. function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
  3301. return function(rotate, listener) {
  3302. var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
  3303. var clip = {
  3304. point: point,
  3305. lineStart: lineStart,
  3306. lineEnd: lineEnd,
  3307. polygonStart: function() {
  3308. clip.point = pointRing;
  3309. clip.lineStart = ringStart;
  3310. clip.lineEnd = ringEnd;
  3311. segments = [];
  3312. polygon = [];
  3313. },
  3314. polygonEnd: function() {
  3315. clip.point = point;
  3316. clip.lineStart = lineStart;
  3317. clip.lineEnd = lineEnd;
  3318. segments = d3.merge(segments);
  3319. var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
  3320. if (segments.length) {
  3321. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3322. d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
  3323. } else if (clipStartInside) {
  3324. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3325. listener.lineStart();
  3326. interpolate(null, null, 1, listener);
  3327. listener.lineEnd();
  3328. }
  3329. if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
  3330. segments = polygon = null;
  3331. },
  3332. sphere: function() {
  3333. listener.polygonStart();
  3334. listener.lineStart();
  3335. interpolate(null, null, 1, listener);
  3336. listener.lineEnd();
  3337. listener.polygonEnd();
  3338. }
  3339. };
  3340. function point(λ, φ) {
  3341. var point = rotate(λ, φ);
  3342. if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
  3343. }
  3344. function pointLine(λ, φ) {
  3345. var point = rotate(λ, φ);
  3346. line.point(point[0], point[1]);
  3347. }
  3348. function lineStart() {
  3349. clip.point = pointLine;
  3350. line.lineStart();
  3351. }
  3352. function lineEnd() {
  3353. clip.point = point;
  3354. line.lineEnd();
  3355. }
  3356. var segments;
  3357. var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
  3358. function pointRing(λ, φ) {
  3359. ring.push([ λ, φ ]);
  3360. var point = rotate(λ, φ);
  3361. ringListener.point(point[0], point[1]);
  3362. }
  3363. function ringStart() {
  3364. ringListener.lineStart();
  3365. ring = [];
  3366. }
  3367. function ringEnd() {
  3368. pointRing(ring[0][0], ring[0][1]);
  3369. ringListener.lineEnd();
  3370. var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
  3371. ring.pop();
  3372. polygon.push(ring);
  3373. ring = null;
  3374. if (!n) return;
  3375. if (clean & 1) {
  3376. segment = ringSegments[0];
  3377. var n = segment.length - 1, i = -1, point;
  3378. if (n > 0) {
  3379. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  3380. listener.lineStart();
  3381. while (++i < n) listener.point((point = segment[i])[0], point[1]);
  3382. listener.lineEnd();
  3383. }
  3384. return;
  3385. }
  3386. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  3387. segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
  3388. }
  3389. return clip;
  3390. };
  3391. }
  3392. function d3_geo_clipSegmentLength1(segment) {
  3393. return segment.length > 1;
  3394. }
  3395. function d3_geo_clipBufferListener() {
  3396. var lines = [], line;
  3397. return {
  3398. lineStart: function() {
  3399. lines.push(line = []);
  3400. },
  3401. point: function(λ, φ) {
  3402. line.push([ λ, φ ]);
  3403. },
  3404. lineEnd: d3_noop,
  3405. buffer: function() {
  3406. var buffer = lines;
  3407. lines = [];
  3408. line = null;
  3409. return buffer;
  3410. },
  3411. rejoin: function() {
  3412. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  3413. }
  3414. };
  3415. }
  3416. function d3_geo_clipSort(a, b) {
  3417. return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
  3418. }
  3419. var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
  3420. function d3_geo_clipAntimeridianLine(listener) {
  3421. var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
  3422. return {
  3423. lineStart: function() {
  3424. listener.lineStart();
  3425. clean = 1;
  3426. },
  3427. point: function(λ1, φ1) {
  3428. var sλ1 = λ1 > 0 ? π : -π, = abs(λ1 - λ0);
  3429. if (abs( - π) < ε) {
  3430. listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
  3431. listener.point(sλ0, φ0);
  3432. listener.lineEnd();
  3433. listener.lineStart();
  3434. listener.point(sλ1, φ0);
  3435. listener.point(λ1, φ0);
  3436. clean = 0;
  3437. } else if (sλ0 !== sλ1 && >= π) {
  3438. if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
  3439. if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
  3440. φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
  3441. listener.point(sλ0, φ0);
  3442. listener.lineEnd();
  3443. listener.lineStart();
  3444. listener.point(sλ1, φ0);
  3445. clean = 0;
  3446. }
  3447. listener.point(λ0 = λ1, φ0 = φ1);
  3448. sλ0 = sλ1;
  3449. },
  3450. lineEnd: function() {
  3451. listener.lineEnd();
  3452. λ0 = φ0 = NaN;
  3453. },
  3454. clean: function() {
  3455. return 2 - clean;
  3456. }
  3457. };
  3458. }
  3459. function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
  3460. var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
  3461. 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;
  3462. }
  3463. function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
  3464. var φ;
  3465. if (from == null) {
  3466. φ = direction * halfπ;
  3467. listener.point(-π, φ);
  3468. listener.point(0, φ);
  3469. listener.point(π, φ);
  3470. listener.point(π, 0);
  3471. listener.point(π, -φ);
  3472. listener.point(0, -φ);
  3473. listener.point(-π, -φ);
  3474. listener.point(-π, 0);
  3475. listener.point(-π, φ);
  3476. } else if (abs(from[0] - to[0]) > ε) {
  3477. var s = from[0] < to[0] ? π : -π;
  3478. φ = direction * s / 2;
  3479. listener.point(-s, φ);
  3480. listener.point(0, φ);
  3481. listener.point(s, φ);
  3482. } else {
  3483. listener.point(to[0], to[1]);
  3484. }
  3485. }
  3486. function d3_geo_pointInPolygon(point, polygon) {
  3487. var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
  3488. d3_geo_areaRingSum.reset();
  3489. for (var i = 0, n = polygon.length; i < n; ++i) {
  3490. var ring = polygon[i], m = ring.length;
  3491. if (!m) continue;
  3492. var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
  3493. while (true) {
  3494. if (j === m) j = 0;
  3495. point = ring[j];
  3496. var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), = λ - λ0, sdλ = >= 0 ? 1 : -1, adλ = sdλ * , antimeridian = adλ > π, k = sinφ0 * sinφ;
  3497. d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
  3498. polarAngle += antimeridian ? + sdλ * τ : ;
  3499. if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
  3500. var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
  3501. d3_geo_cartesianNormalize(arc);
  3502. var intersection = d3_geo_cartesianCross(meridianNormal, arc);
  3503. d3_geo_cartesianNormalize(intersection);
  3504. var φarc = (antimeridian ^ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
  3505. if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
  3506. winding += antimeridian ^ >= 0 ? 1 : -1;
  3507. }
  3508. }
  3509. if (!j++) break;
  3510. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
  3511. }
  3512. }
  3513. return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
  3514. }
  3515. function d3_geo_clipCircle(radius) {
  3516. var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
  3517. return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
  3518. function visible(λ, φ) {
  3519. return Math.cos(λ) * Math.cos(φ) > cr;
  3520. }
  3521. function clipLine(listener) {
  3522. var point0, c0, v0, v00, clean;
  3523. return {
  3524. lineStart: function() {
  3525. v00 = v0 = false;
  3526. clean = 1;
  3527. },
  3528. point: function(λ, φ) {
  3529. var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
  3530. if (!point0 && (v00 = v0 = v)) listener.lineStart();
  3531. if (v !== v0) {
  3532. point2 = intersect(point0, point1);
  3533. if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
  3534. point1[0] += ε;
  3535. point1[1] += ε;
  3536. v = visible(point1[0], point1[1]);
  3537. }
  3538. }
  3539. if (v !== v0) {
  3540. clean = 0;
  3541. if (v) {
  3542. listener.lineStart();
  3543. point2 = intersect(point1, point0);
  3544. listener.point(point2[0], point2[1]);
  3545. } else {
  3546. point2 = intersect(point0, point1);
  3547. listener.point(point2[0], point2[1]);
  3548. listener.lineEnd();
  3549. }
  3550. point0 = point2;
  3551. } else if (notHemisphere && point0 && smallRadius ^ v) {
  3552. var t;
  3553. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  3554. clean = 0;
  3555. if (smallRadius) {
  3556. listener.lineStart();
  3557. listener.point(t[0][0], t[0][1]);
  3558. listener.point(t[1][0], t[1][1]);
  3559. listener.lineEnd();
  3560. } else {
  3561. listener.point(t[1][0], t[1][1]);
  3562. listener.lineEnd();
  3563. listener.lineStart();
  3564. listener.point(t[0][0], t[0][1]);
  3565. }
  3566. }
  3567. }
  3568. if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
  3569. listener.point(point1[0], point1[1]);
  3570. }
  3571. point0 = point1, v0 = v, c0 = c;
  3572. },
  3573. lineEnd: function() {
  3574. if (v0) listener.lineEnd();
  3575. point0 = null;
  3576. },
  3577. clean: function() {
  3578. return clean | (v00 && v0) << 1;
  3579. }
  3580. };
  3581. }
  3582. function intersect(a, b, two) {
  3583. var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
  3584. var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
  3585. if (!determinant) return !two && a;
  3586. 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);
  3587. d3_geo_cartesianAdd(A, B);
  3588. 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);
  3589. if (t2 < 0) return;
  3590. var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
  3591. d3_geo_cartesianAdd(q, A);
  3592. q = d3_geo_spherical(q);
  3593. if (!two) return q;
  3594. var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
  3595. if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
  3596. var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
  3597. if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
  3598. 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)) {
  3599. var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
  3600. d3_geo_cartesianAdd(q1, A);
  3601. return [ q, d3_geo_spherical(q1) ];
  3602. }
  3603. }
  3604. function code(λ, φ) {
  3605. var r = smallRadius ? radius : π - radius, code = 0;
  3606. if (λ < -r) code |= 1; else if (λ > r) code |= 2;
  3607. if (φ < -r) code |= 4; else if (φ > r) code |= 8;
  3608. return code;
  3609. }
  3610. }
  3611. function d3_geom_clipLine(x0, y0, x1, y1) {
  3612. return function(line) {
  3613. 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;
  3614. r = x0 - ax;
  3615. if (!dx && r > 0) return;
  3616. r /= dx;
  3617. if (dx < 0) {
  3618. if (r < t0) return;
  3619. if (r < t1) t1 = r;
  3620. } else if (dx > 0) {
  3621. if (r > t1) return;
  3622. if (r > t0) t0 = r;
  3623. }
  3624. r = x1 - ax;
  3625. if (!dx && r < 0) return;
  3626. r /= dx;
  3627. if (dx < 0) {
  3628. if (r > t1) return;
  3629. if (r > t0) t0 = r;
  3630. } else if (dx > 0) {
  3631. if (r < t0) return;
  3632. if (r < t1) t1 = r;
  3633. }
  3634. r = y0 - ay;
  3635. if (!dy && r > 0) return;
  3636. r /= dy;
  3637. if (dy < 0) {
  3638. if (r < t0) return;
  3639. if (r < t1) t1 = r;
  3640. } else if (dy > 0) {
  3641. if (r > t1) return;
  3642. if (r > t0) t0 = r;
  3643. }
  3644. r = y1 - ay;
  3645. if (!dy && r < 0) return;
  3646. r /= dy;
  3647. if (dy < 0) {
  3648. if (r > t1) return;
  3649. if (r > t0) t0 = r;
  3650. } else if (dy > 0) {
  3651. if (r < t0) return;
  3652. if (r < t1) t1 = r;
  3653. }
  3654. if (t0 > 0) line.a = {
  3655. x: ax + t0 * dx,
  3656. y: ay + t0 * dy
  3657. };
  3658. if (t1 < 1) line.b = {
  3659. x: ax + t1 * dx,
  3660. y: ay + t1 * dy
  3661. };
  3662. return line;
  3663. };
  3664. }
  3665. var d3_geo_clipExtentMAX = 1e9;
  3666. d3.geo.clipExtent = function() {
  3667. var x0, y0, x1, y1, stream, clip, clipExtent = {
  3668. stream: function(output) {
  3669. if (stream) stream.valid = false;
  3670. stream = clip(output);
  3671. stream.valid = true;
  3672. return stream;
  3673. },
  3674. extent: function(_) {
  3675. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  3676. clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
  3677. if (stream) stream.valid = false, stream = null;
  3678. return clipExtent;
  3679. }
  3680. };
  3681. return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
  3682. };
  3683. function d3_geo_clipExtent(x0, y0, x1, y1) {
  3684. return function(listener) {
  3685. var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
  3686. var clip = {
  3687. point: point,
  3688. lineStart: lineStart,
  3689. lineEnd: lineEnd,
  3690. polygonStart: function() {
  3691. listener = bufferListener;
  3692. segments = [];
  3693. polygon = [];
  3694. clean = true;
  3695. },
  3696. polygonEnd: function() {
  3697. listener = listener_;
  3698. segments = d3.merge(segments);
  3699. var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
  3700. if (inside || visible) {
  3701. listener.polygonStart();
  3702. if (inside) {
  3703. listener.lineStart();
  3704. interpolate(null, null, 1, listener);
  3705. listener.lineEnd();
  3706. }
  3707. if (visible) {
  3708. d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
  3709. }
  3710. listener.polygonEnd();
  3711. }
  3712. segments = polygon = ring = null;
  3713. }
  3714. };
  3715. function insidePolygon(p) {
  3716. var wn = 0, n = polygon.length, y = p[1];
  3717. for (var i = 0; i < n; ++i) {
  3718. for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
  3719. b = v[j];
  3720. if (a[1] <= y) {
  3721. if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
  3722. } else {
  3723. if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
  3724. }
  3725. a = b;
  3726. }
  3727. }
  3728. return wn !== 0;
  3729. }
  3730. function interpolate(from, to, direction, listener) {
  3731. var a = 0, a1 = 0;
  3732. if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
  3733. do {
  3734. listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  3735. } while ((a = (a + direction + 4) % 4) !== a1);
  3736. } else {
  3737. listener.point(to[0], to[1]);
  3738. }
  3739. }
  3740. function pointVisible(x, y) {
  3741. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  3742. }
  3743. function point(x, y) {
  3744. if (pointVisible(x, y)) listener.point(x, y);
  3745. }
  3746. var x__, y__, v__, x_, y_, v_, first, clean;
  3747. function lineStart() {
  3748. clip.point = linePoint;
  3749. if (polygon) polygon.push(ring = []);
  3750. first = true;
  3751. v_ = false;
  3752. x_ = y_ = NaN;
  3753. }
  3754. function lineEnd() {
  3755. if (segments) {
  3756. linePoint(x__, y__);
  3757. if (v__ && v_) bufferListener.rejoin();
  3758. segments.push(bufferListener.buffer());
  3759. }
  3760. clip.point = point;
  3761. if (v_) listener.lineEnd();
  3762. }
  3763. function linePoint(x, y) {
  3764. x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
  3765. y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
  3766. var v = pointVisible(x, y);
  3767. if (polygon) ring.push([ x, y ]);
  3768. if (first) {
  3769. x__ = x, y__ = y, v__ = v;
  3770. first = false;
  3771. if (v) {
  3772. listener.lineStart();
  3773. listener.point(x, y);
  3774. }
  3775. } else {
  3776. if (v && v_) listener.point(x, y); else {
  3777. var l = {
  3778. a: {
  3779. x: x_,
  3780. y: y_
  3781. },
  3782. b: {
  3783. x: x,
  3784. y: y
  3785. }
  3786. };
  3787. if (clipLine(l)) {
  3788. if (!v_) {
  3789. listener.lineStart();
  3790. listener.point(l.a.x, l.a.y);
  3791. }
  3792. listener.point(l.b.x, l.b.y);
  3793. if (!v) listener.lineEnd();
  3794. clean = false;
  3795. } else if (v) {
  3796. listener.lineStart();
  3797. listener.point(x, y);
  3798. clean = false;
  3799. }
  3800. }
  3801. }
  3802. x_ = x, y_ = y, v_ = v;
  3803. }
  3804. return clip;
  3805. };
  3806. function corner(p, direction) {
  3807. 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;
  3808. }
  3809. function compare(a, b) {
  3810. return comparePoints(a.x, b.x);
  3811. }
  3812. function comparePoints(a, b) {
  3813. var ca = corner(a, 1), cb = corner(b, 1);
  3814. 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];
  3815. }
  3816. }
  3817. function d3_geo_conic(projectAt) {
  3818. var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
  3819. p.parallels = function(_) {
  3820. if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
  3821. return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
  3822. };
  3823. return p;
  3824. }
  3825. function d3_geo_conicEqualArea(φ0, φ1) {
  3826. 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;
  3827. function forward(λ, φ) {
  3828. var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
  3829. return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
  3830. }
  3831. forward.invert = function(x, y) {
  3832. var ρ0_y = ρ0 - y;
  3833. return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
  3834. };
  3835. return forward;
  3836. }
  3837. (d3.geo.conicEqualArea = function() {
  3838. return d3_geo_conic(d3_geo_conicEqualArea);
  3839. }).raw = d3_geo_conicEqualArea;
  3840. d3.geo.albers = function() {
  3841. return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
  3842. };
  3843. d3.geo.albersUsa = function() {
  3844. var lower48 = d3.geo.albers();
  3845. var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
  3846. var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
  3847. var point, pointStream = {
  3848. point: function(x, y) {
  3849. point = [ x, y ];
  3850. }
  3851. }, lower48Point, alaskaPoint, hawaiiPoint;
  3852. function albersUsa(coordinates) {
  3853. var x = coordinates[0], y = coordinates[1];
  3854. point = null;
  3855. (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
  3856. return point;
  3857. }
  3858. albersUsa.invert = function(coordinates) {
  3859. var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
  3860. return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
  3861. };
  3862. albersUsa.stream = function(stream) {
  3863. var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
  3864. return {
  3865. point: function(x, y) {
  3866. lower48Stream.point(x, y);
  3867. alaskaStream.point(x, y);
  3868. hawaiiStream.point(x, y);
  3869. },
  3870. sphere: function() {
  3871. lower48Stream.sphere();
  3872. alaskaStream.sphere();
  3873. hawaiiStream.sphere();
  3874. },
  3875. lineStart: function() {
  3876. lower48Stream.lineStart();
  3877. alaskaStream.lineStart();
  3878. hawaiiStream.lineStart();
  3879. },
  3880. lineEnd: function() {
  3881. lower48Stream.lineEnd();
  3882. alaskaStream.lineEnd();
  3883. hawaiiStream.lineEnd();
  3884. },
  3885. polygonStart: function() {
  3886. lower48Stream.polygonStart();
  3887. alaskaStream.polygonStart();
  3888. hawaiiStream.polygonStart();
  3889. },
  3890. polygonEnd: function() {
  3891. lower48Stream.polygonEnd();
  3892. alaskaStream.polygonEnd();
  3893. hawaiiStream.polygonEnd();
  3894. }
  3895. };
  3896. };
  3897. albersUsa.precision = function(_) {
  3898. if (!arguments.length) return lower48.precision();
  3899. lower48.precision(_);
  3900. alaska.precision(_);
  3901. hawaii.precision(_);
  3902. return albersUsa;
  3903. };
  3904. albersUsa.scale = function(_) {
  3905. if (!arguments.length) return lower48.scale();
  3906. lower48.scale(_);
  3907. alaska.scale(_ * .35);
  3908. hawaii.scale(_);
  3909. return albersUsa.translate(lower48.translate());
  3910. };
  3911. albersUsa.translate = function(_) {
  3912. if (!arguments.length) return lower48.translate();
  3913. var k = lower48.scale(), x = +_[0], y = +_[1];
  3914. lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
  3915. 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;
  3916. 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;
  3917. return albersUsa;
  3918. };
  3919. return albersUsa.scale(1070);
  3920. };
  3921. var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
  3922. point: d3_noop,
  3923. lineStart: d3_noop,
  3924. lineEnd: d3_noop,
  3925. polygonStart: function() {
  3926. d3_geo_pathAreaPolygon = 0;
  3927. d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
  3928. },
  3929. polygonEnd: function() {
  3930. d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
  3931. d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
  3932. }
  3933. };
  3934. function d3_geo_pathAreaRingStart() {
  3935. var x00, y00, x0, y0;
  3936. d3_geo_pathArea.point = function(x, y) {
  3937. d3_geo_pathArea.point = nextPoint;
  3938. x00 = x0 = x, y00 = y0 = y;
  3939. };
  3940. function nextPoint(x, y) {
  3941. d3_geo_pathAreaPolygon += y0 * x - x0 * y;
  3942. x0 = x, y0 = y;
  3943. }
  3944. d3_geo_pathArea.lineEnd = function() {
  3945. nextPoint(x00, y00);
  3946. };
  3947. }
  3948. var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
  3949. var d3_geo_pathBounds = {
  3950. point: d3_geo_pathBoundsPoint,
  3951. lineStart: d3_noop,
  3952. lineEnd: d3_noop,
  3953. polygonStart: d3_noop,
  3954. polygonEnd: d3_noop
  3955. };
  3956. function d3_geo_pathBoundsPoint(x, y) {
  3957. if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
  3958. if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
  3959. if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
  3960. if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
  3961. }
  3962. function d3_geo_pathBuffer() {
  3963. var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
  3964. var stream = {
  3965. point: point,
  3966. lineStart: function() {
  3967. stream.point = pointLineStart;
  3968. },
  3969. lineEnd: lineEnd,
  3970. polygonStart: function() {
  3971. stream.lineEnd = lineEndPolygon;
  3972. },
  3973. polygonEnd: function() {
  3974. stream.lineEnd = lineEnd;
  3975. stream.point = point;
  3976. },
  3977. pointRadius: function(_) {
  3978. pointCircle = d3_geo_pathBufferCircle(_);
  3979. return stream;
  3980. },
  3981. result: function() {
  3982. if (buffer.length) {
  3983. var result = buffer.join("");
  3984. buffer = [];
  3985. return result;
  3986. }
  3987. }
  3988. };
  3989. function point(x, y) {
  3990. buffer.push("M", x, ",", y, pointCircle);
  3991. }
  3992. function pointLineStart(x, y) {
  3993. buffer.push("M", x, ",", y);
  3994. stream.point = pointLine;
  3995. }
  3996. function pointLine(x, y) {
  3997. buffer.push("L", x, ",", y);
  3998. }
  3999. function lineEnd() {
  4000. stream.point = point;
  4001. }
  4002. function lineEndPolygon() {
  4003. buffer.push("Z");
  4004. }
  4005. return stream;
  4006. }
  4007. function d3_geo_pathBufferCircle(radius) {
  4008. return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
  4009. }
  4010. var d3_geo_pathCentroid = {
  4011. point: d3_geo_pathCentroidPoint,
  4012. lineStart: d3_geo_pathCentroidLineStart,
  4013. lineEnd: d3_geo_pathCentroidLineEnd,
  4014. polygonStart: function() {
  4015. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
  4016. },
  4017. polygonEnd: function() {
  4018. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  4019. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
  4020. d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
  4021. }
  4022. };
  4023. function d3_geo_pathCentroidPoint(x, y) {
  4024. d3_geo_centroidX0 += x;
  4025. d3_geo_centroidY0 += y;
  4026. ++d3_geo_centroidZ0;
  4027. }
  4028. function d3_geo_pathCentroidLineStart() {
  4029. var x0, y0;
  4030. d3_geo_pathCentroid.point = function(x, y) {
  4031. d3_geo_pathCentroid.point = nextPoint;
  4032. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4033. };
  4034. function nextPoint(x, y) {
  4035. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  4036. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4037. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4038. d3_geo_centroidZ1 += z;
  4039. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4040. }
  4041. }
  4042. function d3_geo_pathCentroidLineEnd() {
  4043. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  4044. }
  4045. function d3_geo_pathCentroidRingStart() {
  4046. var x00, y00, x0, y0;
  4047. d3_geo_pathCentroid.point = function(x, y) {
  4048. d3_geo_pathCentroid.point = nextPoint;
  4049. d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
  4050. };
  4051. function nextPoint(x, y) {
  4052. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  4053. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4054. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4055. d3_geo_centroidZ1 += z;
  4056. z = y0 * x - x0 * y;
  4057. d3_geo_centroidX2 += z * (x0 + x);
  4058. d3_geo_centroidY2 += z * (y0 + y);
  4059. d3_geo_centroidZ2 += z * 3;
  4060. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4061. }
  4062. d3_geo_pathCentroid.lineEnd = function() {
  4063. nextPoint(x00, y00);
  4064. };
  4065. }
  4066. function d3_geo_pathContext(context) {
  4067. var pointRadius = 4.5;
  4068. var stream = {
  4069. point: point,
  4070. lineStart: function() {
  4071. stream.point = pointLineStart;
  4072. },
  4073. lineEnd: lineEnd,
  4074. polygonStart: function() {
  4075. stream.lineEnd = lineEndPolygon;
  4076. },
  4077. polygonEnd: function() {
  4078. stream.lineEnd = lineEnd;
  4079. stream.point = point;
  4080. },
  4081. pointRadius: function(_) {
  4082. pointRadius = _;
  4083. return stream;
  4084. },
  4085. result: d3_noop
  4086. };
  4087. function point(x, y) {
  4088. context.moveTo(x + pointRadius, y);
  4089. context.arc(x, y, pointRadius, 0, τ);
  4090. }
  4091. function pointLineStart(x, y) {
  4092. context.moveTo(x, y);
  4093. stream.point = pointLine;
  4094. }
  4095. function pointLine(x, y) {
  4096. context.lineTo(x, y);
  4097. }
  4098. function lineEnd() {
  4099. stream.point = point;
  4100. }
  4101. function lineEndPolygon() {
  4102. context.closePath();
  4103. }
  4104. return stream;
  4105. }
  4106. function d3_geo_resample(project) {
  4107. var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
  4108. function resample(stream) {
  4109. return (maxDepth ? resampleRecursive : resampleNone)(stream);
  4110. }
  4111. function resampleNone(stream) {
  4112. return d3_geo_transformPoint(stream, function(x, y) {
  4113. x = project(x, y);
  4114. stream.point(x[0], x[1]);
  4115. });
  4116. }
  4117. function resampleRecursive(stream) {
  4118. var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
  4119. var resample = {
  4120. point: point,
  4121. lineStart: lineStart,
  4122. lineEnd: lineEnd,
  4123. polygonStart: function() {
  4124. stream.polygonStart();
  4125. resample.lineStart = ringStart;
  4126. },
  4127. polygonEnd: function() {
  4128. stream.polygonEnd();
  4129. resample.lineStart = lineStart;
  4130. }
  4131. };
  4132. function point(x, y) {
  4133. x = project(x, y);
  4134. stream.point(x[0], x[1]);
  4135. }
  4136. function lineStart() {
  4137. x0 = NaN;
  4138. resample.point = linePoint;
  4139. stream.lineStart();
  4140. }
  4141. function linePoint(λ, φ) {
  4142. var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
  4143. 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);
  4144. stream.point(x0, y0);
  4145. }
  4146. function lineEnd() {
  4147. resample.point = point;
  4148. stream.lineEnd();
  4149. }
  4150. function ringStart() {
  4151. lineStart();
  4152. resample.point = ringPoint;
  4153. resample.lineEnd = ringEnd;
  4154. }
  4155. function ringPoint(λ, φ) {
  4156. linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  4157. resample.point = linePoint;
  4158. }
  4159. function ringEnd() {
  4160. resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
  4161. resample.lineEnd = lineEnd;
  4162. lineEnd();
  4163. }
  4164. return resample;
  4165. }
  4166. function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
  4167. var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
  4168. if (d2 > 4 * δ2 && depth--) {
  4169. 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;
  4170. if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
  4171. resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
  4172. stream.point(x2, y2);
  4173. resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
  4174. }
  4175. }
  4176. }
  4177. resample.precision = function(_) {
  4178. if (!arguments.length) return Math.sqrt(δ2);
  4179. maxDepth = (δ2 = _ * _) > 0 && 16;
  4180. return resample;
  4181. };
  4182. return resample;
  4183. }
  4184. d3.geo.path = function() {
  4185. var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
  4186. function path(object) {
  4187. if (object) {
  4188. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  4189. if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
  4190. d3.geo.stream(object, cacheStream);
  4191. }
  4192. return contextStream.result();
  4193. }
  4194. path.area = function(object) {
  4195. d3_geo_pathAreaSum = 0;
  4196. d3.geo.stream(object, projectStream(d3_geo_pathArea));
  4197. return d3_geo_pathAreaSum;
  4198. };
  4199. path.centroid = function(object) {
  4200. 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;
  4201. d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
  4202. 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 ];
  4203. };
  4204. path.bounds = function(object) {
  4205. d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
  4206. d3.geo.stream(object, projectStream(d3_geo_pathBounds));
  4207. return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
  4208. };
  4209. path.projection = function(_) {
  4210. if (!arguments.length) return projection;
  4211. projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
  4212. return reset();
  4213. };
  4214. path.context = function(_) {
  4215. if (!arguments.length) return context;
  4216. contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
  4217. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  4218. return reset();
  4219. };
  4220. path.pointRadius = function(_) {
  4221. if (!arguments.length) return pointRadius;
  4222. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  4223. return path;
  4224. };
  4225. function reset() {
  4226. cacheStream = null;
  4227. return path;
  4228. }
  4229. return path.projection(d3.geo.albersUsa()).context(null);
  4230. };
  4231. function d3_geo_pathProjectStream(project) {
  4232. var resample = d3_geo_resample(function(x, y) {
  4233. return project([ x * d3_degrees, y * d3_degrees ]);
  4234. });
  4235. return function(stream) {
  4236. return d3_geo_projectionRadians(resample(stream));
  4237. };
  4238. }
  4239. d3.geo.transform = function(methods) {
  4240. return {
  4241. stream: function(stream) {
  4242. var transform = new d3_geo_transform(stream);
  4243. for (var k in methods) transform[k] = methods[k];
  4244. return transform;
  4245. }
  4246. };
  4247. };
  4248. function d3_geo_transform(stream) {
  4249. this.stream = stream;
  4250. }
  4251. d3_geo_transform.prototype = {
  4252. point: function(x, y) {
  4253. this.stream.point(x, y);
  4254. },
  4255. sphere: function() {
  4256. this.stream.sphere();
  4257. },
  4258. lineStart: function() {
  4259. this.stream.lineStart();
  4260. },
  4261. lineEnd: function() {
  4262. this.stream.lineEnd();
  4263. },
  4264. polygonStart: function() {
  4265. this.stream.polygonStart();
  4266. },
  4267. polygonEnd: function() {
  4268. this.stream.polygonEnd();
  4269. }
  4270. };
  4271. function d3_geo_transformPoint(stream, point) {
  4272. return {
  4273. point: point,
  4274. sphere: function() {
  4275. stream.sphere();
  4276. },
  4277. lineStart: function() {
  4278. stream.lineStart();
  4279. },
  4280. lineEnd: function() {
  4281. stream.lineEnd();
  4282. },
  4283. polygonStart: function() {
  4284. stream.polygonStart();
  4285. },
  4286. polygonEnd: function() {
  4287. stream.polygonEnd();
  4288. }
  4289. };
  4290. }
  4291. d3.geo.projection = d3_geo_projection;
  4292. d3.geo.projectionMutator = d3_geo_projectionMutator;
  4293. function d3_geo_projection(project) {
  4294. return d3_geo_projectionMutator(function() {
  4295. return project;
  4296. })();
  4297. }
  4298. function d3_geo_projectionMutator(projectAt) {
  4299. var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
  4300. x = project(x, y);
  4301. return [ x[0] * k + δx, δy - x[1] * k ];
  4302. }), 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;
  4303. function projection(point) {
  4304. point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
  4305. return [ point[0] * k + δx, δy - point[1] * k ];
  4306. }
  4307. function invert(point) {
  4308. point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
  4309. return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
  4310. }
  4311. projection.stream = function(output) {
  4312. if (stream) stream.valid = false;
  4313. stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
  4314. stream.valid = true;
  4315. return stream;
  4316. };
  4317. projection.clipAngle = function(_) {
  4318. if (!arguments.length) return clipAngle;
  4319. preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
  4320. return invalidate();
  4321. };
  4322. projection.clipExtent = function(_) {
  4323. if (!arguments.length) return clipExtent;
  4324. clipExtent = _;
  4325. postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
  4326. return invalidate();
  4327. };
  4328. projection.scale = function(_) {
  4329. if (!arguments.length) return k;
  4330. k = +_;
  4331. return reset();
  4332. };
  4333. projection.translate = function(_) {
  4334. if (!arguments.length) return [ x, y ];
  4335. x = +_[0];
  4336. y = +_[1];
  4337. return reset();
  4338. };
  4339. projection.center = function(_) {
  4340. if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
  4341. λ = _[0] % 360 * d3_radians;
  4342. φ = _[1] % 360 * d3_radians;
  4343. return reset();
  4344. };
  4345. projection.rotate = function(_) {
  4346. if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
  4347. δλ = _[0] % 360 * d3_radians;
  4348. δφ = _[1] % 360 * d3_radians;
  4349. δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
  4350. return reset();
  4351. };
  4352. d3.rebind(projection, projectResample, "precision");
  4353. function reset() {
  4354. projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
  4355. var center = project(λ, φ);
  4356. δx = x - center[0] * k;
  4357. δy = y + center[1] * k;
  4358. return invalidate();
  4359. }
  4360. function invalidate() {
  4361. if (stream) stream.valid = false, stream = null;
  4362. return projection;
  4363. }
  4364. return function() {
  4365. project = projectAt.apply(this, arguments);
  4366. projection.invert = project.invert && invert;
  4367. return reset();
  4368. };
  4369. }
  4370. function d3_geo_projectionRadians(stream) {
  4371. return d3_geo_transformPoint(stream, function(x, y) {
  4372. stream.point(x * d3_radians, y * d3_radians);
  4373. });
  4374. }
  4375. function d3_geo_equirectangular(λ, φ) {
  4376. return [ λ, φ ];
  4377. }
  4378. (d3.geo.equirectangular = function() {
  4379. return d3_geo_projection(d3_geo_equirectangular);
  4380. }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
  4381. d3.geo.rotation = function(rotate) {
  4382. rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
  4383. function forward(coordinates) {
  4384. coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4385. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4386. }
  4387. forward.invert = function(coordinates) {
  4388. coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  4389. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  4390. };
  4391. return forward;
  4392. };
  4393. function d3_geo_identityRotation(λ, φ) {
  4394. return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4395. }
  4396. d3_geo_identityRotation.invert = d3_geo_equirectangular;
  4397. function d3_geo_rotation(δλ, δφ, δγ) {
  4398. return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
  4399. }
  4400. function d3_geo_forwardRotationλ(δλ) {
  4401. return function(λ, φ) {
  4402. return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  4403. };
  4404. }
  4405. function d3_geo_rotationλ(δλ) {
  4406. var rotation = d3_geo_forwardRotationλ(δλ);
  4407. rotation.invert = d3_geo_forwardRotationλ(-δλ);
  4408. return rotation;
  4409. }
  4410. function d3_geo_rotationφγ(δφ, δγ) {
  4411. var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
  4412. function rotation(λ, φ) {
  4413. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
  4414. return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
  4415. }
  4416. rotation.invert = function(λ, φ) {
  4417. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
  4418. return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
  4419. };
  4420. return rotation;
  4421. }
  4422. d3.geo.circle = function() {
  4423. var origin = [ 0, 0 ], angle, precision = 6, interpolate;
  4424. function circle() {
  4425. 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 = [];
  4426. interpolate(null, null, 1, {
  4427. point: function(x, y) {
  4428. ring.push(x = rotate(x, y));
  4429. x[0] *= d3_degrees, x[1] *= d3_degrees;
  4430. }
  4431. });
  4432. return {
  4433. type: "Polygon",
  4434. coordinates: [ ring ]
  4435. };
  4436. }
  4437. circle.origin = function(x) {
  4438. if (!arguments.length) return origin;
  4439. origin = x;
  4440. return circle;
  4441. };
  4442. circle.angle = function(x) {
  4443. if (!arguments.length) return angle;
  4444. interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
  4445. return circle;
  4446. };
  4447. circle.precision = function(_) {
  4448. if (!arguments.length) return precision;
  4449. interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
  4450. return circle;
  4451. };
  4452. return circle.angle(90);
  4453. };
  4454. function d3_geo_circleInterpolate(radius, precision) {
  4455. var cr = Math.cos(radius), sr = Math.sin(radius);
  4456. return function(from, to, direction, listener) {
  4457. var step = direction * precision;
  4458. if (from != null) {
  4459. from = d3_geo_circleAngle(cr, from);
  4460. to = d3_geo_circleAngle(cr, to);
  4461. if (direction > 0 ? from < to : from > to) from += direction * τ;
  4462. } else {
  4463. from = radius + direction * τ;
  4464. to = radius - .5 * step;
  4465. }
  4466. for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
  4467. listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
  4468. }
  4469. };
  4470. }
  4471. function d3_geo_circleAngle(cr, point) {
  4472. var a = d3_geo_cartesian(point);
  4473. a[0] -= cr;
  4474. d3_geo_cartesianNormalize(a);
  4475. var angle = d3_acos(-a[1]);
  4476. return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
  4477. }
  4478. d3.geo.distance = function(a, b) {
  4479. 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;
  4480. 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Δλ);
  4481. };
  4482. d3.geo.graticule = function() {
  4483. var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
  4484. function graticule() {
  4485. return {
  4486. type: "MultiLineString",
  4487. coordinates: lines()
  4488. };
  4489. }
  4490. function lines() {
  4491. 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) {
  4492. return abs(x % DX) > ε;
  4493. }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
  4494. return abs(y % DY) > ε;
  4495. }).map(y));
  4496. }
  4497. graticule.lines = function() {
  4498. return lines().map(function(coordinates) {
  4499. return {
  4500. type: "LineString",
  4501. coordinates: coordinates
  4502. };
  4503. });
  4504. };
  4505. graticule.outline = function() {
  4506. return {
  4507. type: "Polygon",
  4508. coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
  4509. };
  4510. };
  4511. graticule.extent = function(_) {
  4512. if (!arguments.length) return graticule.minorExtent();
  4513. return graticule.majorExtent(_).minorExtent(_);
  4514. };
  4515. graticule.majorExtent = function(_) {
  4516. if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
  4517. X0 = +_[0][0], X1 = +_[1][0];
  4518. Y0 = +_[0][1], Y1 = +_[1][1];
  4519. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  4520. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  4521. return graticule.precision(precision);
  4522. };
  4523. graticule.minorExtent = function(_) {
  4524. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  4525. x0 = +_[0][0], x1 = +_[1][0];
  4526. y0 = +_[0][1], y1 = +_[1][1];
  4527. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  4528. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  4529. return graticule.precision(precision);
  4530. };
  4531. graticule.step = function(_) {
  4532. if (!arguments.length) return graticule.minorStep();
  4533. return graticule.majorStep(_).minorStep(_);
  4534. };
  4535. graticule.majorStep = function(_) {
  4536. if (!arguments.length) return [ DX, DY ];
  4537. DX = +_[0], DY = +_[1];
  4538. return graticule;
  4539. };
  4540. graticule.minorStep = function(_) {
  4541. if (!arguments.length) return [ dx, dy ];
  4542. dx = +_[0], dy = +_[1];
  4543. return graticule;
  4544. };
  4545. graticule.precision = function(_) {
  4546. if (!arguments.length) return precision;
  4547. precision = +_;
  4548. x = d3_geo_graticuleX(y0, y1, 90);
  4549. y = d3_geo_graticuleY(x0, x1, precision);
  4550. X = d3_geo_graticuleX(Y0, Y1, 90);
  4551. Y = d3_geo_graticuleY(X0, X1, precision);
  4552. return graticule;
  4553. };
  4554. return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
  4555. };
  4556. function d3_geo_graticuleX(y0, y1, dy) {
  4557. var y = d3.range(y0, y1 - ε, dy).concat(y1);
  4558. return function(x) {
  4559. return y.map(function(y) {
  4560. return [ x, y ];
  4561. });
  4562. };
  4563. }
  4564. function d3_geo_graticuleY(x0, x1, dx) {
  4565. var x = d3.range(x0, x1 - ε, dx).concat(x1);
  4566. return function(y) {
  4567. return x.map(function(x) {
  4568. return [ x, y ];
  4569. });
  4570. };
  4571. }
  4572. function d3_source(d) {
  4573. return d.source;
  4574. }
  4575. function d3_target(d) {
  4576. return d.target;
  4577. }
  4578. d3.geo.greatArc = function() {
  4579. var source = d3_source, source_, target = d3_target, target_;
  4580. function greatArc() {
  4581. return {
  4582. type: "LineString",
  4583. coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
  4584. };
  4585. }
  4586. greatArc.distance = function() {
  4587. return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
  4588. };
  4589. greatArc.source = function(_) {
  4590. if (!arguments.length) return source;
  4591. source = _, source_ = typeof _ === "function" ? null : _;
  4592. return greatArc;
  4593. };
  4594. greatArc.target = function(_) {
  4595. if (!arguments.length) return target;
  4596. target = _, target_ = typeof _ === "function" ? null : _;
  4597. return greatArc;
  4598. };
  4599. greatArc.precision = function() {
  4600. return arguments.length ? greatArc : 0;
  4601. };
  4602. return greatArc;
  4603. };
  4604. d3.geo.interpolate = function(source, target) {
  4605. return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
  4606. };
  4607. function d3_geo_interpolate(x0, y0, x1, y1) {
  4608. 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);
  4609. var interpolate = d ? function(t) {
  4610. 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;
  4611. return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
  4612. } : function() {
  4613. return [ x0 * d3_degrees, y0 * d3_degrees ];
  4614. };
  4615. interpolate.distance = d;
  4616. return interpolate;
  4617. }
  4618. d3.geo.length = function(object) {
  4619. d3_geo_lengthSum = 0;
  4620. d3.geo.stream(object, d3_geo_length);
  4621. return d3_geo_lengthSum;
  4622. };
  4623. var d3_geo_lengthSum;
  4624. var d3_geo_length = {
  4625. sphere: d3_noop,
  4626. point: d3_noop,
  4627. lineStart: d3_geo_lengthLineStart,
  4628. lineEnd: d3_noop,
  4629. polygonStart: d3_noop,
  4630. polygonEnd: d3_noop
  4631. };
  4632. function d3_geo_lengthLineStart() {
  4633. var λ0, sinφ0, cosφ0;
  4634. d3_geo_length.point = function(λ, φ) {
  4635. λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
  4636. d3_geo_length.point = nextPoint;
  4637. };
  4638. d3_geo_length.lineEnd = function() {
  4639. d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
  4640. };
  4641. function nextPoint(λ, φ) {
  4642. var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
  4643. 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Δλ);
  4644. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
  4645. }
  4646. }
  4647. function d3_geo_azimuthal(scale, angle) {
  4648. function azimuthal(λ, φ) {
  4649. var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
  4650. return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
  4651. }
  4652. azimuthal.invert = function(x, y) {
  4653. var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
  4654. return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
  4655. };
  4656. return azimuthal;
  4657. }
  4658. var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
  4659. return Math.sqrt(2 / (1 + cosλcosφ));
  4660. }, function(ρ) {
  4661. return 2 * Math.asin(ρ / 2);
  4662. });
  4663. (d3.geo.azimuthalEqualArea = function() {
  4664. return d3_geo_projection(d3_geo_azimuthalEqualArea);
  4665. }).raw = d3_geo_azimuthalEqualArea;
  4666. var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
  4667. var c = Math.acos(cosλcosφ);
  4668. return c && c / Math.sin(c);
  4669. }, d3_identity);
  4670. (d3.geo.azimuthalEquidistant = function() {
  4671. return d3_geo_projection(d3_geo_azimuthalEquidistant);
  4672. }).raw = d3_geo_azimuthalEquidistant;
  4673. function d3_geo_conicConformal(φ0, φ1) {
  4674. var cosφ0 = Math.cos(φ0), t = function(φ) {
  4675. return Math.tan(π / 4 + φ / 2);
  4676. }, 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;
  4677. if (!n) return d3_geo_mercator;
  4678. function forward(λ, φ) {
  4679. if (F > 0) {
  4680. if (φ < -halfπ + ε) φ = -halfπ + ε;
  4681. } else {
  4682. if (φ > halfπ - ε) φ = halfπ - ε;
  4683. }
  4684. var ρ = F / Math.pow(t(φ), n);
  4685. return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
  4686. }
  4687. forward.invert = function(x, y) {
  4688. var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
  4689. return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
  4690. };
  4691. return forward;
  4692. }
  4693. (d3.geo.conicConformal = function() {
  4694. return d3_geo_conic(d3_geo_conicConformal);
  4695. }).raw = d3_geo_conicConformal;
  4696. function d3_geo_conicEquidistant(φ0, φ1) {
  4697. var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
  4698. if (abs(n) < ε) return d3_geo_equirectangular;
  4699. function forward(λ, φ) {
  4700. var ρ = G - φ;
  4701. return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
  4702. }
  4703. forward.invert = function(x, y) {
  4704. var ρ0_y = G - y;
  4705. return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
  4706. };
  4707. return forward;
  4708. }
  4709. (d3.geo.conicEquidistant = function() {
  4710. return d3_geo_conic(d3_geo_conicEquidistant);
  4711. }).raw = d3_geo_conicEquidistant;
  4712. var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
  4713. return 1 / cosλcosφ;
  4714. }, Math.atan);
  4715. (d3.geo.gnomonic = function() {
  4716. return d3_geo_projection(d3_geo_gnomonic);
  4717. }).raw = d3_geo_gnomonic;
  4718. function d3_geo_mercator(λ, φ) {
  4719. return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
  4720. }
  4721. d3_geo_mercator.invert = function(x, y) {
  4722. return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
  4723. };
  4724. function d3_geo_mercatorProjection(project) {
  4725. var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
  4726. m.scale = function() {
  4727. var v = scale.apply(m, arguments);
  4728. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4729. };
  4730. m.translate = function() {
  4731. var v = translate.apply(m, arguments);
  4732. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  4733. };
  4734. m.clipExtent = function(_) {
  4735. var v = clipExtent.apply(m, arguments);
  4736. if (v === m) {
  4737. if (clipAuto = _ == null) {
  4738. var k = π * scale(), t = translate();
  4739. clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
  4740. }
  4741. } else if (clipAuto) {
  4742. v = null;
  4743. }
  4744. return v;
  4745. };
  4746. return m.clipExtent(null);
  4747. }
  4748. (d3.geo.mercator = function() {
  4749. return d3_geo_mercatorProjection(d3_geo_mercator);
  4750. }).raw = d3_geo_mercator;
  4751. var d3_geo_orthographic = d3_geo_azimuthal(function() {
  4752. return 1;
  4753. }, Math.asin);
  4754. (d3.geo.orthographic = function() {
  4755. return d3_geo_projection(d3_geo_orthographic);
  4756. }).raw = d3_geo_orthographic;
  4757. var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
  4758. return 1 / (1 + cosλcosφ);
  4759. }, function(ρ) {
  4760. return 2 * Math.atan(ρ);
  4761. });
  4762. (d3.geo.stereographic = function() {
  4763. return d3_geo_projection(d3_geo_stereographic);
  4764. }).raw = d3_geo_stereographic;
  4765. function d3_geo_transverseMercator(λ, φ) {
  4766. return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
  4767. }
  4768. d3_geo_transverseMercator.invert = function(x, y) {
  4769. return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
  4770. };
  4771. (d3.geo.transverseMercator = function() {
  4772. var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
  4773. projection.center = function(_) {
  4774. return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
  4775. };
  4776. projection.rotate = function(_) {
  4777. return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
  4778. [ _[0], _[1], _[2] - 90 ]);
  4779. };
  4780. return rotate([ 0, 0, 90 ]);
  4781. }).raw = d3_geo_transverseMercator;
  4782. d3.geom = {};
  4783. function d3_geom_pointX(d) {
  4784. return d[0];
  4785. }
  4786. function d3_geom_pointY(d) {
  4787. return d[1];
  4788. }
  4789. d3.geom.hull = function(vertices) {
  4790. var x = d3_geom_pointX, y = d3_geom_pointY;
  4791. if (arguments.length) return hull(vertices);
  4792. function hull(data) {
  4793. if (data.length < 3) return [];
  4794. var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
  4795. for (i = 0; i < n; i++) {
  4796. points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
  4797. }
  4798. points.sort(d3_geom_hullOrder);
  4799. for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
  4800. var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
  4801. var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
  4802. for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
  4803. for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
  4804. return polygon;
  4805. }
  4806. hull.x = function(_) {
  4807. return arguments.length ? (x = _, hull) : x;
  4808. };
  4809. hull.y = function(_) {
  4810. return arguments.length ? (y = _, hull) : y;
  4811. };
  4812. return hull;
  4813. };
  4814. function d3_geom_hullUpper(points) {
  4815. var n = points.length, hull = [ 0, 1 ], hs = 2;
  4816. for (var i = 2; i < n; i++) {
  4817. while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
  4818. hull[hs++] = i;
  4819. }
  4820. return hull.slice(0, hs);
  4821. }
  4822. function d3_geom_hullOrder(a, b) {
  4823. return a[0] - b[0] || a[1] - b[1];
  4824. }
  4825. d3.geom.polygon = function(coordinates) {
  4826. d3_subclass(coordinates, d3_geom_polygonPrototype);
  4827. return coordinates;
  4828. };
  4829. var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
  4830. d3_geom_polygonPrototype.area = function() {
  4831. var i = -1, n = this.length, a, b = this[n - 1], area = 0;
  4832. while (++i < n) {
  4833. a = b;
  4834. b = this[i];
  4835. area += a[1] * b[0] - a[0] * b[1];
  4836. }
  4837. return area * .5;
  4838. };
  4839. d3_geom_polygonPrototype.centroid = function(k) {
  4840. var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
  4841. if (!arguments.length) k = -1 / (6 * this.area());
  4842. while (++i < n) {
  4843. a = b;
  4844. b = this[i];
  4845. c = a[0] * b[1] - b[0] * a[1];
  4846. x += (a[0] + b[0]) * c;
  4847. y += (a[1] + b[1]) * c;
  4848. }
  4849. return [ x * k, y * k ];
  4850. };
  4851. d3_geom_polygonPrototype.clip = function(subject) {
  4852. 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;
  4853. while (++i < n) {
  4854. input = subject.slice();
  4855. subject.length = 0;
  4856. b = this[i];
  4857. c = input[(m = input.length - closed) - 1];
  4858. j = -1;
  4859. while (++j < m) {
  4860. d = input[j];
  4861. if (d3_geom_polygonInside(d, a, b)) {
  4862. if (!d3_geom_polygonInside(c, a, b)) {
  4863. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4864. }
  4865. subject.push(d);
  4866. } else if (d3_geom_polygonInside(c, a, b)) {
  4867. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  4868. }
  4869. c = d;
  4870. }
  4871. if (closed) subject.push(subject[0]);
  4872. a = b;
  4873. }
  4874. return subject;
  4875. };
  4876. function d3_geom_polygonInside(p, a, b) {
  4877. return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
  4878. }
  4879. function d3_geom_polygonIntersect(c, d, a, b) {
  4880. 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);
  4881. return [ x1 + ua * x21, y1 + ua * y21 ];
  4882. }
  4883. function d3_geom_polygonClosed(coordinates) {
  4884. var a = coordinates[0], b = coordinates[coordinates.length - 1];
  4885. return !(a[0] - b[0] || a[1] - b[1]);
  4886. }
  4887. var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
  4888. function d3_geom_voronoiBeach() {
  4889. d3_geom_voronoiRedBlackNode(this);
  4890. this.edge = this.site = this.circle = null;
  4891. }
  4892. function d3_geom_voronoiCreateBeach(site) {
  4893. var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
  4894. beach.site = site;
  4895. return beach;
  4896. }
  4897. function d3_geom_voronoiDetachBeach(beach) {
  4898. d3_geom_voronoiDetachCircle(beach);
  4899. d3_geom_voronoiBeaches.remove(beach);
  4900. d3_geom_voronoiBeachPool.push(beach);
  4901. d3_geom_voronoiRedBlackNode(beach);
  4902. }
  4903. function d3_geom_voronoiRemoveBeach(beach) {
  4904. var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
  4905. x: x,
  4906. y: y
  4907. }, previous = beach.P, next = beach.N, disappearing = [ beach ];
  4908. d3_geom_voronoiDetachBeach(beach);
  4909. var lArc = previous;
  4910. while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
  4911. previous = lArc.P;
  4912. disappearing.unshift(lArc);
  4913. d3_geom_voronoiDetachBeach(lArc);
  4914. lArc = previous;
  4915. }
  4916. disappearing.unshift(lArc);
  4917. d3_geom_voronoiDetachCircle(lArc);
  4918. var rArc = next;
  4919. while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
  4920. next = rArc.N;
  4921. disappearing.push(rArc);
  4922. d3_geom_voronoiDetachBeach(rArc);
  4923. rArc = next;
  4924. }
  4925. disappearing.push(rArc);
  4926. d3_geom_voronoiDetachCircle(rArc);
  4927. var nArcs = disappearing.length, iArc;
  4928. for (iArc = 1; iArc < nArcs; ++iArc) {
  4929. rArc = disappearing[iArc];
  4930. lArc = disappearing[iArc - 1];
  4931. d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  4932. }
  4933. lArc = disappearing[0];
  4934. rArc = disappearing[nArcs - 1];
  4935. rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
  4936. d3_geom_voronoiAttachCircle(lArc);
  4937. d3_geom_voronoiAttachCircle(rArc);
  4938. }
  4939. function d3_geom_voronoiAddBeach(site) {
  4940. var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
  4941. while (node) {
  4942. dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
  4943. if (dxl > ε) node = node.L; else {
  4944. dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
  4945. if (dxr > ε) {
  4946. if (!node.R) {
  4947. lArc = node;
  4948. break;
  4949. }
  4950. node = node.R;
  4951. } else {
  4952. if (dxl > -ε) {
  4953. lArc = node.P;
  4954. rArc = node;
  4955. } else if (dxr > -ε) {
  4956. lArc = node;
  4957. rArc = node.N;
  4958. } else {
  4959. lArc = rArc = node;
  4960. }
  4961. break;
  4962. }
  4963. }
  4964. }
  4965. var newArc = d3_geom_voronoiCreateBeach(site);
  4966. d3_geom_voronoiBeaches.insert(lArc, newArc);
  4967. if (!lArc && !rArc) return;
  4968. if (lArc === rArc) {
  4969. d3_geom_voronoiDetachCircle(lArc);
  4970. rArc = d3_geom_voronoiCreateBeach(lArc.site);
  4971. d3_geom_voronoiBeaches.insert(newArc, rArc);
  4972. newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  4973. d3_geom_voronoiAttachCircle(lArc);
  4974. d3_geom_voronoiAttachCircle(rArc);
  4975. return;
  4976. }
  4977. if (!rArc) {
  4978. newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  4979. return;
  4980. }
  4981. d3_geom_voronoiDetachCircle(lArc);
  4982. d3_geom_voronoiDetachCircle(rArc);
  4983. 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 = {
  4984. x: (cy * hb - by * hc) / d + ax,
  4985. y: (bx * hc - cx * hb) / d + ay
  4986. };
  4987. d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
  4988. newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
  4989. rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
  4990. d3_geom_voronoiAttachCircle(lArc);
  4991. d3_geom_voronoiAttachCircle(rArc);
  4992. }
  4993. function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
  4994. var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
  4995. if (!pby2) return rfocx;
  4996. var lArc = arc.P;
  4997. if (!lArc) return -Infinity;
  4998. site = lArc.site;
  4999. var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
  5000. if (!plby2) return lfocx;
  5001. var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
  5002. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  5003. return (rfocx + lfocx) / 2;
  5004. }
  5005. function d3_geom_voronoiRightBreakPoint(arc, directrix) {
  5006. var rArc = arc.N;
  5007. if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
  5008. var site = arc.site;
  5009. return site.y === directrix ? site.x : Infinity;
  5010. }
  5011. function d3_geom_voronoiCell(site) {
  5012. this.site = site;
  5013. this.edges = [];
  5014. }
  5015. d3_geom_voronoiCell.prototype.prepare = function() {
  5016. var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
  5017. while (iHalfEdge--) {
  5018. edge = halfEdges[iHalfEdge].edge;
  5019. if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
  5020. }
  5021. halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
  5022. return halfEdges.length;
  5023. };
  5024. function d3_geom_voronoiCloseCells(extent) {
  5025. 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;
  5026. while (iCell--) {
  5027. cell = cells[iCell];
  5028. if (!cell || !cell.prepare()) continue;
  5029. halfEdges = cell.edges;
  5030. nHalfEdges = halfEdges.length;
  5031. iHalfEdge = 0;
  5032. while (iHalfEdge < nHalfEdges) {
  5033. end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
  5034. start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
  5035. if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
  5036. halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
  5037. x: x0,
  5038. y: abs(x2 - x0) < ε ? y2 : y1
  5039. } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
  5040. x: abs(y2 - y1) < ε ? x2 : x1,
  5041. y: y1
  5042. } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
  5043. x: x1,
  5044. y: abs(x2 - x1) < ε ? y2 : y0
  5045. } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
  5046. x: abs(y2 - y0) < ε ? x2 : x0,
  5047. y: y0
  5048. } : null), cell.site, null));
  5049. ++nHalfEdges;
  5050. }
  5051. }
  5052. }
  5053. }
  5054. function d3_geom_voronoiHalfEdgeOrder(a, b) {
  5055. return b.angle - a.angle;
  5056. }
  5057. function d3_geom_voronoiCircle() {
  5058. d3_geom_voronoiRedBlackNode(this);
  5059. this.x = this.y = this.arc = this.site = this.cy = null;
  5060. }
  5061. function d3_geom_voronoiAttachCircle(arc) {
  5062. var lArc = arc.P, rArc = arc.N;
  5063. if (!lArc || !rArc) return;
  5064. var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
  5065. if (lSite === rSite) return;
  5066. var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
  5067. var d = 2 * (ax * cy - ay * cx);
  5068. if (d >= -ε2) return;
  5069. 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;
  5070. var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
  5071. circle.arc = arc;
  5072. circle.site = cSite;
  5073. circle.x = x + bx;
  5074. circle.y = cy + Math.sqrt(x * x + y * y);
  5075. circle.cy = cy;
  5076. arc.circle = circle;
  5077. var before = null, node = d3_geom_voronoiCircles._;
  5078. while (node) {
  5079. if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
  5080. if (node.L) node = node.L; else {
  5081. before = node.P;
  5082. break;
  5083. }
  5084. } else {
  5085. if (node.R) node = node.R; else {
  5086. before = node;
  5087. break;
  5088. }
  5089. }
  5090. }
  5091. d3_geom_voronoiCircles.insert(before, circle);
  5092. if (!before) d3_geom_voronoiFirstCircle = circle;
  5093. }
  5094. function d3_geom_voronoiDetachCircle(arc) {
  5095. var circle = arc.circle;
  5096. if (circle) {
  5097. if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
  5098. d3_geom_voronoiCircles.remove(circle);
  5099. d3_geom_voronoiCirclePool.push(circle);
  5100. d3_geom_voronoiRedBlackNode(circle);
  5101. arc.circle = null;
  5102. }
  5103. }
  5104. function d3_geom_voronoiClipEdges(extent) {
  5105. 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;
  5106. while (i--) {
  5107. e = edges[i];
  5108. if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
  5109. e.a = e.b = null;
  5110. edges.splice(i, 1);
  5111. }
  5112. }
  5113. }
  5114. function d3_geom_voronoiConnectEdge(edge, extent) {
  5115. var vb = edge.b;
  5116. if (vb) return true;
  5117. 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;
  5118. if (ry === ly) {
  5119. if (fx < x0 || fx >= x1) return;
  5120. if (lx > rx) {
  5121. if (!va) va = {
  5122. x: fx,
  5123. y: y0
  5124. }; else if (va.y >= y1) return;
  5125. vb = {
  5126. x: fx,
  5127. y: y1
  5128. };
  5129. } else {
  5130. if (!va) va = {
  5131. x: fx,
  5132. y: y1
  5133. }; else if (va.y < y0) return;
  5134. vb = {
  5135. x: fx,
  5136. y: y0
  5137. };
  5138. }
  5139. } else {
  5140. fm = (lx - rx) / (ry - ly);
  5141. fb = fy - fm * fx;
  5142. if (fm < -1 || fm > 1) {
  5143. if (lx > rx) {
  5144. if (!va) va = {
  5145. x: (y0 - fb) / fm,
  5146. y: y0
  5147. }; else if (va.y >= y1) return;
  5148. vb = {
  5149. x: (y1 - fb) / fm,
  5150. y: y1
  5151. };
  5152. } else {
  5153. if (!va) va = {
  5154. x: (y1 - fb) / fm,
  5155. y: y1
  5156. }; else if (va.y < y0) return;
  5157. vb = {
  5158. x: (y0 - fb) / fm,
  5159. y: y0
  5160. };
  5161. }
  5162. } else {
  5163. if (ly < ry) {
  5164. if (!va) va = {
  5165. x: x0,
  5166. y: fm * x0 + fb
  5167. }; else if (va.x >= x1) return;
  5168. vb = {
  5169. x: x1,
  5170. y: fm * x1 + fb
  5171. };
  5172. } else {
  5173. if (!va) va = {
  5174. x: x1,
  5175. y: fm * x1 + fb
  5176. }; else if (va.x < x0) return;
  5177. vb = {
  5178. x: x0,
  5179. y: fm * x0 + fb
  5180. };
  5181. }
  5182. }
  5183. }
  5184. edge.a = va;
  5185. edge.b = vb;
  5186. return true;
  5187. }
  5188. function d3_geom_voronoiEdge(lSite, rSite) {
  5189. this.l = lSite;
  5190. this.r = rSite;
  5191. this.a = this.b = null;
  5192. }
  5193. function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
  5194. var edge = new d3_geom_voronoiEdge(lSite, rSite);
  5195. d3_geom_voronoiEdges.push(edge);
  5196. if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
  5197. if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
  5198. d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
  5199. d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
  5200. return edge;
  5201. }
  5202. function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
  5203. var edge = new d3_geom_voronoiEdge(lSite, null);
  5204. edge.a = va;
  5205. edge.b = vb;
  5206. d3_geom_voronoiEdges.push(edge);
  5207. return edge;
  5208. }
  5209. function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
  5210. if (!edge.a && !edge.b) {
  5211. edge.a = vertex;
  5212. edge.l = lSite;
  5213. edge.r = rSite;
  5214. } else if (edge.l === rSite) {
  5215. edge.b = vertex;
  5216. } else {
  5217. edge.a = vertex;
  5218. }
  5219. }
  5220. function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
  5221. var va = edge.a, vb = edge.b;
  5222. this.edge = edge;
  5223. this.site = lSite;
  5224. 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);
  5225. }
  5226. d3_geom_voronoiHalfEdge.prototype = {
  5227. start: function() {
  5228. return this.edge.l === this.site ? this.edge.a : this.edge.b;
  5229. },
  5230. end: function() {
  5231. return this.edge.l === this.site ? this.edge.b : this.edge.a;
  5232. }
  5233. };
  5234. function d3_geom_voronoiRedBlackTree() {
  5235. this._ = null;
  5236. }
  5237. function d3_geom_voronoiRedBlackNode(node) {
  5238. node.U = node.C = node.L = node.R = node.P = node.N = null;
  5239. }
  5240. d3_geom_voronoiRedBlackTree.prototype = {
  5241. insert: function(after, node) {
  5242. var parent, grandpa, uncle;
  5243. if (after) {
  5244. node.P = after;
  5245. node.N = after.N;
  5246. if (after.N) after.N.P = node;
  5247. after.N = node;
  5248. if (after.R) {
  5249. after = after.R;
  5250. while (after.L) after = after.L;
  5251. after.L = node;
  5252. } else {
  5253. after.R = node;
  5254. }
  5255. parent = after;
  5256. } else if (this._) {
  5257. after = d3_geom_voronoiRedBlackFirst(this._);
  5258. node.P = null;
  5259. node.N = after;
  5260. after.P = after.L = node;
  5261. parent = after;
  5262. } else {
  5263. node.P = node.N = null;
  5264. this._ = node;
  5265. parent = null;
  5266. }
  5267. node.L = node.R = null;
  5268. node.U = parent;
  5269. node.C = true;
  5270. after = node;
  5271. while (parent && parent.C) {
  5272. grandpa = parent.U;
  5273. if (parent === grandpa.L) {
  5274. uncle = grandpa.R;
  5275. if (uncle && uncle.C) {
  5276. parent.C = uncle.C = false;
  5277. grandpa.C = true;
  5278. after = grandpa;
  5279. } else {
  5280. if (after === parent.R) {
  5281. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5282. after = parent;
  5283. parent = after.U;
  5284. }
  5285. parent.C = false;
  5286. grandpa.C = true;
  5287. d3_geom_voronoiRedBlackRotateRight(this, grandpa);
  5288. }
  5289. } else {
  5290. uncle = grandpa.L;
  5291. if (uncle && uncle.C) {
  5292. parent.C = uncle.C = false;
  5293. grandpa.C = true;
  5294. after = grandpa;
  5295. } else {
  5296. if (after === parent.L) {
  5297. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5298. after = parent;
  5299. parent = after.U;
  5300. }
  5301. parent.C = false;
  5302. grandpa.C = true;
  5303. d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
  5304. }
  5305. }
  5306. parent = after.U;
  5307. }
  5308. this._.C = false;
  5309. },
  5310. remove: function(node) {
  5311. if (node.N) node.N.P = node.P;
  5312. if (node.P) node.P.N = node.N;
  5313. node.N = node.P = null;
  5314. var parent = node.U, sibling, left = node.L, right = node.R, next, red;
  5315. if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
  5316. if (parent) {
  5317. if (parent.L === node) parent.L = next; else parent.R = next;
  5318. } else {
  5319. this._ = next;
  5320. }
  5321. if (left && right) {
  5322. red = next.C;
  5323. next.C = node.C;
  5324. next.L = left;
  5325. left.U = next;
  5326. if (next !== right) {
  5327. parent = next.U;
  5328. next.U = node.U;
  5329. node = next.R;
  5330. parent.L = node;
  5331. next.R = right;
  5332. right.U = next;
  5333. } else {
  5334. next.U = parent;
  5335. parent = next;
  5336. node = next.R;
  5337. }
  5338. } else {
  5339. red = node.C;
  5340. node = next;
  5341. }
  5342. if (node) node.U = parent;
  5343. if (red) return;
  5344. if (node && node.C) {
  5345. node.C = false;
  5346. return;
  5347. }
  5348. do {
  5349. if (node === this._) break;
  5350. if (node === parent.L) {
  5351. sibling = parent.R;
  5352. if (sibling.C) {
  5353. sibling.C = false;
  5354. parent.C = true;
  5355. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5356. sibling = parent.R;
  5357. }
  5358. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5359. if (!sibling.R || !sibling.R.C) {
  5360. sibling.L.C = false;
  5361. sibling.C = true;
  5362. d3_geom_voronoiRedBlackRotateRight(this, sibling);
  5363. sibling = parent.R;
  5364. }
  5365. sibling.C = parent.C;
  5366. parent.C = sibling.R.C = false;
  5367. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  5368. node = this._;
  5369. break;
  5370. }
  5371. } else {
  5372. sibling = parent.L;
  5373. if (sibling.C) {
  5374. sibling.C = false;
  5375. parent.C = true;
  5376. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5377. sibling = parent.L;
  5378. }
  5379. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  5380. if (!sibling.L || !sibling.L.C) {
  5381. sibling.R.C = false;
  5382. sibling.C = true;
  5383. d3_geom_voronoiRedBlackRotateLeft(this, sibling);
  5384. sibling = parent.L;
  5385. }
  5386. sibling.C = parent.C;
  5387. parent.C = sibling.L.C = false;
  5388. d3_geom_voronoiRedBlackRotateRight(this, parent);
  5389. node = this._;
  5390. break;
  5391. }
  5392. }
  5393. sibling.C = true;
  5394. node = parent;
  5395. parent = parent.U;
  5396. } while (!node.C);
  5397. if (node) node.C = false;
  5398. }
  5399. };
  5400. function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
  5401. var p = node, q = node.R, parent = p.U;
  5402. if (parent) {
  5403. if (parent.L === p) parent.L = q; else parent.R = q;
  5404. } else {
  5405. tree._ = q;
  5406. }
  5407. q.U = parent;
  5408. p.U = q;
  5409. p.R = q.L;
  5410. if (p.R) p.R.U = p;
  5411. q.L = p;
  5412. }
  5413. function d3_geom_voronoiRedBlackRotateRight(tree, node) {
  5414. var p = node, q = node.L, parent = p.U;
  5415. if (parent) {
  5416. if (parent.L === p) parent.L = q; else parent.R = q;
  5417. } else {
  5418. tree._ = q;
  5419. }
  5420. q.U = parent;
  5421. p.U = q;
  5422. p.L = q.R;
  5423. if (p.L) p.L.U = p;
  5424. q.R = p;
  5425. }
  5426. function d3_geom_voronoiRedBlackFirst(node) {
  5427. while (node.L) node = node.L;
  5428. return node;
  5429. }
  5430. function d3_geom_voronoi(sites, bbox) {
  5431. var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
  5432. d3_geom_voronoiEdges = [];
  5433. d3_geom_voronoiCells = new Array(sites.length);
  5434. d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
  5435. d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
  5436. while (true) {
  5437. circle = d3_geom_voronoiFirstCircle;
  5438. if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
  5439. if (site.x !== x0 || site.y !== y0) {
  5440. d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
  5441. d3_geom_voronoiAddBeach(site);
  5442. x0 = site.x, y0 = site.y;
  5443. }
  5444. site = sites.pop();
  5445. } else if (circle) {
  5446. d3_geom_voronoiRemoveBeach(circle.arc);
  5447. } else {
  5448. break;
  5449. }
  5450. }
  5451. if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
  5452. var diagram = {
  5453. cells: d3_geom_voronoiCells,
  5454. edges: d3_geom_voronoiEdges
  5455. };
  5456. d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
  5457. return diagram;
  5458. }
  5459. function d3_geom_voronoiVertexOrder(a, b) {
  5460. return b.y - a.y || b.x - a.x;
  5461. }
  5462. d3.geom.voronoi = function(points) {
  5463. var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
  5464. if (points) return voronoi(points);
  5465. function voronoi(data) {
  5466. var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
  5467. d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
  5468. var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
  5469. var s = e.start();
  5470. return [ s.x, s.y ];
  5471. }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
  5472. polygon.point = data[i];
  5473. });
  5474. return polygons;
  5475. }
  5476. function sites(data) {
  5477. return data.map(function(d, i) {
  5478. return {
  5479. x: Math.round(fx(d, i) / ε) * ε,
  5480. y: Math.round(fy(d, i) / ε) * ε,
  5481. i: i
  5482. };
  5483. });
  5484. }
  5485. voronoi.links = function(data) {
  5486. return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
  5487. return edge.l && edge.r;
  5488. }).map(function(edge) {
  5489. return {
  5490. source: data[edge.l.i],
  5491. target: data[edge.r.i]
  5492. };
  5493. });
  5494. };
  5495. voronoi.triangles = function(data) {
  5496. var triangles = [];
  5497. d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
  5498. 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;
  5499. while (++j < m) {
  5500. e0 = e1;
  5501. s0 = s1;
  5502. e1 = edges[j].edge;
  5503. s1 = e1.l === site ? e1.r : e1.l;
  5504. if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
  5505. triangles.push([ data[i], data[s0.i], data[s1.i] ]);
  5506. }
  5507. }
  5508. });
  5509. return triangles;
  5510. };
  5511. voronoi.x = function(_) {
  5512. return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
  5513. };
  5514. voronoi.y = function(_) {
  5515. return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
  5516. };
  5517. voronoi.clipExtent = function(_) {
  5518. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
  5519. clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
  5520. return voronoi;
  5521. };
  5522. voronoi.size = function(_) {
  5523. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
  5524. return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
  5525. };
  5526. return voronoi;
  5527. };
  5528. var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
  5529. function d3_geom_voronoiTriangleArea(a, b, c) {
  5530. return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
  5531. }
  5532. d3.geom.delaunay = function(vertices) {
  5533. return d3.geom.voronoi().triangles(vertices);
  5534. };
  5535. d3.geom.quadtree = function(points, x1, y1, x2, y2) {
  5536. var x = d3_geom_pointX, y = d3_geom_pointY, compat;
  5537. if (compat = arguments.length) {
  5538. x = d3_geom_quadtreeCompatX;
  5539. y = d3_geom_quadtreeCompatY;
  5540. if (compat === 3) {
  5541. y2 = y1;
  5542. x2 = x1;
  5543. y1 = x1 = 0;
  5544. }
  5545. return quadtree(points);
  5546. }
  5547. function quadtree(data) {
  5548. var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
  5549. if (x1 != null) {
  5550. x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
  5551. } else {
  5552. x2_ = y2_ = -(x1_ = y1_ = Infinity);
  5553. xs = [], ys = [];
  5554. n = data.length;
  5555. if (compat) for (i = 0; i < n; ++i) {
  5556. d = data[i];
  5557. if (d.x < x1_) x1_ = d.x;
  5558. if (d.y < y1_) y1_ = d.y;
  5559. if (d.x > x2_) x2_ = d.x;
  5560. if (d.y > y2_) y2_ = d.y;
  5561. xs.push(d.x);
  5562. ys.push(d.y);
  5563. } else for (i = 0; i < n; ++i) {
  5564. var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
  5565. if (x_ < x1_) x1_ = x_;
  5566. if (y_ < y1_) y1_ = y_;
  5567. if (x_ > x2_) x2_ = x_;
  5568. if (y_ > y2_) y2_ = y_;
  5569. xs.push(x_);
  5570. ys.push(y_);
  5571. }
  5572. }
  5573. var dx = x2_ - x1_, dy = y2_ - y1_;
  5574. if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
  5575. function insert(n, d, x, y, x1, y1, x2, y2) {
  5576. if (isNaN(x) || isNaN(y)) return;
  5577. if (n.leaf) {
  5578. var nx = n.x, ny = n.y;
  5579. if (nx != null) {
  5580. if (abs(nx - x) + abs(ny - y) < .01) {
  5581. insertChild(n, d, x, y, x1, y1, x2, y2);
  5582. } else {
  5583. var nPoint = n.point;
  5584. n.x = n.y = n.point = null;
  5585. insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
  5586. insertChild(n, d, x, y, x1, y1, x2, y2);
  5587. }
  5588. } else {
  5589. n.x = x, n.y = y, n.point = d;
  5590. }
  5591. } else {
  5592. insertChild(n, d, x, y, x1, y1, x2, y2);
  5593. }
  5594. }
  5595. function insertChild(n, d, x, y, x1, y1, x2, y2) {
  5596. var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
  5597. n.leaf = false;
  5598. n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
  5599. if (right) x1 = xm; else x2 = xm;
  5600. if (below) y1 = ym; else y2 = ym;
  5601. insert(n, d, x, y, x1, y1, x2, y2);
  5602. }
  5603. var root = d3_geom_quadtreeNode();
  5604. root.add = function(d) {
  5605. insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
  5606. };
  5607. root.visit = function(f) {
  5608. d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
  5609. };
  5610. root.find = function(point) {
  5611. return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
  5612. };
  5613. i = -1;
  5614. if (x1 == null) {
  5615. while (++i < n) {
  5616. insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
  5617. }
  5618. --i;
  5619. } else data.forEach(root.add);
  5620. xs = ys = data = d = null;
  5621. return root;
  5622. }
  5623. quadtree.x = function(_) {
  5624. return arguments.length ? (x = _, quadtree) : x;
  5625. };
  5626. quadtree.y = function(_) {
  5627. return arguments.length ? (y = _, quadtree) : y;
  5628. };
  5629. quadtree.extent = function(_) {
  5630. if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
  5631. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
  5632. y2 = +_[1][1];
  5633. return quadtree;
  5634. };
  5635. quadtree.size = function(_) {
  5636. if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
  5637. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
  5638. return quadtree;
  5639. };
  5640. return quadtree;
  5641. };
  5642. function d3_geom_quadtreeCompatX(d) {
  5643. return d.x;
  5644. }
  5645. function d3_geom_quadtreeCompatY(d) {
  5646. return d.y;
  5647. }
  5648. function d3_geom_quadtreeNode() {
  5649. return {
  5650. leaf: true,
  5651. nodes: [],
  5652. point: null,
  5653. x: null,
  5654. y: null
  5655. };
  5656. }
  5657. function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
  5658. if (!f(node, x1, y1, x2, y2)) {
  5659. var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
  5660. if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
  5661. if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
  5662. if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
  5663. if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
  5664. }
  5665. }
  5666. function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
  5667. var minDistance2 = Infinity, closestPoint;
  5668. (function find(node, x1, y1, x2, y2) {
  5669. if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
  5670. if (point = node.point) {
  5671. var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
  5672. if (distance2 < minDistance2) {
  5673. var distance = Math.sqrt(minDistance2 = distance2);
  5674. x0 = x - distance, y0 = y - distance;
  5675. x3 = x + distance, y3 = y + distance;
  5676. closestPoint = point;
  5677. }
  5678. }
  5679. var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
  5680. for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
  5681. if (node = children[i & 3]) switch (i & 3) {
  5682. case 0:
  5683. find(node, x1, y1, xm, ym);
  5684. break;
  5685. case 1:
  5686. find(node, xm, y1, x2, ym);
  5687. break;
  5688. case 2:
  5689. find(node, x1, ym, xm, y2);
  5690. break;
  5691. case 3:
  5692. find(node, xm, ym, x2, y2);
  5693. break;
  5694. }
  5695. }
  5696. })(root, x0, y0, x3, y3);
  5697. return closestPoint;
  5698. }
  5699. d3.interpolateRgb = d3_interpolateRgb;
  5700. function d3_interpolateRgb(a, b) {
  5701. a = d3.rgb(a);
  5702. b = d3.rgb(b);
  5703. var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
  5704. return function(t) {
  5705. 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));
  5706. };
  5707. }
  5708. d3.interpolateObject = d3_interpolateObject;
  5709. function d3_interpolateObject(a, b) {
  5710. var i = {}, c = {}, k;
  5711. for (k in a) {
  5712. if (k in b) {
  5713. i[k] = d3_interpolate(a[k], b[k]);
  5714. } else {
  5715. c[k] = a[k];
  5716. }
  5717. }
  5718. for (k in b) {
  5719. if (!(k in a)) {
  5720. c[k] = b[k];
  5721. }
  5722. }
  5723. return function(t) {
  5724. for (k in i) c[k] = i[k](t);
  5725. return c;
  5726. };
  5727. }
  5728. d3.interpolateNumber = d3_interpolateNumber;
  5729. function d3_interpolateNumber(a, b) {
  5730. a = +a, b = +b;
  5731. return function(t) {
  5732. return a * (1 - t) + b * t;
  5733. };
  5734. }
  5735. d3.interpolateString = d3_interpolateString;
  5736. function d3_interpolateString(a, b) {
  5737. var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
  5738. a = a + "", b = b + "";
  5739. while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
  5740. if ((bs = bm.index) > bi) {
  5741. bs = b.slice(bi, bs);
  5742. if (s[i]) s[i] += bs; else s[++i] = bs;
  5743. }
  5744. if ((am = am[0]) === (bm = bm[0])) {
  5745. if (s[i]) s[i] += bm; else s[++i] = bm;
  5746. } else {
  5747. s[++i] = null;
  5748. q.push({
  5749. i: i,
  5750. x: d3_interpolateNumber(am, bm)
  5751. });
  5752. }
  5753. bi = d3_interpolate_numberB.lastIndex;
  5754. }
  5755. if (bi < b.length) {
  5756. bs = b.slice(bi);
  5757. if (s[i]) s[i] += bs; else s[++i] = bs;
  5758. }
  5759. return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
  5760. return b(t) + "";
  5761. }) : function() {
  5762. return b;
  5763. } : (b = q.length, function(t) {
  5764. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  5765. return s.join("");
  5766. });
  5767. }
  5768. var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
  5769. d3.interpolate = d3_interpolate;
  5770. function d3_interpolate(a, b) {
  5771. var i = d3.interpolators.length, f;
  5772. while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
  5773. return f;
  5774. }
  5775. d3.interpolators = [ function(a, b) {
  5776. var t = typeof b;
  5777. return (t === "string" ? d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\(|hsl\()/i.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);
  5778. } ];
  5779. d3.interpolateArray = d3_interpolateArray;
  5780. function d3_interpolateArray(a, b) {
  5781. var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
  5782. for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
  5783. for (;i < na; ++i) c[i] = a[i];
  5784. for (;i < nb; ++i) c[i] = b[i];
  5785. return function(t) {
  5786. for (i = 0; i < n0; ++i) c[i] = x[i](t);
  5787. return c;
  5788. };
  5789. }
  5790. var d3_ease_default = function() {
  5791. return d3_identity;
  5792. };
  5793. var d3_ease = d3.map({
  5794. linear: d3_ease_default,
  5795. poly: d3_ease_poly,
  5796. quad: function() {
  5797. return d3_ease_quad;
  5798. },
  5799. cubic: function() {
  5800. return d3_ease_cubic;
  5801. },
  5802. sin: function() {
  5803. return d3_ease_sin;
  5804. },
  5805. exp: function() {
  5806. return d3_ease_exp;
  5807. },
  5808. circle: function() {
  5809. return d3_ease_circle;
  5810. },
  5811. elastic: d3_ease_elastic,
  5812. back: d3_ease_back,
  5813. bounce: function() {
  5814. return d3_ease_bounce;
  5815. }
  5816. });
  5817. var d3_ease_mode = d3.map({
  5818. "in": d3_identity,
  5819. out: d3_ease_reverse,
  5820. "in-out": d3_ease_reflect,
  5821. "out-in": function(f) {
  5822. return d3_ease_reflect(d3_ease_reverse(f));
  5823. }
  5824. });
  5825. d3.ease = function(name) {
  5826. var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
  5827. t = d3_ease.get(t) || d3_ease_default;
  5828. m = d3_ease_mode.get(m) || d3_identity;
  5829. return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
  5830. };
  5831. function d3_ease_clamp(f) {
  5832. return function(t) {
  5833. return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
  5834. };
  5835. }
  5836. function d3_ease_reverse(f) {
  5837. return function(t) {
  5838. return 1 - f(1 - t);
  5839. };
  5840. }
  5841. function d3_ease_reflect(f) {
  5842. return function(t) {
  5843. return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
  5844. };
  5845. }
  5846. function d3_ease_quad(t) {
  5847. return t * t;
  5848. }
  5849. function d3_ease_cubic(t) {
  5850. return t * t * t;
  5851. }
  5852. function d3_ease_cubicInOut(t) {
  5853. if (t <= 0) return 0;
  5854. if (t >= 1) return 1;
  5855. var t2 = t * t, t3 = t2 * t;
  5856. return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
  5857. }
  5858. function d3_ease_poly(e) {
  5859. return function(t) {
  5860. return Math.pow(t, e);
  5861. };
  5862. }
  5863. function d3_ease_sin(t) {
  5864. return 1 - Math.cos(t * halfπ);
  5865. }
  5866. function d3_ease_exp(t) {
  5867. return Math.pow(2, 10 * (t - 1));
  5868. }
  5869. function d3_ease_circle(t) {
  5870. return 1 - Math.sqrt(1 - t * t);
  5871. }
  5872. function d3_ease_elastic(a, p) {
  5873. var s;
  5874. if (arguments.length < 2) p = .45;
  5875. if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
  5876. return function(t) {
  5877. return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
  5878. };
  5879. }
  5880. function d3_ease_back(s) {
  5881. if (!s) s = 1.70158;
  5882. return function(t) {
  5883. return t * t * ((s + 1) * t - s);
  5884. };
  5885. }
  5886. function d3_ease_bounce(t) {
  5887. 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;
  5888. }
  5889. d3.interpolateHcl = d3_interpolateHcl;
  5890. function d3_interpolateHcl(a, b) {
  5891. a = d3.hcl(a);
  5892. b = d3.hcl(b);
  5893. var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
  5894. if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
  5895. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5896. return function(t) {
  5897. return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
  5898. };
  5899. }
  5900. d3.interpolateHsl = d3_interpolateHsl;
  5901. function d3_interpolateHsl(a, b) {
  5902. a = d3.hsl(a);
  5903. b = d3.hsl(b);
  5904. var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
  5905. if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
  5906. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  5907. return function(t) {
  5908. return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
  5909. };
  5910. }
  5911. d3.interpolateLab = d3_interpolateLab;
  5912. function d3_interpolateLab(a, b) {
  5913. a = d3.lab(a);
  5914. b = d3.lab(b);
  5915. var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
  5916. return function(t) {
  5917. return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
  5918. };
  5919. }
  5920. d3.interpolateRound = d3_interpolateRound;
  5921. function d3_interpolateRound(a, b) {
  5922. b -= a;
  5923. return function(t) {
  5924. return Math.round(a + b * t);
  5925. };
  5926. }
  5927. d3.transform = function(string) {
  5928. var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
  5929. return (d3.transform = function(string) {
  5930. if (string != null) {
  5931. g.setAttribute("transform", string);
  5932. var t = g.transform.baseVal.consolidate();
  5933. }
  5934. return new d3_transform(t ? t.matrix : d3_transformIdentity);
  5935. })(string);
  5936. };
  5937. function d3_transform(m) {
  5938. 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;
  5939. if (r0[0] * r1[1] < r1[0] * r0[1]) {
  5940. r0[0] *= -1;
  5941. r0[1] *= -1;
  5942. kx *= -1;
  5943. kz *= -1;
  5944. }
  5945. this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
  5946. this.translate = [ m.e, m.f ];
  5947. this.scale = [ kx, ky ];
  5948. this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
  5949. }
  5950. d3_transform.prototype.toString = function() {
  5951. return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
  5952. };
  5953. function d3_transformDot(a, b) {
  5954. return a[0] * b[0] + a[1] * b[1];
  5955. }
  5956. function d3_transformNormalize(a) {
  5957. var k = Math.sqrt(d3_transformDot(a, a));
  5958. if (k) {
  5959. a[0] /= k;
  5960. a[1] /= k;
  5961. }
  5962. return k;
  5963. }
  5964. function d3_transformCombine(a, b, k) {
  5965. a[0] += k * b[0];
  5966. a[1] += k * b[1];
  5967. return a;
  5968. }
  5969. var d3_transformIdentity = {
  5970. a: 1,
  5971. b: 0,
  5972. c: 0,
  5973. d: 1,
  5974. e: 0,
  5975. f: 0
  5976. };
  5977. d3.interpolateTransform = d3_interpolateTransform;
  5978. function d3_interpolateTransform(a, b) {
  5979. 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;
  5980. if (ta[0] != tb[0] || ta[1] != tb[1]) {
  5981. s.push("translate(", null, ",", null, ")");
  5982. q.push({
  5983. i: 1,
  5984. x: d3_interpolateNumber(ta[0], tb[0])
  5985. }, {
  5986. i: 3,
  5987. x: d3_interpolateNumber(ta[1], tb[1])
  5988. });
  5989. } else if (tb[0] || tb[1]) {
  5990. s.push("translate(" + tb + ")");
  5991. } else {
  5992. s.push("");
  5993. }
  5994. if (ra != rb) {
  5995. if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
  5996. q.push({
  5997. i: s.push(s.pop() + "rotate(", null, ")") - 2,
  5998. x: d3_interpolateNumber(ra, rb)
  5999. });
  6000. } else if (rb) {
  6001. s.push(s.pop() + "rotate(" + rb + ")");
  6002. }
  6003. if (wa != wb) {
  6004. q.push({
  6005. i: s.push(s.pop() + "skewX(", null, ")") - 2,
  6006. x: d3_interpolateNumber(wa, wb)
  6007. });
  6008. } else if (wb) {
  6009. s.push(s.pop() + "skewX(" + wb + ")");
  6010. }
  6011. if (ka[0] != kb[0] || ka[1] != kb[1]) {
  6012. n = s.push(s.pop() + "scale(", null, ",", null, ")");
  6013. q.push({
  6014. i: n - 4,
  6015. x: d3_interpolateNumber(ka[0], kb[0])
  6016. }, {
  6017. i: n - 2,
  6018. x: d3_interpolateNumber(ka[1], kb[1])
  6019. });
  6020. } else if (kb[0] != 1 || kb[1] != 1) {
  6021. s.push(s.pop() + "scale(" + kb + ")");
  6022. }
  6023. n = q.length;
  6024. return function(t) {
  6025. var i = -1, o;
  6026. while (++i < n) s[(o = q[i]).i] = o.x(t);
  6027. return s.join("");
  6028. };
  6029. }
  6030. function d3_uninterpolateNumber(a, b) {
  6031. b = (b -= a = +a) || 1 / b;
  6032. return function(x) {
  6033. return (x - a) / b;
  6034. };
  6035. }
  6036. function d3_uninterpolateClamp(a, b) {
  6037. b = (b -= a = +a) || 1 / b;
  6038. return function(x) {
  6039. return Math.max(0, Math.min(1, (x - a) / b));
  6040. };
  6041. }
  6042. d3.layout = {};
  6043. d3.layout.bundle = function() {
  6044. return function(links) {
  6045. var paths = [], i = -1, n = links.length;
  6046. while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
  6047. return paths;
  6048. };
  6049. };
  6050. function d3_layout_bundlePath(link) {
  6051. var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
  6052. while (start !== lca) {
  6053. start = start.parent;
  6054. points.push(start);
  6055. }
  6056. var k = points.length;
  6057. while (end !== lca) {
  6058. points.splice(k, 0, end);
  6059. end = end.parent;
  6060. }
  6061. return points;
  6062. }
  6063. function d3_layout_bundleAncestors(node) {
  6064. var ancestors = [], parent = node.parent;
  6065. while (parent != null) {
  6066. ancestors.push(node);
  6067. node = parent;
  6068. parent = parent.parent;
  6069. }
  6070. ancestors.push(node);
  6071. return ancestors;
  6072. }
  6073. function d3_layout_bundleLeastCommonAncestor(a, b) {
  6074. if (a === b) return a;
  6075. var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
  6076. while (aNode === bNode) {
  6077. sharedNode = aNode;
  6078. aNode = aNodes.pop();
  6079. bNode = bNodes.pop();
  6080. }
  6081. return sharedNode;
  6082. }
  6083. d3.layout.chord = function() {
  6084. var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
  6085. function relayout() {
  6086. var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
  6087. chords = [];
  6088. groups = [];
  6089. k = 0, i = -1;
  6090. while (++i < n) {
  6091. x = 0, j = -1;
  6092. while (++j < n) {
  6093. x += matrix[i][j];
  6094. }
  6095. groupSums.push(x);
  6096. subgroupIndex.push(d3.range(n));
  6097. k += x;
  6098. }
  6099. if (sortGroups) {
  6100. groupIndex.sort(function(a, b) {
  6101. return sortGroups(groupSums[a], groupSums[b]);
  6102. });
  6103. }
  6104. if (sortSubgroups) {
  6105. subgroupIndex.forEach(function(d, i) {
  6106. d.sort(function(a, b) {
  6107. return sortSubgroups(matrix[i][a], matrix[i][b]);
  6108. });
  6109. });
  6110. }
  6111. k = (τ - padding * n) / k;
  6112. x = 0, i = -1;
  6113. while (++i < n) {
  6114. x0 = x, j = -1;
  6115. while (++j < n) {
  6116. var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
  6117. subgroups[di + "-" + dj] = {
  6118. index: di,
  6119. subindex: dj,
  6120. startAngle: a0,
  6121. endAngle: a1,
  6122. value: v
  6123. };
  6124. }
  6125. groups[di] = {
  6126. index: di,
  6127. startAngle: x0,
  6128. endAngle: x,
  6129. value: (x - x0) / k
  6130. };
  6131. x += padding;
  6132. }
  6133. i = -1;
  6134. while (++i < n) {
  6135. j = i - 1;
  6136. while (++j < n) {
  6137. var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
  6138. if (source.value || target.value) {
  6139. chords.push(source.value < target.value ? {
  6140. source: target,
  6141. target: source
  6142. } : {
  6143. source: source,
  6144. target: target
  6145. });
  6146. }
  6147. }
  6148. }
  6149. if (sortChords) resort();
  6150. }
  6151. function resort() {
  6152. chords.sort(function(a, b) {
  6153. return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
  6154. });
  6155. }
  6156. chord.matrix = function(x) {
  6157. if (!arguments.length) return matrix;
  6158. n = (matrix = x) && matrix.length;
  6159. chords = groups = null;
  6160. return chord;
  6161. };
  6162. chord.padding = function(x) {
  6163. if (!arguments.length) return padding;
  6164. padding = x;
  6165. chords = groups = null;
  6166. return chord;
  6167. };
  6168. chord.sortGroups = function(x) {
  6169. if (!arguments.length) return sortGroups;
  6170. sortGroups = x;
  6171. chords = groups = null;
  6172. return chord;
  6173. };
  6174. chord.sortSubgroups = function(x) {
  6175. if (!arguments.length) return sortSubgroups;
  6176. sortSubgroups = x;
  6177. chords = null;
  6178. return chord;
  6179. };
  6180. chord.sortChords = function(x) {
  6181. if (!arguments.length) return sortChords;
  6182. sortChords = x;
  6183. if (chords) resort();
  6184. return chord;
  6185. };
  6186. chord.chords = function() {
  6187. if (!chords) relayout();
  6188. return chords;
  6189. };
  6190. chord.groups = function() {
  6191. if (!groups) relayout();
  6192. return groups;
  6193. };
  6194. return chord;
  6195. };
  6196. d3.layout.force = function() {
  6197. 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;
  6198. function repulse(node) {
  6199. return function(quad, x1, _, x2) {
  6200. if (quad.point !== node) {
  6201. var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
  6202. if (dw * dw / theta2 < dn) {
  6203. if (dn < chargeDistance2) {
  6204. var k = quad.charge / dn;
  6205. node.px -= dx * k;
  6206. node.py -= dy * k;
  6207. }
  6208. return true;
  6209. }
  6210. if (quad.point && dn && dn < chargeDistance2) {
  6211. var k = quad.pointCharge / dn;
  6212. node.px -= dx * k;
  6213. node.py -= dy * k;
  6214. }
  6215. }
  6216. return !quad.charge;
  6217. };
  6218. }
  6219. force.tick = function() {
  6220. if ((alpha *= .99) < .005) {
  6221. event.end({
  6222. type: "end",
  6223. alpha: alpha = 0
  6224. });
  6225. return true;
  6226. }
  6227. var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
  6228. for (i = 0; i < m; ++i) {
  6229. o = links[i];
  6230. s = o.source;
  6231. t = o.target;
  6232. x = t.x - s.x;
  6233. y = t.y - s.y;
  6234. if (l = x * x + y * y) {
  6235. l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
  6236. x *= l;
  6237. y *= l;
  6238. t.x -= x * (k = s.weight / (t.weight + s.weight));
  6239. t.y -= y * k;
  6240. s.x += x * (k = 1 - k);
  6241. s.y += y * k;
  6242. }
  6243. }
  6244. if (k = alpha * gravity) {
  6245. x = size[0] / 2;
  6246. y = size[1] / 2;
  6247. i = -1;
  6248. if (k) while (++i < n) {
  6249. o = nodes[i];
  6250. o.x += (x - o.x) * k;
  6251. o.y += (y - o.y) * k;
  6252. }
  6253. }
  6254. if (charge) {
  6255. d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
  6256. i = -1;
  6257. while (++i < n) {
  6258. if (!(o = nodes[i]).fixed) {
  6259. q.visit(repulse(o));
  6260. }
  6261. }
  6262. }
  6263. i = -1;
  6264. while (++i < n) {
  6265. o = nodes[i];
  6266. if (o.fixed) {
  6267. o.x = o.px;
  6268. o.y = o.py;
  6269. } else {
  6270. o.x -= (o.px - (o.px = o.x)) * friction;
  6271. o.y -= (o.py - (o.py = o.y)) * friction;
  6272. }
  6273. }
  6274. event.tick({
  6275. type: "tick",
  6276. alpha: alpha
  6277. });
  6278. };
  6279. force.nodes = function(x) {
  6280. if (!arguments.length) return nodes;
  6281. nodes = x;
  6282. return force;
  6283. };
  6284. force.links = function(x) {
  6285. if (!arguments.length) return links;
  6286. links = x;
  6287. return force;
  6288. };
  6289. force.size = function(x) {
  6290. if (!arguments.length) return size;
  6291. size = x;
  6292. return force;
  6293. };
  6294. force.linkDistance = function(x) {
  6295. if (!arguments.length) return linkDistance;
  6296. linkDistance = typeof x === "function" ? x : +x;
  6297. return force;
  6298. };
  6299. force.distance = force.linkDistance;
  6300. force.linkStrength = function(x) {
  6301. if (!arguments.length) return linkStrength;
  6302. linkStrength = typeof x === "function" ? x : +x;
  6303. return force;
  6304. };
  6305. force.friction = function(x) {
  6306. if (!arguments.length) return friction;
  6307. friction = +x;
  6308. return force;
  6309. };
  6310. force.charge = function(x) {
  6311. if (!arguments.length) return charge;
  6312. charge = typeof x === "function" ? x : +x;
  6313. return force;
  6314. };
  6315. force.chargeDistance = function(x) {
  6316. if (!arguments.length) return Math.sqrt(chargeDistance2);
  6317. chargeDistance2 = x * x;
  6318. return force;
  6319. };
  6320. force.gravity = function(x) {
  6321. if (!arguments.length) return gravity;
  6322. gravity = +x;
  6323. return force;
  6324. };
  6325. force.theta = function(x) {
  6326. if (!arguments.length) return Math.sqrt(theta2);
  6327. theta2 = x * x;
  6328. return force;
  6329. };
  6330. force.alpha = function(x) {
  6331. if (!arguments.length) return alpha;
  6332. x = +x;
  6333. if (alpha) {
  6334. if (x > 0) alpha = x; else alpha = 0;
  6335. } else if (x > 0) {
  6336. event.start({
  6337. type: "start",
  6338. alpha: alpha = x
  6339. });
  6340. d3.timer(force.tick);
  6341. }
  6342. return force;
  6343. };
  6344. force.start = function() {
  6345. var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
  6346. for (i = 0; i < n; ++i) {
  6347. (o = nodes[i]).index = i;
  6348. o.weight = 0;
  6349. }
  6350. for (i = 0; i < m; ++i) {
  6351. o = links[i];
  6352. if (typeof o.source == "number") o.source = nodes[o.source];
  6353. if (typeof o.target == "number") o.target = nodes[o.target];
  6354. ++o.source.weight;
  6355. ++o.target.weight;
  6356. }
  6357. for (i = 0; i < n; ++i) {
  6358. o = nodes[i];
  6359. if (isNaN(o.x)) o.x = position("x", w);
  6360. if (isNaN(o.y)) o.y = position("y", h);
  6361. if (isNaN(o.px)) o.px = o.x;
  6362. if (isNaN(o.py)) o.py = o.y;
  6363. }
  6364. distances = [];
  6365. 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;
  6366. strengths = [];
  6367. 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;
  6368. charges = [];
  6369. 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;
  6370. function position(dimension, size) {
  6371. if (!neighbors) {
  6372. neighbors = new Array(n);
  6373. for (j = 0; j < n; ++j) {
  6374. neighbors[j] = [];
  6375. }
  6376. for (j = 0; j < m; ++j) {
  6377. var o = links[j];
  6378. neighbors[o.source.index].push(o.target);
  6379. neighbors[o.target.index].push(o.source);
  6380. }
  6381. }
  6382. var candidates = neighbors[i], j = -1, l = candidates.length, x;
  6383. while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
  6384. return Math.random() * size;
  6385. }
  6386. return force.resume();
  6387. };
  6388. force.resume = function() {
  6389. return force.alpha(.1);
  6390. };
  6391. force.stop = function() {
  6392. return force.alpha(0);
  6393. };
  6394. force.drag = function() {
  6395. 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);
  6396. if (!arguments.length) return drag;
  6397. this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
  6398. };
  6399. function dragmove(d) {
  6400. d.px = d3.event.x, d.py = d3.event.y;
  6401. force.resume();
  6402. }
  6403. return d3.rebind(force, event, "on");
  6404. };
  6405. function d3_layout_forceDragstart(d) {
  6406. d.fixed |= 2;
  6407. }
  6408. function d3_layout_forceDragend(d) {
  6409. d.fixed &= ~6;
  6410. }
  6411. function d3_layout_forceMouseover(d) {
  6412. d.fixed |= 4;
  6413. d.px = d.x, d.py = d.y;
  6414. }
  6415. function d3_layout_forceMouseout(d) {
  6416. d.fixed &= ~4;
  6417. }
  6418. function d3_layout_forceAccumulate(quad, alpha, charges) {
  6419. var cx = 0, cy = 0;
  6420. quad.charge = 0;
  6421. if (!quad.leaf) {
  6422. var nodes = quad.nodes, n = nodes.length, i = -1, c;
  6423. while (++i < n) {
  6424. c = nodes[i];
  6425. if (c == null) continue;
  6426. d3_layout_forceAccumulate(c, alpha, charges);
  6427. quad.charge += c.charge;
  6428. cx += c.charge * c.cx;
  6429. cy += c.charge * c.cy;
  6430. }
  6431. }
  6432. if (quad.point) {
  6433. if (!quad.leaf) {
  6434. quad.point.x += Math.random() - .5;
  6435. quad.point.y += Math.random() - .5;
  6436. }
  6437. var k = alpha * charges[quad.point.index];
  6438. quad.charge += quad.pointCharge = k;
  6439. cx += k * quad.point.x;
  6440. cy += k * quad.point.y;
  6441. }
  6442. quad.cx = cx / quad.charge;
  6443. quad.cy = cy / quad.charge;
  6444. }
  6445. var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
  6446. d3.layout.hierarchy = function() {
  6447. var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
  6448. function hierarchy(root) {
  6449. var stack = [ root ], nodes = [], node;
  6450. root.depth = 0;
  6451. while ((node = stack.pop()) != null) {
  6452. nodes.push(node);
  6453. if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
  6454. var n, childs, child;
  6455. while (--n >= 0) {
  6456. stack.push(child = childs[n]);
  6457. child.parent = node;
  6458. child.depth = node.depth + 1;
  6459. }
  6460. if (value) node.value = 0;
  6461. node.children = childs;
  6462. } else {
  6463. if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6464. delete node.children;
  6465. }
  6466. }
  6467. d3_layout_hierarchyVisitAfter(root, function(node) {
  6468. var childs, parent;
  6469. if (sort && (childs = node.children)) childs.sort(sort);
  6470. if (value && (parent = node.parent)) parent.value += node.value;
  6471. });
  6472. return nodes;
  6473. }
  6474. hierarchy.sort = function(x) {
  6475. if (!arguments.length) return sort;
  6476. sort = x;
  6477. return hierarchy;
  6478. };
  6479. hierarchy.children = function(x) {
  6480. if (!arguments.length) return children;
  6481. children = x;
  6482. return hierarchy;
  6483. };
  6484. hierarchy.value = function(x) {
  6485. if (!arguments.length) return value;
  6486. value = x;
  6487. return hierarchy;
  6488. };
  6489. hierarchy.revalue = function(root) {
  6490. if (value) {
  6491. d3_layout_hierarchyVisitBefore(root, function(node) {
  6492. if (node.children) node.value = 0;
  6493. });
  6494. d3_layout_hierarchyVisitAfter(root, function(node) {
  6495. var parent;
  6496. if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
  6497. if (parent = node.parent) parent.value += node.value;
  6498. });
  6499. }
  6500. return root;
  6501. };
  6502. return hierarchy;
  6503. };
  6504. function d3_layout_hierarchyRebind(object, hierarchy) {
  6505. d3.rebind(object, hierarchy, "sort", "children", "value");
  6506. object.nodes = object;
  6507. object.links = d3_layout_hierarchyLinks;
  6508. return object;
  6509. }
  6510. function d3_layout_hierarchyVisitBefore(node, callback) {
  6511. var nodes = [ node ];
  6512. while ((node = nodes.pop()) != null) {
  6513. callback(node);
  6514. if ((children = node.children) && (n = children.length)) {
  6515. var n, children;
  6516. while (--n >= 0) nodes.push(children[n]);
  6517. }
  6518. }
  6519. }
  6520. function d3_layout_hierarchyVisitAfter(node, callback) {
  6521. var nodes = [ node ], nodes2 = [];
  6522. while ((node = nodes.pop()) != null) {
  6523. nodes2.push(node);
  6524. if ((children = node.children) && (n = children.length)) {
  6525. var i = -1, n, children;
  6526. while (++i < n) nodes.push(children[i]);
  6527. }
  6528. }
  6529. while ((node = nodes2.pop()) != null) {
  6530. callback(node);
  6531. }
  6532. }
  6533. function d3_layout_hierarchyChildren(d) {
  6534. return d.children;
  6535. }
  6536. function d3_layout_hierarchyValue(d) {
  6537. return d.value;
  6538. }
  6539. function d3_layout_hierarchySort(a, b) {
  6540. return b.value - a.value;
  6541. }
  6542. function d3_layout_hierarchyLinks(nodes) {
  6543. return d3.merge(nodes.map(function(parent) {
  6544. return (parent.children || []).map(function(child) {
  6545. return {
  6546. source: parent,
  6547. target: child
  6548. };
  6549. });
  6550. }));
  6551. }
  6552. d3.layout.partition = function() {
  6553. var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
  6554. function position(node, x, dx, dy) {
  6555. var children = node.children;
  6556. node.x = x;
  6557. node.y = node.depth * dy;
  6558. node.dx = dx;
  6559. node.dy = dy;
  6560. if (children && (n = children.length)) {
  6561. var i = -1, n, c, d;
  6562. dx = node.value ? dx / node.value : 0;
  6563. while (++i < n) {
  6564. position(c = children[i], x, d = c.value * dx, dy);
  6565. x += d;
  6566. }
  6567. }
  6568. }
  6569. function depth(node) {
  6570. var children = node.children, d = 0;
  6571. if (children && (n = children.length)) {
  6572. var i = -1, n;
  6573. while (++i < n) d = Math.max(d, depth(children[i]));
  6574. }
  6575. return 1 + d;
  6576. }
  6577. function partition(d, i) {
  6578. var nodes = hierarchy.call(this, d, i);
  6579. position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
  6580. return nodes;
  6581. }
  6582. partition.size = function(x) {
  6583. if (!arguments.length) return size;
  6584. size = x;
  6585. return partition;
  6586. };
  6587. return d3_layout_hierarchyRebind(partition, hierarchy);
  6588. };
  6589. d3.layout.pie = function() {
  6590. var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
  6591. function pie(data) {
  6592. var n = data.length, values = data.map(function(d, i) {
  6593. return +value.call(pie, d, i);
  6594. }), 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;
  6595. if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
  6596. return values[j] - values[i];
  6597. } : function(i, j) {
  6598. return sort(data[i], data[j]);
  6599. });
  6600. index.forEach(function(i) {
  6601. arcs[i] = {
  6602. data: data[i],
  6603. value: v = values[i],
  6604. startAngle: a,
  6605. endAngle: a += v * k + pa,
  6606. padAngle: p
  6607. };
  6608. });
  6609. return arcs;
  6610. }
  6611. pie.value = function(_) {
  6612. if (!arguments.length) return value;
  6613. value = _;
  6614. return pie;
  6615. };
  6616. pie.sort = function(_) {
  6617. if (!arguments.length) return sort;
  6618. sort = _;
  6619. return pie;
  6620. };
  6621. pie.startAngle = function(_) {
  6622. if (!arguments.length) return startAngle;
  6623. startAngle = _;
  6624. return pie;
  6625. };
  6626. pie.endAngle = function(_) {
  6627. if (!arguments.length) return endAngle;
  6628. endAngle = _;
  6629. return pie;
  6630. };
  6631. pie.padAngle = function(_) {
  6632. if (!arguments.length) return padAngle;
  6633. padAngle = _;
  6634. return pie;
  6635. };
  6636. return pie;
  6637. };
  6638. var d3_layout_pieSortByValue = {};
  6639. d3.layout.stack = function() {
  6640. var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
  6641. function stack(data, index) {
  6642. if (!(n = data.length)) return data;
  6643. var series = data.map(function(d, i) {
  6644. return values.call(stack, d, i);
  6645. });
  6646. var points = series.map(function(d) {
  6647. return d.map(function(v, i) {
  6648. return [ x.call(stack, v, i), y.call(stack, v, i) ];
  6649. });
  6650. });
  6651. var orders = order.call(stack, points, index);
  6652. series = d3.permute(series, orders);
  6653. points = d3.permute(points, orders);
  6654. var offsets = offset.call(stack, points, index);
  6655. var m = series[0].length, n, i, j, o;
  6656. for (j = 0; j < m; ++j) {
  6657. out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
  6658. for (i = 1; i < n; ++i) {
  6659. out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
  6660. }
  6661. }
  6662. return data;
  6663. }
  6664. stack.values = function(x) {
  6665. if (!arguments.length) return values;
  6666. values = x;
  6667. return stack;
  6668. };
  6669. stack.order = function(x) {
  6670. if (!arguments.length) return order;
  6671. order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
  6672. return stack;
  6673. };
  6674. stack.offset = function(x) {
  6675. if (!arguments.length) return offset;
  6676. offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
  6677. return stack;
  6678. };
  6679. stack.x = function(z) {
  6680. if (!arguments.length) return x;
  6681. x = z;
  6682. return stack;
  6683. };
  6684. stack.y = function(z) {
  6685. if (!arguments.length) return y;
  6686. y = z;
  6687. return stack;
  6688. };
  6689. stack.out = function(z) {
  6690. if (!arguments.length) return out;
  6691. out = z;
  6692. return stack;
  6693. };
  6694. return stack;
  6695. };
  6696. function d3_layout_stackX(d) {
  6697. return d.x;
  6698. }
  6699. function d3_layout_stackY(d) {
  6700. return d.y;
  6701. }
  6702. function d3_layout_stackOut(d, y0, y) {
  6703. d.y0 = y0;
  6704. d.y = y;
  6705. }
  6706. var d3_layout_stackOrders = d3.map({
  6707. "inside-out": function(data) {
  6708. 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) {
  6709. return max[a] - max[b];
  6710. }), top = 0, bottom = 0, tops = [], bottoms = [];
  6711. for (i = 0; i < n; ++i) {
  6712. j = index[i];
  6713. if (top < bottom) {
  6714. top += sums[j];
  6715. tops.push(j);
  6716. } else {
  6717. bottom += sums[j];
  6718. bottoms.push(j);
  6719. }
  6720. }
  6721. return bottoms.reverse().concat(tops);
  6722. },
  6723. reverse: function(data) {
  6724. return d3.range(data.length).reverse();
  6725. },
  6726. "default": d3_layout_stackOrderDefault
  6727. });
  6728. var d3_layout_stackOffsets = d3.map({
  6729. silhouette: function(data) {
  6730. var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
  6731. for (j = 0; j < m; ++j) {
  6732. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6733. if (o > max) max = o;
  6734. sums.push(o);
  6735. }
  6736. for (j = 0; j < m; ++j) {
  6737. y0[j] = (max - sums[j]) / 2;
  6738. }
  6739. return y0;
  6740. },
  6741. wiggle: function(data) {
  6742. var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
  6743. y0[0] = o = o0 = 0;
  6744. for (j = 1; j < m; ++j) {
  6745. for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
  6746. for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
  6747. for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
  6748. s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
  6749. }
  6750. s2 += s3 * data[i][j][1];
  6751. }
  6752. y0[j] = o -= s1 ? s2 / s1 * dx : 0;
  6753. if (o < o0) o0 = o;
  6754. }
  6755. for (j = 0; j < m; ++j) y0[j] -= o0;
  6756. return y0;
  6757. },
  6758. expand: function(data) {
  6759. var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
  6760. for (j = 0; j < m; ++j) {
  6761. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  6762. 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;
  6763. }
  6764. for (j = 0; j < m; ++j) y0[j] = 0;
  6765. return y0;
  6766. },
  6767. zero: d3_layout_stackOffsetZero
  6768. });
  6769. function d3_layout_stackOrderDefault(data) {
  6770. return d3.range(data.length);
  6771. }
  6772. function d3_layout_stackOffsetZero(data) {
  6773. var j = -1, m = data[0].length, y0 = [];
  6774. while (++j < m) y0[j] = 0;
  6775. return y0;
  6776. }
  6777. function d3_layout_stackMaxIndex(array) {
  6778. var i = 1, j = 0, v = array[0][1], k, n = array.length;
  6779. for (;i < n; ++i) {
  6780. if ((k = array[i][1]) > v) {
  6781. j = i;
  6782. v = k;
  6783. }
  6784. }
  6785. return j;
  6786. }
  6787. function d3_layout_stackReduceSum(d) {
  6788. return d.reduce(d3_layout_stackSum, 0);
  6789. }
  6790. function d3_layout_stackSum(p, d) {
  6791. return p + d[1];
  6792. }
  6793. d3.layout.histogram = function() {
  6794. var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
  6795. function histogram(data, i) {
  6796. 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;
  6797. while (++i < m) {
  6798. bin = bins[i] = [];
  6799. bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
  6800. bin.y = 0;
  6801. }
  6802. if (m > 0) {
  6803. i = -1;
  6804. while (++i < n) {
  6805. x = values[i];
  6806. if (x >= range[0] && x <= range[1]) {
  6807. bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
  6808. bin.y += k;
  6809. bin.push(data[i]);
  6810. }
  6811. }
  6812. }
  6813. return bins;
  6814. }
  6815. histogram.value = function(x) {
  6816. if (!arguments.length) return valuer;
  6817. valuer = x;
  6818. return histogram;
  6819. };
  6820. histogram.range = function(x) {
  6821. if (!arguments.length) return ranger;
  6822. ranger = d3_functor(x);
  6823. return histogram;
  6824. };
  6825. histogram.bins = function(x) {
  6826. if (!arguments.length) return binner;
  6827. binner = typeof x === "number" ? function(range) {
  6828. return d3_layout_histogramBinFixed(range, x);
  6829. } : d3_functor(x);
  6830. return histogram;
  6831. };
  6832. histogram.frequency = function(x) {
  6833. if (!arguments.length) return frequency;
  6834. frequency = !!x;
  6835. return histogram;
  6836. };
  6837. return histogram;
  6838. };
  6839. function d3_layout_histogramBinSturges(range, values) {
  6840. return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
  6841. }
  6842. function d3_layout_histogramBinFixed(range, n) {
  6843. var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
  6844. while (++x <= n) f[x] = m * x + b;
  6845. return f;
  6846. }
  6847. function d3_layout_histogramRange(values) {
  6848. return [ d3.min(values), d3.max(values) ];
  6849. }
  6850. d3.layout.pack = function() {
  6851. var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
  6852. function pack(d, i) {
  6853. 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() {
  6854. return radius;
  6855. };
  6856. root.x = root.y = 0;
  6857. d3_layout_hierarchyVisitAfter(root, function(d) {
  6858. d.r = +r(d.value);
  6859. });
  6860. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6861. if (padding) {
  6862. var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
  6863. d3_layout_hierarchyVisitAfter(root, function(d) {
  6864. d.r += dr;
  6865. });
  6866. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  6867. d3_layout_hierarchyVisitAfter(root, function(d) {
  6868. d.r -= dr;
  6869. });
  6870. }
  6871. d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
  6872. return nodes;
  6873. }
  6874. pack.size = function(_) {
  6875. if (!arguments.length) return size;
  6876. size = _;
  6877. return pack;
  6878. };
  6879. pack.radius = function(_) {
  6880. if (!arguments.length) return radius;
  6881. radius = _ == null || typeof _ === "function" ? _ : +_;
  6882. return pack;
  6883. };
  6884. pack.padding = function(_) {
  6885. if (!arguments.length) return padding;
  6886. padding = +_;
  6887. return pack;
  6888. };
  6889. return d3_layout_hierarchyRebind(pack, hierarchy);
  6890. };
  6891. function d3_layout_packSort(a, b) {
  6892. return a.value - b.value;
  6893. }
  6894. function d3_layout_packInsert(a, b) {
  6895. var c = a._pack_next;
  6896. a._pack_next = b;
  6897. b._pack_prev = a;
  6898. b._pack_next = c;
  6899. c._pack_prev = b;
  6900. }
  6901. function d3_layout_packSplice(a, b) {
  6902. a._pack_next = b;
  6903. b._pack_prev = a;
  6904. }
  6905. function d3_layout_packIntersects(a, b) {
  6906. var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
  6907. return .999 * dr * dr > dx * dx + dy * dy;
  6908. }
  6909. function d3_layout_packSiblings(node) {
  6910. if (!(nodes = node.children) || !(n = nodes.length)) return;
  6911. var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
  6912. function bound(node) {
  6913. xMin = Math.min(node.x - node.r, xMin);
  6914. xMax = Math.max(node.x + node.r, xMax);
  6915. yMin = Math.min(node.y - node.r, yMin);
  6916. yMax = Math.max(node.y + node.r, yMax);
  6917. }
  6918. nodes.forEach(d3_layout_packLink);
  6919. a = nodes[0];
  6920. a.x = -a.r;
  6921. a.y = 0;
  6922. bound(a);
  6923. if (n > 1) {
  6924. b = nodes[1];
  6925. b.x = b.r;
  6926. b.y = 0;
  6927. bound(b);
  6928. if (n > 2) {
  6929. c = nodes[2];
  6930. d3_layout_packPlace(a, b, c);
  6931. bound(c);
  6932. d3_layout_packInsert(a, c);
  6933. a._pack_prev = c;
  6934. d3_layout_packInsert(c, b);
  6935. b = a._pack_next;
  6936. for (i = 3; i < n; i++) {
  6937. d3_layout_packPlace(a, b, c = nodes[i]);
  6938. var isect = 0, s1 = 1, s2 = 1;
  6939. for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
  6940. if (d3_layout_packIntersects(j, c)) {
  6941. isect = 1;
  6942. break;
  6943. }
  6944. }
  6945. if (isect == 1) {
  6946. for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
  6947. if (d3_layout_packIntersects(k, c)) {
  6948. break;
  6949. }
  6950. }
  6951. }
  6952. if (isect) {
  6953. if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
  6954. i--;
  6955. } else {
  6956. d3_layout_packInsert(a, c);
  6957. b = c;
  6958. bound(c);
  6959. }
  6960. }
  6961. }
  6962. }
  6963. var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
  6964. for (i = 0; i < n; i++) {
  6965. c = nodes[i];
  6966. c.x -= cx;
  6967. c.y -= cy;
  6968. cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
  6969. }
  6970. node.r = cr;
  6971. nodes.forEach(d3_layout_packUnlink);
  6972. }
  6973. function d3_layout_packLink(node) {
  6974. node._pack_next = node._pack_prev = node;
  6975. }
  6976. function d3_layout_packUnlink(node) {
  6977. delete node._pack_next;
  6978. delete node._pack_prev;
  6979. }
  6980. function d3_layout_packTransform(node, x, y, k) {
  6981. var children = node.children;
  6982. node.x = x += k * node.x;
  6983. node.y = y += k * node.y;
  6984. node.r *= k;
  6985. if (children) {
  6986. var i = -1, n = children.length;
  6987. while (++i < n) d3_layout_packTransform(children[i], x, y, k);
  6988. }
  6989. }
  6990. function d3_layout_packPlace(a, b, c) {
  6991. var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
  6992. if (db && (dx || dy)) {
  6993. var da = b.r + c.r, dc = dx * dx + dy * dy;
  6994. da *= da;
  6995. db *= db;
  6996. var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  6997. c.x = a.x + x * dx + y * dy;
  6998. c.y = a.y + x * dy - y * dx;
  6999. } else {
  7000. c.x = a.x + db;
  7001. c.y = a.y;
  7002. }
  7003. }
  7004. d3.layout.tree = function() {
  7005. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
  7006. function tree(d, i) {
  7007. var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
  7008. d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
  7009. d3_layout_hierarchyVisitBefore(root1, secondWalk);
  7010. if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
  7011. var left = root0, right = root0, bottom = root0;
  7012. d3_layout_hierarchyVisitBefore(root0, function(node) {
  7013. if (node.x < left.x) left = node;
  7014. if (node.x > right.x) right = node;
  7015. if (node.depth > bottom.depth) bottom = node;
  7016. });
  7017. var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
  7018. d3_layout_hierarchyVisitBefore(root0, function(node) {
  7019. node.x = (node.x + tx) * kx;
  7020. node.y = node.depth * ky;
  7021. });
  7022. }
  7023. return nodes;
  7024. }
  7025. function wrapTree(root0) {
  7026. var root1 = {
  7027. A: null,
  7028. children: [ root0 ]
  7029. }, queue = [ root1 ], node1;
  7030. while ((node1 = queue.pop()) != null) {
  7031. for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
  7032. queue.push((children[i] = child = {
  7033. _: children[i],
  7034. parent: node1,
  7035. children: (child = children[i].children) && child.slice() || [],
  7036. A: null,
  7037. a: null,
  7038. z: 0,
  7039. m: 0,
  7040. c: 0,
  7041. s: 0,
  7042. t: null,
  7043. i: i
  7044. }).a = child);
  7045. }
  7046. }
  7047. return root1.children[0];
  7048. }
  7049. function firstWalk(v) {
  7050. var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
  7051. if (children.length) {
  7052. d3_layout_treeShift(v);
  7053. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  7054. if (w) {
  7055. v.z = w.z + separation(v._, w._);
  7056. v.m = v.z - midpoint;
  7057. } else {
  7058. v.z = midpoint;
  7059. }
  7060. } else if (w) {
  7061. v.z = w.z + separation(v._, w._);
  7062. }
  7063. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  7064. }
  7065. function secondWalk(v) {
  7066. v._.x = v.z + v.parent.m;
  7067. v.m += v.parent.m;
  7068. }
  7069. function apportion(v, w, ancestor) {
  7070. if (w) {
  7071. 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;
  7072. while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
  7073. vom = d3_layout_treeLeft(vom);
  7074. vop = d3_layout_treeRight(vop);
  7075. vop.a = v;
  7076. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  7077. if (shift > 0) {
  7078. d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
  7079. sip += shift;
  7080. sop += shift;
  7081. }
  7082. sim += vim.m;
  7083. sip += vip.m;
  7084. som += vom.m;
  7085. sop += vop.m;
  7086. }
  7087. if (vim && !d3_layout_treeRight(vop)) {
  7088. vop.t = vim;
  7089. vop.m += sim - sop;
  7090. }
  7091. if (vip && !d3_layout_treeLeft(vom)) {
  7092. vom.t = vip;
  7093. vom.m += sip - som;
  7094. ancestor = v;
  7095. }
  7096. }
  7097. return ancestor;
  7098. }
  7099. function sizeNode(node) {
  7100. node.x *= size[0];
  7101. node.y = node.depth * size[1];
  7102. }
  7103. tree.separation = function(x) {
  7104. if (!arguments.length) return separation;
  7105. separation = x;
  7106. return tree;
  7107. };
  7108. tree.size = function(x) {
  7109. if (!arguments.length) return nodeSize ? null : size;
  7110. nodeSize = (size = x) == null ? sizeNode : null;
  7111. return tree;
  7112. };
  7113. tree.nodeSize = function(x) {
  7114. if (!arguments.length) return nodeSize ? size : null;
  7115. nodeSize = (size = x) == null ? null : sizeNode;
  7116. return tree;
  7117. };
  7118. return d3_layout_hierarchyRebind(tree, hierarchy);
  7119. };
  7120. function d3_layout_treeSeparation(a, b) {
  7121. return a.parent == b.parent ? 1 : 2;
  7122. }
  7123. function d3_layout_treeLeft(v) {
  7124. var children = v.children;
  7125. return children.length ? children[0] : v.t;
  7126. }
  7127. function d3_layout_treeRight(v) {
  7128. var children = v.children, n;
  7129. return (n = children.length) ? children[n - 1] : v.t;
  7130. }
  7131. function d3_layout_treeMove(wm, wp, shift) {
  7132. var change = shift / (wp.i - wm.i);
  7133. wp.c -= change;
  7134. wp.s += shift;
  7135. wm.c += change;
  7136. wp.z += shift;
  7137. wp.m += shift;
  7138. }
  7139. function d3_layout_treeShift(v) {
  7140. var shift = 0, change = 0, children = v.children, i = children.length, w;
  7141. while (--i >= 0) {
  7142. w = children[i];
  7143. w.z += shift;
  7144. w.m += shift;
  7145. shift += w.s + (change += w.c);
  7146. }
  7147. }
  7148. function d3_layout_treeAncestor(vim, v, ancestor) {
  7149. return vim.a.parent === v.parent ? vim.a : ancestor;
  7150. }
  7151. d3.layout.cluster = function() {
  7152. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
  7153. function cluster(d, i) {
  7154. var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
  7155. d3_layout_hierarchyVisitAfter(root, function(node) {
  7156. var children = node.children;
  7157. if (children && children.length) {
  7158. node.x = d3_layout_clusterX(children);
  7159. node.y = d3_layout_clusterY(children);
  7160. } else {
  7161. node.x = previousNode ? x += separation(node, previousNode) : 0;
  7162. node.y = 0;
  7163. previousNode = node;
  7164. }
  7165. });
  7166. 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;
  7167. d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
  7168. node.x = (node.x - root.x) * size[0];
  7169. node.y = (root.y - node.y) * size[1];
  7170. } : function(node) {
  7171. node.x = (node.x - x0) / (x1 - x0) * size[0];
  7172. node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
  7173. });
  7174. return nodes;
  7175. }
  7176. cluster.separation = function(x) {
  7177. if (!arguments.length) return separation;
  7178. separation = x;
  7179. return cluster;
  7180. };
  7181. cluster.size = function(x) {
  7182. if (!arguments.length) return nodeSize ? null : size;
  7183. nodeSize = (size = x) == null;
  7184. return cluster;
  7185. };
  7186. cluster.nodeSize = function(x) {
  7187. if (!arguments.length) return nodeSize ? size : null;
  7188. nodeSize = (size = x) != null;
  7189. return cluster;
  7190. };
  7191. return d3_layout_hierarchyRebind(cluster, hierarchy);
  7192. };
  7193. function d3_layout_clusterY(children) {
  7194. return 1 + d3.max(children, function(child) {
  7195. return child.y;
  7196. });
  7197. }
  7198. function d3_layout_clusterX(children) {
  7199. return children.reduce(function(x, child) {
  7200. return x + child.x;
  7201. }, 0) / children.length;
  7202. }
  7203. function d3_layout_clusterLeft(node) {
  7204. var children = node.children;
  7205. return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
  7206. }
  7207. function d3_layout_clusterRight(node) {
  7208. var children = node.children, n;
  7209. return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
  7210. }
  7211. d3.layout.treemap = function() {
  7212. 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));
  7213. function scale(children, k) {
  7214. var i = -1, n = children.length, child, area;
  7215. while (++i < n) {
  7216. area = (child = children[i]).value * (k < 0 ? 0 : k);
  7217. child.area = isNaN(area) || area <= 0 ? 0 : area;
  7218. }
  7219. }
  7220. function squarify(node) {
  7221. var children = node.children;
  7222. if (children && children.length) {
  7223. 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;
  7224. scale(remaining, rect.dx * rect.dy / node.value);
  7225. row.area = 0;
  7226. while ((n = remaining.length) > 0) {
  7227. row.push(child = remaining[n - 1]);
  7228. row.area += child.area;
  7229. if (mode !== "squarify" || (score = worst(row, u)) <= best) {
  7230. remaining.pop();
  7231. best = score;
  7232. } else {
  7233. row.area -= row.pop().area;
  7234. position(row, u, rect, false);
  7235. u = Math.min(rect.dx, rect.dy);
  7236. row.length = row.area = 0;
  7237. best = Infinity;
  7238. }
  7239. }
  7240. if (row.length) {
  7241. position(row, u, rect, true);
  7242. row.length = row.area = 0;
  7243. }
  7244. children.forEach(squarify);
  7245. }
  7246. }
  7247. function stickify(node) {
  7248. var children = node.children;
  7249. if (children && children.length) {
  7250. var rect = pad(node), remaining = children.slice(), child, row = [];
  7251. scale(remaining, rect.dx * rect.dy / node.value);
  7252. row.area = 0;
  7253. while (child = remaining.pop()) {
  7254. row.push(child);
  7255. row.area += child.area;
  7256. if (child.z != null) {
  7257. position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
  7258. row.length = row.area = 0;
  7259. }
  7260. }
  7261. children.forEach(stickify);
  7262. }
  7263. }
  7264. function worst(row, u) {
  7265. var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
  7266. while (++i < n) {
  7267. if (!(r = row[i].area)) continue;
  7268. if (r < rmin) rmin = r;
  7269. if (r > rmax) rmax = r;
  7270. }
  7271. s *= s;
  7272. u *= u;
  7273. return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
  7274. }
  7275. function position(row, u, rect, flush) {
  7276. var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
  7277. if (u == rect.dx) {
  7278. if (flush || v > rect.dy) v = rect.dy;
  7279. while (++i < n) {
  7280. o = row[i];
  7281. o.x = x;
  7282. o.y = y;
  7283. o.dy = v;
  7284. x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
  7285. }
  7286. o.z = true;
  7287. o.dx += rect.x + rect.dx - x;
  7288. rect.y += v;
  7289. rect.dy -= v;
  7290. } else {
  7291. if (flush || v > rect.dx) v = rect.dx;
  7292. while (++i < n) {
  7293. o = row[i];
  7294. o.x = x;
  7295. o.y = y;
  7296. o.dx = v;
  7297. y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
  7298. }
  7299. o.z = false;
  7300. o.dy += rect.y + rect.dy - y;
  7301. rect.x += v;
  7302. rect.dx -= v;
  7303. }
  7304. }
  7305. function treemap(d) {
  7306. var nodes = stickies || hierarchy(d), root = nodes[0];
  7307. root.x = 0;
  7308. root.y = 0;
  7309. root.dx = size[0];
  7310. root.dy = size[1];
  7311. if (stickies) hierarchy.revalue(root);
  7312. scale([ root ], root.dx * root.dy / root.value);
  7313. (stickies ? stickify : squarify)(root);
  7314. if (sticky) stickies = nodes;
  7315. return nodes;
  7316. }
  7317. treemap.size = function(x) {
  7318. if (!arguments.length) return size;
  7319. size = x;
  7320. return treemap;
  7321. };
  7322. treemap.padding = function(x) {
  7323. if (!arguments.length) return padding;
  7324. function padFunction(node) {
  7325. var p = x.call(treemap, node, node.depth);
  7326. return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
  7327. }
  7328. function padConstant(node) {
  7329. return d3_layout_treemapPad(node, x);
  7330. }
  7331. var type;
  7332. pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
  7333. padConstant) : padConstant;
  7334. return treemap;
  7335. };
  7336. treemap.round = function(x) {
  7337. if (!arguments.length) return round != Number;
  7338. round = x ? Math.round : Number;
  7339. return treemap;
  7340. };
  7341. treemap.sticky = function(x) {
  7342. if (!arguments.length) return sticky;
  7343. sticky = x;
  7344. stickies = null;
  7345. return treemap;
  7346. };
  7347. treemap.ratio = function(x) {
  7348. if (!arguments.length) return ratio;
  7349. ratio = x;
  7350. return treemap;
  7351. };
  7352. treemap.mode = function(x) {
  7353. if (!arguments.length) return mode;
  7354. mode = x + "";
  7355. return treemap;
  7356. };
  7357. return d3_layout_hierarchyRebind(treemap, hierarchy);
  7358. };
  7359. function d3_layout_treemapPadNull(node) {
  7360. return {
  7361. x: node.x,
  7362. y: node.y,
  7363. dx: node.dx,
  7364. dy: node.dy
  7365. };
  7366. }
  7367. function d3_layout_treemapPad(node, padding) {
  7368. 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];
  7369. if (dx < 0) {
  7370. x += dx / 2;
  7371. dx = 0;
  7372. }
  7373. if (dy < 0) {
  7374. y += dy / 2;
  7375. dy = 0;
  7376. }
  7377. return {
  7378. x: x,
  7379. y: y,
  7380. dx: dx,
  7381. dy: dy
  7382. };
  7383. }
  7384. d3.random = {
  7385. normal: function(µ, σ) {
  7386. var n = arguments.length;
  7387. if (n < 2) σ = 1;
  7388. if (n < 1) µ = 0;
  7389. return function() {
  7390. var x, y, r;
  7391. do {
  7392. x = Math.random() * 2 - 1;
  7393. y = Math.random() * 2 - 1;
  7394. r = x * x + y * y;
  7395. } while (!r || r > 1);
  7396. return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
  7397. };
  7398. },
  7399. logNormal: function() {
  7400. var random = d3.random.normal.apply(d3, arguments);
  7401. return function() {
  7402. return Math.exp(random());
  7403. };
  7404. },
  7405. bates: function(m) {
  7406. var random = d3.random.irwinHall(m);
  7407. return function() {
  7408. return random() / m;
  7409. };
  7410. },
  7411. irwinHall: function(m) {
  7412. return function() {
  7413. for (var s = 0, j = 0; j < m; j++) s += Math.random();
  7414. return s;
  7415. };
  7416. }
  7417. };
  7418. d3.scale = {};
  7419. function d3_scaleExtent(domain) {
  7420. var start = domain[0], stop = domain[domain.length - 1];
  7421. return start < stop ? [ start, stop ] : [ stop, start ];
  7422. }
  7423. function d3_scaleRange(scale) {
  7424. return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
  7425. }
  7426. function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
  7427. var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
  7428. return function(x) {
  7429. return i(u(x));
  7430. };
  7431. }
  7432. function d3_scale_nice(domain, nice) {
  7433. var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
  7434. if (x1 < x0) {
  7435. dx = i0, i0 = i1, i1 = dx;
  7436. dx = x0, x0 = x1, x1 = dx;
  7437. }
  7438. domain[i0] = nice.floor(x0);
  7439. domain[i1] = nice.ceil(x1);
  7440. return domain;
  7441. }
  7442. function d3_scale_niceStep(step) {
  7443. return step ? {
  7444. floor: function(x) {
  7445. return Math.floor(x / step) * step;
  7446. },
  7447. ceil: function(x) {
  7448. return Math.ceil(x / step) * step;
  7449. }
  7450. } : d3_scale_niceIdentity;
  7451. }
  7452. var d3_scale_niceIdentity = {
  7453. floor: d3_identity,
  7454. ceil: d3_identity
  7455. };
  7456. function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
  7457. var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
  7458. if (domain[k] < domain[0]) {
  7459. domain = domain.slice().reverse();
  7460. range = range.slice().reverse();
  7461. }
  7462. while (++j <= k) {
  7463. u.push(uninterpolate(domain[j - 1], domain[j]));
  7464. i.push(interpolate(range[j - 1], range[j]));
  7465. }
  7466. return function(x) {
  7467. var j = d3.bisect(domain, x, 1, k) - 1;
  7468. return i[j](u[j](x));
  7469. };
  7470. }
  7471. d3.scale.linear = function() {
  7472. return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
  7473. };
  7474. function d3_scale_linear(domain, range, interpolate, clamp) {
  7475. var output, input;
  7476. function rescale() {
  7477. var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
  7478. output = linear(domain, range, uninterpolate, interpolate);
  7479. input = linear(range, domain, uninterpolate, d3_interpolate);
  7480. return scale;
  7481. }
  7482. function scale(x) {
  7483. return output(x);
  7484. }
  7485. scale.invert = function(y) {
  7486. return input(y);
  7487. };
  7488. scale.domain = function(x) {
  7489. if (!arguments.length) return domain;
  7490. domain = x.map(Number);
  7491. return rescale();
  7492. };
  7493. scale.range = function(x) {
  7494. if (!arguments.length) return range;
  7495. range = x;
  7496. return rescale();
  7497. };
  7498. scale.rangeRound = function(x) {
  7499. return scale.range(x).interpolate(d3_interpolateRound);
  7500. };
  7501. scale.clamp = function(x) {
  7502. if (!arguments.length) return clamp;
  7503. clamp = x;
  7504. return rescale();
  7505. };
  7506. scale.interpolate = function(x) {
  7507. if (!arguments.length) return interpolate;
  7508. interpolate = x;
  7509. return rescale();
  7510. };
  7511. scale.ticks = function(m) {
  7512. return d3_scale_linearTicks(domain, m);
  7513. };
  7514. scale.tickFormat = function(m, format) {
  7515. return d3_scale_linearTickFormat(domain, m, format);
  7516. };
  7517. scale.nice = function(m) {
  7518. d3_scale_linearNice(domain, m);
  7519. return rescale();
  7520. };
  7521. scale.copy = function() {
  7522. return d3_scale_linear(domain, range, interpolate, clamp);
  7523. };
  7524. return rescale();
  7525. }
  7526. function d3_scale_linearRebind(scale, linear) {
  7527. return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
  7528. }
  7529. function d3_scale_linearNice(domain, m) {
  7530. return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
  7531. }
  7532. function d3_scale_linearTickRange(domain, m) {
  7533. if (m == null) m = 10;
  7534. 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;
  7535. if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
  7536. extent[0] = Math.ceil(extent[0] / step) * step;
  7537. extent[1] = Math.floor(extent[1] / step) * step + step * .5;
  7538. extent[2] = step;
  7539. return extent;
  7540. }
  7541. function d3_scale_linearTicks(domain, m) {
  7542. return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
  7543. }
  7544. function d3_scale_linearTickFormat(domain, m, format) {
  7545. var range = d3_scale_linearTickRange(domain, m);
  7546. if (format) {
  7547. var match = d3_format_re.exec(format);
  7548. match.shift();
  7549. if (match[8] === "s") {
  7550. var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
  7551. if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
  7552. match[8] = "f";
  7553. format = d3.format(match.join(""));
  7554. return function(d) {
  7555. return format(prefix.scale(d)) + prefix.symbol;
  7556. };
  7557. }
  7558. if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
  7559. format = match.join("");
  7560. } else {
  7561. format = ",." + d3_scale_linearPrecision(range[2]) + "f";
  7562. }
  7563. return d3.format(format);
  7564. }
  7565. var d3_scale_linearFormatSignificant = {
  7566. s: 1,
  7567. g: 1,
  7568. p: 1,
  7569. r: 1,
  7570. e: 1
  7571. };
  7572. function d3_scale_linearPrecision(value) {
  7573. return -Math.floor(Math.log(value) / Math.LN10 + .01);
  7574. }
  7575. function d3_scale_linearFormatPrecision(type, range) {
  7576. var p = d3_scale_linearPrecision(range[2]);
  7577. 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;
  7578. }
  7579. d3.scale.log = function() {
  7580. return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
  7581. };
  7582. function d3_scale_log(linear, base, positive, domain) {
  7583. function log(x) {
  7584. return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
  7585. }
  7586. function pow(x) {
  7587. return positive ? Math.pow(base, x) : -Math.pow(base, -x);
  7588. }
  7589. function scale(x) {
  7590. return linear(log(x));
  7591. }
  7592. scale.invert = function(x) {
  7593. return pow(linear.invert(x));
  7594. };
  7595. scale.domain = function(x) {
  7596. if (!arguments.length) return domain;
  7597. positive = x[0] >= 0;
  7598. linear.domain((domain = x.map(Number)).map(log));
  7599. return scale;
  7600. };
  7601. scale.base = function(_) {
  7602. if (!arguments.length) return base;
  7603. base = +_;
  7604. linear.domain(domain.map(log));
  7605. return scale;
  7606. };
  7607. scale.nice = function() {
  7608. var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
  7609. linear.domain(niced);
  7610. domain = niced.map(pow);
  7611. return scale;
  7612. };
  7613. scale.ticks = function() {
  7614. 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;
  7615. if (isFinite(j - i)) {
  7616. if (positive) {
  7617. for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
  7618. ticks.push(pow(i));
  7619. } else {
  7620. ticks.push(pow(i));
  7621. for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
  7622. }
  7623. for (i = 0; ticks[i] < u; i++) {}
  7624. for (j = ticks.length; ticks[j - 1] > v; j--) {}
  7625. ticks = ticks.slice(i, j);
  7626. }
  7627. return ticks;
  7628. };
  7629. scale.tickFormat = function(n, format) {
  7630. if (!arguments.length) return d3_scale_logFormat;
  7631. if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
  7632. var k = Math.max(.1, n / scale.ticks().length), f = positive ? (e = 1e-12, Math.ceil) : (e = -1e-12,
  7633. Math.floor), e;
  7634. return function(d) {
  7635. return d / pow(f(log(d) + e)) <= k ? format(d) : "";
  7636. };
  7637. };
  7638. scale.copy = function() {
  7639. return d3_scale_log(linear.copy(), base, positive, domain);
  7640. };
  7641. return d3_scale_linearRebind(scale, linear);
  7642. }
  7643. var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
  7644. floor: function(x) {
  7645. return -Math.ceil(-x);
  7646. },
  7647. ceil: function(x) {
  7648. return -Math.floor(-x);
  7649. }
  7650. };
  7651. d3.scale.pow = function() {
  7652. return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
  7653. };
  7654. function d3_scale_pow(linear, exponent, domain) {
  7655. var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
  7656. function scale(x) {
  7657. return linear(powp(x));
  7658. }
  7659. scale.invert = function(x) {
  7660. return powb(linear.invert(x));
  7661. };
  7662. scale.domain = function(x) {
  7663. if (!arguments.length) return domain;
  7664. linear.domain((domain = x.map(Number)).map(powp));
  7665. return scale;
  7666. };
  7667. scale.ticks = function(m) {
  7668. return d3_scale_linearTicks(domain, m);
  7669. };
  7670. scale.tickFormat = function(m, format) {
  7671. return d3_scale_linearTickFormat(domain, m, format);
  7672. };
  7673. scale.nice = function(m) {
  7674. return scale.domain(d3_scale_linearNice(domain, m));
  7675. };
  7676. scale.exponent = function(x) {
  7677. if (!arguments.length) return exponent;
  7678. powp = d3_scale_powPow(exponent = x);
  7679. powb = d3_scale_powPow(1 / exponent);
  7680. linear.domain(domain.map(powp));
  7681. return scale;
  7682. };
  7683. scale.copy = function() {
  7684. return d3_scale_pow(linear.copy(), exponent, domain);
  7685. };
  7686. return d3_scale_linearRebind(scale, linear);
  7687. }
  7688. function d3_scale_powPow(e) {
  7689. return function(x) {
  7690. return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
  7691. };
  7692. }
  7693. d3.scale.sqrt = function() {
  7694. return d3.scale.pow().exponent(.5);
  7695. };
  7696. d3.scale.ordinal = function() {
  7697. return d3_scale_ordinal([], {
  7698. t: "range",
  7699. a: [ [] ]
  7700. });
  7701. };
  7702. function d3_scale_ordinal(domain, ranger) {
  7703. var index, range, rangeBand;
  7704. function scale(x) {
  7705. return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
  7706. }
  7707. function steps(start, step) {
  7708. return d3.range(domain.length).map(function(i) {
  7709. return start + step * i;
  7710. });
  7711. }
  7712. scale.domain = function(x) {
  7713. if (!arguments.length) return domain;
  7714. domain = [];
  7715. index = new d3_Map();
  7716. var i = -1, n = x.length, xi;
  7717. while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
  7718. return scale[ranger.t].apply(scale, ranger.a);
  7719. };
  7720. scale.range = function(x) {
  7721. if (!arguments.length) return range;
  7722. range = x;
  7723. rangeBand = 0;
  7724. ranger = {
  7725. t: "range",
  7726. a: arguments
  7727. };
  7728. return scale;
  7729. };
  7730. scale.rangePoints = function(x, padding) {
  7731. if (arguments.length < 2) padding = 0;
  7732. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
  7733. 0) : (stop - start) / (domain.length - 1 + padding);
  7734. range = steps(start + step * padding / 2, step);
  7735. rangeBand = 0;
  7736. ranger = {
  7737. t: "rangePoints",
  7738. a: arguments
  7739. };
  7740. return scale;
  7741. };
  7742. scale.rangeRoundPoints = function(x, padding) {
  7743. if (arguments.length < 2) padding = 0;
  7744. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
  7745. 0) : (stop - start) / (domain.length - 1 + padding) | 0;
  7746. range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
  7747. rangeBand = 0;
  7748. ranger = {
  7749. t: "rangeRoundPoints",
  7750. a: arguments
  7751. };
  7752. return scale;
  7753. };
  7754. scale.rangeBands = function(x, padding, outerPadding) {
  7755. if (arguments.length < 2) padding = 0;
  7756. if (arguments.length < 3) outerPadding = padding;
  7757. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
  7758. range = steps(start + step * outerPadding, step);
  7759. if (reverse) range.reverse();
  7760. rangeBand = step * (1 - padding);
  7761. ranger = {
  7762. t: "rangeBands",
  7763. a: arguments
  7764. };
  7765. return scale;
  7766. };
  7767. scale.rangeRoundBands = function(x, padding, outerPadding) {
  7768. if (arguments.length < 2) padding = 0;
  7769. if (arguments.length < 3) outerPadding = padding;
  7770. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
  7771. range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
  7772. if (reverse) range.reverse();
  7773. rangeBand = Math.round(step * (1 - padding));
  7774. ranger = {
  7775. t: "rangeRoundBands",
  7776. a: arguments
  7777. };
  7778. return scale;
  7779. };
  7780. scale.rangeBand = function() {
  7781. return rangeBand;
  7782. };
  7783. scale.rangeExtent = function() {
  7784. return d3_scaleExtent(ranger.a[0]);
  7785. };
  7786. scale.copy = function() {
  7787. return d3_scale_ordinal(domain, ranger);
  7788. };
  7789. return scale.domain(domain);
  7790. }
  7791. d3.scale.category10 = function() {
  7792. return d3.scale.ordinal().range(d3_category10);
  7793. };
  7794. d3.scale.category20 = function() {
  7795. return d3.scale.ordinal().range(d3_category20);
  7796. };
  7797. d3.scale.category20b = function() {
  7798. return d3.scale.ordinal().range(d3_category20b);
  7799. };
  7800. d3.scale.category20c = function() {
  7801. return d3.scale.ordinal().range(d3_category20c);
  7802. };
  7803. var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
  7804. 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);
  7805. 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);
  7806. 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);
  7807. d3.scale.quantile = function() {
  7808. return d3_scale_quantile([], []);
  7809. };
  7810. function d3_scale_quantile(domain, range) {
  7811. var thresholds;
  7812. function rescale() {
  7813. var k = 0, q = range.length;
  7814. thresholds = [];
  7815. while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
  7816. return scale;
  7817. }
  7818. function scale(x) {
  7819. if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
  7820. }
  7821. scale.domain = function(x) {
  7822. if (!arguments.length) return domain;
  7823. domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
  7824. return rescale();
  7825. };
  7826. scale.range = function(x) {
  7827. if (!arguments.length) return range;
  7828. range = x;
  7829. return rescale();
  7830. };
  7831. scale.quantiles = function() {
  7832. return thresholds;
  7833. };
  7834. scale.invertExtent = function(y) {
  7835. y = range.indexOf(y);
  7836. return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
  7837. };
  7838. scale.copy = function() {
  7839. return d3_scale_quantile(domain, range);
  7840. };
  7841. return rescale();
  7842. }
  7843. d3.scale.quantize = function() {
  7844. return d3_scale_quantize(0, 1, [ 0, 1 ]);
  7845. };
  7846. function d3_scale_quantize(x0, x1, range) {
  7847. var kx, i;
  7848. function scale(x) {
  7849. return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
  7850. }
  7851. function rescale() {
  7852. kx = range.length / (x1 - x0);
  7853. i = range.length - 1;
  7854. return scale;
  7855. }
  7856. scale.domain = function(x) {
  7857. if (!arguments.length) return [ x0, x1 ];
  7858. x0 = +x[0];
  7859. x1 = +x[x.length - 1];
  7860. return rescale();
  7861. };
  7862. scale.range = function(x) {
  7863. if (!arguments.length) return range;
  7864. range = x;
  7865. return rescale();
  7866. };
  7867. scale.invertExtent = function(y) {
  7868. y = range.indexOf(y);
  7869. y = y < 0 ? NaN : y / kx + x0;
  7870. return [ y, y + 1 / kx ];
  7871. };
  7872. scale.copy = function() {
  7873. return d3_scale_quantize(x0, x1, range);
  7874. };
  7875. return rescale();
  7876. }
  7877. d3.scale.threshold = function() {
  7878. return d3_scale_threshold([ .5 ], [ 0, 1 ]);
  7879. };
  7880. function d3_scale_threshold(domain, range) {
  7881. function scale(x) {
  7882. if (x <= x) return range[d3.bisect(domain, x)];
  7883. }
  7884. scale.domain = function(_) {
  7885. if (!arguments.length) return domain;
  7886. domain = _;
  7887. return scale;
  7888. };
  7889. scale.range = function(_) {
  7890. if (!arguments.length) return range;
  7891. range = _;
  7892. return scale;
  7893. };
  7894. scale.invertExtent = function(y) {
  7895. y = range.indexOf(y);
  7896. return [ domain[y - 1], domain[y] ];
  7897. };
  7898. scale.copy = function() {
  7899. return d3_scale_threshold(domain, range);
  7900. };
  7901. return scale;
  7902. }
  7903. d3.scale.identity = function() {
  7904. return d3_scale_identity([ 0, 1 ]);
  7905. };
  7906. function d3_scale_identity(domain) {
  7907. function identity(x) {
  7908. return +x;
  7909. }
  7910. identity.invert = identity;
  7911. identity.domain = identity.range = function(x) {
  7912. if (!arguments.length) return domain;
  7913. domain = x.map(identity);
  7914. return identity;
  7915. };
  7916. identity.ticks = function(m) {
  7917. return d3_scale_linearTicks(domain, m);
  7918. };
  7919. identity.tickFormat = function(m, format) {
  7920. return d3_scale_linearTickFormat(domain, m, format);
  7921. };
  7922. identity.copy = function() {
  7923. return d3_scale_identity(domain);
  7924. };
  7925. return identity;
  7926. }
  7927. d3.svg = {};
  7928. function d3_zero() {
  7929. return 0;
  7930. }
  7931. d3.svg.arc = function() {
  7932. 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;
  7933. function arc() {
  7934. 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;
  7935. if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
  7936. if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
  7937. var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
  7938. if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
  7939. rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
  7940. if (!cw) p1 *= -1;
  7941. if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
  7942. if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
  7943. }
  7944. if (r1) {
  7945. x0 = r1 * Math.cos(a0 + p1);
  7946. y0 = r1 * Math.sin(a0 + p1);
  7947. x1 = r1 * Math.cos(a1 - p1);
  7948. y1 = r1 * Math.sin(a1 - p1);
  7949. var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
  7950. if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
  7951. var h1 = (a0 + a1) / 2;
  7952. x0 = r1 * Math.cos(h1);
  7953. y0 = r1 * Math.sin(h1);
  7954. x1 = y1 = null;
  7955. }
  7956. } else {
  7957. x0 = y0 = 0;
  7958. }
  7959. if (r0) {
  7960. x2 = r0 * Math.cos(a1 - p0);
  7961. y2 = r0 * Math.sin(a1 - p0);
  7962. x3 = r0 * Math.cos(a0 + p0);
  7963. y3 = r0 * Math.sin(a0 + p0);
  7964. var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
  7965. if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
  7966. var h0 = (a0 + a1) / 2;
  7967. x2 = r0 * Math.cos(h0);
  7968. y2 = r0 * Math.sin(h0);
  7969. x3 = y3 = null;
  7970. }
  7971. } else {
  7972. x2 = y2 = 0;
  7973. }
  7974. if ((rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
  7975. cr = r0 < r1 ^ cw ? 0 : 1;
  7976. 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]);
  7977. if (x1 != null) {
  7978. 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);
  7979. if (rc === rc1) {
  7980. 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]);
  7981. } else {
  7982. path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
  7983. }
  7984. } else {
  7985. path.push("M", x0, ",", y0);
  7986. }
  7987. if (x3 != null) {
  7988. 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);
  7989. if (rc === rc0) {
  7990. 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]);
  7991. } else {
  7992. path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
  7993. }
  7994. } else {
  7995. path.push("L", x2, ",", y2);
  7996. }
  7997. } else {
  7998. path.push("M", x0, ",", y0);
  7999. if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
  8000. path.push("L", x2, ",", y2);
  8001. if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
  8002. }
  8003. path.push("Z");
  8004. return path.join("");
  8005. }
  8006. function circleSegment(r1, cw) {
  8007. return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
  8008. }
  8009. arc.innerRadius = function(v) {
  8010. if (!arguments.length) return innerRadius;
  8011. innerRadius = d3_functor(v);
  8012. return arc;
  8013. };
  8014. arc.outerRadius = function(v) {
  8015. if (!arguments.length) return outerRadius;
  8016. outerRadius = d3_functor(v);
  8017. return arc;
  8018. };
  8019. arc.cornerRadius = function(v) {
  8020. if (!arguments.length) return cornerRadius;
  8021. cornerRadius = d3_functor(v);
  8022. return arc;
  8023. };
  8024. arc.padRadius = function(v) {
  8025. if (!arguments.length) return padRadius;
  8026. padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
  8027. return arc;
  8028. };
  8029. arc.startAngle = function(v) {
  8030. if (!arguments.length) return startAngle;
  8031. startAngle = d3_functor(v);
  8032. return arc;
  8033. };
  8034. arc.endAngle = function(v) {
  8035. if (!arguments.length) return endAngle;
  8036. endAngle = d3_functor(v);
  8037. return arc;
  8038. };
  8039. arc.padAngle = function(v) {
  8040. if (!arguments.length) return padAngle;
  8041. padAngle = d3_functor(v);
  8042. return arc;
  8043. };
  8044. arc.centroid = function() {
  8045. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
  8046. return [ Math.cos(a) * r, Math.sin(a) * r ];
  8047. };
  8048. return arc;
  8049. };
  8050. var d3_svg_arcAuto = "auto";
  8051. function d3_svg_arcInnerRadius(d) {
  8052. return d.innerRadius;
  8053. }
  8054. function d3_svg_arcOuterRadius(d) {
  8055. return d.outerRadius;
  8056. }
  8057. function d3_svg_arcStartAngle(d) {
  8058. return d.startAngle;
  8059. }
  8060. function d3_svg_arcEndAngle(d) {
  8061. return d.endAngle;
  8062. }
  8063. function d3_svg_arcPadAngle(d) {
  8064. return d && d.padAngle;
  8065. }
  8066. function d3_svg_arcSweep(x0, y0, x1, y1) {
  8067. return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
  8068. }
  8069. function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
  8070. 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;
  8071. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  8072. return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
  8073. }
  8074. function d3_svg_line(projection) {
  8075. var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
  8076. function line(data) {
  8077. var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
  8078. function segment() {
  8079. segments.push("M", interpolate(projection(points), tension));
  8080. }
  8081. while (++i < n) {
  8082. if (defined.call(this, d = data[i], i)) {
  8083. points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
  8084. } else if (points.length) {
  8085. segment();
  8086. points = [];
  8087. }
  8088. }
  8089. if (points.length) segment();
  8090. return segments.length ? segments.join("") : null;
  8091. }
  8092. line.x = function(_) {
  8093. if (!arguments.length) return x;
  8094. x = _;
  8095. return line;
  8096. };
  8097. line.y = function(_) {
  8098. if (!arguments.length) return y;
  8099. y = _;
  8100. return line;
  8101. };
  8102. line.defined = function(_) {
  8103. if (!arguments.length) return defined;
  8104. defined = _;
  8105. return line;
  8106. };
  8107. line.interpolate = function(_) {
  8108. if (!arguments.length) return interpolateKey;
  8109. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8110. return line;
  8111. };
  8112. line.tension = function(_) {
  8113. if (!arguments.length) return tension;
  8114. tension = _;
  8115. return line;
  8116. };
  8117. return line;
  8118. }
  8119. d3.svg.line = function() {
  8120. return d3_svg_line(d3_identity);
  8121. };
  8122. var d3_svg_lineInterpolators = d3.map({
  8123. linear: d3_svg_lineLinear,
  8124. "linear-closed": d3_svg_lineLinearClosed,
  8125. step: d3_svg_lineStep,
  8126. "step-before": d3_svg_lineStepBefore,
  8127. "step-after": d3_svg_lineStepAfter,
  8128. basis: d3_svg_lineBasis,
  8129. "basis-open": d3_svg_lineBasisOpen,
  8130. "basis-closed": d3_svg_lineBasisClosed,
  8131. bundle: d3_svg_lineBundle,
  8132. cardinal: d3_svg_lineCardinal,
  8133. "cardinal-open": d3_svg_lineCardinalOpen,
  8134. "cardinal-closed": d3_svg_lineCardinalClosed,
  8135. monotone: d3_svg_lineMonotone
  8136. });
  8137. d3_svg_lineInterpolators.forEach(function(key, value) {
  8138. value.key = key;
  8139. value.closed = /-closed$/.test(key);
  8140. });
  8141. function d3_svg_lineLinear(points) {
  8142. return points.join("L");
  8143. }
  8144. function d3_svg_lineLinearClosed(points) {
  8145. return d3_svg_lineLinear(points) + "Z";
  8146. }
  8147. function d3_svg_lineStep(points) {
  8148. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8149. while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
  8150. if (n > 1) path.push("H", p[0]);
  8151. return path.join("");
  8152. }
  8153. function d3_svg_lineStepBefore(points) {
  8154. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8155. while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
  8156. return path.join("");
  8157. }
  8158. function d3_svg_lineStepAfter(points) {
  8159. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8160. while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
  8161. return path.join("");
  8162. }
  8163. function d3_svg_lineCardinalOpen(points, tension) {
  8164. return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
  8165. }
  8166. function d3_svg_lineCardinalClosed(points, tension) {
  8167. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
  8168. points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
  8169. }
  8170. function d3_svg_lineCardinal(points, tension) {
  8171. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
  8172. }
  8173. function d3_svg_lineHermite(points, tangents) {
  8174. if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
  8175. return d3_svg_lineLinear(points);
  8176. }
  8177. var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
  8178. if (quad) {
  8179. path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
  8180. p0 = points[1];
  8181. pi = 2;
  8182. }
  8183. if (tangents.length > 1) {
  8184. t = tangents[1];
  8185. p = points[pi];
  8186. pi++;
  8187. path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  8188. for (var i = 2; i < tangents.length; i++, pi++) {
  8189. p = points[pi];
  8190. t = tangents[i];
  8191. path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  8192. }
  8193. }
  8194. if (quad) {
  8195. var lp = points[pi];
  8196. path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
  8197. }
  8198. return path;
  8199. }
  8200. function d3_svg_lineCardinalTangents(points, tension) {
  8201. var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
  8202. while (++i < n) {
  8203. p0 = p1;
  8204. p1 = p2;
  8205. p2 = points[i];
  8206. tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
  8207. }
  8208. return tangents;
  8209. }
  8210. function d3_svg_lineBasis(points) {
  8211. if (points.length < 3) return d3_svg_lineLinear(points);
  8212. 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) ];
  8213. points.push(points[n - 1]);
  8214. while (++i <= n) {
  8215. pi = points[i];
  8216. px.shift();
  8217. px.push(pi[0]);
  8218. py.shift();
  8219. py.push(pi[1]);
  8220. d3_svg_lineBasisBezier(path, px, py);
  8221. }
  8222. points.pop();
  8223. path.push("L", pi);
  8224. return path.join("");
  8225. }
  8226. function d3_svg_lineBasisOpen(points) {
  8227. if (points.length < 4) return d3_svg_lineLinear(points);
  8228. var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
  8229. while (++i < 3) {
  8230. pi = points[i];
  8231. px.push(pi[0]);
  8232. py.push(pi[1]);
  8233. }
  8234. path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
  8235. --i;
  8236. while (++i < n) {
  8237. pi = points[i];
  8238. px.shift();
  8239. px.push(pi[0]);
  8240. py.shift();
  8241. py.push(pi[1]);
  8242. d3_svg_lineBasisBezier(path, px, py);
  8243. }
  8244. return path.join("");
  8245. }
  8246. function d3_svg_lineBasisClosed(points) {
  8247. var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
  8248. while (++i < 4) {
  8249. pi = points[i % n];
  8250. px.push(pi[0]);
  8251. py.push(pi[1]);
  8252. }
  8253. path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  8254. --i;
  8255. while (++i < m) {
  8256. pi = points[i % n];
  8257. px.shift();
  8258. px.push(pi[0]);
  8259. py.shift();
  8260. py.push(pi[1]);
  8261. d3_svg_lineBasisBezier(path, px, py);
  8262. }
  8263. return path.join("");
  8264. }
  8265. function d3_svg_lineBundle(points, tension) {
  8266. var n = points.length - 1;
  8267. if (n) {
  8268. var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
  8269. while (++i <= n) {
  8270. p = points[i];
  8271. t = i / n;
  8272. p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
  8273. p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
  8274. }
  8275. }
  8276. return d3_svg_lineBasis(points);
  8277. }
  8278. function d3_svg_lineDot4(a, b) {
  8279. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
  8280. }
  8281. 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 ];
  8282. function d3_svg_lineBasisBezier(path, x, y) {
  8283. 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));
  8284. }
  8285. function d3_svg_lineSlope(p0, p1) {
  8286. return (p1[1] - p0[1]) / (p1[0] - p0[0]);
  8287. }
  8288. function d3_svg_lineFiniteDifferences(points) {
  8289. var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
  8290. while (++i < j) {
  8291. m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
  8292. }
  8293. m[i] = d;
  8294. return m;
  8295. }
  8296. function d3_svg_lineMonotoneTangents(points) {
  8297. var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
  8298. while (++i < j) {
  8299. d = d3_svg_lineSlope(points[i], points[i + 1]);
  8300. if (abs(d) < ε) {
  8301. m[i] = m[i + 1] = 0;
  8302. } else {
  8303. a = m[i] / d;
  8304. b = m[i + 1] / d;
  8305. s = a * a + b * b;
  8306. if (s > 9) {
  8307. s = d * 3 / Math.sqrt(s);
  8308. m[i] = s * a;
  8309. m[i + 1] = s * b;
  8310. }
  8311. }
  8312. }
  8313. i = -1;
  8314. while (++i <= j) {
  8315. s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
  8316. tangents.push([ s || 0, m[i] * s || 0 ]);
  8317. }
  8318. return tangents;
  8319. }
  8320. function d3_svg_lineMonotone(points) {
  8321. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
  8322. }
  8323. d3.svg.line.radial = function() {
  8324. var line = d3_svg_line(d3_svg_lineRadial);
  8325. line.radius = line.x, delete line.x;
  8326. line.angle = line.y, delete line.y;
  8327. return line;
  8328. };
  8329. function d3_svg_lineRadial(points) {
  8330. var point, i = -1, n = points.length, r, a;
  8331. while (++i < n) {
  8332. point = points[i];
  8333. r = point[0];
  8334. a = point[1] - halfπ;
  8335. point[0] = r * Math.cos(a);
  8336. point[1] = r * Math.sin(a);
  8337. }
  8338. return points;
  8339. }
  8340. function d3_svg_area(projection) {
  8341. 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;
  8342. function area(data) {
  8343. var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
  8344. return x;
  8345. } : d3_functor(x1), fy1 = y0 === y1 ? function() {
  8346. return y;
  8347. } : d3_functor(y1), x, y;
  8348. function segment() {
  8349. segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
  8350. }
  8351. while (++i < n) {
  8352. if (defined.call(this, d = data[i], i)) {
  8353. points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
  8354. points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
  8355. } else if (points0.length) {
  8356. segment();
  8357. points0 = [];
  8358. points1 = [];
  8359. }
  8360. }
  8361. if (points0.length) segment();
  8362. return segments.length ? segments.join("") : null;
  8363. }
  8364. area.x = function(_) {
  8365. if (!arguments.length) return x1;
  8366. x0 = x1 = _;
  8367. return area;
  8368. };
  8369. area.x0 = function(_) {
  8370. if (!arguments.length) return x0;
  8371. x0 = _;
  8372. return area;
  8373. };
  8374. area.x1 = function(_) {
  8375. if (!arguments.length) return x1;
  8376. x1 = _;
  8377. return area;
  8378. };
  8379. area.y = function(_) {
  8380. if (!arguments.length) return y1;
  8381. y0 = y1 = _;
  8382. return area;
  8383. };
  8384. area.y0 = function(_) {
  8385. if (!arguments.length) return y0;
  8386. y0 = _;
  8387. return area;
  8388. };
  8389. area.y1 = function(_) {
  8390. if (!arguments.length) return y1;
  8391. y1 = _;
  8392. return area;
  8393. };
  8394. area.defined = function(_) {
  8395. if (!arguments.length) return defined;
  8396. defined = _;
  8397. return area;
  8398. };
  8399. area.interpolate = function(_) {
  8400. if (!arguments.length) return interpolateKey;
  8401. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8402. interpolateReverse = interpolate.reverse || interpolate;
  8403. L = interpolate.closed ? "M" : "L";
  8404. return area;
  8405. };
  8406. area.tension = function(_) {
  8407. if (!arguments.length) return tension;
  8408. tension = _;
  8409. return area;
  8410. };
  8411. return area;
  8412. }
  8413. d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
  8414. d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
  8415. d3.svg.area = function() {
  8416. return d3_svg_area(d3_identity);
  8417. };
  8418. d3.svg.area.radial = function() {
  8419. var area = d3_svg_area(d3_svg_lineRadial);
  8420. area.radius = area.x, delete area.x;
  8421. area.innerRadius = area.x0, delete area.x0;
  8422. area.outerRadius = area.x1, delete area.x1;
  8423. area.angle = area.y, delete area.y;
  8424. area.startAngle = area.y0, delete area.y0;
  8425. area.endAngle = area.y1, delete area.y1;
  8426. return area;
  8427. };
  8428. d3.svg.chord = function() {
  8429. var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
  8430. function chord(d, i) {
  8431. var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
  8432. 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";
  8433. }
  8434. function subgroup(self, f, d, i) {
  8435. 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π;
  8436. return {
  8437. r: r,
  8438. a0: a0,
  8439. a1: a1,
  8440. p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
  8441. p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
  8442. };
  8443. }
  8444. function equals(a, b) {
  8445. return a.a0 == b.a0 && a.a1 == b.a1;
  8446. }
  8447. function arc(r, p, a) {
  8448. return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
  8449. }
  8450. function curve(r0, p0, r1, p1) {
  8451. return "Q 0,0 " + p1;
  8452. }
  8453. chord.radius = function(v) {
  8454. if (!arguments.length) return radius;
  8455. radius = d3_functor(v);
  8456. return chord;
  8457. };
  8458. chord.source = function(v) {
  8459. if (!arguments.length) return source;
  8460. source = d3_functor(v);
  8461. return chord;
  8462. };
  8463. chord.target = function(v) {
  8464. if (!arguments.length) return target;
  8465. target = d3_functor(v);
  8466. return chord;
  8467. };
  8468. chord.startAngle = function(v) {
  8469. if (!arguments.length) return startAngle;
  8470. startAngle = d3_functor(v);
  8471. return chord;
  8472. };
  8473. chord.endAngle = function(v) {
  8474. if (!arguments.length) return endAngle;
  8475. endAngle = d3_functor(v);
  8476. return chord;
  8477. };
  8478. return chord;
  8479. };
  8480. function d3_svg_chordRadius(d) {
  8481. return d.radius;
  8482. }
  8483. d3.svg.diagonal = function() {
  8484. var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
  8485. function diagonal(d, i) {
  8486. var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
  8487. x: p0.x,
  8488. y: m
  8489. }, {
  8490. x: p3.x,
  8491. y: m
  8492. }, p3 ];
  8493. p = p.map(projection);
  8494. return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
  8495. }
  8496. diagonal.source = function(x) {
  8497. if (!arguments.length) return source;
  8498. source = d3_functor(x);
  8499. return diagonal;
  8500. };
  8501. diagonal.target = function(x) {
  8502. if (!arguments.length) return target;
  8503. target = d3_functor(x);
  8504. return diagonal;
  8505. };
  8506. diagonal.projection = function(x) {
  8507. if (!arguments.length) return projection;
  8508. projection = x;
  8509. return diagonal;
  8510. };
  8511. return diagonal;
  8512. };
  8513. function d3_svg_diagonalProjection(d) {
  8514. return [ d.x, d.y ];
  8515. }
  8516. d3.svg.diagonal.radial = function() {
  8517. var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
  8518. diagonal.projection = function(x) {
  8519. return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
  8520. };
  8521. return diagonal;
  8522. };
  8523. function d3_svg_diagonalRadialProjection(projection) {
  8524. return function() {
  8525. var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
  8526. return [ r * Math.cos(a), r * Math.sin(a) ];
  8527. };
  8528. }
  8529. d3.svg.symbol = function() {
  8530. var type = d3_svg_symbolType, size = d3_svg_symbolSize;
  8531. function symbol(d, i) {
  8532. return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
  8533. }
  8534. symbol.type = function(x) {
  8535. if (!arguments.length) return type;
  8536. type = d3_functor(x);
  8537. return symbol;
  8538. };
  8539. symbol.size = function(x) {
  8540. if (!arguments.length) return size;
  8541. size = d3_functor(x);
  8542. return symbol;
  8543. };
  8544. return symbol;
  8545. };
  8546. function d3_svg_symbolSize() {
  8547. return 64;
  8548. }
  8549. function d3_svg_symbolType() {
  8550. return "circle";
  8551. }
  8552. function d3_svg_symbolCircle(size) {
  8553. var r = Math.sqrt(size / π);
  8554. return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
  8555. }
  8556. var d3_svg_symbols = d3.map({
  8557. circle: d3_svg_symbolCircle,
  8558. cross: function(size) {
  8559. var r = Math.sqrt(size / 5) / 2;
  8560. 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";
  8561. },
  8562. diamond: function(size) {
  8563. var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
  8564. return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
  8565. },
  8566. square: function(size) {
  8567. var r = Math.sqrt(size) / 2;
  8568. return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
  8569. },
  8570. "triangle-down": function(size) {
  8571. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8572. return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
  8573. },
  8574. "triangle-up": function(size) {
  8575. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  8576. return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
  8577. }
  8578. });
  8579. d3.svg.symbolTypes = d3_svg_symbols.keys();
  8580. var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
  8581. d3_selectionPrototype.transition = function(name) {
  8582. var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
  8583. time: Date.now(),
  8584. ease: d3_ease_cubicInOut,
  8585. delay: 0,
  8586. duration: 250
  8587. };
  8588. for (var j = -1, m = this.length; ++j < m; ) {
  8589. subgroups.push(subgroup = []);
  8590. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8591. if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
  8592. subgroup.push(node);
  8593. }
  8594. }
  8595. return d3_transition(subgroups, ns, id);
  8596. };
  8597. d3_selectionPrototype.interrupt = function(name) {
  8598. return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
  8599. };
  8600. var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
  8601. function d3_selection_interruptNS(ns) {
  8602. return function() {
  8603. var lock, active;
  8604. if ((lock = this[ns]) && (active = lock[lock.active])) {
  8605. if (--lock.count) delete lock[lock.active]; else delete this[ns];
  8606. lock.active += .5;
  8607. active.event && active.event.interrupt.call(this, this.__data__, active.index);
  8608. }
  8609. };
  8610. }
  8611. function d3_transition(groups, ns, id) {
  8612. d3_subclass(groups, d3_transitionPrototype);
  8613. groups.namespace = ns;
  8614. groups.id = id;
  8615. return groups;
  8616. }
  8617. var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
  8618. d3_transitionPrototype.call = d3_selectionPrototype.call;
  8619. d3_transitionPrototype.empty = d3_selectionPrototype.empty;
  8620. d3_transitionPrototype.node = d3_selectionPrototype.node;
  8621. d3_transitionPrototype.size = d3_selectionPrototype.size;
  8622. d3.transition = function(selection, name) {
  8623. return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
  8624. };
  8625. d3.transition.prototype = d3_transitionPrototype;
  8626. d3_transitionPrototype.select = function(selector) {
  8627. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
  8628. selector = d3_selection_selector(selector);
  8629. for (var j = -1, m = this.length; ++j < m; ) {
  8630. subgroups.push(subgroup = []);
  8631. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8632. if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
  8633. if ("__data__" in node) subnode.__data__ = node.__data__;
  8634. d3_transitionNode(subnode, i, ns, id, node[ns][id]);
  8635. subgroup.push(subnode);
  8636. } else {
  8637. subgroup.push(null);
  8638. }
  8639. }
  8640. }
  8641. return d3_transition(subgroups, ns, id);
  8642. };
  8643. d3_transitionPrototype.selectAll = function(selector) {
  8644. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
  8645. selector = d3_selection_selectorAll(selector);
  8646. for (var j = -1, m = this.length; ++j < m; ) {
  8647. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  8648. if (node = group[i]) {
  8649. transition = node[ns][id];
  8650. subnodes = selector.call(node, node.__data__, i, j);
  8651. subgroups.push(subgroup = []);
  8652. for (var k = -1, o = subnodes.length; ++k < o; ) {
  8653. if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
  8654. subgroup.push(subnode);
  8655. }
  8656. }
  8657. }
  8658. }
  8659. return d3_transition(subgroups, ns, id);
  8660. };
  8661. d3_transitionPrototype.filter = function(filter) {
  8662. var subgroups = [], subgroup, group, node;
  8663. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  8664. for (var j = 0, m = this.length; j < m; j++) {
  8665. subgroups.push(subgroup = []);
  8666. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8667. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  8668. subgroup.push(node);
  8669. }
  8670. }
  8671. }
  8672. return d3_transition(subgroups, this.namespace, this.id);
  8673. };
  8674. d3_transitionPrototype.tween = function(name, tween) {
  8675. var id = this.id, ns = this.namespace;
  8676. if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
  8677. return d3_selection_each(this, tween == null ? function(node) {
  8678. node[ns][id].tween.remove(name);
  8679. } : function(node) {
  8680. node[ns][id].tween.set(name, tween);
  8681. });
  8682. };
  8683. function d3_transition_tween(groups, name, value, tween) {
  8684. var id = groups.id, ns = groups.namespace;
  8685. return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
  8686. node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
  8687. } : (value = tween(value), function(node) {
  8688. node[ns][id].tween.set(name, value);
  8689. }));
  8690. }
  8691. d3_transitionPrototype.attr = function(nameNS, value) {
  8692. if (arguments.length < 2) {
  8693. for (value in nameNS) this.attr(value, nameNS[value]);
  8694. return this;
  8695. }
  8696. var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
  8697. function attrNull() {
  8698. this.removeAttribute(name);
  8699. }
  8700. function attrNullNS() {
  8701. this.removeAttributeNS(name.space, name.local);
  8702. }
  8703. function attrTween(b) {
  8704. return b == null ? attrNull : (b += "", function() {
  8705. var a = this.getAttribute(name), i;
  8706. return a !== b && (i = interpolate(a, b), function(t) {
  8707. this.setAttribute(name, i(t));
  8708. });
  8709. });
  8710. }
  8711. function attrTweenNS(b) {
  8712. return b == null ? attrNullNS : (b += "", function() {
  8713. var a = this.getAttributeNS(name.space, name.local), i;
  8714. return a !== b && (i = interpolate(a, b), function(t) {
  8715. this.setAttributeNS(name.space, name.local, i(t));
  8716. });
  8717. });
  8718. }
  8719. return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
  8720. };
  8721. d3_transitionPrototype.attrTween = function(nameNS, tween) {
  8722. var name = d3.ns.qualify(nameNS);
  8723. function attrTween(d, i) {
  8724. var f = tween.call(this, d, i, this.getAttribute(name));
  8725. return f && function(t) {
  8726. this.setAttribute(name, f(t));
  8727. };
  8728. }
  8729. function attrTweenNS(d, i) {
  8730. var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
  8731. return f && function(t) {
  8732. this.setAttributeNS(name.space, name.local, f(t));
  8733. };
  8734. }
  8735. return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
  8736. };
  8737. d3_transitionPrototype.style = function(name, value, priority) {
  8738. var n = arguments.length;
  8739. if (n < 3) {
  8740. if (typeof name !== "string") {
  8741. if (n < 2) value = "";
  8742. for (priority in name) this.style(priority, name[priority], value);
  8743. return this;
  8744. }
  8745. priority = "";
  8746. }
  8747. function styleNull() {
  8748. this.style.removeProperty(name);
  8749. }
  8750. function styleString(b) {
  8751. return b == null ? styleNull : (b += "", function() {
  8752. var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
  8753. return a !== b && (i = d3_interpolate(a, b), function(t) {
  8754. this.style.setProperty(name, i(t), priority);
  8755. });
  8756. });
  8757. }
  8758. return d3_transition_tween(this, "style." + name, value, styleString);
  8759. };
  8760. d3_transitionPrototype.styleTween = function(name, tween, priority) {
  8761. if (arguments.length < 3) priority = "";
  8762. function styleTween(d, i) {
  8763. var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
  8764. return f && function(t) {
  8765. this.style.setProperty(name, f(t), priority);
  8766. };
  8767. }
  8768. return this.tween("style." + name, styleTween);
  8769. };
  8770. d3_transitionPrototype.text = function(value) {
  8771. return d3_transition_tween(this, "text", value, d3_transition_text);
  8772. };
  8773. function d3_transition_text(b) {
  8774. if (b == null) b = "";
  8775. return function() {
  8776. this.textContent = b;
  8777. };
  8778. }
  8779. d3_transitionPrototype.remove = function() {
  8780. var ns = this.namespace;
  8781. return this.each("end.transition", function() {
  8782. var p;
  8783. if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
  8784. });
  8785. };
  8786. d3_transitionPrototype.ease = function(value) {
  8787. var id = this.id, ns = this.namespace;
  8788. if (arguments.length < 1) return this.node()[ns][id].ease;
  8789. if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
  8790. return d3_selection_each(this, function(node) {
  8791. node[ns][id].ease = value;
  8792. });
  8793. };
  8794. d3_transitionPrototype.delay = function(value) {
  8795. var id = this.id, ns = this.namespace;
  8796. if (arguments.length < 1) return this.node()[ns][id].delay;
  8797. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8798. node[ns][id].delay = +value.call(node, node.__data__, i, j);
  8799. } : (value = +value, function(node) {
  8800. node[ns][id].delay = value;
  8801. }));
  8802. };
  8803. d3_transitionPrototype.duration = function(value) {
  8804. var id = this.id, ns = this.namespace;
  8805. if (arguments.length < 1) return this.node()[ns][id].duration;
  8806. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  8807. node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
  8808. } : (value = Math.max(1, value), function(node) {
  8809. node[ns][id].duration = value;
  8810. }));
  8811. };
  8812. d3_transitionPrototype.each = function(type, listener) {
  8813. var id = this.id, ns = this.namespace;
  8814. if (arguments.length < 2) {
  8815. var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
  8816. try {
  8817. d3_transitionInheritId = id;
  8818. d3_selection_each(this, function(node, i, j) {
  8819. d3_transitionInherit = node[ns][id];
  8820. type.call(node, node.__data__, i, j);
  8821. });
  8822. } finally {
  8823. d3_transitionInherit = inherit;
  8824. d3_transitionInheritId = inheritId;
  8825. }
  8826. } else {
  8827. d3_selection_each(this, function(node) {
  8828. var transition = node[ns][id];
  8829. (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
  8830. });
  8831. }
  8832. return this;
  8833. };
  8834. d3_transitionPrototype.transition = function() {
  8835. var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
  8836. for (var j = 0, m = this.length; j < m; j++) {
  8837. subgroups.push(subgroup = []);
  8838. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  8839. if (node = group[i]) {
  8840. transition = node[ns][id0];
  8841. d3_transitionNode(node, i, ns, id1, {
  8842. time: transition.time,
  8843. ease: transition.ease,
  8844. delay: transition.delay + transition.duration,
  8845. duration: transition.duration
  8846. });
  8847. }
  8848. subgroup.push(node);
  8849. }
  8850. }
  8851. return d3_transition(subgroups, ns, id1);
  8852. };
  8853. function d3_transitionNamespace(name) {
  8854. return name == null ? "__transition__" : "__transition_" + name + "__";
  8855. }
  8856. function d3_transitionNode(node, i, ns, id, inherit) {
  8857. var lock = node[ns] || (node[ns] = {
  8858. active: 0,
  8859. count: 0
  8860. }), transition = lock[id];
  8861. if (!transition) {
  8862. var time = inherit.time;
  8863. transition = lock[id] = {
  8864. tween: new d3_Map(),
  8865. time: time,
  8866. delay: inherit.delay,
  8867. duration: inherit.duration,
  8868. ease: inherit.ease,
  8869. index: i
  8870. };
  8871. inherit = null;
  8872. ++lock.count;
  8873. d3.timer(function(elapsed) {
  8874. var delay = transition.delay, duration, ease, timer = d3_timer_active, tweened = [];
  8875. timer.t = delay + time;
  8876. if (delay <= elapsed) return start(elapsed - delay);
  8877. timer.c = start;
  8878. function start(elapsed) {
  8879. if (lock.active > id) return stop();
  8880. var active = lock[lock.active];
  8881. if (active) {
  8882. --lock.count;
  8883. delete lock[lock.active];
  8884. active.event && active.event.interrupt.call(node, node.__data__, active.index);
  8885. }
  8886. lock.active = id;
  8887. transition.event && transition.event.start.call(node, node.__data__, i);
  8888. transition.tween.forEach(function(key, value) {
  8889. if (value = value.call(node, node.__data__, i)) {
  8890. tweened.push(value);
  8891. }
  8892. });
  8893. ease = transition.ease;
  8894. duration = transition.duration;
  8895. d3.timer(function() {
  8896. timer.c = tick(elapsed || 1) ? d3_true : tick;
  8897. return 1;
  8898. }, 0, time);
  8899. }
  8900. function tick(elapsed) {
  8901. if (lock.active !== id) return 1;
  8902. var t = elapsed / duration, e = ease(t), n = tweened.length;
  8903. while (n > 0) {
  8904. tweened[--n].call(node, e);
  8905. }
  8906. if (t >= 1) {
  8907. transition.event && transition.event.end.call(node, node.__data__, i);
  8908. return stop();
  8909. }
  8910. }
  8911. function stop() {
  8912. if (--lock.count) delete lock[id]; else delete node[ns];
  8913. return 1;
  8914. }
  8915. }, 0, time);
  8916. }
  8917. }
  8918. d3.svg.axis = function() {
  8919. var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
  8920. function axis(g) {
  8921. g.each(function() {
  8922. var g = d3.select(this);
  8923. var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
  8924. 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;
  8925. var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
  8926. d3.transition(path));
  8927. tickEnter.append("line");
  8928. tickEnter.append("text");
  8929. 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;
  8930. if (orient === "bottom" || orient === "top") {
  8931. tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
  8932. text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
  8933. pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
  8934. } else {
  8935. tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
  8936. text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
  8937. pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
  8938. }
  8939. lineEnter.attr(y2, sign * innerTickSize);
  8940. textEnter.attr(y1, sign * tickSpacing);
  8941. lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
  8942. textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
  8943. if (scale1.rangeBand) {
  8944. var x = scale1, dx = x.rangeBand() / 2;
  8945. scale0 = scale1 = function(d) {
  8946. return x(d) + dx;
  8947. };
  8948. } else if (scale0.rangeBand) {
  8949. scale0 = scale1;
  8950. } else {
  8951. tickExit.call(tickTransform, scale1, scale0);
  8952. }
  8953. tickEnter.call(tickTransform, scale0, scale1);
  8954. tickUpdate.call(tickTransform, scale1, scale1);
  8955. });
  8956. }
  8957. axis.scale = function(x) {
  8958. if (!arguments.length) return scale;
  8959. scale = x;
  8960. return axis;
  8961. };
  8962. axis.orient = function(x) {
  8963. if (!arguments.length) return orient;
  8964. orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
  8965. return axis;
  8966. };
  8967. axis.ticks = function() {
  8968. if (!arguments.length) return tickArguments_;
  8969. tickArguments_ = arguments;
  8970. return axis;
  8971. };
  8972. axis.tickValues = function(x) {
  8973. if (!arguments.length) return tickValues;
  8974. tickValues = x;
  8975. return axis;
  8976. };
  8977. axis.tickFormat = function(x) {
  8978. if (!arguments.length) return tickFormat_;
  8979. tickFormat_ = x;
  8980. return axis;
  8981. };
  8982. axis.tickSize = function(x) {
  8983. var n = arguments.length;
  8984. if (!n) return innerTickSize;
  8985. innerTickSize = +x;
  8986. outerTickSize = +arguments[n - 1];
  8987. return axis;
  8988. };
  8989. axis.innerTickSize = function(x) {
  8990. if (!arguments.length) return innerTickSize;
  8991. innerTickSize = +x;
  8992. return axis;
  8993. };
  8994. axis.outerTickSize = function(x) {
  8995. if (!arguments.length) return outerTickSize;
  8996. outerTickSize = +x;
  8997. return axis;
  8998. };
  8999. axis.tickPadding = function(x) {
  9000. if (!arguments.length) return tickPadding;
  9001. tickPadding = +x;
  9002. return axis;
  9003. };
  9004. axis.tickSubdivide = function() {
  9005. return arguments.length && axis;
  9006. };
  9007. return axis;
  9008. };
  9009. var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
  9010. top: 1,
  9011. right: 1,
  9012. bottom: 1,
  9013. left: 1
  9014. };
  9015. function d3_svg_axisX(selection, x0, x1) {
  9016. selection.attr("transform", function(d) {
  9017. var v0 = x0(d);
  9018. return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
  9019. });
  9020. }
  9021. function d3_svg_axisY(selection, y0, y1) {
  9022. selection.attr("transform", function(d) {
  9023. var v0 = y0(d);
  9024. return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
  9025. });
  9026. }
  9027. d3.svg.brush = function() {
  9028. 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];
  9029. function brush(g) {
  9030. g.each(function() {
  9031. 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);
  9032. var background = g.selectAll(".background").data([ 0 ]);
  9033. background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
  9034. g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
  9035. var resize = g.selectAll(".resize").data(resizes, d3_identity);
  9036. resize.exit().remove();
  9037. resize.enter().append("g").attr("class", function(d) {
  9038. return "resize " + d;
  9039. }).style("cursor", function(d) {
  9040. return d3_svg_brushCursor[d];
  9041. }).append("rect").attr("x", function(d) {
  9042. return /[ew]$/.test(d) ? -3 : null;
  9043. }).attr("y", function(d) {
  9044. return /^[ns]/.test(d) ? -3 : null;
  9045. }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
  9046. resize.style("display", brush.empty() ? "none" : null);
  9047. var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
  9048. if (x) {
  9049. range = d3_scaleRange(x);
  9050. backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
  9051. redrawX(gUpdate);
  9052. }
  9053. if (y) {
  9054. range = d3_scaleRange(y);
  9055. backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
  9056. redrawY(gUpdate);
  9057. }
  9058. redraw(gUpdate);
  9059. });
  9060. }
  9061. brush.event = function(g) {
  9062. g.each(function() {
  9063. var event_ = event.of(this, arguments), extent1 = {
  9064. x: xExtent,
  9065. y: yExtent,
  9066. i: xExtentDomain,
  9067. j: yExtentDomain
  9068. }, extent0 = this.__chart__ || extent1;
  9069. this.__chart__ = extent1;
  9070. if (d3_transitionInheritId) {
  9071. d3.select(this).transition().each("start.brush", function() {
  9072. xExtentDomain = extent0.i;
  9073. yExtentDomain = extent0.j;
  9074. xExtent = extent0.x;
  9075. yExtent = extent0.y;
  9076. event_({
  9077. type: "brushstart"
  9078. });
  9079. }).tween("brush:brush", function() {
  9080. var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
  9081. xExtentDomain = yExtentDomain = null;
  9082. return function(t) {
  9083. xExtent = extent1.x = xi(t);
  9084. yExtent = extent1.y = yi(t);
  9085. event_({
  9086. type: "brush",
  9087. mode: "resize"
  9088. });
  9089. };
  9090. }).each("end.brush", function() {
  9091. xExtentDomain = extent1.i;
  9092. yExtentDomain = extent1.j;
  9093. event_({
  9094. type: "brush",
  9095. mode: "resize"
  9096. });
  9097. event_({
  9098. type: "brushend"
  9099. });
  9100. });
  9101. } else {
  9102. event_({
  9103. type: "brushstart"
  9104. });
  9105. event_({
  9106. type: "brush",
  9107. mode: "resize"
  9108. });
  9109. event_({
  9110. type: "brushend"
  9111. });
  9112. }
  9113. });
  9114. };
  9115. function redraw(g) {
  9116. g.selectAll(".resize").attr("transform", function(d) {
  9117. return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
  9118. });
  9119. }
  9120. function redrawX(g) {
  9121. g.select(".extent").attr("x", xExtent[0]);
  9122. g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
  9123. }
  9124. function redrawY(g) {
  9125. g.select(".extent").attr("y", yExtent[0]);
  9126. g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
  9127. }
  9128. function brushstart() {
  9129. 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(target), center, origin = d3.mouse(target), offset;
  9130. var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
  9131. if (d3.event.changedTouches) {
  9132. w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
  9133. } else {
  9134. w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
  9135. }
  9136. g.interrupt().selectAll("*").interrupt();
  9137. if (dragging) {
  9138. origin[0] = xExtent[0] - origin[0];
  9139. origin[1] = yExtent[0] - origin[1];
  9140. } else if (resizing) {
  9141. var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
  9142. offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
  9143. origin[0] = xExtent[ex];
  9144. origin[1] = yExtent[ey];
  9145. } else if (d3.event.altKey) center = origin.slice();
  9146. g.style("pointer-events", "none").selectAll(".resize").style("display", null);
  9147. d3.select("body").style("cursor", eventTarget.style("cursor"));
  9148. event_({
  9149. type: "brushstart"
  9150. });
  9151. brushmove();
  9152. function keydown() {
  9153. if (d3.event.keyCode == 32) {
  9154. if (!dragging) {
  9155. center = null;
  9156. origin[0] -= xExtent[1];
  9157. origin[1] -= yExtent[1];
  9158. dragging = 2;
  9159. }
  9160. d3_eventPreventDefault();
  9161. }
  9162. }
  9163. function keyup() {
  9164. if (d3.event.keyCode == 32 && dragging == 2) {
  9165. origin[0] += xExtent[1];
  9166. origin[1] += yExtent[1];
  9167. dragging = 0;
  9168. d3_eventPreventDefault();
  9169. }
  9170. }
  9171. function brushmove() {
  9172. var point = d3.mouse(target), moved = false;
  9173. if (offset) {
  9174. point[0] += offset[0];
  9175. point[1] += offset[1];
  9176. }
  9177. if (!dragging) {
  9178. if (d3.event.altKey) {
  9179. if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
  9180. origin[0] = xExtent[+(point[0] < center[0])];
  9181. origin[1] = yExtent[+(point[1] < center[1])];
  9182. } else center = null;
  9183. }
  9184. if (resizingX && move1(point, x, 0)) {
  9185. redrawX(g);
  9186. moved = true;
  9187. }
  9188. if (resizingY && move1(point, y, 1)) {
  9189. redrawY(g);
  9190. moved = true;
  9191. }
  9192. if (moved) {
  9193. redraw(g);
  9194. event_({
  9195. type: "brush",
  9196. mode: dragging ? "move" : "resize"
  9197. });
  9198. }
  9199. }
  9200. function move1(point, scale, i) {
  9201. 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;
  9202. if (dragging) {
  9203. r0 -= position;
  9204. r1 -= size + position;
  9205. }
  9206. min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
  9207. if (dragging) {
  9208. max = (min += position) + size;
  9209. } else {
  9210. if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
  9211. if (position < min) {
  9212. max = min;
  9213. min = position;
  9214. } else {
  9215. max = position;
  9216. }
  9217. }
  9218. if (extent[0] != min || extent[1] != max) {
  9219. if (i) yExtentDomain = null; else xExtentDomain = null;
  9220. extent[0] = min;
  9221. extent[1] = max;
  9222. return true;
  9223. }
  9224. }
  9225. function brushend() {
  9226. brushmove();
  9227. g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
  9228. d3.select("body").style("cursor", null);
  9229. 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);
  9230. dragRestore();
  9231. event_({
  9232. type: "brushend"
  9233. });
  9234. }
  9235. }
  9236. brush.x = function(z) {
  9237. if (!arguments.length) return x;
  9238. x = z;
  9239. resizes = d3_svg_brushResizes[!x << 1 | !y];
  9240. return brush;
  9241. };
  9242. brush.y = function(z) {
  9243. if (!arguments.length) return y;
  9244. y = z;
  9245. resizes = d3_svg_brushResizes[!x << 1 | !y];
  9246. return brush;
  9247. };
  9248. brush.clamp = function(z) {
  9249. if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
  9250. if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
  9251. return brush;
  9252. };
  9253. brush.extent = function(z) {
  9254. var x0, x1, y0, y1, t;
  9255. if (!arguments.length) {
  9256. if (x) {
  9257. if (xExtentDomain) {
  9258. x0 = xExtentDomain[0], x1 = xExtentDomain[1];
  9259. } else {
  9260. x0 = xExtent[0], x1 = xExtent[1];
  9261. if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
  9262. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  9263. }
  9264. }
  9265. if (y) {
  9266. if (yExtentDomain) {
  9267. y0 = yExtentDomain[0], y1 = yExtentDomain[1];
  9268. } else {
  9269. y0 = yExtent[0], y1 = yExtent[1];
  9270. if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
  9271. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9272. }
  9273. }
  9274. return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
  9275. }
  9276. if (x) {
  9277. x0 = z[0], x1 = z[1];
  9278. if (y) x0 = x0[0], x1 = x1[0];
  9279. xExtentDomain = [ x0, x1 ];
  9280. if (x.invert) x0 = x(x0), x1 = x(x1);
  9281. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  9282. if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
  9283. }
  9284. if (y) {
  9285. y0 = z[0], y1 = z[1];
  9286. if (x) y0 = y0[1], y1 = y1[1];
  9287. yExtentDomain = [ y0, y1 ];
  9288. if (y.invert) y0 = y(y0), y1 = y(y1);
  9289. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  9290. if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
  9291. }
  9292. return brush;
  9293. };
  9294. brush.clear = function() {
  9295. if (!brush.empty()) {
  9296. xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
  9297. xExtentDomain = yExtentDomain = null;
  9298. }
  9299. return brush;
  9300. };
  9301. brush.empty = function() {
  9302. return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
  9303. };
  9304. return d3.rebind(brush, event, "on");
  9305. };
  9306. var d3_svg_brushCursor = {
  9307. n: "ns-resize",
  9308. e: "ew-resize",
  9309. s: "ns-resize",
  9310. w: "ew-resize",
  9311. nw: "nwse-resize",
  9312. ne: "nesw-resize",
  9313. se: "nwse-resize",
  9314. sw: "nesw-resize"
  9315. };
  9316. var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
  9317. var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
  9318. var d3_time_formatUtc = d3_time_format.utc;
  9319. var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
  9320. d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
  9321. function d3_time_formatIsoNative(date) {
  9322. return date.toISOString();
  9323. }
  9324. d3_time_formatIsoNative.parse = function(string) {
  9325. var date = new Date(string);
  9326. return isNaN(date) ? null : date;
  9327. };
  9328. d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
  9329. d3_time.second = d3_time_interval(function(date) {
  9330. return new d3_date(Math.floor(date / 1e3) * 1e3);
  9331. }, function(date, offset) {
  9332. date.setTime(date.getTime() + Math.floor(offset) * 1e3);
  9333. }, function(date) {
  9334. return date.getSeconds();
  9335. });
  9336. d3_time.seconds = d3_time.second.range;
  9337. d3_time.seconds.utc = d3_time.second.utc.range;
  9338. d3_time.minute = d3_time_interval(function(date) {
  9339. return new d3_date(Math.floor(date / 6e4) * 6e4);
  9340. }, function(date, offset) {
  9341. date.setTime(date.getTime() + Math.floor(offset) * 6e4);
  9342. }, function(date) {
  9343. return date.getMinutes();
  9344. });
  9345. d3_time.minutes = d3_time.minute.range;
  9346. d3_time.minutes.utc = d3_time.minute.utc.range;
  9347. d3_time.hour = d3_time_interval(function(date) {
  9348. var timezone = date.getTimezoneOffset() / 60;
  9349. return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
  9350. }, function(date, offset) {
  9351. date.setTime(date.getTime() + Math.floor(offset) * 36e5);
  9352. }, function(date) {
  9353. return date.getHours();
  9354. });
  9355. d3_time.hours = d3_time.hour.range;
  9356. d3_time.hours.utc = d3_time.hour.utc.range;
  9357. d3_time.month = d3_time_interval(function(date) {
  9358. date = d3_time.day(date);
  9359. date.setDate(1);
  9360. return date;
  9361. }, function(date, offset) {
  9362. date.setMonth(date.getMonth() + offset);
  9363. }, function(date) {
  9364. return date.getMonth();
  9365. });
  9366. d3_time.months = d3_time.month.range;
  9367. d3_time.months.utc = d3_time.month.utc.range;
  9368. function d3_time_scale(linear, methods, format) {
  9369. function scale(x) {
  9370. return linear(x);
  9371. }
  9372. scale.invert = function(x) {
  9373. return d3_time_scaleDate(linear.invert(x));
  9374. };
  9375. scale.domain = function(x) {
  9376. if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
  9377. linear.domain(x);
  9378. return scale;
  9379. };
  9380. function tickMethod(extent, count) {
  9381. var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
  9382. return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
  9383. return d / 31536e6;
  9384. }), 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];
  9385. }
  9386. scale.nice = function(interval, skip) {
  9387. var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
  9388. if (method) interval = method[0], skip = method[1];
  9389. function skipped(date) {
  9390. return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
  9391. }
  9392. return scale.domain(d3_scale_nice(domain, skip > 1 ? {
  9393. floor: function(date) {
  9394. while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
  9395. return date;
  9396. },
  9397. ceil: function(date) {
  9398. while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
  9399. return date;
  9400. }
  9401. } : interval));
  9402. };
  9403. scale.ticks = function(interval, skip) {
  9404. var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
  9405. range: interval
  9406. }, skip ];
  9407. if (method) interval = method[0], skip = method[1];
  9408. return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
  9409. };
  9410. scale.tickFormat = function() {
  9411. return format;
  9412. };
  9413. scale.copy = function() {
  9414. return d3_time_scale(linear.copy(), methods, format);
  9415. };
  9416. return d3_scale_linearRebind(scale, linear);
  9417. }
  9418. function d3_time_scaleDate(t) {
  9419. return new Date(t);
  9420. }
  9421. var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
  9422. 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 ] ];
  9423. var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
  9424. return d.getMilliseconds();
  9425. } ], [ ":%S", function(d) {
  9426. return d.getSeconds();
  9427. } ], [ "%I:%M", function(d) {
  9428. return d.getMinutes();
  9429. } ], [ "%I %p", function(d) {
  9430. return d.getHours();
  9431. } ], [ "%a %d", function(d) {
  9432. return d.getDay() && d.getDate() != 1;
  9433. } ], [ "%b %d", function(d) {
  9434. return d.getDate() != 1;
  9435. } ], [ "%B", function(d) {
  9436. return d.getMonth();
  9437. } ], [ "%Y", d3_true ] ]);
  9438. var d3_time_scaleMilliseconds = {
  9439. range: function(start, stop, step) {
  9440. return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
  9441. },
  9442. floor: d3_identity,
  9443. ceil: d3_identity
  9444. };
  9445. d3_time_scaleLocalMethods.year = d3_time.year;
  9446. d3_time.scale = function() {
  9447. return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
  9448. };
  9449. var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
  9450. return [ m[0].utc, m[1] ];
  9451. });
  9452. var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
  9453. return d.getUTCMilliseconds();
  9454. } ], [ ":%S", function(d) {
  9455. return d.getUTCSeconds();
  9456. } ], [ "%I:%M", function(d) {
  9457. return d.getUTCMinutes();
  9458. } ], [ "%I %p", function(d) {
  9459. return d.getUTCHours();
  9460. } ], [ "%a %d", function(d) {
  9461. return d.getUTCDay() && d.getUTCDate() != 1;
  9462. } ], [ "%b %d", function(d) {
  9463. return d.getUTCDate() != 1;
  9464. } ], [ "%B", function(d) {
  9465. return d.getUTCMonth();
  9466. } ], [ "%Y", d3_true ] ]);
  9467. d3_time_scaleUtcMethods.year = d3_time.year.utc;
  9468. d3_time.scale.utc = function() {
  9469. return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
  9470. };
  9471. d3.text = d3_xhrType(function(request) {
  9472. return request.responseText;
  9473. });
  9474. d3.json = function(url, callback) {
  9475. return d3_xhr(url, "application/json", d3_json, callback);
  9476. };
  9477. function d3_json(request) {
  9478. return JSON.parse(request.responseText);
  9479. }
  9480. d3.html = function(url, callback) {
  9481. return d3_xhr(url, "text/html", d3_html, callback);
  9482. };
  9483. function d3_html(request) {
  9484. var range = d3_document.createRange();
  9485. range.selectNode(d3_document.body);
  9486. return range.createContextualFragment(request.responseText);
  9487. }
  9488. d3.xml = d3_xhrType(function(request) {
  9489. return request.responseXML;
  9490. });
  9491. if (typeof define === "function" && define.amd) define(d3); else if (typeof module === "object" && module.exports) module.exports = d3;
  9492. this.d3 = d3;
  9493. }();