comparison templates/lib/d3.v3.js @ 0:cce6989ed423

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