5 var d3_arraySlice = [].slice, d3_array =
function(list) {
6 return d3_arraySlice.call(list);
8 var d3_document = this.document;
9 function d3_documentElement(node) {
10 return node && (node.ownerDocument || node.document || node).documentElement;
12 function d3_window(node) {
13 return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
17 d3_array(d3_document.documentElement.childNodes)[0].nodeType;
19 d3_array =
function(list) {
20 var i = list.length, array =
new Array(i);
21 while (i--) array[i] = list[i];
26 if (!Date.now) Date.now =
function() {
31 d3_document.createElement(
"DIV").style.setProperty(
"opacity", 0,
"");
33 var d3_element_prototype = this.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = this.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
34 d3_element_prototype.setAttribute =
function(name, value) {
35 d3_element_setAttribute.call(
this, name, value +
"");
37 d3_element_prototype.setAttributeNS =
function(space, local, value) {
38 d3_element_setAttributeNS.call(
this, space, local, value +
"");
40 d3_style_prototype.setProperty =
function(name, value, priority) {
41 d3_style_setProperty.call(
this, name, value +
"", priority);
45 d3.ascending = d3_ascending;
46 function d3_ascending(a, b) {
47 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
49 d3.descending =
function(a, b) {
50 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
52 d3.min =
function(array, f) {
53 var i = -1, n = array.length, a, b;
54 if (arguments.length === 1) {
55 while (++i < n)
if ((b = array[i]) != null && b >= b) {
59 while (++i < n)
if ((b = array[i]) != null && a > b) a = b;
61 while (++i < n)
if ((b = f.call(array, array[i], i)) != null && b >= b) {
65 while (++i < n)
if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
69 d3.max =
function(array, f) {
70 var i = -1, n = array.length, a, b;
71 if (arguments.length === 1) {
72 while (++i < n)
if ((b = array[i]) != null && b >= b) {
76 while (++i < n)
if ((b = array[i]) != null && b > a) a = b;
78 while (++i < n)
if ((b = f.call(array, array[i], i)) != null && b >= b) {
82 while (++i < n)
if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
86 d3.extent =
function(array, f) {
87 var i = -1, n = array.length, a, b, c;
88 if (arguments.length === 1) {
89 while (++i < n)
if ((b = array[i]) != null && b >= b) {
93 while (++i < n)
if ((b = array[i]) != null) {
98 while (++i < n)
if ((b = f.call(array, array[i], i)) != null && b >= b) {
102 while (++i < n)
if ((b = f.call(array, array[i], i)) != null) {
109 function d3_number(x) {
110 return x === null ? NaN : +x;
112 function d3_numeric(x) {
115 d3.sum =
function(array, f) {
116 var s = 0, n = array.length, a, i = -1;
117 if (arguments.length === 1) {
118 while (++i < n)
if (d3_numeric(a = +array[i])) s += a;
120 while (++i < n)
if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
124 d3.mean =
function(array, f) {
125 var s = 0, n = array.length, a, i = -1, j = n;
126 if (arguments.length === 1) {
127 while (++i < n)
if (d3_numeric(a = d3_number(array[i]))) s += a;
else --j;
129 while (++i < n)
if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a;
else --j;
133 d3.quantile =
function(values, p) {
134 var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
135 return e ? v + e * (values[h] - v) : v;
137 d3.median =
function(array, f) {
138 var numbers = [], n = array.length, a, i = -1;
139 if (arguments.length === 1) {
140 while (++i < n)
if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
142 while (++i < n)
if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
144 if (numbers.length)
return d3.quantile(numbers.sort(d3_ascending), .5);
146 d3.variance =
function(array, f) {
147 var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
148 if (arguments.length === 1) {
150 if (d3_numeric(a = d3_number(array[i]))) {
158 if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
165 if (j > 1)
return s / (j - 1);
167 d3.deviation =
function() {
168 var v = d3.variance.apply(
this, arguments);
169 return v ? Math.sqrt(v) : v;
171 function d3_bisector(compare) {
173 left:
function(a, x, lo, hi) {
174 if (arguments.length < 3) lo = 0;
175 if (arguments.length < 4) hi = a.length;
177 var mid = lo + hi >>> 1;
178 if (compare(a[mid], x) < 0) lo = mid + 1;
else hi = mid;
182 right:
function(a, x, lo, hi) {
183 if (arguments.length < 3) lo = 0;
184 if (arguments.length < 4) hi = a.length;
186 var mid = lo + hi >>> 1;
187 if (compare(a[mid], x) > 0) hi = mid;
else lo = mid + 1;
193 var d3_bisect = d3_bisector(d3_ascending);
194 d3.bisectLeft = d3_bisect.left;
195 d3.bisect = d3.bisectRight = d3_bisect.right;
196 d3.bisector =
function(f) {
197 return d3_bisector(f.length === 1 ?
function(d, x) {
198 return d3_ascending(f(d), x);
201 d3.shuffle =
function(array, i0, i1) {
202 if ((m = arguments.length) < 3) {
206 var m = i1 - i0, t, i;
208 i = Math.random() * m-- | 0;
209 t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
213 d3.permute =
function(array, indexes) {
214 var i = indexes.length, permutes =
new Array(i);
215 while (i--) permutes[i] = array[indexes[i]];
218 d3.pairs =
function(array) {
219 var i = 0, n = array.length - 1, p0, p1 = array[0], pairs =
new Array(n < 0 ? 0 : n);
220 while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
223 d3.zip =
function() {
224 if (!(n = arguments.length))
return [];
225 for (var i = -1, m = d3.min(arguments, d3_zipLength), zips =
new Array(m); ++i < m; ) {
226 for (var j = -1, n, zip = zips[i] =
new Array(n); ++j < n; ) {
227 zip[j] = arguments[j][i];
232 function d3_zipLength(d) {
235 d3.transpose =
function(matrix) {
236 return d3.zip.apply(d3, matrix);
238 d3.keys =
function(map) {
240 for (var key in map) keys.push(key);
243 d3.values =
function(map) {
245 for (var key in map) values.push(map[key]);
248 d3.entries =
function(map) {
250 for (var key in map) entries.push({
256 d3.merge =
function(arrays) {
257 var n = arrays.length, m, i = -1, j = 0, merged, array;
258 while (++i < n) j += arrays[i].length;
259 merged =
new Array(j);
264 merged[--j] = array[m];
270 d3.range =
function(start, stop, step) {
271 if (arguments.length < 3) {
273 if (arguments.length < 2) {
278 if ((stop - start) / step === Infinity)
throw new Error(
"infinite range");
279 var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
280 start *= k, stop *= k, step *= k;
281 if (step < 0)
while ((j = start + step * ++i) > stop) range.push(j / k);
else while ((j = start + step * ++i) < stop) range.push(j / k);
284 function d3_range_integerScale(x) {
286 while (x * k % 1) k *= 10;
289 function d3_class(ctor, properties) {
290 for (var key in properties) {
291 Object.defineProperty(ctor.prototype, key, {
292 value: properties[key],
297 d3.map =
function(object, f) {
298 var map =
new d3_Map();
299 if (
object instanceof d3_Map) {
300 object.forEach(
function(key, value) {
303 }
else if (Array.isArray(
object)) {
304 var i = -1, n =
object.length, o;
305 if (arguments.length === 1)
while (++i < n) map.set(i,
object[i]);
else while (++i < n) map.set(f.call(
object, o =
object[i], i), o);
307 for (var key in
object) map.set(key,
object[key]);
312 this._ = Object.create(null);
314 var d3_map_proto =
"__proto__", d3_map_zero =
"\x00";
318 return this._[d3_map_escape(key)];
320 set:
function(key, value) {
321 return this._[d3_map_escape(key)] = value;
323 remove: d3_map_remove,
327 for (var key in this._) values.push(this._[key]);
330 entries:
function() {
332 for (var key in this._) entries.push({
333 key: d3_map_unescape(key),
340 forEach:
function(f) {
341 for (var key in this._) f.call(
this, d3_map_unescape(key), this._[key]);
344 function d3_map_escape(key) {
345 return (key +=
"") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
347 function d3_map_unescape(key) {
348 return (key +=
"")[0] === d3_map_zero ? key.slice(1) : key;
350 function d3_map_has(key) {
351 return d3_map_escape(key) in this._;
353 function d3_map_remove(key) {
354 return (key = d3_map_escape(key)) in this._ &&
delete this._[key];
356 function d3_map_keys() {
358 for (var key in this._) keys.push(d3_map_unescape(key));
361 function d3_map_size() {
363 for (var key in this._) ++size;
366 function d3_map_empty() {
367 for (var key in this._)
return false;
370 d3.nest =
function() {
371 var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
372 function map(mapType, array, depth) {
373 if (depth >= keys.length)
return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
374 var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey =
new d3_Map(), values;
376 if (values = valuesByKey.get(keyValue = key(
object = array[i]))) {
379 valuesByKey.set(keyValue, [
object ]);
384 setter =
function(keyValue, values) {
385 object.set(keyValue, map(mapType, values, depth));
389 setter =
function(keyValue, values) {
390 object[keyValue] = map(mapType, values, depth);
393 valuesByKey.forEach(setter);
396 function entries(map, depth) {
397 if (depth >= keys.length)
return map;
398 var array = [], sortKey = sortKeys[depth++];
399 map.forEach(
function(key, keyMap) {
402 values: entries(keyMap, depth)
405 return sortKey ? array.sort(
function(a, b) {
406 return sortKey(a.key, b.key);
409 nest.map =
function(array, mapType) {
410 return map(mapType, array, 0);
412 nest.entries =
function(array) {
413 return entries(map(d3.map, array, 0), 0);
415 nest.key =
function(d) {
419 nest.sortKeys =
function(order) {
420 sortKeys[keys.length - 1] = order;
423 nest.sortValues =
function(order) {
427 nest.rollup =
function(f) {
433 d3.set =
function(array) {
434 var set =
new d3_Set();
435 if (array)
for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
439 this._ = Object.create(null);
444 this._[d3_map_escape(key +=
"")] =
true;
447 remove: d3_map_remove,
451 forEach:
function(f) {
452 for (var key in this._) f.call(
this, d3_map_unescape(key));
456 function d3_identity(d) {
459 d3.rebind =
function(target, source) {
460 var i = 1, n = arguments.length, method;
461 while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
464 function d3_rebind(target, source, method) {
466 var value = method.apply(source, arguments);
467 return value === source ? target : value;
470 function d3_vendorSymbol(
object, name) {
471 if (name in
object)
return name;
472 name = name.charAt(0).toUpperCase() + name.slice(1);
473 for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
474 var prefixName = d3_vendorPrefixes[i] + name;
475 if (prefixName in
object)
return prefixName;
478 var d3_vendorPrefixes = [
"webkit",
"ms",
"moz",
"Moz",
"o",
"O" ];
479 function d3_noop() {}
480 d3.dispatch =
function() {
481 var dispatch =
new d3_dispatch(), i = -1, n = arguments.length;
482 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
485 function d3_dispatch() {}
486 d3_dispatch.prototype.on =
function(type, listener) {
487 var i = type.indexOf(
"."), name =
"";
489 name = type.slice(i + 1);
490 type = type.slice(0, i);
492 if (type)
return arguments.length < 2 ?
this[type].on(name) :
this[type].on(name, listener);
493 if (arguments.length === 2) {
494 if (listener == null)
for (type in
this) {
495 if (this.hasOwnProperty(type))
this[type].on(name, null);
500 function d3_dispatch_event(dispatch) {
501 var listeners = [], listenerByName =
new d3_Map();
503 var z = listeners, i = -1, n = z.length, l;
504 while (++i < n)
if (l = z[i].on) l.apply(
this, arguments);
507 event.on =
function(name, listener) {
508 var l = listenerByName.get(name), i;
509 if (arguments.length < 2)
return l && l.on;
512 listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
513 listenerByName.remove(name);
515 if (listener) listeners.push(listenerByName.set(name, {
523 function d3_eventPreventDefault() {
524 d3.event.preventDefault();
526 function d3_eventSource() {
528 while (s = e.sourceEvent) e = s;
531 function d3_eventDispatch(target) {
532 var dispatch =
new d3_dispatch(), i = 0, n = arguments.length;
533 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
534 dispatch.of =
function(thiz, argumentz) {
535 return function(e1) {
537 var e0 = e1.sourceEvent = d3.event;
540 dispatch[e1.type].apply(thiz, argumentz);
548 d3.requote =
function(s) {
549 return s.replace(d3_requote_re,
"\\$&");
551 var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
552 var d3_subclass = {}.__proto__ ?
function(object, prototype) {
553 object.__proto__ = prototype;
554 } :
function(object, prototype) {
555 for (var property in prototype)
object[property] = prototype[property];
557 function d3_selection(groups) {
558 d3_subclass(groups, d3_selectionPrototype);
561 var d3_select =
function(s, n) {
562 return n.querySelector(s);
563 }, d3_selectAll =
function(s, n) {
564 return n.querySelectorAll(s);
565 }, d3_selectMatches =
function(n, s) {
566 var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n,
"matchesSelector")];
567 d3_selectMatches =
function(n, s) {
568 return d3_selectMatcher.call(n, s);
570 return d3_selectMatches(n, s);
572 if (typeof Sizzle ===
"function") {
573 d3_select =
function(s, n) {
574 return Sizzle(s, n)[0] || null;
576 d3_selectAll = Sizzle;
577 d3_selectMatches = Sizzle.matchesSelector;
579 d3.selection =
function() {
580 return d3.select(d3_document.documentElement);
582 var d3_selectionPrototype = d3.selection.prototype = [];
583 d3_selectionPrototype.select =
function(selector) {
584 var subgroups = [], subgroup, subnode, group, node;
585 selector = d3_selection_selector(selector);
586 for (var j = -1, m = this.length; ++j < m; ) {
587 subgroups.push(subgroup = []);
588 subgroup.parentNode = (group =
this[j]).parentNode;
589 for (var i = -1, n = group.length; ++i < n; ) {
590 if (node = group[i]) {
591 subgroup.push(subnode = selector.call(node, node.__data__, i, j));
592 if (subnode &&
"__data__" in node) subnode.__data__ = node.__data__;
598 return d3_selection(subgroups);
600 function d3_selection_selector(selector) {
601 return typeof selector ===
"function" ? selector :
function() {
602 return d3_select(selector,
this);
605 d3_selectionPrototype.selectAll =
function(selector) {
606 var subgroups = [], subgroup, node;
607 selector = d3_selection_selectorAll(selector);
608 for (var j = -1, m = this.length; ++j < m; ) {
609 for (var group =
this[j], i = -1, n = group.length; ++i < n; ) {
610 if (node = group[i]) {
611 subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
612 subgroup.parentNode = node;
616 return d3_selection(subgroups);
618 function d3_selection_selectorAll(selector) {
619 return typeof selector ===
"function" ? selector :
function() {
620 return d3_selectAll(selector,
this);
624 svg:
"http://www.w3.org/2000/svg",
625 xhtml:
"http://www.w3.org/1999/xhtml",
626 xlink:
"http://www.w3.org/1999/xlink",
627 xml:
"http://www.w3.org/XML/1998/namespace",
628 xmlns:
"http://www.w3.org/2000/xmlns/"
632 qualify:
function(name) {
633 var i = name.indexOf(
":"), prefix = name;
635 prefix = name.slice(0, i);
636 name = name.slice(i + 1);
638 return d3_nsPrefix.hasOwnProperty(prefix) ? {
639 space: d3_nsPrefix[prefix],
644 d3_selectionPrototype.attr =
function(name, value) {
645 if (arguments.length < 2) {
646 if (typeof name ===
"string") {
647 var node = this.node();
648 name = d3.ns.qualify(name);
649 return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
651 for (value in name) this.each(d3_selection_attr(value, name[value]));
654 return this.each(d3_selection_attr(name, value));
656 function d3_selection_attr(name, value) {
657 name = d3.ns.qualify(name);
658 function attrNull() {
659 this.removeAttribute(name);
661 function attrNullNS() {
662 this.removeAttributeNS(name.space, name.local);
664 function attrConstant() {
665 this.setAttribute(name, value);
667 function attrConstantNS() {
668 this.setAttributeNS(name.space, name.local, value);
670 function attrFunction() {
671 var x = value.apply(
this, arguments);
672 if (x == null) this.removeAttribute(name);
else this.setAttribute(name, x);
674 function attrFunctionNS() {
675 var x = value.apply(
this, arguments);
676 if (x == null) this.removeAttributeNS(name.space, name.local);
else this.setAttributeNS(name.space, name.local, x);
678 return value == null ? name.local ? attrNullNS : attrNull : typeof value ===
"function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
680 function d3_collapse(s) {
681 return s.trim().replace(/\s+/g,
" ");
683 d3_selectionPrototype.classed =
function(name, value) {
684 if (arguments.length < 2) {
685 if (typeof name ===
"string") {
686 var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
687 if (value = node.classList) {
688 while (++i < n)
if (!value.contains(name[i]))
return false;
690 value = node.getAttribute(
"class");
691 while (++i < n)
if (!d3_selection_classedRe(name[i]).test(value))
return false;
695 for (value in name) this.each(d3_selection_classed(value, name[value]));
698 return this.each(d3_selection_classed(name, value));
700 function d3_selection_classedRe(name) {
701 return new RegExp(
"(?:^|\\s+)" + d3.requote(name) +
"(?:\\s+|$)",
"g");
703 function d3_selection_classes(name) {
704 return (name +
"").trim().split(/^|\s+/);
706 function d3_selection_classed(name, value) {
707 name = d3_selection_classes(name).map(d3_selection_classedName);
709 function classedConstant() {
711 while (++i < n) name[i](
this, value);
713 function classedFunction() {
714 var i = -1, x = value.apply(
this, arguments);
715 while (++i < n) name[i](
this, x);
717 return typeof value ===
"function" ? classedFunction : classedConstant;
719 function d3_selection_classedName(name) {
720 var re = d3_selection_classedRe(name);
721 return function(node, value) {
722 if (c = node.classList)
return value ? c.add(name) : c.remove(name);
723 var c = node.getAttribute(
"class") ||
"";
726 if (!re.test(c)) node.setAttribute(
"class", d3_collapse(c +
" " + name));
728 node.setAttribute(
"class", d3_collapse(c.replace(re,
" ")));
732 d3_selectionPrototype.style =
function(name, value, priority) {
733 var n = arguments.length;
735 if (typeof name !==
"string") {
736 if (n < 2) value =
"";
737 for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
741 var node = this.node();
742 return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
746 return this.each(d3_selection_style(name, value, priority));
748 function d3_selection_style(name, value, priority) {
749 function styleNull() {
750 this.style.removeProperty(name);
752 function styleConstant() {
753 this.style.setProperty(name, value, priority);
755 function styleFunction() {
756 var x = value.apply(
this, arguments);
757 if (x == null) this.style.removeProperty(name);
else this.style.setProperty(name, x, priority);
759 return value == null ? styleNull : typeof value ===
"function" ? styleFunction : styleConstant;
761 d3_selectionPrototype.property =
function(name, value) {
762 if (arguments.length < 2) {
763 if (typeof name ===
"string")
return this.node()[name];
764 for (value in name) this.each(d3_selection_property(value, name[value]));
767 return this.each(d3_selection_property(name, value));
769 function d3_selection_property(name, value) {
770 function propertyNull() {
773 function propertyConstant() {
776 function propertyFunction() {
777 var x = value.apply(
this, arguments);
778 if (x == null)
delete this[name];
else this[name] = x;
780 return value == null ? propertyNull : typeof value ===
"function" ? propertyFunction : propertyConstant;
782 d3_selectionPrototype.text =
function(value) {
783 return arguments.length ? this.each(typeof value ===
"function" ?
function() {
784 var v = value.apply(
this, arguments);
785 this.textContent = v == null ?
"" : v;
786 } : value == null ?
function() {
787 this.textContent =
"";
789 this.textContent = value;
790 }) : this.node().textContent;
792 d3_selectionPrototype.html =
function(value) {
793 return arguments.length ? this.each(typeof value ===
"function" ?
function() {
794 var v = value.apply(
this, arguments);
795 this.innerHTML = v == null ?
"" : v;
796 } : value == null ?
function() {
799 this.innerHTML = value;
800 }) : this.node().innerHTML;
802 d3_selectionPrototype.append =
function(name) {
803 name = d3_selection_creator(name);
804 return this.select(
function() {
805 return this.appendChild(name.apply(
this, arguments));
808 function d3_selection_creator(name) {
810 var document = this.ownerDocument,
namespace = this.namespaceURI;
811 return namespace ? document.createElementNS(namespace, name) : document.createElement(name);
813 function createNS() {
814 return this.ownerDocument.createElementNS(name.space, name.local);
816 return typeof name ===
"function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
818 d3_selectionPrototype.insert =
function(name, before) {
819 name = d3_selection_creator(name);
820 before = d3_selection_selector(before);
821 return this.select(
function() {
822 return this.insertBefore(name.apply(
this, arguments), before.apply(
this, arguments) || null);
825 d3_selectionPrototype.remove =
function() {
826 return this.each(d3_selectionRemove);
828 function d3_selectionRemove() {
829 var parent = this.parentNode;
830 if (parent) parent.removeChild(
this);
832 d3_selectionPrototype.data =
function(value, key) {
833 var i = -1, n = this.length, group, node;
834 if (!arguments.length) {
835 value =
new Array(n = (group =
this[0]).length);
837 if (node = group[i]) {
838 value[i] = node.__data__;
843 function bind(group, groupData) {
844 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;
846 var nodeByKeyValue =
new d3_Map(), keyValues =
new Array(n), keyValue;
847 for (i = -1; ++i < n; ) {
848 if (nodeByKeyValue.has(keyValue = key.call(node = group[i], node.__data__, i))) {
851 nodeByKeyValue.set(keyValue, node);
853 keyValues[i] = keyValue;
855 for (i = -1; ++i < m; ) {
856 if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
857 enterNodes[i] = d3_selection_dataNode(nodeData);
858 }
else if (node !==
true) {
859 updateNodes[i] = node;
860 node.__data__ = nodeData;
862 nodeByKeyValue.set(keyValue,
true);
864 for (i = -1; ++i < n; ) {
865 if (nodeByKeyValue.get(keyValues[i]) !==
true) {
866 exitNodes[i] = group[i];
870 for (i = -1; ++i < n0; ) {
872 nodeData = groupData[i];
874 node.__data__ = nodeData;
875 updateNodes[i] = node;
877 enterNodes[i] = d3_selection_dataNode(nodeData);
881 enterNodes[i] = d3_selection_dataNode(groupData[i]);
884 exitNodes[i] = group[i];
887 enterNodes.update = updateNodes;
888 enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
889 enter.push(enterNodes);
890 update.push(updateNodes);
891 exit.push(exitNodes);
893 var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
894 if (typeof value ===
"function") {
896 bind(group =
this[i], value.call(group, group.parentNode.__data__, i));
900 bind(group =
this[i], value);
903 update.enter =
function() {
906 update.exit =
function() {
911 function d3_selection_dataNode(data) {
916 d3_selectionPrototype.datum =
function(value) {
917 return arguments.length ? this.property(
"__data__", value) : this.property(
"__data__");
919 d3_selectionPrototype.filter =
function(filter) {
920 var subgroups = [], subgroup, group, node;
921 if (typeof filter !==
"function") filter = d3_selection_filter(filter);
922 for (var j = 0, m = this.length; j < m; j++) {
923 subgroups.push(subgroup = []);
924 subgroup.parentNode = (group =
this[j]).parentNode;
925 for (var i = 0, n = group.length; i < n; i++) {
926 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
931 return d3_selection(subgroups);
933 function d3_selection_filter(selector) {
935 return d3_selectMatches(
this, selector);
938 d3_selectionPrototype.order =
function() {
939 for (var j = -1, m = this.length; ++j < m; ) {
940 for (var group =
this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
941 if (node = group[i]) {
942 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
949 d3_selectionPrototype.sort =
function(comparator) {
950 comparator = d3_selection_sortComparator.apply(
this, arguments);
951 for (var j = -1, m = this.length; ++j < m; )
this[j].sort(comparator);
954 function d3_selection_sortComparator(comparator) {
955 if (!arguments.length) comparator = d3_ascending;
956 return function(a, b) {
957 return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
960 d3_selectionPrototype.each =
function(callback) {
961 return d3_selection_each(
this,
function(node, i, j) {
962 callback.call(node, node.__data__, i, j);
965 function d3_selection_each(groups, callback) {
966 for (var j = 0, m = groups.length; j < m; j++) {
967 for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
968 if (node = group[i]) callback(node, i, j);
973 d3_selectionPrototype.call =
function(callback) {
974 var args = d3_array(arguments);
975 callback.apply(args[0] =
this, args);
978 d3_selectionPrototype.empty =
function() {
981 d3_selectionPrototype.node =
function() {
982 for (var j = 0, m = this.length; j < m; j++) {
983 for (var group =
this[j], i = 0, n = group.length; i < n; i++) {
985 if (node)
return node;
990 d3_selectionPrototype.size =
function() {
992 d3_selection_each(
this,
function() {
997 function d3_selection_enter(selection) {
998 d3_subclass(selection, d3_selection_enterPrototype);
1001 var d3_selection_enterPrototype = [];
1002 d3.selection.enter = d3_selection_enter;
1003 d3.selection.enter.prototype = d3_selection_enterPrototype;
1004 d3_selection_enterPrototype.append = d3_selectionPrototype.append;
1005 d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
1006 d3_selection_enterPrototype.node = d3_selectionPrototype.node;
1007 d3_selection_enterPrototype.call = d3_selectionPrototype.call;
1008 d3_selection_enterPrototype.size = d3_selectionPrototype.size;
1009 d3_selection_enterPrototype.select =
function(selector) {
1010 var subgroups = [], subgroup, subnode, upgroup, group, node;
1011 for (var j = -1, m = this.length; ++j < m; ) {
1012 upgroup = (group =
this[j]).update;
1013 subgroups.push(subgroup = []);
1014 subgroup.parentNode = group.parentNode;
1015 for (var i = -1, n = group.length; ++i < n; ) {
1016 if (node = group[i]) {
1017 subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
1018 subnode.__data__ = node.__data__;
1020 subgroup.push(null);
1024 return d3_selection(subgroups);
1026 d3_selection_enterPrototype.insert =
function(name, before) {
1027 if (arguments.length < 2) before = d3_selection_enterInsertBefore(
this);
1028 return d3_selectionPrototype.insert.call(
this, name, before);
1030 function d3_selection_enterInsertBefore(enter) {
1032 return function(d, i, j) {
1033 var group = enter[j].update, n = group.length, node;
1034 if (j != j0) j0 = j, i0 = 0;
1035 if (i >= i0) i0 = i + 1;
1036 while (!(node = group[i0]) && ++i0 < n) ;
1040 d3.select =
function(node) {
1042 if (typeof node ===
"string") {
1043 group = [ d3_select(node, d3_document) ];
1044 group.parentNode = d3_document.documentElement;
1047 group.parentNode = d3_documentElement(node);
1049 return d3_selection([ group ]);
1051 d3.selectAll =
function(nodes) {
1053 if (typeof nodes ===
"string") {
1054 group = d3_array(d3_selectAll(nodes, d3_document));
1055 group.parentNode = d3_document.documentElement;
1058 group.parentNode = null;
1060 return d3_selection([ group ]);
1062 d3_selectionPrototype.on =
function(type, listener, capture) {
1063 var n = arguments.length;
1065 if (typeof type !==
"string") {
1066 if (n < 2) listener =
false;
1067 for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
1070 if (n < 2)
return (n = this.node()[
"__on" + type]) && n._;
1073 return this.each(d3_selection_on(type, listener, capture));
1075 function d3_selection_on(type, listener, capture) {
1076 var name =
"__on" + type, i = type.indexOf(
"."), wrap = d3_selection_onListener;
1077 if (i > 0) type = type.slice(0, i);
1078 var filter = d3_selection_onFilters.get(type);
1079 if (filter) type = filter, wrap = d3_selection_onFilter;
1080 function onRemove() {
1083 this.removeEventListener(type, l, l.$);
1088 var l = wrap(listener, d3_array(arguments));
1089 onRemove.call(
this);
1090 this.addEventListener(type,
this[name] = l, l.$ = capture);
1093 function removeAll() {
1094 var re =
new RegExp(
"^__on([^.]+)" + d3.requote(type) +
"$"), match;
1095 for (var name in
this) {
1096 if (match = name.match(re)) {
1098 this.removeEventListener(match[1], l, l.$);
1103 return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
1105 var d3_selection_onFilters = d3.map({
1106 mouseenter:
"mouseover",
1107 mouseleave:
"mouseout"
1110 d3_selection_onFilters.forEach(
function(k) {
1111 if (
"on" + k in d3_document) d3_selection_onFilters.remove(k);
1114 function d3_selection_onListener(listener, argumentz) {
1115 return function(e) {
1118 argumentz[0] = this.__data__;
1120 listener.apply(
this, argumentz);
1126 function d3_selection_onFilter(listener, argumentz) {
1127 var l = d3_selection_onListener(listener, argumentz);
1128 return function(e) {
1129 var target =
this, related = e.relatedTarget;
1130 if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
1135 var d3_event_dragSelect, d3_event_dragId = 0;
1136 function d3_event_dragSuppress(node) {
1137 var name =
".dragsuppress-" + ++d3_event_dragId, click =
"click" + name, w = d3.select(d3_window(node)).on(
"touchmove" + name, d3_eventPreventDefault).on(
"dragstart" + name, d3_eventPreventDefault).on(
"selectstart" + name, d3_eventPreventDefault);
1138 if (d3_event_dragSelect == null) {
1139 d3_event_dragSelect =
"onselectstart" in node ?
false : d3_vendorSymbol(node.style,
"userSelect");
1141 if (d3_event_dragSelect) {
1142 var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
1143 style[d3_event_dragSelect] =
"none";
1145 return function(suppressClick) {
1147 if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
1148 if (suppressClick) {
1149 var off =
function() {
1152 w.on(click,
function() {
1153 d3_eventPreventDefault();
1160 d3.mouse =
function(container) {
1161 return d3_mousePoint(container, d3_eventSource());
1163 var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
1164 function d3_mousePoint(container, e) {
1165 if (e.changedTouches) e = e.changedTouches[0];
1166 var svg = container.ownerSVGElement || container;
1167 if (svg.createSVGPoint) {
1168 var point = svg.createSVGPoint();
1169 if (d3_mouse_bug44083 < 0) {
1170 var window = d3_window(container);
1171 if (window.scrollX || window.scrollY) {
1172 svg = d3.select(
"body").append(
"svg").style({
1173 position:
"absolute",
1180 var ctm = svg[0][0].getScreenCTM();
1181 d3_mouse_bug44083 = !(ctm.f || ctm.e);
1185 if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY;
else point.x = e.clientX,
1186 point.y = e.clientY;
1187 point = point.matrixTransform(container.getScreenCTM().inverse());
1188 return [ point.x, point.y ];
1190 var rect = container.getBoundingClientRect();
1191 return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
1193 d3.touch =
function(container, touches, identifier) {
1194 if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
1195 if (touches)
for (var i = 0, n = touches.length, touch; i < n; ++i) {
1196 if ((touch = touches[i]).identifier === identifier) {
1197 return d3_mousePoint(container, touch);
1201 d3.behavior.drag =
function() {
1202 var
event = d3_eventDispatch(drag,
"drag",
"dragstart",
"dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_window,
"mousemove",
"mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_identity,
"touchmove",
"touchend");
1204 this.on(
"mousedown.drag", mousedown).on(
"touchstart.drag", touchstart);
1206 function dragstart(
id, position, subject, move, end) {
1208 var that =
this, target = d3.event.target, parent = that.parentNode, dispatch =
event.of(that, arguments), dragged = 0, dragId = id(), dragName =
".drag" + (dragId == null ?
"" :
"-" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
1210 dragOffset = origin.apply(that, arguments);
1211 dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
1213 dragOffset = [ 0, 0 ];
1219 var position1 = position(parent, dragId), dx, dy;
1220 if (!position1)
return;
1221 dx = position1[0] - position0[0];
1222 dy = position1[1] - position0[1];
1224 position0 = position1;
1227 x: position1[0] + dragOffset[0],
1228 y: position1[1] + dragOffset[1],
1234 if (!position(parent, dragId))
return;
1235 dragSubject.on(move + dragName, null).on(end + dragName, null);
1236 dragRestore(dragged && d3.event.target === target);
1243 drag.origin =
function(x) {
1244 if (!arguments.length)
return origin;
1248 return d3.rebind(drag, event,
"on");
1250 function d3_behavior_dragTouchId() {
1251 return d3.event.changedTouches[0].identifier;
1253 d3.touches =
function(container, touches) {
1254 if (arguments.length < 2) touches = d3_eventSource().touches;
1255 return touches ? d3_array(touches).map(
function(touch) {
1256 var point = d3_mousePoint(container, touch);
1257 point.identifier = touch.identifier;
1261 var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
1262 function d3_sgn(x) {
1263 return x > 0 ? 1 : x < 0 ? -1 : 0;
1265 function d3_cross2d(a, b, c) {
1266 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
1268 function d3_acos(x) {
1269 return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
1271 function d3_asin(x) {
1272 return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
1274 function d3_sinh(x) {
1275 return ((x = Math.exp(x)) - 1 / x) / 2;
1277 function d3_cosh(x) {
1278 return ((x = Math.exp(x)) + 1 / x) / 2;
1280 function d3_tanh(x) {
1281 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
1283 function d3_haversin(x) {
1284 return (x = Math.sin(x / 2)) * x;
1286 var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
1287 d3.interpolateZoom =
function(p0, p1) {
1288 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2];
1289 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)) / ρ;
1290 function interpolate(t) {
1293 var coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
1294 return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
1296 return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * s) ];
1298 interpolate.duration = S * 1e3;
1301 d3.behavior.zoom =
function() {
1306 }, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, duration = 250, zooming = 0, mousedown =
"mousedown.zoom", mousemove =
"mousemove.zoom", mouseup =
"mouseup.zoom", mousewheelTimer, touchstart =
"touchstart.zoom", touchtime,
event = d3_eventDispatch(zoom,
"zoomstart",
"zoom",
"zoomend"), x0, x1, y0, y1;
1307 if (!d3_behavior_zoomWheel) {
1308 d3_behavior_zoomWheel =
"onwheel" in d3_document ? (d3_behavior_zoomDelta =
function() {
1309 return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
1310 },
"wheel") :
"onmousewheel" in d3_document ? (d3_behavior_zoomDelta =
function() {
1311 return d3.event.wheelDelta;
1312 },
"mousewheel") : (d3_behavior_zoomDelta =
function() {
1313 return -d3.event.detail;
1314 },
"MozMousePixelScroll");
1317 g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel +
".zoom", mousewheeled).on(
"dblclick.zoom", dblclicked).on(touchstart, touchstarted);
1319 zoom.event =
function(g) {
1321 var dispatch =
event.of(
this, arguments), view1 = view;
1322 if (d3_transitionInheritId) {
1323 d3.select(
this).transition().each(
"start.zoom",
function() {
1324 view = this.__chart__ || {
1329 zoomstarted(dispatch);
1330 }).tween(
"zoom:zoom",
function() {
1331 var dx = size[0], dy = size[1], cx = center0 ? center0[0] : dx / 2, cy = center0 ? center0[1] : dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]);
1332 return function(t) {
1333 var l = i(t), k = dx / l[2];
1334 this.__chart__ = view = {
1341 }).each(
"interrupt.zoom",
function() {
1342 zoomended(dispatch);
1343 }).each(
"end.zoom",
function() {
1344 zoomended(dispatch);
1347 this.__chart__ = view;
1348 zoomstarted(dispatch);
1350 zoomended(dispatch);
1354 zoom.translate =
function(_) {
1355 if (!arguments.length)
return [ view.x, view.y ];
1364 zoom.scale =
function(_) {
1365 if (!arguments.length)
return view.k;
1374 zoom.scaleExtent =
function(_) {
1375 if (!arguments.length)
return scaleExtent;
1376 scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
1379 zoom.center =
function(_) {
1380 if (!arguments.length)
return center;
1381 center = _ && [ +_[0], +_[1] ];
1384 zoom.size =
function(_) {
1385 if (!arguments.length)
return size;
1386 size = _ && [ +_[0], +_[1] ];
1389 zoom.duration =
function(_) {
1390 if (!arguments.length)
return duration;
1394 zoom.x =
function(z) {
1395 if (!arguments.length)
return x1;
1405 zoom.y =
function(z) {
1406 if (!arguments.length)
return y1;
1416 function location(p) {
1417 return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
1420 return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
1422 function scaleTo(s) {
1423 view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
1425 function translateTo(p, l) {
1427 view.x += p[0] - l[0];
1428 view.y += p[1] - l[1];
1430 function zoomTo(that, p, l, k) {
1436 scaleTo(Math.pow(2, k));
1437 translateTo(center0 = p, l);
1438 that = d3.select(that);
1439 if (duration > 0) that = that.transition().duration(duration);
1440 that.call(zoom.event);
1442 function rescale() {
1443 if (x1) x1.domain(x0.range().map(
function(x) {
1444 return (x - view.x) / view.k;
1446 if (y1) y1.domain(y0.range().map(
function(y) {
1447 return (y - view.y) / view.k;
1450 function zoomstarted(dispatch) {
1451 if (!zooming++) dispatch({
1455 function zoomed(dispatch) {
1460 translate: [ view.x, view.y ]
1463 function zoomended(dispatch) {
1464 if (!--zooming) dispatch({
1469 function mousedowned() {
1470 var that =
this, target = d3.event.target, dispatch =
event.of(that, arguments), dragged = 0, subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress(that);
1471 d3_selection_interrupt.call(that);
1472 zoomstarted(dispatch);
1475 translateTo(d3.mouse(that), location0);
1479 subject.on(mousemove, null).on(mouseup, null);
1480 dragRestore(dragged && d3.event.target === target);
1481 zoomended(dispatch);
1484 function touchstarted() {
1485 var that =
this, dispatch =
event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName =
".zoom-" + d3.event.changedTouches[0].identifier, touchmove =
"touchmove" + zoomName, touchend =
"touchend" + zoomName, targets = [], subject = d3.select(that), dragRestore = d3_event_dragSuppress(that);
1487 zoomstarted(dispatch);
1488 subject.on(mousedown, null).on(touchstart, started);
1489 function relocate() {
1490 var touches = d3.touches(that);
1492 touches.forEach(
function(t) {
1493 if (t.identifier in locations0) locations0[t.identifier] = location(t);
1497 function started() {
1498 var target = d3.event.target;
1499 d3.select(target).on(touchmove, moved).on(touchend, ended);
1500 targets.push(target);
1501 var changed = d3.event.changedTouches;
1502 for (var i = 0, n = changed.length; i < n; ++i) {
1503 locations0[changed[i].identifier] = null;
1505 var touches = relocate(), now = Date.now();
1506 if (touches.length === 1) {
1507 if (now - touchtime < 500) {
1509 zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
1510 d3_eventPreventDefault();
1513 }
else if (touches.length > 1) {
1514 var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
1515 distance0 = dx * dx + dy * dy;
1519 var touches = d3.touches(that), p0, l0, p1, l1;
1520 d3_selection_interrupt.call(that);
1521 for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
1523 if (l1 = locations0[p1.identifier]) {
1529 var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
1530 p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
1531 l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
1532 scaleTo(scale1 * scale0);
1535 translateTo(p0, l0);
1539 if (d3.event.touches.length) {
1540 var changed = d3.event.changedTouches;
1541 for (var i = 0, n = changed.length; i < n; ++i) {
1542 delete locations0[changed[i].identifier];
1544 for (var identifier in locations0) {
1545 return void relocate();
1548 d3.selectAll(targets).on(zoomName, null);
1549 subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
1551 zoomended(dispatch);
1554 function mousewheeled() {
1555 var dispatch =
event.of(
this, arguments);
1556 if (mousewheelTimer) clearTimeout(mousewheelTimer);
else translate0 = location(center0 = center || d3.mouse(
this)),
1557 d3_selection_interrupt.call(
this), zoomstarted(dispatch);
1558 mousewheelTimer = setTimeout(
function() {
1559 mousewheelTimer = null;
1560 zoomended(dispatch);
1562 d3_eventPreventDefault();
1563 scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
1564 translateTo(center0, translate0);
1567 function dblclicked() {
1568 var p = d3.mouse(
this), k = Math.log(view.k) / Math.LN2;
1569 zoomTo(
this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
1571 return d3.rebind(zoom, event,
"on");
1573 var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
1574 d3.color = d3_color;
1575 function d3_color() {}
1576 d3_color.prototype.toString =
function() {
1577 return this.rgb() +
"";
1580 function d3_hsl(h, s, l) {
1581 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);
1583 var d3_hslPrototype = d3_hsl.prototype =
new d3_color();
1584 d3_hslPrototype.brighter =
function(k) {
1585 k = Math.pow(.7, arguments.length ? k : 1);
1586 return new d3_hsl(this.h, this.s, this.l / k);
1588 d3_hslPrototype.darker =
function(k) {
1589 k = Math.pow(.7, arguments.length ? k : 1);
1590 return new d3_hsl(this.h, this.s, k * this.l);
1592 d3_hslPrototype.rgb =
function() {
1593 return d3_hsl_rgb(this.h, this.s, this.l);
1595 function d3_hsl_rgb(h, s, l) {
1597 h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
1598 s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
1599 l = l < 0 ? 0 : l > 1 ? 1 : l;
1600 m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
1603 if (h > 360) h -= 360;
else if (h < 0) h += 360;
1604 if (h < 60)
return m1 + (m2 - m1) * h / 60;
1605 if (h < 180)
return m2;
1606 if (h < 240)
return m1 + (m2 - m1) * (240 - h) / 60;
1610 return Math.round(v(h) * 255);
1612 return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
1615 function d3_hcl(h, c, l) {
1616 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);
1618 var d3_hclPrototype = d3_hcl.prototype =
new d3_color();
1619 d3_hclPrototype.brighter =
function(k) {
1620 return new d3_hcl(this.h, this.c, Math.min(100,
this.l + d3_lab_K * (arguments.length ? k : 1)));
1622 d3_hclPrototype.darker =
function(k) {
1623 return new d3_hcl(this.h, this.c, Math.max(0,
this.l - d3_lab_K * (arguments.length ? k : 1)));
1625 d3_hclPrototype.rgb =
function() {
1626 return d3_hcl_lab(this.h, this.c, this.l).rgb();
1628 function d3_hcl_lab(h, c, l) {
1629 if (isNaN(h)) h = 0;
1630 if (isNaN(c)) c = 0;
1631 return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
1634 function d3_lab(l, a, b) {
1635 return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) : arguments.length < 2 ? l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) : l instanceof d3_hcl ? d3_hcl_lab(l.h, l.c, l.l) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b);
1638 var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
1639 var d3_labPrototype = d3_lab.prototype =
new d3_color();
1640 d3_labPrototype.brighter =
function(k) {
1641 return new d3_lab(Math.min(100,
this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1643 d3_labPrototype.darker =
function(k) {
1644 return new d3_lab(Math.max(0,
this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1646 d3_labPrototype.rgb =
function() {
1647 return d3_lab_rgb(this.l, this.a, this.b);
1649 function d3_lab_rgb(l, a, b) {
1650 var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
1651 x = d3_lab_xyz(x) * d3_lab_X;
1652 y = d3_lab_xyz(y) * d3_lab_Y;
1653 z = d3_lab_xyz(z) * d3_lab_Z;
1654 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));
1656 function d3_lab_hcl(l, a, b) {
1657 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);
1659 function d3_lab_xyz(x) {
1660 return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
1662 function d3_xyz_lab(x) {
1663 return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
1665 function d3_xyz_rgb(r) {
1666 return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
1669 function d3_rgb(r, g, b) {
1670 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);
1672 function d3_rgbNumber(value) {
1673 return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
1675 function d3_rgbString(value) {
1676 return d3_rgbNumber(value) +
"";
1678 var d3_rgbPrototype = d3_rgb.prototype =
new d3_color();
1679 d3_rgbPrototype.brighter =
function(k) {
1680 k = Math.pow(.7, arguments.length ? k : 1);
1681 var r = this.r, g = this.g, b = this.b, i = 30;
1682 if (!r && !g && !b)
return new d3_rgb(i, i, i);
1683 if (r && r < i) r = i;
1684 if (g && g < i) g = i;
1685 if (b && b < i) b = i;
1686 return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
1688 d3_rgbPrototype.darker =
function(k) {
1689 k = Math.pow(.7, arguments.length ? k : 1);
1690 return new d3_rgb(k * this.r, k * this.g, k * this.b);
1692 d3_rgbPrototype.hsl =
function() {
1693 return d3_rgb_hsl(this.r, this.g, this.b);
1695 d3_rgbPrototype.toString =
function() {
1696 return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
1698 function d3_rgb_hex(v) {
1699 return v < 16 ?
"0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
1701 function d3_rgb_parse(format, rgb, hsl) {
1702 var r = 0, g = 0, b = 0, m1, m2, color;
1703 m1 = /([a-z]+)\((.*)\)/i.exec(format);
1705 m2 = m1[2].split(
",");
1709 return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
1714 return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
1718 if (color = d3_rgb_names.get(format.toLowerCase())) {
1719 return rgb(color.r, color.g, color.b);
1721 if (format != null && format.charAt(0) ===
"#" && !isNaN(color = parseInt(format.slice(1), 16))) {
1722 if (format.length === 4) {
1723 r = (color & 3840) >> 4;
1729 }
else if (format.length === 7) {
1730 r = (color & 16711680) >> 16;
1731 g = (color & 65280) >> 8;
1735 return rgb(r, g, b);
1737 function d3_rgb_hsl(r, g, b) {
1738 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;
1740 s = l < .5 ? d / (max + min) : d / (2 - max - min);
1741 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;
1745 s = l > 0 && l < 1 ? 0 : h;
1747 return new d3_hsl(h, s, l);
1749 function d3_rgb_lab(r, g, b) {
1753 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);
1754 return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
1756 function d3_rgb_xyz(r) {
1757 return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
1759 function d3_rgb_parseNumber(c) {
1760 var f = parseFloat(c);
1761 return c.charAt(c.length - 1) ===
"%" ? Math.round(f * 2.55) : f;
1763 var d3_rgb_names = d3.map({
1764 aliceblue: 15792383,
1765 antiquewhite: 16444375,
1767 aquamarine: 8388564,
1772 blanchedalmond: 16772045,
1774 blueviolet: 9055202,
1776 burlywood: 14596231,
1778 chartreuse: 8388352,
1779 chocolate: 13789470,
1781 cornflowerblue: 6591981,
1787 darkgoldenrod: 12092939,
1791 darkkhaki: 12433259,
1792 darkmagenta: 9109643,
1793 darkolivegreen: 5597999,
1794 darkorange: 16747520,
1795 darkorchid: 10040012,
1797 darksalmon: 15308410,
1798 darkseagreen: 9419919,
1799 darkslateblue: 4734347,
1800 darkslategray: 3100495,
1801 darkslategrey: 3100495,
1802 darkturquoise: 52945,
1803 darkviolet: 9699539,
1808 dodgerblue: 2003199,
1809 firebrick: 11674146,
1810 floralwhite: 16775920,
1811 forestgreen: 2263842,
1813 gainsboro: 14474460,
1814 ghostwhite: 16316671,
1816 goldenrod: 14329120,
1819 greenyellow: 11403055,
1823 indianred: 13458524,
1828 lavenderblush: 16773365,
1830 lemonchiffon: 16775885,
1831 lightblue: 11393254,
1832 lightcoral: 15761536,
1833 lightcyan: 14745599,
1834 lightgoldenrodyellow: 16448210,
1835 lightgray: 13882323,
1836 lightgreen: 9498256,
1837 lightgrey: 13882323,
1838 lightpink: 16758465,
1839 lightsalmon: 16752762,
1840 lightseagreen: 2142890,
1841 lightskyblue: 8900346,
1842 lightslategray: 7833753,
1843 lightslategrey: 7833753,
1844 lightsteelblue: 11584734,
1845 lightyellow: 16777184,
1851 mediumaquamarine: 6737322,
1853 mediumorchid: 12211667,
1854 mediumpurple: 9662683,
1855 mediumseagreen: 3978097,
1856 mediumslateblue: 8087790,
1857 mediumspringgreen: 64154,
1858 mediumturquoise: 4772300,
1859 mediumvioletred: 13047173,
1860 midnightblue: 1644912,
1861 mintcream: 16121850,
1862 mistyrose: 16770273,
1864 navajowhite: 16768685,
1870 orangered: 16729344,
1872 palegoldenrod: 15657130,
1873 palegreen: 10025880,
1874 paleturquoise: 11529966,
1875 palevioletred: 14381203,
1876 papayawhip: 16773077,
1877 peachpuff: 16767673,
1881 powderblue: 11591910,
1883 rebeccapurple: 6697881,
1885 rosybrown: 12357519,
1887 saddlebrown: 9127187,
1889 sandybrown: 16032864,
1909 whitesmoke: 16119285,
1911 yellowgreen: 10145074
1913 d3_rgb_names.forEach(
function(key, value) {
1914 d3_rgb_names.set(key, d3_rgbNumber(value));
1916 function d3_functor(v) {
1917 return typeof v ===
"function" ? v :
function() {
1921 d3.functor = d3_functor;
1922 d3.xhr = d3_xhrType(d3_identity);
1923 function d3_xhrType(response) {
1924 return function(url, mimeType, callback) {
1925 if (arguments.length === 2 && typeof mimeType ===
"function") callback = mimeType,
1927 return d3_xhr(url, mimeType, response, callback);
1930 function d3_xhr(url, mimeType, response, callback) {
1931 var xhr = {}, dispatch = d3.dispatch(
"beforesend",
"progress",
"load",
"error"), headers = {}, request =
new XMLHttpRequest(), responseType = null;
1932 if (this.XDomainRequest && !(
"withCredentials" in request) && /^(http(s)?:)?\/\
1933 "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange =
function() {
1934 request.readyState > 3 && respond();
1936 function respond() {
1937 var status = request.status, result;
1938 if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
1940 result = response.call(xhr, request);
1942 dispatch.error.call(xhr, e);
1945 dispatch.load.call(xhr, result);
1947 dispatch.error.call(xhr, request);
1950 request.onprogress =
function(event) {
1954 dispatch.progress.call(xhr, request);
1959 xhr.header =
function(name, value) {
1960 name = (name +
"").toLowerCase();
1961 if (arguments.length < 2)
return headers[name];
1962 if (value == null)
delete headers[name];
else headers[name] = value +
"";
1965 xhr.mimeType =
function(value) {
1966 if (!arguments.length)
return mimeType;
1967 mimeType = value == null ? null : value +
"";
1970 xhr.responseType =
function(value) {
1971 if (!arguments.length)
return responseType;
1972 responseType = value;
1975 xhr.response =
function(value) {
1979 [
"get",
"post" ].forEach(
function(method) {
1980 xhr[method] =
function() {
1981 return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
1984 xhr.send =
function(method, data, callback) {
1985 if (arguments.length === 2 && typeof data ===
"function") callback = data, data = null;
1986 request.open(method, url,
true);
1987 if (mimeType != null && !(
"accept" in headers)) headers[
"accept"] = mimeType +
",*/*";
1988 if (request.setRequestHeader)
for (var name in headers) request.setRequestHeader(name, headers[name]);
1989 if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
1990 if (responseType != null) request.responseType = responseType;
1991 if (callback != null) xhr.on(
"error", callback).on(
"load",
function(request) {
1992 callback(null, request);
1994 dispatch.beforesend.call(xhr, request);
1995 request.send(data == null ? null : data);
1998 xhr.abort =
function() {
2002 d3.rebind(xhr, dispatch,
"on");
2003 return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
2005 function d3_xhr_fixCallback(callback) {
2006 return callback.length === 1 ?
function(error, request) {
2007 callback(error == null ? request : null);
2010 function d3_xhrHasResponse(request) {
2011 var type = request.responseType;
2012 return type && type !==
"text" ? request.response : request.responseText;
2014 d3.dsv =
function(delimiter, mimeType) {
2015 var reFormat =
new RegExp(
'["' + delimiter +
"\n]"), delimiterCode = delimiter.charCodeAt(0);
2016 function dsv(url, row, callback) {
2017 if (arguments.length < 3) callback = row, row = null;
2018 var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
2019 xhr.row =
function(_) {
2020 return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
2024 function response(request) {
2025 return dsv.parse(request.responseText);
2027 function typedResponse(f) {
2028 return function(request) {
2029 return dsv.parse(request.responseText, f);
2032 dsv.parse =
function(text, f) {
2034 return dsv.parseRows(text,
function(row, i) {
2035 if (o)
return o(row, i - 1);
2036 var a =
new Function(
"d",
"return {" + row.map(
function(name, i) {
2037 return JSON.stringify(name) +
": d[" + i +
"]";
2038 }).join(
",") +
"}");
2039 o = f ?
function(row, i) {
2040 return f(a(row), i);
2044 dsv.parseRows =
function(text, f) {
2045 var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
2047 if (I >= N)
return EOF;
2048 if (eol)
return eol =
false, EOL;
2050 if (text.charCodeAt(j) === 34) {
2053 if (text.charCodeAt(i) === 34) {
2054 if (text.charCodeAt(i + 1) !== 34)
break;
2059 var c = text.charCodeAt(i + 1);
2062 if (text.charCodeAt(i + 2) === 10) ++I;
2063 }
else if (c === 10) {
2066 return text.slice(j + 1, i).replace(/
""/g,
'"');
2069 var c = text.charCodeAt(I++), k = 1;
2070 if (c === 10) eol =
true;
else if (c === 13) {
2072 if (text.charCodeAt(I) === 10) ++I, ++k;
2073 }
else if (c !== delimiterCode)
continue;
2074 return text.slice(j, I - k);
2076 return text.slice(j);
2078 while ((t = token()) !== EOF) {
2080 while (t !== EOL && t !== EOF) {
2084 if (f && (a = f(a, n++)) == null)
continue;
2089 dsv.format =
function(rows) {
2090 if (Array.isArray(rows[0]))
return dsv.formatRows(rows);
2091 var fieldSet =
new d3_Set(), fields = [];
2092 rows.forEach(
function(row) {
2093 for (var field in row) {
2094 if (!fieldSet.has(field)) {
2095 fields.push(fieldSet.add(field));
2099 return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(
function(row) {
2100 return fields.map(
function(field) {
2101 return formatValue(row[field]);
2105 dsv.formatRows =
function(rows) {
2106 return rows.map(formatRow).join(
"\n");
2108 function formatRow(row) {
2109 return row.map(formatValue).join(delimiter);
2111 function formatValue(text) {
2112 return reFormat.test(text) ?
'"' + text.replace(/\
"/g, '""') + '"' : text;
2116 d3.csv = d3.dsv(",", "text/csv");
2117 d3.tsv = d3.dsv(" ", "text/tab-separated-values");
2118 var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_active, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
2119 setTimeout(callback, 17);
2121 d3.timer = function(callback, delay, then) {
2122 var n = arguments.length;
2123 if (n < 2) delay = 0;
2124 if (n < 3) then = Date.now();
2125 var time = then + delay, timer = {
2131 if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
2132 d3_timer_queueTail = timer;
2133 if (!d3_timer_interval) {
2134 d3_timer_timeout = clearTimeout(d3_timer_timeout);
2135 d3_timer_interval = 1;
2136 d3_timer_frame(d3_timer_step);
2139 function d3_timer_step() {
2140 var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
2142 if (isFinite(delay)) {
2143 clearTimeout(d3_timer_timeout);
2144 d3_timer_timeout = setTimeout(d3_timer_step, delay);
2146 d3_timer_interval = 0;
2148 d3_timer_interval = 1;
2149 d3_timer_frame(d3_timer_step);
2152 d3.timer.flush = function() {
2156 function d3_timer_mark() {
2157 var now = Date.now();
2158 d3_timer_active = d3_timer_queueHead;
2159 while (d3_timer_active) {
2160 if (now >= d3_timer_active.t) d3_timer_active.f = d3_timer_active.c(now - d3_timer_active.t);
2161 d3_timer_active = d3_timer_active.n;
2165 function d3_timer_sweep() {
2166 var t0, t1 = d3_timer_queueHead, time = Infinity;
2169 t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
2171 if (t1.t < time) time = t1.t;
2175 d3_timer_queueTail = t0;
2178 function d3_format_precision(x, p) {
2179 return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
2181 d3.round = function(x, n) {
2182 return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
2184 var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
2185 d3.formatPrefix = function(value, precision) {
2188 if (value < 0) value *= -1;
2189 if (precision) value = d3.round(value, d3_format_precision(value, precision));
2190 i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
2191 i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
2193 return d3_formatPrefixes[8 + i / 3];
2195 function d3_formatPrefix(d, i) {
2196 var k = Math.pow(10, abs(8 - i) * 3);
2198 scale: i > 8 ? function(d) {
2206 function d3_locale_numberFormat(locale) {
2207 var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping && locale_thousands ? function(value, width) {
2208 var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
2209 while (i > 0 && g > 0) {
2210 if (length + g + 1 > width) g = Math.max(1, width - length);
2211 t.push(value.substring(i -= g, i + g));
2212 if ((length += g + 1) > width) break;
2213 g = locale_grouping[j = (j + 1) % locale_grouping.length];
2215 return t.reverse().join(locale_thousands);
2217 return function(specifier) {
2218 var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "-", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false, exponent = true;
2219 if (precision) precision = +precision.substring(1);
2220 if (zfill || fill === "0" && align === "=") {
2246 if (symbol === "#") prefix = "0" + type.toLowerCase();
2261 if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
2262 if (type == "r" && !precision) type = "g";
2263 if (precision != null) {
2264 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));
2266 type = d3_format_types.get(type) || d3_format_typeDefault;
2267 var zcomma = zfill && comma;
2268 return function(value) {
2269 var fullSuffix = suffix;
2270 if (integer && value % 1) return "";
2271 var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
2273 var unit = d3.formatPrefix(value, precision);
2274 value = unit.scale(value);
2275 fullSuffix = unit.symbol + suffix;
2279 value = type(value, precision);
2280 var i = value.lastIndexOf("."), before, after;
2282 var j = exponent ? value.lastIndexOf("e") : -1;
2283 if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
2285 before = value.substring(0, i);
2286 after = locale_decimal + value.substring(i + 1);
2288 if (!zfill && comma) before = formatGroup(before, Infinity);
2289 var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
2290 if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
2292 value = before + after;
2293 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;
2297 var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
2298 var d3_format_types = d3.map({
2300 return x.toString(2);
2303 return String.fromCharCode(x);
2306 return x.toString(8);
2309 return x.toString(16);
2312 return x.toString(16).toUpperCase();
2315 return x.toPrecision(p);
2318 return x.toExponential(p);
2321 return x.toFixed(p);
2324 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))));
2327 function d3_format_typeDefault(x) {
2330 var d3_time = d3.time = {}, d3_date = Date;
2331 function d3_date_utc() {
2332 this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
2334 d3_date_utc.prototype = {
2335 getDate: function() {
2336 return this._.getUTCDate();
2338 getDay: function() {
2339 return this._.getUTCDay();
2341 getFullYear: function() {
2342 return this._.getUTCFullYear();
2344 getHours: function() {
2345 return this._.getUTCHours();
2347 getMilliseconds: function() {
2348 return this._.getUTCMilliseconds();
2350 getMinutes: function() {
2351 return this._.getUTCMinutes();
2353 getMonth: function() {
2354 return this._.getUTCMonth();
2356 getSeconds: function() {
2357 return this._.getUTCSeconds();
2359 getTime: function() {
2360 return this._.getTime();
2362 getTimezoneOffset: function() {
2365 valueOf: function() {
2366 return this._.valueOf();
2368 setDate: function() {
2369 d3_time_prototype.setUTCDate.apply(this._, arguments);
2371 setDay: function() {
2372 d3_time_prototype.setUTCDay.apply(this._, arguments);
2374 setFullYear: function() {
2375 d3_time_prototype.setUTCFullYear.apply(this._, arguments);
2377 setHours: function() {
2378 d3_time_prototype.setUTCHours.apply(this._, arguments);
2380 setMilliseconds: function() {
2381 d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
2383 setMinutes: function() {
2384 d3_time_prototype.setUTCMinutes.apply(this._, arguments);
2386 setMonth: function() {
2387 d3_time_prototype.setUTCMonth.apply(this._, arguments);
2389 setSeconds: function() {
2390 d3_time_prototype.setUTCSeconds.apply(this._, arguments);
2392 setTime: function() {
2393 d3_time_prototype.setTime.apply(this._, arguments);
2396 var d3_time_prototype = Date.prototype;
2397 function d3_time_interval(local, step, number) {
2398 function round(date) {
2399 var d0 = local(date), d1 = offset(d0, 1);
2400 return date - d0 < d1 - date ? d0 : d1;
2402 function ceil(date) {
2403 step(date = local(new d3_date(date - 1)), 1);
2406 function offset(date, k) {
2407 step(date = new d3_date(+date), k);
2410 function range(t0, t1, dt) {
2411 var time = ceil(t0), times = [];
2414 if (!(number(time) % dt)) times.push(new Date(+time));
2418 while (time < t1) times.push(new Date(+time)), step(time, 1);
2422 function range_utc(t0, t1, dt) {
2424 d3_date = d3_date_utc;
2425 var utc = new d3_date_utc();
2427 return range(utc, t1, dt);
2432 local.floor = local;
2433 local.round = round;
2435 local.offset = offset;
2436 local.range = range;
2437 var utc = local.utc = d3_time_interval_utc(local);
2439 utc.round = d3_time_interval_utc(round);
2440 utc.ceil = d3_time_interval_utc(ceil);
2441 utc.offset = d3_time_interval_utc(offset);
2442 utc.range = range_utc;
2445 function d3_time_interval_utc(method) {
2446 return function(date, k) {
2448 d3_date = d3_date_utc;
2449 var utc = new d3_date_utc();
2451 return method(utc, k)._;
2457 d3_time.year = d3_time_interval(function(date) {
2458 date = d3_time.day(date);
2459 date.setMonth(0, 1);
2461 }, function(date, offset) {
2462 date.setFullYear(date.getFullYear() + offset);
2464 return date.getFullYear();
2466 d3_time.years = d3_time.year.range;
2467 d3_time.years.utc = d3_time.year.utc.range;
2468 d3_time.day = d3_time_interval(function(date) {
2469 var day = new d3_date(2e3, 0);
2470 day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
2472 }, function(date, offset) {
2473 date.setDate(date.getDate() + offset);
2475 return date.getDate() - 1;
2477 d3_time.days = d3_time.day.range;
2478 d3_time.days.utc = d3_time.day.utc.range;
2479 d3_time.dayOfYear = function(date) {
2480 var year = d3_time.year(date);
2481 return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
2483 [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
2485 var interval = d3_time[day] = d3_time_interval(function(date) {
2486 (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
2488 }, function(date, offset) {
2489 date.setDate(date.getDate() + Math.floor(offset) * 7);
2491 var day = d3_time.year(date).getDay();
2492 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
2494 d3_time[day + "s"] = interval.range;
2495 d3_time[day + "s"].utc = interval.utc.range;
2496 d3_time[day + "OfYear"] = function(date) {
2497 var day = d3_time.year(date).getDay();
2498 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
2501 d3_time.week = d3_time.sunday;
2502 d3_time.weeks = d3_time.sunday.range;
2503 d3_time.weeks.utc = d3_time.sunday.utc.range;
2504 d3_time.weekOfYear = d3_time.sundayOfYear;
2505 function d3_locale_timeFormat(locale) {
2506 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;
2507 function d3_time_format(template) {
2508 var n = template.length;
2509 function format(date) {
2510 var string = [], i = -1, j = 0, c, p, f;
2512 if (template.charCodeAt(i) === 37) {
2513 string.push(template.slice(j, i));
2514 if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
2515 if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
2520 string.push(template.slice(j, i));
2521 return string.join("");
2523 format.parse = function(string) {
2533 }, i = d3_time_parse(d, template, string, 0);
2534 if (i != string.length) return null;
2535 if ("p" in d) d.H = d.H % 12 + d.p * 12;
2536 var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
2537 if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
2538 date.setFullYear(d.y, 0, 1);
2539 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);
2540 } else date.setFullYear(d.y, d.m, d.d);
2541 date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
2542 return localZ ? date._ : date;
2544 format.toString = function() {
2549 function d3_time_parse(date, template, string, j) {
2550 var c, p, t, i = 0, n = template.length, m = string.length;
2552 if (j >= m) return -1;
2553 c = template.charCodeAt(i++);
2555 t = template.charAt(i++);
2556 p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
2557 if (!p || (j = p(date, string, j)) < 0) return -1;
2558 } else if (c != string.charCodeAt(j++)) {
2564 d3_time_format.utc = function(template) {
2565 var local = d3_time_format(template);
2566 function format(date) {
2568 d3_date = d3_date_utc;
2569 var utc = new d3_date();
2576 format.parse = function(string) {
2578 d3_date = d3_date_utc;
2579 var date = local.parse(string);
2580 return date && date._;
2585 format.toString = local.toString;
2588 d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
2589 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);
2590 locale_periods.forEach(function(p, i) {
2591 d3_time_periodLookup.set(p.toLowerCase(), i);
2593 var d3_time_formats = {
2595 return locale_shortDays[d.getDay()];
2598 return locale_days[d.getDay()];
2601 return locale_shortMonths[d.getMonth()];
2604 return locale_months[d.getMonth()];
2606 c: d3_time_format(locale_dateTime),
2608 return d3_time_formatPad(d.getDate(), p, 2);
2611 return d3_time_formatPad(d.getDate(), p, 2);
2614 return d3_time_formatPad(d.getHours(), p, 2);
2617 return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
2620 return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
2623 return d3_time_formatPad(d.getMilliseconds(), p, 3);
2626 return d3_time_formatPad(d.getMonth() + 1, p, 2);
2629 return d3_time_formatPad(d.getMinutes(), p, 2);
2632 return locale_periods[+(d.getHours() >= 12)];
2635 return d3_time_formatPad(d.getSeconds(), p, 2);
2638 return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
2644 return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
2646 x: d3_time_format(locale_date),
2647 X: d3_time_format(locale_time),
2649 return d3_time_formatPad(d.getFullYear() % 100, p, 2);
2652 return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
2659 var d3_time_parsers = {
2660 a: d3_time_parseWeekdayAbbrev,
2661 A: d3_time_parseWeekday,
2662 b: d3_time_parseMonthAbbrev,
2663 B: d3_time_parseMonth,
2664 c: d3_time_parseLocaleFull,
2665 d: d3_time_parseDay,
2666 e: d3_time_parseDay,
2667 H: d3_time_parseHour24,
2668 I: d3_time_parseHour24,
2669 j: d3_time_parseDayOfYear,
2670 L: d3_time_parseMilliseconds,
2671 m: d3_time_parseMonthNumber,
2672 M: d3_time_parseMinutes,
2673 p: d3_time_parseAmPm,
2674 S: d3_time_parseSeconds,
2675 U: d3_time_parseWeekNumberSunday,
2676 w: d3_time_parseWeekdayNumber,
2677 W: d3_time_parseWeekNumberMonday,
2678 x: d3_time_parseLocaleDate,
2679 X: d3_time_parseLocaleTime,
2680 y: d3_time_parseYear,
2681 Y: d3_time_parseFullYear,
2682 Z: d3_time_parseZone,
2683 "%": d3_time_parseLiteralPercent
2685 function d3_time_parseWeekdayAbbrev(date, string, i) {
2686 d3_time_dayAbbrevRe.lastIndex = 0;
2687 var n = d3_time_dayAbbrevRe.exec(string.slice(i));
2688 return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2690 function d3_time_parseWeekday(date, string, i) {
2691 d3_time_dayRe.lastIndex = 0;
2692 var n = d3_time_dayRe.exec(string.slice(i));
2693 return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2695 function d3_time_parseMonthAbbrev(date, string, i) {
2696 d3_time_monthAbbrevRe.lastIndex = 0;
2697 var n = d3_time_monthAbbrevRe.exec(string.slice(i));
2698 return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2700 function d3_time_parseMonth(date, string, i) {
2701 d3_time_monthRe.lastIndex = 0;
2702 var n = d3_time_monthRe.exec(string.slice(i));
2703 return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2705 function d3_time_parseLocaleFull(date, string, i) {
2706 return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
2708 function d3_time_parseLocaleDate(date, string, i) {
2709 return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
2711 function d3_time_parseLocaleTime(date, string, i) {
2712 return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
2714 function d3_time_parseAmPm(date, string, i) {
2715 var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
2716 return n == null ? -1 : (date.p = n, i);
2718 return d3_time_format;
2720 var d3_time_formatPads = {
2724 }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
2725 function d3_time_formatPad(value, fill, width) {
2726 var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
2727 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
2729 function d3_time_formatRe(names) {
2730 return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
2732 function d3_time_formatLookup(names) {
2733 var map = new d3_Map(), i = -1, n = names.length;
2734 while (++i < n) map.set(names[i].toLowerCase(), i);
2737 function d3_time_parseWeekdayNumber(date, string, i) {
2738 d3_time_numberRe.lastIndex = 0;
2739 var n = d3_time_numberRe.exec(string.slice(i, i + 1));
2740 return n ? (date.w = +n[0], i + n[0].length) : -1;
2742 function d3_time_parseWeekNumberSunday(date, string, i) {
2743 d3_time_numberRe.lastIndex = 0;
2744 var n = d3_time_numberRe.exec(string.slice(i));
2745 return n ? (date.U = +n[0], i + n[0].length) : -1;
2747 function d3_time_parseWeekNumberMonday(date, string, i) {
2748 d3_time_numberRe.lastIndex = 0;
2749 var n = d3_time_numberRe.exec(string.slice(i));
2750 return n ? (date.W = +n[0], i + n[0].length) : -1;
2752 function d3_time_parseFullYear(date, string, i) {
2753 d3_time_numberRe.lastIndex = 0;
2754 var n = d3_time_numberRe.exec(string.slice(i, i + 4));
2755 return n ? (date.y = +n[0], i + n[0].length) : -1;
2757 function d3_time_parseYear(date, string, i) {
2758 d3_time_numberRe.lastIndex = 0;
2759 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2760 return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
2762 function d3_time_parseZone(date, string, i) {
2763 return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
2766 function d3_time_expandYear(d) {
2767 return d + (d > 68 ? 1900 : 2e3);
2769 function d3_time_parseMonthNumber(date, string, i) {
2770 d3_time_numberRe.lastIndex = 0;
2771 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2772 return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
2774 function d3_time_parseDay(date, string, i) {
2775 d3_time_numberRe.lastIndex = 0;
2776 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2777 return n ? (date.d = +n[0], i + n[0].length) : -1;
2779 function d3_time_parseDayOfYear(date, string, i) {
2780 d3_time_numberRe.lastIndex = 0;
2781 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
2782 return n ? (date.j = +n[0], i + n[0].length) : -1;
2784 function d3_time_parseHour24(date, string, i) {
2785 d3_time_numberRe.lastIndex = 0;
2786 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2787 return n ? (date.H = +n[0], i + n[0].length) : -1;
2789 function d3_time_parseMinutes(date, string, i) {
2790 d3_time_numberRe.lastIndex = 0;
2791 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2792 return n ? (date.M = +n[0], i + n[0].length) : -1;
2794 function d3_time_parseSeconds(date, string, i) {
2795 d3_time_numberRe.lastIndex = 0;
2796 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2797 return n ? (date.S = +n[0], i + n[0].length) : -1;
2799 function d3_time_parseMilliseconds(date, string, i) {
2800 d3_time_numberRe.lastIndex = 0;
2801 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
2802 return n ? (date.L = +n[0], i + n[0].length) : -1;
2804 function d3_time_zone(d) {
2805 var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
2806 return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
2808 function d3_time_parseLiteralPercent(date, string, i) {
2809 d3_time_percentRe.lastIndex = 0;
2810 var n = d3_time_percentRe.exec(string.slice(i, i + 1));
2811 return n ? i + n[0].length : -1;
2813 function d3_time_formatMulti(formats) {
2814 var n = formats.length, i = -1;
2815 while (++i < n) formats[i][0] = this(formats[i][0]);
2816 return function(date) {
2817 var i = 0, f = formats[i];
2818 while (!f[1](date)) f = formats[++i];
2822 d3.locale = function(locale) {
2824 numberFormat: d3_locale_numberFormat(locale),
2825 timeFormat: d3_locale_timeFormat(locale)
2828 var d3_locale_enUS = d3.locale({
2832 currency: [ "$", "" ],
2833 dateTime: "%a %b %e %X %Y",
2836 periods: [ "AM", "PM" ],
2837 days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
2838 shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
2839 months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
2840 shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
2842 d3.format = d3_locale_enUS.numberFormat;
2844 function d3_adder() {}
2845 d3_adder.prototype = {
2849 d3_adderSum(y, this.t, d3_adderTemp);
2850 d3_adderSum(d3_adderTemp.s, this.s, this);
2851 if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
2854 this.s = this.t = 0;
2856 valueOf: function() {
2860 var d3_adderTemp = new d3_adder();
2861 function d3_adderSum(a, b, o) {
2862 var x = o.s = a + b, bv = x - a, av = x - bv;
2863 o.t = a - av + (b - bv);
2865 d3.geo.stream = function(object, listener) {
2866 if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
2867 d3_geo_streamObjectType[object.type](object, listener);
2869 d3_geo_streamGeometry(object, listener);
2872 function d3_geo_streamGeometry(geometry, listener) {
2873 if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
2874 d3_geo_streamGeometryType[geometry.type](geometry, listener);
2877 var d3_geo_streamObjectType = {
2878 Feature: function(feature, listener) {
2879 d3_geo_streamGeometry(feature.geometry, listener);
2881 FeatureCollection: function(object, listener) {
2882 var features = object.features, i = -1, n = features.length;
2883 while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
2886 var d3_geo_streamGeometryType = {
2887 Sphere: function(object, listener) {
2890 Point: function(object, listener) {
2891 object = object.coordinates;
2892 listener.point(object[0], object[1], object[2]);
2894 MultiPoint: function(object, listener) {
2895 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2896 while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
2898 LineString: function(object, listener) {
2899 d3_geo_streamLine(object.coordinates, listener, 0);
2901 MultiLineString: function(object, listener) {
2902 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2903 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
2905 Polygon: function(object, listener) {
2906 d3_geo_streamPolygon(object.coordinates, listener);
2908 MultiPolygon: function(object, listener) {
2909 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2910 while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
2912 GeometryCollection: function(object, listener) {
2913 var geometries = object.geometries, i = -1, n = geometries.length;
2914 while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
2917 function d3_geo_streamLine(coordinates, listener, closed) {
2918 var i = -1, n = coordinates.length - closed, coordinate;
2919 listener.lineStart();
2920 while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
2923 function d3_geo_streamPolygon(coordinates, listener) {
2924 var i = -1, n = coordinates.length;
2925 listener.polygonStart();
2926 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
2927 listener.polygonEnd();
2929 d3.geo.area = function(object) {
2931 d3.geo.stream(object, d3_geo_area);
2932 return d3_geo_areaSum;
2934 var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
2936 sphere: function() {
2937 d3_geo_areaSum += 4 * π;
2942 polygonStart: function() {
2943 d3_geo_areaRingSum.reset();
2944 d3_geo_area.lineStart = d3_geo_areaRingStart;
2946 polygonEnd: function() {
2947 var area = 2 * d3_geo_areaRingSum;
2948 d3_geo_areaSum += area < 0 ? 4 * π + area : area;
2949 d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
2952 function d3_geo_areaRingStart() {
2953 var λ00, φ00, λ0, cosφ0, sinφ0;
2954 d3_geo_area.point = function(λ, φ) {
2955 d3_geo_area.point = nextPoint;
2956 λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
2957 sinφ0 = Math.sin(φ);
2959 function nextPoint(λ, φ) {
2961 φ = φ * d3_radians / 2 + π / 4;
2962 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λ);
2963 d3_geo_areaRingSum.add(Math.atan2(v, u));
2964 λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
2966 d3_geo_area.lineEnd = function() {
2967 nextPoint(λ00, φ00);
2970 function d3_geo_cartesian(spherical) {
2971 var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
2972 return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
2974 function d3_geo_cartesianDot(a, b) {
2975 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
2977 function d3_geo_cartesianCross(a, b) {
2978 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] ];
2980 function d3_geo_cartesianAdd(a, b) {
2985 function d3_geo_cartesianScale(vector, k) {
2986 return [ vector[0] * k, vector[1] * k, vector[2] * k ];
2988 function d3_geo_cartesianNormalize(d) {
2989 var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
2994 function d3_geo_spherical(cartesian) {
2995 return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
2997 function d3_geo_sphericalEqual(a, b) {
2998 return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
3000 d3.geo.bounds = function() {
3001 var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
3004 lineStart: lineStart,
3006 polygonStart: function() {
3007 bound.point = ringPoint;
3008 bound.lineStart = ringStart;
3009 bound.lineEnd = ringEnd;
3011 d3_geo_area.polygonStart();
3013 polygonEnd: function() {
3014 d3_geo_area.polygonEnd();
3015 bound.point = point;
3016 bound.lineStart = lineStart;
3017 bound.lineEnd = lineEnd;
3018 if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
3019 range[0] = λ0, range[1] = λ1;
3022 function point(λ, φ) {
3023 ranges.push(range = [ λ0 = λ, λ1 = λ ]);
3027 function linePoint(λ, φ) {
3028 var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
3030 var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
3031 d3_geo_cartesianNormalize(inflection);
3032 inflection = d3_geo_spherical(inflection);
3033 var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
3034 if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
3035 var φi = inflection[1] * d3_degrees;
3036 if (φi > φ1) φ1 = φi;
3037 } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
3038 var φi = -inflection[1] * d3_degrees;
3039 if (φi < φ0) φ0 = φi;
3046 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
3048 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
3056 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
3058 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
3067 function lineStart() {
3068 bound.point = linePoint;
3070 function lineEnd() {
3071 range[0] = λ0, range[1] = λ1;
3072 bound.point = point;
3075 function ringPoint(λ, φ) {
3078 dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
3079 } else λ__ = λ, φ__ = φ;
3080 d3_geo_area.point(λ, φ);
3083 function ringStart() {
3084 d3_geo_area.lineStart();
3086 function ringEnd() {
3087 ringPoint(λ__, φ__);
3088 d3_geo_area.lineEnd();
3089 if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
3090 range[0] = λ0, range[1] = λ1;
3093 function angle(λ0, λ1) {
3094 return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
3096 function compareRanges(a, b) {
3099 function withinRange(x, range) {
3100 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
3102 return function(feature) {
3103 φ1 = λ1 = -(λ0 = φ0 = Infinity);
3105 d3.geo.stream(feature, bound);
3106 var n = ranges.length;
3108 ranges.sort(compareRanges);
3109 for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
3111 if (withinRange(b[0], a) || withinRange(b[1], a)) {
3112 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
3113 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
3118 var best = -Infinity, dλ;
3119 for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
3121 if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
3124 ranges = range = null;
3125 return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
3128 d3.geo.centroid = function(object) {
3129 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;
3130 d3.geo.stream(object, d3_geo_centroid);
3131 var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
3133 x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
3134 if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
3135 m = x * x + y * y + z * z;
3136 if (m < ε2) return [ NaN, NaN ];
3138 return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
3140 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;
3141 var d3_geo_centroid = {
3143 point: d3_geo_centroidPoint,
3144 lineStart: d3_geo_centroidLineStart,
3145 lineEnd: d3_geo_centroidLineEnd,
3146 polygonStart: function() {
3147 d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
3149 polygonEnd: function() {
3150 d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
3153 function d3_geo_centroidPoint(λ, φ) {
3155 var cosφ = Math.cos(φ *= d3_radians);
3156 d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
3158 function d3_geo_centroidPointXYZ(x, y, z) {
3159 ++d3_geo_centroidW0;
3160 d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
3161 d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
3162 d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
3164 function d3_geo_centroidLineStart() {
3166 d3_geo_centroid.point = function(λ, φ) {
3168 var cosφ = Math.cos(φ *= d3_radians);
3169 x0 = cosφ * Math.cos(λ);
3170 y0 = cosφ * Math.sin(λ);
3172 d3_geo_centroid.point = nextPoint;
3173 d3_geo_centroidPointXYZ(x0, y0, z0);
3175 function nextPoint(λ, φ) {
3177 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);
3178 d3_geo_centroidW1 += w;
3179 d3_geo_centroidX1 += w * (x0 + (x0 = x));
3180 d3_geo_centroidY1 += w * (y0 + (y0 = y));
3181 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3182 d3_geo_centroidPointXYZ(x0, y0, z0);
3185 function d3_geo_centroidLineEnd() {
3186 d3_geo_centroid.point = d3_geo_centroidPoint;
3188 function d3_geo_centroidRingStart() {
3189 var λ00, φ00, x0, y0, z0;
3190 d3_geo_centroid.point = function(λ, φ) {
3192 d3_geo_centroid.point = nextPoint;
3194 var cosφ = Math.cos(φ *= d3_radians);
3195 x0 = cosφ * Math.cos(λ);
3196 y0 = cosφ * Math.sin(λ);
3198 d3_geo_centroidPointXYZ(x0, y0, z0);
3200 d3_geo_centroid.lineEnd = function() {
3201 nextPoint(λ00, φ00);
3202 d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
3203 d3_geo_centroid.point = d3_geo_centroidPoint;
3205 function nextPoint(λ, φ) {
3207 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);
3208 d3_geo_centroidX2 += v * cx;
3209 d3_geo_centroidY2 += v * cy;
3210 d3_geo_centroidZ2 += v * cz;
3211 d3_geo_centroidW1 += w;
3212 d3_geo_centroidX1 += w * (x0 + (x0 = x));
3213 d3_geo_centroidY1 += w * (y0 + (y0 = y));
3214 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3215 d3_geo_centroidPointXYZ(x0, y0, z0);
3218 function d3_geo_compose(a, b) {
3219 function compose(x, y) {
3220 return x = a(x, y), b(x[0], x[1]);
3222 if (a.invert && b.invert) compose.invert = function(x, y) {
3223 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
3227 function d3_true() {
3230 function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
3231 var subject = [], clip = [];
3232 segments.forEach(function(segment) {
3233 if ((n = segment.length - 1) <= 0) return;
3234 var n, p0 = segment[0], p1 = segment[n];
3235 if (d3_geo_sphericalEqual(p0, p1)) {
3236 listener.lineStart();
3237 for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
3241 var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
3245 a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
3246 b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
3252 d3_geo_clipPolygonLinkCircular(subject);
3253 d3_geo_clipPolygonLinkCircular(clip);
3254 if (!subject.length) return;
3255 for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
3256 clip[i].e = entry = !entry;
3258 var start = subject[0], points, point;
3260 var current = start, isSubject = true;
3261 while (current.v) if ((current = current.n) === start) return;
3263 listener.lineStart();
3265 current.v = current.o.v = true;
3268 for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
3270 interpolate(current.x, current.n.x, 1, listener);
3272 current = current.n;
3275 points = current.p.z;
3276 for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
3278 interpolate(current.x, current.p.x, -1, listener);
3280 current = current.p;
3282 current = current.o;
3284 isSubject = !isSubject;
3285 } while (!current.v);
3289 function d3_geo_clipPolygonLinkCircular(array) {
3290 if (!(n = array.length)) return;
3291 var n, i = 0, a = array[0], b;
3300 function d3_geo_clipPolygonIntersection(point, points, other, entry) {
3306 this.n = this.p = null;
3308 function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
3309 return function(rotate, listener) {
3310 var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
3313 lineStart: lineStart,
3315 polygonStart: function() {
3316 clip.point = pointRing;
3317 clip.lineStart = ringStart;
3318 clip.lineEnd = ringEnd;
3322 polygonEnd: function() {
3324 clip.lineStart = lineStart;
3325 clip.lineEnd = lineEnd;
3326 segments = d3.merge(segments);
3327 var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
3328 if (segments.length) {
3329 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3330 d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
3331 } else if (clipStartInside) {
3332 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3333 listener.lineStart();
3334 interpolate(null, null, 1, listener);
3337 if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
3338 segments = polygon = null;
3340 sphere: function() {
3341 listener.polygonStart();
3342 listener.lineStart();
3343 interpolate(null, null, 1, listener);
3345 listener.polygonEnd();
3348 function point(λ, φ) {
3349 var point = rotate(λ, φ);
3350 if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
3352 function pointLine(λ, φ) {
3353 var point = rotate(λ, φ);
3354 line.point(point[0], point[1]);
3356 function lineStart() {
3357 clip.point = pointLine;
3360 function lineEnd() {
3365 var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
3366 function pointRing(λ, φ) {
3367 ring.push([ λ, φ ]);
3368 var point = rotate(λ, φ);
3369 ringListener.point(point[0], point[1]);
3371 function ringStart() {
3372 ringListener.lineStart();
3375 function ringEnd() {
3376 pointRing(ring[0][0], ring[0][1]);
3377 ringListener.lineEnd();
3378 var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
3384 segment = ringSegments[0];
3385 var n = segment.length - 1, i = -1, point;
3387 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3388 listener.lineStart();
3389 while (++i < n) listener.point((point = segment[i])[0], point[1]);
3394 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
3395 segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
3400 function d3_geo_clipSegmentLength1(segment) {
3401 return segment.length > 1;
3403 function d3_geo_clipBufferListener() {
3404 var lines = [], line;
3406 lineStart: function() {
3407 lines.push(line = []);
3409 point: function(λ, φ) {
3410 line.push([ λ, φ ]);
3413 buffer: function() {
3419 rejoin: function() {
3420 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
3424 function d3_geo_clipSort(a, b) {
3425 return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
3427 var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
3428 function d3_geo_clipAntimeridianLine(listener) {
3429 var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
3431 lineStart: function() {
3432 listener.lineStart();
3435 point: function(λ1, φ1) {
3436 var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
3437 if (abs(dλ - π) < ε) {
3438 listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
3439 listener.point(sλ0, φ0);
3441 listener.lineStart();
3442 listener.point(sλ1, φ0);
3443 listener.point(λ1, φ0);
3445 } else if (sλ0 !== sλ1 && dλ >= π) {
3446 if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
3447 if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
3448 φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
3449 listener.point(sλ0, φ0);
3451 listener.lineStart();
3452 listener.point(sλ1, φ0);
3455 listener.point(λ0 = λ1, φ0 = φ1);
3458 lineEnd: function() {
3467 function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
3468 var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
3469 return abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2;
3471 function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
3474 φ = direction * halfπ;
3475 listener.point(-π, φ);
3476 listener.point(0, φ);
3477 listener.point(π, φ);
3478 listener.point(π, 0);
3479 listener.point(π, -φ);
3480 listener.point(0, -φ);
3481 listener.point(-π, -φ);
3482 listener.point(-π, 0);
3483 listener.point(-π, φ);
3484 } else if (abs(from[0] - to[0]) > ε) {
3485 var s = from[0] < to[0] ? π : -π;
3486 φ = direction * s / 2;
3487 listener.point(-s, φ);
3488 listener.point(0, φ);
3489 listener.point(s, φ);
3491 listener.point(to[0], to[1]);
3494 function d3_geo_pointInPolygon(point, polygon) {
3495 var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
3496 d3_geo_areaRingSum.reset();
3497 for (var i = 0, n = polygon.length; i < n; ++i) {
3498 var ring = polygon[i], m = ring.length;
3500 var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
3504 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φ;
3505 d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
3506 polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
3507 if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
3508 var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
3509 d3_geo_cartesianNormalize(arc);
3510 var intersection = d3_geo_cartesianCross(meridianNormal, arc);
3511 d3_geo_cartesianNormalize(intersection);
3512 var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
3513 if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
3514 winding += antimeridian ^ dλ >= 0 ? 1 : -1;
3518 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
3521 return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
3523 function d3_geo_clipCircle(radius) {
3524 var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
3525 return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
3526 function visible(λ, φ) {
3527 return Math.cos(λ) * Math.cos(φ) > cr;
3529 function clipLine(listener) {
3530 var point0, c0, v0, v00, clean;
3532 lineStart: function() {
3536 point: function(λ, φ) {
3537 var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
3538 if (!point0 && (v00 = v0 = v)) listener.lineStart();
3540 point2 = intersect(point0, point1);
3541 if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
3544 v = visible(point1[0], point1[1]);
3550 listener.lineStart();
3551 point2 = intersect(point1, point0);
3552 listener.point(point2[0], point2[1]);
3554 point2 = intersect(point0, point1);
3555 listener.point(point2[0], point2[1]);
3559 } else if (notHemisphere && point0 && smallRadius ^ v) {
3561 if (!(c & c0) && (t = intersect(point1, point0, true))) {
3564 listener.lineStart();
3565 listener.point(t[0][0], t[0][1]);
3566 listener.point(t[1][0], t[1][1]);
3569 listener.point(t[1][0], t[1][1]);
3571 listener.lineStart();
3572 listener.point(t[0][0], t[0][1]);
3576 if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
3577 listener.point(point1[0], point1[1]);
3579 point0 = point1, v0 = v, c0 = c;
3581 lineEnd: function() {
3582 if (v0) listener.lineEnd();
3586 return clean | (v00 && v0) << 1;
3590 function intersect(a, b, two) {
3591 var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
3592 var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
3593 if (!determinant) return !two && a;
3594 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);
3595 d3_geo_cartesianAdd(A, B);
3596 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);
3598 var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
3599 d3_geo_cartesianAdd(q, A);
3600 q = d3_geo_spherical(q);
3602 var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
3603 if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
3604 var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
3605 if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
3606 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)) {
3607 var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
3608 d3_geo_cartesianAdd(q1, A);
3609 return [ q, d3_geo_spherical(q1) ];
3612 function code(λ, φ) {
3613 var r = smallRadius ? radius : π - radius, code = 0;
3614 if (λ < -r) code |= 1; else if (λ > r) code |= 2;
3615 if (φ < -r) code |= 4; else if (φ > r) code |= 8;
3619 function d3_geom_clipLine(x0, y0, x1, y1) {
3620 return function(line) {
3621 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;
3623 if (!dx && r > 0) return;
3628 } else if (dx > 0) {
3633 if (!dx && r < 0) return;
3638 } else if (dx > 0) {
3643 if (!dy && r > 0) return;
3648 } else if (dy > 0) {
3653 if (!dy && r < 0) return;
3658 } else if (dy > 0) {
3662 if (t0 > 0) line.a = {
3666 if (t1 < 1) line.b = {
3673 var d3_geo_clipExtentMAX = 1e9;
3674 d3.geo.clipExtent = function() {
3675 var x0, y0, x1, y1, stream, clip, clipExtent = {
3676 stream: function(output) {
3677 if (stream) stream.valid = false;
3678 stream = clip(output);
3679 stream.valid = true;
3682 extent: function(_) {
3683 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
3684 clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
3685 if (stream) stream.valid = false, stream = null;
3689 return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
3691 function d3_geo_clipExtent(x0, y0, x1, y1) {
3692 return function(listener) {
3693 var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
3696 lineStart: lineStart,
3698 polygonStart: function() {
3699 listener = bufferListener;
3704 polygonEnd: function() {
3705 listener = listener_;
3706 segments = d3.merge(segments);
3707 var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
3708 if (inside || visible) {
3709 listener.polygonStart();
3711 listener.lineStart();
3712 interpolate(null, null, 1, listener);
3716 d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
3718 listener.polygonEnd();
3720 segments = polygon = ring = null;
3723 function insidePolygon(p) {
3724 var wn = 0, n = polygon.length, y = p[1];
3725 for (var i = 0; i < n; ++i) {
3726 for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
3729 if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
3731 if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
3738 function interpolate(from, to, direction, listener) {
3740 if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
3742 listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
3743 } while ((a = (a + direction + 4) % 4) !== a1);
3745 listener.point(to[0], to[1]);
3748 function pointVisible(x, y) {
3749 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
3751 function point(x, y) {
3752 if (pointVisible(x, y)) listener.point(x, y);
3754 var x__, y__, v__, x_, y_, v_, first, clean;
3755 function lineStart() {
3756 clip.point = linePoint;
3757 if (polygon) polygon.push(ring = []);
3762 function lineEnd() {
3764 linePoint(x__, y__);
3765 if (v__ && v_) bufferListener.rejoin();
3766 segments.push(bufferListener.buffer());
3769 if (v_) listener.lineEnd();
3771 function linePoint(x, y) {
3772 x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
3773 y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
3774 var v = pointVisible(x, y);
3775 if (polygon) ring.push([ x, y ]);
3777 x__ = x, y__ = y, v__ = v;
3780 listener.lineStart();
3781 listener.point(x, y);
3784 if (v && v_) listener.point(x, y); else {
3797 listener.lineStart();
3798 listener.point(l.a.x, l.a.y);
3800 listener.point(l.b.x, l.b.y);
3801 if (!v) listener.lineEnd();
3804 listener.lineStart();
3805 listener.point(x, y);
3810 x_ = x, y_ = y, v_ = v;
3814 function corner(p, direction) {
3815 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;
3817 function compare(a, b) {
3818 return comparePoints(a.x, b.x);
3820 function comparePoints(a, b) {
3821 var ca = corner(a, 1), cb = corner(b, 1);
3822 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];
3825 function d3_geo_conic(projectAt) {
3826 var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
3827 p.parallels = function(_) {
3828 if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
3829 return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
3833 function d3_geo_conicEqualArea(φ0, φ1) {
3834 var sinφ0 = Math.sin(φ0), n = (sinφ0 + Math.sin(φ1)) / 2, C = 1 + sinφ0 * (2 * n - sinφ0), ρ0 = Math.sqrt(C) / n;
3835 function forward(λ, φ) {
3836 var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
3837 return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
3839 forward.invert = function(x, y) {
3841 return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
3845 (d3.geo.conicEqualArea = function() {
3846 return d3_geo_conic(d3_geo_conicEqualArea);
3847 }).raw = d3_geo_conicEqualArea;
3848 d3.geo.albers = function() {
3849 return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
3851 d3.geo.albersUsa = function() {
3852 var lower48 = d3.geo.albers();
3853 var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
3854 var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
3855 var point, pointStream = {
3856 point: function(x, y) {
3859 }, lower48Point, alaskaPoint, hawaiiPoint;
3860 function albersUsa(coordinates) {
3861 var x = coordinates[0], y = coordinates[1];
3863 (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
3866 albersUsa.invert = function(coordinates) {
3867 var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
3868 return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
3870 albersUsa.stream = function(stream) {
3871 var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
3873 point: function(x, y) {
3874 lower48Stream.point(x, y);
3875 alaskaStream.point(x, y);
3876 hawaiiStream.point(x, y);
3878 sphere: function() {
3879 lower48Stream.sphere();
3880 alaskaStream.sphere();
3881 hawaiiStream.sphere();
3883 lineStart: function() {
3884 lower48Stream.lineStart();
3885 alaskaStream.lineStart();
3886 hawaiiStream.lineStart();
3888 lineEnd: function() {
3889 lower48Stream.lineEnd();
3890 alaskaStream.lineEnd();
3891 hawaiiStream.lineEnd();
3893 polygonStart: function() {
3894 lower48Stream.polygonStart();
3895 alaskaStream.polygonStart();
3896 hawaiiStream.polygonStart();
3898 polygonEnd: function() {
3899 lower48Stream.polygonEnd();
3900 alaskaStream.polygonEnd();
3901 hawaiiStream.polygonEnd();
3905 albersUsa.precision = function(_) {
3906 if (!arguments.length) return lower48.precision();
3907 lower48.precision(_);
3908 alaska.precision(_);
3909 hawaii.precision(_);
3912 albersUsa.scale = function(_) {
3913 if (!arguments.length) return lower48.scale();
3915 alaska.scale(_ * .35);
3917 return albersUsa.translate(lower48.translate());
3919 albersUsa.translate = function(_) {
3920 if (!arguments.length) return lower48.translate();
3921 var k = lower48.scale(), x = +_[0], y = +_[1];
3922 lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
3923 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;
3924 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;
3927 return albersUsa.scale(1070);
3929 var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
3933 polygonStart: function() {
3934 d3_geo_pathAreaPolygon = 0;
3935 d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
3937 polygonEnd: function() {
3938 d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
3939 d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
3942 function d3_geo_pathAreaRingStart() {
3943 var x00, y00, x0, y0;
3944 d3_geo_pathArea.point = function(x, y) {
3945 d3_geo_pathArea.point = nextPoint;
3946 x00 = x0 = x, y00 = y0 = y;
3948 function nextPoint(x, y) {
3949 d3_geo_pathAreaPolygon += y0 * x - x0 * y;
3952 d3_geo_pathArea.lineEnd = function() {
3953 nextPoint(x00, y00);
3956 var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
3957 var d3_geo_pathBounds = {
3958 point: d3_geo_pathBoundsPoint,
3961 polygonStart: d3_noop,
3964 function d3_geo_pathBoundsPoint(x, y) {
3965 if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
3966 if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
3967 if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
3968 if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
3970 function d3_geo_pathBuffer() {
3971 var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
3974 lineStart: function() {
3975 stream.point = pointLineStart;
3978 polygonStart: function() {
3979 stream.lineEnd = lineEndPolygon;
3981 polygonEnd: function() {
3982 stream.lineEnd = lineEnd;
3983 stream.point = point;
3985 pointRadius: function(_) {
3986 pointCircle = d3_geo_pathBufferCircle(_);
3989 result: function() {
3990 if (buffer.length) {
3991 var result = buffer.join("");
3997 function point(x, y) {
3998 buffer.push("M", x, ",", y, pointCircle);
4000 function pointLineStart(x, y) {
4001 buffer.push("M", x, ",", y);
4002 stream.point = pointLine;
4004 function pointLine(x, y) {
4005 buffer.push("L", x, ",", y);
4007 function lineEnd() {
4008 stream.point = point;
4010 function lineEndPolygon() {
4015 function d3_geo_pathBufferCircle(radius) {
4016 return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
4018 var d3_geo_pathCentroid = {
4019 point: d3_geo_pathCentroidPoint,
4020 lineStart: d3_geo_pathCentroidLineStart,
4021 lineEnd: d3_geo_pathCentroidLineEnd,
4022 polygonStart: function() {
4023 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
4025 polygonEnd: function() {
4026 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
4027 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
4028 d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
4031 function d3_geo_pathCentroidPoint(x, y) {
4032 d3_geo_centroidX0 += x;
4033 d3_geo_centroidY0 += y;
4034 ++d3_geo_centroidZ0;
4036 function d3_geo_pathCentroidLineStart() {
4038 d3_geo_pathCentroid.point = function(x, y) {
4039 d3_geo_pathCentroid.point = nextPoint;
4040 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4042 function nextPoint(x, y) {
4043 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
4044 d3_geo_centroidX1 += z * (x0 + x) / 2;
4045 d3_geo_centroidY1 += z * (y0 + y) / 2;
4046 d3_geo_centroidZ1 += z;
4047 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4050 function d3_geo_pathCentroidLineEnd() {
4051 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
4053 function d3_geo_pathCentroidRingStart() {
4054 var x00, y00, x0, y0;
4055 d3_geo_pathCentroid.point = function(x, y) {
4056 d3_geo_pathCentroid.point = nextPoint;
4057 d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
4059 function nextPoint(x, y) {
4060 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
4061 d3_geo_centroidX1 += z * (x0 + x) / 2;
4062 d3_geo_centroidY1 += z * (y0 + y) / 2;
4063 d3_geo_centroidZ1 += z;
4064 z = y0 * x - x0 * y;
4065 d3_geo_centroidX2 += z * (x0 + x);
4066 d3_geo_centroidY2 += z * (y0 + y);
4067 d3_geo_centroidZ2 += z * 3;
4068 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4070 d3_geo_pathCentroid.lineEnd = function() {
4071 nextPoint(x00, y00);
4074 function d3_geo_pathContext(context) {
4075 var pointRadius = 4.5;
4078 lineStart: function() {
4079 stream.point = pointLineStart;
4082 polygonStart: function() {
4083 stream.lineEnd = lineEndPolygon;
4085 polygonEnd: function() {
4086 stream.lineEnd = lineEnd;
4087 stream.point = point;
4089 pointRadius: function(_) {
4095 function point(x, y) {
4096 context.moveTo(x + pointRadius, y);
4097 context.arc(x, y, pointRadius, 0, τ);
4099 function pointLineStart(x, y) {
4100 context.moveTo(x, y);
4101 stream.point = pointLine;
4103 function pointLine(x, y) {
4104 context.lineTo(x, y);
4106 function lineEnd() {
4107 stream.point = point;
4109 function lineEndPolygon() {
4110 context.closePath();
4114 function d3_geo_resample(project) {
4115 var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
4116 function resample(stream) {
4117 return (maxDepth ? resampleRecursive : resampleNone)(stream);
4119 function resampleNone(stream) {
4120 return d3_geo_transformPoint(stream, function(x, y) {
4122 stream.point(x[0], x[1]);
4125 function resampleRecursive(stream) {
4126 var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
4129 lineStart: lineStart,
4131 polygonStart: function() {
4132 stream.polygonStart();
4133 resample.lineStart = ringStart;
4135 polygonEnd: function() {
4136 stream.polygonEnd();
4137 resample.lineStart = lineStart;
4140 function point(x, y) {
4142 stream.point(x[0], x[1]);
4144 function lineStart() {
4146 resample.point = linePoint;
4149 function linePoint(λ, φ) {
4150 var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
4151 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);
4152 stream.point(x0, y0);
4154 function lineEnd() {
4155 resample.point = point;
4158 function ringStart() {
4160 resample.point = ringPoint;
4161 resample.lineEnd = ringEnd;
4163 function ringPoint(λ, φ) {
4164 linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
4165 resample.point = linePoint;
4167 function ringEnd() {
4168 resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
4169 resample.lineEnd = lineEnd;
4174 function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
4175 var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
4176 if (d2 > 4 * δ2 && depth--) {
4177 var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = abs(abs(c) - 1) < ε || abs(λ0 - λ1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
4178 if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
4179 resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
4180 stream.point(x2, y2);
4181 resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
4185 resample.precision = function(_) {
4186 if (!arguments.length) return Math.sqrt(δ2);
4187 maxDepth = (δ2 = _ * _) > 0 && 16;
4192 d3.geo.path = function() {
4193 var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
4194 function path(object) {
4196 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
4197 if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
4198 d3.geo.stream(object, cacheStream);
4200 return contextStream.result();
4202 path.area = function(object) {
4203 d3_geo_pathAreaSum = 0;
4204 d3.geo.stream(object, projectStream(d3_geo_pathArea));
4205 return d3_geo_pathAreaSum;
4207 path.centroid = function(object) {
4208 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;
4209 d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
4210 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 ];
4212 path.bounds = function(object) {
4213 d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
4214 d3.geo.stream(object, projectStream(d3_geo_pathBounds));
4215 return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
4217 path.projection = function(_) {
4218 if (!arguments.length) return projection;
4219 projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
4222 path.context = function(_) {
4223 if (!arguments.length) return context;
4224 contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
4225 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
4228 path.pointRadius = function(_) {
4229 if (!arguments.length) return pointRadius;
4230 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
4237 return path.projection(d3.geo.albersUsa()).context(null);
4239 function d3_geo_pathProjectStream(project) {
4240 var resample = d3_geo_resample(function(x, y) {
4241 return project([ x * d3_degrees, y * d3_degrees ]);
4243 return function(stream) {
4244 return d3_geo_projectionRadians(resample(stream));
4247 d3.geo.transform = function(methods) {
4249 stream: function(stream) {
4250 var transform = new d3_geo_transform(stream);
4251 for (var k in methods) transform[k] = methods[k];
4256 function d3_geo_transform(stream) {
4257 this.stream = stream;
4259 d3_geo_transform.prototype = {
4260 point: function(x, y) {
4261 this.stream.point(x, y);
4263 sphere: function() {
4264 this.stream.sphere();
4266 lineStart: function() {
4267 this.stream.lineStart();
4269 lineEnd: function() {
4270 this.stream.lineEnd();
4272 polygonStart: function() {
4273 this.stream.polygonStart();
4275 polygonEnd: function() {
4276 this.stream.polygonEnd();
4279 function d3_geo_transformPoint(stream, point) {
4282 sphere: function() {
4285 lineStart: function() {
4288 lineEnd: function() {
4291 polygonStart: function() {
4292 stream.polygonStart();
4294 polygonEnd: function() {
4295 stream.polygonEnd();
4299 d3.geo.projection = d3_geo_projection;
4300 d3.geo.projectionMutator = d3_geo_projectionMutator;
4301 function d3_geo_projection(project) {
4302 return d3_geo_projectionMutator(function() {
4306 function d3_geo_projectionMutator(projectAt) {
4307 var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
4309 return [ x[0] * k + δx, δy - x[1] * k ];
4310 }), 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;
4311 function projection(point) {
4312 point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
4313 return [ point[0] * k + δx, δy - point[1] * k ];
4315 function invert(point) {
4316 point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
4317 return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
4319 projection.stream = function(output) {
4320 if (stream) stream.valid = false;
4321 stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
4322 stream.valid = true;
4325 projection.clipAngle = function(_) {
4326 if (!arguments.length) return clipAngle;
4327 preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
4328 return invalidate();
4330 projection.clipExtent = function(_) {
4331 if (!arguments.length) return clipExtent;
4333 postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
4334 return invalidate();
4336 projection.scale = function(_) {
4337 if (!arguments.length) return k;
4341 projection.translate = function(_) {
4342 if (!arguments.length) return [ x, y ];
4347 projection.center = function(_) {
4348 if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
4349 λ = _[0] % 360 * d3_radians;
4350 φ = _[1] % 360 * d3_radians;
4353 projection.rotate = function(_) {
4354 if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
4355 δλ = _[0] % 360 * d3_radians;
4356 δφ = _[1] % 360 * d3_radians;
4357 δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
4360 d3.rebind(projection, projectResample, "precision");
4362 projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
4363 var center = project(λ, φ);
4364 δx = x - center[0] * k;
4365 δy = y + center[1] * k;
4366 return invalidate();
4368 function invalidate() {
4369 if (stream) stream.valid = false, stream = null;
4373 project = projectAt.apply(this, arguments);
4374 projection.invert = project.invert && invert;
4378 function d3_geo_projectionRadians(stream) {
4379 return d3_geo_transformPoint(stream, function(x, y) {
4380 stream.point(x * d3_radians, y * d3_radians);
4383 function d3_geo_equirectangular(λ, φ) {
4386 (d3.geo.equirectangular = function() {
4387 return d3_geo_projection(d3_geo_equirectangular);
4388 }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
4389 d3.geo.rotation = function(rotate) {
4390 rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
4391 function forward(coordinates) {
4392 coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4393 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
4395 forward.invert = function(coordinates) {
4396 coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4397 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
4401 function d3_geo_identityRotation(λ, φ) {
4402 return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
4404 d3_geo_identityRotation.invert = d3_geo_equirectangular;
4405 function d3_geo_rotation(δλ, δφ, δγ) {
4406 return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
4408 function d3_geo_forwardRotationλ(δλ) {
4409 return function(λ, φ) {
4410 return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
4413 function d3_geo_rotationλ(δλ) {
4414 var rotation = d3_geo_forwardRotationλ(δλ);
4415 rotation.invert = d3_geo_forwardRotationλ(-δλ);
4418 function d3_geo_rotationφγ(δφ, δγ) {
4419 var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
4420 function rotation(λ, φ) {
4421 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
4422 return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
4424 rotation.invert = function(λ, φ) {
4425 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
4426 return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
4430 d3.geo.circle = function() {
4431 var origin = [ 0, 0 ], angle, precision = 6, interpolate;
4433 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 = [];
4434 interpolate(null, null, 1, {
4435 point: function(x, y) {
4436 ring.push(x = rotate(x, y));
4437 x[0] *= d3_degrees, x[1] *= d3_degrees;
4442 coordinates: [ ring ]
4445 circle.origin = function(x) {
4446 if (!arguments.length) return origin;
4450 circle.angle = function(x) {
4451 if (!arguments.length) return angle;
4452 interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
4455 circle.precision = function(_) {
4456 if (!arguments.length) return precision;
4457 interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
4460 return circle.angle(90);
4462 function d3_geo_circleInterpolate(radius, precision) {
4463 var cr = Math.cos(radius), sr = Math.sin(radius);
4464 return function(from, to, direction, listener) {
4465 var step = direction * precision;
4467 from = d3_geo_circleAngle(cr, from);
4468 to = d3_geo_circleAngle(cr, to);
4469 if (direction > 0 ? from < to : from > to) from += direction * τ;
4471 from = radius + direction * τ;
4472 to = radius - .5 * step;
4474 for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
4475 listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
4479 function d3_geo_circleAngle(cr, point) {
4480 var a = d3_geo_cartesian(point);
4482 d3_geo_cartesianNormalize(a);
4483 var angle = d3_acos(-a[1]);
4484 return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
4486 d3.geo.distance = function(a, b) {
4487 var Δλ = (b[0] - a[0]) * d3_radians, φ0 = a[1] * d3_radians, φ1 = b[1] * d3_radians, sinΔλ = Math.sin(Δλ), cosΔλ = Math.cos(Δλ), sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1), t;
4488 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Δλ);
4490 d3.geo.graticule = function() {
4491 var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
4492 function graticule() {
4494 type: "MultiLineString",
4495 coordinates: lines()
4499 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) {
4500 return abs(x % DX) > ε;
4501 }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
4502 return abs(y % DY) > ε;
4505 graticule.lines = function() {
4506 return lines().map(function(coordinates) {
4509 coordinates: coordinates
4513 graticule.outline = function() {
4516 coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
4519 graticule.extent = function(_) {
4520 if (!arguments.length) return graticule.minorExtent();
4521 return graticule.majorExtent(_).minorExtent(_);
4523 graticule.majorExtent = function(_) {
4524 if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
4525 X0 = +_[0][0], X1 = +_[1][0];
4526 Y0 = +_[0][1], Y1 = +_[1][1];
4527 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
4528 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
4529 return graticule.precision(precision);
4531 graticule.minorExtent = function(_) {
4532 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
4533 x0 = +_[0][0], x1 = +_[1][0];
4534 y0 = +_[0][1], y1 = +_[1][1];
4535 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
4536 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
4537 return graticule.precision(precision);
4539 graticule.step = function(_) {
4540 if (!arguments.length) return graticule.minorStep();
4541 return graticule.majorStep(_).minorStep(_);
4543 graticule.majorStep = function(_) {
4544 if (!arguments.length) return [ DX, DY ];
4545 DX = +_[0], DY = +_[1];
4548 graticule.minorStep = function(_) {
4549 if (!arguments.length) return [ dx, dy ];
4550 dx = +_[0], dy = +_[1];
4553 graticule.precision = function(_) {
4554 if (!arguments.length) return precision;
4556 x = d3_geo_graticuleX(y0, y1, 90);
4557 y = d3_geo_graticuleY(x0, x1, precision);
4558 X = d3_geo_graticuleX(Y0, Y1, 90);
4559 Y = d3_geo_graticuleY(X0, X1, precision);
4562 return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
4564 function d3_geo_graticuleX(y0, y1, dy) {
4565 var y = d3.range(y0, y1 - ε, dy).concat(y1);
4566 return function(x) {
4567 return y.map(function(y) {
4572 function d3_geo_graticuleY(x0, x1, dx) {
4573 var x = d3.range(x0, x1 - ε, dx).concat(x1);
4574 return function(y) {
4575 return x.map(function(x) {
4580 function d3_source(d) {
4583 function d3_target(d) {
4586 d3.geo.greatArc = function() {
4587 var source = d3_source, source_, target = d3_target, target_;
4588 function greatArc() {
4591 coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
4594 greatArc.distance = function() {
4595 return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
4597 greatArc.source = function(_) {
4598 if (!arguments.length) return source;
4599 source = _, source_ = typeof _ === "function" ? null : _;
4602 greatArc.target = function(_) {
4603 if (!arguments.length) return target;
4604 target = _, target_ = typeof _ === "function" ? null : _;
4607 greatArc.precision = function() {
4608 return arguments.length ? greatArc : 0;
4612 d3.geo.interpolate = function(source, target) {
4613 return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
4615 function d3_geo_interpolate(x0, y0, x1, y1) {
4616 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);
4617 var interpolate = d ? function(t) {
4618 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;
4619 return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
4621 return [ x0 * d3_degrees, y0 * d3_degrees ];
4623 interpolate.distance = d;
4626 d3.geo.length = function(object) {
4627 d3_geo_lengthSum = 0;
4628 d3.geo.stream(object, d3_geo_length);
4629 return d3_geo_lengthSum;
4631 var d3_geo_lengthSum;
4632 var d3_geo_length = {
4635 lineStart: d3_geo_lengthLineStart,
4637 polygonStart: d3_noop,
4640 function d3_geo_lengthLineStart() {
4641 var λ0, sinφ0, cosφ0;
4642 d3_geo_length.point = function(λ, φ) {
4643 λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
4644 d3_geo_length.point = nextPoint;
4646 d3_geo_length.lineEnd = function() {
4647 d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
4649 function nextPoint(λ, φ) {
4650 var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
4651 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Δλ);
4652 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
4655 function d3_geo_azimuthal(scale, angle) {
4656 function azimuthal(λ, φ) {
4657 var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
4658 return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
4660 azimuthal.invert = function(x, y) {
4661 var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
4662 return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
4666 var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
4667 return Math.sqrt(2 / (1 + cosλcosφ));
4669 return 2 * Math.asin(ρ / 2);
4671 (d3.geo.azimuthalEqualArea = function() {
4672 return d3_geo_projection(d3_geo_azimuthalEqualArea);
4673 }).raw = d3_geo_azimuthalEqualArea;
4674 var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
4675 var c = Math.acos(cosλcosφ);
4676 return c && c / Math.sin(c);
4678 (d3.geo.azimuthalEquidistant = function() {
4679 return d3_geo_projection(d3_geo_azimuthalEquidistant);
4680 }).raw = d3_geo_azimuthalEquidistant;
4681 function d3_geo_conicConformal(φ0, φ1) {
4682 var cosφ0 = Math.cos(φ0), t = function(φ) {
4683 return Math.tan(π / 4 + φ / 2);
4684 }, n = φ0 === φ1 ? Math.sin(φ0) : Math.log(cosφ0 / Math.cos(φ1)) / Math.log(t(φ1) / t(φ0)), F = cosφ0 * Math.pow(t(φ0), n) / n;
4685 if (!n) return d3_geo_mercator;
4686 function forward(λ, φ) {
4688 if (φ < -halfπ + ε) φ = -halfπ + ε;
4690 if (φ > halfπ - ε) φ = halfπ - ε;
4692 var ρ = F / Math.pow(t(φ), n);
4693 return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
4695 forward.invert = function(x, y) {
4696 var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
4697 return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
4701 (d3.geo.conicConformal = function() {
4702 return d3_geo_conic(d3_geo_conicConformal);
4703 }).raw = d3_geo_conicConformal;
4704 function d3_geo_conicEquidistant(φ0, φ1) {
4705 var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
4706 if (abs(n) < ε) return d3_geo_equirectangular;
4707 function forward(λ, φ) {
4709 return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
4711 forward.invert = function(x, y) {
4713 return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
4717 (d3.geo.conicEquidistant = function() {
4718 return d3_geo_conic(d3_geo_conicEquidistant);
4719 }).raw = d3_geo_conicEquidistant;
4720 var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
4721 return 1 / cosλcosφ;
4723 (d3.geo.gnomonic = function() {
4724 return d3_geo_projection(d3_geo_gnomonic);
4725 }).raw = d3_geo_gnomonic;
4726 function d3_geo_mercator(λ, φ) {
4727 return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
4729 d3_geo_mercator.invert = function(x, y) {
4730 return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
4732 function d3_geo_mercatorProjection(project) {
4733 var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
4734 m.scale = function() {
4735 var v = scale.apply(m, arguments);
4736 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4738 m.translate = function() {
4739 var v = translate.apply(m, arguments);
4740 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4742 m.clipExtent = function(_) {
4743 var v = clipExtent.apply(m, arguments);
4745 if (clipAuto = _ == null) {
4746 var k = π * scale(), t = translate();
4747 clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
4749 } else if (clipAuto) {
4754 return m.clipExtent(null);
4756 (d3.geo.mercator = function() {
4757 return d3_geo_mercatorProjection(d3_geo_mercator);
4758 }).raw = d3_geo_mercator;
4759 var d3_geo_orthographic = d3_geo_azimuthal(function() {
4762 (d3.geo.orthographic = function() {
4763 return d3_geo_projection(d3_geo_orthographic);
4764 }).raw = d3_geo_orthographic;
4765 var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
4766 return 1 / (1 + cosλcosφ);
4768 return 2 * Math.atan(ρ);
4770 (d3.geo.stereographic = function() {
4771 return d3_geo_projection(d3_geo_stereographic);
4772 }).raw = d3_geo_stereographic;
4773 function d3_geo_transverseMercator(λ, φ) {
4774 return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
4776 d3_geo_transverseMercator.invert = function(x, y) {
4777 return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
4779 (d3.geo.transverseMercator = function() {
4780 var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
4781 projection.center = function(_) {
4782 return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
4784 projection.rotate = function(_) {
4785 return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
4786 [ _[0], _[1], _[2] - 90 ]);
4788 return rotate([ 0, 0, 90 ]);
4789 }).raw = d3_geo_transverseMercator;
4791 function d3_geom_pointX(d) {
4794 function d3_geom_pointY(d) {
4797 d3.geom.hull = function(vertices) {
4798 var x = d3_geom_pointX, y = d3_geom_pointY;
4799 if (arguments.length) return hull(vertices);
4800 function hull(data) {
4801 if (data.length < 3) return [];
4802 var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
4803 for (i = 0; i < n; i++) {
4804 points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
4806 points.sort(d3_geom_hullOrder);
4807 for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
4808 var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
4809 var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
4810 for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
4811 for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
4814 hull.x = function(_) {
4815 return arguments.length ? (x = _, hull) : x;
4817 hull.y = function(_) {
4818 return arguments.length ? (y = _, hull) : y;
4822 function d3_geom_hullUpper(points) {
4823 var n = points.length, hull = [ 0, 1 ], hs = 2;
4824 for (var i = 2; i < n; i++) {
4825 while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
4828 return hull.slice(0, hs);
4830 function d3_geom_hullOrder(a, b) {
4831 return a[0] - b[0] || a[1] - b[1];
4833 d3.geom.polygon = function(coordinates) {
4834 d3_subclass(coordinates, d3_geom_polygonPrototype);
4837 var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
4838 d3_geom_polygonPrototype.area = function() {
4839 var i = -1, n = this.length, a, b = this[n - 1], area = 0;
4843 area += a[1] * b[0] - a[0] * b[1];
4847 d3_geom_polygonPrototype.centroid = function(k) {
4848 var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
4849 if (!arguments.length) k = -1 / (6 * this.area());
4853 c = a[0] * b[1] - b[0] * a[1];
4854 x += (a[0] + b[0]) * c;
4855 y += (a[1] + b[1]) * c;
4857 return [ x * k, y * k ];
4859 d3_geom_polygonPrototype.clip = function(subject) {
4860 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;
4862 input = subject.slice();
4865 c = input[(m = input.length - closed) - 1];
4869 if (d3_geom_polygonInside(d, a, b)) {
4870 if (!d3_geom_polygonInside(c, a, b)) {
4871 subject.push(d3_geom_polygonIntersect(c, d, a, b));
4874 } else if (d3_geom_polygonInside(c, a, b)) {
4875 subject.push(d3_geom_polygonIntersect(c, d, a, b));
4879 if (closed) subject.push(subject[0]);
4884 function d3_geom_polygonInside(p, a, b) {
4885 return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
4887 function d3_geom_polygonIntersect(c, d, a, b) {
4888 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);
4889 return [ x1 + ua * x21, y1 + ua * y21 ];
4891 function d3_geom_polygonClosed(coordinates) {
4892 var a = coordinates[0], b = coordinates[coordinates.length - 1];
4893 return !(a[0] - b[0] || a[1] - b[1]);
4895 var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
4896 function d3_geom_voronoiBeach() {
4897 d3_geom_voronoiRedBlackNode(this);
4898 this.edge = this.site = this.circle = null;
4900 function d3_geom_voronoiCreateBeach(site) {
4901 var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
4905 function d3_geom_voronoiDetachBeach(beach) {
4906 d3_geom_voronoiDetachCircle(beach);
4907 d3_geom_voronoiBeaches.remove(beach);
4908 d3_geom_voronoiBeachPool.push(beach);
4909 d3_geom_voronoiRedBlackNode(beach);
4911 function d3_geom_voronoiRemoveBeach(beach) {
4912 var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
4915 }, previous = beach.P, next = beach.N, disappearing = [ beach ];
4916 d3_geom_voronoiDetachBeach(beach);
4917 var lArc = previous;
4918 while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
4920 disappearing.unshift(lArc);
4921 d3_geom_voronoiDetachBeach(lArc);
4924 disappearing.unshift(lArc);
4925 d3_geom_voronoiDetachCircle(lArc);
4927 while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
4929 disappearing.push(rArc);
4930 d3_geom_voronoiDetachBeach(rArc);
4933 disappearing.push(rArc);
4934 d3_geom_voronoiDetachCircle(rArc);
4935 var nArcs = disappearing.length, iArc;
4936 for (iArc = 1; iArc < nArcs; ++iArc) {
4937 rArc = disappearing[iArc];
4938 lArc = disappearing[iArc - 1];
4939 d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
4941 lArc = disappearing[0];
4942 rArc = disappearing[nArcs - 1];
4943 rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
4944 d3_geom_voronoiAttachCircle(lArc);
4945 d3_geom_voronoiAttachCircle(rArc);
4947 function d3_geom_voronoiAddBeach(site) {
4948 var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
4950 dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
4951 if (dxl > ε) node = node.L; else {
4952 dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
4963 } else if (dxr > -ε) {
4973 var newArc = d3_geom_voronoiCreateBeach(site);
4974 d3_geom_voronoiBeaches.insert(lArc, newArc);
4975 if (!lArc && !rArc) return;
4976 if (lArc === rArc) {
4977 d3_geom_voronoiDetachCircle(lArc);
4978 rArc = d3_geom_voronoiCreateBeach(lArc.site);
4979 d3_geom_voronoiBeaches.insert(newArc, rArc);
4980 newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
4981 d3_geom_voronoiAttachCircle(lArc);
4982 d3_geom_voronoiAttachCircle(rArc);
4986 newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
4989 d3_geom_voronoiDetachCircle(lArc);
4990 d3_geom_voronoiDetachCircle(rArc);
4991 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 = {
4992 x: (cy * hb - by * hc) / d + ax,
4993 y: (bx * hc - cx * hb) / d + ay
4995 d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
4996 newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
4997 rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
4998 d3_geom_voronoiAttachCircle(lArc);
4999 d3_geom_voronoiAttachCircle(rArc);
5001 function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
5002 var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
5003 if (!pby2) return rfocx;
5005 if (!lArc) return -Infinity;
5007 var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
5008 if (!plby2) return lfocx;
5009 var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
5010 if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
5011 return (rfocx + lfocx) / 2;
5013 function d3_geom_voronoiRightBreakPoint(arc, directrix) {
5015 if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
5016 var site = arc.site;
5017 return site.y === directrix ? site.x : Infinity;
5019 function d3_geom_voronoiCell(site) {
5023 d3_geom_voronoiCell.prototype.prepare = function() {
5024 var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
5025 while (iHalfEdge--) {
5026 edge = halfEdges[iHalfEdge].edge;
5027 if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
5029 halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
5030 return halfEdges.length;
5032 function d3_geom_voronoiCloseCells(extent) {
5033 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;
5035 cell = cells[iCell];
5036 if (!cell || !cell.prepare()) continue;
5037 halfEdges = cell.edges;
5038 nHalfEdges = halfEdges.length;
5040 while (iHalfEdge < nHalfEdges) {
5041 end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
5042 start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
5043 if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
5044 halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
5046 y: abs(x2 - x0) < ε ? y2 : y1
5047 } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
5048 x: abs(y2 - y1) < ε ? x2 : x1,
5050 } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
5052 y: abs(x2 - x1) < ε ? y2 : y0
5053 } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
5054 x: abs(y2 - y0) < ε ? x2 : x0,
5056 } : null), cell.site, null));
5062 function d3_geom_voronoiHalfEdgeOrder(a, b) {
5063 return b.angle - a.angle;
5065 function d3_geom_voronoiCircle() {
5066 d3_geom_voronoiRedBlackNode(this);
5067 this.x = this.y = this.arc = this.site = this.cy = null;
5069 function d3_geom_voronoiAttachCircle(arc) {
5070 var lArc = arc.P, rArc = arc.N;
5071 if (!lArc || !rArc) return;
5072 var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
5073 if (lSite === rSite) return;
5074 var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
5075 var d = 2 * (ax * cy - ay * cx);
5076 if (d >= -ε2) return;
5077 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;
5078 var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
5080 circle.site = cSite;
5082 circle.y = cy + Math.sqrt(x * x + y * y);
5084 arc.circle = circle;
5085 var before = null, node = d3_geom_voronoiCircles._;
5087 if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
5088 if (node.L) node = node.L; else {
5093 if (node.R) node = node.R; else {
5099 d3_geom_voronoiCircles.insert(before, circle);
5100 if (!before) d3_geom_voronoiFirstCircle = circle;
5102 function d3_geom_voronoiDetachCircle(arc) {
5103 var circle = arc.circle;
5105 if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
5106 d3_geom_voronoiCircles.remove(circle);
5107 d3_geom_voronoiCirclePool.push(circle);
5108 d3_geom_voronoiRedBlackNode(circle);
5112 function d3_geom_voronoiClipEdges(extent) {
5113 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;
5116 if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
5122 function d3_geom_voronoiConnectEdge(edge, extent) {
5124 if (vb) return true;
5125 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;
5127 if (fx < x0 || fx >= x1) return;
5132 }; else if (va.y >= y1) return;
5141 }; else if (va.y < y0) return;
5148 fm = (lx - rx) / (ry - ly);
5150 if (fm < -1 || fm > 1) {
5155 }; else if (va.y >= y1) return;
5164 }; else if (va.y < y0) return;
5175 }; else if (va.x >= x1) return;
5184 }; else if (va.x < x0) return;
5196 function d3_geom_voronoiEdge(lSite, rSite) {
5199 this.a = this.b = null;
5201 function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
5202 var edge = new d3_geom_voronoiEdge(lSite, rSite);
5203 d3_geom_voronoiEdges.push(edge);
5204 if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
5205 if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
5206 d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
5207 d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
5210 function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
5211 var edge = new d3_geom_voronoiEdge(lSite, null);
5214 d3_geom_voronoiEdges.push(edge);
5217 function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
5218 if (!edge.a && !edge.b) {
5222 } else if (edge.l === rSite) {
5228 function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
5229 var va = edge.a, vb = edge.b;
5232 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);
5234 d3_geom_voronoiHalfEdge.prototype = {
5236 return this.edge.l === this.site ? this.edge.a : this.edge.b;
5239 return this.edge.l === this.site ? this.edge.b : this.edge.a;
5242 function d3_geom_voronoiRedBlackTree() {
5245 function d3_geom_voronoiRedBlackNode(node) {
5246 node.U = node.C = node.L = node.R = node.P = node.N = null;
5248 d3_geom_voronoiRedBlackTree.prototype = {
5249 insert: function(after, node) {
5250 var parent, grandpa, uncle;
5254 if (after.N) after.N.P = node;
5258 while (after.L) after = after.L;
5264 } else if (this._) {
5265 after = d3_geom_voronoiRedBlackFirst(this._);
5268 after.P = after.L = node;
5271 node.P = node.N = null;
5275 node.L = node.R = null;
5279 while (parent && parent.C) {
5281 if (parent === grandpa.L) {
5283 if (uncle && uncle.C) {
5284 parent.C = uncle.C = false;
5288 if (after === parent.R) {
5289 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5295 d3_geom_voronoiRedBlackRotateRight(this, grandpa);
5299 if (uncle && uncle.C) {
5300 parent.C = uncle.C = false;
5304 if (after === parent.L) {
5305 d3_geom_voronoiRedBlackRotateRight(this, parent);
5311 d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
5318 remove: function(node) {
5319 if (node.N) node.N.P = node.P;
5320 if (node.P) node.P.N = node.N;
5321 node.N = node.P = null;
5322 var parent = node.U, sibling, left = node.L, right = node.R, next, red;
5323 if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
5325 if (parent.L === node) parent.L = next; else parent.R = next;
5329 if (left && right) {
5334 if (next !== right) {
5350 if (node) node.U = parent;
5352 if (node && node.C) {
5357 if (node === this._) break;
5358 if (node === parent.L) {
5363 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5366 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5367 if (!sibling.R || !sibling.R.C) {
5368 sibling.L.C = false;
5370 d3_geom_voronoiRedBlackRotateRight(this, sibling);
5373 sibling.C = parent.C;
5374 parent.C = sibling.R.C = false;
5375 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5384 d3_geom_voronoiRedBlackRotateRight(this, parent);
5387 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5388 if (!sibling.L || !sibling.L.C) {
5389 sibling.R.C = false;
5391 d3_geom_voronoiRedBlackRotateLeft(this, sibling);
5394 sibling.C = parent.C;
5395 parent.C = sibling.L.C = false;
5396 d3_geom_voronoiRedBlackRotateRight(this, parent);
5405 if (node) node.C = false;
5408 function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
5409 var p = node, q = node.R, parent = p.U;
5411 if (parent.L === p) parent.L = q; else parent.R = q;
5421 function d3_geom_voronoiRedBlackRotateRight(tree, node) {
5422 var p = node, q = node.L, parent = p.U;
5424 if (parent.L === p) parent.L = q; else parent.R = q;
5434 function d3_geom_voronoiRedBlackFirst(node) {
5435 while (node.L) node = node.L;
5438 function d3_geom_voronoi(sites, bbox) {
5439 var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
5440 d3_geom_voronoiEdges = [];
5441 d3_geom_voronoiCells = new Array(sites.length);
5442 d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
5443 d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
5445 circle = d3_geom_voronoiFirstCircle;
5446 if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
5447 if (site.x !== x0 || site.y !== y0) {
5448 d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
5449 d3_geom_voronoiAddBeach(site);
5450 x0 = site.x, y0 = site.y;
5453 } else if (circle) {
5454 d3_geom_voronoiRemoveBeach(circle.arc);
5459 if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
5461 cells: d3_geom_voronoiCells,
5462 edges: d3_geom_voronoiEdges
5464 d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
5467 function d3_geom_voronoiVertexOrder(a, b) {
5468 return b.y - a.y || b.x - a.x;
5470 d3.geom.voronoi = function(points) {
5471 var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
5472 if (points) return voronoi(points);
5473 function voronoi(data) {
5474 var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
5475 d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
5476 var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
5478 return [ s.x, s.y ];
5479 }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
5480 polygon.point = data[i];
5484 function sites(data) {
5485 return data.map(function(d, i) {
5487 x: Math.round(fx(d, i) / ε) * ε,
5488 y: Math.round(fy(d, i) / ε) * ε,
5493 voronoi.links = function(data) {
5494 return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
5495 return edge.l && edge.r;
5496 }).map(function(edge) {
5498 source: data[edge.l.i],
5499 target: data[edge.r.i]
5503 voronoi.triangles = function(data) {
5505 d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
5506 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;
5511 s1 = e1.l === site ? e1.r : e1.l;
5512 if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
5513 triangles.push([ data[i], data[s0.i], data[s1.i] ]);
5519 voronoi.x = function(_) {
5520 return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
5522 voronoi.y = function(_) {
5523 return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
5525 voronoi.clipExtent = function(_) {
5526 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
5527 clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
5530 voronoi.size = function(_) {
5531 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
5532 return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
5536 var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
5537 function d3_geom_voronoiTriangleArea(a, b, c) {
5538 return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
5540 d3.geom.delaunay = function(vertices) {
5541 return d3.geom.voronoi().triangles(vertices);
5543 d3.geom.quadtree = function(points, x1, y1, x2, y2) {
5544 var x = d3_geom_pointX, y = d3_geom_pointY, compat;
5545 if (compat = arguments.length) {
5546 x = d3_geom_quadtreeCompatX;
5547 y = d3_geom_quadtreeCompatY;
5553 return quadtree(points);
5555 function quadtree(data) {
5556 var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
5558 x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
5560 x2_ = y2_ = -(x1_ = y1_ = Infinity);
5563 if (compat) for (i = 0; i < n; ++i) {
5565 if (d.x < x1_) x1_ = d.x;
5566 if (d.y < y1_) y1_ = d.y;
5567 if (d.x > x2_) x2_ = d.x;
5568 if (d.y > y2_) y2_ = d.y;
5571 } else for (i = 0; i < n; ++i) {
5572 var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
5573 if (x_ < x1_) x1_ = x_;
5574 if (y_ < y1_) y1_ = y_;
5575 if (x_ > x2_) x2_ = x_;
5576 if (y_ > y2_) y2_ = y_;
5581 var dx = x2_ - x1_, dy = y2_ - y1_;
5582 if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
5583 function insert(n, d, x, y, x1, y1, x2, y2) {
5584 if (isNaN(x) || isNaN(y)) return;
5586 var nx = n.x, ny = n.y;
5588 if (abs(nx - x) + abs(ny - y) < .01) {
5589 insertChild(n, d, x, y, x1, y1, x2, y2);
5591 var nPoint = n.point;
5592 n.x = n.y = n.point = null;
5593 insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
5594 insertChild(n, d, x, y, x1, y1, x2, y2);
5597 n.x = x, n.y = y, n.point = d;
5600 insertChild(n, d, x, y, x1, y1, x2, y2);
5603 function insertChild(n, d, x, y, x1, y1, x2, y2) {
5604 var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
5606 n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
5607 if (right) x1 = xm; else x2 = xm;
5608 if (below) y1 = ym; else y2 = ym;
5609 insert(n, d, x, y, x1, y1, x2, y2);
5611 var root = d3_geom_quadtreeNode();
5612 root.add = function(d) {
5613 insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
5615 root.visit = function(f) {
5616 d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
5618 root.find = function(point) {
5619 return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
5624 insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
5627 } else data.forEach(root.add);
5628 xs = ys = data = d = null;
5631 quadtree.x = function(_) {
5632 return arguments.length ? (x = _, quadtree) : x;
5634 quadtree.y = function(_) {
5635 return arguments.length ? (y = _, quadtree) : y;
5637 quadtree.extent = function(_) {
5638 if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
5639 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
5643 quadtree.size = function(_) {
5644 if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
5645 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
5650 function d3_geom_quadtreeCompatX(d) {
5653 function d3_geom_quadtreeCompatY(d) {
5656 function d3_geom_quadtreeNode() {
5665 function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
5666 if (!f(node, x1, y1, x2, y2)) {
5667 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
5668 if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
5669 if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
5670 if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
5671 if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
5674 function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
5675 var minDistance2 = Infinity, closestPoint;
5676 (function find(node, x1, y1, x2, y2) {
5677 if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
5678 if (point = node.point) {
5679 var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
5680 if (distance2 < minDistance2) {
5681 var distance = Math.sqrt(minDistance2 = distance2);
5682 x0 = x - distance, y0 = y - distance;
5683 x3 = x + distance, y3 = y + distance;
5684 closestPoint = point;
5687 var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
5688 for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
5689 if (node = children[i & 3]) switch (i & 3) {
5691 find(node, x1, y1, xm, ym);
5695 find(node, xm, y1, x2, ym);
5699 find(node, x1, ym, xm, y2);
5703 find(node, xm, ym, x2, y2);
5707 })(root, x0, y0, x3, y3);
5708 return closestPoint;
5710 d3.interpolateRgb = d3_interpolateRgb;
5711 function d3_interpolateRgb(a, b) {
5714 var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
5715 return function(t) {
5716 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));
5719 d3.interpolateObject = d3_interpolateObject;
5720 function d3_interpolateObject(a, b) {
5721 var i = {}, c = {}, k;
5724 i[k] = d3_interpolate(a[k], b[k]);
5734 return function(t) {
5735 for (k in i) c[k] = i[k](t);
5739 d3.interpolateNumber = d3_interpolateNumber;
5740 function d3_interpolateNumber(a, b) {
5742 return function(t) {
5743 return a * (1 - t) + b * t;
5746 d3.interpolateString = d3_interpolateString;
5747 function d3_interpolateString(a, b) {
5748 var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
5749 a = a + "", b = b + "";
5750 while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
5751 if ((bs = bm.index) > bi) {
5752 bs = b.slice(bi, bs);
5753 if (s[i]) s[i] += bs; else s[++i] = bs;
5755 if ((am = am[0]) === (bm = bm[0])) {
5756 if (s[i]) s[i] += bm; else s[++i] = bm;
5761 x: d3_interpolateNumber(am, bm)
5764 bi = d3_interpolate_numberB.lastIndex;
5766 if (bi < b.length) {
5768 if (s[i]) s[i] += bs; else s[++i] = bs;
5770 return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
5774 } : (b = q.length, function(t) {
5775 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
5779 var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
5780 d3.interpolate = d3_interpolate;
5781 function d3_interpolate(a, b) {
5782 var i = d3.interpolators.length, f;
5783 while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
5786 d3.interpolators = [ function(a, b) {
5788 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);
5790 d3.interpolateArray = d3_interpolateArray;
5791 function d3_interpolateArray(a, b) {
5792 var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
5793 for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
5794 for (;i < na; ++i) c[i] = a[i];
5795 for (;i < nb; ++i) c[i] = b[i];
5796 return function(t) {
5797 for (i = 0; i < n0; ++i) c[i] = x[i](t);
5801 var d3_ease_default = function() {
5804 var d3_ease = d3.map({
5805 linear: d3_ease_default,
5808 return d3_ease_quad;
5811 return d3_ease_cubic;
5819 circle: function() {
5820 return d3_ease_circle;
5822 elastic: d3_ease_elastic,
5824 bounce: function() {
5825 return d3_ease_bounce;
5828 var d3_ease_mode = d3.map({
5830 out: d3_ease_reverse,
5831 "in-out": d3_ease_reflect,
5832 "out-in": function(f) {
5833 return d3_ease_reflect(d3_ease_reverse(f));
5836 d3.ease = function(name) {
5837 var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
5838 t = d3_ease.get(t) || d3_ease_default;
5839 m = d3_ease_mode.get(m) || d3_identity;
5840 return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
5842 function d3_ease_clamp(f) {
5843 return function(t) {
5844 return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
5847 function d3_ease_reverse(f) {
5848 return function(t) {
5849 return 1 - f(1 - t);
5852 function d3_ease_reflect(f) {
5853 return function(t) {
5854 return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
5857 function d3_ease_quad(t) {
5860 function d3_ease_cubic(t) {
5863 function d3_ease_cubicInOut(t) {
5864 if (t <= 0) return 0;
5865 if (t >= 1) return 1;
5866 var t2 = t * t, t3 = t2 * t;
5867 return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
5869 function d3_ease_poly(e) {
5870 return function(t) {
5871 return Math.pow(t, e);
5874 function d3_ease_sin(t) {
5875 return 1 - Math.cos(t * halfπ);
5877 function d3_ease_exp(t) {
5878 return Math.pow(2, 10 * (t - 1));
5880 function d3_ease_circle(t) {
5881 return 1 - Math.sqrt(1 - t * t);
5883 function d3_ease_elastic(a, p) {
5885 if (arguments.length < 2) p = .45;
5886 if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
5887 return function(t) {
5888 return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
5891 function d3_ease_back(s) {
5892 if (!s) s = 1.70158;
5893 return function(t) {
5894 return t * t * ((s + 1) * t - s);
5897 function d3_ease_bounce(t) {
5898 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;
5900 d3.interpolateHcl = d3_interpolateHcl;
5901 function d3_interpolateHcl(a, b) {
5904 var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
5905 if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
5906 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
5907 return function(t) {
5908 return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
5911 d3.interpolateHsl = d3_interpolateHsl;
5912 function d3_interpolateHsl(a, b) {
5915 var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
5916 if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
5917 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
5918 return function(t) {
5919 return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
5922 d3.interpolateLab = d3_interpolateLab;
5923 function d3_interpolateLab(a, b) {
5926 var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
5927 return function(t) {
5928 return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
5931 d3.interpolateRound = d3_interpolateRound;
5932 function d3_interpolateRound(a, b) {
5934 return function(t) {
5935 return Math.round(a + b * t);
5938 d3.transform = function(string) {
5939 var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
5940 return (d3.transform = function(string) {
5941 if (string != null) {
5942 g.setAttribute("transform", string);
5943 var t = g.transform.baseVal.consolidate();
5945 return new d3_transform(t ? t.matrix : d3_transformIdentity);
5948 function d3_transform(m) {
5949 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;
5950 if (r0[0] * r1[1] < r1[0] * r0[1]) {
5956 this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
5957 this.translate = [ m.e, m.f ];
5958 this.scale = [ kx, ky ];
5959 this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
5961 d3_transform.prototype.toString = function() {
5962 return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
5964 function d3_transformDot(a, b) {
5965 return a[0] * b[0] + a[1] * b[1];
5967 function d3_transformNormalize(a) {
5968 var k = Math.sqrt(d3_transformDot(a, a));
5975 function d3_transformCombine(a, b, k) {
5980 var d3_transformIdentity = {
5988 d3.interpolateTransform = d3_interpolateTransform;
5989 function d3_interpolateTransform(a, b) {
5990 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;
5991 if (ta[0] != tb[0] || ta[1] != tb[1]) {
5992 s.push("translate(", null, ",", null, ")");
5995 x: d3_interpolateNumber(ta[0], tb[0])
5998 x: d3_interpolateNumber(ta[1], tb[1])
6000 } else if (tb[0] || tb[1]) {
6001 s.push("translate(" + tb + ")");
6006 if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
6008 i: s.push(s.pop() + "rotate(", null, ")") - 2,
6009 x: d3_interpolateNumber(ra, rb)
6012 s.push(s.pop() + "rotate(" + rb + ")");
6016 i: s.push(s.pop() + "skewX(", null, ")") - 2,
6017 x: d3_interpolateNumber(wa, wb)
6020 s.push(s.pop() + "skewX(" + wb + ")");
6022 if (ka[0] != kb[0] || ka[1] != kb[1]) {
6023 n = s.push(s.pop() + "scale(", null, ",", null, ")");
6026 x: d3_interpolateNumber(ka[0], kb[0])
6029 x: d3_interpolateNumber(ka[1], kb[1])
6031 } else if (kb[0] != 1 || kb[1] != 1) {
6032 s.push(s.pop() + "scale(" + kb + ")");
6035 return function(t) {
6037 while (++i < n) s[(o = q[i]).i] = o.x(t);
6041 function d3_uninterpolateNumber(a, b) {
6042 b = (b -= a = +a) || 1 / b;
6043 return function(x) {
6047 function d3_uninterpolateClamp(a, b) {
6048 b = (b -= a = +a) || 1 / b;
6049 return function(x) {
6050 return Math.max(0, Math.min(1, (x - a) / b));
6054 d3.layout.bundle = function() {
6055 return function(links) {
6056 var paths = [], i = -1, n = links.length;
6057 while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
6061 function d3_layout_bundlePath(link) {
6062 var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
6063 while (start !== lca) {
6064 start = start.parent;
6067 var k = points.length;
6068 while (end !== lca) {
6069 points.splice(k, 0, end);
6074 function d3_layout_bundleAncestors(node) {
6075 var ancestors = [], parent = node.parent;
6076 while (parent != null) {
6077 ancestors.push(node);
6079 parent = parent.parent;
6081 ancestors.push(node);
6084 function d3_layout_bundleLeastCommonAncestor(a, b) {
6085 if (a === b) return a;
6086 var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
6087 while (aNode === bNode) {
6089 aNode = aNodes.pop();
6090 bNode = bNodes.pop();
6094 d3.layout.chord = function() {
6095 var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
6096 function relayout() {
6097 var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
6107 subgroupIndex.push(d3.range(n));
6111 groupIndex.sort(function(a, b) {
6112 return sortGroups(groupSums[a], groupSums[b]);
6115 if (sortSubgroups) {
6116 subgroupIndex.forEach(function(d, i) {
6117 d.sort(function(a, b) {
6118 return sortSubgroups(matrix[i][a], matrix[i][b]);
6122 k = (τ - padding * n) / k;
6127 var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
6128 subgroups[di + "-" + dj] = {
6148 var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
6149 if (source.value || target.value) {
6150 chords.push(source.value < target.value ? {
6160 if (sortChords) resort();
6163 chords.sort(function(a, b) {
6164 return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
6167 chord.matrix = function(x) {
6168 if (!arguments.length) return matrix;
6169 n = (matrix = x) && matrix.length;
6170 chords = groups = null;
6173 chord.padding = function(x) {
6174 if (!arguments.length) return padding;
6176 chords = groups = null;
6179 chord.sortGroups = function(x) {
6180 if (!arguments.length) return sortGroups;
6182 chords = groups = null;
6185 chord.sortSubgroups = function(x) {
6186 if (!arguments.length) return sortSubgroups;
6191 chord.sortChords = function(x) {
6192 if (!arguments.length) return sortChords;
6194 if (chords) resort();
6197 chord.chords = function() {
6198 if (!chords) relayout();
6201 chord.groups = function() {
6202 if (!groups) relayout();
6207 d3.layout.force = function() {
6208 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;
6209 function repulse(node) {
6210 return function(quad, x1, _, x2) {
6211 if (quad.point !== node) {
6212 var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
6213 if (dw * dw / theta2 < dn) {
6214 if (dn < chargeDistance2) {
6215 var k = quad.charge / dn;
6221 if (quad.point && dn && dn < chargeDistance2) {
6222 var k = quad.pointCharge / dn;
6227 return !quad.charge;
6230 force.tick = function() {
6231 if ((alpha *= .99) < .005) {
6238 var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
6239 for (i = 0; i < m; ++i) {
6245 if (l = x * x + y * y) {
6246 l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
6249 t.x -= x * (k = s.weight / (t.weight + s.weight));
6251 s.x += x * (k = 1 - k);
6255 if (k = alpha * gravity) {
6259 if (k) while (++i < n) {
6261 o.x += (x - o.x) * k;
6262 o.y += (y - o.y) * k;
6266 d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
6269 if (!(o = nodes[i]).fixed) {
6270 q.visit(repulse(o));
6281 o.x -= (o.px - (o.px = o.x)) * friction;
6282 o.y -= (o.py - (o.py = o.y)) * friction;
6290 force.nodes = function(x) {
6291 if (!arguments.length) return nodes;
6295 force.links = function(x) {
6296 if (!arguments.length) return links;
6300 force.size = function(x) {
6301 if (!arguments.length) return size;
6305 force.linkDistance = function(x) {
6306 if (!arguments.length) return linkDistance;
6307 linkDistance = typeof x === "function" ? x : +x;
6310 force.distance = force.linkDistance;
6311 force.linkStrength = function(x) {
6312 if (!arguments.length) return linkStrength;
6313 linkStrength = typeof x === "function" ? x : +x;
6316 force.friction = function(x) {
6317 if (!arguments.length) return friction;
6321 force.charge = function(x) {
6322 if (!arguments.length) return charge;
6323 charge = typeof x === "function" ? x : +x;
6326 force.chargeDistance = function(x) {
6327 if (!arguments.length) return Math.sqrt(chargeDistance2);
6328 chargeDistance2 = x * x;
6331 force.gravity = function(x) {
6332 if (!arguments.length) return gravity;
6336 force.theta = function(x) {
6337 if (!arguments.length) return Math.sqrt(theta2);
6341 force.alpha = function(x) {
6342 if (!arguments.length) return alpha;
6345 if (x > 0) alpha = x; else alpha = 0;
6351 d3.timer(force.tick);
6355 force.start = function() {
6356 var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
6357 for (i = 0; i < n; ++i) {
6358 (o = nodes[i]).index = i;
6361 for (i = 0; i < m; ++i) {
6363 if (typeof o.source == "number") o.source = nodes[o.source];
6364 if (typeof o.target == "number") o.target = nodes[o.target];
6368 for (i = 0; i < n; ++i) {
6370 if (isNaN(o.x)) o.x = position("x", w);
6371 if (isNaN(o.y)) o.y = position("y", h);
6372 if (isNaN(o.px)) o.px = o.x;
6373 if (isNaN(o.py)) o.py = o.y;
6376 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;
6378 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;
6380 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;
6381 function position(dimension, size) {
6383 neighbors = new Array(n);
6384 for (j = 0; j < n; ++j) {
6387 for (j = 0; j < m; ++j) {
6389 neighbors[o.source.index].push(o.target);
6390 neighbors[o.target.index].push(o.source);
6393 var candidates = neighbors[i], j = -1, l = candidates.length, x;
6394 while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
6395 return Math.random() * size;
6397 return force.resume();
6399 force.resume = function() {
6400 return force.alpha(.1);
6402 force.stop = function() {
6403 return force.alpha(0);
6405 force.drag = function() {
6406 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);
6407 if (!arguments.length) return drag;
6408 this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
6410 function dragmove(d) {
6411 d.px = d3.event.x, d.py = d3.event.y;
6414 return d3.rebind(force, event, "on");
6416 function d3_layout_forceDragstart(d) {
6419 function d3_layout_forceDragend(d) {
6422 function d3_layout_forceMouseover(d) {
6424 d.px = d.x, d.py = d.y;
6426 function d3_layout_forceMouseout(d) {
6429 function d3_layout_forceAccumulate(quad, alpha, charges) {
6433 var nodes = quad.nodes, n = nodes.length, i = -1, c;
6436 if (c == null) continue;
6437 d3_layout_forceAccumulate(c, alpha, charges);
6438 quad.charge += c.charge;
6439 cx += c.charge * c.cx;
6440 cy += c.charge * c.cy;
6445 quad.point.x += Math.random() - .5;
6446 quad.point.y += Math.random() - .5;
6448 var k = alpha * charges[quad.point.index];
6449 quad.charge += quad.pointCharge = k;
6450 cx += k * quad.point.x;
6451 cy += k * quad.point.y;
6453 quad.cx = cx / quad.charge;
6454 quad.cy = cy / quad.charge;
6456 var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
6457 d3.layout.hierarchy = function() {
6458 var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
6459 function hierarchy(root) {
6460 var stack = [ root ], nodes = [], node;
6462 while ((node = stack.pop()) != null) {
6464 if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
6465 var n, childs, child;
6467 stack.push(child = childs[n]);
6468 child.parent = node;
6469 child.depth = node.depth + 1;
6471 if (value) node.value = 0;
6472 node.children = childs;
6474 if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
6475 delete node.children;
6478 d3_layout_hierarchyVisitAfter(root, function(node) {
6480 if (sort && (childs = node.children)) childs.sort(sort);
6481 if (value && (parent = node.parent)) parent.value += node.value;
6485 hierarchy.sort = function(x) {
6486 if (!arguments.length) return sort;
6490 hierarchy.children = function(x) {
6491 if (!arguments.length) return children;
6495 hierarchy.value = function(x) {
6496 if (!arguments.length) return value;
6500 hierarchy.revalue = function(root) {
6502 d3_layout_hierarchyVisitBefore(root, function(node) {
6503 if (node.children) node.value = 0;
6505 d3_layout_hierarchyVisitAfter(root, function(node) {
6507 if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
6508 if (parent = node.parent) parent.value += node.value;
6515 function d3_layout_hierarchyRebind(object, hierarchy) {
6516 d3.rebind(object, hierarchy, "sort", "children", "value");
6517 object.nodes = object;
6518 object.links = d3_layout_hierarchyLinks;
6521 function d3_layout_hierarchyVisitBefore(node, callback) {
6522 var nodes = [ node ];
6523 while ((node = nodes.pop()) != null) {
6525 if ((children = node.children) && (n = children.length)) {
6527 while (--n >= 0) nodes.push(children[n]);
6531 function d3_layout_hierarchyVisitAfter(node, callback) {
6532 var nodes = [ node ], nodes2 = [];
6533 while ((node = nodes.pop()) != null) {
6535 if ((children = node.children) && (n = children.length)) {
6536 var i = -1, n, children;
6537 while (++i < n) nodes.push(children[i]);
6540 while ((node = nodes2.pop()) != null) {
6544 function d3_layout_hierarchyChildren(d) {
6547 function d3_layout_hierarchyValue(d) {
6550 function d3_layout_hierarchySort(a, b) {
6551 return b.value - a.value;
6553 function d3_layout_hierarchyLinks(nodes) {
6554 return d3.merge(nodes.map(function(parent) {
6555 return (parent.children || []).map(function(child) {
6563 d3.layout.partition = function() {
6564 var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
6565 function position(node, x, dx, dy) {
6566 var children = node.children;
6568 node.y = node.depth * dy;
6571 if (children && (n = children.length)) {
6572 var i = -1, n, c, d;
6573 dx = node.value ? dx / node.value : 0;
6575 position(c = children[i], x, d = c.value * dx, dy);
6580 function depth(node) {
6581 var children = node.children, d = 0;
6582 if (children && (n = children.length)) {
6584 while (++i < n) d = Math.max(d, depth(children[i]));
6588 function partition(d, i) {
6589 var nodes = hierarchy.call(this, d, i);
6590 position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
6593 partition.size = function(x) {
6594 if (!arguments.length) return size;
6598 return d3_layout_hierarchyRebind(partition, hierarchy);
6600 d3.layout.pie = function() {
6601 var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
6602 function pie(data) {
6603 var n = data.length, values = data.map(function(d, i) {
6604 return +value.call(pie, d, i);
6605 }), a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), k = (da - n * pa) / d3.sum(values), index = d3.range(n), arcs = [], v;
6606 if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
6607 return values[j] - values[i];
6608 } : function(i, j) {
6609 return sort(data[i], data[j]);
6611 index.forEach(function(i) {
6614 value: v = values[i],
6616 endAngle: a += v * k + pa,
6622 pie.value = function(_) {
6623 if (!arguments.length) return value;
6627 pie.sort = function(_) {
6628 if (!arguments.length) return sort;
6632 pie.startAngle = function(_) {
6633 if (!arguments.length) return startAngle;
6637 pie.endAngle = function(_) {
6638 if (!arguments.length) return endAngle;
6642 pie.padAngle = function(_) {
6643 if (!arguments.length) return padAngle;
6649 var d3_layout_pieSortByValue = {};
6650 d3.layout.stack = function() {
6651 var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
6652 function stack(data, index) {
6653 if (!(n = data.length)) return data;
6654 var series = data.map(function(d, i) {
6655 return values.call(stack, d, i);
6657 var points = series.map(function(d) {
6658 return d.map(function(v, i) {
6659 return [ x.call(stack, v, i), y.call(stack, v, i) ];
6662 var orders = order.call(stack, points, index);
6663 series = d3.permute(series, orders);
6664 points = d3.permute(points, orders);
6665 var offsets = offset.call(stack, points, index);
6666 var m = series[0].length, n, i, j, o;
6667 for (j = 0; j < m; ++j) {
6668 out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
6669 for (i = 1; i < n; ++i) {
6670 out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
6675 stack.values = function(x) {
6676 if (!arguments.length) return values;
6680 stack.order = function(x) {
6681 if (!arguments.length) return order;
6682 order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
6685 stack.offset = function(x) {
6686 if (!arguments.length) return offset;
6687 offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
6690 stack.x = function(z) {
6691 if (!arguments.length) return x;
6695 stack.y = function(z) {
6696 if (!arguments.length) return y;
6700 stack.out = function(z) {
6701 if (!arguments.length) return out;
6707 function d3_layout_stackX(d) {
6710 function d3_layout_stackY(d) {
6713 function d3_layout_stackOut(d, y0, y) {
6717 var d3_layout_stackOrders = d3.map({
6718 "inside-out": function(data) {
6719 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) {
6720 return max[a] - max[b];
6721 }), top = 0, bottom = 0, tops = [], bottoms = [];
6722 for (i = 0; i < n; ++i) {
6732 return bottoms.reverse().concat(tops);
6734 reverse: function(data) {
6735 return d3.range(data.length).reverse();
6737 "default": d3_layout_stackOrderDefault
6739 var d3_layout_stackOffsets = d3.map({
6740 silhouette: function(data) {
6741 var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
6742 for (j = 0; j < m; ++j) {
6743 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
6744 if (o > max) max = o;
6747 for (j = 0; j < m; ++j) {
6748 y0[j] = (max - sums[j]) / 2;
6752 wiggle: function(data) {
6753 var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
6755 for (j = 1; j < m; ++j) {
6756 for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
6757 for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
6758 for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
6759 s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
6761 s2 += s3 * data[i][j][1];
6763 y0[j] = o -= s1 ? s2 / s1 * dx : 0;
6766 for (j = 0; j < m; ++j) y0[j] -= o0;
6769 expand: function(data) {
6770 var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
6771 for (j = 0; j < m; ++j) {
6772 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
6773 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;
6775 for (j = 0; j < m; ++j) y0[j] = 0;
6778 zero: d3_layout_stackOffsetZero
6780 function d3_layout_stackOrderDefault(data) {
6781 return d3.range(data.length);
6783 function d3_layout_stackOffsetZero(data) {
6784 var j = -1, m = data[0].length, y0 = [];
6785 while (++j < m) y0[j] = 0;
6788 function d3_layout_stackMaxIndex(array) {
6789 var i = 1, j = 0, v = array[0][1], k, n = array.length;
6791 if ((k = array[i][1]) > v) {
6798 function d3_layout_stackReduceSum(d) {
6799 return d.reduce(d3_layout_stackSum, 0);
6801 function d3_layout_stackSum(p, d) {
6804 d3.layout.histogram = function() {
6805 var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
6806 function histogram(data, i) {
6807 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;
6810 bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
6817 if (x >= range[0] && x <= range[1]) {
6818 bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
6826 histogram.value = function(x) {
6827 if (!arguments.length) return valuer;
6831 histogram.range = function(x) {
6832 if (!arguments.length) return ranger;
6833 ranger = d3_functor(x);
6836 histogram.bins = function(x) {
6837 if (!arguments.length) return binner;
6838 binner = typeof x === "number" ? function(range) {
6839 return d3_layout_histogramBinFixed(range, x);
6843 histogram.frequency = function(x) {
6844 if (!arguments.length) return frequency;
6850 function d3_layout_histogramBinSturges(range, values) {
6851 return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
6853 function d3_layout_histogramBinFixed(range, n) {
6854 var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
6855 while (++x <= n) f[x] = m * x + b;
6858 function d3_layout_histogramRange(values) {
6859 return [ d3.min(values), d3.max(values) ];
6861 d3.layout.pack = function() {
6862 var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
6863 function pack(d, i) {
6864 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() {
6867 root.x = root.y = 0;
6868 d3_layout_hierarchyVisitAfter(root, function(d) {
6871 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
6873 var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
6874 d3_layout_hierarchyVisitAfter(root, function(d) {
6877 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
6878 d3_layout_hierarchyVisitAfter(root, function(d) {
6882 d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
6885 pack.size = function(_) {
6886 if (!arguments.length) return size;
6890 pack.radius = function(_) {
6891 if (!arguments.length) return radius;
6892 radius = _ == null || typeof _ === "function" ? _ : +_;
6895 pack.padding = function(_) {
6896 if (!arguments.length) return padding;
6900 return d3_layout_hierarchyRebind(pack, hierarchy);
6902 function d3_layout_packSort(a, b) {
6903 return a.value - b.value;
6905 function d3_layout_packInsert(a, b) {
6906 var c = a._pack_next;
6912 function d3_layout_packSplice(a, b) {
6916 function d3_layout_packIntersects(a, b) {
6917 var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
6918 return .999 * dr * dr > dx * dx + dy * dy;
6920 function d3_layout_packSiblings(node) {
6921 if (!(nodes = node.children) || !(n = nodes.length)) return;
6922 var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
6923 function bound(node) {
6924 xMin = Math.min(node.x - node.r, xMin);
6925 xMax = Math.max(node.x + node.r, xMax);
6926 yMin = Math.min(node.y - node.r, yMin);
6927 yMax = Math.max(node.y + node.r, yMax);
6929 nodes.forEach(d3_layout_packLink);
6941 d3_layout_packPlace(a, b, c);
6943 d3_layout_packInsert(a, c);
6945 d3_layout_packInsert(c, b);
6947 for (i = 3; i < n; i++) {
6948 d3_layout_packPlace(a, b, c = nodes[i]);
6949 var isect = 0, s1 = 1, s2 = 1;
6950 for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
6951 if (d3_layout_packIntersects(j, c)) {
6957 for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
6958 if (d3_layout_packIntersects(k, c)) {
6964 if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
6967 d3_layout_packInsert(a, c);
6974 var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
6975 for (i = 0; i < n; i++) {
6979 cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
6982 nodes.forEach(d3_layout_packUnlink);
6984 function d3_layout_packLink(node) {
6985 node._pack_next = node._pack_prev = node;
6987 function d3_layout_packUnlink(node) {
6988 delete node._pack_next;
6989 delete node._pack_prev;
6991 function d3_layout_packTransform(node, x, y, k) {
6992 var children = node.children;
6993 node.x = x += k * node.x;
6994 node.y = y += k * node.y;
6997 var i = -1, n = children.length;
6998 while (++i < n) d3_layout_packTransform(children[i], x, y, k);
7001 function d3_layout_packPlace(a, b, c) {
7002 var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
7003 if (db && (dx || dy)) {
7004 var da = b.r + c.r, dc = dx * dx + dy * dy;
7007 var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
7008 c.x = a.x + x * dx + y * dy;
7009 c.y = a.y + x * dy - y * dx;
7015 d3.layout.tree = function() {
7016 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
7017 function tree(d, i) {
7018 var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
7019 d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
7020 d3_layout_hierarchyVisitBefore(root1, secondWalk);
7021 if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
7022 var left = root0, right = root0, bottom = root0;
7023 d3_layout_hierarchyVisitBefore(root0, function(node) {
7024 if (node.x < left.x) left = node;
7025 if (node.x > right.x) right = node;
7026 if (node.depth > bottom.depth) bottom = node;
7028 var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
7029 d3_layout_hierarchyVisitBefore(root0, function(node) {
7030 node.x = (node.x + tx) * kx;
7031 node.y = node.depth * ky;
7036 function wrapTree(root0) {
7040 }, queue = [ root1 ], node1;
7041 while ((node1 = queue.pop()) != null) {
7042 for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
7043 queue.push((children[i] = child = {
7046 children: (child = children[i].children) && child.slice() || [],
7058 return root1.children[0];
7060 function firstWalk(v) {
7061 var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
7062 if (children.length) {
7063 d3_layout_treeShift(v);
7064 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
7066 v.z = w.z + separation(v._, w._);
7067 v.m = v.z - midpoint;
7072 v.z = w.z + separation(v._, w._);
7074 v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
7076 function secondWalk(v) {
7077 v._.x = v.z + v.parent.m;
7080 function apportion(v, w, ancestor) {
7082 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;
7083 while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
7084 vom = d3_layout_treeLeft(vom);
7085 vop = d3_layout_treeRight(vop);
7087 shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
7089 d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
7098 if (vim && !d3_layout_treeRight(vop)) {
7102 if (vip && !d3_layout_treeLeft(vom)) {
7110 function sizeNode(node) {
7112 node.y = node.depth * size[1];
7114 tree.separation = function(x) {
7115 if (!arguments.length) return separation;
7119 tree.size = function(x) {
7120 if (!arguments.length) return nodeSize ? null : size;
7121 nodeSize = (size = x) == null ? sizeNode : null;
7124 tree.nodeSize = function(x) {
7125 if (!arguments.length) return nodeSize ? size : null;
7126 nodeSize = (size = x) == null ? null : sizeNode;
7129 return d3_layout_hierarchyRebind(tree, hierarchy);
7131 function d3_layout_treeSeparation(a, b) {
7132 return a.parent == b.parent ? 1 : 2;
7134 function d3_layout_treeLeft(v) {
7135 var children = v.children;
7136 return children.length ? children[0] : v.t;
7138 function d3_layout_treeRight(v) {
7139 var children = v.children, n;
7140 return (n = children.length) ? children[n - 1] : v.t;
7142 function d3_layout_treeMove(wm, wp, shift) {
7143 var change = shift / (wp.i - wm.i);
7150 function d3_layout_treeShift(v) {
7151 var shift = 0, change = 0, children = v.children, i = children.length, w;
7156 shift += w.s + (change += w.c);
7159 function d3_layout_treeAncestor(vim, v, ancestor) {
7160 return vim.a.parent === v.parent ? vim.a : ancestor;
7162 d3.layout.cluster = function() {
7163 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
7164 function cluster(d, i) {
7165 var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
7166 d3_layout_hierarchyVisitAfter(root, function(node) {
7167 var children = node.children;
7168 if (children && children.length) {
7169 node.x = d3_layout_clusterX(children);
7170 node.y = d3_layout_clusterY(children);
7172 node.x = previousNode ? x += separation(node, previousNode) : 0;
7174 previousNode = node;
7177 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;
7178 d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
7179 node.x = (node.x - root.x) * size[0];
7180 node.y = (root.y - node.y) * size[1];
7181 } : function(node) {
7182 node.x = (node.x - x0) / (x1 - x0) * size[0];
7183 node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
7187 cluster.separation = function(x) {
7188 if (!arguments.length) return separation;
7192 cluster.size = function(x) {
7193 if (!arguments.length) return nodeSize ? null : size;
7194 nodeSize = (size = x) == null;
7197 cluster.nodeSize = function(x) {
7198 if (!arguments.length) return nodeSize ? size : null;
7199 nodeSize = (size = x) != null;
7202 return d3_layout_hierarchyRebind(cluster, hierarchy);
7204 function d3_layout_clusterY(children) {
7205 return 1 + d3.max(children, function(child) {
7209 function d3_layout_clusterX(children) {
7210 return children.reduce(function(x, child) {
7212 }, 0) / children.length;
7214 function d3_layout_clusterLeft(node) {
7215 var children = node.children;
7216 return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
7218 function d3_layout_clusterRight(node) {
7219 var children = node.children, n;
7220 return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
7222 d3.layout.treemap = function() {
7223 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));
7224 function scale(children, k) {
7225 var i = -1, n = children.length, child, area;
7227 area = (child = children[i]).value * (k < 0 ? 0 : k);
7228 child.area = isNaN(area) || area <= 0 ? 0 : area;
7231 function squarify(node) {
7232 var children = node.children;
7233 if (children && children.length) {
7234 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;
7235 scale(remaining, rect.dx * rect.dy / node.value);
7237 while ((n = remaining.length) > 0) {
7238 row.push(child = remaining[n - 1]);
7239 row.area += child.area;
7240 if (mode !== "squarify" || (score = worst(row, u)) <= best) {
7244 row.area -= row.pop().area;
7245 position(row, u, rect, false);
7246 u = Math.min(rect.dx, rect.dy);
7247 row.length = row.area = 0;
7252 position(row, u, rect, true);
7253 row.length = row.area = 0;
7255 children.forEach(squarify);
7258 function stickify(node) {
7259 var children = node.children;
7260 if (children && children.length) {
7261 var rect = pad(node), remaining = children.slice(), child, row = [];
7262 scale(remaining, rect.dx * rect.dy / node.value);
7264 while (child = remaining.pop()) {
7266 row.area += child.area;
7267 if (child.z != null) {
7268 position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
7269 row.length = row.area = 0;
7272 children.forEach(stickify);
7275 function worst(row, u) {
7276 var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
7278 if (!(r = row[i].area)) continue;
7279 if (r < rmin) rmin = r;
7280 if (r > rmax) rmax = r;
7284 return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
7286 function position(row, u, rect, flush) {
7287 var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
7289 if (flush || v > rect.dy) v = rect.dy;
7295 x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
7298 o.dx += rect.x + rect.dx - x;
7302 if (flush || v > rect.dx) v = rect.dx;
7308 y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
7311 o.dy += rect.y + rect.dy - y;
7316 function treemap(d) {
7317 var nodes = stickies || hierarchy(d), root = nodes[0];
7322 if (stickies) hierarchy.revalue(root);
7323 scale([ root ], root.dx * root.dy / root.value);
7324 (stickies ? stickify : squarify)(root);
7325 if (sticky) stickies = nodes;
7328 treemap.size = function(x) {
7329 if (!arguments.length) return size;
7333 treemap.padding = function(x) {
7334 if (!arguments.length) return padding;
7335 function padFunction(node) {
7336 var p = x.call(treemap, node, node.depth);
7337 return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
7339 function padConstant(node) {
7340 return d3_layout_treemapPad(node, x);
7343 pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
7344 padConstant) : padConstant;
7347 treemap.round = function(x) {
7348 if (!arguments.length) return round != Number;
7349 round = x ? Math.round : Number;
7352 treemap.sticky = function(x) {
7353 if (!arguments.length) return sticky;
7358 treemap.ratio = function(x) {
7359 if (!arguments.length) return ratio;
7363 treemap.mode = function(x) {
7364 if (!arguments.length) return mode;
7368 return d3_layout_hierarchyRebind(treemap, hierarchy);
7370 function d3_layout_treemapPadNull(node) {
7378 function d3_layout_treemapPad(node, padding) {
7379 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];
7396 normal: function(µ, σ) {
7397 var n = arguments.length;
7403 x = Math.random() * 2 - 1;
7404 y = Math.random() * 2 - 1;
7406 } while (!r || r > 1);
7407 return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
7410 logNormal: function() {
7411 var random = d3.random.normal.apply(d3, arguments);
7413 return Math.exp(random());
7416 bates: function(m) {
7417 var random = d3.random.irwinHall(m);
7419 return random() / m;
7422 irwinHall: function(m) {
7424 for (var s = 0, j = 0; j < m; j++) s += Math.random();
7430 function d3_scaleExtent(domain) {
7431 var start = domain[0], stop = domain[domain.length - 1];
7432 return start < stop ? [ start, stop ] : [ stop, start ];
7434 function d3_scaleRange(scale) {
7435 return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
7437 function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
7438 var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
7439 return function(x) {
7443 function d3_scale_nice(domain, nice) {
7444 var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
7446 dx = i0, i0 = i1, i1 = dx;
7447 dx = x0, x0 = x1, x1 = dx;
7449 domain[i0] = nice.floor(x0);
7450 domain[i1] = nice.ceil(x1);
7453 function d3_scale_niceStep(step) {
7455 floor: function(x) {
7456 return Math.floor(x / step) * step;
7459 return Math.ceil(x / step) * step;
7461 } : d3_scale_niceIdentity;
7463 var d3_scale_niceIdentity = {
7467 function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
7468 var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
7469 if (domain[k] < domain[0]) {
7470 domain = domain.slice().reverse();
7471 range = range.slice().reverse();
7474 u.push(uninterpolate(domain[j - 1], domain[j]));
7475 i.push(interpolate(range[j - 1], range[j]));
7477 return function(x) {
7478 var j = d3.bisect(domain, x, 1, k) - 1;
7479 return i[j](u[j](x));
7482 d3.scale.linear = function() {
7483 return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
7485 function d3_scale_linear(domain, range, interpolate, clamp) {
7487 function rescale() {
7488 var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
7489 output = linear(domain, range, uninterpolate, interpolate);
7490 input = linear(range, domain, uninterpolate, d3_interpolate);
7496 scale.invert = function(y) {
7499 scale.domain = function(x) {
7500 if (!arguments.length) return domain;
7501 domain = x.map(Number);
7504 scale.range = function(x) {
7505 if (!arguments.length) return range;
7509 scale.rangeRound = function(x) {
7510 return scale.range(x).interpolate(d3_interpolateRound);
7512 scale.clamp = function(x) {
7513 if (!arguments.length) return clamp;
7517 scale.interpolate = function(x) {
7518 if (!arguments.length) return interpolate;
7522 scale.ticks = function(m) {
7523 return d3_scale_linearTicks(domain, m);
7525 scale.tickFormat = function(m, format) {
7526 return d3_scale_linearTickFormat(domain, m, format);
7528 scale.nice = function(m) {
7529 d3_scale_linearNice(domain, m);
7532 scale.copy = function() {
7533 return d3_scale_linear(domain, range, interpolate, clamp);
7537 function d3_scale_linearRebind(scale, linear) {
7538 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
7540 function d3_scale_linearNice(domain, m) {
7541 return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
7543 function d3_scale_linearTickRange(domain, m) {
7544 if (m == null) m = 10;
7545 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;
7546 if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
7547 extent[0] = Math.ceil(extent[0] / step) * step;
7548 extent[1] = Math.floor(extent[1] / step) * step + step * .5;
7552 function d3_scale_linearTicks(domain, m) {
7553 return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
7555 function d3_scale_linearTickFormat(domain, m, format) {
7556 var range = d3_scale_linearTickRange(domain, m);
7558 var match = d3_format_re.exec(format);
7560 if (match[8] === "s") {
7561 var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
7562 if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
7564 format = d3.format(match.join(""));
7565 return function(d) {
7566 return format(prefix.scale(d)) + prefix.symbol;
7569 if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
7570 format = match.join("");
7572 format = ",." + d3_scale_linearPrecision(range[2]) + "f";
7574 return d3.format(format);
7576 var d3_scale_linearFormatSignificant = {
7583 function d3_scale_linearPrecision(value) {
7584 return -Math.floor(Math.log(value) / Math.LN10 + .01);
7586 function d3_scale_linearFormatPrecision(type, range) {
7587 var p = d3_scale_linearPrecision(range[2]);
7588 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;
7590 d3.scale.log = function() {
7591 return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
7593 function d3_scale_log(linear, base, positive, domain) {
7595 return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
7598 return positive ? Math.pow(base, x) : -Math.pow(base, -x);
7601 return linear(log(x));
7603 scale.invert = function(x) {
7604 return pow(linear.invert(x));
7606 scale.domain = function(x) {
7607 if (!arguments.length) return domain;
7608 positive = x[0] >= 0;
7609 linear.domain((domain = x.map(Number)).map(log));
7612 scale.base = function(_) {
7613 if (!arguments.length) return base;
7615 linear.domain(domain.map(log));
7618 scale.nice = function() {
7619 var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
7620 linear.domain(niced);
7621 domain = niced.map(pow);
7624 scale.ticks = function() {
7625 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;
7626 if (isFinite(j - i)) {
7628 for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
7632 for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
7634 for (i = 0; ticks[i] < u; i++) {}
7635 for (j = ticks.length; ticks[j - 1] > v; j--) {}
7636 ticks = ticks.slice(i, j);
7640 scale.tickFormat = function(n, format) {
7641 if (!arguments.length) return d3_scale_logFormat;
7642 if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
7643 var k = Math.max(.1, n / scale.ticks().length), f = positive ? (e = 1e-12, Math.ceil) : (e = -1e-12,
7645 return function(d) {
7646 return d / pow(f(log(d) + e)) <= k ? format(d) : "";
7649 scale.copy = function() {
7650 return d3_scale_log(linear.copy(), base, positive, domain);
7652 return d3_scale_linearRebind(scale, linear);
7654 var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
7655 floor: function(x) {
7656 return -Math.ceil(-x);
7659 return -Math.floor(-x);
7662 d3.scale.pow = function() {
7663 return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
7665 function d3_scale_pow(linear, exponent, domain) {
7666 var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
7668 return linear(powp(x));
7670 scale.invert = function(x) {
7671 return powb(linear.invert(x));
7673 scale.domain = function(x) {
7674 if (!arguments.length) return domain;
7675 linear.domain((domain = x.map(Number)).map(powp));
7678 scale.ticks = function(m) {
7679 return d3_scale_linearTicks(domain, m);
7681 scale.tickFormat = function(m, format) {
7682 return d3_scale_linearTickFormat(domain, m, format);
7684 scale.nice = function(m) {
7685 return scale.domain(d3_scale_linearNice(domain, m));
7687 scale.exponent = function(x) {
7688 if (!arguments.length) return exponent;
7689 powp = d3_scale_powPow(exponent = x);
7690 powb = d3_scale_powPow(1 / exponent);
7691 linear.domain(domain.map(powp));
7694 scale.copy = function() {
7695 return d3_scale_pow(linear.copy(), exponent, domain);
7697 return d3_scale_linearRebind(scale, linear);
7699 function d3_scale_powPow(e) {
7700 return function(x) {
7701 return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
7704 d3.scale.sqrt = function() {
7705 return d3.scale.pow().exponent(.5);
7707 d3.scale.ordinal = function() {
7708 return d3_scale_ordinal([], {
7713 function d3_scale_ordinal(domain, ranger) {
7714 var index, range, rangeBand;
7716 return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
7718 function steps(start, step) {
7719 return d3.range(domain.length).map(function(i) {
7720 return start + step * i;
7723 scale.domain = function(x) {
7724 if (!arguments.length) return domain;
7726 index = new d3_Map();
7727 var i = -1, n = x.length, xi;
7728 while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
7729 return scale[ranger.t].apply(scale, ranger.a);
7731 scale.range = function(x) {
7732 if (!arguments.length) return range;
7741 scale.rangePoints = function(x, padding) {
7742 if (arguments.length < 2) padding = 0;
7743 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
7744 0) : (stop - start) / (domain.length - 1 + padding);
7745 range = steps(start + step * padding / 2, step);
7753 scale.rangeRoundPoints = function(x, padding) {
7754 if (arguments.length < 2) padding = 0;
7755 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
7756 0) : (stop - start) / (domain.length - 1 + padding) | 0;
7757 range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
7760 t: "rangeRoundPoints",
7765 scale.rangeBands = function(x, padding, outerPadding) {
7766 if (arguments.length < 2) padding = 0;
7767 if (arguments.length < 3) outerPadding = padding;
7768 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
7769 range = steps(start + step * outerPadding, step);
7770 if (reverse) range.reverse();
7771 rangeBand = step * (1 - padding);
7778 scale.rangeRoundBands = function(x, padding, outerPadding) {
7779 if (arguments.length < 2) padding = 0;
7780 if (arguments.length < 3) outerPadding = padding;
7781 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
7782 range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
7783 if (reverse) range.reverse();
7784 rangeBand = Math.round(step * (1 - padding));
7786 t: "rangeRoundBands",
7791 scale.rangeBand = function() {
7794 scale.rangeExtent = function() {
7795 return d3_scaleExtent(ranger.a[0]);
7797 scale.copy = function() {
7798 return d3_scale_ordinal(domain, ranger);
7800 return scale.domain(domain);
7802 d3.scale.category10 = function() {
7803 return d3.scale.ordinal().range(d3_category10);
7805 d3.scale.category20 = function() {
7806 return d3.scale.ordinal().range(d3_category20);
7808 d3.scale.category20b = function() {
7809 return d3.scale.ordinal().range(d3_category20b);
7811 d3.scale.category20c = function() {
7812 return d3.scale.ordinal().range(d3_category20c);
7814 var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
7815 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);
7816 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);
7817 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);
7818 d3.scale.quantile = function() {
7819 return d3_scale_quantile([], []);
7821 function d3_scale_quantile(domain, range) {
7823 function rescale() {
7824 var k = 0, q = range.length;
7826 while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
7830 if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
7832 scale.domain = function(x) {
7833 if (!arguments.length) return domain;
7834 domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
7837 scale.range = function(x) {
7838 if (!arguments.length) return range;
7842 scale.quantiles = function() {
7845 scale.invertExtent = function(y) {
7846 y = range.indexOf(y);
7847 return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
7849 scale.copy = function() {
7850 return d3_scale_quantile(domain, range);
7854 d3.scale.quantize = function() {
7855 return d3_scale_quantize(0, 1, [ 0, 1 ]);
7857 function d3_scale_quantize(x0, x1, range) {
7860 return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
7862 function rescale() {
7863 kx = range.length / (x1 - x0);
7864 i = range.length - 1;
7867 scale.domain = function(x) {
7868 if (!arguments.length) return [ x0, x1 ];
7870 x1 = +x[x.length - 1];
7873 scale.range = function(x) {
7874 if (!arguments.length) return range;
7878 scale.invertExtent = function(y) {
7879 y = range.indexOf(y);
7880 y = y < 0 ? NaN : y / kx + x0;
7881 return [ y, y + 1 / kx ];
7883 scale.copy = function() {
7884 return d3_scale_quantize(x0, x1, range);
7888 d3.scale.threshold = function() {
7889 return d3_scale_threshold([ .5 ], [ 0, 1 ]);
7891 function d3_scale_threshold(domain, range) {
7893 if (x <= x) return range[d3.bisect(domain, x)];
7895 scale.domain = function(_) {
7896 if (!arguments.length) return domain;
7900 scale.range = function(_) {
7901 if (!arguments.length) return range;
7905 scale.invertExtent = function(y) {
7906 y = range.indexOf(y);
7907 return [ domain[y - 1], domain[y] ];
7909 scale.copy = function() {
7910 return d3_scale_threshold(domain, range);
7914 d3.scale.identity = function() {
7915 return d3_scale_identity([ 0, 1 ]);
7917 function d3_scale_identity(domain) {
7918 function identity(x) {
7921 identity.invert = identity;
7922 identity.domain = identity.range = function(x) {
7923 if (!arguments.length) return domain;
7924 domain = x.map(identity);
7927 identity.ticks = function(m) {
7928 return d3_scale_linearTicks(domain, m);
7930 identity.tickFormat = function(m, format) {
7931 return d3_scale_linearTickFormat(domain, m, format);
7933 identity.copy = function() {
7934 return d3_scale_identity(domain);
7939 function d3_zero() {
7942 d3.svg.arc = function() {
7943 var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, cornerRadius = d3_zero, padRadius = d3_svg_arcAuto, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle, padAngle = d3_svg_arcPadAngle;
7945 var r0 = Math.max(0, +innerRadius.apply(this, arguments)), r1 = Math.max(0, +outerRadius.apply(this, arguments)), a0 = startAngle.apply(this, arguments) - halfπ, a1 = endAngle.apply(this, arguments) - halfπ, da = Math.abs(a1 - a0), cw = a0 > a1 ? 0 : 1;
7946 if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
7947 if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
7948 var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
7949 if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
7950 rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
7952 if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
7953 if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
7956 x0 = r1 * Math.cos(a0 + p1);
7957 y0 = r1 * Math.sin(a0 + p1);
7958 x1 = r1 * Math.cos(a1 - p1);
7959 y1 = r1 * Math.sin(a1 - p1);
7960 var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
7961 if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
7962 var h1 = (a0 + a1) / 2;
7963 x0 = r1 * Math.cos(h1);
7964 y0 = r1 * Math.sin(h1);
7971 x2 = r0 * Math.cos(a1 - p0);
7972 y2 = r0 * Math.sin(a1 - p0);
7973 x3 = r0 * Math.cos(a0 + p0);
7974 y3 = r0 * Math.sin(a0 + p0);
7975 var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
7976 if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
7977 var h0 = (a0 + a1) / 2;
7978 x2 = r0 * Math.cos(h0);
7979 y2 = r0 * Math.sin(h0);
7985 if ((rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
7986 cr = r0 < r1 ^ cw ? 0 : 1;
7987 var oc = x3 == null ? [ x2, y2 ] : x1 == null ? [ x0, y0 ] : d3_geom_polygonIntersect([ x0, y0 ], [ x3, y3 ], [ x1, y1 ], [ x2, y2 ]), ax = x0 - oc[0], ay = y0 - oc[1], bx = x1 - oc[0], by = y1 - oc[1], kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2), lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
7989 var rc1 = Math.min(rc, (r1 - lc) / (kc + 1)), t30 = d3_svg_arcCornerTangents(x3 == null ? [ x2, y2 ] : [ x3, y3 ], [ x0, y0 ], r1, rc1, cw), t12 = d3_svg_arcCornerTangents([ x1, y1 ], [ x2, y2 ], r1, rc1, cw);
7991 path.push("M", t30[0], "A", rc1, ",", rc1, " 0 0,", cr, " ", t30[1], "A", r1, ",", r1, " 0 ", 1 - cw ^ d3_svg_arcSweep(t30[1][0], t30[1][1], t12[1][0], t12[1][1]), ",", cw, " ", t12[1], "A", rc1, ",", rc1, " 0 0,", cr, " ", t12[0]);
7993 path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
7996 path.push("M", x0, ",", y0);
7999 var rc0 = Math.min(rc, (r0 - lc) / (kc - 1)), t03 = d3_svg_arcCornerTangents([ x0, y0 ], [ x3, y3 ], r0, -rc0, cw), t21 = d3_svg_arcCornerTangents([ x2, y2 ], x1 == null ? [ x0, y0 ] : [ x1, y1 ], r0, -rc0, cw);
8001 path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t21[1], "A", r0, ",", r0, " 0 ", cw ^ d3_svg_arcSweep(t21[1][0], t21[1][1], t03[1][0], t03[1][1]), ",", 1 - cw, " ", t03[1], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
8003 path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
8006 path.push("L", x2, ",", y2);
8009 path.push("M", x0, ",", y0);
8010 if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
8011 path.push("L", x2, ",", y2);
8012 if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
8015 return path.join("");
8017 function circleSegment(r1, cw) {
8018 return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
8020 arc.innerRadius = function(v) {
8021 if (!arguments.length) return innerRadius;
8022 innerRadius = d3_functor(v);
8025 arc.outerRadius = function(v) {
8026 if (!arguments.length) return outerRadius;
8027 outerRadius = d3_functor(v);
8030 arc.cornerRadius = function(v) {
8031 if (!arguments.length) return cornerRadius;
8032 cornerRadius = d3_functor(v);
8035 arc.padRadius = function(v) {
8036 if (!arguments.length) return padRadius;
8037 padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
8040 arc.startAngle = function(v) {
8041 if (!arguments.length) return startAngle;
8042 startAngle = d3_functor(v);
8045 arc.endAngle = function(v) {
8046 if (!arguments.length) return endAngle;
8047 endAngle = d3_functor(v);
8050 arc.padAngle = function(v) {
8051 if (!arguments.length) return padAngle;
8052 padAngle = d3_functor(v);
8055 arc.centroid = function() {
8056 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
8057 return [ Math.cos(a) * r, Math.sin(a) * r ];
8061 var d3_svg_arcAuto = "auto";
8062 function d3_svg_arcInnerRadius(d) {
8063 return d.innerRadius;
8065 function d3_svg_arcOuterRadius(d) {
8066 return d.outerRadius;
8068 function d3_svg_arcStartAngle(d) {
8069 return d.startAngle;
8071 function d3_svg_arcEndAngle(d) {
8074 function d3_svg_arcPadAngle(d) {
8075 return d && d.padAngle;
8077 function d3_svg_arcSweep(x0, y0, x1, y1) {
8078 return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
8080 function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
8081 var x01 = p0[0] - p1[0], y01 = p0[1] - p1[1], lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01), ox = lo * y01, oy = -lo * x01, x1 = p0[0] + ox, y1 = p0[1] + oy, x2 = p1[0] + ox, y2 = p1[1] + oy, x3 = (x1 + x2) / 2, y3 = (y1 + y2) / 2, dx = x2 - x1, dy = y2 - y1, d2 = dx * dx + dy * dy, r = r1 - rc, D = x1 * y2 - x2 * y1, d = (dy < 0 ? -1 : 1) * Math.sqrt(r * r * d2 - D * D), cx0 = (D * dy - dx * d) / d2, cy0 = (-D * dx - dy * d) / d2, cx1 = (D * dy + dx * d) / d2, cy1 = (-D * dx + dy * d) / d2, dx0 = cx0 - x3, dy0 = cy0 - y3, dx1 = cx1 - x3, dy1 = cy1 - y3;
8082 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
8083 return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
8085 function d3_svg_line(projection) {
8086 var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
8087 function line(data) {
8088 var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
8089 function segment() {
8090 segments.push("M", interpolate(projection(points), tension));
8093 if (defined.call(this, d = data[i], i)) {
8094 points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
8095 } else if (points.length) {
8100 if (points.length) segment();
8101 return segments.length ? segments.join("") : null;
8103 line.x = function(_) {
8104 if (!arguments.length) return x;
8108 line.y = function(_) {
8109 if (!arguments.length) return y;
8113 line.defined = function(_) {
8114 if (!arguments.length) return defined;
8118 line.interpolate = function(_) {
8119 if (!arguments.length) return interpolateKey;
8120 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
8123 line.tension = function(_) {
8124 if (!arguments.length) return tension;
8130 d3.svg.line = function() {
8131 return d3_svg_line(d3_identity);
8133 var d3_svg_lineInterpolators = d3.map({
8134 linear: d3_svg_lineLinear,
8135 "linear-closed": d3_svg_lineLinearClosed,
8136 step: d3_svg_lineStep,
8137 "step-before": d3_svg_lineStepBefore,
8138 "step-after": d3_svg_lineStepAfter,
8139 basis: d3_svg_lineBasis,
8140 "basis-open": d3_svg_lineBasisOpen,
8141 "basis-closed": d3_svg_lineBasisClosed,
8142 bundle: d3_svg_lineBundle,
8143 cardinal: d3_svg_lineCardinal,
8144 "cardinal-open": d3_svg_lineCardinalOpen,
8145 "cardinal-closed": d3_svg_lineCardinalClosed,
8146 monotone: d3_svg_lineMonotone
8148 d3_svg_lineInterpolators.forEach(function(key, value) {
8150 value.closed = /-closed$/.test(key);
8152 function d3_svg_lineLinear(points) {
8153 return points.join("L");
8155 function d3_svg_lineLinearClosed(points) {
8156 return d3_svg_lineLinear(points) + "Z";
8158 function d3_svg_lineStep(points) {
8159 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8160 while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
8161 if (n > 1) path.push("H", p[0]);
8162 return path.join("");
8164 function d3_svg_lineStepBefore(points) {
8165 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8166 while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
8167 return path.join("");
8169 function d3_svg_lineStepAfter(points) {
8170 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8171 while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
8172 return path.join("");
8174 function d3_svg_lineCardinalOpen(points, tension) {
8175 return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
8177 function d3_svg_lineCardinalClosed(points, tension) {
8178 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
8179 points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
8181 function d3_svg_lineCardinal(points, tension) {
8182 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
8184 function d3_svg_lineHermite(points, tangents) {
8185 if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
8186 return d3_svg_lineLinear(points);
8188 var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
8190 path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
8194 if (tangents.length > 1) {
8198 path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
8199 for (var i = 2; i < tangents.length; i++, pi++) {
8202 path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
8206 var lp = points[pi];
8207 path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
8211 function d3_svg_lineCardinalTangents(points, tension) {
8212 var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
8217 tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
8221 function d3_svg_lineBasis(points) {
8222 if (points.length < 3) return d3_svg_lineLinear(points);
8223 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) ];
8224 points.push(points[n - 1]);
8231 d3_svg_lineBasisBezier(path, px, py);
8235 return path.join("");
8237 function d3_svg_lineBasisOpen(points) {
8238 if (points.length < 4) return d3_svg_lineLinear(points);
8239 var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
8245 path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
8253 d3_svg_lineBasisBezier(path, px, py);
8255 return path.join("");
8257 function d3_svg_lineBasisClosed(points) {
8258 var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
8264 path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
8272 d3_svg_lineBasisBezier(path, px, py);
8274 return path.join("");
8276 function d3_svg_lineBundle(points, tension) {
8277 var n = points.length - 1;
8279 var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
8283 p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
8284 p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
8287 return d3_svg_lineBasis(points);
8289 function d3_svg_lineDot4(a, b) {
8290 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
8292 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 ];
8293 function d3_svg_lineBasisBezier(path, x, y) {
8294 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));
8296 function d3_svg_lineSlope(p0, p1) {
8297 return (p1[1] - p0[1]) / (p1[0] - p0[0]);
8299 function d3_svg_lineFiniteDifferences(points) {
8300 var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
8302 m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
8307 function d3_svg_lineMonotoneTangents(points) {
8308 var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
8310 d = d3_svg_lineSlope(points[i], points[i + 1]);
8312 m[i] = m[i + 1] = 0;
8318 s = d * 3 / Math.sqrt(s);
8326 s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
8327 tangents.push([ s || 0, m[i] * s || 0 ]);
8331 function d3_svg_lineMonotone(points) {
8332 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
8334 d3.svg.line.radial = function() {
8335 var line = d3_svg_line(d3_svg_lineRadial);
8336 line.radius = line.x, delete line.x;
8337 line.angle = line.y, delete line.y;
8340 function d3_svg_lineRadial(points) {
8341 var point, i = -1, n = points.length, r, a;
8345 a = point[1] - halfπ;
8346 point[0] = r * Math.cos(a);
8347 point[1] = r * Math.sin(a);
8351 function d3_svg_area(projection) {
8352 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;
8353 function area(data) {
8354 var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
8356 } : d3_functor(x1), fy1 = y0 === y1 ? function() {
8358 } : d3_functor(y1), x, y;
8359 function segment() {
8360 segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
8363 if (defined.call(this, d = data[i], i)) {
8364 points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
8365 points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
8366 } else if (points0.length) {
8372 if (points0.length) segment();
8373 return segments.length ? segments.join("") : null;
8375 area.x = function(_) {
8376 if (!arguments.length) return x1;
8380 area.x0 = function(_) {
8381 if (!arguments.length) return x0;
8385 area.x1 = function(_) {
8386 if (!arguments.length) return x1;
8390 area.y = function(_) {
8391 if (!arguments.length) return y1;
8395 area.y0 = function(_) {
8396 if (!arguments.length) return y0;
8400 area.y1 = function(_) {
8401 if (!arguments.length) return y1;
8405 area.defined = function(_) {
8406 if (!arguments.length) return defined;
8410 area.interpolate = function(_) {
8411 if (!arguments.length) return interpolateKey;
8412 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
8413 interpolateReverse = interpolate.reverse || interpolate;
8414 L = interpolate.closed ? "M" : "L";
8417 area.tension = function(_) {
8418 if (!arguments.length) return tension;
8424 d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
8425 d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
8426 d3.svg.area = function() {
8427 return d3_svg_area(d3_identity);
8429 d3.svg.area.radial = function() {
8430 var area = d3_svg_area(d3_svg_lineRadial);
8431 area.radius = area.x, delete area.x;
8432 area.innerRadius = area.x0, delete area.x0;
8433 area.outerRadius = area.x1, delete area.x1;
8434 area.angle = area.y, delete area.y;
8435 area.startAngle = area.y0, delete area.y0;
8436 area.endAngle = area.y1, delete area.y1;
8439 d3.svg.chord = function() {
8440 var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
8441 function chord(d, i) {
8442 var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
8443 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";
8445 function subgroup(self, f, d, i) {
8446 var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) - halfπ, a1 = endAngle.call(self, subgroup, i) - halfπ;
8451 p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
8452 p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
8455 function equals(a, b) {
8456 return a.a0 == b.a0 && a.a1 == b.a1;
8458 function arc(r, p, a) {
8459 return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
8461 function curve(r0, p0, r1, p1) {
8462 return "Q 0,0 " + p1;
8464 chord.radius = function(v) {
8465 if (!arguments.length) return radius;
8466 radius = d3_functor(v);
8469 chord.source = function(v) {
8470 if (!arguments.length) return source;
8471 source = d3_functor(v);
8474 chord.target = function(v) {
8475 if (!arguments.length) return target;
8476 target = d3_functor(v);
8479 chord.startAngle = function(v) {
8480 if (!arguments.length) return startAngle;
8481 startAngle = d3_functor(v);
8484 chord.endAngle = function(v) {
8485 if (!arguments.length) return endAngle;
8486 endAngle = d3_functor(v);
8491 function d3_svg_chordRadius(d) {
8494 d3.svg.diagonal = function() {
8495 var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
8496 function diagonal(d, i) {
8497 var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
8504 p = p.map(projection);
8505 return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
8507 diagonal.source = function(x) {
8508 if (!arguments.length) return source;
8509 source = d3_functor(x);
8512 diagonal.target = function(x) {
8513 if (!arguments.length) return target;
8514 target = d3_functor(x);
8517 diagonal.projection = function(x) {
8518 if (!arguments.length) return projection;
8524 function d3_svg_diagonalProjection(d) {
8525 return [ d.x, d.y ];
8527 d3.svg.diagonal.radial = function() {
8528 var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
8529 diagonal.projection = function(x) {
8530 return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
8534 function d3_svg_diagonalRadialProjection(projection) {
8536 var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
8537 return [ r * Math.cos(a), r * Math.sin(a) ];
8540 d3.svg.symbol = function() {
8541 var type = d3_svg_symbolType, size = d3_svg_symbolSize;
8542 function symbol(d, i) {
8543 return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
8545 symbol.type = function(x) {
8546 if (!arguments.length) return type;
8547 type = d3_functor(x);
8550 symbol.size = function(x) {
8551 if (!arguments.length) return size;
8552 size = d3_functor(x);
8557 function d3_svg_symbolSize() {
8560 function d3_svg_symbolType() {
8563 function d3_svg_symbolCircle(size) {
8564 var r = Math.sqrt(size / π);
8565 return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
8567 var d3_svg_symbols = d3.map({
8568 circle: d3_svg_symbolCircle,
8569 cross: function(size) {
8570 var r = Math.sqrt(size / 5) / 2;
8571 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";
8573 diamond: function(size) {
8574 var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
8575 return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
8577 square: function(size) {
8578 var r = Math.sqrt(size) / 2;
8579 return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
8581 "triangle-down": function(size) {
8582 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8583 return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
8585 "triangle-up": function(size) {
8586 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8587 return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
8590 d3.svg.symbolTypes = d3_svg_symbols.keys();
8591 var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
8592 d3_selectionPrototype.transition = function(name) {
8593 var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
8595 ease: d3_ease_cubicInOut,
8599 for (var j = -1, m = this.length; ++j < m; ) {
8600 subgroups.push(subgroup = []);
8601 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8602 if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
8603 subgroup.push(node);
8606 return d3_transition(subgroups, ns, id);
8608 d3_selectionPrototype.interrupt = function(name) {
8609 return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
8611 var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
8612 function d3_selection_interruptNS(ns) {
8615 if ((lock = this[ns]) && (active = lock[lock.active])) {
8616 if (--lock.count) delete lock[lock.active]; else delete this[ns];
8618 active.event && active.event.interrupt.call(this, this.__data__, active.index);
8622 function d3_transition(groups, ns, id) {
8623 d3_subclass(groups, d3_transitionPrototype);
8624 groups.namespace = ns;
8628 var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
8629 d3_transitionPrototype.call = d3_selectionPrototype.call;
8630 d3_transitionPrototype.empty = d3_selectionPrototype.empty;
8631 d3_transitionPrototype.node = d3_selectionPrototype.node;
8632 d3_transitionPrototype.size = d3_selectionPrototype.size;
8633 d3.transition = function(selection, name) {
8634 return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
8636 d3.transition.prototype = d3_transitionPrototype;
8637 d3_transitionPrototype.select = function(selector) {
8638 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
8639 selector = d3_selection_selector(selector);
8640 for (var j = -1, m = this.length; ++j < m; ) {
8641 subgroups.push(subgroup = []);
8642 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8643 if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
8644 if ("__data__" in node) subnode.__data__ = node.__data__;
8645 d3_transitionNode(subnode, i, ns, id, node[ns][id]);
8646 subgroup.push(subnode);
8648 subgroup.push(null);
8652 return d3_transition(subgroups, ns, id);
8654 d3_transitionPrototype.selectAll = function(selector) {
8655 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
8656 selector = d3_selection_selectorAll(selector);
8657 for (var j = -1, m = this.length; ++j < m; ) {
8658 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8659 if (node = group[i]) {
8660 transition = node[ns][id];
8661 subnodes = selector.call(node, node.__data__, i, j);
8662 subgroups.push(subgroup = []);
8663 for (var k = -1, o = subnodes.length; ++k < o; ) {
8664 if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
8665 subgroup.push(subnode);
8670 return d3_transition(subgroups, ns, id);
8672 d3_transitionPrototype.filter = function(filter) {
8673 var subgroups = [], subgroup, group, node;
8674 if (typeof filter !== "function") filter = d3_selection_filter(filter);
8675 for (var j = 0, m = this.length; j < m; j++) {
8676 subgroups.push(subgroup = []);
8677 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
8678 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
8679 subgroup.push(node);
8683 return d3_transition(subgroups, this.namespace, this.id);
8685 d3_transitionPrototype.tween = function(name, tween) {
8686 var id = this.id, ns = this.namespace;
8687 if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
8688 return d3_selection_each(this, tween == null ? function(node) {
8689 node[ns][id].tween.remove(name);
8690 } : function(node) {
8691 node[ns][id].tween.set(name, tween);
8694 function d3_transition_tween(groups, name, value, tween) {
8695 var id = groups.id, ns = groups.namespace;
8696 return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
8697 node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
8698 } : (value = tween(value), function(node) {
8699 node[ns][id].tween.set(name, value);
8702 d3_transitionPrototype.attr = function(nameNS, value) {
8703 if (arguments.length < 2) {
8704 for (value in nameNS) this.attr(value, nameNS[value]);
8707 var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
8708 function attrNull() {
8709 this.removeAttribute(name);
8711 function attrNullNS() {
8712 this.removeAttributeNS(name.space, name.local);
8714 function attrTween(b) {
8715 return b == null ? attrNull : (b += "", function() {
8716 var a = this.getAttribute(name), i;
8717 return a !== b && (i = interpolate(a, b), function(t) {
8718 this.setAttribute(name, i(t));
8722 function attrTweenNS(b) {
8723 return b == null ? attrNullNS : (b += "", function() {
8724 var a = this.getAttributeNS(name.space, name.local), i;
8725 return a !== b && (i = interpolate(a, b), function(t) {
8726 this.setAttributeNS(name.space, name.local, i(t));
8730 return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
8732 d3_transitionPrototype.attrTween = function(nameNS, tween) {
8733 var name = d3.ns.qualify(nameNS);
8734 function attrTween(d, i) {
8735 var f = tween.call(this, d, i, this.getAttribute(name));
8736 return f && function(t) {
8737 this.setAttribute(name, f(t));
8740 function attrTweenNS(d, i) {
8741 var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
8742 return f && function(t) {
8743 this.setAttributeNS(name.space, name.local, f(t));
8746 return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
8748 d3_transitionPrototype.style = function(name, value, priority) {
8749 var n = arguments.length;
8751 if (typeof name !== "string") {
8752 if (n < 2) value = "";
8753 for (priority in name) this.style(priority, name[priority], value);
8758 function styleNull() {
8759 this.style.removeProperty(name);
8761 function styleString(b) {
8762 return b == null ? styleNull : (b += "", function() {
8763 var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
8764 return a !== b && (i = d3_interpolate(a, b), function(t) {
8765 this.style.setProperty(name, i(t), priority);
8769 return d3_transition_tween(this, "style." + name, value, styleString);
8771 d3_transitionPrototype.styleTween = function(name, tween, priority) {
8772 if (arguments.length < 3) priority = "";
8773 function styleTween(d, i) {
8774 var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
8775 return f && function(t) {
8776 this.style.setProperty(name, f(t), priority);
8779 return this.tween("style." + name, styleTween);
8781 d3_transitionPrototype.text = function(value) {
8782 return d3_transition_tween(this, "text", value, d3_transition_text);
8784 function d3_transition_text(b) {
8785 if (b == null) b = "";
8787 this.textContent = b;
8790 d3_transitionPrototype.remove = function() {
8791 var ns = this.namespace;
8792 return this.each("end.transition", function() {
8794 if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
8797 d3_transitionPrototype.ease = function(value) {
8798 var id = this.id, ns = this.namespace;
8799 if (arguments.length < 1) return this.node()[ns][id].ease;
8800 if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
8801 return d3_selection_each(this, function(node) {
8802 node[ns][id].ease = value;
8805 d3_transitionPrototype.delay = function(value) {
8806 var id = this.id, ns = this.namespace;
8807 if (arguments.length < 1) return this.node()[ns][id].delay;
8808 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8809 node[ns][id].delay = +value.call(node, node.__data__, i, j);
8810 } : (value = +value, function(node) {
8811 node[ns][id].delay = value;
8814 d3_transitionPrototype.duration = function(value) {
8815 var id = this.id, ns = this.namespace;
8816 if (arguments.length < 1) return this.node()[ns][id].duration;
8817 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8818 node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
8819 } : (value = Math.max(1, value), function(node) {
8820 node[ns][id].duration = value;
8823 d3_transitionPrototype.each = function(type, listener) {
8824 var id = this.id, ns = this.namespace;
8825 if (arguments.length < 2) {
8826 var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
8828 d3_transitionInheritId = id;
8829 d3_selection_each(this, function(node, i, j) {
8830 d3_transitionInherit = node[ns][id];
8831 type.call(node, node.__data__, i, j);
8834 d3_transitionInherit = inherit;
8835 d3_transitionInheritId = inheritId;
8838 d3_selection_each(this, function(node) {
8839 var transition = node[ns][id];
8840 (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
8845 d3_transitionPrototype.transition = function() {
8846 var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
8847 for (var j = 0, m = this.length; j < m; j++) {
8848 subgroups.push(subgroup = []);
8849 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
8850 if (node = group[i]) {
8851 transition = node[ns][id0];
8852 d3_transitionNode(node, i, ns, id1, {
8853 time: transition.time,
8854 ease: transition.ease,
8855 delay: transition.delay + transition.duration,
8856 duration: transition.duration
8859 subgroup.push(node);
8862 return d3_transition(subgroups, ns, id1);
8864 function d3_transitionNamespace(name) {
8865 return name == null ? "__transition__" : "__transition_" + name + "__";
8867 function d3_transitionNode(node, i, ns, id, inherit) {
8868 var lock = node[ns] || (node[ns] = {
8871 }), transition = lock[id];
8873 var time = inherit.time;
8874 transition = lock[id] = {
8875 tween: new d3_Map(),
8877 delay: inherit.delay,
8878 duration: inherit.duration,
8884 d3.timer(function(elapsed) {
8885 var delay = transition.delay, duration, ease, timer = d3_timer_active, tweened = [];
8886 timer.t = delay + time;
8887 if (delay <= elapsed) return start(elapsed - delay);
8889 function start(elapsed) {
8890 if (lock.active > id) return stop();
8891 var active = lock[lock.active];
8894 delete lock[lock.active];
8895 active.event && active.event.interrupt.call(node, node.__data__, active.index);
8898 transition.event && transition.event.start.call(node, node.__data__, i);
8899 transition.tween.forEach(function(key, value) {
8900 if (value = value.call(node, node.__data__, i)) {
8901 tweened.push(value);
8904 ease = transition.ease;
8905 duration = transition.duration;
8906 d3.timer(function() {
8907 timer.c = tick(elapsed || 1) ? d3_true : tick;
8911 function tick(elapsed) {
8912 if (lock.active !== id) return 1;
8913 var t = elapsed / duration, e = ease(t), n = tweened.length;
8915 tweened[--n].call(node, e);
8918 transition.event && transition.event.end.call(node, node.__data__, i);
8923 if (--lock.count) delete lock[id]; else delete node[ns];
8929 d3.svg.axis = function() {
8930 var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
8933 var g = d3.select(this);
8934 var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
8935 var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick.order()).style("opacity", 1), tickSpacing = Math.max(innerTickSize, 0) + tickPadding, tickTransform;
8936 var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
8937 d3.transition(path));
8938 tickEnter.append("line");
8939 tickEnter.append("text");
8940 var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text"), sign = orient === "top" || orient === "left" ? -1 : 1, x1, x2, y1, y2;
8941 if (orient === "bottom" || orient === "top") {
8942 tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
8943 text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
8944 pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
8946 tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
8947 text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
8948 pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
8950 lineEnter.attr(y2, sign * innerTickSize);
8951 textEnter.attr(y1, sign * tickSpacing);
8952 lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
8953 textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
8954 if (scale1.rangeBand) {
8955 var x = scale1, dx = x.rangeBand() / 2;
8956 scale0 = scale1 = function(d) {
8959 } else if (scale0.rangeBand) {
8962 tickExit.call(tickTransform, scale1, scale0);
8964 tickEnter.call(tickTransform, scale0, scale1);
8965 tickUpdate.call(tickTransform, scale1, scale1);
8968 axis.scale = function(x) {
8969 if (!arguments.length) return scale;
8973 axis.orient = function(x) {
8974 if (!arguments.length) return orient;
8975 orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
8978 axis.ticks = function() {
8979 if (!arguments.length) return tickArguments_;
8980 tickArguments_ = arguments;
8983 axis.tickValues = function(x) {
8984 if (!arguments.length) return tickValues;
8988 axis.tickFormat = function(x) {
8989 if (!arguments.length) return tickFormat_;
8993 axis.tickSize = function(x) {
8994 var n = arguments.length;
8995 if (!n) return innerTickSize;
8997 outerTickSize = +arguments[n - 1];
9000 axis.innerTickSize = function(x) {
9001 if (!arguments.length) return innerTickSize;
9005 axis.outerTickSize = function(x) {
9006 if (!arguments.length) return outerTickSize;
9010 axis.tickPadding = function(x) {
9011 if (!arguments.length) return tickPadding;
9015 axis.tickSubdivide = function() {
9016 return arguments.length && axis;
9020 var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
9026 function d3_svg_axisX(selection, x0, x1) {
9027 selection.attr("transform", function(d) {
9029 return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
9032 function d3_svg_axisY(selection, y0, y1) {
9033 selection.attr("transform", function(d) {
9035 return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
9038 d3.svg.brush = function() {
9039 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];
9042 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);
9043 var background = g.selectAll(".background").data([ 0 ]);
9044 background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
9045 g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
9046 var resize = g.selectAll(".resize").data(resizes, d3_identity);
9047 resize.exit().remove();
9048 resize.enter().append("g").attr("class", function(d) {
9049 return "resize " + d;
9050 }).style("cursor", function(d) {
9051 return d3_svg_brushCursor[d];
9052 }).append("rect").attr("x", function(d) {
9053 return /[ew]$/.test(d) ? -3 : null;
9054 }).attr("y", function(d) {
9055 return /^[ns]/.test(d) ? -3 : null;
9056 }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
9057 resize.style("display", brush.empty() ? "none" : null);
9058 var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
9060 range = d3_scaleRange(x);
9061 backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
9065 range = d3_scaleRange(y);
9066 backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
9072 brush.event = function(g) {
9074 var event_ = event.of(this, arguments), extent1 = {
9079 }, extent0 = this.__chart__ || extent1;
9080 this.__chart__ = extent1;
9081 if (d3_transitionInheritId) {
9082 d3.select(this).transition().each("start.brush", function() {
9083 xExtentDomain = extent0.i;
9084 yExtentDomain = extent0.j;
9085 xExtent = extent0.x;
9086 yExtent = extent0.y;
9090 }).tween("brush:brush", function() {
9091 var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
9092 xExtentDomain = yExtentDomain = null;
9093 return function(t) {
9094 xExtent = extent1.x = xi(t);
9095 yExtent = extent1.y = yi(t);
9101 }).each("end.brush", function() {
9102 xExtentDomain = extent1.i;
9103 yExtentDomain = extent1.j;
9126 function redraw(g) {
9127 g.selectAll(".resize").attr("transform", function(d) {
9128 return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
9131 function redrawX(g) {
9132 g.select(".extent").attr("x", xExtent[0]);
9133 g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
9135 function redrawY(g) {
9136 g.select(".extent").attr("y", yExtent[0]);
9137 g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
9139 function brushstart() {
9140 var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), dragRestore = d3_event_dragSuppress(target), center, origin = d3.mouse(target), offset;
9141 var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
9142 if (d3.event.changedTouches) {
9143 w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
9145 w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
9147 g.interrupt().selectAll("*").interrupt();
9149 origin[0] = xExtent[0] - origin[0];
9150 origin[1] = yExtent[0] - origin[1];
9151 } else if (resizing) {
9152 var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
9153 offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
9154 origin[0] = xExtent[ex];
9155 origin[1] = yExtent[ey];
9156 } else if (d3.event.altKey) center = origin.slice();
9157 g.style("pointer-events", "none").selectAll(".resize").style("display", null);
9158 d3.select("body").style("cursor", eventTarget.style("cursor"));
9163 function keydown() {
9164 if (d3.event.keyCode == 32) {
9167 origin[0] -= xExtent[1];
9168 origin[1] -= yExtent[1];
9171 d3_eventPreventDefault();
9175 if (d3.event.keyCode == 32 && dragging == 2) {
9176 origin[0] += xExtent[1];
9177 origin[1] += yExtent[1];
9179 d3_eventPreventDefault();
9182 function brushmove() {
9183 var point = d3.mouse(target), moved = false;
9185 point[0] += offset[0];
9186 point[1] += offset[1];
9189 if (d3.event.altKey) {
9190 if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
9191 origin[0] = xExtent[+(point[0] < center[0])];
9192 origin[1] = yExtent[+(point[1] < center[1])];
9193 } else center = null;
9195 if (resizingX && move1(point, x, 0)) {
9199 if (resizingY && move1(point, y, 1)) {
9207 mode: dragging ? "move" : "resize"
9211 function move1(point, scale, i) {
9212 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;
9215 r1 -= size + position;
9217 min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
9219 max = (min += position) + size;
9221 if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
9222 if (position < min) {
9229 if (extent[0] != min || extent[1] != max) {
9230 if (i) yExtentDomain = null; else xExtentDomain = null;
9236 function brushend() {
9238 g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
9239 d3.select("body").style("cursor", null);
9240 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);
9247 brush.x = function(z) {
9248 if (!arguments.length) return x;
9250 resizes = d3_svg_brushResizes[!x << 1 | !y];
9253 brush.y = function(z) {
9254 if (!arguments.length) return y;
9256 resizes = d3_svg_brushResizes[!x << 1 | !y];
9259 brush.clamp = function(z) {
9260 if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
9261 if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
9264 brush.extent = function(z) {
9265 var x0, x1, y0, y1, t;
9266 if (!arguments.length) {
9268 if (xExtentDomain) {
9269 x0 = xExtentDomain[0], x1 = xExtentDomain[1];
9271 x0 = xExtent[0], x1 = xExtent[1];
9272 if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
9273 if (x1 < x0) t = x0, x0 = x1, x1 = t;
9277 if (yExtentDomain) {
9278 y0 = yExtentDomain[0], y1 = yExtentDomain[1];
9280 y0 = yExtent[0], y1 = yExtent[1];
9281 if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
9282 if (y1 < y0) t = y0, y0 = y1, y1 = t;
9285 return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
9288 x0 = z[0], x1 = z[1];
9289 if (y) x0 = x0[0], x1 = x1[0];
9290 xExtentDomain = [ x0, x1 ];
9291 if (x.invert) x0 = x(x0), x1 = x(x1);
9292 if (x1 < x0) t = x0, x0 = x1, x1 = t;
9293 if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
9296 y0 = z[0], y1 = z[1];
9297 if (x) y0 = y0[1], y1 = y1[1];
9298 yExtentDomain = [ y0, y1 ];
9299 if (y.invert) y0 = y(y0), y1 = y(y1);
9300 if (y1 < y0) t = y0, y0 = y1, y1 = t;
9301 if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
9305 brush.clear = function() {
9306 if (!brush.empty()) {
9307 xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
9308 xExtentDomain = yExtentDomain = null;
9312 brush.empty = function() {
9313 return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
9315 return d3.rebind(brush, event, "on");
9317 var d3_svg_brushCursor = {
9327 var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
9328 var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
9329 var d3_time_formatUtc = d3_time_format.utc;
9330 var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
9331 d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
9332 function d3_time_formatIsoNative(date) {
9333 return date.toISOString();
9335 d3_time_formatIsoNative.parse = function(string) {
9336 var date = new Date(string);
9337 return isNaN(date) ? null : date;
9339 d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
9340 d3_time.second = d3_time_interval(function(date) {
9341 return new d3_date(Math.floor(date / 1e3) * 1e3);
9342 }, function(date, offset) {
9343 date.setTime(date.getTime() + Math.floor(offset) * 1e3);
9345 return date.getSeconds();
9347 d3_time.seconds = d3_time.second.range;
9348 d3_time.seconds.utc = d3_time.second.utc.range;
9349 d3_time.minute = d3_time_interval(function(date) {
9350 return new d3_date(Math.floor(date / 6e4) * 6e4);
9351 }, function(date, offset) {
9352 date.setTime(date.getTime() + Math.floor(offset) * 6e4);
9354 return date.getMinutes();
9356 d3_time.minutes = d3_time.minute.range;
9357 d3_time.minutes.utc = d3_time.minute.utc.range;
9358 d3_time.hour = d3_time_interval(function(date) {
9359 var timezone = date.getTimezoneOffset() / 60;
9360 return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
9361 }, function(date, offset) {
9362 date.setTime(date.getTime() + Math.floor(offset) * 36e5);
9364 return date.getHours();
9366 d3_time.hours = d3_time.hour.range;
9367 d3_time.hours.utc = d3_time.hour.utc.range;
9368 d3_time.month = d3_time_interval(function(date) {
9369 date = d3_time.day(date);
9372 }, function(date, offset) {
9373 date.setMonth(date.getMonth() + offset);
9375 return date.getMonth();
9377 d3_time.months = d3_time.month.range;
9378 d3_time.months.utc = d3_time.month.utc.range;
9379 function d3_time_scale(linear, methods, format) {
9383 scale.invert = function(x) {
9384 return d3_time_scaleDate(linear.invert(x));
9386 scale.domain = function(x) {
9387 if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
9391 function tickMethod(extent, count) {
9392 var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
9393 return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
9395 }), 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];
9397 scale.nice = function(interval, skip) {
9398 var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
9399 if (method) interval = method[0], skip = method[1];
9400 function skipped(date) {
9401 return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
9403 return scale.domain(d3_scale_nice(domain, skip > 1 ? {
9404 floor: function(date) {
9405 while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
9408 ceil: function(date) {
9409 while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
9414 scale.ticks = function(interval, skip) {
9415 var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
9418 if (method) interval = method[0], skip = method[1];
9419 return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
9421 scale.tickFormat = function() {
9424 scale.copy = function() {
9425 return d3_time_scale(linear.copy(), methods, format);
9427 return d3_scale_linearRebind(scale, linear);
9429 function d3_time_scaleDate(t) {
9432 var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
9433 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 ] ];
9434 var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
9435 return d.getMilliseconds();
9436 } ], [ ":%S", function(d) {
9437 return d.getSeconds();
9438 } ], [ "%I:%M", function(d) {
9439 return d.getMinutes();
9440 } ], [ "%I %p", function(d) {
9441 return d.getHours();
9442 } ], [ "%a %d", function(d) {
9443 return d.getDay() && d.getDate() != 1;
9444 } ], [ "%b %d", function(d) {
9445 return d.getDate() != 1;
9446 } ], [ "%B", function(d) {
9447 return d.getMonth();
9448 } ], [ "%Y", d3_true ] ]);
9449 var d3_time_scaleMilliseconds = {
9450 range: function(start, stop, step) {
9451 return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
9456 d3_time_scaleLocalMethods.year = d3_time.year;
9457 d3_time.scale = function() {
9458 return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
9460 var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
9461 return [ m[0].utc, m[1] ];
9463 var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
9464 return d.getUTCMilliseconds();
9465 } ], [ ":%S", function(d) {
9466 return d.getUTCSeconds();
9467 } ], [ "%I:%M", function(d) {
9468 return d.getUTCMinutes();
9469 } ], [ "%I %p", function(d) {
9470 return d.getUTCHours();
9471 } ], [ "%a %d", function(d) {
9472 return d.getUTCDay() && d.getUTCDate() != 1;
9473 } ], [ "%b %d", function(d) {
9474 return d.getUTCDate() != 1;
9475 } ], [ "%B", function(d) {
9476 return d.getUTCMonth();
9477 } ], [ "%Y", d3_true ] ]);
9478 d3_time_scaleUtcMethods.year = d3_time.year.utc;
9479 d3_time.scale.utc = function() {
9480 return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
9482 d3.text = d3_xhrType(function(request) {
9483 return request.responseText;
9485 d3.json = function(url, callback) {
9486 return d3_xhr(url, "application/json", d3_json, callback);
9488 function d3_json(request) {
9489 return JSON.parse(request.responseText);
9491 d3.html = function(url, callback) {
9492 return d3_xhr(url, "text/html", d3_html, callback);
9494 function d3_html(request) {
9495 var range = d3_document.createRange();
9496 range.selectNode(d3_document.body);
9497 return range.createContextualFragment(request.responseText);
9499 d3.xml = d3_xhrType(function(request) {
9500 return request.responseXML;
9502 if (typeof define === "function" && define.amd) define(d3); else if (typeof module === "object" && module.exports) module.exports = d3;