1 // Downloaded from http://d3js.org/d3.v3.js
3 // Copyright 2010-2016 Mike Bostock
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without modification,
7 // are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright notice, this
10 // list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above copyright notice,
13 // this list of conditions and the following disclaimer in the documentation
14 // and/or other materials provided with the distribution.
16 // * Neither the name of the author nor the names of contributors may be used to
17 // endorse or promote products derived from this software without specific prior
18 // written permission.
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24 // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 var d3_arraySlice = [].slice, d3_array = function(list) {
36 return d3_arraySlice.call(list);
38 var d3_document = this.document;
39 function d3_documentElement(node) {
40 return node && (node.ownerDocument || node.document || node).documentElement;
42 function d3_window(node) {
43 return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
47 d3_array(d3_document.documentElement.childNodes)[0].nodeType;
49 d3_array = function(list) {
50 var i = list.length, array = new Array(i);
51 while (i--) array[i] = list[i];
56 if (!Date.now) Date.now = function() {
61 d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
63 var d3_element_prototype = this.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = this.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
64 d3_element_prototype.setAttribute = function(name, value) {
65 d3_element_setAttribute.call(this, name, value + "");
67 d3_element_prototype.setAttributeNS = function(space, local, value) {
68 d3_element_setAttributeNS.call(this, space, local, value + "");
70 d3_style_prototype.setProperty = function(name, value, priority) {
71 d3_style_setProperty.call(this, name, value + "", priority);
75 d3.ascending = d3_ascending;
76 function d3_ascending(a, b) {
77 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
79 d3.descending = function(a, b) {
80 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
82 d3.min = function(array, f) {
83 var i = -1, n = array.length, a, b;
84 if (arguments.length === 1) {
85 while (++i < n) if ((b = array[i]) != null && b >= b) {
89 while (++i < n) if ((b = array[i]) != null && a > b) a = b;
91 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
95 while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
99 d3.max = function(array, f) {
100 var i = -1, n = array.length, a, b;
101 if (arguments.length === 1) {
102 while (++i < n) if ((b = array[i]) != null && b >= b) {
106 while (++i < n) if ((b = array[i]) != null && b > a) a = b;
108 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
112 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
116 d3.extent = function(array, f) {
117 var i = -1, n = array.length, a, b, c;
118 if (arguments.length === 1) {
119 while (++i < n) if ((b = array[i]) != null && b >= b) {
123 while (++i < n) if ((b = array[i]) != null) {
128 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
132 while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
139 function d3_number(x) {
140 return x === null ? NaN : +x;
142 function d3_numeric(x) {
145 d3.sum = function(array, f) {
146 var s = 0, n = array.length, a, i = -1;
147 if (arguments.length === 1) {
148 while (++i < n) if (d3_numeric(a = +array[i])) s += a;
150 while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
154 d3.mean = function(array, f) {
155 var s = 0, n = array.length, a, i = -1, j = n;
156 if (arguments.length === 1) {
157 while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
159 while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
163 d3.quantile = function(values, p) {
164 var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
165 return e ? v + e * (values[h] - v) : v;
167 d3.median = function(array, f) {
168 var numbers = [], n = array.length, a, i = -1;
169 if (arguments.length === 1) {
170 while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
172 while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
174 if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
176 d3.variance = function(array, f) {
177 var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
178 if (arguments.length === 1) {
180 if (d3_numeric(a = d3_number(array[i]))) {
188 if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
195 if (j > 1) return s / (j - 1);
197 d3.deviation = function() {
198 var v = d3.variance.apply(this, arguments);
199 return v ? Math.sqrt(v) : v;
201 function d3_bisector(compare) {
203 left: function(a, x, lo, hi) {
204 if (arguments.length < 3) lo = 0;
205 if (arguments.length < 4) hi = a.length;
207 var mid = lo + hi >>> 1;
208 if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
212 right: function(a, x, lo, hi) {
213 if (arguments.length < 3) lo = 0;
214 if (arguments.length < 4) hi = a.length;
216 var mid = lo + hi >>> 1;
217 if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
223 var d3_bisect = d3_bisector(d3_ascending);
224 d3.bisectLeft = d3_bisect.left;
225 d3.bisect = d3.bisectRight = d3_bisect.right;
226 d3.bisector = function(f) {
227 return d3_bisector(f.length === 1 ? function(d, x) {
228 return d3_ascending(f(d), x);
231 d3.shuffle = function(array, i0, i1) {
232 if ((m = arguments.length) < 3) {
236 var m = i1 - i0, t, i;
238 i = Math.random() * m-- | 0;
239 t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
243 d3.permute = function(array, indexes) {
244 var i = indexes.length, permutes = new Array(i);
245 while (i--) permutes[i] = array[indexes[i]];
248 d3.pairs = function(array) {
249 var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
250 while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
253 d3.transpose = function(matrix) {
254 if (!(n = matrix.length)) return [];
255 for (var i = -1, m = d3.min(matrix, d3_transposeLength), transpose = new Array(m); ++i < m; ) {
256 for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n; ) {
257 row[j] = matrix[j][i];
262 function d3_transposeLength(d) {
265 d3.zip = function() {
266 return d3.transpose(arguments);
268 d3.keys = function(map) {
270 for (var key in map) keys.push(key);
273 d3.values = function(map) {
275 for (var key in map) values.push(map[key]);
278 d3.entries = function(map) {
280 for (var key in map) entries.push({
286 d3.merge = function(arrays) {
287 var n = arrays.length, m, i = -1, j = 0, merged, array;
288 while (++i < n) j += arrays[i].length;
289 merged = new Array(j);
294 merged[--j] = array[m];
300 d3.range = function(start, stop, step) {
301 if (arguments.length < 3) {
303 if (arguments.length < 2) {
308 if ((stop - start) / step === Infinity) throw new Error("infinite range");
309 var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
310 start *= k, stop *= k, step *= k;
311 if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
314 function d3_range_integerScale(x) {
316 while (x * k % 1) k *= 10;
319 function d3_class(ctor, properties) {
320 for (var key in properties) {
321 Object.defineProperty(ctor.prototype, key, {
322 value: properties[key],
327 d3.map = function(object, f) {
328 var map = new d3_Map();
329 if (object instanceof d3_Map) {
330 object.forEach(function(key, value) {
333 } else if (Array.isArray(object)) {
334 var i = -1, n = object.length, o;
335 if (arguments.length === 1) while (++i < n) map.set(i, object[i]); else while (++i < n) map.set(f.call(object, o = object[i], i), o);
337 for (var key in object) map.set(key, object[key]);
342 this._ = Object.create(null);
344 var d3_map_proto = "__proto__", d3_map_zero = "\x00";
348 return this._[d3_map_escape(key)];
350 set: function(key, value) {
351 return this._[d3_map_escape(key)] = value;
353 remove: d3_map_remove,
357 for (var key in this._) values.push(this._[key]);
360 entries: function() {
362 for (var key in this._) entries.push({
363 key: d3_map_unescape(key),
370 forEach: function(f) {
371 for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
374 function d3_map_escape(key) {
375 return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
377 function d3_map_unescape(key) {
378 return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
380 function d3_map_has(key) {
381 return d3_map_escape(key) in this._;
383 function d3_map_remove(key) {
384 return (key = d3_map_escape(key)) in this._ && delete this._[key];
386 function d3_map_keys() {
388 for (var key in this._) keys.push(d3_map_unescape(key));
391 function d3_map_size() {
393 for (var key in this._) ++size;
396 function d3_map_empty() {
397 for (var key in this._) return false;
400 d3.nest = function() {
401 var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
402 function map(mapType, array, depth) {
403 if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
404 var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
406 if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
409 valuesByKey.set(keyValue, [ object ]);
414 setter = function(keyValue, values) {
415 object.set(keyValue, map(mapType, values, depth));
419 setter = function(keyValue, values) {
420 object[keyValue] = map(mapType, values, depth);
423 valuesByKey.forEach(setter);
426 function entries(map, depth) {
427 if (depth >= keys.length) return map;
428 var array = [], sortKey = sortKeys[depth++];
429 map.forEach(function(key, keyMap) {
432 values: entries(keyMap, depth)
435 return sortKey ? array.sort(function(a, b) {
436 return sortKey(a.key, b.key);
439 nest.map = function(array, mapType) {
440 return map(mapType, array, 0);
442 nest.entries = function(array) {
443 return entries(map(d3.map, array, 0), 0);
445 nest.key = function(d) {
449 nest.sortKeys = function(order) {
450 sortKeys[keys.length - 1] = order;
453 nest.sortValues = function(order) {
457 nest.rollup = function(f) {
463 d3.set = function(array) {
464 var set = new d3_Set();
465 if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
469 this._ = Object.create(null);
474 this._[d3_map_escape(key += "")] = true;
477 remove: d3_map_remove,
481 forEach: function(f) {
482 for (var key in this._) f.call(this, d3_map_unescape(key));
486 function d3_identity(d) {
489 d3.rebind = function(target, source) {
490 var i = 1, n = arguments.length, method;
491 while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
494 function d3_rebind(target, source, method) {
496 var value = method.apply(source, arguments);
497 return value === source ? target : value;
500 function d3_vendorSymbol(object, name) {
501 if (name in object) return name;
502 name = name.charAt(0).toUpperCase() + name.slice(1);
503 for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
504 var prefixName = d3_vendorPrefixes[i] + name;
505 if (prefixName in object) return prefixName;
508 var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
509 function d3_noop() {}
510 d3.dispatch = function() {
511 var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
512 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
515 function d3_dispatch() {}
516 d3_dispatch.prototype.on = function(type, listener) {
517 var i = type.indexOf("."), name = "";
519 name = type.slice(i + 1);
520 type = type.slice(0, i);
522 if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
523 if (arguments.length === 2) {
524 if (listener == null) for (type in this) {
525 if (this.hasOwnProperty(type)) this[type].on(name, null);
530 function d3_dispatch_event(dispatch) {
531 var listeners = [], listenerByName = new d3_Map();
533 var z = listeners, i = -1, n = z.length, l;
534 while (++i < n) if (l = z[i].on) l.apply(this, arguments);
537 event.on = function(name, listener) {
538 var l = listenerByName.get(name), i;
539 if (arguments.length < 2) return l && l.on;
542 listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
543 listenerByName.remove(name);
545 if (listener) listeners.push(listenerByName.set(name, {
553 function d3_eventPreventDefault() {
554 d3.event.preventDefault();
556 function d3_eventSource() {
558 while (s = e.sourceEvent) e = s;
561 function d3_eventDispatch(target) {
562 var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
563 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
564 dispatch.of = function(thiz, argumentz) {
565 return function(e1) {
567 var e0 = e1.sourceEvent = d3.event;
570 dispatch[e1.type].apply(thiz, argumentz);
578 d3.requote = function(s) {
579 return s.replace(d3_requote_re, "\\$&");
581 var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
582 var d3_subclass = {}.__proto__ ? function(object, prototype) {
583 object.__proto__ = prototype;
584 } : function(object, prototype) {
585 for (var property in prototype) object[property] = prototype[property];
587 function d3_selection(groups) {
588 d3_subclass(groups, d3_selectionPrototype);
591 var d3_select = function(s, n) {
592 return n.querySelector(s);
593 }, d3_selectAll = function(s, n) {
594 return n.querySelectorAll(s);
595 }, d3_selectMatches = function(n, s) {
596 var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")];
597 d3_selectMatches = function(n, s) {
598 return d3_selectMatcher.call(n, s);
600 return d3_selectMatches(n, s);
602 if (typeof Sizzle === "function") {
603 d3_select = function(s, n) {
604 return Sizzle(s, n)[0] || null;
606 d3_selectAll = Sizzle;
607 d3_selectMatches = Sizzle.matchesSelector;
609 d3.selection = function() {
610 return d3.select(d3_document.documentElement);
612 var d3_selectionPrototype = d3.selection.prototype = [];
613 d3_selectionPrototype.select = function(selector) {
614 var subgroups = [], subgroup, subnode, group, node;
615 selector = d3_selection_selector(selector);
616 for (var j = -1, m = this.length; ++j < m; ) {
617 subgroups.push(subgroup = []);
618 subgroup.parentNode = (group = this[j]).parentNode;
619 for (var i = -1, n = group.length; ++i < n; ) {
620 if (node = group[i]) {
621 subgroup.push(subnode = selector.call(node, node.__data__, i, j));
622 if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
628 return d3_selection(subgroups);
630 function d3_selection_selector(selector) {
631 return typeof selector === "function" ? selector : function() {
632 return d3_select(selector, this);
635 d3_selectionPrototype.selectAll = function(selector) {
636 var subgroups = [], subgroup, node;
637 selector = d3_selection_selectorAll(selector);
638 for (var j = -1, m = this.length; ++j < m; ) {
639 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
640 if (node = group[i]) {
641 subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
642 subgroup.parentNode = node;
646 return d3_selection(subgroups);
648 function d3_selection_selectorAll(selector) {
649 return typeof selector === "function" ? selector : function() {
650 return d3_selectAll(selector, this);
653 var d3_nsXhtml = "http://www.w3.org/1999/xhtml";
655 svg: "http://www.w3.org/2000/svg",
657 xlink: "http://www.w3.org/1999/xlink",
658 xml: "http://www.w3.org/XML/1998/namespace",
659 xmlns: "http://www.w3.org/2000/xmlns/"
663 qualify: function(name) {
664 var i = name.indexOf(":"), prefix = name;
665 if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
666 return d3_nsPrefix.hasOwnProperty(prefix) ? {
667 space: d3_nsPrefix[prefix],
672 d3_selectionPrototype.attr = function(name, value) {
673 if (arguments.length < 2) {
674 if (typeof name === "string") {
675 var node = this.node();
676 name = d3.ns.qualify(name);
677 return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
679 for (value in name) this.each(d3_selection_attr(value, name[value]));
682 return this.each(d3_selection_attr(name, value));
684 function d3_selection_attr(name, value) {
685 name = d3.ns.qualify(name);
686 function attrNull() {
687 this.removeAttribute(name);
689 function attrNullNS() {
690 this.removeAttributeNS(name.space, name.local);
692 function attrConstant() {
693 this.setAttribute(name, value);
695 function attrConstantNS() {
696 this.setAttributeNS(name.space, name.local, value);
698 function attrFunction() {
699 var x = value.apply(this, arguments);
700 if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
702 function attrFunctionNS() {
703 var x = value.apply(this, arguments);
704 if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
706 return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
708 function d3_collapse(s) {
709 return s.trim().replace(/\s+/g, " ");
711 d3_selectionPrototype.classed = function(name, value) {
712 if (arguments.length < 2) {
713 if (typeof name === "string") {
714 var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
715 if (value = node.classList) {
716 while (++i < n) if (!value.contains(name[i])) return false;
718 value = node.getAttribute("class");
719 while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
723 for (value in name) this.each(d3_selection_classed(value, name[value]));
726 return this.each(d3_selection_classed(name, value));
728 function d3_selection_classedRe(name) {
729 return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
731 function d3_selection_classes(name) {
732 return (name + "").trim().split(/^|\s+/);
734 function d3_selection_classed(name, value) {
735 name = d3_selection_classes(name).map(d3_selection_classedName);
737 function classedConstant() {
739 while (++i < n) name[i](this, value);
741 function classedFunction() {
742 var i = -1, x = value.apply(this, arguments);
743 while (++i < n) name[i](this, x);
745 return typeof value === "function" ? classedFunction : classedConstant;
747 function d3_selection_classedName(name) {
748 var re = d3_selection_classedRe(name);
749 return function(node, value) {
750 if (c = node.classList) return value ? c.add(name) : c.remove(name);
751 var c = node.getAttribute("class") || "";
754 if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
756 node.setAttribute("class", d3_collapse(c.replace(re, " ")));
760 d3_selectionPrototype.style = function(name, value, priority) {
761 var n = arguments.length;
763 if (typeof name !== "string") {
764 if (n < 2) value = "";
765 for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
769 var node = this.node();
770 return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
774 return this.each(d3_selection_style(name, value, priority));
776 function d3_selection_style(name, value, priority) {
777 function styleNull() {
778 this.style.removeProperty(name);
780 function styleConstant() {
781 this.style.setProperty(name, value, priority);
783 function styleFunction() {
784 var x = value.apply(this, arguments);
785 if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
787 return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
789 d3_selectionPrototype.property = function(name, value) {
790 if (arguments.length < 2) {
791 if (typeof name === "string") return this.node()[name];
792 for (value in name) this.each(d3_selection_property(value, name[value]));
795 return this.each(d3_selection_property(name, value));
797 function d3_selection_property(name, value) {
798 function propertyNull() {
801 function propertyConstant() {
804 function propertyFunction() {
805 var x = value.apply(this, arguments);
806 if (x == null) delete this[name]; else this[name] = x;
808 return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
810 d3_selectionPrototype.text = function(value) {
811 return arguments.length ? this.each(typeof value === "function" ? function() {
812 var v = value.apply(this, arguments);
813 this.textContent = v == null ? "" : v;
814 } : value == null ? function() {
815 this.textContent = "";
817 this.textContent = value;
818 }) : this.node().textContent;
820 d3_selectionPrototype.html = function(value) {
821 return arguments.length ? this.each(typeof value === "function" ? function() {
822 var v = value.apply(this, arguments);
823 this.innerHTML = v == null ? "" : v;
824 } : value == null ? function() {
827 this.innerHTML = value;
828 }) : this.node().innerHTML;
830 d3_selectionPrototype.append = function(name) {
831 name = d3_selection_creator(name);
832 return this.select(function() {
833 return this.appendChild(name.apply(this, arguments));
836 function d3_selection_creator(name) {
838 var document = this.ownerDocument, namespace = this.namespaceURI;
839 return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml ? document.createElement(name) : document.createElementNS(namespace, name);
841 function createNS() {
842 return this.ownerDocument.createElementNS(name.space, name.local);
844 return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
846 d3_selectionPrototype.insert = function(name, before) {
847 name = d3_selection_creator(name);
848 before = d3_selection_selector(before);
849 return this.select(function() {
850 return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
853 d3_selectionPrototype.remove = function() {
854 return this.each(d3_selectionRemove);
856 function d3_selectionRemove() {
857 var parent = this.parentNode;
858 if (parent) parent.removeChild(this);
860 d3_selectionPrototype.data = function(value, key) {
861 var i = -1, n = this.length, group, node;
862 if (!arguments.length) {
863 value = new Array(n = (group = this[0]).length);
865 if (node = group[i]) {
866 value[i] = node.__data__;
871 function bind(group, groupData) {
872 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;
874 var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
875 for (i = -1; ++i < n; ) {
876 if (node = group[i]) {
877 if (nodeByKeyValue.has(keyValue = key.call(node, node.__data__, i))) {
880 nodeByKeyValue.set(keyValue, node);
882 keyValues[i] = keyValue;
885 for (i = -1; ++i < m; ) {
886 if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
887 enterNodes[i] = d3_selection_dataNode(nodeData);
888 } else if (node !== true) {
889 updateNodes[i] = node;
890 node.__data__ = nodeData;
892 nodeByKeyValue.set(keyValue, true);
894 for (i = -1; ++i < n; ) {
895 if (i in keyValues && nodeByKeyValue.get(keyValues[i]) !== true) {
896 exitNodes[i] = group[i];
900 for (i = -1; ++i < n0; ) {
902 nodeData = groupData[i];
904 node.__data__ = nodeData;
905 updateNodes[i] = node;
907 enterNodes[i] = d3_selection_dataNode(nodeData);
911 enterNodes[i] = d3_selection_dataNode(groupData[i]);
914 exitNodes[i] = group[i];
917 enterNodes.update = updateNodes;
918 enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
919 enter.push(enterNodes);
920 update.push(updateNodes);
921 exit.push(exitNodes);
923 var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
924 if (typeof value === "function") {
926 bind(group = this[i], value.call(group, group.parentNode.__data__, i));
930 bind(group = this[i], value);
933 update.enter = function() {
936 update.exit = function() {
941 function d3_selection_dataNode(data) {
946 d3_selectionPrototype.datum = function(value) {
947 return arguments.length ? this.property("__data__", value) : this.property("__data__");
949 d3_selectionPrototype.filter = function(filter) {
950 var subgroups = [], subgroup, group, node;
951 if (typeof filter !== "function") filter = d3_selection_filter(filter);
952 for (var j = 0, m = this.length; j < m; j++) {
953 subgroups.push(subgroup = []);
954 subgroup.parentNode = (group = this[j]).parentNode;
955 for (var i = 0, n = group.length; i < n; i++) {
956 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
961 return d3_selection(subgroups);
963 function d3_selection_filter(selector) {
965 return d3_selectMatches(this, selector);
968 d3_selectionPrototype.order = function() {
969 for (var j = -1, m = this.length; ++j < m; ) {
970 for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
971 if (node = group[i]) {
972 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
979 d3_selectionPrototype.sort = function(comparator) {
980 comparator = d3_selection_sortComparator.apply(this, arguments);
981 for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
984 function d3_selection_sortComparator(comparator) {
985 if (!arguments.length) comparator = d3_ascending;
986 return function(a, b) {
987 return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
990 d3_selectionPrototype.each = function(callback) {
991 return d3_selection_each(this, function(node, i, j) {
992 callback.call(node, node.__data__, i, j);
995 function d3_selection_each(groups, callback) {
996 for (var j = 0, m = groups.length; j < m; j++) {
997 for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
998 if (node = group[i]) callback(node, i, j);
1003 d3_selectionPrototype.call = function(callback) {
1004 var args = d3_array(arguments);
1005 callback.apply(args[0] = this, args);
1008 d3_selectionPrototype.empty = function() {
1009 return !this.node();
1011 d3_selectionPrototype.node = function() {
1012 for (var j = 0, m = this.length; j < m; j++) {
1013 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
1014 var node = group[i];
1015 if (node) return node;
1020 d3_selectionPrototype.size = function() {
1022 d3_selection_each(this, function() {
1027 function d3_selection_enter(selection) {
1028 d3_subclass(selection, d3_selection_enterPrototype);
1031 var d3_selection_enterPrototype = [];
1032 d3.selection.enter = d3_selection_enter;
1033 d3.selection.enter.prototype = d3_selection_enterPrototype;
1034 d3_selection_enterPrototype.append = d3_selectionPrototype.append;
1035 d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
1036 d3_selection_enterPrototype.node = d3_selectionPrototype.node;
1037 d3_selection_enterPrototype.call = d3_selectionPrototype.call;
1038 d3_selection_enterPrototype.size = d3_selectionPrototype.size;
1039 d3_selection_enterPrototype.select = function(selector) {
1040 var subgroups = [], subgroup, subnode, upgroup, group, node;
1041 for (var j = -1, m = this.length; ++j < m; ) {
1042 upgroup = (group = this[j]).update;
1043 subgroups.push(subgroup = []);
1044 subgroup.parentNode = group.parentNode;
1045 for (var i = -1, n = group.length; ++i < n; ) {
1046 if (node = group[i]) {
1047 subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
1048 subnode.__data__ = node.__data__;
1050 subgroup.push(null);
1054 return d3_selection(subgroups);
1056 d3_selection_enterPrototype.insert = function(name, before) {
1057 if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
1058 return d3_selectionPrototype.insert.call(this, name, before);
1060 function d3_selection_enterInsertBefore(enter) {
1062 return function(d, i, j) {
1063 var group = enter[j].update, n = group.length, node;
1064 if (j != j0) j0 = j, i0 = 0;
1065 if (i >= i0) i0 = i + 1;
1066 while (!(node = group[i0]) && ++i0 < n) ;
1070 d3.select = function(node) {
1072 if (typeof node === "string") {
1073 group = [ d3_select(node, d3_document) ];
1074 group.parentNode = d3_document.documentElement;
1077 group.parentNode = d3_documentElement(node);
1079 return d3_selection([ group ]);
1081 d3.selectAll = function(nodes) {
1083 if (typeof nodes === "string") {
1084 group = d3_array(d3_selectAll(nodes, d3_document));
1085 group.parentNode = d3_document.documentElement;
1087 group = d3_array(nodes);
1088 group.parentNode = null;
1090 return d3_selection([ group ]);
1092 d3_selectionPrototype.on = function(type, listener, capture) {
1093 var n = arguments.length;
1095 if (typeof type !== "string") {
1096 if (n < 2) listener = false;
1097 for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
1100 if (n < 2) return (n = this.node()["__on" + type]) && n._;
1103 return this.each(d3_selection_on(type, listener, capture));
1105 function d3_selection_on(type, listener, capture) {
1106 var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
1107 if (i > 0) type = type.slice(0, i);
1108 var filter = d3_selection_onFilters.get(type);
1109 if (filter) type = filter, wrap = d3_selection_onFilter;
1110 function onRemove() {
1113 this.removeEventListener(type, l, l.$);
1118 var l = wrap(listener, d3_array(arguments));
1119 onRemove.call(this);
1120 this.addEventListener(type, this[name] = l, l.$ = capture);
1123 function removeAll() {
1124 var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
1125 for (var name in this) {
1126 if (match = name.match(re)) {
1128 this.removeEventListener(match[1], l, l.$);
1133 return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
1135 var d3_selection_onFilters = d3.map({
1136 mouseenter: "mouseover",
1137 mouseleave: "mouseout"
1140 d3_selection_onFilters.forEach(function(k) {
1141 if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
1144 function d3_selection_onListener(listener, argumentz) {
1145 return function(e) {
1148 argumentz[0] = this.__data__;
1150 listener.apply(this, argumentz);
1156 function d3_selection_onFilter(listener, argumentz) {
1157 var l = d3_selection_onListener(listener, argumentz);
1158 return function(e) {
1159 var target = this, related = e.relatedTarget;
1160 if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
1165 var d3_event_dragSelect, d3_event_dragId = 0;
1166 function d3_event_dragSuppress(node) {
1167 var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window(node)).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
1168 if (d3_event_dragSelect == null) {
1169 d3_event_dragSelect = "onselectstart" in node ? false : d3_vendorSymbol(node.style, "userSelect");
1171 if (d3_event_dragSelect) {
1172 var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
1173 style[d3_event_dragSelect] = "none";
1175 return function(suppressClick) {
1177 if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
1178 if (suppressClick) {
1179 var off = function() {
1182 w.on(click, function() {
1183 d3_eventPreventDefault();
1190 d3.mouse = function(container) {
1191 return d3_mousePoint(container, d3_eventSource());
1193 var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
1194 function d3_mousePoint(container, e) {
1195 if (e.changedTouches) e = e.changedTouches[0];
1196 var svg = container.ownerSVGElement || container;
1197 if (svg.createSVGPoint) {
1198 var point = svg.createSVGPoint();
1199 if (d3_mouse_bug44083 < 0) {
1200 var window = d3_window(container);
1201 if (window.scrollX || window.scrollY) {
1202 svg = d3.select("body").append("svg").style({
1203 position: "absolute",
1210 var ctm = svg[0][0].getScreenCTM();
1211 d3_mouse_bug44083 = !(ctm.f || ctm.e);
1215 if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
1216 point.y = e.clientY;
1217 point = point.matrixTransform(container.getScreenCTM().inverse());
1218 return [ point.x, point.y ];
1220 var rect = container.getBoundingClientRect();
1221 return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
1223 d3.touch = function(container, touches, identifier) {
1224 if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
1225 if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
1226 if ((touch = touches[i]).identifier === identifier) {
1227 return d3_mousePoint(container, touch);
1231 d3.behavior.drag = function() {
1232 var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_window, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_identity, "touchmove", "touchend");
1234 this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
1236 function dragstart(id, position, subject, move, end) {
1238 var that = this, target = d3.event.target.correspondingElement || d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
1240 dragOffset = origin.apply(that, arguments);
1241 dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
1243 dragOffset = [ 0, 0 ];
1249 var position1 = position(parent, dragId), dx, dy;
1250 if (!position1) return;
1251 dx = position1[0] - position0[0];
1252 dy = position1[1] - position0[1];
1254 position0 = position1;
1257 x: position1[0] + dragOffset[0],
1258 y: position1[1] + dragOffset[1],
1264 if (!position(parent, dragId)) return;
1265 dragSubject.on(move + dragName, null).on(end + dragName, null);
1266 dragRestore(dragged);
1273 drag.origin = function(x) {
1274 if (!arguments.length) return origin;
1278 return d3.rebind(drag, event, "on");
1280 function d3_behavior_dragTouchId() {
1281 return d3.event.changedTouches[0].identifier;
1283 d3.touches = function(container, touches) {
1284 if (arguments.length < 2) touches = d3_eventSource().touches;
1285 return touches ? d3_array(touches).map(function(touch) {
1286 var point = d3_mousePoint(container, touch);
1287 point.identifier = touch.identifier;
1291 var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
1292 function d3_sgn(x) {
1293 return x > 0 ? 1 : x < 0 ? -1 : 0;
1295 function d3_cross2d(a, b, c) {
1296 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
1298 function d3_acos(x) {
1299 return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
1301 function d3_asin(x) {
1302 return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
1304 function d3_sinh(x) {
1305 return ((x = Math.exp(x)) - 1 / x) / 2;
1307 function d3_cosh(x) {
1308 return ((x = Math.exp(x)) + 1 / x) / 2;
1310 function d3_tanh(x) {
1311 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
1313 function d3_haversin(x) {
1314 return (x = Math.sin(x / 2)) * x;
1316 var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
1317 d3.interpolateZoom = function(p0, p1) {
1318 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2], dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, i, S;
1320 S = Math.log(w1 / w0) / ρ;
1322 return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * t * S) ];
1325 var 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);
1328 var s = t * S, coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
1329 return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
1332 i.duration = S * 1e3;
1335 d3.behavior.zoom = function() {
1340 }, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, duration = 250, zooming = 0, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
1341 if (!d3_behavior_zoomWheel) {
1342 d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
1343 return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
1344 }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
1345 return d3.event.wheelDelta;
1346 }, "mousewheel") : (d3_behavior_zoomDelta = function() {
1347 return -d3.event.detail;
1348 }, "MozMousePixelScroll");
1351 g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
1353 zoom.event = function(g) {
1355 var dispatch = event.of(this, arguments), view1 = view;
1356 if (d3_transitionInheritId) {
1357 d3.select(this).transition().each("start.zoom", function() {
1358 view = this.__chart__ || {
1363 zoomstarted(dispatch);
1364 }).tween("zoom:zoom", function() {
1365 var dx = size[0], dy = size[1], cx = center0 ? center0[0] : dx / 2, cy = center0 ? center0[1] : dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]);
1366 return function(t) {
1367 var l = i(t), k = dx / l[2];
1368 this.__chart__ = view = {
1375 }).each("interrupt.zoom", function() {
1376 zoomended(dispatch);
1377 }).each("end.zoom", function() {
1378 zoomended(dispatch);
1381 this.__chart__ = view;
1382 zoomstarted(dispatch);
1384 zoomended(dispatch);
1388 zoom.translate = function(_) {
1389 if (!arguments.length) return [ view.x, view.y ];
1398 zoom.scale = function(_) {
1399 if (!arguments.length) return view.k;
1409 zoom.scaleExtent = function(_) {
1410 if (!arguments.length) return scaleExtent;
1411 scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
1414 zoom.center = function(_) {
1415 if (!arguments.length) return center;
1416 center = _ && [ +_[0], +_[1] ];
1419 zoom.size = function(_) {
1420 if (!arguments.length) return size;
1421 size = _ && [ +_[0], +_[1] ];
1424 zoom.duration = function(_) {
1425 if (!arguments.length) return duration;
1429 zoom.x = function(z) {
1430 if (!arguments.length) return x1;
1440 zoom.y = function(z) {
1441 if (!arguments.length) return y1;
1451 function location(p) {
1452 return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
1455 return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
1457 function scaleTo(s) {
1458 view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
1460 function translateTo(p, l) {
1462 view.x += p[0] - l[0];
1463 view.y += p[1] - l[1];
1465 function zoomTo(that, p, l, k) {
1471 scaleTo(Math.pow(2, k));
1472 translateTo(center0 = p, l);
1473 that = d3.select(that);
1474 if (duration > 0) that = that.transition().duration(duration);
1475 that.call(zoom.event);
1477 function rescale() {
1478 if (x1) x1.domain(x0.range().map(function(x) {
1479 return (x - view.x) / view.k;
1481 if (y1) y1.domain(y0.range().map(function(y) {
1482 return (y - view.y) / view.k;
1485 function zoomstarted(dispatch) {
1486 if (!zooming++) dispatch({
1490 function zoomed(dispatch) {
1495 translate: [ view.x, view.y ]
1498 function zoomended(dispatch) {
1499 if (!--zooming) dispatch({
1503 function mousedowned() {
1504 var that = this, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress(that);
1505 d3_selection_interrupt.call(that);
1506 zoomstarted(dispatch);
1509 translateTo(d3.mouse(that), location0);
1513 subject.on(mousemove, null).on(mouseup, null);
1514 dragRestore(dragged);
1515 zoomended(dispatch);
1518 function touchstarted() {
1519 var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, targets = [], subject = d3.select(that), dragRestore = d3_event_dragSuppress(that);
1521 zoomstarted(dispatch);
1522 subject.on(mousedown, null).on(touchstart, started);
1523 function relocate() {
1524 var touches = d3.touches(that);
1526 touches.forEach(function(t) {
1527 if (t.identifier in locations0) locations0[t.identifier] = location(t);
1531 function started() {
1532 var target = d3.event.target;
1533 d3.select(target).on(touchmove, moved).on(touchend, ended);
1534 targets.push(target);
1535 var changed = d3.event.changedTouches;
1536 for (var i = 0, n = changed.length; i < n; ++i) {
1537 locations0[changed[i].identifier] = null;
1539 var touches = relocate(), now = Date.now();
1540 if (touches.length === 1) {
1541 if (now - touchtime < 500) {
1543 zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
1544 d3_eventPreventDefault();
1547 } else if (touches.length > 1) {
1548 var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
1549 distance0 = dx * dx + dy * dy;
1553 var touches = d3.touches(that), p0, l0, p1, l1;
1554 d3_selection_interrupt.call(that);
1555 for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
1557 if (l1 = locations0[p1.identifier]) {
1563 var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
1564 p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
1565 l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
1566 scaleTo(scale1 * scale0);
1569 translateTo(p0, l0);
1573 if (d3.event.touches.length) {
1574 var changed = d3.event.changedTouches;
1575 for (var i = 0, n = changed.length; i < n; ++i) {
1576 delete locations0[changed[i].identifier];
1578 for (var identifier in locations0) {
1579 return void relocate();
1582 d3.selectAll(targets).on(zoomName, null);
1583 subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
1585 zoomended(dispatch);
1588 function mousewheeled() {
1589 var dispatch = event.of(this, arguments);
1590 if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
1591 translate0 = location(center0 = center || d3.mouse(this)), zoomstarted(dispatch);
1592 mousewheelTimer = setTimeout(function() {
1593 mousewheelTimer = null;
1594 zoomended(dispatch);
1596 d3_eventPreventDefault();
1597 scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
1598 translateTo(center0, translate0);
1601 function dblclicked() {
1602 var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
1603 zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
1605 return d3.rebind(zoom, event, "on");
1607 var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
1608 d3.color = d3_color;
1609 function d3_color() {}
1610 d3_color.prototype.toString = function() {
1611 return this.rgb() + "";
1614 function d3_hsl(h, s, l) {
1615 return this instanceof d3_hsl ? void (this.h = +h, this.s = +s, this.l = +l) : arguments.length < 2 ? h instanceof d3_hsl ? new d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : new d3_hsl(h, s, l);
1617 var d3_hslPrototype = d3_hsl.prototype = new d3_color();
1618 d3_hslPrototype.brighter = function(k) {
1619 k = Math.pow(.7, arguments.length ? k : 1);
1620 return new d3_hsl(this.h, this.s, this.l / k);
1622 d3_hslPrototype.darker = function(k) {
1623 k = Math.pow(.7, arguments.length ? k : 1);
1624 return new d3_hsl(this.h, this.s, k * this.l);
1626 d3_hslPrototype.rgb = function() {
1627 return d3_hsl_rgb(this.h, this.s, this.l);
1629 function d3_hsl_rgb(h, s, l) {
1631 h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
1632 s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
1633 l = l < 0 ? 0 : l > 1 ? 1 : l;
1634 m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
1637 if (h > 360) h -= 360; else if (h < 0) h += 360;
1638 if (h < 60) return m1 + (m2 - m1) * h / 60;
1639 if (h < 180) return m2;
1640 if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
1644 return Math.round(v(h) * 255);
1646 return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
1649 function d3_hcl(h, c, l) {
1650 return this instanceof d3_hcl ? void (this.h = +h, this.c = +c, this.l = +l) : arguments.length < 2 ? h instanceof d3_hcl ? new d3_hcl(h.h, h.c, h.l) : h instanceof d3_lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : new d3_hcl(h, c, l);
1652 var d3_hclPrototype = d3_hcl.prototype = new d3_color();
1653 d3_hclPrototype.brighter = function(k) {
1654 return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
1656 d3_hclPrototype.darker = function(k) {
1657 return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
1659 d3_hclPrototype.rgb = function() {
1660 return d3_hcl_lab(this.h, this.c, this.l).rgb();
1662 function d3_hcl_lab(h, c, l) {
1663 if (isNaN(h)) h = 0;
1664 if (isNaN(c)) c = 0;
1665 return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
1668 function d3_lab(l, a, b) {
1669 return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) : arguments.length < 2 ? l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) : l instanceof d3_hcl ? d3_hcl_lab(l.h, l.c, l.l) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b);
1672 var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
1673 var d3_labPrototype = d3_lab.prototype = new d3_color();
1674 d3_labPrototype.brighter = function(k) {
1675 return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1677 d3_labPrototype.darker = function(k) {
1678 return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1680 d3_labPrototype.rgb = function() {
1681 return d3_lab_rgb(this.l, this.a, this.b);
1683 function d3_lab_rgb(l, a, b) {
1684 var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
1685 x = d3_lab_xyz(x) * d3_lab_X;
1686 y = d3_lab_xyz(y) * d3_lab_Y;
1687 z = d3_lab_xyz(z) * d3_lab_Z;
1688 return new d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
1690 function d3_lab_hcl(l, a, b) {
1691 return l > 0 ? new d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : new d3_hcl(NaN, NaN, l);
1693 function d3_lab_xyz(x) {
1694 return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
1696 function d3_xyz_lab(x) {
1697 return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
1699 function d3_xyz_rgb(r) {
1700 return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
1703 function d3_rgb(r, g, b) {
1704 return this instanceof d3_rgb ? void (this.r = ~~r, this.g = ~~g, this.b = ~~b) : arguments.length < 2 ? r instanceof d3_rgb ? new d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : new d3_rgb(r, g, b);
1706 function d3_rgbNumber(value) {
1707 return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
1709 function d3_rgbString(value) {
1710 return d3_rgbNumber(value) + "";
1712 var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
1713 d3_rgbPrototype.brighter = function(k) {
1714 k = Math.pow(.7, arguments.length ? k : 1);
1715 var r = this.r, g = this.g, b = this.b, i = 30;
1716 if (!r && !g && !b) return new d3_rgb(i, i, i);
1717 if (r && r < i) r = i;
1718 if (g && g < i) g = i;
1719 if (b && b < i) b = i;
1720 return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
1722 d3_rgbPrototype.darker = function(k) {
1723 k = Math.pow(.7, arguments.length ? k : 1);
1724 return new d3_rgb(k * this.r, k * this.g, k * this.b);
1726 d3_rgbPrototype.hsl = function() {
1727 return d3_rgb_hsl(this.r, this.g, this.b);
1729 d3_rgbPrototype.toString = function() {
1730 return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
1732 function d3_rgb_hex(v) {
1733 return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
1735 function d3_rgb_parse(format, rgb, hsl) {
1736 var r = 0, g = 0, b = 0, m1, m2, color;
1737 m1 = /([a-z]+)\((.*)\)/.exec(format = format.toLowerCase());
1739 m2 = m1[2].split(",");
1743 return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
1748 return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
1752 if (color = d3_rgb_names.get(format)) {
1753 return rgb(color.r, color.g, color.b);
1755 if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
1756 if (format.length === 4) {
1757 r = (color & 3840) >> 4;
1763 } else if (format.length === 7) {
1764 r = (color & 16711680) >> 16;
1765 g = (color & 65280) >> 8;
1769 return rgb(r, g, b);
1771 function d3_rgb_hsl(r, g, b) {
1772 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;
1774 s = l < .5 ? d / (max + min) : d / (2 - max - min);
1775 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;
1779 s = l > 0 && l < 1 ? 0 : h;
1781 return new d3_hsl(h, s, l);
1783 function d3_rgb_lab(r, g, b) {
1787 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);
1788 return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
1790 function d3_rgb_xyz(r) {
1791 return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
1793 function d3_rgb_parseNumber(c) {
1794 var f = parseFloat(c);
1795 return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
1797 var d3_rgb_names = d3.map({
1798 aliceblue: 15792383,
1799 antiquewhite: 16444375,
1801 aquamarine: 8388564,
1806 blanchedalmond: 16772045,
1808 blueviolet: 9055202,
1810 burlywood: 14596231,
1812 chartreuse: 8388352,
1813 chocolate: 13789470,
1815 cornflowerblue: 6591981,
1821 darkgoldenrod: 12092939,
1825 darkkhaki: 12433259,
1826 darkmagenta: 9109643,
1827 darkolivegreen: 5597999,
1828 darkorange: 16747520,
1829 darkorchid: 10040012,
1831 darksalmon: 15308410,
1832 darkseagreen: 9419919,
1833 darkslateblue: 4734347,
1834 darkslategray: 3100495,
1835 darkslategrey: 3100495,
1836 darkturquoise: 52945,
1837 darkviolet: 9699539,
1842 dodgerblue: 2003199,
1843 firebrick: 11674146,
1844 floralwhite: 16775920,
1845 forestgreen: 2263842,
1847 gainsboro: 14474460,
1848 ghostwhite: 16316671,
1850 goldenrod: 14329120,
1853 greenyellow: 11403055,
1857 indianred: 13458524,
1862 lavenderblush: 16773365,
1864 lemonchiffon: 16775885,
1865 lightblue: 11393254,
1866 lightcoral: 15761536,
1867 lightcyan: 14745599,
1868 lightgoldenrodyellow: 16448210,
1869 lightgray: 13882323,
1870 lightgreen: 9498256,
1871 lightgrey: 13882323,
1872 lightpink: 16758465,
1873 lightsalmon: 16752762,
1874 lightseagreen: 2142890,
1875 lightskyblue: 8900346,
1876 lightslategray: 7833753,
1877 lightslategrey: 7833753,
1878 lightsteelblue: 11584734,
1879 lightyellow: 16777184,
1885 mediumaquamarine: 6737322,
1887 mediumorchid: 12211667,
1888 mediumpurple: 9662683,
1889 mediumseagreen: 3978097,
1890 mediumslateblue: 8087790,
1891 mediumspringgreen: 64154,
1892 mediumturquoise: 4772300,
1893 mediumvioletred: 13047173,
1894 midnightblue: 1644912,
1895 mintcream: 16121850,
1896 mistyrose: 16770273,
1898 navajowhite: 16768685,
1904 orangered: 16729344,
1906 palegoldenrod: 15657130,
1907 palegreen: 10025880,
1908 paleturquoise: 11529966,
1909 palevioletred: 14381203,
1910 papayawhip: 16773077,
1911 peachpuff: 16767673,
1915 powderblue: 11591910,
1917 rebeccapurple: 6697881,
1919 rosybrown: 12357519,
1921 saddlebrown: 9127187,
1923 sandybrown: 16032864,
1943 whitesmoke: 16119285,
1945 yellowgreen: 10145074
1947 d3_rgb_names.forEach(function(key, value) {
1948 d3_rgb_names.set(key, d3_rgbNumber(value));
1950 function d3_functor(v) {
1951 return typeof v === "function" ? v : function() {
1955 d3.functor = d3_functor;
1956 d3.xhr = d3_xhrType(d3_identity);
1957 function d3_xhrType(response) {
1958 return function(url, mimeType, callback) {
1959 if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
1961 return d3_xhr(url, mimeType, response, callback);
1964 function d3_xhr(url, mimeType, response, callback) {
1965 var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
1966 if (this.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
1967 "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
1968 request.readyState > 3 && respond();
1970 function respond() {
1971 var status = request.status, result;
1972 if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
1974 result = response.call(xhr, request);
1976 dispatch.error.call(xhr, e);
1979 dispatch.load.call(xhr, result);
1981 dispatch.error.call(xhr, request);
1984 request.onprogress = function(event) {
1988 dispatch.progress.call(xhr, request);
1993 xhr.header = function(name, value) {
1994 name = (name + "").toLowerCase();
1995 if (arguments.length < 2) return headers[name];
1996 if (value == null) delete headers[name]; else headers[name] = value + "";
1999 xhr.mimeType = function(value) {
2000 if (!arguments.length) return mimeType;
2001 mimeType = value == null ? null : value + "";
2004 xhr.responseType = function(value) {
2005 if (!arguments.length) return responseType;
2006 responseType = value;
2009 xhr.response = function(value) {
2013 [ "get", "post" ].forEach(function(method) {
2014 xhr[method] = function() {
2015 return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
2018 xhr.send = function(method, data, callback) {
2019 if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
2020 request.open(method, url, true);
2021 if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
2022 if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
2023 if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
2024 if (responseType != null) request.responseType = responseType;
2025 if (callback != null) xhr.on("error", callback).on("load", function(request) {
2026 callback(null, request);
2028 dispatch.beforesend.call(xhr, request);
2029 request.send(data == null ? null : data);
2032 xhr.abort = function() {
2036 d3.rebind(xhr, dispatch, "on");
2037 return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
2039 function d3_xhr_fixCallback(callback) {
2040 return callback.length === 1 ? function(error, request) {
2041 callback(error == null ? request : null);
2044 function d3_xhrHasResponse(request) {
2045 var type = request.responseType;
2046 return type && type !== "text" ? request.response : request.responseText;
2048 d3.dsv = function(delimiter, mimeType) {
2049 var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
2050 function dsv(url, row, callback) {
2051 if (arguments.length < 3) callback = row, row = null;
2052 var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
2053 xhr.row = function(_) {
2054 return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
2058 function response(request) {
2059 return dsv.parse(request.responseText);
2061 function typedResponse(f) {
2062 return function(request) {
2063 return dsv.parse(request.responseText, f);
2066 dsv.parse = function(text, f) {
2068 return dsv.parseRows(text, function(row, i) {
2069 if (o) return o(row, i - 1);
2070 var a = new Function("d", "return {" + row.map(function(name, i) {
2071 return JSON.stringify(name) + ": d[" + i + "]";
2072 }).join(",") + "}");
2073 o = f ? function(row, i) {
2074 return f(a(row), i);
2078 dsv.parseRows = function(text, f) {
2079 var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
2081 if (I >= N) return EOF;
2082 if (eol) return eol = false, EOL;
2084 if (text.charCodeAt(j) === 34) {
2087 if (text.charCodeAt(i) === 34) {
2088 if (text.charCodeAt(i + 1) !== 34) break;
2093 var c = text.charCodeAt(i + 1);
2096 if (text.charCodeAt(i + 2) === 10) ++I;
2097 } else if (c === 10) {
2100 return text.slice(j + 1, i).replace(/""/g, '"');
2103 var c = text.charCodeAt(I++), k = 1;
2104 if (c === 10) eol = true; else if (c === 13) {
2106 if (text.charCodeAt(I) === 10) ++I, ++k;
2107 } else if (c !== delimiterCode) continue;
2108 return text.slice(j, I - k);
2110 return text.slice(j);
2112 while ((t = token()) !== EOF) {
2114 while (t !== EOL && t !== EOF) {
2118 if (f && (a = f(a, n++)) == null) continue;
2123 dsv.format = function(rows) {
2124 if (Array.isArray(rows[0])) return dsv.formatRows(rows);
2125 var fieldSet = new d3_Set(), fields = [];
2126 rows.forEach(function(row) {
2127 for (var field in row) {
2128 if (!fieldSet.has(field)) {
2129 fields.push(fieldSet.add(field));
2133 return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
2134 return fields.map(function(field) {
2135 return formatValue(row[field]);
2139 dsv.formatRows = function(rows) {
2140 return rows.map(formatRow).join("\n");
2142 function formatRow(row) {
2143 return row.map(formatValue).join(delimiter);
2145 function formatValue(text) {
2146 return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
2150 d3.csv = d3.dsv(",", "text/csv");
2151 d3.tsv = d3.dsv(" ", "text/tab-separated-values");
2152 var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
2153 setTimeout(callback, 17);
2155 d3.timer = function() {
2156 d3_timer.apply(this, arguments);
2158 function d3_timer(callback, delay, then) {
2159 var n = arguments.length;
2160 if (n < 2) delay = 0;
2161 if (n < 3) then = Date.now();
2162 var time = then + delay, timer = {
2167 if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
2168 d3_timer_queueTail = timer;
2169 if (!d3_timer_interval) {
2170 d3_timer_timeout = clearTimeout(d3_timer_timeout);
2171 d3_timer_interval = 1;
2172 d3_timer_frame(d3_timer_step);
2176 function d3_timer_step() {
2177 var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
2179 if (isFinite(delay)) {
2180 clearTimeout(d3_timer_timeout);
2181 d3_timer_timeout = setTimeout(d3_timer_step, delay);
2183 d3_timer_interval = 0;
2185 d3_timer_interval = 1;
2186 d3_timer_frame(d3_timer_step);
2189 d3.timer.flush = function() {
2193 function d3_timer_mark() {
2194 var now = Date.now(), timer = d3_timer_queueHead;
2196 if (now >= timer.t && timer.c(now - timer.t)) timer.c = null;
2201 function d3_timer_sweep() {
2202 var t0, t1 = d3_timer_queueHead, time = Infinity;
2205 if (t1.t < time) time = t1.t;
2208 t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
2211 d3_timer_queueTail = t0;
2214 function d3_format_precision(x, p) {
2215 return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
2217 d3.round = function(x, n) {
2218 return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
2220 var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
2221 d3.formatPrefix = function(value, precision) {
2223 if (value = +value) {
2224 if (value < 0) value *= -1;
2225 if (precision) value = d3.round(value, d3_format_precision(value, precision));
2226 i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
2227 i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
2229 return d3_formatPrefixes[8 + i / 3];
2231 function d3_formatPrefix(d, i) {
2232 var k = Math.pow(10, abs(8 - i) * 3);
2234 scale: i > 8 ? function(d) {
2242 function d3_locale_numberFormat(locale) {
2243 var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping && locale_thousands ? function(value, width) {
2244 var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
2245 while (i > 0 && g > 0) {
2246 if (length + g + 1 > width) g = Math.max(1, width - length);
2247 t.push(value.substring(i -= g, i + g));
2248 if ((length += g + 1) > width) break;
2249 g = locale_grouping[j = (j + 1) % locale_grouping.length];
2251 return t.reverse().join(locale_thousands);
2253 return function(specifier) {
2254 var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "-", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false, exponent = true;
2255 if (precision) precision = +precision.substring(1);
2256 if (zfill || fill === "0" && align === "=") {
2282 if (symbol === "#") prefix = "0" + type.toLowerCase();
2297 if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
2298 if (type == "r" && !precision) type = "g";
2299 if (precision != null) {
2300 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));
2302 type = d3_format_types.get(type) || d3_format_typeDefault;
2303 var zcomma = zfill && comma;
2304 return function(value) {
2305 var fullSuffix = suffix;
2306 if (integer && value % 1) return "";
2307 var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
2309 var unit = d3.formatPrefix(value, precision);
2310 value = unit.scale(value);
2311 fullSuffix = unit.symbol + suffix;
2315 value = type(value, precision);
2316 var i = value.lastIndexOf("."), before, after;
2318 var j = exponent ? value.lastIndexOf("e") : -1;
2319 if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
2321 before = value.substring(0, i);
2322 after = locale_decimal + value.substring(i + 1);
2324 if (!zfill && comma) before = formatGroup(before, Infinity);
2325 var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
2326 if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
2328 value = before + after;
2329 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;
2333 var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
2334 var d3_format_types = d3.map({
2336 return x.toString(2);
2339 return String.fromCharCode(x);
2342 return x.toString(8);
2345 return x.toString(16);
2348 return x.toString(16).toUpperCase();
2351 return x.toPrecision(p);
2354 return x.toExponential(p);
2357 return x.toFixed(p);
2360 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))));
2363 function d3_format_typeDefault(x) {
2366 var d3_time = d3.time = {}, d3_date = Date;
2367 function d3_date_utc() {
2368 this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
2370 d3_date_utc.prototype = {
2371 getDate: function() {
2372 return this._.getUTCDate();
2374 getDay: function() {
2375 return this._.getUTCDay();
2377 getFullYear: function() {
2378 return this._.getUTCFullYear();
2380 getHours: function() {
2381 return this._.getUTCHours();
2383 getMilliseconds: function() {
2384 return this._.getUTCMilliseconds();
2386 getMinutes: function() {
2387 return this._.getUTCMinutes();
2389 getMonth: function() {
2390 return this._.getUTCMonth();
2392 getSeconds: function() {
2393 return this._.getUTCSeconds();
2395 getTime: function() {
2396 return this._.getTime();
2398 getTimezoneOffset: function() {
2401 valueOf: function() {
2402 return this._.valueOf();
2404 setDate: function() {
2405 d3_time_prototype.setUTCDate.apply(this._, arguments);
2407 setDay: function() {
2408 d3_time_prototype.setUTCDay.apply(this._, arguments);
2410 setFullYear: function() {
2411 d3_time_prototype.setUTCFullYear.apply(this._, arguments);
2413 setHours: function() {
2414 d3_time_prototype.setUTCHours.apply(this._, arguments);
2416 setMilliseconds: function() {
2417 d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
2419 setMinutes: function() {
2420 d3_time_prototype.setUTCMinutes.apply(this._, arguments);
2422 setMonth: function() {
2423 d3_time_prototype.setUTCMonth.apply(this._, arguments);
2425 setSeconds: function() {
2426 d3_time_prototype.setUTCSeconds.apply(this._, arguments);
2428 setTime: function() {
2429 d3_time_prototype.setTime.apply(this._, arguments);
2432 var d3_time_prototype = Date.prototype;
2433 function d3_time_interval(local, step, number) {
2434 function round(date) {
2435 var d0 = local(date), d1 = offset(d0, 1);
2436 return date - d0 < d1 - date ? d0 : d1;
2438 function ceil(date) {
2439 step(date = local(new d3_date(date - 1)), 1);
2442 function offset(date, k) {
2443 step(date = new d3_date(+date), k);
2446 function range(t0, t1, dt) {
2447 var time = ceil(t0), times = [];
2450 if (!(number(time) % dt)) times.push(new Date(+time));
2454 while (time < t1) times.push(new Date(+time)), step(time, 1);
2458 function range_utc(t0, t1, dt) {
2460 d3_date = d3_date_utc;
2461 var utc = new d3_date_utc();
2463 return range(utc, t1, dt);
2468 local.floor = local;
2469 local.round = round;
2471 local.offset = offset;
2472 local.range = range;
2473 var utc = local.utc = d3_time_interval_utc(local);
2475 utc.round = d3_time_interval_utc(round);
2476 utc.ceil = d3_time_interval_utc(ceil);
2477 utc.offset = d3_time_interval_utc(offset);
2478 utc.range = range_utc;
2481 function d3_time_interval_utc(method) {
2482 return function(date, k) {
2484 d3_date = d3_date_utc;
2485 var utc = new d3_date_utc();
2487 return method(utc, k)._;
2493 d3_time.year = d3_time_interval(function(date) {
2494 date = d3_time.day(date);
2495 date.setMonth(0, 1);
2497 }, function(date, offset) {
2498 date.setFullYear(date.getFullYear() + offset);
2500 return date.getFullYear();
2502 d3_time.years = d3_time.year.range;
2503 d3_time.years.utc = d3_time.year.utc.range;
2504 d3_time.day = d3_time_interval(function(date) {
2505 var day = new d3_date(2e3, 0);
2506 day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
2508 }, function(date, offset) {
2509 date.setDate(date.getDate() + offset);
2511 return date.getDate() - 1;
2513 d3_time.days = d3_time.day.range;
2514 d3_time.days.utc = d3_time.day.utc.range;
2515 d3_time.dayOfYear = function(date) {
2516 var year = d3_time.year(date);
2517 return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
2519 [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
2521 var interval = d3_time[day] = d3_time_interval(function(date) {
2522 (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
2524 }, function(date, offset) {
2525 date.setDate(date.getDate() + Math.floor(offset) * 7);
2527 var day = d3_time.year(date).getDay();
2528 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
2530 d3_time[day + "s"] = interval.range;
2531 d3_time[day + "s"].utc = interval.utc.range;
2532 d3_time[day + "OfYear"] = function(date) {
2533 var day = d3_time.year(date).getDay();
2534 return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
2537 d3_time.week = d3_time.sunday;
2538 d3_time.weeks = d3_time.sunday.range;
2539 d3_time.weeks.utc = d3_time.sunday.utc.range;
2540 d3_time.weekOfYear = d3_time.sundayOfYear;
2541 function d3_locale_timeFormat(locale) {
2542 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;
2543 function d3_time_format(template) {
2544 var n = template.length;
2545 function format(date) {
2546 var string = [], i = -1, j = 0, c, p, f;
2548 if (template.charCodeAt(i) === 37) {
2549 string.push(template.slice(j, i));
2550 if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
2551 if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
2556 string.push(template.slice(j, i));
2557 return string.join("");
2559 format.parse = function(string) {
2569 }, i = d3_time_parse(d, template, string, 0);
2570 if (i != string.length) return null;
2571 if ("p" in d) d.H = d.H % 12 + d.p * 12;
2572 var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
2573 if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("W" in d || "U" in d) {
2574 if (!("w" in d)) d.w = "W" in d ? 1 : 0;
2575 date.setFullYear(d.y, 0, 1);
2576 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);
2577 } else date.setFullYear(d.y, d.m, d.d);
2578 date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
2579 return localZ ? date._ : date;
2581 format.toString = function() {
2586 function d3_time_parse(date, template, string, j) {
2587 var c, p, t, i = 0, n = template.length, m = string.length;
2589 if (j >= m) return -1;
2590 c = template.charCodeAt(i++);
2592 t = template.charAt(i++);
2593 p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
2594 if (!p || (j = p(date, string, j)) < 0) return -1;
2595 } else if (c != string.charCodeAt(j++)) {
2601 d3_time_format.utc = function(template) {
2602 var local = d3_time_format(template);
2603 function format(date) {
2605 d3_date = d3_date_utc;
2606 var utc = new d3_date();
2613 format.parse = function(string) {
2615 d3_date = d3_date_utc;
2616 var date = local.parse(string);
2617 return date && date._;
2622 format.toString = local.toString;
2625 d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
2626 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);
2627 locale_periods.forEach(function(p, i) {
2628 d3_time_periodLookup.set(p.toLowerCase(), i);
2630 var d3_time_formats = {
2632 return locale_shortDays[d.getDay()];
2635 return locale_days[d.getDay()];
2638 return locale_shortMonths[d.getMonth()];
2641 return locale_months[d.getMonth()];
2643 c: d3_time_format(locale_dateTime),
2645 return d3_time_formatPad(d.getDate(), p, 2);
2648 return d3_time_formatPad(d.getDate(), p, 2);
2651 return d3_time_formatPad(d.getHours(), p, 2);
2654 return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
2657 return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
2660 return d3_time_formatPad(d.getMilliseconds(), p, 3);
2663 return d3_time_formatPad(d.getMonth() + 1, p, 2);
2666 return d3_time_formatPad(d.getMinutes(), p, 2);
2669 return locale_periods[+(d.getHours() >= 12)];
2672 return d3_time_formatPad(d.getSeconds(), p, 2);
2675 return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
2681 return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
2683 x: d3_time_format(locale_date),
2684 X: d3_time_format(locale_time),
2686 return d3_time_formatPad(d.getFullYear() % 100, p, 2);
2689 return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
2696 var d3_time_parsers = {
2697 a: d3_time_parseWeekdayAbbrev,
2698 A: d3_time_parseWeekday,
2699 b: d3_time_parseMonthAbbrev,
2700 B: d3_time_parseMonth,
2701 c: d3_time_parseLocaleFull,
2702 d: d3_time_parseDay,
2703 e: d3_time_parseDay,
2704 H: d3_time_parseHour24,
2705 I: d3_time_parseHour24,
2706 j: d3_time_parseDayOfYear,
2707 L: d3_time_parseMilliseconds,
2708 m: d3_time_parseMonthNumber,
2709 M: d3_time_parseMinutes,
2710 p: d3_time_parseAmPm,
2711 S: d3_time_parseSeconds,
2712 U: d3_time_parseWeekNumberSunday,
2713 w: d3_time_parseWeekdayNumber,
2714 W: d3_time_parseWeekNumberMonday,
2715 x: d3_time_parseLocaleDate,
2716 X: d3_time_parseLocaleTime,
2717 y: d3_time_parseYear,
2718 Y: d3_time_parseFullYear,
2719 Z: d3_time_parseZone,
2720 "%": d3_time_parseLiteralPercent
2722 function d3_time_parseWeekdayAbbrev(date, string, i) {
2723 d3_time_dayAbbrevRe.lastIndex = 0;
2724 var n = d3_time_dayAbbrevRe.exec(string.slice(i));
2725 return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2727 function d3_time_parseWeekday(date, string, i) {
2728 d3_time_dayRe.lastIndex = 0;
2729 var n = d3_time_dayRe.exec(string.slice(i));
2730 return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2732 function d3_time_parseMonthAbbrev(date, string, i) {
2733 d3_time_monthAbbrevRe.lastIndex = 0;
2734 var n = d3_time_monthAbbrevRe.exec(string.slice(i));
2735 return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2737 function d3_time_parseMonth(date, string, i) {
2738 d3_time_monthRe.lastIndex = 0;
2739 var n = d3_time_monthRe.exec(string.slice(i));
2740 return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
2742 function d3_time_parseLocaleFull(date, string, i) {
2743 return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
2745 function d3_time_parseLocaleDate(date, string, i) {
2746 return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
2748 function d3_time_parseLocaleTime(date, string, i) {
2749 return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
2751 function d3_time_parseAmPm(date, string, i) {
2752 var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
2753 return n == null ? -1 : (date.p = n, i);
2755 return d3_time_format;
2757 var d3_time_formatPads = {
2761 }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
2762 function d3_time_formatPad(value, fill, width) {
2763 var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
2764 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
2766 function d3_time_formatRe(names) {
2767 return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
2769 function d3_time_formatLookup(names) {
2770 var map = new d3_Map(), i = -1, n = names.length;
2771 while (++i < n) map.set(names[i].toLowerCase(), i);
2774 function d3_time_parseWeekdayNumber(date, string, i) {
2775 d3_time_numberRe.lastIndex = 0;
2776 var n = d3_time_numberRe.exec(string.slice(i, i + 1));
2777 return n ? (date.w = +n[0], i + n[0].length) : -1;
2779 function d3_time_parseWeekNumberSunday(date, string, i) {
2780 d3_time_numberRe.lastIndex = 0;
2781 var n = d3_time_numberRe.exec(string.slice(i));
2782 return n ? (date.U = +n[0], i + n[0].length) : -1;
2784 function d3_time_parseWeekNumberMonday(date, string, i) {
2785 d3_time_numberRe.lastIndex = 0;
2786 var n = d3_time_numberRe.exec(string.slice(i));
2787 return n ? (date.W = +n[0], i + n[0].length) : -1;
2789 function d3_time_parseFullYear(date, string, i) {
2790 d3_time_numberRe.lastIndex = 0;
2791 var n = d3_time_numberRe.exec(string.slice(i, i + 4));
2792 return n ? (date.y = +n[0], i + n[0].length) : -1;
2794 function d3_time_parseYear(date, string, i) {
2795 d3_time_numberRe.lastIndex = 0;
2796 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2797 return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
2799 function d3_time_parseZone(date, string, i) {
2800 return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
2803 function d3_time_expandYear(d) {
2804 return d + (d > 68 ? 1900 : 2e3);
2806 function d3_time_parseMonthNumber(date, string, i) {
2807 d3_time_numberRe.lastIndex = 0;
2808 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2809 return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
2811 function d3_time_parseDay(date, string, i) {
2812 d3_time_numberRe.lastIndex = 0;
2813 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2814 return n ? (date.d = +n[0], i + n[0].length) : -1;
2816 function d3_time_parseDayOfYear(date, string, i) {
2817 d3_time_numberRe.lastIndex = 0;
2818 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
2819 return n ? (date.j = +n[0], i + n[0].length) : -1;
2821 function d3_time_parseHour24(date, string, i) {
2822 d3_time_numberRe.lastIndex = 0;
2823 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2824 return n ? (date.H = +n[0], i + n[0].length) : -1;
2826 function d3_time_parseMinutes(date, string, i) {
2827 d3_time_numberRe.lastIndex = 0;
2828 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2829 return n ? (date.M = +n[0], i + n[0].length) : -1;
2831 function d3_time_parseSeconds(date, string, i) {
2832 d3_time_numberRe.lastIndex = 0;
2833 var n = d3_time_numberRe.exec(string.slice(i, i + 2));
2834 return n ? (date.S = +n[0], i + n[0].length) : -1;
2836 function d3_time_parseMilliseconds(date, string, i) {
2837 d3_time_numberRe.lastIndex = 0;
2838 var n = d3_time_numberRe.exec(string.slice(i, i + 3));
2839 return n ? (date.L = +n[0], i + n[0].length) : -1;
2841 function d3_time_zone(d) {
2842 var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
2843 return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
2845 function d3_time_parseLiteralPercent(date, string, i) {
2846 d3_time_percentRe.lastIndex = 0;
2847 var n = d3_time_percentRe.exec(string.slice(i, i + 1));
2848 return n ? i + n[0].length : -1;
2850 function d3_time_formatMulti(formats) {
2851 var n = formats.length, i = -1;
2852 while (++i < n) formats[i][0] = this(formats[i][0]);
2853 return function(date) {
2854 var i = 0, f = formats[i];
2855 while (!f[1](date)) f = formats[++i];
2859 d3.locale = function(locale) {
2861 numberFormat: d3_locale_numberFormat(locale),
2862 timeFormat: d3_locale_timeFormat(locale)
2865 var d3_locale_enUS = d3.locale({
2869 currency: [ "$", "" ],
2870 dateTime: "%a %b %e %X %Y",
2873 periods: [ "AM", "PM" ],
2874 days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
2875 shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
2876 months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
2877 shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
2879 d3.format = d3_locale_enUS.numberFormat;
2881 function d3_adder() {}
2882 d3_adder.prototype = {
2886 d3_adderSum(y, this.t, d3_adderTemp);
2887 d3_adderSum(d3_adderTemp.s, this.s, this);
2888 if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
2891 this.s = this.t = 0;
2893 valueOf: function() {
2897 var d3_adderTemp = new d3_adder();
2898 function d3_adderSum(a, b, o) {
2899 var x = o.s = a + b, bv = x - a, av = x - bv;
2900 o.t = a - av + (b - bv);
2902 d3.geo.stream = function(object, listener) {
2903 if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
2904 d3_geo_streamObjectType[object.type](object, listener);
2906 d3_geo_streamGeometry(object, listener);
2909 function d3_geo_streamGeometry(geometry, listener) {
2910 if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
2911 d3_geo_streamGeometryType[geometry.type](geometry, listener);
2914 var d3_geo_streamObjectType = {
2915 Feature: function(feature, listener) {
2916 d3_geo_streamGeometry(feature.geometry, listener);
2918 FeatureCollection: function(object, listener) {
2919 var features = object.features, i = -1, n = features.length;
2920 while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
2923 var d3_geo_streamGeometryType = {
2924 Sphere: function(object, listener) {
2927 Point: function(object, listener) {
2928 object = object.coordinates;
2929 listener.point(object[0], object[1], object[2]);
2931 MultiPoint: function(object, listener) {
2932 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2933 while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
2935 LineString: function(object, listener) {
2936 d3_geo_streamLine(object.coordinates, listener, 0);
2938 MultiLineString: function(object, listener) {
2939 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2940 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
2942 Polygon: function(object, listener) {
2943 d3_geo_streamPolygon(object.coordinates, listener);
2945 MultiPolygon: function(object, listener) {
2946 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2947 while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
2949 GeometryCollection: function(object, listener) {
2950 var geometries = object.geometries, i = -1, n = geometries.length;
2951 while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
2954 function d3_geo_streamLine(coordinates, listener, closed) {
2955 var i = -1, n = coordinates.length - closed, coordinate;
2956 listener.lineStart();
2957 while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
2960 function d3_geo_streamPolygon(coordinates, listener) {
2961 var i = -1, n = coordinates.length;
2962 listener.polygonStart();
2963 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
2964 listener.polygonEnd();
2966 d3.geo.area = function(object) {
2968 d3.geo.stream(object, d3_geo_area);
2969 return d3_geo_areaSum;
2971 var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
2973 sphere: function() {
2974 d3_geo_areaSum += 4 * π;
2979 polygonStart: function() {
2980 d3_geo_areaRingSum.reset();
2981 d3_geo_area.lineStart = d3_geo_areaRingStart;
2983 polygonEnd: function() {
2984 var area = 2 * d3_geo_areaRingSum;
2985 d3_geo_areaSum += area < 0 ? 4 * π + area : area;
2986 d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
2989 function d3_geo_areaRingStart() {
2990 var λ00, φ00, λ0, cosφ0, sinφ0;
2991 d3_geo_area.point = function(λ, φ) {
2992 d3_geo_area.point = nextPoint;
2993 λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
2994 sinφ0 = Math.sin(φ);
2996 function nextPoint(λ, φ) {
2998 φ = φ * d3_radians / 2 + π / 4;
2999 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λ);
3000 d3_geo_areaRingSum.add(Math.atan2(v, u));
3001 λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
3003 d3_geo_area.lineEnd = function() {
3004 nextPoint(λ00, φ00);
3007 function d3_geo_cartesian(spherical) {
3008 var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
3009 return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
3011 function d3_geo_cartesianDot(a, b) {
3012 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
3014 function d3_geo_cartesianCross(a, b) {
3015 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] ];
3017 function d3_geo_cartesianAdd(a, b) {
3022 function d3_geo_cartesianScale(vector, k) {
3023 return [ vector[0] * k, vector[1] * k, vector[2] * k ];
3025 function d3_geo_cartesianNormalize(d) {
3026 var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
3031 function d3_geo_spherical(cartesian) {
3032 return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
3034 function d3_geo_sphericalEqual(a, b) {
3035 return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
3037 d3.geo.bounds = function() {
3038 var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
3041 lineStart: lineStart,
3043 polygonStart: function() {
3044 bound.point = ringPoint;
3045 bound.lineStart = ringStart;
3046 bound.lineEnd = ringEnd;
3048 d3_geo_area.polygonStart();
3050 polygonEnd: function() {
3051 d3_geo_area.polygonEnd();
3052 bound.point = point;
3053 bound.lineStart = lineStart;
3054 bound.lineEnd = lineEnd;
3055 if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
3056 range[0] = λ0, range[1] = λ1;
3059 function point(λ, φ) {
3060 ranges.push(range = [ λ0 = λ, λ1 = λ ]);
3064 function linePoint(λ, φ) {
3065 var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
3067 var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
3068 d3_geo_cartesianNormalize(inflection);
3069 inflection = d3_geo_spherical(inflection);
3070 var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
3071 if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
3072 var φi = inflection[1] * d3_degrees;
3073 if (φi > φ1) φ1 = φi;
3074 } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
3075 var φi = -inflection[1] * d3_degrees;
3076 if (φi < φ0) φ0 = φi;
3083 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
3085 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
3093 if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
3095 if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
3104 function lineStart() {
3105 bound.point = linePoint;
3107 function lineEnd() {
3108 range[0] = λ0, range[1] = λ1;
3109 bound.point = point;
3112 function ringPoint(λ, φ) {
3115 dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
3116 } else λ__ = λ, φ__ = φ;
3117 d3_geo_area.point(λ, φ);
3120 function ringStart() {
3121 d3_geo_area.lineStart();
3123 function ringEnd() {
3124 ringPoint(λ__, φ__);
3125 d3_geo_area.lineEnd();
3126 if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
3127 range[0] = λ0, range[1] = λ1;
3130 function angle(λ0, λ1) {
3131 return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
3133 function compareRanges(a, b) {
3136 function withinRange(x, range) {
3137 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
3139 return function(feature) {
3140 φ1 = λ1 = -(λ0 = φ0 = Infinity);
3142 d3.geo.stream(feature, bound);
3143 var n = ranges.length;
3145 ranges.sort(compareRanges);
3146 for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
3148 if (withinRange(b[0], a) || withinRange(b[1], a)) {
3149 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
3150 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
3155 var best = -Infinity, dλ;
3156 for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
3158 if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
3161 ranges = range = null;
3162 return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
3165 d3.geo.centroid = function(object) {
3166 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;
3167 d3.geo.stream(object, d3_geo_centroid);
3168 var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
3170 x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
3171 if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
3172 m = x * x + y * y + z * z;
3173 if (m < ε2) return [ NaN, NaN ];
3175 return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
3177 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;
3178 var d3_geo_centroid = {
3180 point: d3_geo_centroidPoint,
3181 lineStart: d3_geo_centroidLineStart,
3182 lineEnd: d3_geo_centroidLineEnd,
3183 polygonStart: function() {
3184 d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
3186 polygonEnd: function() {
3187 d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
3190 function d3_geo_centroidPoint(λ, φ) {
3192 var cosφ = Math.cos(φ *= d3_radians);
3193 d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
3195 function d3_geo_centroidPointXYZ(x, y, z) {
3196 ++d3_geo_centroidW0;
3197 d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
3198 d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
3199 d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
3201 function d3_geo_centroidLineStart() {
3203 d3_geo_centroid.point = function(λ, φ) {
3205 var cosφ = Math.cos(φ *= d3_radians);
3206 x0 = cosφ * Math.cos(λ);
3207 y0 = cosφ * Math.sin(λ);
3209 d3_geo_centroid.point = nextPoint;
3210 d3_geo_centroidPointXYZ(x0, y0, z0);
3212 function nextPoint(λ, φ) {
3214 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);
3215 d3_geo_centroidW1 += w;
3216 d3_geo_centroidX1 += w * (x0 + (x0 = x));
3217 d3_geo_centroidY1 += w * (y0 + (y0 = y));
3218 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3219 d3_geo_centroidPointXYZ(x0, y0, z0);
3222 function d3_geo_centroidLineEnd() {
3223 d3_geo_centroid.point = d3_geo_centroidPoint;
3225 function d3_geo_centroidRingStart() {
3226 var λ00, φ00, x0, y0, z0;
3227 d3_geo_centroid.point = function(λ, φ) {
3229 d3_geo_centroid.point = nextPoint;
3231 var cosφ = Math.cos(φ *= d3_radians);
3232 x0 = cosφ * Math.cos(λ);
3233 y0 = cosφ * Math.sin(λ);
3235 d3_geo_centroidPointXYZ(x0, y0, z0);
3237 d3_geo_centroid.lineEnd = function() {
3238 nextPoint(λ00, φ00);
3239 d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
3240 d3_geo_centroid.point = d3_geo_centroidPoint;
3242 function nextPoint(λ, φ) {
3244 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);
3245 d3_geo_centroidX2 += v * cx;
3246 d3_geo_centroidY2 += v * cy;
3247 d3_geo_centroidZ2 += v * cz;
3248 d3_geo_centroidW1 += w;
3249 d3_geo_centroidX1 += w * (x0 + (x0 = x));
3250 d3_geo_centroidY1 += w * (y0 + (y0 = y));
3251 d3_geo_centroidZ1 += w * (z0 + (z0 = z));
3252 d3_geo_centroidPointXYZ(x0, y0, z0);
3255 function d3_geo_compose(a, b) {
3256 function compose(x, y) {
3257 return x = a(x, y), b(x[0], x[1]);
3259 if (a.invert && b.invert) compose.invert = function(x, y) {
3260 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
3264 function d3_true() {
3267 function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
3268 var subject = [], clip = [];
3269 segments.forEach(function(segment) {
3270 if ((n = segment.length - 1) <= 0) return;
3271 var n, p0 = segment[0], p1 = segment[n];
3272 if (d3_geo_sphericalEqual(p0, p1)) {
3273 listener.lineStart();
3274 for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
3278 var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
3282 a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
3283 b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
3289 d3_geo_clipPolygonLinkCircular(subject);
3290 d3_geo_clipPolygonLinkCircular(clip);
3291 if (!subject.length) return;
3292 for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
3293 clip[i].e = entry = !entry;
3295 var start = subject[0], points, point;
3297 var current = start, isSubject = true;
3298 while (current.v) if ((current = current.n) === start) return;
3300 listener.lineStart();
3302 current.v = current.o.v = true;
3305 for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
3307 interpolate(current.x, current.n.x, 1, listener);
3309 current = current.n;
3312 points = current.p.z;
3313 for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
3315 interpolate(current.x, current.p.x, -1, listener);
3317 current = current.p;
3319 current = current.o;
3321 isSubject = !isSubject;
3322 } while (!current.v);
3326 function d3_geo_clipPolygonLinkCircular(array) {
3327 if (!(n = array.length)) return;
3328 var n, i = 0, a = array[0], b;
3337 function d3_geo_clipPolygonIntersection(point, points, other, entry) {
3343 this.n = this.p = null;
3345 function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
3346 return function(rotate, listener) {
3347 var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
3350 lineStart: lineStart,
3352 polygonStart: function() {
3353 clip.point = pointRing;
3354 clip.lineStart = ringStart;
3355 clip.lineEnd = ringEnd;
3359 polygonEnd: function() {
3361 clip.lineStart = lineStart;
3362 clip.lineEnd = lineEnd;
3363 segments = d3.merge(segments);
3364 var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
3365 if (segments.length) {
3366 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3367 d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
3368 } else if (clipStartInside) {
3369 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3370 listener.lineStart();
3371 interpolate(null, null, 1, listener);
3374 if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
3375 segments = polygon = null;
3377 sphere: function() {
3378 listener.polygonStart();
3379 listener.lineStart();
3380 interpolate(null, null, 1, listener);
3382 listener.polygonEnd();
3385 function point(λ, φ) {
3386 var point = rotate(λ, φ);
3387 if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
3389 function pointLine(λ, φ) {
3390 var point = rotate(λ, φ);
3391 line.point(point[0], point[1]);
3393 function lineStart() {
3394 clip.point = pointLine;
3397 function lineEnd() {
3402 var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
3403 function pointRing(λ, φ) {
3404 ring.push([ λ, φ ]);
3405 var point = rotate(λ, φ);
3406 ringListener.point(point[0], point[1]);
3408 function ringStart() {
3409 ringListener.lineStart();
3412 function ringEnd() {
3413 pointRing(ring[0][0], ring[0][1]);
3414 ringListener.lineEnd();
3415 var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
3421 segment = ringSegments[0];
3422 var n = segment.length - 1, i = -1, point;
3424 if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
3425 listener.lineStart();
3426 while (++i < n) listener.point((point = segment[i])[0], point[1]);
3431 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
3432 segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
3437 function d3_geo_clipSegmentLength1(segment) {
3438 return segment.length > 1;
3440 function d3_geo_clipBufferListener() {
3441 var lines = [], line;
3443 lineStart: function() {
3444 lines.push(line = []);
3446 point: function(λ, φ) {
3447 line.push([ λ, φ ]);
3450 buffer: function() {
3456 rejoin: function() {
3457 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
3461 function d3_geo_clipSort(a, b) {
3462 return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
3464 var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
3465 function d3_geo_clipAntimeridianLine(listener) {
3466 var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
3468 lineStart: function() {
3469 listener.lineStart();
3472 point: function(λ1, φ1) {
3473 var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
3474 if (abs(dλ - π) < ε) {
3475 listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
3476 listener.point(sλ0, φ0);
3478 listener.lineStart();
3479 listener.point(sλ1, φ0);
3480 listener.point(λ1, φ0);
3482 } else if (sλ0 !== sλ1 && dλ >= π) {
3483 if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
3484 if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
3485 φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
3486 listener.point(sλ0, φ0);
3488 listener.lineStart();
3489 listener.point(sλ1, φ0);
3492 listener.point(λ0 = λ1, φ0 = φ1);
3495 lineEnd: function() {
3504 function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
3505 var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
3506 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;
3508 function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
3511 φ = direction * halfπ;
3512 listener.point(-π, φ);
3513 listener.point(0, φ);
3514 listener.point(π, φ);
3515 listener.point(π, 0);
3516 listener.point(π, -φ);
3517 listener.point(0, -φ);
3518 listener.point(-π, -φ);
3519 listener.point(-π, 0);
3520 listener.point(-π, φ);
3521 } else if (abs(from[0] - to[0]) > ε) {
3522 var s = from[0] < to[0] ? π : -π;
3523 φ = direction * s / 2;
3524 listener.point(-s, φ);
3525 listener.point(0, φ);
3526 listener.point(s, φ);
3528 listener.point(to[0], to[1]);
3531 function d3_geo_pointInPolygon(point, polygon) {
3532 var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
3533 d3_geo_areaRingSum.reset();
3534 for (var i = 0, n = polygon.length; i < n; ++i) {
3535 var ring = polygon[i], m = ring.length;
3537 var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
3541 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φ;
3542 d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
3543 polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
3544 if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
3545 var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
3546 d3_geo_cartesianNormalize(arc);
3547 var intersection = d3_geo_cartesianCross(meridianNormal, arc);
3548 d3_geo_cartesianNormalize(intersection);
3549 var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
3550 if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
3551 winding += antimeridian ^ dλ >= 0 ? 1 : -1;
3555 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
3558 return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < -ε) ^ winding & 1;
3560 function d3_geo_clipCircle(radius) {
3561 var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
3562 return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
3563 function visible(λ, φ) {
3564 return Math.cos(λ) * Math.cos(φ) > cr;
3566 function clipLine(listener) {
3567 var point0, c0, v0, v00, clean;
3569 lineStart: function() {
3573 point: function(λ, φ) {
3574 var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
3575 if (!point0 && (v00 = v0 = v)) listener.lineStart();
3577 point2 = intersect(point0, point1);
3578 if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
3581 v = visible(point1[0], point1[1]);
3587 listener.lineStart();
3588 point2 = intersect(point1, point0);
3589 listener.point(point2[0], point2[1]);
3591 point2 = intersect(point0, point1);
3592 listener.point(point2[0], point2[1]);
3596 } else if (notHemisphere && point0 && smallRadius ^ v) {
3598 if (!(c & c0) && (t = intersect(point1, point0, true))) {
3601 listener.lineStart();
3602 listener.point(t[0][0], t[0][1]);
3603 listener.point(t[1][0], t[1][1]);
3606 listener.point(t[1][0], t[1][1]);
3608 listener.lineStart();
3609 listener.point(t[0][0], t[0][1]);
3613 if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
3614 listener.point(point1[0], point1[1]);
3616 point0 = point1, v0 = v, c0 = c;
3618 lineEnd: function() {
3619 if (v0) listener.lineEnd();
3623 return clean | (v00 && v0) << 1;
3627 function intersect(a, b, two) {
3628 var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
3629 var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
3630 if (!determinant) return !two && a;
3631 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);
3632 d3_geo_cartesianAdd(A, B);
3633 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);
3635 var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
3636 d3_geo_cartesianAdd(q, A);
3637 q = d3_geo_spherical(q);
3639 var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
3640 if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
3641 var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
3642 if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
3643 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)) {
3644 var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
3645 d3_geo_cartesianAdd(q1, A);
3646 return [ q, d3_geo_spherical(q1) ];
3649 function code(λ, φ) {
3650 var r = smallRadius ? radius : π - radius, code = 0;
3651 if (λ < -r) code |= 1; else if (λ > r) code |= 2;
3652 if (φ < -r) code |= 4; else if (φ > r) code |= 8;
3656 function d3_geom_clipLine(x0, y0, x1, y1) {
3657 return function(line) {
3658 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;
3660 if (!dx && r > 0) return;
3665 } else if (dx > 0) {
3670 if (!dx && r < 0) return;
3675 } else if (dx > 0) {
3680 if (!dy && r > 0) return;
3685 } else if (dy > 0) {
3690 if (!dy && r < 0) return;
3695 } else if (dy > 0) {
3699 if (t0 > 0) line.a = {
3703 if (t1 < 1) line.b = {
3710 var d3_geo_clipExtentMAX = 1e9;
3711 d3.geo.clipExtent = function() {
3712 var x0, y0, x1, y1, stream, clip, clipExtent = {
3713 stream: function(output) {
3714 if (stream) stream.valid = false;
3715 stream = clip(output);
3716 stream.valid = true;
3719 extent: function(_) {
3720 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
3721 clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
3722 if (stream) stream.valid = false, stream = null;
3726 return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
3728 function d3_geo_clipExtent(x0, y0, x1, y1) {
3729 return function(listener) {
3730 var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
3733 lineStart: lineStart,
3735 polygonStart: function() {
3736 listener = bufferListener;
3741 polygonEnd: function() {
3742 listener = listener_;
3743 segments = d3.merge(segments);
3744 var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
3745 if (inside || visible) {
3746 listener.polygonStart();
3748 listener.lineStart();
3749 interpolate(null, null, 1, listener);
3753 d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
3755 listener.polygonEnd();
3757 segments = polygon = ring = null;
3760 function insidePolygon(p) {
3761 var wn = 0, n = polygon.length, y = p[1];
3762 for (var i = 0; i < n; ++i) {
3763 for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
3766 if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
3768 if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
3775 function interpolate(from, to, direction, listener) {
3777 if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
3779 listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
3780 } while ((a = (a + direction + 4) % 4) !== a1);
3782 listener.point(to[0], to[1]);
3785 function pointVisible(x, y) {
3786 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
3788 function point(x, y) {
3789 if (pointVisible(x, y)) listener.point(x, y);
3791 var x__, y__, v__, x_, y_, v_, first, clean;
3792 function lineStart() {
3793 clip.point = linePoint;
3794 if (polygon) polygon.push(ring = []);
3799 function lineEnd() {
3801 linePoint(x__, y__);
3802 if (v__ && v_) bufferListener.rejoin();
3803 segments.push(bufferListener.buffer());
3806 if (v_) listener.lineEnd();
3808 function linePoint(x, y) {
3809 x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
3810 y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
3811 var v = pointVisible(x, y);
3812 if (polygon) ring.push([ x, y ]);
3814 x__ = x, y__ = y, v__ = v;
3817 listener.lineStart();
3818 listener.point(x, y);
3821 if (v && v_) listener.point(x, y); else {
3834 listener.lineStart();
3835 listener.point(l.a.x, l.a.y);
3837 listener.point(l.b.x, l.b.y);
3838 if (!v) listener.lineEnd();
3841 listener.lineStart();
3842 listener.point(x, y);
3847 x_ = x, y_ = y, v_ = v;
3851 function corner(p, direction) {
3852 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;
3854 function compare(a, b) {
3855 return comparePoints(a.x, b.x);
3857 function comparePoints(a, b) {
3858 var ca = corner(a, 1), cb = corner(b, 1);
3859 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];
3862 function d3_geo_conic(projectAt) {
3863 var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
3864 p.parallels = function(_) {
3865 if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
3866 return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
3870 function d3_geo_conicEqualArea(φ0, φ1) {
3871 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;
3872 function forward(λ, φ) {
3873 var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
3874 return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
3876 forward.invert = function(x, y) {
3878 return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
3882 (d3.geo.conicEqualArea = function() {
3883 return d3_geo_conic(d3_geo_conicEqualArea);
3884 }).raw = d3_geo_conicEqualArea;
3885 d3.geo.albers = function() {
3886 return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
3888 d3.geo.albersUsa = function() {
3889 var lower48 = d3.geo.albers();
3890 var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
3891 var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
3892 var point, pointStream = {
3893 point: function(x, y) {
3896 }, lower48Point, alaskaPoint, hawaiiPoint;
3897 function albersUsa(coordinates) {
3898 var x = coordinates[0], y = coordinates[1];
3900 (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
3903 albersUsa.invert = function(coordinates) {
3904 var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
3905 return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
3907 albersUsa.stream = function(stream) {
3908 var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
3910 point: function(x, y) {
3911 lower48Stream.point(x, y);
3912 alaskaStream.point(x, y);
3913 hawaiiStream.point(x, y);
3915 sphere: function() {
3916 lower48Stream.sphere();
3917 alaskaStream.sphere();
3918 hawaiiStream.sphere();
3920 lineStart: function() {
3921 lower48Stream.lineStart();
3922 alaskaStream.lineStart();
3923 hawaiiStream.lineStart();
3925 lineEnd: function() {
3926 lower48Stream.lineEnd();
3927 alaskaStream.lineEnd();
3928 hawaiiStream.lineEnd();
3930 polygonStart: function() {
3931 lower48Stream.polygonStart();
3932 alaskaStream.polygonStart();
3933 hawaiiStream.polygonStart();
3935 polygonEnd: function() {
3936 lower48Stream.polygonEnd();
3937 alaskaStream.polygonEnd();
3938 hawaiiStream.polygonEnd();
3942 albersUsa.precision = function(_) {
3943 if (!arguments.length) return lower48.precision();
3944 lower48.precision(_);
3945 alaska.precision(_);
3946 hawaii.precision(_);
3949 albersUsa.scale = function(_) {
3950 if (!arguments.length) return lower48.scale();
3952 alaska.scale(_ * .35);
3954 return albersUsa.translate(lower48.translate());
3956 albersUsa.translate = function(_) {
3957 if (!arguments.length) return lower48.translate();
3958 var k = lower48.scale(), x = +_[0], y = +_[1];
3959 lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
3960 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;
3961 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;
3964 return albersUsa.scale(1070);
3966 var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
3970 polygonStart: function() {
3971 d3_geo_pathAreaPolygon = 0;
3972 d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
3974 polygonEnd: function() {
3975 d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
3976 d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
3979 function d3_geo_pathAreaRingStart() {
3980 var x00, y00, x0, y0;
3981 d3_geo_pathArea.point = function(x, y) {
3982 d3_geo_pathArea.point = nextPoint;
3983 x00 = x0 = x, y00 = y0 = y;
3985 function nextPoint(x, y) {
3986 d3_geo_pathAreaPolygon += y0 * x - x0 * y;
3989 d3_geo_pathArea.lineEnd = function() {
3990 nextPoint(x00, y00);
3993 var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
3994 var d3_geo_pathBounds = {
3995 point: d3_geo_pathBoundsPoint,
3998 polygonStart: d3_noop,
4001 function d3_geo_pathBoundsPoint(x, y) {
4002 if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
4003 if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
4004 if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
4005 if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
4007 function d3_geo_pathBuffer() {
4008 var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
4011 lineStart: function() {
4012 stream.point = pointLineStart;
4015 polygonStart: function() {
4016 stream.lineEnd = lineEndPolygon;
4018 polygonEnd: function() {
4019 stream.lineEnd = lineEnd;
4020 stream.point = point;
4022 pointRadius: function(_) {
4023 pointCircle = d3_geo_pathBufferCircle(_);
4026 result: function() {
4027 if (buffer.length) {
4028 var result = buffer.join("");
4034 function point(x, y) {
4035 buffer.push("M", x, ",", y, pointCircle);
4037 function pointLineStart(x, y) {
4038 buffer.push("M", x, ",", y);
4039 stream.point = pointLine;
4041 function pointLine(x, y) {
4042 buffer.push("L", x, ",", y);
4044 function lineEnd() {
4045 stream.point = point;
4047 function lineEndPolygon() {
4052 function d3_geo_pathBufferCircle(radius) {
4053 return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
4055 var d3_geo_pathCentroid = {
4056 point: d3_geo_pathCentroidPoint,
4057 lineStart: d3_geo_pathCentroidLineStart,
4058 lineEnd: d3_geo_pathCentroidLineEnd,
4059 polygonStart: function() {
4060 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
4062 polygonEnd: function() {
4063 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
4064 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
4065 d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
4068 function d3_geo_pathCentroidPoint(x, y) {
4069 d3_geo_centroidX0 += x;
4070 d3_geo_centroidY0 += y;
4071 ++d3_geo_centroidZ0;
4073 function d3_geo_pathCentroidLineStart() {
4075 d3_geo_pathCentroid.point = function(x, y) {
4076 d3_geo_pathCentroid.point = nextPoint;
4077 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4079 function nextPoint(x, y) {
4080 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
4081 d3_geo_centroidX1 += z * (x0 + x) / 2;
4082 d3_geo_centroidY1 += z * (y0 + y) / 2;
4083 d3_geo_centroidZ1 += z;
4084 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4087 function d3_geo_pathCentroidLineEnd() {
4088 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
4090 function d3_geo_pathCentroidRingStart() {
4091 var x00, y00, x0, y0;
4092 d3_geo_pathCentroid.point = function(x, y) {
4093 d3_geo_pathCentroid.point = nextPoint;
4094 d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
4096 function nextPoint(x, y) {
4097 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
4098 d3_geo_centroidX1 += z * (x0 + x) / 2;
4099 d3_geo_centroidY1 += z * (y0 + y) / 2;
4100 d3_geo_centroidZ1 += z;
4101 z = y0 * x - x0 * y;
4102 d3_geo_centroidX2 += z * (x0 + x);
4103 d3_geo_centroidY2 += z * (y0 + y);
4104 d3_geo_centroidZ2 += z * 3;
4105 d3_geo_pathCentroidPoint(x0 = x, y0 = y);
4107 d3_geo_pathCentroid.lineEnd = function() {
4108 nextPoint(x00, y00);
4111 function d3_geo_pathContext(context) {
4112 var pointRadius = 4.5;
4115 lineStart: function() {
4116 stream.point = pointLineStart;
4119 polygonStart: function() {
4120 stream.lineEnd = lineEndPolygon;
4122 polygonEnd: function() {
4123 stream.lineEnd = lineEnd;
4124 stream.point = point;
4126 pointRadius: function(_) {
4132 function point(x, y) {
4133 context.moveTo(x + pointRadius, y);
4134 context.arc(x, y, pointRadius, 0, τ);
4136 function pointLineStart(x, y) {
4137 context.moveTo(x, y);
4138 stream.point = pointLine;
4140 function pointLine(x, y) {
4141 context.lineTo(x, y);
4143 function lineEnd() {
4144 stream.point = point;
4146 function lineEndPolygon() {
4147 context.closePath();
4151 function d3_geo_resample(project) {
4152 var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
4153 function resample(stream) {
4154 return (maxDepth ? resampleRecursive : resampleNone)(stream);
4156 function resampleNone(stream) {
4157 return d3_geo_transformPoint(stream, function(x, y) {
4159 stream.point(x[0], x[1]);
4162 function resampleRecursive(stream) {
4163 var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
4166 lineStart: lineStart,
4168 polygonStart: function() {
4169 stream.polygonStart();
4170 resample.lineStart = ringStart;
4172 polygonEnd: function() {
4173 stream.polygonEnd();
4174 resample.lineStart = lineStart;
4177 function point(x, y) {
4179 stream.point(x[0], x[1]);
4181 function lineStart() {
4183 resample.point = linePoint;
4186 function linePoint(λ, φ) {
4187 var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
4188 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);
4189 stream.point(x0, y0);
4191 function lineEnd() {
4192 resample.point = point;
4195 function ringStart() {
4197 resample.point = ringPoint;
4198 resample.lineEnd = ringEnd;
4200 function ringPoint(λ, φ) {
4201 linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
4202 resample.point = linePoint;
4204 function ringEnd() {
4205 resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
4206 resample.lineEnd = lineEnd;
4211 function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
4212 var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
4213 if (d2 > 4 * δ2 && depth--) {
4214 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;
4215 if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
4216 resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
4217 stream.point(x2, y2);
4218 resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
4222 resample.precision = function(_) {
4223 if (!arguments.length) return Math.sqrt(δ2);
4224 maxDepth = (δ2 = _ * _) > 0 && 16;
4229 d3.geo.path = function() {
4230 var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
4231 function path(object) {
4233 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
4234 if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
4235 d3.geo.stream(object, cacheStream);
4237 return contextStream.result();
4239 path.area = function(object) {
4240 d3_geo_pathAreaSum = 0;
4241 d3.geo.stream(object, projectStream(d3_geo_pathArea));
4242 return d3_geo_pathAreaSum;
4244 path.centroid = function(object) {
4245 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;
4246 d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
4247 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 ];
4249 path.bounds = function(object) {
4250 d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
4251 d3.geo.stream(object, projectStream(d3_geo_pathBounds));
4252 return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
4254 path.projection = function(_) {
4255 if (!arguments.length) return projection;
4256 projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
4259 path.context = function(_) {
4260 if (!arguments.length) return context;
4261 contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
4262 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
4265 path.pointRadius = function(_) {
4266 if (!arguments.length) return pointRadius;
4267 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
4274 return path.projection(d3.geo.albersUsa()).context(null);
4276 function d3_geo_pathProjectStream(project) {
4277 var resample = d3_geo_resample(function(x, y) {
4278 return project([ x * d3_degrees, y * d3_degrees ]);
4280 return function(stream) {
4281 return d3_geo_projectionRadians(resample(stream));
4284 d3.geo.transform = function(methods) {
4286 stream: function(stream) {
4287 var transform = new d3_geo_transform(stream);
4288 for (var k in methods) transform[k] = methods[k];
4293 function d3_geo_transform(stream) {
4294 this.stream = stream;
4296 d3_geo_transform.prototype = {
4297 point: function(x, y) {
4298 this.stream.point(x, y);
4300 sphere: function() {
4301 this.stream.sphere();
4303 lineStart: function() {
4304 this.stream.lineStart();
4306 lineEnd: function() {
4307 this.stream.lineEnd();
4309 polygonStart: function() {
4310 this.stream.polygonStart();
4312 polygonEnd: function() {
4313 this.stream.polygonEnd();
4316 function d3_geo_transformPoint(stream, point) {
4319 sphere: function() {
4322 lineStart: function() {
4325 lineEnd: function() {
4328 polygonStart: function() {
4329 stream.polygonStart();
4331 polygonEnd: function() {
4332 stream.polygonEnd();
4336 d3.geo.projection = d3_geo_projection;
4337 d3.geo.projectionMutator = d3_geo_projectionMutator;
4338 function d3_geo_projection(project) {
4339 return d3_geo_projectionMutator(function() {
4343 function d3_geo_projectionMutator(projectAt) {
4344 var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
4346 return [ x[0] * k + δx, δy - x[1] * k ];
4347 }), 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;
4348 function projection(point) {
4349 point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
4350 return [ point[0] * k + δx, δy - point[1] * k ];
4352 function invert(point) {
4353 point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
4354 return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
4356 projection.stream = function(output) {
4357 if (stream) stream.valid = false;
4358 stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
4359 stream.valid = true;
4362 projection.clipAngle = function(_) {
4363 if (!arguments.length) return clipAngle;
4364 preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
4365 return invalidate();
4367 projection.clipExtent = function(_) {
4368 if (!arguments.length) return clipExtent;
4370 postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
4371 return invalidate();
4373 projection.scale = function(_) {
4374 if (!arguments.length) return k;
4378 projection.translate = function(_) {
4379 if (!arguments.length) return [ x, y ];
4384 projection.center = function(_) {
4385 if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
4386 λ = _[0] % 360 * d3_radians;
4387 φ = _[1] % 360 * d3_radians;
4390 projection.rotate = function(_) {
4391 if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
4392 δλ = _[0] % 360 * d3_radians;
4393 δφ = _[1] % 360 * d3_radians;
4394 δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
4397 d3.rebind(projection, projectResample, "precision");
4399 projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
4400 var center = project(λ, φ);
4401 δx = x - center[0] * k;
4402 δy = y + center[1] * k;
4403 return invalidate();
4405 function invalidate() {
4406 if (stream) stream.valid = false, stream = null;
4410 project = projectAt.apply(this, arguments);
4411 projection.invert = project.invert && invert;
4415 function d3_geo_projectionRadians(stream) {
4416 return d3_geo_transformPoint(stream, function(x, y) {
4417 stream.point(x * d3_radians, y * d3_radians);
4420 function d3_geo_equirectangular(λ, φ) {
4423 (d3.geo.equirectangular = function() {
4424 return d3_geo_projection(d3_geo_equirectangular);
4425 }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
4426 d3.geo.rotation = function(rotate) {
4427 rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
4428 function forward(coordinates) {
4429 coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4430 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
4432 forward.invert = function(coordinates) {
4433 coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
4434 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
4438 function d3_geo_identityRotation(λ, φ) {
4439 return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
4441 d3_geo_identityRotation.invert = d3_geo_equirectangular;
4442 function d3_geo_rotation(δλ, δφ, δγ) {
4443 return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
4445 function d3_geo_forwardRotationλ(δλ) {
4446 return function(λ, φ) {
4447 return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
4450 function d3_geo_rotationλ(δλ) {
4451 var rotation = d3_geo_forwardRotationλ(δλ);
4452 rotation.invert = d3_geo_forwardRotationλ(-δλ);
4455 function d3_geo_rotationφγ(δφ, δγ) {
4456 var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
4457 function rotation(λ, φ) {
4458 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
4459 return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
4461 rotation.invert = function(λ, φ) {
4462 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
4463 return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
4467 d3.geo.circle = function() {
4468 var origin = [ 0, 0 ], angle, precision = 6, interpolate;
4470 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 = [];
4471 interpolate(null, null, 1, {
4472 point: function(x, y) {
4473 ring.push(x = rotate(x, y));
4474 x[0] *= d3_degrees, x[1] *= d3_degrees;
4479 coordinates: [ ring ]
4482 circle.origin = function(x) {
4483 if (!arguments.length) return origin;
4487 circle.angle = function(x) {
4488 if (!arguments.length) return angle;
4489 interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
4492 circle.precision = function(_) {
4493 if (!arguments.length) return precision;
4494 interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
4497 return circle.angle(90);
4499 function d3_geo_circleInterpolate(radius, precision) {
4500 var cr = Math.cos(radius), sr = Math.sin(radius);
4501 return function(from, to, direction, listener) {
4502 var step = direction * precision;
4504 from = d3_geo_circleAngle(cr, from);
4505 to = d3_geo_circleAngle(cr, to);
4506 if (direction > 0 ? from < to : from > to) from += direction * τ;
4508 from = radius + direction * τ;
4509 to = radius - .5 * step;
4511 for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
4512 listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
4516 function d3_geo_circleAngle(cr, point) {
4517 var a = d3_geo_cartesian(point);
4519 d3_geo_cartesianNormalize(a);
4520 var angle = d3_acos(-a[1]);
4521 return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
4523 d3.geo.distance = function(a, b) {
4524 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;
4525 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Δλ);
4527 d3.geo.graticule = function() {
4528 var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
4529 function graticule() {
4531 type: "MultiLineString",
4532 coordinates: lines()
4536 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) {
4537 return abs(x % DX) > ε;
4538 }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
4539 return abs(y % DY) > ε;
4542 graticule.lines = function() {
4543 return lines().map(function(coordinates) {
4546 coordinates: coordinates
4550 graticule.outline = function() {
4553 coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
4556 graticule.extent = function(_) {
4557 if (!arguments.length) return graticule.minorExtent();
4558 return graticule.majorExtent(_).minorExtent(_);
4560 graticule.majorExtent = function(_) {
4561 if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
4562 X0 = +_[0][0], X1 = +_[1][0];
4563 Y0 = +_[0][1], Y1 = +_[1][1];
4564 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
4565 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
4566 return graticule.precision(precision);
4568 graticule.minorExtent = function(_) {
4569 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
4570 x0 = +_[0][0], x1 = +_[1][0];
4571 y0 = +_[0][1], y1 = +_[1][1];
4572 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
4573 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
4574 return graticule.precision(precision);
4576 graticule.step = function(_) {
4577 if (!arguments.length) return graticule.minorStep();
4578 return graticule.majorStep(_).minorStep(_);
4580 graticule.majorStep = function(_) {
4581 if (!arguments.length) return [ DX, DY ];
4582 DX = +_[0], DY = +_[1];
4585 graticule.minorStep = function(_) {
4586 if (!arguments.length) return [ dx, dy ];
4587 dx = +_[0], dy = +_[1];
4590 graticule.precision = function(_) {
4591 if (!arguments.length) return precision;
4593 x = d3_geo_graticuleX(y0, y1, 90);
4594 y = d3_geo_graticuleY(x0, x1, precision);
4595 X = d3_geo_graticuleX(Y0, Y1, 90);
4596 Y = d3_geo_graticuleY(X0, X1, precision);
4599 return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
4601 function d3_geo_graticuleX(y0, y1, dy) {
4602 var y = d3.range(y0, y1 - ε, dy).concat(y1);
4603 return function(x) {
4604 return y.map(function(y) {
4609 function d3_geo_graticuleY(x0, x1, dx) {
4610 var x = d3.range(x0, x1 - ε, dx).concat(x1);
4611 return function(y) {
4612 return x.map(function(x) {
4617 function d3_source(d) {
4620 function d3_target(d) {
4623 d3.geo.greatArc = function() {
4624 var source = d3_source, source_, target = d3_target, target_;
4625 function greatArc() {
4628 coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
4631 greatArc.distance = function() {
4632 return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
4634 greatArc.source = function(_) {
4635 if (!arguments.length) return source;
4636 source = _, source_ = typeof _ === "function" ? null : _;
4639 greatArc.target = function(_) {
4640 if (!arguments.length) return target;
4641 target = _, target_ = typeof _ === "function" ? null : _;
4644 greatArc.precision = function() {
4645 return arguments.length ? greatArc : 0;
4649 d3.geo.interpolate = function(source, target) {
4650 return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
4652 function d3_geo_interpolate(x0, y0, x1, y1) {
4653 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);
4654 var interpolate = d ? function(t) {
4655 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;
4656 return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
4658 return [ x0 * d3_degrees, y0 * d3_degrees ];
4660 interpolate.distance = d;
4663 d3.geo.length = function(object) {
4664 d3_geo_lengthSum = 0;
4665 d3.geo.stream(object, d3_geo_length);
4666 return d3_geo_lengthSum;
4668 var d3_geo_lengthSum;
4669 var d3_geo_length = {
4672 lineStart: d3_geo_lengthLineStart,
4674 polygonStart: d3_noop,
4677 function d3_geo_lengthLineStart() {
4678 var λ0, sinφ0, cosφ0;
4679 d3_geo_length.point = function(λ, φ) {
4680 λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
4681 d3_geo_length.point = nextPoint;
4683 d3_geo_length.lineEnd = function() {
4684 d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
4686 function nextPoint(λ, φ) {
4687 var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
4688 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Δλ);
4689 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
4692 function d3_geo_azimuthal(scale, angle) {
4693 function azimuthal(λ, φ) {
4694 var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
4695 return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
4697 azimuthal.invert = function(x, y) {
4698 var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
4699 return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
4703 var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
4704 return Math.sqrt(2 / (1 + cosλcosφ));
4706 return 2 * Math.asin(ρ / 2);
4708 (d3.geo.azimuthalEqualArea = function() {
4709 return d3_geo_projection(d3_geo_azimuthalEqualArea);
4710 }).raw = d3_geo_azimuthalEqualArea;
4711 var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
4712 var c = Math.acos(cosλcosφ);
4713 return c && c / Math.sin(c);
4715 (d3.geo.azimuthalEquidistant = function() {
4716 return d3_geo_projection(d3_geo_azimuthalEquidistant);
4717 }).raw = d3_geo_azimuthalEquidistant;
4718 function d3_geo_conicConformal(φ0, φ1) {
4719 var cosφ0 = Math.cos(φ0), t = function(φ) {
4720 return Math.tan(π / 4 + φ / 2);
4721 }, 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;
4722 if (!n) return d3_geo_mercator;
4723 function forward(λ, φ) {
4725 if (φ < -halfπ + ε) φ = -halfπ + ε;
4727 if (φ > halfπ - ε) φ = halfπ - ε;
4729 var ρ = F / Math.pow(t(φ), n);
4730 return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
4732 forward.invert = function(x, y) {
4733 var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
4734 return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
4738 (d3.geo.conicConformal = function() {
4739 return d3_geo_conic(d3_geo_conicConformal);
4740 }).raw = d3_geo_conicConformal;
4741 function d3_geo_conicEquidistant(φ0, φ1) {
4742 var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
4743 if (abs(n) < ε) return d3_geo_equirectangular;
4744 function forward(λ, φ) {
4746 return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
4748 forward.invert = function(x, y) {
4750 return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
4754 (d3.geo.conicEquidistant = function() {
4755 return d3_geo_conic(d3_geo_conicEquidistant);
4756 }).raw = d3_geo_conicEquidistant;
4757 var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
4758 return 1 / cosλcosφ;
4760 (d3.geo.gnomonic = function() {
4761 return d3_geo_projection(d3_geo_gnomonic);
4762 }).raw = d3_geo_gnomonic;
4763 function d3_geo_mercator(λ, φ) {
4764 return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
4766 d3_geo_mercator.invert = function(x, y) {
4767 return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
4769 function d3_geo_mercatorProjection(project) {
4770 var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
4771 m.scale = function() {
4772 var v = scale.apply(m, arguments);
4773 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4775 m.translate = function() {
4776 var v = translate.apply(m, arguments);
4777 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
4779 m.clipExtent = function(_) {
4780 var v = clipExtent.apply(m, arguments);
4782 if (clipAuto = _ == null) {
4783 var k = π * scale(), t = translate();
4784 clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
4786 } else if (clipAuto) {
4791 return m.clipExtent(null);
4793 (d3.geo.mercator = function() {
4794 return d3_geo_mercatorProjection(d3_geo_mercator);
4795 }).raw = d3_geo_mercator;
4796 var d3_geo_orthographic = d3_geo_azimuthal(function() {
4799 (d3.geo.orthographic = function() {
4800 return d3_geo_projection(d3_geo_orthographic);
4801 }).raw = d3_geo_orthographic;
4802 var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
4803 return 1 / (1 + cosλcosφ);
4805 return 2 * Math.atan(ρ);
4807 (d3.geo.stereographic = function() {
4808 return d3_geo_projection(d3_geo_stereographic);
4809 }).raw = d3_geo_stereographic;
4810 function d3_geo_transverseMercator(λ, φ) {
4811 return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
4813 d3_geo_transverseMercator.invert = function(x, y) {
4814 return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
4816 (d3.geo.transverseMercator = function() {
4817 var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
4818 projection.center = function(_) {
4819 return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
4821 projection.rotate = function(_) {
4822 return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
4823 [ _[0], _[1], _[2] - 90 ]);
4825 return rotate([ 0, 0, 90 ]);
4826 }).raw = d3_geo_transverseMercator;
4828 function d3_geom_pointX(d) {
4831 function d3_geom_pointY(d) {
4834 d3.geom.hull = function(vertices) {
4835 var x = d3_geom_pointX, y = d3_geom_pointY;
4836 if (arguments.length) return hull(vertices);
4837 function hull(data) {
4838 if (data.length < 3) return [];
4839 var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
4840 for (i = 0; i < n; i++) {
4841 points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
4843 points.sort(d3_geom_hullOrder);
4844 for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
4845 var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
4846 var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
4847 for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
4848 for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
4851 hull.x = function(_) {
4852 return arguments.length ? (x = _, hull) : x;
4854 hull.y = function(_) {
4855 return arguments.length ? (y = _, hull) : y;
4859 function d3_geom_hullUpper(points) {
4860 var n = points.length, hull = [ 0, 1 ], hs = 2;
4861 for (var i = 2; i < n; i++) {
4862 while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
4865 return hull.slice(0, hs);
4867 function d3_geom_hullOrder(a, b) {
4868 return a[0] - b[0] || a[1] - b[1];
4870 d3.geom.polygon = function(coordinates) {
4871 d3_subclass(coordinates, d3_geom_polygonPrototype);
4874 var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
4875 d3_geom_polygonPrototype.area = function() {
4876 var i = -1, n = this.length, a, b = this[n - 1], area = 0;
4880 area += a[1] * b[0] - a[0] * b[1];
4884 d3_geom_polygonPrototype.centroid = function(k) {
4885 var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
4886 if (!arguments.length) k = -1 / (6 * this.area());
4890 c = a[0] * b[1] - b[0] * a[1];
4891 x += (a[0] + b[0]) * c;
4892 y += (a[1] + b[1]) * c;
4894 return [ x * k, y * k ];
4896 d3_geom_polygonPrototype.clip = function(subject) {
4897 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;
4899 input = subject.slice();
4902 c = input[(m = input.length - closed) - 1];
4906 if (d3_geom_polygonInside(d, a, b)) {
4907 if (!d3_geom_polygonInside(c, a, b)) {
4908 subject.push(d3_geom_polygonIntersect(c, d, a, b));
4911 } else if (d3_geom_polygonInside(c, a, b)) {
4912 subject.push(d3_geom_polygonIntersect(c, d, a, b));
4916 if (closed) subject.push(subject[0]);
4921 function d3_geom_polygonInside(p, a, b) {
4922 return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
4924 function d3_geom_polygonIntersect(c, d, a, b) {
4925 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);
4926 return [ x1 + ua * x21, y1 + ua * y21 ];
4928 function d3_geom_polygonClosed(coordinates) {
4929 var a = coordinates[0], b = coordinates[coordinates.length - 1];
4930 return !(a[0] - b[0] || a[1] - b[1]);
4932 var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
4933 function d3_geom_voronoiBeach() {
4934 d3_geom_voronoiRedBlackNode(this);
4935 this.edge = this.site = this.circle = null;
4937 function d3_geom_voronoiCreateBeach(site) {
4938 var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
4942 function d3_geom_voronoiDetachBeach(beach) {
4943 d3_geom_voronoiDetachCircle(beach);
4944 d3_geom_voronoiBeaches.remove(beach);
4945 d3_geom_voronoiBeachPool.push(beach);
4946 d3_geom_voronoiRedBlackNode(beach);
4948 function d3_geom_voronoiRemoveBeach(beach) {
4949 var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
4952 }, previous = beach.P, next = beach.N, disappearing = [ beach ];
4953 d3_geom_voronoiDetachBeach(beach);
4954 var lArc = previous;
4955 while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
4957 disappearing.unshift(lArc);
4958 d3_geom_voronoiDetachBeach(lArc);
4961 disappearing.unshift(lArc);
4962 d3_geom_voronoiDetachCircle(lArc);
4964 while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
4966 disappearing.push(rArc);
4967 d3_geom_voronoiDetachBeach(rArc);
4970 disappearing.push(rArc);
4971 d3_geom_voronoiDetachCircle(rArc);
4972 var nArcs = disappearing.length, iArc;
4973 for (iArc = 1; iArc < nArcs; ++iArc) {
4974 rArc = disappearing[iArc];
4975 lArc = disappearing[iArc - 1];
4976 d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
4978 lArc = disappearing[0];
4979 rArc = disappearing[nArcs - 1];
4980 rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
4981 d3_geom_voronoiAttachCircle(lArc);
4982 d3_geom_voronoiAttachCircle(rArc);
4984 function d3_geom_voronoiAddBeach(site) {
4985 var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
4987 dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
4988 if (dxl > ε) node = node.L; else {
4989 dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
5000 } else if (dxr > -ε) {
5010 var newArc = d3_geom_voronoiCreateBeach(site);
5011 d3_geom_voronoiBeaches.insert(lArc, newArc);
5012 if (!lArc && !rArc) return;
5013 if (lArc === rArc) {
5014 d3_geom_voronoiDetachCircle(lArc);
5015 rArc = d3_geom_voronoiCreateBeach(lArc.site);
5016 d3_geom_voronoiBeaches.insert(newArc, rArc);
5017 newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
5018 d3_geom_voronoiAttachCircle(lArc);
5019 d3_geom_voronoiAttachCircle(rArc);
5023 newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
5026 d3_geom_voronoiDetachCircle(lArc);
5027 d3_geom_voronoiDetachCircle(rArc);
5028 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 = {
5029 x: (cy * hb - by * hc) / d + ax,
5030 y: (bx * hc - cx * hb) / d + ay
5032 d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
5033 newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
5034 rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
5035 d3_geom_voronoiAttachCircle(lArc);
5036 d3_geom_voronoiAttachCircle(rArc);
5038 function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
5039 var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
5040 if (!pby2) return rfocx;
5042 if (!lArc) return -Infinity;
5044 var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
5045 if (!plby2) return lfocx;
5046 var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
5047 if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
5048 return (rfocx + lfocx) / 2;
5050 function d3_geom_voronoiRightBreakPoint(arc, directrix) {
5052 if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
5053 var site = arc.site;
5054 return site.y === directrix ? site.x : Infinity;
5056 function d3_geom_voronoiCell(site) {
5060 d3_geom_voronoiCell.prototype.prepare = function() {
5061 var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
5062 while (iHalfEdge--) {
5063 edge = halfEdges[iHalfEdge].edge;
5064 if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
5066 halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
5067 return halfEdges.length;
5069 function d3_geom_voronoiCloseCells(extent) {
5070 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;
5072 cell = cells[iCell];
5073 if (!cell || !cell.prepare()) continue;
5074 halfEdges = cell.edges;
5075 nHalfEdges = halfEdges.length;
5077 while (iHalfEdge < nHalfEdges) {
5078 end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
5079 start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
5080 if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
5081 halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
5083 y: abs(x2 - x0) < ε ? y2 : y1
5084 } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
5085 x: abs(y2 - y1) < ε ? x2 : x1,
5087 } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
5089 y: abs(x2 - x1) < ε ? y2 : y0
5090 } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
5091 x: abs(y2 - y0) < ε ? x2 : x0,
5093 } : null), cell.site, null));
5099 function d3_geom_voronoiHalfEdgeOrder(a, b) {
5100 return b.angle - a.angle;
5102 function d3_geom_voronoiCircle() {
5103 d3_geom_voronoiRedBlackNode(this);
5104 this.x = this.y = this.arc = this.site = this.cy = null;
5106 function d3_geom_voronoiAttachCircle(arc) {
5107 var lArc = arc.P, rArc = arc.N;
5108 if (!lArc || !rArc) return;
5109 var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
5110 if (lSite === rSite) return;
5111 var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
5112 var d = 2 * (ax * cy - ay * cx);
5113 if (d >= -ε2) return;
5114 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;
5115 var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
5117 circle.site = cSite;
5119 circle.y = cy + Math.sqrt(x * x + y * y);
5121 arc.circle = circle;
5122 var before = null, node = d3_geom_voronoiCircles._;
5124 if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
5125 if (node.L) node = node.L; else {
5130 if (node.R) node = node.R; else {
5136 d3_geom_voronoiCircles.insert(before, circle);
5137 if (!before) d3_geom_voronoiFirstCircle = circle;
5139 function d3_geom_voronoiDetachCircle(arc) {
5140 var circle = arc.circle;
5142 if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
5143 d3_geom_voronoiCircles.remove(circle);
5144 d3_geom_voronoiCirclePool.push(circle);
5145 d3_geom_voronoiRedBlackNode(circle);
5149 function d3_geom_voronoiClipEdges(extent) {
5150 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;
5153 if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
5159 function d3_geom_voronoiConnectEdge(edge, extent) {
5161 if (vb) return true;
5162 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;
5164 if (fx < x0 || fx >= x1) return;
5169 }; else if (va.y >= y1) return;
5178 }; else if (va.y < y0) return;
5185 fm = (lx - rx) / (ry - ly);
5187 if (fm < -1 || fm > 1) {
5192 }; else if (va.y >= y1) return;
5201 }; else if (va.y < y0) return;
5212 }; else if (va.x >= x1) return;
5221 }; else if (va.x < x0) return;
5233 function d3_geom_voronoiEdge(lSite, rSite) {
5236 this.a = this.b = null;
5238 function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
5239 var edge = new d3_geom_voronoiEdge(lSite, rSite);
5240 d3_geom_voronoiEdges.push(edge);
5241 if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
5242 if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
5243 d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
5244 d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
5247 function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
5248 var edge = new d3_geom_voronoiEdge(lSite, null);
5251 d3_geom_voronoiEdges.push(edge);
5254 function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
5255 if (!edge.a && !edge.b) {
5259 } else if (edge.l === rSite) {
5265 function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
5266 var va = edge.a, vb = edge.b;
5269 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);
5271 d3_geom_voronoiHalfEdge.prototype = {
5273 return this.edge.l === this.site ? this.edge.a : this.edge.b;
5276 return this.edge.l === this.site ? this.edge.b : this.edge.a;
5279 function d3_geom_voronoiRedBlackTree() {
5282 function d3_geom_voronoiRedBlackNode(node) {
5283 node.U = node.C = node.L = node.R = node.P = node.N = null;
5285 d3_geom_voronoiRedBlackTree.prototype = {
5286 insert: function(after, node) {
5287 var parent, grandpa, uncle;
5291 if (after.N) after.N.P = node;
5295 while (after.L) after = after.L;
5301 } else if (this._) {
5302 after = d3_geom_voronoiRedBlackFirst(this._);
5305 after.P = after.L = node;
5308 node.P = node.N = null;
5312 node.L = node.R = null;
5316 while (parent && parent.C) {
5318 if (parent === grandpa.L) {
5320 if (uncle && uncle.C) {
5321 parent.C = uncle.C = false;
5325 if (after === parent.R) {
5326 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5332 d3_geom_voronoiRedBlackRotateRight(this, grandpa);
5336 if (uncle && uncle.C) {
5337 parent.C = uncle.C = false;
5341 if (after === parent.L) {
5342 d3_geom_voronoiRedBlackRotateRight(this, parent);
5348 d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
5355 remove: function(node) {
5356 if (node.N) node.N.P = node.P;
5357 if (node.P) node.P.N = node.N;
5358 node.N = node.P = null;
5359 var parent = node.U, sibling, left = node.L, right = node.R, next, red;
5360 if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
5362 if (parent.L === node) parent.L = next; else parent.R = next;
5366 if (left && right) {
5371 if (next !== right) {
5387 if (node) node.U = parent;
5389 if (node && node.C) {
5394 if (node === this._) break;
5395 if (node === parent.L) {
5400 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5403 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5404 if (!sibling.R || !sibling.R.C) {
5405 sibling.L.C = false;
5407 d3_geom_voronoiRedBlackRotateRight(this, sibling);
5410 sibling.C = parent.C;
5411 parent.C = sibling.R.C = false;
5412 d3_geom_voronoiRedBlackRotateLeft(this, parent);
5421 d3_geom_voronoiRedBlackRotateRight(this, parent);
5424 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5425 if (!sibling.L || !sibling.L.C) {
5426 sibling.R.C = false;
5428 d3_geom_voronoiRedBlackRotateLeft(this, sibling);
5431 sibling.C = parent.C;
5432 parent.C = sibling.L.C = false;
5433 d3_geom_voronoiRedBlackRotateRight(this, parent);
5442 if (node) node.C = false;
5445 function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
5446 var p = node, q = node.R, parent = p.U;
5448 if (parent.L === p) parent.L = q; else parent.R = q;
5458 function d3_geom_voronoiRedBlackRotateRight(tree, node) {
5459 var p = node, q = node.L, parent = p.U;
5461 if (parent.L === p) parent.L = q; else parent.R = q;
5471 function d3_geom_voronoiRedBlackFirst(node) {
5472 while (node.L) node = node.L;
5475 function d3_geom_voronoi(sites, bbox) {
5476 var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
5477 d3_geom_voronoiEdges = [];
5478 d3_geom_voronoiCells = new Array(sites.length);
5479 d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
5480 d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
5482 circle = d3_geom_voronoiFirstCircle;
5483 if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
5484 if (site.x !== x0 || site.y !== y0) {
5485 d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
5486 d3_geom_voronoiAddBeach(site);
5487 x0 = site.x, y0 = site.y;
5490 } else if (circle) {
5491 d3_geom_voronoiRemoveBeach(circle.arc);
5496 if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
5498 cells: d3_geom_voronoiCells,
5499 edges: d3_geom_voronoiEdges
5501 d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
5504 function d3_geom_voronoiVertexOrder(a, b) {
5505 return b.y - a.y || b.x - a.x;
5507 d3.geom.voronoi = function(points) {
5508 var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
5509 if (points) return voronoi(points);
5510 function voronoi(data) {
5511 var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
5512 d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
5513 var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
5515 return [ s.x, s.y ];
5516 }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
5517 polygon.point = data[i];
5521 function sites(data) {
5522 return data.map(function(d, i) {
5524 x: Math.round(fx(d, i) / ε) * ε,
5525 y: Math.round(fy(d, i) / ε) * ε,
5530 voronoi.links = function(data) {
5531 return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
5532 return edge.l && edge.r;
5533 }).map(function(edge) {
5535 source: data[edge.l.i],
5536 target: data[edge.r.i]
5540 voronoi.triangles = function(data) {
5542 d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
5543 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;
5548 s1 = e1.l === site ? e1.r : e1.l;
5549 if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
5550 triangles.push([ data[i], data[s0.i], data[s1.i] ]);
5556 voronoi.x = function(_) {
5557 return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
5559 voronoi.y = function(_) {
5560 return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
5562 voronoi.clipExtent = function(_) {
5563 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
5564 clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
5567 voronoi.size = function(_) {
5568 if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
5569 return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
5573 var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
5574 function d3_geom_voronoiTriangleArea(a, b, c) {
5575 return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
5577 d3.geom.delaunay = function(vertices) {
5578 return d3.geom.voronoi().triangles(vertices);
5580 d3.geom.quadtree = function(points, x1, y1, x2, y2) {
5581 var x = d3_geom_pointX, y = d3_geom_pointY, compat;
5582 if (compat = arguments.length) {
5583 x = d3_geom_quadtreeCompatX;
5584 y = d3_geom_quadtreeCompatY;
5590 return quadtree(points);
5592 function quadtree(data) {
5593 var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
5595 x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
5597 x2_ = y2_ = -(x1_ = y1_ = Infinity);
5600 if (compat) for (i = 0; i < n; ++i) {
5602 if (d.x < x1_) x1_ = d.x;
5603 if (d.y < y1_) y1_ = d.y;
5604 if (d.x > x2_) x2_ = d.x;
5605 if (d.y > y2_) y2_ = d.y;
5608 } else for (i = 0; i < n; ++i) {
5609 var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
5610 if (x_ < x1_) x1_ = x_;
5611 if (y_ < y1_) y1_ = y_;
5612 if (x_ > x2_) x2_ = x_;
5613 if (y_ > y2_) y2_ = y_;
5618 var dx = x2_ - x1_, dy = y2_ - y1_;
5619 if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
5620 function insert(n, d, x, y, x1, y1, x2, y2) {
5621 if (isNaN(x) || isNaN(y)) return;
5623 var nx = n.x, ny = n.y;
5625 if (abs(nx - x) + abs(ny - y) < .01) {
5626 insertChild(n, d, x, y, x1, y1, x2, y2);
5628 var nPoint = n.point;
5629 n.x = n.y = n.point = null;
5630 insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
5631 insertChild(n, d, x, y, x1, y1, x2, y2);
5634 n.x = x, n.y = y, n.point = d;
5637 insertChild(n, d, x, y, x1, y1, x2, y2);
5640 function insertChild(n, d, x, y, x1, y1, x2, y2) {
5641 var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
5643 n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
5644 if (right) x1 = xm; else x2 = xm;
5645 if (below) y1 = ym; else y2 = ym;
5646 insert(n, d, x, y, x1, y1, x2, y2);
5648 var root = d3_geom_quadtreeNode();
5649 root.add = function(d) {
5650 insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
5652 root.visit = function(f) {
5653 d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
5655 root.find = function(point) {
5656 return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
5661 insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
5664 } else data.forEach(root.add);
5665 xs = ys = data = d = null;
5668 quadtree.x = function(_) {
5669 return arguments.length ? (x = _, quadtree) : x;
5671 quadtree.y = function(_) {
5672 return arguments.length ? (y = _, quadtree) : y;
5674 quadtree.extent = function(_) {
5675 if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
5676 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
5680 quadtree.size = function(_) {
5681 if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
5682 if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
5687 function d3_geom_quadtreeCompatX(d) {
5690 function d3_geom_quadtreeCompatY(d) {
5693 function d3_geom_quadtreeNode() {
5702 function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
5703 if (!f(node, x1, y1, x2, y2)) {
5704 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
5705 if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
5706 if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
5707 if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
5708 if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
5711 function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
5712 var minDistance2 = Infinity, closestPoint;
5713 (function find(node, x1, y1, x2, y2) {
5714 if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
5715 if (point = node.point) {
5716 var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
5717 if (distance2 < minDistance2) {
5718 var distance = Math.sqrt(minDistance2 = distance2);
5719 x0 = x - distance, y0 = y - distance;
5720 x3 = x + distance, y3 = y + distance;
5721 closestPoint = point;
5724 var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
5725 for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
5726 if (node = children[i & 3]) switch (i & 3) {
5728 find(node, x1, y1, xm, ym);
5732 find(node, xm, y1, x2, ym);
5736 find(node, x1, ym, xm, y2);
5740 find(node, xm, ym, x2, y2);
5744 })(root, x0, y0, x3, y3);
5745 return closestPoint;
5747 d3.interpolateRgb = d3_interpolateRgb;
5748 function d3_interpolateRgb(a, b) {
5751 var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
5752 return function(t) {
5753 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));
5756 d3.interpolateObject = d3_interpolateObject;
5757 function d3_interpolateObject(a, b) {
5758 var i = {}, c = {}, k;
5761 i[k] = d3_interpolate(a[k], b[k]);
5771 return function(t) {
5772 for (k in i) c[k] = i[k](t);
5776 d3.interpolateNumber = d3_interpolateNumber;
5777 function d3_interpolateNumber(a, b) {
5779 return function(t) {
5780 return a * (1 - t) + b * t;
5783 d3.interpolateString = d3_interpolateString;
5784 function d3_interpolateString(a, b) {
5785 var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
5786 a = a + "", b = b + "";
5787 while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
5788 if ((bs = bm.index) > bi) {
5789 bs = b.slice(bi, bs);
5790 if (s[i]) s[i] += bs; else s[++i] = bs;
5792 if ((am = am[0]) === (bm = bm[0])) {
5793 if (s[i]) s[i] += bm; else s[++i] = bm;
5798 x: d3_interpolateNumber(am, bm)
5801 bi = d3_interpolate_numberB.lastIndex;
5803 if (bi < b.length) {
5805 if (s[i]) s[i] += bs; else s[++i] = bs;
5807 return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
5811 } : (b = q.length, function(t) {
5812 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
5816 var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
5817 d3.interpolate = d3_interpolate;
5818 function d3_interpolate(a, b) {
5819 var i = d3.interpolators.length, f;
5820 while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
5823 d3.interpolators = [ function(a, b) {
5825 return (t === "string" ? d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\(|hsl\()/i.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);
5827 d3.interpolateArray = d3_interpolateArray;
5828 function d3_interpolateArray(a, b) {
5829 var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
5830 for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
5831 for (;i < na; ++i) c[i] = a[i];
5832 for (;i < nb; ++i) c[i] = b[i];
5833 return function(t) {
5834 for (i = 0; i < n0; ++i) c[i] = x[i](t);
5838 var d3_ease_default = function() {
5841 var d3_ease = d3.map({
5842 linear: d3_ease_default,
5845 return d3_ease_quad;
5848 return d3_ease_cubic;
5856 circle: function() {
5857 return d3_ease_circle;
5859 elastic: d3_ease_elastic,
5861 bounce: function() {
5862 return d3_ease_bounce;
5865 var d3_ease_mode = d3.map({
5867 out: d3_ease_reverse,
5868 "in-out": d3_ease_reflect,
5869 "out-in": function(f) {
5870 return d3_ease_reflect(d3_ease_reverse(f));
5873 d3.ease = function(name) {
5874 var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
5875 t = d3_ease.get(t) || d3_ease_default;
5876 m = d3_ease_mode.get(m) || d3_identity;
5877 return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
5879 function d3_ease_clamp(f) {
5880 return function(t) {
5881 return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
5884 function d3_ease_reverse(f) {
5885 return function(t) {
5886 return 1 - f(1 - t);
5889 function d3_ease_reflect(f) {
5890 return function(t) {
5891 return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
5894 function d3_ease_quad(t) {
5897 function d3_ease_cubic(t) {
5900 function d3_ease_cubicInOut(t) {
5901 if (t <= 0) return 0;
5902 if (t >= 1) return 1;
5903 var t2 = t * t, t3 = t2 * t;
5904 return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
5906 function d3_ease_poly(e) {
5907 return function(t) {
5908 return Math.pow(t, e);
5911 function d3_ease_sin(t) {
5912 return 1 - Math.cos(t * halfπ);
5914 function d3_ease_exp(t) {
5915 return Math.pow(2, 10 * (t - 1));
5917 function d3_ease_circle(t) {
5918 return 1 - Math.sqrt(1 - t * t);
5920 function d3_ease_elastic(a, p) {
5922 if (arguments.length < 2) p = .45;
5923 if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
5924 return function(t) {
5925 return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
5928 function d3_ease_back(s) {
5929 if (!s) s = 1.70158;
5930 return function(t) {
5931 return t * t * ((s + 1) * t - s);
5934 function d3_ease_bounce(t) {
5935 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;
5937 d3.interpolateHcl = d3_interpolateHcl;
5938 function d3_interpolateHcl(a, b) {
5941 var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
5942 if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
5943 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
5944 return function(t) {
5945 return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
5948 d3.interpolateHsl = d3_interpolateHsl;
5949 function d3_interpolateHsl(a, b) {
5952 var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
5953 if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
5954 if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
5955 return function(t) {
5956 return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
5959 d3.interpolateLab = d3_interpolateLab;
5960 function d3_interpolateLab(a, b) {
5963 var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
5964 return function(t) {
5965 return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
5968 d3.interpolateRound = d3_interpolateRound;
5969 function d3_interpolateRound(a, b) {
5971 return function(t) {
5972 return Math.round(a + b * t);
5975 d3.transform = function(string) {
5976 var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
5977 return (d3.transform = function(string) {
5978 if (string != null) {
5979 g.setAttribute("transform", string);
5980 var t = g.transform.baseVal.consolidate();
5982 return new d3_transform(t ? t.matrix : d3_transformIdentity);
5985 function d3_transform(m) {
5986 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;
5987 if (r0[0] * r1[1] < r1[0] * r0[1]) {
5993 this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
5994 this.translate = [ m.e, m.f ];
5995 this.scale = [ kx, ky ];
5996 this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
5998 d3_transform.prototype.toString = function() {
5999 return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
6001 function d3_transformDot(a, b) {
6002 return a[0] * b[0] + a[1] * b[1];
6004 function d3_transformNormalize(a) {
6005 var k = Math.sqrt(d3_transformDot(a, a));
6012 function d3_transformCombine(a, b, k) {
6017 var d3_transformIdentity = {
6025 d3.interpolateTransform = d3_interpolateTransform;
6026 function d3_interpolateTransformPop(s) {
6027 return s.length ? s.pop() + "," : "";
6029 function d3_interpolateTranslate(ta, tb, s, q) {
6030 if (ta[0] !== tb[0] || ta[1] !== tb[1]) {
6031 var i = s.push("translate(", null, ",", null, ")");
6034 x: d3_interpolateNumber(ta[0], tb[0])
6037 x: d3_interpolateNumber(ta[1], tb[1])
6039 } else if (tb[0] || tb[1]) {
6040 s.push("translate(" + tb + ")");
6043 function d3_interpolateRotate(ra, rb, s, q) {
6045 if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
6047 i: s.push(d3_interpolateTransformPop(s) + "rotate(", null, ")") - 2,
6048 x: d3_interpolateNumber(ra, rb)
6051 s.push(d3_interpolateTransformPop(s) + "rotate(" + rb + ")");
6054 function d3_interpolateSkew(wa, wb, s, q) {
6057 i: s.push(d3_interpolateTransformPop(s) + "skewX(", null, ")") - 2,
6058 x: d3_interpolateNumber(wa, wb)
6061 s.push(d3_interpolateTransformPop(s) + "skewX(" + wb + ")");
6064 function d3_interpolateScale(ka, kb, s, q) {
6065 if (ka[0] !== kb[0] || ka[1] !== kb[1]) {
6066 var i = s.push(d3_interpolateTransformPop(s) + "scale(", null, ",", null, ")");
6069 x: d3_interpolateNumber(ka[0], kb[0])
6072 x: d3_interpolateNumber(ka[1], kb[1])
6074 } else if (kb[0] !== 1 || kb[1] !== 1) {
6075 s.push(d3_interpolateTransformPop(s) + "scale(" + kb + ")");
6078 function d3_interpolateTransform(a, b) {
6080 a = d3.transform(a), b = d3.transform(b);
6081 d3_interpolateTranslate(a.translate, b.translate, s, q);
6082 d3_interpolateRotate(a.rotate, b.rotate, s, q);
6083 d3_interpolateSkew(a.skew, b.skew, s, q);
6084 d3_interpolateScale(a.scale, b.scale, s, q);
6086 return function(t) {
6087 var i = -1, n = q.length, o;
6088 while (++i < n) s[(o = q[i]).i] = o.x(t);
6092 function d3_uninterpolateNumber(a, b) {
6093 b = (b -= a = +a) || 1 / b;
6094 return function(x) {
6098 function d3_uninterpolateClamp(a, b) {
6099 b = (b -= a = +a) || 1 / b;
6100 return function(x) {
6101 return Math.max(0, Math.min(1, (x - a) / b));
6105 d3.layout.bundle = function() {
6106 return function(links) {
6107 var paths = [], i = -1, n = links.length;
6108 while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
6112 function d3_layout_bundlePath(link) {
6113 var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
6114 while (start !== lca) {
6115 start = start.parent;
6118 var k = points.length;
6119 while (end !== lca) {
6120 points.splice(k, 0, end);
6125 function d3_layout_bundleAncestors(node) {
6126 var ancestors = [], parent = node.parent;
6127 while (parent != null) {
6128 ancestors.push(node);
6130 parent = parent.parent;
6132 ancestors.push(node);
6135 function d3_layout_bundleLeastCommonAncestor(a, b) {
6136 if (a === b) return a;
6137 var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
6138 while (aNode === bNode) {
6140 aNode = aNodes.pop();
6141 bNode = bNodes.pop();
6145 d3.layout.chord = function() {
6146 var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
6147 function relayout() {
6148 var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
6158 subgroupIndex.push(d3.range(n));
6162 groupIndex.sort(function(a, b) {
6163 return sortGroups(groupSums[a], groupSums[b]);
6166 if (sortSubgroups) {
6167 subgroupIndex.forEach(function(d, i) {
6168 d.sort(function(a, b) {
6169 return sortSubgroups(matrix[i][a], matrix[i][b]);
6173 k = (τ - padding * n) / k;
6178 var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
6179 subgroups[di + "-" + dj] = {
6191 value: groupSums[di]
6199 var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
6200 if (source.value || target.value) {
6201 chords.push(source.value < target.value ? {
6211 if (sortChords) resort();
6214 chords.sort(function(a, b) {
6215 return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
6218 chord.matrix = function(x) {
6219 if (!arguments.length) return matrix;
6220 n = (matrix = x) && matrix.length;
6221 chords = groups = null;
6224 chord.padding = function(x) {
6225 if (!arguments.length) return padding;
6227 chords = groups = null;
6230 chord.sortGroups = function(x) {
6231 if (!arguments.length) return sortGroups;
6233 chords = groups = null;
6236 chord.sortSubgroups = function(x) {
6237 if (!arguments.length) return sortSubgroups;
6242 chord.sortChords = function(x) {
6243 if (!arguments.length) return sortChords;
6245 if (chords) resort();
6248 chord.chords = function() {
6249 if (!chords) relayout();
6252 chord.groups = function() {
6253 if (!groups) relayout();
6258 d3.layout.force = function() {
6259 var force = {}, event = d3.dispatch("start", "tick", "end"), timer, 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;
6260 function repulse(node) {
6261 return function(quad, x1, _, x2) {
6262 if (quad.point !== node) {
6263 var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
6264 if (dw * dw / theta2 < dn) {
6265 if (dn < chargeDistance2) {
6266 var k = quad.charge / dn;
6272 if (quad.point && dn && dn < chargeDistance2) {
6273 var k = quad.pointCharge / dn;
6278 return !quad.charge;
6281 force.tick = function() {
6282 if ((alpha *= .99) < .005) {
6290 var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
6291 for (i = 0; i < m; ++i) {
6297 if (l = x * x + y * y) {
6298 l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
6301 t.x -= x * (k = s.weight + t.weight ? s.weight / (s.weight + t.weight) : .5);
6303 s.x += x * (k = 1 - k);
6307 if (k = alpha * gravity) {
6311 if (k) while (++i < n) {
6313 o.x += (x - o.x) * k;
6314 o.y += (y - o.y) * k;
6318 d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
6321 if (!(o = nodes[i]).fixed) {
6322 q.visit(repulse(o));
6333 o.x -= (o.px - (o.px = o.x)) * friction;
6334 o.y -= (o.py - (o.py = o.y)) * friction;
6342 force.nodes = function(x) {
6343 if (!arguments.length) return nodes;
6347 force.links = function(x) {
6348 if (!arguments.length) return links;
6352 force.size = function(x) {
6353 if (!arguments.length) return size;
6357 force.linkDistance = function(x) {
6358 if (!arguments.length) return linkDistance;
6359 linkDistance = typeof x === "function" ? x : +x;
6362 force.distance = force.linkDistance;
6363 force.linkStrength = function(x) {
6364 if (!arguments.length) return linkStrength;
6365 linkStrength = typeof x === "function" ? x : +x;
6368 force.friction = function(x) {
6369 if (!arguments.length) return friction;
6373 force.charge = function(x) {
6374 if (!arguments.length) return charge;
6375 charge = typeof x === "function" ? x : +x;
6378 force.chargeDistance = function(x) {
6379 if (!arguments.length) return Math.sqrt(chargeDistance2);
6380 chargeDistance2 = x * x;
6383 force.gravity = function(x) {
6384 if (!arguments.length) return gravity;
6388 force.theta = function(x) {
6389 if (!arguments.length) return Math.sqrt(theta2);
6393 force.alpha = function(x) {
6394 if (!arguments.length) return alpha;
6400 timer.c = null, timer.t = NaN, timer = null;
6411 timer = d3_timer(force.tick);
6415 force.start = function() {
6416 var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
6417 for (i = 0; i < n; ++i) {
6418 (o = nodes[i]).index = i;
6421 for (i = 0; i < m; ++i) {
6423 if (typeof o.source == "number") o.source = nodes[o.source];
6424 if (typeof o.target == "number") o.target = nodes[o.target];
6428 for (i = 0; i < n; ++i) {
6430 if (isNaN(o.x)) o.x = position("x", w);
6431 if (isNaN(o.y)) o.y = position("y", h);
6432 if (isNaN(o.px)) o.px = o.x;
6433 if (isNaN(o.py)) o.py = o.y;
6436 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;
6438 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;
6440 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;
6441 function position(dimension, size) {
6443 neighbors = new Array(n);
6444 for (j = 0; j < n; ++j) {
6447 for (j = 0; j < m; ++j) {
6449 neighbors[o.source.index].push(o.target);
6450 neighbors[o.target.index].push(o.source);
6453 var candidates = neighbors[i], j = -1, l = candidates.length, x;
6454 while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
6455 return Math.random() * size;
6457 return force.resume();
6459 force.resume = function() {
6460 return force.alpha(.1);
6462 force.stop = function() {
6463 return force.alpha(0);
6465 force.drag = function() {
6466 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);
6467 if (!arguments.length) return drag;
6468 this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
6470 function dragmove(d) {
6471 d.px = d3.event.x, d.py = d3.event.y;
6474 return d3.rebind(force, event, "on");
6476 function d3_layout_forceDragstart(d) {
6479 function d3_layout_forceDragend(d) {
6482 function d3_layout_forceMouseover(d) {
6484 d.px = d.x, d.py = d.y;
6486 function d3_layout_forceMouseout(d) {
6489 function d3_layout_forceAccumulate(quad, alpha, charges) {
6493 var nodes = quad.nodes, n = nodes.length, i = -1, c;
6496 if (c == null) continue;
6497 d3_layout_forceAccumulate(c, alpha, charges);
6498 quad.charge += c.charge;
6499 cx += c.charge * c.cx;
6500 cy += c.charge * c.cy;
6505 quad.point.x += Math.random() - .5;
6506 quad.point.y += Math.random() - .5;
6508 var k = alpha * charges[quad.point.index];
6509 quad.charge += quad.pointCharge = k;
6510 cx += k * quad.point.x;
6511 cy += k * quad.point.y;
6513 quad.cx = cx / quad.charge;
6514 quad.cy = cy / quad.charge;
6516 var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
6517 d3.layout.hierarchy = function() {
6518 var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
6519 function hierarchy(root) {
6520 var stack = [ root ], nodes = [], node;
6522 while ((node = stack.pop()) != null) {
6524 if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
6525 var n, childs, child;
6527 stack.push(child = childs[n]);
6528 child.parent = node;
6529 child.depth = node.depth + 1;
6531 if (value) node.value = 0;
6532 node.children = childs;
6534 if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
6535 delete node.children;
6538 d3_layout_hierarchyVisitAfter(root, function(node) {
6540 if (sort && (childs = node.children)) childs.sort(sort);
6541 if (value && (parent = node.parent)) parent.value += node.value;
6545 hierarchy.sort = function(x) {
6546 if (!arguments.length) return sort;
6550 hierarchy.children = function(x) {
6551 if (!arguments.length) return children;
6555 hierarchy.value = function(x) {
6556 if (!arguments.length) return value;
6560 hierarchy.revalue = function(root) {
6562 d3_layout_hierarchyVisitBefore(root, function(node) {
6563 if (node.children) node.value = 0;
6565 d3_layout_hierarchyVisitAfter(root, function(node) {
6567 if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
6568 if (parent = node.parent) parent.value += node.value;
6575 function d3_layout_hierarchyRebind(object, hierarchy) {
6576 d3.rebind(object, hierarchy, "sort", "children", "value");
6577 object.nodes = object;
6578 object.links = d3_layout_hierarchyLinks;
6581 function d3_layout_hierarchyVisitBefore(node, callback) {
6582 var nodes = [ node ];
6583 while ((node = nodes.pop()) != null) {
6585 if ((children = node.children) && (n = children.length)) {
6587 while (--n >= 0) nodes.push(children[n]);
6591 function d3_layout_hierarchyVisitAfter(node, callback) {
6592 var nodes = [ node ], nodes2 = [];
6593 while ((node = nodes.pop()) != null) {
6595 if ((children = node.children) && (n = children.length)) {
6596 var i = -1, n, children;
6597 while (++i < n) nodes.push(children[i]);
6600 while ((node = nodes2.pop()) != null) {
6604 function d3_layout_hierarchyChildren(d) {
6607 function d3_layout_hierarchyValue(d) {
6610 function d3_layout_hierarchySort(a, b) {
6611 return b.value - a.value;
6613 function d3_layout_hierarchyLinks(nodes) {
6614 return d3.merge(nodes.map(function(parent) {
6615 return (parent.children || []).map(function(child) {
6623 d3.layout.partition = function() {
6624 var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
6625 function position(node, x, dx, dy) {
6626 var children = node.children;
6628 node.y = node.depth * dy;
6631 if (children && (n = children.length)) {
6632 var i = -1, n, c, d;
6633 dx = node.value ? dx / node.value : 0;
6635 position(c = children[i], x, d = c.value * dx, dy);
6640 function depth(node) {
6641 var children = node.children, d = 0;
6642 if (children && (n = children.length)) {
6644 while (++i < n) d = Math.max(d, depth(children[i]));
6648 function partition(d, i) {
6649 var nodes = hierarchy.call(this, d, i);
6650 position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
6653 partition.size = function(x) {
6654 if (!arguments.length) return size;
6658 return d3_layout_hierarchyRebind(partition, hierarchy);
6660 d3.layout.pie = function() {
6661 var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
6662 function pie(data) {
6663 var n = data.length, values = data.map(function(d, i) {
6664 return +value.call(pie, d, i);
6665 }), a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), sum = d3.sum(values), k = sum ? (da - n * pa) / sum : 0, index = d3.range(n), arcs = [], v;
6666 if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
6667 return values[j] - values[i];
6668 } : function(i, j) {
6669 return sort(data[i], data[j]);
6671 index.forEach(function(i) {
6674 value: v = values[i],
6676 endAngle: a += v * k + pa,
6682 pie.value = function(_) {
6683 if (!arguments.length) return value;
6687 pie.sort = function(_) {
6688 if (!arguments.length) return sort;
6692 pie.startAngle = function(_) {
6693 if (!arguments.length) return startAngle;
6697 pie.endAngle = function(_) {
6698 if (!arguments.length) return endAngle;
6702 pie.padAngle = function(_) {
6703 if (!arguments.length) return padAngle;
6709 var d3_layout_pieSortByValue = {};
6710 d3.layout.stack = function() {
6711 var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
6712 function stack(data, index) {
6713 if (!(n = data.length)) return data;
6714 var series = data.map(function(d, i) {
6715 return values.call(stack, d, i);
6717 var points = series.map(function(d) {
6718 return d.map(function(v, i) {
6719 return [ x.call(stack, v, i), y.call(stack, v, i) ];
6722 var orders = order.call(stack, points, index);
6723 series = d3.permute(series, orders);
6724 points = d3.permute(points, orders);
6725 var offsets = offset.call(stack, points, index);
6726 var m = series[0].length, n, i, j, o;
6727 for (j = 0; j < m; ++j) {
6728 out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
6729 for (i = 1; i < n; ++i) {
6730 out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
6735 stack.values = function(x) {
6736 if (!arguments.length) return values;
6740 stack.order = function(x) {
6741 if (!arguments.length) return order;
6742 order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
6745 stack.offset = function(x) {
6746 if (!arguments.length) return offset;
6747 offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
6750 stack.x = function(z) {
6751 if (!arguments.length) return x;
6755 stack.y = function(z) {
6756 if (!arguments.length) return y;
6760 stack.out = function(z) {
6761 if (!arguments.length) return out;
6767 function d3_layout_stackX(d) {
6770 function d3_layout_stackY(d) {
6773 function d3_layout_stackOut(d, y0, y) {
6777 var d3_layout_stackOrders = d3.map({
6778 "inside-out": function(data) {
6779 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) {
6780 return max[a] - max[b];
6781 }), top = 0, bottom = 0, tops = [], bottoms = [];
6782 for (i = 0; i < n; ++i) {
6792 return bottoms.reverse().concat(tops);
6794 reverse: function(data) {
6795 return d3.range(data.length).reverse();
6797 "default": d3_layout_stackOrderDefault
6799 var d3_layout_stackOffsets = d3.map({
6800 silhouette: function(data) {
6801 var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
6802 for (j = 0; j < m; ++j) {
6803 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
6804 if (o > max) max = o;
6807 for (j = 0; j < m; ++j) {
6808 y0[j] = (max - sums[j]) / 2;
6812 wiggle: function(data) {
6813 var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
6815 for (j = 1; j < m; ++j) {
6816 for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
6817 for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
6818 for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
6819 s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
6821 s2 += s3 * data[i][j][1];
6823 y0[j] = o -= s1 ? s2 / s1 * dx : 0;
6826 for (j = 0; j < m; ++j) y0[j] -= o0;
6829 expand: function(data) {
6830 var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
6831 for (j = 0; j < m; ++j) {
6832 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
6833 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;
6835 for (j = 0; j < m; ++j) y0[j] = 0;
6838 zero: d3_layout_stackOffsetZero
6840 function d3_layout_stackOrderDefault(data) {
6841 return d3.range(data.length);
6843 function d3_layout_stackOffsetZero(data) {
6844 var j = -1, m = data[0].length, y0 = [];
6845 while (++j < m) y0[j] = 0;
6848 function d3_layout_stackMaxIndex(array) {
6849 var i = 1, j = 0, v = array[0][1], k, n = array.length;
6851 if ((k = array[i][1]) > v) {
6858 function d3_layout_stackReduceSum(d) {
6859 return d.reduce(d3_layout_stackSum, 0);
6861 function d3_layout_stackSum(p, d) {
6864 d3.layout.histogram = function() {
6865 var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
6866 function histogram(data, i) {
6867 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;
6870 bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
6877 if (x >= range[0] && x <= range[1]) {
6878 bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
6886 histogram.value = function(x) {
6887 if (!arguments.length) return valuer;
6891 histogram.range = function(x) {
6892 if (!arguments.length) return ranger;
6893 ranger = d3_functor(x);
6896 histogram.bins = function(x) {
6897 if (!arguments.length) return binner;
6898 binner = typeof x === "number" ? function(range) {
6899 return d3_layout_histogramBinFixed(range, x);
6903 histogram.frequency = function(x) {
6904 if (!arguments.length) return frequency;
6910 function d3_layout_histogramBinSturges(range, values) {
6911 return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
6913 function d3_layout_histogramBinFixed(range, n) {
6914 var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
6915 while (++x <= n) f[x] = m * x + b;
6918 function d3_layout_histogramRange(values) {
6919 return [ d3.min(values), d3.max(values) ];
6921 d3.layout.pack = function() {
6922 var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
6923 function pack(d, i) {
6924 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() {
6927 root.x = root.y = 0;
6928 d3_layout_hierarchyVisitAfter(root, function(d) {
6931 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
6933 var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
6934 d3_layout_hierarchyVisitAfter(root, function(d) {
6937 d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
6938 d3_layout_hierarchyVisitAfter(root, function(d) {
6942 d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
6945 pack.size = function(_) {
6946 if (!arguments.length) return size;
6950 pack.radius = function(_) {
6951 if (!arguments.length) return radius;
6952 radius = _ == null || typeof _ === "function" ? _ : +_;
6955 pack.padding = function(_) {
6956 if (!arguments.length) return padding;
6960 return d3_layout_hierarchyRebind(pack, hierarchy);
6962 function d3_layout_packSort(a, b) {
6963 return a.value - b.value;
6965 function d3_layout_packInsert(a, b) {
6966 var c = a._pack_next;
6972 function d3_layout_packSplice(a, b) {
6976 function d3_layout_packIntersects(a, b) {
6977 var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
6978 return .999 * dr * dr > dx * dx + dy * dy;
6980 function d3_layout_packSiblings(node) {
6981 if (!(nodes = node.children) || !(n = nodes.length)) return;
6982 var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
6983 function bound(node) {
6984 xMin = Math.min(node.x - node.r, xMin);
6985 xMax = Math.max(node.x + node.r, xMax);
6986 yMin = Math.min(node.y - node.r, yMin);
6987 yMax = Math.max(node.y + node.r, yMax);
6989 nodes.forEach(d3_layout_packLink);
7001 d3_layout_packPlace(a, b, c);
7003 d3_layout_packInsert(a, c);
7005 d3_layout_packInsert(c, b);
7007 for (i = 3; i < n; i++) {
7008 d3_layout_packPlace(a, b, c = nodes[i]);
7009 var isect = 0, s1 = 1, s2 = 1;
7010 for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
7011 if (d3_layout_packIntersects(j, c)) {
7017 for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
7018 if (d3_layout_packIntersects(k, c)) {
7024 if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
7027 d3_layout_packInsert(a, c);
7034 var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
7035 for (i = 0; i < n; i++) {
7039 cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
7042 nodes.forEach(d3_layout_packUnlink);
7044 function d3_layout_packLink(node) {
7045 node._pack_next = node._pack_prev = node;
7047 function d3_layout_packUnlink(node) {
7048 delete node._pack_next;
7049 delete node._pack_prev;
7051 function d3_layout_packTransform(node, x, y, k) {
7052 var children = node.children;
7053 node.x = x += k * node.x;
7054 node.y = y += k * node.y;
7057 var i = -1, n = children.length;
7058 while (++i < n) d3_layout_packTransform(children[i], x, y, k);
7061 function d3_layout_packPlace(a, b, c) {
7062 var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
7063 if (db && (dx || dy)) {
7064 var da = b.r + c.r, dc = dx * dx + dy * dy;
7067 var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
7068 c.x = a.x + x * dx + y * dy;
7069 c.y = a.y + x * dy - y * dx;
7075 d3.layout.tree = function() {
7076 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
7077 function tree(d, i) {
7078 var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
7079 d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
7080 d3_layout_hierarchyVisitBefore(root1, secondWalk);
7081 if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
7082 var left = root0, right = root0, bottom = root0;
7083 d3_layout_hierarchyVisitBefore(root0, function(node) {
7084 if (node.x < left.x) left = node;
7085 if (node.x > right.x) right = node;
7086 if (node.depth > bottom.depth) bottom = node;
7088 var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
7089 d3_layout_hierarchyVisitBefore(root0, function(node) {
7090 node.x = (node.x + tx) * kx;
7091 node.y = node.depth * ky;
7096 function wrapTree(root0) {
7100 }, queue = [ root1 ], node1;
7101 while ((node1 = queue.pop()) != null) {
7102 for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
7103 queue.push((children[i] = child = {
7106 children: (child = children[i].children) && child.slice() || [],
7118 return root1.children[0];
7120 function firstWalk(v) {
7121 var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
7122 if (children.length) {
7123 d3_layout_treeShift(v);
7124 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
7126 v.z = w.z + separation(v._, w._);
7127 v.m = v.z - midpoint;
7132 v.z = w.z + separation(v._, w._);
7134 v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
7136 function secondWalk(v) {
7137 v._.x = v.z + v.parent.m;
7140 function apportion(v, w, ancestor) {
7142 var vip = v, vop = v, vim = w, vom = vip.parent.children[0], sip = vip.m, sop = vop.m, sim = vim.m, som = vom.m, shift;
7143 while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
7144 vom = d3_layout_treeLeft(vom);
7145 vop = d3_layout_treeRight(vop);
7147 shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
7149 d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
7158 if (vim && !d3_layout_treeRight(vop)) {
7162 if (vip && !d3_layout_treeLeft(vom)) {
7170 function sizeNode(node) {
7172 node.y = node.depth * size[1];
7174 tree.separation = function(x) {
7175 if (!arguments.length) return separation;
7179 tree.size = function(x) {
7180 if (!arguments.length) return nodeSize ? null : size;
7181 nodeSize = (size = x) == null ? sizeNode : null;
7184 tree.nodeSize = function(x) {
7185 if (!arguments.length) return nodeSize ? size : null;
7186 nodeSize = (size = x) == null ? null : sizeNode;
7189 return d3_layout_hierarchyRebind(tree, hierarchy);
7191 function d3_layout_treeSeparation(a, b) {
7192 return a.parent == b.parent ? 1 : 2;
7194 function d3_layout_treeLeft(v) {
7195 var children = v.children;
7196 return children.length ? children[0] : v.t;
7198 function d3_layout_treeRight(v) {
7199 var children = v.children, n;
7200 return (n = children.length) ? children[n - 1] : v.t;
7202 function d3_layout_treeMove(wm, wp, shift) {
7203 var change = shift / (wp.i - wm.i);
7210 function d3_layout_treeShift(v) {
7211 var shift = 0, change = 0, children = v.children, i = children.length, w;
7216 shift += w.s + (change += w.c);
7219 function d3_layout_treeAncestor(vim, v, ancestor) {
7220 return vim.a.parent === v.parent ? vim.a : ancestor;
7222 d3.layout.cluster = function() {
7223 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
7224 function cluster(d, i) {
7225 var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
7226 d3_layout_hierarchyVisitAfter(root, function(node) {
7227 var children = node.children;
7228 if (children && children.length) {
7229 node.x = d3_layout_clusterX(children);
7230 node.y = d3_layout_clusterY(children);
7232 node.x = previousNode ? x += separation(node, previousNode) : 0;
7234 previousNode = node;
7237 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;
7238 d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
7239 node.x = (node.x - root.x) * size[0];
7240 node.y = (root.y - node.y) * size[1];
7241 } : function(node) {
7242 node.x = (node.x - x0) / (x1 - x0) * size[0];
7243 node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
7247 cluster.separation = function(x) {
7248 if (!arguments.length) return separation;
7252 cluster.size = function(x) {
7253 if (!arguments.length) return nodeSize ? null : size;
7254 nodeSize = (size = x) == null;
7257 cluster.nodeSize = function(x) {
7258 if (!arguments.length) return nodeSize ? size : null;
7259 nodeSize = (size = x) != null;
7262 return d3_layout_hierarchyRebind(cluster, hierarchy);
7264 function d3_layout_clusterY(children) {
7265 return 1 + d3.max(children, function(child) {
7269 function d3_layout_clusterX(children) {
7270 return children.reduce(function(x, child) {
7272 }, 0) / children.length;
7274 function d3_layout_clusterLeft(node) {
7275 var children = node.children;
7276 return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
7278 function d3_layout_clusterRight(node) {
7279 var children = node.children, n;
7280 return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
7282 d3.layout.treemap = function() {
7283 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));
7284 function scale(children, k) {
7285 var i = -1, n = children.length, child, area;
7287 area = (child = children[i]).value * (k < 0 ? 0 : k);
7288 child.area = isNaN(area) || area <= 0 ? 0 : area;
7291 function squarify(node) {
7292 var children = node.children;
7293 if (children && children.length) {
7294 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;
7295 scale(remaining, rect.dx * rect.dy / node.value);
7297 while ((n = remaining.length) > 0) {
7298 row.push(child = remaining[n - 1]);
7299 row.area += child.area;
7300 if (mode !== "squarify" || (score = worst(row, u)) <= best) {
7304 row.area -= row.pop().area;
7305 position(row, u, rect, false);
7306 u = Math.min(rect.dx, rect.dy);
7307 row.length = row.area = 0;
7312 position(row, u, rect, true);
7313 row.length = row.area = 0;
7315 children.forEach(squarify);
7318 function stickify(node) {
7319 var children = node.children;
7320 if (children && children.length) {
7321 var rect = pad(node), remaining = children.slice(), child, row = [];
7322 scale(remaining, rect.dx * rect.dy / node.value);
7324 while (child = remaining.pop()) {
7326 row.area += child.area;
7327 if (child.z != null) {
7328 position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
7329 row.length = row.area = 0;
7332 children.forEach(stickify);
7335 function worst(row, u) {
7336 var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
7338 if (!(r = row[i].area)) continue;
7339 if (r < rmin) rmin = r;
7340 if (r > rmax) rmax = r;
7344 return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
7346 function position(row, u, rect, flush) {
7347 var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
7349 if (flush || v > rect.dy) v = rect.dy;
7355 x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
7358 o.dx += rect.x + rect.dx - x;
7362 if (flush || v > rect.dx) v = rect.dx;
7368 y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
7371 o.dy += rect.y + rect.dy - y;
7376 function treemap(d) {
7377 var nodes = stickies || hierarchy(d), root = nodes[0];
7378 root.x = root.y = 0;
7379 if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0;
7380 if (stickies) hierarchy.revalue(root);
7381 scale([ root ], root.dx * root.dy / root.value);
7382 (stickies ? stickify : squarify)(root);
7383 if (sticky) stickies = nodes;
7386 treemap.size = function(x) {
7387 if (!arguments.length) return size;
7391 treemap.padding = function(x) {
7392 if (!arguments.length) return padding;
7393 function padFunction(node) {
7394 var p = x.call(treemap, node, node.depth);
7395 return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
7397 function padConstant(node) {
7398 return d3_layout_treemapPad(node, x);
7401 pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
7402 padConstant) : padConstant;
7405 treemap.round = function(x) {
7406 if (!arguments.length) return round != Number;
7407 round = x ? Math.round : Number;
7410 treemap.sticky = function(x) {
7411 if (!arguments.length) return sticky;
7416 treemap.ratio = function(x) {
7417 if (!arguments.length) return ratio;
7421 treemap.mode = function(x) {
7422 if (!arguments.length) return mode;
7426 return d3_layout_hierarchyRebind(treemap, hierarchy);
7428 function d3_layout_treemapPadNull(node) {
7436 function d3_layout_treemapPad(node, padding) {
7437 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];
7454 normal: function(µ, σ) {
7455 var n = arguments.length;
7461 x = Math.random() * 2 - 1;
7462 y = Math.random() * 2 - 1;
7464 } while (!r || r > 1);
7465 return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
7468 logNormal: function() {
7469 var random = d3.random.normal.apply(d3, arguments);
7471 return Math.exp(random());
7474 bates: function(m) {
7475 var random = d3.random.irwinHall(m);
7477 return random() / m;
7480 irwinHall: function(m) {
7482 for (var s = 0, j = 0; j < m; j++) s += Math.random();
7488 function d3_scaleExtent(domain) {
7489 var start = domain[0], stop = domain[domain.length - 1];
7490 return start < stop ? [ start, stop ] : [ stop, start ];
7492 function d3_scaleRange(scale) {
7493 return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
7495 function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
7496 var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
7497 return function(x) {
7501 function d3_scale_nice(domain, nice) {
7502 var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
7504 dx = i0, i0 = i1, i1 = dx;
7505 dx = x0, x0 = x1, x1 = dx;
7507 domain[i0] = nice.floor(x0);
7508 domain[i1] = nice.ceil(x1);
7511 function d3_scale_niceStep(step) {
7513 floor: function(x) {
7514 return Math.floor(x / step) * step;
7517 return Math.ceil(x / step) * step;
7519 } : d3_scale_niceIdentity;
7521 var d3_scale_niceIdentity = {
7525 function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
7526 var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
7527 if (domain[k] < domain[0]) {
7528 domain = domain.slice().reverse();
7529 range = range.slice().reverse();
7532 u.push(uninterpolate(domain[j - 1], domain[j]));
7533 i.push(interpolate(range[j - 1], range[j]));
7535 return function(x) {
7536 var j = d3.bisect(domain, x, 1, k) - 1;
7537 return i[j](u[j](x));
7540 d3.scale.linear = function() {
7541 return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
7543 function d3_scale_linear(domain, range, interpolate, clamp) {
7545 function rescale() {
7546 var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
7547 output = linear(domain, range, uninterpolate, interpolate);
7548 input = linear(range, domain, uninterpolate, d3_interpolate);
7554 scale.invert = function(y) {
7557 scale.domain = function(x) {
7558 if (!arguments.length) return domain;
7559 domain = x.map(Number);
7562 scale.range = function(x) {
7563 if (!arguments.length) return range;
7567 scale.rangeRound = function(x) {
7568 return scale.range(x).interpolate(d3_interpolateRound);
7570 scale.clamp = function(x) {
7571 if (!arguments.length) return clamp;
7575 scale.interpolate = function(x) {
7576 if (!arguments.length) return interpolate;
7580 scale.ticks = function(m) {
7581 return d3_scale_linearTicks(domain, m);
7583 scale.tickFormat = function(m, format) {
7584 return d3_scale_linearTickFormat(domain, m, format);
7586 scale.nice = function(m) {
7587 d3_scale_linearNice(domain, m);
7590 scale.copy = function() {
7591 return d3_scale_linear(domain, range, interpolate, clamp);
7595 function d3_scale_linearRebind(scale, linear) {
7596 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
7598 function d3_scale_linearNice(domain, m) {
7599 d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
7600 d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
7603 function d3_scale_linearTickRange(domain, m) {
7604 if (m == null) m = 10;
7605 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;
7606 if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
7607 extent[0] = Math.ceil(extent[0] / step) * step;
7608 extent[1] = Math.floor(extent[1] / step) * step + step * .5;
7612 function d3_scale_linearTicks(domain, m) {
7613 return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
7615 function d3_scale_linearTickFormat(domain, m, format) {
7616 var range = d3_scale_linearTickRange(domain, m);
7618 var match = d3_format_re.exec(format);
7620 if (match[8] === "s") {
7621 var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
7622 if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
7624 format = d3.format(match.join(""));
7625 return function(d) {
7626 return format(prefix.scale(d)) + prefix.symbol;
7629 if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
7630 format = match.join("");
7632 format = ",." + d3_scale_linearPrecision(range[2]) + "f";
7634 return d3.format(format);
7636 var d3_scale_linearFormatSignificant = {
7643 function d3_scale_linearPrecision(value) {
7644 return -Math.floor(Math.log(value) / Math.LN10 + .01);
7646 function d3_scale_linearFormatPrecision(type, range) {
7647 var p = d3_scale_linearPrecision(range[2]);
7648 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;
7650 d3.scale.log = function() {
7651 return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
7653 function d3_scale_log(linear, base, positive, domain) {
7655 return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
7658 return positive ? Math.pow(base, x) : -Math.pow(base, -x);
7661 return linear(log(x));
7663 scale.invert = function(x) {
7664 return pow(linear.invert(x));
7666 scale.domain = function(x) {
7667 if (!arguments.length) return domain;
7668 positive = x[0] >= 0;
7669 linear.domain((domain = x.map(Number)).map(log));
7672 scale.base = function(_) {
7673 if (!arguments.length) return base;
7675 linear.domain(domain.map(log));
7678 scale.nice = function() {
7679 var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
7680 linear.domain(niced);
7681 domain = niced.map(pow);
7684 scale.ticks = function() {
7685 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;
7686 if (isFinite(j - i)) {
7688 for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
7692 for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
7694 for (i = 0; ticks[i] < u; i++) {}
7695 for (j = ticks.length; ticks[j - 1] > v; j--) {}
7696 ticks = ticks.slice(i, j);
7700 scale.tickFormat = function(n, format) {
7701 if (!arguments.length) return d3_scale_logFormat;
7702 if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
7703 var k = Math.max(1, base * n / scale.ticks().length);
7704 return function(d) {
7705 var i = d / pow(Math.round(log(d)));
7706 if (i * base < base - .5) i *= base;
7707 return i <= k ? format(d) : "";
7710 scale.copy = function() {
7711 return d3_scale_log(linear.copy(), base, positive, domain);
7713 return d3_scale_linearRebind(scale, linear);
7715 var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
7716 floor: function(x) {
7717 return -Math.ceil(-x);
7720 return -Math.floor(-x);
7723 d3.scale.pow = function() {
7724 return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
7726 function d3_scale_pow(linear, exponent, domain) {
7727 var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
7729 return linear(powp(x));
7731 scale.invert = function(x) {
7732 return powb(linear.invert(x));
7734 scale.domain = function(x) {
7735 if (!arguments.length) return domain;
7736 linear.domain((domain = x.map(Number)).map(powp));
7739 scale.ticks = function(m) {
7740 return d3_scale_linearTicks(domain, m);
7742 scale.tickFormat = function(m, format) {
7743 return d3_scale_linearTickFormat(domain, m, format);
7745 scale.nice = function(m) {
7746 return scale.domain(d3_scale_linearNice(domain, m));
7748 scale.exponent = function(x) {
7749 if (!arguments.length) return exponent;
7750 powp = d3_scale_powPow(exponent = x);
7751 powb = d3_scale_powPow(1 / exponent);
7752 linear.domain(domain.map(powp));
7755 scale.copy = function() {
7756 return d3_scale_pow(linear.copy(), exponent, domain);
7758 return d3_scale_linearRebind(scale, linear);
7760 function d3_scale_powPow(e) {
7761 return function(x) {
7762 return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
7765 d3.scale.sqrt = function() {
7766 return d3.scale.pow().exponent(.5);
7768 d3.scale.ordinal = function() {
7769 return d3_scale_ordinal([], {
7774 function d3_scale_ordinal(domain, ranger) {
7775 var index, range, rangeBand;
7777 return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
7779 function steps(start, step) {
7780 return d3.range(domain.length).map(function(i) {
7781 return start + step * i;
7784 scale.domain = function(x) {
7785 if (!arguments.length) return domain;
7787 index = new d3_Map();
7788 var i = -1, n = x.length, xi;
7789 while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
7790 return scale[ranger.t].apply(scale, ranger.a);
7792 scale.range = function(x) {
7793 if (!arguments.length) return range;
7802 scale.rangePoints = function(x, padding) {
7803 if (arguments.length < 2) padding = 0;
7804 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
7805 0) : (stop - start) / (domain.length - 1 + padding);
7806 range = steps(start + step * padding / 2, step);
7814 scale.rangeRoundPoints = function(x, padding) {
7815 if (arguments.length < 2) padding = 0;
7816 var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
7817 0) : (stop - start) / (domain.length - 1 + padding) | 0;
7818 range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
7821 t: "rangeRoundPoints",
7826 scale.rangeBands = function(x, padding, outerPadding) {
7827 if (arguments.length < 2) padding = 0;
7828 if (arguments.length < 3) outerPadding = padding;
7829 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
7830 range = steps(start + step * outerPadding, step);
7831 if (reverse) range.reverse();
7832 rangeBand = step * (1 - padding);
7839 scale.rangeRoundBands = function(x, padding, outerPadding) {
7840 if (arguments.length < 2) padding = 0;
7841 if (arguments.length < 3) outerPadding = padding;
7842 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
7843 range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
7844 if (reverse) range.reverse();
7845 rangeBand = Math.round(step * (1 - padding));
7847 t: "rangeRoundBands",
7852 scale.rangeBand = function() {
7855 scale.rangeExtent = function() {
7856 return d3_scaleExtent(ranger.a[0]);
7858 scale.copy = function() {
7859 return d3_scale_ordinal(domain, ranger);
7861 return scale.domain(domain);
7863 d3.scale.category10 = function() {
7864 return d3.scale.ordinal().range(d3_category10);
7866 d3.scale.category20 = function() {
7867 return d3.scale.ordinal().range(d3_category20);
7869 d3.scale.category20b = function() {
7870 return d3.scale.ordinal().range(d3_category20b);
7872 d3.scale.category20c = function() {
7873 return d3.scale.ordinal().range(d3_category20c);
7875 var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
7876 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);
7877 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);
7878 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);
7879 d3.scale.quantile = function() {
7880 return d3_scale_quantile([], []);
7882 function d3_scale_quantile(domain, range) {
7884 function rescale() {
7885 var k = 0, q = range.length;
7887 while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
7891 if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
7893 scale.domain = function(x) {
7894 if (!arguments.length) return domain;
7895 domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
7898 scale.range = function(x) {
7899 if (!arguments.length) return range;
7903 scale.quantiles = function() {
7906 scale.invertExtent = function(y) {
7907 y = range.indexOf(y);
7908 return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
7910 scale.copy = function() {
7911 return d3_scale_quantile(domain, range);
7915 d3.scale.quantize = function() {
7916 return d3_scale_quantize(0, 1, [ 0, 1 ]);
7918 function d3_scale_quantize(x0, x1, range) {
7921 return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
7923 function rescale() {
7924 kx = range.length / (x1 - x0);
7925 i = range.length - 1;
7928 scale.domain = function(x) {
7929 if (!arguments.length) return [ x0, x1 ];
7931 x1 = +x[x.length - 1];
7934 scale.range = function(x) {
7935 if (!arguments.length) return range;
7939 scale.invertExtent = function(y) {
7940 y = range.indexOf(y);
7941 y = y < 0 ? NaN : y / kx + x0;
7942 return [ y, y + 1 / kx ];
7944 scale.copy = function() {
7945 return d3_scale_quantize(x0, x1, range);
7949 d3.scale.threshold = function() {
7950 return d3_scale_threshold([ .5 ], [ 0, 1 ]);
7952 function d3_scale_threshold(domain, range) {
7954 if (x <= x) return range[d3.bisect(domain, x)];
7956 scale.domain = function(_) {
7957 if (!arguments.length) return domain;
7961 scale.range = function(_) {
7962 if (!arguments.length) return range;
7966 scale.invertExtent = function(y) {
7967 y = range.indexOf(y);
7968 return [ domain[y - 1], domain[y] ];
7970 scale.copy = function() {
7971 return d3_scale_threshold(domain, range);
7975 d3.scale.identity = function() {
7976 return d3_scale_identity([ 0, 1 ]);
7978 function d3_scale_identity(domain) {
7979 function identity(x) {
7982 identity.invert = identity;
7983 identity.domain = identity.range = function(x) {
7984 if (!arguments.length) return domain;
7985 domain = x.map(identity);
7988 identity.ticks = function(m) {
7989 return d3_scale_linearTicks(domain, m);
7991 identity.tickFormat = function(m, format) {
7992 return d3_scale_linearTickFormat(domain, m, format);
7994 identity.copy = function() {
7995 return d3_scale_identity(domain);
8000 function d3_zero() {
8003 d3.svg.arc = function() {
8004 var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, cornerRadius = d3_zero, padRadius = d3_svg_arcAuto, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle, padAngle = d3_svg_arcPadAngle;
8006 var r0 = Math.max(0, +innerRadius.apply(this, arguments)), r1 = Math.max(0, +outerRadius.apply(this, arguments)), a0 = startAngle.apply(this, arguments) - halfπ, a1 = endAngle.apply(this, arguments) - halfπ, da = Math.abs(a1 - a0), cw = a0 > a1 ? 0 : 1;
8007 if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
8008 if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
8009 var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
8010 if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
8011 rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
8013 if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
8014 if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
8017 x0 = r1 * Math.cos(a0 + p1);
8018 y0 = r1 * Math.sin(a0 + p1);
8019 x1 = r1 * Math.cos(a1 - p1);
8020 y1 = r1 * Math.sin(a1 - p1);
8021 var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
8022 if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
8023 var h1 = (a0 + a1) / 2;
8024 x0 = r1 * Math.cos(h1);
8025 y0 = r1 * Math.sin(h1);
8032 x2 = r0 * Math.cos(a1 - p0);
8033 y2 = r0 * Math.sin(a1 - p0);
8034 x3 = r0 * Math.cos(a0 + p0);
8035 y3 = r0 * Math.sin(a0 + p0);
8036 var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
8037 if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
8038 var h0 = (a0 + a1) / 2;
8039 x2 = r0 * Math.cos(h0);
8040 y2 = r0 * Math.sin(h0);
8046 if (da > ε && (rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
8047 cr = r0 < r1 ^ cw ? 0 : 1;
8048 var rc1 = rc, rc0 = rc;
8050 var oc = x3 == null ? [ x2, y2 ] : x1 == null ? [ x0, y0 ] : d3_geom_polygonIntersect([ x0, y0 ], [ x3, y3 ], [ x1, y1 ], [ x2, y2 ]), ax = x0 - oc[0], ay = y0 - oc[1], bx = x1 - oc[0], by = y1 - oc[1], kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2), lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
8051 rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
8052 rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
8055 var t30 = d3_svg_arcCornerTangents(x3 == null ? [ x2, y2 ] : [ x3, y3 ], [ x0, y0 ], r1, rc1, cw), t12 = d3_svg_arcCornerTangents([ x1, y1 ], [ x2, y2 ], r1, rc1, cw);
8057 path.push("M", t30[0], "A", rc1, ",", rc1, " 0 0,", cr, " ", t30[1], "A", r1, ",", r1, " 0 ", 1 - cw ^ d3_svg_arcSweep(t30[1][0], t30[1][1], t12[1][0], t12[1][1]), ",", cw, " ", t12[1], "A", rc1, ",", rc1, " 0 0,", cr, " ", t12[0]);
8059 path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
8062 path.push("M", x0, ",", y0);
8065 var t03 = d3_svg_arcCornerTangents([ x0, y0 ], [ x3, y3 ], r0, -rc0, cw), t21 = d3_svg_arcCornerTangents([ x2, y2 ], x1 == null ? [ x0, y0 ] : [ x1, y1 ], r0, -rc0, cw);
8067 path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t21[1], "A", r0, ",", r0, " 0 ", cw ^ d3_svg_arcSweep(t21[1][0], t21[1][1], t03[1][0], t03[1][1]), ",", 1 - cw, " ", t03[1], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
8069 path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
8072 path.push("L", x2, ",", y2);
8075 path.push("M", x0, ",", y0);
8076 if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
8077 path.push("L", x2, ",", y2);
8078 if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
8081 return path.join("");
8083 function circleSegment(r1, cw) {
8084 return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
8086 arc.innerRadius = function(v) {
8087 if (!arguments.length) return innerRadius;
8088 innerRadius = d3_functor(v);
8091 arc.outerRadius = function(v) {
8092 if (!arguments.length) return outerRadius;
8093 outerRadius = d3_functor(v);
8096 arc.cornerRadius = function(v) {
8097 if (!arguments.length) return cornerRadius;
8098 cornerRadius = d3_functor(v);
8101 arc.padRadius = function(v) {
8102 if (!arguments.length) return padRadius;
8103 padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
8106 arc.startAngle = function(v) {
8107 if (!arguments.length) return startAngle;
8108 startAngle = d3_functor(v);
8111 arc.endAngle = function(v) {
8112 if (!arguments.length) return endAngle;
8113 endAngle = d3_functor(v);
8116 arc.padAngle = function(v) {
8117 if (!arguments.length) return padAngle;
8118 padAngle = d3_functor(v);
8121 arc.centroid = function() {
8122 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
8123 return [ Math.cos(a) * r, Math.sin(a) * r ];
8127 var d3_svg_arcAuto = "auto";
8128 function d3_svg_arcInnerRadius(d) {
8129 return d.innerRadius;
8131 function d3_svg_arcOuterRadius(d) {
8132 return d.outerRadius;
8134 function d3_svg_arcStartAngle(d) {
8135 return d.startAngle;
8137 function d3_svg_arcEndAngle(d) {
8140 function d3_svg_arcPadAngle(d) {
8141 return d && d.padAngle;
8143 function d3_svg_arcSweep(x0, y0, x1, y1) {
8144 return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
8146 function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
8147 var x01 = p0[0] - p1[0], y01 = p0[1] - p1[1], lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01), ox = lo * y01, oy = -lo * x01, x1 = p0[0] + ox, y1 = p0[1] + oy, x2 = p1[0] + ox, y2 = p1[1] + oy, x3 = (x1 + x2) / 2, y3 = (y1 + y2) / 2, dx = x2 - x1, dy = y2 - y1, d2 = dx * dx + dy * dy, r = r1 - rc, D = x1 * y2 - x2 * y1, d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)), cx0 = (D * dy - dx * d) / d2, cy0 = (-D * dx - dy * d) / d2, cx1 = (D * dy + dx * d) / d2, cy1 = (-D * dx + dy * d) / d2, dx0 = cx0 - x3, dy0 = cy0 - y3, dx1 = cx1 - x3, dy1 = cy1 - y3;
8148 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
8149 return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
8151 function d3_svg_line(projection) {
8152 var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
8153 function line(data) {
8154 var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
8155 function segment() {
8156 segments.push("M", interpolate(projection(points), tension));
8159 if (defined.call(this, d = data[i], i)) {
8160 points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
8161 } else if (points.length) {
8166 if (points.length) segment();
8167 return segments.length ? segments.join("") : null;
8169 line.x = function(_) {
8170 if (!arguments.length) return x;
8174 line.y = function(_) {
8175 if (!arguments.length) return y;
8179 line.defined = function(_) {
8180 if (!arguments.length) return defined;
8184 line.interpolate = function(_) {
8185 if (!arguments.length) return interpolateKey;
8186 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
8189 line.tension = function(_) {
8190 if (!arguments.length) return tension;
8196 d3.svg.line = function() {
8197 return d3_svg_line(d3_identity);
8199 var d3_svg_lineInterpolators = d3.map({
8200 linear: d3_svg_lineLinear,
8201 "linear-closed": d3_svg_lineLinearClosed,
8202 step: d3_svg_lineStep,
8203 "step-before": d3_svg_lineStepBefore,
8204 "step-after": d3_svg_lineStepAfter,
8205 basis: d3_svg_lineBasis,
8206 "basis-open": d3_svg_lineBasisOpen,
8207 "basis-closed": d3_svg_lineBasisClosed,
8208 bundle: d3_svg_lineBundle,
8209 cardinal: d3_svg_lineCardinal,
8210 "cardinal-open": d3_svg_lineCardinalOpen,
8211 "cardinal-closed": d3_svg_lineCardinalClosed,
8212 monotone: d3_svg_lineMonotone
8214 d3_svg_lineInterpolators.forEach(function(key, value) {
8216 value.closed = /-closed$/.test(key);
8218 function d3_svg_lineLinear(points) {
8219 return points.length > 1 ? points.join("L") : points + "Z";
8221 function d3_svg_lineLinearClosed(points) {
8222 return points.join("L") + "Z";
8224 function d3_svg_lineStep(points) {
8225 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8226 while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
8227 if (n > 1) path.push("H", p[0]);
8228 return path.join("");
8230 function d3_svg_lineStepBefore(points) {
8231 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8232 while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
8233 return path.join("");
8235 function d3_svg_lineStepAfter(points) {
8236 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
8237 while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
8238 return path.join("");
8240 function d3_svg_lineCardinalOpen(points, tension) {
8241 return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
8243 function d3_svg_lineCardinalClosed(points, tension) {
8244 return points.length < 3 ? d3_svg_lineLinearClosed(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
8245 points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
8247 function d3_svg_lineCardinal(points, tension) {
8248 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
8250 function d3_svg_lineHermite(points, tangents) {
8251 if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
8252 return d3_svg_lineLinear(points);
8254 var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
8256 path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
8260 if (tangents.length > 1) {
8264 path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
8265 for (var i = 2; i < tangents.length; i++, pi++) {
8268 path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
8272 var lp = points[pi];
8273 path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
8277 function d3_svg_lineCardinalTangents(points, tension) {
8278 var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
8283 tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
8287 function d3_svg_lineBasis(points) {
8288 if (points.length < 3) return d3_svg_lineLinear(points);
8289 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) ];
8290 points.push(points[n - 1]);
8297 d3_svg_lineBasisBezier(path, px, py);
8301 return path.join("");
8303 function d3_svg_lineBasisOpen(points) {
8304 if (points.length < 4) return d3_svg_lineLinear(points);
8305 var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
8311 path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
8319 d3_svg_lineBasisBezier(path, px, py);
8321 return path.join("");
8323 function d3_svg_lineBasisClosed(points) {
8324 var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
8330 path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
8338 d3_svg_lineBasisBezier(path, px, py);
8340 return path.join("");
8342 function d3_svg_lineBundle(points, tension) {
8343 var n = points.length - 1;
8345 var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
8349 p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
8350 p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
8353 return d3_svg_lineBasis(points);
8355 function d3_svg_lineDot4(a, b) {
8356 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
8358 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 ];
8359 function d3_svg_lineBasisBezier(path, x, y) {
8360 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));
8362 function d3_svg_lineSlope(p0, p1) {
8363 return (p1[1] - p0[1]) / (p1[0] - p0[0]);
8365 function d3_svg_lineFiniteDifferences(points) {
8366 var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
8368 m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
8373 function d3_svg_lineMonotoneTangents(points) {
8374 var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
8376 d = d3_svg_lineSlope(points[i], points[i + 1]);
8378 m[i] = m[i + 1] = 0;
8384 s = d * 3 / Math.sqrt(s);
8392 s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
8393 tangents.push([ s || 0, m[i] * s || 0 ]);
8397 function d3_svg_lineMonotone(points) {
8398 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
8400 d3.svg.line.radial = function() {
8401 var line = d3_svg_line(d3_svg_lineRadial);
8402 line.radius = line.x, delete line.x;
8403 line.angle = line.y, delete line.y;
8406 function d3_svg_lineRadial(points) {
8407 var point, i = -1, n = points.length, r, a;
8411 a = point[1] - halfπ;
8412 point[0] = r * Math.cos(a);
8413 point[1] = r * Math.sin(a);
8417 function d3_svg_area(projection) {
8418 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;
8419 function area(data) {
8420 var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
8422 } : d3_functor(x1), fy1 = y0 === y1 ? function() {
8424 } : d3_functor(y1), x, y;
8425 function segment() {
8426 segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
8429 if (defined.call(this, d = data[i], i)) {
8430 points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
8431 points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
8432 } else if (points0.length) {
8438 if (points0.length) segment();
8439 return segments.length ? segments.join("") : null;
8441 area.x = function(_) {
8442 if (!arguments.length) return x1;
8446 area.x0 = function(_) {
8447 if (!arguments.length) return x0;
8451 area.x1 = function(_) {
8452 if (!arguments.length) return x1;
8456 area.y = function(_) {
8457 if (!arguments.length) return y1;
8461 area.y0 = function(_) {
8462 if (!arguments.length) return y0;
8466 area.y1 = function(_) {
8467 if (!arguments.length) return y1;
8471 area.defined = function(_) {
8472 if (!arguments.length) return defined;
8476 area.interpolate = function(_) {
8477 if (!arguments.length) return interpolateKey;
8478 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
8479 interpolateReverse = interpolate.reverse || interpolate;
8480 L = interpolate.closed ? "M" : "L";
8483 area.tension = function(_) {
8484 if (!arguments.length) return tension;
8490 d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
8491 d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
8492 d3.svg.area = function() {
8493 return d3_svg_area(d3_identity);
8495 d3.svg.area.radial = function() {
8496 var area = d3_svg_area(d3_svg_lineRadial);
8497 area.radius = area.x, delete area.x;
8498 area.innerRadius = area.x0, delete area.x0;
8499 area.outerRadius = area.x1, delete area.x1;
8500 area.angle = area.y, delete area.y;
8501 area.startAngle = area.y0, delete area.y0;
8502 area.endAngle = area.y1, delete area.y1;
8505 d3.svg.chord = function() {
8506 var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
8507 function chord(d, i) {
8508 var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
8509 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";
8511 function subgroup(self, f, d, i) {
8512 var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) - halfπ, a1 = endAngle.call(self, subgroup, i) - halfπ;
8517 p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
8518 p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
8521 function equals(a, b) {
8522 return a.a0 == b.a0 && a.a1 == b.a1;
8524 function arc(r, p, a) {
8525 return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
8527 function curve(r0, p0, r1, p1) {
8528 return "Q 0,0 " + p1;
8530 chord.radius = function(v) {
8531 if (!arguments.length) return radius;
8532 radius = d3_functor(v);
8535 chord.source = function(v) {
8536 if (!arguments.length) return source;
8537 source = d3_functor(v);
8540 chord.target = function(v) {
8541 if (!arguments.length) return target;
8542 target = d3_functor(v);
8545 chord.startAngle = function(v) {
8546 if (!arguments.length) return startAngle;
8547 startAngle = d3_functor(v);
8550 chord.endAngle = function(v) {
8551 if (!arguments.length) return endAngle;
8552 endAngle = d3_functor(v);
8557 function d3_svg_chordRadius(d) {
8560 d3.svg.diagonal = function() {
8561 var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
8562 function diagonal(d, i) {
8563 var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
8570 p = p.map(projection);
8571 return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
8573 diagonal.source = function(x) {
8574 if (!arguments.length) return source;
8575 source = d3_functor(x);
8578 diagonal.target = function(x) {
8579 if (!arguments.length) return target;
8580 target = d3_functor(x);
8583 diagonal.projection = function(x) {
8584 if (!arguments.length) return projection;
8590 function d3_svg_diagonalProjection(d) {
8591 return [ d.x, d.y ];
8593 d3.svg.diagonal.radial = function() {
8594 var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
8595 diagonal.projection = function(x) {
8596 return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
8600 function d3_svg_diagonalRadialProjection(projection) {
8602 var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
8603 return [ r * Math.cos(a), r * Math.sin(a) ];
8606 d3.svg.symbol = function() {
8607 var type = d3_svg_symbolType, size = d3_svg_symbolSize;
8608 function symbol(d, i) {
8609 return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
8611 symbol.type = function(x) {
8612 if (!arguments.length) return type;
8613 type = d3_functor(x);
8616 symbol.size = function(x) {
8617 if (!arguments.length) return size;
8618 size = d3_functor(x);
8623 function d3_svg_symbolSize() {
8626 function d3_svg_symbolType() {
8629 function d3_svg_symbolCircle(size) {
8630 var r = Math.sqrt(size / π);
8631 return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
8633 var d3_svg_symbols = d3.map({
8634 circle: d3_svg_symbolCircle,
8635 cross: function(size) {
8636 var r = Math.sqrt(size / 5) / 2;
8637 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";
8639 diamond: function(size) {
8640 var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
8641 return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
8643 square: function(size) {
8644 var r = Math.sqrt(size) / 2;
8645 return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
8647 "triangle-down": function(size) {
8648 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8649 return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
8651 "triangle-up": function(size) {
8652 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
8653 return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
8656 d3.svg.symbolTypes = d3_svg_symbols.keys();
8657 var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
8658 d3_selectionPrototype.transition = function(name) {
8659 var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
8661 ease: d3_ease_cubicInOut,
8665 for (var j = -1, m = this.length; ++j < m; ) {
8666 subgroups.push(subgroup = []);
8667 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8668 if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
8669 subgroup.push(node);
8672 return d3_transition(subgroups, ns, id);
8674 d3_selectionPrototype.interrupt = function(name) {
8675 return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
8677 var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
8678 function d3_selection_interruptNS(ns) {
8680 var lock, activeId, active;
8681 if ((lock = this[ns]) && (active = lock[activeId = lock.active])) {
8682 active.timer.c = null;
8683 active.timer.t = NaN;
8684 if (--lock.count) delete lock[activeId]; else delete this[ns];
8686 active.event && active.event.interrupt.call(this, this.__data__, active.index);
8690 function d3_transition(groups, ns, id) {
8691 d3_subclass(groups, d3_transitionPrototype);
8692 groups.namespace = ns;
8696 var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
8697 d3_transitionPrototype.call = d3_selectionPrototype.call;
8698 d3_transitionPrototype.empty = d3_selectionPrototype.empty;
8699 d3_transitionPrototype.node = d3_selectionPrototype.node;
8700 d3_transitionPrototype.size = d3_selectionPrototype.size;
8701 d3.transition = function(selection, name) {
8702 return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
8704 d3.transition.prototype = d3_transitionPrototype;
8705 d3_transitionPrototype.select = function(selector) {
8706 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
8707 selector = d3_selection_selector(selector);
8708 for (var j = -1, m = this.length; ++j < m; ) {
8709 subgroups.push(subgroup = []);
8710 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8711 if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
8712 if ("__data__" in node) subnode.__data__ = node.__data__;
8713 d3_transitionNode(subnode, i, ns, id, node[ns][id]);
8714 subgroup.push(subnode);
8716 subgroup.push(null);
8720 return d3_transition(subgroups, ns, id);
8722 d3_transitionPrototype.selectAll = function(selector) {
8723 var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
8724 selector = d3_selection_selectorAll(selector);
8725 for (var j = -1, m = this.length; ++j < m; ) {
8726 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
8727 if (node = group[i]) {
8728 transition = node[ns][id];
8729 subnodes = selector.call(node, node.__data__, i, j);
8730 subgroups.push(subgroup = []);
8731 for (var k = -1, o = subnodes.length; ++k < o; ) {
8732 if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
8733 subgroup.push(subnode);
8738 return d3_transition(subgroups, ns, id);
8740 d3_transitionPrototype.filter = function(filter) {
8741 var subgroups = [], subgroup, group, node;
8742 if (typeof filter !== "function") filter = d3_selection_filter(filter);
8743 for (var j = 0, m = this.length; j < m; j++) {
8744 subgroups.push(subgroup = []);
8745 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
8746 if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
8747 subgroup.push(node);
8751 return d3_transition(subgroups, this.namespace, this.id);
8753 d3_transitionPrototype.tween = function(name, tween) {
8754 var id = this.id, ns = this.namespace;
8755 if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
8756 return d3_selection_each(this, tween == null ? function(node) {
8757 node[ns][id].tween.remove(name);
8758 } : function(node) {
8759 node[ns][id].tween.set(name, tween);
8762 function d3_transition_tween(groups, name, value, tween) {
8763 var id = groups.id, ns = groups.namespace;
8764 return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
8765 node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
8766 } : (value = tween(value), function(node) {
8767 node[ns][id].tween.set(name, value);
8770 d3_transitionPrototype.attr = function(nameNS, value) {
8771 if (arguments.length < 2) {
8772 for (value in nameNS) this.attr(value, nameNS[value]);
8775 var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
8776 function attrNull() {
8777 this.removeAttribute(name);
8779 function attrNullNS() {
8780 this.removeAttributeNS(name.space, name.local);
8782 function attrTween(b) {
8783 return b == null ? attrNull : (b += "", function() {
8784 var a = this.getAttribute(name), i;
8785 return a !== b && (i = interpolate(a, b), function(t) {
8786 this.setAttribute(name, i(t));
8790 function attrTweenNS(b) {
8791 return b == null ? attrNullNS : (b += "", function() {
8792 var a = this.getAttributeNS(name.space, name.local), i;
8793 return a !== b && (i = interpolate(a, b), function(t) {
8794 this.setAttributeNS(name.space, name.local, i(t));
8798 return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
8800 d3_transitionPrototype.attrTween = function(nameNS, tween) {
8801 var name = d3.ns.qualify(nameNS);
8802 function attrTween(d, i) {
8803 var f = tween.call(this, d, i, this.getAttribute(name));
8804 return f && function(t) {
8805 this.setAttribute(name, f(t));
8808 function attrTweenNS(d, i) {
8809 var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
8810 return f && function(t) {
8811 this.setAttributeNS(name.space, name.local, f(t));
8814 return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
8816 d3_transitionPrototype.style = function(name, value, priority) {
8817 var n = arguments.length;
8819 if (typeof name !== "string") {
8820 if (n < 2) value = "";
8821 for (priority in name) this.style(priority, name[priority], value);
8826 function styleNull() {
8827 this.style.removeProperty(name);
8829 function styleString(b) {
8830 return b == null ? styleNull : (b += "", function() {
8831 var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
8832 return a !== b && (i = d3_interpolate(a, b), function(t) {
8833 this.style.setProperty(name, i(t), priority);
8837 return d3_transition_tween(this, "style." + name, value, styleString);
8839 d3_transitionPrototype.styleTween = function(name, tween, priority) {
8840 if (arguments.length < 3) priority = "";
8841 function styleTween(d, i) {
8842 var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
8843 return f && function(t) {
8844 this.style.setProperty(name, f(t), priority);
8847 return this.tween("style." + name, styleTween);
8849 d3_transitionPrototype.text = function(value) {
8850 return d3_transition_tween(this, "text", value, d3_transition_text);
8852 function d3_transition_text(b) {
8853 if (b == null) b = "";
8855 this.textContent = b;
8858 d3_transitionPrototype.remove = function() {
8859 var ns = this.namespace;
8860 return this.each("end.transition", function() {
8862 if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
8865 d3_transitionPrototype.ease = function(value) {
8866 var id = this.id, ns = this.namespace;
8867 if (arguments.length < 1) return this.node()[ns][id].ease;
8868 if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
8869 return d3_selection_each(this, function(node) {
8870 node[ns][id].ease = value;
8873 d3_transitionPrototype.delay = function(value) {
8874 var id = this.id, ns = this.namespace;
8875 if (arguments.length < 1) return this.node()[ns][id].delay;
8876 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8877 node[ns][id].delay = +value.call(node, node.__data__, i, j);
8878 } : (value = +value, function(node) {
8879 node[ns][id].delay = value;
8882 d3_transitionPrototype.duration = function(value) {
8883 var id = this.id, ns = this.namespace;
8884 if (arguments.length < 1) return this.node()[ns][id].duration;
8885 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
8886 node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
8887 } : (value = Math.max(1, value), function(node) {
8888 node[ns][id].duration = value;
8891 d3_transitionPrototype.each = function(type, listener) {
8892 var id = this.id, ns = this.namespace;
8893 if (arguments.length < 2) {
8894 var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
8896 d3_transitionInheritId = id;
8897 d3_selection_each(this, function(node, i, j) {
8898 d3_transitionInherit = node[ns][id];
8899 type.call(node, node.__data__, i, j);
8902 d3_transitionInherit = inherit;
8903 d3_transitionInheritId = inheritId;
8906 d3_selection_each(this, function(node) {
8907 var transition = node[ns][id];
8908 (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
8913 d3_transitionPrototype.transition = function() {
8914 var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
8915 for (var j = 0, m = this.length; j < m; j++) {
8916 subgroups.push(subgroup = []);
8917 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
8918 if (node = group[i]) {
8919 transition = node[ns][id0];
8920 d3_transitionNode(node, i, ns, id1, {
8921 time: transition.time,
8922 ease: transition.ease,
8923 delay: transition.delay + transition.duration,
8924 duration: transition.duration
8927 subgroup.push(node);
8930 return d3_transition(subgroups, ns, id1);
8932 function d3_transitionNamespace(name) {
8933 return name == null ? "__transition__" : "__transition_" + name + "__";
8935 function d3_transitionNode(node, i, ns, id, inherit) {
8936 var lock = node[ns] || (node[ns] = {
8939 }), transition = lock[id], time, timer, duration, ease, tweens;
8940 function schedule(elapsed) {
8941 var delay = transition.delay;
8942 timer.t = delay + time;
8943 if (delay <= elapsed) return start(elapsed - delay);
8946 function start(elapsed) {
8947 var activeId = lock.active, active = lock[activeId];
8949 active.timer.c = null;
8950 active.timer.t = NaN;
8952 delete lock[activeId];
8953 active.event && active.event.interrupt.call(node, node.__data__, active.index);
8955 for (var cancelId in lock) {
8956 if (+cancelId < id) {
8957 var cancel = lock[cancelId];
8958 cancel.timer.c = null;
8959 cancel.timer.t = NaN;
8961 delete lock[cancelId];
8965 d3_timer(function() {
8966 if (timer.c && tick(elapsed || 1)) {
8973 transition.event && transition.event.start.call(node, node.__data__, i);
8975 transition.tween.forEach(function(key, value) {
8976 if (value = value.call(node, node.__data__, i)) {
8980 ease = transition.ease;
8981 duration = transition.duration;
8983 function tick(elapsed) {
8984 var t = elapsed / duration, e = ease(t), n = tweens.length;
8986 tweens[--n].call(node, e);
8989 transition.event && transition.event.end.call(node, node.__data__, i);
8990 if (--lock.count) delete lock[id]; else delete node[ns];
8995 time = inherit.time;
8996 timer = d3_timer(schedule, 0, time);
8997 transition = lock[id] = {
8998 tween: new d3_Map(),
9001 delay: inherit.delay,
9002 duration: inherit.duration,
9010 d3.svg.axis = function() {
9011 var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
9014 var g = d3.select(this);
9015 var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
9016 var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick.order()).style("opacity", 1), tickSpacing = Math.max(innerTickSize, 0) + tickPadding, tickTransform;
9017 var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
9018 d3.transition(path));
9019 tickEnter.append("line");
9020 tickEnter.append("text");
9021 var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text"), sign = orient === "top" || orient === "left" ? -1 : 1, x1, x2, y1, y2;
9022 if (orient === "bottom" || orient === "top") {
9023 tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
9024 text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
9025 pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
9027 tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
9028 text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
9029 pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
9031 lineEnter.attr(y2, sign * innerTickSize);
9032 textEnter.attr(y1, sign * tickSpacing);
9033 lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
9034 textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
9035 if (scale1.rangeBand) {
9036 var x = scale1, dx = x.rangeBand() / 2;
9037 scale0 = scale1 = function(d) {
9040 } else if (scale0.rangeBand) {
9043 tickExit.call(tickTransform, scale1, scale0);
9045 tickEnter.call(tickTransform, scale0, scale1);
9046 tickUpdate.call(tickTransform, scale1, scale1);
9049 axis.scale = function(x) {
9050 if (!arguments.length) return scale;
9054 axis.orient = function(x) {
9055 if (!arguments.length) return orient;
9056 orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
9059 axis.ticks = function() {
9060 if (!arguments.length) return tickArguments_;
9061 tickArguments_ = d3_array(arguments);
9064 axis.tickValues = function(x) {
9065 if (!arguments.length) return tickValues;
9069 axis.tickFormat = function(x) {
9070 if (!arguments.length) return tickFormat_;
9074 axis.tickSize = function(x) {
9075 var n = arguments.length;
9076 if (!n) return innerTickSize;
9078 outerTickSize = +arguments[n - 1];
9081 axis.innerTickSize = function(x) {
9082 if (!arguments.length) return innerTickSize;
9086 axis.outerTickSize = function(x) {
9087 if (!arguments.length) return outerTickSize;
9091 axis.tickPadding = function(x) {
9092 if (!arguments.length) return tickPadding;
9096 axis.tickSubdivide = function() {
9097 return arguments.length && axis;
9101 var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
9107 function d3_svg_axisX(selection, x0, x1) {
9108 selection.attr("transform", function(d) {
9110 return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
9113 function d3_svg_axisY(selection, y0, y1) {
9114 selection.attr("transform", function(d) {
9116 return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
9119 d3.svg.brush = function() {
9120 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];
9123 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);
9124 var background = g.selectAll(".background").data([ 0 ]);
9125 background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
9126 g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
9127 var resize = g.selectAll(".resize").data(resizes, d3_identity);
9128 resize.exit().remove();
9129 resize.enter().append("g").attr("class", function(d) {
9130 return "resize " + d;
9131 }).style("cursor", function(d) {
9132 return d3_svg_brushCursor[d];
9133 }).append("rect").attr("x", function(d) {
9134 return /[ew]$/.test(d) ? -3 : null;
9135 }).attr("y", function(d) {
9136 return /^[ns]/.test(d) ? -3 : null;
9137 }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
9138 resize.style("display", brush.empty() ? "none" : null);
9139 var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
9141 range = d3_scaleRange(x);
9142 backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
9146 range = d3_scaleRange(y);
9147 backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
9153 brush.event = function(g) {
9155 var event_ = event.of(this, arguments), extent1 = {
9160 }, extent0 = this.__chart__ || extent1;
9161 this.__chart__ = extent1;
9162 if (d3_transitionInheritId) {
9163 d3.select(this).transition().each("start.brush", function() {
9164 xExtentDomain = extent0.i;
9165 yExtentDomain = extent0.j;
9166 xExtent = extent0.x;
9167 yExtent = extent0.y;
9171 }).tween("brush:brush", function() {
9172 var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
9173 xExtentDomain = yExtentDomain = null;
9174 return function(t) {
9175 xExtent = extent1.x = xi(t);
9176 yExtent = extent1.y = yi(t);
9182 }).each("end.brush", function() {
9183 xExtentDomain = extent1.i;
9184 yExtentDomain = extent1.j;
9207 function redraw(g) {
9208 g.selectAll(".resize").attr("transform", function(d) {
9209 return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
9212 function redrawX(g) {
9213 g.select(".extent").attr("x", xExtent[0]);
9214 g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
9216 function redrawY(g) {
9217 g.select(".extent").attr("y", yExtent[0]);
9218 g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
9220 function brushstart() {
9221 var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), dragRestore = d3_event_dragSuppress(target), center, origin = d3.mouse(target), offset;
9222 var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
9223 if (d3.event.changedTouches) {
9224 w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
9226 w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
9228 g.interrupt().selectAll("*").interrupt();
9230 origin[0] = xExtent[0] - origin[0];
9231 origin[1] = yExtent[0] - origin[1];
9232 } else if (resizing) {
9233 var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
9234 offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
9235 origin[0] = xExtent[ex];
9236 origin[1] = yExtent[ey];
9237 } else if (d3.event.altKey) center = origin.slice();
9238 g.style("pointer-events", "none").selectAll(".resize").style("display", null);
9239 d3.select("body").style("cursor", eventTarget.style("cursor"));
9244 function keydown() {
9245 if (d3.event.keyCode == 32) {
9248 origin[0] -= xExtent[1];
9249 origin[1] -= yExtent[1];
9252 d3_eventPreventDefault();
9256 if (d3.event.keyCode == 32 && dragging == 2) {
9257 origin[0] += xExtent[1];
9258 origin[1] += yExtent[1];
9260 d3_eventPreventDefault();
9263 function brushmove() {
9264 var point = d3.mouse(target), moved = false;
9266 point[0] += offset[0];
9267 point[1] += offset[1];
9270 if (d3.event.altKey) {
9271 if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
9272 origin[0] = xExtent[+(point[0] < center[0])];
9273 origin[1] = yExtent[+(point[1] < center[1])];
9274 } else center = null;
9276 if (resizingX && move1(point, x, 0)) {
9280 if (resizingY && move1(point, y, 1)) {
9288 mode: dragging ? "move" : "resize"
9292 function move1(point, scale, i) {
9293 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;
9296 r1 -= size + position;
9298 min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
9300 max = (min += position) + size;
9302 if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
9303 if (position < min) {
9310 if (extent[0] != min || extent[1] != max) {
9311 if (i) yExtentDomain = null; else xExtentDomain = null;
9317 function brushend() {
9319 g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
9320 d3.select("body").style("cursor", null);
9321 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);
9328 brush.x = function(z) {
9329 if (!arguments.length) return x;
9331 resizes = d3_svg_brushResizes[!x << 1 | !y];
9334 brush.y = function(z) {
9335 if (!arguments.length) return y;
9337 resizes = d3_svg_brushResizes[!x << 1 | !y];
9340 brush.clamp = function(z) {
9341 if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
9342 if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
9345 brush.extent = function(z) {
9346 var x0, x1, y0, y1, t;
9347 if (!arguments.length) {
9349 if (xExtentDomain) {
9350 x0 = xExtentDomain[0], x1 = xExtentDomain[1];
9352 x0 = xExtent[0], x1 = xExtent[1];
9353 if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
9354 if (x1 < x0) t = x0, x0 = x1, x1 = t;
9358 if (yExtentDomain) {
9359 y0 = yExtentDomain[0], y1 = yExtentDomain[1];
9361 y0 = yExtent[0], y1 = yExtent[1];
9362 if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
9363 if (y1 < y0) t = y0, y0 = y1, y1 = t;
9366 return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
9369 x0 = z[0], x1 = z[1];
9370 if (y) x0 = x0[0], x1 = x1[0];
9371 xExtentDomain = [ x0, x1 ];
9372 if (x.invert) x0 = x(x0), x1 = x(x1);
9373 if (x1 < x0) t = x0, x0 = x1, x1 = t;
9374 if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
9377 y0 = z[0], y1 = z[1];
9378 if (x) y0 = y0[1], y1 = y1[1];
9379 yExtentDomain = [ y0, y1 ];
9380 if (y.invert) y0 = y(y0), y1 = y(y1);
9381 if (y1 < y0) t = y0, y0 = y1, y1 = t;
9382 if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
9386 brush.clear = function() {
9387 if (!brush.empty()) {
9388 xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
9389 xExtentDomain = yExtentDomain = null;
9393 brush.empty = function() {
9394 return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
9396 return d3.rebind(brush, event, "on");
9398 var d3_svg_brushCursor = {
9408 var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
9409 var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
9410 var d3_time_formatUtc = d3_time_format.utc;
9411 var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
9412 d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
9413 function d3_time_formatIsoNative(date) {
9414 return date.toISOString();
9416 d3_time_formatIsoNative.parse = function(string) {
9417 var date = new Date(string);
9418 return isNaN(date) ? null : date;
9420 d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
9421 d3_time.second = d3_time_interval(function(date) {
9422 return new d3_date(Math.floor(date / 1e3) * 1e3);
9423 }, function(date, offset) {
9424 date.setTime(date.getTime() + Math.floor(offset) * 1e3);
9426 return date.getSeconds();
9428 d3_time.seconds = d3_time.second.range;
9429 d3_time.seconds.utc = d3_time.second.utc.range;
9430 d3_time.minute = d3_time_interval(function(date) {
9431 return new d3_date(Math.floor(date / 6e4) * 6e4);
9432 }, function(date, offset) {
9433 date.setTime(date.getTime() + Math.floor(offset) * 6e4);
9435 return date.getMinutes();
9437 d3_time.minutes = d3_time.minute.range;
9438 d3_time.minutes.utc = d3_time.minute.utc.range;
9439 d3_time.hour = d3_time_interval(function(date) {
9440 var timezone = date.getTimezoneOffset() / 60;
9441 return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
9442 }, function(date, offset) {
9443 date.setTime(date.getTime() + Math.floor(offset) * 36e5);
9445 return date.getHours();
9447 d3_time.hours = d3_time.hour.range;
9448 d3_time.hours.utc = d3_time.hour.utc.range;
9449 d3_time.month = d3_time_interval(function(date) {
9450 date = d3_time.day(date);
9453 }, function(date, offset) {
9454 date.setMonth(date.getMonth() + offset);
9456 return date.getMonth();
9458 d3_time.months = d3_time.month.range;
9459 d3_time.months.utc = d3_time.month.utc.range;
9460 function d3_time_scale(linear, methods, format) {
9464 scale.invert = function(x) {
9465 return d3_time_scaleDate(linear.invert(x));
9467 scale.domain = function(x) {
9468 if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
9472 function tickMethod(extent, count) {
9473 var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
9474 return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
9476 }), 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];
9478 scale.nice = function(interval, skip) {
9479 var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
9480 if (method) interval = method[0], skip = method[1];
9481 function skipped(date) {
9482 return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
9484 return scale.domain(d3_scale_nice(domain, skip > 1 ? {
9485 floor: function(date) {
9486 while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
9489 ceil: function(date) {
9490 while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
9495 scale.ticks = function(interval, skip) {
9496 var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
9499 if (method) interval = method[0], skip = method[1];
9500 return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
9502 scale.tickFormat = function() {
9505 scale.copy = function() {
9506 return d3_time_scale(linear.copy(), methods, format);
9508 return d3_scale_linearRebind(scale, linear);
9510 function d3_time_scaleDate(t) {
9513 var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
9514 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 ] ];
9515 var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
9516 return d.getMilliseconds();
9517 } ], [ ":%S", function(d) {
9518 return d.getSeconds();
9519 } ], [ "%I:%M", function(d) {
9520 return d.getMinutes();
9521 } ], [ "%I %p", function(d) {
9522 return d.getHours();
9523 } ], [ "%a %d", function(d) {
9524 return d.getDay() && d.getDate() != 1;
9525 } ], [ "%b %d", function(d) {
9526 return d.getDate() != 1;
9527 } ], [ "%B", function(d) {
9528 return d.getMonth();
9529 } ], [ "%Y", d3_true ] ]);
9530 var d3_time_scaleMilliseconds = {
9531 range: function(start, stop, step) {
9532 return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
9537 d3_time_scaleLocalMethods.year = d3_time.year;
9538 d3_time.scale = function() {
9539 return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
9541 var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
9542 return [ m[0].utc, m[1] ];
9544 var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
9545 return d.getUTCMilliseconds();
9546 } ], [ ":%S", function(d) {
9547 return d.getUTCSeconds();
9548 } ], [ "%I:%M", function(d) {
9549 return d.getUTCMinutes();
9550 } ], [ "%I %p", function(d) {
9551 return d.getUTCHours();
9552 } ], [ "%a %d", function(d) {
9553 return d.getUTCDay() && d.getUTCDate() != 1;
9554 } ], [ "%b %d", function(d) {
9555 return d.getUTCDate() != 1;
9556 } ], [ "%B", function(d) {
9557 return d.getUTCMonth();
9558 } ], [ "%Y", d3_true ] ]);
9559 d3_time_scaleUtcMethods.year = d3_time.year.utc;
9560 d3_time.scale.utc = function() {
9561 return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
9563 d3.text = d3_xhrType(function(request) {
9564 return request.responseText;
9566 d3.json = function(url, callback) {
9567 return d3_xhr(url, "application/json", d3_json, callback);
9569 function d3_json(request) {
9570 return JSON.parse(request.responseText);
9572 d3.html = function(url, callback) {
9573 return d3_xhr(url, "text/html", d3_html, callback);
9575 function d3_html(request) {
9576 var range = d3_document.createRange();
9577 range.selectNode(d3_document.body);
9578 return range.createContextualFragment(request.responseText);
9580 d3.xml = d3_xhrType(function(request) {
9581 return request.responseXML;
9583 if (typeof define === "function" && define.amd) this.d3 = d3, define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;