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