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