5 if (!Date.now) Date.now = function() {
8 var d3_arraySlice = [].slice, d3_array = function(list) {
9 return d3_arraySlice.call(list);
11 var d3_document = document, d3_documentElement = d3_document.documentElement, d3_window = window;
13 d3_array(d3_documentElement.childNodes)[0].nodeType;
15 d3_array = function(list) {
16 var i = list.length, array = new Array(i);
17 while (i--) array[i] = list[i];
22 d3_document.createElement("div").style.setProperty("opacity", 0, "");
24 var d3_element_prototype = d3_window.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = d3_window.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
25 d3_element_prototype.setAttribute = function(name, value) {
26 d3_element_setAttribute.call(this, name, value + "");
28 d3_element_prototype.setAttributeNS = function(space, local, value) {
29 d3_element_setAttributeNS.call(this, space, local, value + "");
31 d3_style_prototype.setProperty = function(name, value, priority) {
32 d3_style_setProperty.call(this, name, value + "", priority);
35 d3.ascending = d3_ascending;
36 function d3_ascending(a, b) {
37 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
39 d3.descending = function(a, b) {
40 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
42 d3.min = function(array, f) {
43 var i = -1, n = array.length, a, b;
44 if (arguments.length === 1) {
45 while (++i < n && !((a = array[i]) != null && a <= a)) a = undefined;
46 while (++i < n) if ((b = array[i]) != null && a > b) a = b;
48 while (++i < n && !((a = f.call(array, array[i], i)) != null && a <= a)) a = undefined;
49 while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
53 d3.max = function(array, f) {
54 var i = -1, n = array.length, a, b;
55 if (arguments.length === 1) {
56 while (++i < n && !((a = array[i]) != null && a <= a)) a = undefined;
57 while (++i < n) if ((b = array[i]) != null && b > a) a = b;
59 while (++i < n && !((a = f.call(array, array[i], i)) != null && a <= a)) a = undefined;
60 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
64 d3.extent = function(array, f) {
65 var i = -1, n = array.length, a, b, c;
66 if (arguments.length === 1) {
67 while (++i < n && !((a = c = array[i]) != null && a <= a)) a = c = undefined;
68 while (++i < n) if ((b = array[i]) != null) {
73 while (++i < n && !((a = c = f.call(array, array[i], i)) != null && a <= a)) a = undefined;
74 while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
81 d3.sum = function(array, f) {
82 var s = 0, n = array.length, a, i = -1;
83 if (arguments.length === 1) {
84 while (++i < n) if (!isNaN(a = +array[i])) s += a;
86 while (++i < n) if (!isNaN(a = +f.call(array, array[i], i))) s += a;
90 function d3_number(x) {
91 return x != null && !isNaN(x);
93 d3.mean = function(array, f) {
94 var n = array.length, a, m = 0, i = -1, j = 0;
95 if (arguments.length === 1) {
96 while (++i < n) if (d3_number(a = array[i])) m += (a - m) / ++j;
98 while (++i < n) if (d3_number(a = f.call(array, array[i], i))) m += (a - m) / ++j;
100 return j ? m : undefined;
102 d3.quantile = function(values, p) {
103 var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
104 return e ? v + e * (values[h] - v) : v;
106 d3.median = function(array, f) {
107 if (arguments.length > 1) array = array.map(f);
108 array = array.filter(d3_number);
109 return array.length ? d3.quantile(array.sort(d3_ascending), .5) : undefined;
111 function d3_bisector(compare) {
113 left: function(a, x, lo, hi) {
114 if (arguments.length < 3) lo = 0;
115 if (arguments.length < 4) hi = a.length;
117 var mid = lo + hi >>> 1;
118 if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
122 right: function(a, x, lo, hi) {
123 if (arguments.length < 3) lo = 0;
124 if (arguments.length < 4) hi = a.length;
126 var mid = lo + hi >>> 1;
127 if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
133 var d3_bisect = d3_bisector(d3_ascending);
134 d3.bisectLeft = d3_bisect.left;
135 d3.bisect = d3.bisectRight = d3_bisect.right;
136 d3.bisector = function(f) {
137 return d3_bisector(f.length === 1 ? function(d, x) {
138 return d3_ascending(f(d), x);
141 d3.shuffle = function(array) {
142 var m = array.length, t, i;
144 i = Math.random() * m-- | 0;
145 t = array[m], array[m] = array[i], array[i] = t;
149 d3.permute = function(array, indexes) {
150 var i = indexes.length, permutes = new Array(i);
151 while (i--) permutes[i] = array[indexes[i]];
154 d3.pairs = function(array) {
155 var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
156 while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
159 d3.zip = function() {
160 if (!(n = arguments.length)) return [];
161 for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
162 for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
163 zip[j] = arguments[j][i];
168 function d3_zipLength(d) {
171 d3.transpose = function(matrix) {
172 return d3.zip.apply(d3, matrix);
174 d3.keys = function(map) {
176 for (var key in map) keys.push(key);
179 d3.values = function(map) {
181 for (var key in map) values.push(map[key]);
184 d3.entries = function(map) {
186 for (var key in map) entries.push({
192 d3.merge = function(arrays) {
193 var n = arrays.length, m, i = -1, j = 0, merged, array;
194 while (++i < n) j += arrays[i].length;
195 merged = new Array(j);
200 merged[--j] = array[m];
206 d3.range = function(start, stop, step) {
207 if (arguments.length < 3) {
209 if (arguments.length < 2) {
214 if ((stop - start) / step === Infinity) throw new Error("infinite range");
215 var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
216 start *= k, stop *= k, step *= k;
217 if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
220 function d3_range_integerScale(x) {
222 while (x * k % 1) k *= 10;
225 function d3_class(ctor, properties) {
227 for (var key in properties) {
228 Object.defineProperty(ctor.prototype, key, {
229 value: properties[key],
234 ctor.prototype = properties;
237 d3.map = function(object) {
238 var map = new d3_Map();
239 if (object instanceof d3_Map) object.forEach(function(key, value) {
241 }); else for (var key in object) map.set(key, object[key]);
248 return this[d3_map_prefix + key];
250 set: function(key, value) {
251 return this[d3_map_prefix + key] = value;
253 remove: d3_map_remove,
257 this.forEach(function(key, value) {
262 entries: function() {
264 this.forEach(function(key, value) {
274 forEach: function(f) {
275 for (var key in this) if (key.charCodeAt(0) === d3_map_prefixCode) f.call(this, key.substring(1), this[key]);
278 var d3_map_prefix = "\x00", d3_map_prefixCode = d3_map_prefix.charCodeAt(0);
279 function d3_map_has(key) {
280 return d3_map_prefix + key in this;
282 function d3_map_remove(key) {
283 key = d3_map_prefix + key;
284 return key in this && delete this[key];
286 function d3_map_keys() {
288 this.forEach(function(key) {
293 function d3_map_size() {
295 for (var key in this) if (key.charCodeAt(0) === d3_map_prefixCode) ++size;
298 function d3_map_empty() {
299 for (var key in this) if (key.charCodeAt(0) === d3_map_prefixCode) return false;
302 d3.nest = function() {
303 var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
304 function map(mapType, array, depth) {
305 if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
306 var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
308 if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
311 valuesByKey.set(keyValue, [ object ]);
316 setter = function(keyValue, values) {
317 object.set(keyValue, map(mapType, values, depth));
321 setter = function(keyValue, values) {
322 object[keyValue] = map(mapType, values, depth);
325 valuesByKey.forEach(setter);
328 function entries(map, depth) {
329 if (depth >= keys.length) return map;
330 var array = [], sortKey = sortKeys[depth++];
331 map.forEach(function(key, keyMap) {
334 values: entries(keyMap, depth)
337 return sortKey ? array.sort(function(a, b) {
338 return sortKey(a.key, b.key);
341 nest.map = function(array, mapType) {
342 return map(mapType, array, 0);
344 nest.entries = function(array) {
345 return entries(map(d3.map, array, 0), 0);
347 nest.key = function(d) {
351 nest.sortKeys = function(order) {
352 sortKeys[keys.length - 1] = order;
355 nest.sortValues = function(order) {
359 nest.rollup = function(f) {
365 d3.set = function(array) {
366 var set = new d3_Set();
367 if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
373 add: function(value) {
374 this[d3_map_prefix + value] = true;
377 remove: function(value) {
378 value = d3_map_prefix + value;
379 return value in this && delete this[value];
384 forEach: function(f) {
385 for (var value in this) if (value.charCodeAt(0) === d3_map_prefixCode) f.call(this, value.substring(1));
389 d3.rebind = function(target, source) {
390 var i = 1, n = arguments.length, method;
391 while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
394 function d3_rebind(target, source, method) {
396 var value = method.apply(source, arguments);
397 return value === source ? target : value;
400 function d3_vendorSymbol(object, name) {
401 if (name in object) return name;
402 name = name.charAt(0).toUpperCase() + name.substring(1);
403 for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
404 var prefixName = d3_vendorPrefixes[i] + name;
405 if (prefixName in object) return prefixName;
408 var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
409 function d3_noop() {}
410 d3.dispatch = function() {
411 var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
412 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
415 function d3_dispatch() {}
416 d3_dispatch.prototype.on = function(type, listener) {
417 var i = type.indexOf("."), name = "";
419 name = type.substring(i + 1);
420 type = type.substring(0, i);
422 if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
423 if (arguments.length === 2) {
424 if (listener == null) for (type in this) {
425 if (this.hasOwnProperty(type)) this[type].on(name, null);
430 function d3_dispatch_event(dispatch) {
431 var listeners = [], listenerByName = new d3_Map();
433 var z = listeners, i = -1, n = z.length, l;
434 while (++i < n) if (l = z[i].on) l.apply(this, arguments);
437 event.on = function(name, listener) {
438 var l = listenerByName.get(name), i;
439 if (arguments.length < 2) return l && l.on;
442 listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
443 listenerByName.remove(name);
445 if (listener) listeners.push(listenerByName.set(name, {
453 function d3_eventPreventDefault() {
454 d3.event.preventDefault();
456 function d3_eventSource() {
458 while (s = e.sourceEvent) e = s;
461 function d3_eventDispatch(target) {
462 var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
463 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
464 dispatch.of = function(thiz, argumentz) {
465 return function(e1) {
467 var e0 = e1.sourceEvent = d3.event;
470 dispatch[e1.type].apply(thiz, argumentz);
478 d3.requote = function(s) {
479 return s.replace(d3_requote_re, "\\$&");
481 var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
482 var d3_subclass = {}.__proto__ ? function(object, prototype) {
483 object.__proto__ = prototype;
484 } : function(object, prototype) {
485 for (var property in prototype) object[property] = prototype[property];
487 function d3_selection(groups) {
488 d3_subclass(groups, d3_selectionPrototype);
491 var d3_select = function(s, n) {
492 return n.querySelector(s);
493 }, d3_selectAll = function(s, n) {
494 return n.querySelectorAll(s);
495 }, d3_selectMatcher = d3_documentElement[d3_vendorSymbol(d3_documentElement, "matchesSelector")], d3_selectMatches = function(n, s) {
496 return d3_selectMatcher.call(n, s);
498 if (typeof Sizzle === "function") {
499 d3_select = function(s, n) {
500 return Sizzle(s, n)[0] || null;
502 d3_selectAll = Sizzle;
503 d3_selectMatches = Sizzle.matchesSelector;
505 d3.selection = function() {
506 return d3_selectionRoot;
508 var d3_selectionPrototype = d3.selection.prototype = [];
509 d3_selectionPrototype.select = function(selector) {
510 var subgroups = [], subgroup, subnode, group, node;
511 selector = d3_selection_selector(selector);
512 for (var j = -1, m = this.length; ++j < m; ) {
513 subgroups.push(subgroup = []);
514 subgroup.parentNode = (group = this[j]).parentNode;
515 for (var i = -1, n = group.length; ++i < n; ) {
516 if (node = group[i]) {
517 subgroup.push(subnode = selector.call(node, node.__data__, i, j));
518 if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
524 return d3_selection(subgroups);
526 function d3_selection_selector(selector) {
527 return typeof selector === "function" ? selector : function() {
528 return d3_select(selector, this);
531 d3_selectionPrototype.selectAll = function(selector) {
532 var subgroups = [], subgroup, node;
533 selector = d3_selection_selectorAll(selector);
534 for (var j = -1, m = this.length; ++j < m; ) {
535 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
536 if (node = group[i]) {
537 subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
538 subgroup.parentNode = node;
542 return d3_selection(subgroups);
544 function d3_selection_selectorAll(selector) {
545 return typeof selector === "function" ? selector : function() {
546 return d3_selectAll(selector, this);
550 svg: "http://www.w3.org/2000/svg",
551 xhtml: "http://www.w3.org/1999/xhtml",
552 xlink: "http://www.w3.org/1999/xlink",
553 xml: "http://www.w3.org/XML/1998/namespace",
554 xmlns: "http://www.w3.org/2000/xmlns/"
558 qualify: function(name) {
559 var i = name.indexOf(":"), prefix = name;
561 prefix = name.substring(0, i);
562 name = name.substring(i + 1);
564 return d3_nsPrefix.hasOwnProperty(prefix) ? {
565 space: d3_nsPrefix[prefix],
570 d3_selectionPrototype.attr = function(name, value) {
571 if (arguments.length < 2) {
572 if (typeof name === "string") {
573 var node = this.node();
574 name = d3.ns.qualify(name);
575 return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
577 for (value in name) this.each(d3_selection_attr(value, name[value]));
580 return this.each(d3_selection_attr(name, value));
582 function d3_selection_attr(name, value) {
583 name = d3.ns.qualify(name);
584 function attrNull() {
585 this.removeAttribute(name);
587 function attrNullNS() {
588 this.removeAttributeNS(name.space, name.local);
590 function attrConstant() {
591 this.setAttribute(name, value);
593 function attrConstantNS() {
594 this.setAttributeNS(name.space, name.local, value);
596 function attrFunction() {
597 var x = value.apply(this, arguments);
598 if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
600 function attrFunctionNS() {
601 var x = value.apply(this, arguments);
602 if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
604 return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
606 function d3_collapse(s) {
607 return s.trim().replace(/\s+/g, " ");
609 d3_selectionPrototype.classed = function(name, value) {
610 if (arguments.length < 2) {
611 if (typeof name === "string") {
612 var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
613 if (value = node.classList) {
614 while (++i < n) if (!value.contains(name[i])) return false;
616 value = node.getAttribute("class");
617 while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
621 for (value in name) this.each(d3_selection_classed(value, name[value]));
624 return this.each(d3_selection_classed(name, value));
626 function d3_selection_classedRe(name) {
627 return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
629 function d3_selection_classes(name) {
630 return name.trim().split(/^|\s+/);
632 function d3_selection_classed(name, value) {
633 name = d3_selection_classes(name).map(d3_selection_classedName);
635 function classedConstant() {
637 while (++i < n) name[i](this, value);
639 function classedFunction() {
640 var i = -1, x = value.apply(this, arguments);
641 while (++i < n) name[i](this, x);
643 return typeof value === "function" ? classedFunction : classedConstant;
645 function d3_selection_classedName(name) {
646 var re = d3_selection_classedRe(name);
647 return function(node, value) {
648 if (c = node.classList) return value ? c.add(name) : c.remove(name);
649 var c = node.getAttribute("class") || "";
652 if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
654 node.setAttribute("class", d3_collapse(c.replace(re, " ")));
658 d3_selectionPrototype.style = function(name, value, priority) {
659 var n = arguments.length;
661 if (typeof name !== "string") {
662 if (n < 2) value = "";
663 for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
666 if (n < 2) return d3_window.getComputedStyle(this.node(), null).getPropertyValue(name);
669 return this.each(d3_selection_style(name, value, priority));
671 function d3_selection_style(name, value, priority) {
672 function styleNull() {
673 this.style.removeProperty(name);
675 function styleConstant() {
676 this.style.setProperty(name, value, priority);
678 function styleFunction() {
679 var x = value.apply(this, arguments);
680 if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
682 return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
684 d3_selectionPrototype.property = function(name, value) {
685 if (arguments.length < 2) {
686 if (typeof name === "string") return this.node()[name];
687 for (value in name) this.each(d3_selection_property(value, name[value]));
690 return this.each(d3_selection_property(name, value));
692 function d3_selection_property(name, value) {
693 function propertyNull() {
696 function propertyConstant() {
699 function propertyFunction() {
700 var x = value.apply(this, arguments);
701 if (x == null) delete this[name]; else this[name] = x;
703 return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
705 d3_selectionPrototype.text = function(value) {
706 return arguments.length ? this.each(typeof value === "function" ? function() {
707 var v = value.apply(this, arguments);
708 this.textContent = v == null ? "" : v;
709 } : value == null ? function() {
710 this.textContent = "";
712 this.textContent = value;
713 }) : this.node().textContent;
715 d3_selectionPrototype.html = function(value) {
716 throw "disallowed by chromium security";
717 return arguments.length ? this.each(typeof value === "function" ? function() {
718 var v = value.apply(this, arguments);
719 this.innerHTML = v == null ? "" : v;
720 } : value == null ? function() {
723 this.innerHTML = value;
724 }) : this.node().innerHTML;
726 d3_selectionPrototype.append = function(name) {
727 name = d3_selection_creator(name);
728 return this.select(function() {
729 return this.appendChild(name.apply(this, arguments));
732 function d3_selection_creator(name) {
733 return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? function() {
734 return this.ownerDocument.createElementNS(name.space, name.local);
736 return this.ownerDocument.createElementNS(this.namespaceURI, name);
739 d3_selectionPrototype.insert = function(name, before) {
740 name = d3_selection_creator(name);
741 before = d3_selection_selector(before);
742 return this.select(function() {
743 return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
746 d3_selectionPrototype.remove = function() {
747 return this.each(function() {
748 var parent = this.parentNode;
749 if (parent) parent.removeChild(this);
752 d3_selectionPrototype.data = function(value, key) {
753 var i = -1, n = this.length, group, node;
754 if (!arguments.length) {
755 value = new Array(n = (group = this[0]).length);
757 if (node = group[i]) {
758 value[i] = node.__data__;
763 function bind(group, groupData) {
764 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;
766 var nodeByKeyValue = new d3_Map(), dataByKeyValue = new d3_Map(), keyValues = [], keyValue;
767 for (i = -1; ++i < n; ) {
768 keyValue = key.call(node = group[i], node.__data__, i);
769 if (nodeByKeyValue.has(keyValue)) {
772 nodeByKeyValue.set(keyValue, node);
774 keyValues.push(keyValue);
776 for (i = -1; ++i < m; ) {
777 keyValue = key.call(groupData, nodeData = groupData[i], i);
778 if (node = nodeByKeyValue.get(keyValue)) {
779 updateNodes[i] = node;
780 node.__data__ = nodeData;
781 } else if (!dataByKeyValue.has(keyValue)) {
782 enterNodes[i] = d3_selection_dataNode(nodeData);
784 dataByKeyValue.set(keyValue, nodeData);
785 nodeByKeyValue.remove(keyValue);
787 for (i = -1; ++i < n; ) {
788 if (nodeByKeyValue.has(keyValues[i])) {
789 exitNodes[i] = group[i];
793 for (i = -1; ++i < n0; ) {
795 nodeData = groupData[i];
797 node.__data__ = nodeData;
798 updateNodes[i] = node;
800 enterNodes[i] = d3_selection_dataNode(nodeData);
804 enterNodes[i] = d3_selection_dataNode(groupData[i]);
807 exitNodes[i] = group[i];
810 enterNodes.update = updateNodes;
811 enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
812 enter.push(enterNodes);
813 update.push(updateNodes);
814 exit.push(exitNodes);
816 var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
817 if (typeof value === "function") {
819 bind(group = this[i], value.call(group, group.parentNode.__data__, i));
823 bind(group = this[i], value);
826 update.enter = function() {
829 update.exit = function() {
834 function d3_selection_dataNode(data) {
839 d3_selectionPrototype.datum = function(value) {
840 return arguments.length ? this.property("__data__", value) : this.property("__data__");
842 d3_selectionPrototype.filter = function(filter) {
843 var subgroups = [], subgroup, group, node;
844 if (typeof filter !== "function") filter = d3_selection_filter(filter);
845 for (var j = 0, m = this.length; j < m; j++) {
846 subgroups.push(subgroup = []);
847 subgroup.parentNode = (group = this[j]).parentNode;
848 for (var i = 0, n = group.length; i < n; i++) {
849 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
854 return d3_selection(subgroups);
856 function d3_selection_filter(selector) {
858 return d3_selectMatches(this, selector);
861 d3_selectionPrototype.order = function() {
862 for (var j = -1, m = this.length; ++j < m; ) {
863 for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
864 if (node = group[i]) {
865 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
872 d3_selectionPrototype.sort = function(comparator) {
873 comparator = d3_selection_sortComparator.apply(this, arguments);
874 for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
877 function d3_selection_sortComparator(comparator) {
878 if (!arguments.length) comparator = d3_ascending;
879 return function(a, b) {
880 return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
883 d3_selectionPrototype.each = function(callback) {
884 return d3_selection_each(this, function(node, i, j) {
885 callback.call(node, node.__data__, i, j);
888 function d3_selection_each(groups, callback) {
889 for (var j = 0, m = groups.length; j < m; j++) {
890 for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
891 if (node = group[i]) callback(node, i, j);
896 d3_selectionPrototype.call = function(callback) {
897 var args = d3_array(arguments);
898 callback.apply(args[0] = this, args);
901 d3_selectionPrototype.empty = function() {
904 d3_selectionPrototype.node = function() {
905 for (var j = 0, m = this.length; j < m; j++) {
906 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
908 if (node) return node;
913 d3_selectionPrototype.size = function() {
915 this.each(function() {
920 function d3_selection_enter(selection) {
921 d3_subclass(selection, d3_selection_enterPrototype);
924 var d3_selection_enterPrototype = [];
925 d3.selection.enter = d3_selection_enter;
926 d3.selection.enter.prototype = d3_selection_enterPrototype;
927 d3_selection_enterPrototype.append = d3_selectionPrototype.append;
928 d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
929 d3_selection_enterPrototype.node = d3_selectionPrototype.node;
930 d3_selection_enterPrototype.call = d3_selectionPrototype.call;
931 d3_selection_enterPrototype.size = d3_selectionPrototype.size;
932 d3_selection_enterPrototype.select = function(selector) {
933 var subgroups = [], subgroup, subnode, upgroup, group, node;
934 for (var j = -1, m = this.length; ++j < m; ) {
935 upgroup = (group = this[j]).update;
936 subgroups.push(subgroup = []);
937 subgroup.parentNode = group.parentNode;
938 for (var i = -1, n = group.length; ++i < n; ) {
939 if (node = group[i]) {
940 subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
941 subnode.__data__ = node.__data__;
947 return d3_selection(subgroups);
949 d3_selection_enterPrototype.insert = function(name, before) {
950 if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
951 return d3_selectionPrototype.insert.call(this, name, before);
953 function d3_selection_enterInsertBefore(enter) {
955 return function(d, i, j) {
956 var group = enter[j].update, n = group.length, node;
957 if (j != j0) j0 = j, i0 = 0;
958 if (i >= i0) i0 = i + 1;
959 while (!(node = group[i0]) && ++i0 < n) ;
963 d3_selectionPrototype.transition = function() {
964 var id = d3_transitionInheritId || ++d3_transitionId, subgroups = [], subgroup, node, transition = d3_transitionInherit || {
966 ease: d3_ease_cubicInOut,
970 for (var j = -1, m = this.length; ++j < m; ) {
971 subgroups.push(subgroup = []);
972 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
973 if (node = group[i]) d3_transitionNode(node, i, id, transition);
977 return d3_transition(subgroups, id);
979 d3_selectionPrototype.interrupt = function() {
980 return this.each(d3_selection_interrupt);
982 function d3_selection_interrupt() {
983 var lock = this.__transition__;
984 if (lock) ++lock.active;
986 d3.select = function(node) {
987 var group = [ typeof node === "string" ? d3_select(node, d3_document) : node ];
988 group.parentNode = d3_documentElement;
989 return d3_selection([ group ]);
991 d3.selectAll = function(nodes) {
992 var group = d3_array(typeof nodes === "string" ? d3_selectAll(nodes, d3_document) : nodes);
993 group.parentNode = d3_documentElement;
994 return d3_selection([ group ]);
996 var d3_selectionRoot = d3.select(d3_documentElement);
997 d3_selectionPrototype.on = function(type, listener, capture) {
998 var n = arguments.length;
1000 if (typeof type !== "string") {
1001 if (n < 2) listener = false;
1002 for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
1005 if (n < 2) return (n = this.node()["__on" + type]) && n._;
1008 return this.each(d3_selection_on(type, listener, capture));
1010 function d3_selection_on(type, listener, capture) {
1011 var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
1012 if (i > 0) type = type.substring(0, i);
1013 var filter = d3_selection_onFilters.get(type);
1014 if (filter) type = filter, wrap = d3_selection_onFilter;
1015 function onRemove() {
1018 this.removeEventListener(type, l, l.$);
1023 var l = wrap(listener, d3_array(arguments));
1024 onRemove.call(this);
1025 this.addEventListener(type, this[name] = l, l.$ = capture);
1028 function removeAll() {
1029 var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
1030 for (var name in this) {
1031 if (match = name.match(re)) {
1033 this.removeEventListener(match[1], l, l.$);
1038 return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
1040 var d3_selection_onFilters = d3.map({
1041 mouseenter: "mouseover",
1042 mouseleave: "mouseout"
1044 d3_selection_onFilters.forEach(function(k) {
1045 if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
1047 function d3_selection_onListener(listener, argumentz) {
1048 return function(e) {
1051 argumentz[0] = this.__data__;
1053 listener.apply(this, argumentz);
1059 function d3_selection_onFilter(listener, argumentz) {
1060 var l = d3_selection_onListener(listener, argumentz);
1061 return function(e) {
1062 var target = this, related = e.relatedTarget;
1063 if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
1068 var d3_event_dragSelect = "onselectstart" in d3_document ? null : d3_vendorSymbol(d3_documentElement.style, "userSelect"), d3_event_dragId = 0;
1069 function d3_event_dragSuppress() {
1070 var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
1071 if (d3_event_dragSelect) {
1072 var style = d3_documentElement.style, select = style[d3_event_dragSelect];
1073 style[d3_event_dragSelect] = "none";
1075 return function(suppressClick) {
1077 if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
1078 if (suppressClick) {
1082 w.on(click, function() {
1083 d3_eventPreventDefault();
1090 d3.mouse = function(container) {
1091 return d3_mousePoint(container, d3_eventSource());
1093 function d3_mousePoint(container, e) {
1094 if (e.changedTouches) e = e.changedTouches[0];
1095 var svg = container.ownerSVGElement || container;
1096 if (svg.createSVGPoint) {
1097 var point = svg.createSVGPoint();
1098 point.x = e.clientX, point.y = e.clientY;
1099 point = point.matrixTransform(container.getScreenCTM().inverse());
1100 return [ point.x, point.y ];
1102 var rect = container.getBoundingClientRect();
1103 return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
1105 d3.touches = function(container, touches) {
1106 if (arguments.length < 2) touches = d3_eventSource().touches;
1107 return touches ? d3_array(touches).map(function(touch) {
1108 var point = d3_mousePoint(container, touch);
1109 point.identifier = touch.identifier;
1113 d3.behavior.drag = function() {
1114 var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_behavior_dragMouseSubject, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_behavior_dragTouchSubject, "touchmove", "touchend");
1116 this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
1118 function dragstart(id, position, subject, move, end) {
1120 var that = this, target = d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject()).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(), position0 = position(parent, dragId);
1122 dragOffset = origin.apply(that, arguments);
1123 dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
1125 dragOffset = [ 0, 0 ];
1131 var position1 = position(parent, dragId), dx, dy;
1132 if (!position1) return;
1133 dx = position1[0] - position0[0];
1134 dy = position1[1] - position0[1];
1136 position0 = position1;
1139 x: position1[0] + dragOffset[0],
1140 y: position1[1] + dragOffset[1],
1146 if (!position(parent, dragId)) return;
1147 dragSubject.on(move + dragName, null).on(end + dragName, null);
1148 dragRestore(dragged && d3.event.target === target);
1155 drag.origin = function(x) {
1156 if (!arguments.length) return origin;
1160 return d3.rebind(drag, event, "on");
1162 function d3_behavior_dragTouchId() {
1163 return d3.event.changedTouches[0].identifier;
1165 function d3_behavior_dragTouchSubject() {
1166 return d3.event.target;
1168 function d3_behavior_dragMouseSubject() {
1171 var π = Math.PI, τ = 2 * π, halfπ = π / 2, ε = 1e-6, ε2 = ε * ε, d3_radians = π / 180, d3_degrees = 180 / π;
1172 function d3_sgn(x) {
1173 return x > 0 ? 1 : x < 0 ? -1 : 0;
1175 function d3_cross2d(a, b, c) {
1176 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
1178 function d3_acos(x) {
1179 return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
1181 function d3_asin(x) {
1182 return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
1184 function d3_sinh(x) {
1185 return ((x = Math.exp(x)) - 1 / x) / 2;
1187 function d3_cosh(x) {
1188 return ((x = Math.exp(x)) + 1 / x) / 2;
1190 function d3_tanh(x) {
1191 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
1193 function d3_haversin(x) {
1194 return (x = Math.sin(x / 2)) * x;
1196 var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
1197 d3.interpolateZoom = function(p0, p1) {
1198 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2];
1199 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)) / ρ;
1200 function interpolate(t) {
1203 var coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
1204 return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
1206 return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * s) ];
1208 interpolate.duration = S * 1e3;
1211 d3.behavior.zoom = function() {
1216 }, translate0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
1218 g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on(mousemove, mousewheelreset).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
1220 zoom.event = function(g) {
1222 var dispatch = event.of(this, arguments), view1 = view;
1223 if (d3_transitionInheritId) {
1224 d3.select(this).transition().each("start.zoom", function() {
1225 view = this.__chart__ || {
1230 zoomstarted(dispatch);
1231 }).tween("zoom:zoom", function() {
1232 var dx = size[0], dy = size[1], cx = dx / 2, cy = dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]);
1233 return function(t) {
1234 var l = i(t), k = dx / l[2];
1235 this.__chart__ = view = {
1242 }).each("end.zoom", function() {
1243 zoomended(dispatch);
1246 this.__chart__ = view;
1247 zoomstarted(dispatch);
1249 zoomended(dispatch);
1253 zoom.translate = function(_) {
1254 if (!arguments.length) return [ view.x, view.y ];
1263 zoom.scale = function(_) {
1264 if (!arguments.length) return view.k;
1273 zoom.scaleExtent = function(_) {
1274 if (!arguments.length) return scaleExtent;
1275 scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
1278 zoom.center = function(_) {
1279 if (!arguments.length) return center;
1280 center = _ && [ +_[0], +_[1] ];
1283 zoom.size = function(_) {
1284 if (!arguments.length) return size;
1285 size = _ && [ +_[0], +_[1] ];
1288 zoom.x = function(z) {
1289 if (!arguments.length) return x1;
1299 zoom.y = function(z) {
1300 if (!arguments.length) return y1;
1310 function location(p) {
1311 return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
1314 return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
1316 function scaleTo(s) {
1317 view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
1319 function translateTo(p, l) {
1321 view.x += p[0] - l[0];
1322 view.y += p[1] - l[1];
1324 function rescale() {
1325 if (x1) x1.domain(x0.range().map(function(x) {
1326 return (x - view.x) / view.k;
1328 if (y1) y1.domain(y0.range().map(function(y) {
1329 return (y - view.y) / view.k;
1332 function zoomstarted(dispatch) {
1337 function zoomed(dispatch) {
1342 translate: [ view.x, view.y ]
1345 function zoomended(dispatch) {
1350 function mousedowned() {
1351 var that = this, target = d3.event.target, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress();
1352 d3_selection_interrupt.call(that);
1353 zoomstarted(dispatch);
1356 translateTo(d3.mouse(that), location0);
1360 subject.on(mousemove, d3_window === that ? mousewheelreset : null).on(mouseup, null);
1361 dragRestore(dragged && d3.event.target === target);
1362 zoomended(dispatch);
1365 function touchstarted() {
1366 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, target = d3.select(d3.event.target).on(touchmove, moved).on(touchend, ended), subject = d3.select(that).on(mousedown, null).on(touchstart, started), dragRestore = d3_event_dragSuppress();
1367 d3_selection_interrupt.call(that);
1369 zoomstarted(dispatch);
1370 function relocate() {
1371 var touches = d3.touches(that);
1373 touches.forEach(function(t) {
1374 if (t.identifier in locations0) locations0[t.identifier] = location(t);
1378 function started() {
1379 var changed = d3.event.changedTouches;
1380 for (var i = 0, n = changed.length; i < n; ++i) {
1381 locations0[changed[i].identifier] = null;
1383 var touches = relocate(), now = Date.now();
1384 if (touches.length === 1) {
1385 if (now - touchtime < 500) {
1386 var p = touches[0], l = locations0[p.identifier];
1387 scaleTo(view.k * 2);
1389 d3_eventPreventDefault();
1393 } else if (touches.length > 1) {
1394 var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
1395 distance0 = dx * dx + dy * dy;
1399 var touches = d3.touches(that), p0, l0, p1, l1;
1400 for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
1402 if (l1 = locations0[p1.identifier]) {
1408 var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
1409 p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
1410 l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
1411 scaleTo(scale1 * scale0);
1414 translateTo(p0, l0);
1418 if (d3.event.touches.length) {
1419 var changed = d3.event.changedTouches;
1420 for (var i = 0, n = changed.length; i < n; ++i) {
1421 delete locations0[changed[i].identifier];
1423 for (var identifier in locations0) {
1424 return void relocate();
1427 target.on(zoomName, null);
1428 subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
1430 zoomended(dispatch);
1433 function mousewheeled() {
1434 var dispatch = event.of(this, arguments);
1435 if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
1436 zoomstarted(dispatch);
1437 mousewheelTimer = setTimeout(function() {
1438 mousewheelTimer = null;
1439 zoomended(dispatch);
1441 d3_eventPreventDefault();
1442 var point = center || d3.mouse(this);
1443 if (!translate0) translate0 = location(point);
1444 scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
1445 translateTo(point, translate0);
1448 function mousewheelreset() {
1451 function dblclicked() {
1452 var dispatch = event.of(this, arguments), p = d3.mouse(this), l = location(p), k = Math.log(view.k) / Math.LN2;
1453 zoomstarted(dispatch);
1454 scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1));
1457 zoomended(dispatch);
1459 return d3.rebind(zoom, event, "on");
1461 var d3_behavior_zoomInfinity = [ 0, Infinity ];
1462 var d3_behavior_zoomDelta, d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
1463 return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
1464 }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
1465 return d3.event.wheelDelta;
1466 }, "mousewheel") : (d3_behavior_zoomDelta = function() {
1467 return -d3.event.detail;
1468 }, "MozMousePixelScroll");
1469 function d3_Color() {}
1470 d3_Color.prototype.toString = function() {
1471 return this.rgb() + "";
1473 d3.hsl = function(h, s, l) {
1474 return arguments.length === 1 ? h instanceof d3_Hsl ? d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : d3_hsl(+h, +s, +l);
1476 function d3_hsl(h, s, l) {
1477 return new d3_Hsl(h, s, l);
1479 function d3_Hsl(h, s, l) {
1484 var d3_hslPrototype = d3_Hsl.prototype = new d3_Color();
1485 d3_hslPrototype.brighter = function(k) {
1486 k = Math.pow(.7, arguments.length ? k : 1);
1487 return d3_hsl(this.h, this.s, this.l / k);
1489 d3_hslPrototype.darker = function(k) {
1490 k = Math.pow(.7, arguments.length ? k : 1);
1491 return d3_hsl(this.h, this.s, k * this.l);
1493 d3_hslPrototype.rgb = function() {
1494 return d3_hsl_rgb(this.h, this.s, this.l);
1496 function d3_hsl_rgb(h, s, l) {
1498 h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
1499 s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
1500 l = l < 0 ? 0 : l > 1 ? 1 : l;
1501 m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
1504 if (h > 360) h -= 360; else if (h < 0) h += 360;
1505 if (h < 60) return m1 + (m2 - m1) * h / 60;
1506 if (h < 180) return m2;
1507 if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
1511 return Math.round(v(h) * 255);
1513 return d3_rgb(vv(h + 120), vv(h), vv(h - 120));
1515 d3.hcl = function(h, c, l) {
1516 return arguments.length === 1 ? h instanceof d3_Hcl ? 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) : d3_hcl(+h, +c, +l);
1518 function d3_hcl(h, c, l) {
1519 return new d3_Hcl(h, c, l);
1521 function d3_Hcl(h, c, l) {
1526 var d3_hclPrototype = d3_Hcl.prototype = new d3_Color();
1527 d3_hclPrototype.brighter = function(k) {
1528 return d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
1530 d3_hclPrototype.darker = function(k) {
1531 return d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
1533 d3_hclPrototype.rgb = function() {
1534 return d3_hcl_lab(this.h, this.c, this.l).rgb();
1536 function d3_hcl_lab(h, c, l) {
1537 if (isNaN(h)) h = 0;
1538 if (isNaN(c)) c = 0;
1539 return d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
1541 d3.lab = function(l, a, b) {
1542 return arguments.length === 1 ? l instanceof d3_Lab ? d3_lab(l.l, l.a, l.b) : l instanceof d3_Hcl ? d3_hcl_lab(l.l, l.c, l.h) : d3_rgb_lab((l = d3.rgb(l)).r, l.g, l.b) : d3_lab(+l, +a, +b);
1544 function d3_lab(l, a, b) {
1545 return new d3_Lab(l, a, b);
1547 function d3_Lab(l, a, b) {
1553 var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
1554 var d3_labPrototype = d3_Lab.prototype = new d3_Color();
1555 d3_labPrototype.brighter = function(k) {
1556 return d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1558 d3_labPrototype.darker = function(k) {
1559 return d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1561 d3_labPrototype.rgb = function() {
1562 return d3_lab_rgb(this.l, this.a, this.b);
1564 function d3_lab_rgb(l, a, b) {
1565 var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
1566 x = d3_lab_xyz(x) * d3_lab_X;
1567 y = d3_lab_xyz(y) * d3_lab_Y;
1568 z = d3_lab_xyz(z) * d3_lab_Z;
1569 return 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));
1571 function d3_lab_hcl(l, a, b) {
1572 return l > 0 ? d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : d3_hcl(NaN, NaN, l);
1574 function d3_lab_xyz(x) {
1575 return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
1577 function d3_xyz_lab(x) {
1578 return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
1580 function d3_xyz_rgb(r) {
1581 return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
1583 d3.rgb = function(r, g, b) {
1584 return arguments.length === 1 ? r instanceof d3_Rgb ? d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : d3_rgb(~~r, ~~g, ~~b);
1586 function d3_rgbNumber(value) {
1587 return d3_rgb(value >> 16, value >> 8 & 255, value & 255);
1589 function d3_rgbString(value) {
1590 return d3_rgbNumber(value) + "";
1592 function d3_rgb(r, g, b) {
1593 return new d3_Rgb(r, g, b);
1595 function d3_Rgb(r, g, b) {
1600 var d3_rgbPrototype = d3_Rgb.prototype = new d3_Color();
1601 d3_rgbPrototype.brighter = function(k) {
1602 k = Math.pow(.7, arguments.length ? k : 1);
1603 var r = this.r, g = this.g, b = this.b, i = 30;
1604 if (!r && !g && !b) return d3_rgb(i, i, i);
1605 if (r && r < i) r = i;
1606 if (g && g < i) g = i;
1607 if (b && b < i) b = i;
1608 return d3_rgb(Math.min(255, ~~(r / k)), Math.min(255, ~~(g / k)), Math.min(255, ~~(b / k)));
1610 d3_rgbPrototype.darker = function(k) {
1611 k = Math.pow(.7, arguments.length ? k : 1);
1612 return d3_rgb(~~(k * this.r), ~~(k * this.g), ~~(k * this.b));
1614 d3_rgbPrototype.hsl = function() {
1615 return d3_rgb_hsl(this.r, this.g, this.b);
1617 d3_rgbPrototype.toString = function() {
1618 return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
1620 function d3_rgb_hex(v) {
1621 return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
1623 function d3_rgb_parse(format, rgb, hsl) {
1624 var r = 0, g = 0, b = 0, m1, m2, color;
1625 m1 = /([a-z]+)\((.*)\)/i.exec(format);
1627 m2 = m1[2].split(",");
1631 return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
1636 return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
1640 if (color = d3_rgb_names.get(format)) return rgb(color.r, color.g, color.b);
1641 if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.substring(1), 16))) {
1642 if (format.length === 4) {
1643 r = (color & 3840) >> 4;
1649 } else if (format.length === 7) {
1650 r = (color & 16711680) >> 16;
1651 g = (color & 65280) >> 8;
1655 return rgb(r, g, b);
1657 function d3_rgb_hsl(r, g, b) {
1658 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;
1660 s = l < .5 ? d / (max + min) : d / (2 - max - min);
1661 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;
1665 s = l > 0 && l < 1 ? 0 : h;
1667 return d3_hsl(h, s, l);
1669 function d3_rgb_lab(r, g, b) {
1673 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);
1674 return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
1676 function d3_rgb_xyz(r) {
1677 return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
1679 function d3_rgb_parseNumber(c) {
1680 var f = parseFloat(c);
1681 return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
1683 var d3_rgb_names = d3.map({
1684 aliceblue: 15792383,
1685 antiquewhite: 16444375,
1687 aquamarine: 8388564,
1692 blanchedalmond: 16772045,
1694 blueviolet: 9055202,
1696 burlywood: 14596231,
1698 chartreuse: 8388352,
1699 chocolate: 13789470,
1701 cornflowerblue: 6591981,
1707 darkgoldenrod: 12092939,
1711 darkkhaki: 12433259,
1712 darkmagenta: 9109643,
1713 darkolivegreen: 5597999,
1714 darkorange: 16747520,
1715 darkorchid: 10040012,
1717 darksalmon: 15308410,
1718 darkseagreen: 9419919,
1719 darkslateblue: 4734347,
1720 darkslategray: 3100495,
1721 darkslategrey: 3100495,
1722 darkturquoise: 52945,
1723 darkviolet: 9699539,
1728 dodgerblue: 2003199,
1729 firebrick: 11674146,
1730 floralwhite: 16775920,
1731 forestgreen: 2263842,
1733 gainsboro: 14474460,
1734 ghostwhite: 16316671,
1736 goldenrod: 14329120,
1739 greenyellow: 11403055,
1743 indianred: 13458524,
1748 lavenderblush: 16773365,
1750 lemonchiffon: 16775885,
1751 lightblue: 11393254,
1752 lightcoral: 15761536,
1753 lightcyan: 14745599,
1754 lightgoldenrodyellow: 16448210,
1755 lightgray: 13882323,
1756 lightgreen: 9498256,
1757 lightgrey: 13882323,
1758 lightpink: 16758465,
1759 lightsalmon: 16752762,
1760 lightseagreen: 2142890,
1761 lightskyblue: 8900346,
1762 lightslategray: 7833753,
1763 lightslategrey: 7833753,
1764 lightsteelblue: 11584734,
1765 lightyellow: 16777184,
1771 mediumaquamarine: 6737322,
1773 mediumorchid: 12211667,
1774 mediumpurple: 9662683,
1775 mediumseagreen: 3978097,
1776 mediumslateblue: 8087790,
1777 mediumspringgreen: 64154,
1778 mediumturquoise: 4772300,
1779 mediumvioletred: 13047173,
1780 midnightblue: 1644912,
1781 mintcream: 16121850,
1782 mistyrose: 16770273,
1784 navajowhite: 16768685,
1790 orangered: 16729344,
1792 palegoldenrod: 15657130,
1793 palegreen: 10025880,
1794 paleturquoise: 11529966,
1795 palevioletred: 14381203,
1796 papayawhip: 16773077,
1797 peachpuff: 16767673,
1801 powderblue: 11591910,
1804 rosybrown: 12357519,
1806 saddlebrown: 9127187,
1808 sandybrown: 16032864,
1828 whitesmoke: 16119285,
1830 yellowgreen: 10145074
1832 d3_rgb_names.forEach(function(key, value) {
1833 d3_rgb_names.set(key, d3_rgbNumber(value));
1835 function d3_functor(v) {
1836 return typeof v === "function" ? v : function() {
1840 d3.functor = d3_functor;
1841 function d3_identity(d) {
1844 d3.xhr = d3_xhrType(d3_identity);
1845 function d3_xhrType(response) {
1846 return function(url, mimeType, callback) {
1847 if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
1849 return d3_xhr(url, mimeType, response, callback);
1852 function d3_xhr(url, mimeType, response, callback) {
1853 var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
1854 if (d3_window.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
1855 "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
1856 request.readyState > 3 && respond();
1858 function respond() {
1859 var status = request.status, result;
1860 if (!status && request.responseText || status >= 200 && status < 300 || status === 304) {
1862 result = response.call(xhr, request);
1864 dispatch.error.call(xhr, e);
1867 dispatch.load.call(xhr, result);
1869 dispatch.error.call(xhr, request);
1872 request.onprogress = function(event) {
1876 dispatch.progress.call(xhr, request);
1881 xhr.header = function(name, value) {
1882 name = (name + "").toLowerCase();
1883 if (arguments.length < 2) return headers[name];
1884 if (value == null) delete headers[name]; else headers[name] = value + "";
1887 xhr.mimeType = function(value) {
1888 if (!arguments.length) return mimeType;
1889 mimeType = value == null ? null : value + "";
1892 xhr.responseType = function(value) {
1893 if (!arguments.length) return responseType;
1894 responseType = value;
1897 xhr.response = function(value) {
1901 [ "get", "post" ].forEach(function(method) {
1902 xhr[method] = function() {
1903 return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
1906 xhr.send = function(method, data, callback) {
1907 if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
1908 request.open(method, url, true);
1909 if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
1910 if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
1911 if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
1912 if (responseType != null) request.responseType = responseType;
1913 if (callback != null) xhr.on("error", callback).on("load", function(request) {
1914 callback(null, request);
1916 dispatch.beforesend.call(xhr, request);
1917 request.send(data == null ? null : data);
1920 xhr.abort = function() {
1924 d3.rebind(xhr, dispatch, "on");
1925 return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
1927 function d3_xhr_fixCallback(callback) {
1928 return callback.length === 1 ? function(error, request) {
1929 callback(error == null ? request : null);
1932 d3.dsv = function(delimiter, mimeType) {
1933 var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
1934 function dsv(url, row, callback) {
1935 if (arguments.length < 3) callback = row, row = null;
1936 var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
1937 xhr.row = function(_) {
1938 return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
1942 function response(request) {
1943 return dsv.parse(request.responseText);
1945 function typedResponse(f) {
1946 return function(request) {
1947 return dsv.parse(request.responseText, f);
1950 dsv.parse = function(text, f) {
1952 return dsv.parseRows(text, function(row, i) {
1953 if (o) return o(row, i - 1);
1954 var a = new Function("d", "return {" + row.map(function(name, i) {
1955 return JSON.stringify(name) + ": d[" + i + "]";
1956 }).join(",") + "}");
1957 o = f ? function(row, i) {
1958 return f(a(row), i);
1962 dsv.parseRows = function(text, f) {
1963 var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
1965 if (I >= N) return EOF;
1966 if (eol) return eol = false, EOL;
1968 if (text.charCodeAt(j) === 34) {
1971 if (text.charCodeAt(i) === 34) {
1972 if (text.charCodeAt(i + 1) !== 34) break;
1977 var c = text.charCodeAt(i + 1);
1980 if (text.charCodeAt(i + 2) === 10) ++I;
1981 } else if (c === 10) {
1984 return text.substring(j + 1, i).replace(/""/g, '"');
1987 var c = text.charCodeAt(I++), k = 1;
1988 if (c === 10) eol = true; else if (c === 13) {
1990 if (text.charCodeAt(I) === 10) ++I, ++k;
1991 } else if (c !== delimiterCode) continue;
1992 return text.substring(j, I - k);
1994 return text.substring(j);
1996 while ((t = token()) !== EOF) {
1998 while (t !== EOL && t !== EOF) {
2002 if (f && !(a = f(a, n++))) continue;
2007 dsv.format = function(rows) {
2008 if (Array.isArray(rows[0])) return dsv.formatRows(rows);
2009 var fieldSet = new d3_Set(), fields = [];
2010 rows.forEach(function(row) {
2011 for (var field in row) {
2012 if (!fieldSet.has(field)) {
2013 fields.push(fieldSet.add(field));
2017 return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
2018 return fields.map(function(field) {
2019 return formatValue(row[field]);
2023 dsv.formatRows = function(rows) {
2024 return rows.map(formatRow).join("\n");
2026 function formatRow(row) {
2027 return row.map(formatValue).join(delimiter);
2029 function formatValue(text) {
2030 return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
2034 d3.csv = d3.dsv(",", "text/csv");
2035 d3.tsv = d3.dsv(" ", "text/tab-separated-values");
2036 d3.touch = function(container, touches, identifier) {
2037 if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
2038 if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
2039 if ((touch = touches[i]).identifier === identifier) {
2040 return d3_mousePoint(container, touch);
2044 var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_active, d3_timer_frame = d3_window[d3_vendorSymbol(d3_window, "requestAnimationFrame")] || function(callback) {
2045 setTimeout(callback, 17);
2047 d3.timer = function(callback, delay, then) {
2048 var n = arguments.length;
2049 if (n < 2) delay = 0;
2050 if (n < 3) then = Date.now();
2051 var time = then + delay, timer = {
2057 if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
2058 d3_timer_queueTail = timer;
2059 if (!d3_timer_interval) {
2060 d3_timer_timeout = clearTimeout(d3_timer_timeout);
2061 d3_timer_interval = 1;
2062 d3_timer_frame(d3_timer_step);
2065 function d3_timer_step() {
2066 var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
2068 if (isFinite(delay)) {
2069 clearTimeout(d3_timer_timeout);
2070 d3_timer_timeout = setTimeout(d3_timer_step, delay);
2072 d3_timer_interval = 0;
2074 d3_timer_interval = 1;
2075 d3_timer_frame(d3_timer_step);
2078 d3.timer.flush = function() {
2082 function d3_timer_mark() {
2083 var now = Date.now();
2084 d3_timer_active = d3_timer_queueHead;
2085 while (d3_timer_active) {
2086 if (now >= d3_timer_active.t) d3_timer_active.f = d3_timer_active.c(now - d3_timer_active.t);
2087 d3_timer_active = d3_timer_active.n;
2091 function d3_timer_sweep() {
2092 var t0, t1 = d3_timer_queueHead, time = Infinity;
2095 t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
2097 if (t1.t < time) time = t1.t;
2101 d3_timer_queueTail = t0;
2104 function d3_format_precision(x, p) {
2105 return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
2107 d3.round = function(x, n) {
2108 return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
2110 var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
2111 d3.formatPrefix = function(value, precision) {
2114 if (value < 0) value *= -1;
2115 if (precision) value = d3.round(value, d3_format_precision(value, precision));
2116 i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
2117 i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
2119 return d3_formatPrefixes[8 + i / 3];
2121 function d3_formatPrefix(d, i) {
2122 var k = Math.pow(10, abs(8 - i) * 3);
2124 scale: i > 8 ? function(d) {
2132 function d3_locale_numberFormat(locale) {
2133 var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping ? function(value) {
2134 var i = value.length, t = [], j = 0, g = locale_grouping[0];
2135 while (i > 0 && g > 0) {
2136 t.push(value.substring(i -= g, i + g));
2137 g = locale_grouping[j = (j + 1) % locale_grouping.length];
2139 return t.reverse().join(locale_thousands);
2141 return function(specifier) {
2142 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;
2143 if (precision) precision = +precision.substring(1);
2144 if (zfill || fill === "0" && align === "=") {
2147 if (comma) width -= Math.floor((width - 1) / 4);
2171 if (symbol === "#") prefix = "0" + type.toLowerCase();
2184 if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
2185 if (type == "r" && !precision) type = "g";
2186 if (precision != null) {
2187 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));
2189 type = d3_format_types.get(type) || d3_format_typeDefault;
2190 var zcomma = zfill && comma;
2191 return function(value) {
2192 var fullSuffix = suffix;
2193 if (integer && value % 1) return "";
2194 var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign;
2196 var unit = d3.formatPrefix(value, precision);
2197 value = unit.scale(value);
2198 fullSuffix = unit.symbol + suffix;
2202 value = type(value, precision);
2203 var i = value.lastIndexOf("."), before = i < 0 ? value : value.substring(0, i), after = i < 0 ? "" : locale_decimal + value.substring(i + 1);
2204 if (!zfill && comma) before = formatGroup(before);
2205 var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
2206 if (zcomma) before = formatGroup(padding + before);
2208 value = before + after;
2209 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;
2213 var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
2214 var d3_format_types = d3.map({
2216 return x.toString(2);
2219 return String.fromCharCode(x);
2222 return x.toString(8);
2225 return x.toString(16);
2228 return x.toString(16).toUpperCase();
2231 return x.toPrecision(p);
2234 return x.toExponential(p);
2237 return x.toFixed(p);
2240 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))));
2243 function d3_format_typeDefault(x) {
2246 var d3_time = d3.time = {}, d3_date = Date;
2247 function d3_date_utc() {
2248 this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
2250 d3_date_utc.prototype = {
2251 getDate: function() {
2252 return this._.getUTCDate();
2254 getDay: function() {
2255 return this._.getUTCDay();
2257 getFullYear: function() {
2258 return this._.getUTCFullYear();
2260 getHours: function() {
2261 return this._.getUTCHours();
2263 getMilliseconds: function() {
2264 return this._.getUTCMilliseconds();
2266 getMinutes: function() {
2267 return this._.getUTCMinutes();
2269 getMonth: function() {
2270 return this._.getUTCMonth();
2272 getSeconds: function() {
2273 return this._.getUTCSeconds();
2275 getTime: function() {
2276 return this._.getTime();
2278 getTimezoneOffset: function() {
2281 valueOf: function() {
2282 return this._.valueOf();
2284 setDate: function() {
2285 d3_time_prototype.setUTCDate.apply(this._, arguments);
2287 setDay: function() {
2288 d3_time_prototype.setUTCDay.apply(this._, arguments);
2290 setFullYear: function() {
2291 d3_time_prototype.setUTCFullYear.apply(this._, arguments);
2293 setHours: function() {
2294 d3_time_prototype.setUTCHours.apply(this._, arguments);
2296 setMilliseconds: function() {
2297 d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
2299 setMinutes: function() {
2300 d3_time_prototype.setUTCMinutes.apply(this._, arguments);
2302 setMonth: function() {
2303 d3_time_prototype.setUTCMonth.apply(this._, arguments);
2305 setSeconds: function() {
2306 d3_time_prototype.setUTCSeconds.apply(this._, arguments);
2308 setTime: function() {
2309 d3_time_prototype.setTime.apply(this._, arguments);
2312 var d3_time_prototype = Date.prototype;
2313 function d3_time_interval(local, step, number) {
2314 function round(date) {
2315 var d0 = local(date), d1 = offset(d0, 1);
2316 return date - d0 < d1 - date ? d0 : d1;
2318 function ceil(date) {
2319 step(date = local(new d3_date(date - 1)), 1);
2322 function offset(date, k) {
2323 step(date = new d3_date(+date), k);
2326 function range(t0, t1, dt) {
2327 var time = ceil(t0), times = [];
2330 if (!(number(time) % dt)) times.push(new Date(+time));
2334 while (time < t1) times.push(new Date(+time)), step(time, 1);
2338 function range_utc(t0, t1, dt) {
2340 d3_date = d3_date_utc;
2341 var utc = new d3_date_utc();
2343 return range(utc, t1, dt);
2348 local.floor = local;
2349 local.round = round;
2351 local.offset = offset;
2352 local.range = range;
2353 var utc = local.utc = d3_time_interval_utc(local);
2355 utc.round = d3_time_interval_utc(round);
2356 utc.ceil = d3_time_interval_utc(ceil);
2357 utc.offset = d3_time_interval_utc(offset);
2358 utc.range = range_utc;
2361 function d3_time_interval_utc(method) {
2362 return function(date, k) {
2364 d3_date = d3_date_utc;
2365 var utc = new d3_date_utc();
2367 return method(utc, k)._;
2373 d3_time.year = d3_time_interval(function(date) {
2374 date = d3_time.day(date);
2375 date.setMonth(0, 1);
2377 }, function(date, offset) {
2378 date.setFullYear(date.getFullYear() + offset);
2380 return date.getFullYear();
2382 d3_time.years = d3_time.year.range;
2383 d3_time.years.utc = d3_time.year.utc.range;
2384 d3_time.day = d3_time_interval(function(date) {
2385 var day = new d3_date(2e3, 0);
2386 day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
2388 }, function(date, offset) {
2389 date.setDate(date.getDate() + offset);
2391 return date.getDate() - 1;
2393 d3_time.days = d3_time.day.range;
2394 d3_time.days.utc = d3_time.day.utc.range;
2395 d3_time.dayOfYear = function(date) {
2396 var year = d3_time.year(date);
2397 return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
2399 [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
2401 var interval = d3_time[day] = d3_time_interval(function(date) {
2402 (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
2404 }, function(date, offset) {
2405 date.setDate(date.getDate() + Math.floor(offset) * 7);
2407 var day = d3_time.year(date).getDay();
2408 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
2410 d3_time[day + "s"] = interval.range;
2411 d3_time[day + "s"].utc = interval.utc.range;
2412 d3_time[day + "OfYear"] = function(date) {
2413 var day = d3_time.year(date).getDay();
2414 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
2417 d3_time.week = d3_time.sunday;
2418 d3_time.weeks = d3_time.sunday.range;
2419 d3_time.weeks.utc = d3_time.sunday.utc.range;
2420 d3_time.weekOfYear = d3_time.sundayOfYear;
2421 function d3_locale_timeFormat(locale) {
2422 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;
2423 function d3_time_format(template) {
2424 var n = template.length;
2425 function format(date) {
2426 var string = [], i = -1, j = 0, c, p, f;
2428 if (template.charCodeAt(i) === 37) {
2429 string.push(template.substring(j, i));
2430 if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
2431 if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
2436 string.push(template.substring(j, i));
2437 return string.join("");
2439 format.parse = function(string) {
2449 }, i = d3_time_parse(d, template, string, 0);
2450 if (i != string.length) return null;
2451 if ("p" in d) d.H = d.H % 12 + d.p * 12;
2452 var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
2453 if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
2454 date.setFullYear(d.y, 0, 1);
2455 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);
2456 } else date.setFullYear(d.y, d.m, d.d);
2457 date.setHours(d.H + Math.floor(d.Z / 100), d.M + d.Z % 100, d.S, d.L);
2458 return localZ ? date._ : date;
2460 format.toString = function() {
2465 function d3_time_parse(date, template, string, j) {
2466 var c, p, t, i = 0, n = template.length, m = string.length;
2468 if (j >= m) return -1;
2469 c = template.charCodeAt(i++);
2471 t = template.charAt(i++);
2472 p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
2473 if (!p || (j = p(date, string, j)) < 0) return -1;
2474 } else if (c != string.charCodeAt(j++)) {
2480 d3_time_format.utc = function(template) {
2481 var local = d3_time_format(template);
2482 function format(date) {
2484 d3_date = d3_date_utc;
2485 var utc = new d3_date();
2492 format.parse = function(string) {
2494 d3_date = d3_date_utc;
2495 var date = local.parse(string);
2496 return date && date._;
2501 format.toString = local.toString;
2504 d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
2505 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);
2506 locale_periods.forEach(function(p, i) {
2507 d3_time_periodLookup.set(p.toLowerCase(), i);
2509 var d3_time_formats = {
2511 return locale_shortDays[d.getDay()];
2514 return locale_days[d.getDay()];
2517 return locale_shortMonths[d.getMonth()];
2520 return locale_months[d.getMonth()];
2522 c: d3_time_format(locale_dateTime),
2524 return d3_time_formatPad(d.getDate(), p, 2);
2527 return d3_time_formatPad(d.getDate(), p, 2);
2530 return d3_time_formatPad(d.getHours(), p, 2);
2533 return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
2536 return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
2539 return d3_time_formatPad(d.getMilliseconds(), p, 3);
2542 return d3_time_formatPad(d.getMonth() + 1, p, 2);
2545 return d3_time_formatPad(d.getMinutes(), p, 2);
2548 return locale_periods[+(d.getHours() >= 12)];
2551 return d3_time_formatPad(d.getSeconds(), p, 2);
2554 return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
2560 return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
2562 x: d3_time_format(locale_date),
2563 X: d3_time_format(locale_time),
2565 return d3_time_formatPad(d.getFullYear() % 100, p, 2);
2568 return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
2575 var d3_time_parsers = {
2576 a: d3_time_parseWeekdayAbbrev,
2577 A: d3_time_parseWeekday,
2578 b: d3_time_parseMonthAbbrev,
2579 B: d3_time_parseMonth,
2580 c: d3_time_parseLocaleFull,
2581 d: d3_time_parseDay,
2582 e: d3_time_parseDay,
2583 H: d3_time_parseHour24,
2584 I: d3_time_parseHour24,
2585 j: d3_time_parseDayOfYear,
2586 L: d3_time_parseMilliseconds,
2587 m: d3_time_parseMonthNumber,
2588 M: d3_time_parseMinutes,
2589 p: d3_time_parseAmPm,
2590 S: d3_time_parseSeconds,
2591 U: d3_time_parseWeekNumberSunday,
2592 w: d3_time_parseWeekdayNumber,
2593 W: d3_time_parseWeekNumberMonday,
2594 x: d3_time_parseLocaleDate,
2595 X: d3_time_parseLocaleTime,
2596 y: d3_time_parseYear,
2597 Y: d3_time_parseFullYear,
2598 Z: d3_time_parseZone,
2599 "%": d3_time_parseLiteralPercent
2601 function d3_time_parseWeekdayAbbrev(date, string, i) {
2602 d3_time_dayAbbrevRe.lastIndex = 0;
2603 var n = d3_time_dayAbbrevRe.exec(string.substring(i));
2604 return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2606 function d3_time_parseWeekday(date, string, i) {
2607 d3_time_dayRe.lastIndex = 0;
2608 var n = d3_time_dayRe.exec(string.substring(i));
2609 return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2611 function d3_time_parseMonthAbbrev(date, string, i) {
2612 d3_time_monthAbbrevRe.lastIndex = 0;
2613 var n = d3_time_monthAbbrevRe.exec(string.substring(i));
2614 return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2616 function d3_time_parseMonth(date, string, i) {
2617 d3_time_monthRe.lastIndex = 0;
2618 var n = d3_time_monthRe.exec(string.substring(i));
2619 return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2621 function d3_time_parseLocaleFull(date, string, i) {
2622 return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
2624 function d3_time_parseLocaleDate(date, string, i) {
2625 return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
2627 function d3_time_parseLocaleTime(date, string, i) {
2628 return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
2630 function d3_time_parseAmPm(date, string, i) {
2631 var n = d3_time_periodLookup.get(string.substring(i, i += 2).toLowerCase());
2632 return n == null ? -1 : (date.p = n, i);
2634 return d3_time_format;
2636 var d3_time_formatPads = {
2640 }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
2641 function d3_time_formatPad(value, fill, width) {
2642 var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
2643 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
2645 function d3_time_formatRe(names) {
2646 return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
2648 function d3_time_formatLookup(names) {
2649 var map = new d3_Map(), i = -1, n = names.length;
2650 while (++i < n) map.set(names[i].toLowerCase(), i);
2653 function d3_time_parseWeekdayNumber(date, string, i) {
2654 d3_time_numberRe.lastIndex = 0;
2655 var n = d3_time_numberRe.exec(string.substring(i, i + 1));
2656 return n ? (date.w = +n[0], i + n[0].length) : -1;
2658 function d3_time_parseWeekNumberSunday(date, string, i) {
2659 d3_time_numberRe.lastIndex = 0;
2660 var n = d3_time_numberRe.exec(string.substring(i));
2661 return n ? (date.U = +n[0], i + n[0].length) : -1;
2663 function d3_time_parseWeekNumberMonday(date, string, i) {
2664 d3_time_numberRe.lastIndex = 0;
2665 var n = d3_time_numberRe.exec(string.substring(i));
2666 return n ? (date.W = +n[0], i + n[0].length) : -1;
2668 function d3_time_parseFullYear(date, string, i) {
2669 d3_time_numberRe.lastIndex = 0;
2670 var n = d3_time_numberRe.exec(string.substring(i, i + 4));
2671 return n ? (date.y = +n[0], i + n[0].length) : -1;
2673 function d3_time_parseYear(date, string, i) {
2674 d3_time_numberRe.lastIndex = 0;
2675 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2676 return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
2678 function d3_time_parseZone(date, string, i) {
2679 return /^[+-]\d{4}$/.test(string = string.substring(i, i + 5)) ? (date.Z = +string,
2682 function d3_time_expandYear(d) {
2683 return d + (d > 68 ? 1900 : 2e3);
2685 function d3_time_parseMonthNumber(date, string, i) {
2686 d3_time_numberRe.lastIndex = 0;
2687 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2688 return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
2690 function d3_time_parseDay(date, string, i) {
2691 d3_time_numberRe.lastIndex = 0;
2692 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2693 return n ? (date.d = +n[0], i + n[0].length) : -1;
2695 function d3_time_parseDayOfYear(date, string, i) {
2696 d3_time_numberRe.lastIndex = 0;
2697 var n = d3_time_numberRe.exec(string.substring(i, i + 3));
2698 return n ? (date.j = +n[0], i + n[0].length) : -1;
2700 function d3_time_parseHour24(date, string, i) {
2701 d3_time_numberRe.lastIndex = 0;
2702 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2703 return n ? (date.H = +n[0], i + n[0].length) : -1;
2705 function d3_time_parseMinutes(date, string, i) {
2706 d3_time_numberRe.lastIndex = 0;
2707 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2708 return n ? (date.M = +n[0], i + n[0].length) : -1;
2710 function d3_time_parseSeconds(date, string, i) {
2711 d3_time_numberRe.lastIndex = 0;
2712 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
2713 return n ? (date.S = +n[0], i + n[0].length) : -1;
2715 function d3_time_parseMilliseconds(date, string, i) {
2716 d3_time_numberRe.lastIndex = 0;
2717 var n = d3_time_numberRe.exec(string.substring(i, i + 3));
2718 return n ? (date.L = +n[0], i + n[0].length) : -1;
2720 function d3_time_zone(d) {
2721 var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = ~~(abs(z) / 60), zm = abs(z) % 60;
2722 return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
2724 function d3_time_parseLiteralPercent(date, string, i) {
2725 d3_time_percentRe.lastIndex = 0;
2726 var n = d3_time_percentRe.exec(string.substring(i, i + 1));
2727 return n ? i + n[0].length : -1;
2729 function d3_time_formatMulti(formats) {
2730 var n = formats.length, i = -1;
2731 while (++i < n) formats[i][0] = this(formats[i][0]);
2732 return function(date) {
2733 var i = 0, f = formats[i];
2734 while (!f[1](date)) f = formats[++i];
2738 d3.locale = function(locale) {
2740 numberFormat: d3_locale_numberFormat(locale),
2741 timeFormat: d3_locale_timeFormat(locale)
2744 var d3_locale_enUS = d3.locale({
2748 currency: [ "$", "" ],
2749 dateTime: "%a %b %e %X %Y",
2752 periods: [ "AM", "PM" ],
2753 days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
2754 shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
2755 months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
2756 shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
2758 d3.format = d3_locale_enUS.numberFormat;
2760 function d3_adder() {}
2761 d3_adder.prototype = {
2765 d3_adderSum(y, this.t, d3_adderTemp);
2766 d3_adderSum(d3_adderTemp.s, this.s, this);
2767 if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
2770 this.s = this.t = 0;
2772 valueOf: function() {
2776 var d3_adderTemp = new d3_adder();
2777 function d3_adderSum(a, b, o) {
2778 var x = o.s = a + b, bv = x - a, av = x - bv;
2779 o.t = a - av + (b - bv);
2781 d3.geo.stream = function(object, listener) {
2782 if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
2783 d3_geo_streamObjectType[object.type](object, listener);
2785 d3_geo_streamGeometry(object, listener);
2788 function d3_geo_streamGeometry(geometry, listener) {
2789 if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
2790 d3_geo_streamGeometryType[geometry.type](geometry, listener);
2793 var d3_geo_streamObjectType = {
2794 Feature: function(feature, listener) {
2795 d3_geo_streamGeometry(feature.geometry, listener);
2797 FeatureCollection: function(object, listener) {
2798 var features = object.features, i = -1, n = features.length;
2799 while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
2802 var d3_geo_streamGeometryType = {
2803 Sphere: function(object, listener) {
2806 Point: function(object, listener) {
2807 object = object.coordinates;
2808 listener.point(object[0], object[1], object[2]);
2810 MultiPoint: function(object, listener) {
2811 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2812 while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
2814 LineString: function(object, listener) {
2815 d3_geo_streamLine(object.coordinates, listener, 0);
2817 MultiLineString: function(object, listener) {
2818 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2819 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
2821 Polygon: function(object, listener) {
2822 d3_geo_streamPolygon(object.coordinates, listener);
2824 MultiPolygon: function(object, listener) {
2825 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2826 while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
2828 GeometryCollection: function(object, listener) {
2829 var geometries = object.geometries, i = -1, n = geometries.length;
2830 while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
2833 function d3_geo_streamLine(coordinates, listener, closed) {
2834 var i = -1, n = coordinates.length - closed, coordinate;
2835 listener.lineStart();
2836 while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
2839 function d3_geo_streamPolygon(coordinates, listener) {
2840 var i = -1, n = coordinates.length;
2841 listener.polygonStart();
2842 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
2843 listener.polygonEnd();
2845 d3.geo.area = function(object) {
2847 d3.geo.stream(object, d3_geo_area);
2848 return d3_geo_areaSum;
2850 var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
2852 sphere: function() {
2853 d3_geo_areaSum += 4 * π;
2858 polygonStart: function() {
2859 d3_geo_areaRingSum.reset();
2860 d3_geo_area.lineStart = d3_geo_areaRingStart;
2862 polygonEnd: function() {
2863 var area = 2 * d3_geo_areaRingSum;
2864 d3_geo_areaSum += area < 0 ? 4 * π + area : area;
2865 d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
2868 function d3_geo_areaRingStart() {
2869 var λ00, φ00, λ0, cosφ0, sinφ0;
2870 d3_geo_area.point = function(λ, φ) {
2871 d3_geo_area.point = nextPoint;
2872 λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
2873 sinφ0 = Math.sin(φ);
2875 function nextPoint(λ, φ) {
2877 φ = φ * d3_radians / 2 + π / 4;
2878 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λ);
2879 d3_geo_areaRingSum.add(Math.atan2(v, u));
2880 λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
2882 d3_geo_area.lineEnd = function() {
2883 nextPoint(λ00, φ00);
2886 function d3_geo_cartesian(spherical) {
2887 var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
2888 return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
2890 function d3_geo_cartesianDot(a, b) {
2891 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
2893 function d3_geo_cartesianCross(a, b) {
2894 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] ];
2896 function d3_geo_cartesianAdd(a, b) {
2901 function d3_geo_cartesianScale(vector, k) {
2902 return [ vector[0] * k, vector[1] * k, vector[2] * k ];
2904 function d3_geo_cartesianNormalize(d) {
2905 var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
2910 function d3_geo_spherical(cartesian) {
2911 return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
2913 function d3_geo_sphericalEqual(a, b) {
2914 return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
2916 d3.geo.bounds = function() {
2917 var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
2920 lineStart: lineStart,
2922 polygonStart: function() {
2923 bound.point = ringPoint;
2924 bound.lineStart = ringStart;
2925 bound.lineEnd = ringEnd;
2927 d3_geo_area.polygonStart();
2929 polygonEnd: function() {
2930 d3_geo_area.polygonEnd();
2931 bound.point = point;
2932 bound.lineStart = lineStart;
2933 bound.lineEnd = lineEnd;
2934 if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
2935 range[0] = λ0, range[1] = λ1;
2938 function point(λ, φ) {
2939 ranges.push(range = [ λ0 = λ, λ1 = λ ]);
2943 function linePoint(λ, φ) {
2944 var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
2946 var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
2947 d3_geo_cartesianNormalize(inflection);
2948 inflection = d3_geo_spherical(inflection);
2949 var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
2950 if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
2951 var φi = inflection[1] * d3_degrees;
2952 if (φi > φ1) φ1 = φi;
2953 } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
2954 var φi = -inflection[1] * d3_degrees;
2955 if (φi < φ0) φ0 = φi;
2962 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
2964 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
2972 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
2974 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
2983 function lineStart() {
2984 bound.point = linePoint;
2986 function lineEnd() {
2987 range[0] = λ0, range[1] = λ1;
2988 bound.point = point;
2991 function ringPoint(λ, φ) {
2994 dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
2995 } else λ__ = λ, φ__ = φ;
2996 d3_geo_area.point(λ, φ);
2999 function ringStart() {
3000 d3_geo_area.lineStart();
3002 function ringEnd() {
3003 ringPoint(λ__, φ__);
3004 d3_geo_area.lineEnd();
3005 if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
3006 range[0] = λ0, range[1] = λ1;
3009 function angle(λ0, λ1) {
3010 return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
3012 function compareRanges(a, b) {
3015 function withinRange(x, range) {
3016 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
3018 return function(feature) {
3019 φ1 = λ1 = -(λ0 = φ0 = Infinity);
3021 d3.geo.stream(feature, bound);
3022 var n = ranges.length;
3024 ranges.sort(compareRanges);
3025 for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
3027 if (withinRange(b[0], a) || withinRange(b[1], a)) {
3028 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
3029 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
3034 var best = -Infinity, dλ;
3035 for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
3037 if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
3040 ranges = range = null;
3041 return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
3044 d3.geo.centroid = function(object) {
3045 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;
3046 d3.geo.stream(object, d3_geo_centroid);
3047 var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
3049 x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
3050 if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
3051 m = x * x + y * y + z * z;
3052 if (m < ε2) return [ NaN, NaN ];
3054 return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
3056 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;
3057 var d3_geo_centroid = {
3059 point: d3_geo_centroidPoint,
3060 lineStart: d3_geo_centroidLineStart,
3061 lineEnd: d3_geo_centroidLineEnd,
3062 polygonStart: function() {
3063 d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
3065 polygonEnd: function() {
3066 d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
3069 function d3_geo_centroidPoint(λ, φ) {
3071 var cosφ = Math.cos(φ *= d3_radians);
3072 d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
3074 function d3_geo_centroidPointXYZ(x, y, z) {
3075 ++d3_geo_centroidW0;
3076 d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
3077 d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
3078 d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
3080 function d3_geo_centroidLineStart() {
3082 d3_geo_centroid.point = function(λ, φ) {
3084 var cosφ = Math.cos(φ *= d3_radians);
3085 x0 = cosφ * Math.cos(λ);
3086 y0 = cosφ * Math.sin(λ);
3088 d3_geo_centroid.point = nextPoint;
3089 d3_geo_centroidPointXYZ(x0, y0, z0);
3091 function nextPoint(λ, φ) {
3093 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);
3094 d3_geo_centroidW1 += w;
3095 d3_geo_centroidX1 += w * (x0 + (x0 = x));
3096 d3_geo_centroidY1 += w * (y0 + (y0 = y));
3097 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3098 d3_geo_centroidPointXYZ(x0, y0, z0);
3101 function d3_geo_centroidLineEnd() {
3102 d3_geo_centroid.point = d3_geo_centroidPoint;
3104 function d3_geo_centroidRingStart() {
3105 var λ00, φ00, x0, y0, z0;
3106 d3_geo_centroid.point = function(λ, φ) {
3108 d3_geo_centroid.point = nextPoint;
3110 var cosφ = Math.cos(φ *= d3_radians);
3111 x0 = cosφ * Math.cos(λ);
3112 y0 = cosφ * Math.sin(λ);
3114 d3_geo_centroidPointXYZ(x0, y0, z0);
3116 d3_geo_centroid.lineEnd = function() {
3117 nextPoint(λ00, φ00);
3118 d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
3119 d3_geo_centroid.point = d3_geo_centroidPoint;
3121 function nextPoint(λ, φ) {
3123 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);
3124 d3_geo_centroidX2 += v * cx;
3125 d3_geo_centroidY2 += v * cy;
3126 d3_geo_centroidZ2 += v * cz;
3127 d3_geo_centroidW1 += w;
3128 d3_geo_centroidX1 += w * (x0 + (x0 = x));
3129 d3_geo_centroidY1 += w * (y0 + (y0 = y));
3130 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3131 d3_geo_centroidPointXYZ(x0, y0, z0);
3134 function d3_true() {
3137 function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
3138 var subject = [], clip = [];
3139 segments.forEach(function(segment) {
3140 if ((n = segment.length - 1) <= 0) return;
3141 var n, p0 = segment[0], p1 = segment[n];
3142 if (d3_geo_sphericalEqual(p0, p1)) {
3143 listener.lineStart();
3144 for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
3148 var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
3152 a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
3153 b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
3159 d3_geo_clipPolygonLinkCircular(subject);
3160 d3_geo_clipPolygonLinkCircular(clip);
3161 if (!subject.length) return;
3162 for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
3163 clip[i].e = entry = !entry;
3165 var start = subject[0], points, point;
3167 var current = start, isSubject = true;
3168 while (current.v) if ((current = current.n) === start) return;
3170 listener.lineStart();
3172 current.v = current.o.v = true;
3175 for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
3177 interpolate(current.x, current.n.x, 1, listener);
3179 current = current.n;
3182 points = current.p.z;
3183 for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
3185 interpolate(current.x, current.p.x, -1, listener);
3187 current = current.p;
3189 current = current.o;
3191 isSubject = !isSubject;
3192 } while (!current.v);
3196 function d3_geo_clipPolygonLinkCircular(array) {
3197 if (!(n = array.length)) return;
3198 var n, i = 0, a = array[0], b;
3207 function d3_geo_clipPolygonIntersection(point, points, other, entry) {
3213 this.n = this.p = null;
3215 function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
3216 return function(rotate, listener) {
3217 var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
3220 lineStart: lineStart,
3222 polygonStart: function() {
3223 clip.point = pointRing;
3224 clip.lineStart = ringStart;
3225 clip.lineEnd = ringEnd;
3228 listener.polygonStart();
3230 polygonEnd: function() {
3232 clip.lineStart = lineStart;
3233 clip.lineEnd = lineEnd;
3234 segments = d3.merge(segments);
3235 var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
3236 if (segments.length) {
3237 d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
3238 } else if (clipStartInside) {
3239 listener.lineStart();
3240 interpolate(null, null, 1, listener);
3243 listener.polygonEnd();
3244 segments = polygon = null;
3246 sphere: function() {
3247 listener.polygonStart();
3248 listener.lineStart();
3249 interpolate(null, null, 1, listener);
3251 listener.polygonEnd();
3254 function point(λ, φ) {
3255 var point = rotate(λ, φ);
3256 if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
3258 function pointLine(λ, φ) {
3259 var point = rotate(λ, φ);
3260 line.point(point[0], point[1]);
3262 function lineStart() {
3263 clip.point = pointLine;
3266 function lineEnd() {
3271 var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygon, ring;
3272 function pointRing(λ, φ) {
3273 ring.push([ λ, φ ]);
3274 var point = rotate(λ, φ);
3275 ringListener.point(point[0], point[1]);
3277 function ringStart() {
3278 ringListener.lineStart();
3281 function ringEnd() {
3282 pointRing(ring[0][0], ring[0][1]);
3283 ringListener.lineEnd();
3284 var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
3290 segment = ringSegments[0];
3291 var n = segment.length - 1, i = -1, point;
3292 listener.lineStart();
3293 while (++i < n) listener.point((point = segment[i])[0], point[1]);
3297 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
3298 segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
3303 function d3_geo_clipSegmentLength1(segment) {
3304 return segment.length > 1;
3306 function d3_geo_clipBufferListener() {
3307 var lines = [], line;
3309 lineStart: function() {
3310 lines.push(line = []);
3312 point: function(λ, φ) {
3313 line.push([ λ, φ ]);
3316 buffer: function() {
3322 rejoin: function() {
3323 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
3327 function d3_geo_clipSort(a, b) {
3328 return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
3330 function d3_geo_pointInPolygon(point, polygon) {
3331 var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
3332 d3_geo_areaRingSum.reset();
3333 for (var i = 0, n = polygon.length; i < n; ++i) {
3334 var ring = polygon[i], m = ring.length;
3336 var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
3340 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φ;
3341 d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
3342 polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
3343 if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
3344 var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
3345 d3_geo_cartesianNormalize(arc);
3346 var intersection = d3_geo_cartesianCross(meridianNormal, arc);
3347 d3_geo_cartesianNormalize(intersection);
3348 var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
3349 if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
3350 winding += antimeridian ^ dλ >= 0 ? 1 : -1;
3354 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
3357 return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1;
3359 var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
3360 function d3_geo_clipAntimeridianLine(listener) {
3361 var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
3363 lineStart: function() {
3364 listener.lineStart();
3367 point: function(λ1, φ1) {
3368 var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
3369 if (abs(dλ - π) < ε) {
3370 listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
3371 listener.point(sλ0, φ0);
3373 listener.lineStart();
3374 listener.point(sλ1, φ0);
3375 listener.point(λ1, φ0);
3377 } else if (sλ0 !== sλ1 && dλ >= π) {
3378 if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
3379 if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
3380 φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
3381 listener.point(sλ0, φ0);
3383 listener.lineStart();
3384 listener.point(sλ1, φ0);
3387 listener.point(λ0 = λ1, φ0 = φ1);
3390 lineEnd: function() {
3399 function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
3400 var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
3401 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;
3403 function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
3406 φ = direction * halfπ;
3407 listener.point(-π, φ);
3408 listener.point(0, φ);
3409 listener.point(π, φ);
3410 listener.point(π, 0);
3411 listener.point(π, -φ);
3412 listener.point(0, -φ);
3413 listener.point(-π, -φ);
3414 listener.point(-π, 0);
3415 listener.point(-π, φ);
3416 } else if (abs(from[0] - to[0]) > ε) {
3417 var s = from[0] < to[0] ? π : -π;
3418 φ = direction * s / 2;
3419 listener.point(-s, φ);
3420 listener.point(0, φ);
3421 listener.point(s, φ);
3423 listener.point(to[0], to[1]);
3426 function d3_geo_clipCircle(radius) {
3427 var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
3428 return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
3429 function visible(λ, φ) {
3430 return Math.cos(λ) * Math.cos(φ) > cr;
3432 function clipLine(listener) {
3433 var point0, c0, v0, v00, clean;
3435 lineStart: function() {
3439 point: function(λ, φ) {
3440 var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
3441 if (!point0 && (v00 = v0 = v)) listener.lineStart();
3443 point2 = intersect(point0, point1);
3444 if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
3447 v = visible(point1[0], point1[1]);
3453 listener.lineStart();
3454 point2 = intersect(point1, point0);
3455 listener.point(point2[0], point2[1]);
3457 point2 = intersect(point0, point1);
3458 listener.point(point2[0], point2[1]);
3462 } else if (notHemisphere && point0 && smallRadius ^ v) {
3464 if (!(c & c0) && (t = intersect(point1, point0, true))) {
3467 listener.lineStart();
3468 listener.point(t[0][0], t[0][1]);
3469 listener.point(t[1][0], t[1][1]);
3472 listener.point(t[1][0], t[1][1]);
3474 listener.lineStart();
3475 listener.point(t[0][0], t[0][1]);
3479 if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
3480 listener.point(point1[0], point1[1]);
3482 point0 = point1, v0 = v, c0 = c;
3484 lineEnd: function() {
3485 if (v0) listener.lineEnd();
3489 return clean | (v00 && v0) << 1;
3493 function intersect(a, b, two) {
3494 var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
3495 var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
3496 if (!determinant) return !two && a;
3497 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);
3498 d3_geo_cartesianAdd(A, B);
3499 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);
3501 var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
3502 d3_geo_cartesianAdd(q, A);
3503 q = d3_geo_spherical(q);
3505 var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
3506 if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
3507 var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
3508 if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
3509 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)) {
3510 var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
3511 d3_geo_cartesianAdd(q1, A);
3512 return [ q, d3_geo_spherical(q1) ];
3515 function code(λ, φ) {
3516 var r = smallRadius ? radius : π - radius, code = 0;
3517 if (λ < -r) code |= 1; else if (λ > r) code |= 2;
3518 if (φ < -r) code |= 4; else if (φ > r) code |= 8;
3522 function d3_geom_clipLine(x0, y0, x1, y1) {
3523 return function(line) {
3524 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;
3526 if (!dx && r > 0) return;
3531 } else if (dx > 0) {
3536 if (!dx && r < 0) return;
3541 } else if (dx > 0) {
3546 if (!dy && r > 0) return;
3551 } else if (dy > 0) {
3556 if (!dy && r < 0) return;
3561 } else if (dy > 0) {
3565 if (t0 > 0) line.a = {
3569 if (t1 < 1) line.b = {
3576 var d3_geo_clipExtentMAX = 1e9;
3577 d3.geo.clipExtent = function() {
3578 var x0, y0, x1, y1, stream, clip, clipExtent = {
3579 stream: function(output) {
3580 if (stream) stream.valid = false;
3581 stream = clip(output);
3582 stream.valid = true;
3585 extent: function(_) {
3586 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
3587 clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
3588 if (stream) stream.valid = false, stream = null;
3592 return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
3594 function d3_geo_clipExtent(x0, y0, x1, y1) {
3595 return function(listener) {
3596 var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
3599 lineStart: lineStart,
3601 polygonStart: function() {
3602 listener = bufferListener;
3607 polygonEnd: function() {
3608 listener = listener_;
3609 segments = d3.merge(segments);
3610 var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
3611 if (inside || visible) {
3612 listener.polygonStart();
3614 listener.lineStart();
3615 interpolate(null, null, 1, listener);
3619 d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
3621 listener.polygonEnd();
3623 segments = polygon = ring = null;
3626 function insidePolygon(p) {
3627 var wn = 0, n = polygon.length, y = p[1];
3628 for (var i = 0; i < n; ++i) {
3629 for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
3632 if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
3634 if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
3641 function interpolate(from, to, direction, listener) {
3643 if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
3645 listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
3646 } while ((a = (a + direction + 4) % 4) !== a1);
3648 listener.point(to[0], to[1]);
3651 function pointVisible(x, y) {
3652 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
3654 function point(x, y) {
3655 if (pointVisible(x, y)) listener.point(x, y);
3657 var x__, y__, v__, x_, y_, v_, first, clean;
3658 function lineStart() {
3659 clip.point = linePoint;
3660 if (polygon) polygon.push(ring = []);
3665 function lineEnd() {
3667 linePoint(x__, y__);
3668 if (v__ && v_) bufferListener.rejoin();
3669 segments.push(bufferListener.buffer());
3672 if (v_) listener.lineEnd();
3674 function linePoint(x, y) {
3675 x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
3676 y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
3677 var v = pointVisible(x, y);
3678 if (polygon) ring.push([ x, y ]);
3680 x__ = x, y__ = y, v__ = v;
3683 listener.lineStart();
3684 listener.point(x, y);
3687 if (v && v_) listener.point(x, y); else {
3700 listener.lineStart();
3701 listener.point(l.a.x, l.a.y);
3703 listener.point(l.b.x, l.b.y);
3704 if (!v) listener.lineEnd();
3707 listener.lineStart();
3708 listener.point(x, y);
3713 x_ = x, y_ = y, v_ = v;
3717 function corner(p, direction) {
3718 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;
3720 function compare(a, b) {
3721 return comparePoints(a.x, b.x);
3723 function comparePoints(a, b) {
3724 var ca = corner(a, 1), cb = corner(b, 1);
3725 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];
3728 function d3_geo_compose(a, b) {
3729 function compose(x, y) {
3730 return x = a(x, y), b(x[0], x[1]);
3732 if (a.invert && b.invert) compose.invert = function(x, y) {
3733 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
3737 function d3_geo_conic(projectAt) {
3738 var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
3739 p.parallels = function(_) {
3740 if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
3741 return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
3745 function d3_geo_conicEqualArea(φ0, φ1) {
3746 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;
3747 function forward(λ, φ) {
3748 var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
3749 return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
3751 forward.invert = function(x, y) {
3753 return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
3757 (d3.geo.conicEqualArea = function() {
3758 return d3_geo_conic(d3_geo_conicEqualArea);
3759 }).raw = d3_geo_conicEqualArea;
3760 d3.geo.albers = function() {
3761 return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
3763 d3.geo.albersUsa = function() {
3764 var lower48 = d3.geo.albers();
3765 var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
3766 var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
3767 var point, pointStream = {
3768 point: function(x, y) {
3771 }, lower48Point, alaskaPoint, hawaiiPoint;
3772 function albersUsa(coordinates) {
3773 var x = coordinates[0], y = coordinates[1];
3775 (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
3778 albersUsa.invert = function(coordinates) {
3779 var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
3780 return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
3782 albersUsa.stream = function(stream) {
3783 var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
3785 point: function(x, y) {
3786 lower48Stream.point(x, y);
3787 alaskaStream.point(x, y);
3788 hawaiiStream.point(x, y);
3790 sphere: function() {
3791 lower48Stream.sphere();
3792 alaskaStream.sphere();
3793 hawaiiStream.sphere();
3795 lineStart: function() {
3796 lower48Stream.lineStart();
3797 alaskaStream.lineStart();
3798 hawaiiStream.lineStart();
3800 lineEnd: function() {
3801 lower48Stream.lineEnd();
3802 alaskaStream.lineEnd();
3803 hawaiiStream.lineEnd();
3805 polygonStart: function() {
3806 lower48Stream.polygonStart();
3807 alaskaStream.polygonStart();
3808 hawaiiStream.polygonStart();
3810 polygonEnd: function() {
3811 lower48Stream.polygonEnd();
3812 alaskaStream.polygonEnd();
3813 hawaiiStream.polygonEnd();
3817 albersUsa.precision = function(_) {
3818 if (!arguments.length) return lower48.precision();
3819 lower48.precision(_);
3820 alaska.precision(_);
3821 hawaii.precision(_);
3824 albersUsa.scale = function(_) {
3825 if (!arguments.length) return lower48.scale();
3827 alaska.scale(_ * .35);
3829 return albersUsa.translate(lower48.translate());
3831 albersUsa.translate = function(_) {
3832 if (!arguments.length) return lower48.translate();
3833 var k = lower48.scale(), x = +_[0], y = +_[1];
3834 lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
3835 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;
3836 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;
3839 return albersUsa.scale(1070);
3841 var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
3845 polygonStart: function() {
3846 d3_geo_pathAreaPolygon = 0;
3847 d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
3849 polygonEnd: function() {
3850 d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
3851 d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
3854 function d3_geo_pathAreaRingStart() {
3855 var x00, y00, x0, y0;
3856 d3_geo_pathArea.point = function(x, y) {
3857 d3_geo_pathArea.point = nextPoint;
3858 x00 = x0 = x, y00 = y0 = y;
3860 function nextPoint(x, y) {
3861 d3_geo_pathAreaPolygon += y0 * x - x0 * y;
3864 d3_geo_pathArea.lineEnd = function() {
3865 nextPoint(x00, y00);
3868 var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
3869 var d3_geo_pathBounds = {
3870 point: d3_geo_pathBoundsPoint,
3873 polygonStart: d3_noop,
3876 function d3_geo_pathBoundsPoint(x, y) {
3877 if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
3878 if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
3879 if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
3880 if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
3882 function d3_geo_pathBuffer() {
3883 var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
3886 lineStart: function() {
3887 stream.point = pointLineStart;
3890 polygonStart: function() {
3891 stream.lineEnd = lineEndPolygon;
3893 polygonEnd: function() {
3894 stream.lineEnd = lineEnd;
3895 stream.point = point;
3897 pointRadius: function(_) {
3898 pointCircle = d3_geo_pathBufferCircle(_);
3901 result: function() {
3902 if (buffer.length) {
3903 var result = buffer.join("");
3909 function point(x, y) {
3910 buffer.push("M", x, ",", y, pointCircle);
3912 function pointLineStart(x, y) {
3913 buffer.push("M", x, ",", y);
3914 stream.point = pointLine;
3916 function pointLine(x, y) {
3917 buffer.push("L", x, ",", y);
3919 function lineEnd() {
3920 stream.point = point;
3922 function lineEndPolygon() {
3927 function d3_geo_pathBufferCircle(radius) {
3928 return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
3930 var d3_geo_pathCentroid = {
3931 point: d3_geo_pathCentroidPoint,
3932 lineStart: d3_geo_pathCentroidLineStart,
3933 lineEnd: d3_geo_pathCentroidLineEnd,
3934 polygonStart: function() {
3935 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
3937 polygonEnd: function() {
3938 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
3939 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
3940 d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
3943 function d3_geo_pathCentroidPoint(x, y) {
3944 d3_geo_centroidX0 += x;
3945 d3_geo_centroidY0 += y;
3946 ++d3_geo_centroidZ0;
3948 function d3_geo_pathCentroidLineStart() {
3950 d3_geo_pathCentroid.point = function(x, y) {
3951 d3_geo_pathCentroid.point = nextPoint;
3952 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
3954 function nextPoint(x, y) {
3955 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
3956 d3_geo_centroidX1 += z * (x0 + x) / 2;
3957 d3_geo_centroidY1 += z * (y0 + y) / 2;
3958 d3_geo_centroidZ1 += z;
3959 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
3962 function d3_geo_pathCentroidLineEnd() {
3963 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
3965 function d3_geo_pathCentroidRingStart() {
3966 var x00, y00, x0, y0;
3967 d3_geo_pathCentroid.point = function(x, y) {
3968 d3_geo_pathCentroid.point = nextPoint;
3969 d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
3971 function nextPoint(x, y) {
3972 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
3973 d3_geo_centroidX1 += z * (x0 + x) / 2;
3974 d3_geo_centroidY1 += z * (y0 + y) / 2;
3975 d3_geo_centroidZ1 += z;
3976 z = y0 * x - x0 * y;
3977 d3_geo_centroidX2 += z * (x0 + x);
3978 d3_geo_centroidY2 += z * (y0 + y);
3979 d3_geo_centroidZ2 += z * 3;
3980 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
3982 d3_geo_pathCentroid.lineEnd = function() {
3983 nextPoint(x00, y00);
3986 function d3_geo_pathContext(context) {
3987 var pointRadius = 4.5;
3990 lineStart: function() {
3991 stream.point = pointLineStart;
3994 polygonStart: function() {
3995 stream.lineEnd = lineEndPolygon;
3997 polygonEnd: function() {
3998 stream.lineEnd = lineEnd;
3999 stream.point = point;
4001 pointRadius: function(_) {
4007 function point(x, y) {
4008 context.moveTo(x, y);
4009 context.arc(x, y, pointRadius, 0, τ);
4011 function pointLineStart(x, y) {
4012 context.moveTo(x, y);
4013 stream.point = pointLine;
4015 function pointLine(x, y) {
4016 context.lineTo(x, y);
4018 function lineEnd() {
4019 stream.point = point;
4021 function lineEndPolygon() {
4022 context.closePath();
4026 function d3_geo_resample(project) {
4027 var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
4028 function resample(stream) {
4029 return (maxDepth ? resampleRecursive : resampleNone)(stream);
4031 function resampleNone(stream) {
4032 return d3_geo_transformPoint(stream, function(x, y) {
4034 stream.point(x[0], x[1]);
4037 function resampleRecursive(stream) {
4038 var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
4041 lineStart: lineStart,
4043 polygonStart: function() {
4044 stream.polygonStart();
4045 resample.lineStart = ringStart;
4047 polygonEnd: function() {
4048 stream.polygonEnd();
4049 resample.lineStart = lineStart;
4052 function point(x, y) {
4054 stream.point(x[0], x[1]);
4056 function lineStart() {
4058 resample.point = linePoint;
4061 function linePoint(λ, φ) {
4062 var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
4063 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);
4064 stream.point(x0, y0);
4066 function lineEnd() {
4067 resample.point = point;
4070 function ringStart() {
4072 resample.point = ringPoint;
4073 resample.lineEnd = ringEnd;
4075 function ringPoint(λ, φ) {
4076 linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
4077 resample.point = linePoint;
4079 function ringEnd() {
4080 resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
4081 resample.lineEnd = lineEnd;
4086 function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
4087 var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
4088 if (d2 > 4 * δ2 && depth--) {
4089 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;
4090 if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
4091 resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
4092 stream.point(x2, y2);
4093 resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
4097 resample.precision = function(_) {
4098 if (!arguments.length) return Math.sqrt(δ2);
4099 maxDepth = (δ2 = _ * _) > 0 && 16;
4104 d3.geo.path = function() {
4105 var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
4106 function path(object) {
4108 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
4109 if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
4110 d3.geo.stream(object, cacheStream);
4112 return contextStream.result();
4114 path.area = function(object) {
4115 d3_geo_pathAreaSum = 0;
4116 d3.geo.stream(object, projectStream(d3_geo_pathArea));
4117 return d3_geo_pathAreaSum;
4119 path.centroid = function(object) {
4120 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;
4121 d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
4122 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 ];
4124 path.bounds = function(object) {
4125 d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
4126 d3.geo.stream(object, projectStream(d3_geo_pathBounds));
4127 return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
4129 path.projection = function(_) {
4130 if (!arguments.length) return projection;
4131 projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
4134 path.context = function(_) {
4135 if (!arguments.length) return context;
4136 contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
4137 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
4140 path.pointRadius = function(_) {
4141 if (!arguments.length) return pointRadius;
4142 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
4149 return path.projection(d3.geo.albersUsa()).context(null);
4151 function d3_geo_pathProjectStream(project) {
4152 var resample = d3_geo_resample(function(x, y) {
4153 return project([ x * d3_degrees, y * d3_degrees ]);
4155 return function(stream) {
4156 return d3_geo_projectionRadians(resample(stream));
4159 d3.geo.transform = function(methods) {
4161 stream: function(stream) {
4162 var transform = new d3_geo_transform(stream);
4163 for (var k in methods) transform[k] = methods[k];
4168 function d3_geo_transform(stream) {
4169 this.stream = stream;
4171 d3_geo_transform.prototype = {
4172 point: function(x, y) {
4173 this.stream.point(x, y);
4175 sphere: function() {
4176 this.stream.sphere();
4178 lineStart: function() {
4179 this.stream.lineStart();
4181 lineEnd: function() {
4182 this.stream.lineEnd();
4184 polygonStart: function() {
4185 this.stream.polygonStart();
4187 polygonEnd: function() {
4188 this.stream.polygonEnd();
4191 function d3_geo_transformPoint(stream, point) {
4194 sphere: function() {
4197 lineStart: function() {
4200 lineEnd: function() {
4203 polygonStart: function() {
4204 stream.polygonStart();
4206 polygonEnd: function() {
4207 stream.polygonEnd();
4211 d3.geo.projection = d3_geo_projection;
4212 d3.geo.projectionMutator = d3_geo_projectionMutator;
4213 function d3_geo_projection(project) {
4214 return d3_geo_projectionMutator(function() {
4218 function d3_geo_projectionMutator(projectAt) {
4219 var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
4221 return [ x[0] * k + δx, δy - x[1] * k ];
4222 }), 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;
4223 function projection(point) {
4224 point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
4225 return [ point[0] * k + δx, δy - point[1] * k ];
4227 function invert(point) {
4228 point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
4229 return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
4231 projection.stream = function(output) {
4232 if (stream) stream.valid = false;
4233 stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
4234 stream.valid = true;
4237 projection.clipAngle = function(_) {
4238 if (!arguments.length) return clipAngle;
4239 preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
4240 return invalidate();
4242 projection.clipExtent = function(_) {
4243 if (!arguments.length) return clipExtent;
4245 postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
4246 return invalidate();
4248 projection.scale = function(_) {
4249 if (!arguments.length) return k;
4253 projection.translate = function(_) {
4254 if (!arguments.length) return [ x, y ];
4259 projection.center = function(_) {
4260 if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
4261 λ = _[0] % 360 * d3_radians;
4262 φ = _[1] % 360 * d3_radians;
4265 projection.rotate = function(_) {
4266 if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
4267 δλ = _[0] % 360 * d3_radians;
4268 δφ = _[1] % 360 * d3_radians;
4269 δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
4272 d3.rebind(projection, projectResample, "precision");
4274 projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
4275 var center = project(λ, φ);
4276 δx = x - center[0] * k;
4277 δy = y + center[1] * k;
4278 return invalidate();
4280 function invalidate() {
4281 if (stream) stream.valid = false, stream = null;
4285 project = projectAt.apply(this, arguments);
4286 projection.invert = project.invert && invert;
4290 function d3_geo_projectionRadians(stream) {
4291 return d3_geo_transformPoint(stream, function(x, y) {
4292 stream.point(x * d3_radians, y * d3_radians);
4295 function d3_geo_equirectangular(λ, φ) {
4298 (d3.geo.equirectangular = function() {
4299 return d3_geo_projection(d3_geo_equirectangular);
4300 }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
4301 d3.geo.rotation = function(rotate) {
4302 rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
4303 function forward(coordinates) {
4304 coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4305 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
4307 forward.invert = function(coordinates) {
4308 coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4309 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
4313 function d3_geo_identityRotation(λ, φ) {
4314 return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
4316 d3_geo_identityRotation.invert = d3_geo_equirectangular;
4317 function d3_geo_rotation(δλ, δφ, δγ) {
4318 return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
4320 function d3_geo_forwardRotationλ(δλ) {
4321 return function(λ, φ) {
4322 return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
4325 function d3_geo_rotationλ(δλ) {
4326 var rotation = d3_geo_forwardRotationλ(δλ);
4327 rotation.invert = d3_geo_forwardRotationλ(-δλ);
4330 function d3_geo_rotationφγ(δφ, δγ) {
4331 var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
4332 function rotation(λ, φ) {
4333 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
4334 return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
4336 rotation.invert = function(λ, φ) {
4337 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
4338 return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
4342 d3.geo.circle = function() {
4343 var origin = [ 0, 0 ], angle, precision = 6, interpolate;
4345 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 = [];
4346 interpolate(null, null, 1, {
4347 point: function(x, y) {
4348 ring.push(x = rotate(x, y));
4349 x[0] *= d3_degrees, x[1] *= d3_degrees;
4354 coordinates: [ ring ]
4357 circle.origin = function(x) {
4358 if (!arguments.length) return origin;
4362 circle.angle = function(x) {
4363 if (!arguments.length) return angle;
4364 interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
4367 circle.precision = function(_) {
4368 if (!arguments.length) return precision;
4369 interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
4372 return circle.angle(90);
4374 function d3_geo_circleInterpolate(radius, precision) {
4375 var cr = Math.cos(radius), sr = Math.sin(radius);
4376 return function(from, to, direction, listener) {
4377 var step = direction * precision;
4379 from = d3_geo_circleAngle(cr, from);
4380 to = d3_geo_circleAngle(cr, to);
4381 if (direction > 0 ? from < to : from > to) from += direction * τ;
4383 from = radius + direction * τ;
4384 to = radius - .5 * step;
4386 for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
4387 listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
4391 function d3_geo_circleAngle(cr, point) {
4392 var a = d3_geo_cartesian(point);
4394 d3_geo_cartesianNormalize(a);
4395 var angle = d3_acos(-a[1]);
4396 return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
4398 d3.geo.distance = function(a, b) {
4399 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;
4400 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Δλ);
4402 d3.geo.graticule = function() {
4403 var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
4404 function graticule() {
4406 type: "MultiLineString",
4407 coordinates: lines()
4411 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) {
4412 return abs(x % DX) > ε;
4413 }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
4414 return abs(y % DY) > ε;
4417 graticule.lines = function() {
4418 return lines().map(function(coordinates) {
4421 coordinates: coordinates
4425 graticule.outline = function() {
4428 coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
4431 graticule.extent = function(_) {
4432 if (!arguments.length) return graticule.minorExtent();
4433 return graticule.majorExtent(_).minorExtent(_);
4435 graticule.majorExtent = function(_) {
4436 if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
4437 X0 = +_[0][0], X1 = +_[1][0];
4438 Y0 = +_[0][1], Y1 = +_[1][1];
4439 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
4440 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
4441 return graticule.precision(precision);
4443 graticule.minorExtent = function(_) {
4444 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
4445 x0 = +_[0][0], x1 = +_[1][0];
4446 y0 = +_[0][1], y1 = +_[1][1];
4447 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
4448 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
4449 return graticule.precision(precision);
4451 graticule.step = function(_) {
4452 if (!arguments.length) return graticule.minorStep();
4453 return graticule.majorStep(_).minorStep(_);
4455 graticule.majorStep = function(_) {
4456 if (!arguments.length) return [ DX, DY ];
4457 DX = +_[0], DY = +_[1];
4460 graticule.minorStep = function(_) {
4461 if (!arguments.length) return [ dx, dy ];
4462 dx = +_[0], dy = +_[1];
4465 graticule.precision = function(_) {
4466 if (!arguments.length) return precision;
4468 x = d3_geo_graticuleX(y0, y1, 90);
4469 y = d3_geo_graticuleY(x0, x1, precision);
4470 X = d3_geo_graticuleX(Y0, Y1, 90);
4471 Y = d3_geo_graticuleY(X0, X1, precision);
4474 return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
4476 function d3_geo_graticuleX(y0, y1, dy) {
4477 var y = d3.range(y0, y1 - ε, dy).concat(y1);
4478 return function(x) {
4479 return y.map(function(y) {
4484 function d3_geo_graticuleY(x0, x1, dx) {
4485 var x = d3.range(x0, x1 - ε, dx).concat(x1);
4486 return function(y) {
4487 return x.map(function(x) {
4492 function d3_source(d) {
4495 function d3_target(d) {
4498 d3.geo.greatArc = function() {
4499 var source = d3_source, source_, target = d3_target, target_;
4500 function greatArc() {
4503 coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
4506 greatArc.distance = function() {
4507 return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
4509 greatArc.source = function(_) {
4510 if (!arguments.length) return source;
4511 source = _, source_ = typeof _ === "function" ? null : _;
4514 greatArc.target = function(_) {
4515 if (!arguments.length) return target;
4516 target = _, target_ = typeof _ === "function" ? null : _;
4519 greatArc.precision = function() {
4520 return arguments.length ? greatArc : 0;
4524 d3.geo.interpolate = function(source, target) {
4525 return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
4527 function d3_geo_interpolate(x0, y0, x1, y1) {
4528 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);
4529 var interpolate = d ? function(t) {
4530 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;
4531 return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
4533 return [ x0 * d3_degrees, y0 * d3_degrees ];
4535 interpolate.distance = d;
4538 d3.geo.length = function(object) {
4539 d3_geo_lengthSum = 0;
4540 d3.geo.stream(object, d3_geo_length);
4541 return d3_geo_lengthSum;
4543 var d3_geo_lengthSum;
4544 var d3_geo_length = {
4547 lineStart: d3_geo_lengthLineStart,
4549 polygonStart: d3_noop,
4552 function d3_geo_lengthLineStart() {
4553 var λ0, sinφ0, cosφ0;
4554 d3_geo_length.point = function(λ, φ) {
4555 λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
4556 d3_geo_length.point = nextPoint;
4558 d3_geo_length.lineEnd = function() {
4559 d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
4561 function nextPoint(λ, φ) {
4562 var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
4563 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Δλ);
4564 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
4567 function d3_geo_azimuthal(scale, angle) {
4568 function azimuthal(λ, φ) {
4569 var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
4570 return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
4572 azimuthal.invert = function(x, y) {
4573 var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
4574 return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
4578 var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
4579 return Math.sqrt(2 / (1 + cosλcosφ));
4581 return 2 * Math.asin(ρ / 2);
4583 (d3.geo.azimuthalEqualArea = function() {
4584 return d3_geo_projection(d3_geo_azimuthalEqualArea);
4585 }).raw = d3_geo_azimuthalEqualArea;
4586 var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
4587 var c = Math.acos(cosλcosφ);
4588 return c && c / Math.sin(c);
4590 (d3.geo.azimuthalEquidistant = function() {
4591 return d3_geo_projection(d3_geo_azimuthalEquidistant);
4592 }).raw = d3_geo_azimuthalEquidistant;
4593 function d3_geo_conicConformal(φ0, φ1) {
4594 var cosφ0 = Math.cos(φ0), t = function(φ) {
4595 return Math.tan(π / 4 + φ / 2);
4596 }, 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;
4597 if (!n) return d3_geo_mercator;
4598 function forward(λ, φ) {
4600 if (φ < -halfπ + ε) φ = -halfπ + ε;
4602 if (φ > halfπ - ε) φ = halfπ - ε;
4604 var ρ = F / Math.pow(t(φ), n);
4605 return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
4607 forward.invert = function(x, y) {
4608 var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
4609 return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
4613 (d3.geo.conicConformal = function() {
4614 return d3_geo_conic(d3_geo_conicConformal);
4615 }).raw = d3_geo_conicConformal;
4616 function d3_geo_conicEquidistant(φ0, φ1) {
4617 var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
4618 if (abs(n) < ε) return d3_geo_equirectangular;
4619 function forward(λ, φ) {
4621 return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
4623 forward.invert = function(x, y) {
4625 return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
4629 (d3.geo.conicEquidistant = function() {
4630 return d3_geo_conic(d3_geo_conicEquidistant);
4631 }).raw = d3_geo_conicEquidistant;
4632 var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
4633 return 1 / cosλcosφ;
4635 (d3.geo.gnomonic = function() {
4636 return d3_geo_projection(d3_geo_gnomonic);
4637 }).raw = d3_geo_gnomonic;
4638 function d3_geo_mercator(λ, φ) {
4639 return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
4641 d3_geo_mercator.invert = function(x, y) {
4642 return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
4644 function d3_geo_mercatorProjection(project) {
4645 var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
4646 m.scale = function() {
4647 var v = scale.apply(m, arguments);
4648 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4650 m.translate = function() {
4651 var v = translate.apply(m, arguments);
4652 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4654 m.clipExtent = function(_) {
4655 var v = clipExtent.apply(m, arguments);
4657 if (clipAuto = _ == null) {
4658 var k = π * scale(), t = translate();
4659 clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
4661 } else if (clipAuto) {
4666 return m.clipExtent(null);
4668 (d3.geo.mercator = function() {
4669 return d3_geo_mercatorProjection(d3_geo_mercator);
4670 }).raw = d3_geo_mercator;
4671 var d3_geo_orthographic = d3_geo_azimuthal(function() {
4674 (d3.geo.orthographic = function() {
4675 return d3_geo_projection(d3_geo_orthographic);
4676 }).raw = d3_geo_orthographic;
4677 var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
4678 return 1 / (1 + cosλcosφ);
4680 return 2 * Math.atan(ρ);
4682 (d3.geo.stereographic = function() {
4683 return d3_geo_projection(d3_geo_stereographic);
4684 }).raw = d3_geo_stereographic;
4685 function d3_geo_transverseMercator(λ, φ) {
4686 return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
4688 d3_geo_transverseMercator.invert = function(x, y) {
4689 return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
4691 (d3.geo.transverseMercator = function() {
4692 var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
4693 projection.center = function(_) {
4694 return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ -_[1], _[0] ]);
4696 projection.rotate = function(_) {
4697 return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
4698 [ _[0], _[1], _[2] - 90 ]);
4700 return projection.rotate([ 0, 0 ]);
4701 }).raw = d3_geo_transverseMercator;
4703 function d3_geom_pointX(d) {
4706 function d3_geom_pointY(d) {
4709 d3.geom.hull = function(vertices) {
4710 var x = d3_geom_pointX, y = d3_geom_pointY;
4711 if (arguments.length) return hull(vertices);
4712 function hull(data) {
4713 if (data.length < 3) return [];
4714 var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
4715 for (i = 0; i < n; i++) {
4716 points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
4718 points.sort(d3_geom_hullOrder);
4719 for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
4720 var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
4721 var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
4722 for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
4723 for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
4726 hull.x = function(_) {
4727 return arguments.length ? (x = _, hull) : x;
4729 hull.y = function(_) {
4730 return arguments.length ? (y = _, hull) : y;
4734 function d3_geom_hullUpper(points) {
4735 var n = points.length, hull = [ 0, 1 ], hs = 2;
4736 for (var i = 2; i < n; i++) {
4737 while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
4740 return hull.slice(0, hs);
4742 function d3_geom_hullOrder(a, b) {
4743 return a[0] - b[0] || a[1] - b[1];
4745 d3.geom.polygon = function(coordinates) {
4746 d3_subclass(coordinates, d3_geom_polygonPrototype);
4749 var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
4750 d3_geom_polygonPrototype.area = function() {
4751 var i = -1, n = this.length, a, b = this[n - 1], area = 0;
4755 area += a[1] * b[0] - a[0] * b[1];
4759 d3_geom_polygonPrototype.centroid = function(k) {
4760 var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
4761 if (!arguments.length) k = -1 / (6 * this.area());
4765 c = a[0] * b[1] - b[0] * a[1];
4766 x += (a[0] + b[0]) * c;
4767 y += (a[1] + b[1]) * c;
4769 return [ x * k, y * k ];
4771 d3_geom_polygonPrototype.clip = function(subject) {
4772 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;
4774 input = subject.slice();
4777 c = input[(m = input.length - closed) - 1];
4781 if (d3_geom_polygonInside(d, a, b)) {
4782 if (!d3_geom_polygonInside(c, a, b)) {
4783 subject.push(d3_geom_polygonIntersect(c, d, a, b));
4786 } else if (d3_geom_polygonInside(c, a, b)) {
4787 subject.push(d3_geom_polygonIntersect(c, d, a, b));
4791 if (closed) subject.push(subject[0]);
4796 function d3_geom_polygonInside(p, a, b) {
4797 return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
4799 function d3_geom_polygonIntersect(c, d, a, b) {
4800 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);
4801 return [ x1 + ua * x21, y1 + ua * y21 ];
4803 function d3_geom_polygonClosed(coordinates) {
4804 var a = coordinates[0], b = coordinates[coordinates.length - 1];
4805 return !(a[0] - b[0] || a[1] - b[1]);
4807 var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
4808 function d3_geom_voronoiBeach() {
4809 d3_geom_voronoiRedBlackNode(this);
4810 this.edge = this.site = this.circle = null;
4812 function d3_geom_voronoiCreateBeach(site) {
4813 var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
4817 function d3_geom_voronoiDetachBeach(beach) {
4818 d3_geom_voronoiDetachCircle(beach);
4819 d3_geom_voronoiBeaches.remove(beach);
4820 d3_geom_voronoiBeachPool.push(beach);
4821 d3_geom_voronoiRedBlackNode(beach);
4823 function d3_geom_voronoiRemoveBeach(beach) {
4824 var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
4827 }, previous = beach.P, next = beach.N, disappearing = [ beach ];
4828 d3_geom_voronoiDetachBeach(beach);
4829 var lArc = previous;
4830 while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
4832 disappearing.unshift(lArc);
4833 d3_geom_voronoiDetachBeach(lArc);
4836 disappearing.unshift(lArc);
4837 d3_geom_voronoiDetachCircle(lArc);
4839 while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
4841 disappearing.push(rArc);
4842 d3_geom_voronoiDetachBeach(rArc);
4845 disappearing.push(rArc);
4846 d3_geom_voronoiDetachCircle(rArc);
4847 var nArcs = disappearing.length, iArc;
4848 for (iArc = 1; iArc < nArcs; ++iArc) {
4849 rArc = disappearing[iArc];
4850 lArc = disappearing[iArc - 1];
4851 d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
4853 lArc = disappearing[0];
4854 rArc = disappearing[nArcs - 1];
4855 rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
4856 d3_geom_voronoiAttachCircle(lArc);
4857 d3_geom_voronoiAttachCircle(rArc);
4859 function d3_geom_voronoiAddBeach(site) {
4860 var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
4862 dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
4863 if (dxl > ε) node = node.L; else {
4864 dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
4875 } else if (dxr > -ε) {
4885 var newArc = d3_geom_voronoiCreateBeach(site);
4886 d3_geom_voronoiBeaches.insert(lArc, newArc);
4887 if (!lArc && !rArc) return;
4888 if (lArc === rArc) {
4889 d3_geom_voronoiDetachCircle(lArc);
4890 rArc = d3_geom_voronoiCreateBeach(lArc.site);
4891 d3_geom_voronoiBeaches.insert(newArc, rArc);
4892 newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
4893 d3_geom_voronoiAttachCircle(lArc);
4894 d3_geom_voronoiAttachCircle(rArc);
4898 newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
4901 d3_geom_voronoiDetachCircle(lArc);
4902 d3_geom_voronoiDetachCircle(rArc);
4903 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 = {
4904 x: (cy * hb - by * hc) / d + ax,
4905 y: (bx * hc - cx * hb) / d + ay
4907 d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
4908 newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
4909 rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
4910 d3_geom_voronoiAttachCircle(lArc);
4911 d3_geom_voronoiAttachCircle(rArc);
4913 function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
4914 var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
4915 if (!pby2) return rfocx;
4917 if (!lArc) return -Infinity;
4919 var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
4920 if (!plby2) return lfocx;
4921 var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
4922 if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
4923 return (rfocx + lfocx) / 2;
4925 function d3_geom_voronoiRightBreakPoint(arc, directrix) {
4927 if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
4928 var site = arc.site;
4929 return site.y === directrix ? site.x : Infinity;
4931 function d3_geom_voronoiCell(site) {
4935 d3_geom_voronoiCell.prototype.prepare = function() {
4936 var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
4937 while (iHalfEdge--) {
4938 edge = halfEdges[iHalfEdge].edge;
4939 if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
4941 halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
4942 return halfEdges.length;
4944 function d3_geom_voronoiCloseCells(extent) {
4945 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;
4947 cell = cells[iCell];
4948 if (!cell || !cell.prepare()) continue;
4949 halfEdges = cell.edges;
4950 nHalfEdges = halfEdges.length;
4952 while (iHalfEdge < nHalfEdges) {
4953 end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
4954 start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
4955 if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
4956 halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
4958 y: abs(x2 - x0) < ε ? y2 : y1
4959 } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
4960 x: abs(y2 - y1) < ε ? x2 : x1,
4962 } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
4964 y: abs(x2 - x1) < ε ? y2 : y0
4965 } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
4966 x: abs(y2 - y0) < ε ? x2 : x0,
4968 } : null), cell.site, null));
4974 function d3_geom_voronoiHalfEdgeOrder(a, b) {
4975 return b.angle - a.angle;
4977 function d3_geom_voronoiCircle() {
4978 d3_geom_voronoiRedBlackNode(this);
4979 this.x = this.y = this.arc = this.site = this.cy = null;
4981 function d3_geom_voronoiAttachCircle(arc) {
4982 var lArc = arc.P, rArc = arc.N;
4983 if (!lArc || !rArc) return;
4984 var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
4985 if (lSite === rSite) return;
4986 var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
4987 var d = 2 * (ax * cy - ay * cx);
4988 if (d >= -ε2) return;
4989 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;
4990 var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
4992 circle.site = cSite;
4994 circle.y = cy + Math.sqrt(x * x + y * y);
4996 arc.circle = circle;
4997 var before = null, node = d3_geom_voronoiCircles._;
4999 if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
5000 if (node.L) node = node.L; else {
5005 if (node.R) node = node.R; else {
5011 d3_geom_voronoiCircles.insert(before, circle);
5012 if (!before) d3_geom_voronoiFirstCircle = circle;
5014 function d3_geom_voronoiDetachCircle(arc) {
5015 var circle = arc.circle;
5017 if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
5018 d3_geom_voronoiCircles.remove(circle);
5019 d3_geom_voronoiCirclePool.push(circle);
5020 d3_geom_voronoiRedBlackNode(circle);
5024 function d3_geom_voronoiClipEdges(extent) {
5025 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;
5028 if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
5034 function d3_geom_voronoiConnectEdge(edge, extent) {
5036 if (vb) return true;
5037 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;
5039 if (fx < x0 || fx >= x1) return;
5044 }; else if (va.y >= y1) return;
5053 }; else if (va.y < y0) return;
5060 fm = (lx - rx) / (ry - ly);
5062 if (fm < -1 || fm > 1) {
5067 }; else if (va.y >= y1) return;
5076 }; else if (va.y < y0) return;
5087 }; else if (va.x >= x1) return;
5096 }; else if (va.x < x0) return;
5108 function d3_geom_voronoiEdge(lSite, rSite) {
5111 this.a = this.b = null;
5113 function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
5114 var edge = new d3_geom_voronoiEdge(lSite, rSite);
5115 d3_geom_voronoiEdges.push(edge);
5116 if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
5117 if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
5118 d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
5119 d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
5122 function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
5123 var edge = new d3_geom_voronoiEdge(lSite, null);
5126 d3_geom_voronoiEdges.push(edge);
5129 function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
5130 if (!edge.a && !edge.b) {
5134 } else if (edge.l === rSite) {
5140 function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
5141 var va = edge.a, vb = edge.b;
5144 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);
5146 d3_geom_voronoiHalfEdge.prototype = {
5148 return this.edge.l === this.site ? this.edge.a : this.edge.b;
5151 return this.edge.l === this.site ? this.edge.b : this.edge.a;
5154 function d3_geom_voronoiRedBlackTree() {
5157 function d3_geom_voronoiRedBlackNode(node) {
5158 node.U = node.C = node.L = node.R = node.P = node.N = null;
5160 d3_geom_voronoiRedBlackTree.prototype = {
5161 insert: function(after, node) {
5162 var parent, grandpa, uncle;
5166 if (after.N) after.N.P = node;
5170 while (after.L) after = after.L;
5176 } else if (this._) {
5177 after = d3_geom_voronoiRedBlackFirst(this._);
5180 after.P = after.L = node;
5183 node.P = node.N = null;
5187 node.L = node.R = null;
5191 while (parent && parent.C) {
5193 if (parent === grandpa.L) {
5195 if (uncle && uncle.C) {
5196 parent.C = uncle.C = false;
5200 if (after === parent.R) {
5201 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5207 d3_geom_voronoiRedBlackRotateRight(this, grandpa);
5211 if (uncle && uncle.C) {
5212 parent.C = uncle.C = false;
5216 if (after === parent.L) {
5217 d3_geom_voronoiRedBlackRotateRight(this, parent);
5223 d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
5230 remove: function(node) {
5231 if (node.N) node.N.P = node.P;
5232 if (node.P) node.P.N = node.N;
5233 node.N = node.P = null;
5234 var parent = node.U, sibling, left = node.L, right = node.R, next, red;
5235 if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
5237 if (parent.L === node) parent.L = next; else parent.R = next;
5241 if (left && right) {
5246 if (next !== right) {
5262 if (node) node.U = parent;
5264 if (node && node.C) {
5269 if (node === this._) break;
5270 if (node === parent.L) {
5275 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5278 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5279 if (!sibling.R || !sibling.R.C) {
5280 sibling.L.C = false;
5282 d3_geom_voronoiRedBlackRotateRight(this, sibling);
5285 sibling.C = parent.C;
5286 parent.C = sibling.R.C = false;
5287 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5296 d3_geom_voronoiRedBlackRotateRight(this, parent);
5299 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5300 if (!sibling.L || !sibling.L.C) {
5301 sibling.R.C = false;
5303 d3_geom_voronoiRedBlackRotateLeft(this, sibling);
5306 sibling.C = parent.C;
5307 parent.C = sibling.L.C = false;
5308 d3_geom_voronoiRedBlackRotateRight(this, parent);
5317 if (node) node.C = false;
5320 function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
5321 var p = node, q = node.R, parent = p.U;
5323 if (parent.L === p) parent.L = q; else parent.R = q;
5333 function d3_geom_voronoiRedBlackRotateRight(tree, node) {
5334 var p = node, q = node.L, parent = p.U;
5336 if (parent.L === p) parent.L = q; else parent.R = q;
5346 function d3_geom_voronoiRedBlackFirst(node) {
5347 while (node.L) node = node.L;
5350 function d3_geom_voronoi(sites, bbox) {
5351 var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
5352 d3_geom_voronoiEdges = [];
5353 d3_geom_voronoiCells = new Array(sites.length);
5354 d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
5355 d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
5357 circle = d3_geom_voronoiFirstCircle;
5358 if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
5359 if (site.x !== x0 || site.y !== y0) {
5360 d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
5361 d3_geom_voronoiAddBeach(site);
5362 x0 = site.x, y0 = site.y;
5365 } else if (circle) {
5366 d3_geom_voronoiRemoveBeach(circle.arc);
5371 if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
5373 cells: d3_geom_voronoiCells,
5374 edges: d3_geom_voronoiEdges
5376 d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
5379 function d3_geom_voronoiVertexOrder(a, b) {
5380 return b.y - a.y || b.x - a.x;
5382 d3.geom.voronoi = function(points) {
5383 var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
5384 if (points) return voronoi(points);
5385 function voronoi(data) {
5386 var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
5387 d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
5388 var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
5390 return [ s.x, s.y ];
5391 }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
5392 polygon.point = data[i];
5396 function sites(data) {
5397 return data.map(function(d, i) {
5399 x: Math.round(fx(d, i) / ε) * ε,
5400 y: Math.round(fy(d, i) / ε) * ε,
5405 voronoi.links = function(data) {
5406 return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
5407 return edge.l && edge.r;
5408 }).map(function(edge) {
5410 source: data[edge.l.i],
5411 target: data[edge.r.i]
5415 voronoi.triangles = function(data) {
5417 d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
5418 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;
5423 s1 = e1.l === site ? e1.r : e1.l;
5424 if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
5425 triangles.push([ data[i], data[s0.i], data[s1.i] ]);
5431 voronoi.x = function(_) {
5432 return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
5434 voronoi.y = function(_) {
5435 return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
5437 voronoi.clipExtent = function(_) {
5438 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
5439 clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
5442 voronoi.size = function(_) {
5443 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
5444 return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
5448 var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
5449 function d3_geom_voronoiTriangleArea(a, b, c) {
5450 return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
5452 d3.geom.delaunay = function(vertices) {
5453 return d3.geom.voronoi().triangles(vertices);
5455 d3.geom.quadtree = function(points, x1, y1, x2, y2) {
5456 var x = d3_geom_pointX, y = d3_geom_pointY, compat;
5457 if (compat = arguments.length) {
5458 x = d3_geom_quadtreeCompatX;
5459 y = d3_geom_quadtreeCompatY;
5465 return quadtree(points);
5467 function quadtree(data) {
5468 var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
5470 x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
5472 x2_ = y2_ = -(x1_ = y1_ = Infinity);
5475 if (compat) for (i = 0; i < n; ++i) {
5477 if (d.x < x1_) x1_ = d.x;
5478 if (d.y < y1_) y1_ = d.y;
5479 if (d.x > x2_) x2_ = d.x;
5480 if (d.y > y2_) y2_ = d.y;
5483 } else for (i = 0; i < n; ++i) {
5484 var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
5485 if (x_ < x1_) x1_ = x_;
5486 if (y_ < y1_) y1_ = y_;
5487 if (x_ > x2_) x2_ = x_;
5488 if (y_ > y2_) y2_ = y_;
5493 var dx = x2_ - x1_, dy = y2_ - y1_;
5494 if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
5495 function insert(n, d, x, y, x1, y1, x2, y2) {
5496 if (isNaN(x) || isNaN(y)) return;
5498 var nx = n.x, ny = n.y;
5500 if (abs(nx - x) + abs(ny - y) < .01) {
5501 insertChild(n, d, x, y, x1, y1, x2, y2);
5503 var nPoint = n.point;
5504 n.x = n.y = n.point = null;
5505 insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
5506 insertChild(n, d, x, y, x1, y1, x2, y2);
5509 n.x = x, n.y = y, n.point = d;
5512 insertChild(n, d, x, y, x1, y1, x2, y2);
5515 function insertChild(n, d, x, y, x1, y1, x2, y2) {
5516 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, right = x >= sx, bottom = y >= sy, i = (bottom << 1) + right;
5518 n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
5519 if (right) x1 = sx; else x2 = sx;
5520 if (bottom) y1 = sy; else y2 = sy;
5521 insert(n, d, x, y, x1, y1, x2, y2);
5523 var root = d3_geom_quadtreeNode();
5524 root.add = function(d) {
5525 insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
5527 root.visit = function(f) {
5528 d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
5533 insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
5536 } else data.forEach(root.add);
5537 xs = ys = data = d = null;
5540 quadtree.x = function(_) {
5541 return arguments.length ? (x = _, quadtree) : x;
5543 quadtree.y = function(_) {
5544 return arguments.length ? (y = _, quadtree) : y;
5546 quadtree.extent = function(_) {
5547 if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
5548 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
5552 quadtree.size = function(_) {
5553 if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
5554 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
5559 function d3_geom_quadtreeCompatX(d) {
5562 function d3_geom_quadtreeCompatY(d) {
5565 function d3_geom_quadtreeNode() {
5574 function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
5575 if (!f(node, x1, y1, x2, y2)) {
5576 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
5577 if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
5578 if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
5579 if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
5580 if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
5583 d3.interpolateRgb = d3_interpolateRgb;
5584 function d3_interpolateRgb(a, b) {
5587 var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
5588 return function(t) {
5589 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));
5592 d3.interpolateObject = d3_interpolateObject;
5593 function d3_interpolateObject(a, b) {
5594 var i = {}, c = {}, k;
5597 i[k] = d3_interpolate(a[k], b[k]);
5607 return function(t) {
5608 for (k in i) c[k] = i[k](t);
5612 d3.interpolateNumber = d3_interpolateNumber;
5613 function d3_interpolateNumber(a, b) {
5615 return function(t) {
5619 d3.interpolateString = d3_interpolateString;
5620 function d3_interpolateString(a, b) {
5621 var m, i, j, s0 = 0, s1 = 0, s = [], q = [], n, o;
5622 a = a + "", b = b + "";
5623 d3_interpolate_number.lastIndex = 0;
5624 for (i = 0; m = d3_interpolate_number.exec(b); ++i) {
5625 if (m.index) s.push(b.substring(s0, s1 = m.index));
5631 s0 = d3_interpolate_number.lastIndex;
5633 if (s0 < b.length) s.push(b.substring(s0));
5634 for (i = 0, n = q.length; (m = d3_interpolate_number.exec(a)) && i < n; ++i) {
5638 if (s[o.i + 1] == null) {
5641 for (j = i + 1; j < n; ++j) q[j].i--;
5643 s[o.i - 1] += o.x + s[o.i + 1];
5645 for (j = i + 1; j < n; ++j) q[j].i -= 2;
5648 if (s[o.i + 1] == null) {
5651 s[o.i] = o.x + s[o.i + 1];
5652 s.splice(o.i + 1, 1);
5653 for (j = i + 1; j < n; ++j) q[j].i--;
5660 o.x = d3_interpolateNumber(parseFloat(m[0]), parseFloat(o.x));
5665 if (s[o.i + 1] == null) {
5668 s[o.i] = o.x + s[o.i + 1];
5669 s.splice(o.i + 1, 1);
5673 if (s.length === 1) {
5674 return s[0] == null ? (o = q[0].x, function(t) {
5680 return function(t) {
5681 for (i = 0; i < n; ++i) s[(o = q[i]).i] = o.x(t);
5685 var d3_interpolate_number = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
5686 d3.interpolate = d3_interpolate;
5687 function d3_interpolate(a, b) {
5688 var i = d3.interpolators.length, f;
5689 while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
5692 d3.interpolators = [ function(a, b) {
5694 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);
5696 d3.interpolateArray = d3_interpolateArray;
5697 function d3_interpolateArray(a, b) {
5698 var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
5699 for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
5700 for (;i < na; ++i) c[i] = a[i];
5701 for (;i < nb; ++i) c[i] = b[i];
5702 return function(t) {
5703 for (i = 0; i < n0; ++i) c[i] = x[i](t);
5707 var d3_ease_default = function() {
5710 var d3_ease = d3.map({
5711 linear: d3_ease_default,
5714 return d3_ease_quad;
5717 return d3_ease_cubic;
5725 circle: function() {
5726 return d3_ease_circle;
5728 elastic: d3_ease_elastic,
5730 bounce: function() {
5731 return d3_ease_bounce;
5734 var d3_ease_mode = d3.map({
5736 out: d3_ease_reverse,
5737 "in-out": d3_ease_reflect,
5738 "out-in": function(f) {
5739 return d3_ease_reflect(d3_ease_reverse(f));
5742 d3.ease = function(name) {
5743 var i = name.indexOf("-"), t = i >= 0 ? name.substring(0, i) : name, m = i >= 0 ? name.substring(i + 1) : "in";
5744 t = d3_ease.get(t) || d3_ease_default;
5745 m = d3_ease_mode.get(m) || d3_identity;
5746 return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
5748 function d3_ease_clamp(f) {
5749 return function(t) {
5750 return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
5753 function d3_ease_reverse(f) {
5754 return function(t) {
5755 return 1 - f(1 - t);
5758 function d3_ease_reflect(f) {
5759 return function(t) {
5760 return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
5763 function d3_ease_quad(t) {
5766 function d3_ease_cubic(t) {
5769 function d3_ease_cubicInOut(t) {
5770 if (t <= 0) return 0;
5771 if (t >= 1) return 1;
5772 var t2 = t * t, t3 = t2 * t;
5773 return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
5775 function d3_ease_poly(e) {
5776 return function(t) {
5777 return Math.pow(t, e);
5780 function d3_ease_sin(t) {
5781 return 1 - Math.cos(t * halfπ);
5783 function d3_ease_exp(t) {
5784 return Math.pow(2, 10 * (t - 1));
5786 function d3_ease_circle(t) {
5787 return 1 - Math.sqrt(1 - t * t);
5789 function d3_ease_elastic(a, p) {
5791 if (arguments.length < 2) p = .45;
5792 if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
5793 return function(t) {
5794 return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
5797 function d3_ease_back(s) {
5798 if (!s) s = 1.70158;
5799 return function(t) {
5800 return t * t * ((s + 1) * t - s);
5803 function d3_ease_bounce(t) {
5804 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;
5806 d3.interpolateHcl = d3_interpolateHcl;
5807 function d3_interpolateHcl(a, b) {
5810 var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
5811 if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
5812 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
5813 return function(t) {
5814 return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
5817 d3.interpolateHsl = d3_interpolateHsl;
5818 function d3_interpolateHsl(a, b) {
5821 var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
5822 if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
5823 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
5824 return function(t) {
5825 return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
5828 d3.interpolateLab = d3_interpolateLab;
5829 function d3_interpolateLab(a, b) {
5832 var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
5833 return function(t) {
5834 return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
5837 d3.interpolateRound = d3_interpolateRound;
5838 function d3_interpolateRound(a, b) {
5840 return function(t) {
5841 return Math.round(a + b * t);
5844 d3.transform = function(string) {
5845 var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
5846 return (d3.transform = function(string) {
5847 if (string != null) {
5848 g.setAttribute("transform", string);
5849 var t = g.transform.baseVal.consolidate();
5851 return new d3_transform(t ? t.matrix : d3_transformIdentity);
5854 function d3_transform(m) {
5855 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;
5856 if (r0[0] * r1[1] < r1[0] * r0[1]) {
5862 this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
5863 this.translate = [ m.e, m.f ];
5864 this.scale = [ kx, ky ];
5865 this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
5867 d3_transform.prototype.toString = function() {
5868 return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
5870 function d3_transformDot(a, b) {
5871 return a[0] * b[0] + a[1] * b[1];
5873 function d3_transformNormalize(a) {
5874 var k = Math.sqrt(d3_transformDot(a, a));
5881 function d3_transformCombine(a, b, k) {
5886 var d3_transformIdentity = {
5894 d3.interpolateTransform = d3_interpolateTransform;
5895 function d3_interpolateTransform(a, b) {
5896 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;
5897 if (ta[0] != tb[0] || ta[1] != tb[1]) {
5898 s.push("translate(", null, ",", null, ")");
5901 x: d3_interpolateNumber(ta[0], tb[0])
5904 x: d3_interpolateNumber(ta[1], tb[1])
5906 } else if (tb[0] || tb[1]) {
5907 s.push("translate(" + tb + ")");
5912 if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
5914 i: s.push(s.pop() + "rotate(", null, ")") - 2,
5915 x: d3_interpolateNumber(ra, rb)
5918 s.push(s.pop() + "rotate(" + rb + ")");
5922 i: s.push(s.pop() + "skewX(", null, ")") - 2,
5923 x: d3_interpolateNumber(wa, wb)
5926 s.push(s.pop() + "skewX(" + wb + ")");
5928 if (ka[0] != kb[0] || ka[1] != kb[1]) {
5929 n = s.push(s.pop() + "scale(", null, ",", null, ")");
5932 x: d3_interpolateNumber(ka[0], kb[0])
5935 x: d3_interpolateNumber(ka[1], kb[1])
5937 } else if (kb[0] != 1 || kb[1] != 1) {
5938 s.push(s.pop() + "scale(" + kb + ")");
5941 return function(t) {
5943 while (++i < n) s[(o = q[i]).i] = o.x(t);
5947 function d3_uninterpolateNumber(a, b) {
5948 b = b - (a = +a) ? 1 / (b - a) : 0;
5949 return function(x) {
5953 function d3_uninterpolateClamp(a, b) {
5954 b = b - (a = +a) ? 1 / (b - a) : 0;
5955 return function(x) {
5956 return Math.max(0, Math.min(1, (x - a) * b));
5960 d3.layout.bundle = function() {
5961 return function(links) {
5962 var paths = [], i = -1, n = links.length;
5963 while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
5967 function d3_layout_bundlePath(link) {
5968 var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
5969 while (start !== lca) {
5970 start = start.parent;
5973 var k = points.length;
5974 while (end !== lca) {
5975 points.splice(k, 0, end);
5980 function d3_layout_bundleAncestors(node) {
5981 var ancestors = [], parent = node.parent;
5982 while (parent != null) {
5983 ancestors.push(node);
5985 parent = parent.parent;
5987 ancestors.push(node);
5990 function d3_layout_bundleLeastCommonAncestor(a, b) {
5991 if (a === b) return a;
5992 var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
5993 while (aNode === bNode) {
5995 aNode = aNodes.pop();
5996 bNode = bNodes.pop();
6000 d3.layout.chord = function() {
6001 var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
6002 function relayout() {
6003 var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
6013 subgroupIndex.push(d3.range(n));
6017 groupIndex.sort(function(a, b) {
6018 return sortGroups(groupSums[a], groupSums[b]);
6021 if (sortSubgroups) {
6022 subgroupIndex.forEach(function(d, i) {
6023 d.sort(function(a, b) {
6024 return sortSubgroups(matrix[i][a], matrix[i][b]);
6028 k = (τ - padding * n) / k;
6033 var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
6034 subgroups[di + "-" + dj] = {
6054 var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
6055 if (source.value || target.value) {
6056 chords.push(source.value < target.value ? {
6066 if (sortChords) resort();
6069 chords.sort(function(a, b) {
6070 return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
6073 chord.matrix = function(x) {
6074 if (!arguments.length) return matrix;
6075 n = (matrix = x) && matrix.length;
6076 chords = groups = null;
6079 chord.padding = function(x) {
6080 if (!arguments.length) return padding;
6082 chords = groups = null;
6085 chord.sortGroups = function(x) {
6086 if (!arguments.length) return sortGroups;
6088 chords = groups = null;
6091 chord.sortSubgroups = function(x) {
6092 if (!arguments.length) return sortSubgroups;
6097 chord.sortChords = function(x) {
6098 if (!arguments.length) return sortChords;
6100 if (chords) resort();
6103 chord.chords = function() {
6104 if (!chords) relayout();
6107 chord.groups = function() {
6108 if (!groups) relayout();
6113 d3.layout.force = function() {
6114 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;
6115 function repulse(node) {
6116 return function(quad, x1, _, x2) {
6117 if (quad.point !== node) {
6118 var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
6119 if (dw * dw / theta2 < dn) {
6120 if (dn < chargeDistance2) {
6121 var k = quad.charge / dn;
6127 if (quad.point && dn && dn < chargeDistance2) {
6128 var k = quad.pointCharge / dn;
6133 return !quad.charge;
6136 force.tick = function() {
6137 if ((alpha *= .99) < .005) {
6144 var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
6145 for (i = 0; i < m; ++i) {
6151 if (l = x * x + y * y) {
6152 l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
6155 t.x -= x * (k = s.weight / (t.weight + s.weight));
6157 s.x += x * (k = 1 - k);
6161 if (k = alpha * gravity) {
6165 if (k) while (++i < n) {
6167 o.x += (x - o.x) * k;
6168 o.y += (y - o.y) * k;
6172 d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
6175 if (!(o = nodes[i]).fixed) {
6176 q.visit(repulse(o));
6187 o.x -= (o.px - (o.px = o.x)) * friction;
6188 o.y -= (o.py - (o.py = o.y)) * friction;
6196 force.nodes = function(x) {
6197 if (!arguments.length) return nodes;
6201 force.links = function(x) {
6202 if (!arguments.length) return links;
6206 force.size = function(x) {
6207 if (!arguments.length) return size;
6211 force.linkDistance = function(x) {
6212 if (!arguments.length) return linkDistance;
6213 linkDistance = typeof x === "function" ? x : +x;
6216 force.distance = force.linkDistance;
6217 force.linkStrength = function(x) {
6218 if (!arguments.length) return linkStrength;
6219 linkStrength = typeof x === "function" ? x : +x;
6222 force.friction = function(x) {
6223 if (!arguments.length) return friction;
6227 force.charge = function(x) {
6228 if (!arguments.length) return charge;
6229 charge = typeof x === "function" ? x : +x;
6232 force.chargeDistance = function(x) {
6233 if (!arguments.length) return Math.sqrt(chargeDistance2);
6234 chargeDistance2 = x * x;
6237 force.gravity = function(x) {
6238 if (!arguments.length) return gravity;
6242 force.theta = function(x) {
6243 if (!arguments.length) return Math.sqrt(theta2);
6247 force.alpha = function(x) {
6248 if (!arguments.length) return alpha;
6251 if (x > 0) alpha = x; else alpha = 0;
6257 d3.timer(force.tick);
6261 force.start = function() {
6262 var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
6263 for (i = 0; i < n; ++i) {
6264 (o = nodes[i]).index = i;
6267 for (i = 0; i < m; ++i) {
6269 if (typeof o.source == "number") o.source = nodes[o.source];
6270 if (typeof o.target == "number") o.target = nodes[o.target];
6274 for (i = 0; i < n; ++i) {
6276 if (isNaN(o.x)) o.x = position("x", w);
6277 if (isNaN(o.y)) o.y = position("y", h);
6278 if (isNaN(o.px)) o.px = o.x;
6279 if (isNaN(o.py)) o.py = o.y;
6282 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;
6284 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;
6286 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;
6287 function position(dimension, size) {
6289 neighbors = new Array(n);
6290 for (j = 0; j < n; ++j) {
6293 for (j = 0; j < m; ++j) {
6295 neighbors[o.source.index].push(o.target);
6296 neighbors[o.target.index].push(o.source);
6299 var candidates = neighbors[i], j = -1, m = candidates.length, x;
6300 while (++j < m) if (!isNaN(x = candidates[j][dimension])) return x;
6301 return Math.random() * size;
6303 return force.resume();
6305 force.resume = function() {
6306 return force.alpha(.1);
6308 force.stop = function() {
6309 return force.alpha(0);
6311 force.drag = function() {
6312 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);
6313 if (!arguments.length) return drag;
6314 this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
6316 function dragmove(d) {
6317 d.px = d3.event.x, d.py = d3.event.y;
6320 return d3.rebind(force, event, "on");
6322 function d3_layout_forceDragstart(d) {
6325 function d3_layout_forceDragend(d) {
6328 function d3_layout_forceMouseover(d) {
6330 d.px = d.x, d.py = d.y;
6332 function d3_layout_forceMouseout(d) {
6335 function d3_layout_forceAccumulate(quad, alpha, charges) {
6339 var nodes = quad.nodes, n = nodes.length, i = -1, c;
6342 if (c == null) continue;
6343 d3_layout_forceAccumulate(c, alpha, charges);
6344 quad.charge += c.charge;
6345 cx += c.charge * c.cx;
6346 cy += c.charge * c.cy;
6351 quad.point.x += Math.random() - .5;
6352 quad.point.y += Math.random() - .5;
6354 var k = alpha * charges[quad.point.index];
6355 quad.charge += quad.pointCharge = k;
6356 cx += k * quad.point.x;
6357 cy += k * quad.point.y;
6359 quad.cx = cx / quad.charge;
6360 quad.cy = cy / quad.charge;
6362 var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
6363 d3.layout.hierarchy = function() {
6364 var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
6365 function recurse(node, depth, nodes) {
6366 var childs = children.call(hierarchy, node, depth);
6369 if (childs && (n = childs.length)) {
6370 var i = -1, n, c = node.children = new Array(n), v = 0, j = depth + 1, d;
6372 d = c[i] = recurse(childs[i], j, nodes);
6376 if (sort) c.sort(sort);
6377 if (value) node.value = v;
6379 delete node.children;
6381 node.value = +value.call(hierarchy, node, depth) || 0;
6386 function revalue(node, depth) {
6387 var children = node.children, v = 0;
6388 if (children && (n = children.length)) {
6389 var i = -1, n, j = depth + 1;
6390 while (++i < n) v += revalue(children[i], j);
6392 v = +value.call(hierarchy, node, depth) || 0;
6394 if (value) node.value = v;
6397 function hierarchy(d) {
6399 recurse(d, 0, nodes);
6402 hierarchy.sort = function(x) {
6403 if (!arguments.length) return sort;
6407 hierarchy.children = function(x) {
6408 if (!arguments.length) return children;
6412 hierarchy.value = function(x) {
6413 if (!arguments.length) return value;
6417 hierarchy.revalue = function(root) {
6423 function d3_layout_hierarchyRebind(object, hierarchy) {
6424 d3.rebind(object, hierarchy, "sort", "children", "value");
6425 object.nodes = object;
6426 object.links = d3_layout_hierarchyLinks;
6429 function d3_layout_hierarchyChildren(d) {
6432 function d3_layout_hierarchyValue(d) {
6435 function d3_layout_hierarchySort(a, b) {
6436 return b.value - a.value;
6438 function d3_layout_hierarchyLinks(nodes) {
6439 return d3.merge(nodes.map(function(parent) {
6440 return (parent.children || []).map(function(child) {
6448 d3.layout.partition = function() {
6449 var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
6450 function position(node, x, dx, dy) {
6451 var children = node.children;
6453 node.y = node.depth * dy;
6456 if (children && (n = children.length)) {
6457 var i = -1, n, c, d;
6458 dx = node.value ? dx / node.value : 0;
6460 position(c = children[i], x, d = c.value * dx, dy);
6465 function depth(node) {
6466 var children = node.children, d = 0;
6467 if (children && (n = children.length)) {
6469 while (++i < n) d = Math.max(d, depth(children[i]));
6473 function partition(d, i) {
6474 var nodes = hierarchy.call(this, d, i);
6475 position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
6478 partition.size = function(x) {
6479 if (!arguments.length) return size;
6483 return d3_layout_hierarchyRebind(partition, hierarchy);
6485 d3.layout.pie = function() {
6486 var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ;
6487 function pie(data) {
6488 var values = data.map(function(d, i) {
6489 return +value.call(pie, d, i);
6491 var a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle);
6492 var k = ((typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a) / d3.sum(values);
6493 var index = d3.range(data.length);
6494 if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
6495 return values[j] - values[i];
6496 } : function(i, j) {
6497 return sort(data[i], data[j]);
6500 index.forEach(function(i) {
6504 value: d = values[i],
6506 endAngle: a += d * k
6511 pie.value = function(x) {
6512 if (!arguments.length) return value;
6516 pie.sort = function(x) {
6517 if (!arguments.length) return sort;
6521 pie.startAngle = function(x) {
6522 if (!arguments.length) return startAngle;
6526 pie.endAngle = function(x) {
6527 if (!arguments.length) return endAngle;
6533 var d3_layout_pieSortByValue = {};
6534 d3.layout.stack = function() {
6535 var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
6536 function stack(data, index) {
6537 var series = data.map(function(d, i) {
6538 return values.call(stack, d, i);
6540 var points = series.map(function(d) {
6541 return d.map(function(v, i) {
6542 return [ x.call(stack, v, i), y.call(stack, v, i) ];
6545 var orders = order.call(stack, points, index);
6546 series = d3.permute(series, orders);
6547 points = d3.permute(points, orders);
6548 var offsets = offset.call(stack, points, index);
6549 var n = series.length, m = series[0].length, i, j, o;
6550 for (j = 0; j < m; ++j) {
6551 out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
6552 for (i = 1; i < n; ++i) {
6553 out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
6558 stack.values = function(x) {
6559 if (!arguments.length) return values;
6563 stack.order = function(x) {
6564 if (!arguments.length) return order;
6565 order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
6568 stack.offset = function(x) {
6569 if (!arguments.length) return offset;
6570 offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
6573 stack.x = function(z) {
6574 if (!arguments.length) return x;
6578 stack.y = function(z) {
6579 if (!arguments.length) return y;
6583 stack.out = function(z) {
6584 if (!arguments.length) return out;
6590 function d3_layout_stackX(d) {
6593 function d3_layout_stackY(d) {
6596 function d3_layout_stackOut(d, y0, y) {
6600 var d3_layout_stackOrders = d3.map({
6601 "inside-out": function(data) {
6602 var n = data.length, i, j, max = data.map(d3_layout_stackMaxIndex), sums = data.map(d3_layout_stackReduceSum), index = d3.range(n).sort(function(a, b) {
6603 return max[a] - max[b];
6604 }), top = 0, bottom = 0, tops = [], bottoms = [];
6605 for (i = 0; i < n; ++i) {
6615 return bottoms.reverse().concat(tops);
6617 reverse: function(data) {
6618 return d3.range(data.length).reverse();
6620 "default": d3_layout_stackOrderDefault
6622 var d3_layout_stackOffsets = d3.map({
6623 silhouette: function(data) {
6624 var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
6625 for (j = 0; j < m; ++j) {
6626 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
6627 if (o > max) max = o;
6630 for (j = 0; j < m; ++j) {
6631 y0[j] = (max - sums[j]) / 2;
6635 wiggle: function(data) {
6636 var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
6638 for (j = 1; j < m; ++j) {
6639 for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
6640 for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
6641 for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
6642 s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
6644 s2 += s3 * data[i][j][1];
6646 y0[j] = o -= s1 ? s2 / s1 * dx : 0;
6649 for (j = 0; j < m; ++j) y0[j] -= o0;
6652 expand: function(data) {
6653 var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
6654 for (j = 0; j < m; ++j) {
6655 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
6656 if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; else for (i = 0; i < n; i++) data[i][j][1] = k;
6658 for (j = 0; j < m; ++j) y0[j] = 0;
6661 zero: d3_layout_stackOffsetZero
6663 function d3_layout_stackOrderDefault(data) {
6664 return d3.range(data.length);
6666 function d3_layout_stackOffsetZero(data) {
6667 var j = -1, m = data[0].length, y0 = [];
6668 while (++j < m) y0[j] = 0;
6671 function d3_layout_stackMaxIndex(array) {
6672 var i = 1, j = 0, v = array[0][1], k, n = array.length;
6674 if ((k = array[i][1]) > v) {
6681 function d3_layout_stackReduceSum(d) {
6682 return d.reduce(d3_layout_stackSum, 0);
6684 function d3_layout_stackSum(p, d) {
6687 d3.layout.histogram = function() {
6688 var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
6689 function histogram(data, i) {
6690 var bins = [], values = data.map(valuer, this), range = ranger.call(this, values, i), thresholds = binner.call(this, range, values, i), bin, i = -1, n = values.length, m = thresholds.length - 1, k = frequency ? 1 : 1 / n, x;
6693 bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
6700 if (x >= range[0] && x <= range[1]) {
6701 bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
6709 histogram.value = function(x) {
6710 if (!arguments.length) return valuer;
6714 histogram.range = function(x) {
6715 if (!arguments.length) return ranger;
6716 ranger = d3_functor(x);
6719 histogram.bins = function(x) {
6720 if (!arguments.length) return binner;
6721 binner = typeof x === "number" ? function(range) {
6722 return d3_layout_histogramBinFixed(range, x);
6726 histogram.frequency = function(x) {
6727 if (!arguments.length) return frequency;
6733 function d3_layout_histogramBinSturges(range, values) {
6734 return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
6736 function d3_layout_histogramBinFixed(range, n) {
6737 var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
6738 while (++x <= n) f[x] = m * x + b;
6741 function d3_layout_histogramRange(values) {
6742 return [ d3.min(values), d3.max(values) ];
6744 d3.layout.tree = function() {
6745 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
6746 function tree(d, i) {
6747 var nodes = hierarchy.call(this, d, i), root = nodes[0];
6748 function firstWalk(node, previousSibling) {
6749 var children = node.children, layout = node._tree;
6750 if (children && (n = children.length)) {
6751 var n, firstChild = children[0], previousChild, ancestor = firstChild, child, i = -1;
6753 child = children[i];
6754 firstWalk(child, previousChild);
6755 ancestor = apportion(child, previousChild, ancestor);
6756 previousChild = child;
6758 d3_layout_treeShift(node);
6759 var midpoint = .5 * (firstChild._tree.prelim + child._tree.prelim);
6760 if (previousSibling) {
6761 layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
6762 layout.mod = layout.prelim - midpoint;
6764 layout.prelim = midpoint;
6767 if (previousSibling) {
6768 layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
6772 function secondWalk(node, x) {
6773 node.x = node._tree.prelim + x;
6774 var children = node.children;
6775 if (children && (n = children.length)) {
6777 x += node._tree.mod;
6779 secondWalk(children[i], x);
6783 function apportion(node, previousSibling, ancestor) {
6784 if (previousSibling) {
6785 var vip = node, vop = node, vim = previousSibling, vom = node.parent.children[0], sip = vip._tree.mod, sop = vop._tree.mod, sim = vim._tree.mod, som = vom._tree.mod, shift;
6786 while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
6787 vom = d3_layout_treeLeft(vom);
6788 vop = d3_layout_treeRight(vop);
6789 vop._tree.ancestor = node;
6790 shift = vim._tree.prelim + sim - vip._tree.prelim - sip + separation(vim, vip);
6792 d3_layout_treeMove(d3_layout_treeAncestor(vim, node, ancestor), node, shift);
6796 sim += vim._tree.mod;
6797 sip += vip._tree.mod;
6798 som += vom._tree.mod;
6799 sop += vop._tree.mod;
6801 if (vim && !d3_layout_treeRight(vop)) {
6802 vop._tree.thread = vim;
6803 vop._tree.mod += sim - sop;
6805 if (vip && !d3_layout_treeLeft(vom)) {
6806 vom._tree.thread = vip;
6807 vom._tree.mod += sip - som;
6813 d3_layout_treeVisitAfter(root, function(node, previousSibling) {
6820 number: previousSibling ? previousSibling._tree.number + 1 : 0
6824 secondWalk(root, -root._tree.prelim);
6825 var left = d3_layout_treeSearch(root, d3_layout_treeLeftmost), right = d3_layout_treeSearch(root, d3_layout_treeRightmost), deep = d3_layout_treeSearch(root, d3_layout_treeDeepest), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2, y1 = deep.depth || 1;
6826 d3_layout_treeVisitAfter(root, nodeSize ? function(node) {
6828 node.y = node.depth * size[1];
6830 } : function(node) {
6831 node.x = (node.x - x0) / (x1 - x0) * size[0];
6832 node.y = node.depth / y1 * size[1];
6837 tree.separation = function(x) {
6838 if (!arguments.length) return separation;
6842 tree.size = function(x) {
6843 if (!arguments.length) return nodeSize ? null : size;
6844 nodeSize = (size = x) == null;
6847 tree.nodeSize = function(x) {
6848 if (!arguments.length) return nodeSize ? size : null;
6849 nodeSize = (size = x) != null;
6852 return d3_layout_hierarchyRebind(tree, hierarchy);
6854 function d3_layout_treeSeparation(a, b) {
6855 return a.parent == b.parent ? 1 : 2;
6857 function d3_layout_treeLeft(node) {
6858 var children = node.children;
6859 return children && children.length ? children[0] : node._tree.thread;
6861 function d3_layout_treeRight(node) {
6862 var children = node.children, n;
6863 return children && (n = children.length) ? children[n - 1] : node._tree.thread;
6865 function d3_layout_treeSearch(node, compare) {
6866 var children = node.children;
6867 if (children && (n = children.length)) {
6868 var child, n, i = -1;
6870 if (compare(child = d3_layout_treeSearch(children[i], compare), node) > 0) {
6877 function d3_layout_treeRightmost(a, b) {
6880 function d3_layout_treeLeftmost(a, b) {
6883 function d3_layout_treeDeepest(a, b) {
6884 return a.depth - b.depth;
6886 function d3_layout_treeVisitAfter(node, callback) {
6887 function visit(node, previousSibling) {
6888 var children = node.children;
6889 if (children && (n = children.length)) {
6890 var child, previousChild = null, i = -1, n;
6892 child = children[i];
6893 visit(child, previousChild);
6894 previousChild = child;
6897 callback(node, previousSibling);
6901 function d3_layout_treeShift(node) {
6902 var shift = 0, change = 0, children = node.children, i = children.length, child;
6904 child = children[i]._tree;
6905 child.prelim += shift;
6907 shift += child.shift + (change += child.change);
6910 function d3_layout_treeMove(ancestor, node, shift) {
6911 ancestor = ancestor._tree;
6913 var change = shift / (node.number - ancestor.number);
6914 ancestor.change += change;
6915 node.change -= change;
6916 node.shift += shift;
6917 node.prelim += shift;
6920 function d3_layout_treeAncestor(vim, node, ancestor) {
6921 return vim._tree.ancestor.parent == node.parent ? vim._tree.ancestor : ancestor;
6923 d3.layout.pack = function() {
6924 var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
6925 function pack(d, i) {
6926 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() {
6929 root.x = root.y = 0;
6930 d3_layout_treeVisitAfter(root, function(d) {
6933 d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
6935 var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
6936 d3_layout_treeVisitAfter(root, function(d) {
6939 d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
6940 d3_layout_treeVisitAfter(root, function(d) {
6944 d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
6947 pack.size = function(_) {
6948 if (!arguments.length) return size;
6952 pack.radius = function(_) {
6953 if (!arguments.length) return radius;
6954 radius = _ == null || typeof _ === "function" ? _ : +_;
6957 pack.padding = function(_) {
6958 if (!arguments.length) return padding;
6962 return d3_layout_hierarchyRebind(pack, hierarchy);
6964 function d3_layout_packSort(a, b) {
6965 return a.value - b.value;
6967 function d3_layout_packInsert(a, b) {
6968 var c = a._pack_next;
6974 function d3_layout_packSplice(a, b) {
6978 function d3_layout_packIntersects(a, b) {
6979 var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
6980 return .999 * dr * dr > dx * dx + dy * dy;
6982 function d3_layout_packSiblings(node) {
6983 if (!(nodes = node.children) || !(n = nodes.length)) return;
6984 var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
6985 function bound(node) {
6986 xMin = Math.min(node.x - node.r, xMin);
6987 xMax = Math.max(node.x + node.r, xMax);
6988 yMin = Math.min(node.y - node.r, yMin);
6989 yMax = Math.max(node.y + node.r, yMax);
6991 nodes.forEach(d3_layout_packLink);
7003 d3_layout_packPlace(a, b, c);
7005 d3_layout_packInsert(a, c);
7007 d3_layout_packInsert(c, b);
7009 for (i = 3; i < n; i++) {
7010 d3_layout_packPlace(a, b, c = nodes[i]);
7011 var isect = 0, s1 = 1, s2 = 1;
7012 for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
7013 if (d3_layout_packIntersects(j, c)) {
7019 for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
7020 if (d3_layout_packIntersects(k, c)) {
7026 if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
7029 d3_layout_packInsert(a, c);
7036 var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
7037 for (i = 0; i < n; i++) {
7041 cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
7044 nodes.forEach(d3_layout_packUnlink);
7046 function d3_layout_packLink(node) {
7047 node._pack_next = node._pack_prev = node;
7049 function d3_layout_packUnlink(node) {
7050 delete node._pack_next;
7051 delete node._pack_prev;
7053 function d3_layout_packTransform(node, x, y, k) {
7054 var children = node.children;
7055 node.x = x += k * node.x;
7056 node.y = y += k * node.y;
7059 var i = -1, n = children.length;
7060 while (++i < n) d3_layout_packTransform(children[i], x, y, k);
7063 function d3_layout_packPlace(a, b, c) {
7064 var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
7065 if (db && (dx || dy)) {
7066 var da = b.r + c.r, dc = dx * dx + dy * dy;
7069 var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
7070 c.x = a.x + x * dx + y * dy;
7071 c.y = a.y + x * dy - y * dx;
7077 d3.layout.cluster = function() {
7078 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
7079 function cluster(d, i) {
7080 var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
7081 d3_layout_treeVisitAfter(root, function(node) {
7082 var children = node.children;
7083 if (children && children.length) {
7084 node.x = d3_layout_clusterX(children);
7085 node.y = d3_layout_clusterY(children);
7087 node.x = previousNode ? x += separation(node, previousNode) : 0;
7089 previousNode = node;
7092 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;
7093 d3_layout_treeVisitAfter(root, nodeSize ? function(node) {
7094 node.x = (node.x - root.x) * size[0];
7095 node.y = (root.y - node.y) * size[1];
7096 } : function(node) {
7097 node.x = (node.x - x0) / (x1 - x0) * size[0];
7098 node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
7102 cluster.separation = function(x) {
7103 if (!arguments.length) return separation;
7107 cluster.size = function(x) {
7108 if (!arguments.length) return nodeSize ? null : size;
7109 nodeSize = (size = x) == null;
7112 cluster.nodeSize = function(x) {
7113 if (!arguments.length) return nodeSize ? size : null;
7114 nodeSize = (size = x) != null;
7117 return d3_layout_hierarchyRebind(cluster, hierarchy);
7119 function d3_layout_clusterY(children) {
7120 return 1 + d3.max(children, function(child) {
7124 function d3_layout_clusterX(children) {
7125 return children.reduce(function(x, child) {
7127 }, 0) / children.length;
7129 function d3_layout_clusterLeft(node) {
7130 var children = node.children;
7131 return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
7133 function d3_layout_clusterRight(node) {
7134 var children = node.children, n;
7135 return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
7137 d3.layout.treemap = function() {
7138 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));
7139 function scale(children, k) {
7140 var i = -1, n = children.length, child, area;
7142 area = (child = children[i]).value * (k < 0 ? 0 : k);
7143 child.area = isNaN(area) || area <= 0 ? 0 : area;
7146 function squarify(node) {
7147 var children = node.children;
7148 if (children && children.length) {
7149 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;
7150 scale(remaining, rect.dx * rect.dy / node.value);
7152 while ((n = remaining.length) > 0) {
7153 row.push(child = remaining[n - 1]);
7154 row.area += child.area;
7155 if (mode !== "squarify" || (score = worst(row, u)) <= best) {
7159 row.area -= row.pop().area;
7160 position(row, u, rect, false);
7161 u = Math.min(rect.dx, rect.dy);
7162 row.length = row.area = 0;
7167 position(row, u, rect, true);
7168 row.length = row.area = 0;
7170 children.forEach(squarify);
7173 function stickify(node) {
7174 var children = node.children;
7175 if (children && children.length) {
7176 var rect = pad(node), remaining = children.slice(), child, row = [];
7177 scale(remaining, rect.dx * rect.dy / node.value);
7179 while (child = remaining.pop()) {
7181 row.area += child.area;
7182 if (child.z != null) {
7183 position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
7184 row.length = row.area = 0;
7187 children.forEach(stickify);
7190 function worst(row, u) {
7191 var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
7193 if (!(r = row[i].area)) continue;
7194 if (r < rmin) rmin = r;
7195 if (r > rmax) rmax = r;
7199 return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
7201 function position(row, u, rect, flush) {
7202 var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
7204 if (flush || v > rect.dy) v = rect.dy;
7210 x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
7213 o.dx += rect.x + rect.dx - x;
7217 if (flush || v > rect.dx) v = rect.dx;
7223 y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
7226 o.dy += rect.y + rect.dy - y;
7231 function treemap(d) {
7232 var nodes = stickies || hierarchy(d), root = nodes[0];
7237 if (stickies) hierarchy.revalue(root);
7238 scale([ root ], root.dx * root.dy / root.value);
7239 (stickies ? stickify : squarify)(root);
7240 if (sticky) stickies = nodes;
7243 treemap.size = function(x) {
7244 if (!arguments.length) return size;
7248 treemap.padding = function(x) {
7249 if (!arguments.length) return padding;
7250 function padFunction(node) {
7251 var p = x.call(treemap, node, node.depth);
7252 return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
7254 function padConstant(node) {
7255 return d3_layout_treemapPad(node, x);
7258 pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
7259 padConstant) : padConstant;
7262 treemap.round = function(x) {
7263 if (!arguments.length) return round != Number;
7264 round = x ? Math.round : Number;
7267 treemap.sticky = function(x) {
7268 if (!arguments.length) return sticky;
7273 treemap.ratio = function(x) {
7274 if (!arguments.length) return ratio;
7278 treemap.mode = function(x) {
7279 if (!arguments.length) return mode;
7283 return d3_layout_hierarchyRebind(treemap, hierarchy);
7285 function d3_layout_treemapPadNull(node) {
7293 function d3_layout_treemapPad(node, padding) {
7294 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];
7311 normal: function(µ, σ) {
7312 var n = arguments.length;
7318 x = Math.random() * 2 - 1;
7319 y = Math.random() * 2 - 1;
7321 } while (!r || r > 1);
7322 return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
7325 logNormal: function() {
7326 var random = d3.random.normal.apply(d3, arguments);
7328 return Math.exp(random());
7331 bates: function(m) {
7332 var random = d3.random.irwinHall(m);
7334 return random() / m;
7337 irwinHall: function(m) {
7339 for (var s = 0, j = 0; j < m; j++) s += Math.random();
7345 function d3_scaleExtent(domain) {
7346 var start = domain[0], stop = domain[domain.length - 1];
7347 return start < stop ? [ start, stop ] : [ stop, start ];
7349 function d3_scaleRange(scale) {
7350 return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
7352 function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
7353 var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
7354 return function(x) {
7358 function d3_scale_nice(domain, nice) {
7359 var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
7361 dx = i0, i0 = i1, i1 = dx;
7362 dx = x0, x0 = x1, x1 = dx;
7364 domain[i0] = nice.floor(x0);
7365 domain[i1] = nice.ceil(x1);
7368 function d3_scale_niceStep(step) {
7370 floor: function(x) {
7371 return Math.floor(x / step) * step;
7374 return Math.ceil(x / step) * step;
7376 } : d3_scale_niceIdentity;
7378 var d3_scale_niceIdentity = {
7382 function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
7383 var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
7384 if (domain[k] < domain[0]) {
7385 domain = domain.slice().reverse();
7386 range = range.slice().reverse();
7389 u.push(uninterpolate(domain[j - 1], domain[j]));
7390 i.push(interpolate(range[j - 1], range[j]));
7392 return function(x) {
7393 var j = d3.bisect(domain, x, 1, k) - 1;
7394 return i[j](u[j](x));
7397 d3.scale.linear = function() {
7398 return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
7400 function d3_scale_linear(domain, range, interpolate, clamp) {
7402 function rescale() {
7403 var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
7404 output = linear(domain, range, uninterpolate, interpolate);
7405 input = linear(range, domain, uninterpolate, d3_interpolate);
7411 scale.invert = function(y) {
7414 scale.domain = function(x) {
7415 if (!arguments.length) return domain;
7416 domain = x.map(Number);
7419 scale.range = function(x) {
7420 if (!arguments.length) return range;
7424 scale.rangeRound = function(x) {
7425 return scale.range(x).interpolate(d3_interpolateRound);
7427 scale.clamp = function(x) {
7428 if (!arguments.length) return clamp;
7432 scale.interpolate = function(x) {
7433 if (!arguments.length) return interpolate;
7437 scale.ticks = function(m) {
7438 return d3_scale_linearTicks(domain, m);
7440 scale.tickFormat = function(m, format) {
7441 return d3_scale_linearTickFormat(domain, m, format);
7443 scale.nice = function(m) {
7444 d3_scale_linearNice(domain, m);
7447 scale.copy = function() {
7448 return d3_scale_linear(domain, range, interpolate, clamp);
7452 function d3_scale_linearRebind(scale, linear) {
7453 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
7455 function d3_scale_linearNice(domain, m) {
7456 return d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
7458 function d3_scale_linearTickRange(domain, m) {
7459 if (m == null) m = 10;
7460 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;
7461 if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
7462 extent[0] = Math.ceil(extent[0] / step) * step;
7463 extent[1] = Math.floor(extent[1] / step) * step + step * .5;
7467 function d3_scale_linearTicks(domain, m) {
7468 return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
7470 function d3_scale_linearTickFormat(domain, m, format) {
7471 var range = d3_scale_linearTickRange(domain, m);
7473 var match = d3_format_re.exec(format);
7475 if (match[8] === "s") {
7476 var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
7477 if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
7479 format = d3.format(match.join(""));
7480 return function(d) {
7481 return format(prefix.scale(d)) + prefix.symbol;
7484 if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
7485 format = match.join("");
7487 format = ",." + d3_scale_linearPrecision(range[2]) + "f";
7489 return d3.format(format);
7491 var d3_scale_linearFormatSignificant = {
7498 function d3_scale_linearPrecision(value) {
7499 return -Math.floor(Math.log(value) / Math.LN10 + .01);
7501 function d3_scale_linearFormatPrecision(type, range) {
7502 var p = d3_scale_linearPrecision(range[2]);
7503 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;
7505 d3.scale.log = function() {
7506 return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
7508 function d3_scale_log(linear, base, positive, domain) {
7510 return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
7513 return positive ? Math.pow(base, x) : -Math.pow(base, -x);
7516 return linear(log(x));
7518 scale.invert = function(x) {
7519 return pow(linear.invert(x));
7521 scale.domain = function(x) {
7522 if (!arguments.length) return domain;
7523 positive = x[0] >= 0;
7524 linear.domain((domain = x.map(Number)).map(log));
7527 scale.base = function(_) {
7528 if (!arguments.length) return base;
7530 linear.domain(domain.map(log));
7533 scale.nice = function() {
7534 var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
7535 linear.domain(niced);
7536 domain = niced.map(pow);
7539 scale.ticks = function() {
7540 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;
7541 if (isFinite(j - i)) {
7543 for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
7547 for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
7549 for (i = 0; ticks[i] < u; i++) {}
7550 for (j = ticks.length; ticks[j - 1] > v; j--) {}
7551 ticks = ticks.slice(i, j);
7555 scale.tickFormat = function(n, format) {
7556 if (!arguments.length) return d3_scale_logFormat;
7557 if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
7558 var k = Math.max(.1, n / scale.ticks().length), f = positive ? (e = 1e-12, Math.ceil) : (e = -1e-12,
7560 return function(d) {
7561 return d / pow(f(log(d) + e)) <= k ? format(d) : "";
7564 scale.copy = function() {
7565 return d3_scale_log(linear.copy(), base, positive, domain);
7567 return d3_scale_linearRebind(scale, linear);
7569 var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
7570 floor: function(x) {
7571 return -Math.ceil(-x);
7574 return -Math.floor(-x);
7577 d3.scale.pow = function() {
7578 return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
7580 function d3_scale_pow(linear, exponent, domain) {
7581 var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
7583 return linear(powp(x));
7585 scale.invert = function(x) {
7586 return powb(linear.invert(x));
7588 scale.domain = function(x) {
7589 if (!arguments.length) return domain;
7590 linear.domain((domain = x.map(Number)).map(powp));
7593 scale.ticks = function(m) {
7594 return d3_scale_linearTicks(domain, m);
7596 scale.tickFormat = function(m, format) {
7597 return d3_scale_linearTickFormat(domain, m, format);
7599 scale.nice = function(m) {
7600 return scale.domain(d3_scale_linearNice(domain, m));
7602 scale.exponent = function(x) {
7603 if (!arguments.length) return exponent;
7604 powp = d3_scale_powPow(exponent = x);
7605 powb = d3_scale_powPow(1 / exponent);
7606 linear.domain(domain.map(powp));
7609 scale.copy = function() {
7610 return d3_scale_pow(linear.copy(), exponent, domain);
7612 return d3_scale_linearRebind(scale, linear);
7614 function d3_scale_powPow(e) {
7615 return function(x) {
7616 return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
7619 d3.scale.sqrt = function() {
7620 return d3.scale.pow().exponent(.5);
7622 d3.scale.ordinal = function() {
7623 return d3_scale_ordinal([], {
7628 function d3_scale_ordinal(domain, ranger) {
7629 var index, range, rangeBand;
7631 return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
7633 function steps(start, step) {
7634 return d3.range(domain.length).map(function(i) {
7635 return start + step * i;
7638 scale.domain = function(x) {
7639 if (!arguments.length) return domain;
7641 index = new d3_Map();
7642 var i = -1, n = x.length, xi;
7643 while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
7644 return scale[ranger.t].apply(scale, ranger.a);
7646 scale.range = function(x) {
7647 if (!arguments.length) return range;
7656 scale.rangePoints = function(x, padding) {
7657 if (arguments.length < 2) padding = 0;
7658 var start = x[0], stop = x[1], step = (stop - start) / (Math.max(1, domain.length - 1) + padding);
7659 range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step);
7667 scale.rangeBands = function(x, padding, outerPadding) {
7668 if (arguments.length < 2) padding = 0;
7669 if (arguments.length < 3) outerPadding = padding;
7670 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
7671 range = steps(start + step * outerPadding, step);
7672 if (reverse) range.reverse();
7673 rangeBand = step * (1 - padding);
7680 scale.rangeRoundBands = function(x, padding, outerPadding) {
7681 if (arguments.length < 2) padding = 0;
7682 if (arguments.length < 3) outerPadding = padding;
7683 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding)), error = stop - start - (domain.length - padding) * step;
7684 range = steps(start + Math.round(error / 2), step);
7685 if (reverse) range.reverse();
7686 rangeBand = Math.round(step * (1 - padding));
7688 t: "rangeRoundBands",
7693 scale.rangeBand = function() {
7696 scale.rangeExtent = function() {
7697 return d3_scaleExtent(ranger.a[0]);
7699 scale.copy = function() {
7700 return d3_scale_ordinal(domain, ranger);
7702 return scale.domain(domain);
7704 d3.scale.category10 = function() {
7705 return d3.scale.ordinal().range(d3_category10);
7707 d3.scale.category20 = function() {
7708 return d3.scale.ordinal().range(d3_category20);
7710 d3.scale.category20b = function() {
7711 return d3.scale.ordinal().range(d3_category20b);
7713 d3.scale.category20c = function() {
7714 return d3.scale.ordinal().range(d3_category20c);
7716 var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
7717 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);
7718 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);
7719 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);
7720 d3.scale.quantile = function() {
7721 return d3_scale_quantile([], []);
7723 function d3_scale_quantile(domain, range) {
7725 function rescale() {
7726 var k = 0, q = range.length;
7728 while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
7732 if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
7734 scale.domain = function(x) {
7735 if (!arguments.length) return domain;
7736 domain = x.filter(function(d) {
7738 }).sort(d3_ascending);
7741 scale.range = function(x) {
7742 if (!arguments.length) return range;
7746 scale.quantiles = function() {
7749 scale.invertExtent = function(y) {
7750 y = range.indexOf(y);
7751 return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
7753 scale.copy = function() {
7754 return d3_scale_quantile(domain, range);
7758 d3.scale.quantize = function() {
7759 return d3_scale_quantize(0, 1, [ 0, 1 ]);
7761 function d3_scale_quantize(x0, x1, range) {
7764 return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
7766 function rescale() {
7767 kx = range.length / (x1 - x0);
7768 i = range.length - 1;
7771 scale.domain = function(x) {
7772 if (!arguments.length) return [ x0, x1 ];
7774 x1 = +x[x.length - 1];
7777 scale.range = function(x) {
7778 if (!arguments.length) return range;
7782 scale.invertExtent = function(y) {
7783 y = range.indexOf(y);
7784 y = y < 0 ? NaN : y / kx + x0;
7785 return [ y, y + 1 / kx ];
7787 scale.copy = function() {
7788 return d3_scale_quantize(x0, x1, range);
7792 d3.scale.threshold = function() {
7793 return d3_scale_threshold([ .5 ], [ 0, 1 ]);
7795 function d3_scale_threshold(domain, range) {
7797 if (x <= x) return range[d3.bisect(domain, x)];
7799 scale.domain = function(_) {
7800 if (!arguments.length) return domain;
7804 scale.range = function(_) {
7805 if (!arguments.length) return range;
7809 scale.invertExtent = function(y) {
7810 y = range.indexOf(y);
7811 return [ domain[y - 1], domain[y] ];
7813 scale.copy = function() {
7814 return d3_scale_threshold(domain, range);
7818 d3.scale.identity = function() {
7819 return d3_scale_identity([ 0, 1 ]);
7821 function d3_scale_identity(domain) {
7822 function identity(x) {
7825 identity.invert = identity;
7826 identity.domain = identity.range = function(x) {
7827 if (!arguments.length) return domain;
7828 domain = x.map(identity);
7831 identity.ticks = function(m) {
7832 return d3_scale_linearTicks(domain, m);
7834 identity.tickFormat = function(m, format) {
7835 return d3_scale_linearTickFormat(domain, m, format);
7837 identity.copy = function() {
7838 return d3_scale_identity(domain);
7843 d3.svg.arc = function() {
7844 var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
7846 var r0 = innerRadius.apply(this, arguments), r1 = outerRadius.apply(this, arguments), a0 = startAngle.apply(this, arguments) + d3_svg_arcOffset, a1 = endAngle.apply(this, arguments) + d3_svg_arcOffset, da = (a1 < a0 && (da = a0,
7847 a0 = a1, a1 = da), a1 - a0), df = da < π ? "0" : "1", c0 = Math.cos(a0), s0 = Math.sin(a0), c1 = Math.cos(a1), s1 = Math.sin(a1);
7848 return da >= d3_svg_arcMax ? r0 ? "M0," + r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + -r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + r1 + "M0," + r0 + "A" + r0 + "," + r0 + " 0 1,0 0," + -r0 + "A" + r0 + "," + r0 + " 0 1,0 0," + r0 + "Z" : "M0," + r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + -r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + r1 + "Z" : r0 ? "M" + r1 * c0 + "," + r1 * s0 + "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1 + "L" + r0 * c1 + "," + r0 * s1 + "A" + r0 + "," + r0 + " 0 " + df + ",0 " + r0 * c0 + "," + r0 * s0 + "Z" : "M" + r1 * c0 + "," + r1 * s0 + "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1 + "L0,0" + "Z";
7850 arc.innerRadius = function(v) {
7851 if (!arguments.length) return innerRadius;
7852 innerRadius = d3_functor(v);
7855 arc.outerRadius = function(v) {
7856 if (!arguments.length) return outerRadius;
7857 outerRadius = d3_functor(v);
7860 arc.startAngle = function(v) {
7861 if (!arguments.length) return startAngle;
7862 startAngle = d3_functor(v);
7865 arc.endAngle = function(v) {
7866 if (!arguments.length) return endAngle;
7867 endAngle = d3_functor(v);
7870 arc.centroid = function() {
7871 var r = (innerRadius.apply(this, arguments) + outerRadius.apply(this, arguments)) / 2, a = (startAngle.apply(this, arguments) + endAngle.apply(this, arguments)) / 2 + d3_svg_arcOffset;
7872 return [ Math.cos(a) * r, Math.sin(a) * r ];
7876 var d3_svg_arcOffset = -halfπ, d3_svg_arcMax = τ - ε;
7877 function d3_svg_arcInnerRadius(d) {
7878 return d.innerRadius;
7880 function d3_svg_arcOuterRadius(d) {
7881 return d.outerRadius;
7883 function d3_svg_arcStartAngle(d) {
7884 return d.startAngle;
7886 function d3_svg_arcEndAngle(d) {
7889 function d3_svg_line(projection) {
7890 var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
7891 function line(data) {
7892 var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
7893 function segment() {
7894 segments.push("M", interpolate(projection(points), tension));
7897 if (defined.call(this, d = data[i], i)) {
7898 points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
7899 } else if (points.length) {
7904 if (points.length) segment();
7905 return segments.length ? segments.join("") : null;
7907 line.x = function(_) {
7908 if (!arguments.length) return x;
7912 line.y = function(_) {
7913 if (!arguments.length) return y;
7917 line.defined = function(_) {
7918 if (!arguments.length) return defined;
7922 line.interpolate = function(_) {
7923 if (!arguments.length) return interpolateKey;
7924 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
7927 line.tension = function(_) {
7928 if (!arguments.length) return tension;
7934 d3.svg.line = function() {
7935 return d3_svg_line(d3_identity);
7937 var d3_svg_lineInterpolators = d3.map({
7938 linear: d3_svg_lineLinear,
7939 "linear-closed": d3_svg_lineLinearClosed,
7940 step: d3_svg_lineStep,
7941 "step-before": d3_svg_lineStepBefore,
7942 "step-after": d3_svg_lineStepAfter,
7943 basis: d3_svg_lineBasis,
7944 "basis-open": d3_svg_lineBasisOpen,
7945 "basis-closed": d3_svg_lineBasisClosed,
7946 bundle: d3_svg_lineBundle,
7947 cardinal: d3_svg_lineCardinal,
7948 "cardinal-open": d3_svg_lineCardinalOpen,
7949 "cardinal-closed": d3_svg_lineCardinalClosed,
7950 monotone: d3_svg_lineMonotone
7952 d3_svg_lineInterpolators.forEach(function(key, value) {
7954 value.closed = /-closed$/.test(key);
7956 function d3_svg_lineLinear(points) {
7957 return points.join("L");
7959 function d3_svg_lineLinearClosed(points) {
7960 return d3_svg_lineLinear(points) + "Z";
7962 function d3_svg_lineStep(points) {
7963 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
7964 while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
7965 if (n > 1) path.push("H", p[0]);
7966 return path.join("");
7968 function d3_svg_lineStepBefore(points) {
7969 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
7970 while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
7971 return path.join("");
7973 function d3_svg_lineStepAfter(points) {
7974 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
7975 while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
7976 return path.join("");
7978 function d3_svg_lineCardinalOpen(points, tension) {
7979 return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, points.length - 1), d3_svg_lineCardinalTangents(points, tension));
7981 function d3_svg_lineCardinalClosed(points, tension) {
7982 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
7983 points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
7985 function d3_svg_lineCardinal(points, tension) {
7986 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
7988 function d3_svg_lineHermite(points, tangents) {
7989 if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
7990 return d3_svg_lineLinear(points);
7992 var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
7994 path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
7998 if (tangents.length > 1) {
8002 path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
8003 for (var i = 2; i < tangents.length; i++, pi++) {
8006 path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
8010 var lp = points[pi];
8011 path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
8015 function d3_svg_lineCardinalTangents(points, tension) {
8016 var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
8021 tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
8025 function d3_svg_lineBasis(points) {
8026 if (points.length < 3) return d3_svg_lineLinear(points);
8027 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) ];
8028 points.push(points[n - 1]);
8035 d3_svg_lineBasisBezier(path, px, py);
8039 return path.join("");
8041 function d3_svg_lineBasisOpen(points) {
8042 if (points.length < 4) return d3_svg_lineLinear(points);
8043 var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
8049 path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
8057 d3_svg_lineBasisBezier(path, px, py);
8059 return path.join("");
8061 function d3_svg_lineBasisClosed(points) {
8062 var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
8068 path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
8076 d3_svg_lineBasisBezier(path, px, py);
8078 return path.join("");
8080 function d3_svg_lineBundle(points, tension) {
8081 var n = points.length - 1;
8083 var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
8087 p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
8088 p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
8091 return d3_svg_lineBasis(points);
8093 function d3_svg_lineDot4(a, b) {
8094 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
8096 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 ];
8097 function d3_svg_lineBasisBezier(path, x, y) {
8098 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));
8100 function d3_svg_lineSlope(p0, p1) {
8101 return (p1[1] - p0[1]) / (p1[0] - p0[0]);
8103 function d3_svg_lineFiniteDifferences(points) {
8104 var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
8106 m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
8111 function d3_svg_lineMonotoneTangents(points) {
8112 var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
8114 d = d3_svg_lineSlope(points[i], points[i + 1]);
8116 m[i] = m[i + 1] = 0;
8122 s = d * 3 / Math.sqrt(s);
8130 s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
8131 tangents.push([ s || 0, m[i] * s || 0 ]);
8135 function d3_svg_lineMonotone(points) {
8136 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
8138 d3.svg.line.radial = function() {
8139 var line = d3_svg_line(d3_svg_lineRadial);
8140 line.radius = line.x, delete line.x;
8141 line.angle = line.y, delete line.y;
8144 function d3_svg_lineRadial(points) {
8145 var point, i = -1, n = points.length, r, a;
8149 a = point[1] + d3_svg_arcOffset;
8150 point[0] = r * Math.cos(a);
8151 point[1] = r * Math.sin(a);
8155 function d3_svg_area(projection) {
8156 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;
8157 function area(data) {
8158 var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
8160 } : d3_functor(x1), fy1 = y0 === y1 ? function() {
8162 } : d3_functor(y1), x, y;
8163 function segment() {
8164 segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
8167 if (defined.call(this, d = data[i], i)) {
8168 points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
8169 points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
8170 } else if (points0.length) {
8176 if (points0.length) segment();
8177 return segments.length ? segments.join("") : null;
8179 area.x = function(_) {
8180 if (!arguments.length) return x1;
8184 area.x0 = function(_) {
8185 if (!arguments.length) return x0;
8189 area.x1 = function(_) {
8190 if (!arguments.length) return x1;
8194 area.y = function(_) {
8195 if (!arguments.length) return y1;
8199 area.y0 = function(_) {
8200 if (!arguments.length) return y0;
8204 area.y1 = function(_) {
8205 if (!arguments.length) return y1;
8209 area.defined = function(_) {
8210 if (!arguments.length) return defined;
8214 area.interpolate = function(_) {
8215 if (!arguments.length) return interpolateKey;
8216 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
8217 interpolateReverse = interpolate.reverse || interpolate;
8218 L = interpolate.closed ? "M" : "L";
8221 area.tension = function(_) {
8222 if (!arguments.length) return tension;
8228 d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
8229 d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
8230 d3.svg.area = function() {
8231 return d3_svg_area(d3_identity);
8233 d3.svg.area.radial = function() {
8234 var area = d3_svg_area(d3_svg_lineRadial);
8235 area.radius = area.x, delete area.x;
8236 area.innerRadius = area.x0, delete area.x0;
8237 area.outerRadius = area.x1, delete area.x1;
8238 area.angle = area.y, delete area.y;
8239 area.startAngle = area.y0, delete area.y0;
8240 area.endAngle = area.y1, delete area.y1;
8243 d3.svg.chord = function() {
8244 var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
8245 function chord(d, i) {
8246 var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
8247 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";
8249 function subgroup(self, f, d, i) {
8250 var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) + d3_svg_arcOffset, a1 = endAngle.call(self, subgroup, i) + d3_svg_arcOffset;
8255 p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
8256 p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
8259 function equals(a, b) {
8260 return a.a0 == b.a0 && a.a1 == b.a1;
8262 function arc(r, p, a) {
8263 return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
8265 function curve(r0, p0, r1, p1) {
8266 return "Q 0,0 " + p1;
8268 chord.radius = function(v) {
8269 if (!arguments.length) return radius;
8270 radius = d3_functor(v);
8273 chord.source = function(v) {
8274 if (!arguments.length) return source;
8275 source = d3_functor(v);
8278 chord.target = function(v) {
8279 if (!arguments.length) return target;
8280 target = d3_functor(v);
8283 chord.startAngle = function(v) {
8284 if (!arguments.length) return startAngle;
8285 startAngle = d3_functor(v);
8288 chord.endAngle = function(v) {
8289 if (!arguments.length) return endAngle;
8290 endAngle = d3_functor(v);
8295 function d3_svg_chordRadius(d) {
8298 d3.svg.diagonal = function() {
8299 var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
8300 function diagonal(d, i) {
8301 var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
8308 p = p.map(projection);
8309 return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
8311 diagonal.source = function(x) {
8312 if (!arguments.length) return source;
8313 source = d3_functor(x);
8316 diagonal.target = function(x) {
8317 if (!arguments.length) return target;
8318 target = d3_functor(x);
8321 diagonal.projection = function(x) {
8322 if (!arguments.length) return projection;
8328 function d3_svg_diagonalProjection(d) {
8329 return [ d.x, d.y ];
8331 d3.svg.diagonal.radial = function() {
8332 var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
8333 diagonal.projection = function(x) {
8334 return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
8338 function d3_svg_diagonalRadialProjection(projection) {
8340 var d = projection.apply(this, arguments), r = d[0], a = d[1] + d3_svg_arcOffset;
8341 return [ r * Math.cos(a), r * Math.sin(a) ];
8344 d3.svg.symbol = function() {
8345 var type = d3_svg_symbolType, size = d3_svg_symbolSize;
8346 function symbol(d, i) {
8347 return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
8349 symbol.type = function(x) {
8350 if (!arguments.length) return type;
8351 type = d3_functor(x);
8354 symbol.size = function(x) {
8355 if (!arguments.length) return size;
8356 size = d3_functor(x);
8361 function d3_svg_symbolSize() {
8364 function d3_svg_symbolType() {
8367 function d3_svg_symbolCircle(size) {
8368 var r = Math.sqrt(size / π);
8369 return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
8371 var d3_svg_symbols = d3.map({
8372 circle: d3_svg_symbolCircle,
8373 cross: function(size) {
8374 var r = Math.sqrt(size / 5) / 2;
8375 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";
8377 diamond: function(size) {
8378 var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
8379 return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
8381 square: function(size) {
8382 var r = Math.sqrt(size) / 2;
8383 return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
8385 "triangle-down": function(size) {
8386 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8387 return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
8389 "triangle-up": function(size) {
8390 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8391 return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
8394 d3.svg.symbolTypes = d3_svg_symbols.keys();
8395 var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
8396 function d3_transition(groups, id) {
8397 d3_subclass(groups, d3_transitionPrototype);
8401 var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
8402 d3_transitionPrototype.call = d3_selectionPrototype.call;
8403 d3_transitionPrototype.empty = d3_selectionPrototype.empty;
8404 d3_transitionPrototype.node = d3_selectionPrototype.node;
8405 d3_transitionPrototype.size = d3_selectionPrototype.size;
8406 d3.transition = function(selection) {
8407 return arguments.length ? d3_transitionInheritId ? selection.transition() : selection : d3_selectionRoot.transition();
8409 d3.transition.prototype = d3_transitionPrototype;
8410 d3_transitionPrototype.select = function(selector) {
8411 var id = this.id, subgroups = [], subgroup, subnode, node;
8412 selector = d3_selection_selector(selector);
8413 for (var j = -1, m = this.length; ++j < m; ) {
8414 subgroups.push(subgroup = []);
8415 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8416 if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
8417 if ("__data__" in node) subnode.__data__ = node.__data__;
8418 d3_transitionNode(subnode, i, id, node.__transition__[id]);
8419 subgroup.push(subnode);
8421 subgroup.push(null);
8425 return d3_transition(subgroups, id);
8427 d3_transitionPrototype.selectAll = function(selector) {
8428 var id = this.id, subgroups = [], subgroup, subnodes, node, subnode, transition;
8429 selector = d3_selection_selectorAll(selector);
8430 for (var j = -1, m = this.length; ++j < m; ) {
8431 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8432 if (node = group[i]) {
8433 transition = node.__transition__[id];
8434 subnodes = selector.call(node, node.__data__, i, j);
8435 subgroups.push(subgroup = []);
8436 for (var k = -1, o = subnodes.length; ++k < o; ) {
8437 if (subnode = subnodes[k]) d3_transitionNode(subnode, k, id, transition);
8438 subgroup.push(subnode);
8443 return d3_transition(subgroups, id);
8445 d3_transitionPrototype.filter = function(filter) {
8446 var subgroups = [], subgroup, group, node;
8447 if (typeof filter !== "function") filter = d3_selection_filter(filter);
8448 for (var j = 0, m = this.length; j < m; j++) {
8449 subgroups.push(subgroup = []);
8450 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
8451 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
8452 subgroup.push(node);
8456 return d3_transition(subgroups, this.id);
8458 d3_transitionPrototype.tween = function(name, tween) {
8460 if (arguments.length < 2) return this.node().__transition__[id].tween.get(name);
8461 return d3_selection_each(this, tween == null ? function(node) {
8462 node.__transition__[id].tween.remove(name);
8463 } : function(node) {
8464 node.__transition__[id].tween.set(name, tween);
8467 function d3_transition_tween(groups, name, value, tween) {
8469 return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
8470 node.__transition__[id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
8471 } : (value = tween(value), function(node) {
8472 node.__transition__[id].tween.set(name, value);
8475 d3_transitionPrototype.attr = function(nameNS, value) {
8476 if (arguments.length < 2) {
8477 for (value in nameNS) this.attr(value, nameNS[value]);
8480 var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
8481 function attrNull() {
8482 this.removeAttribute(name);
8484 function attrNullNS() {
8485 this.removeAttributeNS(name.space, name.local);
8487 function attrTween(b) {
8488 return b == null ? attrNull : (b += "", function() {
8489 var a = this.getAttribute(name), i;
8490 return a !== b && (i = interpolate(a, b), function(t) {
8491 this.setAttribute(name, i(t));
8495 function attrTweenNS(b) {
8496 return b == null ? attrNullNS : (b += "", function() {
8497 var a = this.getAttributeNS(name.space, name.local), i;
8498 return a !== b && (i = interpolate(a, b), function(t) {
8499 this.setAttributeNS(name.space, name.local, i(t));
8503 return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
8505 d3_transitionPrototype.attrTween = function(nameNS, tween) {
8506 var name = d3.ns.qualify(nameNS);
8507 function attrTween(d, i) {
8508 var f = tween.call(this, d, i, this.getAttribute(name));
8509 return f && function(t) {
8510 this.setAttribute(name, f(t));
8513 function attrTweenNS(d, i) {
8514 var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
8515 return f && function(t) {
8516 this.setAttributeNS(name.space, name.local, f(t));
8519 return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
8521 d3_transitionPrototype.style = function(name, value, priority) {
8522 var n = arguments.length;
8524 if (typeof name !== "string") {
8525 if (n < 2) value = "";
8526 for (priority in name) this.style(priority, name[priority], value);
8531 function styleNull() {
8532 this.style.removeProperty(name);
8534 function styleString(b) {
8535 return b == null ? styleNull : (b += "", function() {
8536 var a = d3_window.getComputedStyle(this, null).getPropertyValue(name), i;
8537 return a !== b && (i = d3_interpolate(a, b), function(t) {
8538 this.style.setProperty(name, i(t), priority);
8542 return d3_transition_tween(this, "style." + name, value, styleString);
8544 d3_transitionPrototype.styleTween = function(name, tween, priority) {
8545 if (arguments.length < 3) priority = "";
8546 function styleTween(d, i) {
8547 var f = tween.call(this, d, i, d3_window.getComputedStyle(this, null).getPropertyValue(name));
8548 return f && function(t) {
8549 this.style.setProperty(name, f(t), priority);
8552 return this.tween("style." + name, styleTween);
8554 d3_transitionPrototype.text = function(value) {
8555 return d3_transition_tween(this, "text", value, d3_transition_text);
8557 function d3_transition_text(b) {
8558 if (b == null) b = "";
8560 this.textContent = b;
8563 d3_transitionPrototype.remove = function() {
8564 return this.each("end.transition", function() {
8566 if (this.__transition__.count < 2 && (p = this.parentNode)) p.removeChild(this);
8569 d3_transitionPrototype.ease = function(value) {
8571 if (arguments.length < 1) return this.node().__transition__[id].ease;
8572 if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
8573 return d3_selection_each(this, function(node) {
8574 node.__transition__[id].ease = value;
8577 d3_transitionPrototype.delay = function(value) {
8579 if (arguments.length < 1) return this.node().__transition__[id].delay;
8580 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8581 node.__transition__[id].delay = +value.call(node, node.__data__, i, j);
8582 } : (value = +value, function(node) {
8583 node.__transition__[id].delay = value;
8586 d3_transitionPrototype.duration = function(value) {
8588 if (arguments.length < 1) return this.node().__transition__[id].duration;
8589 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8590 node.__transition__[id].duration = Math.max(1, value.call(node, node.__data__, i, j));
8591 } : (value = Math.max(1, value), function(node) {
8592 node.__transition__[id].duration = value;
8595 d3_transitionPrototype.each = function(type, listener) {
8597 if (arguments.length < 2) {
8598 var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
8599 d3_transitionInheritId = id;
8600 d3_selection_each(this, function(node, i, j) {
8601 d3_transitionInherit = node.__transition__[id];
8602 type.call(node, node.__data__, i, j);
8604 d3_transitionInherit = inherit;
8605 d3_transitionInheritId = inheritId;
8607 d3_selection_each(this, function(node) {
8608 var transition = node.__transition__[id];
8609 (transition.event || (transition.event = d3.dispatch("start", "end"))).on(type, listener);
8614 d3_transitionPrototype.transition = function() {
8615 var id0 = this.id, id1 = ++d3_transitionId, subgroups = [], subgroup, group, node, transition;
8616 for (var j = 0, m = this.length; j < m; j++) {
8617 subgroups.push(subgroup = []);
8618 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
8619 if (node = group[i]) {
8620 transition = Object.create(node.__transition__[id0]);
8621 transition.delay += transition.duration;
8622 d3_transitionNode(node, i, id1, transition);
8624 subgroup.push(node);
8627 return d3_transition(subgroups, id1);
8629 function d3_transitionNode(node, i, id, inherit) {
8630 var lock = node.__transition__ || (node.__transition__ = {
8633 }), transition = lock[id];
8635 var time = inherit.time;
8636 transition = lock[id] = {
8637 tween: new d3_Map(),
8640 delay: inherit.delay,
8641 duration: inherit.duration
8644 d3.timer(function(elapsed) {
8645 var d = node.__data__, ease = transition.ease, delay = transition.delay, duration = transition.duration, timer = d3_timer_active, tweened = [];
8646 timer.t = delay + time;
8647 if (delay <= elapsed) return start(elapsed - delay);
8649 function start(elapsed) {
8650 if (lock.active > id) return stop();
8652 transition.event && transition.event.start.call(node, d, i);
8653 transition.tween.forEach(function(key, value) {
8654 if (value = value.call(node, d, i)) {
8655 tweened.push(value);
8658 d3.timer(function() {
8659 timer.c = tick(elapsed || 1) ? d3_true : tick;
8663 function tick(elapsed) {
8664 if (lock.active !== id) return stop();
8665 var t = elapsed / duration, e = ease(t), n = tweened.length;
8667 tweened[--n].call(node, e);
8670 transition.event && transition.event.end.call(node, d, i);
8675 if (--lock.count) delete lock[id]; else delete node.__transition__;
8681 d3.svg.axis = function() {
8682 var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
8685 var g = d3.select(this);
8686 var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
8687 var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick.order()).style("opacity", 1), tickTransform;
8688 var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
8689 d3.transition(path));
8690 tickEnter.append("line");
8691 tickEnter.append("text");
8692 var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text");
8696 tickTransform = d3_svg_axisX;
8697 lineEnter.attr("y2", innerTickSize);
8698 textEnter.attr("y", Math.max(innerTickSize, 0) + tickPadding);
8699 lineUpdate.attr("x2", 0).attr("y2", innerTickSize);
8700 textUpdate.attr("x", 0).attr("y", Math.max(innerTickSize, 0) + tickPadding);
8701 text.attr("dy", ".71em").style("text-anchor", "middle");
8702 pathUpdate.attr("d", "M" + range[0] + "," + outerTickSize + "V0H" + range[1] + "V" + outerTickSize);
8708 tickTransform = d3_svg_axisX;
8709 lineEnter.attr("y2", -innerTickSize);
8710 textEnter.attr("y", -(Math.max(innerTickSize, 0) + tickPadding));
8711 lineUpdate.attr("x2", 0).attr("y2", -innerTickSize);
8712 textUpdate.attr("x", 0).attr("y", -(Math.max(innerTickSize, 0) + tickPadding));
8713 text.attr("dy", "0em").style("text-anchor", "middle");
8714 pathUpdate.attr("d", "M" + range[0] + "," + -outerTickSize + "V0H" + range[1] + "V" + -outerTickSize);
8720 tickTransform = d3_svg_axisY;
8721 lineEnter.attr("x2", -innerTickSize);
8722 textEnter.attr("x", -(Math.max(innerTickSize, 0) + tickPadding));
8723 lineUpdate.attr("x2", -innerTickSize).attr("y2", 0);
8724 textUpdate.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)).attr("y", 0);
8725 text.attr("dy", ".32em").style("text-anchor", "end");
8726 pathUpdate.attr("d", "M" + -outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + -outerTickSize);
8732 tickTransform = d3_svg_axisY;
8733 lineEnter.attr("x2", innerTickSize);
8734 textEnter.attr("x", Math.max(innerTickSize, 0) + tickPadding);
8735 lineUpdate.attr("x2", innerTickSize).attr("y2", 0);
8736 textUpdate.attr("x", Math.max(innerTickSize, 0) + tickPadding).attr("y", 0);
8737 text.attr("dy", ".32em").style("text-anchor", "start");
8738 pathUpdate.attr("d", "M" + outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + outerTickSize);
8742 if (scale1.rangeBand) {
8743 var x = scale1, dx = x.rangeBand() / 2;
8744 scale0 = scale1 = function(d) {
8747 } else if (scale0.rangeBand) {
8750 tickExit.call(tickTransform, scale1);
8752 tickEnter.call(tickTransform, scale0);
8753 tickUpdate.call(tickTransform, scale1);
8756 axis.scale = function(x) {
8757 if (!arguments.length) return scale;
8761 axis.orient = function(x) {
8762 if (!arguments.length) return orient;
8763 orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
8766 axis.ticks = function() {
8767 if (!arguments.length) return tickArguments_;
8768 tickArguments_ = arguments;
8771 axis.tickValues = function(x) {
8772 if (!arguments.length) return tickValues;
8776 axis.tickFormat = function(x) {
8777 if (!arguments.length) return tickFormat_;
8781 axis.tickSize = function(x) {
8782 var n = arguments.length;
8783 if (!n) return innerTickSize;
8785 outerTickSize = +arguments[n - 1];
8788 axis.innerTickSize = function(x) {
8789 if (!arguments.length) return innerTickSize;
8793 axis.outerTickSize = function(x) {
8794 if (!arguments.length) return outerTickSize;
8798 axis.tickPadding = function(x) {
8799 if (!arguments.length) return tickPadding;
8803 axis.tickSubdivide = function() {
8804 return arguments.length && axis;
8808 var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
8814 function d3_svg_axisX(selection, x) {
8815 selection.attr("transform", function(d) {
8816 return "translate(" + x(d) + ",0)";
8819 function d3_svg_axisY(selection, y) {
8820 selection.attr("transform", function(d) {
8821 return "translate(0," + y(d) + ")";
8824 d3.svg.brush = function() {
8825 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];
8828 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);
8829 var background = g.selectAll(".background").data([ 0 ]);
8830 background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
8831 g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
8832 var resize = g.selectAll(".resize").data(resizes, d3_identity);
8833 resize.exit().remove();
8834 resize.enter().append("g").attr("class", function(d) {
8835 return "resize " + d;
8836 }).style("cursor", function(d) {
8837 return d3_svg_brushCursor[d];
8838 }).append("rect").attr("x", function(d) {
8839 return /[ew]$/.test(d) ? -3 : null;
8840 }).attr("y", function(d) {
8841 return /^[ns]/.test(d) ? -3 : null;
8842 }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
8843 resize.style("display", brush.empty() ? "none" : null);
8844 var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
8846 range = d3_scaleRange(x);
8847 backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
8851 range = d3_scaleRange(y);
8852 backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
8858 brush.event = function(g) {
8860 var event_ = event.of(this, arguments), extent1 = {
8865 }, extent0 = this.__chart__ || extent1;
8866 this.__chart__ = extent1;
8867 if (d3_transitionInheritId) {
8868 d3.select(this).transition().each("start.brush", function() {
8869 xExtentDomain = extent0.i;
8870 yExtentDomain = extent0.j;
8871 xExtent = extent0.x;
8872 yExtent = extent0.y;
8876 }).tween("brush:brush", function() {
8877 var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
8878 xExtentDomain = yExtentDomain = null;
8879 return function(t) {
8880 xExtent = extent1.x = xi(t);
8881 yExtent = extent1.y = yi(t);
8887 }).each("end.brush", function() {
8888 xExtentDomain = extent1.i;
8889 yExtentDomain = extent1.j;
8912 function redraw(g) {
8913 g.selectAll(".resize").attr("transform", function(d) {
8914 return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
8917 function redrawX(g) {
8918 g.select(".extent").attr("x", xExtent[0]);
8919 g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
8921 function redrawY(g) {
8922 g.select(".extent").attr("y", yExtent[0]);
8923 g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
8925 function brushstart() {
8926 var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), dragRestore = d3_event_dragSuppress(), center, origin = d3.mouse(target), offset;
8927 var w = d3.select(d3_window).on("keydown.brush", keydown).on("keyup.brush", keyup);
8928 if (d3.event.changedTouches) {
8929 w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
8931 w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
8933 g.interrupt().selectAll("*").interrupt();
8935 origin[0] = xExtent[0] - origin[0];
8936 origin[1] = yExtent[0] - origin[1];
8937 } else if (resizing) {
8938 var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
8939 offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
8940 origin[0] = xExtent[ex];
8941 origin[1] = yExtent[ey];
8942 } else if (d3.event.altKey) center = origin.slice();
8943 g.style("pointer-events", "none").selectAll(".resize").style("display", null);
8944 d3.select("body").style("cursor", eventTarget.style("cursor"));
8949 function keydown() {
8950 if (d3.event.keyCode == 32) {
8953 origin[0] -= xExtent[1];
8954 origin[1] -= yExtent[1];
8957 d3_eventPreventDefault();
8961 if (d3.event.keyCode == 32 && dragging == 2) {
8962 origin[0] += xExtent[1];
8963 origin[1] += yExtent[1];
8965 d3_eventPreventDefault();
8968 function brushmove() {
8969 var point = d3.mouse(target), moved = false;
8971 point[0] += offset[0];
8972 point[1] += offset[1];
8975 if (d3.event.altKey) {
8976 if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
8977 origin[0] = xExtent[+(point[0] < center[0])];
8978 origin[1] = yExtent[+(point[1] < center[1])];
8979 } else center = null;
8981 if (resizingX && move1(point, x, 0)) {
8985 if (resizingY && move1(point, y, 1)) {
8993 mode: dragging ? "move" : "resize"
8997 function move1(point, scale, i) {
8998 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;
9001 r1 -= size + position;
9003 min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
9005 max = (min += position) + size;
9007 if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
9008 if (position < min) {
9015 if (extent[0] != min || extent[1] != max) {
9016 if (i) yExtentDomain = null; else xExtentDomain = null;
9022 function brushend() {
9024 g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
9025 d3.select("body").style("cursor", null);
9026 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);
9033 brush.x = function(z) {
9034 if (!arguments.length) return x;
9036 resizes = d3_svg_brushResizes[!x << 1 | !y];
9039 brush.y = function(z) {
9040 if (!arguments.length) return y;
9042 resizes = d3_svg_brushResizes[!x << 1 | !y];
9045 brush.clamp = function(z) {
9046 if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
9047 if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
9050 brush.extent = function(z) {
9051 var x0, x1, y0, y1, t;
9052 if (!arguments.length) {
9054 if (xExtentDomain) {
9055 x0 = xExtentDomain[0], x1 = xExtentDomain[1];
9057 x0 = xExtent[0], x1 = xExtent[1];
9058 if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
9059 if (x1 < x0) t = x0, x0 = x1, x1 = t;
9063 if (yExtentDomain) {
9064 y0 = yExtentDomain[0], y1 = yExtentDomain[1];
9066 y0 = yExtent[0], y1 = yExtent[1];
9067 if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
9068 if (y1 < y0) t = y0, y0 = y1, y1 = t;
9071 return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
9074 x0 = z[0], x1 = z[1];
9075 if (y) x0 = x0[0], x1 = x1[0];
9076 xExtentDomain = [ x0, x1 ];
9077 if (x.invert) x0 = x(x0), x1 = x(x1);
9078 if (x1 < x0) t = x0, x0 = x1, x1 = t;
9079 if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
9082 y0 = z[0], y1 = z[1];
9083 if (x) y0 = y0[1], y1 = y1[1];
9084 yExtentDomain = [ y0, y1 ];
9085 if (y.invert) y0 = y(y0), y1 = y(y1);
9086 if (y1 < y0) t = y0, y0 = y1, y1 = t;
9087 if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
9091 brush.clear = function() {
9092 if (!brush.empty()) {
9093 xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
9094 xExtentDomain = yExtentDomain = null;
9098 brush.empty = function() {
9099 return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
9101 return d3.rebind(brush, event, "on");
9103 var d3_svg_brushCursor = {
9113 var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
9114 var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
9115 var d3_time_formatUtc = d3_time_format.utc;
9116 var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
9117 d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
9118 function d3_time_formatIsoNative(date) {
9119 return date.toISOString();
9121 d3_time_formatIsoNative.parse = function(string) {
9122 var date = new Date(string);
9123 return isNaN(date) ? null : date;
9125 d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
9126 d3_time.second = d3_time_interval(function(date) {
9127 return new d3_date(Math.floor(date / 1e3) * 1e3);
9128 }, function(date, offset) {
9129 date.setTime(date.getTime() + Math.floor(offset) * 1e3);
9131 return date.getSeconds();
9133 d3_time.seconds = d3_time.second.range;
9134 d3_time.seconds.utc = d3_time.second.utc.range;
9135 d3_time.minute = d3_time_interval(function(date) {
9136 return new d3_date(Math.floor(date / 6e4) * 6e4);
9137 }, function(date, offset) {
9138 date.setTime(date.getTime() + Math.floor(offset) * 6e4);
9140 return date.getMinutes();
9142 d3_time.minutes = d3_time.minute.range;
9143 d3_time.minutes.utc = d3_time.minute.utc.range;
9144 d3_time.hour = d3_time_interval(function(date) {
9145 var timezone = date.getTimezoneOffset() / 60;
9146 return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
9147 }, function(date, offset) {
9148 date.setTime(date.getTime() + Math.floor(offset) * 36e5);
9150 return date.getHours();
9152 d3_time.hours = d3_time.hour.range;
9153 d3_time.hours.utc = d3_time.hour.utc.range;
9154 d3_time.month = d3_time_interval(function(date) {
9155 date = d3_time.day(date);
9158 }, function(date, offset) {
9159 date.setMonth(date.getMonth() + offset);
9161 return date.getMonth();
9163 d3_time.months = d3_time.month.range;
9164 d3_time.months.utc = d3_time.month.utc.range;
9165 function d3_time_scale(linear, methods, format) {
9169 scale.invert = function(x) {
9170 return d3_time_scaleDate(linear.invert(x));
9172 scale.domain = function(x) {
9173 if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
9177 function tickMethod(extent, count) {
9178 var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
9179 return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
9181 }), 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];
9183 scale.nice = function(interval, skip) {
9184 var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
9185 if (method) interval = method[0], skip = method[1];
9186 function skipped(date) {
9187 return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
9189 return scale.domain(d3_scale_nice(domain, skip > 1 ? {
9190 floor: function(date) {
9191 while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
9194 ceil: function(date) {
9195 while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
9200 scale.ticks = function(interval, skip) {
9201 var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
9204 if (method) interval = method[0], skip = method[1];
9205 return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
9207 scale.tickFormat = function() {
9210 scale.copy = function() {
9211 return d3_time_scale(linear.copy(), methods, format);
9213 return d3_scale_linearRebind(scale, linear);
9215 function d3_time_scaleDate(t) {
9218 var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
9219 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 ] ];
9220 var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
9221 return d.getMilliseconds();
9222 } ], [ ":%S", function(d) {
9223 return d.getSeconds();
9224 } ], [ "%I:%M", function(d) {
9225 return d.getMinutes();
9226 } ], [ "%I %p", function(d) {
9227 return d.getHours();
9228 } ], [ "%a %d", function(d) {
9229 return d.getDay() && d.getDate() != 1;
9230 } ], [ "%b %d", function(d) {
9231 return d.getDate() != 1;
9232 } ], [ "%B", function(d) {
9233 return d.getMonth();
9234 } ], [ "%Y", d3_true ] ]);
9235 var d3_time_scaleMilliseconds = {
9236 range: function(start, stop, step) {
9237 return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
9242 d3_time_scaleLocalMethods.year = d3_time.year;
9243 d3_time.scale = function() {
9244 return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
9246 var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
9247 return [ m[0].utc, m[1] ];
9249 var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
9250 return d.getUTCMilliseconds();
9251 } ], [ ":%S", function(d) {
9252 return d.getUTCSeconds();
9253 } ], [ "%I:%M", function(d) {
9254 return d.getUTCMinutes();
9255 } ], [ "%I %p", function(d) {
9256 return d.getUTCHours();
9257 } ], [ "%a %d", function(d) {
9258 return d.getUTCDay() && d.getUTCDate() != 1;
9259 } ], [ "%b %d", function(d) {
9260 return d.getUTCDate() != 1;
9261 } ], [ "%B", function(d) {
9262 return d.getUTCMonth();
9263 } ], [ "%Y", d3_true ] ]);
9264 d3_time_scaleUtcMethods.year = d3_time.year.utc;
9265 d3_time.scale.utc = function() {
9266 return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
9268 d3.text = d3_xhrType(function(request) {
9269 return request.responseText;
9271 d3.json = function(url, callback) {
9272 return d3_xhr(url, "application/json", d3_json, callback);
9274 function d3_json(request) {
9275 return JSON.parse(request.responseText);
9277 d3.html = function(url, callback) {
9278 throw "disallowed by chromium security";
9279 return d3_xhr(url, "text/html", d3_html, callback);
9281 function d3_html(request) {
9282 throw "disallowed by chromium security";
9283 var range = d3_document.createRange();
9284 range.selectNode(d3_document.body);
9285 return range.createContextualFragment(request.responseText);
9287 d3.xml = d3_xhrType(function(request) {
9288 return request.responseXML;
9290 if (typeof define === "function" && define.amd) {
9292 } else if (typeof module === "object" && module.exports) {
9293 module.exports = d3;