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