00001 !function() {
00002 var d3 = {
00003 version: "3.5.5"
00004 };
00005 var d3_arraySlice = [].slice, d3_array = function(list) {
00006 return d3_arraySlice.call(list);
00007 };
00008 var d3_document = this.document;
00009 function d3_documentElement(node) {
00010 return node && (node.ownerDocument || node.document || node).documentElement;
00011 }
00012 function d3_window(node) {
00013 return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
00014 }
00015 if (d3_document) {
00016 try {
00017 d3_array(d3_document.documentElement.childNodes)[0].nodeType;
00018 } catch (e) {
00019 d3_array = function(list) {
00020 var i = list.length, array = new Array(i);
00021 while (i--) array[i] = list[i];
00022 return array;
00023 };
00024 }
00025 }
00026 if (!Date.now) Date.now = function() {
00027 return +new Date();
00028 };
00029 if (d3_document) {
00030 try {
00031 d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
00032 } catch (error) {
00033 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;
00034 d3_element_prototype.setAttribute = function(name, value) {
00035 d3_element_setAttribute.call(this, name, value + "");
00036 };
00037 d3_element_prototype.setAttributeNS = function(space, local, value) {
00038 d3_element_setAttributeNS.call(this, space, local, value + "");
00039 };
00040 d3_style_prototype.setProperty = function(name, value, priority) {
00041 d3_style_setProperty.call(this, name, value + "", priority);
00042 };
00043 }
00044 }
00045 d3.ascending = d3_ascending;
00046 function d3_ascending(a, b) {
00047 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
00048 }
00049 d3.descending = function(a, b) {
00050 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
00051 };
00052 d3.min = function(array, f) {
00053 var i = -1, n = array.length, a, b;
00054 if (arguments.length === 1) {
00055 while (++i < n) if ((b = array[i]) != null && b >= b) {
00056 a = b;
00057 break;
00058 }
00059 while (++i < n) if ((b = array[i]) != null && a > b) a = b;
00060 } else {
00061 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
00062 a = b;
00063 break;
00064 }
00065 while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
00066 }
00067 return a;
00068 };
00069 d3.max = function(array, f) {
00070 var i = -1, n = array.length, a, b;
00071 if (arguments.length === 1) {
00072 while (++i < n) if ((b = array[i]) != null && b >= b) {
00073 a = b;
00074 break;
00075 }
00076 while (++i < n) if ((b = array[i]) != null && b > a) a = b;
00077 } else {
00078 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
00079 a = b;
00080 break;
00081 }
00082 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
00083 }
00084 return a;
00085 };
00086 d3.extent = function(array, f) {
00087 var i = -1, n = array.length, a, b, c;
00088 if (arguments.length === 1) {
00089 while (++i < n) if ((b = array[i]) != null && b >= b) {
00090 a = c = b;
00091 break;
00092 }
00093 while (++i < n) if ((b = array[i]) != null) {
00094 if (a > b) a = b;
00095 if (c < b) c = b;
00096 }
00097 } else {
00098 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
00099 a = c = b;
00100 break;
00101 }
00102 while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
00103 if (a > b) a = b;
00104 if (c < b) c = b;
00105 }
00106 }
00107 return [ a, c ];
00108 };
00109 function d3_number(x) {
00110 return x === null ? NaN : +x;
00111 }
00112 function d3_numeric(x) {
00113 return !isNaN(x);
00114 }
00115 d3.sum = function(array, f) {
00116 var s = 0, n = array.length, a, i = -1;
00117 if (arguments.length === 1) {
00118 while (++i < n) if (d3_numeric(a = +array[i])) s += a;
00119 } else {
00120 while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
00121 }
00122 return s;
00123 };
00124 d3.mean = function(array, f) {
00125 var s = 0, n = array.length, a, i = -1, j = n;
00126 if (arguments.length === 1) {
00127 while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
00128 } else {
00129 while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
00130 }
00131 if (j) return s / j;
00132 };
00133 d3.quantile = function(values, p) {
00134 var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
00135 return e ? v + e * (values[h] - v) : v;
00136 };
00137 d3.median = function(array, f) {
00138 var numbers = [], n = array.length, a, i = -1;
00139 if (arguments.length === 1) {
00140 while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
00141 } else {
00142 while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
00143 }
00144 if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
00145 };
00146 d3.variance = function(array, f) {
00147 var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
00148 if (arguments.length === 1) {
00149 while (++i < n) {
00150 if (d3_numeric(a = d3_number(array[i]))) {
00151 d = a - m;
00152 m += d / ++j;
00153 s += d * (a - m);
00154 }
00155 }
00156 } else {
00157 while (++i < n) {
00158 if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
00159 d = a - m;
00160 m += d / ++j;
00161 s += d * (a - m);
00162 }
00163 }
00164 }
00165 if (j > 1) return s / (j - 1);
00166 };
00167 d3.deviation = function() {
00168 var v = d3.variance.apply(this, arguments);
00169 return v ? Math.sqrt(v) : v;
00170 };
00171 function d3_bisector(compare) {
00172 return {
00173 left: function(a, x, lo, hi) {
00174 if (arguments.length < 3) lo = 0;
00175 if (arguments.length < 4) hi = a.length;
00176 while (lo < hi) {
00177 var mid = lo + hi >>> 1;
00178 if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
00179 }
00180 return lo;
00181 },
00182 right: function(a, x, lo, hi) {
00183 if (arguments.length < 3) lo = 0;
00184 if (arguments.length < 4) hi = a.length;
00185 while (lo < hi) {
00186 var mid = lo + hi >>> 1;
00187 if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
00188 }
00189 return lo;
00190 }
00191 };
00192 }
00193 var d3_bisect = d3_bisector(d3_ascending);
00194 d3.bisectLeft = d3_bisect.left;
00195 d3.bisect = d3.bisectRight = d3_bisect.right;
00196 d3.bisector = function(f) {
00197 return d3_bisector(f.length === 1 ? function(d, x) {
00198 return d3_ascending(f(d), x);
00199 } : f);
00200 };
00201 d3.shuffle = function(array, i0, i1) {
00202 if ((m = arguments.length) < 3) {
00203 i1 = array.length;
00204 if (m < 2) i0 = 0;
00205 }
00206 var m = i1 - i0, t, i;
00207 while (m) {
00208 i = Math.random() * m-- | 0;
00209 t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
00210 }
00211 return array;
00212 };
00213 d3.permute = function(array, indexes) {
00214 var i = indexes.length, permutes = new Array(i);
00215 while (i--) permutes[i] = array[indexes[i]];
00216 return permutes;
00217 };
00218 d3.pairs = function(array) {
00219 var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
00220 while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
00221 return pairs;
00222 };
00223 d3.zip = function() {
00224 if (!(n = arguments.length)) return [];
00225 for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
00226 for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
00227 zip[j] = arguments[j][i];
00228 }
00229 }
00230 return zips;
00231 };
00232 function d3_zipLength(d) {
00233 return d.length;
00234 }
00235 d3.transpose = function(matrix) {
00236 return d3.zip.apply(d3, matrix);
00237 };
00238 d3.keys = function(map) {
00239 var keys = [];
00240 for (var key in map) keys.push(key);
00241 return keys;
00242 };
00243 d3.values = function(map) {
00244 var values = [];
00245 for (var key in map) values.push(map[key]);
00246 return values;
00247 };
00248 d3.entries = function(map) {
00249 var entries = [];
00250 for (var key in map) entries.push({
00251 key: key,
00252 value: map[key]
00253 });
00254 return entries;
00255 };
00256 d3.merge = function(arrays) {
00257 var n = arrays.length, m, i = -1, j = 0, merged, array;
00258 while (++i < n) j += arrays[i].length;
00259 merged = new Array(j);
00260 while (--n >= 0) {
00261 array = arrays[n];
00262 m = array.length;
00263 while (--m >= 0) {
00264 merged[--j] = array[m];
00265 }
00266 }
00267 return merged;
00268 };
00269 var abs = Math.abs;
00270 d3.range = function(start, stop, step) {
00271 if (arguments.length < 3) {
00272 step = 1;
00273 if (arguments.length < 2) {
00274 stop = start;
00275 start = 0;
00276 }
00277 }
00278 if ((stop - start) / step === Infinity) throw new Error("infinite range");
00279 var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
00280 start *= k, stop *= k, step *= k;
00281 if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
00282 return range;
00283 };
00284 function d3_range_integerScale(x) {
00285 var k = 1;
00286 while (x * k % 1) k *= 10;
00287 return k;
00288 }
00289 function d3_class(ctor, properties) {
00290 for (var key in properties) {
00291 Object.defineProperty(ctor.prototype, key, {
00292 value: properties[key],
00293 enumerable: false
00294 });
00295 }
00296 }
00297 d3.map = function(object, f) {
00298 var map = new d3_Map();
00299 if (object instanceof d3_Map) {
00300 object.forEach(function(key, value) {
00301 map.set(key, value);
00302 });
00303 } else if (Array.isArray(object)) {
00304 var i = -1, n = object.length, o;
00305 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);
00306 } else {
00307 for (var key in object) map.set(key, object[key]);
00308 }
00309 return map;
00310 };
00311 function d3_Map() {
00312 this._ = Object.create(null);
00313 }
00314 var d3_map_proto = "__proto__", d3_map_zero = "\x00";
00315 d3_class(d3_Map, {
00316 has: d3_map_has,
00317 get: function(key) {
00318 return this._[d3_map_escape(key)];
00319 },
00320 set: function(key, value) {
00321 return this._[d3_map_escape(key)] = value;
00322 },
00323 remove: d3_map_remove,
00324 keys: d3_map_keys,
00325 values: function() {
00326 var values = [];
00327 for (var key in this._) values.push(this._[key]);
00328 return values;
00329 },
00330 entries: function() {
00331 var entries = [];
00332 for (var key in this._) entries.push({
00333 key: d3_map_unescape(key),
00334 value: this._[key]
00335 });
00336 return entries;
00337 },
00338 size: d3_map_size,
00339 empty: d3_map_empty,
00340 forEach: function(f) {
00341 for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
00342 }
00343 });
00344 function d3_map_escape(key) {
00345 return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
00346 }
00347 function d3_map_unescape(key) {
00348 return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
00349 }
00350 function d3_map_has(key) {
00351 return d3_map_escape(key) in this._;
00352 }
00353 function d3_map_remove(key) {
00354 return (key = d3_map_escape(key)) in this._ && delete this._[key];
00355 }
00356 function d3_map_keys() {
00357 var keys = [];
00358 for (var key in this._) keys.push(d3_map_unescape(key));
00359 return keys;
00360 }
00361 function d3_map_size() {
00362 var size = 0;
00363 for (var key in this._) ++size;
00364 return size;
00365 }
00366 function d3_map_empty() {
00367 for (var key in this._) return false;
00368 return true;
00369 }
00370 d3.nest = function() {
00371 var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
00372 function map(mapType, array, depth) {
00373 if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
00374 var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
00375 while (++i < n) {
00376 if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
00377 values.push(object);
00378 } else {
00379 valuesByKey.set(keyValue, [ object ]);
00380 }
00381 }
00382 if (mapType) {
00383 object = mapType();
00384 setter = function(keyValue, values) {
00385 object.set(keyValue, map(mapType, values, depth));
00386 };
00387 } else {
00388 object = {};
00389 setter = function(keyValue, values) {
00390 object[keyValue] = map(mapType, values, depth);
00391 };
00392 }
00393 valuesByKey.forEach(setter);
00394 return object;
00395 }
00396 function entries(map, depth) {
00397 if (depth >= keys.length) return map;
00398 var array = [], sortKey = sortKeys[depth++];
00399 map.forEach(function(key, keyMap) {
00400 array.push({
00401 key: key,
00402 values: entries(keyMap, depth)
00403 });
00404 });
00405 return sortKey ? array.sort(function(a, b) {
00406 return sortKey(a.key, b.key);
00407 }) : array;
00408 }
00409 nest.map = function(array, mapType) {
00410 return map(mapType, array, 0);
00411 };
00412 nest.entries = function(array) {
00413 return entries(map(d3.map, array, 0), 0);
00414 };
00415 nest.key = function(d) {
00416 keys.push(d);
00417 return nest;
00418 };
00419 nest.sortKeys = function(order) {
00420 sortKeys[keys.length - 1] = order;
00421 return nest;
00422 };
00423 nest.sortValues = function(order) {
00424 sortValues = order;
00425 return nest;
00426 };
00427 nest.rollup = function(f) {
00428 rollup = f;
00429 return nest;
00430 };
00431 return nest;
00432 };
00433 d3.set = function(array) {
00434 var set = new d3_Set();
00435 if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
00436 return set;
00437 };
00438 function d3_Set() {
00439 this._ = Object.create(null);
00440 }
00441 d3_class(d3_Set, {
00442 has: d3_map_has,
00443 add: function(key) {
00444 this._[d3_map_escape(key += "")] = true;
00445 return key;
00446 },
00447 remove: d3_map_remove,
00448 values: d3_map_keys,
00449 size: d3_map_size,
00450 empty: d3_map_empty,
00451 forEach: function(f) {
00452 for (var key in this._) f.call(this, d3_map_unescape(key));
00453 }
00454 });
00455 d3.behavior = {};
00456 function d3_identity(d) {
00457 return d;
00458 }
00459 d3.rebind = function(target, source) {
00460 var i = 1, n = arguments.length, method;
00461 while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
00462 return target;
00463 };
00464 function d3_rebind(target, source, method) {
00465 return function() {
00466 var value = method.apply(source, arguments);
00467 return value === source ? target : value;
00468 };
00469 }
00470 function d3_vendorSymbol(object, name) {
00471 if (name in object) return name;
00472 name = name.charAt(0).toUpperCase() + name.slice(1);
00473 for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
00474 var prefixName = d3_vendorPrefixes[i] + name;
00475 if (prefixName in object) return prefixName;
00476 }
00477 }
00478 var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
00479 function d3_noop() {}
00480 d3.dispatch = function() {
00481 var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
00482 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
00483 return dispatch;
00484 };
00485 function d3_dispatch() {}
00486 d3_dispatch.prototype.on = function(type, listener) {
00487 var i = type.indexOf("."), name = "";
00488 if (i >= 0) {
00489 name = type.slice(i + 1);
00490 type = type.slice(0, i);
00491 }
00492 if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
00493 if (arguments.length === 2) {
00494 if (listener == null) for (type in this) {
00495 if (this.hasOwnProperty(type)) this[type].on(name, null);
00496 }
00497 return this;
00498 }
00499 };
00500 function d3_dispatch_event(dispatch) {
00501 var listeners = [], listenerByName = new d3_Map();
00502 function event() {
00503 var z = listeners, i = -1, n = z.length, l;
00504 while (++i < n) if (l = z[i].on) l.apply(this, arguments);
00505 return dispatch;
00506 }
00507 event.on = function(name, listener) {
00508 var l = listenerByName.get(name), i;
00509 if (arguments.length < 2) return l && l.on;
00510 if (l) {
00511 l.on = null;
00512 listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
00513 listenerByName.remove(name);
00514 }
00515 if (listener) listeners.push(listenerByName.set(name, {
00516 on: listener
00517 }));
00518 return dispatch;
00519 };
00520 return event;
00521 }
00522 d3.event = null;
00523 function d3_eventPreventDefault() {
00524 d3.event.preventDefault();
00525 }
00526 function d3_eventSource() {
00527 var e = d3.event, s;
00528 while (s = e.sourceEvent) e = s;
00529 return e;
00530 }
00531 function d3_eventDispatch(target) {
00532 var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
00533 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
00534 dispatch.of = function(thiz, argumentz) {
00535 return function(e1) {
00536 try {
00537 var e0 = e1.sourceEvent = d3.event;
00538 e1.target = target;
00539 d3.event = e1;
00540 dispatch[e1.type].apply(thiz, argumentz);
00541 } finally {
00542 d3.event = e0;
00543 }
00544 };
00545 };
00546 return dispatch;
00547 }
00548 d3.requote = function(s) {
00549 return s.replace(d3_requote_re, "\\$&");
00550 };
00551 var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
00552 var d3_subclass = {}.__proto__ ? function(object, prototype) {
00553 object.__proto__ = prototype;
00554 } : function(object, prototype) {
00555 for (var property in prototype) object[property] = prototype[property];
00556 };
00557 function d3_selection(groups) {
00558 d3_subclass(groups, d3_selectionPrototype);
00559 return groups;
00560 }
00561 var d3_select = function(s, n) {
00562 return n.querySelector(s);
00563 }, d3_selectAll = function(s, n) {
00564 return n.querySelectorAll(s);
00565 }, d3_selectMatches = function(n, s) {
00566 var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")];
00567 d3_selectMatches = function(n, s) {
00568 return d3_selectMatcher.call(n, s);
00569 };
00570 return d3_selectMatches(n, s);
00571 };
00572 if (typeof Sizzle === "function") {
00573 d3_select = function(s, n) {
00574 return Sizzle(s, n)[0] || null;
00575 };
00576 d3_selectAll = Sizzle;
00577 d3_selectMatches = Sizzle.matchesSelector;
00578 }
00579 d3.selection = function() {
00580 return d3.select(d3_document.documentElement);
00581 };
00582 var d3_selectionPrototype = d3.selection.prototype = [];
00583 d3_selectionPrototype.select = function(selector) {
00584 var subgroups = [], subgroup, subnode, group, node;
00585 selector = d3_selection_selector(selector);
00586 for (var j = -1, m = this.length; ++j < m; ) {
00587 subgroups.push(subgroup = []);
00588 subgroup.parentNode = (group = this[j]).parentNode;
00589 for (var i = -1, n = group.length; ++i < n; ) {
00590 if (node = group[i]) {
00591 subgroup.push(subnode = selector.call(node, node.__data__, i, j));
00592 if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
00593 } else {
00594 subgroup.push(null);
00595 }
00596 }
00597 }
00598 return d3_selection(subgroups);
00599 };
00600 function d3_selection_selector(selector) {
00601 return typeof selector === "function" ? selector : function() {
00602 return d3_select(selector, this);
00603 };
00604 }
00605 d3_selectionPrototype.selectAll = function(selector) {
00606 var subgroups = [], subgroup, node;
00607 selector = d3_selection_selectorAll(selector);
00608 for (var j = -1, m = this.length; ++j < m; ) {
00609 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
00610 if (node = group[i]) {
00611 subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
00612 subgroup.parentNode = node;
00613 }
00614 }
00615 }
00616 return d3_selection(subgroups);
00617 };
00618 function d3_selection_selectorAll(selector) {
00619 return typeof selector === "function" ? selector : function() {
00620 return d3_selectAll(selector, this);
00621 };
00622 }
00623 var d3_nsPrefix = {
00624 svg: "http://www.w3.org/2000/svg",
00625 xhtml: "http://www.w3.org/1999/xhtml",
00626 xlink: "http://www.w3.org/1999/xlink",
00627 xml: "http://www.w3.org/XML/1998/namespace",
00628 xmlns: "http://www.w3.org/2000/xmlns/"
00629 };
00630 d3.ns = {
00631 prefix: d3_nsPrefix,
00632 qualify: function(name) {
00633 var i = name.indexOf(":"), prefix = name;
00634 if (i >= 0) {
00635 prefix = name.slice(0, i);
00636 name = name.slice(i + 1);
00637 }
00638 return d3_nsPrefix.hasOwnProperty(prefix) ? {
00639 space: d3_nsPrefix[prefix],
00640 local: name
00641 } : name;
00642 }
00643 };
00644 d3_selectionPrototype.attr = function(name, value) {
00645 if (arguments.length < 2) {
00646 if (typeof name === "string") {
00647 var node = this.node();
00648 name = d3.ns.qualify(name);
00649 return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
00650 }
00651 for (value in name) this.each(d3_selection_attr(value, name[value]));
00652 return this;
00653 }
00654 return this.each(d3_selection_attr(name, value));
00655 };
00656 function d3_selection_attr(name, value) {
00657 name = d3.ns.qualify(name);
00658 function attrNull() {
00659 this.removeAttribute(name);
00660 }
00661 function attrNullNS() {
00662 this.removeAttributeNS(name.space, name.local);
00663 }
00664 function attrConstant() {
00665 this.setAttribute(name, value);
00666 }
00667 function attrConstantNS() {
00668 this.setAttributeNS(name.space, name.local, value);
00669 }
00670 function attrFunction() {
00671 var x = value.apply(this, arguments);
00672 if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
00673 }
00674 function attrFunctionNS() {
00675 var x = value.apply(this, arguments);
00676 if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
00677 }
00678 return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
00679 }
00680 function d3_collapse(s) {
00681 return s.trim().replace(/\s+/g, " ");
00682 }
00683 d3_selectionPrototype.classed = function(name, value) {
00684 if (arguments.length < 2) {
00685 if (typeof name === "string") {
00686 var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
00687 if (value = node.classList) {
00688 while (++i < n) if (!value.contains(name[i])) return false;
00689 } else {
00690 value = node.getAttribute("class");
00691 while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
00692 }
00693 return true;
00694 }
00695 for (value in name) this.each(d3_selection_classed(value, name[value]));
00696 return this;
00697 }
00698 return this.each(d3_selection_classed(name, value));
00699 };
00700 function d3_selection_classedRe(name) {
00701 return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
00702 }
00703 function d3_selection_classes(name) {
00704 return (name + "").trim().split(/^|\s+/);
00705 }
00706 function d3_selection_classed(name, value) {
00707 name = d3_selection_classes(name).map(d3_selection_classedName);
00708 var n = name.length;
00709 function classedConstant() {
00710 var i = -1;
00711 while (++i < n) name[i](this, value);
00712 }
00713 function classedFunction() {
00714 var i = -1, x = value.apply(this, arguments);
00715 while (++i < n) name[i](this, x);
00716 }
00717 return typeof value === "function" ? classedFunction : classedConstant;
00718 }
00719 function d3_selection_classedName(name) {
00720 var re = d3_selection_classedRe(name);
00721 return function(node, value) {
00722 if (c = node.classList) return value ? c.add(name) : c.remove(name);
00723 var c = node.getAttribute("class") || "";
00724 if (value) {
00725 re.lastIndex = 0;
00726 if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
00727 } else {
00728 node.setAttribute("class", d3_collapse(c.replace(re, " ")));
00729 }
00730 };
00731 }
00732 d3_selectionPrototype.style = function(name, value, priority) {
00733 var n = arguments.length;
00734 if (n < 3) {
00735 if (typeof name !== "string") {
00736 if (n < 2) value = "";
00737 for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
00738 return this;
00739 }
00740 if (n < 2) {
00741 var node = this.node();
00742 return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
00743 }
00744 priority = "";
00745 }
00746 return this.each(d3_selection_style(name, value, priority));
00747 };
00748 function d3_selection_style(name, value, priority) {
00749 function styleNull() {
00750 this.style.removeProperty(name);
00751 }
00752 function styleConstant() {
00753 this.style.setProperty(name, value, priority);
00754 }
00755 function styleFunction() {
00756 var x = value.apply(this, arguments);
00757 if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
00758 }
00759 return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
00760 }
00761 d3_selectionPrototype.property = function(name, value) {
00762 if (arguments.length < 2) {
00763 if (typeof name === "string") return this.node()[name];
00764 for (value in name) this.each(d3_selection_property(value, name[value]));
00765 return this;
00766 }
00767 return this.each(d3_selection_property(name, value));
00768 };
00769 function d3_selection_property(name, value) {
00770 function propertyNull() {
00771 delete this[name];
00772 }
00773 function propertyConstant() {
00774 this[name] = value;
00775 }
00776 function propertyFunction() {
00777 var x = value.apply(this, arguments);
00778 if (x == null) delete this[name]; else this[name] = x;
00779 }
00780 return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
00781 }
00782 d3_selectionPrototype.text = function(value) {
00783 return arguments.length ? this.each(typeof value === "function" ? function() {
00784 var v = value.apply(this, arguments);
00785 this.textContent = v == null ? "" : v;
00786 } : value == null ? function() {
00787 this.textContent = "";
00788 } : function() {
00789 this.textContent = value;
00790 }) : this.node().textContent;
00791 };
00792 d3_selectionPrototype.html = function(value) {
00793 return arguments.length ? this.each(typeof value === "function" ? function() {
00794 var v = value.apply(this, arguments);
00795 this.innerHTML = v == null ? "" : v;
00796 } : value == null ? function() {
00797 this.innerHTML = "";
00798 } : function() {
00799 this.innerHTML = value;
00800 }) : this.node().innerHTML;
00801 };
00802 d3_selectionPrototype.append = function(name) {
00803 name = d3_selection_creator(name);
00804 return this.select(function() {
00805 return this.appendChild(name.apply(this, arguments));
00806 });
00807 };
00808 function d3_selection_creator(name) {
00809 function create() {
00810 var document = this.ownerDocument, namespace = this.namespaceURI;
00811 return namespace ? document.createElementNS(namespace, name) : document.createElement(name);
00812 }
00813 function createNS() {
00814 return this.ownerDocument.createElementNS(name.space, name.local);
00815 }
00816 return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
00817 }
00818 d3_selectionPrototype.insert = function(name, before) {
00819 name = d3_selection_creator(name);
00820 before = d3_selection_selector(before);
00821 return this.select(function() {
00822 return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
00823 });
00824 };
00825 d3_selectionPrototype.remove = function() {
00826 return this.each(d3_selectionRemove);
00827 };
00828 function d3_selectionRemove() {
00829 var parent = this.parentNode;
00830 if (parent) parent.removeChild(this);
00831 }
00832 d3_selectionPrototype.data = function(value, key) {
00833 var i = -1, n = this.length, group, node;
00834 if (!arguments.length) {
00835 value = new Array(n = (group = this[0]).length);
00836 while (++i < n) {
00837 if (node = group[i]) {
00838 value[i] = node.__data__;
00839 }
00840 }
00841 return value;
00842 }
00843 function bind(group, groupData) {
00844 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;
00845 if (key) {
00846 var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
00847 for (i = -1; ++i < n; ) {
00848 if (nodeByKeyValue.has(keyValue = key.call(node = group[i], node.__data__, i))) {
00849 exitNodes[i] = node;
00850 } else {
00851 nodeByKeyValue.set(keyValue, node);
00852 }
00853 keyValues[i] = keyValue;
00854 }
00855 for (i = -1; ++i < m; ) {
00856 if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
00857 enterNodes[i] = d3_selection_dataNode(nodeData);
00858 } else if (node !== true) {
00859 updateNodes[i] = node;
00860 node.__data__ = nodeData;
00861 }
00862 nodeByKeyValue.set(keyValue, true);
00863 }
00864 for (i = -1; ++i < n; ) {
00865 if (nodeByKeyValue.get(keyValues[i]) !== true) {
00866 exitNodes[i] = group[i];
00867 }
00868 }
00869 } else {
00870 for (i = -1; ++i < n0; ) {
00871 node = group[i];
00872 nodeData = groupData[i];
00873 if (node) {
00874 node.__data__ = nodeData;
00875 updateNodes[i] = node;
00876 } else {
00877 enterNodes[i] = d3_selection_dataNode(nodeData);
00878 }
00879 }
00880 for (;i < m; ++i) {
00881 enterNodes[i] = d3_selection_dataNode(groupData[i]);
00882 }
00883 for (;i < n; ++i) {
00884 exitNodes[i] = group[i];
00885 }
00886 }
00887 enterNodes.update = updateNodes;
00888 enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
00889 enter.push(enterNodes);
00890 update.push(updateNodes);
00891 exit.push(exitNodes);
00892 }
00893 var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
00894 if (typeof value === "function") {
00895 while (++i < n) {
00896 bind(group = this[i], value.call(group, group.parentNode.__data__, i));
00897 }
00898 } else {
00899 while (++i < n) {
00900 bind(group = this[i], value);
00901 }
00902 }
00903 update.enter = function() {
00904 return enter;
00905 };
00906 update.exit = function() {
00907 return exit;
00908 };
00909 return update;
00910 };
00911 function d3_selection_dataNode(data) {
00912 return {
00913 __data__: data
00914 };
00915 }
00916 d3_selectionPrototype.datum = function(value) {
00917 return arguments.length ? this.property("__data__", value) : this.property("__data__");
00918 };
00919 d3_selectionPrototype.filter = function(filter) {
00920 var subgroups = [], subgroup, group, node;
00921 if (typeof filter !== "function") filter = d3_selection_filter(filter);
00922 for (var j = 0, m = this.length; j < m; j++) {
00923 subgroups.push(subgroup = []);
00924 subgroup.parentNode = (group = this[j]).parentNode;
00925 for (var i = 0, n = group.length; i < n; i++) {
00926 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
00927 subgroup.push(node);
00928 }
00929 }
00930 }
00931 return d3_selection(subgroups);
00932 };
00933 function d3_selection_filter(selector) {
00934 return function() {
00935 return d3_selectMatches(this, selector);
00936 };
00937 }
00938 d3_selectionPrototype.order = function() {
00939 for (var j = -1, m = this.length; ++j < m; ) {
00940 for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
00941 if (node = group[i]) {
00942 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
00943 next = node;
00944 }
00945 }
00946 }
00947 return this;
00948 };
00949 d3_selectionPrototype.sort = function(comparator) {
00950 comparator = d3_selection_sortComparator.apply(this, arguments);
00951 for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
00952 return this.order();
00953 };
00954 function d3_selection_sortComparator(comparator) {
00955 if (!arguments.length) comparator = d3_ascending;
00956 return function(a, b) {
00957 return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
00958 };
00959 }
00960 d3_selectionPrototype.each = function(callback) {
00961 return d3_selection_each(this, function(node, i, j) {
00962 callback.call(node, node.__data__, i, j);
00963 });
00964 };
00965 function d3_selection_each(groups, callback) {
00966 for (var j = 0, m = groups.length; j < m; j++) {
00967 for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
00968 if (node = group[i]) callback(node, i, j);
00969 }
00970 }
00971 return groups;
00972 }
00973 d3_selectionPrototype.call = function(callback) {
00974 var args = d3_array(arguments);
00975 callback.apply(args[0] = this, args);
00976 return this;
00977 };
00978 d3_selectionPrototype.empty = function() {
00979 return !this.node();
00980 };
00981 d3_selectionPrototype.node = function() {
00982 for (var j = 0, m = this.length; j < m; j++) {
00983 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
00984 var node = group[i];
00985 if (node) return node;
00986 }
00987 }
00988 return null;
00989 };
00990 d3_selectionPrototype.size = function() {
00991 var n = 0;
00992 d3_selection_each(this, function() {
00993 ++n;
00994 });
00995 return n;
00996 };
00997 function d3_selection_enter(selection) {
00998 d3_subclass(selection, d3_selection_enterPrototype);
00999 return selection;
01000 }
01001 var d3_selection_enterPrototype = [];
01002 d3.selection.enter = d3_selection_enter;
01003 d3.selection.enter.prototype = d3_selection_enterPrototype;
01004 d3_selection_enterPrototype.append = d3_selectionPrototype.append;
01005 d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
01006 d3_selection_enterPrototype.node = d3_selectionPrototype.node;
01007 d3_selection_enterPrototype.call = d3_selectionPrototype.call;
01008 d3_selection_enterPrototype.size = d3_selectionPrototype.size;
01009 d3_selection_enterPrototype.select = function(selector) {
01010 var subgroups = [], subgroup, subnode, upgroup, group, node;
01011 for (var j = -1, m = this.length; ++j < m; ) {
01012 upgroup = (group = this[j]).update;
01013 subgroups.push(subgroup = []);
01014 subgroup.parentNode = group.parentNode;
01015 for (var i = -1, n = group.length; ++i < n; ) {
01016 if (node = group[i]) {
01017 subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
01018 subnode.__data__ = node.__data__;
01019 } else {
01020 subgroup.push(null);
01021 }
01022 }
01023 }
01024 return d3_selection(subgroups);
01025 };
01026 d3_selection_enterPrototype.insert = function(name, before) {
01027 if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
01028 return d3_selectionPrototype.insert.call(this, name, before);
01029 };
01030 function d3_selection_enterInsertBefore(enter) {
01031 var i0, j0;
01032 return function(d, i, j) {
01033 var group = enter[j].update, n = group.length, node;
01034 if (j != j0) j0 = j, i0 = 0;
01035 if (i >= i0) i0 = i + 1;
01036 while (!(node = group[i0]) && ++i0 < n) ;
01037 return node;
01038 };
01039 }
01040 d3.select = function(node) {
01041 var group;
01042 if (typeof node === "string") {
01043 group = [ d3_select(node, d3_document) ];
01044 group.parentNode = d3_document.documentElement;
01045 } else {
01046 group = [ node ];
01047 group.parentNode = d3_documentElement(node);
01048 }
01049 return d3_selection([ group ]);
01050 };
01051 d3.selectAll = function(nodes) {
01052 var group;
01053 if (typeof nodes === "string") {
01054 group = d3_array(d3_selectAll(nodes, d3_document));
01055 group.parentNode = d3_document.documentElement;
01056 } else {
01057 group = nodes;
01058 group.parentNode = null;
01059 }
01060 return d3_selection([ group ]);
01061 };
01062 d3_selectionPrototype.on = function(type, listener, capture) {
01063 var n = arguments.length;
01064 if (n < 3) {
01065 if (typeof type !== "string") {
01066 if (n < 2) listener = false;
01067 for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
01068 return this;
01069 }
01070 if (n < 2) return (n = this.node()["__on" + type]) && n._;
01071 capture = false;
01072 }
01073 return this.each(d3_selection_on(type, listener, capture));
01074 };
01075 function d3_selection_on(type, listener, capture) {
01076 var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
01077 if (i > 0) type = type.slice(0, i);
01078 var filter = d3_selection_onFilters.get(type);
01079 if (filter) type = filter, wrap = d3_selection_onFilter;
01080 function onRemove() {
01081 var l = this[name];
01082 if (l) {
01083 this.removeEventListener(type, l, l.$);
01084 delete this[name];
01085 }
01086 }
01087 function onAdd() {
01088 var l = wrap(listener, d3_array(arguments));
01089 onRemove.call(this);
01090 this.addEventListener(type, this[name] = l, l.$ = capture);
01091 l._ = listener;
01092 }
01093 function removeAll() {
01094 var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
01095 for (var name in this) {
01096 if (match = name.match(re)) {
01097 var l = this[name];
01098 this.removeEventListener(match[1], l, l.$);
01099 delete this[name];
01100 }
01101 }
01102 }
01103 return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
01104 }
01105 var d3_selection_onFilters = d3.map({
01106 mouseenter: "mouseover",
01107 mouseleave: "mouseout"
01108 });
01109 if (d3_document) {
01110 d3_selection_onFilters.forEach(function(k) {
01111 if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
01112 });
01113 }
01114 function d3_selection_onListener(listener, argumentz) {
01115 return function(e) {
01116 var o = d3.event;
01117 d3.event = e;
01118 argumentz[0] = this.__data__;
01119 try {
01120 listener.apply(this, argumentz);
01121 } finally {
01122 d3.event = o;
01123 }
01124 };
01125 }
01126 function d3_selection_onFilter(listener, argumentz) {
01127 var l = d3_selection_onListener(listener, argumentz);
01128 return function(e) {
01129 var target = this, related = e.relatedTarget;
01130 if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
01131 l.call(target, e);
01132 }
01133 };
01134 }
01135 var d3_event_dragSelect, d3_event_dragId = 0;
01136 function d3_event_dragSuppress(node) {
01137 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);
01138 if (d3_event_dragSelect == null) {
01139 d3_event_dragSelect = "onselectstart" in node ? false : d3_vendorSymbol(node.style, "userSelect");
01140 }
01141 if (d3_event_dragSelect) {
01142 var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
01143 style[d3_event_dragSelect] = "none";
01144 }
01145 return function(suppressClick) {
01146 w.on(name, null);
01147 if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
01148 if (suppressClick) {
01149 var off = function() {
01150 w.on(click, null);
01151 };
01152 w.on(click, function() {
01153 d3_eventPreventDefault();
01154 off();
01155 }, true);
01156 setTimeout(off, 0);
01157 }
01158 };
01159 }
01160 d3.mouse = function(container) {
01161 return d3_mousePoint(container, d3_eventSource());
01162 };
01163 var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
01164 function d3_mousePoint(container, e) {
01165 if (e.changedTouches) e = e.changedTouches[0];
01166 var svg = container.ownerSVGElement || container;
01167 if (svg.createSVGPoint) {
01168 var point = svg.createSVGPoint();
01169 if (d3_mouse_bug44083 < 0) {
01170 var window = d3_window(container);
01171 if (window.scrollX || window.scrollY) {
01172 svg = d3.select("body").append("svg").style({
01173 position: "absolute",
01174 top: 0,
01175 left: 0,
01176 margin: 0,
01177 padding: 0,
01178 border: "none"
01179 }, "important");
01180 var ctm = svg[0][0].getScreenCTM();
01181 d3_mouse_bug44083 = !(ctm.f || ctm.e);
01182 svg.remove();
01183 }
01184 }
01185 if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
01186 point.y = e.clientY;
01187 point = point.matrixTransform(container.getScreenCTM().inverse());
01188 return [ point.x, point.y ];
01189 }
01190 var rect = container.getBoundingClientRect();
01191 return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
01192 }
01193 d3.touch = function(container, touches, identifier) {
01194 if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
01195 if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
01196 if ((touch = touches[i]).identifier === identifier) {
01197 return d3_mousePoint(container, touch);
01198 }
01199 }
01200 };
01201 d3.behavior.drag = function() {
01202 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");
01203 function drag() {
01204 this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
01205 }
01206 function dragstart(id, position, subject, move, end) {
01207 return function() {
01208 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);
01209 if (origin) {
01210 dragOffset = origin.apply(that, arguments);
01211 dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
01212 } else {
01213 dragOffset = [ 0, 0 ];
01214 }
01215 dispatch({
01216 type: "dragstart"
01217 });
01218 function moved() {
01219 var position1 = position(parent, dragId), dx, dy;
01220 if (!position1) return;
01221 dx = position1[0] - position0[0];
01222 dy = position1[1] - position0[1];
01223 dragged |= dx | dy;
01224 position0 = position1;
01225 dispatch({
01226 type: "drag",
01227 x: position1[0] + dragOffset[0],
01228 y: position1[1] + dragOffset[1],
01229 dx: dx,
01230 dy: dy
01231 });
01232 }
01233 function ended() {
01234 if (!position(parent, dragId)) return;
01235 dragSubject.on(move + dragName, null).on(end + dragName, null);
01236 dragRestore(dragged && d3.event.target === target);
01237 dispatch({
01238 type: "dragend"
01239 });
01240 }
01241 };
01242 }
01243 drag.origin = function(x) {
01244 if (!arguments.length) return origin;
01245 origin = x;
01246 return drag;
01247 };
01248 return d3.rebind(drag, event, "on");
01249 };
01250 function d3_behavior_dragTouchId() {
01251 return d3.event.changedTouches[0].identifier;
01252 }
01253 d3.touches = function(container, touches) {
01254 if (arguments.length < 2) touches = d3_eventSource().touches;
01255 return touches ? d3_array(touches).map(function(touch) {
01256 var point = d3_mousePoint(container, touch);
01257 point.identifier = touch.identifier;
01258 return point;
01259 }) : [];
01260 };
01261 var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
01262 function d3_sgn(x) {
01263 return x > 0 ? 1 : x < 0 ? -1 : 0;
01264 }
01265 function d3_cross2d(a, b, c) {
01266 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
01267 }
01268 function d3_acos(x) {
01269 return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
01270 }
01271 function d3_asin(x) {
01272 return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
01273 }
01274 function d3_sinh(x) {
01275 return ((x = Math.exp(x)) - 1 / x) / 2;
01276 }
01277 function d3_cosh(x) {
01278 return ((x = Math.exp(x)) + 1 / x) / 2;
01279 }
01280 function d3_tanh(x) {
01281 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
01282 }
01283 function d3_haversin(x) {
01284 return (x = Math.sin(x / 2)) * x;
01285 }
01286 var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
01287 d3.interpolateZoom = function(p0, p1) {
01288 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2];
01289 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)) / ρ;
01290 function interpolate(t) {
01291 var s = t * S;
01292 if (dr) {
01293 var coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
01294 return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
01295 }
01296 return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * s) ];
01297 }
01298 interpolate.duration = S * 1e3;
01299 return interpolate;
01300 };
01301 d3.behavior.zoom = function() {
01302 var view = {
01303 x: 0,
01304 y: 0,
01305 k: 1
01306 }, 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;
01307 if (!d3_behavior_zoomWheel) {
01308 d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
01309 return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
01310 }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
01311 return d3.event.wheelDelta;
01312 }, "mousewheel") : (d3_behavior_zoomDelta = function() {
01313 return -d3.event.detail;
01314 }, "MozMousePixelScroll");
01315 }
01316 function zoom(g) {
01317 g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
01318 }
01319 zoom.event = function(g) {
01320 g.each(function() {
01321 var dispatch = event.of(this, arguments), view1 = view;
01322 if (d3_transitionInheritId) {
01323 d3.select(this).transition().each("start.zoom", function() {
01324 view = this.__chart__ || {
01325 x: 0,
01326 y: 0,
01327 k: 1
01328 };
01329 zoomstarted(dispatch);
01330 }).tween("zoom:zoom", function() {
01331 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 ]);
01332 return function(t) {
01333 var l = i(t), k = dx / l[2];
01334 this.__chart__ = view = {
01335 x: cx - l[0] * k,
01336 y: cy - l[1] * k,
01337 k: k
01338 };
01339 zoomed(dispatch);
01340 };
01341 }).each("interrupt.zoom", function() {
01342 zoomended(dispatch);
01343 }).each("end.zoom", function() {
01344 zoomended(dispatch);
01345 });
01346 } else {
01347 this.__chart__ = view;
01348 zoomstarted(dispatch);
01349 zoomed(dispatch);
01350 zoomended(dispatch);
01351 }
01352 });
01353 };
01354 zoom.translate = function(_) {
01355 if (!arguments.length) return [ view.x, view.y ];
01356 view = {
01357 x: +_[0],
01358 y: +_[1],
01359 k: view.k
01360 };
01361 rescale();
01362 return zoom;
01363 };
01364 zoom.scale = function(_) {
01365 if (!arguments.length) return view.k;
01366 view = {
01367 x: view.x,
01368 y: view.y,
01369 k: +_
01370 };
01371 rescale();
01372 return zoom;
01373 };
01374 zoom.scaleExtent = function(_) {
01375 if (!arguments.length) return scaleExtent;
01376 scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
01377 return zoom;
01378 };
01379 zoom.center = function(_) {
01380 if (!arguments.length) return center;
01381 center = _ && [ +_[0], +_[1] ];
01382 return zoom;
01383 };
01384 zoom.size = function(_) {
01385 if (!arguments.length) return size;
01386 size = _ && [ +_[0], +_[1] ];
01387 return zoom;
01388 };
01389 zoom.duration = function(_) {
01390 if (!arguments.length) return duration;
01391 duration = +_;
01392 return zoom;
01393 };
01394 zoom.x = function(z) {
01395 if (!arguments.length) return x1;
01396 x1 = z;
01397 x0 = z.copy();
01398 view = {
01399 x: 0,
01400 y: 0,
01401 k: 1
01402 };
01403 return zoom;
01404 };
01405 zoom.y = function(z) {
01406 if (!arguments.length) return y1;
01407 y1 = z;
01408 y0 = z.copy();
01409 view = {
01410 x: 0,
01411 y: 0,
01412 k: 1
01413 };
01414 return zoom;
01415 };
01416 function location(p) {
01417 return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
01418 }
01419 function point(l) {
01420 return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
01421 }
01422 function scaleTo(s) {
01423 view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
01424 }
01425 function translateTo(p, l) {
01426 l = point(l);
01427 view.x += p[0] - l[0];
01428 view.y += p[1] - l[1];
01429 }
01430 function zoomTo(that, p, l, k) {
01431 that.__chart__ = {
01432 x: view.x,
01433 y: view.y,
01434 k: view.k
01435 };
01436 scaleTo(Math.pow(2, k));
01437 translateTo(center0 = p, l);
01438 that = d3.select(that);
01439 if (duration > 0) that = that.transition().duration(duration);
01440 that.call(zoom.event);
01441 }
01442 function rescale() {
01443 if (x1) x1.domain(x0.range().map(function(x) {
01444 return (x - view.x) / view.k;
01445 }).map(x0.invert));
01446 if (y1) y1.domain(y0.range().map(function(y) {
01447 return (y - view.y) / view.k;
01448 }).map(y0.invert));
01449 }
01450 function zoomstarted(dispatch) {
01451 if (!zooming++) dispatch({
01452 type: "zoomstart"
01453 });
01454 }
01455 function zoomed(dispatch) {
01456 rescale();
01457 dispatch({
01458 type: "zoom",
01459 scale: view.k,
01460 translate: [ view.x, view.y ]
01461 });
01462 }
01463 function zoomended(dispatch) {
01464 if (!--zooming) dispatch({
01465 type: "zoomend"
01466 });
01467 center0 = null;
01468 }
01469 function mousedowned() {
01470 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);
01471 d3_selection_interrupt.call(that);
01472 zoomstarted(dispatch);
01473 function moved() {
01474 dragged = 1;
01475 translateTo(d3.mouse(that), location0);
01476 zoomed(dispatch);
01477 }
01478 function ended() {
01479 subject.on(mousemove, null).on(mouseup, null);
01480 dragRestore(dragged && d3.event.target === target);
01481 zoomended(dispatch);
01482 }
01483 }
01484 function touchstarted() {
01485 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);
01486 started();
01487 zoomstarted(dispatch);
01488 subject.on(mousedown, null).on(touchstart, started);
01489 function relocate() {
01490 var touches = d3.touches(that);
01491 scale0 = view.k;
01492 touches.forEach(function(t) {
01493 if (t.identifier in locations0) locations0[t.identifier] = location(t);
01494 });
01495 return touches;
01496 }
01497 function started() {
01498 var target = d3.event.target;
01499 d3.select(target).on(touchmove, moved).on(touchend, ended);
01500 targets.push(target);
01501 var changed = d3.event.changedTouches;
01502 for (var i = 0, n = changed.length; i < n; ++i) {
01503 locations0[changed[i].identifier] = null;
01504 }
01505 var touches = relocate(), now = Date.now();
01506 if (touches.length === 1) {
01507 if (now - touchtime < 500) {
01508 var p = touches[0];
01509 zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
01510 d3_eventPreventDefault();
01511 }
01512 touchtime = now;
01513 } else if (touches.length > 1) {
01514 var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
01515 distance0 = dx * dx + dy * dy;
01516 }
01517 }
01518 function moved() {
01519 var touches = d3.touches(that), p0, l0, p1, l1;
01520 d3_selection_interrupt.call(that);
01521 for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
01522 p1 = touches[i];
01523 if (l1 = locations0[p1.identifier]) {
01524 if (l0) break;
01525 p0 = p1, l0 = l1;
01526 }
01527 }
01528 if (l1) {
01529 var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
01530 p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
01531 l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
01532 scaleTo(scale1 * scale0);
01533 }
01534 touchtime = null;
01535 translateTo(p0, l0);
01536 zoomed(dispatch);
01537 }
01538 function ended() {
01539 if (d3.event.touches.length) {
01540 var changed = d3.event.changedTouches;
01541 for (var i = 0, n = changed.length; i < n; ++i) {
01542 delete locations0[changed[i].identifier];
01543 }
01544 for (var identifier in locations0) {
01545 return void relocate();
01546 }
01547 }
01548 d3.selectAll(targets).on(zoomName, null);
01549 subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
01550 dragRestore();
01551 zoomended(dispatch);
01552 }
01553 }
01554 function mousewheeled() {
01555 var dispatch = event.of(this, arguments);
01556 if (mousewheelTimer) clearTimeout(mousewheelTimer); else translate0 = location(center0 = center || d3.mouse(this)),
01557 d3_selection_interrupt.call(this), zoomstarted(dispatch);
01558 mousewheelTimer = setTimeout(function() {
01559 mousewheelTimer = null;
01560 zoomended(dispatch);
01561 }, 50);
01562 d3_eventPreventDefault();
01563 scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
01564 translateTo(center0, translate0);
01565 zoomed(dispatch);
01566 }
01567 function dblclicked() {
01568 var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
01569 zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
01570 }
01571 return d3.rebind(zoom, event, "on");
01572 };
01573 var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
01574 d3.color = d3_color;
01575 function d3_color() {}
01576 d3_color.prototype.toString = function() {
01577 return this.rgb() + "";
01578 };
01579 d3.hsl = d3_hsl;
01580 function d3_hsl(h, s, l) {
01581 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);
01582 }
01583 var d3_hslPrototype = d3_hsl.prototype = new d3_color();
01584 d3_hslPrototype.brighter = function(k) {
01585 k = Math.pow(.7, arguments.length ? k : 1);
01586 return new d3_hsl(this.h, this.s, this.l / k);
01587 };
01588 d3_hslPrototype.darker = function(k) {
01589 k = Math.pow(.7, arguments.length ? k : 1);
01590 return new d3_hsl(this.h, this.s, k * this.l);
01591 };
01592 d3_hslPrototype.rgb = function() {
01593 return d3_hsl_rgb(this.h, this.s, this.l);
01594 };
01595 function d3_hsl_rgb(h, s, l) {
01596 var m1, m2;
01597 h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
01598 s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
01599 l = l < 0 ? 0 : l > 1 ? 1 : l;
01600 m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
01601 m1 = 2 * l - m2;
01602 function v(h) {
01603 if (h > 360) h -= 360; else if (h < 0) h += 360;
01604 if (h < 60) return m1 + (m2 - m1) * h / 60;
01605 if (h < 180) return m2;
01606 if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
01607 return m1;
01608 }
01609 function vv(h) {
01610 return Math.round(v(h) * 255);
01611 }
01612 return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
01613 }
01614 d3.hcl = d3_hcl;
01615 function d3_hcl(h, c, l) {
01616 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);
01617 }
01618 var d3_hclPrototype = d3_hcl.prototype = new d3_color();
01619 d3_hclPrototype.brighter = function(k) {
01620 return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
01621 };
01622 d3_hclPrototype.darker = function(k) {
01623 return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
01624 };
01625 d3_hclPrototype.rgb = function() {
01626 return d3_hcl_lab(this.h, this.c, this.l).rgb();
01627 };
01628 function d3_hcl_lab(h, c, l) {
01629 if (isNaN(h)) h = 0;
01630 if (isNaN(c)) c = 0;
01631 return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
01632 }
01633 d3.lab = d3_lab;
01634 function d3_lab(l, a, b) {
01635 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);
01636 }
01637 var d3_lab_K = 18;
01638 var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
01639 var d3_labPrototype = d3_lab.prototype = new d3_color();
01640 d3_labPrototype.brighter = function(k) {
01641 return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
01642 };
01643 d3_labPrototype.darker = function(k) {
01644 return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
01645 };
01646 d3_labPrototype.rgb = function() {
01647 return d3_lab_rgb(this.l, this.a, this.b);
01648 };
01649 function d3_lab_rgb(l, a, b) {
01650 var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
01651 x = d3_lab_xyz(x) * d3_lab_X;
01652 y = d3_lab_xyz(y) * d3_lab_Y;
01653 z = d3_lab_xyz(z) * d3_lab_Z;
01654 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));
01655 }
01656 function d3_lab_hcl(l, a, b) {
01657 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);
01658 }
01659 function d3_lab_xyz(x) {
01660 return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
01661 }
01662 function d3_xyz_lab(x) {
01663 return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
01664 }
01665 function d3_xyz_rgb(r) {
01666 return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
01667 }
01668 d3.rgb = d3_rgb;
01669 function d3_rgb(r, g, b) {
01670 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);
01671 }
01672 function d3_rgbNumber(value) {
01673 return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
01674 }
01675 function d3_rgbString(value) {
01676 return d3_rgbNumber(value) + "";
01677 }
01678 var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
01679 d3_rgbPrototype.brighter = function(k) {
01680 k = Math.pow(.7, arguments.length ? k : 1);
01681 var r = this.r, g = this.g, b = this.b, i = 30;
01682 if (!r && !g && !b) return new d3_rgb(i, i, i);
01683 if (r && r < i) r = i;
01684 if (g && g < i) g = i;
01685 if (b && b < i) b = i;
01686 return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
01687 };
01688 d3_rgbPrototype.darker = function(k) {
01689 k = Math.pow(.7, arguments.length ? k : 1);
01690 return new d3_rgb(k * this.r, k * this.g, k * this.b);
01691 };
01692 d3_rgbPrototype.hsl = function() {
01693 return d3_rgb_hsl(this.r, this.g, this.b);
01694 };
01695 d3_rgbPrototype.toString = function() {
01696 return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
01697 };
01698 function d3_rgb_hex(v) {
01699 return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
01700 }
01701 function d3_rgb_parse(format, rgb, hsl) {
01702 var r = 0, g = 0, b = 0, m1, m2, color;
01703 m1 = /([a-z]+)\((.*)\)/i.exec(format);
01704 if (m1) {
01705 m2 = m1[2].split(",");
01706 switch (m1[1]) {
01707 case "hsl":
01708 {
01709 return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
01710 }
01711
01712 case "rgb":
01713 {
01714 return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
01715 }
01716 }
01717 }
01718 if (color = d3_rgb_names.get(format.toLowerCase())) {
01719 return rgb(color.r, color.g, color.b);
01720 }
01721 if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
01722 if (format.length === 4) {
01723 r = (color & 3840) >> 4;
01724 r = r >> 4 | r;
01725 g = color & 240;
01726 g = g >> 4 | g;
01727 b = color & 15;
01728 b = b << 4 | b;
01729 } else if (format.length === 7) {
01730 r = (color & 16711680) >> 16;
01731 g = (color & 65280) >> 8;
01732 b = color & 255;
01733 }
01734 }
01735 return rgb(r, g, b);
01736 }
01737 function d3_rgb_hsl(r, g, b) {
01738 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;
01739 if (d) {
01740 s = l < .5 ? d / (max + min) : d / (2 - max - min);
01741 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;
01742 h *= 60;
01743 } else {
01744 h = NaN;
01745 s = l > 0 && l < 1 ? 0 : h;
01746 }
01747 return new d3_hsl(h, s, l);
01748 }
01749 function d3_rgb_lab(r, g, b) {
01750 r = d3_rgb_xyz(r);
01751 g = d3_rgb_xyz(g);
01752 b = d3_rgb_xyz(b);
01753 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);
01754 return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
01755 }
01756 function d3_rgb_xyz(r) {
01757 return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
01758 }
01759 function d3_rgb_parseNumber(c) {
01760 var f = parseFloat(c);
01761 return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
01762 }
01763 var d3_rgb_names = d3.map({
01764 aliceblue: 15792383,
01765 antiquewhite: 16444375,
01766 aqua: 65535,
01767 aquamarine: 8388564,
01768 azure: 15794175,
01769 beige: 16119260,
01770 bisque: 16770244,
01771 black: 0,
01772 blanchedalmond: 16772045,
01773 blue: 255,
01774 blueviolet: 9055202,
01775 brown: 10824234,
01776 burlywood: 14596231,
01777 cadetblue: 6266528,
01778 chartreuse: 8388352,
01779 chocolate: 13789470,
01780 coral: 16744272,
01781 cornflowerblue: 6591981,
01782 cornsilk: 16775388,
01783 crimson: 14423100,
01784 cyan: 65535,
01785 darkblue: 139,
01786 darkcyan: 35723,
01787 darkgoldenrod: 12092939,
01788 darkgray: 11119017,
01789 darkgreen: 25600,
01790 darkgrey: 11119017,
01791 darkkhaki: 12433259,
01792 darkmagenta: 9109643,
01793 darkolivegreen: 5597999,
01794 darkorange: 16747520,
01795 darkorchid: 10040012,
01796 darkred: 9109504,
01797 darksalmon: 15308410,
01798 darkseagreen: 9419919,
01799 darkslateblue: 4734347,
01800 darkslategray: 3100495,
01801 darkslategrey: 3100495,
01802 darkturquoise: 52945,
01803 darkviolet: 9699539,
01804 deeppink: 16716947,
01805 deepskyblue: 49151,
01806 dimgray: 6908265,
01807 dimgrey: 6908265,
01808 dodgerblue: 2003199,
01809 firebrick: 11674146,
01810 floralwhite: 16775920,
01811 forestgreen: 2263842,
01812 fuchsia: 16711935,
01813 gainsboro: 14474460,
01814 ghostwhite: 16316671,
01815 gold: 16766720,
01816 goldenrod: 14329120,
01817 gray: 8421504,
01818 green: 32768,
01819 greenyellow: 11403055,
01820 grey: 8421504,
01821 honeydew: 15794160,
01822 hotpink: 16738740,
01823 indianred: 13458524,
01824 indigo: 4915330,
01825 ivory: 16777200,
01826 khaki: 15787660,
01827 lavender: 15132410,
01828 lavenderblush: 16773365,
01829 lawngreen: 8190976,
01830 lemonchiffon: 16775885,
01831 lightblue: 11393254,
01832 lightcoral: 15761536,
01833 lightcyan: 14745599,
01834 lightgoldenrodyellow: 16448210,
01835 lightgray: 13882323,
01836 lightgreen: 9498256,
01837 lightgrey: 13882323,
01838 lightpink: 16758465,
01839 lightsalmon: 16752762,
01840 lightseagreen: 2142890,
01841 lightskyblue: 8900346,
01842 lightslategray: 7833753,
01843 lightslategrey: 7833753,
01844 lightsteelblue: 11584734,
01845 lightyellow: 16777184,
01846 lime: 65280,
01847 limegreen: 3329330,
01848 linen: 16445670,
01849 magenta: 16711935,
01850 maroon: 8388608,
01851 mediumaquamarine: 6737322,
01852 mediumblue: 205,
01853 mediumorchid: 12211667,
01854 mediumpurple: 9662683,
01855 mediumseagreen: 3978097,
01856 mediumslateblue: 8087790,
01857 mediumspringgreen: 64154,
01858 mediumturquoise: 4772300,
01859 mediumvioletred: 13047173,
01860 midnightblue: 1644912,
01861 mintcream: 16121850,
01862 mistyrose: 16770273,
01863 moccasin: 16770229,
01864 navajowhite: 16768685,
01865 navy: 128,
01866 oldlace: 16643558,
01867 olive: 8421376,
01868 olivedrab: 7048739,
01869 orange: 16753920,
01870 orangered: 16729344,
01871 orchid: 14315734,
01872 palegoldenrod: 15657130,
01873 palegreen: 10025880,
01874 paleturquoise: 11529966,
01875 palevioletred: 14381203,
01876 papayawhip: 16773077,
01877 peachpuff: 16767673,
01878 peru: 13468991,
01879 pink: 16761035,
01880 plum: 14524637,
01881 powderblue: 11591910,
01882 purple: 8388736,
01883 rebeccapurple: 6697881,
01884 red: 16711680,
01885 rosybrown: 12357519,
01886 royalblue: 4286945,
01887 saddlebrown: 9127187,
01888 salmon: 16416882,
01889 sandybrown: 16032864,
01890 seagreen: 3050327,
01891 seashell: 16774638,
01892 sienna: 10506797,
01893 silver: 12632256,
01894 skyblue: 8900331,
01895 slateblue: 6970061,
01896 slategray: 7372944,
01897 slategrey: 7372944,
01898 snow: 16775930,
01899 springgreen: 65407,
01900 steelblue: 4620980,
01901 tan: 13808780,
01902 teal: 32896,
01903 thistle: 14204888,
01904 tomato: 16737095,
01905 turquoise: 4251856,
01906 violet: 15631086,
01907 wheat: 16113331,
01908 white: 16777215,
01909 whitesmoke: 16119285,
01910 yellow: 16776960,
01911 yellowgreen: 10145074
01912 });
01913 d3_rgb_names.forEach(function(key, value) {
01914 d3_rgb_names.set(key, d3_rgbNumber(value));
01915 });
01916 function d3_functor(v) {
01917 return typeof v === "function" ? v : function() {
01918 return v;
01919 };
01920 }
01921 d3.functor = d3_functor;
01922 d3.xhr = d3_xhrType(d3_identity);
01923 function d3_xhrType(response) {
01924 return function(url, mimeType, callback) {
01925 if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
01926 mimeType = null;
01927 return d3_xhr(url, mimeType, response, callback);
01928 };
01929 }
01930 function d3_xhr(url, mimeType, response, callback) {
01931 var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
01932 if (this.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\
01933 "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
01934 request.readyState > 3 && respond();
01935 };
01936 function respond() {
01937 var status = request.status, result;
01938 if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
01939 try {
01940 result = response.call(xhr, request);
01941 } catch (e) {
01942 dispatch.error.call(xhr, e);
01943 return;
01944 }
01945 dispatch.load.call(xhr, result);
01946 } else {
01947 dispatch.error.call(xhr, request);
01948 }
01949 }
01950 request.onprogress = function(event) {
01951 var o = d3.event;
01952 d3.event = event;
01953 try {
01954 dispatch.progress.call(xhr, request);
01955 } finally {
01956 d3.event = o;
01957 }
01958 };
01959 xhr.header = function(name, value) {
01960 name = (name + "").toLowerCase();
01961 if (arguments.length < 2) return headers[name];
01962 if (value == null) delete headers[name]; else headers[name] = value + "";
01963 return xhr;
01964 };
01965 xhr.mimeType = function(value) {
01966 if (!arguments.length) return mimeType;
01967 mimeType = value == null ? null : value + "";
01968 return xhr;
01969 };
01970 xhr.responseType = function(value) {
01971 if (!arguments.length) return responseType;
01972 responseType = value;
01973 return xhr;
01974 };
01975 xhr.response = function(value) {
01976 response = value;
01977 return xhr;
01978 };
01979 [ "get", "post" ].forEach(function(method) {
01980 xhr[method] = function() {
01981 return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
01982 };
01983 });
01984 xhr.send = function(method, data, callback) {
01985 if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
01986 request.open(method, url, true);
01987 if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
01988 if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
01989 if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
01990 if (responseType != null) request.responseType = responseType;
01991 if (callback != null) xhr.on("error", callback).on("load", function(request) {
01992 callback(null, request);
01993 });
01994 dispatch.beforesend.call(xhr, request);
01995 request.send(data == null ? null : data);
01996 return xhr;
01997 };
01998 xhr.abort = function() {
01999 request.abort();
02000 return xhr;
02001 };
02002 d3.rebind(xhr, dispatch, "on");
02003 return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
02004 }
02005 function d3_xhr_fixCallback(callback) {
02006 return callback.length === 1 ? function(error, request) {
02007 callback(error == null ? request : null);
02008 } : callback;
02009 }
02010 function d3_xhrHasResponse(request) {
02011 var type = request.responseType;
02012 return type && type !== "text" ? request.response : request.responseText;
02013 }
02014 d3.dsv = function(delimiter, mimeType) {
02015 var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
02016 function dsv(url, row, callback) {
02017 if (arguments.length < 3) callback = row, row = null;
02018 var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
02019 xhr.row = function(_) {
02020 return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
02021 };
02022 return xhr;
02023 }
02024 function response(request) {
02025 return dsv.parse(request.responseText);
02026 }
02027 function typedResponse(f) {
02028 return function(request) {
02029 return dsv.parse(request.responseText, f);
02030 };
02031 }
02032 dsv.parse = function(text, f) {
02033 var o;
02034 return dsv.parseRows(text, function(row, i) {
02035 if (o) return o(row, i - 1);
02036 var a = new Function("d", "return {" + row.map(function(name, i) {
02037 return JSON.stringify(name) + ": d[" + i + "]";
02038 }).join(",") + "}");
02039 o = f ? function(row, i) {
02040 return f(a(row), i);
02041 } : a;
02042 });
02043 };
02044 dsv.parseRows = function(text, f) {
02045 var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
02046 function token() {
02047 if (I >= N) return EOF;
02048 if (eol) return eol = false, EOL;
02049 var j = I;
02050 if (text.charCodeAt(j) === 34) {
02051 var i = j;
02052 while (i++ < N) {
02053 if (text.charCodeAt(i) === 34) {
02054 if (text.charCodeAt(i + 1) !== 34) break;
02055 ++i;
02056 }
02057 }
02058 I = i + 2;
02059 var c = text.charCodeAt(i + 1);
02060 if (c === 13) {
02061 eol = true;
02062 if (text.charCodeAt(i + 2) === 10) ++I;
02063 } else if (c === 10) {
02064 eol = true;
02065 }
02066 return text.slice(j + 1, i).replace(/""/g, '"');
02067 }
02068 while (I < N) {
02069 var c = text.charCodeAt(I++), k = 1;
02070 if (c === 10) eol = true; else if (c === 13) {
02071 eol = true;
02072 if (text.charCodeAt(I) === 10) ++I, ++k;
02073 } else if (c !== delimiterCode) continue;
02074 return text.slice(j, I - k);
02075 }
02076 return text.slice(j);
02077 }
02078 while ((t = token()) !== EOF) {
02079 var a = [];
02080 while (t !== EOL && t !== EOF) {
02081 a.push(t);
02082 t = token();
02083 }
02084 if (f && (a = f(a, n++)) == null) continue;
02085 rows.push(a);
02086 }
02087 return rows;
02088 };
02089 dsv.format = function(rows) {
02090 if (Array.isArray(rows[0])) return dsv.formatRows(rows);
02091 var fieldSet = new d3_Set(), fields = [];
02092 rows.forEach(function(row) {
02093 for (var field in row) {
02094 if (!fieldSet.has(field)) {
02095 fields.push(fieldSet.add(field));
02096 }
02097 }
02098 });
02099 return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
02100 return fields.map(function(field) {
02101 return formatValue(row[field]);
02102 }).join(delimiter);
02103 })).join("\n");
02104 };
02105 dsv.formatRows = function(rows) {
02106 return rows.map(formatRow).join("\n");
02107 };
02108 function formatRow(row) {
02109 return row.map(formatValue).join(delimiter);
02110 }
02111 function formatValue(text) {
02112 return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
02113 }
02114 return dsv;
02115 };
02116 d3.csv = d3.dsv(",", "text/csv");
02117 d3.tsv = d3.dsv(" ", "text/tab-separated-values");
02118 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) {
02119 setTimeout(callback, 17);
02120 };
02121 d3.timer = function(callback, delay, then) {
02122 var n = arguments.length;
02123 if (n < 2) delay = 0;
02124 if (n < 3) then = Date.now();
02125 var time = then + delay, timer = {
02126 c: callback,
02127 t: time,
02128 f: false,
02129 n: null
02130 };
02131 if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
02132 d3_timer_queueTail = timer;
02133 if (!d3_timer_interval) {
02134 d3_timer_timeout = clearTimeout(d3_timer_timeout);
02135 d3_timer_interval = 1;
02136 d3_timer_frame(d3_timer_step);
02137 }
02138 };
02139 function d3_timer_step() {
02140 var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
02141 if (delay > 24) {
02142 if (isFinite(delay)) {
02143 clearTimeout(d3_timer_timeout);
02144 d3_timer_timeout = setTimeout(d3_timer_step, delay);
02145 }
02146 d3_timer_interval = 0;
02147 } else {
02148 d3_timer_interval = 1;
02149 d3_timer_frame(d3_timer_step);
02150 }
02151 }
02152 d3.timer.flush = function() {
02153 d3_timer_mark();
02154 d3_timer_sweep();
02155 };
02156 function d3_timer_mark() {
02157 var now = Date.now();
02158 d3_timer_active = d3_timer_queueHead;
02159 while (d3_timer_active) {
02160 if (now >= d3_timer_active.t) d3_timer_active.f = d3_timer_active.c(now - d3_timer_active.t);
02161 d3_timer_active = d3_timer_active.n;
02162 }
02163 return now;
02164 }
02165 function d3_timer_sweep() {
02166 var t0, t1 = d3_timer_queueHead, time = Infinity;
02167 while (t1) {
02168 if (t1.f) {
02169 t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
02170 } else {
02171 if (t1.t < time) time = t1.t;
02172 t1 = (t0 = t1).n;
02173 }
02174 }
02175 d3_timer_queueTail = t0;
02176 return time;
02177 }
02178 function d3_format_precision(x, p) {
02179 return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
02180 }
02181 d3.round = function(x, n) {
02182 return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
02183 };
02184 var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
02185 d3.formatPrefix = function(value, precision) {
02186 var i = 0;
02187 if (value) {
02188 if (value < 0) value *= -1;
02189 if (precision) value = d3.round(value, d3_format_precision(value, precision));
02190 i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
02191 i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
02192 }
02193 return d3_formatPrefixes[8 + i / 3];
02194 };
02195 function d3_formatPrefix(d, i) {
02196 var k = Math.pow(10, abs(8 - i) * 3);
02197 return {
02198 scale: i > 8 ? function(d) {
02199 return d / k;
02200 } : function(d) {
02201 return d * k;
02202 },
02203 symbol: d
02204 };
02205 }
02206 function d3_locale_numberFormat(locale) {
02207 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) {
02208 var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
02209 while (i > 0 && g > 0) {
02210 if (length + g + 1 > width) g = Math.max(1, width - length);
02211 t.push(value.substring(i -= g, i + g));
02212 if ((length += g + 1) > width) break;
02213 g = locale_grouping[j = (j + 1) % locale_grouping.length];
02214 }
02215 return t.reverse().join(locale_thousands);
02216 } : d3_identity;
02217 return function(specifier) {
02218 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;
02219 if (precision) precision = +precision.substring(1);
02220 if (zfill || fill === "0" && align === "=") {
02221 zfill = fill = "0";
02222 align = "=";
02223 }
02224 switch (type) {
02225 case "n":
02226 comma = true;
02227 type = "g";
02228 break;
02229
02230 case "%":
02231 scale = 100;
02232 suffix = "%";
02233 type = "f";
02234 break;
02235
02236 case "p":
02237 scale = 100;
02238 suffix = "%";
02239 type = "r";
02240 break;
02241
02242 case "b":
02243 case "o":
02244 case "x":
02245 case "X":
02246 if (symbol === "#") prefix = "0" + type.toLowerCase();
02247
02248 case "c":
02249 exponent = false;
02250
02251 case "d":
02252 integer = true;
02253 precision = 0;
02254 break;
02255
02256 case "s":
02257 scale = -1;
02258 type = "r";
02259 break;
02260 }
02261 if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
02262 if (type == "r" && !precision) type = "g";
02263 if (precision != null) {
02264 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));
02265 }
02266 type = d3_format_types.get(type) || d3_format_typeDefault;
02267 var zcomma = zfill && comma;
02268 return function(value) {
02269 var fullSuffix = suffix;
02270 if (integer && value % 1) return "";
02271 var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
02272 if (scale < 0) {
02273 var unit = d3.formatPrefix(value, precision);
02274 value = unit.scale(value);
02275 fullSuffix = unit.symbol + suffix;
02276 } else {
02277 value *= scale;
02278 }
02279 value = type(value, precision);
02280 var i = value.lastIndexOf("."), before, after;
02281 if (i < 0) {
02282 var j = exponent ? value.lastIndexOf("e") : -1;
02283 if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
02284 } else {
02285 before = value.substring(0, i);
02286 after = locale_decimal + value.substring(i + 1);
02287 }
02288 if (!zfill && comma) before = formatGroup(before, Infinity);
02289 var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
02290 if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
02291 negative += prefix;
02292 value = before + after;
02293 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;
02294 };
02295 };
02296 }
02297 var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
02298 var d3_format_types = d3.map({
02299 b: function(x) {
02300 return x.toString(2);
02301 },
02302 c: function(x) {
02303 return String.fromCharCode(x);
02304 },
02305 o: function(x) {
02306 return x.toString(8);
02307 },
02308 x: function(x) {
02309 return x.toString(16);
02310 },
02311 X: function(x) {
02312 return x.toString(16).toUpperCase();
02313 },
02314 g: function(x, p) {
02315 return x.toPrecision(p);
02316 },
02317 e: function(x, p) {
02318 return x.toExponential(p);
02319 },
02320 f: function(x, p) {
02321 return x.toFixed(p);
02322 },
02323 r: function(x, p) {
02324 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))));
02325 }
02326 });
02327 function d3_format_typeDefault(x) {
02328 return x + "";
02329 }
02330 var d3_time = d3.time = {}, d3_date = Date;
02331 function d3_date_utc() {
02332 this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
02333 }
02334 d3_date_utc.prototype = {
02335 getDate: function() {
02336 return this._.getUTCDate();
02337 },
02338 getDay: function() {
02339 return this._.getUTCDay();
02340 },
02341 getFullYear: function() {
02342 return this._.getUTCFullYear();
02343 },
02344 getHours: function() {
02345 return this._.getUTCHours();
02346 },
02347 getMilliseconds: function() {
02348 return this._.getUTCMilliseconds();
02349 },
02350 getMinutes: function() {
02351 return this._.getUTCMinutes();
02352 },
02353 getMonth: function() {
02354 return this._.getUTCMonth();
02355 },
02356 getSeconds: function() {
02357 return this._.getUTCSeconds();
02358 },
02359 getTime: function() {
02360 return this._.getTime();
02361 },
02362 getTimezoneOffset: function() {
02363 return 0;
02364 },
02365 valueOf: function() {
02366 return this._.valueOf();
02367 },
02368 setDate: function() {
02369 d3_time_prototype.setUTCDate.apply(this._, arguments);
02370 },
02371 setDay: function() {
02372 d3_time_prototype.setUTCDay.apply(this._, arguments);
02373 },
02374 setFullYear: function() {
02375 d3_time_prototype.setUTCFullYear.apply(this._, arguments);
02376 },
02377 setHours: function() {
02378 d3_time_prototype.setUTCHours.apply(this._, arguments);
02379 },
02380 setMilliseconds: function() {
02381 d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
02382 },
02383 setMinutes: function() {
02384 d3_time_prototype.setUTCMinutes.apply(this._, arguments);
02385 },
02386 setMonth: function() {
02387 d3_time_prototype.setUTCMonth.apply(this._, arguments);
02388 },
02389 setSeconds: function() {
02390 d3_time_prototype.setUTCSeconds.apply(this._, arguments);
02391 },
02392 setTime: function() {
02393 d3_time_prototype.setTime.apply(this._, arguments);
02394 }
02395 };
02396 var d3_time_prototype = Date.prototype;
02397 function d3_time_interval(local, step, number) {
02398 function round(date) {
02399 var d0 = local(date), d1 = offset(d0, 1);
02400 return date - d0 < d1 - date ? d0 : d1;
02401 }
02402 function ceil(date) {
02403 step(date = local(new d3_date(date - 1)), 1);
02404 return date;
02405 }
02406 function offset(date, k) {
02407 step(date = new d3_date(+date), k);
02408 return date;
02409 }
02410 function range(t0, t1, dt) {
02411 var time = ceil(t0), times = [];
02412 if (dt > 1) {
02413 while (time < t1) {
02414 if (!(number(time) % dt)) times.push(new Date(+time));
02415 step(time, 1);
02416 }
02417 } else {
02418 while (time < t1) times.push(new Date(+time)), step(time, 1);
02419 }
02420 return times;
02421 }
02422 function range_utc(t0, t1, dt) {
02423 try {
02424 d3_date = d3_date_utc;
02425 var utc = new d3_date_utc();
02426 utc._ = t0;
02427 return range(utc, t1, dt);
02428 } finally {
02429 d3_date = Date;
02430 }
02431 }
02432 local.floor = local;
02433 local.round = round;
02434 local.ceil = ceil;
02435 local.offset = offset;
02436 local.range = range;
02437 var utc = local.utc = d3_time_interval_utc(local);
02438 utc.floor = utc;
02439 utc.round = d3_time_interval_utc(round);
02440 utc.ceil = d3_time_interval_utc(ceil);
02441 utc.offset = d3_time_interval_utc(offset);
02442 utc.range = range_utc;
02443 return local;
02444 }
02445 function d3_time_interval_utc(method) {
02446 return function(date, k) {
02447 try {
02448 d3_date = d3_date_utc;
02449 var utc = new d3_date_utc();
02450 utc._ = date;
02451 return method(utc, k)._;
02452 } finally {
02453 d3_date = Date;
02454 }
02455 };
02456 }
02457 d3_time.year = d3_time_interval(function(date) {
02458 date = d3_time.day(date);
02459 date.setMonth(0, 1);
02460 return date;
02461 }, function(date, offset) {
02462 date.setFullYear(date.getFullYear() + offset);
02463 }, function(date) {
02464 return date.getFullYear();
02465 });
02466 d3_time.years = d3_time.year.range;
02467 d3_time.years.utc = d3_time.year.utc.range;
02468 d3_time.day = d3_time_interval(function(date) {
02469 var day = new d3_date(2e3, 0);
02470 day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
02471 return day;
02472 }, function(date, offset) {
02473 date.setDate(date.getDate() + offset);
02474 }, function(date) {
02475 return date.getDate() - 1;
02476 });
02477 d3_time.days = d3_time.day.range;
02478 d3_time.days.utc = d3_time.day.utc.range;
02479 d3_time.dayOfYear = function(date) {
02480 var year = d3_time.year(date);
02481 return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
02482 };
02483 [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
02484 i = 7 - i;
02485 var interval = d3_time[day] = d3_time_interval(function(date) {
02486 (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
02487 return date;
02488 }, function(date, offset) {
02489 date.setDate(date.getDate() + Math.floor(offset) * 7);
02490 }, function(date) {
02491 var day = d3_time.year(date).getDay();
02492 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
02493 });
02494 d3_time[day + "s"] = interval.range;
02495 d3_time[day + "s"].utc = interval.utc.range;
02496 d3_time[day + "OfYear"] = function(date) {
02497 var day = d3_time.year(date).getDay();
02498 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
02499 };
02500 });
02501 d3_time.week = d3_time.sunday;
02502 d3_time.weeks = d3_time.sunday.range;
02503 d3_time.weeks.utc = d3_time.sunday.utc.range;
02504 d3_time.weekOfYear = d3_time.sundayOfYear;
02505 function d3_locale_timeFormat(locale) {
02506 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;
02507 function d3_time_format(template) {
02508 var n = template.length;
02509 function format(date) {
02510 var string = [], i = -1, j = 0, c, p, f;
02511 while (++i < n) {
02512 if (template.charCodeAt(i) === 37) {
02513 string.push(template.slice(j, i));
02514 if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
02515 if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
02516 string.push(c);
02517 j = i + 1;
02518 }
02519 }
02520 string.push(template.slice(j, i));
02521 return string.join("");
02522 }
02523 format.parse = function(string) {
02524 var d = {
02525 y: 1900,
02526 m: 0,
02527 d: 1,
02528 H: 0,
02529 M: 0,
02530 S: 0,
02531 L: 0,
02532 Z: null
02533 }, i = d3_time_parse(d, template, string, 0);
02534 if (i != string.length) return null;
02535 if ("p" in d) d.H = d.H % 12 + d.p * 12;
02536 var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
02537 if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
02538 date.setFullYear(d.y, 0, 1);
02539 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);
02540 } else date.setFullYear(d.y, d.m, d.d);
02541 date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
02542 return localZ ? date._ : date;
02543 };
02544 format.toString = function() {
02545 return template;
02546 };
02547 return format;
02548 }
02549 function d3_time_parse(date, template, string, j) {
02550 var c, p, t, i = 0, n = template.length, m = string.length;
02551 while (i < n) {
02552 if (j >= m) return -1;
02553 c = template.charCodeAt(i++);
02554 if (c === 37) {
02555 t = template.charAt(i++);
02556 p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
02557 if (!p || (j = p(date, string, j)) < 0) return -1;
02558 } else if (c != string.charCodeAt(j++)) {
02559 return -1;
02560 }
02561 }
02562 return j;
02563 }
02564 d3_time_format.utc = function(template) {
02565 var local = d3_time_format(template);
02566 function format(date) {
02567 try {
02568 d3_date = d3_date_utc;
02569 var utc = new d3_date();
02570 utc._ = date;
02571 return local(utc);
02572 } finally {
02573 d3_date = Date;
02574 }
02575 }
02576 format.parse = function(string) {
02577 try {
02578 d3_date = d3_date_utc;
02579 var date = local.parse(string);
02580 return date && date._;
02581 } finally {
02582 d3_date = Date;
02583 }
02584 };
02585 format.toString = local.toString;
02586 return format;
02587 };
02588 d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
02589 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);
02590 locale_periods.forEach(function(p, i) {
02591 d3_time_periodLookup.set(p.toLowerCase(), i);
02592 });
02593 var d3_time_formats = {
02594 a: function(d) {
02595 return locale_shortDays[d.getDay()];
02596 },
02597 A: function(d) {
02598 return locale_days[d.getDay()];
02599 },
02600 b: function(d) {
02601 return locale_shortMonths[d.getMonth()];
02602 },
02603 B: function(d) {
02604 return locale_months[d.getMonth()];
02605 },
02606 c: d3_time_format(locale_dateTime),
02607 d: function(d, p) {
02608 return d3_time_formatPad(d.getDate(), p, 2);
02609 },
02610 e: function(d, p) {
02611 return d3_time_formatPad(d.getDate(), p, 2);
02612 },
02613 H: function(d, p) {
02614 return d3_time_formatPad(d.getHours(), p, 2);
02615 },
02616 I: function(d, p) {
02617 return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
02618 },
02619 j: function(d, p) {
02620 return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
02621 },
02622 L: function(d, p) {
02623 return d3_time_formatPad(d.getMilliseconds(), p, 3);
02624 },
02625 m: function(d, p) {
02626 return d3_time_formatPad(d.getMonth() + 1, p, 2);
02627 },
02628 M: function(d, p) {
02629 return d3_time_formatPad(d.getMinutes(), p, 2);
02630 },
02631 p: function(d) {
02632 return locale_periods[+(d.getHours() >= 12)];
02633 },
02634 S: function(d, p) {
02635 return d3_time_formatPad(d.getSeconds(), p, 2);
02636 },
02637 U: function(d, p) {
02638 return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
02639 },
02640 w: function(d) {
02641 return d.getDay();
02642 },
02643 W: function(d, p) {
02644 return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
02645 },
02646 x: d3_time_format(locale_date),
02647 X: d3_time_format(locale_time),
02648 y: function(d, p) {
02649 return d3_time_formatPad(d.getFullYear() % 100, p, 2);
02650 },
02651 Y: function(d, p) {
02652 return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
02653 },
02654 Z: d3_time_zone,
02655 "%": function() {
02656 return "%";
02657 }
02658 };
02659 var d3_time_parsers = {
02660 a: d3_time_parseWeekdayAbbrev,
02661 A: d3_time_parseWeekday,
02662 b: d3_time_parseMonthAbbrev,
02663 B: d3_time_parseMonth,
02664 c: d3_time_parseLocaleFull,
02665 d: d3_time_parseDay,
02666 e: d3_time_parseDay,
02667 H: d3_time_parseHour24,
02668 I: d3_time_parseHour24,
02669 j: d3_time_parseDayOfYear,
02670 L: d3_time_parseMilliseconds,
02671 m: d3_time_parseMonthNumber,
02672 M: d3_time_parseMinutes,
02673 p: d3_time_parseAmPm,
02674 S: d3_time_parseSeconds,
02675 U: d3_time_parseWeekNumberSunday,
02676 w: d3_time_parseWeekdayNumber,
02677 W: d3_time_parseWeekNumberMonday,
02678 x: d3_time_parseLocaleDate,
02679 X: d3_time_parseLocaleTime,
02680 y: d3_time_parseYear,
02681 Y: d3_time_parseFullYear,
02682 Z: d3_time_parseZone,
02683 "%": d3_time_parseLiteralPercent
02684 };
02685 function d3_time_parseWeekdayAbbrev(date, string, i) {
02686 d3_time_dayAbbrevRe.lastIndex = 0;
02687 var n = d3_time_dayAbbrevRe.exec(string.slice(i));
02688 return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
02689 }
02690 function d3_time_parseWeekday(date, string, i) {
02691 d3_time_dayRe.lastIndex = 0;
02692 var n = d3_time_dayRe.exec(string.slice(i));
02693 return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
02694 }
02695 function d3_time_parseMonthAbbrev(date, string, i) {
02696 d3_time_monthAbbrevRe.lastIndex = 0;
02697 var n = d3_time_monthAbbrevRe.exec(string.slice(i));
02698 return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
02699 }
02700 function d3_time_parseMonth(date, string, i) {
02701 d3_time_monthRe.lastIndex = 0;
02702 var n = d3_time_monthRe.exec(string.slice(i));
02703 return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
02704 }
02705 function d3_time_parseLocaleFull(date, string, i) {
02706 return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
02707 }
02708 function d3_time_parseLocaleDate(date, string, i) {
02709 return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
02710 }
02711 function d3_time_parseLocaleTime(date, string, i) {
02712 return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
02713 }
02714 function d3_time_parseAmPm(date, string, i) {
02715 var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
02716 return n == null ? -1 : (date.p = n, i);
02717 }
02718 return d3_time_format;
02719 }
02720 var d3_time_formatPads = {
02721 "-": "",
02722 _: " ",
02723 "0": "0"
02724 }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
02725 function d3_time_formatPad(value, fill, width) {
02726 var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
02727 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
02728 }
02729 function d3_time_formatRe(names) {
02730 return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
02731 }
02732 function d3_time_formatLookup(names) {
02733 var map = new d3_Map(), i = -1, n = names.length;
02734 while (++i < n) map.set(names[i].toLowerCase(), i);
02735 return map;
02736 }
02737 function d3_time_parseWeekdayNumber(date, string, i) {
02738 d3_time_numberRe.lastIndex = 0;
02739 var n = d3_time_numberRe.exec(string.slice(i, i + 1));
02740 return n ? (date.w = +n[0], i + n[0].length) : -1;
02741 }
02742 function d3_time_parseWeekNumberSunday(date, string, i) {
02743 d3_time_numberRe.lastIndex = 0;
02744 var n = d3_time_numberRe.exec(string.slice(i));
02745 return n ? (date.U = +n[0], i + n[0].length) : -1;
02746 }
02747 function d3_time_parseWeekNumberMonday(date, string, i) {
02748 d3_time_numberRe.lastIndex = 0;
02749 var n = d3_time_numberRe.exec(string.slice(i));
02750 return n ? (date.W = +n[0], i + n[0].length) : -1;
02751 }
02752 function d3_time_parseFullYear(date, string, i) {
02753 d3_time_numberRe.lastIndex = 0;
02754 var n = d3_time_numberRe.exec(string.slice(i, i + 4));
02755 return n ? (date.y = +n[0], i + n[0].length) : -1;
02756 }
02757 function d3_time_parseYear(date, string, i) {
02758 d3_time_numberRe.lastIndex = 0;
02759 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
02760 return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
02761 }
02762 function d3_time_parseZone(date, string, i) {
02763 return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
02764 i + 5) : -1;
02765 }
02766 function d3_time_expandYear(d) {
02767 return d + (d > 68 ? 1900 : 2e3);
02768 }
02769 function d3_time_parseMonthNumber(date, string, i) {
02770 d3_time_numberRe.lastIndex = 0;
02771 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
02772 return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
02773 }
02774 function d3_time_parseDay(date, string, i) {
02775 d3_time_numberRe.lastIndex = 0;
02776 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
02777 return n ? (date.d = +n[0], i + n[0].length) : -1;
02778 }
02779 function d3_time_parseDayOfYear(date, string, i) {
02780 d3_time_numberRe.lastIndex = 0;
02781 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
02782 return n ? (date.j = +n[0], i + n[0].length) : -1;
02783 }
02784 function d3_time_parseHour24(date, string, i) {
02785 d3_time_numberRe.lastIndex = 0;
02786 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
02787 return n ? (date.H = +n[0], i + n[0].length) : -1;
02788 }
02789 function d3_time_parseMinutes(date, string, i) {
02790 d3_time_numberRe.lastIndex = 0;
02791 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
02792 return n ? (date.M = +n[0], i + n[0].length) : -1;
02793 }
02794 function d3_time_parseSeconds(date, string, i) {
02795 d3_time_numberRe.lastIndex = 0;
02796 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
02797 return n ? (date.S = +n[0], i + n[0].length) : -1;
02798 }
02799 function d3_time_parseMilliseconds(date, string, i) {
02800 d3_time_numberRe.lastIndex = 0;
02801 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
02802 return n ? (date.L = +n[0], i + n[0].length) : -1;
02803 }
02804 function d3_time_zone(d) {
02805 var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
02806 return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
02807 }
02808 function d3_time_parseLiteralPercent(date, string, i) {
02809 d3_time_percentRe.lastIndex = 0;
02810 var n = d3_time_percentRe.exec(string.slice(i, i + 1));
02811 return n ? i + n[0].length : -1;
02812 }
02813 function d3_time_formatMulti(formats) {
02814 var n = formats.length, i = -1;
02815 while (++i < n) formats[i][0] = this(formats[i][0]);
02816 return function(date) {
02817 var i = 0, f = formats[i];
02818 while (!f[1](date)) f = formats[++i];
02819 return f[0](date);
02820 };
02821 }
02822 d3.locale = function(locale) {
02823 return {
02824 numberFormat: d3_locale_numberFormat(locale),
02825 timeFormat: d3_locale_timeFormat(locale)
02826 };
02827 };
02828 var d3_locale_enUS = d3.locale({
02829 decimal: ".",
02830 thousands: ",",
02831 grouping: [ 3 ],
02832 currency: [ "$", "" ],
02833 dateTime: "%a %b %e %X %Y",
02834 date: "%m/%d/%Y",
02835 time: "%H:%M:%S",
02836 periods: [ "AM", "PM" ],
02837 days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
02838 shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
02839 months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
02840 shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
02841 });
02842 d3.format = d3_locale_enUS.numberFormat;
02843 d3.geo = {};
02844 function d3_adder() {}
02845 d3_adder.prototype = {
02846 s: 0,
02847 t: 0,
02848 add: function(y) {
02849 d3_adderSum(y, this.t, d3_adderTemp);
02850 d3_adderSum(d3_adderTemp.s, this.s, this);
02851 if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
02852 },
02853 reset: function() {
02854 this.s = this.t = 0;
02855 },
02856 valueOf: function() {
02857 return this.s;
02858 }
02859 };
02860 var d3_adderTemp = new d3_adder();
02861 function d3_adderSum(a, b, o) {
02862 var x = o.s = a + b, bv = x - a, av = x - bv;
02863 o.t = a - av + (b - bv);
02864 }
02865 d3.geo.stream = function(object, listener) {
02866 if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
02867 d3_geo_streamObjectType[object.type](object, listener);
02868 } else {
02869 d3_geo_streamGeometry(object, listener);
02870 }
02871 };
02872 function d3_geo_streamGeometry(geometry, listener) {
02873 if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
02874 d3_geo_streamGeometryType[geometry.type](geometry, listener);
02875 }
02876 }
02877 var d3_geo_streamObjectType = {
02878 Feature: function(feature, listener) {
02879 d3_geo_streamGeometry(feature.geometry, listener);
02880 },
02881 FeatureCollection: function(object, listener) {
02882 var features = object.features, i = -1, n = features.length;
02883 while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
02884 }
02885 };
02886 var d3_geo_streamGeometryType = {
02887 Sphere: function(object, listener) {
02888 listener.sphere();
02889 },
02890 Point: function(object, listener) {
02891 object = object.coordinates;
02892 listener.point(object[0], object[1], object[2]);
02893 },
02894 MultiPoint: function(object, listener) {
02895 var coordinates = object.coordinates, i = -1, n = coordinates.length;
02896 while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
02897 },
02898 LineString: function(object, listener) {
02899 d3_geo_streamLine(object.coordinates, listener, 0);
02900 },
02901 MultiLineString: function(object, listener) {
02902 var coordinates = object.coordinates, i = -1, n = coordinates.length;
02903 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
02904 },
02905 Polygon: function(object, listener) {
02906 d3_geo_streamPolygon(object.coordinates, listener);
02907 },
02908 MultiPolygon: function(object, listener) {
02909 var coordinates = object.coordinates, i = -1, n = coordinates.length;
02910 while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
02911 },
02912 GeometryCollection: function(object, listener) {
02913 var geometries = object.geometries, i = -1, n = geometries.length;
02914 while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
02915 }
02916 };
02917 function d3_geo_streamLine(coordinates, listener, closed) {
02918 var i = -1, n = coordinates.length - closed, coordinate;
02919 listener.lineStart();
02920 while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
02921 listener.lineEnd();
02922 }
02923 function d3_geo_streamPolygon(coordinates, listener) {
02924 var i = -1, n = coordinates.length;
02925 listener.polygonStart();
02926 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
02927 listener.polygonEnd();
02928 }
02929 d3.geo.area = function(object) {
02930 d3_geo_areaSum = 0;
02931 d3.geo.stream(object, d3_geo_area);
02932 return d3_geo_areaSum;
02933 };
02934 var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
02935 var d3_geo_area = {
02936 sphere: function() {
02937 d3_geo_areaSum += 4 * π;
02938 },
02939 point: d3_noop,
02940 lineStart: d3_noop,
02941 lineEnd: d3_noop,
02942 polygonStart: function() {
02943 d3_geo_areaRingSum.reset();
02944 d3_geo_area.lineStart = d3_geo_areaRingStart;
02945 },
02946 polygonEnd: function() {
02947 var area = 2 * d3_geo_areaRingSum;
02948 d3_geo_areaSum += area < 0 ? 4 * π + area : area;
02949 d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
02950 }
02951 };
02952 function d3_geo_areaRingStart() {
02953 var λ00, φ00, λ0, cosφ0, sinφ0;
02954 d3_geo_area.point = function(λ, φ) {
02955 d3_geo_area.point = nextPoint;
02956 λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
02957 sinφ0 = Math.sin(φ);
02958 };
02959 function nextPoint(λ, φ) {
02960 λ *= d3_radians;
02961 φ = φ * d3_radians / 2 + π / 4;
02962 var dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(adλ), v = k * sdλ * Math.sin(adλ);
02963 d3_geo_areaRingSum.add(Math.atan2(v, u));
02964 λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
02965 }
02966 d3_geo_area.lineEnd = function() {
02967 nextPoint(λ00, φ00);
02968 };
02969 }
02970 function d3_geo_cartesian(spherical) {
02971 var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
02972 return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
02973 }
02974 function d3_geo_cartesianDot(a, b) {
02975 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
02976 }
02977 function d3_geo_cartesianCross(a, b) {
02978 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] ];
02979 }
02980 function d3_geo_cartesianAdd(a, b) {
02981 a[0] += b[0];
02982 a[1] += b[1];
02983 a[2] += b[2];
02984 }
02985 function d3_geo_cartesianScale(vector, k) {
02986 return [ vector[0] * k, vector[1] * k, vector[2] * k ];
02987 }
02988 function d3_geo_cartesianNormalize(d) {
02989 var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
02990 d[0] /= l;
02991 d[1] /= l;
02992 d[2] /= l;
02993 }
02994 function d3_geo_spherical(cartesian) {
02995 return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
02996 }
02997 function d3_geo_sphericalEqual(a, b) {
02998 return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
02999 }
03000 d3.geo.bounds = function() {
03001 var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
03002 var bound = {
03003 point: point,
03004 lineStart: lineStart,
03005 lineEnd: lineEnd,
03006 polygonStart: function() {
03007 bound.point = ringPoint;
03008 bound.lineStart = ringStart;
03009 bound.lineEnd = ringEnd;
03010 dλSum = 0;
03011 d3_geo_area.polygonStart();
03012 },
03013 polygonEnd: function() {
03014 d3_geo_area.polygonEnd();
03015 bound.point = point;
03016 bound.lineStart = lineStart;
03017 bound.lineEnd = lineEnd;
03018 if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
03019 range[0] = λ0, range[1] = λ1;
03020 }
03021 };
03022 function point(λ, φ) {
03023 ranges.push(range = [ λ0 = λ, λ1 = λ ]);
03024 if (φ < φ0) φ0 = φ;
03025 if (φ > φ1) φ1 = φ;
03026 }
03027 function linePoint(λ, φ) {
03028 var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
03029 if (p0) {
03030 var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
03031 d3_geo_cartesianNormalize(inflection);
03032 inflection = d3_geo_spherical(inflection);
03033 var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
03034 if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
03035 var φi = inflection[1] * d3_degrees;
03036 if (φi > φ1) φ1 = φi;
03037 } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
03038 var φi = -inflection[1] * d3_degrees;
03039 if (φi < φ0) φ0 = φi;
03040 } else {
03041 if (φ < φ0) φ0 = φ;
03042 if (φ > φ1) φ1 = φ;
03043 }
03044 if (antimeridian) {
03045 if (λ < λ_) {
03046 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
03047 } else {
03048 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
03049 }
03050 } else {
03051 if (λ1 >= λ0) {
03052 if (λ < λ0) λ0 = λ;
03053 if (λ > λ1) λ1 = λ;
03054 } else {
03055 if (λ > λ_) {
03056 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
03057 } else {
03058 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
03059 }
03060 }
03061 }
03062 } else {
03063 point(λ, φ);
03064 }
03065 p0 = p, λ_ = λ;
03066 }
03067 function lineStart() {
03068 bound.point = linePoint;
03069 }
03070 function lineEnd() {
03071 range[0] = λ0, range[1] = λ1;
03072 bound.point = point;
03073 p0 = null;
03074 }
03075 function ringPoint(λ, φ) {
03076 if (p0) {
03077 var dλ = λ - λ_;
03078 dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
03079 } else λ__ = λ, φ__ = φ;
03080 d3_geo_area.point(λ, φ);
03081 linePoint(λ, φ);
03082 }
03083 function ringStart() {
03084 d3_geo_area.lineStart();
03085 }
03086 function ringEnd() {
03087 ringPoint(λ__, φ__);
03088 d3_geo_area.lineEnd();
03089 if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
03090 range[0] = λ0, range[1] = λ1;
03091 p0 = null;
03092 }
03093 function angle(λ0, λ1) {
03094 return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
03095 }
03096 function compareRanges(a, b) {
03097 return a[0] - b[0];
03098 }
03099 function withinRange(x, range) {
03100 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
03101 }
03102 return function(feature) {
03103 φ1 = λ1 = -(λ0 = φ0 = Infinity);
03104 ranges = [];
03105 d3.geo.stream(feature, bound);
03106 var n = ranges.length;
03107 if (n) {
03108 ranges.sort(compareRanges);
03109 for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
03110 b = ranges[i];
03111 if (withinRange(b[0], a) || withinRange(b[1], a)) {
03112 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
03113 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
03114 } else {
03115 merged.push(a = b);
03116 }
03117 }
03118 var best = -Infinity, dλ;
03119 for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
03120 b = merged[i];
03121 if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
03122 }
03123 }
03124 ranges = range = null;
03125 return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
03126 };
03127 }();
03128 d3.geo.centroid = function(object) {
03129 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;
03130 d3.geo.stream(object, d3_geo_centroid);
03131 var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
03132 if (m < ε2) {
03133 x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
03134 if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
03135 m = x * x + y * y + z * z;
03136 if (m < ε2) return [ NaN, NaN ];
03137 }
03138 return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
03139 };
03140 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;
03141 var d3_geo_centroid = {
03142 sphere: d3_noop,
03143 point: d3_geo_centroidPoint,
03144 lineStart: d3_geo_centroidLineStart,
03145 lineEnd: d3_geo_centroidLineEnd,
03146 polygonStart: function() {
03147 d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
03148 },
03149 polygonEnd: function() {
03150 d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
03151 }
03152 };
03153 function d3_geo_centroidPoint(λ, φ) {
03154 λ *= d3_radians;
03155 var cosφ = Math.cos(φ *= d3_radians);
03156 d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
03157 }
03158 function d3_geo_centroidPointXYZ(x, y, z) {
03159 ++d3_geo_centroidW0;
03160 d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
03161 d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
03162 d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
03163 }
03164 function d3_geo_centroidLineStart() {
03165 var x0, y0, z0;
03166 d3_geo_centroid.point = function(λ, φ) {
03167 λ *= d3_radians;
03168 var cosφ = Math.cos(φ *= d3_radians);
03169 x0 = cosφ * Math.cos(λ);
03170 y0 = cosφ * Math.sin(λ);
03171 z0 = Math.sin(φ);
03172 d3_geo_centroid.point = nextPoint;
03173 d3_geo_centroidPointXYZ(x0, y0, z0);
03174 };
03175 function nextPoint(λ, φ) {
03176 λ *= d3_radians;
03177 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);
03178 d3_geo_centroidW1 += w;
03179 d3_geo_centroidX1 += w * (x0 + (x0 = x));
03180 d3_geo_centroidY1 += w * (y0 + (y0 = y));
03181 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
03182 d3_geo_centroidPointXYZ(x0, y0, z0);
03183 }
03184 }
03185 function d3_geo_centroidLineEnd() {
03186 d3_geo_centroid.point = d3_geo_centroidPoint;
03187 }
03188 function d3_geo_centroidRingStart() {
03189 var λ00, φ00, x0, y0, z0;
03190 d3_geo_centroid.point = function(λ, φ) {
03191 λ00 = λ, φ00 = φ;
03192 d3_geo_centroid.point = nextPoint;
03193 λ *= d3_radians;
03194 var cosφ = Math.cos(φ *= d3_radians);
03195 x0 = cosφ * Math.cos(λ);
03196 y0 = cosφ * Math.sin(λ);
03197 z0 = Math.sin(φ);
03198 d3_geo_centroidPointXYZ(x0, y0, z0);
03199 };
03200 d3_geo_centroid.lineEnd = function() {
03201 nextPoint(λ00, φ00);
03202 d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
03203 d3_geo_centroid.point = d3_geo_centroidPoint;
03204 };
03205 function nextPoint(λ, φ) {
03206 λ *= d3_radians;
03207 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);
03208 d3_geo_centroidX2 += v * cx;
03209 d3_geo_centroidY2 += v * cy;
03210 d3_geo_centroidZ2 += v * cz;
03211 d3_geo_centroidW1 += w;
03212 d3_geo_centroidX1 += w * (x0 + (x0 = x));
03213 d3_geo_centroidY1 += w * (y0 + (y0 = y));
03214 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
03215 d3_geo_centroidPointXYZ(x0, y0, z0);
03216 }
03217 }
03218 function d3_geo_compose(a, b) {
03219 function compose(x, y) {
03220 return x = a(x, y), b(x[0], x[1]);
03221 }
03222 if (a.invert && b.invert) compose.invert = function(x, y) {
03223 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
03224 };
03225 return compose;
03226 }
03227 function d3_true() {
03228 return true;
03229 }
03230 function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
03231 var subject = [], clip = [];
03232 segments.forEach(function(segment) {
03233 if ((n = segment.length - 1) <= 0) return;
03234 var n, p0 = segment[0], p1 = segment[n];
03235 if (d3_geo_sphericalEqual(p0, p1)) {
03236 listener.lineStart();
03237 for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
03238 listener.lineEnd();
03239 return;
03240 }
03241 var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
03242 a.o = b;
03243 subject.push(a);
03244 clip.push(b);
03245 a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
03246 b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
03247 a.o = b;
03248 subject.push(a);
03249 clip.push(b);
03250 });
03251 clip.sort(compare);
03252 d3_geo_clipPolygonLinkCircular(subject);
03253 d3_geo_clipPolygonLinkCircular(clip);
03254 if (!subject.length) return;
03255 for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
03256 clip[i].e = entry = !entry;
03257 }
03258 var start = subject[0], points, point;
03259 while (1) {
03260 var current = start, isSubject = true;
03261 while (current.v) if ((current = current.n) === start) return;
03262 points = current.z;
03263 listener.lineStart();
03264 do {
03265 current.v = current.o.v = true;
03266 if (current.e) {
03267 if (isSubject) {
03268 for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
03269 } else {
03270 interpolate(current.x, current.n.x, 1, listener);
03271 }
03272 current = current.n;
03273 } else {
03274 if (isSubject) {
03275 points = current.p.z;
03276 for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
03277 } else {
03278 interpolate(current.x, current.p.x, -1, listener);
03279 }
03280 current = current.p;
03281 }
03282 current = current.o;
03283 points = current.z;
03284 isSubject = !isSubject;
03285 } while (!current.v);
03286 listener.lineEnd();
03287 }
03288 }
03289 function d3_geo_clipPolygonLinkCircular(array) {
03290 if (!(n = array.length)) return;
03291 var n, i = 0, a = array[0], b;
03292 while (++i < n) {
03293 a.n = b = array[i];
03294 b.p = a;
03295 a = b;
03296 }
03297 a.n = b = array[0];
03298 b.p = a;
03299 }
03300 function d3_geo_clipPolygonIntersection(point, points, other, entry) {
03301 this.x = point;
03302 this.z = points;
03303 this.o = other;
03304 this.e = entry;
03305 this.v = false;
03306 this.n = this.p = null;
03307 }
03308 function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
03309 return function(rotate, listener) {
03310 var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
03311 var clip = {
03312 point: point,
03313 lineStart: lineStart,
03314 lineEnd: lineEnd,
03315 polygonStart: function() {
03316 clip.point = pointRing;
03317 clip.lineStart = ringStart;
03318 clip.lineEnd = ringEnd;
03319 segments = [];
03320 polygon = [];
03321 },
03322 polygonEnd: function() {
03323 clip.point = point;
03324 clip.lineStart = lineStart;
03325 clip.lineEnd = lineEnd;
03326 segments = d3.merge(segments);
03327 var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
03328 if (segments.length) {
03329 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
03330 d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
03331 } else if (clipStartInside) {
03332 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
03333 listener.lineStart();
03334 interpolate(null, null, 1, listener);
03335 listener.lineEnd();
03336 }
03337 if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
03338 segments = polygon = null;
03339 },
03340 sphere: function() {
03341 listener.polygonStart();
03342 listener.lineStart();
03343 interpolate(null, null, 1, listener);
03344 listener.lineEnd();
03345 listener.polygonEnd();
03346 }
03347 };
03348 function point(λ, φ) {
03349 var point = rotate(λ, φ);
03350 if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
03351 }
03352 function pointLine(λ, φ) {
03353 var point = rotate(λ, φ);
03354 line.point(point[0], point[1]);
03355 }
03356 function lineStart() {
03357 clip.point = pointLine;
03358 line.lineStart();
03359 }
03360 function lineEnd() {
03361 clip.point = point;
03362 line.lineEnd();
03363 }
03364 var segments;
03365 var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
03366 function pointRing(λ, φ) {
03367 ring.push([ λ, φ ]);
03368 var point = rotate(λ, φ);
03369 ringListener.point(point[0], point[1]);
03370 }
03371 function ringStart() {
03372 ringListener.lineStart();
03373 ring = [];
03374 }
03375 function ringEnd() {
03376 pointRing(ring[0][0], ring[0][1]);
03377 ringListener.lineEnd();
03378 var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
03379 ring.pop();
03380 polygon.push(ring);
03381 ring = null;
03382 if (!n) return;
03383 if (clean & 1) {
03384 segment = ringSegments[0];
03385 var n = segment.length - 1, i = -1, point;
03386 if (n > 0) {
03387 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
03388 listener.lineStart();
03389 while (++i < n) listener.point((point = segment[i])[0], point[1]);
03390 listener.lineEnd();
03391 }
03392 return;
03393 }
03394 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
03395 segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
03396 }
03397 return clip;
03398 };
03399 }
03400 function d3_geo_clipSegmentLength1(segment) {
03401 return segment.length > 1;
03402 }
03403 function d3_geo_clipBufferListener() {
03404 var lines = [], line;
03405 return {
03406 lineStart: function() {
03407 lines.push(line = []);
03408 },
03409 point: function(λ, φ) {
03410 line.push([ λ, φ ]);
03411 },
03412 lineEnd: d3_noop,
03413 buffer: function() {
03414 var buffer = lines;
03415 lines = [];
03416 line = null;
03417 return buffer;
03418 },
03419 rejoin: function() {
03420 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
03421 }
03422 };
03423 }
03424 function d3_geo_clipSort(a, b) {
03425 return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
03426 }
03427 var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
03428 function d3_geo_clipAntimeridianLine(listener) {
03429 var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
03430 return {
03431 lineStart: function() {
03432 listener.lineStart();
03433 clean = 1;
03434 },
03435 point: function(λ1, φ1) {
03436 var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
03437 if (abs(dλ - π) < ε) {
03438 listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
03439 listener.point(sλ0, φ0);
03440 listener.lineEnd();
03441 listener.lineStart();
03442 listener.point(sλ1, φ0);
03443 listener.point(λ1, φ0);
03444 clean = 0;
03445 } else if (sλ0 !== sλ1 && dλ >= π) {
03446 if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
03447 if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
03448 φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
03449 listener.point(sλ0, φ0);
03450 listener.lineEnd();
03451 listener.lineStart();
03452 listener.point(sλ1, φ0);
03453 clean = 0;
03454 }
03455 listener.point(λ0 = λ1, φ0 = φ1);
03456 sλ0 = sλ1;
03457 },
03458 lineEnd: function() {
03459 listener.lineEnd();
03460 λ0 = φ0 = NaN;
03461 },
03462 clean: function() {
03463 return 2 - clean;
03464 }
03465 };
03466 }
03467 function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
03468 var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
03469 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;
03470 }
03471 function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
03472 var φ;
03473 if (from == null) {
03474 φ = direction * halfπ;
03475 listener.point(-π, φ);
03476 listener.point(0, φ);
03477 listener.point(π, φ);
03478 listener.point(π, 0);
03479 listener.point(π, -φ);
03480 listener.point(0, -φ);
03481 listener.point(-π, -φ);
03482 listener.point(-π, 0);
03483 listener.point(-π, φ);
03484 } else if (abs(from[0] - to[0]) > ε) {
03485 var s = from[0] < to[0] ? π : -π;
03486 φ = direction * s / 2;
03487 listener.point(-s, φ);
03488 listener.point(0, φ);
03489 listener.point(s, φ);
03490 } else {
03491 listener.point(to[0], to[1]);
03492 }
03493 }
03494 function d3_geo_pointInPolygon(point, polygon) {
03495 var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
03496 d3_geo_areaRingSum.reset();
03497 for (var i = 0, n = polygon.length; i < n; ++i) {
03498 var ring = polygon[i], m = ring.length;
03499 if (!m) continue;
03500 var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
03501 while (true) {
03502 if (j === m) j = 0;
03503 point = ring[j];
03504 var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, antimeridian = adλ > π, k = sinφ0 * sinφ;
03505 d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
03506 polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
03507 if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
03508 var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
03509 d3_geo_cartesianNormalize(arc);
03510 var intersection = d3_geo_cartesianCross(meridianNormal, arc);
03511 d3_geo_cartesianNormalize(intersection);
03512 var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
03513 if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
03514 winding += antimeridian ^ dλ >= 0 ? 1 : -1;
03515 }
03516 }
03517 if (!j++) break;
03518 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
03519 }
03520 }
03521 return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
03522 }
03523 function d3_geo_clipCircle(radius) {
03524 var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
03525 return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
03526 function visible(λ, φ) {
03527 return Math.cos(λ) * Math.cos(φ) > cr;
03528 }
03529 function clipLine(listener) {
03530 var point0, c0, v0, v00, clean;
03531 return {
03532 lineStart: function() {
03533 v00 = v0 = false;
03534 clean = 1;
03535 },
03536 point: function(λ, φ) {
03537 var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
03538 if (!point0 && (v00 = v0 = v)) listener.lineStart();
03539 if (v !== v0) {
03540 point2 = intersect(point0, point1);
03541 if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
03542 point1[0] += ε;
03543 point1[1] += ε;
03544 v = visible(point1[0], point1[1]);
03545 }
03546 }
03547 if (v !== v0) {
03548 clean = 0;
03549 if (v) {
03550 listener.lineStart();
03551 point2 = intersect(point1, point0);
03552 listener.point(point2[0], point2[1]);
03553 } else {
03554 point2 = intersect(point0, point1);
03555 listener.point(point2[0], point2[1]);
03556 listener.lineEnd();
03557 }
03558 point0 = point2;
03559 } else if (notHemisphere && point0 && smallRadius ^ v) {
03560 var t;
03561 if (!(c & c0) && (t = intersect(point1, point0, true))) {
03562 clean = 0;
03563 if (smallRadius) {
03564 listener.lineStart();
03565 listener.point(t[0][0], t[0][1]);
03566 listener.point(t[1][0], t[1][1]);
03567 listener.lineEnd();
03568 } else {
03569 listener.point(t[1][0], t[1][1]);
03570 listener.lineEnd();
03571 listener.lineStart();
03572 listener.point(t[0][0], t[0][1]);
03573 }
03574 }
03575 }
03576 if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
03577 listener.point(point1[0], point1[1]);
03578 }
03579 point0 = point1, v0 = v, c0 = c;
03580 },
03581 lineEnd: function() {
03582 if (v0) listener.lineEnd();
03583 point0 = null;
03584 },
03585 clean: function() {
03586 return clean | (v00 && v0) << 1;
03587 }
03588 };
03589 }
03590 function intersect(a, b, two) {
03591 var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
03592 var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
03593 if (!determinant) return !two && a;
03594 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);
03595 d3_geo_cartesianAdd(A, B);
03596 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);
03597 if (t2 < 0) return;
03598 var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
03599 d3_geo_cartesianAdd(q, A);
03600 q = d3_geo_spherical(q);
03601 if (!two) return q;
03602 var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
03603 if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
03604 var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
03605 if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
03606 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)) {
03607 var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
03608 d3_geo_cartesianAdd(q1, A);
03609 return [ q, d3_geo_spherical(q1) ];
03610 }
03611 }
03612 function code(λ, φ) {
03613 var r = smallRadius ? radius : π - radius, code = 0;
03614 if (λ < -r) code |= 1; else if (λ > r) code |= 2;
03615 if (φ < -r) code |= 4; else if (φ > r) code |= 8;
03616 return code;
03617 }
03618 }
03619 function d3_geom_clipLine(x0, y0, x1, y1) {
03620 return function(line) {
03621 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;
03622 r = x0 - ax;
03623 if (!dx && r > 0) return;
03624 r /= dx;
03625 if (dx < 0) {
03626 if (r < t0) return;
03627 if (r < t1) t1 = r;
03628 } else if (dx > 0) {
03629 if (r > t1) return;
03630 if (r > t0) t0 = r;
03631 }
03632 r = x1 - ax;
03633 if (!dx && r < 0) return;
03634 r /= dx;
03635 if (dx < 0) {
03636 if (r > t1) return;
03637 if (r > t0) t0 = r;
03638 } else if (dx > 0) {
03639 if (r < t0) return;
03640 if (r < t1) t1 = r;
03641 }
03642 r = y0 - ay;
03643 if (!dy && r > 0) return;
03644 r /= dy;
03645 if (dy < 0) {
03646 if (r < t0) return;
03647 if (r < t1) t1 = r;
03648 } else if (dy > 0) {
03649 if (r > t1) return;
03650 if (r > t0) t0 = r;
03651 }
03652 r = y1 - ay;
03653 if (!dy && r < 0) return;
03654 r /= dy;
03655 if (dy < 0) {
03656 if (r > t1) return;
03657 if (r > t0) t0 = r;
03658 } else if (dy > 0) {
03659 if (r < t0) return;
03660 if (r < t1) t1 = r;
03661 }
03662 if (t0 > 0) line.a = {
03663 x: ax + t0 * dx,
03664 y: ay + t0 * dy
03665 };
03666 if (t1 < 1) line.b = {
03667 x: ax + t1 * dx,
03668 y: ay + t1 * dy
03669 };
03670 return line;
03671 };
03672 }
03673 var d3_geo_clipExtentMAX = 1e9;
03674 d3.geo.clipExtent = function() {
03675 var x0, y0, x1, y1, stream, clip, clipExtent = {
03676 stream: function(output) {
03677 if (stream) stream.valid = false;
03678 stream = clip(output);
03679 stream.valid = true;
03680 return stream;
03681 },
03682 extent: function(_) {
03683 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
03684 clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
03685 if (stream) stream.valid = false, stream = null;
03686 return clipExtent;
03687 }
03688 };
03689 return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
03690 };
03691 function d3_geo_clipExtent(x0, y0, x1, y1) {
03692 return function(listener) {
03693 var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
03694 var clip = {
03695 point: point,
03696 lineStart: lineStart,
03697 lineEnd: lineEnd,
03698 polygonStart: function() {
03699 listener = bufferListener;
03700 segments = [];
03701 polygon = [];
03702 clean = true;
03703 },
03704 polygonEnd: function() {
03705 listener = listener_;
03706 segments = d3.merge(segments);
03707 var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
03708 if (inside || visible) {
03709 listener.polygonStart();
03710 if (inside) {
03711 listener.lineStart();
03712 interpolate(null, null, 1, listener);
03713 listener.lineEnd();
03714 }
03715 if (visible) {
03716 d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
03717 }
03718 listener.polygonEnd();
03719 }
03720 segments = polygon = ring = null;
03721 }
03722 };
03723 function insidePolygon(p) {
03724 var wn = 0, n = polygon.length, y = p[1];
03725 for (var i = 0; i < n; ++i) {
03726 for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
03727 b = v[j];
03728 if (a[1] <= y) {
03729 if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
03730 } else {
03731 if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
03732 }
03733 a = b;
03734 }
03735 }
03736 return wn !== 0;
03737 }
03738 function interpolate(from, to, direction, listener) {
03739 var a = 0, a1 = 0;
03740 if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
03741 do {
03742 listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
03743 } while ((a = (a + direction + 4) % 4) !== a1);
03744 } else {
03745 listener.point(to[0], to[1]);
03746 }
03747 }
03748 function pointVisible(x, y) {
03749 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
03750 }
03751 function point(x, y) {
03752 if (pointVisible(x, y)) listener.point(x, y);
03753 }
03754 var x__, y__, v__, x_, y_, v_, first, clean;
03755 function lineStart() {
03756 clip.point = linePoint;
03757 if (polygon) polygon.push(ring = []);
03758 first = true;
03759 v_ = false;
03760 x_ = y_ = NaN;
03761 }
03762 function lineEnd() {
03763 if (segments) {
03764 linePoint(x__, y__);
03765 if (v__ && v_) bufferListener.rejoin();
03766 segments.push(bufferListener.buffer());
03767 }
03768 clip.point = point;
03769 if (v_) listener.lineEnd();
03770 }
03771 function linePoint(x, y) {
03772 x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
03773 y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
03774 var v = pointVisible(x, y);
03775 if (polygon) ring.push([ x, y ]);
03776 if (first) {
03777 x__ = x, y__ = y, v__ = v;
03778 first = false;
03779 if (v) {
03780 listener.lineStart();
03781 listener.point(x, y);
03782 }
03783 } else {
03784 if (v && v_) listener.point(x, y); else {
03785 var l = {
03786 a: {
03787 x: x_,
03788 y: y_
03789 },
03790 b: {
03791 x: x,
03792 y: y
03793 }
03794 };
03795 if (clipLine(l)) {
03796 if (!v_) {
03797 listener.lineStart();
03798 listener.point(l.a.x, l.a.y);
03799 }
03800 listener.point(l.b.x, l.b.y);
03801 if (!v) listener.lineEnd();
03802 clean = false;
03803 } else if (v) {
03804 listener.lineStart();
03805 listener.point(x, y);
03806 clean = false;
03807 }
03808 }
03809 }
03810 x_ = x, y_ = y, v_ = v;
03811 }
03812 return clip;
03813 };
03814 function corner(p, direction) {
03815 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;
03816 }
03817 function compare(a, b) {
03818 return comparePoints(a.x, b.x);
03819 }
03820 function comparePoints(a, b) {
03821 var ca = corner(a, 1), cb = corner(b, 1);
03822 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];
03823 }
03824 }
03825 function d3_geo_conic(projectAt) {
03826 var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
03827 p.parallels = function(_) {
03828 if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
03829 return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
03830 };
03831 return p;
03832 }
03833 function d3_geo_conicEqualArea(φ0, φ1) {
03834 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;
03835 function forward(λ, φ) {
03836 var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
03837 return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
03838 }
03839 forward.invert = function(x, y) {
03840 var ρ0_y = ρ0 - y;
03841 return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
03842 };
03843 return forward;
03844 }
03845 (d3.geo.conicEqualArea = function() {
03846 return d3_geo_conic(d3_geo_conicEqualArea);
03847 }).raw = d3_geo_conicEqualArea;
03848 d3.geo.albers = function() {
03849 return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
03850 };
03851 d3.geo.albersUsa = function() {
03852 var lower48 = d3.geo.albers();
03853 var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
03854 var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
03855 var point, pointStream = {
03856 point: function(x, y) {
03857 point = [ x, y ];
03858 }
03859 }, lower48Point, alaskaPoint, hawaiiPoint;
03860 function albersUsa(coordinates) {
03861 var x = coordinates[0], y = coordinates[1];
03862 point = null;
03863 (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
03864 return point;
03865 }
03866 albersUsa.invert = function(coordinates) {
03867 var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
03868 return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
03869 };
03870 albersUsa.stream = function(stream) {
03871 var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
03872 return {
03873 point: function(x, y) {
03874 lower48Stream.point(x, y);
03875 alaskaStream.point(x, y);
03876 hawaiiStream.point(x, y);
03877 },
03878 sphere: function() {
03879 lower48Stream.sphere();
03880 alaskaStream.sphere();
03881 hawaiiStream.sphere();
03882 },
03883 lineStart: function() {
03884 lower48Stream.lineStart();
03885 alaskaStream.lineStart();
03886 hawaiiStream.lineStart();
03887 },
03888 lineEnd: function() {
03889 lower48Stream.lineEnd();
03890 alaskaStream.lineEnd();
03891 hawaiiStream.lineEnd();
03892 },
03893 polygonStart: function() {
03894 lower48Stream.polygonStart();
03895 alaskaStream.polygonStart();
03896 hawaiiStream.polygonStart();
03897 },
03898 polygonEnd: function() {
03899 lower48Stream.polygonEnd();
03900 alaskaStream.polygonEnd();
03901 hawaiiStream.polygonEnd();
03902 }
03903 };
03904 };
03905 albersUsa.precision = function(_) {
03906 if (!arguments.length) return lower48.precision();
03907 lower48.precision(_);
03908 alaska.precision(_);
03909 hawaii.precision(_);
03910 return albersUsa;
03911 };
03912 albersUsa.scale = function(_) {
03913 if (!arguments.length) return lower48.scale();
03914 lower48.scale(_);
03915 alaska.scale(_ * .35);
03916 hawaii.scale(_);
03917 return albersUsa.translate(lower48.translate());
03918 };
03919 albersUsa.translate = function(_) {
03920 if (!arguments.length) return lower48.translate();
03921 var k = lower48.scale(), x = +_[0], y = +_[1];
03922 lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
03923 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;
03924 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;
03925 return albersUsa;
03926 };
03927 return albersUsa.scale(1070);
03928 };
03929 var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
03930 point: d3_noop,
03931 lineStart: d3_noop,
03932 lineEnd: d3_noop,
03933 polygonStart: function() {
03934 d3_geo_pathAreaPolygon = 0;
03935 d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
03936 },
03937 polygonEnd: function() {
03938 d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
03939 d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
03940 }
03941 };
03942 function d3_geo_pathAreaRingStart() {
03943 var x00, y00, x0, y0;
03944 d3_geo_pathArea.point = function(x, y) {
03945 d3_geo_pathArea.point = nextPoint;
03946 x00 = x0 = x, y00 = y0 = y;
03947 };
03948 function nextPoint(x, y) {
03949 d3_geo_pathAreaPolygon += y0 * x - x0 * y;
03950 x0 = x, y0 = y;
03951 }
03952 d3_geo_pathArea.lineEnd = function() {
03953 nextPoint(x00, y00);
03954 };
03955 }
03956 var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
03957 var d3_geo_pathBounds = {
03958 point: d3_geo_pathBoundsPoint,
03959 lineStart: d3_noop,
03960 lineEnd: d3_noop,
03961 polygonStart: d3_noop,
03962 polygonEnd: d3_noop
03963 };
03964 function d3_geo_pathBoundsPoint(x, y) {
03965 if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
03966 if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
03967 if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
03968 if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
03969 }
03970 function d3_geo_pathBuffer() {
03971 var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
03972 var stream = {
03973 point: point,
03974 lineStart: function() {
03975 stream.point = pointLineStart;
03976 },
03977 lineEnd: lineEnd,
03978 polygonStart: function() {
03979 stream.lineEnd = lineEndPolygon;
03980 },
03981 polygonEnd: function() {
03982 stream.lineEnd = lineEnd;
03983 stream.point = point;
03984 },
03985 pointRadius: function(_) {
03986 pointCircle = d3_geo_pathBufferCircle(_);
03987 return stream;
03988 },
03989 result: function() {
03990 if (buffer.length) {
03991 var result = buffer.join("");
03992 buffer = [];
03993 return result;
03994 }
03995 }
03996 };
03997 function point(x, y) {
03998 buffer.push("M", x, ",", y, pointCircle);
03999 }
04000 function pointLineStart(x, y) {
04001 buffer.push("M", x, ",", y);
04002 stream.point = pointLine;
04003 }
04004 function pointLine(x, y) {
04005 buffer.push("L", x, ",", y);
04006 }
04007 function lineEnd() {
04008 stream.point = point;
04009 }
04010 function lineEndPolygon() {
04011 buffer.push("Z");
04012 }
04013 return stream;
04014 }
04015 function d3_geo_pathBufferCircle(radius) {
04016 return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
04017 }
04018 var d3_geo_pathCentroid = {
04019 point: d3_geo_pathCentroidPoint,
04020 lineStart: d3_geo_pathCentroidLineStart,
04021 lineEnd: d3_geo_pathCentroidLineEnd,
04022 polygonStart: function() {
04023 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
04024 },
04025 polygonEnd: function() {
04026 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
04027 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
04028 d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
04029 }
04030 };
04031 function d3_geo_pathCentroidPoint(x, y) {
04032 d3_geo_centroidX0 += x;
04033 d3_geo_centroidY0 += y;
04034 ++d3_geo_centroidZ0;
04035 }
04036 function d3_geo_pathCentroidLineStart() {
04037 var x0, y0;
04038 d3_geo_pathCentroid.point = function(x, y) {
04039 d3_geo_pathCentroid.point = nextPoint;
04040 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
04041 };
04042 function nextPoint(x, y) {
04043 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
04044 d3_geo_centroidX1 += z * (x0 + x) / 2;
04045 d3_geo_centroidY1 += z * (y0 + y) / 2;
04046 d3_geo_centroidZ1 += z;
04047 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
04048 }
04049 }
04050 function d3_geo_pathCentroidLineEnd() {
04051 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
04052 }
04053 function d3_geo_pathCentroidRingStart() {
04054 var x00, y00, x0, y0;
04055 d3_geo_pathCentroid.point = function(x, y) {
04056 d3_geo_pathCentroid.point = nextPoint;
04057 d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
04058 };
04059 function nextPoint(x, y) {
04060 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
04061 d3_geo_centroidX1 += z * (x0 + x) / 2;
04062 d3_geo_centroidY1 += z * (y0 + y) / 2;
04063 d3_geo_centroidZ1 += z;
04064 z = y0 * x - x0 * y;
04065 d3_geo_centroidX2 += z * (x0 + x);
04066 d3_geo_centroidY2 += z * (y0 + y);
04067 d3_geo_centroidZ2 += z * 3;
04068 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
04069 }
04070 d3_geo_pathCentroid.lineEnd = function() {
04071 nextPoint(x00, y00);
04072 };
04073 }
04074 function d3_geo_pathContext(context) {
04075 var pointRadius = 4.5;
04076 var stream = {
04077 point: point,
04078 lineStart: function() {
04079 stream.point = pointLineStart;
04080 },
04081 lineEnd: lineEnd,
04082 polygonStart: function() {
04083 stream.lineEnd = lineEndPolygon;
04084 },
04085 polygonEnd: function() {
04086 stream.lineEnd = lineEnd;
04087 stream.point = point;
04088 },
04089 pointRadius: function(_) {
04090 pointRadius = _;
04091 return stream;
04092 },
04093 result: d3_noop
04094 };
04095 function point(x, y) {
04096 context.moveTo(x + pointRadius, y);
04097 context.arc(x, y, pointRadius, 0, τ);
04098 }
04099 function pointLineStart(x, y) {
04100 context.moveTo(x, y);
04101 stream.point = pointLine;
04102 }
04103 function pointLine(x, y) {
04104 context.lineTo(x, y);
04105 }
04106 function lineEnd() {
04107 stream.point = point;
04108 }
04109 function lineEndPolygon() {
04110 context.closePath();
04111 }
04112 return stream;
04113 }
04114 function d3_geo_resample(project) {
04115 var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
04116 function resample(stream) {
04117 return (maxDepth ? resampleRecursive : resampleNone)(stream);
04118 }
04119 function resampleNone(stream) {
04120 return d3_geo_transformPoint(stream, function(x, y) {
04121 x = project(x, y);
04122 stream.point(x[0], x[1]);
04123 });
04124 }
04125 function resampleRecursive(stream) {
04126 var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
04127 var resample = {
04128 point: point,
04129 lineStart: lineStart,
04130 lineEnd: lineEnd,
04131 polygonStart: function() {
04132 stream.polygonStart();
04133 resample.lineStart = ringStart;
04134 },
04135 polygonEnd: function() {
04136 stream.polygonEnd();
04137 resample.lineStart = lineStart;
04138 }
04139 };
04140 function point(x, y) {
04141 x = project(x, y);
04142 stream.point(x[0], x[1]);
04143 }
04144 function lineStart() {
04145 x0 = NaN;
04146 resample.point = linePoint;
04147 stream.lineStart();
04148 }
04149 function linePoint(λ, φ) {
04150 var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
04151 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);
04152 stream.point(x0, y0);
04153 }
04154 function lineEnd() {
04155 resample.point = point;
04156 stream.lineEnd();
04157 }
04158 function ringStart() {
04159 lineStart();
04160 resample.point = ringPoint;
04161 resample.lineEnd = ringEnd;
04162 }
04163 function ringPoint(λ, φ) {
04164 linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
04165 resample.point = linePoint;
04166 }
04167 function ringEnd() {
04168 resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
04169 resample.lineEnd = lineEnd;
04170 lineEnd();
04171 }
04172 return resample;
04173 }
04174 function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
04175 var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
04176 if (d2 > 4 * δ2 && depth--) {
04177 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;
04178 if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
04179 resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
04180 stream.point(x2, y2);
04181 resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
04182 }
04183 }
04184 }
04185 resample.precision = function(_) {
04186 if (!arguments.length) return Math.sqrt(δ2);
04187 maxDepth = (δ2 = _ * _) > 0 && 16;
04188 return resample;
04189 };
04190 return resample;
04191 }
04192 d3.geo.path = function() {
04193 var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
04194 function path(object) {
04195 if (object) {
04196 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
04197 if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
04198 d3.geo.stream(object, cacheStream);
04199 }
04200 return contextStream.result();
04201 }
04202 path.area = function(object) {
04203 d3_geo_pathAreaSum = 0;
04204 d3.geo.stream(object, projectStream(d3_geo_pathArea));
04205 return d3_geo_pathAreaSum;
04206 };
04207 path.centroid = function(object) {
04208 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;
04209 d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
04210 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 ];
04211 };
04212 path.bounds = function(object) {
04213 d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
04214 d3.geo.stream(object, projectStream(d3_geo_pathBounds));
04215 return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
04216 };
04217 path.projection = function(_) {
04218 if (!arguments.length) return projection;
04219 projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
04220 return reset();
04221 };
04222 path.context = function(_) {
04223 if (!arguments.length) return context;
04224 contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
04225 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
04226 return reset();
04227 };
04228 path.pointRadius = function(_) {
04229 if (!arguments.length) return pointRadius;
04230 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
04231 return path;
04232 };
04233 function reset() {
04234 cacheStream = null;
04235 return path;
04236 }
04237 return path.projection(d3.geo.albersUsa()).context(null);
04238 };
04239 function d3_geo_pathProjectStream(project) {
04240 var resample = d3_geo_resample(function(x, y) {
04241 return project([ x * d3_degrees, y * d3_degrees ]);
04242 });
04243 return function(stream) {
04244 return d3_geo_projectionRadians(resample(stream));
04245 };
04246 }
04247 d3.geo.transform = function(methods) {
04248 return {
04249 stream: function(stream) {
04250 var transform = new d3_geo_transform(stream);
04251 for (var k in methods) transform[k] = methods[k];
04252 return transform;
04253 }
04254 };
04255 };
04256 function d3_geo_transform(stream) {
04257 this.stream = stream;
04258 }
04259 d3_geo_transform.prototype = {
04260 point: function(x, y) {
04261 this.stream.point(x, y);
04262 },
04263 sphere: function() {
04264 this.stream.sphere();
04265 },
04266 lineStart: function() {
04267 this.stream.lineStart();
04268 },
04269 lineEnd: function() {
04270 this.stream.lineEnd();
04271 },
04272 polygonStart: function() {
04273 this.stream.polygonStart();
04274 },
04275 polygonEnd: function() {
04276 this.stream.polygonEnd();
04277 }
04278 };
04279 function d3_geo_transformPoint(stream, point) {
04280 return {
04281 point: point,
04282 sphere: function() {
04283 stream.sphere();
04284 },
04285 lineStart: function() {
04286 stream.lineStart();
04287 },
04288 lineEnd: function() {
04289 stream.lineEnd();
04290 },
04291 polygonStart: function() {
04292 stream.polygonStart();
04293 },
04294 polygonEnd: function() {
04295 stream.polygonEnd();
04296 }
04297 };
04298 }
04299 d3.geo.projection = d3_geo_projection;
04300 d3.geo.projectionMutator = d3_geo_projectionMutator;
04301 function d3_geo_projection(project) {
04302 return d3_geo_projectionMutator(function() {
04303 return project;
04304 })();
04305 }
04306 function d3_geo_projectionMutator(projectAt) {
04307 var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
04308 x = project(x, y);
04309 return [ x[0] * k + δx, δy - x[1] * k ];
04310 }), 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;
04311 function projection(point) {
04312 point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
04313 return [ point[0] * k + δx, δy - point[1] * k ];
04314 }
04315 function invert(point) {
04316 point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
04317 return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
04318 }
04319 projection.stream = function(output) {
04320 if (stream) stream.valid = false;
04321 stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
04322 stream.valid = true;
04323 return stream;
04324 };
04325 projection.clipAngle = function(_) {
04326 if (!arguments.length) return clipAngle;
04327 preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
04328 return invalidate();
04329 };
04330 projection.clipExtent = function(_) {
04331 if (!arguments.length) return clipExtent;
04332 clipExtent = _;
04333 postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
04334 return invalidate();
04335 };
04336 projection.scale = function(_) {
04337 if (!arguments.length) return k;
04338 k = +_;
04339 return reset();
04340 };
04341 projection.translate = function(_) {
04342 if (!arguments.length) return [ x, y ];
04343 x = +_[0];
04344 y = +_[1];
04345 return reset();
04346 };
04347 projection.center = function(_) {
04348 if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
04349 λ = _[0] % 360 * d3_radians;
04350 φ = _[1] % 360 * d3_radians;
04351 return reset();
04352 };
04353 projection.rotate = function(_) {
04354 if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
04355 δλ = _[0] % 360 * d3_radians;
04356 δφ = _[1] % 360 * d3_radians;
04357 δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
04358 return reset();
04359 };
04360 d3.rebind(projection, projectResample, "precision");
04361 function reset() {
04362 projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
04363 var center = project(λ, φ);
04364 δx = x - center[0] * k;
04365 δy = y + center[1] * k;
04366 return invalidate();
04367 }
04368 function invalidate() {
04369 if (stream) stream.valid = false, stream = null;
04370 return projection;
04371 }
04372 return function() {
04373 project = projectAt.apply(this, arguments);
04374 projection.invert = project.invert && invert;
04375 return reset();
04376 };
04377 }
04378 function d3_geo_projectionRadians(stream) {
04379 return d3_geo_transformPoint(stream, function(x, y) {
04380 stream.point(x * d3_radians, y * d3_radians);
04381 });
04382 }
04383 function d3_geo_equirectangular(λ, φ) {
04384 return [ λ, φ ];
04385 }
04386 (d3.geo.equirectangular = function() {
04387 return d3_geo_projection(d3_geo_equirectangular);
04388 }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
04389 d3.geo.rotation = function(rotate) {
04390 rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
04391 function forward(coordinates) {
04392 coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
04393 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
04394 }
04395 forward.invert = function(coordinates) {
04396 coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
04397 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
04398 };
04399 return forward;
04400 };
04401 function d3_geo_identityRotation(λ, φ) {
04402 return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
04403 }
04404 d3_geo_identityRotation.invert = d3_geo_equirectangular;
04405 function d3_geo_rotation(δλ, δφ, δγ) {
04406 return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
04407 }
04408 function d3_geo_forwardRotationλ(δλ) {
04409 return function(λ, φ) {
04410 return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
04411 };
04412 }
04413 function d3_geo_rotationλ(δλ) {
04414 var rotation = d3_geo_forwardRotationλ(δλ);
04415 rotation.invert = d3_geo_forwardRotationλ(-δλ);
04416 return rotation;
04417 }
04418 function d3_geo_rotationφγ(δφ, δγ) {
04419 var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
04420 function rotation(λ, φ) {
04421 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
04422 return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
04423 }
04424 rotation.invert = function(λ, φ) {
04425 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
04426 return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
04427 };
04428 return rotation;
04429 }
04430 d3.geo.circle = function() {
04431 var origin = [ 0, 0 ], angle, precision = 6, interpolate;
04432 function circle() {
04433 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 = [];
04434 interpolate(null, null, 1, {
04435 point: function(x, y) {
04436 ring.push(x = rotate(x, y));
04437 x[0] *= d3_degrees, x[1] *= d3_degrees;
04438 }
04439 });
04440 return {
04441 type: "Polygon",
04442 coordinates: [ ring ]
04443 };
04444 }
04445 circle.origin = function(x) {
04446 if (!arguments.length) return origin;
04447 origin = x;
04448 return circle;
04449 };
04450 circle.angle = function(x) {
04451 if (!arguments.length) return angle;
04452 interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
04453 return circle;
04454 };
04455 circle.precision = function(_) {
04456 if (!arguments.length) return precision;
04457 interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
04458 return circle;
04459 };
04460 return circle.angle(90);
04461 };
04462 function d3_geo_circleInterpolate(radius, precision) {
04463 var cr = Math.cos(radius), sr = Math.sin(radius);
04464 return function(from, to, direction, listener) {
04465 var step = direction * precision;
04466 if (from != null) {
04467 from = d3_geo_circleAngle(cr, from);
04468 to = d3_geo_circleAngle(cr, to);
04469 if (direction > 0 ? from < to : from > to) from += direction * τ;
04470 } else {
04471 from = radius + direction * τ;
04472 to = radius - .5 * step;
04473 }
04474 for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
04475 listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
04476 }
04477 };
04478 }
04479 function d3_geo_circleAngle(cr, point) {
04480 var a = d3_geo_cartesian(point);
04481 a[0] -= cr;
04482 d3_geo_cartesianNormalize(a);
04483 var angle = d3_acos(-a[1]);
04484 return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
04485 }
04486 d3.geo.distance = function(a, b) {
04487 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;
04488 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Δλ);
04489 };
04490 d3.geo.graticule = function() {
04491 var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
04492 function graticule() {
04493 return {
04494 type: "MultiLineString",
04495 coordinates: lines()
04496 };
04497 }
04498 function lines() {
04499 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) {
04500 return abs(x % DX) > ε;
04501 }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
04502 return abs(y % DY) > ε;
04503 }).map(y));
04504 }
04505 graticule.lines = function() {
04506 return lines().map(function(coordinates) {
04507 return {
04508 type: "LineString",
04509 coordinates: coordinates
04510 };
04511 });
04512 };
04513 graticule.outline = function() {
04514 return {
04515 type: "Polygon",
04516 coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
04517 };
04518 };
04519 graticule.extent = function(_) {
04520 if (!arguments.length) return graticule.minorExtent();
04521 return graticule.majorExtent(_).minorExtent(_);
04522 };
04523 graticule.majorExtent = function(_) {
04524 if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
04525 X0 = +_[0][0], X1 = +_[1][0];
04526 Y0 = +_[0][1], Y1 = +_[1][1];
04527 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
04528 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
04529 return graticule.precision(precision);
04530 };
04531 graticule.minorExtent = function(_) {
04532 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
04533 x0 = +_[0][0], x1 = +_[1][0];
04534 y0 = +_[0][1], y1 = +_[1][1];
04535 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
04536 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
04537 return graticule.precision(precision);
04538 };
04539 graticule.step = function(_) {
04540 if (!arguments.length) return graticule.minorStep();
04541 return graticule.majorStep(_).minorStep(_);
04542 };
04543 graticule.majorStep = function(_) {
04544 if (!arguments.length) return [ DX, DY ];
04545 DX = +_[0], DY = +_[1];
04546 return graticule;
04547 };
04548 graticule.minorStep = function(_) {
04549 if (!arguments.length) return [ dx, dy ];
04550 dx = +_[0], dy = +_[1];
04551 return graticule;
04552 };
04553 graticule.precision = function(_) {
04554 if (!arguments.length) return precision;
04555 precision = +_;
04556 x = d3_geo_graticuleX(y0, y1, 90);
04557 y = d3_geo_graticuleY(x0, x1, precision);
04558 X = d3_geo_graticuleX(Y0, Y1, 90);
04559 Y = d3_geo_graticuleY(X0, X1, precision);
04560 return graticule;
04561 };
04562 return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
04563 };
04564 function d3_geo_graticuleX(y0, y1, dy) {
04565 var y = d3.range(y0, y1 - ε, dy).concat(y1);
04566 return function(x) {
04567 return y.map(function(y) {
04568 return [ x, y ];
04569 });
04570 };
04571 }
04572 function d3_geo_graticuleY(x0, x1, dx) {
04573 var x = d3.range(x0, x1 - ε, dx).concat(x1);
04574 return function(y) {
04575 return x.map(function(x) {
04576 return [ x, y ];
04577 });
04578 };
04579 }
04580 function d3_source(d) {
04581 return d.source;
04582 }
04583 function d3_target(d) {
04584 return d.target;
04585 }
04586 d3.geo.greatArc = function() {
04587 var source = d3_source, source_, target = d3_target, target_;
04588 function greatArc() {
04589 return {
04590 type: "LineString",
04591 coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
04592 };
04593 }
04594 greatArc.distance = function() {
04595 return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
04596 };
04597 greatArc.source = function(_) {
04598 if (!arguments.length) return source;
04599 source = _, source_ = typeof _ === "function" ? null : _;
04600 return greatArc;
04601 };
04602 greatArc.target = function(_) {
04603 if (!arguments.length) return target;
04604 target = _, target_ = typeof _ === "function" ? null : _;
04605 return greatArc;
04606 };
04607 greatArc.precision = function() {
04608 return arguments.length ? greatArc : 0;
04609 };
04610 return greatArc;
04611 };
04612 d3.geo.interpolate = function(source, target) {
04613 return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
04614 };
04615 function d3_geo_interpolate(x0, y0, x1, y1) {
04616 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);
04617 var interpolate = d ? function(t) {
04618 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;
04619 return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
04620 } : function() {
04621 return [ x0 * d3_degrees, y0 * d3_degrees ];
04622 };
04623 interpolate.distance = d;
04624 return interpolate;
04625 }
04626 d3.geo.length = function(object) {
04627 d3_geo_lengthSum = 0;
04628 d3.geo.stream(object, d3_geo_length);
04629 return d3_geo_lengthSum;
04630 };
04631 var d3_geo_lengthSum;
04632 var d3_geo_length = {
04633 sphere: d3_noop,
04634 point: d3_noop,
04635 lineStart: d3_geo_lengthLineStart,
04636 lineEnd: d3_noop,
04637 polygonStart: d3_noop,
04638 polygonEnd: d3_noop
04639 };
04640 function d3_geo_lengthLineStart() {
04641 var λ0, sinφ0, cosφ0;
04642 d3_geo_length.point = function(λ, φ) {
04643 λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
04644 d3_geo_length.point = nextPoint;
04645 };
04646 d3_geo_length.lineEnd = function() {
04647 d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
04648 };
04649 function nextPoint(λ, φ) {
04650 var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
04651 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Δλ);
04652 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
04653 }
04654 }
04655 function d3_geo_azimuthal(scale, angle) {
04656 function azimuthal(λ, φ) {
04657 var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
04658 return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
04659 }
04660 azimuthal.invert = function(x, y) {
04661 var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
04662 return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
04663 };
04664 return azimuthal;
04665 }
04666 var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
04667 return Math.sqrt(2 / (1 + cosλcosφ));
04668 }, function(ρ) {
04669 return 2 * Math.asin(ρ / 2);
04670 });
04671 (d3.geo.azimuthalEqualArea = function() {
04672 return d3_geo_projection(d3_geo_azimuthalEqualArea);
04673 }).raw = d3_geo_azimuthalEqualArea;
04674 var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
04675 var c = Math.acos(cosλcosφ);
04676 return c && c / Math.sin(c);
04677 }, d3_identity);
04678 (d3.geo.azimuthalEquidistant = function() {
04679 return d3_geo_projection(d3_geo_azimuthalEquidistant);
04680 }).raw = d3_geo_azimuthalEquidistant;
04681 function d3_geo_conicConformal(φ0, φ1) {
04682 var cosφ0 = Math.cos(φ0), t = function(φ) {
04683 return Math.tan(π / 4 + φ / 2);
04684 }, 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;
04685 if (!n) return d3_geo_mercator;
04686 function forward(λ, φ) {
04687 if (F > 0) {
04688 if (φ < -halfπ + ε) φ = -halfπ + ε;
04689 } else {
04690 if (φ > halfπ - ε) φ = halfπ - ε;
04691 }
04692 var ρ = F / Math.pow(t(φ), n);
04693 return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
04694 }
04695 forward.invert = function(x, y) {
04696 var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
04697 return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
04698 };
04699 return forward;
04700 }
04701 (d3.geo.conicConformal = function() {
04702 return d3_geo_conic(d3_geo_conicConformal);
04703 }).raw = d3_geo_conicConformal;
04704 function d3_geo_conicEquidistant(φ0, φ1) {
04705 var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
04706 if (abs(n) < ε) return d3_geo_equirectangular;
04707 function forward(λ, φ) {
04708 var ρ = G - φ;
04709 return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
04710 }
04711 forward.invert = function(x, y) {
04712 var ρ0_y = G - y;
04713 return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
04714 };
04715 return forward;
04716 }
04717 (d3.geo.conicEquidistant = function() {
04718 return d3_geo_conic(d3_geo_conicEquidistant);
04719 }).raw = d3_geo_conicEquidistant;
04720 var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
04721 return 1 / cosλcosφ;
04722 }, Math.atan);
04723 (d3.geo.gnomonic = function() {
04724 return d3_geo_projection(d3_geo_gnomonic);
04725 }).raw = d3_geo_gnomonic;
04726 function d3_geo_mercator(λ, φ) {
04727 return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
04728 }
04729 d3_geo_mercator.invert = function(x, y) {
04730 return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
04731 };
04732 function d3_geo_mercatorProjection(project) {
04733 var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
04734 m.scale = function() {
04735 var v = scale.apply(m, arguments);
04736 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
04737 };
04738 m.translate = function() {
04739 var v = translate.apply(m, arguments);
04740 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
04741 };
04742 m.clipExtent = function(_) {
04743 var v = clipExtent.apply(m, arguments);
04744 if (v === m) {
04745 if (clipAuto = _ == null) {
04746 var k = π * scale(), t = translate();
04747 clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
04748 }
04749 } else if (clipAuto) {
04750 v = null;
04751 }
04752 return v;
04753 };
04754 return m.clipExtent(null);
04755 }
04756 (d3.geo.mercator = function() {
04757 return d3_geo_mercatorProjection(d3_geo_mercator);
04758 }).raw = d3_geo_mercator;
04759 var d3_geo_orthographic = d3_geo_azimuthal(function() {
04760 return 1;
04761 }, Math.asin);
04762 (d3.geo.orthographic = function() {
04763 return d3_geo_projection(d3_geo_orthographic);
04764 }).raw = d3_geo_orthographic;
04765 var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
04766 return 1 / (1 + cosλcosφ);
04767 }, function(ρ) {
04768 return 2 * Math.atan(ρ);
04769 });
04770 (d3.geo.stereographic = function() {
04771 return d3_geo_projection(d3_geo_stereographic);
04772 }).raw = d3_geo_stereographic;
04773 function d3_geo_transverseMercator(λ, φ) {
04774 return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
04775 }
04776 d3_geo_transverseMercator.invert = function(x, y) {
04777 return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
04778 };
04779 (d3.geo.transverseMercator = function() {
04780 var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
04781 projection.center = function(_) {
04782 return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
04783 };
04784 projection.rotate = function(_) {
04785 return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
04786 [ _[0], _[1], _[2] - 90 ]);
04787 };
04788 return rotate([ 0, 0, 90 ]);
04789 }).raw = d3_geo_transverseMercator;
04790 d3.geom = {};
04791 function d3_geom_pointX(d) {
04792 return d[0];
04793 }
04794 function d3_geom_pointY(d) {
04795 return d[1];
04796 }
04797 d3.geom.hull = function(vertices) {
04798 var x = d3_geom_pointX, y = d3_geom_pointY;
04799 if (arguments.length) return hull(vertices);
04800 function hull(data) {
04801 if (data.length < 3) return [];
04802 var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
04803 for (i = 0; i < n; i++) {
04804 points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
04805 }
04806 points.sort(d3_geom_hullOrder);
04807 for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
04808 var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
04809 var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
04810 for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
04811 for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
04812 return polygon;
04813 }
04814 hull.x = function(_) {
04815 return arguments.length ? (x = _, hull) : x;
04816 };
04817 hull.y = function(_) {
04818 return arguments.length ? (y = _, hull) : y;
04819 };
04820 return hull;
04821 };
04822 function d3_geom_hullUpper(points) {
04823 var n = points.length, hull = [ 0, 1 ], hs = 2;
04824 for (var i = 2; i < n; i++) {
04825 while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
04826 hull[hs++] = i;
04827 }
04828 return hull.slice(0, hs);
04829 }
04830 function d3_geom_hullOrder(a, b) {
04831 return a[0] - b[0] || a[1] - b[1];
04832 }
04833 d3.geom.polygon = function(coordinates) {
04834 d3_subclass(coordinates, d3_geom_polygonPrototype);
04835 return coordinates;
04836 };
04837 var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
04838 d3_geom_polygonPrototype.area = function() {
04839 var i = -1, n = this.length, a, b = this[n - 1], area = 0;
04840 while (++i < n) {
04841 a = b;
04842 b = this[i];
04843 area += a[1] * b[0] - a[0] * b[1];
04844 }
04845 return area * .5;
04846 };
04847 d3_geom_polygonPrototype.centroid = function(k) {
04848 var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
04849 if (!arguments.length) k = -1 / (6 * this.area());
04850 while (++i < n) {
04851 a = b;
04852 b = this[i];
04853 c = a[0] * b[1] - b[0] * a[1];
04854 x += (a[0] + b[0]) * c;
04855 y += (a[1] + b[1]) * c;
04856 }
04857 return [ x * k, y * k ];
04858 };
04859 d3_geom_polygonPrototype.clip = function(subject) {
04860 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;
04861 while (++i < n) {
04862 input = subject.slice();
04863 subject.length = 0;
04864 b = this[i];
04865 c = input[(m = input.length - closed) - 1];
04866 j = -1;
04867 while (++j < m) {
04868 d = input[j];
04869 if (d3_geom_polygonInside(d, a, b)) {
04870 if (!d3_geom_polygonInside(c, a, b)) {
04871 subject.push(d3_geom_polygonIntersect(c, d, a, b));
04872 }
04873 subject.push(d);
04874 } else if (d3_geom_polygonInside(c, a, b)) {
04875 subject.push(d3_geom_polygonIntersect(c, d, a, b));
04876 }
04877 c = d;
04878 }
04879 if (closed) subject.push(subject[0]);
04880 a = b;
04881 }
04882 return subject;
04883 };
04884 function d3_geom_polygonInside(p, a, b) {
04885 return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
04886 }
04887 function d3_geom_polygonIntersect(c, d, a, b) {
04888 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);
04889 return [ x1 + ua * x21, y1 + ua * y21 ];
04890 }
04891 function d3_geom_polygonClosed(coordinates) {
04892 var a = coordinates[0], b = coordinates[coordinates.length - 1];
04893 return !(a[0] - b[0] || a[1] - b[1]);
04894 }
04895 var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
04896 function d3_geom_voronoiBeach() {
04897 d3_geom_voronoiRedBlackNode(this);
04898 this.edge = this.site = this.circle = null;
04899 }
04900 function d3_geom_voronoiCreateBeach(site) {
04901 var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
04902 beach.site = site;
04903 return beach;
04904 }
04905 function d3_geom_voronoiDetachBeach(beach) {
04906 d3_geom_voronoiDetachCircle(beach);
04907 d3_geom_voronoiBeaches.remove(beach);
04908 d3_geom_voronoiBeachPool.push(beach);
04909 d3_geom_voronoiRedBlackNode(beach);
04910 }
04911 function d3_geom_voronoiRemoveBeach(beach) {
04912 var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
04913 x: x,
04914 y: y
04915 }, previous = beach.P, next = beach.N, disappearing = [ beach ];
04916 d3_geom_voronoiDetachBeach(beach);
04917 var lArc = previous;
04918 while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
04919 previous = lArc.P;
04920 disappearing.unshift(lArc);
04921 d3_geom_voronoiDetachBeach(lArc);
04922 lArc = previous;
04923 }
04924 disappearing.unshift(lArc);
04925 d3_geom_voronoiDetachCircle(lArc);
04926 var rArc = next;
04927 while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
04928 next = rArc.N;
04929 disappearing.push(rArc);
04930 d3_geom_voronoiDetachBeach(rArc);
04931 rArc = next;
04932 }
04933 disappearing.push(rArc);
04934 d3_geom_voronoiDetachCircle(rArc);
04935 var nArcs = disappearing.length, iArc;
04936 for (iArc = 1; iArc < nArcs; ++iArc) {
04937 rArc = disappearing[iArc];
04938 lArc = disappearing[iArc - 1];
04939 d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
04940 }
04941 lArc = disappearing[0];
04942 rArc = disappearing[nArcs - 1];
04943 rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
04944 d3_geom_voronoiAttachCircle(lArc);
04945 d3_geom_voronoiAttachCircle(rArc);
04946 }
04947 function d3_geom_voronoiAddBeach(site) {
04948 var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
04949 while (node) {
04950 dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
04951 if (dxl > ε) node = node.L; else {
04952 dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
04953 if (dxr > ε) {
04954 if (!node.R) {
04955 lArc = node;
04956 break;
04957 }
04958 node = node.R;
04959 } else {
04960 if (dxl > -ε) {
04961 lArc = node.P;
04962 rArc = node;
04963 } else if (dxr > -ε) {
04964 lArc = node;
04965 rArc = node.N;
04966 } else {
04967 lArc = rArc = node;
04968 }
04969 break;
04970 }
04971 }
04972 }
04973 var newArc = d3_geom_voronoiCreateBeach(site);
04974 d3_geom_voronoiBeaches.insert(lArc, newArc);
04975 if (!lArc && !rArc) return;
04976 if (lArc === rArc) {
04977 d3_geom_voronoiDetachCircle(lArc);
04978 rArc = d3_geom_voronoiCreateBeach(lArc.site);
04979 d3_geom_voronoiBeaches.insert(newArc, rArc);
04980 newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
04981 d3_geom_voronoiAttachCircle(lArc);
04982 d3_geom_voronoiAttachCircle(rArc);
04983 return;
04984 }
04985 if (!rArc) {
04986 newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
04987 return;
04988 }
04989 d3_geom_voronoiDetachCircle(lArc);
04990 d3_geom_voronoiDetachCircle(rArc);
04991 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 = {
04992 x: (cy * hb - by * hc) / d + ax,
04993 y: (bx * hc - cx * hb) / d + ay
04994 };
04995 d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
04996 newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
04997 rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
04998 d3_geom_voronoiAttachCircle(lArc);
04999 d3_geom_voronoiAttachCircle(rArc);
05000 }
05001 function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
05002 var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
05003 if (!pby2) return rfocx;
05004 var lArc = arc.P;
05005 if (!lArc) return -Infinity;
05006 site = lArc.site;
05007 var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
05008 if (!plby2) return lfocx;
05009 var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
05010 if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
05011 return (rfocx + lfocx) / 2;
05012 }
05013 function d3_geom_voronoiRightBreakPoint(arc, directrix) {
05014 var rArc = arc.N;
05015 if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
05016 var site = arc.site;
05017 return site.y === directrix ? site.x : Infinity;
05018 }
05019 function d3_geom_voronoiCell(site) {
05020 this.site = site;
05021 this.edges = [];
05022 }
05023 d3_geom_voronoiCell.prototype.prepare = function() {
05024 var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
05025 while (iHalfEdge--) {
05026 edge = halfEdges[iHalfEdge].edge;
05027 if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
05028 }
05029 halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
05030 return halfEdges.length;
05031 };
05032 function d3_geom_voronoiCloseCells(extent) {
05033 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;
05034 while (iCell--) {
05035 cell = cells[iCell];
05036 if (!cell || !cell.prepare()) continue;
05037 halfEdges = cell.edges;
05038 nHalfEdges = halfEdges.length;
05039 iHalfEdge = 0;
05040 while (iHalfEdge < nHalfEdges) {
05041 end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
05042 start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
05043 if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
05044 halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
05045 x: x0,
05046 y: abs(x2 - x0) < ε ? y2 : y1
05047 } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
05048 x: abs(y2 - y1) < ε ? x2 : x1,
05049 y: y1
05050 } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
05051 x: x1,
05052 y: abs(x2 - x1) < ε ? y2 : y0
05053 } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
05054 x: abs(y2 - y0) < ε ? x2 : x0,
05055 y: y0
05056 } : null), cell.site, null));
05057 ++nHalfEdges;
05058 }
05059 }
05060 }
05061 }
05062 function d3_geom_voronoiHalfEdgeOrder(a, b) {
05063 return b.angle - a.angle;
05064 }
05065 function d3_geom_voronoiCircle() {
05066 d3_geom_voronoiRedBlackNode(this);
05067 this.x = this.y = this.arc = this.site = this.cy = null;
05068 }
05069 function d3_geom_voronoiAttachCircle(arc) {
05070 var lArc = arc.P, rArc = arc.N;
05071 if (!lArc || !rArc) return;
05072 var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
05073 if (lSite === rSite) return;
05074 var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
05075 var d = 2 * (ax * cy - ay * cx);
05076 if (d >= -ε2) return;
05077 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;
05078 var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
05079 circle.arc = arc;
05080 circle.site = cSite;
05081 circle.x = x + bx;
05082 circle.y = cy + Math.sqrt(x * x + y * y);
05083 circle.cy = cy;
05084 arc.circle = circle;
05085 var before = null, node = d3_geom_voronoiCircles._;
05086 while (node) {
05087 if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
05088 if (node.L) node = node.L; else {
05089 before = node.P;
05090 break;
05091 }
05092 } else {
05093 if (node.R) node = node.R; else {
05094 before = node;
05095 break;
05096 }
05097 }
05098 }
05099 d3_geom_voronoiCircles.insert(before, circle);
05100 if (!before) d3_geom_voronoiFirstCircle = circle;
05101 }
05102 function d3_geom_voronoiDetachCircle(arc) {
05103 var circle = arc.circle;
05104 if (circle) {
05105 if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
05106 d3_geom_voronoiCircles.remove(circle);
05107 d3_geom_voronoiCirclePool.push(circle);
05108 d3_geom_voronoiRedBlackNode(circle);
05109 arc.circle = null;
05110 }
05111 }
05112 function d3_geom_voronoiClipEdges(extent) {
05113 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;
05114 while (i--) {
05115 e = edges[i];
05116 if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
05117 e.a = e.b = null;
05118 edges.splice(i, 1);
05119 }
05120 }
05121 }
05122 function d3_geom_voronoiConnectEdge(edge, extent) {
05123 var vb = edge.b;
05124 if (vb) return true;
05125 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;
05126 if (ry === ly) {
05127 if (fx < x0 || fx >= x1) return;
05128 if (lx > rx) {
05129 if (!va) va = {
05130 x: fx,
05131 y: y0
05132 }; else if (va.y >= y1) return;
05133 vb = {
05134 x: fx,
05135 y: y1
05136 };
05137 } else {
05138 if (!va) va = {
05139 x: fx,
05140 y: y1
05141 }; else if (va.y < y0) return;
05142 vb = {
05143 x: fx,
05144 y: y0
05145 };
05146 }
05147 } else {
05148 fm = (lx - rx) / (ry - ly);
05149 fb = fy - fm * fx;
05150 if (fm < -1 || fm > 1) {
05151 if (lx > rx) {
05152 if (!va) va = {
05153 x: (y0 - fb) / fm,
05154 y: y0
05155 }; else if (va.y >= y1) return;
05156 vb = {
05157 x: (y1 - fb) / fm,
05158 y: y1
05159 };
05160 } else {
05161 if (!va) va = {
05162 x: (y1 - fb) / fm,
05163 y: y1
05164 }; else if (va.y < y0) return;
05165 vb = {
05166 x: (y0 - fb) / fm,
05167 y: y0
05168 };
05169 }
05170 } else {
05171 if (ly < ry) {
05172 if (!va) va = {
05173 x: x0,
05174 y: fm * x0 + fb
05175 }; else if (va.x >= x1) return;
05176 vb = {
05177 x: x1,
05178 y: fm * x1 + fb
05179 };
05180 } else {
05181 if (!va) va = {
05182 x: x1,
05183 y: fm * x1 + fb
05184 }; else if (va.x < x0) return;
05185 vb = {
05186 x: x0,
05187 y: fm * x0 + fb
05188 };
05189 }
05190 }
05191 }
05192 edge.a = va;
05193 edge.b = vb;
05194 return true;
05195 }
05196 function d3_geom_voronoiEdge(lSite, rSite) {
05197 this.l = lSite;
05198 this.r = rSite;
05199 this.a = this.b = null;
05200 }
05201 function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
05202 var edge = new d3_geom_voronoiEdge(lSite, rSite);
05203 d3_geom_voronoiEdges.push(edge);
05204 if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
05205 if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
05206 d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
05207 d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
05208 return edge;
05209 }
05210 function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
05211 var edge = new d3_geom_voronoiEdge(lSite, null);
05212 edge.a = va;
05213 edge.b = vb;
05214 d3_geom_voronoiEdges.push(edge);
05215 return edge;
05216 }
05217 function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
05218 if (!edge.a && !edge.b) {
05219 edge.a = vertex;
05220 edge.l = lSite;
05221 edge.r = rSite;
05222 } else if (edge.l === rSite) {
05223 edge.b = vertex;
05224 } else {
05225 edge.a = vertex;
05226 }
05227 }
05228 function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
05229 var va = edge.a, vb = edge.b;
05230 this.edge = edge;
05231 this.site = lSite;
05232 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);
05233 }
05234 d3_geom_voronoiHalfEdge.prototype = {
05235 start: function() {
05236 return this.edge.l === this.site ? this.edge.a : this.edge.b;
05237 },
05238 end: function() {
05239 return this.edge.l === this.site ? this.edge.b : this.edge.a;
05240 }
05241 };
05242 function d3_geom_voronoiRedBlackTree() {
05243 this._ = null;
05244 }
05245 function d3_geom_voronoiRedBlackNode(node) {
05246 node.U = node.C = node.L = node.R = node.P = node.N = null;
05247 }
05248 d3_geom_voronoiRedBlackTree.prototype = {
05249 insert: function(after, node) {
05250 var parent, grandpa, uncle;
05251 if (after) {
05252 node.P = after;
05253 node.N = after.N;
05254 if (after.N) after.N.P = node;
05255 after.N = node;
05256 if (after.R) {
05257 after = after.R;
05258 while (after.L) after = after.L;
05259 after.L = node;
05260 } else {
05261 after.R = node;
05262 }
05263 parent = after;
05264 } else if (this._) {
05265 after = d3_geom_voronoiRedBlackFirst(this._);
05266 node.P = null;
05267 node.N = after;
05268 after.P = after.L = node;
05269 parent = after;
05270 } else {
05271 node.P = node.N = null;
05272 this._ = node;
05273 parent = null;
05274 }
05275 node.L = node.R = null;
05276 node.U = parent;
05277 node.C = true;
05278 after = node;
05279 while (parent && parent.C) {
05280 grandpa = parent.U;
05281 if (parent === grandpa.L) {
05282 uncle = grandpa.R;
05283 if (uncle && uncle.C) {
05284 parent.C = uncle.C = false;
05285 grandpa.C = true;
05286 after = grandpa;
05287 } else {
05288 if (after === parent.R) {
05289 d3_geom_voronoiRedBlackRotateLeft(this, parent);
05290 after = parent;
05291 parent = after.U;
05292 }
05293 parent.C = false;
05294 grandpa.C = true;
05295 d3_geom_voronoiRedBlackRotateRight(this, grandpa);
05296 }
05297 } else {
05298 uncle = grandpa.L;
05299 if (uncle && uncle.C) {
05300 parent.C = uncle.C = false;
05301 grandpa.C = true;
05302 after = grandpa;
05303 } else {
05304 if (after === parent.L) {
05305 d3_geom_voronoiRedBlackRotateRight(this, parent);
05306 after = parent;
05307 parent = after.U;
05308 }
05309 parent.C = false;
05310 grandpa.C = true;
05311 d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
05312 }
05313 }
05314 parent = after.U;
05315 }
05316 this._.C = false;
05317 },
05318 remove: function(node) {
05319 if (node.N) node.N.P = node.P;
05320 if (node.P) node.P.N = node.N;
05321 node.N = node.P = null;
05322 var parent = node.U, sibling, left = node.L, right = node.R, next, red;
05323 if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
05324 if (parent) {
05325 if (parent.L === node) parent.L = next; else parent.R = next;
05326 } else {
05327 this._ = next;
05328 }
05329 if (left && right) {
05330 red = next.C;
05331 next.C = node.C;
05332 next.L = left;
05333 left.U = next;
05334 if (next !== right) {
05335 parent = next.U;
05336 next.U = node.U;
05337 node = next.R;
05338 parent.L = node;
05339 next.R = right;
05340 right.U = next;
05341 } else {
05342 next.U = parent;
05343 parent = next;
05344 node = next.R;
05345 }
05346 } else {
05347 red = node.C;
05348 node = next;
05349 }
05350 if (node) node.U = parent;
05351 if (red) return;
05352 if (node && node.C) {
05353 node.C = false;
05354 return;
05355 }
05356 do {
05357 if (node === this._) break;
05358 if (node === parent.L) {
05359 sibling = parent.R;
05360 if (sibling.C) {
05361 sibling.C = false;
05362 parent.C = true;
05363 d3_geom_voronoiRedBlackRotateLeft(this, parent);
05364 sibling = parent.R;
05365 }
05366 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
05367 if (!sibling.R || !sibling.R.C) {
05368 sibling.L.C = false;
05369 sibling.C = true;
05370 d3_geom_voronoiRedBlackRotateRight(this, sibling);
05371 sibling = parent.R;
05372 }
05373 sibling.C = parent.C;
05374 parent.C = sibling.R.C = false;
05375 d3_geom_voronoiRedBlackRotateLeft(this, parent);
05376 node = this._;
05377 break;
05378 }
05379 } else {
05380 sibling = parent.L;
05381 if (sibling.C) {
05382 sibling.C = false;
05383 parent.C = true;
05384 d3_geom_voronoiRedBlackRotateRight(this, parent);
05385 sibling = parent.L;
05386 }
05387 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
05388 if (!sibling.L || !sibling.L.C) {
05389 sibling.R.C = false;
05390 sibling.C = true;
05391 d3_geom_voronoiRedBlackRotateLeft(this, sibling);
05392 sibling = parent.L;
05393 }
05394 sibling.C = parent.C;
05395 parent.C = sibling.L.C = false;
05396 d3_geom_voronoiRedBlackRotateRight(this, parent);
05397 node = this._;
05398 break;
05399 }
05400 }
05401 sibling.C = true;
05402 node = parent;
05403 parent = parent.U;
05404 } while (!node.C);
05405 if (node) node.C = false;
05406 }
05407 };
05408 function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
05409 var p = node, q = node.R, parent = p.U;
05410 if (parent) {
05411 if (parent.L === p) parent.L = q; else parent.R = q;
05412 } else {
05413 tree._ = q;
05414 }
05415 q.U = parent;
05416 p.U = q;
05417 p.R = q.L;
05418 if (p.R) p.R.U = p;
05419 q.L = p;
05420 }
05421 function d3_geom_voronoiRedBlackRotateRight(tree, node) {
05422 var p = node, q = node.L, parent = p.U;
05423 if (parent) {
05424 if (parent.L === p) parent.L = q; else parent.R = q;
05425 } else {
05426 tree._ = q;
05427 }
05428 q.U = parent;
05429 p.U = q;
05430 p.L = q.R;
05431 if (p.L) p.L.U = p;
05432 q.R = p;
05433 }
05434 function d3_geom_voronoiRedBlackFirst(node) {
05435 while (node.L) node = node.L;
05436 return node;
05437 }
05438 function d3_geom_voronoi(sites, bbox) {
05439 var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
05440 d3_geom_voronoiEdges = [];
05441 d3_geom_voronoiCells = new Array(sites.length);
05442 d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
05443 d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
05444 while (true) {
05445 circle = d3_geom_voronoiFirstCircle;
05446 if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
05447 if (site.x !== x0 || site.y !== y0) {
05448 d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
05449 d3_geom_voronoiAddBeach(site);
05450 x0 = site.x, y0 = site.y;
05451 }
05452 site = sites.pop();
05453 } else if (circle) {
05454 d3_geom_voronoiRemoveBeach(circle.arc);
05455 } else {
05456 break;
05457 }
05458 }
05459 if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
05460 var diagram = {
05461 cells: d3_geom_voronoiCells,
05462 edges: d3_geom_voronoiEdges
05463 };
05464 d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
05465 return diagram;
05466 }
05467 function d3_geom_voronoiVertexOrder(a, b) {
05468 return b.y - a.y || b.x - a.x;
05469 }
05470 d3.geom.voronoi = function(points) {
05471 var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
05472 if (points) return voronoi(points);
05473 function voronoi(data) {
05474 var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
05475 d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
05476 var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
05477 var s = e.start();
05478 return [ s.x, s.y ];
05479 }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
05480 polygon.point = data[i];
05481 });
05482 return polygons;
05483 }
05484 function sites(data) {
05485 return data.map(function(d, i) {
05486 return {
05487 x: Math.round(fx(d, i) / ε) * ε,
05488 y: Math.round(fy(d, i) / ε) * ε,
05489 i: i
05490 };
05491 });
05492 }
05493 voronoi.links = function(data) {
05494 return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
05495 return edge.l && edge.r;
05496 }).map(function(edge) {
05497 return {
05498 source: data[edge.l.i],
05499 target: data[edge.r.i]
05500 };
05501 });
05502 };
05503 voronoi.triangles = function(data) {
05504 var triangles = [];
05505 d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
05506 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;
05507 while (++j < m) {
05508 e0 = e1;
05509 s0 = s1;
05510 e1 = edges[j].edge;
05511 s1 = e1.l === site ? e1.r : e1.l;
05512 if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
05513 triangles.push([ data[i], data[s0.i], data[s1.i] ]);
05514 }
05515 }
05516 });
05517 return triangles;
05518 };
05519 voronoi.x = function(_) {
05520 return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
05521 };
05522 voronoi.y = function(_) {
05523 return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
05524 };
05525 voronoi.clipExtent = function(_) {
05526 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
05527 clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
05528 return voronoi;
05529 };
05530 voronoi.size = function(_) {
05531 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
05532 return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
05533 };
05534 return voronoi;
05535 };
05536 var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
05537 function d3_geom_voronoiTriangleArea(a, b, c) {
05538 return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
05539 }
05540 d3.geom.delaunay = function(vertices) {
05541 return d3.geom.voronoi().triangles(vertices);
05542 };
05543 d3.geom.quadtree = function(points, x1, y1, x2, y2) {
05544 var x = d3_geom_pointX, y = d3_geom_pointY, compat;
05545 if (compat = arguments.length) {
05546 x = d3_geom_quadtreeCompatX;
05547 y = d3_geom_quadtreeCompatY;
05548 if (compat === 3) {
05549 y2 = y1;
05550 x2 = x1;
05551 y1 = x1 = 0;
05552 }
05553 return quadtree(points);
05554 }
05555 function quadtree(data) {
05556 var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
05557 if (x1 != null) {
05558 x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
05559 } else {
05560 x2_ = y2_ = -(x1_ = y1_ = Infinity);
05561 xs = [], ys = [];
05562 n = data.length;
05563 if (compat) for (i = 0; i < n; ++i) {
05564 d = data[i];
05565 if (d.x < x1_) x1_ = d.x;
05566 if (d.y < y1_) y1_ = d.y;
05567 if (d.x > x2_) x2_ = d.x;
05568 if (d.y > y2_) y2_ = d.y;
05569 xs.push(d.x);
05570 ys.push(d.y);
05571 } else for (i = 0; i < n; ++i) {
05572 var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
05573 if (x_ < x1_) x1_ = x_;
05574 if (y_ < y1_) y1_ = y_;
05575 if (x_ > x2_) x2_ = x_;
05576 if (y_ > y2_) y2_ = y_;
05577 xs.push(x_);
05578 ys.push(y_);
05579 }
05580 }
05581 var dx = x2_ - x1_, dy = y2_ - y1_;
05582 if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
05583 function insert(n, d, x, y, x1, y1, x2, y2) {
05584 if (isNaN(x) || isNaN(y)) return;
05585 if (n.leaf) {
05586 var nx = n.x, ny = n.y;
05587 if (nx != null) {
05588 if (abs(nx - x) + abs(ny - y) < .01) {
05589 insertChild(n, d, x, y, x1, y1, x2, y2);
05590 } else {
05591 var nPoint = n.point;
05592 n.x = n.y = n.point = null;
05593 insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
05594 insertChild(n, d, x, y, x1, y1, x2, y2);
05595 }
05596 } else {
05597 n.x = x, n.y = y, n.point = d;
05598 }
05599 } else {
05600 insertChild(n, d, x, y, x1, y1, x2, y2);
05601 }
05602 }
05603 function insertChild(n, d, x, y, x1, y1, x2, y2) {
05604 var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
05605 n.leaf = false;
05606 n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
05607 if (right) x1 = xm; else x2 = xm;
05608 if (below) y1 = ym; else y2 = ym;
05609 insert(n, d, x, y, x1, y1, x2, y2);
05610 }
05611 var root = d3_geom_quadtreeNode();
05612 root.add = function(d) {
05613 insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
05614 };
05615 root.visit = function(f) {
05616 d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
05617 };
05618 root.find = function(point) {
05619 return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
05620 };
05621 i = -1;
05622 if (x1 == null) {
05623 while (++i < n) {
05624 insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
05625 }
05626 --i;
05627 } else data.forEach(root.add);
05628 xs = ys = data = d = null;
05629 return root;
05630 }
05631 quadtree.x = function(_) {
05632 return arguments.length ? (x = _, quadtree) : x;
05633 };
05634 quadtree.y = function(_) {
05635 return arguments.length ? (y = _, quadtree) : y;
05636 };
05637 quadtree.extent = function(_) {
05638 if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
05639 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
05640 y2 = +_[1][1];
05641 return quadtree;
05642 };
05643 quadtree.size = function(_) {
05644 if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
05645 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
05646 return quadtree;
05647 };
05648 return quadtree;
05649 };
05650 function d3_geom_quadtreeCompatX(d) {
05651 return d.x;
05652 }
05653 function d3_geom_quadtreeCompatY(d) {
05654 return d.y;
05655 }
05656 function d3_geom_quadtreeNode() {
05657 return {
05658 leaf: true,
05659 nodes: [],
05660 point: null,
05661 x: null,
05662 y: null
05663 };
05664 }
05665 function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
05666 if (!f(node, x1, y1, x2, y2)) {
05667 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
05668 if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
05669 if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
05670 if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
05671 if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
05672 }
05673 }
05674 function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
05675 var minDistance2 = Infinity, closestPoint;
05676 (function find(node, x1, y1, x2, y2) {
05677 if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
05678 if (point = node.point) {
05679 var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
05680 if (distance2 < minDistance2) {
05681 var distance = Math.sqrt(minDistance2 = distance2);
05682 x0 = x - distance, y0 = y - distance;
05683 x3 = x + distance, y3 = y + distance;
05684 closestPoint = point;
05685 }
05686 }
05687 var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
05688 for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
05689 if (node = children[i & 3]) switch (i & 3) {
05690 case 0:
05691 find(node, x1, y1, xm, ym);
05692 break;
05693
05694 case 1:
05695 find(node, xm, y1, x2, ym);
05696 break;
05697
05698 case 2:
05699 find(node, x1, ym, xm, y2);
05700 break;
05701
05702 case 3:
05703 find(node, xm, ym, x2, y2);
05704 break;
05705 }
05706 }
05707 })(root, x0, y0, x3, y3);
05708 return closestPoint;
05709 }
05710 d3.interpolateRgb = d3_interpolateRgb;
05711 function d3_interpolateRgb(a, b) {
05712 a = d3.rgb(a);
05713 b = d3.rgb(b);
05714 var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
05715 return function(t) {
05716 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));
05717 };
05718 }
05719 d3.interpolateObject = d3_interpolateObject;
05720 function d3_interpolateObject(a, b) {
05721 var i = {}, c = {}, k;
05722 for (k in a) {
05723 if (k in b) {
05724 i[k] = d3_interpolate(a[k], b[k]);
05725 } else {
05726 c[k] = a[k];
05727 }
05728 }
05729 for (k in b) {
05730 if (!(k in a)) {
05731 c[k] = b[k];
05732 }
05733 }
05734 return function(t) {
05735 for (k in i) c[k] = i[k](t);
05736 return c;
05737 };
05738 }
05739 d3.interpolateNumber = d3_interpolateNumber;
05740 function d3_interpolateNumber(a, b) {
05741 a = +a, b = +b;
05742 return function(t) {
05743 return a * (1 - t) + b * t;
05744 };
05745 }
05746 d3.interpolateString = d3_interpolateString;
05747 function d3_interpolateString(a, b) {
05748 var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
05749 a = a + "", b = b + "";
05750 while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
05751 if ((bs = bm.index) > bi) {
05752 bs = b.slice(bi, bs);
05753 if (s[i]) s[i] += bs; else s[++i] = bs;
05754 }
05755 if ((am = am[0]) === (bm = bm[0])) {
05756 if (s[i]) s[i] += bm; else s[++i] = bm;
05757 } else {
05758 s[++i] = null;
05759 q.push({
05760 i: i,
05761 x: d3_interpolateNumber(am, bm)
05762 });
05763 }
05764 bi = d3_interpolate_numberB.lastIndex;
05765 }
05766 if (bi < b.length) {
05767 bs = b.slice(bi);
05768 if (s[i]) s[i] += bs; else s[++i] = bs;
05769 }
05770 return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
05771 return b(t) + "";
05772 }) : function() {
05773 return b;
05774 } : (b = q.length, function(t) {
05775 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
05776 return s.join("");
05777 });
05778 }
05779 var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
05780 d3.interpolate = d3_interpolate;
05781 function d3_interpolate(a, b) {
05782 var i = d3.interpolators.length, f;
05783 while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
05784 return f;
05785 }
05786 d3.interpolators = [ function(a, b) {
05787 var t = typeof b;
05788 return (t === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b);
05789 } ];
05790 d3.interpolateArray = d3_interpolateArray;
05791 function d3_interpolateArray(a, b) {
05792 var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
05793 for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
05794 for (;i < na; ++i) c[i] = a[i];
05795 for (;i < nb; ++i) c[i] = b[i];
05796 return function(t) {
05797 for (i = 0; i < n0; ++i) c[i] = x[i](t);
05798 return c;
05799 };
05800 }
05801 var d3_ease_default = function() {
05802 return d3_identity;
05803 };
05804 var d3_ease = d3.map({
05805 linear: d3_ease_default,
05806 poly: d3_ease_poly,
05807 quad: function() {
05808 return d3_ease_quad;
05809 },
05810 cubic: function() {
05811 return d3_ease_cubic;
05812 },
05813 sin: function() {
05814 return d3_ease_sin;
05815 },
05816 exp: function() {
05817 return d3_ease_exp;
05818 },
05819 circle: function() {
05820 return d3_ease_circle;
05821 },
05822 elastic: d3_ease_elastic,
05823 back: d3_ease_back,
05824 bounce: function() {
05825 return d3_ease_bounce;
05826 }
05827 });
05828 var d3_ease_mode = d3.map({
05829 "in": d3_identity,
05830 out: d3_ease_reverse,
05831 "in-out": d3_ease_reflect,
05832 "out-in": function(f) {
05833 return d3_ease_reflect(d3_ease_reverse(f));
05834 }
05835 });
05836 d3.ease = function(name) {
05837 var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
05838 t = d3_ease.get(t) || d3_ease_default;
05839 m = d3_ease_mode.get(m) || d3_identity;
05840 return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
05841 };
05842 function d3_ease_clamp(f) {
05843 return function(t) {
05844 return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
05845 };
05846 }
05847 function d3_ease_reverse(f) {
05848 return function(t) {
05849 return 1 - f(1 - t);
05850 };
05851 }
05852 function d3_ease_reflect(f) {
05853 return function(t) {
05854 return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
05855 };
05856 }
05857 function d3_ease_quad(t) {
05858 return t * t;
05859 }
05860 function d3_ease_cubic(t) {
05861 return t * t * t;
05862 }
05863 function d3_ease_cubicInOut(t) {
05864 if (t <= 0) return 0;
05865 if (t >= 1) return 1;
05866 var t2 = t * t, t3 = t2 * t;
05867 return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
05868 }
05869 function d3_ease_poly(e) {
05870 return function(t) {
05871 return Math.pow(t, e);
05872 };
05873 }
05874 function d3_ease_sin(t) {
05875 return 1 - Math.cos(t * halfπ);
05876 }
05877 function d3_ease_exp(t) {
05878 return Math.pow(2, 10 * (t - 1));
05879 }
05880 function d3_ease_circle(t) {
05881 return 1 - Math.sqrt(1 - t * t);
05882 }
05883 function d3_ease_elastic(a, p) {
05884 var s;
05885 if (arguments.length < 2) p = .45;
05886 if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
05887 return function(t) {
05888 return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
05889 };
05890 }
05891 function d3_ease_back(s) {
05892 if (!s) s = 1.70158;
05893 return function(t) {
05894 return t * t * ((s + 1) * t - s);
05895 };
05896 }
05897 function d3_ease_bounce(t) {
05898 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;
05899 }
05900 d3.interpolateHcl = d3_interpolateHcl;
05901 function d3_interpolateHcl(a, b) {
05902 a = d3.hcl(a);
05903 b = d3.hcl(b);
05904 var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
05905 if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
05906 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
05907 return function(t) {
05908 return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
05909 };
05910 }
05911 d3.interpolateHsl = d3_interpolateHsl;
05912 function d3_interpolateHsl(a, b) {
05913 a = d3.hsl(a);
05914 b = d3.hsl(b);
05915 var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
05916 if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
05917 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
05918 return function(t) {
05919 return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
05920 };
05921 }
05922 d3.interpolateLab = d3_interpolateLab;
05923 function d3_interpolateLab(a, b) {
05924 a = d3.lab(a);
05925 b = d3.lab(b);
05926 var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
05927 return function(t) {
05928 return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
05929 };
05930 }
05931 d3.interpolateRound = d3_interpolateRound;
05932 function d3_interpolateRound(a, b) {
05933 b -= a;
05934 return function(t) {
05935 return Math.round(a + b * t);
05936 };
05937 }
05938 d3.transform = function(string) {
05939 var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
05940 return (d3.transform = function(string) {
05941 if (string != null) {
05942 g.setAttribute("transform", string);
05943 var t = g.transform.baseVal.consolidate();
05944 }
05945 return new d3_transform(t ? t.matrix : d3_transformIdentity);
05946 })(string);
05947 };
05948 function d3_transform(m) {
05949 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;
05950 if (r0[0] * r1[1] < r1[0] * r0[1]) {
05951 r0[0] *= -1;
05952 r0[1] *= -1;
05953 kx *= -1;
05954 kz *= -1;
05955 }
05956 this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
05957 this.translate = [ m.e, m.f ];
05958 this.scale = [ kx, ky ];
05959 this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
05960 }
05961 d3_transform.prototype.toString = function() {
05962 return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
05963 };
05964 function d3_transformDot(a, b) {
05965 return a[0] * b[0] + a[1] * b[1];
05966 }
05967 function d3_transformNormalize(a) {
05968 var k = Math.sqrt(d3_transformDot(a, a));
05969 if (k) {
05970 a[0] /= k;
05971 a[1] /= k;
05972 }
05973 return k;
05974 }
05975 function d3_transformCombine(a, b, k) {
05976 a[0] += k * b[0];
05977 a[1] += k * b[1];
05978 return a;
05979 }
05980 var d3_transformIdentity = {
05981 a: 1,
05982 b: 0,
05983 c: 0,
05984 d: 1,
05985 e: 0,
05986 f: 0
05987 };
05988 d3.interpolateTransform = d3_interpolateTransform;
05989 function d3_interpolateTransform(a, b) {
05990 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;
05991 if (ta[0] != tb[0] || ta[1] != tb[1]) {
05992 s.push("translate(", null, ",", null, ")");
05993 q.push({
05994 i: 1,
05995 x: d3_interpolateNumber(ta[0], tb[0])
05996 }, {
05997 i: 3,
05998 x: d3_interpolateNumber(ta[1], tb[1])
05999 });
06000 } else if (tb[0] || tb[1]) {
06001 s.push("translate(" + tb + ")");
06002 } else {
06003 s.push("");
06004 }
06005 if (ra != rb) {
06006 if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
06007 q.push({
06008 i: s.push(s.pop() + "rotate(", null, ")") - 2,
06009 x: d3_interpolateNumber(ra, rb)
06010 });
06011 } else if (rb) {
06012 s.push(s.pop() + "rotate(" + rb + ")");
06013 }
06014 if (wa != wb) {
06015 q.push({
06016 i: s.push(s.pop() + "skewX(", null, ")") - 2,
06017 x: d3_interpolateNumber(wa, wb)
06018 });
06019 } else if (wb) {
06020 s.push(s.pop() + "skewX(" + wb + ")");
06021 }
06022 if (ka[0] != kb[0] || ka[1] != kb[1]) {
06023 n = s.push(s.pop() + "scale(", null, ",", null, ")");
06024 q.push({
06025 i: n - 4,
06026 x: d3_interpolateNumber(ka[0], kb[0])
06027 }, {
06028 i: n - 2,
06029 x: d3_interpolateNumber(ka[1], kb[1])
06030 });
06031 } else if (kb[0] != 1 || kb[1] != 1) {
06032 s.push(s.pop() + "scale(" + kb + ")");
06033 }
06034 n = q.length;
06035 return function(t) {
06036 var i = -1, o;
06037 while (++i < n) s[(o = q[i]).i] = o.x(t);
06038 return s.join("");
06039 };
06040 }
06041 function d3_uninterpolateNumber(a, b) {
06042 b = (b -= a = +a) || 1 / b;
06043 return function(x) {
06044 return (x - a) / b;
06045 };
06046 }
06047 function d3_uninterpolateClamp(a, b) {
06048 b = (b -= a = +a) || 1 / b;
06049 return function(x) {
06050 return Math.max(0, Math.min(1, (x - a) / b));
06051 };
06052 }
06053 d3.layout = {};
06054 d3.layout.bundle = function() {
06055 return function(links) {
06056 var paths = [], i = -1, n = links.length;
06057 while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
06058 return paths;
06059 };
06060 };
06061 function d3_layout_bundlePath(link) {
06062 var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
06063 while (start !== lca) {
06064 start = start.parent;
06065 points.push(start);
06066 }
06067 var k = points.length;
06068 while (end !== lca) {
06069 points.splice(k, 0, end);
06070 end = end.parent;
06071 }
06072 return points;
06073 }
06074 function d3_layout_bundleAncestors(node) {
06075 var ancestors = [], parent = node.parent;
06076 while (parent != null) {
06077 ancestors.push(node);
06078 node = parent;
06079 parent = parent.parent;
06080 }
06081 ancestors.push(node);
06082 return ancestors;
06083 }
06084 function d3_layout_bundleLeastCommonAncestor(a, b) {
06085 if (a === b) return a;
06086 var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
06087 while (aNode === bNode) {
06088 sharedNode = aNode;
06089 aNode = aNodes.pop();
06090 bNode = bNodes.pop();
06091 }
06092 return sharedNode;
06093 }
06094 d3.layout.chord = function() {
06095 var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
06096 function relayout() {
06097 var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
06098 chords = [];
06099 groups = [];
06100 k = 0, i = -1;
06101 while (++i < n) {
06102 x = 0, j = -1;
06103 while (++j < n) {
06104 x += matrix[i][j];
06105 }
06106 groupSums.push(x);
06107 subgroupIndex.push(d3.range(n));
06108 k += x;
06109 }
06110 if (sortGroups) {
06111 groupIndex.sort(function(a, b) {
06112 return sortGroups(groupSums[a], groupSums[b]);
06113 });
06114 }
06115 if (sortSubgroups) {
06116 subgroupIndex.forEach(function(d, i) {
06117 d.sort(function(a, b) {
06118 return sortSubgroups(matrix[i][a], matrix[i][b]);
06119 });
06120 });
06121 }
06122 k = (τ - padding * n) / k;
06123 x = 0, i = -1;
06124 while (++i < n) {
06125 x0 = x, j = -1;
06126 while (++j < n) {
06127 var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
06128 subgroups[di + "-" + dj] = {
06129 index: di,
06130 subindex: dj,
06131 startAngle: a0,
06132 endAngle: a1,
06133 value: v
06134 };
06135 }
06136 groups[di] = {
06137 index: di,
06138 startAngle: x0,
06139 endAngle: x,
06140 value: (x - x0) / k
06141 };
06142 x += padding;
06143 }
06144 i = -1;
06145 while (++i < n) {
06146 j = i - 1;
06147 while (++j < n) {
06148 var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
06149 if (source.value || target.value) {
06150 chords.push(source.value < target.value ? {
06151 source: target,
06152 target: source
06153 } : {
06154 source: source,
06155 target: target
06156 });
06157 }
06158 }
06159 }
06160 if (sortChords) resort();
06161 }
06162 function resort() {
06163 chords.sort(function(a, b) {
06164 return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
06165 });
06166 }
06167 chord.matrix = function(x) {
06168 if (!arguments.length) return matrix;
06169 n = (matrix = x) && matrix.length;
06170 chords = groups = null;
06171 return chord;
06172 };
06173 chord.padding = function(x) {
06174 if (!arguments.length) return padding;
06175 padding = x;
06176 chords = groups = null;
06177 return chord;
06178 };
06179 chord.sortGroups = function(x) {
06180 if (!arguments.length) return sortGroups;
06181 sortGroups = x;
06182 chords = groups = null;
06183 return chord;
06184 };
06185 chord.sortSubgroups = function(x) {
06186 if (!arguments.length) return sortSubgroups;
06187 sortSubgroups = x;
06188 chords = null;
06189 return chord;
06190 };
06191 chord.sortChords = function(x) {
06192 if (!arguments.length) return sortChords;
06193 sortChords = x;
06194 if (chords) resort();
06195 return chord;
06196 };
06197 chord.chords = function() {
06198 if (!chords) relayout();
06199 return chords;
06200 };
06201 chord.groups = function() {
06202 if (!groups) relayout();
06203 return groups;
06204 };
06205 return chord;
06206 };
06207 d3.layout.force = function() {
06208 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;
06209 function repulse(node) {
06210 return function(quad, x1, _, x2) {
06211 if (quad.point !== node) {
06212 var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
06213 if (dw * dw / theta2 < dn) {
06214 if (dn < chargeDistance2) {
06215 var k = quad.charge / dn;
06216 node.px -= dx * k;
06217 node.py -= dy * k;
06218 }
06219 return true;
06220 }
06221 if (quad.point && dn && dn < chargeDistance2) {
06222 var k = quad.pointCharge / dn;
06223 node.px -= dx * k;
06224 node.py -= dy * k;
06225 }
06226 }
06227 return !quad.charge;
06228 };
06229 }
06230 force.tick = function() {
06231 if ((alpha *= .99) < .005) {
06232 event.end({
06233 type: "end",
06234 alpha: alpha = 0
06235 });
06236 return true;
06237 }
06238 var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
06239 for (i = 0; i < m; ++i) {
06240 o = links[i];
06241 s = o.source;
06242 t = o.target;
06243 x = t.x - s.x;
06244 y = t.y - s.y;
06245 if (l = x * x + y * y) {
06246 l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
06247 x *= l;
06248 y *= l;
06249 t.x -= x * (k = s.weight / (t.weight + s.weight));
06250 t.y -= y * k;
06251 s.x += x * (k = 1 - k);
06252 s.y += y * k;
06253 }
06254 }
06255 if (k = alpha * gravity) {
06256 x = size[0] / 2;
06257 y = size[1] / 2;
06258 i = -1;
06259 if (k) while (++i < n) {
06260 o = nodes[i];
06261 o.x += (x - o.x) * k;
06262 o.y += (y - o.y) * k;
06263 }
06264 }
06265 if (charge) {
06266 d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
06267 i = -1;
06268 while (++i < n) {
06269 if (!(o = nodes[i]).fixed) {
06270 q.visit(repulse(o));
06271 }
06272 }
06273 }
06274 i = -1;
06275 while (++i < n) {
06276 o = nodes[i];
06277 if (o.fixed) {
06278 o.x = o.px;
06279 o.y = o.py;
06280 } else {
06281 o.x -= (o.px - (o.px = o.x)) * friction;
06282 o.y -= (o.py - (o.py = o.y)) * friction;
06283 }
06284 }
06285 event.tick({
06286 type: "tick",
06287 alpha: alpha
06288 });
06289 };
06290 force.nodes = function(x) {
06291 if (!arguments.length) return nodes;
06292 nodes = x;
06293 return force;
06294 };
06295 force.links = function(x) {
06296 if (!arguments.length) return links;
06297 links = x;
06298 return force;
06299 };
06300 force.size = function(x) {
06301 if (!arguments.length) return size;
06302 size = x;
06303 return force;
06304 };
06305 force.linkDistance = function(x) {
06306 if (!arguments.length) return linkDistance;
06307 linkDistance = typeof x === "function" ? x : +x;
06308 return force;
06309 };
06310 force.distance = force.linkDistance;
06311 force.linkStrength = function(x) {
06312 if (!arguments.length) return linkStrength;
06313 linkStrength = typeof x === "function" ? x : +x;
06314 return force;
06315 };
06316 force.friction = function(x) {
06317 if (!arguments.length) return friction;
06318 friction = +x;
06319 return force;
06320 };
06321 force.charge = function(x) {
06322 if (!arguments.length) return charge;
06323 charge = typeof x === "function" ? x : +x;
06324 return force;
06325 };
06326 force.chargeDistance = function(x) {
06327 if (!arguments.length) return Math.sqrt(chargeDistance2);
06328 chargeDistance2 = x * x;
06329 return force;
06330 };
06331 force.gravity = function(x) {
06332 if (!arguments.length) return gravity;
06333 gravity = +x;
06334 return force;
06335 };
06336 force.theta = function(x) {
06337 if (!arguments.length) return Math.sqrt(theta2);
06338 theta2 = x * x;
06339 return force;
06340 };
06341 force.alpha = function(x) {
06342 if (!arguments.length) return alpha;
06343 x = +x;
06344 if (alpha) {
06345 if (x > 0) alpha = x; else alpha = 0;
06346 } else if (x > 0) {
06347 event.start({
06348 type: "start",
06349 alpha: alpha = x
06350 });
06351 d3.timer(force.tick);
06352 }
06353 return force;
06354 };
06355 force.start = function() {
06356 var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
06357 for (i = 0; i < n; ++i) {
06358 (o = nodes[i]).index = i;
06359 o.weight = 0;
06360 }
06361 for (i = 0; i < m; ++i) {
06362 o = links[i];
06363 if (typeof o.source == "number") o.source = nodes[o.source];
06364 if (typeof o.target == "number") o.target = nodes[o.target];
06365 ++o.source.weight;
06366 ++o.target.weight;
06367 }
06368 for (i = 0; i < n; ++i) {
06369 o = nodes[i];
06370 if (isNaN(o.x)) o.x = position("x", w);
06371 if (isNaN(o.y)) o.y = position("y", h);
06372 if (isNaN(o.px)) o.px = o.x;
06373 if (isNaN(o.py)) o.py = o.y;
06374 }
06375 distances = [];
06376 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;
06377 strengths = [];
06378 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;
06379 charges = [];
06380 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;
06381 function position(dimension, size) {
06382 if (!neighbors) {
06383 neighbors = new Array(n);
06384 for (j = 0; j < n; ++j) {
06385 neighbors[j] = [];
06386 }
06387 for (j = 0; j < m; ++j) {
06388 var o = links[j];
06389 neighbors[o.source.index].push(o.target);
06390 neighbors[o.target.index].push(o.source);
06391 }
06392 }
06393 var candidates = neighbors[i], j = -1, l = candidates.length, x;
06394 while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
06395 return Math.random() * size;
06396 }
06397 return force.resume();
06398 };
06399 force.resume = function() {
06400 return force.alpha(.1);
06401 };
06402 force.stop = function() {
06403 return force.alpha(0);
06404 };
06405 force.drag = function() {
06406 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);
06407 if (!arguments.length) return drag;
06408 this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
06409 };
06410 function dragmove(d) {
06411 d.px = d3.event.x, d.py = d3.event.y;
06412 force.resume();
06413 }
06414 return d3.rebind(force, event, "on");
06415 };
06416 function d3_layout_forceDragstart(d) {
06417 d.fixed |= 2;
06418 }
06419 function d3_layout_forceDragend(d) {
06420 d.fixed &= ~6;
06421 }
06422 function d3_layout_forceMouseover(d) {
06423 d.fixed |= 4;
06424 d.px = d.x, d.py = d.y;
06425 }
06426 function d3_layout_forceMouseout(d) {
06427 d.fixed &= ~4;
06428 }
06429 function d3_layout_forceAccumulate(quad, alpha, charges) {
06430 var cx = 0, cy = 0;
06431 quad.charge = 0;
06432 if (!quad.leaf) {
06433 var nodes = quad.nodes, n = nodes.length, i = -1, c;
06434 while (++i < n) {
06435 c = nodes[i];
06436 if (c == null) continue;
06437 d3_layout_forceAccumulate(c, alpha, charges);
06438 quad.charge += c.charge;
06439 cx += c.charge * c.cx;
06440 cy += c.charge * c.cy;
06441 }
06442 }
06443 if (quad.point) {
06444 if (!quad.leaf) {
06445 quad.point.x += Math.random() - .5;
06446 quad.point.y += Math.random() - .5;
06447 }
06448 var k = alpha * charges[quad.point.index];
06449 quad.charge += quad.pointCharge = k;
06450 cx += k * quad.point.x;
06451 cy += k * quad.point.y;
06452 }
06453 quad.cx = cx / quad.charge;
06454 quad.cy = cy / quad.charge;
06455 }
06456 var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
06457 d3.layout.hierarchy = function() {
06458 var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
06459 function hierarchy(root) {
06460 var stack = [ root ], nodes = [], node;
06461 root.depth = 0;
06462 while ((node = stack.pop()) != null) {
06463 nodes.push(node);
06464 if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
06465 var n, childs, child;
06466 while (--n >= 0) {
06467 stack.push(child = childs[n]);
06468 child.parent = node;
06469 child.depth = node.depth + 1;
06470 }
06471 if (value) node.value = 0;
06472 node.children = childs;
06473 } else {
06474 if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
06475 delete node.children;
06476 }
06477 }
06478 d3_layout_hierarchyVisitAfter(root, function(node) {
06479 var childs, parent;
06480 if (sort && (childs = node.children)) childs.sort(sort);
06481 if (value && (parent = node.parent)) parent.value += node.value;
06482 });
06483 return nodes;
06484 }
06485 hierarchy.sort = function(x) {
06486 if (!arguments.length) return sort;
06487 sort = x;
06488 return hierarchy;
06489 };
06490 hierarchy.children = function(x) {
06491 if (!arguments.length) return children;
06492 children = x;
06493 return hierarchy;
06494 };
06495 hierarchy.value = function(x) {
06496 if (!arguments.length) return value;
06497 value = x;
06498 return hierarchy;
06499 };
06500 hierarchy.revalue = function(root) {
06501 if (value) {
06502 d3_layout_hierarchyVisitBefore(root, function(node) {
06503 if (node.children) node.value = 0;
06504 });
06505 d3_layout_hierarchyVisitAfter(root, function(node) {
06506 var parent;
06507 if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
06508 if (parent = node.parent) parent.value += node.value;
06509 });
06510 }
06511 return root;
06512 };
06513 return hierarchy;
06514 };
06515 function d3_layout_hierarchyRebind(object, hierarchy) {
06516 d3.rebind(object, hierarchy, "sort", "children", "value");
06517 object.nodes = object;
06518 object.links = d3_layout_hierarchyLinks;
06519 return object;
06520 }
06521 function d3_layout_hierarchyVisitBefore(node, callback) {
06522 var nodes = [ node ];
06523 while ((node = nodes.pop()) != null) {
06524 callback(node);
06525 if ((children = node.children) && (n = children.length)) {
06526 var n, children;
06527 while (--n >= 0) nodes.push(children[n]);
06528 }
06529 }
06530 }
06531 function d3_layout_hierarchyVisitAfter(node, callback) {
06532 var nodes = [ node ], nodes2 = [];
06533 while ((node = nodes.pop()) != null) {
06534 nodes2.push(node);
06535 if ((children = node.children) && (n = children.length)) {
06536 var i = -1, n, children;
06537 while (++i < n) nodes.push(children[i]);
06538 }
06539 }
06540 while ((node = nodes2.pop()) != null) {
06541 callback(node);
06542 }
06543 }
06544 function d3_layout_hierarchyChildren(d) {
06545 return d.children;
06546 }
06547 function d3_layout_hierarchyValue(d) {
06548 return d.value;
06549 }
06550 function d3_layout_hierarchySort(a, b) {
06551 return b.value - a.value;
06552 }
06553 function d3_layout_hierarchyLinks(nodes) {
06554 return d3.merge(nodes.map(function(parent) {
06555 return (parent.children || []).map(function(child) {
06556 return {
06557 source: parent,
06558 target: child
06559 };
06560 });
06561 }));
06562 }
06563 d3.layout.partition = function() {
06564 var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
06565 function position(node, x, dx, dy) {
06566 var children = node.children;
06567 node.x = x;
06568 node.y = node.depth * dy;
06569 node.dx = dx;
06570 node.dy = dy;
06571 if (children && (n = children.length)) {
06572 var i = -1, n, c, d;
06573 dx = node.value ? dx / node.value : 0;
06574 while (++i < n) {
06575 position(c = children[i], x, d = c.value * dx, dy);
06576 x += d;
06577 }
06578 }
06579 }
06580 function depth(node) {
06581 var children = node.children, d = 0;
06582 if (children && (n = children.length)) {
06583 var i = -1, n;
06584 while (++i < n) d = Math.max(d, depth(children[i]));
06585 }
06586 return 1 + d;
06587 }
06588 function partition(d, i) {
06589 var nodes = hierarchy.call(this, d, i);
06590 position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
06591 return nodes;
06592 }
06593 partition.size = function(x) {
06594 if (!arguments.length) return size;
06595 size = x;
06596 return partition;
06597 };
06598 return d3_layout_hierarchyRebind(partition, hierarchy);
06599 };
06600 d3.layout.pie = function() {
06601 var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
06602 function pie(data) {
06603 var n = data.length, values = data.map(function(d, i) {
06604 return +value.call(pie, d, i);
06605 }), 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;
06606 if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
06607 return values[j] - values[i];
06608 } : function(i, j) {
06609 return sort(data[i], data[j]);
06610 });
06611 index.forEach(function(i) {
06612 arcs[i] = {
06613 data: data[i],
06614 value: v = values[i],
06615 startAngle: a,
06616 endAngle: a += v * k + pa,
06617 padAngle: p
06618 };
06619 });
06620 return arcs;
06621 }
06622 pie.value = function(_) {
06623 if (!arguments.length) return value;
06624 value = _;
06625 return pie;
06626 };
06627 pie.sort = function(_) {
06628 if (!arguments.length) return sort;
06629 sort = _;
06630 return pie;
06631 };
06632 pie.startAngle = function(_) {
06633 if (!arguments.length) return startAngle;
06634 startAngle = _;
06635 return pie;
06636 };
06637 pie.endAngle = function(_) {
06638 if (!arguments.length) return endAngle;
06639 endAngle = _;
06640 return pie;
06641 };
06642 pie.padAngle = function(_) {
06643 if (!arguments.length) return padAngle;
06644 padAngle = _;
06645 return pie;
06646 };
06647 return pie;
06648 };
06649 var d3_layout_pieSortByValue = {};
06650 d3.layout.stack = function() {
06651 var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
06652 function stack(data, index) {
06653 if (!(n = data.length)) return data;
06654 var series = data.map(function(d, i) {
06655 return values.call(stack, d, i);
06656 });
06657 var points = series.map(function(d) {
06658 return d.map(function(v, i) {
06659 return [ x.call(stack, v, i), y.call(stack, v, i) ];
06660 });
06661 });
06662 var orders = order.call(stack, points, index);
06663 series = d3.permute(series, orders);
06664 points = d3.permute(points, orders);
06665 var offsets = offset.call(stack, points, index);
06666 var m = series[0].length, n, i, j, o;
06667 for (j = 0; j < m; ++j) {
06668 out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
06669 for (i = 1; i < n; ++i) {
06670 out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
06671 }
06672 }
06673 return data;
06674 }
06675 stack.values = function(x) {
06676 if (!arguments.length) return values;
06677 values = x;
06678 return stack;
06679 };
06680 stack.order = function(x) {
06681 if (!arguments.length) return order;
06682 order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
06683 return stack;
06684 };
06685 stack.offset = function(x) {
06686 if (!arguments.length) return offset;
06687 offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
06688 return stack;
06689 };
06690 stack.x = function(z) {
06691 if (!arguments.length) return x;
06692 x = z;
06693 return stack;
06694 };
06695 stack.y = function(z) {
06696 if (!arguments.length) return y;
06697 y = z;
06698 return stack;
06699 };
06700 stack.out = function(z) {
06701 if (!arguments.length) return out;
06702 out = z;
06703 return stack;
06704 };
06705 return stack;
06706 };
06707 function d3_layout_stackX(d) {
06708 return d.x;
06709 }
06710 function d3_layout_stackY(d) {
06711 return d.y;
06712 }
06713 function d3_layout_stackOut(d, y0, y) {
06714 d.y0 = y0;
06715 d.y = y;
06716 }
06717 var d3_layout_stackOrders = d3.map({
06718 "inside-out": function(data) {
06719 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) {
06720 return max[a] - max[b];
06721 }), top = 0, bottom = 0, tops = [], bottoms = [];
06722 for (i = 0; i < n; ++i) {
06723 j = index[i];
06724 if (top < bottom) {
06725 top += sums[j];
06726 tops.push(j);
06727 } else {
06728 bottom += sums[j];
06729 bottoms.push(j);
06730 }
06731 }
06732 return bottoms.reverse().concat(tops);
06733 },
06734 reverse: function(data) {
06735 return d3.range(data.length).reverse();
06736 },
06737 "default": d3_layout_stackOrderDefault
06738 });
06739 var d3_layout_stackOffsets = d3.map({
06740 silhouette: function(data) {
06741 var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
06742 for (j = 0; j < m; ++j) {
06743 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
06744 if (o > max) max = o;
06745 sums.push(o);
06746 }
06747 for (j = 0; j < m; ++j) {
06748 y0[j] = (max - sums[j]) / 2;
06749 }
06750 return y0;
06751 },
06752 wiggle: function(data) {
06753 var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
06754 y0[0] = o = o0 = 0;
06755 for (j = 1; j < m; ++j) {
06756 for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
06757 for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
06758 for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
06759 s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
06760 }
06761 s2 += s3 * data[i][j][1];
06762 }
06763 y0[j] = o -= s1 ? s2 / s1 * dx : 0;
06764 if (o < o0) o0 = o;
06765 }
06766 for (j = 0; j < m; ++j) y0[j] -= o0;
06767 return y0;
06768 },
06769 expand: function(data) {
06770 var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
06771 for (j = 0; j < m; ++j) {
06772 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
06773 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;
06774 }
06775 for (j = 0; j < m; ++j) y0[j] = 0;
06776 return y0;
06777 },
06778 zero: d3_layout_stackOffsetZero
06779 });
06780 function d3_layout_stackOrderDefault(data) {
06781 return d3.range(data.length);
06782 }
06783 function d3_layout_stackOffsetZero(data) {
06784 var j = -1, m = data[0].length, y0 = [];
06785 while (++j < m) y0[j] = 0;
06786 return y0;
06787 }
06788 function d3_layout_stackMaxIndex(array) {
06789 var i = 1, j = 0, v = array[0][1], k, n = array.length;
06790 for (;i < n; ++i) {
06791 if ((k = array[i][1]) > v) {
06792 j = i;
06793 v = k;
06794 }
06795 }
06796 return j;
06797 }
06798 function d3_layout_stackReduceSum(d) {
06799 return d.reduce(d3_layout_stackSum, 0);
06800 }
06801 function d3_layout_stackSum(p, d) {
06802 return p + d[1];
06803 }
06804 d3.layout.histogram = function() {
06805 var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
06806 function histogram(data, i) {
06807 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;
06808 while (++i < m) {
06809 bin = bins[i] = [];
06810 bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
06811 bin.y = 0;
06812 }
06813 if (m > 0) {
06814 i = -1;
06815 while (++i < n) {
06816 x = values[i];
06817 if (x >= range[0] && x <= range[1]) {
06818 bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
06819 bin.y += k;
06820 bin.push(data[i]);
06821 }
06822 }
06823 }
06824 return bins;
06825 }
06826 histogram.value = function(x) {
06827 if (!arguments.length) return valuer;
06828 valuer = x;
06829 return histogram;
06830 };
06831 histogram.range = function(x) {
06832 if (!arguments.length) return ranger;
06833 ranger = d3_functor(x);
06834 return histogram;
06835 };
06836 histogram.bins = function(x) {
06837 if (!arguments.length) return binner;
06838 binner = typeof x === "number" ? function(range) {
06839 return d3_layout_histogramBinFixed(range, x);
06840 } : d3_functor(x);
06841 return histogram;
06842 };
06843 histogram.frequency = function(x) {
06844 if (!arguments.length) return frequency;
06845 frequency = !!x;
06846 return histogram;
06847 };
06848 return histogram;
06849 };
06850 function d3_layout_histogramBinSturges(range, values) {
06851 return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
06852 }
06853 function d3_layout_histogramBinFixed(range, n) {
06854 var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
06855 while (++x <= n) f[x] = m * x + b;
06856 return f;
06857 }
06858 function d3_layout_histogramRange(values) {
06859 return [ d3.min(values), d3.max(values) ];
06860 }
06861 d3.layout.pack = function() {
06862 var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
06863 function pack(d, i) {
06864 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() {
06865 return radius;
06866 };
06867 root.x = root.y = 0;
06868 d3_layout_hierarchyVisitAfter(root, function(d) {
06869 d.r = +r(d.value);
06870 });
06871 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
06872 if (padding) {
06873 var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
06874 d3_layout_hierarchyVisitAfter(root, function(d) {
06875 d.r += dr;
06876 });
06877 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
06878 d3_layout_hierarchyVisitAfter(root, function(d) {
06879 d.r -= dr;
06880 });
06881 }
06882 d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
06883 return nodes;
06884 }
06885 pack.size = function(_) {
06886 if (!arguments.length) return size;
06887 size = _;
06888 return pack;
06889 };
06890 pack.radius = function(_) {
06891 if (!arguments.length) return radius;
06892 radius = _ == null || typeof _ === "function" ? _ : +_;
06893 return pack;
06894 };
06895 pack.padding = function(_) {
06896 if (!arguments.length) return padding;
06897 padding = +_;
06898 return pack;
06899 };
06900 return d3_layout_hierarchyRebind(pack, hierarchy);
06901 };
06902 function d3_layout_packSort(a, b) {
06903 return a.value - b.value;
06904 }
06905 function d3_layout_packInsert(a, b) {
06906 var c = a._pack_next;
06907 a._pack_next = b;
06908 b._pack_prev = a;
06909 b._pack_next = c;
06910 c._pack_prev = b;
06911 }
06912 function d3_layout_packSplice(a, b) {
06913 a._pack_next = b;
06914 b._pack_prev = a;
06915 }
06916 function d3_layout_packIntersects(a, b) {
06917 var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
06918 return .999 * dr * dr > dx * dx + dy * dy;
06919 }
06920 function d3_layout_packSiblings(node) {
06921 if (!(nodes = node.children) || !(n = nodes.length)) return;
06922 var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
06923 function bound(node) {
06924 xMin = Math.min(node.x - node.r, xMin);
06925 xMax = Math.max(node.x + node.r, xMax);
06926 yMin = Math.min(node.y - node.r, yMin);
06927 yMax = Math.max(node.y + node.r, yMax);
06928 }
06929 nodes.forEach(d3_layout_packLink);
06930 a = nodes[0];
06931 a.x = -a.r;
06932 a.y = 0;
06933 bound(a);
06934 if (n > 1) {
06935 b = nodes[1];
06936 b.x = b.r;
06937 b.y = 0;
06938 bound(b);
06939 if (n > 2) {
06940 c = nodes[2];
06941 d3_layout_packPlace(a, b, c);
06942 bound(c);
06943 d3_layout_packInsert(a, c);
06944 a._pack_prev = c;
06945 d3_layout_packInsert(c, b);
06946 b = a._pack_next;
06947 for (i = 3; i < n; i++) {
06948 d3_layout_packPlace(a, b, c = nodes[i]);
06949 var isect = 0, s1 = 1, s2 = 1;
06950 for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
06951 if (d3_layout_packIntersects(j, c)) {
06952 isect = 1;
06953 break;
06954 }
06955 }
06956 if (isect == 1) {
06957 for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
06958 if (d3_layout_packIntersects(k, c)) {
06959 break;
06960 }
06961 }
06962 }
06963 if (isect) {
06964 if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
06965 i--;
06966 } else {
06967 d3_layout_packInsert(a, c);
06968 b = c;
06969 bound(c);
06970 }
06971 }
06972 }
06973 }
06974 var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
06975 for (i = 0; i < n; i++) {
06976 c = nodes[i];
06977 c.x -= cx;
06978 c.y -= cy;
06979 cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
06980 }
06981 node.r = cr;
06982 nodes.forEach(d3_layout_packUnlink);
06983 }
06984 function d3_layout_packLink(node) {
06985 node._pack_next = node._pack_prev = node;
06986 }
06987 function d3_layout_packUnlink(node) {
06988 delete node._pack_next;
06989 delete node._pack_prev;
06990 }
06991 function d3_layout_packTransform(node, x, y, k) {
06992 var children = node.children;
06993 node.x = x += k * node.x;
06994 node.y = y += k * node.y;
06995 node.r *= k;
06996 if (children) {
06997 var i = -1, n = children.length;
06998 while (++i < n) d3_layout_packTransform(children[i], x, y, k);
06999 }
07000 }
07001 function d3_layout_packPlace(a, b, c) {
07002 var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
07003 if (db && (dx || dy)) {
07004 var da = b.r + c.r, dc = dx * dx + dy * dy;
07005 da *= da;
07006 db *= db;
07007 var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
07008 c.x = a.x + x * dx + y * dy;
07009 c.y = a.y + x * dy - y * dx;
07010 } else {
07011 c.x = a.x + db;
07012 c.y = a.y;
07013 }
07014 }
07015 d3.layout.tree = function() {
07016 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
07017 function tree(d, i) {
07018 var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
07019 d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
07020 d3_layout_hierarchyVisitBefore(root1, secondWalk);
07021 if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
07022 var left = root0, right = root0, bottom = root0;
07023 d3_layout_hierarchyVisitBefore(root0, function(node) {
07024 if (node.x < left.x) left = node;
07025 if (node.x > right.x) right = node;
07026 if (node.depth > bottom.depth) bottom = node;
07027 });
07028 var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
07029 d3_layout_hierarchyVisitBefore(root0, function(node) {
07030 node.x = (node.x + tx) * kx;
07031 node.y = node.depth * ky;
07032 });
07033 }
07034 return nodes;
07035 }
07036 function wrapTree(root0) {
07037 var root1 = {
07038 A: null,
07039 children: [ root0 ]
07040 }, queue = [ root1 ], node1;
07041 while ((node1 = queue.pop()) != null) {
07042 for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
07043 queue.push((children[i] = child = {
07044 _: children[i],
07045 parent: node1,
07046 children: (child = children[i].children) && child.slice() || [],
07047 A: null,
07048 a: null,
07049 z: 0,
07050 m: 0,
07051 c: 0,
07052 s: 0,
07053 t: null,
07054 i: i
07055 }).a = child);
07056 }
07057 }
07058 return root1.children[0];
07059 }
07060 function firstWalk(v) {
07061 var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
07062 if (children.length) {
07063 d3_layout_treeShift(v);
07064 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
07065 if (w) {
07066 v.z = w.z + separation(v._, w._);
07067 v.m = v.z - midpoint;
07068 } else {
07069 v.z = midpoint;
07070 }
07071 } else if (w) {
07072 v.z = w.z + separation(v._, w._);
07073 }
07074 v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
07075 }
07076 function secondWalk(v) {
07077 v._.x = v.z + v.parent.m;
07078 v.m += v.parent.m;
07079 }
07080 function apportion(v, w, ancestor) {
07081 if (w) {
07082 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;
07083 while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
07084 vom = d3_layout_treeLeft(vom);
07085 vop = d3_layout_treeRight(vop);
07086 vop.a = v;
07087 shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
07088 if (shift > 0) {
07089 d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
07090 sip += shift;
07091 sop += shift;
07092 }
07093 sim += vim.m;
07094 sip += vip.m;
07095 som += vom.m;
07096 sop += vop.m;
07097 }
07098 if (vim && !d3_layout_treeRight(vop)) {
07099 vop.t = vim;
07100 vop.m += sim - sop;
07101 }
07102 if (vip && !d3_layout_treeLeft(vom)) {
07103 vom.t = vip;
07104 vom.m += sip - som;
07105 ancestor = v;
07106 }
07107 }
07108 return ancestor;
07109 }
07110 function sizeNode(node) {
07111 node.x *= size[0];
07112 node.y = node.depth * size[1];
07113 }
07114 tree.separation = function(x) {
07115 if (!arguments.length) return separation;
07116 separation = x;
07117 return tree;
07118 };
07119 tree.size = function(x) {
07120 if (!arguments.length) return nodeSize ? null : size;
07121 nodeSize = (size = x) == null ? sizeNode : null;
07122 return tree;
07123 };
07124 tree.nodeSize = function(x) {
07125 if (!arguments.length) return nodeSize ? size : null;
07126 nodeSize = (size = x) == null ? null : sizeNode;
07127 return tree;
07128 };
07129 return d3_layout_hierarchyRebind(tree, hierarchy);
07130 };
07131 function d3_layout_treeSeparation(a, b) {
07132 return a.parent == b.parent ? 1 : 2;
07133 }
07134 function d3_layout_treeLeft(v) {
07135 var children = v.children;
07136 return children.length ? children[0] : v.t;
07137 }
07138 function d3_layout_treeRight(v) {
07139 var children = v.children, n;
07140 return (n = children.length) ? children[n - 1] : v.t;
07141 }
07142 function d3_layout_treeMove(wm, wp, shift) {
07143 var change = shift / (wp.i - wm.i);
07144 wp.c -= change;
07145 wp.s += shift;
07146 wm.c += change;
07147 wp.z += shift;
07148 wp.m += shift;
07149 }
07150 function d3_layout_treeShift(v) {
07151 var shift = 0, change = 0, children = v.children, i = children.length, w;
07152 while (--i >= 0) {
07153 w = children[i];
07154 w.z += shift;
07155 w.m += shift;
07156 shift += w.s + (change += w.c);
07157 }
07158 }
07159 function d3_layout_treeAncestor(vim, v, ancestor) {
07160 return vim.a.parent === v.parent ? vim.a : ancestor;
07161 }
07162 d3.layout.cluster = function() {
07163 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
07164 function cluster(d, i) {
07165 var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
07166 d3_layout_hierarchyVisitAfter(root, function(node) {
07167 var children = node.children;
07168 if (children && children.length) {
07169 node.x = d3_layout_clusterX(children);
07170 node.y = d3_layout_clusterY(children);
07171 } else {
07172 node.x = previousNode ? x += separation(node, previousNode) : 0;
07173 node.y = 0;
07174 previousNode = node;
07175 }
07176 });
07177 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;
07178 d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
07179 node.x = (node.x - root.x) * size[0];
07180 node.y = (root.y - node.y) * size[1];
07181 } : function(node) {
07182 node.x = (node.x - x0) / (x1 - x0) * size[0];
07183 node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
07184 });
07185 return nodes;
07186 }
07187 cluster.separation = function(x) {
07188 if (!arguments.length) return separation;
07189 separation = x;
07190 return cluster;
07191 };
07192 cluster.size = function(x) {
07193 if (!arguments.length) return nodeSize ? null : size;
07194 nodeSize = (size = x) == null;
07195 return cluster;
07196 };
07197 cluster.nodeSize = function(x) {
07198 if (!arguments.length) return nodeSize ? size : null;
07199 nodeSize = (size = x) != null;
07200 return cluster;
07201 };
07202 return d3_layout_hierarchyRebind(cluster, hierarchy);
07203 };
07204 function d3_layout_clusterY(children) {
07205 return 1 + d3.max(children, function(child) {
07206 return child.y;
07207 });
07208 }
07209 function d3_layout_clusterX(children) {
07210 return children.reduce(function(x, child) {
07211 return x + child.x;
07212 }, 0) / children.length;
07213 }
07214 function d3_layout_clusterLeft(node) {
07215 var children = node.children;
07216 return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
07217 }
07218 function d3_layout_clusterRight(node) {
07219 var children = node.children, n;
07220 return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
07221 }
07222 d3.layout.treemap = function() {
07223 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));
07224 function scale(children, k) {
07225 var i = -1, n = children.length, child, area;
07226 while (++i < n) {
07227 area = (child = children[i]).value * (k < 0 ? 0 : k);
07228 child.area = isNaN(area) || area <= 0 ? 0 : area;
07229 }
07230 }
07231 function squarify(node) {
07232 var children = node.children;
07233 if (children && children.length) {
07234 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;
07235 scale(remaining, rect.dx * rect.dy / node.value);
07236 row.area = 0;
07237 while ((n = remaining.length) > 0) {
07238 row.push(child = remaining[n - 1]);
07239 row.area += child.area;
07240 if (mode !== "squarify" || (score = worst(row, u)) <= best) {
07241 remaining.pop();
07242 best = score;
07243 } else {
07244 row.area -= row.pop().area;
07245 position(row, u, rect, false);
07246 u = Math.min(rect.dx, rect.dy);
07247 row.length = row.area = 0;
07248 best = Infinity;
07249 }
07250 }
07251 if (row.length) {
07252 position(row, u, rect, true);
07253 row.length = row.area = 0;
07254 }
07255 children.forEach(squarify);
07256 }
07257 }
07258 function stickify(node) {
07259 var children = node.children;
07260 if (children && children.length) {
07261 var rect = pad(node), remaining = children.slice(), child, row = [];
07262 scale(remaining, rect.dx * rect.dy / node.value);
07263 row.area = 0;
07264 while (child = remaining.pop()) {
07265 row.push(child);
07266 row.area += child.area;
07267 if (child.z != null) {
07268 position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
07269 row.length = row.area = 0;
07270 }
07271 }
07272 children.forEach(stickify);
07273 }
07274 }
07275 function worst(row, u) {
07276 var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
07277 while (++i < n) {
07278 if (!(r = row[i].area)) continue;
07279 if (r < rmin) rmin = r;
07280 if (r > rmax) rmax = r;
07281 }
07282 s *= s;
07283 u *= u;
07284 return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
07285 }
07286 function position(row, u, rect, flush) {
07287 var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
07288 if (u == rect.dx) {
07289 if (flush || v > rect.dy) v = rect.dy;
07290 while (++i < n) {
07291 o = row[i];
07292 o.x = x;
07293 o.y = y;
07294 o.dy = v;
07295 x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
07296 }
07297 o.z = true;
07298 o.dx += rect.x + rect.dx - x;
07299 rect.y += v;
07300 rect.dy -= v;
07301 } else {
07302 if (flush || v > rect.dx) v = rect.dx;
07303 while (++i < n) {
07304 o = row[i];
07305 o.x = x;
07306 o.y = y;
07307 o.dx = v;
07308 y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
07309 }
07310 o.z = false;
07311 o.dy += rect.y + rect.dy - y;
07312 rect.x += v;
07313 rect.dx -= v;
07314 }
07315 }
07316 function treemap(d) {
07317 var nodes = stickies || hierarchy(d), root = nodes[0];
07318 root.x = 0;
07319 root.y = 0;
07320 root.dx = size[0];
07321 root.dy = size[1];
07322 if (stickies) hierarchy.revalue(root);
07323 scale([ root ], root.dx * root.dy / root.value);
07324 (stickies ? stickify : squarify)(root);
07325 if (sticky) stickies = nodes;
07326 return nodes;
07327 }
07328 treemap.size = function(x) {
07329 if (!arguments.length) return size;
07330 size = x;
07331 return treemap;
07332 };
07333 treemap.padding = function(x) {
07334 if (!arguments.length) return padding;
07335 function padFunction(node) {
07336 var p = x.call(treemap, node, node.depth);
07337 return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
07338 }
07339 function padConstant(node) {
07340 return d3_layout_treemapPad(node, x);
07341 }
07342 var type;
07343 pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
07344 padConstant) : padConstant;
07345 return treemap;
07346 };
07347 treemap.round = function(x) {
07348 if (!arguments.length) return round != Number;
07349 round = x ? Math.round : Number;
07350 return treemap;
07351 };
07352 treemap.sticky = function(x) {
07353 if (!arguments.length) return sticky;
07354 sticky = x;
07355 stickies = null;
07356 return treemap;
07357 };
07358 treemap.ratio = function(x) {
07359 if (!arguments.length) return ratio;
07360 ratio = x;
07361 return treemap;
07362 };
07363 treemap.mode = function(x) {
07364 if (!arguments.length) return mode;
07365 mode = x + "";
07366 return treemap;
07367 };
07368 return d3_layout_hierarchyRebind(treemap, hierarchy);
07369 };
07370 function d3_layout_treemapPadNull(node) {
07371 return {
07372 x: node.x,
07373 y: node.y,
07374 dx: node.dx,
07375 dy: node.dy
07376 };
07377 }
07378 function d3_layout_treemapPad(node, padding) {
07379 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];
07380 if (dx < 0) {
07381 x += dx / 2;
07382 dx = 0;
07383 }
07384 if (dy < 0) {
07385 y += dy / 2;
07386 dy = 0;
07387 }
07388 return {
07389 x: x,
07390 y: y,
07391 dx: dx,
07392 dy: dy
07393 };
07394 }
07395 d3.random = {
07396 normal: function(µ, σ) {
07397 var n = arguments.length;
07398 if (n < 2) σ = 1;
07399 if (n < 1) µ = 0;
07400 return function() {
07401 var x, y, r;
07402 do {
07403 x = Math.random() * 2 - 1;
07404 y = Math.random() * 2 - 1;
07405 r = x * x + y * y;
07406 } while (!r || r > 1);
07407 return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
07408 };
07409 },
07410 logNormal: function() {
07411 var random = d3.random.normal.apply(d3, arguments);
07412 return function() {
07413 return Math.exp(random());
07414 };
07415 },
07416 bates: function(m) {
07417 var random = d3.random.irwinHall(m);
07418 return function() {
07419 return random() / m;
07420 };
07421 },
07422 irwinHall: function(m) {
07423 return function() {
07424 for (var s = 0, j = 0; j < m; j++) s += Math.random();
07425 return s;
07426 };
07427 }
07428 };
07429 d3.scale = {};
07430 function d3_scaleExtent(domain) {
07431 var start = domain[0], stop = domain[domain.length - 1];
07432 return start < stop ? [ start, stop ] : [ stop, start ];
07433 }
07434 function d3_scaleRange(scale) {
07435 return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
07436 }
07437 function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
07438 var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
07439 return function(x) {
07440 return i(u(x));
07441 };
07442 }
07443 function d3_scale_nice(domain, nice) {
07444 var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
07445 if (x1 < x0) {
07446 dx = i0, i0 = i1, i1 = dx;
07447 dx = x0, x0 = x1, x1 = dx;
07448 }
07449 domain[i0] = nice.floor(x0);
07450 domain[i1] = nice.ceil(x1);
07451 return domain;
07452 }
07453 function d3_scale_niceStep(step) {
07454 return step ? {
07455 floor: function(x) {
07456 return Math.floor(x / step) * step;
07457 },
07458 ceil: function(x) {
07459 return Math.ceil(x / step) * step;
07460 }
07461 } : d3_scale_niceIdentity;
07462 }
07463 var d3_scale_niceIdentity = {
07464 floor: d3_identity,
07465 ceil: d3_identity
07466 };
07467 function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
07468 var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
07469 if (domain[k] < domain[0]) {
07470 domain = domain.slice().reverse();
07471 range = range.slice().reverse();
07472 }
07473 while (++j <= k) {
07474 u.push(uninterpolate(domain[j - 1], domain[j]));
07475 i.push(interpolate(range[j - 1], range[j]));
07476 }
07477 return function(x) {
07478 var j = d3.bisect(domain, x, 1, k) - 1;
07479 return i[j](u[j](x));
07480 };
07481 }
07482 d3.scale.linear = function() {
07483 return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
07484 };
07485 function d3_scale_linear(domain, range, interpolate, clamp) {
07486 var output, input;
07487 function rescale() {
07488 var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
07489 output = linear(domain, range, uninterpolate, interpolate);
07490 input = linear(range, domain, uninterpolate, d3_interpolate);
07491 return scale;
07492 }
07493 function scale(x) {
07494 return output(x);
07495 }
07496 scale.invert = function(y) {
07497 return input(y);
07498 };
07499 scale.domain = function(x) {
07500 if (!arguments.length) return domain;
07501 domain = x.map(Number);
07502 return rescale();
07503 };
07504 scale.range = function(x) {
07505 if (!arguments.length) return range;
07506 range = x;
07507 return rescale();
07508 };
07509 scale.rangeRound = function(x) {
07510 return scale.range(x).interpolate(d3_interpolateRound);
07511 };
07512 scale.clamp = function(x) {
07513 if (!arguments.length) return clamp;
07514 clamp = x;
07515 return rescale();
07516 };
07517 scale.interpolate = function(x) {
07518 if (!arguments.length) return interpolate;
07519 interpolate = x;
07520 return rescale();
07521 };
07522 scale.ticks = function(m) {
07523 return d3_scale_linearTicks(domain, m);
07524 };
07525 scale.tickFormat = function(m, format) {
07526 return d3_scale_linearTickFormat(domain, m, format);
07527 };
07528 scale.nice = function(m) {
07529 d3_scale_linearNice(domain, m);
07530 return rescale();
07531 };
07532 scale.copy = function() {
07533 return d3_scale_linear(domain, range, interpolate, clamp);
07534 };
07535 return rescale();
07536 }
07537 function d3_scale_linearRebind(scale, linear) {
07538 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
07539 }
07540 function d3_scale_linearNice(domain, m) {
07541 return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
07542 }
07543 function d3_scale_linearTickRange(domain, m) {
07544 if (m == null) m = 10;
07545 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;
07546 if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
07547 extent[0] = Math.ceil(extent[0] / step) * step;
07548 extent[1] = Math.floor(extent[1] / step) * step + step * .5;
07549 extent[2] = step;
07550 return extent;
07551 }
07552 function d3_scale_linearTicks(domain, m) {
07553 return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
07554 }
07555 function d3_scale_linearTickFormat(domain, m, format) {
07556 var range = d3_scale_linearTickRange(domain, m);
07557 if (format) {
07558 var match = d3_format_re.exec(format);
07559 match.shift();
07560 if (match[8] === "s") {
07561 var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
07562 if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
07563 match[8] = "f";
07564 format = d3.format(match.join(""));
07565 return function(d) {
07566 return format(prefix.scale(d)) + prefix.symbol;
07567 };
07568 }
07569 if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
07570 format = match.join("");
07571 } else {
07572 format = ",." + d3_scale_linearPrecision(range[2]) + "f";
07573 }
07574 return d3.format(format);
07575 }
07576 var d3_scale_linearFormatSignificant = {
07577 s: 1,
07578 g: 1,
07579 p: 1,
07580 r: 1,
07581 e: 1
07582 };
07583 function d3_scale_linearPrecision(value) {
07584 return -Math.floor(Math.log(value) / Math.LN10 + .01);
07585 }
07586 function d3_scale_linearFormatPrecision(type, range) {
07587 var p = d3_scale_linearPrecision(range[2]);
07588 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;
07589 }
07590 d3.scale.log = function() {
07591 return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
07592 };
07593 function d3_scale_log(linear, base, positive, domain) {
07594 function log(x) {
07595 return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
07596 }
07597 function pow(x) {
07598 return positive ? Math.pow(base, x) : -Math.pow(base, -x);
07599 }
07600 function scale(x) {
07601 return linear(log(x));
07602 }
07603 scale.invert = function(x) {
07604 return pow(linear.invert(x));
07605 };
07606 scale.domain = function(x) {
07607 if (!arguments.length) return domain;
07608 positive = x[0] >= 0;
07609 linear.domain((domain = x.map(Number)).map(log));
07610 return scale;
07611 };
07612 scale.base = function(_) {
07613 if (!arguments.length) return base;
07614 base = +_;
07615 linear.domain(domain.map(log));
07616 return scale;
07617 };
07618 scale.nice = function() {
07619 var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
07620 linear.domain(niced);
07621 domain = niced.map(pow);
07622 return scale;
07623 };
07624 scale.ticks = function() {
07625 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;
07626 if (isFinite(j - i)) {
07627 if (positive) {
07628 for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
07629 ticks.push(pow(i));
07630 } else {
07631 ticks.push(pow(i));
07632 for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
07633 }
07634 for (i = 0; ticks[i] < u; i++) {}
07635 for (j = ticks.length; ticks[j - 1] > v; j--) {}
07636 ticks = ticks.slice(i, j);
07637 }
07638 return ticks;
07639 };
07640 scale.tickFormat = function(n, format) {
07641 if (!arguments.length) return d3_scale_logFormat;
07642 if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
07643 var k = Math.max(.1, n / scale.ticks().length), f = positive ? (e = 1e-12, Math.ceil) : (e = -1e-12,
07644 Math.floor), e;
07645 return function(d) {
07646 return d / pow(f(log(d) + e)) <= k ? format(d) : "";
07647 };
07648 };
07649 scale.copy = function() {
07650 return d3_scale_log(linear.copy(), base, positive, domain);
07651 };
07652 return d3_scale_linearRebind(scale, linear);
07653 }
07654 var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
07655 floor: function(x) {
07656 return -Math.ceil(-x);
07657 },
07658 ceil: function(x) {
07659 return -Math.floor(-x);
07660 }
07661 };
07662 d3.scale.pow = function() {
07663 return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
07664 };
07665 function d3_scale_pow(linear, exponent, domain) {
07666 var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
07667 function scale(x) {
07668 return linear(powp(x));
07669 }
07670 scale.invert = function(x) {
07671 return powb(linear.invert(x));
07672 };
07673 scale.domain = function(x) {
07674 if (!arguments.length) return domain;
07675 linear.domain((domain = x.map(Number)).map(powp));
07676 return scale;
07677 };
07678 scale.ticks = function(m) {
07679 return d3_scale_linearTicks(domain, m);
07680 };
07681 scale.tickFormat = function(m, format) {
07682 return d3_scale_linearTickFormat(domain, m, format);
07683 };
07684 scale.nice = function(m) {
07685 return scale.domain(d3_scale_linearNice(domain, m));
07686 };
07687 scale.exponent = function(x) {
07688 if (!arguments.length) return exponent;
07689 powp = d3_scale_powPow(exponent = x);
07690 powb = d3_scale_powPow(1 / exponent);
07691 linear.domain(domain.map(powp));
07692 return scale;
07693 };
07694 scale.copy = function() {
07695 return d3_scale_pow(linear.copy(), exponent, domain);
07696 };
07697 return d3_scale_linearRebind(scale, linear);
07698 }
07699 function d3_scale_powPow(e) {
07700 return function(x) {
07701 return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
07702 };
07703 }
07704 d3.scale.sqrt = function() {
07705 return d3.scale.pow().exponent(.5);
07706 };
07707 d3.scale.ordinal = function() {
07708 return d3_scale_ordinal([], {
07709 t: "range",
07710 a: [ [] ]
07711 });
07712 };
07713 function d3_scale_ordinal(domain, ranger) {
07714 var index, range, rangeBand;
07715 function scale(x) {
07716 return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
07717 }
07718 function steps(start, step) {
07719 return d3.range(domain.length).map(function(i) {
07720 return start + step * i;
07721 });
07722 }
07723 scale.domain = function(x) {
07724 if (!arguments.length) return domain;
07725 domain = [];
07726 index = new d3_Map();
07727 var i = -1, n = x.length, xi;
07728 while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
07729 return scale[ranger.t].apply(scale, ranger.a);
07730 };
07731 scale.range = function(x) {
07732 if (!arguments.length) return range;
07733 range = x;
07734 rangeBand = 0;
07735 ranger = {
07736 t: "range",
07737 a: arguments
07738 };
07739 return scale;
07740 };
07741 scale.rangePoints = function(x, padding) {
07742 if (arguments.length < 2) padding = 0;
07743 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
07744 0) : (stop - start) / (domain.length - 1 + padding);
07745 range = steps(start + step * padding / 2, step);
07746 rangeBand = 0;
07747 ranger = {
07748 t: "rangePoints",
07749 a: arguments
07750 };
07751 return scale;
07752 };
07753 scale.rangeRoundPoints = function(x, padding) {
07754 if (arguments.length < 2) padding = 0;
07755 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
07756 0) : (stop - start) / (domain.length - 1 + padding) | 0;
07757 range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
07758 rangeBand = 0;
07759 ranger = {
07760 t: "rangeRoundPoints",
07761 a: arguments
07762 };
07763 return scale;
07764 };
07765 scale.rangeBands = function(x, padding, outerPadding) {
07766 if (arguments.length < 2) padding = 0;
07767 if (arguments.length < 3) outerPadding = padding;
07768 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
07769 range = steps(start + step * outerPadding, step);
07770 if (reverse) range.reverse();
07771 rangeBand = step * (1 - padding);
07772 ranger = {
07773 t: "rangeBands",
07774 a: arguments
07775 };
07776 return scale;
07777 };
07778 scale.rangeRoundBands = function(x, padding, outerPadding) {
07779 if (arguments.length < 2) padding = 0;
07780 if (arguments.length < 3) outerPadding = padding;
07781 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
07782 range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
07783 if (reverse) range.reverse();
07784 rangeBand = Math.round(step * (1 - padding));
07785 ranger = {
07786 t: "rangeRoundBands",
07787 a: arguments
07788 };
07789 return scale;
07790 };
07791 scale.rangeBand = function() {
07792 return rangeBand;
07793 };
07794 scale.rangeExtent = function() {
07795 return d3_scaleExtent(ranger.a[0]);
07796 };
07797 scale.copy = function() {
07798 return d3_scale_ordinal(domain, ranger);
07799 };
07800 return scale.domain(domain);
07801 }
07802 d3.scale.category10 = function() {
07803 return d3.scale.ordinal().range(d3_category10);
07804 };
07805 d3.scale.category20 = function() {
07806 return d3.scale.ordinal().range(d3_category20);
07807 };
07808 d3.scale.category20b = function() {
07809 return d3.scale.ordinal().range(d3_category20b);
07810 };
07811 d3.scale.category20c = function() {
07812 return d3.scale.ordinal().range(d3_category20c);
07813 };
07814 var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
07815 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);
07816 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);
07817 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);
07818 d3.scale.quantile = function() {
07819 return d3_scale_quantile([], []);
07820 };
07821 function d3_scale_quantile(domain, range) {
07822 var thresholds;
07823 function rescale() {
07824 var k = 0, q = range.length;
07825 thresholds = [];
07826 while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
07827 return scale;
07828 }
07829 function scale(x) {
07830 if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
07831 }
07832 scale.domain = function(x) {
07833 if (!arguments.length) return domain;
07834 domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
07835 return rescale();
07836 };
07837 scale.range = function(x) {
07838 if (!arguments.length) return range;
07839 range = x;
07840 return rescale();
07841 };
07842 scale.quantiles = function() {
07843 return thresholds;
07844 };
07845 scale.invertExtent = function(y) {
07846 y = range.indexOf(y);
07847 return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
07848 };
07849 scale.copy = function() {
07850 return d3_scale_quantile(domain, range);
07851 };
07852 return rescale();
07853 }
07854 d3.scale.quantize = function() {
07855 return d3_scale_quantize(0, 1, [ 0, 1 ]);
07856 };
07857 function d3_scale_quantize(x0, x1, range) {
07858 var kx, i;
07859 function scale(x) {
07860 return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
07861 }
07862 function rescale() {
07863 kx = range.length / (x1 - x0);
07864 i = range.length - 1;
07865 return scale;
07866 }
07867 scale.domain = function(x) {
07868 if (!arguments.length) return [ x0, x1 ];
07869 x0 = +x[0];
07870 x1 = +x[x.length - 1];
07871 return rescale();
07872 };
07873 scale.range = function(x) {
07874 if (!arguments.length) return range;
07875 range = x;
07876 return rescale();
07877 };
07878 scale.invertExtent = function(y) {
07879 y = range.indexOf(y);
07880 y = y < 0 ? NaN : y / kx + x0;
07881 return [ y, y + 1 / kx ];
07882 };
07883 scale.copy = function() {
07884 return d3_scale_quantize(x0, x1, range);
07885 };
07886 return rescale();
07887 }
07888 d3.scale.threshold = function() {
07889 return d3_scale_threshold([ .5 ], [ 0, 1 ]);
07890 };
07891 function d3_scale_threshold(domain, range) {
07892 function scale(x) {
07893 if (x <= x) return range[d3.bisect(domain, x)];
07894 }
07895 scale.domain = function(_) {
07896 if (!arguments.length) return domain;
07897 domain = _;
07898 return scale;
07899 };
07900 scale.range = function(_) {
07901 if (!arguments.length) return range;
07902 range = _;
07903 return scale;
07904 };
07905 scale.invertExtent = function(y) {
07906 y = range.indexOf(y);
07907 return [ domain[y - 1], domain[y] ];
07908 };
07909 scale.copy = function() {
07910 return d3_scale_threshold(domain, range);
07911 };
07912 return scale;
07913 }
07914 d3.scale.identity = function() {
07915 return d3_scale_identity([ 0, 1 ]);
07916 };
07917 function d3_scale_identity(domain) {
07918 function identity(x) {
07919 return +x;
07920 }
07921 identity.invert = identity;
07922 identity.domain = identity.range = function(x) {
07923 if (!arguments.length) return domain;
07924 domain = x.map(identity);
07925 return identity;
07926 };
07927 identity.ticks = function(m) {
07928 return d3_scale_linearTicks(domain, m);
07929 };
07930 identity.tickFormat = function(m, format) {
07931 return d3_scale_linearTickFormat(domain, m, format);
07932 };
07933 identity.copy = function() {
07934 return d3_scale_identity(domain);
07935 };
07936 return identity;
07937 }
07938 d3.svg = {};
07939 function d3_zero() {
07940 return 0;
07941 }
07942 d3.svg.arc = function() {
07943 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;
07944 function arc() {
07945 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;
07946 if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
07947 if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
07948 var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
07949 if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
07950 rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
07951 if (!cw) p1 *= -1;
07952 if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
07953 if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
07954 }
07955 if (r1) {
07956 x0 = r1 * Math.cos(a0 + p1);
07957 y0 = r1 * Math.sin(a0 + p1);
07958 x1 = r1 * Math.cos(a1 - p1);
07959 y1 = r1 * Math.sin(a1 - p1);
07960 var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
07961 if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
07962 var h1 = (a0 + a1) / 2;
07963 x0 = r1 * Math.cos(h1);
07964 y0 = r1 * Math.sin(h1);
07965 x1 = y1 = null;
07966 }
07967 } else {
07968 x0 = y0 = 0;
07969 }
07970 if (r0) {
07971 x2 = r0 * Math.cos(a1 - p0);
07972 y2 = r0 * Math.sin(a1 - p0);
07973 x3 = r0 * Math.cos(a0 + p0);
07974 y3 = r0 * Math.sin(a0 + p0);
07975 var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
07976 if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
07977 var h0 = (a0 + a1) / 2;
07978 x2 = r0 * Math.cos(h0);
07979 y2 = r0 * Math.sin(h0);
07980 x3 = y3 = null;
07981 }
07982 } else {
07983 x2 = y2 = 0;
07984 }
07985 if ((rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
07986 cr = r0 < r1 ^ cw ? 0 : 1;
07987 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]);
07988 if (x1 != null) {
07989 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);
07990 if (rc === rc1) {
07991 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]);
07992 } else {
07993 path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
07994 }
07995 } else {
07996 path.push("M", x0, ",", y0);
07997 }
07998 if (x3 != null) {
07999 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);
08000 if (rc === rc0) {
08001 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]);
08002 } else {
08003 path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
08004 }
08005 } else {
08006 path.push("L", x2, ",", y2);
08007 }
08008 } else {
08009 path.push("M", x0, ",", y0);
08010 if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
08011 path.push("L", x2, ",", y2);
08012 if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
08013 }
08014 path.push("Z");
08015 return path.join("");
08016 }
08017 function circleSegment(r1, cw) {
08018 return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
08019 }
08020 arc.innerRadius = function(v) {
08021 if (!arguments.length) return innerRadius;
08022 innerRadius = d3_functor(v);
08023 return arc;
08024 };
08025 arc.outerRadius = function(v) {
08026 if (!arguments.length) return outerRadius;
08027 outerRadius = d3_functor(v);
08028 return arc;
08029 };
08030 arc.cornerRadius = function(v) {
08031 if (!arguments.length) return cornerRadius;
08032 cornerRadius = d3_functor(v);
08033 return arc;
08034 };
08035 arc.padRadius = function(v) {
08036 if (!arguments.length) return padRadius;
08037 padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
08038 return arc;
08039 };
08040 arc.startAngle = function(v) {
08041 if (!arguments.length) return startAngle;
08042 startAngle = d3_functor(v);
08043 return arc;
08044 };
08045 arc.endAngle = function(v) {
08046 if (!arguments.length) return endAngle;
08047 endAngle = d3_functor(v);
08048 return arc;
08049 };
08050 arc.padAngle = function(v) {
08051 if (!arguments.length) return padAngle;
08052 padAngle = d3_functor(v);
08053 return arc;
08054 };
08055 arc.centroid = function() {
08056 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
08057 return [ Math.cos(a) * r, Math.sin(a) * r ];
08058 };
08059 return arc;
08060 };
08061 var d3_svg_arcAuto = "auto";
08062 function d3_svg_arcInnerRadius(d) {
08063 return d.innerRadius;
08064 }
08065 function d3_svg_arcOuterRadius(d) {
08066 return d.outerRadius;
08067 }
08068 function d3_svg_arcStartAngle(d) {
08069 return d.startAngle;
08070 }
08071 function d3_svg_arcEndAngle(d) {
08072 return d.endAngle;
08073 }
08074 function d3_svg_arcPadAngle(d) {
08075 return d && d.padAngle;
08076 }
08077 function d3_svg_arcSweep(x0, y0, x1, y1) {
08078 return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
08079 }
08080 function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
08081 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;
08082 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
08083 return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
08084 }
08085 function d3_svg_line(projection) {
08086 var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
08087 function line(data) {
08088 var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
08089 function segment() {
08090 segments.push("M", interpolate(projection(points), tension));
08091 }
08092 while (++i < n) {
08093 if (defined.call(this, d = data[i], i)) {
08094 points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
08095 } else if (points.length) {
08096 segment();
08097 points = [];
08098 }
08099 }
08100 if (points.length) segment();
08101 return segments.length ? segments.join("") : null;
08102 }
08103 line.x = function(_) {
08104 if (!arguments.length) return x;
08105 x = _;
08106 return line;
08107 };
08108 line.y = function(_) {
08109 if (!arguments.length) return y;
08110 y = _;
08111 return line;
08112 };
08113 line.defined = function(_) {
08114 if (!arguments.length) return defined;
08115 defined = _;
08116 return line;
08117 };
08118 line.interpolate = function(_) {
08119 if (!arguments.length) return interpolateKey;
08120 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
08121 return line;
08122 };
08123 line.tension = function(_) {
08124 if (!arguments.length) return tension;
08125 tension = _;
08126 return line;
08127 };
08128 return line;
08129 }
08130 d3.svg.line = function() {
08131 return d3_svg_line(d3_identity);
08132 };
08133 var d3_svg_lineInterpolators = d3.map({
08134 linear: d3_svg_lineLinear,
08135 "linear-closed": d3_svg_lineLinearClosed,
08136 step: d3_svg_lineStep,
08137 "step-before": d3_svg_lineStepBefore,
08138 "step-after": d3_svg_lineStepAfter,
08139 basis: d3_svg_lineBasis,
08140 "basis-open": d3_svg_lineBasisOpen,
08141 "basis-closed": d3_svg_lineBasisClosed,
08142 bundle: d3_svg_lineBundle,
08143 cardinal: d3_svg_lineCardinal,
08144 "cardinal-open": d3_svg_lineCardinalOpen,
08145 "cardinal-closed": d3_svg_lineCardinalClosed,
08146 monotone: d3_svg_lineMonotone
08147 });
08148 d3_svg_lineInterpolators.forEach(function(key, value) {
08149 value.key = key;
08150 value.closed = /-closed$/.test(key);
08151 });
08152 function d3_svg_lineLinear(points) {
08153 return points.join("L");
08154 }
08155 function d3_svg_lineLinearClosed(points) {
08156 return d3_svg_lineLinear(points) + "Z";
08157 }
08158 function d3_svg_lineStep(points) {
08159 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
08160 while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
08161 if (n > 1) path.push("H", p[0]);
08162 return path.join("");
08163 }
08164 function d3_svg_lineStepBefore(points) {
08165 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
08166 while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
08167 return path.join("");
08168 }
08169 function d3_svg_lineStepAfter(points) {
08170 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
08171 while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
08172 return path.join("");
08173 }
08174 function d3_svg_lineCardinalOpen(points, tension) {
08175 return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
08176 }
08177 function d3_svg_lineCardinalClosed(points, tension) {
08178 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
08179 points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
08180 }
08181 function d3_svg_lineCardinal(points, tension) {
08182 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
08183 }
08184 function d3_svg_lineHermite(points, tangents) {
08185 if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
08186 return d3_svg_lineLinear(points);
08187 }
08188 var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
08189 if (quad) {
08190 path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
08191 p0 = points[1];
08192 pi = 2;
08193 }
08194 if (tangents.length > 1) {
08195 t = tangents[1];
08196 p = points[pi];
08197 pi++;
08198 path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
08199 for (var i = 2; i < tangents.length; i++, pi++) {
08200 p = points[pi];
08201 t = tangents[i];
08202 path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
08203 }
08204 }
08205 if (quad) {
08206 var lp = points[pi];
08207 path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
08208 }
08209 return path;
08210 }
08211 function d3_svg_lineCardinalTangents(points, tension) {
08212 var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
08213 while (++i < n) {
08214 p0 = p1;
08215 p1 = p2;
08216 p2 = points[i];
08217 tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
08218 }
08219 return tangents;
08220 }
08221 function d3_svg_lineBasis(points) {
08222 if (points.length < 3) return d3_svg_lineLinear(points);
08223 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) ];
08224 points.push(points[n - 1]);
08225 while (++i <= n) {
08226 pi = points[i];
08227 px.shift();
08228 px.push(pi[0]);
08229 py.shift();
08230 py.push(pi[1]);
08231 d3_svg_lineBasisBezier(path, px, py);
08232 }
08233 points.pop();
08234 path.push("L", pi);
08235 return path.join("");
08236 }
08237 function d3_svg_lineBasisOpen(points) {
08238 if (points.length < 4) return d3_svg_lineLinear(points);
08239 var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
08240 while (++i < 3) {
08241 pi = points[i];
08242 px.push(pi[0]);
08243 py.push(pi[1]);
08244 }
08245 path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
08246 --i;
08247 while (++i < n) {
08248 pi = points[i];
08249 px.shift();
08250 px.push(pi[0]);
08251 py.shift();
08252 py.push(pi[1]);
08253 d3_svg_lineBasisBezier(path, px, py);
08254 }
08255 return path.join("");
08256 }
08257 function d3_svg_lineBasisClosed(points) {
08258 var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
08259 while (++i < 4) {
08260 pi = points[i % n];
08261 px.push(pi[0]);
08262 py.push(pi[1]);
08263 }
08264 path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
08265 --i;
08266 while (++i < m) {
08267 pi = points[i % n];
08268 px.shift();
08269 px.push(pi[0]);
08270 py.shift();
08271 py.push(pi[1]);
08272 d3_svg_lineBasisBezier(path, px, py);
08273 }
08274 return path.join("");
08275 }
08276 function d3_svg_lineBundle(points, tension) {
08277 var n = points.length - 1;
08278 if (n) {
08279 var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
08280 while (++i <= n) {
08281 p = points[i];
08282 t = i / n;
08283 p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
08284 p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
08285 }
08286 }
08287 return d3_svg_lineBasis(points);
08288 }
08289 function d3_svg_lineDot4(a, b) {
08290 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
08291 }
08292 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 ];
08293 function d3_svg_lineBasisBezier(path, x, y) {
08294 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));
08295 }
08296 function d3_svg_lineSlope(p0, p1) {
08297 return (p1[1] - p0[1]) / (p1[0] - p0[0]);
08298 }
08299 function d3_svg_lineFiniteDifferences(points) {
08300 var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
08301 while (++i < j) {
08302 m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
08303 }
08304 m[i] = d;
08305 return m;
08306 }
08307 function d3_svg_lineMonotoneTangents(points) {
08308 var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
08309 while (++i < j) {
08310 d = d3_svg_lineSlope(points[i], points[i + 1]);
08311 if (abs(d) < ε) {
08312 m[i] = m[i + 1] = 0;
08313 } else {
08314 a = m[i] / d;
08315 b = m[i + 1] / d;
08316 s = a * a + b * b;
08317 if (s > 9) {
08318 s = d * 3 / Math.sqrt(s);
08319 m[i] = s * a;
08320 m[i + 1] = s * b;
08321 }
08322 }
08323 }
08324 i = -1;
08325 while (++i <= j) {
08326 s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
08327 tangents.push([ s || 0, m[i] * s || 0 ]);
08328 }
08329 return tangents;
08330 }
08331 function d3_svg_lineMonotone(points) {
08332 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
08333 }
08334 d3.svg.line.radial = function() {
08335 var line = d3_svg_line(d3_svg_lineRadial);
08336 line.radius = line.x, delete line.x;
08337 line.angle = line.y, delete line.y;
08338 return line;
08339 };
08340 function d3_svg_lineRadial(points) {
08341 var point, i = -1, n = points.length, r, a;
08342 while (++i < n) {
08343 point = points[i];
08344 r = point[0];
08345 a = point[1] - halfπ;
08346 point[0] = r * Math.cos(a);
08347 point[1] = r * Math.sin(a);
08348 }
08349 return points;
08350 }
08351 function d3_svg_area(projection) {
08352 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;
08353 function area(data) {
08354 var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
08355 return x;
08356 } : d3_functor(x1), fy1 = y0 === y1 ? function() {
08357 return y;
08358 } : d3_functor(y1), x, y;
08359 function segment() {
08360 segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
08361 }
08362 while (++i < n) {
08363 if (defined.call(this, d = data[i], i)) {
08364 points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
08365 points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
08366 } else if (points0.length) {
08367 segment();
08368 points0 = [];
08369 points1 = [];
08370 }
08371 }
08372 if (points0.length) segment();
08373 return segments.length ? segments.join("") : null;
08374 }
08375 area.x = function(_) {
08376 if (!arguments.length) return x1;
08377 x0 = x1 = _;
08378 return area;
08379 };
08380 area.x0 = function(_) {
08381 if (!arguments.length) return x0;
08382 x0 = _;
08383 return area;
08384 };
08385 area.x1 = function(_) {
08386 if (!arguments.length) return x1;
08387 x1 = _;
08388 return area;
08389 };
08390 area.y = function(_) {
08391 if (!arguments.length) return y1;
08392 y0 = y1 = _;
08393 return area;
08394 };
08395 area.y0 = function(_) {
08396 if (!arguments.length) return y0;
08397 y0 = _;
08398 return area;
08399 };
08400 area.y1 = function(_) {
08401 if (!arguments.length) return y1;
08402 y1 = _;
08403 return area;
08404 };
08405 area.defined = function(_) {
08406 if (!arguments.length) return defined;
08407 defined = _;
08408 return area;
08409 };
08410 area.interpolate = function(_) {
08411 if (!arguments.length) return interpolateKey;
08412 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
08413 interpolateReverse = interpolate.reverse || interpolate;
08414 L = interpolate.closed ? "M" : "L";
08415 return area;
08416 };
08417 area.tension = function(_) {
08418 if (!arguments.length) return tension;
08419 tension = _;
08420 return area;
08421 };
08422 return area;
08423 }
08424 d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
08425 d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
08426 d3.svg.area = function() {
08427 return d3_svg_area(d3_identity);
08428 };
08429 d3.svg.area.radial = function() {
08430 var area = d3_svg_area(d3_svg_lineRadial);
08431 area.radius = area.x, delete area.x;
08432 area.innerRadius = area.x0, delete area.x0;
08433 area.outerRadius = area.x1, delete area.x1;
08434 area.angle = area.y, delete area.y;
08435 area.startAngle = area.y0, delete area.y0;
08436 area.endAngle = area.y1, delete area.y1;
08437 return area;
08438 };
08439 d3.svg.chord = function() {
08440 var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
08441 function chord(d, i) {
08442 var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
08443 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";
08444 }
08445 function subgroup(self, f, d, i) {
08446 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π;
08447 return {
08448 r: r,
08449 a0: a0,
08450 a1: a1,
08451 p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
08452 p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
08453 };
08454 }
08455 function equals(a, b) {
08456 return a.a0 == b.a0 && a.a1 == b.a1;
08457 }
08458 function arc(r, p, a) {
08459 return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
08460 }
08461 function curve(r0, p0, r1, p1) {
08462 return "Q 0,0 " + p1;
08463 }
08464 chord.radius = function(v) {
08465 if (!arguments.length) return radius;
08466 radius = d3_functor(v);
08467 return chord;
08468 };
08469 chord.source = function(v) {
08470 if (!arguments.length) return source;
08471 source = d3_functor(v);
08472 return chord;
08473 };
08474 chord.target = function(v) {
08475 if (!arguments.length) return target;
08476 target = d3_functor(v);
08477 return chord;
08478 };
08479 chord.startAngle = function(v) {
08480 if (!arguments.length) return startAngle;
08481 startAngle = d3_functor(v);
08482 return chord;
08483 };
08484 chord.endAngle = function(v) {
08485 if (!arguments.length) return endAngle;
08486 endAngle = d3_functor(v);
08487 return chord;
08488 };
08489 return chord;
08490 };
08491 function d3_svg_chordRadius(d) {
08492 return d.radius;
08493 }
08494 d3.svg.diagonal = function() {
08495 var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
08496 function diagonal(d, i) {
08497 var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
08498 x: p0.x,
08499 y: m
08500 }, {
08501 x: p3.x,
08502 y: m
08503 }, p3 ];
08504 p = p.map(projection);
08505 return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
08506 }
08507 diagonal.source = function(x) {
08508 if (!arguments.length) return source;
08509 source = d3_functor(x);
08510 return diagonal;
08511 };
08512 diagonal.target = function(x) {
08513 if (!arguments.length) return target;
08514 target = d3_functor(x);
08515 return diagonal;
08516 };
08517 diagonal.projection = function(x) {
08518 if (!arguments.length) return projection;
08519 projection = x;
08520 return diagonal;
08521 };
08522 return diagonal;
08523 };
08524 function d3_svg_diagonalProjection(d) {
08525 return [ d.x, d.y ];
08526 }
08527 d3.svg.diagonal.radial = function() {
08528 var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
08529 diagonal.projection = function(x) {
08530 return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
08531 };
08532 return diagonal;
08533 };
08534 function d3_svg_diagonalRadialProjection(projection) {
08535 return function() {
08536 var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
08537 return [ r * Math.cos(a), r * Math.sin(a) ];
08538 };
08539 }
08540 d3.svg.symbol = function() {
08541 var type = d3_svg_symbolType, size = d3_svg_symbolSize;
08542 function symbol(d, i) {
08543 return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
08544 }
08545 symbol.type = function(x) {
08546 if (!arguments.length) return type;
08547 type = d3_functor(x);
08548 return symbol;
08549 };
08550 symbol.size = function(x) {
08551 if (!arguments.length) return size;
08552 size = d3_functor(x);
08553 return symbol;
08554 };
08555 return symbol;
08556 };
08557 function d3_svg_symbolSize() {
08558 return 64;
08559 }
08560 function d3_svg_symbolType() {
08561 return "circle";
08562 }
08563 function d3_svg_symbolCircle(size) {
08564 var r = Math.sqrt(size / π);
08565 return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
08566 }
08567 var d3_svg_symbols = d3.map({
08568 circle: d3_svg_symbolCircle,
08569 cross: function(size) {
08570 var r = Math.sqrt(size / 5) / 2;
08571 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";
08572 },
08573 diamond: function(size) {
08574 var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
08575 return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
08576 },
08577 square: function(size) {
08578 var r = Math.sqrt(size) / 2;
08579 return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
08580 },
08581 "triangle-down": function(size) {
08582 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
08583 return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
08584 },
08585 "triangle-up": function(size) {
08586 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
08587 return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
08588 }
08589 });
08590 d3.svg.symbolTypes = d3_svg_symbols.keys();
08591 var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
08592 d3_selectionPrototype.transition = function(name) {
08593 var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
08594 time: Date.now(),
08595 ease: d3_ease_cubicInOut,
08596 delay: 0,
08597 duration: 250
08598 };
08599 for (var j = -1, m = this.length; ++j < m; ) {
08600 subgroups.push(subgroup = []);
08601 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
08602 if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
08603 subgroup.push(node);
08604 }
08605 }
08606 return d3_transition(subgroups, ns, id);
08607 };
08608 d3_selectionPrototype.interrupt = function(name) {
08609 return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
08610 };
08611 var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
08612 function d3_selection_interruptNS(ns) {
08613 return function() {
08614 var lock, active;
08615 if ((lock = this[ns]) && (active = lock[lock.active])) {
08616 if (--lock.count) delete lock[lock.active]; else delete this[ns];
08617 lock.active += .5;
08618 active.event && active.event.interrupt.call(this, this.__data__, active.index);
08619 }
08620 };
08621 }
08622 function d3_transition(groups, ns, id) {
08623 d3_subclass(groups, d3_transitionPrototype);
08624 groups.namespace = ns;
08625 groups.id = id;
08626 return groups;
08627 }
08628 var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
08629 d3_transitionPrototype.call = d3_selectionPrototype.call;
08630 d3_transitionPrototype.empty = d3_selectionPrototype.empty;
08631 d3_transitionPrototype.node = d3_selectionPrototype.node;
08632 d3_transitionPrototype.size = d3_selectionPrototype.size;
08633 d3.transition = function(selection, name) {
08634 return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
08635 };
08636 d3.transition.prototype = d3_transitionPrototype;
08637 d3_transitionPrototype.select = function(selector) {
08638 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
08639 selector = d3_selection_selector(selector);
08640 for (var j = -1, m = this.length; ++j < m; ) {
08641 subgroups.push(subgroup = []);
08642 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
08643 if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
08644 if ("__data__" in node) subnode.__data__ = node.__data__;
08645 d3_transitionNode(subnode, i, ns, id, node[ns][id]);
08646 subgroup.push(subnode);
08647 } else {
08648 subgroup.push(null);
08649 }
08650 }
08651 }
08652 return d3_transition(subgroups, ns, id);
08653 };
08654 d3_transitionPrototype.selectAll = function(selector) {
08655 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
08656 selector = d3_selection_selectorAll(selector);
08657 for (var j = -1, m = this.length; ++j < m; ) {
08658 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
08659 if (node = group[i]) {
08660 transition = node[ns][id];
08661 subnodes = selector.call(node, node.__data__, i, j);
08662 subgroups.push(subgroup = []);
08663 for (var k = -1, o = subnodes.length; ++k < o; ) {
08664 if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
08665 subgroup.push(subnode);
08666 }
08667 }
08668 }
08669 }
08670 return d3_transition(subgroups, ns, id);
08671 };
08672 d3_transitionPrototype.filter = function(filter) {
08673 var subgroups = [], subgroup, group, node;
08674 if (typeof filter !== "function") filter = d3_selection_filter(filter);
08675 for (var j = 0, m = this.length; j < m; j++) {
08676 subgroups.push(subgroup = []);
08677 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
08678 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
08679 subgroup.push(node);
08680 }
08681 }
08682 }
08683 return d3_transition(subgroups, this.namespace, this.id);
08684 };
08685 d3_transitionPrototype.tween = function(name, tween) {
08686 var id = this.id, ns = this.namespace;
08687 if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
08688 return d3_selection_each(this, tween == null ? function(node) {
08689 node[ns][id].tween.remove(name);
08690 } : function(node) {
08691 node[ns][id].tween.set(name, tween);
08692 });
08693 };
08694 function d3_transition_tween(groups, name, value, tween) {
08695 var id = groups.id, ns = groups.namespace;
08696 return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
08697 node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
08698 } : (value = tween(value), function(node) {
08699 node[ns][id].tween.set(name, value);
08700 }));
08701 }
08702 d3_transitionPrototype.attr = function(nameNS, value) {
08703 if (arguments.length < 2) {
08704 for (value in nameNS) this.attr(value, nameNS[value]);
08705 return this;
08706 }
08707 var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
08708 function attrNull() {
08709 this.removeAttribute(name);
08710 }
08711 function attrNullNS() {
08712 this.removeAttributeNS(name.space, name.local);
08713 }
08714 function attrTween(b) {
08715 return b == null ? attrNull : (b += "", function() {
08716 var a = this.getAttribute(name), i;
08717 return a !== b && (i = interpolate(a, b), function(t) {
08718 this.setAttribute(name, i(t));
08719 });
08720 });
08721 }
08722 function attrTweenNS(b) {
08723 return b == null ? attrNullNS : (b += "", function() {
08724 var a = this.getAttributeNS(name.space, name.local), i;
08725 return a !== b && (i = interpolate(a, b), function(t) {
08726 this.setAttributeNS(name.space, name.local, i(t));
08727 });
08728 });
08729 }
08730 return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
08731 };
08732 d3_transitionPrototype.attrTween = function(nameNS, tween) {
08733 var name = d3.ns.qualify(nameNS);
08734 function attrTween(d, i) {
08735 var f = tween.call(this, d, i, this.getAttribute(name));
08736 return f && function(t) {
08737 this.setAttribute(name, f(t));
08738 };
08739 }
08740 function attrTweenNS(d, i) {
08741 var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
08742 return f && function(t) {
08743 this.setAttributeNS(name.space, name.local, f(t));
08744 };
08745 }
08746 return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
08747 };
08748 d3_transitionPrototype.style = function(name, value, priority) {
08749 var n = arguments.length;
08750 if (n < 3) {
08751 if (typeof name !== "string") {
08752 if (n < 2) value = "";
08753 for (priority in name) this.style(priority, name[priority], value);
08754 return this;
08755 }
08756 priority = "";
08757 }
08758 function styleNull() {
08759 this.style.removeProperty(name);
08760 }
08761 function styleString(b) {
08762 return b == null ? styleNull : (b += "", function() {
08763 var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
08764 return a !== b && (i = d3_interpolate(a, b), function(t) {
08765 this.style.setProperty(name, i(t), priority);
08766 });
08767 });
08768 }
08769 return d3_transition_tween(this, "style." + name, value, styleString);
08770 };
08771 d3_transitionPrototype.styleTween = function(name, tween, priority) {
08772 if (arguments.length < 3) priority = "";
08773 function styleTween(d, i) {
08774 var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
08775 return f && function(t) {
08776 this.style.setProperty(name, f(t), priority);
08777 };
08778 }
08779 return this.tween("style." + name, styleTween);
08780 };
08781 d3_transitionPrototype.text = function(value) {
08782 return d3_transition_tween(this, "text", value, d3_transition_text);
08783 };
08784 function d3_transition_text(b) {
08785 if (b == null) b = "";
08786 return function() {
08787 this.textContent = b;
08788 };
08789 }
08790 d3_transitionPrototype.remove = function() {
08791 var ns = this.namespace;
08792 return this.each("end.transition", function() {
08793 var p;
08794 if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
08795 });
08796 };
08797 d3_transitionPrototype.ease = function(value) {
08798 var id = this.id, ns = this.namespace;
08799 if (arguments.length < 1) return this.node()[ns][id].ease;
08800 if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
08801 return d3_selection_each(this, function(node) {
08802 node[ns][id].ease = value;
08803 });
08804 };
08805 d3_transitionPrototype.delay = function(value) {
08806 var id = this.id, ns = this.namespace;
08807 if (arguments.length < 1) return this.node()[ns][id].delay;
08808 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
08809 node[ns][id].delay = +value.call(node, node.__data__, i, j);
08810 } : (value = +value, function(node) {
08811 node[ns][id].delay = value;
08812 }));
08813 };
08814 d3_transitionPrototype.duration = function(value) {
08815 var id = this.id, ns = this.namespace;
08816 if (arguments.length < 1) return this.node()[ns][id].duration;
08817 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
08818 node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
08819 } : (value = Math.max(1, value), function(node) {
08820 node[ns][id].duration = value;
08821 }));
08822 };
08823 d3_transitionPrototype.each = function(type, listener) {
08824 var id = this.id, ns = this.namespace;
08825 if (arguments.length < 2) {
08826 var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
08827 try {
08828 d3_transitionInheritId = id;
08829 d3_selection_each(this, function(node, i, j) {
08830 d3_transitionInherit = node[ns][id];
08831 type.call(node, node.__data__, i, j);
08832 });
08833 } finally {
08834 d3_transitionInherit = inherit;
08835 d3_transitionInheritId = inheritId;
08836 }
08837 } else {
08838 d3_selection_each(this, function(node) {
08839 var transition = node[ns][id];
08840 (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
08841 });
08842 }
08843 return this;
08844 };
08845 d3_transitionPrototype.transition = function() {
08846 var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
08847 for (var j = 0, m = this.length; j < m; j++) {
08848 subgroups.push(subgroup = []);
08849 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
08850 if (node = group[i]) {
08851 transition = node[ns][id0];
08852 d3_transitionNode(node, i, ns, id1, {
08853 time: transition.time,
08854 ease: transition.ease,
08855 delay: transition.delay + transition.duration,
08856 duration: transition.duration
08857 });
08858 }
08859 subgroup.push(node);
08860 }
08861 }
08862 return d3_transition(subgroups, ns, id1);
08863 };
08864 function d3_transitionNamespace(name) {
08865 return name == null ? "__transition__" : "__transition_" + name + "__";
08866 }
08867 function d3_transitionNode(node, i, ns, id, inherit) {
08868 var lock = node[ns] || (node[ns] = {
08869 active: 0,
08870 count: 0
08871 }), transition = lock[id];
08872 if (!transition) {
08873 var time = inherit.time;
08874 transition = lock[id] = {
08875 tween: new d3_Map(),
08876 time: time,
08877 delay: inherit.delay,
08878 duration: inherit.duration,
08879 ease: inherit.ease,
08880 index: i
08881 };
08882 inherit = null;
08883 ++lock.count;
08884 d3.timer(function(elapsed) {
08885 var delay = transition.delay, duration, ease, timer = d3_timer_active, tweened = [];
08886 timer.t = delay + time;
08887 if (delay <= elapsed) return start(elapsed - delay);
08888 timer.c = start;
08889 function start(elapsed) {
08890 if (lock.active > id) return stop();
08891 var active = lock[lock.active];
08892 if (active) {
08893 --lock.count;
08894 delete lock[lock.active];
08895 active.event && active.event.interrupt.call(node, node.__data__, active.index);
08896 }
08897 lock.active = id;
08898 transition.event && transition.event.start.call(node, node.__data__, i);
08899 transition.tween.forEach(function(key, value) {
08900 if (value = value.call(node, node.__data__, i)) {
08901 tweened.push(value);
08902 }
08903 });
08904 ease = transition.ease;
08905 duration = transition.duration;
08906 d3.timer(function() {
08907 timer.c = tick(elapsed || 1) ? d3_true : tick;
08908 return 1;
08909 }, 0, time);
08910 }
08911 function tick(elapsed) {
08912 if (lock.active !== id) return 1;
08913 var t = elapsed / duration, e = ease(t), n = tweened.length;
08914 while (n > 0) {
08915 tweened[--n].call(node, e);
08916 }
08917 if (t >= 1) {
08918 transition.event && transition.event.end.call(node, node.__data__, i);
08919 return stop();
08920 }
08921 }
08922 function stop() {
08923 if (--lock.count) delete lock[id]; else delete node[ns];
08924 return 1;
08925 }
08926 }, 0, time);
08927 }
08928 }
08929 d3.svg.axis = function() {
08930 var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
08931 function axis(g) {
08932 g.each(function() {
08933 var g = d3.select(this);
08934 var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
08935 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;
08936 var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
08937 d3.transition(path));
08938 tickEnter.append("line");
08939 tickEnter.append("text");
08940 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;
08941 if (orient === "bottom" || orient === "top") {
08942 tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
08943 text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
08944 pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
08945 } else {
08946 tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
08947 text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
08948 pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
08949 }
08950 lineEnter.attr(y2, sign * innerTickSize);
08951 textEnter.attr(y1, sign * tickSpacing);
08952 lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
08953 textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
08954 if (scale1.rangeBand) {
08955 var x = scale1, dx = x.rangeBand() / 2;
08956 scale0 = scale1 = function(d) {
08957 return x(d) + dx;
08958 };
08959 } else if (scale0.rangeBand) {
08960 scale0 = scale1;
08961 } else {
08962 tickExit.call(tickTransform, scale1, scale0);
08963 }
08964 tickEnter.call(tickTransform, scale0, scale1);
08965 tickUpdate.call(tickTransform, scale1, scale1);
08966 });
08967 }
08968 axis.scale = function(x) {
08969 if (!arguments.length) return scale;
08970 scale = x;
08971 return axis;
08972 };
08973 axis.orient = function(x) {
08974 if (!arguments.length) return orient;
08975 orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
08976 return axis;
08977 };
08978 axis.ticks = function() {
08979 if (!arguments.length) return tickArguments_;
08980 tickArguments_ = arguments;
08981 return axis;
08982 };
08983 axis.tickValues = function(x) {
08984 if (!arguments.length) return tickValues;
08985 tickValues = x;
08986 return axis;
08987 };
08988 axis.tickFormat = function(x) {
08989 if (!arguments.length) return tickFormat_;
08990 tickFormat_ = x;
08991 return axis;
08992 };
08993 axis.tickSize = function(x) {
08994 var n = arguments.length;
08995 if (!n) return innerTickSize;
08996 innerTickSize = +x;
08997 outerTickSize = +arguments[n - 1];
08998 return axis;
08999 };
09000 axis.innerTickSize = function(x) {
09001 if (!arguments.length) return innerTickSize;
09002 innerTickSize = +x;
09003 return axis;
09004 };
09005 axis.outerTickSize = function(x) {
09006 if (!arguments.length) return outerTickSize;
09007 outerTickSize = +x;
09008 return axis;
09009 };
09010 axis.tickPadding = function(x) {
09011 if (!arguments.length) return tickPadding;
09012 tickPadding = +x;
09013 return axis;
09014 };
09015 axis.tickSubdivide = function() {
09016 return arguments.length && axis;
09017 };
09018 return axis;
09019 };
09020 var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
09021 top: 1,
09022 right: 1,
09023 bottom: 1,
09024 left: 1
09025 };
09026 function d3_svg_axisX(selection, x0, x1) {
09027 selection.attr("transform", function(d) {
09028 var v0 = x0(d);
09029 return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
09030 });
09031 }
09032 function d3_svg_axisY(selection, y0, y1) {
09033 selection.attr("transform", function(d) {
09034 var v0 = y0(d);
09035 return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
09036 });
09037 }
09038 d3.svg.brush = function() {
09039 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];
09040 function brush(g) {
09041 g.each(function() {
09042 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);
09043 var background = g.selectAll(".background").data([ 0 ]);
09044 background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
09045 g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
09046 var resize = g.selectAll(".resize").data(resizes, d3_identity);
09047 resize.exit().remove();
09048 resize.enter().append("g").attr("class", function(d) {
09049 return "resize " + d;
09050 }).style("cursor", function(d) {
09051 return d3_svg_brushCursor[d];
09052 }).append("rect").attr("x", function(d) {
09053 return /[ew]$/.test(d) ? -3 : null;
09054 }).attr("y", function(d) {
09055 return /^[ns]/.test(d) ? -3 : null;
09056 }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
09057 resize.style("display", brush.empty() ? "none" : null);
09058 var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
09059 if (x) {
09060 range = d3_scaleRange(x);
09061 backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
09062 redrawX(gUpdate);
09063 }
09064 if (y) {
09065 range = d3_scaleRange(y);
09066 backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
09067 redrawY(gUpdate);
09068 }
09069 redraw(gUpdate);
09070 });
09071 }
09072 brush.event = function(g) {
09073 g.each(function() {
09074 var event_ = event.of(this, arguments), extent1 = {
09075 x: xExtent,
09076 y: yExtent,
09077 i: xExtentDomain,
09078 j: yExtentDomain
09079 }, extent0 = this.__chart__ || extent1;
09080 this.__chart__ = extent1;
09081 if (d3_transitionInheritId) {
09082 d3.select(this).transition().each("start.brush", function() {
09083 xExtentDomain = extent0.i;
09084 yExtentDomain = extent0.j;
09085 xExtent = extent0.x;
09086 yExtent = extent0.y;
09087 event_({
09088 type: "brushstart"
09089 });
09090 }).tween("brush:brush", function() {
09091 var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
09092 xExtentDomain = yExtentDomain = null;
09093 return function(t) {
09094 xExtent = extent1.x = xi(t);
09095 yExtent = extent1.y = yi(t);
09096 event_({
09097 type: "brush",
09098 mode: "resize"
09099 });
09100 };
09101 }).each("end.brush", function() {
09102 xExtentDomain = extent1.i;
09103 yExtentDomain = extent1.j;
09104 event_({
09105 type: "brush",
09106 mode: "resize"
09107 });
09108 event_({
09109 type: "brushend"
09110 });
09111 });
09112 } else {
09113 event_({
09114 type: "brushstart"
09115 });
09116 event_({
09117 type: "brush",
09118 mode: "resize"
09119 });
09120 event_({
09121 type: "brushend"
09122 });
09123 }
09124 });
09125 };
09126 function redraw(g) {
09127 g.selectAll(".resize").attr("transform", function(d) {
09128 return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
09129 });
09130 }
09131 function redrawX(g) {
09132 g.select(".extent").attr("x", xExtent[0]);
09133 g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
09134 }
09135 function redrawY(g) {
09136 g.select(".extent").attr("y", yExtent[0]);
09137 g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
09138 }
09139 function brushstart() {
09140 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;
09141 var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
09142 if (d3.event.changedTouches) {
09143 w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
09144 } else {
09145 w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
09146 }
09147 g.interrupt().selectAll("*").interrupt();
09148 if (dragging) {
09149 origin[0] = xExtent[0] - origin[0];
09150 origin[1] = yExtent[0] - origin[1];
09151 } else if (resizing) {
09152 var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
09153 offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
09154 origin[0] = xExtent[ex];
09155 origin[1] = yExtent[ey];
09156 } else if (d3.event.altKey) center = origin.slice();
09157 g.style("pointer-events", "none").selectAll(".resize").style("display", null);
09158 d3.select("body").style("cursor", eventTarget.style("cursor"));
09159 event_({
09160 type: "brushstart"
09161 });
09162 brushmove();
09163 function keydown() {
09164 if (d3.event.keyCode == 32) {
09165 if (!dragging) {
09166 center = null;
09167 origin[0] -= xExtent[1];
09168 origin[1] -= yExtent[1];
09169 dragging = 2;
09170 }
09171 d3_eventPreventDefault();
09172 }
09173 }
09174 function keyup() {
09175 if (d3.event.keyCode == 32 && dragging == 2) {
09176 origin[0] += xExtent[1];
09177 origin[1] += yExtent[1];
09178 dragging = 0;
09179 d3_eventPreventDefault();
09180 }
09181 }
09182 function brushmove() {
09183 var point = d3.mouse(target), moved = false;
09184 if (offset) {
09185 point[0] += offset[0];
09186 point[1] += offset[1];
09187 }
09188 if (!dragging) {
09189 if (d3.event.altKey) {
09190 if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
09191 origin[0] = xExtent[+(point[0] < center[0])];
09192 origin[1] = yExtent[+(point[1] < center[1])];
09193 } else center = null;
09194 }
09195 if (resizingX && move1(point, x, 0)) {
09196 redrawX(g);
09197 moved = true;
09198 }
09199 if (resizingY && move1(point, y, 1)) {
09200 redrawY(g);
09201 moved = true;
09202 }
09203 if (moved) {
09204 redraw(g);
09205 event_({
09206 type: "brush",
09207 mode: dragging ? "move" : "resize"
09208 });
09209 }
09210 }
09211 function move1(point, scale, i) {
09212 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;
09213 if (dragging) {
09214 r0 -= position;
09215 r1 -= size + position;
09216 }
09217 min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
09218 if (dragging) {
09219 max = (min += position) + size;
09220 } else {
09221 if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
09222 if (position < min) {
09223 max = min;
09224 min = position;
09225 } else {
09226 max = position;
09227 }
09228 }
09229 if (extent[0] != min || extent[1] != max) {
09230 if (i) yExtentDomain = null; else xExtentDomain = null;
09231 extent[0] = min;
09232 extent[1] = max;
09233 return true;
09234 }
09235 }
09236 function brushend() {
09237 brushmove();
09238 g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
09239 d3.select("body").style("cursor", null);
09240 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);
09241 dragRestore();
09242 event_({
09243 type: "brushend"
09244 });
09245 }
09246 }
09247 brush.x = function(z) {
09248 if (!arguments.length) return x;
09249 x = z;
09250 resizes = d3_svg_brushResizes[!x << 1 | !y];
09251 return brush;
09252 };
09253 brush.y = function(z) {
09254 if (!arguments.length) return y;
09255 y = z;
09256 resizes = d3_svg_brushResizes[!x << 1 | !y];
09257 return brush;
09258 };
09259 brush.clamp = function(z) {
09260 if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
09261 if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
09262 return brush;
09263 };
09264 brush.extent = function(z) {
09265 var x0, x1, y0, y1, t;
09266 if (!arguments.length) {
09267 if (x) {
09268 if (xExtentDomain) {
09269 x0 = xExtentDomain[0], x1 = xExtentDomain[1];
09270 } else {
09271 x0 = xExtent[0], x1 = xExtent[1];
09272 if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
09273 if (x1 < x0) t = x0, x0 = x1, x1 = t;
09274 }
09275 }
09276 if (y) {
09277 if (yExtentDomain) {
09278 y0 = yExtentDomain[0], y1 = yExtentDomain[1];
09279 } else {
09280 y0 = yExtent[0], y1 = yExtent[1];
09281 if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
09282 if (y1 < y0) t = y0, y0 = y1, y1 = t;
09283 }
09284 }
09285 return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
09286 }
09287 if (x) {
09288 x0 = z[0], x1 = z[1];
09289 if (y) x0 = x0[0], x1 = x1[0];
09290 xExtentDomain = [ x0, x1 ];
09291 if (x.invert) x0 = x(x0), x1 = x(x1);
09292 if (x1 < x0) t = x0, x0 = x1, x1 = t;
09293 if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
09294 }
09295 if (y) {
09296 y0 = z[0], y1 = z[1];
09297 if (x) y0 = y0[1], y1 = y1[1];
09298 yExtentDomain = [ y0, y1 ];
09299 if (y.invert) y0 = y(y0), y1 = y(y1);
09300 if (y1 < y0) t = y0, y0 = y1, y1 = t;
09301 if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
09302 }
09303 return brush;
09304 };
09305 brush.clear = function() {
09306 if (!brush.empty()) {
09307 xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
09308 xExtentDomain = yExtentDomain = null;
09309 }
09310 return brush;
09311 };
09312 brush.empty = function() {
09313 return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
09314 };
09315 return d3.rebind(brush, event, "on");
09316 };
09317 var d3_svg_brushCursor = {
09318 n: "ns-resize",
09319 e: "ew-resize",
09320 s: "ns-resize",
09321 w: "ew-resize",
09322 nw: "nwse-resize",
09323 ne: "nesw-resize",
09324 se: "nwse-resize",
09325 sw: "nesw-resize"
09326 };
09327 var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
09328 var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
09329 var d3_time_formatUtc = d3_time_format.utc;
09330 var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
09331 d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
09332 function d3_time_formatIsoNative(date) {
09333 return date.toISOString();
09334 }
09335 d3_time_formatIsoNative.parse = function(string) {
09336 var date = new Date(string);
09337 return isNaN(date) ? null : date;
09338 };
09339 d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
09340 d3_time.second = d3_time_interval(function(date) {
09341 return new d3_date(Math.floor(date / 1e3) * 1e3);
09342 }, function(date, offset) {
09343 date.setTime(date.getTime() + Math.floor(offset) * 1e3);
09344 }, function(date) {
09345 return date.getSeconds();
09346 });
09347 d3_time.seconds = d3_time.second.range;
09348 d3_time.seconds.utc = d3_time.second.utc.range;
09349 d3_time.minute = d3_time_interval(function(date) {
09350 return new d3_date(Math.floor(date / 6e4) * 6e4);
09351 }, function(date, offset) {
09352 date.setTime(date.getTime() + Math.floor(offset) * 6e4);
09353 }, function(date) {
09354 return date.getMinutes();
09355 });
09356 d3_time.minutes = d3_time.minute.range;
09357 d3_time.minutes.utc = d3_time.minute.utc.range;
09358 d3_time.hour = d3_time_interval(function(date) {
09359 var timezone = date.getTimezoneOffset() / 60;
09360 return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
09361 }, function(date, offset) {
09362 date.setTime(date.getTime() + Math.floor(offset) * 36e5);
09363 }, function(date) {
09364 return date.getHours();
09365 });
09366 d3_time.hours = d3_time.hour.range;
09367 d3_time.hours.utc = d3_time.hour.utc.range;
09368 d3_time.month = d3_time_interval(function(date) {
09369 date = d3_time.day(date);
09370 date.setDate(1);
09371 return date;
09372 }, function(date, offset) {
09373 date.setMonth(date.getMonth() + offset);
09374 }, function(date) {
09375 return date.getMonth();
09376 });
09377 d3_time.months = d3_time.month.range;
09378 d3_time.months.utc = d3_time.month.utc.range;
09379 function d3_time_scale(linear, methods, format) {
09380 function scale(x) {
09381 return linear(x);
09382 }
09383 scale.invert = function(x) {
09384 return d3_time_scaleDate(linear.invert(x));
09385 };
09386 scale.domain = function(x) {
09387 if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
09388 linear.domain(x);
09389 return scale;
09390 };
09391 function tickMethod(extent, count) {
09392 var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
09393 return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
09394 return d / 31536e6;
09395 }), 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];
09396 }
09397 scale.nice = function(interval, skip) {
09398 var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
09399 if (method) interval = method[0], skip = method[1];
09400 function skipped(date) {
09401 return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
09402 }
09403 return scale.domain(d3_scale_nice(domain, skip > 1 ? {
09404 floor: function(date) {
09405 while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
09406 return date;
09407 },
09408 ceil: function(date) {
09409 while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
09410 return date;
09411 }
09412 } : interval));
09413 };
09414 scale.ticks = function(interval, skip) {
09415 var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
09416 range: interval
09417 }, skip ];
09418 if (method) interval = method[0], skip = method[1];
09419 return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
09420 };
09421 scale.tickFormat = function() {
09422 return format;
09423 };
09424 scale.copy = function() {
09425 return d3_time_scale(linear.copy(), methods, format);
09426 };
09427 return d3_scale_linearRebind(scale, linear);
09428 }
09429 function d3_time_scaleDate(t) {
09430 return new Date(t);
09431 }
09432 var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
09433 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 ] ];
09434 var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
09435 return d.getMilliseconds();
09436 } ], [ ":%S", function(d) {
09437 return d.getSeconds();
09438 } ], [ "%I:%M", function(d) {
09439 return d.getMinutes();
09440 } ], [ "%I %p", function(d) {
09441 return d.getHours();
09442 } ], [ "%a %d", function(d) {
09443 return d.getDay() && d.getDate() != 1;
09444 } ], [ "%b %d", function(d) {
09445 return d.getDate() != 1;
09446 } ], [ "%B", function(d) {
09447 return d.getMonth();
09448 } ], [ "%Y", d3_true ] ]);
09449 var d3_time_scaleMilliseconds = {
09450 range: function(start, stop, step) {
09451 return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
09452 },
09453 floor: d3_identity,
09454 ceil: d3_identity
09455 };
09456 d3_time_scaleLocalMethods.year = d3_time.year;
09457 d3_time.scale = function() {
09458 return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
09459 };
09460 var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
09461 return [ m[0].utc, m[1] ];
09462 });
09463 var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
09464 return d.getUTCMilliseconds();
09465 } ], [ ":%S", function(d) {
09466 return d.getUTCSeconds();
09467 } ], [ "%I:%M", function(d) {
09468 return d.getUTCMinutes();
09469 } ], [ "%I %p", function(d) {
09470 return d.getUTCHours();
09471 } ], [ "%a %d", function(d) {
09472 return d.getUTCDay() && d.getUTCDate() != 1;
09473 } ], [ "%b %d", function(d) {
09474 return d.getUTCDate() != 1;
09475 } ], [ "%B", function(d) {
09476 return d.getUTCMonth();
09477 } ], [ "%Y", d3_true ] ]);
09478 d3_time_scaleUtcMethods.year = d3_time.year.utc;
09479 d3_time.scale.utc = function() {
09480 return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
09481 };
09482 d3.text = d3_xhrType(function(request) {
09483 return request.responseText;
09484 });
09485 d3.json = function(url, callback) {
09486 return d3_xhr(url, "application/json", d3_json, callback);
09487 };
09488 function d3_json(request) {
09489 return JSON.parse(request.responseText);
09490 }
09491 d3.html = function(url, callback) {
09492 return d3_xhr(url, "text/html", d3_html, callback);
09493 };
09494 function d3_html(request) {
09495 var range = d3_document.createRange();
09496 range.selectNode(d3_document.body);
09497 return range.createContextualFragment(request.responseText);
09498 }
09499 d3.xml = d3_xhrType(function(request) {
09500 return request.responseXML;
09501 });
09502 if (typeof define === "function" && define.amd) define(d3); else if (typeof module === "object" && module.exports) module.exports = d3;
09503 this.d3 = d3;
09504 }();