blob: 9b91a1c4b4bf4aa54122d1570133e663ac8a22c6 [file] [log] [blame]
jimbobe00f9e2016-05-26 11:18:06 -04001/**
2 * @license
3 * Copyright (c) 2010-2015, Michael Bostock
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * * The name Michael Bostock may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30!function() {
31 var d3 = {
32 version: "3.5.11"
33 };
34 var d3_arraySlice = [].slice, d3_array = function(list) {
35 return d3_arraySlice.call(list);
36 };
37 var d3_document = this.document;
38 function d3_documentElement(node) {
39 return node && (node.ownerDocument || node.document || node).documentElement;
40 }
41 function d3_window(node) {
42 return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
43 }
44 if (d3_document) {
45 try {
46 d3_array(d3_document.documentElement.childNodes)[0].nodeType;
47 } catch (e) {
48 d3_array = function(list) {
49 var i = list.length, array = new Array(i);
50 while (i--) array[i] = list[i];
51 return array;
52 };
53 }
54 }
55 if (!Date.now) Date.now = function() {
56 return +new Date();
57 };
58 if (d3_document) {
59 try {
60 d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
61 } catch (error) {
62 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;
63 d3_element_prototype.setAttribute = function(name, value) {
64 d3_element_setAttribute.call(this, name, value + "");
65 };
66 d3_element_prototype.setAttributeNS = function(space, local, value) {
67 d3_element_setAttributeNS.call(this, space, local, value + "");
68 };
69 d3_style_prototype.setProperty = function(name, value, priority) {
70 d3_style_setProperty.call(this, name, value + "", priority);
71 };
72 }
73 }
74 d3.ascending = d3_ascending;
75 function d3_ascending(a, b) {
76 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
77 }
78 d3.descending = function(a, b) {
79 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
80 };
81 d3.min = function(array, f) {
82 var i = -1, n = array.length, a, b;
83 if (arguments.length === 1) {
84 while (++i < n) if ((b = array[i]) != null && b >= b) {
85 a = b;
86 break;
87 }
88 while (++i < n) if ((b = array[i]) != null && a > b) a = b;
89 } else {
90 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
91 a = b;
92 break;
93 }
94 while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
95 }
96 return a;
97 };
98 d3.max = function(array, f) {
99 var i = -1, n = array.length, a, b;
100 if (arguments.length === 1) {
101 while (++i < n) if ((b = array[i]) != null && b >= b) {
102 a = b;
103 break;
104 }
105 while (++i < n) if ((b = array[i]) != null && b > a) a = b;
106 } else {
107 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
108 a = b;
109 break;
110 }
111 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
112 }
113 return a;
114 };
115 d3.extent = function(array, f) {
116 var i = -1, n = array.length, a, b, c;
117 if (arguments.length === 1) {
118 while (++i < n) if ((b = array[i]) != null && b >= b) {
119 a = c = b;
120 break;
121 }
122 while (++i < n) if ((b = array[i]) != null) {
123 if (a > b) a = b;
124 if (c < b) c = b;
125 }
126 } else {
127 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
128 a = c = b;
129 break;
130 }
131 while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
132 if (a > b) a = b;
133 if (c < b) c = b;
134 }
135 }
136 return [ a, c ];
137 };
138 function d3_number(x) {
139 return x === null ? NaN : +x;
140 }
141 function d3_numeric(x) {
142 return !isNaN(x);
143 }
144 d3.sum = function(array, f) {
145 var s = 0, n = array.length, a, i = -1;
146 if (arguments.length === 1) {
147 while (++i < n) if (d3_numeric(a = +array[i])) s += a;
148 } else {
149 while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
150 }
151 return s;
152 };
153 d3.mean = function(array, f) {
154 var s = 0, n = array.length, a, i = -1, j = n;
155 if (arguments.length === 1) {
156 while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
157 } else {
158 while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
159 }
160 if (j) return s / j;
161 };
162 d3.quantile = function(values, p) {
163 var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
164 return e ? v + e * (values[h] - v) : v;
165 };
166 d3.median = function(array, f) {
167 var numbers = [], n = array.length, a, i = -1;
168 if (arguments.length === 1) {
169 while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
170 } else {
171 while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
172 }
173 if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
174 };
175 d3.variance = function(array, f) {
176 var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
177 if (arguments.length === 1) {
178 while (++i < n) {
179 if (d3_numeric(a = d3_number(array[i]))) {
180 d = a - m;
181 m += d / ++j;
182 s += d * (a - m);
183 }
184 }
185 } else {
186 while (++i < n) {
187 if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
188 d = a - m;
189 m += d / ++j;
190 s += d * (a - m);
191 }
192 }
193 }
194 if (j > 1) return s / (j - 1);
195 };
196 d3.deviation = function() {
197 var v = d3.variance.apply(this, arguments);
198 return v ? Math.sqrt(v) : v;
199 };
200 function d3_bisector(compare) {
201 return {
202 left: function(a, x, lo, hi) {
203 if (arguments.length < 3) lo = 0;
204 if (arguments.length < 4) hi = a.length;
205 while (lo < hi) {
206 var mid = lo + hi >>> 1;
207 if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
208 }
209 return lo;
210 },
211 right: function(a, x, lo, hi) {
212 if (arguments.length < 3) lo = 0;
213 if (arguments.length < 4) hi = a.length;
214 while (lo < hi) {
215 var mid = lo + hi >>> 1;
216 if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
217 }
218 return lo;
219 }
220 };
221 }
222 var d3_bisect = d3_bisector(d3_ascending);
223 d3.bisectLeft = d3_bisect.left;
224 d3.bisect = d3.bisectRight = d3_bisect.right;
225 d3.bisector = function(f) {
226 return d3_bisector(f.length === 1 ? function(d, x) {
227 return d3_ascending(f(d), x);
228 } : f);
229 };
230 d3.shuffle = function(array, i0, i1) {
231 if ((m = arguments.length) < 3) {
232 i1 = array.length;
233 if (m < 2) i0 = 0;
234 }
235 var m = i1 - i0, t, i;
236 while (m) {
237 i = Math.random() * m-- | 0;
238 t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
239 }
240 return array;
241 };
242 d3.permute = function(array, indexes) {
243 var i = indexes.length, permutes = new Array(i);
244 while (i--) permutes[i] = array[indexes[i]];
245 return permutes;
246 };
247 d3.pairs = function(array) {
248 var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
249 while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
250 return pairs;
251 };
252 d3.zip = function() {
253 if (!(n = arguments.length)) return [];
254 for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
255 for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
256 zip[j] = arguments[j][i];
257 }
258 }
259 return zips;
260 };
261 function d3_zipLength(d) {
262 return d.length;
263 }
264 d3.transpose = function(matrix) {
265 return d3.zip.apply(d3, matrix);
266 };
267 d3.keys = function(map) {
268 var keys = [];
269 for (var key in map) keys.push(key);
270 return keys;
271 };
272 d3.values = function(map) {
273 var values = [];
274 for (var key in map) values.push(map[key]);
275 return values;
276 };
277 d3.entries = function(map) {
278 var entries = [];
279 for (var key in map) entries.push({
280 key: key,
281 value: map[key]
282 });
283 return entries;
284 };
285 d3.merge = function(arrays) {
286 var n = arrays.length, m, i = -1, j = 0, merged, array;
287 while (++i < n) j += arrays[i].length;
288 merged = new Array(j);
289 while (--n >= 0) {
290 array = arrays[n];
291 m = array.length;
292 while (--m >= 0) {
293 merged[--j] = array[m];
294 }
295 }
296 return merged;
297 };
298 var abs = Math.abs;
299 d3.range = function(start, stop, step) {
300 if (arguments.length < 3) {
301 step = 1;
302 if (arguments.length < 2) {
303 stop = start;
304 start = 0;
305 }
306 }
307 if ((stop - start) / step === Infinity) throw new Error("infinite range");
308 var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
309 start *= k, stop *= k, step *= k;
310 if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
311 return range;
312 };
313 function d3_range_integerScale(x) {
314 var k = 1;
315 while (x * k % 1) k *= 10;
316 return k;
317 }
318 function d3_class(ctor, properties) {
319 for (var key in properties) {
320 Object.defineProperty(ctor.prototype, key, {
321 value: properties[key],
322 enumerable: false
323 });
324 }
325 }
326 d3.map = function(object, f) {
327 var map = new d3_Map();
328 if (object instanceof d3_Map) {
329 object.forEach(function(key, value) {
330 map.set(key, value);
331 });
332 } else if (Array.isArray(object)) {
333 var i = -1, n = object.length, o;
334 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);
335 } else {
336 for (var key in object) map.set(key, object[key]);
337 }
338 return map;
339 };
340 function d3_Map() {
341 this._ = Object.create(null);
342 }
343 var d3_map_proto = "__proto__", d3_map_zero = "\x00";
344 d3_class(d3_Map, {
345 has: d3_map_has,
346 get: function(key) {
347 return this._[d3_map_escape(key)];
348 },
349 set: function(key, value) {
350 return this._[d3_map_escape(key)] = value;
351 },
352 remove: d3_map_remove,
353 keys: d3_map_keys,
354 values: function() {
355 var values = [];
356 for (var key in this._) values.push(this._[key]);
357 return values;
358 },
359 entries: function() {
360 var entries = [];
361 for (var key in this._) entries.push({
362 key: d3_map_unescape(key),
363 value: this._[key]
364 });
365 return entries;
366 },
367 size: d3_map_size,
368 empty: d3_map_empty,
369 forEach: function(f) {
370 for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
371 }
372 });
373 function d3_map_escape(key) {
374 return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
375 }
376 function d3_map_unescape(key) {
377 return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
378 }
379 function d3_map_has(key) {
380 return d3_map_escape(key) in this._;
381 }
382 function d3_map_remove(key) {
383 return (key = d3_map_escape(key)) in this._ && delete this._[key];
384 }
385 function d3_map_keys() {
386 var keys = [];
387 for (var key in this._) keys.push(d3_map_unescape(key));
388 return keys;
389 }
390 function d3_map_size() {
391 var size = 0;
392 for (var key in this._) ++size;
393 return size;
394 }
395 function d3_map_empty() {
396 for (var key in this._) return false;
397 return true;
398 }
399 d3.nest = function() {
400 var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
401 function map(mapType, array, depth) {
402 if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
403 var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
404 while (++i < n) {
405 if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
406 values.push(object);
407 } else {
408 valuesByKey.set(keyValue, [ object ]);
409 }
410 }
411 if (mapType) {
412 object = mapType();
413 setter = function(keyValue, values) {
414 object.set(keyValue, map(mapType, values, depth));
415 };
416 } else {
417 object = {};
418 setter = function(keyValue, values) {
419 object[keyValue] = map(mapType, values, depth);
420 };
421 }
422 valuesByKey.forEach(setter);
423 return object;
424 }
425 function entries(map, depth) {
426 if (depth >= keys.length) return map;
427 var array = [], sortKey = sortKeys[depth++];
428 map.forEach(function(key, keyMap) {
429 array.push({
430 key: key,
431 values: entries(keyMap, depth)
432 });
433 });
434 return sortKey ? array.sort(function(a, b) {
435 return sortKey(a.key, b.key);
436 }) : array;
437 }
438 nest.map = function(array, mapType) {
439 return map(mapType, array, 0);
440 };
441 nest.entries = function(array) {
442 return entries(map(d3.map, array, 0), 0);
443 };
444 nest.key = function(d) {
445 keys.push(d);
446 return nest;
447 };
448 nest.sortKeys = function(order) {
449 sortKeys[keys.length - 1] = order;
450 return nest;
451 };
452 nest.sortValues = function(order) {
453 sortValues = order;
454 return nest;
455 };
456 nest.rollup = function(f) {
457 rollup = f;
458 return nest;
459 };
460 return nest;
461 };
462 d3.set = function(array) {
463 var set = new d3_Set();
464 if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
465 return set;
466 };
467 function d3_Set() {
468 this._ = Object.create(null);
469 }
470 d3_class(d3_Set, {
471 has: d3_map_has,
472 add: function(key) {
473 this._[d3_map_escape(key += "")] = true;
474 return key;
475 },
476 remove: d3_map_remove,
477 values: d3_map_keys,
478 size: d3_map_size,
479 empty: d3_map_empty,
480 forEach: function(f) {
481 for (var key in this._) f.call(this, d3_map_unescape(key));
482 }
483 });
484 d3.behavior = {};
485 function d3_identity(d) {
486 return d;
487 }
488 d3.rebind = function(target, source) {
489 var i = 1, n = arguments.length, method;
490 while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
491 return target;
492 };
493 function d3_rebind(target, source, method) {
494 return function() {
495 var value = method.apply(source, arguments);
496 return value === source ? target : value;
497 };
498 }
499 function d3_vendorSymbol(object, name) {
500 if (name in object) return name;
501 name = name.charAt(0).toUpperCase() + name.slice(1);
502 for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
503 var prefixName = d3_vendorPrefixes[i] + name;
504 if (prefixName in object) return prefixName;
505 }
506 }
507 var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
508 function d3_noop() {}
509 d3.dispatch = function() {
510 var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
511 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
512 return dispatch;
513 };
514 function d3_dispatch() {}
515 d3_dispatch.prototype.on = function(type, listener) {
516 var i = type.indexOf("."), name = "";
517 if (i >= 0) {
518 name = type.slice(i + 1);
519 type = type.slice(0, i);
520 }
521 if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
522 if (arguments.length === 2) {
523 if (listener == null) for (type in this) {
524 if (this.hasOwnProperty(type)) this[type].on(name, null);
525 }
526 return this;
527 }
528 };
529 function d3_dispatch_event(dispatch) {
530 var listeners = [], listenerByName = new d3_Map();
531 function event() {
532 var z = listeners, i = -1, n = z.length, l;
533 while (++i < n) if (l = z[i].on) l.apply(this, arguments);
534 return dispatch;
535 }
536 event.on = function(name, listener) {
537 var l = listenerByName.get(name), i;
538 if (arguments.length < 2) return l && l.on;
539 if (l) {
540 l.on = null;
541 listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
542 listenerByName.remove(name);
543 }
544 if (listener) listeners.push(listenerByName.set(name, {
545 on: listener
546 }));
547 return dispatch;
548 };
549 return event;
550 }
551 d3.event = null;
552 function d3_eventPreventDefault() {
553 d3.event.preventDefault();
554 }
555 function d3_eventSource() {
556 var e = d3.event, s;
557 while (s = e.sourceEvent) e = s;
558 return e;
559 }
560 function d3_eventDispatch(target) {
561 var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
562 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
563 dispatch.of = function(thiz, argumentz) {
564 return function(e1) {
565 try {
566 var e0 = e1.sourceEvent = d3.event;
567 e1.target = target;
568 d3.event = e1;
569 dispatch[e1.type].apply(thiz, argumentz);
570 } finally {
571 d3.event = e0;
572 }
573 };
574 };
575 return dispatch;
576 }
577 d3.requote = function(s) {
578 return s.replace(d3_requote_re, "\\$&");
579 };
580 var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
581 var d3_subclass = {}.__proto__ ? function(object, prototype) {
582 object.__proto__ = prototype;
583 } : function(object, prototype) {
584 for (var property in prototype) object[property] = prototype[property];
585 };
586 function d3_selection(groups) {
587 d3_subclass(groups, d3_selectionPrototype);
588 return groups;
589 }
590 var d3_select = function(s, n) {
591 return n.querySelector(s);
592 }, d3_selectAll = function(s, n) {
593 return n.querySelectorAll(s);
594 }, d3_selectMatches = function(n, s) {
595 var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")];
596 d3_selectMatches = function(n, s) {
597 return d3_selectMatcher.call(n, s);
598 };
599 return d3_selectMatches(n, s);
600 };
601 if (typeof Sizzle === "function") {
602 d3_select = function(s, n) {
603 return Sizzle(s, n)[0] || null;
604 };
605 d3_selectAll = Sizzle;
606 d3_selectMatches = Sizzle.matchesSelector;
607 }
608 d3.selection = function() {
609 return d3.select(d3_document.documentElement);
610 };
611 var d3_selectionPrototype = d3.selection.prototype = [];
612 d3_selectionPrototype.select = function(selector) {
613 var subgroups = [], subgroup, subnode, group, node;
614 selector = d3_selection_selector(selector);
615 for (var j = -1, m = this.length; ++j < m; ) {
616 subgroups.push(subgroup = []);
617 subgroup.parentNode = (group = this[j]).parentNode;
618 for (var i = -1, n = group.length; ++i < n; ) {
619 if (node = group[i]) {
620 subgroup.push(subnode = selector.call(node, node.__data__, i, j));
621 if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
622 } else {
623 subgroup.push(null);
624 }
625 }
626 }
627 return d3_selection(subgroups);
628 };
629 function d3_selection_selector(selector) {
630 return typeof selector === "function" ? selector : function() {
631 return d3_select(selector, this);
632 };
633 }
634 d3_selectionPrototype.selectAll = function(selector) {
635 var subgroups = [], subgroup, node;
636 selector = d3_selection_selectorAll(selector);
637 for (var j = -1, m = this.length; ++j < m; ) {
638 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
639 if (node = group[i]) {
640 subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
641 subgroup.parentNode = node;
642 }
643 }
644 }
645 return d3_selection(subgroups);
646 };
647 function d3_selection_selectorAll(selector) {
648 return typeof selector === "function" ? selector : function() {
649 return d3_selectAll(selector, this);
650 };
651 }
652 var d3_nsPrefix = {
653 svg: "http://www.w3.org/2000/svg",
654 xhtml: "http://www.w3.org/1999/xhtml",
655 xlink: "http://www.w3.org/1999/xlink",
656 xml: "http://www.w3.org/XML/1998/namespace",
657 xmlns: "http://www.w3.org/2000/xmlns/"
658 };
659 d3.ns = {
660 prefix: d3_nsPrefix,
661 qualify: function(name) {
662 var i = name.indexOf(":"), prefix = name;
663 if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
664 return d3_nsPrefix.hasOwnProperty(prefix) ? {
665 space: d3_nsPrefix[prefix],
666 local: name
667 } : name;
668 }
669 };
670 d3_selectionPrototype.attr = function(name, value) {
671 if (arguments.length < 2) {
672 if (typeof name === "string") {
673 var node = this.node();
674 name = d3.ns.qualify(name);
675 return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
676 }
677 for (value in name) this.each(d3_selection_attr(value, name[value]));
678 return this;
679 }
680 return this.each(d3_selection_attr(name, value));
681 };
682 function d3_selection_attr(name, value) {
683 name = d3.ns.qualify(name);
684 function attrNull() {
685 this.removeAttribute(name);
686 }
687 function attrNullNS() {
688 this.removeAttributeNS(name.space, name.local);
689 }
690 function attrConstant() {
691 this.setAttribute(name, value);
692 }
693 function attrConstantNS() {
694 this.setAttributeNS(name.space, name.local, value);
695 }
696 function attrFunction() {
697 var x = value.apply(this, arguments);
698 if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
699 }
700 function attrFunctionNS() {
701 var x = value.apply(this, arguments);
702 if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
703 }
704 return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
705 }
706 function d3_collapse(s) {
707 return s.trim().replace(/\s+/g, " ");
708 }
709 d3_selectionPrototype.classed = function(name, value) {
710 if (arguments.length < 2) {
711 if (typeof name === "string") {
712 var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
713 if (value = node.classList) {
714 while (++i < n) if (!value.contains(name[i])) return false;
715 } else {
716 value = node.getAttribute("class");
717 while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
718 }
719 return true;
720 }
721 for (value in name) this.each(d3_selection_classed(value, name[value]));
722 return this;
723 }
724 return this.each(d3_selection_classed(name, value));
725 };
726 function d3_selection_classedRe(name) {
727 return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
728 }
729 function d3_selection_classes(name) {
730 return (name + "").trim().split(/^|\s+/);
731 }
732 function d3_selection_classed(name, value) {
733 name = d3_selection_classes(name).map(d3_selection_classedName);
734 var n = name.length;
735 function classedConstant() {
736 var i = -1;
737 while (++i < n) name[i](this, value);
738 }
739 function classedFunction() {
740 var i = -1, x = value.apply(this, arguments);
741 while (++i < n) name[i](this, x);
742 }
743 return typeof value === "function" ? classedFunction : classedConstant;
744 }
745 function d3_selection_classedName(name) {
746 var re = d3_selection_classedRe(name);
747 return function(node, value) {
748 if (c = node.classList) return value ? c.add(name) : c.remove(name);
749 var c = node.getAttribute("class") || "";
750 if (value) {
751 re.lastIndex = 0;
752 if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
753 } else {
754 node.setAttribute("class", d3_collapse(c.replace(re, " ")));
755 }
756 };
757 }
758 d3_selectionPrototype.style = function(name, value, priority) {
759 var n = arguments.length;
760 if (n < 3) {
761 if (typeof name !== "string") {
762 if (n < 2) value = "";
763 for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
764 return this;
765 }
766 if (n < 2) {
767 var node = this.node();
768 return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
769 }
770 priority = "";
771 }
772 return this.each(d3_selection_style(name, value, priority));
773 };
774 function d3_selection_style(name, value, priority) {
775 function styleNull() {
776 this.style.removeProperty(name);
777 }
778 function styleConstant() {
779 this.style.setProperty(name, value, priority);
780 }
781 function styleFunction() {
782 var x = value.apply(this, arguments);
783 if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
784 }
785 return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
786 }
787 d3_selectionPrototype.property = function(name, value) {
788 if (arguments.length < 2) {
789 if (typeof name === "string") return this.node()[name];
790 for (value in name) this.each(d3_selection_property(value, name[value]));
791 return this;
792 }
793 return this.each(d3_selection_property(name, value));
794 };
795 function d3_selection_property(name, value) {
796 function propertyNull() {
797 delete this[name];
798 }
799 function propertyConstant() {
800 this[name] = value;
801 }
802 function propertyFunction() {
803 var x = value.apply(this, arguments);
804 if (x == null) delete this[name]; else this[name] = x;
805 }
806 return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
807 }
808 d3_selectionPrototype.text = function(value) {
809 return arguments.length ? this.each(typeof value === "function" ? function() {
810 var v = value.apply(this, arguments);
811 this.textContent = v == null ? "" : v;
812 } : value == null ? function() {
813 this.textContent = "";
814 } : function() {
815 this.textContent = value;
816 }) : this.node().textContent;
817 };
818 d3_selectionPrototype.html = function(value) {
819 return arguments.length ? this.each(typeof value === "function" ? function() {
820 var v = value.apply(this, arguments);
821 this.innerHTML = v == null ? "" : v;
822 } : value == null ? function() {
823 this.innerHTML = "";
824 } : function() {
825 this.innerHTML = value;
826 }) : this.node().innerHTML;
827 };
828 d3_selectionPrototype.append = function(name) {
829 name = d3_selection_creator(name);
830 return this.select(function() {
831 return this.appendChild(name.apply(this, arguments));
832 });
833 };
834 function d3_selection_creator(name) {
835 function create() {
836 var document = this.ownerDocument, namespace = this.namespaceURI;
837 return namespace ? document.createElementNS(namespace, name) : document.createElement(name);
838 }
839 function createNS() {
840 return this.ownerDocument.createElementNS(name.space, name.local);
841 }
842 return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
843 }
844 d3_selectionPrototype.insert = function(name, before) {
845 name = d3_selection_creator(name);
846 before = d3_selection_selector(before);
847 return this.select(function() {
848 return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
849 });
850 };
851 d3_selectionPrototype.remove = function() {
852 return this.each(d3_selectionRemove);
853 };
854 function d3_selectionRemove() {
855 var parent = this.parentNode;
856 if (parent) parent.removeChild(this);
857 }
858 d3_selectionPrototype.data = function(value, key) {
859 var i = -1, n = this.length, group, node;
860 if (!arguments.length) {
861 value = new Array(n = (group = this[0]).length);
862 while (++i < n) {
863 if (node = group[i]) {
864 value[i] = node.__data__;
865 }
866 }
867 return value;
868 }
869 function bind(group, groupData) {
870 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;
871 if (key) {
872 var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
873 for (i = -1; ++i < n; ) {
874 if (node = group[i]) {
875 if (nodeByKeyValue.has(keyValue = key.call(node, node.__data__, i))) {
876 exitNodes[i] = node;
877 } else {
878 nodeByKeyValue.set(keyValue, node);
879 }
880 keyValues[i] = keyValue;
881 }
882 }
883 for (i = -1; ++i < m; ) {
884 if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
885 enterNodes[i] = d3_selection_dataNode(nodeData);
886 } else if (node !== true) {
887 updateNodes[i] = node;
888 node.__data__ = nodeData;
889 }
890 nodeByKeyValue.set(keyValue, true);
891 }
892 for (i = -1; ++i < n; ) {
893 if (i in keyValues && nodeByKeyValue.get(keyValues[i]) !== true) {
894 exitNodes[i] = group[i];
895 }
896 }
897 } else {
898 for (i = -1; ++i < n0; ) {
899 node = group[i];
900 nodeData = groupData[i];
901 if (node) {
902 node.__data__ = nodeData;
903 updateNodes[i] = node;
904 } else {
905 enterNodes[i] = d3_selection_dataNode(nodeData);
906 }
907 }
908 for (;i < m; ++i) {
909 enterNodes[i] = d3_selection_dataNode(groupData[i]);
910 }
911 for (;i < n; ++i) {
912 exitNodes[i] = group[i];
913 }
914 }
915 enterNodes.update = updateNodes;
916 enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
917 enter.push(enterNodes);
918 update.push(updateNodes);
919 exit.push(exitNodes);
920 }
921 var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
922 if (typeof value === "function") {
923 while (++i < n) {
924 bind(group = this[i], value.call(group, group.parentNode.__data__, i));
925 }
926 } else {
927 while (++i < n) {
928 bind(group = this[i], value);
929 }
930 }
931 update.enter = function() {
932 return enter;
933 };
934 update.exit = function() {
935 return exit;
936 };
937 return update;
938 };
939 function d3_selection_dataNode(data) {
940 return {
941 __data__: data
942 };
943 }
944 d3_selectionPrototype.datum = function(value) {
945 return arguments.length ? this.property("__data__", value) : this.property("__data__");
946 };
947 d3_selectionPrototype.filter = function(filter) {
948 var subgroups = [], subgroup, group, node;
949 if (typeof filter !== "function") filter = d3_selection_filter(filter);
950 for (var j = 0, m = this.length; j < m; j++) {
951 subgroups.push(subgroup = []);
952 subgroup.parentNode = (group = this[j]).parentNode;
953 for (var i = 0, n = group.length; i < n; i++) {
954 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
955 subgroup.push(node);
956 }
957 }
958 }
959 return d3_selection(subgroups);
960 };
961 function d3_selection_filter(selector) {
962 return function() {
963 return d3_selectMatches(this, selector);
964 };
965 }
966 d3_selectionPrototype.order = function() {
967 for (var j = -1, m = this.length; ++j < m; ) {
968 for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
969 if (node = group[i]) {
970 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
971 next = node;
972 }
973 }
974 }
975 return this;
976 };
977 d3_selectionPrototype.sort = function(comparator) {
978 comparator = d3_selection_sortComparator.apply(this, arguments);
979 for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
980 return this.order();
981 };
982 function d3_selection_sortComparator(comparator) {
983 if (!arguments.length) comparator = d3_ascending;
984 return function(a, b) {
985 return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
986 };
987 }
988 d3_selectionPrototype.each = function(callback) {
989 return d3_selection_each(this, function(node, i, j) {
990 callback.call(node, node.__data__, i, j);
991 });
992 };
993 function d3_selection_each(groups, callback) {
994 for (var j = 0, m = groups.length; j < m; j++) {
995 for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
996 if (node = group[i]) callback(node, i, j);
997 }
998 }
999 return groups;
1000 }
1001 d3_selectionPrototype.call = function(callback) {
1002 var args = d3_array(arguments);
1003 callback.apply(args[0] = this, args);
1004 return this;
1005 };
1006 d3_selectionPrototype.empty = function() {
1007 return !this.node();
1008 };
1009 d3_selectionPrototype.node = function() {
1010 for (var j = 0, m = this.length; j < m; j++) {
1011 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
1012 var node = group[i];
1013 if (node) return node;
1014 }
1015 }
1016 return null;
1017 };
1018 d3_selectionPrototype.size = function() {
1019 var n = 0;
1020 d3_selection_each(this, function() {
1021 ++n;
1022 });
1023 return n;
1024 };
1025 function d3_selection_enter(selection) {
1026 d3_subclass(selection, d3_selection_enterPrototype);
1027 return selection;
1028 }
1029 var d3_selection_enterPrototype = [];
1030 d3.selection.enter = d3_selection_enter;
1031 d3.selection.enter.prototype = d3_selection_enterPrototype;
1032 d3_selection_enterPrototype.append = d3_selectionPrototype.append;
1033 d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
1034 d3_selection_enterPrototype.node = d3_selectionPrototype.node;
1035 d3_selection_enterPrototype.call = d3_selectionPrototype.call;
1036 d3_selection_enterPrototype.size = d3_selectionPrototype.size;
1037 d3_selection_enterPrototype.select = function(selector) {
1038 var subgroups = [], subgroup, subnode, upgroup, group, node;
1039 for (var j = -1, m = this.length; ++j < m; ) {
1040 upgroup = (group = this[j]).update;
1041 subgroups.push(subgroup = []);
1042 subgroup.parentNode = group.parentNode;
1043 for (var i = -1, n = group.length; ++i < n; ) {
1044 if (node = group[i]) {
1045 subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
1046 subnode.__data__ = node.__data__;
1047 } else {
1048 subgroup.push(null);
1049 }
1050 }
1051 }
1052 return d3_selection(subgroups);
1053 };
1054 d3_selection_enterPrototype.insert = function(name, before) {
1055 if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
1056 return d3_selectionPrototype.insert.call(this, name, before);
1057 };
1058 function d3_selection_enterInsertBefore(enter) {
1059 var i0, j0;
1060 return function(d, i, j) {
1061 var group = enter[j].update, n = group.length, node;
1062 if (j != j0) j0 = j, i0 = 0;
1063 if (i >= i0) i0 = i + 1;
1064 while (!(node = group[i0]) && ++i0 < n) ;
1065 return node;
1066 };
1067 }
1068 d3.select = function(node) {
1069 var group;
1070 if (typeof node === "string") {
1071 group = [ d3_select(node, d3_document) ];
1072 group.parentNode = d3_document.documentElement;
1073 } else {
1074 group = [ node ];
1075 group.parentNode = d3_documentElement(node);
1076 }
1077 return d3_selection([ group ]);
1078 };
1079 d3.selectAll = function(nodes) {
1080 var group;
1081 if (typeof nodes === "string") {
1082 group = d3_array(d3_selectAll(nodes, d3_document));
1083 group.parentNode = d3_document.documentElement;
1084 } else {
1085 group = d3_array(nodes);
1086 group.parentNode = null;
1087 }
1088 return d3_selection([ group ]);
1089 };
1090 d3_selectionPrototype.on = function(type, listener, capture) {
1091 var n = arguments.length;
1092 if (n < 3) {
1093 if (typeof type !== "string") {
1094 if (n < 2) listener = false;
1095 for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
1096 return this;
1097 }
1098 if (n < 2) return (n = this.node()["__on" + type]) && n._;
1099 capture = false;
1100 }
1101 return this.each(d3_selection_on(type, listener, capture));
1102 };
1103 function d3_selection_on(type, listener, capture) {
1104 var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
1105 if (i > 0) type = type.slice(0, i);
1106 var filter = d3_selection_onFilters.get(type);
1107 if (filter) type = filter, wrap = d3_selection_onFilter;
1108 function onRemove() {
1109 var l = this[name];
1110 if (l) {
1111 this.removeEventListener(type, l, l.$);
1112 delete this[name];
1113 }
1114 }
1115 function onAdd() {
1116 var l = wrap(listener, d3_array(arguments));
1117 onRemove.call(this);
1118 this.addEventListener(type, this[name] = l, l.$ = capture);
1119 l._ = listener;
1120 }
1121 function removeAll() {
1122 var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
1123 for (var name in this) {
1124 if (match = name.match(re)) {
1125 var l = this[name];
1126 this.removeEventListener(match[1], l, l.$);
1127 delete this[name];
1128 }
1129 }
1130 }
1131 return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
1132 }
1133 var d3_selection_onFilters = d3.map({
1134 mouseenter: "mouseover",
1135 mouseleave: "mouseout"
1136 });
1137 if (d3_document) {
1138 d3_selection_onFilters.forEach(function(k) {
1139 if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
1140 });
1141 }
1142 function d3_selection_onListener(listener, argumentz) {
1143 return function(e) {
1144 var o = d3.event;
1145 d3.event = e;
1146 argumentz[0] = this.__data__;
1147 try {
1148 listener.apply(this, argumentz);
1149 } finally {
1150 d3.event = o;
1151 }
1152 };
1153 }
1154 function d3_selection_onFilter(listener, argumentz) {
1155 var l = d3_selection_onListener(listener, argumentz);
1156 return function(e) {
1157 var target = this, related = e.relatedTarget;
1158 if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
1159 l.call(target, e);
1160 }
1161 };
1162 }
1163 var d3_event_dragSelect, d3_event_dragId = 0;
1164 function d3_event_dragSuppress(node) {
1165 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);
1166 if (d3_event_dragSelect == null) {
1167 d3_event_dragSelect = "onselectstart" in node ? false : d3_vendorSymbol(node.style, "userSelect");
1168 }
1169 if (d3_event_dragSelect) {
1170 var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
1171 style[d3_event_dragSelect] = "none";
1172 }
1173 return function(suppressClick) {
1174 w.on(name, null);
1175 if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
1176 if (suppressClick) {
1177 var off = function() {
1178 w.on(click, null);
1179 };
1180 w.on(click, function() {
1181 d3_eventPreventDefault();
1182 off();
1183 }, true);
1184 setTimeout(off, 0);
1185 }
1186 };
1187 }
1188 d3.mouse = function(container) {
1189 return d3_mousePoint(container, d3_eventSource());
1190 };
1191 var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
1192 function d3_mousePoint(container, e) {
1193 if (e.changedTouches) e = e.changedTouches[0];
1194 var svg = container.ownerSVGElement || container;
1195 if (svg.createSVGPoint) {
1196 var point = svg.createSVGPoint();
1197 if (d3_mouse_bug44083 < 0) {
1198 var window = d3_window(container);
1199 if (window.scrollX || window.scrollY) {
1200 svg = d3.select("body").append("svg").style({
1201 position: "absolute",
1202 top: 0,
1203 left: 0,
1204 margin: 0,
1205 padding: 0,
1206 border: "none"
1207 }, "important");
1208 var ctm = svg[0][0].getScreenCTM();
1209 d3_mouse_bug44083 = !(ctm.f || ctm.e);
1210 svg.remove();
1211 }
1212 }
1213 if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
1214 point.y = e.clientY;
1215 point = point.matrixTransform(container.getScreenCTM().inverse());
1216 return [ point.x, point.y ];
1217 }
1218 var rect = container.getBoundingClientRect();
1219 return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
1220 }
1221 d3.touch = function(container, touches, identifier) {
1222 if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
1223 if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
1224 if ((touch = touches[i]).identifier === identifier) {
1225 return d3_mousePoint(container, touch);
1226 }
1227 }
1228 };
1229 d3.behavior.drag = function() {
1230 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");
1231 function drag() {
1232 this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
1233 }
1234 function dragstart(id, position, subject, move, end) {
1235 return function() {
1236 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);
1237 if (origin) {
1238 dragOffset = origin.apply(that, arguments);
1239 dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
1240 } else {
1241 dragOffset = [ 0, 0 ];
1242 }
1243 dispatch({
1244 type: "dragstart"
1245 });
1246 function moved() {
1247 var position1 = position(parent, dragId), dx, dy;
1248 if (!position1) return;
1249 dx = position1[0] - position0[0];
1250 dy = position1[1] - position0[1];
1251 dragged |= dx | dy;
1252 position0 = position1;
1253 dispatch({
1254 type: "drag",
1255 x: position1[0] + dragOffset[0],
1256 y: position1[1] + dragOffset[1],
1257 dx: dx,
1258 dy: dy
1259 });
1260 }
1261 function ended() {
1262 if (!position(parent, dragId)) return;
1263 dragSubject.on(move + dragName, null).on(end + dragName, null);
1264 dragRestore(dragged);
1265 dispatch({
1266 type: "dragend"
1267 });
1268 }
1269 };
1270 }
1271 drag.origin = function(x) {
1272 if (!arguments.length) return origin;
1273 origin = x;
1274 return drag;
1275 };
1276 return d3.rebind(drag, event, "on");
1277 };
1278 function d3_behavior_dragTouchId() {
1279 return d3.event.changedTouches[0].identifier;
1280 }
1281 d3.touches = function(container, touches) {
1282 if (arguments.length < 2) touches = d3_eventSource().touches;
1283 return touches ? d3_array(touches).map(function(touch) {
1284 var point = d3_mousePoint(container, touch);
1285 point.identifier = touch.identifier;
1286 return point;
1287 }) : [];
1288 };
1289 var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
1290 function d3_sgn(x) {
1291 return x > 0 ? 1 : x < 0 ? -1 : 0;
1292 }
1293 function d3_cross2d(a, b, c) {
1294 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
1295 }
1296 function d3_acos(x) {
1297 return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
1298 }
1299 function d3_asin(x) {
1300 return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
1301 }
1302 function d3_sinh(x) {
1303 return ((x = Math.exp(x)) - 1 / x) / 2;
1304 }
1305 function d3_cosh(x) {
1306 return ((x = Math.exp(x)) + 1 / x) / 2;
1307 }
1308 function d3_tanh(x) {
1309 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
1310 }
1311 function d3_haversin(x) {
1312 return (x = Math.sin(x / 2)) * x;
1313 }
1314 var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
1315 d3.interpolateZoom = function(p0, p1) {
1316 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2], dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, i, S;
1317 if (d2 < ε2) {
1318 S = Math.log(w1 / w0) / ρ;
1319 i = function(t) {
1320 return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp * t * S) ];
1321 };
1322 } else {
1323 var 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);
1324 S = (r1 - r0) / ρ;
1325 i = function(t) {
1326 var s = t * S, coshr0 = d3_cosh(r0), u = w0 / 2 * d1) * (coshr0 * d3_tanh * s + r0) - d3_sinh(r0));
1327 return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh * s + r0) ];
1328 };
1329 }
1330 i.duration = S * 1e3;
1331 return i;
1332 };
1333 d3.behavior.zoom = function() {
1334 var view = {
1335 x: 0,
1336 y: 0,
1337 k: 1
1338 }, 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;
1339 if (!d3_behavior_zoomWheel) {
1340 d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
1341 return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
1342 }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
1343 return d3.event.wheelDelta;
1344 }, "mousewheel") : (d3_behavior_zoomDelta = function() {
1345 return -d3.event.detail;
1346 }, "MozMousePixelScroll");
1347 }
1348 function zoom(g) {
1349 g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
1350 }
1351 zoom.event = function(g) {
1352 g.each(function() {
1353 var dispatch = event.of(this, arguments), view1 = view;
1354 if (d3_transitionInheritId) {
1355 d3.select(this).transition().each("start.zoom", function() {
1356 view = this.__chart__ || {
1357 x: 0,
1358 y: 0,
1359 k: 1
1360 };
1361 zoomstarted(dispatch);
1362 }).tween("zoom:zoom", function() {
1363 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 ]);
1364 return function(t) {
1365 var l = i(t), k = dx / l[2];
1366 this.__chart__ = view = {
1367 x: cx - l[0] * k,
1368 y: cy - l[1] * k,
1369 k: k
1370 };
1371 zoomed(dispatch);
1372 };
1373 }).each("interrupt.zoom", function() {
1374 zoomended(dispatch);
1375 }).each("end.zoom", function() {
1376 zoomended(dispatch);
1377 });
1378 } else {
1379 this.__chart__ = view;
1380 zoomstarted(dispatch);
1381 zoomed(dispatch);
1382 zoomended(dispatch);
1383 }
1384 });
1385 };
1386 zoom.translate = function(_) {
1387 if (!arguments.length) return [ view.x, view.y ];
1388 view = {
1389 x: +_[0],
1390 y: +_[1],
1391 k: view.k
1392 };
1393 rescale();
1394 return zoom;
1395 };
1396 zoom.scale = function(_) {
1397 if (!arguments.length) return view.k;
1398 view = {
1399 x: view.x,
1400 y: view.y,
1401 k: null
1402 };
1403 scaleTo(+_);
1404 rescale();
1405 return zoom;
1406 };
1407 zoom.scaleExtent = function(_) {
1408 if (!arguments.length) return scaleExtent;
1409 scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
1410 return zoom;
1411 };
1412 zoom.center = function(_) {
1413 if (!arguments.length) return center;
1414 center = _ && [ +_[0], +_[1] ];
1415 return zoom;
1416 };
1417 zoom.size = function(_) {
1418 if (!arguments.length) return size;
1419 size = _ && [ +_[0], +_[1] ];
1420 return zoom;
1421 };
1422 zoom.duration = function(_) {
1423 if (!arguments.length) return duration;
1424 duration = +_;
1425 return zoom;
1426 };
1427 zoom.x = function(z) {
1428 if (!arguments.length) return x1;
1429 x1 = z;
1430 x0 = z.copy();
1431 view = {
1432 x: 0,
1433 y: 0,
1434 k: 1
1435 };
1436 return zoom;
1437 };
1438 zoom.y = function(z) {
1439 if (!arguments.length) return y1;
1440 y1 = z;
1441 y0 = z.copy();
1442 view = {
1443 x: 0,
1444 y: 0,
1445 k: 1
1446 };
1447 return zoom;
1448 };
1449 function location(p) {
1450 return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
1451 }
1452 function point(l) {
1453 return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
1454 }
1455 function scaleTo(s) {
1456 view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
1457 }
1458 function translateTo(p, l) {
1459 l = point(l);
1460 view.x += p[0] - l[0];
1461 view.y += p[1] - l[1];
1462 }
1463 function zoomTo(that, p, l, k) {
1464 that.__chart__ = {
1465 x: view.x,
1466 y: view.y,
1467 k: view.k
1468 };
1469 scaleTo(Math.pow(2, k));
1470 translateTo(center0 = p, l);
1471 that = d3.select(that);
1472 if (duration > 0) that = that.transition().duration(duration);
1473 that.call(zoom.event);
1474 }
1475 function rescale() {
1476 if (x1) x1.domain(x0.range().map(function(x) {
1477 return (x - view.x) / view.k;
1478 }).map(x0.invert));
1479 if (y1) y1.domain(y0.range().map(function(y) {
1480 return (y - view.y) / view.k;
1481 }).map(y0.invert));
1482 }
1483 function zoomstarted(dispatch) {
1484 if (!zooming++) dispatch({
1485 type: "zoomstart"
1486 });
1487 }
1488 function zoomed(dispatch) {
1489 rescale();
1490 dispatch({
1491 type: "zoom",
1492 scale: view.k,
1493 translate: [ view.x, view.y ]
1494 });
1495 }
1496 function zoomended(dispatch) {
1497 if (!--zooming) dispatch({
1498 type: "zoomend"
1499 }), center0 = null;
1500 }
1501 function mousedowned() {
1502 var that = this, 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);
1503 d3_selection_interrupt.call(that);
1504 zoomstarted(dispatch);
1505 function moved() {
1506 dragged = 1;
1507 translateTo(d3.mouse(that), location0);
1508 zoomed(dispatch);
1509 }
1510 function ended() {
1511 subject.on(mousemove, null).on(mouseup, null);
1512 dragRestore(dragged);
1513 zoomended(dispatch);
1514 }
1515 }
1516 function touchstarted() {
1517 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);
1518 started();
1519 zoomstarted(dispatch);
1520 subject.on(mousedown, null).on(touchstart, started);
1521 function relocate() {
1522 var touches = d3.touches(that);
1523 scale0 = view.k;
1524 touches.forEach(function(t) {
1525 if (t.identifier in locations0) locations0[t.identifier] = location(t);
1526 });
1527 return touches;
1528 }
1529 function started() {
1530 var target = d3.event.target;
1531 d3.select(target).on(touchmove, moved).on(touchend, ended);
1532 targets.push(target);
1533 var changed = d3.event.changedTouches;
1534 for (var i = 0, n = changed.length; i < n; ++i) {
1535 locations0[changed[i].identifier] = null;
1536 }
1537 var touches = relocate(), now = Date.now();
1538 if (touches.length === 1) {
1539 if (now - touchtime < 500) {
1540 var p = touches[0];
1541 zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
1542 d3_eventPreventDefault();
1543 }
1544 touchtime = now;
1545 } else if (touches.length > 1) {
1546 var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
1547 distance0 = dx * dx + dy * dy;
1548 }
1549 }
1550 function moved() {
1551 var touches = d3.touches(that), p0, l0, p1, l1;
1552 d3_selection_interrupt.call(that);
1553 for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
1554 p1 = touches[i];
1555 if (l1 = locations0[p1.identifier]) {
1556 if (l0) break;
1557 p0 = p1, l0 = l1;
1558 }
1559 }
1560 if (l1) {
1561 var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
1562 p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
1563 l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
1564 scaleTo(scale1 * scale0);
1565 }
1566 touchtime = null;
1567 translateTo(p0, l0);
1568 zoomed(dispatch);
1569 }
1570 function ended() {
1571 if (d3.event.touches.length) {
1572 var changed = d3.event.changedTouches;
1573 for (var i = 0, n = changed.length; i < n; ++i) {
1574 delete locations0[changed[i].identifier];
1575 }
1576 for (var identifier in locations0) {
1577 return void relocate();
1578 }
1579 }
1580 d3.selectAll(targets).on(zoomName, null);
1581 subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
1582 dragRestore();
1583 zoomended(dispatch);
1584 }
1585 }
1586 function mousewheeled() {
1587 var dispatch = event.of(this, arguments);
1588 if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
1589 translate0 = location(center0 = center || d3.mouse(this)), zoomstarted(dispatch);
1590 mousewheelTimer = setTimeout(function() {
1591 mousewheelTimer = null;
1592 zoomended(dispatch);
1593 }, 50);
1594 d3_eventPreventDefault();
1595 scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
1596 translateTo(center0, translate0);
1597 zoomed(dispatch);
1598 }
1599 function dblclicked() {
1600 var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
1601 zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
1602 }
1603 return d3.rebind(zoom, event, "on");
1604 };
1605 var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
1606 d3.color = d3_color;
1607 function d3_color() {}
1608 d3_color.prototype.toString = function() {
1609 return this.rgb() + "";
1610 };
1611 d3.hsl = d3_hsl;
1612 function d3_hsl(h, s, l) {
1613 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);
1614 }
1615 var d3_hslPrototype = d3_hsl.prototype = new d3_color();
1616 d3_hslPrototype.brighter = function(k) {
1617 k = Math.pow(.7, arguments.length ? k : 1);
1618 return new d3_hsl(this.h, this.s, this.l / k);
1619 };
1620 d3_hslPrototype.darker = function(k) {
1621 k = Math.pow(.7, arguments.length ? k : 1);
1622 return new d3_hsl(this.h, this.s, k * this.l);
1623 };
1624 d3_hslPrototype.rgb = function() {
1625 return d3_hsl_rgb(this.h, this.s, this.l);
1626 };
1627 function d3_hsl_rgb(h, s, l) {
1628 var m1, m2;
1629 h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
1630 s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
1631 l = l < 0 ? 0 : l > 1 ? 1 : l;
1632 m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
1633 m1 = 2 * l - m2;
1634 function v(h) {
1635 if (h > 360) h -= 360; else if (h < 0) h += 360;
1636 if (h < 60) return m1 + (m2 - m1) * h / 60;
1637 if (h < 180) return m2;
1638 if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
1639 return m1;
1640 }
1641 function vv(h) {
1642 return Math.round(v(h) * 255);
1643 }
1644 return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
1645 }
1646 d3.hcl = d3_hcl;
1647 function d3_hcl(h, c, l) {
1648 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);
1649 }
1650 var d3_hclPrototype = d3_hcl.prototype = new d3_color();
1651 d3_hclPrototype.brighter = function(k) {
1652 return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
1653 };
1654 d3_hclPrototype.darker = function(k) {
1655 return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
1656 };
1657 d3_hclPrototype.rgb = function() {
1658 return d3_hcl_lab(this.h, this.c, this.l).rgb();
1659 };
1660 function d3_hcl_lab(h, c, l) {
1661 if (isNaN(h)) h = 0;
1662 if (isNaN(c)) c = 0;
1663 return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
1664 }
1665 d3.lab = d3_lab;
1666 function d3_lab(l, a, b) {
1667 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);
1668 }
1669 var d3_lab_K = 18;
1670 var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
1671 var d3_labPrototype = d3_lab.prototype = new d3_color();
1672 d3_labPrototype.brighter = function(k) {
1673 return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1674 };
1675 d3_labPrototype.darker = function(k) {
1676 return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1677 };
1678 d3_labPrototype.rgb = function() {
1679 return d3_lab_rgb(this.l, this.a, this.b);
1680 };
1681 function d3_lab_rgb(l, a, b) {
1682 var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
1683 x = d3_lab_xyz(x) * d3_lab_X;
1684 y = d3_lab_xyz(y) * d3_lab_Y;
1685 z = d3_lab_xyz(z) * d3_lab_Z;
1686 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));
1687 }
1688 function d3_lab_hcl(l, a, b) {
1689 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);
1690 }
1691 function d3_lab_xyz(x) {
1692 return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
1693 }
1694 function d3_xyz_lab(x) {
1695 return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
1696 }
1697 function d3_xyz_rgb(r) {
1698 return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
1699 }
1700 d3.rgb = d3_rgb;
1701 function d3_rgb(r, g, b) {
1702 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);
1703 }
1704 function d3_rgbNumber(value) {
1705 return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
1706 }
1707 function d3_rgbString(value) {
1708 return d3_rgbNumber(value) + "";
1709 }
1710 var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
1711 d3_rgbPrototype.brighter = function(k) {
1712 k = Math.pow(.7, arguments.length ? k : 1);
1713 var r = this.r, g = this.g, b = this.b, i = 30;
1714 if (!r && !g && !b) return new d3_rgb(i, i, i);
1715 if (r && r < i) r = i;
1716 if (g && g < i) g = i;
1717 if (b && b < i) b = i;
1718 return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
1719 };
1720 d3_rgbPrototype.darker = function(k) {
1721 k = Math.pow(.7, arguments.length ? k : 1);
1722 return new d3_rgb(k * this.r, k * this.g, k * this.b);
1723 };
1724 d3_rgbPrototype.hsl = function() {
1725 return d3_rgb_hsl(this.r, this.g, this.b);
1726 };
1727 d3_rgbPrototype.toString = function() {
1728 return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
1729 };
1730 function d3_rgb_hex(v) {
1731 return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
1732 }
1733 function d3_rgb_parse(format, rgb, hsl) {
1734 var r = 0, g = 0, b = 0, m1, m2, color;
1735 m1 = /([a-z]+)\((.*)\)/.exec(format = format.toLowerCase());
1736 if (m1) {
1737 m2 = m1[2].split(",");
1738 switch (m1[1]) {
1739 case "hsl":
1740 {
1741 return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
1742 }
1743
1744 case "rgb":
1745 {
1746 return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
1747 }
1748 }
1749 }
1750 if (color = d3_rgb_names.get(format)) {
1751 return rgb(color.r, color.g, color.b);
1752 }
1753 if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
1754 if (format.length === 4) {
1755 r = (color & 3840) >> 4;
1756 r = r >> 4 | r;
1757 g = color & 240;
1758 g = g >> 4 | g;
1759 b = color & 15;
1760 b = b << 4 | b;
1761 } else if (format.length === 7) {
1762 r = (color & 16711680) >> 16;
1763 g = (color & 65280) >> 8;
1764 b = color & 255;
1765 }
1766 }
1767 return rgb(r, g, b);
1768 }
1769 function d3_rgb_hsl(r, g, b) {
1770 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;
1771 if (d) {
1772 s = l < .5 ? d / (max + min) : d / (2 - max - min);
1773 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;
1774 h *= 60;
1775 } else {
1776 h = NaN;
1777 s = l > 0 && l < 1 ? 0 : h;
1778 }
1779 return new d3_hsl(h, s, l);
1780 }
1781 function d3_rgb_lab(r, g, b) {
1782 r = d3_rgb_xyz(r);
1783 g = d3_rgb_xyz(g);
1784 b = d3_rgb_xyz(b);
1785 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);
1786 return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
1787 }
1788 function d3_rgb_xyz(r) {
1789 return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
1790 }
1791 function d3_rgb_parseNumber(c) {
1792 var f = parseFloat(c);
1793 return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
1794 }
1795 var d3_rgb_names = d3.map({
1796 aliceblue: 15792383,
1797 antiquewhite: 16444375,
1798 aqua: 65535,
1799 aquamarine: 8388564,
1800 azure: 15794175,
1801 beige: 16119260,
1802 bisque: 16770244,
1803 black: 0,
1804 blanchedalmond: 16772045,
1805 blue: 255,
1806 blueviolet: 9055202,
1807 brown: 10824234,
1808 burlywood: 14596231,
1809 cadetblue: 6266528,
1810 chartreuse: 8388352,
1811 chocolate: 13789470,
1812 coral: 16744272,
1813 cornflowerblue: 6591981,
1814 cornsilk: 16775388,
1815 crimson: 14423100,
1816 cyan: 65535,
1817 darkblue: 139,
1818 darkcyan: 35723,
1819 darkgoldenrod: 12092939,
1820 darkgray: 11119017,
1821 darkgreen: 25600,
1822 darkgrey: 11119017,
1823 darkkhaki: 12433259,
1824 darkmagenta: 9109643,
1825 darkolivegreen: 5597999,
1826 darkorange: 16747520,
1827 darkorchid: 10040012,
1828 darkred: 9109504,
1829 darksalmon: 15308410,
1830 darkseagreen: 9419919,
1831 darkslateblue: 4734347,
1832 darkslategray: 3100495,
1833 darkslategrey: 3100495,
1834 darkturquoise: 52945,
1835 darkviolet: 9699539,
1836 deeppink: 16716947,
1837 deepskyblue: 49151,
1838 dimgray: 6908265,
1839 dimgrey: 6908265,
1840 dodgerblue: 2003199,
1841 firebrick: 11674146,
1842 floralwhite: 16775920,
1843 forestgreen: 2263842,
1844 fuchsia: 16711935,
1845 gainsboro: 14474460,
1846 ghostwhite: 16316671,
1847 gold: 16766720,
1848 goldenrod: 14329120,
1849 gray: 8421504,
1850 green: 32768,
1851 greenyellow: 11403055,
1852 grey: 8421504,
1853 honeydew: 15794160,
1854 hotpink: 16738740,
1855 indianred: 13458524,
1856 indigo: 4915330,
1857 ivory: 16777200,
1858 khaki: 15787660,
1859 lavender: 15132410,
1860 lavenderblush: 16773365,
1861 lawngreen: 8190976,
1862 lemonchiffon: 16775885,
1863 lightblue: 11393254,
1864 lightcoral: 15761536,
1865 lightcyan: 14745599,
1866 lightgoldenrodyellow: 16448210,
1867 lightgray: 13882323,
1868 lightgreen: 9498256,
1869 lightgrey: 13882323,
1870 lightpink: 16758465,
1871 lightsalmon: 16752762,
1872 lightseagreen: 2142890,
1873 lightskyblue: 8900346,
1874 lightslategray: 7833753,
1875 lightslategrey: 7833753,
1876 lightsteelblue: 11584734,
1877 lightyellow: 16777184,
1878 lime: 65280,
1879 limegreen: 3329330,
1880 linen: 16445670,
1881 magenta: 16711935,
1882 maroon: 8388608,
1883 mediumaquamarine: 6737322,
1884 mediumblue: 205,
1885 mediumorchid: 12211667,
1886 mediumpurple: 9662683,
1887 mediumseagreen: 3978097,
1888 mediumslateblue: 8087790,
1889 mediumspringgreen: 64154,
1890 mediumturquoise: 4772300,
1891 mediumvioletred: 13047173,
1892 midnightblue: 1644912,
1893 mintcream: 16121850,
1894 mistyrose: 16770273,
1895 moccasin: 16770229,
1896 navajowhite: 16768685,
1897 navy: 128,
1898 oldlace: 16643558,
1899 olive: 8421376,
1900 olivedrab: 7048739,
1901 orange: 16753920,
1902 orangered: 16729344,
1903 orchid: 14315734,
1904 palegoldenrod: 15657130,
1905 palegreen: 10025880,
1906 paleturquoise: 11529966,
1907 palevioletred: 14381203,
1908 papayawhip: 16773077,
1909 peachpuff: 16767673,
1910 peru: 13468991,
1911 pink: 16761035,
1912 plum: 14524637,
1913 powderblue: 11591910,
1914 purple: 8388736,
1915 rebeccapurple: 6697881,
1916 red: 16711680,
1917 rosybrown: 12357519,
1918 royalblue: 4286945,
1919 saddlebrown: 9127187,
1920 salmon: 16416882,
1921 sandybrown: 16032864,
1922 seagreen: 3050327,
1923 seashell: 16774638,
1924 sienna: 10506797,
1925 silver: 12632256,
1926 skyblue: 8900331,
1927 slateblue: 6970061,
1928 slategray: 7372944,
1929 slategrey: 7372944,
1930 snow: 16775930,
1931 springgreen: 65407,
1932 steelblue: 4620980,
1933 tan: 13808780,
1934 teal: 32896,
1935 thistle: 14204888,
1936 tomato: 16737095,
1937 turquoise: 4251856,
1938 violet: 15631086,
1939 wheat: 16113331,
1940 white: 16777215,
1941 whitesmoke: 16119285,
1942 yellow: 16776960,
1943 yellowgreen: 10145074
1944 });
1945 d3_rgb_names.forEach(function(key, value) {
1946 d3_rgb_names.set(key, d3_rgbNumber(value));
1947 });
1948 function d3_functor(v) {
1949 return typeof v === "function" ? v : function() {
1950 return v;
1951 };
1952 }
1953 d3.functor = d3_functor;
1954 d3.xhr = d3_xhrType(d3_identity);
1955 function d3_xhrType(response) {
1956 return function(url, mimeType, callback) {
1957 if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
1958 mimeType = null;
1959 return d3_xhr(url, mimeType, response, callback);
1960 };
1961 }
1962 function d3_xhr(url, mimeType, response, callback) {
1963 var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
1964 if (this.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
1965 "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
1966 request.readyState > 3 && respond();
1967 };
1968 function respond() {
1969 var status = request.status, result;
1970 if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
1971 try {
1972 result = response.call(xhr, request);
1973 } catch (e) {
1974 dispatch.error.call(xhr, e);
1975 return;
1976 }
1977 dispatch.load.call(xhr, result);
1978 } else {
1979 dispatch.error.call(xhr, request);
1980 }
1981 }
1982 request.onprogress = function(event) {
1983 var o = d3.event;
1984 d3.event = event;
1985 try {
1986 dispatch.progress.call(xhr, request);
1987 } finally {
1988 d3.event = o;
1989 }
1990 };
1991 xhr.header = function(name, value) {
1992 name = (name + "").toLowerCase();
1993 if (arguments.length < 2) return headers[name];
1994 if (value == null) delete headers[name]; else headers[name] = value + "";
1995 return xhr;
1996 };
1997 xhr.mimeType = function(value) {
1998 if (!arguments.length) return mimeType;
1999 mimeType = value == null ? null : value + "";
2000 return xhr;
2001 };
2002 xhr.responseType = function(value) {
2003 if (!arguments.length) return responseType;
2004 responseType = value;
2005 return xhr;
2006 };
2007 xhr.response = function(value) {
2008 response = value;
2009 return xhr;
2010 };
2011 [ "get", "post" ].forEach(function(method) {
2012 xhr[method] = function() {
2013 return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
2014 };
2015 });
2016 xhr.send = function(method, data, callback) {
2017 if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
2018 request.open(method, url, true);
2019 if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
2020 if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
2021 if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
2022 if (responseType != null) request.responseType = responseType;
2023 if (callback != null) xhr.on("error", callback).on("load", function(request) {
2024 callback(null, request);
2025 });
2026 dispatch.beforesend.call(xhr, request);
2027 request.send(data == null ? null : data);
2028 return xhr;
2029 };
2030 xhr.abort = function() {
2031 request.abort();
2032 return xhr;
2033 };
2034 d3.rebind(xhr, dispatch, "on");
2035 return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
2036 }
2037 function d3_xhr_fixCallback(callback) {
2038 return callback.length === 1 ? function(error, request) {
2039 callback(error == null ? request : null);
2040 } : callback;
2041 }
2042 function d3_xhrHasResponse(request) {
2043 var type = request.responseType;
2044 return type && type !== "text" ? request.response : request.responseText;
2045 }
2046 d3.dsv = function(delimiter, mimeType) {
2047 var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
2048 function dsv(url, row, callback) {
2049 if (arguments.length < 3) callback = row, row = null;
2050 var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
2051 xhr.row = function(_) {
2052 return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
2053 };
2054 return xhr;
2055 }
2056 function response(request) {
2057 return dsv.parse(request.responseText);
2058 }
2059 function typedResponse(f) {
2060 return function(request) {
2061 return dsv.parse(request.responseText, f);
2062 };
2063 }
2064 dsv.parse = function(text, f) {
2065 var o;
2066 return dsv.parseRows(text, function(row, i) {
2067 if (o) return o(row, i - 1);
2068 var a = new Function("d", "return {" + row.map(function(name, i) {
2069 return JSON.stringify(name) + ": d[" + i + "]";
2070 }).join(",") + "}");
2071 o = f ? function(row, i) {
2072 return f(a(row), i);
2073 } : a;
2074 });
2075 };
2076 dsv.parseRows = function(text, f) {
2077 var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
2078 function token() {
2079 if (I >= N) return EOF;
2080 if (eol) return eol = false, EOL;
2081 var j = I;
2082 if (text.charCodeAt(j) === 34) {
2083 var i = j;
2084 while (i++ < N) {
2085 if (text.charCodeAt(i) === 34) {
2086 if (text.charCodeAt(i + 1) !== 34) break;
2087 ++i;
2088 }
2089 }
2090 I = i + 2;
2091 var c = text.charCodeAt(i + 1);
2092 if (c === 13) {
2093 eol = true;
2094 if (text.charCodeAt(i + 2) === 10) ++I;
2095 } else if (c === 10) {
2096 eol = true;
2097 }
2098 return text.slice(j + 1, i).replace(/""/g, '"');
2099 }
2100 while (I < N) {
2101 var c = text.charCodeAt(I++), k = 1;
2102 if (c === 10) eol = true; else if (c === 13) {
2103 eol = true;
2104 if (text.charCodeAt(I) === 10) ++I, ++k;
2105 } else if (c !== delimiterCode) continue;
2106 return text.slice(j, I - k);
2107 }
2108 return text.slice(j);
2109 }
2110 while ((t = token()) !== EOF) {
2111 var a = [];
2112 while (t !== EOL && t !== EOF) {
2113 a.push(t);
2114 t = token();
2115 }
2116 if (f && (a = f(a, n++)) == null) continue;
2117 rows.push(a);
2118 }
2119 return rows;
2120 };
2121 dsv.format = function(rows) {
2122 if (Array.isArray(rows[0])) return dsv.formatRows(rows);
2123 var fieldSet = new d3_Set(), fields = [];
2124 rows.forEach(function(row) {
2125 for (var field in row) {
2126 if (!fieldSet.has(field)) {
2127 fields.push(fieldSet.add(field));
2128 }
2129 }
2130 });
2131 return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
2132 return fields.map(function(field) {
2133 return formatValue(row[field]);
2134 }).join(delimiter);
2135 })).join("\n");
2136 };
2137 dsv.formatRows = function(rows) {
2138 return rows.map(formatRow).join("\n");
2139 };
2140 function formatRow(row) {
2141 return row.map(formatValue).join(delimiter);
2142 }
2143 function formatValue(text) {
2144 return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
2145 }
2146 return dsv;
2147 };
2148 d3.csv = d3.dsv(",", "text/csv");
2149 d3.tsv = d3.dsv(" ", "text/tab-separated-values");
2150 var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
2151 setTimeout(callback, 17);
2152 };
2153 d3.timer = function() {
2154 d3_timer.apply(this, arguments);
2155 };
2156 function d3_timer(callback, delay, then) {
2157 var n = arguments.length;
2158 if (n < 2) delay = 0;
2159 if (n < 3) then = Date.now();
2160 var time = then + delay, timer = {
2161 c: callback,
2162 t: time,
2163 n: null
2164 };
2165 if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
2166 d3_timer_queueTail = timer;
2167 if (!d3_timer_interval) {
2168 d3_timer_timeout = clearTimeout(d3_timer_timeout);
2169 d3_timer_interval = 1;
2170 d3_timer_frame(d3_timer_step);
2171 }
2172 return timer;
2173 }
2174 function d3_timer_step() {
2175 var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
2176 if (delay > 24) {
2177 if (isFinite(delay)) {
2178 clearTimeout(d3_timer_timeout);
2179 d3_timer_timeout = setTimeout(d3_timer_step, delay);
2180 }
2181 d3_timer_interval = 0;
2182 } else {
2183 d3_timer_interval = 1;
2184 d3_timer_frame(d3_timer_step);
2185 }
2186 }
2187 d3.timer.flush = function() {
2188 d3_timer_mark();
2189 d3_timer_sweep();
2190 };
2191 function d3_timer_mark() {
2192 var now = Date.now(), timer = d3_timer_queueHead;
2193 while (timer) {
2194 if (now >= timer.t && timer.c(now - timer.t)) timer.c = null;
2195 timer = timer.n;
2196 }
2197 return now;
2198 }
2199 function d3_timer_sweep() {
2200 var t0, t1 = d3_timer_queueHead, time = Infinity;
2201 while (t1) {
2202 if (t1.c) {
2203 if (t1.t < time) time = t1.t;
2204 t1 = (t0 = t1).n;
2205 } else {
2206 t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
2207 }
2208 }
2209 d3_timer_queueTail = t0;
2210 return time;
2211 }
2212 function d3_format_precision(x, p) {
2213 return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
2214 }
2215 d3.round = function(x, n) {
2216 return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
2217 };
2218 var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
2219 d3.formatPrefix = function(value, precision) {
2220 var i = 0;
2221 if (value = +value) {
2222 if (value < 0) value *= -1;
2223 if (precision) value = d3.round(value, d3_format_precision(value, precision));
2224 i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
2225 i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
2226 }
2227 return d3_formatPrefixes[8 + i / 3];
2228 };
2229 function d3_formatPrefix(d, i) {
2230 var k = Math.pow(10, abs(8 - i) * 3);
2231 return {
2232 scale: i > 8 ? function(d) {
2233 return d / k;
2234 } : function(d) {
2235 return d * k;
2236 },
2237 symbol: d
2238 };
2239 }
2240 function d3_locale_numberFormat(locale) {
2241 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) {
2242 var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
2243 while (i > 0 && g > 0) {
2244 if (length + g + 1 > width) g = Math.max(1, width - length);
2245 t.push(value.substring(i -= g, i + g));
2246 if ((length += g + 1) > width) break;
2247 g = locale_grouping[j = (j + 1) % locale_grouping.length];
2248 }
2249 return t.reverse().join(locale_thousands);
2250 } : d3_identity;
2251 return function(specifier) {
2252 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;
2253 if (precision) precision = +precision.substring(1);
2254 if (zfill || fill === "0" && align === "=") {
2255 zfill = fill = "0";
2256 align = "=";
2257 }
2258 switch (type) {
2259 case "n":
2260 comma = true;
2261 type = "g";
2262 break;
2263
2264 case "%":
2265 scale = 100;
2266 suffix = "%";
2267 type = "f";
2268 break;
2269
2270 case "p":
2271 scale = 100;
2272 suffix = "%";
2273 type = "r";
2274 break;
2275
2276 case "b":
2277 case "o":
2278 case "x":
2279 case "X":
2280 if (symbol === "#") prefix = "0" + type.toLowerCase();
2281
2282 case "c":
2283 exponent = false;
2284
2285 case "d":
2286 integer = true;
2287 precision = 0;
2288 break;
2289
2290 case "s":
2291 scale = -1;
2292 type = "r";
2293 break;
2294 }
2295 if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
2296 if (type == "r" && !precision) type = "g";
2297 if (precision != null) {
2298 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));
2299 }
2300 type = d3_format_types.get(type) || d3_format_typeDefault;
2301 var zcomma = zfill && comma;
2302 return function(value) {
2303 var fullSuffix = suffix;
2304 if (integer && value % 1) return "";
2305 var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
2306 if (scale < 0) {
2307 var unit = d3.formatPrefix(value, precision);
2308 value = unit.scale(value);
2309 fullSuffix = unit.symbol + suffix;
2310 } else {
2311 value *= scale;
2312 }
2313 value = type(value, precision);
2314 var i = value.lastIndexOf("."), before, after;
2315 if (i < 0) {
2316 var j = exponent ? value.lastIndexOf("e") : -1;
2317 if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
2318 } else {
2319 before = value.substring(0, i);
2320 after = locale_decimal + value.substring(i + 1);
2321 }
2322 if (!zfill && comma) before = formatGroup(before, Infinity);
2323 var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
2324 if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
2325 negative += prefix;
2326 value = before + after;
2327 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;
2328 };
2329 };
2330 }
2331 var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
2332 var d3_format_types = d3.map({
2333 b: function(x) {
2334 return x.toString(2);
2335 },
2336 c: function(x) {
2337 return String.fromCharCode(x);
2338 },
2339 o: function(x) {
2340 return x.toString(8);
2341 },
2342 x: function(x) {
2343 return x.toString(16);
2344 },
2345 X: function(x) {
2346 return x.toString(16).toUpperCase();
2347 },
2348 g: function(x, p) {
2349 return x.toPrecision(p);
2350 },
2351 e: function(x, p) {
2352 return x.toExponential(p);
2353 },
2354 f: function(x, p) {
2355 return x.toFixed(p);
2356 },
2357 r: function(x, p) {
2358 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))));
2359 }
2360 });
2361 function d3_format_typeDefault(x) {
2362 return x + "";
2363 }
2364 var d3_time = d3.time = {}, d3_date = Date;
2365 function d3_date_utc() {
2366 this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
2367 }
2368 d3_date_utc.prototype = {
2369 getDate: function() {
2370 return this._.getUTCDate();
2371 },
2372 getDay: function() {
2373 return this._.getUTCDay();
2374 },
2375 getFullYear: function() {
2376 return this._.getUTCFullYear();
2377 },
2378 getHours: function() {
2379 return this._.getUTCHours();
2380 },
2381 getMilliseconds: function() {
2382 return this._.getUTCMilliseconds();
2383 },
2384 getMinutes: function() {
2385 return this._.getUTCMinutes();
2386 },
2387 getMonth: function() {
2388 return this._.getUTCMonth();
2389 },
2390 getSeconds: function() {
2391 return this._.getUTCSeconds();
2392 },
2393 getTime: function() {
2394 return this._.getTime();
2395 },
2396 getTimezoneOffset: function() {
2397 return 0;
2398 },
2399 valueOf: function() {
2400 return this._.valueOf();
2401 },
2402 setDate: function() {
2403 d3_time_prototype.setUTCDate.apply(this._, arguments);
2404 },
2405 setDay: function() {
2406 d3_time_prototype.setUTCDay.apply(this._, arguments);
2407 },
2408 setFullYear: function() {
2409 d3_time_prototype.setUTCFullYear.apply(this._, arguments);
2410 },
2411 setHours: function() {
2412 d3_time_prototype.setUTCHours.apply(this._, arguments);
2413 },
2414 setMilliseconds: function() {
2415 d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
2416 },
2417 setMinutes: function() {
2418 d3_time_prototype.setUTCMinutes.apply(this._, arguments);
2419 },
2420 setMonth: function() {
2421 d3_time_prototype.setUTCMonth.apply(this._, arguments);
2422 },
2423 setSeconds: function() {
2424 d3_time_prototype.setUTCSeconds.apply(this._, arguments);
2425 },
2426 setTime: function() {
2427 d3_time_prototype.setTime.apply(this._, arguments);
2428 }
2429 };
2430 var d3_time_prototype = Date.prototype;
2431 function d3_time_interval(local, step, number) {
2432 function round(date) {
2433 var d0 = local(date), d1 = offset(d0, 1);
2434 return date - d0 < d1 - date ? d0 : d1;
2435 }
2436 function ceil(date) {
2437 step(date = local(new d3_date(date - 1)), 1);
2438 return date;
2439 }
2440 function offset(date, k) {
2441 step(date = new d3_date(+date), k);
2442 return date;
2443 }
2444 function range(t0, t1, dt) {
2445 var time = ceil(t0), times = [];
2446 if (dt > 1) {
2447 while (time < t1) {
2448 if (!(number(time) % dt)) times.push(new Date(+time));
2449 step(time, 1);
2450 }
2451 } else {
2452 while (time < t1) times.push(new Date(+time)), step(time, 1);
2453 }
2454 return times;
2455 }
2456 function range_utc(t0, t1, dt) {
2457 try {
2458 d3_date = d3_date_utc;
2459 var utc = new d3_date_utc();
2460 utc._ = t0;
2461 return range(utc, t1, dt);
2462 } finally {
2463 d3_date = Date;
2464 }
2465 }
2466 local.floor = local;
2467 local.round = round;
2468 local.ceil = ceil;
2469 local.offset = offset;
2470 local.range = range;
2471 var utc = local.utc = d3_time_interval_utc(local);
2472 utc.floor = utc;
2473 utc.round = d3_time_interval_utc(round);
2474 utc.ceil = d3_time_interval_utc(ceil);
2475 utc.offset = d3_time_interval_utc(offset);
2476 utc.range = range_utc;
2477 return local;
2478 }
2479 function d3_time_interval_utc(method) {
2480 return function(date, k) {
2481 try {
2482 d3_date = d3_date_utc;
2483 var utc = new d3_date_utc();
2484 utc._ = date;
2485 return method(utc, k)._;
2486 } finally {
2487 d3_date = Date;
2488 }
2489 };
2490 }
2491 d3_time.year = d3_time_interval(function(date) {
2492 date = d3_time.day(date);
2493 date.setMonth(0, 1);
2494 return date;
2495 }, function(date, offset) {
2496 date.setFullYear(date.getFullYear() + offset);
2497 }, function(date) {
2498 return date.getFullYear();
2499 });
2500 d3_time.years = d3_time.year.range;
2501 d3_time.years.utc = d3_time.year.utc.range;
2502 d3_time.day = d3_time_interval(function(date) {
2503 var day = new d3_date(2e3, 0);
2504 day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
2505 return day;
2506 }, function(date, offset) {
2507 date.setDate(date.getDate() + offset);
2508 }, function(date) {
2509 return date.getDate() - 1;
2510 });
2511 d3_time.days = d3_time.day.range;
2512 d3_time.days.utc = d3_time.day.utc.range;
2513 d3_time.dayOfYear = function(date) {
2514 var year = d3_time.year(date);
2515 return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
2516 };
2517 [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
2518 i = 7 - i;
2519 var interval = d3_time[day] = d3_time_interval(function(date) {
2520 (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
2521 return date;
2522 }, function(date, offset) {
2523 date.setDate(date.getDate() + Math.floor(offset) * 7);
2524 }, function(date) {
2525 var day = d3_time.year(date).getDay();
2526 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
2527 });
2528 d3_time[day + "s"] = interval.range;
2529 d3_time[day + "s"].utc = interval.utc.range;
2530 d3_time[day + "OfYear"] = function(date) {
2531 var day = d3_time.year(date).getDay();
2532 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
2533 };
2534 });
2535 d3_time.week = d3_time.sunday;
2536 d3_time.weeks = d3_time.sunday.range;
2537 d3_time.weeks.utc = d3_time.sunday.utc.range;
2538 d3_time.weekOfYear = d3_time.sundayOfYear;
2539 function d3_locale_timeFormat(locale) {
2540 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;
2541 function d3_time_format(template) {
2542 var n = template.length;
2543 function format(date) {
2544 var string = [], i = -1, j = 0, c, p, f;
2545 while (++i < n) {
2546 if (template.charCodeAt(i) === 37) {
2547 string.push(template.slice(j, i));
2548 if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
2549 if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
2550 string.push(c);
2551 j = i + 1;
2552 }
2553 }
2554 string.push(template.slice(j, i));
2555 return string.join("");
2556 }
2557 format.parse = function(string) {
2558 var d = {
2559 y: 1900,
2560 m: 0,
2561 d: 1,
2562 H: 0,
2563 M: 0,
2564 S: 0,
2565 L: 0,
2566 Z: null
2567 }, i = d3_time_parse(d, template, string, 0);
2568 if (i != string.length) return null;
2569 if ("p" in d) d.H = d.H % 12 + d.p * 12;
2570 var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
2571 if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("W" in d || "U" in d) {
2572 if (!("w" in d)) d.w = "W" in d ? 1 : 0;
2573 date.setFullYear(d.y, 0, 1);
2574 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);
2575 } else date.setFullYear(d.y, d.m, d.d);
2576 date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
2577 return localZ ? date._ : date;
2578 };
2579 format.toString = function() {
2580 return template;
2581 };
2582 return format;
2583 }
2584 function d3_time_parse(date, template, string, j) {
2585 var c, p, t, i = 0, n = template.length, m = string.length;
2586 while (i < n) {
2587 if (j >= m) return -1;
2588 c = template.charCodeAt(i++);
2589 if (c === 37) {
2590 t = template.charAt(i++);
2591 p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
2592 if (!p || (j = p(date, string, j)) < 0) return -1;
2593 } else if (c != string.charCodeAt(j++)) {
2594 return -1;
2595 }
2596 }
2597 return j;
2598 }
2599 d3_time_format.utc = function(template) {
2600 var local = d3_time_format(template);
2601 function format(date) {
2602 try {
2603 d3_date = d3_date_utc;
2604 var utc = new d3_date();
2605 utc._ = date;
2606 return local(utc);
2607 } finally {
2608 d3_date = Date;
2609 }
2610 }
2611 format.parse = function(string) {
2612 try {
2613 d3_date = d3_date_utc;
2614 var date = local.parse(string);
2615 return date && date._;
2616 } finally {
2617 d3_date = Date;
2618 }
2619 };
2620 format.toString = local.toString;
2621 return format;
2622 };
2623 d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
2624 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);
2625 locale_periods.forEach(function(p, i) {
2626 d3_time_periodLookup.set(p.toLowerCase(), i);
2627 });
2628 var d3_time_formats = {
2629 a: function(d) {
2630 return locale_shortDays[d.getDay()];
2631 },
2632 A: function(d) {
2633 return locale_days[d.getDay()];
2634 },
2635 b: function(d) {
2636 return locale_shortMonths[d.getMonth()];
2637 },
2638 B: function(d) {
2639 return locale_months[d.getMonth()];
2640 },
2641 c: d3_time_format(locale_dateTime),
2642 d: function(d, p) {
2643 return d3_time_formatPad(d.getDate(), p, 2);
2644 },
2645 e: function(d, p) {
2646 return d3_time_formatPad(d.getDate(), p, 2);
2647 },
2648 H: function(d, p) {
2649 return d3_time_formatPad(d.getHours(), p, 2);
2650 },
2651 I: function(d, p) {
2652 return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
2653 },
2654 j: function(d, p) {
2655 return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
2656 },
2657 L: function(d, p) {
2658 return d3_time_formatPad(d.getMilliseconds(), p, 3);
2659 },
2660 m: function(d, p) {
2661 return d3_time_formatPad(d.getMonth() + 1, p, 2);
2662 },
2663 M: function(d, p) {
2664 return d3_time_formatPad(d.getMinutes(), p, 2);
2665 },
2666 p: function(d) {
2667 return locale_periods[+(d.getHours() >= 12)];
2668 },
2669 S: function(d, p) {
2670 return d3_time_formatPad(d.getSeconds(), p, 2);
2671 },
2672 U: function(d, p) {
2673 return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
2674 },
2675 w: function(d) {
2676 return d.getDay();
2677 },
2678 W: function(d, p) {
2679 return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
2680 },
2681 x: d3_time_format(locale_date),
2682 X: d3_time_format(locale_time),
2683 y: function(d, p) {
2684 return d3_time_formatPad(d.getFullYear() % 100, p, 2);
2685 },
2686 Y: function(d, p) {
2687 return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
2688 },
2689 Z: d3_time_zone,
2690 "%": function() {
2691 return "%";
2692 }
2693 };
2694 var d3_time_parsers = {
2695 a: d3_time_parseWeekdayAbbrev,
2696 A: d3_time_parseWeekday,
2697 b: d3_time_parseMonthAbbrev,
2698 B: d3_time_parseMonth,
2699 c: d3_time_parseLocaleFull,
2700 d: d3_time_parseDay,
2701 e: d3_time_parseDay,
2702 H: d3_time_parseHour24,
2703 I: d3_time_parseHour24,
2704 j: d3_time_parseDayOfYear,
2705 L: d3_time_parseMilliseconds,
2706 m: d3_time_parseMonthNumber,
2707 M: d3_time_parseMinutes,
2708 p: d3_time_parseAmPm,
2709 S: d3_time_parseSeconds,
2710 U: d3_time_parseWeekNumberSunday,
2711 w: d3_time_parseWeekdayNumber,
2712 W: d3_time_parseWeekNumberMonday,
2713 x: d3_time_parseLocaleDate,
2714 X: d3_time_parseLocaleTime,
2715 y: d3_time_parseYear,
2716 Y: d3_time_parseFullYear,
2717 Z: d3_time_parseZone,
2718 "%": d3_time_parseLiteralPercent
2719 };
2720 function d3_time_parseWeekdayAbbrev(date, string, i) {
2721 d3_time_dayAbbrevRe.lastIndex = 0;
2722 var n = d3_time_dayAbbrevRe.exec(string.slice(i));
2723 return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2724 }
2725 function d3_time_parseWeekday(date, string, i) {
2726 d3_time_dayRe.lastIndex = 0;
2727 var n = d3_time_dayRe.exec(string.slice(i));
2728 return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2729 }
2730 function d3_time_parseMonthAbbrev(date, string, i) {
2731 d3_time_monthAbbrevRe.lastIndex = 0;
2732 var n = d3_time_monthAbbrevRe.exec(string.slice(i));
2733 return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2734 }
2735 function d3_time_parseMonth(date, string, i) {
2736 d3_time_monthRe.lastIndex = 0;
2737 var n = d3_time_monthRe.exec(string.slice(i));
2738 return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2739 }
2740 function d3_time_parseLocaleFull(date, string, i) {
2741 return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
2742 }
2743 function d3_time_parseLocaleDate(date, string, i) {
2744 return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
2745 }
2746 function d3_time_parseLocaleTime(date, string, i) {
2747 return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
2748 }
2749 function d3_time_parseAmPm(date, string, i) {
2750 var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
2751 return n == null ? -1 : (date.p = n, i);
2752 }
2753 return d3_time_format;
2754 }
2755 var d3_time_formatPads = {
2756 "-": "",
2757 _: " ",
2758 "0": "0"
2759 }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
2760 function d3_time_formatPad(value, fill, width) {
2761 var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
2762 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
2763 }
2764 function d3_time_formatRe(names) {
2765 return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
2766 }
2767 function d3_time_formatLookup(names) {
2768 var map = new d3_Map(), i = -1, n = names.length;
2769 while (++i < n) map.set(names[i].toLowerCase(), i);
2770 return map;
2771 }
2772 function d3_time_parseWeekdayNumber(date, string, i) {
2773 d3_time_numberRe.lastIndex = 0;
2774 var n = d3_time_numberRe.exec(string.slice(i, i + 1));
2775 return n ? (date.w = +n[0], i + n[0].length) : -1;
2776 }
2777 function d3_time_parseWeekNumberSunday(date, string, i) {
2778 d3_time_numberRe.lastIndex = 0;
2779 var n = d3_time_numberRe.exec(string.slice(i));
2780 return n ? (date.U = +n[0], i + n[0].length) : -1;
2781 }
2782 function d3_time_parseWeekNumberMonday(date, string, i) {
2783 d3_time_numberRe.lastIndex = 0;
2784 var n = d3_time_numberRe.exec(string.slice(i));
2785 return n ? (date.W = +n[0], i + n[0].length) : -1;
2786 }
2787 function d3_time_parseFullYear(date, string, i) {
2788 d3_time_numberRe.lastIndex = 0;
2789 var n = d3_time_numberRe.exec(string.slice(i, i + 4));
2790 return n ? (date.y = +n[0], i + n[0].length) : -1;
2791 }
2792 function d3_time_parseYear(date, string, i) {
2793 d3_time_numberRe.lastIndex = 0;
2794 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2795 return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
2796 }
2797 function d3_time_parseZone(date, string, i) {
2798 return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
2799 i + 5) : -1;
2800 }
2801 function d3_time_expandYear(d) {
2802 return d + (d > 68 ? 1900 : 2e3);
2803 }
2804 function d3_time_parseMonthNumber(date, string, i) {
2805 d3_time_numberRe.lastIndex = 0;
2806 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2807 return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
2808 }
2809 function d3_time_parseDay(date, string, i) {
2810 d3_time_numberRe.lastIndex = 0;
2811 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2812 return n ? (date.d = +n[0], i + n[0].length) : -1;
2813 }
2814 function d3_time_parseDayOfYear(date, string, i) {
2815 d3_time_numberRe.lastIndex = 0;
2816 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
2817 return n ? (date.j = +n[0], i + n[0].length) : -1;
2818 }
2819 function d3_time_parseHour24(date, string, i) {
2820 d3_time_numberRe.lastIndex = 0;
2821 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2822 return n ? (date.H = +n[0], i + n[0].length) : -1;
2823 }
2824 function d3_time_parseMinutes(date, string, i) {
2825 d3_time_numberRe.lastIndex = 0;
2826 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2827 return n ? (date.M = +n[0], i + n[0].length) : -1;
2828 }
2829 function d3_time_parseSeconds(date, string, i) {
2830 d3_time_numberRe.lastIndex = 0;
2831 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2832 return n ? (date.S = +n[0], i + n[0].length) : -1;
2833 }
2834 function d3_time_parseMilliseconds(date, string, i) {
2835 d3_time_numberRe.lastIndex = 0;
2836 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
2837 return n ? (date.L = +n[0], i + n[0].length) : -1;
2838 }
2839 function d3_time_zone(d) {
2840 var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
2841 return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
2842 }
2843 function d3_time_parseLiteralPercent(date, string, i) {
2844 d3_time_percentRe.lastIndex = 0;
2845 var n = d3_time_percentRe.exec(string.slice(i, i + 1));
2846 return n ? i + n[0].length : -1;
2847 }
2848 function d3_time_formatMulti(formats) {
2849 var n = formats.length, i = -1;
2850 while (++i < n) formats[i][0] = this(formats[i][0]);
2851 return function(date) {
2852 var i = 0, f = formats[i];
2853 while (!f[1](date)) f = formats[++i];
2854 return f[0](date);
2855 };
2856 }
2857 d3.locale = function(locale) {
2858 return {
2859 numberFormat: d3_locale_numberFormat(locale),
2860 timeFormat: d3_locale_timeFormat(locale)
2861 };
2862 };
2863 var d3_locale_enUS = d3.locale({
2864 decimal: ".",
2865 thousands: ",",
2866 grouping: [ 3 ],
2867 currency: [ "$", "" ],
2868 dateTime: "%a %b %e %X %Y",
2869 date: "%m/%d/%Y",
2870 time: "%H:%M:%S",
2871 periods: [ "AM", "PM" ],
2872 days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
2873 shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
2874 months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
2875 shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
2876 });
2877 d3.format = d3_locale_enUS.numberFormat;
2878 d3.geo = {};
2879 function d3_adder() {}
2880 d3_adder.prototype = {
2881 s: 0,
2882 t: 0,
2883 add: function(y) {
2884 d3_adderSum(y, this.t, d3_adderTemp);
2885 d3_adderSum(d3_adderTemp.s, this.s, this);
2886 if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
2887 },
2888 reset: function() {
2889 this.s = this.t = 0;
2890 },
2891 valueOf: function() {
2892 return this.s;
2893 }
2894 };
2895 var d3_adderTemp = new d3_adder();
2896 function d3_adderSum(a, b, o) {
2897 var x = o.s = a + b, bv = x - a, av = x - bv;
2898 o.t = a - av + (b - bv);
2899 }
2900 d3.geo.stream = function(object, listener) {
2901 if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
2902 d3_geo_streamObjectType[object.type](object, listener);
2903 } else {
2904 d3_geo_streamGeometry(object, listener);
2905 }
2906 };
2907 function d3_geo_streamGeometry(geometry, listener) {
2908 if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
2909 d3_geo_streamGeometryType[geometry.type](geometry, listener);
2910 }
2911 }
2912 var d3_geo_streamObjectType = {
2913 Feature: function(feature, listener) {
2914 d3_geo_streamGeometry(feature.geometry, listener);
2915 },
2916 FeatureCollection: function(object, listener) {
2917 var features = object.features, i = -1, n = features.length;
2918 while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
2919 }
2920 };
2921 var d3_geo_streamGeometryType = {
2922 Sphere: function(object, listener) {
2923 listener.sphere();
2924 },
2925 Point: function(object, listener) {
2926 object = object.coordinates;
2927 listener.point(object[0], object[1], object[2]);
2928 },
2929 MultiPoint: function(object, listener) {
2930 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2931 while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
2932 },
2933 LineString: function(object, listener) {
2934 d3_geo_streamLine(object.coordinates, listener, 0);
2935 },
2936 MultiLineString: function(object, listener) {
2937 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2938 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
2939 },
2940 Polygon: function(object, listener) {
2941 d3_geo_streamPolygon(object.coordinates, listener);
2942 },
2943 MultiPolygon: function(object, listener) {
2944 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2945 while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
2946 },
2947 GeometryCollection: function(object, listener) {
2948 var geometries = object.geometries, i = -1, n = geometries.length;
2949 while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
2950 }
2951 };
2952 function d3_geo_streamLine(coordinates, listener, closed) {
2953 var i = -1, n = coordinates.length - closed, coordinate;
2954 listener.lineStart();
2955 while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
2956 listener.lineEnd();
2957 }
2958 function d3_geo_streamPolygon(coordinates, listener) {
2959 var i = -1, n = coordinates.length;
2960 listener.polygonStart();
2961 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
2962 listener.polygonEnd();
2963 }
2964 d3.geo.area = function(object) {
2965 d3_geo_areaSum = 0;
2966 d3.geo.stream(object, d3_geo_area);
2967 return d3_geo_areaSum;
2968 };
2969 var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
2970 var d3_geo_area = {
2971 sphere: function() {
2972 d3_geo_areaSum += 4 * π;
2973 },
2974 point: d3_noop,
2975 lineStart: d3_noop,
2976 lineEnd: d3_noop,
2977 polygonStart: function() {
2978 d3_geo_areaRingSum.reset();
2979 d3_geo_area.lineStart = d3_geo_areaRingStart;
2980 },
2981 polygonEnd: function() {
2982 var area = 2 * d3_geo_areaRingSum;
2983 d3_geo_areaSum += area < 0 ? 4 * π + area : area;
2984 d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
2985 }
2986 };
2987 function d3_geo_areaRingStart() {
2988 var λ00, φ00, λ0, cosφ0, sinφ0;
2989 d3_geo_area.point = function(λ, φ) {
2990 d3_geo_area.point = nextPoint;
2991 λ0 = 00 = λ) * d3_radians, cosφ0 = Math.cos = 00 = φ) * d3_radians / 2 + π / 4),
2992 sinφ0 = Math.sin(φ);
2993 };
2994 function nextPoint(λ, φ) {
2995 λ *= d3_radians;
2996 φ = φ * d3_radians / 2 + π / 4;
2997 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λ);
2998 d3_geo_areaRingSum.add(Math.atan2(v, u));
2999 λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
3000 }
3001 d3_geo_area.lineEnd = function() {
3002 nextPoint00, φ00);
3003 };
3004 }
3005 function d3_geo_cartesian(spherical) {
3006 var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
3007 return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
3008 }
3009 function d3_geo_cartesianDot(a, b) {
3010 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
3011 }
3012 function d3_geo_cartesianCross(a, b) {
3013 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] ];
3014 }
3015 function d3_geo_cartesianAdd(a, b) {
3016 a[0] += b[0];
3017 a[1] += b[1];
3018 a[2] += b[2];
3019 }
3020 function d3_geo_cartesianScale(vector, k) {
3021 return [ vector[0] * k, vector[1] * k, vector[2] * k ];
3022 }
3023 function d3_geo_cartesianNormalize(d) {
3024 var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
3025 d[0] /= l;
3026 d[1] /= l;
3027 d[2] /= l;
3028 }
3029 function d3_geo_spherical(cartesian) {
3030 return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
3031 }
3032 function d3_geo_sphericalEqual(a, b) {
3033 return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
3034 }
3035 d3.geo.bounds = function() {
3036 var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
3037 var bound = {
3038 point: point,
3039 lineStart: lineStart,
3040 lineEnd: lineEnd,
3041 polygonStart: function() {
3042 bound.point = ringPoint;
3043 bound.lineStart = ringStart;
3044 bound.lineEnd = ringEnd;
3045 dλSum = 0;
3046 d3_geo_area.polygonStart();
3047 },
3048 polygonEnd: function() {
3049 d3_geo_area.polygonEnd();
3050 bound.point = point;
3051 bound.lineStart = lineStart;
3052 bound.lineEnd = lineEnd;
3053 if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
3054 range[0] = λ0, range[1] = λ1;
3055 }
3056 };
3057 function point(λ, φ) {
3058 ranges.push(range = [ λ0 = λ, λ1 = λ ]);
3059 if < φ0) φ0 = φ;
3060 if > φ1) φ1 = φ;
3061 }
3062 function linePoint(λ, φ) {
3063 var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
3064 if (p0) {
3065 var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
3066 d3_geo_cartesianNormalize(inflection);
3067 inflection = d3_geo_spherical(inflection);
3068 var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
3069 if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
3070 var φi = inflection[1] * d3_degrees;
3071 if i > φ1) φ1 = φi;
3072 } else if i = i + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
3073 var φi = -inflection[1] * d3_degrees;
3074 if i < φ0) φ0 = φi;
3075 } else {
3076 if < φ0) φ0 = φ;
3077 if > φ1) φ1 = φ;
3078 }
3079 if (antimeridian) {
3080 if < λ_) {
3081 if (angle0, λ) > angle0, λ1)) λ1 = λ;
3082 } else {
3083 if (angle(λ, λ1) > angle0, λ1)) λ0 = λ;
3084 }
3085 } else {
3086 if 1 >= λ0) {
3087 if < λ0) λ0 = λ;
3088 if > λ1) λ1 = λ;
3089 } else {
3090 if > λ_) {
3091 if (angle0, λ) > angle0, λ1)) λ1 = λ;
3092 } else {
3093 if (angle(λ, λ1) > angle0, λ1)) λ0 = λ;
3094 }
3095 }
3096 }
3097 } else {
3098 point(λ, φ);
3099 }
3100 p0 = p, λ_ = λ;
3101 }
3102 function lineStart() {
3103 bound.point = linePoint;
3104 }
3105 function lineEnd() {
3106 range[0] = λ0, range[1] = λ1;
3107 bound.point = point;
3108 p0 = null;
3109 }
3110 function ringPoint(λ, φ) {
3111 if (p0) {
3112 var dλ = λ - λ_;
3113 dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
3114 } else λ__ = λ, φ__ = φ;
3115 d3_geo_area.point(λ, φ);
3116 linePoint(λ, φ);
3117 }
3118 function ringStart() {
3119 d3_geo_area.lineStart();
3120 }
3121 function ringEnd() {
3122 ringPoint__, φ__);
3123 d3_geo_area.lineEnd();
3124 if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
3125 range[0] = λ0, range[1] = λ1;
3126 p0 = null;
3127 }
3128 function angle0, λ1) {
3129 return 1 -= λ0) < 0 ? λ1 + 360 : λ1;
3130 }
3131 function compareRanges(a, b) {
3132 return a[0] - b[0];
3133 }
3134 function withinRange(x, range) {
3135 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
3136 }
3137 return function(feature) {
3138 φ1 = λ1 = -(λ0 = φ0 = Infinity);
3139 ranges = [];
3140 d3.geo.stream(feature, bound);
3141 var n = ranges.length;
3142 if (n) {
3143 ranges.sort(compareRanges);
3144 for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
3145 b = ranges[i];
3146 if (withinRange(b[0], a) || withinRange(b[1], a)) {
3147 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
3148 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
3149 } else {
3150 merged.push(a = b);
3151 }
3152 }
3153 var best = -Infinity, dλ;
3154 for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
3155 b = merged[i];
3156 if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
3157 }
3158 }
3159 ranges = range = null;
3160 return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
3161 };
3162 }();
3163 d3.geo.centroid = function(object) {
3164 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;
3165 d3.geo.stream(object, d3_geo_centroid);
3166 var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
3167 if (m < ε2) {
3168 x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
3169 if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
3170 m = x * x + y * y + z * z;
3171 if (m < ε2) return [ NaN, NaN ];
3172 }
3173 return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
3174 };
3175 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;
3176 var d3_geo_centroid = {
3177 sphere: d3_noop,
3178 point: d3_geo_centroidPoint,
3179 lineStart: d3_geo_centroidLineStart,
3180 lineEnd: d3_geo_centroidLineEnd,
3181 polygonStart: function() {
3182 d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
3183 },
3184 polygonEnd: function() {
3185 d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
3186 }
3187 };
3188 function d3_geo_centroidPoint(λ, φ) {
3189 λ *= d3_radians;
3190 var cosφ = Math.cos *= d3_radians);
3191 d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
3192 }
3193 function d3_geo_centroidPointXYZ(x, y, z) {
3194 ++d3_geo_centroidW0;
3195 d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
3196 d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
3197 d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
3198 }
3199 function d3_geo_centroidLineStart() {
3200 var x0, y0, z0;
3201 d3_geo_centroid.point = function(λ, φ) {
3202 λ *= d3_radians;
3203 var cosφ = Math.cos *= d3_radians);
3204 x0 = cosφ * Math.cos(λ);
3205 y0 = cosφ * Math.sin(λ);
3206 z0 = Math.sin(φ);
3207 d3_geo_centroid.point = nextPoint;
3208 d3_geo_centroidPointXYZ(x0, y0, z0);
3209 };
3210 function nextPoint(λ, φ) {
3211 λ *= d3_radians;
3212 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);
3213 d3_geo_centroidW1 += w;
3214 d3_geo_centroidX1 += w * (x0 + (x0 = x));
3215 d3_geo_centroidY1 += w * (y0 + (y0 = y));
3216 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3217 d3_geo_centroidPointXYZ(x0, y0, z0);
3218 }
3219 }
3220 function d3_geo_centroidLineEnd() {
3221 d3_geo_centroid.point = d3_geo_centroidPoint;
3222 }
3223 function d3_geo_centroidRingStart() {
3224 var λ00, φ00, x0, y0, z0;
3225 d3_geo_centroid.point = function(λ, φ) {
3226 λ00 = λ, φ00 = φ;
3227 d3_geo_centroid.point = nextPoint;
3228 λ *= d3_radians;
3229 var cosφ = Math.cos *= d3_radians);
3230 x0 = cosφ * Math.cos(λ);
3231 y0 = cosφ * Math.sin(λ);
3232 z0 = Math.sin(φ);
3233 d3_geo_centroidPointXYZ(x0, y0, z0);
3234 };
3235 d3_geo_centroid.lineEnd = function() {
3236 nextPoint00, φ00);
3237 d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
3238 d3_geo_centroid.point = d3_geo_centroidPoint;
3239 };
3240 function nextPoint(λ, φ) {
3241 λ *= d3_radians;
3242 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);
3243 d3_geo_centroidX2 += v * cx;
3244 d3_geo_centroidY2 += v * cy;
3245 d3_geo_centroidZ2 += v * cz;
3246 d3_geo_centroidW1 += w;
3247 d3_geo_centroidX1 += w * (x0 + (x0 = x));
3248 d3_geo_centroidY1 += w * (y0 + (y0 = y));
3249 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3250 d3_geo_centroidPointXYZ(x0, y0, z0);
3251 }
3252 }
3253 function d3_geo_compose(a, b) {
3254 function compose(x, y) {
3255 return x = a(x, y), b(x[0], x[1]);
3256 }
3257 if (a.invert && b.invert) compose.invert = function(x, y) {
3258 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
3259 };
3260 return compose;
3261 }
3262 function d3_true() {
3263 return true;
3264 }
3265 function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
3266 var subject = [], clip = [];
3267 segments.forEach(function(segment) {
3268 if ((n = segment.length - 1) <= 0) return;
3269 var n, p0 = segment[0], p1 = segment[n];
3270 if (d3_geo_sphericalEqual(p0, p1)) {
3271 listener.lineStart();
3272 for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
3273 listener.lineEnd();
3274 return;
3275 }
3276 var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
3277 a.o = b;
3278 subject.push(a);
3279 clip.push(b);
3280 a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
3281 b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
3282 a.o = b;
3283 subject.push(a);
3284 clip.push(b);
3285 });
3286 clip.sort(compare);
3287 d3_geo_clipPolygonLinkCircular(subject);
3288 d3_geo_clipPolygonLinkCircular(clip);
3289 if (!subject.length) return;
3290 for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
3291 clip[i].e = entry = !entry;
3292 }
3293 var start = subject[0], points, point;
3294 while (1) {
3295 var current = start, isSubject = true;
3296 while (current.v) if ((current = current.n) === start) return;
3297 points = current.z;
3298 listener.lineStart();
3299 do {
3300 current.v = current.o.v = true;
3301 if (current.e) {
3302 if (isSubject) {
3303 for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
3304 } else {
3305 interpolate(current.x, current.n.x, 1, listener);
3306 }
3307 current = current.n;
3308 } else {
3309 if (isSubject) {
3310 points = current.p.z;
3311 for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
3312 } else {
3313 interpolate(current.x, current.p.x, -1, listener);
3314 }
3315 current = current.p;
3316 }
3317 current = current.o;
3318 points = current.z;
3319 isSubject = !isSubject;
3320 } while (!current.v);
3321 listener.lineEnd();
3322 }
3323 }
3324 function d3_geo_clipPolygonLinkCircular(array) {
3325 if (!(n = array.length)) return;
3326 var n, i = 0, a = array[0], b;
3327 while (++i < n) {
3328 a.n = b = array[i];
3329 b.p = a;
3330 a = b;
3331 }
3332 a.n = b = array[0];
3333 b.p = a;
3334 }
3335 function d3_geo_clipPolygonIntersection(point, points, other, entry) {
3336 this.x = point;
3337 this.z = points;
3338 this.o = other;
3339 this.e = entry;
3340 this.v = false;
3341 this.n = this.p = null;
3342 }
3343 function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
3344 return function(rotate, listener) {
3345 var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
3346 var clip = {
3347 point: point,
3348 lineStart: lineStart,
3349 lineEnd: lineEnd,
3350 polygonStart: function() {
3351 clip.point = pointRing;
3352 clip.lineStart = ringStart;
3353 clip.lineEnd = ringEnd;
3354 segments = [];
3355 polygon = [];
3356 },
3357 polygonEnd: function() {
3358 clip.point = point;
3359 clip.lineStart = lineStart;
3360 clip.lineEnd = lineEnd;
3361 segments = d3.merge(segments);
3362 var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
3363 if (segments.length) {
3364 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3365 d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
3366 } else if (clipStartInside) {
3367 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3368 listener.lineStart();
3369 interpolate(null, null, 1, listener);
3370 listener.lineEnd();
3371 }
3372 if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
3373 segments = polygon = null;
3374 },
3375 sphere: function() {
3376 listener.polygonStart();
3377 listener.lineStart();
3378 interpolate(null, null, 1, listener);
3379 listener.lineEnd();
3380 listener.polygonEnd();
3381 }
3382 };
3383 function point(λ, φ) {
3384 var point = rotate(λ, φ);
3385 if (pointVisible = point[0], φ = point[1])) listener.point(λ, φ);
3386 }
3387 function pointLine(λ, φ) {
3388 var point = rotate(λ, φ);
3389 line.point(point[0], point[1]);
3390 }
3391 function lineStart() {
3392 clip.point = pointLine;
3393 line.lineStart();
3394 }
3395 function lineEnd() {
3396 clip.point = point;
3397 line.lineEnd();
3398 }
3399 var segments;
3400 var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
3401 function pointRing(λ, φ) {
3402 ring.push([ λ, φ ]);
3403 var point = rotate(λ, φ);
3404 ringListener.point(point[0], point[1]);
3405 }
3406 function ringStart() {
3407 ringListener.lineStart();
3408 ring = [];
3409 }
3410 function ringEnd() {
3411 pointRing(ring[0][0], ring[0][1]);
3412 ringListener.lineEnd();
3413 var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
3414 ring.pop();
3415 polygon.push(ring);
3416 ring = null;
3417 if (!n) return;
3418 if (clean & 1) {
3419 segment = ringSegments[0];
3420 var n = segment.length - 1, i = -1, point;
3421 if (n > 0) {
3422 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3423 listener.lineStart();
3424 while (++i < n) listener.point((point = segment[i])[0], point[1]);
3425 listener.lineEnd();
3426 }
3427 return;
3428 }
3429 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
3430 segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
3431 }
3432 return clip;
3433 };
3434 }
3435 function d3_geo_clipSegmentLength1(segment) {
3436 return segment.length > 1;
3437 }
3438 function d3_geo_clipBufferListener() {
3439 var lines = [], line;
3440 return {
3441 lineStart: function() {
3442 lines.push(line = []);
3443 },
3444 point: function(λ, φ) {
3445 line.push([ λ, φ ]);
3446 },
3447 lineEnd: d3_noop,
3448 buffer: function() {
3449 var buffer = lines;
3450 lines = [];
3451 line = null;
3452 return buffer;
3453 },
3454 rejoin: function() {
3455 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
3456 }
3457 };
3458 }
3459 function d3_geo_clipSort(a, b) {
3460 return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
3461 }
3462 var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, / 2 ]);
3463 function d3_geo_clipAntimeridianLine(listener) {
3464 var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
3465 return {
3466 lineStart: function() {
3467 listener.lineStart();
3468 clean = 1;
3469 },
3470 point: function1, φ1) {
3471 var sλ1 = λ1 > 0 ? π : -π, dλ = abs1 - λ0);
3472 if (abs(dλ - π) < ε) {
3473 listener.point0, φ0 = 0 + φ1) / 2 > 0 ? halfπ : -halfπ);
3474 listener.point(sλ0, φ0);
3475 listener.lineEnd();
3476 listener.lineStart();
3477 listener.point(sλ1, φ0);
3478 listener.point1, φ0);
3479 clean = 0;
3480 } else if (sλ0 !== sλ1 && dλ >= π) {
3481 if (abs0 - sλ0) < ε) λ0 -= sλ0 * ε;
3482 if (abs1 - sλ1) < ε) λ1 -= sλ1 * ε;
3483 φ0 = d3_geo_clipAntimeridianIntersect0, φ0, λ1, φ1);
3484 listener.point(sλ0, φ0);
3485 listener.lineEnd();
3486 listener.lineStart();
3487 listener.point(sλ1, φ0);
3488 clean = 0;
3489 }
3490 listener.point0 = λ1, φ0 = φ1);
3491 sλ0 = sλ1;
3492 },
3493 lineEnd: function() {
3494 listener.lineEnd();
3495 λ0 = φ0 = NaN;
3496 },
3497 clean: function() {
3498 return 2 - clean;
3499 }
3500 };
3501 }
3502 function d3_geo_clipAntimeridianIntersect0, φ0, λ1, φ1) {
3503 var cosφ0, cosφ1, sinλ0_λ1 = Math.sin0 - λ1);
3504 return abs(sinλ0_λ1) > ε ? Math.atan((Math.sin0) * (cosφ1 = Math.cos1)) * Math.sin1) - Math.sin1) * (cosφ0 = Math.cos0)) * Math.sin0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : 0 + φ1) / 2;
3505 }
3506 function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
3507 var φ;
3508 if (from == null) {
3509 φ = direction * halfπ;
3510 listener.point(-π, φ);
3511 listener.point(0, φ);
3512 listener.point(π, φ);
3513 listener.point(π, 0);
3514 listener.point(π, -φ);
3515 listener.point(0, -φ);
3516 listener.point(-π, -φ);
3517 listener.point(-π, 0);
3518 listener.point(-π, φ);
3519 } else if (abs(from[0] - to[0]) > ε) {
3520 var s = from[0] < to[0] ? π : -π;
3521 φ = direction * s / 2;
3522 listener.point(-s, φ);
3523 listener.point(0, φ);
3524 listener.point(s, φ);
3525 } else {
3526 listener.point(to[0], to[1]);
3527 }
3528 }
3529 function d3_geo_pointInPolygon(point, polygon) {
3530 var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
3531 d3_geo_areaRingSum.reset();
3532 for (var i = 0, n = polygon.length; i < n; ++i) {
3533 var ring = polygon[i], m = ring.length;
3534 if (!m) continue;
3535 var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin0), cosφ0 = Math.cos0), j = 1;
3536 while (true) {
3537 if (j === m) j = 0;
3538 point = ring[j];
3539 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φ;
3540 d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
3541 polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
3542 if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
3543 var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
3544 d3_geo_cartesianNormalize(arc);
3545 var intersection = d3_geo_cartesianCross(meridianNormal, arc);
3546 d3_geo_cartesianNormalize(intersection);
3547 var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
3548 if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
3549 winding += antimeridian ^ dλ >= 0 ? 1 : -1;
3550 }
3551 }
3552 if (!j++) break;
3553 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
3554 }
3555 }
3556 return (polarAngle < || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
3557 }
3558 function d3_geo_clipCircle(radius) {
3559 var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
3560 return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
3561 function visible(λ, φ) {
3562 return Math.cos(λ) * Math.cos(φ) > cr;
3563 }
3564 function clipLine(listener) {
3565 var point0, c0, v0, v00, clean;
3566 return {
3567 lineStart: function() {
3568 v00 = v0 = false;
3569 clean = 1;
3570 },
3571 point: function(λ, φ) {
3572 var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code + < 0 ? π : -π), φ) : 0;
3573 if (!point0 && (v00 = v0 = v)) listener.lineStart();
3574 if (v !== v0) {
3575 point2 = intersect(point0, point1);
3576 if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
3577 point1[0] += ε;
3578 point1[1] += ε;
3579 v = visible(point1[0], point1[1]);
3580 }
3581 }
3582 if (v !== v0) {
3583 clean = 0;
3584 if (v) {
3585 listener.lineStart();
3586 point2 = intersect(point1, point0);
3587 listener.point(point2[0], point2[1]);
3588 } else {
3589 point2 = intersect(point0, point1);
3590 listener.point(point2[0], point2[1]);
3591 listener.lineEnd();
3592 }
3593 point0 = point2;
3594 } else if (notHemisphere && point0 && smallRadius ^ v) {
3595 var t;
3596 if (!(c & c0) && (t = intersect(point1, point0, true))) {
3597 clean = 0;
3598 if (smallRadius) {
3599 listener.lineStart();
3600 listener.point(t[0][0], t[0][1]);
3601 listener.point(t[1][0], t[1][1]);
3602 listener.lineEnd();
3603 } else {
3604 listener.point(t[1][0], t[1][1]);
3605 listener.lineEnd();
3606 listener.lineStart();
3607 listener.point(t[0][0], t[0][1]);
3608 }
3609 }
3610 }
3611 if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
3612 listener.point(point1[0], point1[1]);
3613 }
3614 point0 = point1, v0 = v, c0 = c;
3615 },
3616 lineEnd: function() {
3617 if (v0) listener.lineEnd();
3618 point0 = null;
3619 },
3620 clean: function() {
3621 return clean | (v00 && v0) << 1;
3622 }
3623 };
3624 }
3625 function intersect(a, b, two) {
3626 var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
3627 var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
3628 if (!determinant) return !two && a;
3629 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);
3630 d3_geo_cartesianAdd(A, B);
3631 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);
3632 if (t2 < 0) return;
3633 var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
3634 d3_geo_cartesianAdd(q, A);
3635 q = d3_geo_spherical(q);
3636 if (!two) return q;
3637 var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
3638 if 1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
3639 var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
3640 if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
3641 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)) {
3642 var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
3643 d3_geo_cartesianAdd(q1, A);
3644 return [ q, d3_geo_spherical(q1) ];
3645 }
3646 }
3647 function code(λ, φ) {
3648 var r = smallRadius ? radius : π - radius, code = 0;
3649 if < -r) code |= 1; else if > r) code |= 2;
3650 if < -r) code |= 4; else if > r) code |= 8;
3651 return code;
3652 }
3653 }
3654 function d3_geom_clipLine(x0, y0, x1, y1) {
3655 return function(line) {
3656 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;
3657 r = x0 - ax;
3658 if (!dx && r > 0) return;
3659 r /= dx;
3660 if (dx < 0) {
3661 if (r < t0) return;
3662 if (r < t1) t1 = r;
3663 } else if (dx > 0) {
3664 if (r > t1) return;
3665 if (r > t0) t0 = r;
3666 }
3667 r = x1 - ax;
3668 if (!dx && r < 0) return;
3669 r /= dx;
3670 if (dx < 0) {
3671 if (r > t1) return;
3672 if (r > t0) t0 = r;
3673 } else if (dx > 0) {
3674 if (r < t0) return;
3675 if (r < t1) t1 = r;
3676 }
3677 r = y0 - ay;
3678 if (!dy && r > 0) return;
3679 r /= dy;
3680 if (dy < 0) {
3681 if (r < t0) return;
3682 if (r < t1) t1 = r;
3683 } else if (dy > 0) {
3684 if (r > t1) return;
3685 if (r > t0) t0 = r;
3686 }
3687 r = y1 - ay;
3688 if (!dy && r < 0) return;
3689 r /= dy;
3690 if (dy < 0) {
3691 if (r > t1) return;
3692 if (r > t0) t0 = r;
3693 } else if (dy > 0) {
3694 if (r < t0) return;
3695 if (r < t1) t1 = r;
3696 }
3697 if (t0 > 0) line.a = {
3698 x: ax + t0 * dx,
3699 y: ay + t0 * dy
3700 };
3701 if (t1 < 1) line.b = {
3702 x: ax + t1 * dx,
3703 y: ay + t1 * dy
3704 };
3705 return line;
3706 };
3707 }
3708 var d3_geo_clipExtentMAX = 1e9;
3709 d3.geo.clipExtent = function() {
3710 var x0, y0, x1, y1, stream, clip, clipExtent = {
3711 stream: function(output) {
3712 if (stream) stream.valid = false;
3713 stream = clip(output);
3714 stream.valid = true;
3715 return stream;
3716 },
3717 extent: function(_) {
3718 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
3719 clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
3720 if (stream) stream.valid = false, stream = null;
3721 return clipExtent;
3722 }
3723 };
3724 return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
3725 };
3726 function d3_geo_clipExtent(x0, y0, x1, y1) {
3727 return function(listener) {
3728 var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
3729 var clip = {
3730 point: point,
3731 lineStart: lineStart,
3732 lineEnd: lineEnd,
3733 polygonStart: function() {
3734 listener = bufferListener;
3735 segments = [];
3736 polygon = [];
3737 clean = true;
3738 },
3739 polygonEnd: function() {
3740 listener = listener_;
3741 segments = d3.merge(segments);
3742 var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
3743 if (inside || visible) {
3744 listener.polygonStart();
3745 if (inside) {
3746 listener.lineStart();
3747 interpolate(null, null, 1, listener);
3748 listener.lineEnd();
3749 }
3750 if (visible) {
3751 d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
3752 }
3753 listener.polygonEnd();
3754 }
3755 segments = polygon = ring = null;
3756 }
3757 };
3758 function insidePolygon(p) {
3759 var wn = 0, n = polygon.length, y = p[1];
3760 for (var i = 0; i < n; ++i) {
3761 for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
3762 b = v[j];
3763 if (a[1] <= y) {
3764 if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
3765 } else {
3766 if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
3767 }
3768 a = b;
3769 }
3770 }
3771 return wn !== 0;
3772 }
3773 function interpolate(from, to, direction, listener) {
3774 var a = 0, a1 = 0;
3775 if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
3776 do {
3777 listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
3778 } while ((a = (a + direction + 4) % 4) !== a1);
3779 } else {
3780 listener.point(to[0], to[1]);
3781 }
3782 }
3783 function pointVisible(x, y) {
3784 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
3785 }
3786 function point(x, y) {
3787 if (pointVisible(x, y)) listener.point(x, y);
3788 }
3789 var x__, y__, v__, x_, y_, v_, first, clean;
3790 function lineStart() {
3791 clip.point = linePoint;
3792 if (polygon) polygon.push(ring = []);
3793 first = true;
3794 v_ = false;
3795 x_ = y_ = NaN;
3796 }
3797 function lineEnd() {
3798 if (segments) {
3799 linePoint(x__, y__);
3800 if (v__ && v_) bufferListener.rejoin();
3801 segments.push(bufferListener.buffer());
3802 }
3803 clip.point = point;
3804 if (v_) listener.lineEnd();
3805 }
3806 function linePoint(x, y) {
3807 x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
3808 y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
3809 var v = pointVisible(x, y);
3810 if (polygon) ring.push([ x, y ]);
3811 if (first) {
3812 x__ = x, y__ = y, v__ = v;
3813 first = false;
3814 if (v) {
3815 listener.lineStart();
3816 listener.point(x, y);
3817 }
3818 } else {
3819 if (v && v_) listener.point(x, y); else {
3820 var l = {
3821 a: {
3822 x: x_,
3823 y: y_
3824 },
3825 b: {
3826 x: x,
3827 y: y
3828 }
3829 };
3830 if (clipLine(l)) {
3831 if (!v_) {
3832 listener.lineStart();
3833 listener.point(l.a.x, l.a.y);
3834 }
3835 listener.point(l.b.x, l.b.y);
3836 if (!v) listener.lineEnd();
3837 clean = false;
3838 } else if (v) {
3839 listener.lineStart();
3840 listener.point(x, y);
3841 clean = false;
3842 }
3843 }
3844 }
3845 x_ = x, y_ = y, v_ = v;
3846 }
3847 return clip;
3848 };
3849 function corner(p, direction) {
3850 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;
3851 }
3852 function compare(a, b) {
3853 return comparePoints(a.x, b.x);
3854 }
3855 function comparePoints(a, b) {
3856 var ca = corner(a, 1), cb = corner(b, 1);
3857 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];
3858 }
3859 }
3860 function d3_geo_conic(projectAt) {
3861 var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m0, φ1);
3862 p.parallels = function(_) {
3863 if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
3864 return m0 = _[0] * π / 180, φ1 = _[1] * π / 180);
3865 };
3866 return p;
3867 }
3868 function d3_geo_conicEqualArea0, φ1) {
3869 var sinφ0 = Math.sin0), n = (sinφ0 + Math.sin1)) / 2, C = 1 + sinφ0 * (2 * n - sinφ0), ρ0 = Math.sqrt(C) / n;
3870 function forward(λ, φ) {
3871 var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
3872 return [ ρ * Math.sin *= n), ρ0 - ρ * Math.cos(λ) ];
3873 }
3874 forward.invert = function(x, y) {
3875 var ρ0_y = ρ0 - y;
3876 return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
3877 };
3878 return forward;
3879 }
3880 (d3.geo.conicEqualArea = function() {
3881 return d3_geo_conic(d3_geo_conicEqualArea);
3882 }).raw = d3_geo_conicEqualArea;
3883 d3.geo.albers = function() {
3884 return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
3885 };
3886 d3.geo.albersUsa = function() {
3887 var lower48 = d3.geo.albers();
3888 var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
3889 var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
3890 var point, pointStream = {
3891 point: function(x, y) {
3892 point = [ x, y ];
3893 }
3894 }, lower48Point, alaskaPoint, hawaiiPoint;
3895 function albersUsa(coordinates) {
3896 var x = coordinates[0], y = coordinates[1];
3897 point = null;
3898 (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
3899 return point;
3900 }
3901 albersUsa.invert = function(coordinates) {
3902 var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
3903 return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
3904 };
3905 albersUsa.stream = function(stream) {
3906 var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
3907 return {
3908 point: function(x, y) {
3909 lower48Stream.point(x, y);
3910 alaskaStream.point(x, y);
3911 hawaiiStream.point(x, y);
3912 },
3913 sphere: function() {
3914 lower48Stream.sphere();
3915 alaskaStream.sphere();
3916 hawaiiStream.sphere();
3917 },
3918 lineStart: function() {
3919 lower48Stream.lineStart();
3920 alaskaStream.lineStart();
3921 hawaiiStream.lineStart();
3922 },
3923 lineEnd: function() {
3924 lower48Stream.lineEnd();
3925 alaskaStream.lineEnd();
3926 hawaiiStream.lineEnd();
3927 },
3928 polygonStart: function() {
3929 lower48Stream.polygonStart();
3930 alaskaStream.polygonStart();
3931 hawaiiStream.polygonStart();
3932 },
3933 polygonEnd: function() {
3934 lower48Stream.polygonEnd();
3935 alaskaStream.polygonEnd();
3936 hawaiiStream.polygonEnd();
3937 }
3938 };
3939 };
3940 albersUsa.precision = function(_) {
3941 if (!arguments.length) return lower48.precision();
3942 lower48.precision(_);
3943 alaska.precision(_);
3944 hawaii.precision(_);
3945 return albersUsa;
3946 };
3947 albersUsa.scale = function(_) {
3948 if (!arguments.length) return lower48.scale();
3949 lower48.scale(_);
3950 alaska.scale(_ * .35);
3951 hawaii.scale(_);
3952 return albersUsa.translate(lower48.translate());
3953 };
3954 albersUsa.translate = function(_) {
3955 if (!arguments.length) return lower48.translate();
3956 var k = lower48.scale(), x = +_[0], y = +_[1];
3957 lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
3958 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;
3959 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;
3960 return albersUsa;
3961 };
3962 return albersUsa.scale(1070);
3963 };
3964 var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
3965 point: d3_noop,
3966 lineStart: d3_noop,
3967 lineEnd: d3_noop,
3968 polygonStart: function() {
3969 d3_geo_pathAreaPolygon = 0;
3970 d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
3971 },
3972 polygonEnd: function() {
3973 d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
3974 d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
3975 }
3976 };
3977 function d3_geo_pathAreaRingStart() {
3978 var x00, y00, x0, y0;
3979 d3_geo_pathArea.point = function(x, y) {
3980 d3_geo_pathArea.point = nextPoint;
3981 x00 = x0 = x, y00 = y0 = y;
3982 };
3983 function nextPoint(x, y) {
3984 d3_geo_pathAreaPolygon += y0 * x - x0 * y;
3985 x0 = x, y0 = y;
3986 }
3987 d3_geo_pathArea.lineEnd = function() {
3988 nextPoint(x00, y00);
3989 };
3990 }
3991 var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
3992 var d3_geo_pathBounds = {
3993 point: d3_geo_pathBoundsPoint,
3994 lineStart: d3_noop,
3995 lineEnd: d3_noop,
3996 polygonStart: d3_noop,
3997 polygonEnd: d3_noop
3998 };
3999 function d3_geo_pathBoundsPoint(x, y) {
4000 if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
4001 if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
4002 if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
4003 if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
4004 }
4005 function d3_geo_pathBuffer() {
4006 var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
4007 var stream = {
4008 point: point,
4009 lineStart: function() {
4010 stream.point = pointLineStart;
4011 },
4012 lineEnd: lineEnd,
4013 polygonStart: function() {
4014 stream.lineEnd = lineEndPolygon;
4015 },
4016 polygonEnd: function() {
4017 stream.lineEnd = lineEnd;
4018 stream.point = point;
4019 },
4020 pointRadius: function(_) {
4021 pointCircle = d3_geo_pathBufferCircle(_);
4022 return stream;
4023 },
4024 result: function() {
4025 if (buffer.length) {
4026 var result = buffer.join("");
4027 buffer = [];
4028 return result;
4029 }
4030 }
4031 };
4032 function point(x, y) {
4033 buffer.push("M", x, ",", y, pointCircle);
4034 }
4035 function pointLineStart(x, y) {
4036 buffer.push("M", x, ",", y);
4037 stream.point = pointLine;
4038 }
4039 function pointLine(x, y) {
4040 buffer.push("L", x, ",", y);
4041 }
4042 function lineEnd() {
4043 stream.point = point;
4044 }
4045 function lineEndPolygon() {
4046 buffer.push("Z");
4047 }
4048 return stream;
4049 }
4050 function d3_geo_pathBufferCircle(radius) {
4051 return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
4052 }
4053 var d3_geo_pathCentroid = {
4054 point: d3_geo_pathCentroidPoint,
4055 lineStart: d3_geo_pathCentroidLineStart,
4056 lineEnd: d3_geo_pathCentroidLineEnd,
4057 polygonStart: function() {
4058 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
4059 },
4060 polygonEnd: function() {
4061 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
4062 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
4063 d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
4064 }
4065 };
4066 function d3_geo_pathCentroidPoint(x, y) {
4067 d3_geo_centroidX0 += x;
4068 d3_geo_centroidY0 += y;
4069 ++d3_geo_centroidZ0;
4070 }
4071 function d3_geo_pathCentroidLineStart() {
4072 var x0, y0;
4073 d3_geo_pathCentroid.point = function(x, y) {
4074 d3_geo_pathCentroid.point = nextPoint;
4075 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4076 };
4077 function nextPoint(x, y) {
4078 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
4079 d3_geo_centroidX1 += z * (x0 + x) / 2;
4080 d3_geo_centroidY1 += z * (y0 + y) / 2;
4081 d3_geo_centroidZ1 += z;
4082 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4083 }
4084 }
4085 function d3_geo_pathCentroidLineEnd() {
4086 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
4087 }
4088 function d3_geo_pathCentroidRingStart() {
4089 var x00, y00, x0, y0;
4090 d3_geo_pathCentroid.point = function(x, y) {
4091 d3_geo_pathCentroid.point = nextPoint;
4092 d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
4093 };
4094 function nextPoint(x, y) {
4095 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
4096 d3_geo_centroidX1 += z * (x0 + x) / 2;
4097 d3_geo_centroidY1 += z * (y0 + y) / 2;
4098 d3_geo_centroidZ1 += z;
4099 z = y0 * x - x0 * y;
4100 d3_geo_centroidX2 += z * (x0 + x);
4101 d3_geo_centroidY2 += z * (y0 + y);
4102 d3_geo_centroidZ2 += z * 3;
4103 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4104 }
4105 d3_geo_pathCentroid.lineEnd = function() {
4106 nextPoint(x00, y00);
4107 };
4108 }
4109 function d3_geo_pathContext(context) {
4110 var pointRadius = 4.5;
4111 var stream = {
4112 point: point,
4113 lineStart: function() {
4114 stream.point = pointLineStart;
4115 },
4116 lineEnd: lineEnd,
4117 polygonStart: function() {
4118 stream.lineEnd = lineEndPolygon;
4119 },
4120 polygonEnd: function() {
4121 stream.lineEnd = lineEnd;
4122 stream.point = point;
4123 },
4124 pointRadius: function(_) {
4125 pointRadius = _;
4126 return stream;
4127 },
4128 result: d3_noop
4129 };
4130 function point(x, y) {
4131 context.moveTo(x + pointRadius, y);
4132 context.arc(x, y, pointRadius, 0, τ);
4133 }
4134 function pointLineStart(x, y) {
4135 context.moveTo(x, y);
4136 stream.point = pointLine;
4137 }
4138 function pointLine(x, y) {
4139 context.lineTo(x, y);
4140 }
4141 function lineEnd() {
4142 stream.point = point;
4143 }
4144 function lineEndPolygon() {
4145 context.closePath();
4146 }
4147 return stream;
4148 }
4149 function d3_geo_resample(project) {
4150 var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
4151 function resample(stream) {
4152 return (maxDepth ? resampleRecursive : resampleNone)(stream);
4153 }
4154 function resampleNone(stream) {
4155 return d3_geo_transformPoint(stream, function(x, y) {
4156 x = project(x, y);
4157 stream.point(x[0], x[1]);
4158 });
4159 }
4160 function resampleRecursive(stream) {
4161 var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
4162 var resample = {
4163 point: point,
4164 lineStart: lineStart,
4165 lineEnd: lineEnd,
4166 polygonStart: function() {
4167 stream.polygonStart();
4168 resample.lineStart = ringStart;
4169 },
4170 polygonEnd: function() {
4171 stream.polygonEnd();
4172 resample.lineStart = lineStart;
4173 }
4174 };
4175 function point(x, y) {
4176 x = project(x, y);
4177 stream.point(x[0], x[1]);
4178 }
4179 function lineStart() {
4180 x0 = NaN;
4181 resample.point = linePoint;
4182 stream.lineStart();
4183 }
4184 function linePoint(λ, φ) {
4185 var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
4186 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);
4187 stream.point(x0, y0);
4188 }
4189 function lineEnd() {
4190 resample.point = point;
4191 stream.lineEnd();
4192 }
4193 function ringStart() {
4194 lineStart();
4195 resample.point = ringPoint;
4196 resample.lineEnd = ringEnd;
4197 }
4198 function ringPoint(λ, φ) {
4199 linePoint00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
4200 resample.point = linePoint;
4201 }
4202 function ringEnd() {
4203 resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
4204 resample.lineEnd = lineEnd;
4205 lineEnd();
4206 }
4207 return resample;
4208 }
4209 function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
4210 var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
4211 if (d2 > 4 * δ2 && depth--) {
4212 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) < ε || abs0 - λ1) < ε ? 0 + λ1) / 2 : Math.atan2(b, a), p = project2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
4213 if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
4214 resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
4215 stream.point(x2, y2);
4216 resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
4217 }
4218 }
4219 }
4220 resample.precision = function(_) {
4221 if (!arguments.length) return Math.sqrt2);
4222 maxDepth = 2 = _ * _) > 0 && 16;
4223 return resample;
4224 };
4225 return resample;
4226 }
4227 d3.geo.path = function() {
4228 var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
4229 function path(object) {
4230 if (object) {
4231 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
4232 if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
4233 d3.geo.stream(object, cacheStream);
4234 }
4235 return contextStream.result();
4236 }
4237 path.area = function(object) {
4238 d3_geo_pathAreaSum = 0;
4239 d3.geo.stream(object, projectStream(d3_geo_pathArea));
4240 return d3_geo_pathAreaSum;
4241 };
4242 path.centroid = function(object) {
4243 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;
4244 d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
4245 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 ];
4246 };
4247 path.bounds = function(object) {
4248 d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
4249 d3.geo.stream(object, projectStream(d3_geo_pathBounds));
4250 return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
4251 };
4252 path.projection = function(_) {
4253 if (!arguments.length) return projection;
4254 projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
4255 return reset();
4256 };
4257 path.context = function(_) {
4258 if (!arguments.length) return context;
4259 contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
4260 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
4261 return reset();
4262 };
4263 path.pointRadius = function(_) {
4264 if (!arguments.length) return pointRadius;
4265 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
4266 return path;
4267 };
4268 function reset() {
4269 cacheStream = null;
4270 return path;
4271 }
4272 return path.projection(d3.geo.albersUsa()).context(null);
4273 };
4274 function d3_geo_pathProjectStream(project) {
4275 var resample = d3_geo_resample(function(x, y) {
4276 return project([ x * d3_degrees, y * d3_degrees ]);
4277 });
4278 return function(stream) {
4279 return d3_geo_projectionRadians(resample(stream));
4280 };
4281 }
4282 d3.geo.transform = function(methods) {
4283 return {
4284 stream: function(stream) {
4285 var transform = new d3_geo_transform(stream);
4286 for (var k in methods) transform[k] = methods[k];
4287 return transform;
4288 }
4289 };
4290 };
4291 function d3_geo_transform(stream) {
4292 this.stream = stream;
4293 }
4294 d3_geo_transform.prototype = {
4295 point: function(x, y) {
4296 this.stream.point(x, y);
4297 },
4298 sphere: function() {
4299 this.stream.sphere();
4300 },
4301 lineStart: function() {
4302 this.stream.lineStart();
4303 },
4304 lineEnd: function() {
4305 this.stream.lineEnd();
4306 },
4307 polygonStart: function() {
4308 this.stream.polygonStart();
4309 },
4310 polygonEnd: function() {
4311 this.stream.polygonEnd();
4312 }
4313 };
4314 function d3_geo_transformPoint(stream, point) {
4315 return {
4316 point: point,
4317 sphere: function() {
4318 stream.sphere();
4319 },
4320 lineStart: function() {
4321 stream.lineStart();
4322 },
4323 lineEnd: function() {
4324 stream.lineEnd();
4325 },
4326 polygonStart: function() {
4327 stream.polygonStart();
4328 },
4329 polygonEnd: function() {
4330 stream.polygonEnd();
4331 }
4332 };
4333 }
4334 d3.geo.projection = d3_geo_projection;
4335 d3.geo.projectionMutator = d3_geo_projectionMutator;
4336 function d3_geo_projection(project) {
4337 return d3_geo_projectionMutator(function() {
4338 return project;
4339 })();
4340 }
4341 function d3_geo_projectionMutator(projectAt) {
4342 var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
4343 x = project(x, y);
4344 return [ x[0] * k + δx, δy - x[1] * k ];
4345 }), 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;
4346 function projection(point) {
4347 point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
4348 return [ point[0] * k + δx, δy - point[1] * k ];
4349 }
4350 function invert(point) {
4351 point = projectRotate.invert((point[0] - δx) / k, y - point[1]) / k);
4352 return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
4353 }
4354 projection.stream = function(output) {
4355 if (stream) stream.valid = false;
4356 stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
4357 stream.valid = true;
4358 return stream;
4359 };
4360 projection.clipAngle = function(_) {
4361 if (!arguments.length) return clipAngle;
4362 preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
4363 return invalidate();
4364 };
4365 projection.clipExtent = function(_) {
4366 if (!arguments.length) return clipExtent;
4367 clipExtent = _;
4368 postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
4369 return invalidate();
4370 };
4371 projection.scale = function(_) {
4372 if (!arguments.length) return k;
4373 k = +_;
4374 return reset();
4375 };
4376 projection.translate = function(_) {
4377 if (!arguments.length) return [ x, y ];
4378 x = +_[0];
4379 y = +_[1];
4380 return reset();
4381 };
4382 projection.center = function(_) {
4383 if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
4384 λ = _[0] % 360 * d3_radians;
4385 φ = _[1] % 360 * d3_radians;
4386 return reset();
4387 };
4388 projection.rotate = function(_) {
4389 if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
4390 δλ = _[0] % 360 * d3_radians;
4391 δφ = _[1] % 360 * d3_radians;
4392 δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
4393 return reset();
4394 };
4395 d3.rebind(projection, projectResample, "precision");
4396 function reset() {
4397 projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
4398 var center = project(λ, φ);
4399 δx = x - center[0] * k;
4400 δy = y + center[1] * k;
4401 return invalidate();
4402 }
4403 function invalidate() {
4404 if (stream) stream.valid = false, stream = null;
4405 return projection;
4406 }
4407 return function() {
4408 project = projectAt.apply(this, arguments);
4409 projection.invert = project.invert && invert;
4410 return reset();
4411 };
4412 }
4413 function d3_geo_projectionRadians(stream) {
4414 return d3_geo_transformPoint(stream, function(x, y) {
4415 stream.point(x * d3_radians, y * d3_radians);
4416 });
4417 }
4418 function d3_geo_equirectangular(λ, φ) {
4419 return [ λ, φ ];
4420 }
4421 (d3.geo.equirectangular = function() {
4422 return d3_geo_projection(d3_geo_equirectangular);
4423 }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
4424 d3.geo.rotation = function(rotate) {
4425 rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
4426 function forward(coordinates) {
4427 coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4428 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
4429 }
4430 forward.invert = function(coordinates) {
4431 coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4432 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
4433 };
4434 return forward;
4435 };
4436 function d3_geo_identityRotation(λ, φ) {
4437 return [ λ > π ? λ - τ : λ < ? λ + τ : λ, φ ];
4438 }
4439 d3_geo_identityRotation.invert = d3_geo_equirectangular;
4440 function d3_geo_rotation(δλ, δφ, δγ) {
4441 return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
4442 }
4443 function d3_geo_forwardRotationλ(δλ) {
4444 return function(λ, φ) {
4445 return λ += δλ, [ λ > π ? λ - τ : λ < ? λ + τ : λ, φ ];
4446 };
4447 }
4448 function d3_geo_rotationλ(δλ) {
4449 var rotation = d3_geo_forwardRotationλ(δλ);
4450 rotation.invert = d3_geo_forwardRotationλ(-δλ);
4451 return rotation;
4452 }
4453 function d3_geo_rotationφγ(δφ, δγ) {
4454 var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
4455 function rotation(λ, φ) {
4456 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
4457 return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
4458 }
4459 rotation.invert = function(λ, φ) {
4460 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
4461 return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
4462 };
4463 return rotation;
4464 }
4465 d3.geo.circle = function() {
4466 var origin = [ 0, 0 ], angle, precision = 6, interpolate;
4467 function circle() {
4468 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 = [];
4469 interpolate(null, null, 1, {
4470 point: function(x, y) {
4471 ring.push(x = rotate(x, y));
4472 x[0] *= d3_degrees, x[1] *= d3_degrees;
4473 }
4474 });
4475 return {
4476 type: "Polygon",
4477 coordinates: [ ring ]
4478 };
4479 }
4480 circle.origin = function(x) {
4481 if (!arguments.length) return origin;
4482 origin = x;
4483 return circle;
4484 };
4485 circle.angle = function(x) {
4486 if (!arguments.length) return angle;
4487 interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
4488 return circle;
4489 };
4490 circle.precision = function(_) {
4491 if (!arguments.length) return precision;
4492 interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
4493 return circle;
4494 };
4495 return circle.angle(90);
4496 };
4497 function d3_geo_circleInterpolate(radius, precision) {
4498 var cr = Math.cos(radius), sr = Math.sin(radius);
4499 return function(from, to, direction, listener) {
4500 var step = direction * precision;
4501 if (from != null) {
4502 from = d3_geo_circleAngle(cr, from);
4503 to = d3_geo_circleAngle(cr, to);
4504 if (direction > 0 ? from < to : from > to) from += direction * τ;
4505 } else {
4506 from = radius + direction * τ;
4507 to = radius - .5 * step;
4508 }
4509 for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
4510 listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
4511 }
4512 };
4513 }
4514 function d3_geo_circleAngle(cr, point) {
4515 var a = d3_geo_cartesian(point);
4516 a[0] -= cr;
4517 d3_geo_cartesianNormalize(a);
4518 var angle = d3_acos(-a[1]);
4519 return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
4520 }
4521 d3.geo.distance = function(a, b) {
4522 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.sin0), cosφ0 = Math.cos0), sinφ1 = Math.sin1), cosφ1 = Math.cos1), t;
4523 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Δλ);
4524 };
4525 d3.geo.graticule = function() {
4526 var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
4527 function graticule() {
4528 return {
4529 type: "MultiLineString",
4530 coordinates: lines()
4531 };
4532 }
4533 function lines() {
4534 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) {
4535 return abs(x % DX) > ε;
4536 }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
4537 return abs(y % DY) > ε;
4538 }).map(y));
4539 }
4540 graticule.lines = function() {
4541 return lines().map(function(coordinates) {
4542 return {
4543 type: "LineString",
4544 coordinates: coordinates
4545 };
4546 });
4547 };
4548 graticule.outline = function() {
4549 return {
4550 type: "Polygon",
4551 coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
4552 };
4553 };
4554 graticule.extent = function(_) {
4555 if (!arguments.length) return graticule.minorExtent();
4556 return graticule.majorExtent(_).minorExtent(_);
4557 };
4558 graticule.majorExtent = function(_) {
4559 if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
4560 X0 = +_[0][0], X1 = +_[1][0];
4561 Y0 = +_[0][1], Y1 = +_[1][1];
4562 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
4563 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
4564 return graticule.precision(precision);
4565 };
4566 graticule.minorExtent = function(_) {
4567 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
4568 x0 = +_[0][0], x1 = +_[1][0];
4569 y0 = +_[0][1], y1 = +_[1][1];
4570 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
4571 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
4572 return graticule.precision(precision);
4573 };
4574 graticule.step = function(_) {
4575 if (!arguments.length) return graticule.minorStep();
4576 return graticule.majorStep(_).minorStep(_);
4577 };
4578 graticule.majorStep = function(_) {
4579 if (!arguments.length) return [ DX, DY ];
4580 DX = +_[0], DY = +_[1];
4581 return graticule;
4582 };
4583 graticule.minorStep = function(_) {
4584 if (!arguments.length) return [ dx, dy ];
4585 dx = +_[0], dy = +_[1];
4586 return graticule;
4587 };
4588 graticule.precision = function(_) {
4589 if (!arguments.length) return precision;
4590 precision = +_;
4591 x = d3_geo_graticuleX(y0, y1, 90);
4592 y = d3_geo_graticuleY(x0, x1, precision);
4593 X = d3_geo_graticuleX(Y0, Y1, 90);
4594 Y = d3_geo_graticuleY(X0, X1, precision);
4595 return graticule;
4596 };
4597 return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
4598 };
4599 function d3_geo_graticuleX(y0, y1, dy) {
4600 var y = d3.range(y0, y1 - ε, dy).concat(y1);
4601 return function(x) {
4602 return y.map(function(y) {
4603 return [ x, y ];
4604 });
4605 };
4606 }
4607 function d3_geo_graticuleY(x0, x1, dx) {
4608 var x = d3.range(x0, x1 - ε, dx).concat(x1);
4609 return function(y) {
4610 return x.map(function(x) {
4611 return [ x, y ];
4612 });
4613 };
4614 }
4615 function d3_source(d) {
4616 return d.source;
4617 }
4618 function d3_target(d) {
4619 return d.target;
4620 }
4621 d3.geo.greatArc = function() {
4622 var source = d3_source, source_, target = d3_target, target_;
4623 function greatArc() {
4624 return {
4625 type: "LineString",
4626 coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
4627 };
4628 }
4629 greatArc.distance = function() {
4630 return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
4631 };
4632 greatArc.source = function(_) {
4633 if (!arguments.length) return source;
4634 source = _, source_ = typeof _ === "function" ? null : _;
4635 return greatArc;
4636 };
4637 greatArc.target = function(_) {
4638 if (!arguments.length) return target;
4639 target = _, target_ = typeof _ === "function" ? null : _;
4640 return greatArc;
4641 };
4642 greatArc.precision = function() {
4643 return arguments.length ? greatArc : 0;
4644 };
4645 return greatArc;
4646 };
4647 d3.geo.interpolate = function(source, target) {
4648 return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
4649 };
4650 function d3_geo_interpolate(x0, y0, x1, y1) {
4651 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);
4652 var interpolate = d ? function(t) {
4653 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;
4654 return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
4655 } : function() {
4656 return [ x0 * d3_degrees, y0 * d3_degrees ];
4657 };
4658 interpolate.distance = d;
4659 return interpolate;
4660 }
4661 d3.geo.length = function(object) {
4662 d3_geo_lengthSum = 0;
4663 d3.geo.stream(object, d3_geo_length);
4664 return d3_geo_lengthSum;
4665 };
4666 var d3_geo_lengthSum;
4667 var d3_geo_length = {
4668 sphere: d3_noop,
4669 point: d3_noop,
4670 lineStart: d3_geo_lengthLineStart,
4671 lineEnd: d3_noop,
4672 polygonStart: d3_noop,
4673 polygonEnd: d3_noop
4674 };
4675 function d3_geo_lengthLineStart() {
4676 var λ0, sinφ0, cosφ0;
4677 d3_geo_length.point = function(λ, φ) {
4678 λ0 = λ * d3_radians, sinφ0 = Math.sin *= d3_radians), cosφ0 = Math.cos(φ);
4679 d3_geo_length.point = nextPoint;
4680 };
4681 d3_geo_length.lineEnd = function() {
4682 d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
4683 };
4684 function nextPoint(λ, φ) {
4685 var sinφ = Math.sin *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
4686 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Δλ);
4687 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
4688 }
4689 }
4690 function d3_geo_azimuthal(scale, angle) {
4691 function azimuthal(λ, φ) {
4692 var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
4693 return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
4694 }
4695 azimuthal.invert = function(x, y) {
4696 var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
4697 return [ Math.atan2(x * sinc, ρ * cosc), Math.asin && y * sinc / ρ) ];
4698 };
4699 return azimuthal;
4700 }
4701 var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
4702 return Math.sqrt(2 / (1 + cosλcosφ));
4703 }, function(ρ) {
4704 return 2 * Math.asin / 2);
4705 });
4706 (d3.geo.azimuthalEqualArea = function() {
4707 return d3_geo_projection(d3_geo_azimuthalEqualArea);
4708 }).raw = d3_geo_azimuthalEqualArea;
4709 var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
4710 var c = Math.acos(cosλcosφ);
4711 return c && c / Math.sin(c);
4712 }, d3_identity);
4713 (d3.geo.azimuthalEquidistant = function() {
4714 return d3_geo_projection(d3_geo_azimuthalEquidistant);
4715 }).raw = d3_geo_azimuthalEquidistant;
4716 function d3_geo_conicConformal0, φ1) {
4717 var cosφ0 = Math.cos0), t = function(φ) {
4718 return Math.tan / 4 + φ / 2);
4719 }, n = φ0 === φ1 ? Math.sin0) : Math.log(cosφ0 / Math.cos1)) / Math.log(t1) / t0)), F = cosφ0 * Math.pow(t0), n) / n;
4720 if (!n) return d3_geo_mercator;
4721 function forward(λ, φ) {
4722 if (F > 0) {
4723 if < -halfπ + ε) φ = -halfπ + ε;
4724 } else {
4725 if > halfπ - ε) φ = halfπ - ε;
4726 }
4727 var ρ = F / Math.pow(t(φ), n);
4728 return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
4729 }
4730 forward.invert = function(x, y) {
4731 var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
4732 return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
4733 };
4734 return forward;
4735 }
4736 (d3.geo.conicConformal = function() {
4737 return d3_geo_conic(d3_geo_conicConformal);
4738 }).raw = d3_geo_conicConformal;
4739 function d3_geo_conicEquidistant0, φ1) {
4740 var cosφ0 = Math.cos0), n = φ0 === φ1 ? Math.sin0) : (cosφ0 - Math.cos1)) / 1 - φ0), G = cosφ0 / n + φ0;
4741 if (abs(n) < ε) return d3_geo_equirectangular;
4742 function forward(λ, φ) {
4743 var ρ = G - φ;
4744 return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
4745 }
4746 forward.invert = function(x, y) {
4747 var ρ0_y = G - y;
4748 return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
4749 };
4750 return forward;
4751 }
4752 (d3.geo.conicEquidistant = function() {
4753 return d3_geo_conic(d3_geo_conicEquidistant);
4754 }).raw = d3_geo_conicEquidistant;
4755 var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
4756 return 1 / cosλcosφ;
4757 }, Math.atan);
4758 (d3.geo.gnomonic = function() {
4759 return d3_geo_projection(d3_geo_gnomonic);
4760 }).raw = d3_geo_gnomonic;
4761 function d3_geo_mercator(λ, φ) {
4762 return [ λ, Math.log(Math.tan / 4 + φ / 2)) ];
4763 }
4764 d3_geo_mercator.invert = function(x, y) {
4765 return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
4766 };
4767 function d3_geo_mercatorProjection(project) {
4768 var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
4769 m.scale = function() {
4770 var v = scale.apply(m, arguments);
4771 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4772 };
4773 m.translate = function() {
4774 var v = translate.apply(m, arguments);
4775 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4776 };
4777 m.clipExtent = function(_) {
4778 var v = clipExtent.apply(m, arguments);
4779 if (v === m) {
4780 if (clipAuto = _ == null) {
4781 var k = π * scale(), t = translate();
4782 clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
4783 }
4784 } else if (clipAuto) {
4785 v = null;
4786 }
4787 return v;
4788 };
4789 return m.clipExtent(null);
4790 }
4791 (d3.geo.mercator = function() {
4792 return d3_geo_mercatorProjection(d3_geo_mercator);
4793 }).raw = d3_geo_mercator;
4794 var d3_geo_orthographic = d3_geo_azimuthal(function() {
4795 return 1;
4796 }, Math.asin);
4797 (d3.geo.orthographic = function() {
4798 return d3_geo_projection(d3_geo_orthographic);
4799 }).raw = d3_geo_orthographic;
4800 var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
4801 return 1 / (1 + cosλcosφ);
4802 }, function(ρ) {
4803 return 2 * Math.atan(ρ);
4804 });
4805 (d3.geo.stereographic = function() {
4806 return d3_geo_projection(d3_geo_stereographic);
4807 }).raw = d3_geo_stereographic;
4808 function d3_geo_transverseMercator(λ, φ) {
4809 return [ Math.log(Math.tan / 4 + φ / 2)), ];
4810 }
4811 d3_geo_transverseMercator.invert = function(x, y) {
4812 return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
4813 };
4814 (d3.geo.transverseMercator = function() {
4815 var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
4816 projection.center = function(_) {
4817 return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
4818 };
4819 projection.rotate = function(_) {
4820 return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
4821 [ _[0], _[1], _[2] - 90 ]);
4822 };
4823 return rotate([ 0, 0, 90 ]);
4824 }).raw = d3_geo_transverseMercator;
4825 d3.geom = {};
4826 function d3_geom_pointX(d) {
4827 return d[0];
4828 }
4829 function d3_geom_pointY(d) {
4830 return d[1];
4831 }
4832 d3.geom.hull = function(vertices) {
4833 var x = d3_geom_pointX, y = d3_geom_pointY;
4834 if (arguments.length) return hull(vertices);
4835 function hull(data) {
4836 if (data.length < 3) return [];
4837 var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
4838 for (i = 0; i < n; i++) {
4839 points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
4840 }
4841 points.sort(d3_geom_hullOrder);
4842 for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
4843 var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
4844 var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
4845 for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
4846 for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
4847 return polygon;
4848 }
4849 hull.x = function(_) {
4850 return arguments.length ? (x = _, hull) : x;
4851 };
4852 hull.y = function(_) {
4853 return arguments.length ? (y = _, hull) : y;
4854 };
4855 return hull;
4856 };
4857 function d3_geom_hullUpper(points) {
4858 var n = points.length, hull = [ 0, 1 ], hs = 2;
4859 for (var i = 2; i < n; i++) {
4860 while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
4861 hull[hs++] = i;
4862 }
4863 return hull.slice(0, hs);
4864 }
4865 function d3_geom_hullOrder(a, b) {
4866 return a[0] - b[0] || a[1] - b[1];
4867 }
4868 d3.geom.polygon = function(coordinates) {
4869 d3_subclass(coordinates, d3_geom_polygonPrototype);
4870 return coordinates;
4871 };
4872 var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
4873 d3_geom_polygonPrototype.area = function() {
4874 var i = -1, n = this.length, a, b = this[n - 1], area = 0;
4875 while (++i < n) {
4876 a = b;
4877 b = this[i];
4878 area += a[1] * b[0] - a[0] * b[1];
4879 }
4880 return area * .5;
4881 };
4882 d3_geom_polygonPrototype.centroid = function(k) {
4883 var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
4884 if (!arguments.length) k = -1 / (6 * this.area());
4885 while (++i < n) {
4886 a = b;
4887 b = this[i];
4888 c = a[0] * b[1] - b[0] * a[1];
4889 x += (a[0] + b[0]) * c;
4890 y += (a[1] + b[1]) * c;
4891 }
4892 return [ x * k, y * k ];
4893 };
4894 d3_geom_polygonPrototype.clip = function(subject) {
4895 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;
4896 while (++i < n) {
4897 input = subject.slice();
4898 subject.length = 0;
4899 b = this[i];
4900 c = input[(m = input.length - closed) - 1];
4901 j = -1;
4902 while (++j < m) {
4903 d = input[j];
4904 if (d3_geom_polygonInside(d, a, b)) {
4905 if (!d3_geom_polygonInside(c, a, b)) {
4906 subject.push(d3_geom_polygonIntersect(c, d, a, b));
4907 }
4908 subject.push(d);
4909 } else if (d3_geom_polygonInside(c, a, b)) {
4910 subject.push(d3_geom_polygonIntersect(c, d, a, b));
4911 }
4912 c = d;
4913 }
4914 if (closed) subject.push(subject[0]);
4915 a = b;
4916 }
4917 return subject;
4918 };
4919 function d3_geom_polygonInside(p, a, b) {
4920 return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
4921 }
4922 function d3_geom_polygonIntersect(c, d, a, b) {
4923 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);
4924 return [ x1 + ua * x21, y1 + ua * y21 ];
4925 }
4926 function d3_geom_polygonClosed(coordinates) {
4927 var a = coordinates[0], b = coordinates[coordinates.length - 1];
4928 return !(a[0] - b[0] || a[1] - b[1]);
4929 }
4930 var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
4931 function d3_geom_voronoiBeach() {
4932 d3_geom_voronoiRedBlackNode(this);
4933 this.edge = this.site = this.circle = null;
4934 }
4935 function d3_geom_voronoiCreateBeach(site) {
4936 var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
4937 beach.site = site;
4938 return beach;
4939 }
4940 function d3_geom_voronoiDetachBeach(beach) {
4941 d3_geom_voronoiDetachCircle(beach);
4942 d3_geom_voronoiBeaches.remove(beach);
4943 d3_geom_voronoiBeachPool.push(beach);
4944 d3_geom_voronoiRedBlackNode(beach);
4945 }
4946 function d3_geom_voronoiRemoveBeach(beach) {
4947 var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
4948 x: x,
4949 y: y
4950 }, previous = beach.P, next = beach.N, disappearing = [ beach ];
4951 d3_geom_voronoiDetachBeach(beach);
4952 var lArc = previous;
4953 while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
4954 previous = lArc.P;
4955 disappearing.unshift(lArc);
4956 d3_geom_voronoiDetachBeach(lArc);
4957 lArc = previous;
4958 }
4959 disappearing.unshift(lArc);
4960 d3_geom_voronoiDetachCircle(lArc);
4961 var rArc = next;
4962 while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
4963 next = rArc.N;
4964 disappearing.push(rArc);
4965 d3_geom_voronoiDetachBeach(rArc);
4966 rArc = next;
4967 }
4968 disappearing.push(rArc);
4969 d3_geom_voronoiDetachCircle(rArc);
4970 var nArcs = disappearing.length, iArc;
4971 for (iArc = 1; iArc < nArcs; ++iArc) {
4972 rArc = disappearing[iArc];
4973 lArc = disappearing[iArc - 1];
4974 d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
4975 }
4976 lArc = disappearing[0];
4977 rArc = disappearing[nArcs - 1];
4978 rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
4979 d3_geom_voronoiAttachCircle(lArc);
4980 d3_geom_voronoiAttachCircle(rArc);
4981 }
4982 function d3_geom_voronoiAddBeach(site) {
4983 var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
4984 while (node) {
4985 dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
4986 if (dxl > ε) node = node.L; else {
4987 dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
4988 if (dxr > ε) {
4989 if (!node.R) {
4990 lArc = node;
4991 break;
4992 }
4993 node = node.R;
4994 } else {
4995 if (dxl > -ε) {
4996 lArc = node.P;
4997 rArc = node;
4998 } else if (dxr > -ε) {
4999 lArc = node;
5000 rArc = node.N;
5001 } else {
5002 lArc = rArc = node;
5003 }
5004 break;
5005 }
5006 }
5007 }
5008 var newArc = d3_geom_voronoiCreateBeach(site);
5009 d3_geom_voronoiBeaches.insert(lArc, newArc);
5010 if (!lArc && !rArc) return;
5011 if (lArc === rArc) {
5012 d3_geom_voronoiDetachCircle(lArc);
5013 rArc = d3_geom_voronoiCreateBeach(lArc.site);
5014 d3_geom_voronoiBeaches.insert(newArc, rArc);
5015 newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
5016 d3_geom_voronoiAttachCircle(lArc);
5017 d3_geom_voronoiAttachCircle(rArc);
5018 return;
5019 }
5020 if (!rArc) {
5021 newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
5022 return;
5023 }
5024 d3_geom_voronoiDetachCircle(lArc);
5025 d3_geom_voronoiDetachCircle(rArc);
5026 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 = {
5027 x: (cy * hb - by * hc) / d + ax,
5028 y: (bx * hc - cx * hb) / d + ay
5029 };
5030 d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
5031 newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
5032 rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
5033 d3_geom_voronoiAttachCircle(lArc);
5034 d3_geom_voronoiAttachCircle(rArc);
5035 }
5036 function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
5037 var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
5038 if (!pby2) return rfocx;
5039 var lArc = arc.P;
5040 if (!lArc) return -Infinity;
5041 site = lArc.site;
5042 var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
5043 if (!plby2) return lfocx;
5044 var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
5045 if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
5046 return (rfocx + lfocx) / 2;
5047 }
5048 function d3_geom_voronoiRightBreakPoint(arc, directrix) {
5049 var rArc = arc.N;
5050 if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
5051 var site = arc.site;
5052 return site.y === directrix ? site.x : Infinity;
5053 }
5054 function d3_geom_voronoiCell(site) {
5055 this.site = site;
5056 this.edges = [];
5057 }
5058 d3_geom_voronoiCell.prototype.prepare = function() {
5059 var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
5060 while (iHalfEdge--) {
5061 edge = halfEdges[iHalfEdge].edge;
5062 if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
5063 }
5064 halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
5065 return halfEdges.length;
5066 };
5067 function d3_geom_voronoiCloseCells(extent) {
5068 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;
5069 while (iCell--) {
5070 cell = cells[iCell];
5071 if (!cell || !cell.prepare()) continue;
5072 halfEdges = cell.edges;
5073 nHalfEdges = halfEdges.length;
5074 iHalfEdge = 0;
5075 while (iHalfEdge < nHalfEdges) {
5076 end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
5077 start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
5078 if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
5079 halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
5080 x: x0,
5081 y: abs(x2 - x0) < ε ? y2 : y1
5082 } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
5083 x: abs(y2 - y1) < ε ? x2 : x1,
5084 y: y1
5085 } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
5086 x: x1,
5087 y: abs(x2 - x1) < ε ? y2 : y0
5088 } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
5089 x: abs(y2 - y0) < ε ? x2 : x0,
5090 y: y0
5091 } : null), cell.site, null));
5092 ++nHalfEdges;
5093 }
5094 }
5095 }
5096 }
5097 function d3_geom_voronoiHalfEdgeOrder(a, b) {
5098 return b.angle - a.angle;
5099 }
5100 function d3_geom_voronoiCircle() {
5101 d3_geom_voronoiRedBlackNode(this);
5102 this.x = this.y = this.arc = this.site = this.cy = null;
5103 }
5104 function d3_geom_voronoiAttachCircle(arc) {
5105 var lArc = arc.P, rArc = arc.N;
5106 if (!lArc || !rArc) return;
5107 var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
5108 if (lSite === rSite) return;
5109 var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
5110 var d = 2 * (ax * cy - ay * cx);
5111 if (d >= 2) return;
5112 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;
5113 var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
5114 circle.arc = arc;
5115 circle.site = cSite;
5116 circle.x = x + bx;
5117 circle.y = cy + Math.sqrt(x * x + y * y);
5118 circle.cy = cy;
5119 arc.circle = circle;
5120 var before = null, node = d3_geom_voronoiCircles._;
5121 while (node) {
5122 if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
5123 if (node.L) node = node.L; else {
5124 before = node.P;
5125 break;
5126 }
5127 } else {
5128 if (node.R) node = node.R; else {
5129 before = node;
5130 break;
5131 }
5132 }
5133 }
5134 d3_geom_voronoiCircles.insert(before, circle);
5135 if (!before) d3_geom_voronoiFirstCircle = circle;
5136 }
5137 function d3_geom_voronoiDetachCircle(arc) {
5138 var circle = arc.circle;
5139 if (circle) {
5140 if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
5141 d3_geom_voronoiCircles.remove(circle);
5142 d3_geom_voronoiCirclePool.push(circle);
5143 d3_geom_voronoiRedBlackNode(circle);
5144 arc.circle = null;
5145 }
5146 }
5147 function d3_geom_voronoiClipEdges(extent) {
5148 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;
5149 while (i--) {
5150 e = edges[i];
5151 if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
5152 e.a = e.b = null;
5153 edges.splice(i, 1);
5154 }
5155 }
5156 }
5157 function d3_geom_voronoiConnectEdge(edge, extent) {
5158 var vb = edge.b;
5159 if (vb) return true;
5160 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;
5161 if (ry === ly) {
5162 if (fx < x0 || fx >= x1) return;
5163 if (lx > rx) {
5164 if (!va) va = {
5165 x: fx,
5166 y: y0
5167 }; else if (va.y >= y1) return;
5168 vb = {
5169 x: fx,
5170 y: y1
5171 };
5172 } else {
5173 if (!va) va = {
5174 x: fx,
5175 y: y1
5176 }; else if (va.y < y0) return;
5177 vb = {
5178 x: fx,
5179 y: y0
5180 };
5181 }
5182 } else {
5183 fm = (lx - rx) / (ry - ly);
5184 fb = fy - fm * fx;
5185 if (fm < -1 || fm > 1) {
5186 if (lx > rx) {
5187 if (!va) va = {
5188 x: (y0 - fb) / fm,
5189 y: y0
5190 }; else if (va.y >= y1) return;
5191 vb = {
5192 x: (y1 - fb) / fm,
5193 y: y1
5194 };
5195 } else {
5196 if (!va) va = {
5197 x: (y1 - fb) / fm,
5198 y: y1
5199 }; else if (va.y < y0) return;
5200 vb = {
5201 x: (y0 - fb) / fm,
5202 y: y0
5203 };
5204 }
5205 } else {
5206 if (ly < ry) {
5207 if (!va) va = {
5208 x: x0,
5209 y: fm * x0 + fb
5210 }; else if (va.x >= x1) return;
5211 vb = {
5212 x: x1,
5213 y: fm * x1 + fb
5214 };
5215 } else {
5216 if (!va) va = {
5217 x: x1,
5218 y: fm * x1 + fb
5219 }; else if (va.x < x0) return;
5220 vb = {
5221 x: x0,
5222 y: fm * x0 + fb
5223 };
5224 }
5225 }
5226 }
5227 edge.a = va;
5228 edge.b = vb;
5229 return true;
5230 }
5231 function d3_geom_voronoiEdge(lSite, rSite) {
5232 this.l = lSite;
5233 this.r = rSite;
5234 this.a = this.b = null;
5235 }
5236 function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
5237 var edge = new d3_geom_voronoiEdge(lSite, rSite);
5238 d3_geom_voronoiEdges.push(edge);
5239 if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
5240 if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
5241 d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
5242 d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
5243 return edge;
5244 }
5245 function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
5246 var edge = new d3_geom_voronoiEdge(lSite, null);
5247 edge.a = va;
5248 edge.b = vb;
5249 d3_geom_voronoiEdges.push(edge);
5250 return edge;
5251 }
5252 function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
5253 if (!edge.a && !edge.b) {
5254 edge.a = vertex;
5255 edge.l = lSite;
5256 edge.r = rSite;
5257 } else if (edge.l === rSite) {
5258 edge.b = vertex;
5259 } else {
5260 edge.a = vertex;
5261 }
5262 }
5263 function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
5264 var va = edge.a, vb = edge.b;
5265 this.edge = edge;
5266 this.site = lSite;
5267 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);
5268 }
5269 d3_geom_voronoiHalfEdge.prototype = {
5270 start: function() {
5271 return this.edge.l === this.site ? this.edge.a : this.edge.b;
5272 },
5273 end: function() {
5274 return this.edge.l === this.site ? this.edge.b : this.edge.a;
5275 }
5276 };
5277 function d3_geom_voronoiRedBlackTree() {
5278 this._ = null;
5279 }
5280 function d3_geom_voronoiRedBlackNode(node) {
5281 node.U = node.C = node.L = node.R = node.P = node.N = null;
5282 }
5283 d3_geom_voronoiRedBlackTree.prototype = {
5284 insert: function(after, node) {
5285 var parent, grandpa, uncle;
5286 if (after) {
5287 node.P = after;
5288 node.N = after.N;
5289 if (after.N) after.N.P = node;
5290 after.N = node;
5291 if (after.R) {
5292 after = after.R;
5293 while (after.L) after = after.L;
5294 after.L = node;
5295 } else {
5296 after.R = node;
5297 }
5298 parent = after;
5299 } else if (this._) {
5300 after = d3_geom_voronoiRedBlackFirst(this._);
5301 node.P = null;
5302 node.N = after;
5303 after.P = after.L = node;
5304 parent = after;
5305 } else {
5306 node.P = node.N = null;
5307 this._ = node;
5308 parent = null;
5309 }
5310 node.L = node.R = null;
5311 node.U = parent;
5312 node.C = true;
5313 after = node;
5314 while (parent && parent.C) {
5315 grandpa = parent.U;
5316 if (parent === grandpa.L) {
5317 uncle = grandpa.R;
5318 if (uncle && uncle.C) {
5319 parent.C = uncle.C = false;
5320 grandpa.C = true;
5321 after = grandpa;
5322 } else {
5323 if (after === parent.R) {
5324 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5325 after = parent;
5326 parent = after.U;
5327 }
5328 parent.C = false;
5329 grandpa.C = true;
5330 d3_geom_voronoiRedBlackRotateRight(this, grandpa);
5331 }
5332 } else {
5333 uncle = grandpa.L;
5334 if (uncle && uncle.C) {
5335 parent.C = uncle.C = false;
5336 grandpa.C = true;
5337 after = grandpa;
5338 } else {
5339 if (after === parent.L) {
5340 d3_geom_voronoiRedBlackRotateRight(this, parent);
5341 after = parent;
5342 parent = after.U;
5343 }
5344 parent.C = false;
5345 grandpa.C = true;
5346 d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
5347 }
5348 }
5349 parent = after.U;
5350 }
5351 this._.C = false;
5352 },
5353 remove: function(node) {
5354 if (node.N) node.N.P = node.P;
5355 if (node.P) node.P.N = node.N;
5356 node.N = node.P = null;
5357 var parent = node.U, sibling, left = node.L, right = node.R, next, red;
5358 if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
5359 if (parent) {
5360 if (parent.L === node) parent.L = next; else parent.R = next;
5361 } else {
5362 this._ = next;
5363 }
5364 if (left && right) {
5365 red = next.C;
5366 next.C = node.C;
5367 next.L = left;
5368 left.U = next;
5369 if (next !== right) {
5370 parent = next.U;
5371 next.U = node.U;
5372 node = next.R;
5373 parent.L = node;
5374 next.R = right;
5375 right.U = next;
5376 } else {
5377 next.U = parent;
5378 parent = next;
5379 node = next.R;
5380 }
5381 } else {
5382 red = node.C;
5383 node = next;
5384 }
5385 if (node) node.U = parent;
5386 if (red) return;
5387 if (node && node.C) {
5388 node.C = false;
5389 return;
5390 }
5391 do {
5392 if (node === this._) break;
5393 if (node === parent.L) {
5394 sibling = parent.R;
5395 if (sibling.C) {
5396 sibling.C = false;
5397 parent.C = true;
5398 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5399 sibling = parent.R;
5400 }
5401 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5402 if (!sibling.R || !sibling.R.C) {
5403 sibling.L.C = false;
5404 sibling.C = true;
5405 d3_geom_voronoiRedBlackRotateRight(this, sibling);
5406 sibling = parent.R;
5407 }
5408 sibling.C = parent.C;
5409 parent.C = sibling.R.C = false;
5410 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5411 node = this._;
5412 break;
5413 }
5414 } else {
5415 sibling = parent.L;
5416 if (sibling.C) {
5417 sibling.C = false;
5418 parent.C = true;
5419 d3_geom_voronoiRedBlackRotateRight(this, parent);
5420 sibling = parent.L;
5421 }
5422 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5423 if (!sibling.L || !sibling.L.C) {
5424 sibling.R.C = false;
5425 sibling.C = true;
5426 d3_geom_voronoiRedBlackRotateLeft(this, sibling);
5427 sibling = parent.L;
5428 }
5429 sibling.C = parent.C;
5430 parent.C = sibling.L.C = false;
5431 d3_geom_voronoiRedBlackRotateRight(this, parent);
5432 node = this._;
5433 break;
5434 }
5435 }
5436 sibling.C = true;
5437 node = parent;
5438 parent = parent.U;
5439 } while (!node.C);
5440 if (node) node.C = false;
5441 }
5442 };
5443 function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
5444 var p = node, q = node.R, parent = p.U;
5445 if (parent) {
5446 if (parent.L === p) parent.L = q; else parent.R = q;
5447 } else {
5448 tree._ = q;
5449 }
5450 q.U = parent;
5451 p.U = q;
5452 p.R = q.L;
5453 if (p.R) p.R.U = p;
5454 q.L = p;
5455 }
5456 function d3_geom_voronoiRedBlackRotateRight(tree, node) {
5457 var p = node, q = node.L, parent = p.U;
5458 if (parent) {
5459 if (parent.L === p) parent.L = q; else parent.R = q;
5460 } else {
5461 tree._ = q;
5462 }
5463 q.U = parent;
5464 p.U = q;
5465 p.L = q.R;
5466 if (p.L) p.L.U = p;
5467 q.R = p;
5468 }
5469 function d3_geom_voronoiRedBlackFirst(node) {
5470 while (node.L) node = node.L;
5471 return node;
5472 }
5473 function d3_geom_voronoi(sites, bbox) {
5474 var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
5475 d3_geom_voronoiEdges = [];
5476 d3_geom_voronoiCells = new Array(sites.length);
5477 d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
5478 d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
5479 while (true) {
5480 circle = d3_geom_voronoiFirstCircle;
5481 if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
5482 if (site.x !== x0 || site.y !== y0) {
5483 d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
5484 d3_geom_voronoiAddBeach(site);
5485 x0 = site.x, y0 = site.y;
5486 }
5487 site = sites.pop();
5488 } else if (circle) {
5489 d3_geom_voronoiRemoveBeach(circle.arc);
5490 } else {
5491 break;
5492 }
5493 }
5494 if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
5495 var diagram = {
5496 cells: d3_geom_voronoiCells,
5497 edges: d3_geom_voronoiEdges
5498 };
5499 d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
5500 return diagram;
5501 }
5502 function d3_geom_voronoiVertexOrder(a, b) {
5503 return b.y - a.y || b.x - a.x;
5504 }
5505 d3.geom.voronoi = function(points) {
5506 var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
5507 if (points) return voronoi(points);
5508 function voronoi(data) {
5509 var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
5510 d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
5511 var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
5512 var s = e.start();
5513 return [ s.x, s.y ];
5514 }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
5515 polygon.point = data[i];
5516 });
5517 return polygons;
5518 }
5519 function sites(data) {
5520 return data.map(function(d, i) {
5521 return {
5522 x: Math.round(fx(d, i) / ε) * ε,
5523 y: Math.round(fy(d, i) / ε) * ε,
5524 i: i
5525 };
5526 });
5527 }
5528 voronoi.links = function(data) {
5529 return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
5530 return edge.l && edge.r;
5531 }).map(function(edge) {
5532 return {
5533 source: data[edge.l.i],
5534 target: data[edge.r.i]
5535 };
5536 });
5537 };
5538 voronoi.triangles = function(data) {
5539 var triangles = [];
5540 d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
5541 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;
5542 while (++j < m) {
5543 e0 = e1;
5544 s0 = s1;
5545 e1 = edges[j].edge;
5546 s1 = e1.l === site ? e1.r : e1.l;
5547 if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
5548 triangles.push([ data[i], data[s0.i], data[s1.i] ]);
5549 }
5550 }
5551 });
5552 return triangles;
5553 };
5554 voronoi.x = function(_) {
5555 return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
5556 };
5557 voronoi.y = function(_) {
5558 return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
5559 };
5560 voronoi.clipExtent = function(_) {
5561 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
5562 clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
5563 return voronoi;
5564 };
5565 voronoi.size = function(_) {
5566 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
5567 return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
5568 };
5569 return voronoi;
5570 };
5571 var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
5572 function d3_geom_voronoiTriangleArea(a, b, c) {
5573 return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
5574 }
5575 d3.geom.delaunay = function(vertices) {
5576 return d3.geom.voronoi().triangles(vertices);
5577 };
5578 d3.geom.quadtree = function(points, x1, y1, x2, y2) {
5579 var x = d3_geom_pointX, y = d3_geom_pointY, compat;
5580 if (compat = arguments.length) {
5581 x = d3_geom_quadtreeCompatX;
5582 y = d3_geom_quadtreeCompatY;
5583 if (compat === 3) {
5584 y2 = y1;
5585 x2 = x1;
5586 y1 = x1 = 0;
5587 }
5588 return quadtree(points);
5589 }
5590 function quadtree(data) {
5591 var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
5592 if (x1 != null) {
5593 x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
5594 } else {
5595 x2_ = y2_ = -(x1_ = y1_ = Infinity);
5596 xs = [], ys = [];
5597 n = data.length;
5598 if (compat) for (i = 0; i < n; ++i) {
5599 d = data[i];
5600 if (d.x < x1_) x1_ = d.x;
5601 if (d.y < y1_) y1_ = d.y;
5602 if (d.x > x2_) x2_ = d.x;
5603 if (d.y > y2_) y2_ = d.y;
5604 xs.push(d.x);
5605 ys.push(d.y);
5606 } else for (i = 0; i < n; ++i) {
5607 var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
5608 if (x_ < x1_) x1_ = x_;
5609 if (y_ < y1_) y1_ = y_;
5610 if (x_ > x2_) x2_ = x_;
5611 if (y_ > y2_) y2_ = y_;
5612 xs.push(x_);
5613 ys.push(y_);
5614 }
5615 }
5616 var dx = x2_ - x1_, dy = y2_ - y1_;
5617 if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
5618 function insert(n, d, x, y, x1, y1, x2, y2) {
5619 if (isNaN(x) || isNaN(y)) return;
5620 if (n.leaf) {
5621 var nx = n.x, ny = n.y;
5622 if (nx != null) {
5623 if (abs(nx - x) + abs(ny - y) < .01) {
5624 insertChild(n, d, x, y, x1, y1, x2, y2);
5625 } else {
5626 var nPoint = n.point;
5627 n.x = n.y = n.point = null;
5628 insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
5629 insertChild(n, d, x, y, x1, y1, x2, y2);
5630 }
5631 } else {
5632 n.x = x, n.y = y, n.point = d;
5633 }
5634 } else {
5635 insertChild(n, d, x, y, x1, y1, x2, y2);
5636 }
5637 }
5638 function insertChild(n, d, x, y, x1, y1, x2, y2) {
5639 var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
5640 n.leaf = false;
5641 n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
5642 if (right) x1 = xm; else x2 = xm;
5643 if (below) y1 = ym; else y2 = ym;
5644 insert(n, d, x, y, x1, y1, x2, y2);
5645 }
5646 var root = d3_geom_quadtreeNode();
5647 root.add = function(d) {
5648 insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
5649 };
5650 root.visit = function(f) {
5651 d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
5652 };
5653 root.find = function(point) {
5654 return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
5655 };
5656 i = -1;
5657 if (x1 == null) {
5658 while (++i < n) {
5659 insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
5660 }
5661 --i;
5662 } else data.forEach(root.add);
5663 xs = ys = data = d = null;
5664 return root;
5665 }
5666 quadtree.x = function(_) {
5667 return arguments.length ? (x = _, quadtree) : x;
5668 };
5669 quadtree.y = function(_) {
5670 return arguments.length ? (y = _, quadtree) : y;
5671 };
5672 quadtree.extent = function(_) {
5673 if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
5674 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
5675 y2 = +_[1][1];
5676 return quadtree;
5677 };
5678 quadtree.size = function(_) {
5679 if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
5680 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
5681 return quadtree;
5682 };
5683 return quadtree;
5684 };
5685 function d3_geom_quadtreeCompatX(d) {
5686 return d.x;
5687 }
5688 function d3_geom_quadtreeCompatY(d) {
5689 return d.y;
5690 }
5691 function d3_geom_quadtreeNode() {
5692 return {
5693 leaf: true,
5694 nodes: [],
5695 point: null,
5696 x: null,
5697 y: null
5698 };
5699 }
5700 function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
5701 if (!f(node, x1, y1, x2, y2)) {
5702 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
5703 if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
5704 if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
5705 if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
5706 if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
5707 }
5708 }
5709 function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
5710 var minDistance2 = Infinity, closestPoint;
5711 (function find(node, x1, y1, x2, y2) {
5712 if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
5713 if (point = node.point) {
5714 var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
5715 if (distance2 < minDistance2) {
5716 var distance = Math.sqrt(minDistance2 = distance2);
5717 x0 = x - distance, y0 = y - distance;
5718 x3 = x + distance, y3 = y + distance;
5719 closestPoint = point;
5720 }
5721 }
5722 var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
5723 for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
5724 if (node = children[i & 3]) switch (i & 3) {
5725 case 0:
5726 find(node, x1, y1, xm, ym);
5727 break;
5728
5729 case 1:
5730 find(node, xm, y1, x2, ym);
5731 break;
5732
5733 case 2:
5734 find(node, x1, ym, xm, y2);
5735 break;
5736
5737 case 3:
5738 find(node, xm, ym, x2, y2);
5739 break;
5740 }
5741 }
5742 })(root, x0, y0, x3, y3);
5743 return closestPoint;
5744 }
5745 d3.interpolateRgb = d3_interpolateRgb;
5746 function d3_interpolateRgb(a, b) {
5747 a = d3.rgb(a);
5748 b = d3.rgb(b);
5749 var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
5750 return function(t) {
5751 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));
5752 };
5753 }
5754 d3.interpolateObject = d3_interpolateObject;
5755 function d3_interpolateObject(a, b) {
5756 var i = {}, c = {}, k;
5757 for (k in a) {
5758 if (k in b) {
5759 i[k] = d3_interpolate(a[k], b[k]);
5760 } else {
5761 c[k] = a[k];
5762 }
5763 }
5764 for (k in b) {
5765 if (!(k in a)) {
5766 c[k] = b[k];
5767 }
5768 }
5769 return function(t) {
5770 for (k in i) c[k] = i[k](t);
5771 return c;
5772 };
5773 }
5774 d3.interpolateNumber = d3_interpolateNumber;
5775 function d3_interpolateNumber(a, b) {
5776 a = +a, b = +b;
5777 return function(t) {
5778 return a * (1 - t) + b * t;
5779 };
5780 }
5781 d3.interpolateString = d3_interpolateString;
5782 function d3_interpolateString(a, b) {
5783 var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
5784 a = a + "", b = b + "";
5785 while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
5786 if ((bs = bm.index) > bi) {
5787 bs = b.slice(bi, bs);
5788 if (s[i]) s[i] += bs; else s[++i] = bs;
5789 }
5790 if ((am = am[0]) === (bm = bm[0])) {
5791 if (s[i]) s[i] += bm; else s[++i] = bm;
5792 } else {
5793 s[++i] = null;
5794 q.push({
5795 i: i,
5796 x: d3_interpolateNumber(am, bm)
5797 });
5798 }
5799 bi = d3_interpolate_numberB.lastIndex;
5800 }
5801 if (bi < b.length) {
5802 bs = b.slice(bi);
5803 if (s[i]) s[i] += bs; else s[++i] = bs;
5804 }
5805 return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
5806 return b(t) + "";
5807 }) : function() {
5808 return b;
5809 } : (b = q.length, function(t) {
5810 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
5811 return s.join("");
5812 });
5813 }
5814 var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
5815 d3.interpolate = d3_interpolate;
5816 function d3_interpolate(a, b) {
5817 var i = d3.interpolators.length, f;
5818 while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
5819 return f;
5820 }
5821 d3.interpolators = [ function(a, b) {
5822 var t = typeof b;
5823 return (t === "string" ? d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\(|hsl\()/i.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b);
5824 } ];
5825 d3.interpolateArray = d3_interpolateArray;
5826 function d3_interpolateArray(a, b) {
5827 var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
5828 for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
5829 for (;i < na; ++i) c[i] = a[i];
5830 for (;i < nb; ++i) c[i] = b[i];
5831 return function(t) {
5832 for (i = 0; i < n0; ++i) c[i] = x[i](t);
5833 return c;
5834 };
5835 }
5836 var d3_ease_default = function() {
5837 return d3_identity;
5838 };
5839 var d3_ease = d3.map({
5840 linear: d3_ease_default,
5841 poly: d3_ease_poly,
5842 quad: function() {
5843 return d3_ease_quad;
5844 },
5845 cubic: function() {
5846 return d3_ease_cubic;
5847 },
5848 sin: function() {
5849 return d3_ease_sin;
5850 },
5851 exp: function() {
5852 return d3_ease_exp;
5853 },
5854 circle: function() {
5855 return d3_ease_circle;
5856 },
5857 elastic: d3_ease_elastic,
5858 back: d3_ease_back,
5859 bounce: function() {
5860 return d3_ease_bounce;
5861 }
5862 });
5863 var d3_ease_mode = d3.map({
5864 "in": d3_identity,
5865 out: d3_ease_reverse,
5866 "in-out": d3_ease_reflect,
5867 "out-in": function(f) {
5868 return d3_ease_reflect(d3_ease_reverse(f));
5869 }
5870 });
5871 d3.ease = function(name) {
5872 var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
5873 t = d3_ease.get(t) || d3_ease_default;
5874 m = d3_ease_mode.get(m) || d3_identity;
5875 return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
5876 };
5877 function d3_ease_clamp(f) {
5878 return function(t) {
5879 return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
5880 };
5881 }
5882 function d3_ease_reverse(f) {
5883 return function(t) {
5884 return 1 - f(1 - t);
5885 };
5886 }
5887 function d3_ease_reflect(f) {
5888 return function(t) {
5889 return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
5890 };
5891 }
5892 function d3_ease_quad(t) {
5893 return t * t;
5894 }
5895 function d3_ease_cubic(t) {
5896 return t * t * t;
5897 }
5898 function d3_ease_cubicInOut(t) {
5899 if (t <= 0) return 0;
5900 if (t >= 1) return 1;
5901 var t2 = t * t, t3 = t2 * t;
5902 return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
5903 }
5904 function d3_ease_poly(e) {
5905 return function(t) {
5906 return Math.pow(t, e);
5907 };
5908 }
5909 function d3_ease_sin(t) {
5910 return 1 - Math.cos(t * halfπ);
5911 }
5912 function d3_ease_exp(t) {
5913 return Math.pow(2, 10 * (t - 1));
5914 }
5915 function d3_ease_circle(t) {
5916 return 1 - Math.sqrt(1 - t * t);
5917 }
5918 function d3_ease_elastic(a, p) {
5919 var s;
5920 if (arguments.length < 2) p = .45;
5921 if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
5922 return function(t) {
5923 return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
5924 };
5925 }
5926 function d3_ease_back(s) {
5927 if (!s) s = 1.70158;
5928 return function(t) {
5929 return t * t * ((s + 1) * t - s);
5930 };
5931 }
5932 function d3_ease_bounce(t) {
5933 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;
5934 }
5935 d3.interpolateHcl = d3_interpolateHcl;
5936 function d3_interpolateHcl(a, b) {
5937 a = d3.hcl(a);
5938 b = d3.hcl(b);
5939 var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
5940 if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
5941 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
5942 return function(t) {
5943 return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
5944 };
5945 }
5946 d3.interpolateHsl = d3_interpolateHsl;
5947 function d3_interpolateHsl(a, b) {
5948 a = d3.hsl(a);
5949 b = d3.hsl(b);
5950 var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
5951 if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
5952 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
5953 return function(t) {
5954 return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
5955 };
5956 }
5957 d3.interpolateLab = d3_interpolateLab;
5958 function d3_interpolateLab(a, b) {
5959 a = d3.lab(a);
5960 b = d3.lab(b);
5961 var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
5962 return function(t) {
5963 return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
5964 };
5965 }
5966 d3.interpolateRound = d3_interpolateRound;
5967 function d3_interpolateRound(a, b) {
5968 b -= a;
5969 return function(t) {
5970 return Math.round(a + b * t);
5971 };
5972 }
5973 d3.transform = function(string) {
5974 var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
5975 return (d3.transform = function(string) {
5976 if (string != null) {
5977 g.setAttribute("transform", string);
5978 var t = g.transform.baseVal.consolidate();
5979 }
5980 return new d3_transform(t ? t.matrix : d3_transformIdentity);
5981 })(string);
5982 };
5983 function d3_transform(m) {
5984 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;
5985 if (r0[0] * r1[1] < r1[0] * r0[1]) {
5986 r0[0] *= -1;
5987 r0[1] *= -1;
5988 kx *= -1;
5989 kz *= -1;
5990 }
5991 this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
5992 this.translate = [ m.e, m.f ];
5993 this.scale = [ kx, ky ];
5994 this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
5995 }
5996 d3_transform.prototype.toString = function() {
5997 return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
5998 };
5999 function d3_transformDot(a, b) {
6000 return a[0] * b[0] + a[1] * b[1];
6001 }
6002 function d3_transformNormalize(a) {
6003 var k = Math.sqrt(d3_transformDot(a, a));
6004 if (k) {
6005 a[0] /= k;
6006 a[1] /= k;
6007 }
6008 return k;
6009 }
6010 function d3_transformCombine(a, b, k) {
6011 a[0] += k * b[0];
6012 a[1] += k * b[1];
6013 return a;
6014 }
6015 var d3_transformIdentity = {
6016 a: 1,
6017 b: 0,
6018 c: 0,
6019 d: 1,
6020 e: 0,
6021 f: 0
6022 };
6023 d3.interpolateTransform = d3_interpolateTransform;
6024 function d3_interpolateTransformPop(s) {
6025 return s.length ? s.pop() + "," : "";
6026 }
6027 function d3_interpolateTranslate(ta, tb, s, q) {
6028 if (ta[0] !== tb[0] || ta[1] !== tb[1]) {
6029 var i = s.push("translate(", null, ",", null, ")");
6030 q.push({
6031 i: i - 4,
6032 x: d3_interpolateNumber(ta[0], tb[0])
6033 }, {
6034 i: i - 2,
6035 x: d3_interpolateNumber(ta[1], tb[1])
6036 });
6037 } else if (tb[0] || tb[1]) {
6038 s.push("translate(" + tb + ")");
6039 }
6040 }
6041 function d3_interpolateRotate(ra, rb, s, q) {
6042 if (ra !== rb) {
6043 if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
6044 q.push({
6045 i: s.push(d3_interpolateTransformPop(s) + "rotate(", null, ")") - 2,
6046 x: d3_interpolateNumber(ra, rb)
6047 });
6048 } else if (rb) {
6049 s.push(d3_interpolateTransformPop(s) + "rotate(" + rb + ")");
6050 }
6051 }
6052 function d3_interpolateSkew(wa, wb, s, q) {
6053 if (wa !== wb) {
6054 q.push({
6055 i: s.push(d3_interpolateTransformPop(s) + "skewX(", null, ")") - 2,
6056 x: d3_interpolateNumber(wa, wb)
6057 });
6058 } else if (wb) {
6059 s.push(d3_interpolateTransformPop(s) + "skewX(" + wb + ")");
6060 }
6061 }
6062 function d3_interpolateScale(ka, kb, s, q) {
6063 if (ka[0] !== kb[0] || ka[1] !== kb[1]) {
6064 var i = s.push(d3_interpolateTransformPop(s) + "scale(", null, ",", null, ")");
6065 q.push({
6066 i: i - 4,
6067 x: d3_interpolateNumber(ka[0], kb[0])
6068 }, {
6069 i: i - 2,
6070 x: d3_interpolateNumber(ka[1], kb[1])
6071 });
6072 } else if (kb[0] !== 1 || kb[1] !== 1) {
6073 s.push(d3_interpolateTransformPop(s) + "scale(" + kb + ")");
6074 }
6075 }
6076 function d3_interpolateTransform(a, b) {
6077 var s = [], q = [];
6078 a = d3.transform(a), b = d3.transform(b);
6079 d3_interpolateTranslate(a.translate, b.translate, s, q);
6080 d3_interpolateRotate(a.rotate, b.rotate, s, q);
6081 d3_interpolateSkew(a.skew, b.skew, s, q);
6082 d3_interpolateScale(a.scale, b.scale, s, q);
6083 a = b = null;
6084 return function(t) {
6085 var i = -1, n = q.length, o;
6086 while (++i < n) s[(o = q[i]).i] = o.x(t);
6087 return s.join("");
6088 };
6089 }
6090 function d3_uninterpolateNumber(a, b) {
6091 b = (b -= a = +a) || 1 / b;
6092 return function(x) {
6093 return (x - a) / b;
6094 };
6095 }
6096 function d3_uninterpolateClamp(a, b) {
6097 b = (b -= a = +a) || 1 / b;
6098 return function(x) {
6099 return Math.max(0, Math.min(1, (x - a) / b));
6100 };
6101 }
6102 d3.layout = {};
6103 d3.layout.bundle = function() {
6104 return function(links) {
6105 var paths = [], i = -1, n = links.length;
6106 while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
6107 return paths;
6108 };
6109 };
6110 function d3_layout_bundlePath(link) {
6111 var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
6112 while (start !== lca) {
6113 start = start.parent;
6114 points.push(start);
6115 }
6116 var k = points.length;
6117 while (end !== lca) {
6118 points.splice(k, 0, end);
6119 end = end.parent;
6120 }
6121 return points;
6122 }
6123 function d3_layout_bundleAncestors(node) {
6124 var ancestors = [], parent = node.parent;
6125 while (parent != null) {
6126 ancestors.push(node);
6127 node = parent;
6128 parent = parent.parent;
6129 }
6130 ancestors.push(node);
6131 return ancestors;
6132 }
6133 function d3_layout_bundleLeastCommonAncestor(a, b) {
6134 if (a === b) return a;
6135 var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
6136 while (aNode === bNode) {
6137 sharedNode = aNode;
6138 aNode = aNodes.pop();
6139 bNode = bNodes.pop();
6140 }
6141 return sharedNode;
6142 }
6143 d3.layout.chord = function() {
6144 var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
6145 function relayout() {
6146 var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
6147 chords = [];
6148 groups = [];
6149 k = 0, i = -1;
6150 while (++i < n) {
6151 x = 0, j = -1;
6152 while (++j < n) {
6153 x += matrix[i][j];
6154 }
6155 groupSums.push(x);
6156 subgroupIndex.push(d3.range(n));
6157 k += x;
6158 }
6159 if (sortGroups) {
6160 groupIndex.sort(function(a, b) {
6161 return sortGroups(groupSums[a], groupSums[b]);
6162 });
6163 }
6164 if (sortSubgroups) {
6165 subgroupIndex.forEach(function(d, i) {
6166 d.sort(function(a, b) {
6167 return sortSubgroups(matrix[i][a], matrix[i][b]);
6168 });
6169 });
6170 }
6171 k = - padding * n) / k;
6172 x = 0, i = -1;
6173 while (++i < n) {
6174 x0 = x, j = -1;
6175 while (++j < n) {
6176 var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
6177 subgroups[di + "-" + dj] = {
6178 index: di,
6179 subindex: dj,
6180 startAngle: a0,
6181 endAngle: a1,
6182 value: v
6183 };
6184 }
6185 groups[di] = {
6186 index: di,
6187 startAngle: x0,
6188 endAngle: x,
6189 value: groupSums[di]
6190 };
6191 x += padding;
6192 }
6193 i = -1;
6194 while (++i < n) {
6195 j = i - 1;
6196 while (++j < n) {
6197 var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
6198 if (source.value || target.value) {
6199 chords.push(source.value < target.value ? {
6200 source: target,
6201 target: source
6202 } : {
6203 source: source,
6204 target: target
6205 });
6206 }
6207 }
6208 }
6209 if (sortChords) resort();
6210 }
6211 function resort() {
6212 chords.sort(function(a, b) {
6213 return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
6214 });
6215 }
6216 chord.matrix = function(x) {
6217 if (!arguments.length) return matrix;
6218 n = (matrix = x) && matrix.length;
6219 chords = groups = null;
6220 return chord;
6221 };
6222 chord.padding = function(x) {
6223 if (!arguments.length) return padding;
6224 padding = x;
6225 chords = groups = null;
6226 return chord;
6227 };
6228 chord.sortGroups = function(x) {
6229 if (!arguments.length) return sortGroups;
6230 sortGroups = x;
6231 chords = groups = null;
6232 return chord;
6233 };
6234 chord.sortSubgroups = function(x) {
6235 if (!arguments.length) return sortSubgroups;
6236 sortSubgroups = x;
6237 chords = null;
6238 return chord;
6239 };
6240 chord.sortChords = function(x) {
6241 if (!arguments.length) return sortChords;
6242 sortChords = x;
6243 if (chords) resort();
6244 return chord;
6245 };
6246 chord.chords = function() {
6247 if (!chords) relayout();
6248 return chords;
6249 };
6250 chord.groups = function() {
6251 if (!groups) relayout();
6252 return groups;
6253 };
6254 return chord;
6255 };
6256 d3.layout.force = function() {
6257 var force = {}, event = d3.dispatch("start", "tick", "end"), timer, 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;
6258 function repulse(node) {
6259 return function(quad, x1, _, x2) {
6260 if (quad.point !== node) {
6261 var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
6262 if (dw * dw / theta2 < dn) {
6263 if (dn < chargeDistance2) {
6264 var k = quad.charge / dn;
6265 node.px -= dx * k;
6266 node.py -= dy * k;
6267 }
6268 return true;
6269 }
6270 if (quad.point && dn && dn < chargeDistance2) {
6271 var k = quad.pointCharge / dn;
6272 node.px -= dx * k;
6273 node.py -= dy * k;
6274 }
6275 }
6276 return !quad.charge;
6277 };
6278 }
6279 force.tick = function() {
6280 if ((alpha *= .99) < .005) {
6281 timer = null;
6282 event.end({
6283 type: "end",
6284 alpha: alpha = 0
6285 });
6286 return true;
6287 }
6288 var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
6289 for (i = 0; i < m; ++i) {
6290 o = links[i];
6291 s = o.source;
6292 t = o.target;
6293 x = t.x - s.x;
6294 y = t.y - s.y;
6295 if (l = x * x + y * y) {
6296 l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
6297 x *= l;
6298 y *= l;
6299 t.x -= x * (k = s.weight + t.weight ? s.weight / (s.weight + t.weight) : .5);
6300 t.y -= y * k;
6301 s.x += x * (k = 1 - k);
6302 s.y += y * k;
6303 }
6304 }
6305 if (k = alpha * gravity) {
6306 x = size[0] / 2;
6307 y = size[1] / 2;
6308 i = -1;
6309 if (k) while (++i < n) {
6310 o = nodes[i];
6311 o.x += (x - o.x) * k;
6312 o.y += (y - o.y) * k;
6313 }
6314 }
6315 if (charge) {
6316 d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
6317 i = -1;
6318 while (++i < n) {
6319 if (!(o = nodes[i]).fixed) {
6320 q.visit(repulse(o));
6321 }
6322 }
6323 }
6324 i = -1;
6325 while (++i < n) {
6326 o = nodes[i];
6327 if (o.fixed) {
6328 o.x = o.px;
6329 o.y = o.py;
6330 } else {
6331 o.x -= (o.px - (o.px = o.x)) * friction;
6332 o.y -= (o.py - (o.py = o.y)) * friction;
6333 }
6334 }
6335 event.tick({
6336 type: "tick",
6337 alpha: alpha
6338 });
6339 };
6340 force.nodes = function(x) {
6341 if (!arguments.length) return nodes;
6342 nodes = x;
6343 return force;
6344 };
6345 force.links = function(x) {
6346 if (!arguments.length) return links;
6347 links = x;
6348 return force;
6349 };
6350 force.size = function(x) {
6351 if (!arguments.length) return size;
6352 size = x;
6353 return force;
6354 };
6355 force.linkDistance = function(x) {
6356 if (!arguments.length) return linkDistance;
6357 linkDistance = typeof x === "function" ? x : +x;
6358 return force;
6359 };
6360 force.distance = force.linkDistance;
6361 force.linkStrength = function(x) {
6362 if (!arguments.length) return linkStrength;
6363 linkStrength = typeof x === "function" ? x : +x;
6364 return force;
6365 };
6366 force.friction = function(x) {
6367 if (!arguments.length) return friction;
6368 friction = +x;
6369 return force;
6370 };
6371 force.charge = function(x) {
6372 if (!arguments.length) return charge;
6373 charge = typeof x === "function" ? x : +x;
6374 return force;
6375 };
6376 force.chargeDistance = function(x) {
6377 if (!arguments.length) return Math.sqrt(chargeDistance2);
6378 chargeDistance2 = x * x;
6379 return force;
6380 };
6381 force.gravity = function(x) {
6382 if (!arguments.length) return gravity;
6383 gravity = +x;
6384 return force;
6385 };
6386 force.theta = function(x) {
6387 if (!arguments.length) return Math.sqrt(theta2);
6388 theta2 = x * x;
6389 return force;
6390 };
6391 force.alpha = function(x) {
6392 if (!arguments.length) return alpha;
6393 x = +x;
6394 if (alpha) {
6395 if (x > 0) {
6396 alpha = x;
6397 } else {
6398 timer.c = null, timer.t = NaN, timer = null;
6399 event.end({
6400 type: "end",
6401 alpha: alpha = 0
6402 });
6403 }
6404 } else if (x > 0) {
6405 event.start({
6406 type: "start",
6407 alpha: alpha = x
6408 });
6409 timer = d3_timer(force.tick);
6410 }
6411 return force;
6412 };
6413 force.start = function() {
6414 var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
6415 for (i = 0; i < n; ++i) {
6416 (o = nodes[i]).index = i;
6417 o.weight = 0;
6418 }
6419 for (i = 0; i < m; ++i) {
6420 o = links[i];
6421 if (typeof o.source == "number") o.source = nodes[o.source];
6422 if (typeof o.target == "number") o.target = nodes[o.target];
6423 ++o.source.weight;
6424 ++o.target.weight;
6425 }
6426 for (i = 0; i < n; ++i) {
6427 o = nodes[i];
6428 if (isNaN(o.x)) o.x = position("x", w);
6429 if (isNaN(o.y)) o.y = position("y", h);
6430 if (isNaN(o.px)) o.px = o.x;
6431 if (isNaN(o.py)) o.py = o.y;
6432 }
6433 distances = [];
6434 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;
6435 strengths = [];
6436 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;
6437 charges = [];
6438 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;
6439 function position(dimension, size) {
6440 if (!neighbors) {
6441 neighbors = new Array(n);
6442 for (j = 0; j < n; ++j) {
6443 neighbors[j] = [];
6444 }
6445 for (j = 0; j < m; ++j) {
6446 var o = links[j];
6447 neighbors[o.source.index].push(o.target);
6448 neighbors[o.target.index].push(o.source);
6449 }
6450 }
6451 var candidates = neighbors[i], j = -1, l = candidates.length, x;
6452 while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
6453 return Math.random() * size;
6454 }
6455 return force.resume();
6456 };
6457 force.resume = function() {
6458 return force.alpha(.1);
6459 };
6460 force.stop = function() {
6461 return force.alpha(0);
6462 };
6463 force.drag = function() {
6464 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);
6465 if (!arguments.length) return drag;
6466 this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
6467 };
6468 function dragmove(d) {
6469 d.px = d3.event.x, d.py = d3.event.y;
6470 force.resume();
6471 }
6472 return d3.rebind(force, event, "on");
6473 };
6474 function d3_layout_forceDragstart(d) {
6475 d.fixed |= 2;
6476 }
6477 function d3_layout_forceDragend(d) {
6478 d.fixed &= ~6;
6479 }
6480 function d3_layout_forceMouseover(d) {
6481 d.fixed |= 4;
6482 d.px = d.x, d.py = d.y;
6483 }
6484 function d3_layout_forceMouseout(d) {
6485 d.fixed &= ~4;
6486 }
6487 function d3_layout_forceAccumulate(quad, alpha, charges) {
6488 var cx = 0, cy = 0;
6489 quad.charge = 0;
6490 if (!quad.leaf) {
6491 var nodes = quad.nodes, n = nodes.length, i = -1, c;
6492 while (++i < n) {
6493 c = nodes[i];
6494 if (c == null) continue;
6495 d3_layout_forceAccumulate(c, alpha, charges);
6496 quad.charge += c.charge;
6497 cx += c.charge * c.cx;
6498 cy += c.charge * c.cy;
6499 }
6500 }
6501 if (quad.point) {
6502 if (!quad.leaf) {
6503 quad.point.x += Math.random() - .5;
6504 quad.point.y += Math.random() - .5;
6505 }
6506 var k = alpha * charges[quad.point.index];
6507 quad.charge += quad.pointCharge = k;
6508 cx += k * quad.point.x;
6509 cy += k * quad.point.y;
6510 }
6511 quad.cx = cx / quad.charge;
6512 quad.cy = cy / quad.charge;
6513 }
6514 var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
6515 d3.layout.hierarchy = function() {
6516 var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
6517 function hierarchy(root) {
6518 var stack = [ root ], nodes = [], node;
6519 root.depth = 0;
6520 while ((node = stack.pop()) != null) {
6521 nodes.push(node);
6522 if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
6523 var n, childs, child;
6524 while (--n >= 0) {
6525 stack.push(child = childs[n]);
6526 child.parent = node;
6527 child.depth = node.depth + 1;
6528 }
6529 if (value) node.value = 0;
6530 node.children = childs;
6531 } else {
6532 if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
6533 delete node.children;
6534 }
6535 }
6536 d3_layout_hierarchyVisitAfter(root, function(node) {
6537 var childs, parent;
6538 if (sort && (childs = node.children)) childs.sort(sort);
6539 if (value && (parent = node.parent)) parent.value += node.value;
6540 });
6541 return nodes;
6542 }
6543 hierarchy.sort = function(x) {
6544 if (!arguments.length) return sort;
6545 sort = x;
6546 return hierarchy;
6547 };
6548 hierarchy.children = function(x) {
6549 if (!arguments.length) return children;
6550 children = x;
6551 return hierarchy;
6552 };
6553 hierarchy.value = function(x) {
6554 if (!arguments.length) return value;
6555 value = x;
6556 return hierarchy;
6557 };
6558 hierarchy.revalue = function(root) {
6559 if (value) {
6560 d3_layout_hierarchyVisitBefore(root, function(node) {
6561 if (node.children) node.value = 0;
6562 });
6563 d3_layout_hierarchyVisitAfter(root, function(node) {
6564 var parent;
6565 if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
6566 if (parent = node.parent) parent.value += node.value;
6567 });
6568 }
6569 return root;
6570 };
6571 return hierarchy;
6572 };
6573 function d3_layout_hierarchyRebind(object, hierarchy) {
6574 d3.rebind(object, hierarchy, "sort", "children", "value");
6575 object.nodes = object;
6576 object.links = d3_layout_hierarchyLinks;
6577 return object;
6578 }
6579 function d3_layout_hierarchyVisitBefore(node, callback) {
6580 var nodes = [ node ];
6581 while ((node = nodes.pop()) != null) {
6582 callback(node);
6583 if ((children = node.children) && (n = children.length)) {
6584 var n, children;
6585 while (--n >= 0) nodes.push(children[n]);
6586 }
6587 }
6588 }
6589 function d3_layout_hierarchyVisitAfter(node, callback) {
6590 var nodes = [ node ], nodes2 = [];
6591 while ((node = nodes.pop()) != null) {
6592 nodes2.push(node);
6593 if ((children = node.children) && (n = children.length)) {
6594 var i = -1, n, children;
6595 while (++i < n) nodes.push(children[i]);
6596 }
6597 }
6598 while ((node = nodes2.pop()) != null) {
6599 callback(node);
6600 }
6601 }
6602 function d3_layout_hierarchyChildren(d) {
6603 return d.children;
6604 }
6605 function d3_layout_hierarchyValue(d) {
6606 return d.value;
6607 }
6608 function d3_layout_hierarchySort(a, b) {
6609 return b.value - a.value;
6610 }
6611 function d3_layout_hierarchyLinks(nodes) {
6612 return d3.merge(nodes.map(function(parent) {
6613 return (parent.children || []).map(function(child) {
6614 return {
6615 source: parent,
6616 target: child
6617 };
6618 });
6619 }));
6620 }
6621 d3.layout.partition = function() {
6622 var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
6623 function position(node, x, dx, dy) {
6624 var children = node.children;
6625 node.x = x;
6626 node.y = node.depth * dy;
6627 node.dx = dx;
6628 node.dy = dy;
6629 if (children && (n = children.length)) {
6630 var i = -1, n, c, d;
6631 dx = node.value ? dx / node.value : 0;
6632 while (++i < n) {
6633 position(c = children[i], x, d = c.value * dx, dy);
6634 x += d;
6635 }
6636 }
6637 }
6638 function depth(node) {
6639 var children = node.children, d = 0;
6640 if (children && (n = children.length)) {
6641 var i = -1, n;
6642 while (++i < n) d = Math.max(d, depth(children[i]));
6643 }
6644 return 1 + d;
6645 }
6646 function partition(d, i) {
6647 var nodes = hierarchy.call(this, d, i);
6648 position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
6649 return nodes;
6650 }
6651 partition.size = function(x) {
6652 if (!arguments.length) return size;
6653 size = x;
6654 return partition;
6655 };
6656 return d3_layout_hierarchyRebind(partition, hierarchy);
6657 };
6658 d3.layout.pie = function() {
6659 var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
6660 function pie(data) {
6661 var n = data.length, values = data.map(function(d, i) {
6662 return +value.call(pie, d, i);
6663 }), 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), sum = d3.sum(values), k = sum ? (da - n * pa) / sum : 0, index = d3.range(n), arcs = [], v;
6664 if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
6665 return values[j] - values[i];
6666 } : function(i, j) {
6667 return sort(data[i], data[j]);
6668 });
6669 index.forEach(function(i) {
6670 arcs[i] = {
6671 data: data[i],
6672 value: v = values[i],
6673 startAngle: a,
6674 endAngle: a += v * k + pa,
6675 padAngle: p
6676 };
6677 });
6678 return arcs;
6679 }
6680 pie.value = function(_) {
6681 if (!arguments.length) return value;
6682 value = _;
6683 return pie;
6684 };
6685 pie.sort = function(_) {
6686 if (!arguments.length) return sort;
6687 sort = _;
6688 return pie;
6689 };
6690 pie.startAngle = function(_) {
6691 if (!arguments.length) return startAngle;
6692 startAngle = _;
6693 return pie;
6694 };
6695 pie.endAngle = function(_) {
6696 if (!arguments.length) return endAngle;
6697 endAngle = _;
6698 return pie;
6699 };
6700 pie.padAngle = function(_) {
6701 if (!arguments.length) return padAngle;
6702 padAngle = _;
6703 return pie;
6704 };
6705 return pie;
6706 };
6707 var d3_layout_pieSortByValue = {};
6708 d3.layout.stack = function() {
6709 var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
6710 function stack(data, index) {
6711 if (!(n = data.length)) return data;
6712 var series = data.map(function(d, i) {
6713 return values.call(stack, d, i);
6714 });
6715 var points = series.map(function(d) {
6716 return d.map(function(v, i) {
6717 return [ x.call(stack, v, i), y.call(stack, v, i) ];
6718 });
6719 });
6720 var orders = order.call(stack, points, index);
6721 series = d3.permute(series, orders);
6722 points = d3.permute(points, orders);
6723 var offsets = offset.call(stack, points, index);
6724 var m = series[0].length, n, i, j, o;
6725 for (j = 0; j < m; ++j) {
6726 out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
6727 for (i = 1; i < n; ++i) {
6728 out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
6729 }
6730 }
6731 return data;
6732 }
6733 stack.values = function(x) {
6734 if (!arguments.length) return values;
6735 values = x;
6736 return stack;
6737 };
6738 stack.order = function(x) {
6739 if (!arguments.length) return order;
6740 order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
6741 return stack;
6742 };
6743 stack.offset = function(x) {
6744 if (!arguments.length) return offset;
6745 offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
6746 return stack;
6747 };
6748 stack.x = function(z) {
6749 if (!arguments.length) return x;
6750 x = z;
6751 return stack;
6752 };
6753 stack.y = function(z) {
6754 if (!arguments.length) return y;
6755 y = z;
6756 return stack;
6757 };
6758 stack.out = function(z) {
6759 if (!arguments.length) return out;
6760 out = z;
6761 return stack;
6762 };
6763 return stack;
6764 };
6765 function d3_layout_stackX(d) {
6766 return d.x;
6767 }
6768 function d3_layout_stackY(d) {
6769 return d.y;
6770 }
6771 function d3_layout_stackOut(d, y0, y) {
6772 d.y0 = y0;
6773 d.y = y;
6774 }
6775 var d3_layout_stackOrders = d3.map({
6776 "inside-out": function(data) {
6777 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) {
6778 return max[a] - max[b];
6779 }), top = 0, bottom = 0, tops = [], bottoms = [];
6780 for (i = 0; i < n; ++i) {
6781 j = index[i];
6782 if (top < bottom) {
6783 top += sums[j];
6784 tops.push(j);
6785 } else {
6786 bottom += sums[j];
6787 bottoms.push(j);
6788 }
6789 }
6790 return bottoms.reverse().concat(tops);
6791 },
6792 reverse: function(data) {
6793 return d3.range(data.length).reverse();
6794 },
6795 "default": d3_layout_stackOrderDefault
6796 });
6797 var d3_layout_stackOffsets = d3.map({
6798 silhouette: function(data) {
6799 var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
6800 for (j = 0; j < m; ++j) {
6801 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
6802 if (o > max) max = o;
6803 sums.push(o);
6804 }
6805 for (j = 0; j < m; ++j) {
6806 y0[j] = (max - sums[j]) / 2;
6807 }
6808 return y0;
6809 },
6810 wiggle: function(data) {
6811 var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
6812 y0[0] = o = o0 = 0;
6813 for (j = 1; j < m; ++j) {
6814 for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
6815 for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
6816 for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
6817 s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
6818 }
6819 s2 += s3 * data[i][j][1];
6820 }
6821 y0[j] = o -= s1 ? s2 / s1 * dx : 0;
6822 if (o < o0) o0 = o;
6823 }
6824 for (j = 0; j < m; ++j) y0[j] -= o0;
6825 return y0;
6826 },
6827 expand: function(data) {
6828 var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
6829 for (j = 0; j < m; ++j) {
6830 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
6831 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;
6832 }
6833 for (j = 0; j < m; ++j) y0[j] = 0;
6834 return y0;
6835 },
6836 zero: d3_layout_stackOffsetZero
6837 });
6838 function d3_layout_stackOrderDefault(data) {
6839 return d3.range(data.length);
6840 }
6841 function d3_layout_stackOffsetZero(data) {
6842 var j = -1, m = data[0].length, y0 = [];
6843 while (++j < m) y0[j] = 0;
6844 return y0;
6845 }
6846 function d3_layout_stackMaxIndex(array) {
6847 var i = 1, j = 0, v = array[0][1], k, n = array.length;
6848 for (;i < n; ++i) {
6849 if ((k = array[i][1]) > v) {
6850 j = i;
6851 v = k;
6852 }
6853 }
6854 return j;
6855 }
6856 function d3_layout_stackReduceSum(d) {
6857 return d.reduce(d3_layout_stackSum, 0);
6858 }
6859 function d3_layout_stackSum(p, d) {
6860 return p + d[1];
6861 }
6862 d3.layout.histogram = function() {
6863 var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
6864 function histogram(data, i) {
6865 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;
6866 while (++i < m) {
6867 bin = bins[i] = [];
6868 bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
6869 bin.y = 0;
6870 }
6871 if (m > 0) {
6872 i = -1;
6873 while (++i < n) {
6874 x = values[i];
6875 if (x >= range[0] && x <= range[1]) {
6876 bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
6877 bin.y += k;
6878 bin.push(data[i]);
6879 }
6880 }
6881 }
6882 return bins;
6883 }
6884 histogram.value = function(x) {
6885 if (!arguments.length) return valuer;
6886 valuer = x;
6887 return histogram;
6888 };
6889 histogram.range = function(x) {
6890 if (!arguments.length) return ranger;
6891 ranger = d3_functor(x);
6892 return histogram;
6893 };
6894 histogram.bins = function(x) {
6895 if (!arguments.length) return binner;
6896 binner = typeof x === "number" ? function(range) {
6897 return d3_layout_histogramBinFixed(range, x);
6898 } : d3_functor(x);
6899 return histogram;
6900 };
6901 histogram.frequency = function(x) {
6902 if (!arguments.length) return frequency;
6903 frequency = !!x;
6904 return histogram;
6905 };
6906 return histogram;
6907 };
6908 function d3_layout_histogramBinSturges(range, values) {
6909 return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
6910 }
6911 function d3_layout_histogramBinFixed(range, n) {
6912 var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
6913 while (++x <= n) f[x] = m * x + b;
6914 return f;
6915 }
6916 function d3_layout_histogramRange(values) {
6917 return [ d3.min(values), d3.max(values) ];
6918 }
6919 d3.layout.pack = function() {
6920 var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
6921 function pack(d, i) {
6922 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() {
6923 return radius;
6924 };
6925 root.x = root.y = 0;
6926 d3_layout_hierarchyVisitAfter(root, function(d) {
6927 d.r = +r(d.value);
6928 });
6929 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
6930 if (padding) {
6931 var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
6932 d3_layout_hierarchyVisitAfter(root, function(d) {
6933 d.r += dr;
6934 });
6935 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
6936 d3_layout_hierarchyVisitAfter(root, function(d) {
6937 d.r -= dr;
6938 });
6939 }
6940 d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
6941 return nodes;
6942 }
6943 pack.size = function(_) {
6944 if (!arguments.length) return size;
6945 size = _;
6946 return pack;
6947 };
6948 pack.radius = function(_) {
6949 if (!arguments.length) return radius;
6950 radius = _ == null || typeof _ === "function" ? _ : +_;
6951 return pack;
6952 };
6953 pack.padding = function(_) {
6954 if (!arguments.length) return padding;
6955 padding = +_;
6956 return pack;
6957 };
6958 return d3_layout_hierarchyRebind(pack, hierarchy);
6959 };
6960 function d3_layout_packSort(a, b) {
6961 return a.value - b.value;
6962 }
6963 function d3_layout_packInsert(a, b) {
6964 var c = a._pack_next;
6965 a._pack_next = b;
6966 b._pack_prev = a;
6967 b._pack_next = c;
6968 c._pack_prev = b;
6969 }
6970 function d3_layout_packSplice(a, b) {
6971 a._pack_next = b;
6972 b._pack_prev = a;
6973 }
6974 function d3_layout_packIntersects(a, b) {
6975 var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
6976 return .999 * dr * dr > dx * dx + dy * dy;
6977 }
6978 function d3_layout_packSiblings(node) {
6979 if (!(nodes = node.children) || !(n = nodes.length)) return;
6980 var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
6981 function bound(node) {
6982 xMin = Math.min(node.x - node.r, xMin);
6983 xMax = Math.max(node.x + node.r, xMax);
6984 yMin = Math.min(node.y - node.r, yMin);
6985 yMax = Math.max(node.y + node.r, yMax);
6986 }
6987 nodes.forEach(d3_layout_packLink);
6988 a = nodes[0];
6989 a.x = -a.r;
6990 a.y = 0;
6991 bound(a);
6992 if (n > 1) {
6993 b = nodes[1];
6994 b.x = b.r;
6995 b.y = 0;
6996 bound(b);
6997 if (n > 2) {
6998 c = nodes[2];
6999 d3_layout_packPlace(a, b, c);
7000 bound(c);
7001 d3_layout_packInsert(a, c);
7002 a._pack_prev = c;
7003 d3_layout_packInsert(c, b);
7004 b = a._pack_next;
7005 for (i = 3; i < n; i++) {
7006 d3_layout_packPlace(a, b, c = nodes[i]);
7007 var isect = 0, s1 = 1, s2 = 1;
7008 for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
7009 if (d3_layout_packIntersects(j, c)) {
7010 isect = 1;
7011 break;
7012 }
7013 }
7014 if (isect == 1) {
7015 for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
7016 if (d3_layout_packIntersects(k, c)) {
7017 break;
7018 }
7019 }
7020 }
7021 if (isect) {
7022 if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
7023 i--;
7024 } else {
7025 d3_layout_packInsert(a, c);
7026 b = c;
7027 bound(c);
7028 }
7029 }
7030 }
7031 }
7032 var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
7033 for (i = 0; i < n; i++) {
7034 c = nodes[i];
7035 c.x -= cx;
7036 c.y -= cy;
7037 cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
7038 }
7039 node.r = cr;
7040 nodes.forEach(d3_layout_packUnlink);
7041 }
7042 function d3_layout_packLink(node) {
7043 node._pack_next = node._pack_prev = node;
7044 }
7045 function d3_layout_packUnlink(node) {
7046 delete node._pack_next;
7047 delete node._pack_prev;
7048 }
7049 function d3_layout_packTransform(node, x, y, k) {
7050 var children = node.children;
7051 node.x = x += k * node.x;
7052 node.y = y += k * node.y;
7053 node.r *= k;
7054 if (children) {
7055 var i = -1, n = children.length;
7056 while (++i < n) d3_layout_packTransform(children[i], x, y, k);
7057 }
7058 }
7059 function d3_layout_packPlace(a, b, c) {
7060 var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
7061 if (db && (dx || dy)) {
7062 var da = b.r + c.r, dc = dx * dx + dy * dy;
7063 da *= da;
7064 db *= db;
7065 var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
7066 c.x = a.x + x * dx + y * dy;
7067 c.y = a.y + x * dy - y * dx;
7068 } else {
7069 c.x = a.x + db;
7070 c.y = a.y;
7071 }
7072 }
7073 d3.layout.tree = function() {
7074 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
7075 function tree(d, i) {
7076 var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
7077 d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
7078 d3_layout_hierarchyVisitBefore(root1, secondWalk);
7079 if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
7080 var left = root0, right = root0, bottom = root0;
7081 d3_layout_hierarchyVisitBefore(root0, function(node) {
7082 if (node.x < left.x) left = node;
7083 if (node.x > right.x) right = node;
7084 if (node.depth > bottom.depth) bottom = node;
7085 });
7086 var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
7087 d3_layout_hierarchyVisitBefore(root0, function(node) {
7088 node.x = (node.x + tx) * kx;
7089 node.y = node.depth * ky;
7090 });
7091 }
7092 return nodes;
7093 }
7094 function wrapTree(root0) {
7095 var root1 = {
7096 A: null,
7097 children: [ root0 ]
7098 }, queue = [ root1 ], node1;
7099 while ((node1 = queue.pop()) != null) {
7100 for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
7101 queue.push((children[i] = child = {
7102 _: children[i],
7103 parent: node1,
7104 children: (child = children[i].children) && child.slice() || [],
7105 A: null,
7106 a: null,
7107 z: 0,
7108 m: 0,
7109 c: 0,
7110 s: 0,
7111 t: null,
7112 i: i
7113 }).a = child);
7114 }
7115 }
7116 return root1.children[0];
7117 }
7118 function firstWalk(v) {
7119 var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
7120 if (children.length) {
7121 d3_layout_treeShift(v);
7122 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
7123 if (w) {
7124 v.z = w.z + separation(v._, w._);
7125 v.m = v.z - midpoint;
7126 } else {
7127 v.z = midpoint;
7128 }
7129 } else if (w) {
7130 v.z = w.z + separation(v._, w._);
7131 }
7132 v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
7133 }
7134 function secondWalk(v) {
7135 v._.x = v.z + v.parent.m;
7136 v.m += v.parent.m;
7137 }
7138 function apportion(v, w, ancestor) {
7139 if (w) {
7140 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;
7141 while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
7142 vom = d3_layout_treeLeft(vom);
7143 vop = d3_layout_treeRight(vop);
7144 vop.a = v;
7145 shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
7146 if (shift > 0) {
7147 d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
7148 sip += shift;
7149 sop += shift;
7150 }
7151 sim += vim.m;
7152 sip += vip.m;
7153 som += vom.m;
7154 sop += vop.m;
7155 }
7156 if (vim && !d3_layout_treeRight(vop)) {
7157 vop.t = vim;
7158 vop.m += sim - sop;
7159 }
7160 if (vip && !d3_layout_treeLeft(vom)) {
7161 vom.t = vip;
7162 vom.m += sip - som;
7163 ancestor = v;
7164 }
7165 }
7166 return ancestor;
7167 }
7168 function sizeNode(node) {
7169 node.x *= size[0];
7170 node.y = node.depth * size[1];
7171 }
7172 tree.separation = function(x) {
7173 if (!arguments.length) return separation;
7174 separation = x;
7175 return tree;
7176 };
7177 tree.size = function(x) {
7178 if (!arguments.length) return nodeSize ? null : size;
7179 nodeSize = (size = x) == null ? sizeNode : null;
7180 return tree;
7181 };
7182 tree.nodeSize = function(x) {
7183 if (!arguments.length) return nodeSize ? size : null;
7184 nodeSize = (size = x) == null ? null : sizeNode;
7185 return tree;
7186 };
7187 return d3_layout_hierarchyRebind(tree, hierarchy);
7188 };
7189 function d3_layout_treeSeparation(a, b) {
7190 return a.parent == b.parent ? 1 : 2;
7191 }
7192 function d3_layout_treeLeft(v) {
7193 var children = v.children;
7194 return children.length ? children[0] : v.t;
7195 }
7196 function d3_layout_treeRight(v) {
7197 var children = v.children, n;
7198 return (n = children.length) ? children[n - 1] : v.t;
7199 }
7200 function d3_layout_treeMove(wm, wp, shift) {
7201 var change = shift / (wp.i - wm.i);
7202 wp.c -= change;
7203 wp.s += shift;
7204 wm.c += change;
7205 wp.z += shift;
7206 wp.m += shift;
7207 }
7208 function d3_layout_treeShift(v) {
7209 var shift = 0, change = 0, children = v.children, i = children.length, w;
7210 while (--i >= 0) {
7211 w = children[i];
7212 w.z += shift;
7213 w.m += shift;
7214 shift += w.s + (change += w.c);
7215 }
7216 }
7217 function d3_layout_treeAncestor(vim, v, ancestor) {
7218 return vim.a.parent === v.parent ? vim.a : ancestor;
7219 }
7220 d3.layout.cluster = function() {
7221 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
7222 function cluster(d, i) {
7223 var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
7224 d3_layout_hierarchyVisitAfter(root, function(node) {
7225 var children = node.children;
7226 if (children && children.length) {
7227 node.x = d3_layout_clusterX(children);
7228 node.y = d3_layout_clusterY(children);
7229 } else {
7230 node.x = previousNode ? x += separation(node, previousNode) : 0;
7231 node.y = 0;
7232 previousNode = node;
7233 }
7234 });
7235 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;
7236 d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
7237 node.x = (node.x - root.x) * size[0];
7238 node.y = (root.y - node.y) * size[1];
7239 } : function(node) {
7240 node.x = (node.x - x0) / (x1 - x0) * size[0];
7241 node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
7242 });
7243 return nodes;
7244 }
7245 cluster.separation = function(x) {
7246 if (!arguments.length) return separation;
7247 separation = x;
7248 return cluster;
7249 };
7250 cluster.size = function(x) {
7251 if (!arguments.length) return nodeSize ? null : size;
7252 nodeSize = (size = x) == null;
7253 return cluster;
7254 };
7255 cluster.nodeSize = function(x) {
7256 if (!arguments.length) return nodeSize ? size : null;
7257 nodeSize = (size = x) != null;
7258 return cluster;
7259 };
7260 return d3_layout_hierarchyRebind(cluster, hierarchy);
7261 };
7262 function d3_layout_clusterY(children) {
7263 return 1 + d3.max(children, function(child) {
7264 return child.y;
7265 });
7266 }
7267 function d3_layout_clusterX(children) {
7268 return children.reduce(function(x, child) {
7269 return x + child.x;
7270 }, 0) / children.length;
7271 }
7272 function d3_layout_clusterLeft(node) {
7273 var children = node.children;
7274 return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
7275 }
7276 function d3_layout_clusterRight(node) {
7277 var children = node.children, n;
7278 return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
7279 }
7280 d3.layout.treemap = function() {
7281 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));
7282 function scale(children, k) {
7283 var i = -1, n = children.length, child, area;
7284 while (++i < n) {
7285 area = (child = children[i]).value * (k < 0 ? 0 : k);
7286 child.area = isNaN(area) || area <= 0 ? 0 : area;
7287 }
7288 }
7289 function squarify(node) {
7290 var children = node.children;
7291 if (children && children.length) {
7292 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;
7293 scale(remaining, rect.dx * rect.dy / node.value);
7294 row.area = 0;
7295 while ((n = remaining.length) > 0) {
7296 row.push(child = remaining[n - 1]);
7297 row.area += child.area;
7298 if (mode !== "squarify" || (score = worst(row, u)) <= best) {
7299 remaining.pop();
7300 best = score;
7301 } else {
7302 row.area -= row.pop().area;
7303 position(row, u, rect, false);
7304 u = Math.min(rect.dx, rect.dy);
7305 row.length = row.area = 0;
7306 best = Infinity;
7307 }
7308 }
7309 if (row.length) {
7310 position(row, u, rect, true);
7311 row.length = row.area = 0;
7312 }
7313 children.forEach(squarify);
7314 }
7315 }
7316 function stickify(node) {
7317 var children = node.children;
7318 if (children && children.length) {
7319 var rect = pad(node), remaining = children.slice(), child, row = [];
7320 scale(remaining, rect.dx * rect.dy / node.value);
7321 row.area = 0;
7322 while (child = remaining.pop()) {
7323 row.push(child);
7324 row.area += child.area;
7325 if (child.z != null) {
7326 position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
7327 row.length = row.area = 0;
7328 }
7329 }
7330 children.forEach(stickify);
7331 }
7332 }
7333 function worst(row, u) {
7334 var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
7335 while (++i < n) {
7336 if (!(r = row[i].area)) continue;
7337 if (r < rmin) rmin = r;
7338 if (r > rmax) rmax = r;
7339 }
7340 s *= s;
7341 u *= u;
7342 return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
7343 }
7344 function position(row, u, rect, flush) {
7345 var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
7346 if (u == rect.dx) {
7347 if (flush || v > rect.dy) v = rect.dy;
7348 while (++i < n) {
7349 o = row[i];
7350 o.x = x;
7351 o.y = y;
7352 o.dy = v;
7353 x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
7354 }
7355 o.z = true;
7356 o.dx += rect.x + rect.dx - x;
7357 rect.y += v;
7358 rect.dy -= v;
7359 } else {
7360 if (flush || v > rect.dx) v = rect.dx;
7361 while (++i < n) {
7362 o = row[i];
7363 o.x = x;
7364 o.y = y;
7365 o.dx = v;
7366 y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
7367 }
7368 o.z = false;
7369 o.dy += rect.y + rect.dy - y;
7370 rect.x += v;
7371 rect.dx -= v;
7372 }
7373 }
7374 function treemap(d) {
7375 var nodes = stickies || hierarchy(d), root = nodes[0];
7376 root.x = root.y = 0;
7377 if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0;
7378 if (stickies) hierarchy.revalue(root);
7379 scale([ root ], root.dx * root.dy / root.value);
7380 (stickies ? stickify : squarify)(root);
7381 if (sticky) stickies = nodes;
7382 return nodes;
7383 }
7384 treemap.size = function(x) {
7385 if (!arguments.length) return size;
7386 size = x;
7387 return treemap;
7388 };
7389 treemap.padding = function(x) {
7390 if (!arguments.length) return padding;
7391 function padFunction(node) {
7392 var p = x.call(treemap, node, node.depth);
7393 return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
7394 }
7395 function padConstant(node) {
7396 return d3_layout_treemapPad(node, x);
7397 }
7398 var type;
7399 pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
7400 padConstant) : padConstant;
7401 return treemap;
7402 };
7403 treemap.round = function(x) {
7404 if (!arguments.length) return round != Number;
7405 round = x ? Math.round : Number;
7406 return treemap;
7407 };
7408 treemap.sticky = function(x) {
7409 if (!arguments.length) return sticky;
7410 sticky = x;
7411 stickies = null;
7412 return treemap;
7413 };
7414 treemap.ratio = function(x) {
7415 if (!arguments.length) return ratio;
7416 ratio = x;
7417 return treemap;
7418 };
7419 treemap.mode = function(x) {
7420 if (!arguments.length) return mode;
7421 mode = x + "";
7422 return treemap;
7423 };
7424 return d3_layout_hierarchyRebind(treemap, hierarchy);
7425 };
7426 function d3_layout_treemapPadNull(node) {
7427 return {
7428 x: node.x,
7429 y: node.y,
7430 dx: node.dx,
7431 dy: node.dy
7432 };
7433 }
7434 function d3_layout_treemapPad(node, padding) {
7435 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];
7436 if (dx < 0) {
7437 x += dx / 2;
7438 dx = 0;
7439 }
7440 if (dy < 0) {
7441 y += dy / 2;
7442 dy = 0;
7443 }
7444 return {
7445 x: x,
7446 y: y,
7447 dx: dx,
7448 dy: dy
7449 };
7450 }
7451 d3.random = {
7452 normal: function(µ, σ) {
7453 var n = arguments.length;
7454 if (n < 2) σ = 1;
7455 if (n < 1) µ = 0;
7456 return function() {
7457 var x, y, r;
7458 do {
7459 x = Math.random() * 2 - 1;
7460 y = Math.random() * 2 - 1;
7461 r = x * x + y * y;
7462 } while (!r || r > 1);
7463 return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
7464 };
7465 },
7466 logNormal: function() {
7467 var random = d3.random.normal.apply(d3, arguments);
7468 return function() {
7469 return Math.exp(random());
7470 };
7471 },
7472 bates: function(m) {
7473 var random = d3.random.irwinHall(m);
7474 return function() {
7475 return random() / m;
7476 };
7477 },
7478 irwinHall: function(m) {
7479 return function() {
7480 for (var s = 0, j = 0; j < m; j++) s += Math.random();
7481 return s;
7482 };
7483 }
7484 };
7485 d3.scale = {};
7486 function d3_scaleExtent(domain) {
7487 var start = domain[0], stop = domain[domain.length - 1];
7488 return start < stop ? [ start, stop ] : [ stop, start ];
7489 }
7490 function d3_scaleRange(scale) {
7491 return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
7492 }
7493 function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
7494 var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
7495 return function(x) {
7496 return i(u(x));
7497 };
7498 }
7499 function d3_scale_nice(domain, nice) {
7500 var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
7501 if (x1 < x0) {
7502 dx = i0, i0 = i1, i1 = dx;
7503 dx = x0, x0 = x1, x1 = dx;
7504 }
7505 domain[i0] = nice.floor(x0);
7506 domain[i1] = nice.ceil(x1);
7507 return domain;
7508 }
7509 function d3_scale_niceStep(step) {
7510 return step ? {
7511 floor: function(x) {
7512 return Math.floor(x / step) * step;
7513 },
7514 ceil: function(x) {
7515 return Math.ceil(x / step) * step;
7516 }
7517 } : d3_scale_niceIdentity;
7518 }
7519 var d3_scale_niceIdentity = {
7520 floor: d3_identity,
7521 ceil: d3_identity
7522 };
7523 function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
7524 var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
7525 if (domain[k] < domain[0]) {
7526 domain = domain.slice().reverse();
7527 range = range.slice().reverse();
7528 }
7529 while (++j <= k) {
7530 u.push(uninterpolate(domain[j - 1], domain[j]));
7531 i.push(interpolate(range[j - 1], range[j]));
7532 }
7533 return function(x) {
7534 var j = d3.bisect(domain, x, 1, k) - 1;
7535 return i[j](u[j](x));
7536 };
7537 }
7538 d3.scale.linear = function() {
7539 return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
7540 };
7541 function d3_scale_linear(domain, range, interpolate, clamp) {
7542 var output, input;
7543 function rescale() {
7544 var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
7545 output = linear(domain, range, uninterpolate, interpolate);
7546 input = linear(range, domain, uninterpolate, d3_interpolate);
7547 return scale;
7548 }
7549 function scale(x) {
7550 return output(x);
7551 }
7552 scale.invert = function(y) {
7553 return input(y);
7554 };
7555 scale.domain = function(x) {
7556 if (!arguments.length) return domain;
7557 domain = x.map(Number);
7558 return rescale();
7559 };
7560 scale.range = function(x) {
7561 if (!arguments.length) return range;
7562 range = x;
7563 return rescale();
7564 };
7565 scale.rangeRound = function(x) {
7566 return scale.range(x).interpolate(d3_interpolateRound);
7567 };
7568 scale.clamp = function(x) {
7569 if (!arguments.length) return clamp;
7570 clamp = x;
7571 return rescale();
7572 };
7573 scale.interpolate = function(x) {
7574 if (!arguments.length) return interpolate;
7575 interpolate = x;
7576 return rescale();
7577 };
7578 scale.ticks = function(m) {
7579 return d3_scale_linearTicks(domain, m);
7580 };
7581 scale.tickFormat = function(m, format) {
7582 return d3_scale_linearTickFormat(domain, m, format);
7583 };
7584 scale.nice = function(m) {
7585 d3_scale_linearNice(domain, m);
7586 return rescale();
7587 };
7588 scale.copy = function() {
7589 return d3_scale_linear(domain, range, interpolate, clamp);
7590 };
7591 return rescale();
7592 }
7593 function d3_scale_linearRebind(scale, linear) {
7594 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
7595 }
7596 function d3_scale_linearNice(domain, m) {
7597 return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
7598 }
7599 function d3_scale_linearTickRange(domain, m) {
7600 if (m == null) m = 10;
7601 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;
7602 if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
7603 extent[0] = Math.ceil(extent[0] / step) * step;
7604 extent[1] = Math.floor(extent[1] / step) * step + step * .5;
7605 extent[2] = step;
7606 return extent;
7607 }
7608 function d3_scale_linearTicks(domain, m) {
7609 return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
7610 }
7611 function d3_scale_linearTickFormat(domain, m, format) {
7612 var range = d3_scale_linearTickRange(domain, m);
7613 if (format) {
7614 var match = d3_format_re.exec(format);
7615 match.shift();
7616 if (match[8] === "s") {
7617 var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
7618 if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
7619 match[8] = "f";
7620 format = d3.format(match.join(""));
7621 return function(d) {
7622 return format(prefix.scale(d)) + prefix.symbol;
7623 };
7624 }
7625 if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
7626 format = match.join("");
7627 } else {
7628 format = ",." + d3_scale_linearPrecision(range[2]) + "f";
7629 }
7630 return d3.format(format);
7631 }
7632 var d3_scale_linearFormatSignificant = {
7633 s: 1,
7634 g: 1,
7635 p: 1,
7636 r: 1,
7637 e: 1
7638 };
7639 function d3_scale_linearPrecision(value) {
7640 return -Math.floor(Math.log(value) / Math.LN10 + .01);
7641 }
7642 function d3_scale_linearFormatPrecision(type, range) {
7643 var p = d3_scale_linearPrecision(range[2]);
7644 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;
7645 }
7646 d3.scale.log = function() {
7647 return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
7648 };
7649 function d3_scale_log(linear, base, positive, domain) {
7650 function log(x) {
7651 return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
7652 }
7653 function pow(x) {
7654 return positive ? Math.pow(base, x) : -Math.pow(base, -x);
7655 }
7656 function scale(x) {
7657 return linear(log(x));
7658 }
7659 scale.invert = function(x) {
7660 return pow(linear.invert(x));
7661 };
7662 scale.domain = function(x) {
7663 if (!arguments.length) return domain;
7664 positive = x[0] >= 0;
7665 linear.domain((domain = x.map(Number)).map(log));
7666 return scale;
7667 };
7668 scale.base = function(_) {
7669 if (!arguments.length) return base;
7670 base = +_;
7671 linear.domain(domain.map(log));
7672 return scale;
7673 };
7674 scale.nice = function() {
7675 var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
7676 linear.domain(niced);
7677 domain = niced.map(pow);
7678 return scale;
7679 };
7680 scale.ticks = function() {
7681 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;
7682 if (isFinite(j - i)) {
7683 if (positive) {
7684 for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
7685 ticks.push(pow(i));
7686 } else {
7687 ticks.push(pow(i));
7688 for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
7689 }
7690 for (i = 0; ticks[i] < u; i++) {}
7691 for (j = ticks.length; ticks[j - 1] > v; j--) {}
7692 ticks = ticks.slice(i, j);
7693 }
7694 return ticks;
7695 };
7696 scale.tickFormat = function(n, format) {
7697 if (!arguments.length) return d3_scale_logFormat;
7698 if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
7699 var k = Math.max(1, base * n / scale.ticks().length);
7700 return function(d) {
7701 var i = d / pow(Math.round(log(d)));
7702 if (i * base < base - .5) i *= base;
7703 return i <= k ? format(d) : "";
7704 };
7705 };
7706 scale.copy = function() {
7707 return d3_scale_log(linear.copy(), base, positive, domain);
7708 };
7709 return d3_scale_linearRebind(scale, linear);
7710 }
7711 var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
7712 floor: function(x) {
7713 return -Math.ceil(-x);
7714 },
7715 ceil: function(x) {
7716 return -Math.floor(-x);
7717 }
7718 };
7719 d3.scale.pow = function() {
7720 return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
7721 };
7722 function d3_scale_pow(linear, exponent, domain) {
7723 var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
7724 function scale(x) {
7725 return linear(powp(x));
7726 }
7727 scale.invert = function(x) {
7728 return powb(linear.invert(x));
7729 };
7730 scale.domain = function(x) {
7731 if (!arguments.length) return domain;
7732 linear.domain((domain = x.map(Number)).map(powp));
7733 return scale;
7734 };
7735 scale.ticks = function(m) {
7736 return d3_scale_linearTicks(domain, m);
7737 };
7738 scale.tickFormat = function(m, format) {
7739 return d3_scale_linearTickFormat(domain, m, format);
7740 };
7741 scale.nice = function(m) {
7742 return scale.domain(d3_scale_linearNice(domain, m));
7743 };
7744 scale.exponent = function(x) {
7745 if (!arguments.length) return exponent;
7746 powp = d3_scale_powPow(exponent = x);
7747 powb = d3_scale_powPow(1 / exponent);
7748 linear.domain(domain.map(powp));
7749 return scale;
7750 };
7751 scale.copy = function() {
7752 return d3_scale_pow(linear.copy(), exponent, domain);
7753 };
7754 return d3_scale_linearRebind(scale, linear);
7755 }
7756 function d3_scale_powPow(e) {
7757 return function(x) {
7758 return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
7759 };
7760 }
7761 d3.scale.sqrt = function() {
7762 return d3.scale.pow().exponent(.5);
7763 };
7764 d3.scale.ordinal = function() {
7765 return d3_scale_ordinal([], {
7766 t: "range",
7767 a: [ [] ]
7768 });
7769 };
7770 function d3_scale_ordinal(domain, ranger) {
7771 var index, range, rangeBand;
7772 function scale(x) {
7773 return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
7774 }
7775 function steps(start, step) {
7776 return d3.range(domain.length).map(function(i) {
7777 return start + step * i;
7778 });
7779 }
7780 scale.domain = function(x) {
7781 if (!arguments.length) return domain;
7782 domain = [];
7783 index = new d3_Map();
7784 var i = -1, n = x.length, xi;
7785 while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
7786 return scale[ranger.t].apply(scale, ranger.a);
7787 };
7788 scale.range = function(x) {
7789 if (!arguments.length) return range;
7790 range = x;
7791 rangeBand = 0;
7792 ranger = {
7793 t: "range",
7794 a: arguments
7795 };
7796 return scale;
7797 };
7798 scale.rangePoints = function(x, padding) {
7799 if (arguments.length < 2) padding = 0;
7800 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
7801 0) : (stop - start) / (domain.length - 1 + padding);
7802 range = steps(start + step * padding / 2, step);
7803 rangeBand = 0;
7804 ranger = {
7805 t: "rangePoints",
7806 a: arguments
7807 };
7808 return scale;
7809 };
7810 scale.rangeRoundPoints = function(x, padding) {
7811 if (arguments.length < 2) padding = 0;
7812 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
7813 0) : (stop - start) / (domain.length - 1 + padding) | 0;
7814 range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
7815 rangeBand = 0;
7816 ranger = {
7817 t: "rangeRoundPoints",
7818 a: arguments
7819 };
7820 return scale;
7821 };
7822 scale.rangeBands = function(x, padding, outerPadding) {
7823 if (arguments.length < 2) padding = 0;
7824 if (arguments.length < 3) outerPadding = padding;
7825 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
7826 range = steps(start + step * outerPadding, step);
7827 if (reverse) range.reverse();
7828 rangeBand = step * (1 - padding);
7829 ranger = {
7830 t: "rangeBands",
7831 a: arguments
7832 };
7833 return scale;
7834 };
7835 scale.rangeRoundBands = function(x, padding, outerPadding) {
7836 if (arguments.length < 2) padding = 0;
7837 if (arguments.length < 3) outerPadding = padding;
7838 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
7839 range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
7840 if (reverse) range.reverse();
7841 rangeBand = Math.round(step * (1 - padding));
7842 ranger = {
7843 t: "rangeRoundBands",
7844 a: arguments
7845 };
7846 return scale;
7847 };
7848 scale.rangeBand = function() {
7849 return rangeBand;
7850 };
7851 scale.rangeExtent = function() {
7852 return d3_scaleExtent(ranger.a[0]);
7853 };
7854 scale.copy = function() {
7855 return d3_scale_ordinal(domain, ranger);
7856 };
7857 return scale.domain(domain);
7858 }
7859 d3.scale.category10 = function() {
7860 return d3.scale.ordinal().range(d3_category10);
7861 };
7862 d3.scale.category20 = function() {
7863 return d3.scale.ordinal().range(d3_category20);
7864 };
7865 d3.scale.category20b = function() {
7866 return d3.scale.ordinal().range(d3_category20b);
7867 };
7868 d3.scale.category20c = function() {
7869 return d3.scale.ordinal().range(d3_category20c);
7870 };
7871 var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
7872 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);
7873 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);
7874 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);
7875 d3.scale.quantile = function() {
7876 return d3_scale_quantile([], []);
7877 };
7878 function d3_scale_quantile(domain, range) {
7879 var thresholds;
7880 function rescale() {
7881 var k = 0, q = range.length;
7882 thresholds = [];
7883 while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
7884 return scale;
7885 }
7886 function scale(x) {
7887 if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
7888 }
7889 scale.domain = function(x) {
7890 if (!arguments.length) return domain;
7891 domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
7892 return rescale();
7893 };
7894 scale.range = function(x) {
7895 if (!arguments.length) return range;
7896 range = x;
7897 return rescale();
7898 };
7899 scale.quantiles = function() {
7900 return thresholds;
7901 };
7902 scale.invertExtent = function(y) {
7903 y = range.indexOf(y);
7904 return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
7905 };
7906 scale.copy = function() {
7907 return d3_scale_quantile(domain, range);
7908 };
7909 return rescale();
7910 }
7911 d3.scale.quantize = function() {
7912 return d3_scale_quantize(0, 1, [ 0, 1 ]);
7913 };
7914 function d3_scale_quantize(x0, x1, range) {
7915 var kx, i;
7916 function scale(x) {
7917 return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
7918 }
7919 function rescale() {
7920 kx = range.length / (x1 - x0);
7921 i = range.length - 1;
7922 return scale;
7923 }
7924 scale.domain = function(x) {
7925 if (!arguments.length) return [ x0, x1 ];
7926 x0 = +x[0];
7927 x1 = +x[x.length - 1];
7928 return rescale();
7929 };
7930 scale.range = function(x) {
7931 if (!arguments.length) return range;
7932 range = x;
7933 return rescale();
7934 };
7935 scale.invertExtent = function(y) {
7936 y = range.indexOf(y);
7937 y = y < 0 ? NaN : y / kx + x0;
7938 return [ y, y + 1 / kx ];
7939 };
7940 scale.copy = function() {
7941 return d3_scale_quantize(x0, x1, range);
7942 };
7943 return rescale();
7944 }
7945 d3.scale.threshold = function() {
7946 return d3_scale_threshold([ .5 ], [ 0, 1 ]);
7947 };
7948 function d3_scale_threshold(domain, range) {
7949 function scale(x) {
7950 if (x <= x) return range[d3.bisect(domain, x)];
7951 }
7952 scale.domain = function(_) {
7953 if (!arguments.length) return domain;
7954 domain = _;
7955 return scale;
7956 };
7957 scale.range = function(_) {
7958 if (!arguments.length) return range;
7959 range = _;
7960 return scale;
7961 };
7962 scale.invertExtent = function(y) {
7963 y = range.indexOf(y);
7964 return [ domain[y - 1], domain[y] ];
7965 };
7966 scale.copy = function() {
7967 return d3_scale_threshold(domain, range);
7968 };
7969 return scale;
7970 }
7971 d3.scale.identity = function() {
7972 return d3_scale_identity([ 0, 1 ]);
7973 };
7974 function d3_scale_identity(domain) {
7975 function identity(x) {
7976 return +x;
7977 }
7978 identity.invert = identity;
7979 identity.domain = identity.range = function(x) {
7980 if (!arguments.length) return domain;
7981 domain = x.map(identity);
7982 return identity;
7983 };
7984 identity.ticks = function(m) {
7985 return d3_scale_linearTicks(domain, m);
7986 };
7987 identity.tickFormat = function(m, format) {
7988 return d3_scale_linearTickFormat(domain, m, format);
7989 };
7990 identity.copy = function() {
7991 return d3_scale_identity(domain);
7992 };
7993 return identity;
7994 }
7995 d3.svg = {};
7996 function d3_zero() {
7997 return 0;
7998 }
7999 d3.svg.arc = function() {
8000 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;
8001 function arc() {
8002 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;
8003 if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
8004 if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
8005 var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
8006 if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
8007 rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
8008 if (!cw) p1 *= -1;
8009 if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
8010 if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
8011 }
8012 if (r1) {
8013 x0 = r1 * Math.cos(a0 + p1);
8014 y0 = r1 * Math.sin(a0 + p1);
8015 x1 = r1 * Math.cos(a1 - p1);
8016 y1 = r1 * Math.sin(a1 - p1);
8017 var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
8018 if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
8019 var h1 = (a0 + a1) / 2;
8020 x0 = r1 * Math.cos(h1);
8021 y0 = r1 * Math.sin(h1);
8022 x1 = y1 = null;
8023 }
8024 } else {
8025 x0 = y0 = 0;
8026 }
8027 if (r0) {
8028 x2 = r0 * Math.cos(a1 - p0);
8029 y2 = r0 * Math.sin(a1 - p0);
8030 x3 = r0 * Math.cos(a0 + p0);
8031 y3 = r0 * Math.sin(a0 + p0);
8032 var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
8033 if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
8034 var h0 = (a0 + a1) / 2;
8035 x2 = r0 * Math.cos(h0);
8036 y2 = r0 * Math.sin(h0);
8037 x3 = y3 = null;
8038 }
8039 } else {
8040 x2 = y2 = 0;
8041 }
8042 if (da > ε && (rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
8043 cr = r0 < r1 ^ cw ? 0 : 1;
8044 var rc1 = rc, rc0 = rc;
8045 if (da < π) {
8046 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]);
8047 rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
8048 rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
8049 }
8050 if (x1 != null) {
8051 var 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);
8052 if (rc === rc1) {
8053 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]);
8054 } else {
8055 path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
8056 }
8057 } else {
8058 path.push("M", x0, ",", y0);
8059 }
8060 if (x3 != null) {
8061 var 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);
8062 if (rc === rc0) {
8063 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]);
8064 } else {
8065 path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
8066 }
8067 } else {
8068 path.push("L", x2, ",", y2);
8069 }
8070 } else {
8071 path.push("M", x0, ",", y0);
8072 if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
8073 path.push("L", x2, ",", y2);
8074 if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
8075 }
8076 path.push("Z");
8077 return path.join("");
8078 }
8079 function circleSegment(r1, cw) {
8080 return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
8081 }
8082 arc.innerRadius = function(v) {
8083 if (!arguments.length) return innerRadius;
8084 innerRadius = d3_functor(v);
8085 return arc;
8086 };
8087 arc.outerRadius = function(v) {
8088 if (!arguments.length) return outerRadius;
8089 outerRadius = d3_functor(v);
8090 return arc;
8091 };
8092 arc.cornerRadius = function(v) {
8093 if (!arguments.length) return cornerRadius;
8094 cornerRadius = d3_functor(v);
8095 return arc;
8096 };
8097 arc.padRadius = function(v) {
8098 if (!arguments.length) return padRadius;
8099 padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
8100 return arc;
8101 };
8102 arc.startAngle = function(v) {
8103 if (!arguments.length) return startAngle;
8104 startAngle = d3_functor(v);
8105 return arc;
8106 };
8107 arc.endAngle = function(v) {
8108 if (!arguments.length) return endAngle;
8109 endAngle = d3_functor(v);
8110 return arc;
8111 };
8112 arc.padAngle = function(v) {
8113 if (!arguments.length) return padAngle;
8114 padAngle = d3_functor(v);
8115 return arc;
8116 };
8117 arc.centroid = function() {
8118 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
8119 return [ Math.cos(a) * r, Math.sin(a) * r ];
8120 };
8121 return arc;
8122 };
8123 var d3_svg_arcAuto = "auto";
8124 function d3_svg_arcInnerRadius(d) {
8125 return d.innerRadius;
8126 }
8127 function d3_svg_arcOuterRadius(d) {
8128 return d.outerRadius;
8129 }
8130 function d3_svg_arcStartAngle(d) {
8131 return d.startAngle;
8132 }
8133 function d3_svg_arcEndAngle(d) {
8134 return d.endAngle;
8135 }
8136 function d3_svg_arcPadAngle(d) {
8137 return d && d.padAngle;
8138 }
8139 function d3_svg_arcSweep(x0, y0, x1, y1) {
8140 return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
8141 }
8142 function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
8143 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(Math.max(0, 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;
8144 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
8145 return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
8146 }
8147 function d3_svg_line(projection) {
8148 var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
8149 function line(data) {
8150 var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
8151 function segment() {
8152 segments.push("M", interpolate(projection(points), tension));
8153 }
8154 while (++i < n) {
8155 if (defined.call(this, d = data[i], i)) {
8156 points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
8157 } else if (points.length) {
8158 segment();
8159 points = [];
8160 }
8161 }
8162 if (points.length) segment();
8163 return segments.length ? segments.join("") : null;
8164 }
8165 line.x = function(_) {
8166 if (!arguments.length) return x;
8167 x = _;
8168 return line;
8169 };
8170 line.y = function(_) {
8171 if (!arguments.length) return y;
8172 y = _;
8173 return line;
8174 };
8175 line.defined = function(_) {
8176 if (!arguments.length) return defined;
8177 defined = _;
8178 return line;
8179 };
8180 line.interpolate = function(_) {
8181 if (!arguments.length) return interpolateKey;
8182 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
8183 return line;
8184 };
8185 line.tension = function(_) {
8186 if (!arguments.length) return tension;
8187 tension = _;
8188 return line;
8189 };
8190 return line;
8191 }
8192 d3.svg.line = function() {
8193 return d3_svg_line(d3_identity);
8194 };
8195 var d3_svg_lineInterpolators = d3.map({
8196 linear: d3_svg_lineLinear,
8197 "linear-closed": d3_svg_lineLinearClosed,
8198 step: d3_svg_lineStep,
8199 "step-before": d3_svg_lineStepBefore,
8200 "step-after": d3_svg_lineStepAfter,
8201 basis: d3_svg_lineBasis,
8202 "basis-open": d3_svg_lineBasisOpen,
8203 "basis-closed": d3_svg_lineBasisClosed,
8204 bundle: d3_svg_lineBundle,
8205 cardinal: d3_svg_lineCardinal,
8206 "cardinal-open": d3_svg_lineCardinalOpen,
8207 "cardinal-closed": d3_svg_lineCardinalClosed,
8208 monotone: d3_svg_lineMonotone
8209 });
8210 d3_svg_lineInterpolators.forEach(function(key, value) {
8211 value.key = key;
8212 value.closed = /-closed$/.test(key);
8213 });
8214 function d3_svg_lineLinear(points) {
8215 return points.length > 1 ? points.join("L") : points + "Z";
8216 }
8217 function d3_svg_lineLinearClosed(points) {
8218 return points.join("L") + "Z";
8219 }
8220 function d3_svg_lineStep(points) {
8221 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8222 while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
8223 if (n > 1) path.push("H", p[0]);
8224 return path.join("");
8225 }
8226 function d3_svg_lineStepBefore(points) {
8227 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8228 while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
8229 return path.join("");
8230 }
8231 function d3_svg_lineStepAfter(points) {
8232 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8233 while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
8234 return path.join("");
8235 }
8236 function d3_svg_lineCardinalOpen(points, tension) {
8237 return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
8238 }
8239 function d3_svg_lineCardinalClosed(points, tension) {
8240 return points.length < 3 ? d3_svg_lineLinearClosed(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
8241 points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
8242 }
8243 function d3_svg_lineCardinal(points, tension) {
8244 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
8245 }
8246 function d3_svg_lineHermite(points, tangents) {
8247 if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
8248 return d3_svg_lineLinear(points);
8249 }
8250 var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
8251 if (quad) {
8252 path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
8253 p0 = points[1];
8254 pi = 2;
8255 }
8256 if (tangents.length > 1) {
8257 t = tangents[1];
8258 p = points[pi];
8259 pi++;
8260 path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
8261 for (var i = 2; i < tangents.length; i++, pi++) {
8262 p = points[pi];
8263 t = tangents[i];
8264 path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
8265 }
8266 }
8267 if (quad) {
8268 var lp = points[pi];
8269 path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
8270 }
8271 return path;
8272 }
8273 function d3_svg_lineCardinalTangents(points, tension) {
8274 var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
8275 while (++i < n) {
8276 p0 = p1;
8277 p1 = p2;
8278 p2 = points[i];
8279 tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
8280 }
8281 return tangents;
8282 }
8283 function d3_svg_lineBasis(points) {
8284 if (points.length < 3) return d3_svg_lineLinear(points);
8285 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) ];
8286 points.push(points[n - 1]);
8287 while (++i <= n) {
8288 pi = points[i];
8289 px.shift();
8290 px.push(pi[0]);
8291 py.shift();
8292 py.push(pi[1]);
8293 d3_svg_lineBasisBezier(path, px, py);
8294 }
8295 points.pop();
8296 path.push("L", pi);
8297 return path.join("");
8298 }
8299 function d3_svg_lineBasisOpen(points) {
8300 if (points.length < 4) return d3_svg_lineLinear(points);
8301 var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
8302 while (++i < 3) {
8303 pi = points[i];
8304 px.push(pi[0]);
8305 py.push(pi[1]);
8306 }
8307 path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
8308 --i;
8309 while (++i < n) {
8310 pi = points[i];
8311 px.shift();
8312 px.push(pi[0]);
8313 py.shift();
8314 py.push(pi[1]);
8315 d3_svg_lineBasisBezier(path, px, py);
8316 }
8317 return path.join("");
8318 }
8319 function d3_svg_lineBasisClosed(points) {
8320 var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
8321 while (++i < 4) {
8322 pi = points[i % n];
8323 px.push(pi[0]);
8324 py.push(pi[1]);
8325 }
8326 path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
8327 --i;
8328 while (++i < m) {
8329 pi = points[i % n];
8330 px.shift();
8331 px.push(pi[0]);
8332 py.shift();
8333 py.push(pi[1]);
8334 d3_svg_lineBasisBezier(path, px, py);
8335 }
8336 return path.join("");
8337 }
8338 function d3_svg_lineBundle(points, tension) {
8339 var n = points.length - 1;
8340 if (n) {
8341 var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
8342 while (++i <= n) {
8343 p = points[i];
8344 t = i / n;
8345 p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
8346 p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
8347 }
8348 }
8349 return d3_svg_lineBasis(points);
8350 }
8351 function d3_svg_lineDot4(a, b) {
8352 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
8353 }
8354 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 ];
8355 function d3_svg_lineBasisBezier(path, x, y) {
8356 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));
8357 }
8358 function d3_svg_lineSlope(p0, p1) {
8359 return (p1[1] - p0[1]) / (p1[0] - p0[0]);
8360 }
8361 function d3_svg_lineFiniteDifferences(points) {
8362 var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
8363 while (++i < j) {
8364 m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
8365 }
8366 m[i] = d;
8367 return m;
8368 }
8369 function d3_svg_lineMonotoneTangents(points) {
8370 var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
8371 while (++i < j) {
8372 d = d3_svg_lineSlope(points[i], points[i + 1]);
8373 if (abs(d) < ε) {
8374 m[i] = m[i + 1] = 0;
8375 } else {
8376 a = m[i] / d;
8377 b = m[i + 1] / d;
8378 s = a * a + b * b;
8379 if (s > 9) {
8380 s = d * 3 / Math.sqrt(s);
8381 m[i] = s * a;
8382 m[i + 1] = s * b;
8383 }
8384 }
8385 }
8386 i = -1;
8387 while (++i <= j) {
8388 s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
8389 tangents.push([ s || 0, m[i] * s || 0 ]);
8390 }
8391 return tangents;
8392 }
8393 function d3_svg_lineMonotone(points) {
8394 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
8395 }
8396 d3.svg.line.radial = function() {
8397 var line = d3_svg_line(d3_svg_lineRadial);
8398 line.radius = line.x, delete line.x;
8399 line.angle = line.y, delete line.y;
8400 return line;
8401 };
8402 function d3_svg_lineRadial(points) {
8403 var point, i = -1, n = points.length, r, a;
8404 while (++i < n) {
8405 point = points[i];
8406 r = point[0];
8407 a = point[1] - halfπ;
8408 point[0] = r * Math.cos(a);
8409 point[1] = r * Math.sin(a);
8410 }
8411 return points;
8412 }
8413 function d3_svg_area(projection) {
8414 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;
8415 function area(data) {
8416 var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
8417 return x;
8418 } : d3_functor(x1), fy1 = y0 === y1 ? function() {
8419 return y;
8420 } : d3_functor(y1), x, y;
8421 function segment() {
8422 segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
8423 }
8424 while (++i < n) {
8425 if (defined.call(this, d = data[i], i)) {
8426 points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
8427 points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
8428 } else if (points0.length) {
8429 segment();
8430 points0 = [];
8431 points1 = [];
8432 }
8433 }
8434 if (points0.length) segment();
8435 return segments.length ? segments.join("") : null;
8436 }
8437 area.x = function(_) {
8438 if (!arguments.length) return x1;
8439 x0 = x1 = _;
8440 return area;
8441 };
8442 area.x0 = function(_) {
8443 if (!arguments.length) return x0;
8444 x0 = _;
8445 return area;
8446 };
8447 area.x1 = function(_) {
8448 if (!arguments.length) return x1;
8449 x1 = _;
8450 return area;
8451 };
8452 area.y = function(_) {
8453 if (!arguments.length) return y1;
8454 y0 = y1 = _;
8455 return area;
8456 };
8457 area.y0 = function(_) {
8458 if (!arguments.length) return y0;
8459 y0 = _;
8460 return area;
8461 };
8462 area.y1 = function(_) {
8463 if (!arguments.length) return y1;
8464 y1 = _;
8465 return area;
8466 };
8467 area.defined = function(_) {
8468 if (!arguments.length) return defined;
8469 defined = _;
8470 return area;
8471 };
8472 area.interpolate = function(_) {
8473 if (!arguments.length) return interpolateKey;
8474 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
8475 interpolateReverse = interpolate.reverse || interpolate;
8476 L = interpolate.closed ? "M" : "L";
8477 return area;
8478 };
8479 area.tension = function(_) {
8480 if (!arguments.length) return tension;
8481 tension = _;
8482 return area;
8483 };
8484 return area;
8485 }
8486 d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
8487 d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
8488 d3.svg.area = function() {
8489 return d3_svg_area(d3_identity);
8490 };
8491 d3.svg.area.radial = function() {
8492 var area = d3_svg_area(d3_svg_lineRadial);
8493 area.radius = area.x, delete area.x;
8494 area.innerRadius = area.x0, delete area.x0;
8495 area.outerRadius = area.x1, delete area.x1;
8496 area.angle = area.y, delete area.y;
8497 area.startAngle = area.y0, delete area.y0;
8498 area.endAngle = area.y1, delete area.y1;
8499 return area;
8500 };
8501 d3.svg.chord = function() {
8502 var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
8503 function chord(d, i) {
8504 var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
8505 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";
8506 }
8507 function subgroup(self, f, d, i) {
8508 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π;
8509 return {
8510 r: r,
8511 a0: a0,
8512 a1: a1,
8513 p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
8514 p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
8515 };
8516 }
8517 function equals(a, b) {
8518 return a.a0 == b.a0 && a.a1 == b.a1;
8519 }
8520 function arc(r, p, a) {
8521 return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
8522 }
8523 function curve(r0, p0, r1, p1) {
8524 return "Q 0,0 " + p1;
8525 }
8526 chord.radius = function(v) {
8527 if (!arguments.length) return radius;
8528 radius = d3_functor(v);
8529 return chord;
8530 };
8531 chord.source = function(v) {
8532 if (!arguments.length) return source;
8533 source = d3_functor(v);
8534 return chord;
8535 };
8536 chord.target = function(v) {
8537 if (!arguments.length) return target;
8538 target = d3_functor(v);
8539 return chord;
8540 };
8541 chord.startAngle = function(v) {
8542 if (!arguments.length) return startAngle;
8543 startAngle = d3_functor(v);
8544 return chord;
8545 };
8546 chord.endAngle = function(v) {
8547 if (!arguments.length) return endAngle;
8548 endAngle = d3_functor(v);
8549 return chord;
8550 };
8551 return chord;
8552 };
8553 function d3_svg_chordRadius(d) {
8554 return d.radius;
8555 }
8556 d3.svg.diagonal = function() {
8557 var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
8558 function diagonal(d, i) {
8559 var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
8560 x: p0.x,
8561 y: m
8562 }, {
8563 x: p3.x,
8564 y: m
8565 }, p3 ];
8566 p = p.map(projection);
8567 return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
8568 }
8569 diagonal.source = function(x) {
8570 if (!arguments.length) return source;
8571 source = d3_functor(x);
8572 return diagonal;
8573 };
8574 diagonal.target = function(x) {
8575 if (!arguments.length) return target;
8576 target = d3_functor(x);
8577 return diagonal;
8578 };
8579 diagonal.projection = function(x) {
8580 if (!arguments.length) return projection;
8581 projection = x;
8582 return diagonal;
8583 };
8584 return diagonal;
8585 };
8586 function d3_svg_diagonalProjection(d) {
8587 return [ d.x, d.y ];
8588 }
8589 d3.svg.diagonal.radial = function() {
8590 var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
8591 diagonal.projection = function(x) {
8592 return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
8593 };
8594 return diagonal;
8595 };
8596 function d3_svg_diagonalRadialProjection(projection) {
8597 return function() {
8598 var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
8599 return [ r * Math.cos(a), r * Math.sin(a) ];
8600 };
8601 }
8602 d3.svg.symbol = function() {
8603 var type = d3_svg_symbolType, size = d3_svg_symbolSize;
8604 function symbol(d, i) {
8605 return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
8606 }
8607 symbol.type = function(x) {
8608 if (!arguments.length) return type;
8609 type = d3_functor(x);
8610 return symbol;
8611 };
8612 symbol.size = function(x) {
8613 if (!arguments.length) return size;
8614 size = d3_functor(x);
8615 return symbol;
8616 };
8617 return symbol;
8618 };
8619 function d3_svg_symbolSize() {
8620 return 64;
8621 }
8622 function d3_svg_symbolType() {
8623 return "circle";
8624 }
8625 function d3_svg_symbolCircle(size) {
8626 var r = Math.sqrt(size / π);
8627 return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
8628 }
8629 var d3_svg_symbols = d3.map({
8630 circle: d3_svg_symbolCircle,
8631 cross: function(size) {
8632 var r = Math.sqrt(size / 5) / 2;
8633 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";
8634 },
8635 diamond: function(size) {
8636 var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
8637 return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
8638 },
8639 square: function(size) {
8640 var r = Math.sqrt(size) / 2;
8641 return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
8642 },
8643 "triangle-down": function(size) {
8644 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8645 return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
8646 },
8647 "triangle-up": function(size) {
8648 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8649 return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
8650 }
8651 });
8652 d3.svg.symbolTypes = d3_svg_symbols.keys();
8653 var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
8654 d3_selectionPrototype.transition = function(name) {
8655 var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
8656 time: Date.now(),
8657 ease: d3_ease_cubicInOut,
8658 delay: 0,
8659 duration: 250
8660 };
8661 for (var j = -1, m = this.length; ++j < m; ) {
8662 subgroups.push(subgroup = []);
8663 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8664 if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
8665 subgroup.push(node);
8666 }
8667 }
8668 return d3_transition(subgroups, ns, id);
8669 };
8670 d3_selectionPrototype.interrupt = function(name) {
8671 return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
8672 };
8673 var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
8674 function d3_selection_interruptNS(ns) {
8675 return function() {
8676 var lock, activeId, active;
8677 if ((lock = this[ns]) && (active = lock[activeId = lock.active])) {
8678 active.timer.c = null;
8679 active.timer.t = NaN;
8680 if (--lock.count) delete lock[activeId]; else delete this[ns];
8681 lock.active += .5;
8682 active.event && active.event.interrupt.call(this, this.__data__, active.index);
8683 }
8684 };
8685 }
8686 function d3_transition(groups, ns, id) {
8687 d3_subclass(groups, d3_transitionPrototype);
8688 groups.namespace = ns;
8689 groups.id = id;
8690 return groups;
8691 }
8692 var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
8693 d3_transitionPrototype.call = d3_selectionPrototype.call;
8694 d3_transitionPrototype.empty = d3_selectionPrototype.empty;
8695 d3_transitionPrototype.node = d3_selectionPrototype.node;
8696 d3_transitionPrototype.size = d3_selectionPrototype.size;
8697 d3.transition = function(selection, name) {
8698 return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
8699 };
8700 d3.transition.prototype = d3_transitionPrototype;
8701 d3_transitionPrototype.select = function(selector) {
8702 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
8703 selector = d3_selection_selector(selector);
8704 for (var j = -1, m = this.length; ++j < m; ) {
8705 subgroups.push(subgroup = []);
8706 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8707 if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
8708 if ("__data__" in node) subnode.__data__ = node.__data__;
8709 d3_transitionNode(subnode, i, ns, id, node[ns][id]);
8710 subgroup.push(subnode);
8711 } else {
8712 subgroup.push(null);
8713 }
8714 }
8715 }
8716 return d3_transition(subgroups, ns, id);
8717 };
8718 d3_transitionPrototype.selectAll = function(selector) {
8719 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
8720 selector = d3_selection_selectorAll(selector);
8721 for (var j = -1, m = this.length; ++j < m; ) {
8722 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8723 if (node = group[i]) {
8724 transition = node[ns][id];
8725 subnodes = selector.call(node, node.__data__, i, j);
8726 subgroups.push(subgroup = []);
8727 for (var k = -1, o = subnodes.length; ++k < o; ) {
8728 if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
8729 subgroup.push(subnode);
8730 }
8731 }
8732 }
8733 }
8734 return d3_transition(subgroups, ns, id);
8735 };
8736 d3_transitionPrototype.filter = function(filter) {
8737 var subgroups = [], subgroup, group, node;
8738 if (typeof filter !== "function") filter = d3_selection_filter(filter);
8739 for (var j = 0, m = this.length; j < m; j++) {
8740 subgroups.push(subgroup = []);
8741 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
8742 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
8743 subgroup.push(node);
8744 }
8745 }
8746 }
8747 return d3_transition(subgroups, this.namespace, this.id);
8748 };
8749 d3_transitionPrototype.tween = function(name, tween) {
8750 var id = this.id, ns = this.namespace;
8751 if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
8752 return d3_selection_each(this, tween == null ? function(node) {
8753 node[ns][id].tween.remove(name);
8754 } : function(node) {
8755 node[ns][id].tween.set(name, tween);
8756 });
8757 };
8758 function d3_transition_tween(groups, name, value, tween) {
8759 var id = groups.id, ns = groups.namespace;
8760 return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
8761 node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
8762 } : (value = tween(value), function(node) {
8763 node[ns][id].tween.set(name, value);
8764 }));
8765 }
8766 d3_transitionPrototype.attr = function(nameNS, value) {
8767 if (arguments.length < 2) {
8768 for (value in nameNS) this.attr(value, nameNS[value]);
8769 return this;
8770 }
8771 var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
8772 function attrNull() {
8773 this.removeAttribute(name);
8774 }
8775 function attrNullNS() {
8776 this.removeAttributeNS(name.space, name.local);
8777 }
8778 function attrTween(b) {
8779 return b == null ? attrNull : (b += "", function() {
8780 var a = this.getAttribute(name), i;
8781 return a !== b && (i = interpolate(a, b), function(t) {
8782 this.setAttribute(name, i(t));
8783 });
8784 });
8785 }
8786 function attrTweenNS(b) {
8787 return b == null ? attrNullNS : (b += "", function() {
8788 var a = this.getAttributeNS(name.space, name.local), i;
8789 return a !== b && (i = interpolate(a, b), function(t) {
8790 this.setAttributeNS(name.space, name.local, i(t));
8791 });
8792 });
8793 }
8794 return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
8795 };
8796 d3_transitionPrototype.attrTween = function(nameNS, tween) {
8797 var name = d3.ns.qualify(nameNS);
8798 function attrTween(d, i) {
8799 var f = tween.call(this, d, i, this.getAttribute(name));
8800 return f && function(t) {
8801 this.setAttribute(name, f(t));
8802 };
8803 }
8804 function attrTweenNS(d, i) {
8805 var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
8806 return f && function(t) {
8807 this.setAttributeNS(name.space, name.local, f(t));
8808 };
8809 }
8810 return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
8811 };
8812 d3_transitionPrototype.style = function(name, value, priority) {
8813 var n = arguments.length;
8814 if (n < 3) {
8815 if (typeof name !== "string") {
8816 if (n < 2) value = "";
8817 for (priority in name) this.style(priority, name[priority], value);
8818 return this;
8819 }
8820 priority = "";
8821 }
8822 function styleNull() {
8823 this.style.removeProperty(name);
8824 }
8825 function styleString(b) {
8826 return b == null ? styleNull : (b += "", function() {
8827 var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
8828 return a !== b && (i = d3_interpolate(a, b), function(t) {
8829 this.style.setProperty(name, i(t), priority);
8830 });
8831 });
8832 }
8833 return d3_transition_tween(this, "style." + name, value, styleString);
8834 };
8835 d3_transitionPrototype.styleTween = function(name, tween, priority) {
8836 if (arguments.length < 3) priority = "";
8837 function styleTween(d, i) {
8838 var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
8839 return f && function(t) {
8840 this.style.setProperty(name, f(t), priority);
8841 };
8842 }
8843 return this.tween("style." + name, styleTween);
8844 };
8845 d3_transitionPrototype.text = function(value) {
8846 return d3_transition_tween(this, "text", value, d3_transition_text);
8847 };
8848 function d3_transition_text(b) {
8849 if (b == null) b = "";
8850 return function() {
8851 this.textContent = b;
8852 };
8853 }
8854 d3_transitionPrototype.remove = function() {
8855 var ns = this.namespace;
8856 return this.each("end.transition", function() {
8857 var p;
8858 if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
8859 });
8860 };
8861 d3_transitionPrototype.ease = function(value) {
8862 var id = this.id, ns = this.namespace;
8863 if (arguments.length < 1) return this.node()[ns][id].ease;
8864 if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
8865 return d3_selection_each(this, function(node) {
8866 node[ns][id].ease = value;
8867 });
8868 };
8869 d3_transitionPrototype.delay = function(value) {
8870 var id = this.id, ns = this.namespace;
8871 if (arguments.length < 1) return this.node()[ns][id].delay;
8872 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8873 node[ns][id].delay = +value.call(node, node.__data__, i, j);
8874 } : (value = +value, function(node) {
8875 node[ns][id].delay = value;
8876 }));
8877 };
8878 d3_transitionPrototype.duration = function(value) {
8879 var id = this.id, ns = this.namespace;
8880 if (arguments.length < 1) return this.node()[ns][id].duration;
8881 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8882 node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
8883 } : (value = Math.max(1, value), function(node) {
8884 node[ns][id].duration = value;
8885 }));
8886 };
8887 d3_transitionPrototype.each = function(type, listener) {
8888 var id = this.id, ns = this.namespace;
8889 if (arguments.length < 2) {
8890 var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
8891 try {
8892 d3_transitionInheritId = id;
8893 d3_selection_each(this, function(node, i, j) {
8894 d3_transitionInherit = node[ns][id];
8895 type.call(node, node.__data__, i, j);
8896 });
8897 } finally {
8898 d3_transitionInherit = inherit;
8899 d3_transitionInheritId = inheritId;
8900 }
8901 } else {
8902 d3_selection_each(this, function(node) {
8903 var transition = node[ns][id];
8904 (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
8905 });
8906 }
8907 return this;
8908 };
8909 d3_transitionPrototype.transition = function() {
8910 var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
8911 for (var j = 0, m = this.length; j < m; j++) {
8912 subgroups.push(subgroup = []);
8913 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
8914 if (node = group[i]) {
8915 transition = node[ns][id0];
8916 d3_transitionNode(node, i, ns, id1, {
8917 time: transition.time,
8918 ease: transition.ease,
8919 delay: transition.delay + transition.duration,
8920 duration: transition.duration
8921 });
8922 }
8923 subgroup.push(node);
8924 }
8925 }
8926 return d3_transition(subgroups, ns, id1);
8927 };
8928 function d3_transitionNamespace(name) {
8929 return name == null ? "__transition__" : "__transition_" + name + "__";
8930 }
8931 function d3_transitionNode(node, i, ns, id, inherit) {
8932 var lock = node[ns] || (node[ns] = {
8933 active: 0,
8934 count: 0
8935 }), transition = lock[id], time, timer, duration, ease, tweens;
8936 function schedule(elapsed) {
8937 var delay = transition.delay;
8938 timer.t = delay + time;
8939 if (delay <= elapsed) return start(elapsed - delay);
8940 timer.c = start;
8941 }
8942 function start(elapsed) {
8943 var activeId = lock.active, active = lock[activeId];
8944 if (active) {
8945 active.timer.c = null;
8946 active.timer.t = NaN;
8947 --lock.count;
8948 delete lock[activeId];
8949 active.event && active.event.interrupt.call(node, node.__data__, active.index);
8950 }
8951 for (var cancelId in lock) {
8952 if (+cancelId < id) {
8953 var cancel = lock[cancelId];
8954 cancel.timer.c = null;
8955 cancel.timer.t = NaN;
8956 --lock.count;
8957 delete lock[cancelId];
8958 }
8959 }
8960 timer.c = tick;
8961 d3_timer(function() {
8962 if (timer.c && tick(elapsed || 1)) {
8963 timer.c = null;
8964 timer.t = NaN;
8965 }
8966 return 1;
8967 }, 0, time);
8968 lock.active = id;
8969 transition.event && transition.event.start.call(node, node.__data__, i);
8970 tweens = [];
8971 transition.tween.forEach(function(key, value) {
8972 if (value = value.call(node, node.__data__, i)) {
8973 tweens.push(value);
8974 }
8975 });
8976 ease = transition.ease;
8977 duration = transition.duration;
8978 }
8979 function tick(elapsed) {
8980 var t = elapsed / duration, e = ease(t), n = tweens.length;
8981 while (n > 0) {
8982 tweens[--n].call(node, e);
8983 }
8984 if (t >= 1) {
8985 transition.event && transition.event.end.call(node, node.__data__, i);
8986 if (--lock.count) delete lock[id]; else delete node[ns];
8987 return 1;
8988 }
8989 }
8990 if (!transition) {
8991 time = inherit.time;
8992 timer = d3_timer(schedule, 0, time);
8993 transition = lock[id] = {
8994 tween: new d3_Map(),
8995 time: time,
8996 timer: timer,
8997 delay: inherit.delay,
8998 duration: inherit.duration,
8999 ease: inherit.ease,
9000 index: i
9001 };
9002 inherit = null;
9003 ++lock.count;
9004 }
9005 }
9006 d3.svg.axis = function() {
9007 var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
9008 function axis(g) {
9009 g.each(function() {
9010 var g = d3.select(this);
9011 var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
9012 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;
9013 var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
9014 d3.transition(path));
9015 tickEnter.append("line");
9016 tickEnter.append("text");
9017 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;
9018 if (orient === "bottom" || orient === "top") {
9019 tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
9020 text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
9021 pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
9022 } else {
9023 tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
9024 text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
9025 pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
9026 }
9027 lineEnter.attr(y2, sign * innerTickSize);
9028 textEnter.attr(y1, sign * tickSpacing);
9029 lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
9030 textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
9031 if (scale1.rangeBand) {
9032 var x = scale1, dx = x.rangeBand() / 2;
9033 scale0 = scale1 = function(d) {
9034 return x(d) + dx;
9035 };
9036 } else if (scale0.rangeBand) {
9037 scale0 = scale1;
9038 } else {
9039 tickExit.call(tickTransform, scale1, scale0);
9040 }
9041 tickEnter.call(tickTransform, scale0, scale1);
9042 tickUpdate.call(tickTransform, scale1, scale1);
9043 });
9044 }
9045 axis.scale = function(x) {
9046 if (!arguments.length) return scale;
9047 scale = x;
9048 return axis;
9049 };
9050 axis.orient = function(x) {
9051 if (!arguments.length) return orient;
9052 orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
9053 return axis;
9054 };
9055 axis.ticks = function() {
9056 if (!arguments.length) return tickArguments_;
9057 tickArguments_ = d3_array(arguments);
9058 return axis;
9059 };
9060 axis.tickValues = function(x) {
9061 if (!arguments.length) return tickValues;
9062 tickValues = x;
9063 return axis;
9064 };
9065 axis.tickFormat = function(x) {
9066 if (!arguments.length) return tickFormat_;
9067 tickFormat_ = x;
9068 return axis;
9069 };
9070 axis.tickSize = function(x) {
9071 var n = arguments.length;
9072 if (!n) return innerTickSize;
9073 innerTickSize = +x;
9074 outerTickSize = +arguments[n - 1];
9075 return axis;
9076 };
9077 axis.innerTickSize = function(x) {
9078 if (!arguments.length) return innerTickSize;
9079 innerTickSize = +x;
9080 return axis;
9081 };
9082 axis.outerTickSize = function(x) {
9083 if (!arguments.length) return outerTickSize;
9084 outerTickSize = +x;
9085 return axis;
9086 };
9087 axis.tickPadding = function(x) {
9088 if (!arguments.length) return tickPadding;
9089 tickPadding = +x;
9090 return axis;
9091 };
9092 axis.tickSubdivide = function() {
9093 return arguments.length && axis;
9094 };
9095 return axis;
9096 };
9097 var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
9098 top: 1,
9099 right: 1,
9100 bottom: 1,
9101 left: 1
9102 };
9103 function d3_svg_axisX(selection, x0, x1) {
9104 selection.attr("transform", function(d) {
9105 var v0 = x0(d);
9106 return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
9107 });
9108 }
9109 function d3_svg_axisY(selection, y0, y1) {
9110 selection.attr("transform", function(d) {
9111 var v0 = y0(d);
9112 return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
9113 });
9114 }
9115 d3.svg.brush = function() {
9116 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];
9117 function brush(g) {
9118 g.each(function() {
9119 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);
9120 var background = g.selectAll(".background").data([ 0 ]);
9121 background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
9122 g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
9123 var resize = g.selectAll(".resize").data(resizes, d3_identity);
9124 resize.exit().remove();
9125 resize.enter().append("g").attr("class", function(d) {
9126 return "resize " + d;
9127 }).style("cursor", function(d) {
9128 return d3_svg_brushCursor[d];
9129 }).append("rect").attr("x", function(d) {
9130 return /[ew]$/.test(d) ? -3 : null;
9131 }).attr("y", function(d) {
9132 return /^[ns]/.test(d) ? -3 : null;
9133 }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
9134 resize.style("display", brush.empty() ? "none" : null);
9135 var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
9136 if (x) {
9137 range = d3_scaleRange(x);
9138 backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
9139 redrawX(gUpdate);
9140 }
9141 if (y) {
9142 range = d3_scaleRange(y);
9143 backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
9144 redrawY(gUpdate);
9145 }
9146 redraw(gUpdate);
9147 });
9148 }
9149 brush.event = function(g) {
9150 g.each(function() {
9151 var event_ = event.of(this, arguments), extent1 = {
9152 x: xExtent,
9153 y: yExtent,
9154 i: xExtentDomain,
9155 j: yExtentDomain
9156 }, extent0 = this.__chart__ || extent1;
9157 this.__chart__ = extent1;
9158 if (d3_transitionInheritId) {
9159 d3.select(this).transition().each("start.brush", function() {
9160 xExtentDomain = extent0.i;
9161 yExtentDomain = extent0.j;
9162 xExtent = extent0.x;
9163 yExtent = extent0.y;
9164 event_({
9165 type: "brushstart"
9166 });
9167 }).tween("brush:brush", function() {
9168 var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
9169 xExtentDomain = yExtentDomain = null;
9170 return function(t) {
9171 xExtent = extent1.x = xi(t);
9172 yExtent = extent1.y = yi(t);
9173 event_({
9174 type: "brush",
9175 mode: "resize"
9176 });
9177 };
9178 }).each("end.brush", function() {
9179 xExtentDomain = extent1.i;
9180 yExtentDomain = extent1.j;
9181 event_({
9182 type: "brush",
9183 mode: "resize"
9184 });
9185 event_({
9186 type: "brushend"
9187 });
9188 });
9189 } else {
9190 event_({
9191 type: "brushstart"
9192 });
9193 event_({
9194 type: "brush",
9195 mode: "resize"
9196 });
9197 event_({
9198 type: "brushend"
9199 });
9200 }
9201 });
9202 };
9203 function redraw(g) {
9204 g.selectAll(".resize").attr("transform", function(d) {
9205 return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
9206 });
9207 }
9208 function redrawX(g) {
9209 g.select(".extent").attr("x", xExtent[0]);
9210 g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
9211 }
9212 function redrawY(g) {
9213 g.select(".extent").attr("y", yExtent[0]);
9214 g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
9215 }
9216 function brushstart() {
9217 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;
9218 var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
9219 if (d3.event.changedTouches) {
9220 w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
9221 } else {
9222 w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
9223 }
9224 g.interrupt().selectAll("*").interrupt();
9225 if (dragging) {
9226 origin[0] = xExtent[0] - origin[0];
9227 origin[1] = yExtent[0] - origin[1];
9228 } else if (resizing) {
9229 var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
9230 offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
9231 origin[0] = xExtent[ex];
9232 origin[1] = yExtent[ey];
9233 } else if (d3.event.altKey) center = origin.slice();
9234 g.style("pointer-events", "none").selectAll(".resize").style("display", null);
9235 d3.select("body").style("cursor", eventTarget.style("cursor"));
9236 event_({
9237 type: "brushstart"
9238 });
9239 brushmove();
9240 function keydown() {
9241 if (d3.event.keyCode == 32) {
9242 if (!dragging) {
9243 center = null;
9244 origin[0] -= xExtent[1];
9245 origin[1] -= yExtent[1];
9246 dragging = 2;
9247 }
9248 d3_eventPreventDefault();
9249 }
9250 }
9251 function keyup() {
9252 if (d3.event.keyCode == 32 && dragging == 2) {
9253 origin[0] += xExtent[1];
9254 origin[1] += yExtent[1];
9255 dragging = 0;
9256 d3_eventPreventDefault();
9257 }
9258 }
9259 function brushmove() {
9260 var point = d3.mouse(target), moved = false;
9261 if (offset) {
9262 point[0] += offset[0];
9263 point[1] += offset[1];
9264 }
9265 if (!dragging) {
9266 if (d3.event.altKey) {
9267 if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
9268 origin[0] = xExtent[+(point[0] < center[0])];
9269 origin[1] = yExtent[+(point[1] < center[1])];
9270 } else center = null;
9271 }
9272 if (resizingX && move1(point, x, 0)) {
9273 redrawX(g);
9274 moved = true;
9275 }
9276 if (resizingY && move1(point, y, 1)) {
9277 redrawY(g);
9278 moved = true;
9279 }
9280 if (moved) {
9281 redraw(g);
9282 event_({
9283 type: "brush",
9284 mode: dragging ? "move" : "resize"
9285 });
9286 }
9287 }
9288 function move1(point, scale, i) {
9289 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;
9290 if (dragging) {
9291 r0 -= position;
9292 r1 -= size + position;
9293 }
9294 min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
9295 if (dragging) {
9296 max = (min += position) + size;
9297 } else {
9298 if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
9299 if (position < min) {
9300 max = min;
9301 min = position;
9302 } else {
9303 max = position;
9304 }
9305 }
9306 if (extent[0] != min || extent[1] != max) {
9307 if (i) yExtentDomain = null; else xExtentDomain = null;
9308 extent[0] = min;
9309 extent[1] = max;
9310 return true;
9311 }
9312 }
9313 function brushend() {
9314 brushmove();
9315 g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
9316 d3.select("body").style("cursor", null);
9317 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);
9318 dragRestore();
9319 event_({
9320 type: "brushend"
9321 });
9322 }
9323 }
9324 brush.x = function(z) {
9325 if (!arguments.length) return x;
9326 x = z;
9327 resizes = d3_svg_brushResizes[!x << 1 | !y];
9328 return brush;
9329 };
9330 brush.y = function(z) {
9331 if (!arguments.length) return y;
9332 y = z;
9333 resizes = d3_svg_brushResizes[!x << 1 | !y];
9334 return brush;
9335 };
9336 brush.clamp = function(z) {
9337 if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
9338 if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
9339 return brush;
9340 };
9341 brush.extent = function(z) {
9342 var x0, x1, y0, y1, t;
9343 if (!arguments.length) {
9344 if (x) {
9345 if (xExtentDomain) {
9346 x0 = xExtentDomain[0], x1 = xExtentDomain[1];
9347 } else {
9348 x0 = xExtent[0], x1 = xExtent[1];
9349 if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
9350 if (x1 < x0) t = x0, x0 = x1, x1 = t;
9351 }
9352 }
9353 if (y) {
9354 if (yExtentDomain) {
9355 y0 = yExtentDomain[0], y1 = yExtentDomain[1];
9356 } else {
9357 y0 = yExtent[0], y1 = yExtent[1];
9358 if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
9359 if (y1 < y0) t = y0, y0 = y1, y1 = t;
9360 }
9361 }
9362 return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
9363 }
9364 if (x) {
9365 x0 = z[0], x1 = z[1];
9366 if (y) x0 = x0[0], x1 = x1[0];
9367 xExtentDomain = [ x0, x1 ];
9368 if (x.invert) x0 = x(x0), x1 = x(x1);
9369 if (x1 < x0) t = x0, x0 = x1, x1 = t;
9370 if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
9371 }
9372 if (y) {
9373 y0 = z[0], y1 = z[1];
9374 if (x) y0 = y0[1], y1 = y1[1];
9375 yExtentDomain = [ y0, y1 ];
9376 if (y.invert) y0 = y(y0), y1 = y(y1);
9377 if (y1 < y0) t = y0, y0 = y1, y1 = t;
9378 if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
9379 }
9380 return brush;
9381 };
9382 brush.clear = function() {
9383 if (!brush.empty()) {
9384 xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
9385 xExtentDomain = yExtentDomain = null;
9386 }
9387 return brush;
9388 };
9389 brush.empty = function() {
9390 return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
9391 };
9392 return d3.rebind(brush, event, "on");
9393 };
9394 var d3_svg_brushCursor = {
9395 n: "ns-resize",
9396 e: "ew-resize",
9397 s: "ns-resize",
9398 w: "ew-resize",
9399 nw: "nwse-resize",
9400 ne: "nesw-resize",
9401 se: "nwse-resize",
9402 sw: "nesw-resize"
9403 };
9404 var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
9405 var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
9406 var d3_time_formatUtc = d3_time_format.utc;
9407 var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
9408 d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
9409 function d3_time_formatIsoNative(date) {
9410 return date.toISOString();
9411 }
9412 d3_time_formatIsoNative.parse = function(string) {
9413 var date = new Date(string);
9414 return isNaN(date) ? null : date;
9415 };
9416 d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
9417 d3_time.second = d3_time_interval(function(date) {
9418 return new d3_date(Math.floor(date / 1e3) * 1e3);
9419 }, function(date, offset) {
9420 date.setTime(date.getTime() + Math.floor(offset) * 1e3);
9421 }, function(date) {
9422 return date.getSeconds();
9423 });
9424 d3_time.seconds = d3_time.second.range;
9425 d3_time.seconds.utc = d3_time.second.utc.range;
9426 d3_time.minute = d3_time_interval(function(date) {
9427 return new d3_date(Math.floor(date / 6e4) * 6e4);
9428 }, function(date, offset) {
9429 date.setTime(date.getTime() + Math.floor(offset) * 6e4);
9430 }, function(date) {
9431 return date.getMinutes();
9432 });
9433 d3_time.minutes = d3_time.minute.range;
9434 d3_time.minutes.utc = d3_time.minute.utc.range;
9435 d3_time.hour = d3_time_interval(function(date) {
9436 var timezone = date.getTimezoneOffset() / 60;
9437 return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
9438 }, function(date, offset) {
9439 date.setTime(date.getTime() + Math.floor(offset) * 36e5);
9440 }, function(date) {
9441 return date.getHours();
9442 });
9443 d3_time.hours = d3_time.hour.range;
9444 d3_time.hours.utc = d3_time.hour.utc.range;
9445 d3_time.month = d3_time_interval(function(date) {
9446 date = d3_time.day(date);
9447 date.setDate(1);
9448 return date;
9449 }, function(date, offset) {
9450 date.setMonth(date.getMonth() + offset);
9451 }, function(date) {
9452 return date.getMonth();
9453 });
9454 d3_time.months = d3_time.month.range;
9455 d3_time.months.utc = d3_time.month.utc.range;
9456 function d3_time_scale(linear, methods, format) {
9457 function scale(x) {
9458 return linear(x);
9459 }
9460 scale.invert = function(x) {
9461 return d3_time_scaleDate(linear.invert(x));
9462 };
9463 scale.domain = function(x) {
9464 if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
9465 linear.domain(x);
9466 return scale;
9467 };
9468 function tickMethod(extent, count) {
9469 var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
9470 return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
9471 return d / 31536e6;
9472 }), 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];
9473 }
9474 scale.nice = function(interval, skip) {
9475 var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
9476 if (method) interval = method[0], skip = method[1];
9477 function skipped(date) {
9478 return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
9479 }
9480 return scale.domain(d3_scale_nice(domain, skip > 1 ? {
9481 floor: function(date) {
9482 while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
9483 return date;
9484 },
9485 ceil: function(date) {
9486 while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
9487 return date;
9488 }
9489 } : interval));
9490 };
9491 scale.ticks = function(interval, skip) {
9492 var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
9493 range: interval
9494 }, skip ];
9495 if (method) interval = method[0], skip = method[1];
9496 return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
9497 };
9498 scale.tickFormat = function() {
9499 return format;
9500 };
9501 scale.copy = function() {
9502 return d3_time_scale(linear.copy(), methods, format);
9503 };
9504 return d3_scale_linearRebind(scale, linear);
9505 }
9506 function d3_time_scaleDate(t) {
9507 return new Date(t);
9508 }
9509 var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
9510 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 ] ];
9511 var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
9512 return d.getMilliseconds();
9513 } ], [ ":%S", function(d) {
9514 return d.getSeconds();
9515 } ], [ "%I:%M", function(d) {
9516 return d.getMinutes();
9517 } ], [ "%I %p", function(d) {
9518 return d.getHours();
9519 } ], [ "%a %d", function(d) {
9520 return d.getDay() && d.getDate() != 1;
9521 } ], [ "%b %d", function(d) {
9522 return d.getDate() != 1;
9523 } ], [ "%B", function(d) {
9524 return d.getMonth();
9525 } ], [ "%Y", d3_true ] ]);
9526 var d3_time_scaleMilliseconds = {
9527 range: function(start, stop, step) {
9528 return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
9529 },
9530 floor: d3_identity,
9531 ceil: d3_identity
9532 };
9533 d3_time_scaleLocalMethods.year = d3_time.year;
9534 d3_time.scale = function() {
9535 return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
9536 };
9537 var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
9538 return [ m[0].utc, m[1] ];
9539 });
9540 var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
9541 return d.getUTCMilliseconds();
9542 } ], [ ":%S", function(d) {
9543 return d.getUTCSeconds();
9544 } ], [ "%I:%M", function(d) {
9545 return d.getUTCMinutes();
9546 } ], [ "%I %p", function(d) {
9547 return d.getUTCHours();
9548 } ], [ "%a %d", function(d) {
9549 return d.getUTCDay() && d.getUTCDate() != 1;
9550 } ], [ "%b %d", function(d) {
9551 return d.getUTCDate() != 1;
9552 } ], [ "%B", function(d) {
9553 return d.getUTCMonth();
9554 } ], [ "%Y", d3_true ] ]);
9555 d3_time_scaleUtcMethods.year = d3_time.year.utc;
9556 d3_time.scale.utc = function() {
9557 return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
9558 };
9559 d3.text = d3_xhrType(function(request) {
9560 return request.responseText;
9561 });
9562 d3.json = function(url, callback) {
9563 return d3_xhr(url, "application/json", d3_json, callback);
9564 };
9565 function d3_json(request) {
9566 return JSON.parse(request.responseText);
9567 }
9568 d3.html = function(url, callback) {
9569 return d3_xhr(url, "text/html", d3_html, callback);
9570 };
9571 function d3_html(request) {
9572 var range = d3_document.createRange();
9573 range.selectNode(d3_document.body);
9574 return range.createContextualFragment(request.responseText);
9575 }
9576 d3.xml = d3_xhrType(function(request) {
9577 return request.responseXML;
9578 });
9579 if (typeof define === "function" && define.amd) this.d3 = d3, define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
9580}();