5 if (!Date.now) Date.now = function() {
8 var d3_document = document, d3_window = window;
10 d3_document.createElement("div").style.setProperty("opacity", 0, "");
12 var d3_style_prototype = d3_window.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
13 d3_style_prototype.setProperty = function(name, value, priority) {
14 d3_style_setProperty.call(this, name, value + "", priority);
17 d3.ascending = function(a, b) {
18 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
20 d3.descending = function(a, b) {
21 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
23 d3.min = function(array, f) {
24 var i = -1, n = array.length, a, b;
25 if (arguments.length === 1) {
26 while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
27 while (++i < n) if ((b = array[i]) != null && a > b) a = b;
29 while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
30 while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
34 d3.max = function(array, f) {
35 var i = -1, n = array.length, a, b;
36 if (arguments.length === 1) {
37 while (++i < n && ((a = array[i]) == null || a != a)) a = undefined;
38 while (++i < n) if ((b = array[i]) != null && b > a) a = b;
40 while (++i < n && ((a = f.call(array, array[i], i)) == null || a != a)) a = undefined;
41 while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
45 d3.extent = function(array, f) {
46 var i = -1, n = array.length, a, b, c;
47 if (arguments.length === 1) {
48 while (++i < n && ((a = c = array[i]) == null || a != a)) a = c = undefined;
49 while (++i < n) if ((b = array[i]) != null) {
54 while (++i < n && ((a = c = f.call(array, array[i], i)) == null || a != a)) a = undefined;
55 while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
62 d3.sum = function(array, f) {
63 var s = 0, n = array.length, a, i = -1;
64 if (arguments.length === 1) {
65 while (++i < n) if (!isNaN(a = +array[i])) s += a;
67 while (++i < n) if (!isNaN(a = +f.call(array, array[i], i))) s += a;
71 function d3_number(x) {
72 return x != null && !isNaN(x);
74 d3.mean = function(array, f) {
75 var n = array.length, a, m = 0, i = -1, j = 0;
76 if (arguments.length === 1) {
77 while (++i < n) if (d3_number(a = array[i])) m += (a - m) / ++j;
79 while (++i < n) if (d3_number(a = f.call(array, array[i], i))) m += (a - m) / ++j;
81 return j ? m : undefined;
83 d3.quantile = function(values, p) {
84 var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
85 return e ? v + e * (values[h] - v) : v;
87 d3.median = function(array, f) {
88 if (arguments.length > 1) array = array.map(f);
89 array = array.filter(d3_number);
90 return array.length ? d3.quantile(array.sort(d3.ascending), .5) : undefined;
92 d3.bisector = function(f) {
94 left: function(a, x, lo, hi) {
95 if (arguments.length < 3) lo = 0;
96 if (arguments.length < 4) hi = a.length;
98 var mid = lo + hi >>> 1;
99 if (f.call(a, a[mid], mid) < x) lo = mid + 1; else hi = mid;
103 right: function(a, x, lo, hi) {
104 if (arguments.length < 3) lo = 0;
105 if (arguments.length < 4) hi = a.length;
107 var mid = lo + hi >>> 1;
108 if (x < f.call(a, a[mid], mid)) hi = mid; else lo = mid + 1;
114 var d3_bisector = d3.bisector(function(d) {
117 d3.bisectLeft = d3_bisector.left;
118 d3.bisect = d3.bisectRight = d3_bisector.right;
119 d3.shuffle = function(array) {
120 var m = array.length, t, i;
122 i = Math.random() * m-- | 0;
123 t = array[m], array[m] = array[i], array[i] = t;
127 d3.permute = function(array, indexes) {
128 var permutes = [], i = -1, n = indexes.length;
129 while (++i < n) permutes[i] = array[indexes[i]];
132 d3.zip = function() {
133 if (!(n = arguments.length)) return [];
134 for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m; ) {
135 for (var j = -1, n, zip = zips[i] = new Array(n); ++j < n; ) {
136 zip[j] = arguments[j][i];
141 function d3_zipLength(d) {
144 d3.transpose = function(matrix) {
145 return d3.zip.apply(d3, matrix);
147 d3.keys = function(map) {
149 for (var key in map) keys.push(key);
152 d3.values = function(map) {
154 for (var key in map) values.push(map[key]);
157 d3.entries = function(map) {
159 for (var key in map) entries.push({
165 d3.merge = function(arrays) {
166 return Array.prototype.concat.apply([], arrays);
168 d3.range = function(start, stop, step) {
169 if (arguments.length < 3) {
171 if (arguments.length < 2) {
176 if ((stop - start) / step === Infinity) throw new Error("infinite range");
177 var range = [], k = d3_range_integerScale(Math.abs(step)), i = -1, j;
178 start *= k, stop *= k, step *= k;
179 if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
182 function d3_range_integerScale(x) {
184 while (x * k % 1) k *= 10;
187 function d3_class(ctor, properties) {
189 for (var key in properties) {
190 Object.defineProperty(ctor.prototype, key, {
191 value: properties[key],
196 ctor.prototype = properties;
199 d3.map = function(object) {
200 var map = new d3_Map();
201 for (var key in object) map.set(key, object[key]);
207 return d3_map_prefix + key in this;
210 return this[d3_map_prefix + key];
212 set: function(key, value) {
213 return this[d3_map_prefix + key] = value;
215 remove: function(key) {
216 key = d3_map_prefix + key;
217 return key in this && delete this[key];
221 this.forEach(function(key) {
228 this.forEach(function(key, value) {
233 entries: function() {
235 this.forEach(function(key, value) {
243 forEach: function(f) {
244 for (var key in this) {
245 if (key.charCodeAt(0) === d3_map_prefixCode) {
246 f.call(this, key.substring(1), this[key]);
251 var d3_map_prefix = "\0", d3_map_prefixCode = d3_map_prefix.charCodeAt(0);
252 d3.nest = function() {
253 var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
254 function map(mapType, array, depth) {
255 if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
256 var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
258 if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
261 valuesByKey.set(keyValue, [ object ]);
266 setter = function(keyValue, values) {
267 object.set(keyValue, map(mapType, values, depth));
271 setter = function(keyValue, values) {
272 object[keyValue] = map(mapType, values, depth);
275 valuesByKey.forEach(setter);
278 function entries(map, depth) {
279 if (depth >= keys.length) return map;
280 var array = [], sortKey = sortKeys[depth++];
281 map.forEach(function(key, keyMap) {
284 values: entries(keyMap, depth)
287 return sortKey ? array.sort(function(a, b) {
288 return sortKey(a.key, b.key);
291 nest.map = function(array, mapType) {
292 return map(mapType, array, 0);
294 nest.entries = function(array) {
295 return entries(map(d3.map, array, 0), 0);
297 nest.key = function(d) {
301 nest.sortKeys = function(order) {
302 sortKeys[keys.length - 1] = order;
305 nest.sortValues = function(order) {
309 nest.rollup = function(f) {
315 d3.set = function(array) {
316 var set = new d3_Set();
317 if (array) for (var i = 0; i < array.length; i++) set.add(array[i]);
322 has: function(value) {
323 return d3_map_prefix + value in this;
325 add: function(value) {
326 this[d3_map_prefix + value] = true;
329 remove: function(value) {
330 value = d3_map_prefix + value;
331 return value in this && delete this[value];
335 this.forEach(function(value) {
340 forEach: function(f) {
341 for (var value in this) {
342 if (value.charCodeAt(0) === d3_map_prefixCode) {
343 f.call(this, value.substring(1));
349 d3.rebind = function(target, source) {
350 var i = 1, n = arguments.length, method;
351 while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
354 function d3_rebind(target, source, method) {
356 var value = method.apply(source, arguments);
357 return value === source ? target : value;
360 d3.dispatch = function() {
361 var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
362 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
365 function d3_dispatch() {}
366 d3_dispatch.prototype.on = function(type, listener) {
367 var i = type.indexOf("."), name = "";
369 name = type.substring(i + 1);
370 type = type.substring(0, i);
372 if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
373 if (arguments.length === 2) {
374 if (listener == null) for (type in this) {
375 if (this.hasOwnProperty(type)) this[type].on(name, null);
380 function d3_dispatch_event(dispatch) {
381 var listeners = [], listenerByName = new d3_Map();
383 var z = listeners, i = -1, n = z.length, l;
384 while (++i < n) if (l = z[i].on) l.apply(this, arguments);
387 event.on = function(name, listener) {
388 var l = listenerByName.get(name), i;
389 if (arguments.length < 2) return l && l.on;
392 listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
393 listenerByName.remove(name);
395 if (listener) listeners.push(listenerByName.set(name, {
403 function d3_eventCancel() {
404 d3.event.stopPropagation();
405 d3.event.preventDefault();
407 function d3_eventSource() {
409 while (s = e.sourceEvent) e = s;
412 function d3_eventSuppress(target, type) {
414 target.on(type, null);
416 target.on(type, function() {
422 function d3_eventDispatch(target) {
423 var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
424 while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
425 dispatch.of = function(thiz, argumentz) {
426 return function(e1) {
428 var e0 = e1.sourceEvent = d3.event;
431 dispatch[e1.type].apply(thiz, argumentz);
439 d3.mouse = function(container) {
440 return d3_mousePoint(container, d3_eventSource());
442 var d3_mouse_bug44083 = /WebKit/.test(d3_window.navigator.userAgent) ? -1 : 0;
443 function d3_mousePoint(container, e) {
444 var svg = container.ownerSVGElement || container;
445 if (svg.createSVGPoint) {
446 var point = svg.createSVGPoint();
447 if (d3_mouse_bug44083 < 0 && (d3_window.scrollX || d3_window.scrollY)) {
448 svg = d3.select(d3_document.body).append("svg").style("position", "absolute").style("top", 0).style("left", 0);
449 var ctm = svg[0][0].getScreenCTM();
450 d3_mouse_bug44083 = !(ctm.f || ctm.e);
453 if (d3_mouse_bug44083) {
460 point = point.matrixTransform(container.getScreenCTM().inverse());
461 return [ point.x, point.y ];
463 var rect = container.getBoundingClientRect();
464 return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
466 var d3_array = d3_arraySlice;
467 function d3_arrayCopy(pseudoarray) {
468 var i = -1, n = pseudoarray.length, array = [];
469 while (++i < n) array.push(pseudoarray[i]);
472 function d3_arraySlice(pseudoarray) {
473 return Array.prototype.slice.call(pseudoarray);
476 d3_array(d3_document.documentElement.childNodes)[0].nodeType;
478 d3_array = d3_arrayCopy;
480 var d3_arraySubclass = [].__proto__ ? function(array, prototype) {
481 array.__proto__ = prototype;
482 } : function(array, prototype) {
483 for (var property in prototype) array[property] = prototype[property];
485 d3.touches = function(container, touches) {
486 if (arguments.length < 2) touches = d3_eventSource().touches;
487 return touches ? d3_array(touches).map(function(touch) {
488 var point = d3_mousePoint(container, touch);
489 point.identifier = touch.identifier;
493 d3.behavior.drag = function() {
494 var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null;
496 this.on("mousedown.drag", mousedown).on("touchstart.drag", mousedown);
498 function mousedown() {
499 var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, touchId = d3.event.touches ? d3.event.changedTouches[0].identifier : null, offset, origin_ = point(), moved = 0;
500 var w = d3.select(d3_window).on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", dragmove).on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", dragend, true);
502 offset = origin.apply(target, arguments);
503 offset = [ offset.x - origin_[0], offset.y - origin_[1] ];
507 if (touchId == null) d3_eventCancel();
512 var p = target.parentNode;
513 return touchId != null ? d3.touches(p).filter(function(p) {
514 return p.identifier === touchId;
517 function dragmove() {
518 if (!target.parentNode) return dragend();
519 var p = point(), dx = p[0] - origin_[0], dy = p[1] - origin_[1];
537 if (d3.event.target === eventTarget) d3_eventSuppress(w, "click");
539 w.on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", null).on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", null);
542 drag.origin = function(x) {
543 if (!arguments.length) return origin;
547 return d3.rebind(drag, event, "on");
549 function d3_selection(groups) {
550 d3_arraySubclass(groups, d3_selectionPrototype);
553 var d3_select = function(s, n) {
554 return n.querySelector(s);
555 }, d3_selectAll = function(s, n) {
556 return n.querySelectorAll(s);
557 }, d3_selectRoot = d3_document.documentElement, d3_selectMatcher = d3_selectRoot.matchesSelector || d3_selectRoot.webkitMatchesSelector || d3_selectRoot.mozMatchesSelector || d3_selectRoot.msMatchesSelector || d3_selectRoot.oMatchesSelector, d3_selectMatches = function(n, s) {
558 return d3_selectMatcher.call(n, s);
560 if (typeof Sizzle === "function") {
561 d3_select = function(s, n) {
562 return Sizzle(s, n)[0] || null;
564 d3_selectAll = function(s, n) {
565 return Sizzle.uniqueSort(Sizzle(s, n));
567 d3_selectMatches = Sizzle.matchesSelector;
569 var d3_selectionPrototype = [];
570 d3.selection = function() {
571 return d3_selectionRoot;
573 d3.selection.prototype = d3_selectionPrototype;
574 d3_selectionPrototype.select = function(selector) {
575 var subgroups = [], subgroup, subnode, group, node;
576 if (typeof selector !== "function") selector = d3_selection_selector(selector);
577 for (var j = -1, m = this.length; ++j < m; ) {
578 subgroups.push(subgroup = []);
579 subgroup.parentNode = (group = this[j]).parentNode;
580 for (var i = -1, n = group.length; ++i < n; ) {
581 if (node = group[i]) {
582 subgroup.push(subnode = selector.call(node, node.__data__, i));
583 if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
589 return d3_selection(subgroups);
591 function d3_selection_selector(selector) {
593 return d3_select(selector, this);
596 d3_selectionPrototype.selectAll = function(selector) {
597 var subgroups = [], subgroup, node;
598 if (typeof selector !== "function") selector = d3_selection_selectorAll(selector);
599 for (var j = -1, m = this.length; ++j < m; ) {
600 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
601 if (node = group[i]) {
602 subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i)));
603 subgroup.parentNode = node;
607 return d3_selection(subgroups);
609 function d3_selection_selectorAll(selector) {
611 return d3_selectAll(selector, this);
615 svg: "http://www.w3.org/2000/svg",
616 xhtml: "http://www.w3.org/1999/xhtml",
617 xlink: "http://www.w3.org/1999/xlink",
618 xml: "http://www.w3.org/XML/1998/namespace",
619 xmlns: "http://www.w3.org/2000/xmlns/"
623 qualify: function(name) {
624 var i = name.indexOf(":"), prefix = name;
626 prefix = name.substring(0, i);
627 name = name.substring(i + 1);
629 return d3_nsPrefix.hasOwnProperty(prefix) ? {
630 space: d3_nsPrefix[prefix],
635 d3_selectionPrototype.attr = function(name, value) {
636 if (arguments.length < 2) {
637 if (typeof name === "string") {
638 var node = this.node();
639 name = d3.ns.qualify(name);
640 return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
642 for (value in name) this.each(d3_selection_attr(value, name[value]));
645 return this.each(d3_selection_attr(name, value));
647 function d3_selection_attr(name, value) {
648 name = d3.ns.qualify(name);
649 function attrNull() {
650 this.removeAttribute(name);
652 function attrNullNS() {
653 this.removeAttributeNS(name.space, name.local);
655 function attrConstant() {
656 this.setAttribute(name, value);
658 function attrConstantNS() {
659 this.setAttributeNS(name.space, name.local, value);
661 function attrFunction() {
662 var x = value.apply(this, arguments);
663 if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
665 function attrFunctionNS() {
666 var x = value.apply(this, arguments);
667 if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
669 return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
671 function d3_collapse(s) {
672 return s.trim().replace(/\s+/g, " ");
674 d3.requote = function(s) {
675 return s.replace(d3_requote_re, "\\$&");
677 var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
678 d3_selectionPrototype.classed = function(name, value) {
679 if (arguments.length < 2) {
680 if (typeof name === "string") {
681 var node = this.node(), n = (name = name.trim().split(/^|\s+/g)).length, i = -1;
682 if (value = node.classList) {
683 while (++i < n) if (!value.contains(name[i])) return false;
685 value = node.getAttribute("class");
686 while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
690 for (value in name) this.each(d3_selection_classed(value, name[value]));
693 return this.each(d3_selection_classed(name, value));
695 function d3_selection_classedRe(name) {
696 return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
698 function d3_selection_classed(name, value) {
699 name = name.trim().split(/\s+/).map(d3_selection_classedName);
701 function classedConstant() {
703 while (++i < n) name[i](this, value);
705 function classedFunction() {
706 var i = -1, x = value.apply(this, arguments);
707 while (++i < n) name[i](this, x);
709 return typeof value === "function" ? classedFunction : classedConstant;
711 function d3_selection_classedName(name) {
712 var re = d3_selection_classedRe(name);
713 return function(node, value) {
714 if (c = node.classList) return value ? c.add(name) : c.remove(name);
715 var c = node.getAttribute("class") || "";
718 if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
720 node.setAttribute("class", d3_collapse(c.replace(re, " ")));
724 d3_selectionPrototype.style = function(name, value, priority) {
725 var n = arguments.length;
727 if (typeof name !== "string") {
728 if (n < 2) value = "";
729 for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
732 if (n < 2) return d3_window.getComputedStyle(this.node(), null).getPropertyValue(name);
735 return this.each(d3_selection_style(name, value, priority));
737 function d3_selection_style(name, value, priority) {
738 function styleNull() {
739 this.style.removeProperty(name);
741 function styleConstant() {
742 this.style.setProperty(name, value, priority);
744 function styleFunction() {
745 var x = value.apply(this, arguments);
746 if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
748 return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
750 d3_selectionPrototype.property = function(name, value) {
751 if (arguments.length < 2) {
752 if (typeof name === "string") return this.node()[name];
753 for (value in name) this.each(d3_selection_property(value, name[value]));
756 return this.each(d3_selection_property(name, value));
758 function d3_selection_property(name, value) {
759 function propertyNull() {
762 function propertyConstant() {
765 function propertyFunction() {
766 var x = value.apply(this, arguments);
767 if (x == null) delete this[name]; else this[name] = x;
769 return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
771 d3_selectionPrototype.text = function(value) {
772 return arguments.length ? this.each(typeof value === "function" ? function() {
773 var v = value.apply(this, arguments);
774 this.textContent = v == null ? "" : v;
775 } : value == null ? function() {
776 this.textContent = "";
778 this.textContent = value;
779 }) : this.node().textContent;
781 d3_selectionPrototype.html = function(value) {
782 return arguments.length ? this.each(typeof value === "function" ? function() {
783 var v = value.apply(this, arguments);
784 this.innerHTML = v == null ? "" : v;
785 } : value == null ? function() {
788 this.innerHTML = value;
789 }) : this.node().innerHTML;
791 d3_selectionPrototype.append = function(name) {
792 name = d3.ns.qualify(name);
794 return this.appendChild(d3_document.createElementNS(this.namespaceURI, name));
796 function appendNS() {
797 return this.appendChild(d3_document.createElementNS(name.space, name.local));
799 return this.select(name.local ? appendNS : append);
801 d3_selectionPrototype.insert = function(name, before) {
802 name = d3.ns.qualify(name);
803 if (typeof before !== "function") before = d3_selection_selector(before);
804 function insert(d, i) {
805 return this.insertBefore(d3_document.createElementNS(this.namespaceURI, name), before.call(this, d, i));
807 function insertNS(d, i) {
808 return this.insertBefore(d3_document.createElementNS(name.space, name.local), before.call(this, d, i));
810 return this.select(name.local ? insertNS : insert);
812 d3_selectionPrototype.remove = function() {
813 return this.each(function() {
814 var parent = this.parentNode;
815 if (parent) parent.removeChild(this);
818 d3_selectionPrototype.data = function(value, key) {
819 var i = -1, n = this.length, group, node;
820 if (!arguments.length) {
821 value = new Array(n = (group = this[0]).length);
823 if (node = group[i]) {
824 value[i] = node.__data__;
829 function bind(group, groupData) {
830 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;
832 var nodeByKeyValue = new d3_Map(), dataByKeyValue = new d3_Map(), keyValues = [], keyValue;
833 for (i = -1; ++i < n; ) {
834 keyValue = key.call(node = group[i], node.__data__, i);
835 if (nodeByKeyValue.has(keyValue)) {
838 nodeByKeyValue.set(keyValue, node);
840 keyValues.push(keyValue);
842 for (i = -1; ++i < m; ) {
843 keyValue = key.call(groupData, nodeData = groupData[i], i);
844 if (node = nodeByKeyValue.get(keyValue)) {
845 updateNodes[i] = node;
846 node.__data__ = nodeData;
847 } else if (!dataByKeyValue.has(keyValue)) {
848 enterNodes[i] = d3_selection_dataNode(nodeData);
850 dataByKeyValue.set(keyValue, nodeData);
851 nodeByKeyValue.remove(keyValue);
853 for (i = -1; ++i < n; ) {
854 if (nodeByKeyValue.has(keyValues[i])) {
855 exitNodes[i] = group[i];
859 for (i = -1; ++i < n0; ) {
861 nodeData = groupData[i];
863 node.__data__ = nodeData;
864 updateNodes[i] = node;
866 enterNodes[i] = d3_selection_dataNode(nodeData);
870 enterNodes[i] = d3_selection_dataNode(groupData[i]);
873 exitNodes[i] = group[i];
876 enterNodes.update = updateNodes;
877 enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
878 enter.push(enterNodes);
879 update.push(updateNodes);
880 exit.push(exitNodes);
882 var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
883 if (typeof value === "function") {
885 bind(group = this[i], value.call(group, group.parentNode.__data__, i));
889 bind(group = this[i], value);
892 update.enter = function() {
895 update.exit = function() {
900 function d3_selection_dataNode(data) {
905 d3_selectionPrototype.datum = function(value) {
906 return arguments.length ? this.property("__data__", value) : this.property("__data__");
908 d3_selectionPrototype.filter = function(filter) {
909 var subgroups = [], subgroup, group, node;
910 if (typeof filter !== "function") filter = d3_selection_filter(filter);
911 for (var j = 0, m = this.length; j < m; j++) {
912 subgroups.push(subgroup = []);
913 subgroup.parentNode = (group = this[j]).parentNode;
914 for (var i = 0, n = group.length; i < n; i++) {
915 if ((node = group[i]) && filter.call(node, node.__data__, i)) {
920 return d3_selection(subgroups);
922 function d3_selection_filter(selector) {
924 return d3_selectMatches(this, selector);
927 d3_selectionPrototype.order = function() {
928 for (var j = -1, m = this.length; ++j < m; ) {
929 for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
930 if (node = group[i]) {
931 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
938 d3_selectionPrototype.sort = function(comparator) {
939 comparator = d3_selection_sortComparator.apply(this, arguments);
940 for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
943 function d3_selection_sortComparator(comparator) {
944 if (!arguments.length) comparator = d3.ascending;
945 return function(a, b) {
946 return !a - !b || comparator(a.__data__, b.__data__);
949 function d3_noop() {}
950 d3_selectionPrototype.on = function(type, listener, capture) {
951 var n = arguments.length;
953 if (typeof type !== "string") {
954 if (n < 2) listener = false;
955 for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
958 if (n < 2) return (n = this.node()["__on" + type]) && n._;
961 return this.each(d3_selection_on(type, listener, capture));
963 function d3_selection_on(type, listener, capture) {
964 var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
965 if (i > 0) type = type.substring(0, i);
966 var filter = d3_selection_onFilters.get(type);
967 if (filter) type = filter, wrap = d3_selection_onFilter;
968 function onRemove() {
971 this.removeEventListener(type, l, l.$);
976 var l = wrap(listener, d3_array(arguments));
978 this.addEventListener(type, this[name] = l, l.$ = capture);
981 function removeAll() {
982 var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
983 for (var name in this) {
984 if (match = name.match(re)) {
986 this.removeEventListener(match[1], l, l.$);
991 return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
993 var d3_selection_onFilters = d3.map({
994 mouseenter: "mouseover",
995 mouseleave: "mouseout"
997 d3_selection_onFilters.forEach(function(k) {
998 if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
1000 function d3_selection_onListener(listener, argumentz) {
1001 return function(e) {
1004 argumentz[0] = this.__data__;
1006 listener.apply(this, argumentz);
1012 function d3_selection_onFilter(listener, argumentz) {
1013 var l = d3_selection_onListener(listener, argumentz);
1014 return function(e) {
1015 var target = this, related = e.relatedTarget;
1016 if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
1021 d3_selectionPrototype.each = function(callback) {
1022 return d3_selection_each(this, function(node, i, j) {
1023 callback.call(node, node.__data__, i, j);
1026 function d3_selection_each(groups, callback) {
1027 for (var j = 0, m = groups.length; j < m; j++) {
1028 for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
1029 if (node = group[i]) callback(node, i, j);
1034 d3_selectionPrototype.call = function(callback) {
1035 var args = d3_array(arguments);
1036 callback.apply(args[0] = this, args);
1039 d3_selectionPrototype.empty = function() {
1040 return !this.node();
1042 d3_selectionPrototype.node = function() {
1043 for (var j = 0, m = this.length; j < m; j++) {
1044 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
1045 var node = group[i];
1046 if (node) return node;
1051 function d3_selection_enter(selection) {
1052 d3_arraySubclass(selection, d3_selection_enterPrototype);
1055 var d3_selection_enterPrototype = [];
1056 d3.selection.enter = d3_selection_enter;
1057 d3.selection.enter.prototype = d3_selection_enterPrototype;
1058 d3_selection_enterPrototype.append = d3_selectionPrototype.append;
1059 d3_selection_enterPrototype.insert = d3_selectionPrototype.insert;
1060 d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
1061 d3_selection_enterPrototype.node = d3_selectionPrototype.node;
1062 d3_selection_enterPrototype.select = function(selector) {
1063 var subgroups = [], subgroup, subnode, upgroup, group, node;
1064 for (var j = -1, m = this.length; ++j < m; ) {
1065 upgroup = (group = this[j]).update;
1066 subgroups.push(subgroup = []);
1067 subgroup.parentNode = group.parentNode;
1068 for (var i = -1, n = group.length; ++i < n; ) {
1069 if (node = group[i]) {
1070 subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i));
1071 subnode.__data__ = node.__data__;
1073 subgroup.push(null);
1077 return d3_selection(subgroups);
1079 d3_selectionPrototype.transition = function() {
1080 var id = d3_transitionInheritId || ++d3_transitionId, subgroups = [], subgroup, node, transition = Object.create(d3_transitionInherit);
1081 transition.time = Date.now();
1082 for (var j = -1, m = this.length; ++j < m; ) {
1083 subgroups.push(subgroup = []);
1084 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
1085 if (node = group[i]) d3_transitionNode(node, i, id, transition);
1086 subgroup.push(node);
1089 return d3_transition(subgroups, id);
1091 var d3_selectionRoot = d3_selection([ [ d3_document ] ]);
1092 d3_selectionRoot[0].parentNode = d3_selectRoot;
1093 d3.select = function(selector) {
1094 return typeof selector === "string" ? d3_selectionRoot.select(selector) : d3_selection([ [ selector ] ]);
1096 d3.selectAll = function(selector) {
1097 return typeof selector === "string" ? d3_selectionRoot.selectAll(selector) : d3_selection([ d3_array(selector) ]);
1099 d3.behavior.zoom = function() {
1100 var translate = [ 0, 0 ], translate0, scale = 1, scale0, scaleExtent = d3_behavior_zoomInfinity, event = d3_eventDispatch(zoom, "zoom"), x0, x1, y0, y1, touchtime;
1102 this.on("mousedown.zoom", mousedown).on("mousemove.zoom", mousemove).on(d3_behavior_zoomWheel + ".zoom", mousewheel).on("dblclick.zoom", dblclick).on("touchstart.zoom", touchstart).on("touchmove.zoom", touchmove).on("touchend.zoom", touchstart);
1104 zoom.translate = function(x) {
1105 if (!arguments.length) return translate;
1106 translate = x.map(Number);
1110 zoom.scale = function(x) {
1111 if (!arguments.length) return scale;
1116 zoom.scaleExtent = function(x) {
1117 if (!arguments.length) return scaleExtent;
1118 scaleExtent = x == null ? d3_behavior_zoomInfinity : x.map(Number);
1121 zoom.x = function(z) {
1122 if (!arguments.length) return x1;
1125 translate = [ 0, 0 ];
1129 zoom.y = function(z) {
1130 if (!arguments.length) return y1;
1133 translate = [ 0, 0 ];
1137 function location(p) {
1138 return [ (p[0] - translate[0]) / scale, (p[1] - translate[1]) / scale ];
1141 return [ l[0] * scale + translate[0], l[1] * scale + translate[1] ];
1143 function scaleTo(s) {
1144 scale = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
1146 function translateTo(p, l) {
1148 translate[0] += p[0] - l[0];
1149 translate[1] += p[1] - l[1];
1151 function rescale() {
1152 if (x1) x1.domain(x0.range().map(function(x) {
1153 return (x - translate[0]) / scale;
1155 if (y1) y1.domain(y0.range().map(function(y) {
1156 return (y - translate[1]) / scale;
1159 function dispatch(event) {
1161 d3.event.preventDefault();
1165 translate: translate
1168 function mousedown() {
1169 var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, moved = 0, w = d3.select(d3_window).on("mousemove.zoom", mousemove).on("mouseup.zoom", mouseup), l = location(d3.mouse(target));
1172 function mousemove() {
1174 translateTo(d3.mouse(target), l);
1177 function mouseup() {
1178 if (moved) d3_eventCancel();
1179 w.on("mousemove.zoom", null).on("mouseup.zoom", null);
1180 if (moved && d3.event.target === eventTarget) d3_eventSuppress(w, "click.zoom");
1183 function mousewheel() {
1184 if (!translate0) translate0 = location(d3.mouse(this));
1185 scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * scale);
1186 translateTo(d3.mouse(this), translate0);
1187 dispatch(event.of(this, arguments));
1189 function mousemove() {
1192 function dblclick() {
1193 var p = d3.mouse(this), l = location(p), k = Math.log(scale) / Math.LN2;
1194 scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1));
1196 dispatch(event.of(this, arguments));
1198 function touchstart() {
1199 var touches = d3.touches(this), now = Date.now();
1202 touches.forEach(function(t) {
1203 translate0[t.identifier] = location(t);
1206 if (touches.length === 1) {
1207 if (now - touchtime < 500) {
1208 var p = touches[0], l = location(touches[0]);
1211 dispatch(event.of(this, arguments));
1216 function touchmove() {
1217 var touches = d3.touches(this), p0 = touches[0], l0 = translate0[p0.identifier];
1218 if (p1 = touches[1]) {
1219 var p1, l1 = translate0[p1.identifier];
1220 p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
1221 l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
1222 scaleTo(d3.event.scale * scale0);
1224 translateTo(p0, l0);
1226 dispatch(event.of(this, arguments));
1228 return d3.rebind(zoom, event, "on");
1230 var d3_behavior_zoomInfinity = [ 0, Infinity ];
1231 var d3_behavior_zoomDelta, d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
1232 return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
1233 }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
1234 return d3.event.wheelDelta;
1235 }, "mousewheel") : (d3_behavior_zoomDelta = function() {
1236 return -d3.event.detail;
1237 }, "MozMousePixelScroll");
1238 function d3_Color() {}
1239 d3_Color.prototype.toString = function() {
1240 return this.rgb() + "";
1242 d3.hsl = function(h, s, l) {
1243 return arguments.length === 1 ? h instanceof d3_Hsl ? d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : d3_hsl(+h, +s, +l);
1245 function d3_hsl(h, s, l) {
1246 return new d3_Hsl(h, s, l);
1248 function d3_Hsl(h, s, l) {
1253 var d3_hslPrototype = d3_Hsl.prototype = new d3_Color();
1254 d3_hslPrototype.brighter = function(k) {
1255 k = Math.pow(.7, arguments.length ? k : 1);
1256 return d3_hsl(this.h, this.s, this.l / k);
1258 d3_hslPrototype.darker = function(k) {
1259 k = Math.pow(.7, arguments.length ? k : 1);
1260 return d3_hsl(this.h, this.s, k * this.l);
1262 d3_hslPrototype.rgb = function() {
1263 return d3_hsl_rgb(this.h, this.s, this.l);
1265 function d3_hsl_rgb(h, s, l) {
1268 if (h < 0) h += 360;
1269 s = s < 0 ? 0 : s > 1 ? 1 : s;
1270 l = l < 0 ? 0 : l > 1 ? 1 : l;
1271 m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
1274 if (h > 360) h -= 360; else if (h < 0) h += 360;
1275 if (h < 60) return m1 + (m2 - m1) * h / 60;
1276 if (h < 180) return m2;
1277 if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
1281 return Math.round(v(h) * 255);
1283 return d3_rgb(vv(h + 120), vv(h), vv(h - 120));
1285 var π = Math.PI, ε = 1e-6, d3_radians = π / 180, d3_degrees = 180 / π;
1286 function d3_sgn(x) {
1287 return x > 0 ? 1 : x < 0 ? -1 : 0;
1289 function d3_acos(x) {
1290 return Math.acos(Math.max(-1, Math.min(1, x)));
1292 function d3_asin(x) {
1293 return x > 1 ? π / 2 : x < -1 ? -π / 2 : Math.asin(x);
1295 function d3_sinh(x) {
1296 return (Math.exp(x) - Math.exp(-x)) / 2;
1298 function d3_cosh(x) {
1299 return (Math.exp(x) + Math.exp(-x)) / 2;
1301 function d3_haversin(x) {
1302 return (x = Math.sin(x / 2)) * x;
1304 d3.hcl = function(h, c, l) {
1305 return arguments.length === 1 ? h instanceof d3_Hcl ? d3_hcl(h.h, h.c, h.l) : h instanceof d3_Lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : d3_hcl(+h, +c, +l);
1307 function d3_hcl(h, c, l) {
1308 return new d3_Hcl(h, c, l);
1310 function d3_Hcl(h, c, l) {
1315 var d3_hclPrototype = d3_Hcl.prototype = new d3_Color();
1316 d3_hclPrototype.brighter = function(k) {
1317 return d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
1319 d3_hclPrototype.darker = function(k) {
1320 return d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
1322 d3_hclPrototype.rgb = function() {
1323 return d3_hcl_lab(this.h, this.c, this.l).rgb();
1325 function d3_hcl_lab(h, c, l) {
1326 return d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
1328 d3.lab = function(l, a, b) {
1329 return arguments.length === 1 ? l instanceof d3_Lab ? d3_lab(l.l, l.a, l.b) : l instanceof d3_Hcl ? d3_hcl_lab(l.l, l.c, l.h) : d3_rgb_lab((l = d3.rgb(l)).r, l.g, l.b) : d3_lab(+l, +a, +b);
1331 function d3_lab(l, a, b) {
1332 return new d3_Lab(l, a, b);
1334 function d3_Lab(l, a, b) {
1340 var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
1341 var d3_labPrototype = d3_Lab.prototype = new d3_Color();
1342 d3_labPrototype.brighter = function(k) {
1343 return d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1345 d3_labPrototype.darker = function(k) {
1346 return d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
1348 d3_labPrototype.rgb = function() {
1349 return d3_lab_rgb(this.l, this.a, this.b);
1351 function d3_lab_rgb(l, a, b) {
1352 var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
1353 x = d3_lab_xyz(x) * d3_lab_X;
1354 y = d3_lab_xyz(y) * d3_lab_Y;
1355 z = d3_lab_xyz(z) * d3_lab_Z;
1356 return d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
1358 function d3_lab_hcl(l, a, b) {
1359 return d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l);
1361 function d3_lab_xyz(x) {
1362 return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
1364 function d3_xyz_lab(x) {
1365 return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
1367 function d3_xyz_rgb(r) {
1368 return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
1370 d3.rgb = function(r, g, b) {
1371 return arguments.length === 1 ? r instanceof d3_Rgb ? d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : d3_rgb(~~r, ~~g, ~~b);
1373 function d3_rgb(r, g, b) {
1374 return new d3_Rgb(r, g, b);
1376 function d3_Rgb(r, g, b) {
1381 var d3_rgbPrototype = d3_Rgb.prototype = new d3_Color();
1382 d3_rgbPrototype.brighter = function(k) {
1383 k = Math.pow(.7, arguments.length ? k : 1);
1384 var r = this.r, g = this.g, b = this.b, i = 30;
1385 if (!r && !g && !b) return d3_rgb(i, i, i);
1386 if (r && r < i) r = i;
1387 if (g && g < i) g = i;
1388 if (b && b < i) b = i;
1389 return d3_rgb(Math.min(255, Math.floor(r / k)), Math.min(255, Math.floor(g / k)), Math.min(255, Math.floor(b / k)));
1391 d3_rgbPrototype.darker = function(k) {
1392 k = Math.pow(.7, arguments.length ? k : 1);
1393 return d3_rgb(Math.floor(k * this.r), Math.floor(k * this.g), Math.floor(k * this.b));
1395 d3_rgbPrototype.hsl = function() {
1396 return d3_rgb_hsl(this.r, this.g, this.b);
1398 d3_rgbPrototype.toString = function() {
1399 return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
1401 function d3_rgb_hex(v) {
1402 return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
1404 function d3_rgb_parse(format, rgb, hsl) {
1405 var r = 0, g = 0, b = 0, m1, m2, name;
1406 m1 = /([a-z]+)\((.*)\)/i.exec(format);
1408 m2 = m1[2].split(",");
1412 return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
1417 return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
1421 if (name = d3_rgb_names.get(format)) return rgb(name.r, name.g, name.b);
1422 if (format != null && format.charAt(0) === "#") {
1423 if (format.length === 4) {
1424 r = format.charAt(1);
1426 g = format.charAt(2);
1428 b = format.charAt(3);
1430 } else if (format.length === 7) {
1431 r = format.substring(1, 3);
1432 g = format.substring(3, 5);
1433 b = format.substring(5, 7);
1435 r = parseInt(r, 16);
1436 g = parseInt(g, 16);
1437 b = parseInt(b, 16);
1439 return rgb(r, g, b);
1441 function d3_rgb_hsl(r, g, b) {
1442 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;
1444 s = l < .5 ? d / (max + min) : d / (2 - max - min);
1445 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;
1450 return d3_hsl(h, s, l);
1452 function d3_rgb_lab(r, g, b) {
1456 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);
1457 return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
1459 function d3_rgb_xyz(r) {
1460 return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
1462 function d3_rgb_parseNumber(c) {
1463 var f = parseFloat(c);
1464 return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
1466 var d3_rgb_names = d3.map({
1467 aliceblue: "#f0f8ff",
1468 antiquewhite: "#faebd7",
1470 aquamarine: "#7fffd4",
1475 blanchedalmond: "#ffebcd",
1477 blueviolet: "#8a2be2",
1479 burlywood: "#deb887",
1480 cadetblue: "#5f9ea0",
1481 chartreuse: "#7fff00",
1482 chocolate: "#d2691e",
1484 cornflowerblue: "#6495ed",
1485 cornsilk: "#fff8dc",
1488 darkblue: "#00008b",
1489 darkcyan: "#008b8b",
1490 darkgoldenrod: "#b8860b",
1491 darkgray: "#a9a9a9",
1492 darkgreen: "#006400",
1493 darkgrey: "#a9a9a9",
1494 darkkhaki: "#bdb76b",
1495 darkmagenta: "#8b008b",
1496 darkolivegreen: "#556b2f",
1497 darkorange: "#ff8c00",
1498 darkorchid: "#9932cc",
1500 darksalmon: "#e9967a",
1501 darkseagreen: "#8fbc8f",
1502 darkslateblue: "#483d8b",
1503 darkslategray: "#2f4f4f",
1504 darkslategrey: "#2f4f4f",
1505 darkturquoise: "#00ced1",
1506 darkviolet: "#9400d3",
1507 deeppink: "#ff1493",
1508 deepskyblue: "#00bfff",
1511 dodgerblue: "#1e90ff",
1512 firebrick: "#b22222",
1513 floralwhite: "#fffaf0",
1514 forestgreen: "#228b22",
1516 gainsboro: "#dcdcdc",
1517 ghostwhite: "#f8f8ff",
1519 goldenrod: "#daa520",
1522 greenyellow: "#adff2f",
1524 honeydew: "#f0fff0",
1526 indianred: "#cd5c5c",
1530 lavender: "#e6e6fa",
1531 lavenderblush: "#fff0f5",
1532 lawngreen: "#7cfc00",
1533 lemonchiffon: "#fffacd",
1534 lightblue: "#add8e6",
1535 lightcoral: "#f08080",
1536 lightcyan: "#e0ffff",
1537 lightgoldenrodyellow: "#fafad2",
1538 lightgray: "#d3d3d3",
1539 lightgreen: "#90ee90",
1540 lightgrey: "#d3d3d3",
1541 lightpink: "#ffb6c1",
1542 lightsalmon: "#ffa07a",
1543 lightseagreen: "#20b2aa",
1544 lightskyblue: "#87cefa",
1545 lightslategray: "#778899",
1546 lightslategrey: "#778899",
1547 lightsteelblue: "#b0c4de",
1548 lightyellow: "#ffffe0",
1550 limegreen: "#32cd32",
1554 mediumaquamarine: "#66cdaa",
1555 mediumblue: "#0000cd",
1556 mediumorchid: "#ba55d3",
1557 mediumpurple: "#9370db",
1558 mediumseagreen: "#3cb371",
1559 mediumslateblue: "#7b68ee",
1560 mediumspringgreen: "#00fa9a",
1561 mediumturquoise: "#48d1cc",
1562 mediumvioletred: "#c71585",
1563 midnightblue: "#191970",
1564 mintcream: "#f5fffa",
1565 mistyrose: "#ffe4e1",
1566 moccasin: "#ffe4b5",
1567 navajowhite: "#ffdead",
1571 olivedrab: "#6b8e23",
1573 orangered: "#ff4500",
1575 palegoldenrod: "#eee8aa",
1576 palegreen: "#98fb98",
1577 paleturquoise: "#afeeee",
1578 palevioletred: "#db7093",
1579 papayawhip: "#ffefd5",
1580 peachpuff: "#ffdab9",
1584 powderblue: "#b0e0e6",
1587 rosybrown: "#bc8f8f",
1588 royalblue: "#4169e1",
1589 saddlebrown: "#8b4513",
1591 sandybrown: "#f4a460",
1592 seagreen: "#2e8b57",
1593 seashell: "#fff5ee",
1597 slateblue: "#6a5acd",
1598 slategray: "#708090",
1599 slategrey: "#708090",
1601 springgreen: "#00ff7f",
1602 steelblue: "#4682b4",
1607 turquoise: "#40e0d0",
1611 whitesmoke: "#f5f5f5",
1613 yellowgreen: "#9acd32"
1615 d3_rgb_names.forEach(function(key, value) {
1616 d3_rgb_names.set(key, d3_rgb_parse(value, d3_rgb, d3_hsl_rgb));
1618 function d3_functor(v) {
1619 return typeof v === "function" ? v : function() {
1623 d3.functor = d3_functor;
1624 function d3_identity(d) {
1627 d3.xhr = function(url, mimeType, callback) {
1628 var xhr = {}, dispatch = d3.dispatch("progress", "load", "error"), headers = {}, response = d3_identity, request = new (d3_window.XDomainRequest && /^(http(s)?:)?\/\//.test(url) ? XDomainRequest : XMLHttpRequest)();
1629 "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
1630 request.readyState > 3 && respond();
1632 function respond() {
1633 var s = request.status;
1634 !s && request.responseText || s >= 200 && s < 300 || s === 304 ? dispatch.load.call(xhr, response.call(xhr, request)) : dispatch.error.call(xhr, request);
1636 request.onprogress = function(event) {
1640 dispatch.progress.call(xhr, request);
1645 xhr.header = function(name, value) {
1646 name = (name + "").toLowerCase();
1647 if (arguments.length < 2) return headers[name];
1648 if (value == null) delete headers[name]; else headers[name] = value + "";
1651 xhr.mimeType = function(value) {
1652 if (!arguments.length) return mimeType;
1653 mimeType = value == null ? null : value + "";
1656 xhr.response = function(value) {
1660 [ "get", "post" ].forEach(function(method) {
1661 xhr[method] = function() {
1662 return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
1665 xhr.send = function(method, data, callback) {
1666 if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
1667 request.open(method, url, true);
1668 if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
1669 if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
1670 if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
1671 if (callback != null) xhr.on("error", callback).on("load", function(request) {
1672 callback(null, request);
1674 request.send(data == null ? null : data);
1677 xhr.abort = function() {
1681 d3.rebind(xhr, dispatch, "on");
1682 if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
1684 return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
1686 function d3_xhr_fixCallback(callback) {
1687 return callback.length === 1 ? function(error, request) {
1688 callback(error == null ? request : null);
1691 function d3_dsv(delimiter, mimeType) {
1692 var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
1693 function dsv(url, row, callback) {
1694 if (arguments.length < 3) callback = row, row = null;
1695 var xhr = d3.xhr(url, mimeType, callback);
1696 xhr.row = function(_) {
1697 return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
1699 return xhr.row(row);
1701 function response(request) {
1702 return dsv.parse(request.responseText);
1704 function typedResponse(f) {
1705 return function(request) {
1706 return dsv.parse(request.responseText, f);
1709 dsv.parse = function(text, f) {
1711 return dsv.parseRows(text, function(row, i) {
1712 if (o) return o(row, i - 1);
1713 var a = new Function("d", "return {" + row.map(function(name, i) {
1714 return JSON.stringify(name) + ": d[" + i + "]";
1715 }).join(",") + "}");
1716 o = f ? function(row, i) {
1717 return f(a(row), i);
1721 dsv.parseRows = function(text, f) {
1722 var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
1724 if (I >= N) return EOF;
1725 if (eol) return eol = false, EOL;
1727 if (text.charCodeAt(j) === 34) {
1730 if (text.charCodeAt(i) === 34) {
1731 if (text.charCodeAt(i + 1) !== 34) break;
1736 var c = text.charCodeAt(i + 1);
1739 if (text.charCodeAt(i + 2) === 10) ++I;
1740 } else if (c === 10) {
1743 return text.substring(j + 1, i).replace(/""/g, '"');
1746 var c = text.charCodeAt(I++), k = 1;
1747 if (c === 10) eol = true; else if (c === 13) {
1749 if (text.charCodeAt(I) === 10) ++I, ++k;
1750 } else if (c !== delimiterCode) continue;
1751 return text.substring(j, I - k);
1753 return text.substring(j);
1755 while ((t = token()) !== EOF) {
1757 while (t !== EOL && t !== EOF) {
1761 if (f && !(a = f(a, n++))) continue;
1766 dsv.format = function(rows) {
1767 if (Array.isArray(rows[0])) return dsv.formatRows(rows);
1768 var fieldSet = new d3_Set(), fields = [];
1769 rows.forEach(function(row) {
1770 for (var field in row) {
1771 if (!fieldSet.has(field)) {
1772 fields.push(fieldSet.add(field));
1776 return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
1777 return fields.map(function(field) {
1778 return formatValue(row[field]);
1782 dsv.formatRows = function(rows) {
1783 return rows.map(formatRow).join("\n");
1785 function formatRow(row) {
1786 return row.map(formatValue).join(delimiter);
1788 function formatValue(text) {
1789 return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
1793 d3.csv = d3_dsv(",", "text/csv");
1794 d3.tsv = d3_dsv(" ", "text/tab-separated-values");
1795 var d3_timer_id = 0, d3_timer_byId = {}, d3_timer_queue = null, d3_timer_interval, d3_timer_timeout;
1796 d3.timer = function(callback, delay, then) {
1797 if (arguments.length < 3) {
1798 if (arguments.length < 2) delay = 0; else if (!isFinite(delay)) return;
1801 var timer = d3_timer_byId[callback.id];
1802 if (timer && timer.callback === callback) {
1804 timer.delay = delay;
1805 } else d3_timer_byId[callback.id = ++d3_timer_id] = d3_timer_queue = {
1809 next: d3_timer_queue
1811 if (!d3_timer_interval) {
1812 d3_timer_timeout = clearTimeout(d3_timer_timeout);
1813 d3_timer_interval = 1;
1814 d3_timer_frame(d3_timer_step);
1817 function d3_timer_step() {
1818 var elapsed, now = Date.now(), t1 = d3_timer_queue;
1820 elapsed = now - t1.then;
1821 if (elapsed >= t1.delay) t1.flush = t1.callback(elapsed);
1824 var delay = d3_timer_flush() - now;
1826 if (isFinite(delay)) {
1827 clearTimeout(d3_timer_timeout);
1828 d3_timer_timeout = setTimeout(d3_timer_step, delay);
1830 d3_timer_interval = 0;
1832 d3_timer_interval = 1;
1833 d3_timer_frame(d3_timer_step);
1836 d3.timer.flush = function() {
1837 var elapsed, now = Date.now(), t1 = d3_timer_queue;
1839 elapsed = now - t1.then;
1840 if (!t1.delay) t1.flush = t1.callback(elapsed);
1845 function d3_timer_flush() {
1846 var t0 = null, t1 = d3_timer_queue, then = Infinity;
1849 delete d3_timer_byId[t1.callback.id];
1850 t1 = t0 ? t0.next = t1.next : d3_timer_queue = t1.next;
1852 then = Math.min(then, t1.then + t1.delay);
1853 t1 = (t0 = t1).next;
1858 var d3_timer_frame = d3_window.requestAnimationFrame || d3_window.webkitRequestAnimationFrame || d3_window.mozRequestAnimationFrame || d3_window.oRequestAnimationFrame || d3_window.msRequestAnimationFrame || function(callback) {
1859 setTimeout(callback, 17);
1861 var d3_format_decimalPoint = ".", d3_format_thousandsSeparator = ",", d3_format_grouping = [ 3, 3 ];
1862 var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
1863 d3.formatPrefix = function(value, precision) {
1866 if (value < 0) value *= -1;
1867 if (precision) value = d3.round(value, d3_format_precision(value, precision));
1868 i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
1869 i = Math.max(-24, Math.min(24, Math.floor((i <= 0 ? i + 1 : i - 1) / 3) * 3));
1871 return d3_formatPrefixes[8 + i / 3];
1873 function d3_formatPrefix(d, i) {
1874 var k = Math.pow(10, Math.abs(8 - i) * 3);
1876 scale: i > 8 ? function(d) {
1884 d3.round = function(x, n) {
1885 return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
1887 d3.format = function(specifier) {
1888 var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "", basePrefix = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, suffix = "", integer = false;
1889 if (precision) precision = +precision.substring(1);
1890 if (zfill || fill === "0" && align === "=") {
1893 if (comma) width -= Math.floor((width - 1) / 4);
1917 if (basePrefix) basePrefix = "0" + type.toLowerCase();
1930 if (basePrefix === "#") basePrefix = "";
1931 if (type == "r" && !precision) type = "g";
1932 if (precision != null) {
1933 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));
1935 type = d3_format_types.get(type) || d3_format_typeDefault;
1936 var zcomma = zfill && comma;
1937 return function(value) {
1938 if (integer && value % 1) return "";
1939 var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign;
1941 var prefix = d3.formatPrefix(value, precision);
1942 value = prefix.scale(value);
1943 suffix = prefix.symbol;
1947 value = type(value, precision);
1948 if (!zfill && comma) value = d3_format_group(value);
1949 var length = basePrefix.length + value.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
1950 if (zcomma) value = d3_format_group(padding + value);
1951 if (d3_format_decimalPoint) value.replace(".", d3_format_decimalPoint);
1952 negative += basePrefix;
1953 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)) + suffix;
1956 var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
1957 var d3_format_types = d3.map({
1959 return x.toString(2);
1962 return String.fromCharCode(x);
1965 return x.toString(8);
1968 return x.toString(16);
1971 return x.toString(16).toUpperCase();
1974 return x.toPrecision(p);
1977 return x.toExponential(p);
1980 return x.toFixed(p);
1983 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))));
1986 function d3_format_precision(x, p) {
1987 return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
1989 function d3_format_typeDefault(x) {
1992 var d3_format_group = d3_identity;
1993 if (d3_format_grouping) {
1994 var d3_format_groupingLength = d3_format_grouping.length;
1995 d3_format_group = function(value) {
1996 var i = value.lastIndexOf("."), f = i >= 0 ? "." + value.substring(i + 1) : (i = value.length,
1997 ""), t = [], j = 0, g = d3_format_grouping[0];
1998 while (i > 0 && g > 0) {
1999 t.push(value.substring(i -= g, i + g));
2000 g = d3_format_grouping[j = (j + 1) % d3_format_groupingLength];
2002 return t.reverse().join(d3_format_thousandsSeparator || "") + f;
2006 d3.geo.stream = function(object, listener) {
2007 if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
2008 d3_geo_streamObjectType[object.type](object, listener);
2010 d3_geo_streamGeometry(object, listener);
2013 function d3_geo_streamGeometry(geometry, listener) {
2014 if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
2015 d3_geo_streamGeometryType[geometry.type](geometry, listener);
2018 var d3_geo_streamObjectType = {
2019 Feature: function(feature, listener) {
2020 d3_geo_streamGeometry(feature.geometry, listener);
2022 FeatureCollection: function(object, listener) {
2023 var features = object.features, i = -1, n = features.length;
2024 while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
2027 var d3_geo_streamGeometryType = {
2028 Sphere: function(object, listener) {
2031 Point: function(object, listener) {
2032 var coordinate = object.coordinates;
2033 listener.point(coordinate[0], coordinate[1]);
2035 MultiPoint: function(object, listener) {
2036 var coordinates = object.coordinates, i = -1, n = coordinates.length, coordinate;
2037 while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1]);
2039 LineString: function(object, listener) {
2040 d3_geo_streamLine(object.coordinates, listener, 0);
2042 MultiLineString: function(object, listener) {
2043 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2044 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
2046 Polygon: function(object, listener) {
2047 d3_geo_streamPolygon(object.coordinates, listener);
2049 MultiPolygon: function(object, listener) {
2050 var coordinates = object.coordinates, i = -1, n = coordinates.length;
2051 while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
2053 GeometryCollection: function(object, listener) {
2054 var geometries = object.geometries, i = -1, n = geometries.length;
2055 while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
2058 function d3_geo_streamLine(coordinates, listener, closed) {
2059 var i = -1, n = coordinates.length - closed, coordinate;
2060 listener.lineStart();
2061 while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1]);
2064 function d3_geo_streamPolygon(coordinates, listener) {
2065 var i = -1, n = coordinates.length;
2066 listener.polygonStart();
2067 while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
2068 listener.polygonEnd();
2070 d3.geo.area = function(object) {
2072 d3.geo.stream(object, d3_geo_area);
2073 return d3_geo_areaSum;
2075 var d3_geo_areaSum, d3_geo_areaRingU, d3_geo_areaRingV;
2077 sphere: function() {
2078 d3_geo_areaSum += 4 * π;
2083 polygonStart: function() {
2084 d3_geo_areaRingU = 1, d3_geo_areaRingV = 0;
2085 d3_geo_area.lineStart = d3_geo_areaRingStart;
2087 polygonEnd: function() {
2088 var area = 2 * Math.atan2(d3_geo_areaRingV, d3_geo_areaRingU);
2089 d3_geo_areaSum += area < 0 ? 4 * π + area : area;
2090 d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
2093 function d3_geo_areaRingStart() {
2094 var λ00, φ00, λ0, cosφ0, sinφ0;
2095 d3_geo_area.point = function(λ, φ) {
2096 d3_geo_area.point = nextPoint;
2097 λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
2098 sinφ0 = Math.sin(φ);
2100 function nextPoint(λ, φ) {
2102 φ = φ * d3_radians / 2 + π / 4;
2103 var dλ = λ - λ0, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u0 = d3_geo_areaRingU, v0 = d3_geo_areaRingV, u = cosφ0 * cosφ + k * Math.cos(dλ), v = k * Math.sin(dλ);
2104 d3_geo_areaRingU = u0 * u - v0 * v;
2105 d3_geo_areaRingV = v0 * u + u0 * v;
2106 λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
2108 d3_geo_area.lineEnd = function() {
2109 nextPoint(λ00, φ00);
2112 d3.geo.bounds = d3_geo_bounds(d3_identity);
2113 function d3_geo_bounds(projectStream) {
2119 polygonStart: function() {
2120 bound.lineEnd = boundPolygonLineEnd;
2122 polygonEnd: function() {
2123 bound.point = boundPoint;
2126 function boundPoint(x, y) {
2132 function boundPolygonLineEnd() {
2133 bound.point = bound.lineEnd = d3_noop;
2135 return function(feature) {
2136 y1 = x1 = -(x0 = y0 = Infinity);
2137 d3.geo.stream(feature, projectStream(bound));
2138 return [ [ x0, y0 ], [ x1, y1 ] ];
2141 d3.geo.centroid = function(object) {
2142 d3_geo_centroidDimension = d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
2143 d3.geo.stream(object, d3_geo_centroid);
2145 if (d3_geo_centroidW && Math.abs(m = Math.sqrt(d3_geo_centroidX * d3_geo_centroidX + d3_geo_centroidY * d3_geo_centroidY + d3_geo_centroidZ * d3_geo_centroidZ)) > ε) {
2146 return [ Math.atan2(d3_geo_centroidY, d3_geo_centroidX) * d3_degrees, Math.asin(Math.max(-1, Math.min(1, d3_geo_centroidZ / m))) * d3_degrees ];
2149 var d3_geo_centroidDimension, d3_geo_centroidW, d3_geo_centroidX, d3_geo_centroidY, d3_geo_centroidZ;
2150 var d3_geo_centroid = {
2151 sphere: function() {
2152 if (d3_geo_centroidDimension < 2) {
2153 d3_geo_centroidDimension = 2;
2154 d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
2157 point: d3_geo_centroidPoint,
2158 lineStart: d3_geo_centroidLineStart,
2159 lineEnd: d3_geo_centroidLineEnd,
2160 polygonStart: function() {
2161 if (d3_geo_centroidDimension < 2) {
2162 d3_geo_centroidDimension = 2;
2163 d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
2165 d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
2167 polygonEnd: function() {
2168 d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
2171 function d3_geo_centroidPoint(λ, φ) {
2172 if (d3_geo_centroidDimension) return;
2175 var cosφ = Math.cos(φ *= d3_radians);
2176 d3_geo_centroidX += (cosφ * Math.cos(λ) - d3_geo_centroidX) / d3_geo_centroidW;
2177 d3_geo_centroidY += (cosφ * Math.sin(λ) - d3_geo_centroidY) / d3_geo_centroidW;
2178 d3_geo_centroidZ += (Math.sin(φ) - d3_geo_centroidZ) / d3_geo_centroidW;
2180 function d3_geo_centroidRingStart() {
2182 d3_geo_centroidDimension = 1;
2183 d3_geo_centroidLineStart();
2184 d3_geo_centroidDimension = 2;
2185 var linePoint = d3_geo_centroid.point;
2186 d3_geo_centroid.point = function(λ, φ) {
2187 linePoint(λ00 = λ, φ00 = φ);
2189 d3_geo_centroid.lineEnd = function() {
2190 d3_geo_centroid.point(λ00, φ00);
2191 d3_geo_centroidLineEnd();
2192 d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
2195 function d3_geo_centroidLineStart() {
2197 if (d3_geo_centroidDimension > 1) return;
2198 if (d3_geo_centroidDimension < 1) {
2199 d3_geo_centroidDimension = 1;
2200 d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
2202 d3_geo_centroid.point = function(λ, φ) {
2204 var cosφ = Math.cos(φ *= d3_radians);
2205 x0 = cosφ * Math.cos(λ);
2206 y0 = cosφ * Math.sin(λ);
2208 d3_geo_centroid.point = nextPoint;
2210 function nextPoint(λ, φ) {
2212 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);
2213 d3_geo_centroidW += w;
2214 d3_geo_centroidX += w * (x0 + (x0 = x));
2215 d3_geo_centroidY += w * (y0 + (y0 = y));
2216 d3_geo_centroidZ += w * (z0 + (z0 = z));
2219 function d3_geo_centroidLineEnd() {
2220 d3_geo_centroid.point = d3_geo_centroidPoint;
2222 function d3_geo_cartesian(spherical) {
2223 var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
2224 return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
2226 function d3_geo_cartesianDot(a, b) {
2227 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
2229 function d3_geo_cartesianCross(a, b) {
2230 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] ];
2232 function d3_geo_cartesianAdd(a, b) {
2237 function d3_geo_cartesianScale(vector, k) {
2238 return [ vector[0] * k, vector[1] * k, vector[2] * k ];
2240 function d3_geo_cartesianNormalize(d) {
2241 var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
2246 function d3_true() {
2249 function d3_geo_spherical(cartesian) {
2250 return [ Math.atan2(cartesian[1], cartesian[0]), Math.asin(Math.max(-1, Math.min(1, cartesian[2]))) ];
2252 function d3_geo_sphericalEqual(a, b) {
2253 return Math.abs(a[0] - b[0]) < ε && Math.abs(a[1] - b[1]) < ε;
2255 function d3_geo_clipPolygon(segments, compare, inside, interpolate, listener) {
2256 var subject = [], clip = [];
2257 segments.forEach(function(segment) {
2258 if ((n = segment.length - 1) <= 0) return;
2259 var n, p0 = segment[0], p1 = segment[n];
2260 if (d3_geo_sphericalEqual(p0, p1)) {
2261 listener.lineStart();
2262 for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
2305 d3_geo_clipPolygonLinkCircular(subject);
2306 d3_geo_clipPolygonLinkCircular(clip);
2307 if (!subject.length) return;
2308 if (inside) for (var i = 1, e = !inside(clip[0].point), n = clip.length; i < n; ++i) {
2309 clip[i].entry = e = !e;
2311 var start = subject[0], current, points, point;
2314 while (current.visited) if ((current = current.next) === start) return;
2315 points = current.points;
2316 listener.lineStart();
2318 current.visited = current.other.visited = true;
2319 if (current.entry) {
2320 if (current.subject) {
2321 for (var i = 0; i < points.length; i++) listener.point((point = points[i])[0], point[1]);
2323 interpolate(current.point, current.next.point, 1, listener);
2325 current = current.next;
2327 if (current.subject) {
2328 points = current.prev.points;
2329 for (var i = points.length; --i >= 0; ) listener.point((point = points[i])[0], point[1]);
2331 interpolate(current.point, current.prev.point, -1, listener);
2333 current = current.prev;
2335 current = current.other;
2336 points = current.points;
2337 } while (!current.visited);
2341 function d3_geo_clipPolygonLinkCircular(array) {
2342 if (!(n = array.length)) return;
2343 var n, i = 0, a = array[0], b;
2345 a.next = b = array[i];
2349 a.next = b = array[0];
2352 function d3_geo_clip(pointVisible, clipLine, interpolate) {
2353 return function(listener) {
2354 var line = clipLine(listener);
2357 lineStart: lineStart,
2359 polygonStart: function() {
2360 clip.point = pointRing;
2361 clip.lineStart = ringStart;
2362 clip.lineEnd = ringEnd;
2364 invisibleArea = visibleArea = 0;
2366 listener.polygonStart();
2368 polygonEnd: function() {
2370 clip.lineStart = lineStart;
2371 clip.lineEnd = lineEnd;
2372 segments = d3.merge(segments);
2373 if (segments.length) {
2374 d3_geo_clipPolygon(segments, d3_geo_clipSort, null, interpolate, listener);
2375 } else if (visibleArea < -ε || invisible && invisibleArea < -ε) {
2376 listener.lineStart();
2377 interpolate(null, null, 1, listener);
2380 listener.polygonEnd();
2383 sphere: function() {
2384 listener.polygonStart();
2385 listener.lineStart();
2386 interpolate(null, null, 1, listener);
2388 listener.polygonEnd();
2391 function point(λ, φ) {
2392 if (pointVisible(λ, φ)) listener.point(λ, φ);
2394 function pointLine(λ, φ) {
2397 function lineStart() {
2398 clip.point = pointLine;
2401 function lineEnd() {
2405 var segments, visibleArea, invisibleArea, invisible;
2406 var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), ring;
2407 function pointRing(λ, φ) {
2408 ringListener.point(λ, φ);
2409 ring.push([ λ, φ ]);
2411 function ringStart() {
2412 ringListener.lineStart();
2415 function ringEnd() {
2416 pointRing(ring[0][0], ring[0][1]);
2417 ringListener.lineEnd();
2418 var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
2421 invisibleArea += d3_geo_clipAreaRing(ring, -1);
2427 segment = ringSegments[0];
2428 visibleArea += d3_geo_clipAreaRing(segment, 1);
2429 var n = segment.length - 1, i = -1, point;
2430 listener.lineStart();
2431 while (++i < n) listener.point((point = segment[i])[0], point[1]);
2435 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
2436 segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
2441 function d3_geo_clipSegmentLength1(segment) {
2442 return segment.length > 1;
2444 function d3_geo_clipBufferListener() {
2445 var lines = [], line;
2447 lineStart: function() {
2448 lines.push(line = []);
2450 point: function(λ, φ) {
2451 line.push([ λ, φ ]);
2454 buffer: function() {
2460 rejoin: function() {
2461 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
2465 function d3_geo_clipAreaRing(ring, invisible) {
2466 if (!(n = ring.length)) return 0;
2467 var n, i = 0, area = 0, p = ring[0], λ = p[0], φ = p[1], cosφ = Math.cos(φ), x0 = Math.atan2(invisible * Math.sin(λ) * cosφ, Math.sin(φ)), y0 = 1 - invisible * Math.cos(λ) * cosφ, x1 = x0, x, y;
2470 cosφ = Math.cos(φ = p[1]);
2471 x = Math.atan2(invisible * Math.sin(λ = p[0]) * cosφ, Math.sin(φ));
2472 y = 1 - invisible * Math.cos(λ) * cosφ;
2473 if (Math.abs(y0 - 2) < ε && Math.abs(y - 2) < ε) continue;
2474 if (Math.abs(y) < ε || Math.abs(y0) < ε) {} else if (Math.abs(Math.abs(x - x0) - π) < ε) {
2475 if (y + y0 > 2) area += 4 * (x - x0);
2476 } else if (Math.abs(y0 - 2) < ε) area += 4 * (x - x1); else area += ((3 * π + x - x0) % (2 * π) - π) * (y0 + y);
2477 x1 = x0, x0 = x, y0 = y;
2481 function d3_geo_clipSort(a, b) {
2482 return ((a = a.point)[0] < 0 ? a[1] - π / 2 - ε : π / 2 - a[1]) - ((b = b.point)[0] < 0 ? b[1] - π / 2 - ε : π / 2 - b[1]);
2484 var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate);
2485 function d3_geo_clipAntimeridianLine(listener) {
2486 var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
2488 lineStart: function() {
2489 listener.lineStart();
2492 point: function(λ1, φ1) {
2493 var sλ1 = λ1 > 0 ? π : -π, dλ = Math.abs(λ1 - λ0);
2494 if (Math.abs(dλ - π) < ε) {
2495 listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? π / 2 : -π / 2);
2496 listener.point(sλ0, φ0);
2498 listener.lineStart();
2499 listener.point(sλ1, φ0);
2500 listener.point(λ1, φ0);
2502 } else if (sλ0 !== sλ1 && dλ >= π) {
2503 if (Math.abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
2504 if (Math.abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
2505 φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
2506 listener.point(sλ0, φ0);
2508 listener.lineStart();
2509 listener.point(sλ1, φ0);
2512 listener.point(λ0 = λ1, φ0 = φ1);
2515 lineEnd: function() {
2524 function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
2525 var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
2526 return Math.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;
2528 function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
2531 φ = direction * π / 2;
2532 listener.point(-π, φ);
2533 listener.point(0, φ);
2534 listener.point(π, φ);
2535 listener.point(π, 0);
2536 listener.point(π, -φ);
2537 listener.point(0, -φ);
2538 listener.point(-π, -φ);
2539 listener.point(-π, 0);
2540 listener.point(-π, φ);
2541 } else if (Math.abs(from[0] - to[0]) > ε) {
2542 var s = (from[0] < to[0] ? 1 : -1) * π;
2543 φ = direction * s / 2;
2544 listener.point(-s, φ);
2545 listener.point(0, φ);
2546 listener.point(s, φ);
2548 listener.point(to[0], to[1]);
2551 function d3_geo_clipCircle(radius) {
2552 var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = Math.abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
2553 return d3_geo_clip(visible, clipLine, interpolate);
2554 function visible(λ, φ) {
2555 return Math.cos(λ) * Math.cos(φ) > cr;
2557 function clipLine(listener) {
2558 var point0, c0, v0, v00, clean;
2560 lineStart: function() {
2564 point: function(λ, φ) {
2565 var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
2566 if (!point0 && (v00 = v0 = v)) listener.lineStart();
2568 point2 = intersect(point0, point1);
2569 if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
2572 v = visible(point1[0], point1[1]);
2578 listener.lineStart();
2579 point2 = intersect(point1, point0);
2580 listener.point(point2[0], point2[1]);
2582 point2 = intersect(point0, point1);
2583 listener.point(point2[0], point2[1]);
2587 } else if (notHemisphere && point0 && smallRadius ^ v) {
2589 if (!(c & c0) && (t = intersect(point1, point0, true))) {
2592 listener.lineStart();
2593 listener.point(t[0][0], t[0][1]);
2594 listener.point(t[1][0], t[1][1]);
2597 listener.point(t[1][0], t[1][1]);
2599 listener.lineStart();
2600 listener.point(t[0][0], t[0][1]);
2604 if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
2605 listener.point(point1[0], point1[1]);
2607 point0 = point1, v0 = v, c0 = c;
2609 lineEnd: function() {
2610 if (v0) listener.lineEnd();
2614 return clean | (v00 && v0) << 1;
2618 function intersect(a, b, two) {
2619 var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
2620 var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
2621 if (!determinant) return !two && a;
2622 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);
2623 d3_geo_cartesianAdd(A, B);
2624 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);
2626 var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
2627 d3_geo_cartesianAdd(q, A);
2628 q = d3_geo_spherical(q);
2630 var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
2631 if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
2632 var δλ = λ1 - λ0, polar = Math.abs(δλ - π) < ε, meridian = polar || δλ < ε;
2633 if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
2634 if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (Math.abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
2635 var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
2636 d3_geo_cartesianAdd(q1, A);
2637 return [ q, d3_geo_spherical(q1) ];
2640 function code(λ, φ) {
2641 var r = smallRadius ? radius : π - radius, code = 0;
2642 if (λ < -r) code |= 1; else if (λ > r) code |= 2;
2643 if (φ < -r) code |= 4; else if (φ > r) code |= 8;
2647 var d3_geo_clipViewMAX = 1e9;
2648 function d3_geo_clipView(x0, y0, x1, y1) {
2649 return function(listener) {
2650 var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), segments, polygon, ring;
2653 lineStart: lineStart,
2655 polygonStart: function() {
2656 listener = bufferListener;
2660 polygonEnd: function() {
2661 listener = listener_;
2662 if ((segments = d3.merge(segments)).length) {
2663 listener.polygonStart();
2664 d3_geo_clipPolygon(segments, compare, inside, interpolate, listener);
2665 listener.polygonEnd();
2666 } else if (insidePolygon([ x0, y0 ])) {
2667 listener.polygonStart(), listener.lineStart();
2668 interpolate(null, null, 1, listener);
2669 listener.lineEnd(), listener.polygonEnd();
2671 segments = polygon = ring = null;
2674 function inside(point) {
2675 var a = corner(point, -1), i = insidePolygon([ a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0 ]);
2678 function insidePolygon(p) {
2679 var wn = 0, n = polygon.length, y = p[1];
2680 for (var i = 0; i < n; ++i) {
2681 for (var j = 1, v = polygon[i], m = v.length, a = v[0]; j < m; ++j) {
2684 if (b[1] > y && isLeft(a, b, p) > 0) ++wn;
2686 if (b[1] <= y && isLeft(a, b, p) < 0) --wn;
2693 function isLeft(a, b, c) {
2694 return (b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1]);
2696 function interpolate(from, to, direction, listener) {
2698 if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
2700 listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
2701 } while ((a = (a + direction + 4) % 4) !== a1);
2703 listener.point(to[0], to[1]);
2706 function visible(x, y) {
2707 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
2709 function point(x, y) {
2710 if (visible(x, y)) listener.point(x, y);
2712 var x__, y__, v__, x_, y_, v_, first;
2713 function lineStart() {
2714 clip.point = linePoint;
2715 if (polygon) polygon.push(ring = []);
2720 function lineEnd() {
2722 linePoint(x__, y__);
2723 if (v__ && v_) bufferListener.rejoin();
2724 segments.push(bufferListener.buffer());
2727 if (v_) listener.lineEnd();
2729 function linePoint(x, y) {
2730 x = Math.max(-d3_geo_clipViewMAX, Math.min(d3_geo_clipViewMAX, x));
2731 y = Math.max(-d3_geo_clipViewMAX, Math.min(d3_geo_clipViewMAX, y));
2732 var v = visible(x, y);
2733 if (polygon) ring.push([ x, y ]);
2735 x__ = x, y__ = y, v__ = v;
2738 listener.lineStart();
2739 listener.point(x, y);
2742 if (v && v_) listener.point(x, y); else {
2743 var a = [ x_, y_ ], b = [ x, y ];
2744 if (clipLine(a, b)) {
2746 listener.lineStart();
2747 listener.point(a[0], a[1]);
2749 listener.point(b[0], b[1]);
2750 if (!v) listener.lineEnd();
2752 listener.lineStart();
2753 listener.point(x, y);
2757 x_ = x, y_ = y, v_ = v;
2761 function corner(p, direction) {
2762 return Math.abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : Math.abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : Math.abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;
2764 function compare(a, b) {
2765 return comparePoints(a.point, b.point);
2767 function comparePoints(a, b) {
2768 var ca = corner(a, 1), cb = corner(b, 1);
2769 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];
2771 function clipLine(a, b) {
2772 var dx = b[0] - a[0], dy = b[1] - a[1], t = [ 0, 1 ];
2773 if (Math.abs(dx) < ε && Math.abs(dy) < ε) return x0 <= a[0] && a[0] <= x1 && y0 <= a[1] && a[1] <= y1;
2774 if (d3_geo_clipViewT(x0 - a[0], dx, t) && d3_geo_clipViewT(a[0] - x1, -dx, t) && d3_geo_clipViewT(y0 - a[1], dy, t) && d3_geo_clipViewT(a[1] - y1, -dy, t)) {
2776 b[0] = a[0] + t[1] * dx;
2777 b[1] = a[1] + t[1] * dy;
2788 function d3_geo_clipViewT(num, denominator, t) {
2789 if (Math.abs(denominator) < ε) return num <= 0;
2790 var u = num / denominator;
2791 if (denominator > 0) {
2792 if (u > t[1]) return false;
2793 if (u > t[0]) t[0] = u;
2795 if (u < t[0]) return false;
2796 if (u < t[1]) t[1] = u;
2800 function d3_geo_compose(a, b) {
2801 function compose(x, y) {
2802 return x = a(x, y), b(x[0], x[1]);
2804 if (a.invert && b.invert) compose.invert = function(x, y) {
2805 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
2809 function d3_geo_resample(project) {
2810 var δ2 = .5, maxDepth = 16;
2811 function resample(stream) {
2812 var λ0, x0, y0, a0, b0, c0;
2815 lineStart: lineStart,
2817 polygonStart: function() {
2818 stream.polygonStart();
2819 resample.lineStart = polygonLineStart;
2821 polygonEnd: function() {
2822 stream.polygonEnd();
2823 resample.lineStart = lineStart;
2826 function point(x, y) {
2828 stream.point(x[0], x[1]);
2830 function lineStart() {
2832 resample.point = linePoint;
2835 function linePoint(λ, φ) {
2836 var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
2837 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);
2838 stream.point(x0, y0);
2840 function lineEnd() {
2841 resample.point = point;
2844 function polygonLineStart() {
2845 var λ00, φ00, x00, y00, a00, b00, c00;
2847 resample.point = function(λ, φ) {
2848 linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
2849 resample.point = linePoint;
2851 resample.lineEnd = function() {
2852 resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
2853 resample.lineEnd = lineEnd;
2859 function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
2860 var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
2861 if (d2 > 4 * δ2 && depth--) {
2862 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 = Math.abs(Math.abs(c) - 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;
2863 if (dz * dz / d2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / d2 - .5) > .3) {
2864 resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
2865 stream.point(x2, y2);
2866 resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
2870 resample.precision = function(_) {
2871 if (!arguments.length) return Math.sqrt(δ2);
2872 maxDepth = (δ2 = _ * _) > 0 && 16;
2877 d3.geo.projection = d3_geo_projection;
2878 d3.geo.projectionMutator = d3_geo_projectionMutator;
2879 function d3_geo_projection(project) {
2880 return d3_geo_projectionMutator(function() {
2884 function d3_geo_projectionMutator(projectAt) {
2885 var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
2887 return [ x[0] * k + δx, δy - x[1] * k ];
2888 }), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, preclip = d3_geo_clipAntimeridian, postclip = d3_identity, clipAngle = null, clipExtent = null;
2889 function projection(point) {
2890 point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
2891 return [ point[0] * k + δx, δy - point[1] * k ];
2893 function invert(point) {
2894 point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
2895 return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
2897 projection.stream = function(stream) {
2898 return d3_geo_projectionRadiansRotate(rotate, preclip(projectResample(postclip(stream))));
2900 projection.clipAngle = function(_) {
2901 if (!arguments.length) return clipAngle;
2902 preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
2905 projection.clipExtent = function(_) {
2906 if (!arguments.length) return clipExtent;
2908 postclip = _ == null ? d3_identity : d3_geo_clipView(_[0][0], _[0][1], _[1][0], _[1][1]);
2911 projection.scale = function(_) {
2912 if (!arguments.length) return k;
2916 projection.translate = function(_) {
2917 if (!arguments.length) return [ x, y ];
2922 projection.center = function(_) {
2923 if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
2924 λ = _[0] % 360 * d3_radians;
2925 φ = _[1] % 360 * d3_radians;
2928 projection.rotate = function(_) {
2929 if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
2930 δλ = _[0] % 360 * d3_radians;
2931 δφ = _[1] % 360 * d3_radians;
2932 δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
2935 d3.rebind(projection, projectResample, "precision");
2937 projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
2938 var center = project(λ, φ);
2939 δx = x - center[0] * k;
2940 δy = y + center[1] * k;
2944 project = projectAt.apply(this, arguments);
2945 projection.invert = project.invert && invert;
2949 function d3_geo_projectionRadiansRotate(rotate, stream) {
2951 point: function(x, y) {
2952 y = rotate(x * d3_radians, y * d3_radians), x = y[0];
2953 stream.point(x > π ? x - 2 * π : x < -π ? x + 2 * π : x, y[1]);
2955 sphere: function() {
2958 lineStart: function() {
2961 lineEnd: function() {
2964 polygonStart: function() {
2965 stream.polygonStart();
2967 polygonEnd: function() {
2968 stream.polygonEnd();
2972 function d3_geo_equirectangular(λ, φ) {
2975 (d3.geo.equirectangular = function() {
2976 return d3_geo_projection(d3_geo_equirectangular);
2977 }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
2978 d3.geo.rotation = function(rotate) {
2979 rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
2980 function forward(coordinates) {
2981 coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
2982 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
2984 forward.invert = function(coordinates) {
2985 coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
2986 return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
2990 function d3_geo_rotation(δλ, δφ, δγ) {
2991 return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_equirectangular;
2993 function d3_geo_forwardRotationλ(δλ) {
2994 return function(λ, φ) {
2995 return λ += δλ, [ λ > π ? λ - 2 * π : λ < -π ? λ + 2 * π : λ, φ ];
2998 function d3_geo_rotationλ(δλ) {
2999 var rotation = d3_geo_forwardRotationλ(δλ);
3000 rotation.invert = d3_geo_forwardRotationλ(-δλ);
3003 function d3_geo_rotationφγ(δφ, δγ) {
3004 var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
3005 function rotation(λ, φ) {
3006 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
3007 return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), Math.asin(Math.max(-1, Math.min(1, k * cosδγ + y * sinδγ))) ];
3009 rotation.invert = function(λ, φ) {
3010 var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
3011 return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), Math.asin(Math.max(-1, Math.min(1, k * cosδφ - x * sinδφ))) ];
3015 d3.geo.circle = function() {
3016 var origin = [ 0, 0 ], angle, precision = 6, interpolate;
3018 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 = [];
3019 interpolate(null, null, 1, {
3020 point: function(x, y) {
3021 ring.push(x = rotate(x, y));
3022 x[0] *= d3_degrees, x[1] *= d3_degrees;
3027 coordinates: [ ring ]
3030 circle.origin = function(x) {
3031 if (!arguments.length) return origin;
3035 circle.angle = function(x) {
3036 if (!arguments.length) return angle;
3037 interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
3040 circle.precision = function(_) {
3041 if (!arguments.length) return precision;
3042 interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
3045 return circle.angle(90);
3047 function d3_geo_circleInterpolate(radius, precision) {
3048 var cr = Math.cos(radius), sr = Math.sin(radius);
3049 return function(from, to, direction, listener) {
3051 from = d3_geo_circleAngle(cr, from);
3052 to = d3_geo_circleAngle(cr, to);
3053 if (direction > 0 ? from < to : from > to) from += direction * 2 * π;
3055 from = radius + direction * 2 * π;
3059 for (var step = direction * precision, t = from; direction > 0 ? t > to : t < to; t -= step) {
3060 listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
3064 function d3_geo_circleAngle(cr, point) {
3065 var a = d3_geo_cartesian(point);
3067 d3_geo_cartesianNormalize(a);
3068 var angle = d3_acos(-a[1]);
3069 return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
3071 d3.geo.distance = function(a, b) {
3072 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;
3073 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Δλ);
3075 d3.geo.graticule = function() {
3076 var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
3077 function graticule() {
3079 type: "MultiLineString",
3080 coordinates: lines()
3084 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) {
3085 return Math.abs(x % DX) > ε;
3086 }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
3087 return Math.abs(y % DY) > ε;
3090 graticule.lines = function() {
3091 return lines().map(function(coordinates) {
3094 coordinates: coordinates
3098 graticule.outline = function() {
3101 coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
3104 graticule.extent = function(_) {
3105 if (!arguments.length) return graticule.minorExtent();
3106 return graticule.majorExtent(_).minorExtent(_);
3108 graticule.majorExtent = function(_) {
3109 if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
3110 X0 = +_[0][0], X1 = +_[1][0];
3111 Y0 = +_[0][1], Y1 = +_[1][1];
3112 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
3113 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
3114 return graticule.precision(precision);
3116 graticule.minorExtent = function(_) {
3117 if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
3118 x0 = +_[0][0], x1 = +_[1][0];
3119 y0 = +_[0][1], y1 = +_[1][1];
3120 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
3121 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
3122 return graticule.precision(precision);
3124 graticule.step = function(_) {
3125 if (!arguments.length) return graticule.minorStep();
3126 return graticule.majorStep(_).minorStep(_);
3128 graticule.majorStep = function(_) {
3129 if (!arguments.length) return [ DX, DY ];
3130 DX = +_[0], DY = +_[1];
3133 graticule.minorStep = function(_) {
3134 if (!arguments.length) return [ dx, dy ];
3135 dx = +_[0], dy = +_[1];
3138 graticule.precision = function(_) {
3139 if (!arguments.length) return precision;
3141 x = d3_geo_graticuleX(y0, y1, 90);
3142 y = d3_geo_graticuleY(x0, x1, precision);
3143 X = d3_geo_graticuleX(Y0, Y1, 90);
3144 Y = d3_geo_graticuleY(X0, X1, precision);
3147 return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
3149 function d3_geo_graticuleX(y0, y1, dy) {
3150 var y = d3.range(y0, y1 - ε, dy).concat(y1);
3151 return function(x) {
3152 return y.map(function(y) {
3157 function d3_geo_graticuleY(x0, x1, dx) {
3158 var x = d3.range(x0, x1 - ε, dx).concat(x1);
3159 return function(y) {
3160 return x.map(function(x) {
3165 function d3_source(d) {
3168 function d3_target(d) {
3171 d3.geo.greatArc = function() {
3172 var source = d3_source, source_, target = d3_target, target_;
3173 function greatArc() {
3176 coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
3179 greatArc.distance = function() {
3180 return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
3182 greatArc.source = function(_) {
3183 if (!arguments.length) return source;
3184 source = _, source_ = typeof _ === "function" ? null : _;
3187 greatArc.target = function(_) {
3188 if (!arguments.length) return target;
3189 target = _, target_ = typeof _ === "function" ? null : _;
3192 greatArc.precision = function() {
3193 return arguments.length ? greatArc : 0;
3197 d3.geo.interpolate = function(source, target) {
3198 return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
3200 function d3_geo_interpolate(x0, y0, x1, y1) {
3201 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);
3202 var interpolate = d ? function(t) {
3203 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;
3204 return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
3206 return [ x0 * d3_degrees, y0 * d3_degrees ];
3208 interpolate.distance = d;
3211 d3.geo.length = function(object) {
3212 d3_geo_lengthSum = 0;
3213 d3.geo.stream(object, d3_geo_length);
3214 return d3_geo_lengthSum;
3216 var d3_geo_lengthSum;
3217 var d3_geo_length = {
3220 lineStart: d3_geo_lengthLineStart,
3222 polygonStart: d3_noop,
3225 function d3_geo_lengthLineStart() {
3226 var λ0, sinφ0, cosφ0;
3227 d3_geo_length.point = function(λ, φ) {
3228 λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
3229 d3_geo_length.point = nextPoint;
3231 d3_geo_length.lineEnd = function() {
3232 d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
3234 function nextPoint(λ, φ) {
3235 var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = Math.abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
3236 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Δλ);
3237 λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
3240 function d3_geo_conic(projectAt) {
3241 var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
3242 p.parallels = function(_) {
3243 if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
3244 return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
3248 function d3_geo_conicEqualArea(φ0, φ1) {
3249 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;
3250 function forward(λ, φ) {
3251 var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
3252 return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
3254 forward.invert = function(x, y) {
3256 return [ Math.atan2(x, ρ0_y) / n, Math.asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
3260 (d3.geo.conicEqualArea = function() {
3261 return d3_geo_conic(d3_geo_conicEqualArea);
3262 }).raw = d3_geo_conicEqualArea;
3263 d3.geo.albersUsa = function() {
3264 var lower48 = d3.geo.conicEqualArea().rotate([ 98, 0 ]).center([ 0, 38 ]).parallels([ 29.5, 45.5 ]);
3265 var alaska = d3.geo.conicEqualArea().rotate([ 160, 0 ]).center([ 0, 60 ]).parallels([ 55, 65 ]);
3266 var hawaii = d3.geo.conicEqualArea().rotate([ 160, 0 ]).center([ 0, 20 ]).parallels([ 8, 18 ]);
3267 var puertoRico = d3.geo.conicEqualArea().rotate([ 60, 0 ]).center([ 0, 10 ]).parallels([ 8, 18 ]);
3268 var alaskaInvert, hawaiiInvert, puertoRicoInvert;
3269 function albersUsa(coordinates) {
3270 return projection(coordinates)(coordinates);
3272 function projection(point) {
3273 var lon = point[0], lat = point[1];
3274 return lat > 50 ? alaska : lon < -140 ? hawaii : lat < 21 ? puertoRico : lower48;
3276 albersUsa.invert = function(coordinates) {
3277 return alaskaInvert(coordinates) || hawaiiInvert(coordinates) || puertoRicoInvert(coordinates) || lower48.invert(coordinates);
3279 albersUsa.scale = function(x) {
3280 if (!arguments.length) return lower48.scale();
3282 alaska.scale(x * .6);
3284 puertoRico.scale(x * 1.5);
3285 return albersUsa.translate(lower48.translate());
3287 albersUsa.translate = function(x) {
3288 if (!arguments.length) return lower48.translate();
3289 var dz = lower48.scale(), dx = x[0], dy = x[1];
3290 lower48.translate(x);
3291 alaska.translate([ dx - .4 * dz, dy + .17 * dz ]);
3292 hawaii.translate([ dx - .19 * dz, dy + .2 * dz ]);
3293 puertoRico.translate([ dx + .58 * dz, dy + .43 * dz ]);
3294 alaskaInvert = d3_geo_albersUsaInvert(alaska, [ [ -180, 50 ], [ -130, 72 ] ]);
3295 hawaiiInvert = d3_geo_albersUsaInvert(hawaii, [ [ -164, 18 ], [ -154, 24 ] ]);
3296 puertoRicoInvert = d3_geo_albersUsaInvert(puertoRico, [ [ -67.5, 17.5 ], [ -65, 19 ] ]);
3299 return albersUsa.scale(1e3);
3301 function d3_geo_albersUsaInvert(projection, extent) {
3302 var a = projection(extent[0]), b = projection([ .5 * (extent[0][0] + extent[1][0]), extent[0][1] ]), c = projection([ extent[1][0], extent[0][1] ]), d = projection(extent[1]);
3303 var dya = b[1] - a[1], dxa = b[0] - a[0], dyb = c[1] - b[1], dxb = c[0] - b[0];
3304 var ma = dya / dxa, mb = dyb / dxb;
3305 var cx = .5 * (ma * mb * (a[1] - c[1]) + mb * (a[0] + b[0]) - ma * (b[0] + c[0])) / (mb - ma), cy = (.5 * (a[0] + b[0]) - cx) / ma + .5 * (a[1] + b[1]);
3306 var dx0 = d[0] - cx, dy0 = d[1] - cy, dx1 = a[0] - cx, dy1 = a[1] - cy, r0 = dx0 * dx0 + dy0 * dy0, r1 = dx1 * dx1 + dy1 * dy1;
3307 var a0 = Math.atan2(dy0, dx0), a1 = Math.atan2(dy1, dx1);
3308 return function(coordinates) {
3309 var dx = coordinates[0] - cx, dy = coordinates[1] - cy, r = dx * dx + dy * dy, a = Math.atan2(dy, dx);
3310 if (r0 < r && r < r1 && a0 < a && a < a1) return projection.invert(coordinates);
3313 var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
3317 polygonStart: function() {
3318 d3_geo_pathAreaPolygon = 0;
3319 d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
3321 polygonEnd: function() {
3322 d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
3323 d3_geo_pathAreaSum += Math.abs(d3_geo_pathAreaPolygon / 2);
3326 function d3_geo_pathAreaRingStart() {
3327 var x00, y00, x0, y0;
3328 d3_geo_pathArea.point = function(x, y) {
3329 d3_geo_pathArea.point = nextPoint;
3330 x00 = x0 = x, y00 = y0 = y;
3332 function nextPoint(x, y) {
3333 d3_geo_pathAreaPolygon += y0 * x - x0 * y;
3336 d3_geo_pathArea.lineEnd = function() {
3337 nextPoint(x00, y00);
3340 function d3_geo_pathBuffer() {
3341 var pointCircle = d3_geo_pathCircle(4.5), buffer = [];
3344 lineStart: function() {
3345 stream.point = pointLineStart;
3348 polygonStart: function() {
3349 stream.lineEnd = lineEndPolygon;
3351 polygonEnd: function() {
3352 stream.lineEnd = lineEnd;
3353 stream.point = point;
3355 pointRadius: function(_) {
3356 pointCircle = d3_geo_pathCircle(_);
3359 result: function() {
3360 if (buffer.length) {
3361 var result = buffer.join("");
3367 function point(x, y) {
3368 buffer.push("M", x, ",", y, pointCircle);
3370 function pointLineStart(x, y) {
3371 buffer.push("M", x, ",", y);
3372 stream.point = pointLine;
3374 function pointLine(x, y) {
3375 buffer.push("L", x, ",", y);
3377 function lineEnd() {
3378 stream.point = point;
3380 function lineEndPolygon() {
3385 var d3_geo_pathCentroid = {
3386 point: d3_geo_pathCentroidPoint,
3387 lineStart: d3_geo_pathCentroidLineStart,
3388 lineEnd: d3_geo_pathCentroidLineEnd,
3389 polygonStart: function() {
3390 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
3392 polygonEnd: function() {
3393 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
3394 d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
3395 d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
3398 function d3_geo_pathCentroidPoint(x, y) {
3399 if (d3_geo_centroidDimension) return;
3400 d3_geo_centroidX += x;
3401 d3_geo_centroidY += y;
3404 function d3_geo_pathCentroidLineStart() {
3406 if (d3_geo_centroidDimension !== 1) {
3407 if (d3_geo_centroidDimension < 1) {
3408 d3_geo_centroidDimension = 1;
3409 d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
3412 d3_geo_pathCentroid.point = function(x, y) {
3413 d3_geo_pathCentroid.point = nextPoint;
3416 function nextPoint(x, y) {
3417 var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
3418 d3_geo_centroidX += z * (x0 + x) / 2;
3419 d3_geo_centroidY += z * (y0 + y) / 2;
3420 d3_geo_centroidZ += z;
3424 function d3_geo_pathCentroidLineEnd() {
3425 d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
3427 function d3_geo_pathCentroidRingStart() {
3428 var x00, y00, x0, y0;
3429 if (d3_geo_centroidDimension < 2) {
3430 d3_geo_centroidDimension = 2;
3431 d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
3433 d3_geo_pathCentroid.point = function(x, y) {
3434 d3_geo_pathCentroid.point = nextPoint;
3435 x00 = x0 = x, y00 = y0 = y;
3437 function nextPoint(x, y) {
3438 var z = y0 * x - x0 * y;
3439 d3_geo_centroidX += z * (x0 + x);
3440 d3_geo_centroidY += z * (y0 + y);
3441 d3_geo_centroidZ += z * 3;
3444 d3_geo_pathCentroid.lineEnd = function() {
3445 nextPoint(x00, y00);
3448 function d3_geo_pathContext(context) {
3449 var pointRadius = 4.5;
3452 lineStart: function() {
3453 stream.point = pointLineStart;
3456 polygonStart: function() {
3457 stream.lineEnd = lineEndPolygon;
3459 polygonEnd: function() {
3460 stream.lineEnd = lineEnd;
3461 stream.point = point;
3463 pointRadius: function(_) {
3469 function point(x, y) {
3470 context.moveTo(x, y);
3471 context.arc(x, y, pointRadius, 0, 2 * π);
3473 function pointLineStart(x, y) {
3474 context.moveTo(x, y);
3475 stream.point = pointLine;
3477 function pointLine(x, y) {
3478 context.lineTo(x, y);
3480 function lineEnd() {
3481 stream.point = point;
3483 function lineEndPolygon() {
3484 context.closePath();
3488 d3.geo.path = function() {
3489 var pointRadius = 4.5, projection, context, projectStream, contextStream;
3490 function path(object) {
3491 if (object) d3.geo.stream(object, projectStream(contextStream.pointRadius(typeof pointRadius === "function" ? +pointRadius.apply(this, arguments) : pointRadius)));
3492 return contextStream.result();
3494 path.area = function(object) {
3495 d3_geo_pathAreaSum = 0;
3496 d3.geo.stream(object, projectStream(d3_geo_pathArea));
3497 return d3_geo_pathAreaSum;
3499 path.centroid = function(object) {
3500 d3_geo_centroidDimension = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
3501 d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
3502 return d3_geo_centroidZ ? [ d3_geo_centroidX / d3_geo_centroidZ, d3_geo_centroidY / d3_geo_centroidZ ] : undefined;
3504 path.bounds = function(object) {
3505 return d3_geo_bounds(projectStream)(object);
3507 path.projection = function(_) {
3508 if (!arguments.length) return projection;
3509 projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
3512 path.context = function(_) {
3513 if (!arguments.length) return context;
3514 contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
3517 path.pointRadius = function(_) {
3518 if (!arguments.length) return pointRadius;
3519 pointRadius = typeof _ === "function" ? _ : +_;
3522 return path.projection(d3.geo.albersUsa()).context(null);
3524 function d3_geo_pathCircle(radius) {
3525 return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + +2 * radius + "z";
3527 function d3_geo_pathProjectStream(project) {
3528 var resample = d3_geo_resample(function(λ, φ) {
3529 return project([ λ * d3_degrees, φ * d3_degrees ]);
3531 return function(stream) {
3532 stream = resample(stream);
3534 point: function(λ, φ) {
3535 stream.point(λ * d3_radians, φ * d3_radians);
3537 sphere: function() {
3540 lineStart: function() {
3543 lineEnd: function() {
3546 polygonStart: function() {
3547 stream.polygonStart();
3549 polygonEnd: function() {
3550 stream.polygonEnd();
3555 d3.geo.albers = function() {
3556 return d3.geo.conicEqualArea().parallels([ 29.5, 45.5 ]).rotate([ 98, 0 ]).center([ 0, 38 ]).scale(1e3);
3558 function d3_geo_azimuthal(scale, angle) {
3559 function azimuthal(λ, φ) {
3560 var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
3561 return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
3563 azimuthal.invert = function(x, y) {
3564 var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
3565 return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
3569 var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
3570 return Math.sqrt(2 / (1 + cosλcosφ));
3572 return 2 * Math.asin(ρ / 2);
3574 (d3.geo.azimuthalEqualArea = function() {
3575 return d3_geo_projection(d3_geo_azimuthalEqualArea);
3576 }).raw = d3_geo_azimuthalEqualArea;
3577 var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
3578 var c = Math.acos(cosλcosφ);
3579 return c && c / Math.sin(c);
3581 (d3.geo.azimuthalEquidistant = function() {
3582 return d3_geo_projection(d3_geo_azimuthalEquidistant);
3583 }).raw = d3_geo_azimuthalEquidistant;
3584 function d3_geo_conicConformal(φ0, φ1) {
3585 var cosφ0 = Math.cos(φ0), t = function(φ) {
3586 return Math.tan(π / 4 + φ / 2);
3587 }, 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;
3588 if (!n) return d3_geo_mercator;
3589 function forward(λ, φ) {
3590 var ρ = Math.abs(Math.abs(φ) - π / 2) < ε ? 0 : F / Math.pow(t(φ), n);
3591 return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
3593 forward.invert = function(x, y) {
3594 var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
3595 return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - π / 2 ];
3599 (d3.geo.conicConformal = function() {
3600 return d3_geo_conic(d3_geo_conicConformal);
3601 }).raw = d3_geo_conicConformal;
3602 function d3_geo_conicEquidistant(φ0, φ1) {
3603 var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
3604 if (Math.abs(n) < ε) return d3_geo_equirectangular;
3605 function forward(λ, φ) {
3607 return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
3609 forward.invert = function(x, y) {
3611 return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
3615 (d3.geo.conicEquidistant = function() {
3616 return d3_geo_conic(d3_geo_conicEquidistant);
3617 }).raw = d3_geo_conicEquidistant;
3618 var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
3619 return 1 / cosλcosφ;
3621 (d3.geo.gnomonic = function() {
3622 return d3_geo_projection(d3_geo_gnomonic);
3623 }).raw = d3_geo_gnomonic;
3624 function d3_geo_mercator(λ, φ) {
3625 return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
3627 d3_geo_mercator.invert = function(x, y) {
3628 return [ x, 2 * Math.atan(Math.exp(y)) - π / 2 ];
3630 function d3_geo_mercatorProjection(project) {
3631 var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
3632 m.scale = function() {
3633 var v = scale.apply(m, arguments);
3634 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
3636 m.translate = function() {
3637 var v = translate.apply(m, arguments);
3638 return v === m ? clipAuto ? m.clipExtent(null) : m : v;
3640 m.clipExtent = function(_) {
3641 var v = clipExtent.apply(m, arguments);
3643 if (clipAuto = _ == null) {
3644 var k = π * scale(), t = translate();
3645 clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
3647 } else if (clipAuto) {
3652 return m.clipExtent(null);
3654 (d3.geo.mercator = function() {
3655 return d3_geo_mercatorProjection(d3_geo_mercator);
3656 }).raw = d3_geo_mercator;
3657 var d3_geo_orthographic = d3_geo_azimuthal(function() {
3660 (d3.geo.orthographic = function() {
3661 return d3_geo_projection(d3_geo_orthographic);
3662 }).raw = d3_geo_orthographic;
3663 var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
3664 return 1 / (1 + cosλcosφ);
3666 return 2 * Math.atan(ρ);
3668 (d3.geo.stereographic = function() {
3669 return d3_geo_projection(d3_geo_stereographic);
3670 }).raw = d3_geo_stereographic;
3671 function d3_geo_transverseMercator(λ, φ) {
3672 var B = Math.cos(φ) * Math.sin(λ);
3673 return [ Math.log((1 + B) / (1 - B)) / 2, Math.atan2(Math.tan(φ), Math.cos(λ)) ];
3675 d3_geo_transverseMercator.invert = function(x, y) {
3676 return [ Math.atan2(d3_sinh(x), Math.cos(y)), d3_asin(Math.sin(y) / d3_cosh(x)) ];
3678 (d3.geo.transverseMercator = function() {
3679 return d3_geo_mercatorProjection(d3_geo_transverseMercator);
3680 }).raw = d3_geo_transverseMercator;
3683 function d3_svg_line(projection) {
3684 var x = d3_svg_lineX, y = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
3685 function line(data) {
3686 var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
3687 function segment() {
3688 segments.push("M", interpolate(projection(points), tension));
3691 if (defined.call(this, d = data[i], i)) {
3692 points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
3693 } else if (points.length) {
3698 if (points.length) segment();
3699 return segments.length ? segments.join("") : null;
3701 line.x = function(_) {
3702 if (!arguments.length) return x;
3706 line.y = function(_) {
3707 if (!arguments.length) return y;
3711 line.defined = function(_) {
3712 if (!arguments.length) return defined;
3716 line.interpolate = function(_) {
3717 if (!arguments.length) return interpolateKey;
3718 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
3721 line.tension = function(_) {
3722 if (!arguments.length) return tension;
3728 d3.svg.line = function() {
3729 return d3_svg_line(d3_identity);
3731 function d3_svg_lineX(d) {
3734 function d3_svg_lineY(d) {
3737 var d3_svg_lineInterpolators = d3.map({
3738 linear: d3_svg_lineLinear,
3739 "linear-closed": d3_svg_lineLinearClosed,
3740 "step-before": d3_svg_lineStepBefore,
3741 "step-after": d3_svg_lineStepAfter,
3742 basis: d3_svg_lineBasis,
3743 "basis-open": d3_svg_lineBasisOpen,
3744 "basis-closed": d3_svg_lineBasisClosed,
3745 bundle: d3_svg_lineBundle,
3746 cardinal: d3_svg_lineCardinal,
3747 "cardinal-open": d3_svg_lineCardinalOpen,
3748 "cardinal-closed": d3_svg_lineCardinalClosed,
3749 monotone: d3_svg_lineMonotone
3751 d3_svg_lineInterpolators.forEach(function(key, value) {
3753 value.closed = /-closed$/.test(key);
3755 function d3_svg_lineLinear(points) {
3756 return points.join("L");
3758 function d3_svg_lineLinearClosed(points) {
3759 return d3_svg_lineLinear(points) + "Z";
3761 function d3_svg_lineStepBefore(points) {
3762 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
3763 while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
3764 return path.join("");
3766 function d3_svg_lineStepAfter(points) {
3767 var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
3768 while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
3769 return path.join("");
3771 function d3_svg_lineCardinalOpen(points, tension) {
3772 return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, points.length - 1), d3_svg_lineCardinalTangents(points, tension));
3774 function d3_svg_lineCardinalClosed(points, tension) {
3775 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
3776 points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
3778 function d3_svg_lineCardinal(points, tension) {
3779 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
3781 function d3_svg_lineHermite(points, tangents) {
3782 if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
3783 return d3_svg_lineLinear(points);
3785 var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
3787 path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
3791 if (tangents.length > 1) {
3795 path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
3796 for (var i = 2; i < tangents.length; i++, pi++) {
3799 path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
3803 var lp = points[pi];
3804 path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
3808 function d3_svg_lineCardinalTangents(points, tension) {
3809 var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
3814 tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
3818 function d3_svg_lineBasis(points) {
3819 if (points.length < 3) return d3_svg_lineLinear(points);
3820 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 ];
3821 d3_svg_lineBasisBezier(path, px, py);
3828 d3_svg_lineBasisBezier(path, px, py);
3836 d3_svg_lineBasisBezier(path, px, py);
3838 return path.join("");
3840 function d3_svg_lineBasisOpen(points) {
3841 if (points.length < 4) return d3_svg_lineLinear(points);
3842 var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
3848 path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
3856 d3_svg_lineBasisBezier(path, px, py);
3858 return path.join("");
3860 function d3_svg_lineBasisClosed(points) {
3861 var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
3867 path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
3875 d3_svg_lineBasisBezier(path, px, py);
3877 return path.join("");
3879 function d3_svg_lineBundle(points, tension) {
3880 var n = points.length - 1;
3882 var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
3886 p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
3887 p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
3890 return d3_svg_lineBasis(points);
3892 function d3_svg_lineDot4(a, b) {
3893 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
3895 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 ];
3896 function d3_svg_lineBasisBezier(path, x, y) {
3897 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));
3899 function d3_svg_lineSlope(p0, p1) {
3900 return (p1[1] - p0[1]) / (p1[0] - p0[0]);
3902 function d3_svg_lineFiniteDifferences(points) {
3903 var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
3905 m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
3910 function d3_svg_lineMonotoneTangents(points) {
3911 var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
3913 d = d3_svg_lineSlope(points[i], points[i + 1]);
3914 if (Math.abs(d) < 1e-6) {
3915 m[i] = m[i + 1] = 0;
3921 s = d * 3 / Math.sqrt(s);
3929 s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
3930 tangents.push([ s || 0, m[i] * s || 0 ]);
3934 function d3_svg_lineMonotone(points) {
3935 return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
3937 d3.geom.hull = function(vertices) {
3938 var x = d3_svg_lineX, y = d3_svg_lineY;
3939 if (arguments.length) return hull(vertices);
3940 function hull(data) {
3941 if (data.length < 3) return [];
3942 var fx = d3_functor(x), fy = d3_functor(y), n = data.length, vertices, plen = n - 1, points = [], stack = [], d, i, j, h = 0, x1, y1, x2, y2, u, v, a, sp;
3943 if (fx === d3_svg_lineX && y === d3_svg_lineY) vertices = data; else for (i = 0,
3944 vertices = []; i < n; ++i) {
3945 vertices.push([ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]);
3947 for (i = 1; i < n; ++i) {
3948 if (vertices[i][1] < vertices[h][1]) {
3950 } else if (vertices[i][1] == vertices[h][1]) {
3951 h = vertices[i][0] < vertices[h][0] ? i : h;
3954 for (i = 0; i < n; ++i) {
3955 if (i === h) continue;
3956 y1 = vertices[i][1] - vertices[h][1];
3957 x1 = vertices[i][0] - vertices[h][0];
3959 angle: Math.atan2(y1, x1),
3963 points.sort(function(a, b) {
3964 return a.angle - b.angle;
3966 a = points[0].angle;
3967 v = points[0].index;
3969 for (i = 1; i < plen; ++i) {
3970 j = points[i].index;
3971 if (a == points[i].angle) {
3972 x1 = vertices[v][0] - vertices[h][0];
3973 y1 = vertices[v][1] - vertices[h][1];
3974 x2 = vertices[j][0] - vertices[h][0];
3975 y2 = vertices[j][1] - vertices[h][1];
3976 if (x1 * x1 + y1 * y1 >= x2 * x2 + y2 * y2) {
3977 points[i].index = -1;
3979 points[u].index = -1;
3980 a = points[i].angle;
3985 a = points[i].angle;
3991 for (i = 0, j = 0; i < 2; ++j) {
3992 if (points[j].index !== -1) {
3993 stack.push(points[j].index);
3998 for (;j < plen; ++j) {
3999 if (points[j].index === -1) continue;
4000 while (!d3_geom_hullCCW(stack[sp - 2], stack[sp - 1], points[j].index, vertices)) {
4003 stack[sp++] = points[j].index;
4006 for (i = 0; i < sp; ++i) {
4007 poly.push(data[stack[i]]);
4011 hull.x = function(_) {
4012 return arguments.length ? (x = _, hull) : x;
4014 hull.y = function(_) {
4015 return arguments.length ? (y = _, hull) : y;
4019 function d3_geom_hullCCW(i1, i2, i3, v) {
4020 var t, a, b, c, d, e, f;
4030 return (f - b) * (c - a) - (d - b) * (e - a) > 0;
4032 d3.geom.polygon = function(coordinates) {
4033 coordinates.area = function() {
4034 var i = 0, n = coordinates.length, area = coordinates[n - 1][1] * coordinates[0][0] - coordinates[n - 1][0] * coordinates[0][1];
4036 area += coordinates[i - 1][1] * coordinates[i][0] - coordinates[i - 1][0] * coordinates[i][1];
4040 coordinates.centroid = function(k) {
4041 var i = -1, n = coordinates.length, x = 0, y = 0, a, b = coordinates[n - 1], c;
4042 if (!arguments.length) k = -1 / (6 * coordinates.area());
4046 c = a[0] * b[1] - b[0] * a[1];
4047 x += (a[0] + b[0]) * c;
4048 y += (a[1] + b[1]) * c;
4050 return [ x * k, y * k ];
4052 coordinates.clip = function(subject) {
4053 var input, i = -1, n = coordinates.length, j, m, a = coordinates[n - 1], b, c, d;
4055 input = subject.slice();
4058 c = input[(m = input.length) - 1];
4062 if (d3_geom_polygonInside(d, a, b)) {
4063 if (!d3_geom_polygonInside(c, a, b)) {
4064 subject.push(d3_geom_polygonIntersect(c, d, a, b));
4067 } else if (d3_geom_polygonInside(c, a, b)) {
4068 subject.push(d3_geom_polygonIntersect(c, d, a, b));
4078 function d3_geom_polygonInside(p, a, b) {
4079 return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
4081 function d3_geom_polygonIntersect(c, d, a, b) {
4082 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);
4083 return [ x1 + ua * x21, y1 + ua * y21 ];
4085 d3.geom.delaunay = function(vertices) {
4086 var edges = vertices.map(function() {
4089 d3_geom_voronoiTessellate(vertices, function(e) {
4090 edges[e.region.l.index].push(vertices[e.region.r.index]);
4092 edges.forEach(function(edge, i) {
4093 var v = vertices[i], cx = v[0], cy = v[1];
4094 edge.forEach(function(v) {
4095 v.angle = Math.atan2(v[0] - cx, v[1] - cy);
4097 edge.sort(function(a, b) {
4098 return a.angle - b.angle;
4100 for (var j = 0, m = edge.length - 1; j < m; j++) {
4101 triangles.push([ v, edge[j], edge[j + 1] ]);
4106 d3.geom.voronoi = function(points) {
4107 var size = null, x = d3_svg_lineX, y = d3_svg_lineY, clip;
4108 if (arguments.length) return voronoi(points);
4109 function voronoi(data) {
4110 var points, polygons = data.map(function() {
4112 }), fx = d3_functor(x), fy = d3_functor(y), d, i, n = data.length, Z = 1e6;
4113 if (fx === d3_svg_lineX && fy === d3_svg_lineY) points = data; else for (points = [],
4114 i = 0; i < n; ++i) {
4115 points.push([ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]);
4117 d3_geom_voronoiTessellate(points, function(e) {
4118 var s1, s2, x1, x2, y1, y2;
4119 if (e.a === 1 && e.b >= 0) {
4127 y1 = s1 ? s1.y : -Z;
4128 x1 = e.c - e.b * y1;
4130 x2 = e.c - e.b * y2;
4132 x1 = s1 ? s1.x : -Z;
4133 y1 = e.c - e.a * x1;
4135 y2 = e.c - e.a * x2;
4137 var v1 = [ x1, y1 ], v2 = [ x2, y2 ];
4138 polygons[e.region.l.index].push(v1, v2);
4139 polygons[e.region.r.index].push(v1, v2);
4141 polygons = polygons.map(function(polygon, i) {
4142 var cx = points[i][0], cy = points[i][1], angle = polygon.map(function(v) {
4143 return Math.atan2(v[0] - cx, v[1] - cy);
4144 }), order = d3.range(polygon.length).sort(function(a, b) {
4145 return angle[a] - angle[b];
4147 return order.filter(function(d, i) {
4148 return !i || angle[d] - angle[order[i - 1]] > ε;
4149 }).map(function(d) {
4153 polygons.forEach(function(polygon, i) {
4154 var n = polygon.length;
4155 if (!n) return polygon.push([ -Z, -Z ], [ -Z, Z ], [ Z, Z ], [ Z, -Z ]);
4157 var p0 = points[i], p1 = polygon[0], p2 = polygon[1], x0 = p0[0], y0 = p0[1], x1 = p1[0], y1 = p1[1], x2 = p2[0], y2 = p2[1], dx = Math.abs(x2 - x1), dy = y2 - y1;
4158 if (Math.abs(dy) < ε) {
4159 var y = y0 < y1 ? -Z : Z;
4160 polygon.push([ -Z, y ], [ Z, y ]);
4161 } else if (dx < ε) {
4162 var x = x0 < x1 ? -Z : Z;
4163 polygon.push([ x, -Z ], [ x, Z ]);
4165 var y = (x2 - x1) * (y1 - y0) < (x1 - x0) * (y2 - y1) ? Z : -Z, z = Math.abs(dy) - dx;
4166 if (Math.abs(z) < ε) {
4167 polygon.push([ dy < 0 ? y : -y, y ]);
4170 polygon.push([ -Z, y ], [ Z, y ]);
4174 if (clip) for (i = 0; i < n; ++i) clip(polygons[i]);
4175 for (i = 0; i < n; ++i) polygons[i].point = data[i];
4178 voronoi.x = function(_) {
4179 return arguments.length ? (x = _, voronoi) : x;
4181 voronoi.y = function(_) {
4182 return arguments.length ? (y = _, voronoi) : y;
4184 voronoi.size = function(_) {
4185 if (!arguments.length) return size;
4189 size = [ +_[0], +_[1] ];
4190 clip = d3.geom.polygon([ [ 0, 0 ], [ 0, size[1] ], size, [ size[0], 0 ] ]).clip;
4194 voronoi.links = function(data) {
4195 var points, graph = data.map(function() {
4197 }), links = [], fx = d3_functor(x), fy = d3_functor(y), d, i, n = data.length;
4198 if (fx === d3_svg_lineX && fy === d3_svg_lineY) points = data; else for (i = 0; i < n; ++i) {
4199 points.push([ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]);
4201 d3_geom_voronoiTessellate(points, function(e) {
4202 var l = e.region.l.index, r = e.region.r.index;
4203 if (graph[l][r]) return;
4204 graph[l][r] = graph[r][l] = true;
4212 voronoi.triangles = function(data) {
4213 if (x === d3_svg_lineX && y === d3_svg_lineY) return d3.geom.delaunay(data);
4214 var points, point, fx = d3_functor(x), fy = d3_functor(y), d, i, n;
4215 for (i = 0, points = [], n = data.length; i < n; ++i) {
4216 point = [ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ];
4220 return d3.geom.delaunay(points).map(function(triangle) {
4221 return triangle.map(function(point) {
4228 var d3_geom_voronoiOpposite = {
4232 function d3_geom_voronoiTessellate(points, callback) {
4234 list: points.map(function(v, i) {
4240 }).sort(function(a, b) {
4241 return a.y < b.y ? -1 : a.y > b.y ? 1 : a.x < b.x ? -1 : a.x > b.x ? 1 : 0;
4250 EdgeList.leftEnd = EdgeList.createHalfEdge(null, "l");
4251 EdgeList.rightEnd = EdgeList.createHalfEdge(null, "l");
4252 EdgeList.leftEnd.r = EdgeList.rightEnd;
4253 EdgeList.rightEnd.l = EdgeList.leftEnd;
4254 EdgeList.list.unshift(EdgeList.leftEnd, EdgeList.rightEnd);
4256 createHalfEdge: function(edge, side) {
4265 insert: function(lb, he) {
4271 leftBound: function(p) {
4272 var he = EdgeList.leftEnd;
4275 } while (he != EdgeList.rightEnd && Geom.rightOf(he, p));
4284 right: function(he) {
4287 left: function(he) {
4290 leftRegion: function(he) {
4291 return he.edge == null ? Sites.bottomSite : he.edge.region[he.side];
4293 rightRegion: function(he) {
4294 return he.edge == null ? Sites.bottomSite : he.edge.region[d3_geom_voronoiOpposite[he.side]];
4298 bisect: function(s1, s2) {
4309 var dx = s2.x - s1.x, dy = s2.y - s1.y, adx = dx > 0 ? dx : -dx, ady = dy > 0 ? dy : -dy;
4310 newEdge.c = s1.x * dx + s1.y * dy + (dx * dx + dy * dy) * .5;
4313 newEdge.b = dy / dx;
4317 newEdge.a = dx / dy;
4322 intersect: function(el1, el2) {
4323 var e1 = el1.edge, e2 = el2.edge;
4324 if (!e1 || !e2 || e1.region.r == e2.region.r) {
4327 var d = e1.a * e2.b - e1.b * e2.a;
4328 if (Math.abs(d) < 1e-10) {
4331 var xint = (e1.c * e2.b - e2.c * e1.b) / d, yint = (e2.c * e1.a - e1.c * e2.a) / d, e1r = e1.region.r, e2r = e2.region.r, el, e;
4332 if (e1r.y < e2r.y || e1r.y == e2r.y && e1r.x < e2r.x) {
4339 var rightOfSite = xint >= e.region.r.x;
4340 if (rightOfSite && el.side === "l" || !rightOfSite && el.side === "r") {
4348 rightOf: function(he, p) {
4349 var e = he.edge, topsite = e.region.r, rightOfSite = p.x > topsite.x;
4350 if (rightOfSite && he.side === "l") {
4353 if (!rightOfSite && he.side === "r") {
4357 var dyp = p.y - topsite.y, dxp = p.x - topsite.x, fast = 0, above = 0;
4358 if (!rightOfSite && e.b < 0 || rightOfSite && e.b >= 0) {
4359 above = fast = dyp >= e.b * dxp;
4361 above = p.x + p.y * e.b > e.c;
4370 var dxs = topsite.x - e.region.l.x;
4371 above = e.b * (dxp * dxp - dyp * dyp) < dxs * dyp * (1 + 2 * dxp / dxs + e.b * e.b);
4377 var yl = e.c - e.a * p.x, t1 = p.y - yl, t2 = p.x - topsite.x, t3 = yl - topsite.y;
4378 above = t1 * t1 > t2 * t2 + t3 * t3;
4380 return he.side === "l" ? above : !above;
4382 endPoint: function(edge, side, site) {
4383 edge.ep[side] = site;
4384 if (!edge.ep[d3_geom_voronoiOpposite[side]]) return;
4387 distance: function(s, t) {
4388 var dx = s.x - t.x, dy = s.y - t.y;
4389 return Math.sqrt(dx * dx + dy * dy);
4394 insert: function(he, site, offset) {
4396 he.ystar = site.y + offset;
4397 for (var i = 0, list = EventQueue.list, l = list.length; i < l; i++) {
4399 if (he.ystar > next.ystar || he.ystar == next.ystar && site.x > next.vertex.x) {
4405 list.splice(i, 0, he);
4408 for (var i = 0, ls = EventQueue.list, l = ls.length; i < l && ls[i] != he; ++i) {}
4412 return EventQueue.list.length === 0;
4414 nextEvent: function(he) {
4415 for (var i = 0, ls = EventQueue.list, l = ls.length; i < l; ++i) {
4416 if (ls[i] == he) return ls[i + 1];
4421 var elem = EventQueue.list[0];
4427 extractMin: function() {
4428 return EventQueue.list.shift();
4432 Sites.bottomSite = Sites.list.shift();
4433 var newSite = Sites.list.shift(), newIntStar;
4434 var lbnd, rbnd, llbnd, rrbnd, bisector;
4435 var bot, top, temp, p, v;
4438 if (!EventQueue.empty()) {
4439 newIntStar = EventQueue.min();
4441 if (newSite && (EventQueue.empty() || newSite.y < newIntStar.y || newSite.y == newIntStar.y && newSite.x < newIntStar.x)) {
4442 lbnd = EdgeList.leftBound(newSite);
4443 rbnd = EdgeList.right(lbnd);
4444 bot = EdgeList.rightRegion(lbnd);
4445 e = Geom.bisect(bot, newSite);
4446 bisector = EdgeList.createHalfEdge(e, "l");
4447 EdgeList.insert(lbnd, bisector);
4448 p = Geom.intersect(lbnd, bisector);
4450 EventQueue.del(lbnd);
4451 EventQueue.insert(lbnd, p, Geom.distance(p, newSite));
4454 bisector = EdgeList.createHalfEdge(e, "r");
4455 EdgeList.insert(lbnd, bisector);
4456 p = Geom.intersect(bisector, rbnd);
4458 EventQueue.insert(bisector, p, Geom.distance(p, newSite));
4460 newSite = Sites.list.shift();
4461 } else if (!EventQueue.empty()) {
4462 lbnd = EventQueue.extractMin();
4463 llbnd = EdgeList.left(lbnd);
4464 rbnd = EdgeList.right(lbnd);
4465 rrbnd = EdgeList.right(rbnd);
4466 bot = EdgeList.leftRegion(lbnd);
4467 top = EdgeList.rightRegion(rbnd);
4469 Geom.endPoint(lbnd.edge, lbnd.side, v);
4470 Geom.endPoint(rbnd.edge, rbnd.side, v);
4472 EventQueue.del(rbnd);
4475 if (bot.y > top.y) {
4481 e = Geom.bisect(bot, top);
4482 bisector = EdgeList.createHalfEdge(e, pm);
4483 EdgeList.insert(llbnd, bisector);
4484 Geom.endPoint(e, d3_geom_voronoiOpposite[pm], v);
4485 p = Geom.intersect(llbnd, bisector);
4487 EventQueue.del(llbnd);
4488 EventQueue.insert(llbnd, p, Geom.distance(p, bot));
4490 p = Geom.intersect(bisector, rrbnd);
4492 EventQueue.insert(bisector, p, Geom.distance(p, bot));
4498 for (lbnd = EdgeList.right(EdgeList.leftEnd); lbnd != EdgeList.rightEnd; lbnd = EdgeList.right(lbnd)) {
4499 callback(lbnd.edge);
4502 d3.geom.quadtree = function(points, x1, y1, x2, y2) {
4503 var x = d3_svg_lineX, y = d3_svg_lineY, compat;
4504 if (compat = arguments.length) {
4505 x = d3_geom_quadtreeCompatX;
4506 y = d3_geom_quadtreeCompatY;
4512 return quadtree(points);
4514 function quadtree(data) {
4515 var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
4517 x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
4519 x2_ = y2_ = -(x1_ = y1_ = Infinity);
4522 if (compat) for (i = 0; i < n; ++i) {
4524 if (d.x < x1_) x1_ = d.x;
4525 if (d.y < y1_) y1_ = d.y;
4526 if (d.x > x2_) x2_ = d.x;
4527 if (d.y > y2_) y2_ = d.y;
4530 } else for (i = 0; i < n; ++i) {
4531 var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
4532 if (x_ < x1_) x1_ = x_;
4533 if (y_ < y1_) y1_ = y_;
4534 if (x_ > x2_) x2_ = x_;
4535 if (y_ > y2_) y2_ = y_;
4540 var dx = x2_ - x1_, dy = y2_ - y1_;
4541 if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
4542 function insert(n, d, x, y, x1, y1, x2, y2) {
4543 if (isNaN(x) || isNaN(y)) return;
4545 var nx = n.x, ny = n.y;
4547 if (Math.abs(nx - x) + Math.abs(ny - y) < .01) {
4548 insertChild(n, d, x, y, x1, y1, x2, y2);
4550 var nPoint = n.point;
4551 n.x = n.y = n.point = null;
4552 insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
4553 insertChild(n, d, x, y, x1, y1, x2, y2);
4556 n.x = x, n.y = y, n.point = d;
4559 insertChild(n, d, x, y, x1, y1, x2, y2);
4562 function insertChild(n, d, x, y, x1, y1, x2, y2) {
4563 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, right = x >= sx, bottom = y >= sy, i = (bottom << 1) + right;
4565 n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
4566 if (right) x1 = sx; else x2 = sx;
4567 if (bottom) y1 = sy; else y2 = sy;
4568 insert(n, d, x, y, x1, y1, x2, y2);
4570 var root = d3_geom_quadtreeNode();
4571 root.add = function(d) {
4572 insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
4574 root.visit = function(f) {
4575 d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
4580 insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
4583 } else data.forEach(root.add);
4584 xs = ys = data = d = null;
4587 quadtree.x = function(_) {
4588 return arguments.length ? (x = _, quadtree) : x;
4590 quadtree.y = function(_) {
4591 return arguments.length ? (y = _, quadtree) : y;
4593 quadtree.size = function(_) {
4594 if (!arguments.length) return x1 == null ? null : [ x2, y2 ];
4596 x1 = y1 = x2 = y2 = null;
4599 x2 = +_[0], y2 = +_[1];
4605 function d3_geom_quadtreeCompatX(d) {
4608 function d3_geom_quadtreeCompatY(d) {
4611 function d3_geom_quadtreeNode() {
4620 function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
4621 if (!f(node, x1, y1, x2, y2)) {
4622 var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
4623 if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
4624 if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
4625 if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
4626 if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
4629 d3.interpolateRgb = d3_interpolateRgb;
4630 function d3_interpolateRgb(a, b) {
4633 var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
4634 return function(t) {
4635 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));
4638 d3.transform = function(string) {
4639 var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
4640 return (d3.transform = function(string) {
4641 g.setAttribute("transform", string);
4642 var t = g.transform.baseVal.consolidate();
4643 return new d3_transform(t ? t.matrix : d3_transformIdentity);
4646 function d3_transform(m) {
4647 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;
4648 if (r0[0] * r1[1] < r1[0] * r0[1]) {
4654 this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
4655 this.translate = [ m.e, m.f ];
4656 this.scale = [ kx, ky ];
4657 this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
4659 d3_transform.prototype.toString = function() {
4660 return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
4662 function d3_transformDot(a, b) {
4663 return a[0] * b[0] + a[1] * b[1];
4665 function d3_transformNormalize(a) {
4666 var k = Math.sqrt(d3_transformDot(a, a));
4673 function d3_transformCombine(a, b, k) {
4678 var d3_transformIdentity = {
4686 d3.interpolateNumber = d3_interpolateNumber;
4687 function d3_interpolateNumber(a, b) {
4689 return function(t) {
4693 d3.interpolateTransform = d3_interpolateTransform;
4694 function d3_interpolateTransform(a, b) {
4695 var s = [], q = [], n, A = d3.transform(a), B = d3.transform(b), ta = A.translate, tb = B.translate, ra = A.rotate, rb = B.rotate, wa = A.skew, wb = B.skew, ka = A.scale, kb = B.scale;
4696 if (ta[0] != tb[0] || ta[1] != tb[1]) {
4697 s.push("translate(", null, ",", null, ")");
4700 x: d3_interpolateNumber(ta[0], tb[0])
4703 x: d3_interpolateNumber(ta[1], tb[1])
4705 } else if (tb[0] || tb[1]) {
4706 s.push("translate(" + tb + ")");
4711 if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
4713 i: s.push(s.pop() + "rotate(", null, ")") - 2,
4714 x: d3_interpolateNumber(ra, rb)
4717 s.push(s.pop() + "rotate(" + rb + ")");
4721 i: s.push(s.pop() + "skewX(", null, ")") - 2,
4722 x: d3_interpolateNumber(wa, wb)
4725 s.push(s.pop() + "skewX(" + wb + ")");
4727 if (ka[0] != kb[0] || ka[1] != kb[1]) {
4728 n = s.push(s.pop() + "scale(", null, ",", null, ")");
4731 x: d3_interpolateNumber(ka[0], kb[0])
4734 x: d3_interpolateNumber(ka[1], kb[1])
4736 } else if (kb[0] != 1 || kb[1] != 1) {
4737 s.push(s.pop() + "scale(" + kb + ")");
4740 return function(t) {
4742 while (++i < n) s[(o = q[i]).i] = o.x(t);
4746 d3.interpolateObject = d3_interpolateObject;
4747 function d3_interpolateObject(a, b) {
4748 var i = {}, c = {}, k;
4751 i[k] = d3_interpolateByName(k)(a[k], b[k]);
4761 return function(t) {
4762 for (k in i) c[k] = i[k](t);
4766 d3.interpolateString = d3_interpolateString;
4767 function d3_interpolateString(a, b) {
4768 var m, i, j, s0 = 0, s1 = 0, s = [], q = [], n, o;
4769 a = a + "", b = b + "";
4770 d3_interpolate_number.lastIndex = 0;
4771 for (i = 0; m = d3_interpolate_number.exec(b); ++i) {
4772 if (m.index) s.push(b.substring(s0, s1 = m.index));
4778 s0 = d3_interpolate_number.lastIndex;
4780 if (s0 < b.length) s.push(b.substring(s0));
4781 for (i = 0, n = q.length; (m = d3_interpolate_number.exec(a)) && i < n; ++i) {
4785 if (s[o.i + 1] == null) {
4788 for (j = i + 1; j < n; ++j) q[j].i--;
4790 s[o.i - 1] += o.x + s[o.i + 1];
4792 for (j = i + 1; j < n; ++j) q[j].i -= 2;
4795 if (s[o.i + 1] == null) {
4798 s[o.i] = o.x + s[o.i + 1];
4799 s.splice(o.i + 1, 1);
4800 for (j = i + 1; j < n; ++j) q[j].i--;
4807 o.x = d3_interpolateNumber(parseFloat(m[0]), parseFloat(o.x));
4812 if (s[o.i + 1] == null) {
4815 s[o.i] = o.x + s[o.i + 1];
4816 s.splice(o.i + 1, 1);
4820 if (s.length === 1) {
4821 return s[0] == null ? q[0].x : function() {
4825 return function(t) {
4826 for (i = 0; i < n; ++i) s[(o = q[i]).i] = o.x(t);
4830 var d3_interpolate_number = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
4831 d3.interpolate = d3_interpolate;
4832 function d3_interpolate(a, b) {
4833 var i = d3.interpolators.length, f;
4834 while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
4837 function d3_interpolateByName(name) {
4838 return name == "transform" ? d3_interpolateTransform : d3_interpolate;
4840 d3.interpolators = [ function(a, b) {
4842 return (t === "string" || t !== typeof a ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_Color ? d3_interpolateRgb : t === "object" ? Array.isArray(b) ? d3_interpolateArray : d3_interpolateObject : d3_interpolateNumber)(a, b);
4844 d3.interpolateArray = d3_interpolateArray;
4845 function d3_interpolateArray(a, b) {
4846 var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
4847 for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
4848 for (;i < na; ++i) c[i] = a[i];
4849 for (;i < nb; ++i) c[i] = b[i];
4850 return function(t) {
4851 for (i = 0; i < n0; ++i) c[i] = x[i](t);
4855 var d3_ease_default = function() {
4858 var d3_ease = d3.map({
4859 linear: d3_ease_default,
4862 return d3_ease_quad;
4865 return d3_ease_cubic;
4873 circle: function() {
4874 return d3_ease_circle;
4876 elastic: d3_ease_elastic,
4878 bounce: function() {
4879 return d3_ease_bounce;
4882 var d3_ease_mode = d3.map({
4884 out: d3_ease_reverse,
4885 "in-out": d3_ease_reflect,
4886 "out-in": function(f) {
4887 return d3_ease_reflect(d3_ease_reverse(f));
4890 d3.ease = function(name) {
4891 var i = name.indexOf("-"), t = i >= 0 ? name.substring(0, i) : name, m = i >= 0 ? name.substring(i + 1) : "in";
4892 t = d3_ease.get(t) || d3_ease_default;
4893 m = d3_ease_mode.get(m) || d3_identity;
4894 return d3_ease_clamp(m(t.apply(null, Array.prototype.slice.call(arguments, 1))));
4896 function d3_ease_clamp(f) {
4897 return function(t) {
4898 return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
4901 function d3_ease_reverse(f) {
4902 return function(t) {
4903 return 1 - f(1 - t);
4906 function d3_ease_reflect(f) {
4907 return function(t) {
4908 return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
4911 function d3_ease_quad(t) {
4914 function d3_ease_cubic(t) {
4917 function d3_ease_cubicInOut(t) {
4918 if (t <= 0) return 0;
4919 if (t >= 1) return 1;
4920 var t2 = t * t, t3 = t2 * t;
4921 return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
4923 function d3_ease_poly(e) {
4924 return function(t) {
4925 return Math.pow(t, e);
4928 function d3_ease_sin(t) {
4929 return 1 - Math.cos(t * π / 2);
4931 function d3_ease_exp(t) {
4932 return Math.pow(2, 10 * (t - 1));
4934 function d3_ease_circle(t) {
4935 return 1 - Math.sqrt(1 - t * t);
4937 function d3_ease_elastic(a, p) {
4939 if (arguments.length < 2) p = .45;
4940 if (arguments.length) s = p / (2 * π) * Math.asin(1 / a); else a = 1, s = p / 4;
4941 return function(t) {
4942 return 1 + a * Math.pow(2, 10 * -t) * Math.sin((t - s) * 2 * π / p);
4945 function d3_ease_back(s) {
4946 if (!s) s = 1.70158;
4947 return function(t) {
4948 return t * t * ((s + 1) * t - s);
4951 function d3_ease_bounce(t) {
4952 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;
4954 d3.interpolateHcl = d3_interpolateHcl;
4955 function d3_interpolateHcl(a, b) {
4958 var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
4959 if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
4960 return function(t) {
4961 return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
4964 d3.interpolateHsl = d3_interpolateHsl;
4965 function d3_interpolateHsl(a, b) {
4968 var h0 = a.h, s0 = a.s, l0 = a.l, h1 = b.h - h0, s1 = b.s - s0, l1 = b.l - l0;
4969 if (h1 > 180) h1 -= 360; else if (h1 < -180) h1 += 360;
4970 return function(t) {
4971 return d3_hsl_rgb(h0 + h1 * t, s0 + s1 * t, l0 + l1 * t) + "";
4974 d3.interpolateLab = d3_interpolateLab;
4975 function d3_interpolateLab(a, b) {
4978 var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
4979 return function(t) {
4980 return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
4983 d3.interpolateRound = d3_interpolateRound;
4984 function d3_interpolateRound(a, b) {
4986 return function(t) {
4987 return Math.round(a + b * t);
4990 function d3_uninterpolateNumber(a, b) {
4991 b = b - (a = +a) ? 1 / (b - a) : 0;
4992 return function(x) {
4996 function d3_uninterpolateClamp(a, b) {
4997 b = b - (a = +a) ? 1 / (b - a) : 0;
4998 return function(x) {
4999 return Math.max(0, Math.min(1, (x - a) * b));
5003 d3.layout.bundle = function() {
5004 return function(links) {
5005 var paths = [], i = -1, n = links.length;
5006 while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
5010 function d3_layout_bundlePath(link) {
5011 var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
5012 while (start !== lca) {
5013 start = start.parent;
5016 var k = points.length;
5017 while (end !== lca) {
5018 points.splice(k, 0, end);
5023 function d3_layout_bundleAncestors(node) {
5024 var ancestors = [], parent = node.parent;
5025 while (parent != null) {
5026 ancestors.push(node);
5028 parent = parent.parent;
5030 ancestors.push(node);
5033 function d3_layout_bundleLeastCommonAncestor(a, b) {
5034 if (a === b) return a;
5035 var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
5036 while (aNode === bNode) {
5038 aNode = aNodes.pop();
5039 bNode = bNodes.pop();
5043 d3.layout.chord = function() {
5044 var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
5045 function relayout() {
5046 var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
5056 subgroupIndex.push(d3.range(n));
5060 groupIndex.sort(function(a, b) {
5061 return sortGroups(groupSums[a], groupSums[b]);
5064 if (sortSubgroups) {
5065 subgroupIndex.forEach(function(d, i) {
5066 d.sort(function(a, b) {
5067 return sortSubgroups(matrix[i][a], matrix[i][b]);
5071 k = (2 * π - padding * n) / k;
5076 var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
5077 subgroups[di + "-" + dj] = {
5097 var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
5098 if (source.value || target.value) {
5099 chords.push(source.value < target.value ? {
5109 if (sortChords) resort();
5112 chords.sort(function(a, b) {
5113 return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
5116 chord.matrix = function(x) {
5117 if (!arguments.length) return matrix;
5118 n = (matrix = x) && matrix.length;
5119 chords = groups = null;
5122 chord.padding = function(x) {
5123 if (!arguments.length) return padding;
5125 chords = groups = null;
5128 chord.sortGroups = function(x) {
5129 if (!arguments.length) return sortGroups;
5131 chords = groups = null;
5134 chord.sortSubgroups = function(x) {
5135 if (!arguments.length) return sortSubgroups;
5140 chord.sortChords = function(x) {
5141 if (!arguments.length) return sortChords;
5143 if (chords) resort();
5146 chord.chords = function() {
5147 if (!chords) relayout();
5150 chord.groups = function() {
5151 if (!groups) relayout();
5156 d3.layout.force = function() {
5157 var force = {}, event = d3.dispatch("start", "tick", "end"), size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, gravity = .1, theta = .8, nodes = [], links = [], distances, strengths, charges;
5158 function repulse(node) {
5159 return function(quad, x1, _, x2) {
5160 if (quad.point !== node) {
5161 var dx = quad.cx - node.x, dy = quad.cy - node.y, dn = 1 / Math.sqrt(dx * dx + dy * dy);
5162 if ((x2 - x1) * dn < theta) {
5163 var k = quad.charge * dn * dn;
5168 if (quad.point && isFinite(dn)) {
5169 var k = quad.pointCharge * dn * dn;
5174 return !quad.charge;
5177 force.tick = function() {
5178 if ((alpha *= .99) < .005) {
5185 var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
5186 for (i = 0; i < m; ++i) {
5192 if (l = x * x + y * y) {
5193 l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
5196 t.x -= x * (k = s.weight / (t.weight + s.weight));
5198 s.x += x * (k = 1 - k);
5202 if (k = alpha * gravity) {
5206 if (k) while (++i < n) {
5208 o.x += (x - o.x) * k;
5209 o.y += (y - o.y) * k;
5213 d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
5216 if (!(o = nodes[i]).fixed) {
5217 q.visit(repulse(o));
5228 o.x -= (o.px - (o.px = o.x)) * friction;
5229 o.y -= (o.py - (o.py = o.y)) * friction;
5237 force.nodes = function(x) {
5238 if (!arguments.length) return nodes;
5242 force.links = function(x) {
5243 if (!arguments.length) return links;
5247 force.size = function(x) {
5248 if (!arguments.length) return size;
5252 force.linkDistance = function(x) {
5253 if (!arguments.length) return linkDistance;
5254 linkDistance = typeof x === "function" ? x : +x;
5257 force.distance = force.linkDistance;
5258 force.linkStrength = function(x) {
5259 if (!arguments.length) return linkStrength;
5260 linkStrength = typeof x === "function" ? x : +x;
5263 force.friction = function(x) {
5264 if (!arguments.length) return friction;
5268 force.charge = function(x) {
5269 if (!arguments.length) return charge;
5270 charge = typeof x === "function" ? x : +x;
5273 force.gravity = function(x) {
5274 if (!arguments.length) return gravity;
5278 force.theta = function(x) {
5279 if (!arguments.length) return theta;
5283 force.alpha = function(x) {
5284 if (!arguments.length) return alpha;
5287 if (x > 0) alpha = x; else alpha = 0;
5293 d3.timer(force.tick);
5297 force.start = function() {
5298 var i, j, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
5299 for (i = 0; i < n; ++i) {
5300 (o = nodes[i]).index = i;
5303 for (i = 0; i < m; ++i) {
5305 if (typeof o.source == "number") o.source = nodes[o.source];
5306 if (typeof o.target == "number") o.target = nodes[o.target];
5310 for (i = 0; i < n; ++i) {
5312 if (isNaN(o.x)) o.x = position("x", w);
5313 if (isNaN(o.y)) o.y = position("y", h);
5314 if (isNaN(o.px)) o.px = o.x;
5315 if (isNaN(o.py)) o.py = o.y;
5318 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;
5320 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;
5322 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;
5323 function position(dimension, size) {
5324 var neighbors = neighbor(i), j = -1, m = neighbors.length, x;
5325 while (++j < m) if (!isNaN(x = neighbors[j][dimension])) return x;
5326 return Math.random() * size;
5328 function neighbor() {
5331 for (j = 0; j < n; ++j) {
5334 for (j = 0; j < m; ++j) {
5336 neighbors[o.source.index].push(o.target);
5337 neighbors[o.target.index].push(o.source);
5340 return neighbors[i];
5342 return force.resume();
5344 force.resume = function() {
5345 return force.alpha(.1);
5347 force.stop = function() {
5348 return force.alpha(0);
5350 force.drag = function() {
5351 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);
5352 if (!arguments.length) return drag;
5353 this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
5355 function dragmove(d) {
5356 d.px = d3.event.x, d.py = d3.event.y;
5359 return d3.rebind(force, event, "on");
5361 function d3_layout_forceDragstart(d) {
5364 function d3_layout_forceDragend(d) {
5367 function d3_layout_forceMouseover(d) {
5369 d.px = d.x, d.py = d.y;
5371 function d3_layout_forceMouseout(d) {
5374 function d3_layout_forceAccumulate(quad, alpha, charges) {
5378 var nodes = quad.nodes, n = nodes.length, i = -1, c;
5381 if (c == null) continue;
5382 d3_layout_forceAccumulate(c, alpha, charges);
5383 quad.charge += c.charge;
5384 cx += c.charge * c.cx;
5385 cy += c.charge * c.cy;
5390 quad.point.x += Math.random() - .5;
5391 quad.point.y += Math.random() - .5;
5393 var k = alpha * charges[quad.point.index];
5394 quad.charge += quad.pointCharge = k;
5395 cx += k * quad.point.x;
5396 cy += k * quad.point.y;
5398 quad.cx = cx / quad.charge;
5399 quad.cy = cy / quad.charge;
5401 var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1;
5402 d3.layout.hierarchy = function() {
5403 var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
5404 function recurse(node, depth, nodes) {
5405 var childs = children.call(hierarchy, node, depth);
5408 if (childs && (n = childs.length)) {
5409 var i = -1, n, c = node.children = [], v = 0, j = depth + 1, d;
5411 d = recurse(childs[i], j, nodes);
5416 if (sort) c.sort(sort);
5417 if (value) node.value = v;
5419 node.value = +value.call(hierarchy, node, depth) || 0;
5423 function revalue(node, depth) {
5424 var children = node.children, v = 0;
5425 if (children && (n = children.length)) {
5426 var i = -1, n, j = depth + 1;
5427 while (++i < n) v += revalue(children[i], j);
5429 v = +value.call(hierarchy, node, depth) || 0;
5431 if (value) node.value = v;
5434 function hierarchy(d) {
5436 recurse(d, 0, nodes);
5439 hierarchy.sort = function(x) {
5440 if (!arguments.length) return sort;
5444 hierarchy.children = function(x) {
5445 if (!arguments.length) return children;
5449 hierarchy.value = function(x) {
5450 if (!arguments.length) return value;
5454 hierarchy.revalue = function(root) {
5460 function d3_layout_hierarchyRebind(object, hierarchy) {
5461 d3.rebind(object, hierarchy, "sort", "children", "value");
5462 object.nodes = object;
5463 object.links = d3_layout_hierarchyLinks;
5466 function d3_layout_hierarchyChildren(d) {
5469 function d3_layout_hierarchyValue(d) {
5472 function d3_layout_hierarchySort(a, b) {
5473 return b.value - a.value;
5475 function d3_layout_hierarchyLinks(nodes) {
5476 return d3.merge(nodes.map(function(parent) {
5477 return (parent.children || []).map(function(child) {
5485 d3.layout.partition = function() {
5486 var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
5487 function position(node, x, dx, dy) {
5488 var children = node.children;
5490 node.y = node.depth * dy;
5493 if (children && (n = children.length)) {
5494 var i = -1, n, c, d;
5495 dx = node.value ? dx / node.value : 0;
5497 position(c = children[i], x, d = c.value * dx, dy);
5502 function depth(node) {
5503 var children = node.children, d = 0;
5504 if (children && (n = children.length)) {
5506 while (++i < n) d = Math.max(d, depth(children[i]));
5510 function partition(d, i) {
5511 var nodes = hierarchy.call(this, d, i);
5512 position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
5515 partition.size = function(x) {
5516 if (!arguments.length) return size;
5520 return d3_layout_hierarchyRebind(partition, hierarchy);
5522 d3.layout.pie = function() {
5523 var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = 2 * π;
5524 function pie(data) {
5525 var values = data.map(function(d, i) {
5526 return +value.call(pie, d, i);
5528 var a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle);
5529 var k = ((typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a) / d3.sum(values);
5530 var index = d3.range(data.length);
5531 if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
5532 return values[j] - values[i];
5533 } : function(i, j) {
5534 return sort(data[i], data[j]);
5537 index.forEach(function(i) {
5541 value: d = values[i],
5543 endAngle: a += d * k
5548 pie.value = function(x) {
5549 if (!arguments.length) return value;
5553 pie.sort = function(x) {
5554 if (!arguments.length) return sort;
5558 pie.startAngle = function(x) {
5559 if (!arguments.length) return startAngle;
5563 pie.endAngle = function(x) {
5564 if (!arguments.length) return endAngle;
5570 var d3_layout_pieSortByValue = {};
5571 d3.layout.stack = function() {
5572 var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
5573 function stack(data, index) {
5574 var series = data.map(function(d, i) {
5575 return values.call(stack, d, i);
5577 var points = series.map(function(d) {
5578 return d.map(function(v, i) {
5579 return [ x.call(stack, v, i), y.call(stack, v, i) ];
5582 var orders = order.call(stack, points, index);
5583 series = d3.permute(series, orders);
5584 points = d3.permute(points, orders);
5585 var offsets = offset.call(stack, points, index);
5586 var n = series.length, m = series[0].length, i, j, o;
5587 for (j = 0; j < m; ++j) {
5588 out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
5589 for (i = 1; i < n; ++i) {
5590 out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
5595 stack.values = function(x) {
5596 if (!arguments.length) return values;
5600 stack.order = function(x) {
5601 if (!arguments.length) return order;
5602 order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
5605 stack.offset = function(x) {
5606 if (!arguments.length) return offset;
5607 offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
5610 stack.x = function(z) {
5611 if (!arguments.length) return x;
5615 stack.y = function(z) {
5616 if (!arguments.length) return y;
5620 stack.out = function(z) {
5621 if (!arguments.length) return out;
5627 function d3_layout_stackX(d) {
5630 function d3_layout_stackY(d) {
5633 function d3_layout_stackOut(d, y0, y) {
5637 var d3_layout_stackOrders = d3.map({
5638 "inside-out": function(data) {
5639 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) {
5640 return max[a] - max[b];
5641 }), top = 0, bottom = 0, tops = [], bottoms = [];
5642 for (i = 0; i < n; ++i) {
5652 return bottoms.reverse().concat(tops);
5654 reverse: function(data) {
5655 return d3.range(data.length).reverse();
5657 "default": d3_layout_stackOrderDefault
5659 var d3_layout_stackOffsets = d3.map({
5660 silhouette: function(data) {
5661 var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
5662 for (j = 0; j < m; ++j) {
5663 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
5664 if (o > max) max = o;
5667 for (j = 0; j < m; ++j) {
5668 y0[j] = (max - sums[j]) / 2;
5672 wiggle: function(data) {
5673 var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
5675 for (j = 1; j < m; ++j) {
5676 for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
5677 for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
5678 for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
5679 s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
5681 s2 += s3 * data[i][j][1];
5683 y0[j] = o -= s1 ? s2 / s1 * dx : 0;
5686 for (j = 0; j < m; ++j) y0[j] -= o0;
5689 expand: function(data) {
5690 var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
5691 for (j = 0; j < m; ++j) {
5692 for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
5693 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;
5695 for (j = 0; j < m; ++j) y0[j] = 0;
5698 zero: d3_layout_stackOffsetZero
5700 function d3_layout_stackOrderDefault(data) {
5701 return d3.range(data.length);
5703 function d3_layout_stackOffsetZero(data) {
5704 var j = -1, m = data[0].length, y0 = [];
5705 while (++j < m) y0[j] = 0;
5708 function d3_layout_stackMaxIndex(array) {
5709 var i = 1, j = 0, v = array[0][1], k, n = array.length;
5711 if ((k = array[i][1]) > v) {
5718 function d3_layout_stackReduceSum(d) {
5719 return d.reduce(d3_layout_stackSum, 0);
5721 function d3_layout_stackSum(p, d) {
5724 d3.layout.histogram = function() {
5725 var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
5726 function histogram(data, i) {
5727 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;
5730 bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
5737 if (x >= range[0] && x <= range[1]) {
5738 bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
5746 histogram.value = function(x) {
5747 if (!arguments.length) return valuer;
5751 histogram.range = function(x) {
5752 if (!arguments.length) return ranger;
5753 ranger = d3_functor(x);
5756 histogram.bins = function(x) {
5757 if (!arguments.length) return binner;
5758 binner = typeof x === "number" ? function(range) {
5759 return d3_layout_histogramBinFixed(range, x);
5763 histogram.frequency = function(x) {
5764 if (!arguments.length) return frequency;
5770 function d3_layout_histogramBinSturges(range, values) {
5771 return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
5773 function d3_layout_histogramBinFixed(range, n) {
5774 var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
5775 while (++x <= n) f[x] = m * x + b;
5778 function d3_layout_histogramRange(values) {
5779 return [ d3.min(values), d3.max(values) ];
5781 d3.layout.tree = function() {
5782 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ];
5783 function tree(d, i) {
5784 var nodes = hierarchy.call(this, d, i), root = nodes[0];
5785 function firstWalk(node, previousSibling) {
5786 var children = node.children, layout = node._tree;
5787 if (children && (n = children.length)) {
5788 var n, firstChild = children[0], previousChild, ancestor = firstChild, child, i = -1;
5790 child = children[i];
5791 firstWalk(child, previousChild);
5792 ancestor = apportion(child, previousChild, ancestor);
5793 previousChild = child;
5795 d3_layout_treeShift(node);
5796 var midpoint = .5 * (firstChild._tree.prelim + child._tree.prelim);
5797 if (previousSibling) {
5798 layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
5799 layout.mod = layout.prelim - midpoint;
5801 layout.prelim = midpoint;
5804 if (previousSibling) {
5805 layout.prelim = previousSibling._tree.prelim + separation(node, previousSibling);
5809 function secondWalk(node, x) {
5810 node.x = node._tree.prelim + x;
5811 var children = node.children;
5812 if (children && (n = children.length)) {
5814 x += node._tree.mod;
5816 secondWalk(children[i], x);
5820 function apportion(node, previousSibling, ancestor) {
5821 if (previousSibling) {
5822 var vip = node, vop = node, vim = previousSibling, vom = node.parent.children[0], sip = vip._tree.mod, sop = vop._tree.mod, sim = vim._tree.mod, som = vom._tree.mod, shift;
5823 while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
5824 vom = d3_layout_treeLeft(vom);
5825 vop = d3_layout_treeRight(vop);
5826 vop._tree.ancestor = node;
5827 shift = vim._tree.prelim + sim - vip._tree.prelim - sip + separation(vim, vip);
5829 d3_layout_treeMove(d3_layout_treeAncestor(vim, node, ancestor), node, shift);
5833 sim += vim._tree.mod;
5834 sip += vip._tree.mod;
5835 som += vom._tree.mod;
5836 sop += vop._tree.mod;
5838 if (vim && !d3_layout_treeRight(vop)) {
5839 vop._tree.thread = vim;
5840 vop._tree.mod += sim - sop;
5842 if (vip && !d3_layout_treeLeft(vom)) {
5843 vom._tree.thread = vip;
5844 vom._tree.mod += sip - som;
5850 d3_layout_treeVisitAfter(root, function(node, previousSibling) {
5857 number: previousSibling ? previousSibling._tree.number + 1 : 0
5861 secondWalk(root, -root._tree.prelim);
5862 var left = d3_layout_treeSearch(root, d3_layout_treeLeftmost), right = d3_layout_treeSearch(root, d3_layout_treeRightmost), deep = d3_layout_treeSearch(root, d3_layout_treeDeepest), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2, y1 = deep.depth || 1;
5863 d3_layout_treeVisitAfter(root, function(node) {
5864 node.x = (node.x - x0) / (x1 - x0) * size[0];
5865 node.y = node.depth / y1 * size[1];
5870 tree.separation = function(x) {
5871 if (!arguments.length) return separation;
5875 tree.size = function(x) {
5876 if (!arguments.length) return size;
5880 return d3_layout_hierarchyRebind(tree, hierarchy);
5882 function d3_layout_treeSeparation(a, b) {
5883 return a.parent == b.parent ? 1 : 2;
5885 function d3_layout_treeLeft(node) {
5886 var children = node.children;
5887 return children && children.length ? children[0] : node._tree.thread;
5889 function d3_layout_treeRight(node) {
5890 var children = node.children, n;
5891 return children && (n = children.length) ? children[n - 1] : node._tree.thread;
5893 function d3_layout_treeSearch(node, compare) {
5894 var children = node.children;
5895 if (children && (n = children.length)) {
5896 var child, n, i = -1;
5898 if (compare(child = d3_layout_treeSearch(children[i], compare), node) > 0) {
5905 function d3_layout_treeRightmost(a, b) {
5908 function d3_layout_treeLeftmost(a, b) {
5911 function d3_layout_treeDeepest(a, b) {
5912 return a.depth - b.depth;
5914 function d3_layout_treeVisitAfter(node, callback) {
5915 function visit(node, previousSibling) {
5916 var children = node.children;
5917 if (children && (n = children.length)) {
5918 var child, previousChild = null, i = -1, n;
5920 child = children[i];
5921 visit(child, previousChild);
5922 previousChild = child;
5925 callback(node, previousSibling);
5929 function d3_layout_treeShift(node) {
5930 var shift = 0, change = 0, children = node.children, i = children.length, child;
5932 child = children[i]._tree;
5933 child.prelim += shift;
5935 shift += child.shift + (change += child.change);
5938 function d3_layout_treeMove(ancestor, node, shift) {
5939 ancestor = ancestor._tree;
5941 var change = shift / (node.number - ancestor.number);
5942 ancestor.change += change;
5943 node.change -= change;
5944 node.shift += shift;
5945 node.prelim += shift;
5948 function d3_layout_treeAncestor(vim, node, ancestor) {
5949 return vim._tree.ancestor.parent == node.parent ? vim._tree.ancestor : ancestor;
5951 d3.layout.pack = function() {
5952 var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ];
5953 function pack(d, i) {
5954 var nodes = hierarchy.call(this, d, i), root = nodes[0];
5957 d3_layout_treeVisitAfter(root, function(d) {
5958 d.r = Math.sqrt(d.value);
5960 d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
5961 var w = size[0], h = size[1], k = Math.max(2 * root.r / w, 2 * root.r / h);
5963 var dr = padding * k / 2;
5964 d3_layout_treeVisitAfter(root, function(d) {
5967 d3_layout_treeVisitAfter(root, d3_layout_packSiblings);
5968 d3_layout_treeVisitAfter(root, function(d) {
5971 k = Math.max(2 * root.r / w, 2 * root.r / h);
5973 d3_layout_packTransform(root, w / 2, h / 2, 1 / k);
5976 pack.size = function(x) {
5977 if (!arguments.length) return size;
5981 pack.padding = function(_) {
5982 if (!arguments.length) return padding;
5986 return d3_layout_hierarchyRebind(pack, hierarchy);
5988 function d3_layout_packSort(a, b) {
5989 return a.value - b.value;
5991 function d3_layout_packInsert(a, b) {
5992 var c = a._pack_next;
5998 function d3_layout_packSplice(a, b) {
6002 function d3_layout_packIntersects(a, b) {
6003 var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
6004 return dr * dr - dx * dx - dy * dy > .001;
6006 function d3_layout_packSiblings(node) {
6007 if (!(nodes = node.children) || !(n = nodes.length)) return;
6008 var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
6009 function bound(node) {
6010 xMin = Math.min(node.x - node.r, xMin);
6011 xMax = Math.max(node.x + node.r, xMax);
6012 yMin = Math.min(node.y - node.r, yMin);
6013 yMax = Math.max(node.y + node.r, yMax);
6015 nodes.forEach(d3_layout_packLink);
6027 d3_layout_packPlace(a, b, c);
6029 d3_layout_packInsert(a, c);
6031 d3_layout_packInsert(c, b);
6033 for (i = 3; i < n; i++) {
6034 d3_layout_packPlace(a, b, c = nodes[i]);
6035 var isect = 0, s1 = 1, s2 = 1;
6036 for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
6037 if (d3_layout_packIntersects(j, c)) {
6043 for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
6044 if (d3_layout_packIntersects(k, c)) {
6050 if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
6053 d3_layout_packInsert(a, c);
6060 var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
6061 for (i = 0; i < n; i++) {
6065 cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
6068 nodes.forEach(d3_layout_packUnlink);
6070 function d3_layout_packLink(node) {
6071 node._pack_next = node._pack_prev = node;
6073 function d3_layout_packUnlink(node) {
6074 delete node._pack_next;
6075 delete node._pack_prev;
6077 function d3_layout_packTransform(node, x, y, k) {
6078 var children = node.children;
6079 node.x = x += k * node.x;
6080 node.y = y += k * node.y;
6083 var i = -1, n = children.length;
6084 while (++i < n) d3_layout_packTransform(children[i], x, y, k);
6087 function d3_layout_packPlace(a, b, c) {
6088 var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
6089 if (db && (dx || dy)) {
6090 var da = b.r + c.r, dc = dx * dx + dy * dy;
6093 var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
6094 c.x = a.x + x * dx + y * dy;
6095 c.y = a.y + x * dy - y * dx;
6101 d3.layout.cluster = function() {
6102 var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ];
6103 function cluster(d, i) {
6104 var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
6105 d3_layout_treeVisitAfter(root, function(node) {
6106 var children = node.children;
6107 if (children && children.length) {
6108 node.x = d3_layout_clusterX(children);
6109 node.y = d3_layout_clusterY(children);
6111 node.x = previousNode ? x += separation(node, previousNode) : 0;
6113 previousNode = node;
6116 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;
6117 d3_layout_treeVisitAfter(root, function(node) {
6118 node.x = (node.x - x0) / (x1 - x0) * size[0];
6119 node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
6123 cluster.separation = function(x) {
6124 if (!arguments.length) return separation;
6128 cluster.size = function(x) {
6129 if (!arguments.length) return size;
6133 return d3_layout_hierarchyRebind(cluster, hierarchy);
6135 function d3_layout_clusterY(children) {
6136 return 1 + d3.max(children, function(child) {
6140 function d3_layout_clusterX(children) {
6141 return children.reduce(function(x, child) {
6143 }, 0) / children.length;
6145 function d3_layout_clusterLeft(node) {
6146 var children = node.children;
6147 return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
6149 function d3_layout_clusterRight(node) {
6150 var children = node.children, n;
6151 return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
6153 d3.layout.treemap = function() {
6154 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));
6155 function scale(children, k) {
6156 var i = -1, n = children.length, child, area;
6158 area = (child = children[i]).value * (k < 0 ? 0 : k);
6159 child.area = isNaN(area) || area <= 0 ? 0 : area;
6162 function squarify(node) {
6163 var children = node.children;
6164 if (children && children.length) {
6165 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;
6166 scale(remaining, rect.dx * rect.dy / node.value);
6168 while ((n = remaining.length) > 0) {
6169 row.push(child = remaining[n - 1]);
6170 row.area += child.area;
6171 if (mode !== "squarify" || (score = worst(row, u)) <= best) {
6175 row.area -= row.pop().area;
6176 position(row, u, rect, false);
6177 u = Math.min(rect.dx, rect.dy);
6178 row.length = row.area = 0;
6183 position(row, u, rect, true);
6184 row.length = row.area = 0;
6186 children.forEach(squarify);
6189 function stickify(node) {
6190 var children = node.children;
6191 if (children && children.length) {
6192 var rect = pad(node), remaining = children.slice(), child, row = [];
6193 scale(remaining, rect.dx * rect.dy / node.value);
6195 while (child = remaining.pop()) {
6197 row.area += child.area;
6198 if (child.z != null) {
6199 position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
6200 row.length = row.area = 0;
6203 children.forEach(stickify);
6206 function worst(row, u) {
6207 var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
6209 if (!(r = row[i].area)) continue;
6210 if (r < rmin) rmin = r;
6211 if (r > rmax) rmax = r;
6215 return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
6217 function position(row, u, rect, flush) {
6218 var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
6220 if (flush || v > rect.dy) v = rect.dy;
6226 x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
6229 o.dx += rect.x + rect.dx - x;
6233 if (flush || v > rect.dx) v = rect.dx;
6239 y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
6242 o.dy += rect.y + rect.dy - y;
6247 function treemap(d) {
6248 var nodes = stickies || hierarchy(d), root = nodes[0];
6253 if (stickies) hierarchy.revalue(root);
6254 scale([ root ], root.dx * root.dy / root.value);
6255 (stickies ? stickify : squarify)(root);
6256 if (sticky) stickies = nodes;
6259 treemap.size = function(x) {
6260 if (!arguments.length) return size;
6264 treemap.padding = function(x) {
6265 if (!arguments.length) return padding;
6266 function padFunction(node) {
6267 var p = x.call(treemap, node, node.depth);
6268 return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
6270 function padConstant(node) {
6271 return d3_layout_treemapPad(node, x);
6274 pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
6275 padConstant) : padConstant;
6278 treemap.round = function(x) {
6279 if (!arguments.length) return round != Number;
6280 round = x ? Math.round : Number;
6283 treemap.sticky = function(x) {
6284 if (!arguments.length) return sticky;
6289 treemap.ratio = function(x) {
6290 if (!arguments.length) return ratio;
6294 treemap.mode = function(x) {
6295 if (!arguments.length) return mode;
6299 return d3_layout_hierarchyRebind(treemap, hierarchy);
6301 function d3_layout_treemapPadNull(node) {
6309 function d3_layout_treemapPad(node, padding) {
6310 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];
6327 normal: function(µ, σ) {
6328 var n = arguments.length;
6334 x = Math.random() * 2 - 1;
6335 y = Math.random() * 2 - 1;
6337 } while (!r || r > 1);
6338 return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
6341 logNormal: function() {
6342 var random = d3.random.normal.apply(d3, arguments);
6344 return Math.exp(random());
6347 irwinHall: function(m) {
6349 for (var s = 0, j = 0; j < m; j++) s += Math.random();
6355 function d3_scaleExtent(domain) {
6356 var start = domain[0], stop = domain[domain.length - 1];
6357 return start < stop ? [ start, stop ] : [ stop, start ];
6359 function d3_scaleRange(scale) {
6360 return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
6362 function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
6363 var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
6364 return function(x) {
6368 function d3_scale_nice(domain, nice) {
6369 var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
6371 dx = i0, i0 = i1, i1 = dx;
6372 dx = x0, x0 = x1, x1 = dx;
6374 if (nice = nice(x1 - x0)) {
6375 domain[i0] = nice.floor(x0);
6376 domain[i1] = nice.ceil(x1);
6380 function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
6381 var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
6382 if (domain[k] < domain[0]) {
6383 domain = domain.slice().reverse();
6384 range = range.slice().reverse();
6387 u.push(uninterpolate(domain[j - 1], domain[j]));
6388 i.push(interpolate(range[j - 1], range[j]));
6390 return function(x) {
6391 var j = d3.bisect(domain, x, 1, k) - 1;
6392 return i[j](u[j](x));
6395 d3.scale.linear = function() {
6396 return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
6398 function d3_scale_linear(domain, range, interpolate, clamp) {
6400 function rescale() {
6401 var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
6402 output = linear(domain, range, uninterpolate, interpolate);
6403 input = linear(range, domain, uninterpolate, d3_interpolate);
6409 scale.invert = function(y) {
6412 scale.domain = function(x) {
6413 if (!arguments.length) return domain;
6414 domain = x.map(Number);
6417 scale.range = function(x) {
6418 if (!arguments.length) return range;
6422 scale.rangeRound = function(x) {
6423 return scale.range(x).interpolate(d3_interpolateRound);
6425 scale.clamp = function(x) {
6426 if (!arguments.length) return clamp;
6430 scale.interpolate = function(x) {
6431 if (!arguments.length) return interpolate;
6435 scale.ticks = function(m) {
6436 return d3_scale_linearTicks(domain, m);
6438 scale.tickFormat = function(m, format) {
6439 return d3_scale_linearTickFormat(domain, m, format);
6441 scale.nice = function() {
6442 d3_scale_nice(domain, d3_scale_linearNice);
6445 scale.copy = function() {
6446 return d3_scale_linear(domain, range, interpolate, clamp);
6450 function d3_scale_linearRebind(scale, linear) {
6451 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
6453 function d3_scale_linearNice(dx) {
6454 dx = Math.pow(10, Math.round(Math.log(dx) / Math.LN10) - 1);
6456 floor: function(x) {
6457 return Math.floor(x / dx) * dx;
6460 return Math.ceil(x / dx) * dx;
6464 function d3_scale_linearTickRange(domain, m) {
6465 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;
6466 if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
6467 extent[0] = Math.ceil(extent[0] / step) * step;
6468 extent[1] = Math.floor(extent[1] / step) * step + step * .5;
6472 function d3_scale_linearTicks(domain, m) {
6473 return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
6475 function d3_scale_linearTickFormat(domain, m, format) {
6476 var precision = -Math.floor(Math.log(d3_scale_linearTickRange(domain, m)[2]) / Math.LN10 + .01);
6477 return d3.format(format ? format.replace(d3_format_re, function(a, b, c, d, e, f, g, h, i, j) {
6478 return [ b, c, d, e, f, g, h, i || "." + (precision - (j === "%") * 2), j ].join("");
6479 }) : ",." + precision + "f");
6481 d3.scale.log = function() {
6482 return d3_scale_log(d3.scale.linear().domain([ 0, Math.LN10 ]), 10, d3_scale_logp, d3_scale_powp);
6484 function d3_scale_log(linear, base, log, pow) {
6486 return linear(log(x));
6488 scale.invert = function(x) {
6489 return pow(linear.invert(x));
6491 scale.domain = function(x) {
6492 if (!arguments.length) return linear.domain().map(pow);
6493 if (x[0] < 0) log = d3_scale_logn, pow = d3_scale_pown; else log = d3_scale_logp,
6494 pow = d3_scale_powp;
6495 linear.domain(x.map(log));
6498 scale.base = function(_) {
6499 if (!arguments.length) return base;
6503 scale.nice = function() {
6504 linear.domain(d3_scale_nice(linear.domain(), d3_scale_logNice(base)));
6507 scale.ticks = function() {
6508 var extent = d3_scaleExtent(linear.domain()), ticks = [];
6509 if (extent.every(isFinite)) {
6510 var b = Math.log(base), i = Math.floor(extent[0] / b), j = Math.ceil(extent[1] / b), u = pow(extent[0]), v = pow(extent[1]), n = base % 1 ? 2 : base;
6511 if (log === d3_scale_logn) {
6512 ticks.push(-Math.pow(base, -i));
6513 for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(-Math.pow(base, -i) * k);
6515 for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(Math.pow(base, i) * k);
6516 ticks.push(Math.pow(base, i));
6518 for (i = 0; ticks[i] < u; i++) {}
6519 for (j = ticks.length; ticks[j - 1] > v; j--) {}
6520 ticks = ticks.slice(i, j);
6524 scale.tickFormat = function(n, format) {
6525 if (arguments.length < 2) format = d3_scale_logFormat;
6526 if (!arguments.length) return format;
6527 var b = Math.log(base), k = Math.max(.1, n / scale.ticks().length), f = log === d3_scale_logn ? (e = -1e-12,
6528 Math.floor) : (e = 1e-12, Math.ceil), e;
6529 return function(d) {
6530 return d / pow(b * f(log(d) / b + e)) <= k ? format(d) : "";
6533 scale.copy = function() {
6534 return d3_scale_log(linear.copy(), base, log, pow);
6536 return d3_scale_linearRebind(scale, linear);
6538 var d3_scale_logFormat = d3.format(".0e");
6539 function d3_scale_logp(x) {
6540 return Math.log(x < 0 ? 0 : x);
6542 function d3_scale_powp(x) {
6545 function d3_scale_logn(x) {
6546 return -Math.log(x > 0 ? 0 : -x);
6548 function d3_scale_pown(x) {
6549 return -Math.exp(-x);
6551 function d3_scale_logNice(base) {
6552 base = Math.log(base);
6554 floor: function(x) {
6555 return Math.floor(x / base) * base;
6558 return Math.ceil(x / base) * base;
6565 d3.scale.pow = function() {
6566 return d3_scale_pow(d3.scale.linear(), 1);
6568 function d3_scale_pow(linear, exponent) {
6569 var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
6571 return linear(powp(x));
6573 scale.invert = function(x) {
6574 return powb(linear.invert(x));
6576 scale.domain = function(x) {
6577 if (!arguments.length) return linear.domain().map(powb);
6578 linear.domain(x.map(powp));
6581 scale.ticks = function(m) {
6582 return d3_scale_linearTicks(scale.domain(), m);
6584 scale.tickFormat = function(m, format) {
6585 return d3_scale_linearTickFormat(scale.domain(), m, format);
6587 scale.nice = function() {
6588 return scale.domain(d3_scale_nice(scale.domain(), d3_scale_linearNice));
6590 scale.exponent = function(x) {
6591 if (!arguments.length) return exponent;
6592 var domain = scale.domain();
6593 powp = d3_scale_powPow(exponent = x);
6594 powb = d3_scale_powPow(1 / exponent);
6595 return scale.domain(domain);
6597 scale.copy = function() {
6598 return d3_scale_pow(linear.copy(), exponent);
6600 return d3_scale_linearRebind(scale, linear);
6602 function d3_scale_powPow(e) {
6603 return function(x) {
6604 return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
6607 d3.scale.sqrt = function() {
6608 return d3.scale.pow().exponent(.5);
6610 d3.scale.ordinal = function() {
6611 return d3_scale_ordinal([], {
6616 function d3_scale_ordinal(domain, ranger) {
6617 var index, range, rangeBand;
6619 return range[((index.get(x) || index.set(x, domain.push(x))) - 1) % range.length];
6621 function steps(start, step) {
6622 return d3.range(domain.length).map(function(i) {
6623 return start + step * i;
6626 scale.domain = function(x) {
6627 if (!arguments.length) return domain;
6629 index = new d3_Map();
6630 var i = -1, n = x.length, xi;
6631 while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
6632 return scale[ranger.t].apply(scale, ranger.a);
6634 scale.range = function(x) {
6635 if (!arguments.length) return range;
6644 scale.rangePoints = function(x, padding) {
6645 if (arguments.length < 2) padding = 0;
6646 var start = x[0], stop = x[1], step = (stop - start) / (Math.max(1, domain.length - 1) + padding);
6647 range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step);
6655 scale.rangeBands = function(x, padding, outerPadding) {
6656 if (arguments.length < 2) padding = 0;
6657 if (arguments.length < 3) outerPadding = padding;
6658 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
6659 range = steps(start + step * outerPadding, step);
6660 if (reverse) range.reverse();
6661 rangeBand = step * (1 - padding);
6668 scale.rangeRoundBands = function(x, padding, outerPadding) {
6669 if (arguments.length < 2) padding = 0;
6670 if (arguments.length < 3) outerPadding = padding;
6671 var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding)), error = stop - start - (domain.length - padding) * step;
6672 range = steps(start + Math.round(error / 2), step);
6673 if (reverse) range.reverse();
6674 rangeBand = Math.round(step * (1 - padding));
6676 t: "rangeRoundBands",
6681 scale.rangeBand = function() {
6684 scale.rangeExtent = function() {
6685 return d3_scaleExtent(ranger.a[0]);
6687 scale.copy = function() {
6688 return d3_scale_ordinal(domain, ranger);
6690 return scale.domain(domain);
6692 d3.scale.category10 = function() {
6693 return d3.scale.ordinal().range(d3_category10);
6695 d3.scale.category20 = function() {
6696 return d3.scale.ordinal().range(d3_category20);
6698 d3.scale.category20b = function() {
6699 return d3.scale.ordinal().range(d3_category20b);
6701 d3.scale.category20c = function() {
6702 return d3.scale.ordinal().range(d3_category20c);
6704 var d3_category10 = [ "#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf" ];
6705 var d3_category20 = [ "#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c", "#98df8a", "#d62728", "#ff9896", "#9467bd", "#c5b0d5", "#8c564b", "#c49c94", "#e377c2", "#f7b6d2", "#7f7f7f", "#c7c7c7", "#bcbd22", "#dbdb8d", "#17becf", "#9edae5" ];
6706 var d3_category20b = [ "#393b79", "#5254a3", "#6b6ecf", "#9c9ede", "#637939", "#8ca252", "#b5cf6b", "#cedb9c", "#8c6d31", "#bd9e39", "#e7ba52", "#e7cb94", "#843c39", "#ad494a", "#d6616b", "#e7969c", "#7b4173", "#a55194", "#ce6dbd", "#de9ed6" ];
6707 var d3_category20c = [ "#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#e6550d", "#fd8d3c", "#fdae6b", "#fdd0a2", "#31a354", "#74c476", "#a1d99b", "#c7e9c0", "#756bb1", "#9e9ac8", "#bcbddc", "#dadaeb", "#636363", "#969696", "#bdbdbd", "#d9d9d9" ];
6708 d3.scale.quantile = function() {
6709 return d3_scale_quantile([], []);
6711 function d3_scale_quantile(domain, range) {
6713 function rescale() {
6714 var k = 0, q = range.length;
6716 while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
6720 if (isNaN(x = +x)) return NaN;
6721 return range[d3.bisect(thresholds, x)];
6723 scale.domain = function(x) {
6724 if (!arguments.length) return domain;
6725 domain = x.filter(function(d) {
6727 }).sort(d3.ascending);
6730 scale.range = function(x) {
6731 if (!arguments.length) return range;
6735 scale.quantiles = function() {
6738 scale.copy = function() {
6739 return d3_scale_quantile(domain, range);
6743 d3.scale.quantize = function() {
6744 return d3_scale_quantize(0, 1, [ 0, 1 ]);
6746 function d3_scale_quantize(x0, x1, range) {
6749 return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
6751 function rescale() {
6752 kx = range.length / (x1 - x0);
6753 i = range.length - 1;
6756 scale.domain = function(x) {
6757 if (!arguments.length) return [ x0, x1 ];
6759 x1 = +x[x.length - 1];
6762 scale.range = function(x) {
6763 if (!arguments.length) return range;
6767 scale.copy = function() {
6768 return d3_scale_quantize(x0, x1, range);
6772 d3.scale.threshold = function() {
6773 return d3_scale_threshold([ .5 ], [ 0, 1 ]);
6775 function d3_scale_threshold(domain, range) {
6777 return range[d3.bisect(domain, x)];
6779 scale.domain = function(_) {
6780 if (!arguments.length) return domain;
6784 scale.range = function(_) {
6785 if (!arguments.length) return range;
6789 scale.copy = function() {
6790 return d3_scale_threshold(domain, range);
6794 d3.scale.identity = function() {
6795 return d3_scale_identity([ 0, 1 ]);
6797 function d3_scale_identity(domain) {
6798 function identity(x) {
6801 identity.invert = identity;
6802 identity.domain = identity.range = function(x) {
6803 if (!arguments.length) return domain;
6804 domain = x.map(identity);
6807 identity.ticks = function(m) {
6808 return d3_scale_linearTicks(domain, m);
6810 identity.tickFormat = function(m, format) {
6811 return d3_scale_linearTickFormat(domain, m, format);
6813 identity.copy = function() {
6814 return d3_scale_identity(domain);
6818 d3.svg.arc = function() {
6819 var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
6821 var r0 = innerRadius.apply(this, arguments), r1 = outerRadius.apply(this, arguments), a0 = startAngle.apply(this, arguments) + d3_svg_arcOffset, a1 = endAngle.apply(this, arguments) + d3_svg_arcOffset, da = (a1 < a0 && (da = a0,
6822 a0 = a1, a1 = da), a1 - a0), df = da < π ? "0" : "1", c0 = Math.cos(a0), s0 = Math.sin(a0), c1 = Math.cos(a1), s1 = Math.sin(a1);
6823 return da >= d3_svg_arcMax ? r0 ? "M0," + r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + -r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + r1 + "M0," + r0 + "A" + r0 + "," + r0 + " 0 1,0 0," + -r0 + "A" + r0 + "," + r0 + " 0 1,0 0," + r0 + "Z" : "M0," + r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + -r1 + "A" + r1 + "," + r1 + " 0 1,1 0," + r1 + "Z" : r0 ? "M" + r1 * c0 + "," + r1 * s0 + "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1 + "L" + r0 * c1 + "," + r0 * s1 + "A" + r0 + "," + r0 + " 0 " + df + ",0 " + r0 * c0 + "," + r0 * s0 + "Z" : "M" + r1 * c0 + "," + r1 * s0 + "A" + r1 + "," + r1 + " 0 " + df + ",1 " + r1 * c1 + "," + r1 * s1 + "L0,0" + "Z";
6825 arc.innerRadius = function(v) {
6826 if (!arguments.length) return innerRadius;
6827 innerRadius = d3_functor(v);
6830 arc.outerRadius = function(v) {
6831 if (!arguments.length) return outerRadius;
6832 outerRadius = d3_functor(v);
6835 arc.startAngle = function(v) {
6836 if (!arguments.length) return startAngle;
6837 startAngle = d3_functor(v);
6840 arc.endAngle = function(v) {
6841 if (!arguments.length) return endAngle;
6842 endAngle = d3_functor(v);
6845 arc.centroid = function() {
6846 var r = (innerRadius.apply(this, arguments) + outerRadius.apply(this, arguments)) / 2, a = (startAngle.apply(this, arguments) + endAngle.apply(this, arguments)) / 2 + d3_svg_arcOffset;
6847 return [ Math.cos(a) * r, Math.sin(a) * r ];
6851 var d3_svg_arcOffset = -π / 2, d3_svg_arcMax = 2 * π - 1e-6;
6852 function d3_svg_arcInnerRadius(d) {
6853 return d.innerRadius;
6855 function d3_svg_arcOuterRadius(d) {
6856 return d.outerRadius;
6858 function d3_svg_arcStartAngle(d) {
6859 return d.startAngle;
6861 function d3_svg_arcEndAngle(d) {
6864 d3.svg.line.radial = function() {
6865 var line = d3_svg_line(d3_svg_lineRadial);
6866 line.radius = line.x, delete line.x;
6867 line.angle = line.y, delete line.y;
6870 function d3_svg_lineRadial(points) {
6871 var point, i = -1, n = points.length, r, a;
6875 a = point[1] + d3_svg_arcOffset;
6876 point[0] = r * Math.cos(a);
6877 point[1] = r * Math.sin(a);
6881 function d3_svg_area(projection) {
6882 var x0 = d3_svg_lineX, x1 = d3_svg_lineX, y0 = 0, y1 = d3_svg_lineY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
6883 function area(data) {
6884 var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
6886 } : d3_functor(x1), fy1 = y0 === y1 ? function() {
6888 } : d3_functor(y1), x, y;
6889 function segment() {
6890 segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
6893 if (defined.call(this, d = data[i], i)) {
6894 points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
6895 points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
6896 } else if (points0.length) {
6902 if (points0.length) segment();
6903 return segments.length ? segments.join("") : null;
6905 area.x = function(_) {
6906 if (!arguments.length) return x1;
6910 area.x0 = function(_) {
6911 if (!arguments.length) return x0;
6915 area.x1 = function(_) {
6916 if (!arguments.length) return x1;
6920 area.y = function(_) {
6921 if (!arguments.length) return y1;
6925 area.y0 = function(_) {
6926 if (!arguments.length) return y0;
6930 area.y1 = function(_) {
6931 if (!arguments.length) return y1;
6935 area.defined = function(_) {
6936 if (!arguments.length) return defined;
6940 area.interpolate = function(_) {
6941 if (!arguments.length) return interpolateKey;
6942 if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
6943 interpolateReverse = interpolate.reverse || interpolate;
6944 L = interpolate.closed ? "M" : "L";
6947 area.tension = function(_) {
6948 if (!arguments.length) return tension;
6954 d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
6955 d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
6956 d3.svg.area = function() {
6957 return d3_svg_area(d3_identity);
6959 d3.svg.area.radial = function() {
6960 var area = d3_svg_area(d3_svg_lineRadial);
6961 area.radius = area.x, delete area.x;
6962 area.innerRadius = area.x0, delete area.x0;
6963 area.outerRadius = area.x1, delete area.x1;
6964 area.angle = area.y, delete area.y;
6965 area.startAngle = area.y0, delete area.y0;
6966 area.endAngle = area.y1, delete area.y1;
6969 d3.svg.chord = function() {
6970 var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
6971 function chord(d, i) {
6972 var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
6973 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";
6975 function subgroup(self, f, d, i) {
6976 var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) + d3_svg_arcOffset, a1 = endAngle.call(self, subgroup, i) + d3_svg_arcOffset;
6981 p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
6982 p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
6985 function equals(a, b) {
6986 return a.a0 == b.a0 && a.a1 == b.a1;
6988 function arc(r, p, a) {
6989 return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
6991 function curve(r0, p0, r1, p1) {
6992 return "Q 0,0 " + p1;
6994 chord.radius = function(v) {
6995 if (!arguments.length) return radius;
6996 radius = d3_functor(v);
6999 chord.source = function(v) {
7000 if (!arguments.length) return source;
7001 source = d3_functor(v);
7004 chord.target = function(v) {
7005 if (!arguments.length) return target;
7006 target = d3_functor(v);
7009 chord.startAngle = function(v) {
7010 if (!arguments.length) return startAngle;
7011 startAngle = d3_functor(v);
7014 chord.endAngle = function(v) {
7015 if (!arguments.length) return endAngle;
7016 endAngle = d3_functor(v);
7021 function d3_svg_chordRadius(d) {
7024 d3.svg.diagonal = function() {
7025 var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
7026 function diagonal(d, i) {
7027 var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
7034 p = p.map(projection);
7035 return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
7037 diagonal.source = function(x) {
7038 if (!arguments.length) return source;
7039 source = d3_functor(x);
7042 diagonal.target = function(x) {
7043 if (!arguments.length) return target;
7044 target = d3_functor(x);
7047 diagonal.projection = function(x) {
7048 if (!arguments.length) return projection;
7054 function d3_svg_diagonalProjection(d) {
7055 return [ d.x, d.y ];
7057 d3.svg.diagonal.radial = function() {
7058 var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
7059 diagonal.projection = function(x) {
7060 return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
7064 function d3_svg_diagonalRadialProjection(projection) {
7066 var d = projection.apply(this, arguments), r = d[0], a = d[1] + d3_svg_arcOffset;
7067 return [ r * Math.cos(a), r * Math.sin(a) ];
7070 d3.svg.symbol = function() {
7071 var type = d3_svg_symbolType, size = d3_svg_symbolSize;
7072 function symbol(d, i) {
7073 return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
7075 symbol.type = function(x) {
7076 if (!arguments.length) return type;
7077 type = d3_functor(x);
7080 symbol.size = function(x) {
7081 if (!arguments.length) return size;
7082 size = d3_functor(x);
7087 function d3_svg_symbolSize() {
7090 function d3_svg_symbolType() {
7093 function d3_svg_symbolCircle(size) {
7094 var r = Math.sqrt(size / π);
7095 return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
7097 var d3_svg_symbols = d3.map({
7098 circle: d3_svg_symbolCircle,
7099 cross: function(size) {
7100 var r = Math.sqrt(size / 5) / 2;
7101 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";
7103 diamond: function(size) {
7104 var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
7105 return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
7107 square: function(size) {
7108 var r = Math.sqrt(size) / 2;
7109 return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
7111 "triangle-down": function(size) {
7112 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
7113 return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
7115 "triangle-up": function(size) {
7116 var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
7117 return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
7120 d3.svg.symbolTypes = d3_svg_symbols.keys();
7121 var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
7122 function d3_transition(groups, id) {
7123 d3_arraySubclass(groups, d3_transitionPrototype);
7127 var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit = {
7128 ease: d3_ease_cubicInOut,
7132 d3_transitionPrototype.call = d3_selectionPrototype.call;
7133 d3_transitionPrototype.empty = d3_selectionPrototype.empty;
7134 d3_transitionPrototype.node = d3_selectionPrototype.node;
7135 d3.transition = function(selection) {
7136 return arguments.length ? d3_transitionInheritId ? selection.transition() : selection : d3_selectionRoot.transition();
7138 d3.transition.prototype = d3_transitionPrototype;
7139 d3_transitionPrototype.select = function(selector) {
7140 var id = this.id, subgroups = [], subgroup, subnode, node;
7141 if (typeof selector !== "function") selector = d3_selection_selector(selector);
7142 for (var j = -1, m = this.length; ++j < m; ) {
7143 subgroups.push(subgroup = []);
7144 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
7145 if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i))) {
7146 if ("__data__" in node) subnode.__data__ = node.__data__;
7147 d3_transitionNode(subnode, i, id, node.__transition__[id]);
7148 subgroup.push(subnode);
7150 subgroup.push(null);
7154 return d3_transition(subgroups, id);
7156 d3_transitionPrototype.selectAll = function(selector) {
7157 var id = this.id, subgroups = [], subgroup, subnodes, node, subnode, transition;
7158 if (typeof selector !== "function") selector = d3_selection_selectorAll(selector);
7159 for (var j = -1, m = this.length; ++j < m; ) {
7160 for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
7161 if (node = group[i]) {
7162 transition = node.__transition__[id];
7163 subnodes = selector.call(node, node.__data__, i);
7164 subgroups.push(subgroup = []);
7165 for (var k = -1, o = subnodes.length; ++k < o; ) {
7166 d3_transitionNode(subnode = subnodes[k], k, id, transition);
7167 subgroup.push(subnode);
7172 return d3_transition(subgroups, id);
7174 d3_transitionPrototype.filter = function(filter) {
7175 var subgroups = [], subgroup, group, node;
7176 if (typeof filter !== "function") filter = d3_selection_filter(filter);
7177 for (var j = 0, m = this.length; j < m; j++) {
7178 subgroups.push(subgroup = []);
7179 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
7180 if ((node = group[i]) && filter.call(node, node.__data__, i)) {
7181 subgroup.push(node);
7185 return d3_transition(subgroups, this.id, this.time).ease(this.ease());
7187 d3_transitionPrototype.tween = function(name, tween) {
7189 if (arguments.length < 2) return this.node().__transition__[id].tween.get(name);
7190 return d3_selection_each(this, tween == null ? function(node) {
7191 node.__transition__[id].tween.remove(name);
7192 } : function(node) {
7193 node.__transition__[id].tween.set(name, tween);
7196 function d3_transition_tween(groups, name, value, tween) {
7198 return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
7199 node.__transition__[id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
7200 } : (value = tween(value), function(node) {
7201 node.__transition__[id].tween.set(name, value);
7204 d3_transitionPrototype.attr = function(nameNS, value) {
7205 if (arguments.length < 2) {
7206 for (value in nameNS) this.attr(value, nameNS[value]);
7209 var interpolate = d3_interpolateByName(nameNS), name = d3.ns.qualify(nameNS);
7210 function attrNull() {
7211 this.removeAttribute(name);
7213 function attrNullNS() {
7214 this.removeAttributeNS(name.space, name.local);
7216 return d3_transition_tween(this, "attr." + nameNS, value, function(b) {
7217 function attrString() {
7218 var a = this.getAttribute(name), i;
7219 return a !== b && (i = interpolate(a, b), function(t) {
7220 this.setAttribute(name, i(t));
7223 function attrStringNS() {
7224 var a = this.getAttributeNS(name.space, name.local), i;
7225 return a !== b && (i = interpolate(a, b), function(t) {
7226 this.setAttributeNS(name.space, name.local, i(t));
7229 return b == null ? name.local ? attrNullNS : attrNull : (b += "", name.local ? attrStringNS : attrString);
7232 d3_transitionPrototype.attrTween = function(nameNS, tween) {
7233 var name = d3.ns.qualify(nameNS);
7234 function attrTween(d, i) {
7235 var f = tween.call(this, d, i, this.getAttribute(name));
7236 return f && function(t) {
7237 this.setAttribute(name, f(t));
7240 function attrTweenNS(d, i) {
7241 var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
7242 return f && function(t) {
7243 this.setAttributeNS(name.space, name.local, f(t));
7246 return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
7248 d3_transitionPrototype.style = function(name, value, priority) {
7249 var n = arguments.length;
7251 if (typeof name !== "string") {
7252 if (n < 2) value = "";
7253 for (priority in name) this.style(priority, name[priority], value);
7258 var interpolate = d3_interpolateByName(name);
7259 function styleNull() {
7260 this.style.removeProperty(name);
7262 return d3_transition_tween(this, "style." + name, value, function(b) {
7263 function styleString() {
7264 var a = d3_window.getComputedStyle(this, null).getPropertyValue(name), i;
7265 return a !== b && (i = interpolate(a, b), function(t) {
7266 this.style.setProperty(name, i(t), priority);
7269 return b == null ? styleNull : (b += "", styleString);
7272 d3_transitionPrototype.styleTween = function(name, tween, priority) {
7273 if (arguments.length < 3) priority = "";
7274 return this.tween("style." + name, function(d, i) {
7275 var f = tween.call(this, d, i, d3_window.getComputedStyle(this, null).getPropertyValue(name));
7276 return f && function(t) {
7277 this.style.setProperty(name, f(t), priority);
7281 d3_transitionPrototype.text = function(value) {
7282 return d3_transition_tween(this, "text", value, d3_transition_text);
7284 function d3_transition_text(b) {
7285 if (b == null) b = "";
7287 this.textContent = b;
7290 d3_transitionPrototype.remove = function() {
7291 return this.each("end.transition", function() {
7293 if (!this.__transition__ && (p = this.parentNode)) p.removeChild(this);
7296 d3_transitionPrototype.ease = function(value) {
7298 if (arguments.length < 1) return this.node().__transition__[id].ease;
7299 if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
7300 return d3_selection_each(this, function(node) {
7301 node.__transition__[id].ease = value;
7304 d3_transitionPrototype.delay = function(value) {
7306 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
7307 node.__transition__[id].delay = value.call(node, node.__data__, i, j) | 0;
7308 } : (value |= 0, function(node) {
7309 node.__transition__[id].delay = value;
7312 d3_transitionPrototype.duration = function(value) {
7314 return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
7315 node.__transition__[id].duration = Math.max(1, value.call(node, node.__data__, i, j) | 0);
7316 } : (value = Math.max(1, value | 0), function(node) {
7317 node.__transition__[id].duration = value;
7320 d3_transitionPrototype.each = function(type, listener) {
7322 if (arguments.length < 2) {
7323 var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
7324 d3_transitionInheritId = id;
7325 d3_selection_each(this, function(node, i, j) {
7326 d3_transitionInherit = node.__transition__[id];
7327 type.call(node, node.__data__, i, j);
7329 d3_transitionInherit = inherit;
7330 d3_transitionInheritId = inheritId;
7332 d3_selection_each(this, function(node) {
7333 node.__transition__[id].event.on(type, listener);
7338 d3_transitionPrototype.transition = function() {
7339 var id0 = this.id, id1 = ++d3_transitionId, subgroups = [], subgroup, group, node, transition;
7340 for (var j = 0, m = this.length; j < m; j++) {
7341 subgroups.push(subgroup = []);
7342 for (var group = this[j], i = 0, n = group.length; i < n; i++) {
7343 if (node = group[i]) {
7344 transition = Object.create(node.__transition__[id0]);
7345 transition.delay += transition.duration;
7346 d3_transitionNode(node, i, id1, transition);
7348 subgroup.push(node);
7351 return d3_transition(subgroups, id1);
7353 function d3_transitionNode(node, i, id, inherit) {
7354 var lock = node.__transition__ || (node.__transition__ = {
7357 }), transition = lock[id];
7359 var time = inherit.time;
7360 transition = lock[id] = {
7361 tween: new d3_Map(),
7362 event: d3.dispatch("start", "end"),
7365 delay: inherit.delay,
7366 duration: inherit.duration
7369 d3.timer(function(elapsed) {
7370 var d = node.__data__, ease = transition.ease, event = transition.event, delay = transition.delay, duration = transition.duration, tweened = [];
7371 return delay <= elapsed ? start(elapsed) : d3.timer(start, delay, time), 1;
7372 function start(elapsed) {
7373 if (lock.active > id) return stop();
7375 event.start.call(node, d, i);
7376 transition.tween.forEach(function(key, value) {
7377 if (value = value.call(node, d, i)) {
7378 tweened.push(value);
7381 if (!tick(elapsed)) d3.timer(tick, 0, time);
7384 function tick(elapsed) {
7385 if (lock.active !== id) return stop();
7386 var t = (elapsed - delay) / duration, e = ease(t), n = tweened.length;
7388 tweened[--n].call(node, e);
7392 event.end.call(node, d, i);
7397 if (--lock.count) delete lock[id]; else delete node.__transition__;
7404 d3.svg.axis = function() {
7405 var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, tickMajorSize = 6, tickMinorSize = 6, tickEndSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_, tickSubdivide = 0;
7408 var g = d3.select(this);
7409 var ticks = tickValues == null ? scale.ticks ? scale.ticks.apply(scale, tickArguments_) : scale.domain() : tickValues, tickFormat = tickFormat_ == null ? scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments_) : String : tickFormat_;
7410 var subticks = d3_svg_axisSubdivide(scale, ticks, tickSubdivide), subtick = g.selectAll(".tick.minor").data(subticks, String), subtickEnter = subtick.enter().insert("line", ".tick").attr("class", "tick minor").style("opacity", 1e-6), subtickExit = d3.transition(subtick.exit()).style("opacity", 1e-6).remove(), subtickUpdate = d3.transition(subtick).style("opacity", 1);
7411 var tick = g.selectAll(".tick.major").data(ticks, String), tickEnter = tick.enter().insert("g", "path").attr("class", "tick major").style("opacity", 1e-6), tickExit = d3.transition(tick.exit()).style("opacity", 1e-6).remove(), tickUpdate = d3.transition(tick).style("opacity", 1), tickTransform;
7412 var range = d3_scaleRange(scale), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
7413 d3.transition(path));
7414 var scale1 = scale.copy(), scale0 = this.__chart__ || scale1;
7415 this.__chart__ = scale1;
7416 tickEnter.append("line");
7417 tickEnter.append("text");
7418 var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text");
7422 tickTransform = d3_svg_axisX;
7423 subtickEnter.attr("y2", tickMinorSize);
7424 subtickUpdate.attr("x2", 0).attr("y2", tickMinorSize);
7425 lineEnter.attr("y2", tickMajorSize);
7426 textEnter.attr("y", Math.max(tickMajorSize, 0) + tickPadding);
7427 lineUpdate.attr("x2", 0).attr("y2", tickMajorSize);
7428 textUpdate.attr("x", 0).attr("y", Math.max(tickMajorSize, 0) + tickPadding);
7429 text.attr("dy", ".71em").style("text-anchor", "middle");
7430 pathUpdate.attr("d", "M" + range[0] + "," + tickEndSize + "V0H" + range[1] + "V" + tickEndSize);
7436 tickTransform = d3_svg_axisX;
7437 subtickEnter.attr("y2", -tickMinorSize);
7438 subtickUpdate.attr("x2", 0).attr("y2", -tickMinorSize);
7439 lineEnter.attr("y2", -tickMajorSize);
7440 textEnter.attr("y", -(Math.max(tickMajorSize, 0) + tickPadding));
7441 lineUpdate.attr("x2", 0).attr("y2", -tickMajorSize);
7442 textUpdate.attr("x", 0).attr("y", -(Math.max(tickMajorSize, 0) + tickPadding));
7443 text.attr("dy", "0em").style("text-anchor", "middle");
7444 pathUpdate.attr("d", "M" + range[0] + "," + -tickEndSize + "V0H" + range[1] + "V" + -tickEndSize);
7450 tickTransform = d3_svg_axisY;
7451 subtickEnter.attr("x2", -tickMinorSize);
7452 subtickUpdate.attr("x2", -tickMinorSize).attr("y2", 0);
7453 lineEnter.attr("x2", -tickMajorSize);
7454 textEnter.attr("x", -(Math.max(tickMajorSize, 0) + tickPadding));
7455 lineUpdate.attr("x2", -tickMajorSize).attr("y2", 0);
7456 textUpdate.attr("x", -(Math.max(tickMajorSize, 0) + tickPadding)).attr("y", 0);
7457 text.attr("dy", ".32em").style("text-anchor", "end");
7458 pathUpdate.attr("d", "M" + -tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + -tickEndSize);
7464 tickTransform = d3_svg_axisY;
7465 subtickEnter.attr("x2", tickMinorSize);
7466 subtickUpdate.attr("x2", tickMinorSize).attr("y2", 0);
7467 lineEnter.attr("x2", tickMajorSize);
7468 textEnter.attr("x", Math.max(tickMajorSize, 0) + tickPadding);
7469 lineUpdate.attr("x2", tickMajorSize).attr("y2", 0);
7470 textUpdate.attr("x", Math.max(tickMajorSize, 0) + tickPadding).attr("y", 0);
7471 text.attr("dy", ".32em").style("text-anchor", "start");
7472 pathUpdate.attr("d", "M" + tickEndSize + "," + range[0] + "H0V" + range[1] + "H" + tickEndSize);
7477 tickEnter.call(tickTransform, scale0);
7478 tickUpdate.call(tickTransform, scale1);
7479 tickExit.call(tickTransform, scale1);
7480 subtickEnter.call(tickTransform, scale0);
7481 subtickUpdate.call(tickTransform, scale1);
7482 subtickExit.call(tickTransform, scale1);
7484 var dx = scale1.rangeBand() / 2, x = function(d) {
7485 return scale1(d) + dx;
7487 tickEnter.call(tickTransform, x);
7488 tickUpdate.call(tickTransform, x);
7492 axis.scale = function(x) {
7493 if (!arguments.length) return scale;
7497 axis.orient = function(x) {
7498 if (!arguments.length) return orient;
7499 orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
7502 axis.ticks = function() {
7503 if (!arguments.length) return tickArguments_;
7504 tickArguments_ = arguments;
7507 axis.tickValues = function(x) {
7508 if (!arguments.length) return tickValues;
7512 axis.tickFormat = function(x) {
7513 if (!arguments.length) return tickFormat_;
7517 axis.tickSize = function(x, y) {
7518 if (!arguments.length) return tickMajorSize;
7519 var n = arguments.length - 1;
7521 tickMinorSize = n > 1 ? +y : tickMajorSize;
7522 tickEndSize = n > 0 ? +arguments[n] : tickMajorSize;
7525 axis.tickPadding = function(x) {
7526 if (!arguments.length) return tickPadding;
7530 axis.tickSubdivide = function(x) {
7531 if (!arguments.length) return tickSubdivide;
7537 var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
7543 function d3_svg_axisX(selection, x) {
7544 selection.attr("transform", function(d) {
7545 return "translate(" + x(d) + ",0)";
7548 function d3_svg_axisY(selection, y) {
7549 selection.attr("transform", function(d) {
7550 return "translate(0," + y(d) + ")";
7553 function d3_svg_axisSubdivide(scale, ticks, m) {
7555 if (m && ticks.length > 1) {
7556 var extent = d3_scaleExtent(scale.domain()), subticks, i = -1, n = ticks.length, d = (ticks[1] - ticks[0]) / ++m, j, v;
7558 for (j = m; --j > 0; ) {
7559 if ((v = +ticks[i] - j * d) >= extent[0]) {
7564 for (--i, j = 0; ++j < m && (v = +ticks[i] + j * d) < extent[1]; ) {
7570 d3.svg.brush = function() {
7571 var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, resizes = d3_svg_brushResizes[0], extent = [ [ 0, 0 ], [ 0, 0 ] ], extentDomain;
7574 var g = d3.select(this), bg = g.selectAll(".background").data([ 0 ]), fg = g.selectAll(".extent").data([ 0 ]), tz = g.selectAll(".resize").data(resizes, String), e;
7575 g.style("pointer-events", "all").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart);
7576 bg.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
7577 fg.enter().append("rect").attr("class", "extent").style("cursor", "move");
7578 tz.enter().append("g").attr("class", function(d) {
7579 return "resize " + d;
7580 }).style("cursor", function(d) {
7581 return d3_svg_brushCursor[d];
7582 }).append("rect").attr("x", function(d) {
7583 return /[ew]$/.test(d) ? -3 : null;
7584 }).attr("y", function(d) {
7585 return /^[ns]/.test(d) ? -3 : null;
7586 }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
7587 tz.style("display", brush.empty() ? "none" : null);
7590 e = d3_scaleRange(x);
7591 bg.attr("x", e[0]).attr("width", e[1] - e[0]);
7595 e = d3_scaleRange(y);
7596 bg.attr("y", e[0]).attr("height", e[1] - e[0]);
7602 function redraw(g) {
7603 g.selectAll(".resize").attr("transform", function(d) {
7604 return "translate(" + extent[+/e$/.test(d)][0] + "," + extent[+/^s/.test(d)][1] + ")";
7607 function redrawX(g) {
7608 g.select(".extent").attr("x", extent[0][0]);
7609 g.selectAll(".extent,.n>rect,.s>rect").attr("width", extent[1][0] - extent[0][0]);
7611 function redrawY(g) {
7612 g.select(".extent").attr("y", extent[0][1]);
7613 g.selectAll(".extent,.e>rect,.w>rect").attr("height", extent[1][1] - extent[0][1]);
7615 function brushstart() {
7616 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"), center, origin = mouse(), offset;
7617 var w = d3.select(d3_window).on("mousemove.brush", brushmove).on("mouseup.brush", brushend).on("touchmove.brush", brushmove).on("touchend.brush", brushend).on("keydown.brush", keydown).on("keyup.brush", keyup);
7619 origin[0] = extent[0][0] - origin[0];
7620 origin[1] = extent[0][1] - origin[1];
7621 } else if (resizing) {
7622 var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
7623 offset = [ extent[1 - ex][0] - origin[0], extent[1 - ey][1] - origin[1] ];
7624 origin[0] = extent[ex][0];
7625 origin[1] = extent[ey][1];
7626 } else if (d3.event.altKey) center = origin.slice();
7627 g.style("pointer-events", "none").selectAll(".resize").style("display", null);
7628 d3.select("body").style("cursor", eventTarget.style("cursor"));
7635 var touches = d3.event.changedTouches;
7636 return touches ? d3.touches(target, touches)[0] : d3.mouse(target);
7638 function keydown() {
7639 if (d3.event.keyCode == 32) {
7642 origin[0] -= extent[1][0];
7643 origin[1] -= extent[1][1];
7650 if (d3.event.keyCode == 32 && dragging == 2) {
7651 origin[0] += extent[1][0];
7652 origin[1] += extent[1][1];
7657 function brushmove() {
7658 var point = mouse(), moved = false;
7660 point[0] += offset[0];
7661 point[1] += offset[1];
7664 if (d3.event.altKey) {
7665 if (!center) center = [ (extent[0][0] + extent[1][0]) / 2, (extent[0][1] + extent[1][1]) / 2 ];
7666 origin[0] = extent[+(point[0] < center[0])][0];
7667 origin[1] = extent[+(point[1] < center[1])][1];
7668 } else center = null;
7670 if (resizingX && move1(point, x, 0)) {
7674 if (resizingY && move1(point, y, 1)) {
7682 mode: dragging ? "move" : "resize"
7686 function move1(point, scale, i) {
7687 var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], size = extent[1][i] - extent[0][i], min, max;
7690 r1 -= size + position;
7692 min = Math.max(r0, Math.min(r1, point[i]));
7694 max = (min += position) + size;
7696 if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
7697 if (position < min) {
7704 if (extent[0][i] !== min || extent[1][i] !== max) {
7705 extentDomain = null;
7711 function brushend() {
7713 g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
7714 d3.select("body").style("cursor", null);
7715 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);
7722 brush.x = function(z) {
7723 if (!arguments.length) return x;
7725 resizes = d3_svg_brushResizes[!x << 1 | !y];
7728 brush.y = function(z) {
7729 if (!arguments.length) return y;
7731 resizes = d3_svg_brushResizes[!x << 1 | !y];
7734 brush.extent = function(z) {
7735 var x0, x1, y0, y1, t;
7736 if (!arguments.length) {
7737 z = extentDomain || extent;
7739 x0 = z[0][0], x1 = z[1][0];
7740 if (!extentDomain) {
7741 x0 = extent[0][0], x1 = extent[1][0];
7742 if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
7743 if (x1 < x0) t = x0, x0 = x1, x1 = t;
7747 y0 = z[0][1], y1 = z[1][1];
7748 if (!extentDomain) {
7749 y0 = extent[0][1], y1 = extent[1][1];
7750 if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
7751 if (y1 < y0) t = y0, y0 = y1, y1 = t;
7754 return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
7756 extentDomain = [ [ 0, 0 ], [ 0, 0 ] ];
7758 x0 = z[0], x1 = z[1];
7759 if (y) x0 = x0[0], x1 = x1[0];
7760 extentDomain[0][0] = x0, extentDomain[1][0] = x1;
7761 if (x.invert) x0 = x(x0), x1 = x(x1);
7762 if (x1 < x0) t = x0, x0 = x1, x1 = t;
7763 extent[0][0] = x0 | 0, extent[1][0] = x1 | 0;
7766 y0 = z[0], y1 = z[1];
7767 if (x) y0 = y0[1], y1 = y1[1];
7768 extentDomain[0][1] = y0, extentDomain[1][1] = y1;
7769 if (y.invert) y0 = y(y0), y1 = y(y1);
7770 if (y1 < y0) t = y0, y0 = y1, y1 = t;
7771 extent[0][1] = y0 | 0, extent[1][1] = y1 | 0;
7775 brush.clear = function() {
7776 extentDomain = null;
7777 extent[0][0] = extent[0][1] = extent[1][0] = extent[1][1] = 0;
7780 brush.empty = function() {
7781 return x && extent[0][0] === extent[1][0] || y && extent[0][1] === extent[1][1];
7783 return d3.rebind(brush, event, "on");
7785 var d3_svg_brushCursor = {
7795 var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
7797 var d3_time = Date, d3_time_daySymbols = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
7798 function d3_time_utc() {
7799 this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
7801 d3_time_utc.prototype = {
7802 getDate: function() {
7803 return this._.getUTCDate();
7805 getDay: function() {
7806 return this._.getUTCDay();
7808 getFullYear: function() {
7809 return this._.getUTCFullYear();
7811 getHours: function() {
7812 return this._.getUTCHours();
7814 getMilliseconds: function() {
7815 return this._.getUTCMilliseconds();
7817 getMinutes: function() {
7818 return this._.getUTCMinutes();
7820 getMonth: function() {
7821 return this._.getUTCMonth();
7823 getSeconds: function() {
7824 return this._.getUTCSeconds();
7826 getTime: function() {
7827 return this._.getTime();
7829 getTimezoneOffset: function() {
7832 valueOf: function() {
7833 return this._.valueOf();
7835 setDate: function() {
7836 d3_time_prototype.setUTCDate.apply(this._, arguments);
7838 setDay: function() {
7839 d3_time_prototype.setUTCDay.apply(this._, arguments);
7841 setFullYear: function() {
7842 d3_time_prototype.setUTCFullYear.apply(this._, arguments);
7844 setHours: function() {
7845 d3_time_prototype.setUTCHours.apply(this._, arguments);
7847 setMilliseconds: function() {
7848 d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
7850 setMinutes: function() {
7851 d3_time_prototype.setUTCMinutes.apply(this._, arguments);
7853 setMonth: function() {
7854 d3_time_prototype.setUTCMonth.apply(this._, arguments);
7856 setSeconds: function() {
7857 d3_time_prototype.setUTCSeconds.apply(this._, arguments);
7859 setTime: function() {
7860 d3_time_prototype.setTime.apply(this._, arguments);
7863 var d3_time_prototype = Date.prototype;
7864 var d3_time_formatDateTime = "%a %b %e %X %Y", d3_time_formatDate = "%m/%d/%Y", d3_time_formatTime = "%H:%M:%S";
7865 var d3_time_days = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ], d3_time_dayAbbreviations = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ], d3_time_months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], d3_time_monthAbbreviations = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
7866 function d3_time_interval(local, step, number) {
7867 function round(date) {
7868 var d0 = local(date), d1 = offset(d0, 1);
7869 return date - d0 < d1 - date ? d0 : d1;
7871 function ceil(date) {
7872 step(date = local(new d3_time(date - 1)), 1);
7875 function offset(date, k) {
7876 step(date = new d3_time(+date), k);
7879 function range(t0, t1, dt) {
7880 var time = ceil(t0), times = [];
7883 if (!(number(time) % dt)) times.push(new Date(+time));
7887 while (time < t1) times.push(new Date(+time)), step(time, 1);
7891 function range_utc(t0, t1, dt) {
7893 d3_time = d3_time_utc;
7894 var utc = new d3_time_utc();
7896 return range(utc, t1, dt);
7901 local.floor = local;
7902 local.round = round;
7904 local.offset = offset;
7905 local.range = range;
7906 var utc = local.utc = d3_time_interval_utc(local);
7908 utc.round = d3_time_interval_utc(round);
7909 utc.ceil = d3_time_interval_utc(ceil);
7910 utc.offset = d3_time_interval_utc(offset);
7911 utc.range = range_utc;
7914 function d3_time_interval_utc(method) {
7915 return function(date, k) {
7917 d3_time = d3_time_utc;
7918 var utc = new d3_time_utc();
7920 return method(utc, k)._;
7926 d3.time.year = d3_time_interval(function(date) {
7927 date = d3.time.day(date);
7928 date.setMonth(0, 1);
7930 }, function(date, offset) {
7931 date.setFullYear(date.getFullYear() + offset);
7933 return date.getFullYear();
7935 d3.time.years = d3.time.year.range;
7936 d3.time.years.utc = d3.time.year.utc.range;
7937 d3.time.day = d3_time_interval(function(date) {
7938 var day = new d3_time(1970, 0);
7939 day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
7941 }, function(date, offset) {
7942 date.setDate(date.getDate() + offset);
7944 return date.getDate() - 1;
7946 d3.time.days = d3.time.day.range;
7947 d3.time.days.utc = d3.time.day.utc.range;
7948 d3.time.dayOfYear = function(date) {
7949 var year = d3.time.year(date);
7950 return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
7952 d3_time_daySymbols.forEach(function(day, i) {
7953 day = day.toLowerCase();
7955 var interval = d3.time[day] = d3_time_interval(function(date) {
7956 (date = d3.time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
7958 }, function(date, offset) {
7959 date.setDate(date.getDate() + Math.floor(offset) * 7);
7961 var day = d3.time.year(date).getDay();
7962 return Math.floor((d3.time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
7964 d3.time[day + "s"] = interval.range;
7965 d3.time[day + "s"].utc = interval.utc.range;
7966 d3.time[day + "OfYear"] = function(date) {
7967 var day = d3.time.year(date).getDay();
7968 return Math.floor((d3.time.dayOfYear(date) + (day + i) % 7) / 7);
7971 d3.time.week = d3.time.sunday;
7972 d3.time.weeks = d3.time.sunday.range;
7973 d3.time.weeks.utc = d3.time.sunday.utc.range;
7974 d3.time.weekOfYear = d3.time.sundayOfYear;
7975 d3.time.format = function(template) {
7976 var n = template.length;
7977 function format(date) {
7978 var string = [], i = -1, j = 0, c, p, f;
7980 if (template.charCodeAt(i) === 37) {
7981 string.push(template.substring(j, i));
7982 if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
7983 if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
7988 string.push(template.substring(j, i));
7989 return string.join("");
7991 format.parse = function(string) {
8000 }, i = d3_time_parse(d, template, string, 0);
8001 if (i != string.length) return null;
8002 if ("p" in d) d.H = d.H % 12 + d.p * 12;
8003 var date = new d3_time();
8004 date.setFullYear(d.y, d.m, d.d);
8005 date.setHours(d.H, d.M, d.S, d.L);
8008 format.toString = function() {
8013 function d3_time_parse(date, template, string, j) {
8014 var c, p, i = 0, n = template.length, m = string.length;
8016 if (j >= m) return -1;
8017 c = template.charCodeAt(i++);
8019 p = d3_time_parsers[template.charAt(i++)];
8020 if (!p || (j = p(date, string, j)) < 0) return -1;
8021 } else if (c != string.charCodeAt(j++)) {
8027 function d3_time_formatRe(names) {
8028 return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
8030 function d3_time_formatLookup(names) {
8031 var map = new d3_Map(), i = -1, n = names.length;
8032 while (++i < n) map.set(names[i].toLowerCase(), i);
8035 function d3_time_formatPad(value, fill, width) {
8037 var length = value.length;
8038 return length < width ? new Array(width - length + 1).join(fill) + value : value;
8040 var d3_time_dayRe = d3_time_formatRe(d3_time_days), d3_time_dayAbbrevRe = d3_time_formatRe(d3_time_dayAbbreviations), d3_time_monthRe = d3_time_formatRe(d3_time_months), d3_time_monthLookup = d3_time_formatLookup(d3_time_months), d3_time_monthAbbrevRe = d3_time_formatRe(d3_time_monthAbbreviations), d3_time_monthAbbrevLookup = d3_time_formatLookup(d3_time_monthAbbreviations);
8041 var d3_time_formatPads = {
8046 var d3_time_formats = {
8048 return d3_time_dayAbbreviations[d.getDay()];
8051 return d3_time_days[d.getDay()];
8054 return d3_time_monthAbbreviations[d.getMonth()];
8057 return d3_time_months[d.getMonth()];
8059 c: d3.time.format(d3_time_formatDateTime),
8061 return d3_time_formatPad(d.getDate(), p, 2);
8064 return d3_time_formatPad(d.getDate(), p, 2);
8067 return d3_time_formatPad(d.getHours(), p, 2);
8070 return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
8073 return d3_time_formatPad(1 + d3.time.dayOfYear(d), p, 3);
8076 return d3_time_formatPad(d.getMilliseconds(), p, 3);
8079 return d3_time_formatPad(d.getMonth() + 1, p, 2);
8082 return d3_time_formatPad(d.getMinutes(), p, 2);
8085 return d.getHours() >= 12 ? "PM" : "AM";
8088 return d3_time_formatPad(d.getSeconds(), p, 2);
8091 return d3_time_formatPad(d3.time.sundayOfYear(d), p, 2);
8097 return d3_time_formatPad(d3.time.mondayOfYear(d), p, 2);
8099 x: d3.time.format(d3_time_formatDate),
8100 X: d3.time.format(d3_time_formatTime),
8102 return d3_time_formatPad(d.getFullYear() % 100, p, 2);
8105 return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
8112 var d3_time_parsers = {
8113 a: d3_time_parseWeekdayAbbrev,
8114 A: d3_time_parseWeekday,
8115 b: d3_time_parseMonthAbbrev,
8116 B: d3_time_parseMonth,
8117 c: d3_time_parseLocaleFull,
8118 d: d3_time_parseDay,
8119 e: d3_time_parseDay,
8120 H: d3_time_parseHour24,
8121 I: d3_time_parseHour24,
8122 L: d3_time_parseMilliseconds,
8123 m: d3_time_parseMonthNumber,
8124 M: d3_time_parseMinutes,
8125 p: d3_time_parseAmPm,
8126 S: d3_time_parseSeconds,
8127 x: d3_time_parseLocaleDate,
8128 X: d3_time_parseLocaleTime,
8129 y: d3_time_parseYear,
8130 Y: d3_time_parseFullYear
8132 function d3_time_parseWeekdayAbbrev(date, string, i) {
8133 d3_time_dayAbbrevRe.lastIndex = 0;
8134 var n = d3_time_dayAbbrevRe.exec(string.substring(i));
8135 return n ? i += n[0].length : -1;
8137 function d3_time_parseWeekday(date, string, i) {
8138 d3_time_dayRe.lastIndex = 0;
8139 var n = d3_time_dayRe.exec(string.substring(i));
8140 return n ? i += n[0].length : -1;
8142 function d3_time_parseMonthAbbrev(date, string, i) {
8143 d3_time_monthAbbrevRe.lastIndex = 0;
8144 var n = d3_time_monthAbbrevRe.exec(string.substring(i));
8145 return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
8147 function d3_time_parseMonth(date, string, i) {
8148 d3_time_monthRe.lastIndex = 0;
8149 var n = d3_time_monthRe.exec(string.substring(i));
8150 return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
8152 function d3_time_parseLocaleFull(date, string, i) {
8153 return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
8155 function d3_time_parseLocaleDate(date, string, i) {
8156 return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
8158 function d3_time_parseLocaleTime(date, string, i) {
8159 return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
8161 function d3_time_parseFullYear(date, string, i) {
8162 d3_time_numberRe.lastIndex = 0;
8163 var n = d3_time_numberRe.exec(string.substring(i, i + 4));
8164 return n ? (date.y = +n[0], i += n[0].length) : -1;
8166 function d3_time_parseYear(date, string, i) {
8167 d3_time_numberRe.lastIndex = 0;
8168 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
8169 return n ? (date.y = d3_time_expandYear(+n[0]), i += n[0].length) : -1;
8171 function d3_time_expandYear(d) {
8172 return d + (d > 68 ? 1900 : 2e3);
8174 function d3_time_parseMonthNumber(date, string, i) {
8175 d3_time_numberRe.lastIndex = 0;
8176 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
8177 return n ? (date.m = n[0] - 1, i += n[0].length) : -1;
8179 function d3_time_parseDay(date, string, i) {
8180 d3_time_numberRe.lastIndex = 0;
8181 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
8182 return n ? (date.d = +n[0], i += n[0].length) : -1;
8184 function d3_time_parseHour24(date, string, i) {
8185 d3_time_numberRe.lastIndex = 0;
8186 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
8187 return n ? (date.H = +n[0], i += n[0].length) : -1;
8189 function d3_time_parseMinutes(date, string, i) {
8190 d3_time_numberRe.lastIndex = 0;
8191 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
8192 return n ? (date.M = +n[0], i += n[0].length) : -1;
8194 function d3_time_parseSeconds(date, string, i) {
8195 d3_time_numberRe.lastIndex = 0;
8196 var n = d3_time_numberRe.exec(string.substring(i, i + 2));
8197 return n ? (date.S = +n[0], i += n[0].length) : -1;
8199 function d3_time_parseMilliseconds(date, string, i) {
8200 d3_time_numberRe.lastIndex = 0;
8201 var n = d3_time_numberRe.exec(string.substring(i, i + 3));
8202 return n ? (date.L = +n[0], i += n[0].length) : -1;
8204 var d3_time_numberRe = /^\s*\d+/;
8205 function d3_time_parseAmPm(date, string, i) {
8206 var n = d3_time_amPmLookup.get(string.substring(i, i += 2).toLowerCase());
8207 return n == null ? -1 : (date.p = n, i);
8209 var d3_time_amPmLookup = d3.map({
8213 function d3_time_zone(d) {
8214 var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = ~~(Math.abs(z) / 60), zm = Math.abs(z) % 60;
8215 return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
8217 d3.time.format.utc = function(template) {
8218 var local = d3.time.format(template);
8219 function format(date) {
8221 d3_time = d3_time_utc;
8222 var utc = new d3_time();
8229 format.parse = function(string) {
8231 d3_time = d3_time_utc;
8232 var date = local.parse(string);
8233 return date && date._;
8238 format.toString = local.toString;
8241 var d3_time_formatIso = d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%LZ");
8242 d3.time.format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
8243 function d3_time_formatIsoNative(date) {
8244 return date.toISOString();
8246 d3_time_formatIsoNative.parse = function(string) {
8247 var date = new Date(string);
8248 return isNaN(date) ? null : date;
8250 d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
8251 d3.time.second = d3_time_interval(function(date) {
8252 return new d3_time(Math.floor(date / 1e3) * 1e3);
8253 }, function(date, offset) {
8254 date.setTime(date.getTime() + Math.floor(offset) * 1e3);
8256 return date.getSeconds();
8258 d3.time.seconds = d3.time.second.range;
8259 d3.time.seconds.utc = d3.time.second.utc.range;
8260 d3.time.minute = d3_time_interval(function(date) {
8261 return new d3_time(Math.floor(date / 6e4) * 6e4);
8262 }, function(date, offset) {
8263 date.setTime(date.getTime() + Math.floor(offset) * 6e4);
8265 return date.getMinutes();
8267 d3.time.minutes = d3.time.minute.range;
8268 d3.time.minutes.utc = d3.time.minute.utc.range;
8269 d3.time.hour = d3_time_interval(function(date) {
8270 var timezone = date.getTimezoneOffset() / 60;
8271 return new d3_time((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
8272 }, function(date, offset) {
8273 date.setTime(date.getTime() + Math.floor(offset) * 36e5);
8275 return date.getHours();
8277 d3.time.hours = d3.time.hour.range;
8278 d3.time.hours.utc = d3.time.hour.utc.range;
8279 d3.time.month = d3_time_interval(function(date) {
8280 date = d3.time.day(date);
8283 }, function(date, offset) {
8284 date.setMonth(date.getMonth() + offset);
8286 return date.getMonth();
8288 d3.time.months = d3.time.month.range;
8289 d3.time.months.utc = d3.time.month.utc.range;
8290 function d3_time_scale(linear, methods, format) {
8294 scale.invert = function(x) {
8295 return d3_time_scaleDate(linear.invert(x));
8297 scale.domain = function(x) {
8298 if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
8302 scale.nice = function(m) {
8303 return scale.domain(d3_scale_nice(scale.domain(), function() {
8307 scale.ticks = function(m, k) {
8308 var extent = d3_time_scaleExtent(scale.domain());
8309 if (typeof m !== "function") {
8310 var span = extent[1] - extent[0], target = span / m, i = d3.bisect(d3_time_scaleSteps, target);
8311 if (i == d3_time_scaleSteps.length) return methods.year(extent, m);
8312 if (!i) return linear.ticks(m).map(d3_time_scaleDate);
8313 if (Math.log(target / d3_time_scaleSteps[i - 1]) < Math.log(d3_time_scaleSteps[i] / target)) --i;
8318 return m(extent[0], new Date(+extent[1] + 1), k);
8320 scale.tickFormat = function() {
8323 scale.copy = function() {
8324 return d3_time_scale(linear.copy(), methods, format);
8326 return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
8328 function d3_time_scaleExtent(domain) {
8329 var start = domain[0], stop = domain[domain.length - 1];
8330 return start < stop ? [ start, stop ] : [ stop, start ];
8332 function d3_time_scaleDate(t) {
8335 function d3_time_scaleFormat(formats) {
8336 return function(date) {
8337 var i = formats.length - 1, f = formats[i];
8338 while (!f[1](date)) f = formats[--i];
8342 function d3_time_scaleSetYear(y) {
8343 var d = new Date(y, 0, 1);
8347 function d3_time_scaleGetYear(d) {
8348 var y = d.getFullYear(), d0 = d3_time_scaleSetYear(y), d1 = d3_time_scaleSetYear(y + 1);
8349 return y + (d - d0) / (d1 - d0);
8351 var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
8352 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 ] ];
8353 var d3_time_scaleLocalFormats = [ [ d3.time.format("%Y"), d3_true ], [ d3.time.format("%B"), function(d) {
8354 return d.getMonth();
8355 } ], [ d3.time.format("%b %d"), function(d) {
8356 return d.getDate() != 1;
8357 } ], [ d3.time.format("%a %d"), function(d) {
8358 return d.getDay() && d.getDate() != 1;
8359 } ], [ d3.time.format("%I %p"), function(d) {
8360 return d.getHours();
8361 } ], [ d3.time.format("%I:%M"), function(d) {
8362 return d.getMinutes();
8363 } ], [ d3.time.format(":%S"), function(d) {
8364 return d.getSeconds();
8365 } ], [ d3.time.format(".%L"), function(d) {
8366 return d.getMilliseconds();
8368 var d3_time_scaleLinear = d3.scale.linear(), d3_time_scaleLocalFormat = d3_time_scaleFormat(d3_time_scaleLocalFormats);
8369 d3_time_scaleLocalMethods.year = function(extent, m) {
8370 return d3_time_scaleLinear.domain(extent.map(d3_time_scaleGetYear)).ticks(m).map(d3_time_scaleSetYear);
8372 d3.time.scale = function() {
8373 return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
8375 var d3_time_scaleUTCMethods = d3_time_scaleLocalMethods.map(function(m) {
8376 return [ m[0].utc, m[1] ];
8378 var d3_time_scaleUTCFormats = [ [ d3.time.format.utc("%Y"), d3_true ], [ d3.time.format.utc("%B"), function(d) {
8379 return d.getUTCMonth();
8380 } ], [ d3.time.format.utc("%b %d"), function(d) {
8381 return d.getUTCDate() != 1;
8382 } ], [ d3.time.format.utc("%a %d"), function(d) {
8383 return d.getUTCDay() && d.getUTCDate() != 1;
8384 } ], [ d3.time.format.utc("%I %p"), function(d) {
8385 return d.getUTCHours();
8386 } ], [ d3.time.format.utc("%I:%M"), function(d) {
8387 return d.getUTCMinutes();
8388 } ], [ d3.time.format.utc(":%S"), function(d) {
8389 return d.getUTCSeconds();
8390 } ], [ d3.time.format.utc(".%L"), function(d) {
8391 return d.getUTCMilliseconds();
8393 var d3_time_scaleUTCFormat = d3_time_scaleFormat(d3_time_scaleUTCFormats);
8394 function d3_time_scaleUTCSetYear(y) {
8395 var d = new Date(Date.UTC(y, 0, 1));
8396 d.setUTCFullYear(y);
8399 function d3_time_scaleUTCGetYear(d) {
8400 var y = d.getUTCFullYear(), d0 = d3_time_scaleUTCSetYear(y), d1 = d3_time_scaleUTCSetYear(y + 1);
8401 return y + (d - d0) / (d1 - d0);
8403 d3_time_scaleUTCMethods.year = function(extent, m) {
8404 return d3_time_scaleLinear.domain(extent.map(d3_time_scaleUTCGetYear)).ticks(m).map(d3_time_scaleUTCSetYear);
8406 d3.time.scale.utc = function() {
8407 return d3_time_scale(d3.scale.linear(), d3_time_scaleUTCMethods, d3_time_scaleUTCFormat);
8409 d3.text = function() {
8410 return d3.xhr.apply(d3, arguments).response(d3_text);
8412 function d3_text(request) {
8413 return request.responseText;
8415 d3.json = function(url, callback) {
8416 return d3.xhr(url, "application/json", callback).response(d3_json);
8418 function d3_json(request) {
8419 return JSON.parse(request.responseText);
8421 d3.html = function(url, callback) {
8422 return d3.xhr(url, "text/html", callback).response(d3_html);
8424 function d3_html(request) {
8425 var range = d3_document.createRange();
8426 range.selectNode(d3_document.body);
8427 return range.createContextualFragment(request.responseText);
8429 d3.xml = function() {
8430 return d3.xhr.apply(d3, arguments).response(d3_xml);
8432 function d3_xml(request) {
8433 return request.responseXML;