1 // https://d3js.org Version 5.5.0. Copyright 2018 Mike Bostock.
2 (function (global, factory) {
3 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4 typeof define === 'function' && define.amd ? define(['exports'], factory) :
5 (factory((global.d3 = global.d3 || {})));
6 }(this, (function (exports) { 'use strict';
10 function ascending(a, b) {
11 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
14 function bisector(compare) {
15 if (compare.length === 1) compare = ascendingComparator(compare);
17 left: function(a, x, lo, hi) {
18 if (lo == null) lo = 0;
19 if (hi == null) hi = a.length;
21 var mid = lo + hi >>> 1;
22 if (compare(a[mid], x) < 0) lo = mid + 1;
27 right: function(a, x, lo, hi) {
28 if (lo == null) lo = 0;
29 if (hi == null) hi = a.length;
31 var mid = lo + hi >>> 1;
32 if (compare(a[mid], x) > 0) hi = mid;
40 function ascendingComparator(f) {
41 return function(d, x) {
42 return ascending(f(d), x);
46 var ascendingBisect = bisector(ascending);
47 var bisectRight = ascendingBisect.right;
48 var bisectLeft = ascendingBisect.left;
50 function pairs(array, f) {
51 if (f == null) f = pair;
52 var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
53 while (i < n) pairs[i] = f(p, p = array[++i]);
61 function cross(values0, values1, reduce) {
62 var n0 = values0.length,
64 values = new Array(n0 * n1),
70 if (reduce == null) reduce = pair;
72 for (i0 = i = 0; i0 < n0; ++i0) {
73 for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
74 values[i] = reduce(value0, values1[i1]);
81 function descending(a, b) {
82 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
86 return x === null ? NaN : +x;
89 function variance(values, valueof) {
90 var n = values.length,
98 if (valueof == null) {
100 if (!isNaN(value = number(values[i]))) {
101 delta = value - mean;
103 sum += delta * (value - mean);
110 if (!isNaN(value = number(valueof(values[i], i, values)))) {
111 delta = value - mean;
113 sum += delta * (value - mean);
118 if (m > 1) return sum / (m - 1);
121 function deviation(array, f) {
122 var v = variance(array, f);
123 return v ? Math.sqrt(v) : v;
126 function extent(values, valueof) {
127 var n = values.length,
133 if (valueof == null) {
134 while (++i < n) { // Find the first comparable value.
135 if ((value = values[i]) != null && value >= value) {
137 while (++i < n) { // Compare the remaining values.
138 if ((value = values[i]) != null) {
139 if (min > value) min = value;
140 if (max < value) max = value;
148 while (++i < n) { // Find the first comparable value.
149 if ((value = valueof(values[i], i, values)) != null && value >= value) {
151 while (++i < n) { // Compare the remaining values.
152 if ((value = valueof(values[i], i, values)) != null) {
153 if (min > value) min = value;
154 if (max < value) max = value;
164 var array = Array.prototype;
166 var slice = array.slice;
169 function constant(x) {
175 function identity(x) {
179 function sequence(start, stop, step) {
180 start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
183 n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
184 range = new Array(n);
187 range[i] = start + i * step;
193 var e10 = Math.sqrt(50),
197 function ticks(start, stop, count) {
204 stop = +stop, start = +start, count = +count;
205 if (start === stop && count > 0) return [start];
206 if (reverse = stop < start) n = start, start = stop, stop = n;
207 if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
210 start = Math.ceil(start / step);
211 stop = Math.floor(stop / step);
212 ticks = new Array(n = Math.ceil(stop - start + 1));
213 while (++i < n) ticks[i] = (start + i) * step;
215 start = Math.floor(start * step);
216 stop = Math.ceil(stop * step);
217 ticks = new Array(n = Math.ceil(start - stop + 1));
218 while (++i < n) ticks[i] = (start - i) / step;
221 if (reverse) ticks.reverse();
226 function tickIncrement(start, stop, count) {
227 var step = (stop - start) / Math.max(0, count),
228 power = Math.floor(Math.log(step) / Math.LN10),
229 error = step / Math.pow(10, power);
231 ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
232 : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
235 function tickStep(start, stop, count) {
236 var step0 = Math.abs(stop - start) / Math.max(0, count),
237 step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
238 error = step0 / step1;
239 if (error >= e10) step1 *= 10;
240 else if (error >= e5) step1 *= 5;
241 else if (error >= e2) step1 *= 2;
242 return stop < start ? -step1 : step1;
245 function thresholdSturges(values) {
246 return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
249 function histogram() {
250 var value = identity,
252 threshold = thresholdSturges;
254 function histogram(data) {
258 values = new Array(n);
260 for (i = 0; i < n; ++i) {
261 values[i] = value(data[i], i, data);
264 var xz = domain(values),
267 tz = threshold(values, x0, x1);
269 // Convert number of thresholds into uniform thresholds.
270 if (!Array.isArray(tz)) {
271 tz = tickStep(x0, x1, tz);
272 tz = sequence(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive
275 // Remove any thresholds outside the domain.
277 while (tz[0] <= x0) tz.shift(), --m;
278 while (tz[m - 1] > x1) tz.pop(), --m;
280 var bins = new Array(m + 1),
284 for (i = 0; i <= m; ++i) {
286 bin.x0 = i > 0 ? tz[i - 1] : x0;
287 bin.x1 = i < m ? tz[i] : x1;
290 // Assign data to bins by value, ignoring any outside the domain.
291 for (i = 0; i < n; ++i) {
293 if (x0 <= x && x <= x1) {
294 bins[bisectRight(tz, x, 0, m)].push(data[i]);
301 histogram.value = function(_) {
302 return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
305 histogram.domain = function(_) {
306 return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
309 histogram.thresholds = function(_) {
310 return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
316 function threshold(values, p, valueof) {
317 if (valueof == null) valueof = number;
318 if (!(n = values.length)) return;
319 if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
320 if (p >= 1) return +valueof(values[n - 1], n - 1, values);
324 value0 = +valueof(values[i0], i0, values),
325 value1 = +valueof(values[i0 + 1], i0 + 1, values);
326 return value0 + (value1 - value0) * (i - i0);
329 function freedmanDiaconis(values, min, max) {
330 values = map.call(values, number).sort(ascending);
331 return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
334 function scott(values, min, max) {
335 return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
338 function max(values, valueof) {
339 var n = values.length,
344 if (valueof == null) {
345 while (++i < n) { // Find the first comparable value.
346 if ((value = values[i]) != null && value >= value) {
348 while (++i < n) { // Compare the remaining values.
349 if ((value = values[i]) != null && value > max) {
358 while (++i < n) { // Find the first comparable value.
359 if ((value = valueof(values[i], i, values)) != null && value >= value) {
361 while (++i < n) { // Compare the remaining values.
362 if ((value = valueof(values[i], i, values)) != null && value > max) {
373 function mean(values, valueof) {
374 var n = values.length,
380 if (valueof == null) {
382 if (!isNaN(value = number(values[i]))) sum += value;
389 if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
394 if (m) return sum / m;
397 function median(values, valueof) {
398 var n = values.length,
403 if (valueof == null) {
405 if (!isNaN(value = number(values[i]))) {
413 if (!isNaN(value = number(valueof(values[i], i, values)))) {
419 return threshold(numbers.sort(ascending), 0.5);
422 function merge(arrays) {
423 var n = arrays.length,
430 while (++i < n) j += arrays[i].length;
431 merged = new Array(j);
437 merged[--j] = array[m];
444 function min(values, valueof) {
445 var n = values.length,
450 if (valueof == null) {
451 while (++i < n) { // Find the first comparable value.
452 if ((value = values[i]) != null && value >= value) {
454 while (++i < n) { // Compare the remaining values.
455 if ((value = values[i]) != null && min > value) {
464 while (++i < n) { // Find the first comparable value.
465 if ((value = valueof(values[i], i, values)) != null && value >= value) {
467 while (++i < n) { // Compare the remaining values.
468 if ((value = valueof(values[i], i, values)) != null && min > value) {
479 function permute(array, indexes) {
480 var i = indexes.length, permutes = new Array(i);
481 while (i--) permutes[i] = array[indexes[i]];
485 function scan(values, compare) {
486 if (!(n = values.length)) return;
493 if (compare == null) compare = ascending;
496 if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
501 if (compare(xj, xj) === 0) return j;
504 function shuffle(array, i0, i1) {
505 var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
510 i = Math.random() * m-- | 0;
512 array[m + i0] = array[i + i0];
519 function sum(values, valueof) {
520 var n = values.length,
525 if (valueof == null) {
527 if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
533 if (value = +valueof(values[i], i, values)) sum += value;
540 function transpose(matrix) {
541 if (!(n = matrix.length)) return [];
542 for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
543 for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
544 row[j] = matrix[j][i];
555 return transpose(arguments);
558 var slice$1 = Array.prototype.slice;
560 function identity$1(x) {
570 function translateX(x) {
571 return "translate(" + (x + 0.5) + ",0)";
574 function translateY(y) {
575 return "translate(0," + (y + 0.5) + ")";
578 function number$1(scale) {
584 function center(scale) {
585 var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
586 if (scale.round()) offset = Math.round(offset);
588 return +scale(d) + offset;
592 function entering() {
596 function axis(orient, scale) {
597 var tickArguments = [],
603 k = orient === top || orient === left ? -1 : 1,
604 x = orient === left || orient === right ? "x" : "y",
605 transform = orient === top || orient === bottom ? translateX : translateY;
607 function axis(context) {
608 var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
609 format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
610 spacing = Math.max(tickSizeInner, 0) + tickPadding,
611 range = scale.range(),
612 range0 = +range[0] + 0.5,
613 range1 = +range[range.length - 1] + 0.5,
614 position = (scale.bandwidth ? center : number$1)(scale.copy()),
615 selection = context.selection ? context.selection() : context,
616 path = selection.selectAll(".domain").data([null]),
617 tick = selection.selectAll(".tick").data(values, scale).order(),
618 tickExit = tick.exit(),
619 tickEnter = tick.enter().append("g").attr("class", "tick"),
620 line = tick.select("line"),
621 text = tick.select("text");
623 path = path.merge(path.enter().insert("path", ".tick")
624 .attr("class", "domain")
625 .attr("stroke", "#000"));
627 tick = tick.merge(tickEnter);
629 line = line.merge(tickEnter.append("line")
630 .attr("stroke", "#000")
631 .attr(x + "2", k * tickSizeInner));
633 text = text.merge(tickEnter.append("text")
634 .attr("fill", "#000")
635 .attr(x, k * spacing)
636 .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
638 if (context !== selection) {
639 path = path.transition(context);
640 tick = tick.transition(context);
641 line = line.transition(context);
642 text = text.transition(context);
644 tickExit = tickExit.transition(context)
645 .attr("opacity", epsilon)
646 .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
649 .attr("opacity", epsilon)
650 .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
656 .attr("d", orient === left || orient == right
657 ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
658 : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
662 .attr("transform", function(d) { return transform(position(d)); });
665 .attr(x + "2", k * tickSizeInner);
668 .attr(x, k * spacing)
671 selection.filter(entering)
672 .attr("fill", "none")
673 .attr("font-size", 10)
674 .attr("font-family", "sans-serif")
675 .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
678 .each(function() { this.__axis = position; });
681 axis.scale = function(_) {
682 return arguments.length ? (scale = _, axis) : scale;
685 axis.ticks = function() {
686 return tickArguments = slice$1.call(arguments), axis;
689 axis.tickArguments = function(_) {
690 return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
693 axis.tickValues = function(_) {
694 return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
697 axis.tickFormat = function(_) {
698 return arguments.length ? (tickFormat = _, axis) : tickFormat;
701 axis.tickSize = function(_) {
702 return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
705 axis.tickSizeInner = function(_) {
706 return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
709 axis.tickSizeOuter = function(_) {
710 return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
713 axis.tickPadding = function(_) {
714 return arguments.length ? (tickPadding = +_, axis) : tickPadding;
720 function axisTop(scale) {
721 return axis(top, scale);
724 function axisRight(scale) {
725 return axis(right, scale);
728 function axisBottom(scale) {
729 return axis(bottom, scale);
732 function axisLeft(scale) {
733 return axis(left, scale);
736 var noop = {value: function() {}};
738 function dispatch() {
739 for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
740 if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
743 return new Dispatch(_);
746 function Dispatch(_) {
750 function parseTypenames(typenames, types) {
751 return typenames.trim().split(/^|\s+/).map(function(t) {
752 var name = "", i = t.indexOf(".");
753 if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
754 if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
755 return {type: t, name: name};
759 Dispatch.prototype = dispatch.prototype = {
760 constructor: Dispatch,
761 on: function(typename, callback) {
763 T = parseTypenames(typename + "", _),
768 // If no callback was specified, return the callback of the given type and name.
769 if (arguments.length < 2) {
770 while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
774 // If a type was specified, set the callback for the given type and name.
775 // Otherwise, if a null callback was specified, remove callbacks of the given name.
776 if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
778 if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
779 else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
785 var copy = {}, _ = this._;
786 for (var t in _) copy[t] = _[t].slice();
787 return new Dispatch(copy);
789 call: function(type, that) {
790 if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
791 if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
792 for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
794 apply: function(type, that, args) {
795 if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
796 for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
800 function get(type, name) {
801 for (var i = 0, n = type.length, c; i < n; ++i) {
802 if ((c = type[i]).name === name) {
808 function set(type, name, callback) {
809 for (var i = 0, n = type.length; i < n; ++i) {
810 if (type[i].name === name) {
811 type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
815 if (callback != null) type.push({name: name, value: callback});
819 var xhtml = "http://www.w3.org/1999/xhtml";
822 svg: "http://www.w3.org/2000/svg",
824 xlink: "http://www.w3.org/1999/xlink",
825 xml: "http://www.w3.org/XML/1998/namespace",
826 xmlns: "http://www.w3.org/2000/xmlns/"
829 function namespace(name) {
830 var prefix = name += "", i = prefix.indexOf(":");
831 if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
832 return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
835 function creatorInherit(name) {
837 var document = this.ownerDocument,
838 uri = this.namespaceURI;
839 return uri === xhtml && document.documentElement.namespaceURI === xhtml
840 ? document.createElement(name)
841 : document.createElementNS(uri, name);
845 function creatorFixed(fullname) {
847 return this.ownerDocument.createElementNS(fullname.space, fullname.local);
851 function creator(name) {
852 var fullname = namespace(name);
853 return (fullname.local
855 : creatorInherit)(fullname);
860 function selector(selector) {
861 return selector == null ? none : function() {
862 return this.querySelector(selector);
866 function selection_select(select) {
867 if (typeof select !== "function") select = selector(select);
869 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
870 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
871 if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
872 if ("__data__" in node) subnode.__data__ = node.__data__;
873 subgroup[i] = subnode;
878 return new Selection(subgroups, this._parents);
885 function selectorAll(selector) {
886 return selector == null ? empty : function() {
887 return this.querySelectorAll(selector);
891 function selection_selectAll(select) {
892 if (typeof select !== "function") select = selectorAll(select);
894 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
895 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
896 if (node = group[i]) {
897 subgroups.push(select.call(node, node.__data__, i, group));
903 return new Selection(subgroups, parents);
906 var matcher = function(selector) {
908 return this.matches(selector);
912 if (typeof document !== "undefined") {
913 var element = document.documentElement;
914 if (!element.matches) {
915 var vendorMatches = element.webkitMatchesSelector
916 || element.msMatchesSelector
917 || element.mozMatchesSelector
918 || element.oMatchesSelector;
919 matcher = function(selector) {
921 return vendorMatches.call(this, selector);
927 var matcher$1 = matcher;
929 function selection_filter(match) {
930 if (typeof match !== "function") match = matcher$1(match);
932 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
933 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
934 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
940 return new Selection(subgroups, this._parents);
943 function sparse(update) {
944 return new Array(update.length);
947 function selection_enter() {
948 return new Selection(this._enter || this._groups.map(sparse), this._parents);
951 function EnterNode(parent, datum) {
952 this.ownerDocument = parent.ownerDocument;
953 this.namespaceURI = parent.namespaceURI;
955 this._parent = parent;
956 this.__data__ = datum;
959 EnterNode.prototype = {
960 constructor: EnterNode,
961 appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
962 insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
963 querySelector: function(selector) { return this._parent.querySelector(selector); },
964 querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
967 function constant$1(x) {
973 var keyPrefix = "$"; // Protect against keys like “__proto__”.
975 function bindIndex(parent, group, enter, update, exit, data) {
978 groupLength = group.length,
979 dataLength = data.length;
981 // Put any non-null nodes that fit into update.
982 // Put any null nodes into enter.
983 // Put any remaining data into enter.
984 for (; i < dataLength; ++i) {
985 if (node = group[i]) {
986 node.__data__ = data[i];
989 enter[i] = new EnterNode(parent, data[i]);
993 // Put any non-null nodes that don’t fit into exit.
994 for (; i < groupLength; ++i) {
995 if (node = group[i]) {
1001 function bindKey(parent, group, enter, update, exit, data, key) {
1004 nodeByKeyValue = {},
1005 groupLength = group.length,
1006 dataLength = data.length,
1007 keyValues = new Array(groupLength),
1010 // Compute the key for each node.
1011 // If multiple nodes have the same key, the duplicates are added to exit.
1012 for (i = 0; i < groupLength; ++i) {
1013 if (node = group[i]) {
1014 keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
1015 if (keyValue in nodeByKeyValue) {
1018 nodeByKeyValue[keyValue] = node;
1023 // Compute the key for each datum.
1024 // If there a node associated with this key, join and add it to update.
1025 // If there is not (or the key is a duplicate), add it to enter.
1026 for (i = 0; i < dataLength; ++i) {
1027 keyValue = keyPrefix + key.call(parent, data[i], i, data);
1028 if (node = nodeByKeyValue[keyValue]) {
1030 node.__data__ = data[i];
1031 nodeByKeyValue[keyValue] = null;
1033 enter[i] = new EnterNode(parent, data[i]);
1037 // Add any remaining nodes that were not bound to data to exit.
1038 for (i = 0; i < groupLength; ++i) {
1039 if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
1045 function selection_data(value, key) {
1047 data = new Array(this.size()), j = -1;
1048 this.each(function(d) { data[++j] = d; });
1052 var bind = key ? bindKey : bindIndex,
1053 parents = this._parents,
1054 groups = this._groups;
1056 if (typeof value !== "function") value = constant$1(value);
1058 for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
1059 var parent = parents[j],
1061 groupLength = group.length,
1062 data = value.call(parent, parent && parent.__data__, j, parents),
1063 dataLength = data.length,
1064 enterGroup = enter[j] = new Array(dataLength),
1065 updateGroup = update[j] = new Array(dataLength),
1066 exitGroup = exit[j] = new Array(groupLength);
1068 bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
1070 // Now connect the enter nodes to their following update node, such that
1071 // appendChild can insert the materialized enter node before this node,
1072 // rather than at the end of the parent node.
1073 for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
1074 if (previous = enterGroup[i0]) {
1075 if (i0 >= i1) i1 = i0 + 1;
1076 while (!(next = updateGroup[i1]) && ++i1 < dataLength);
1077 previous._next = next || null;
1082 update = new Selection(update, parents);
1083 update._enter = enter;
1084 update._exit = exit;
1088 function selection_exit() {
1089 return new Selection(this._exit || this._groups.map(sparse), this._parents);
1092 function selection_merge(selection$$1) {
1094 for (var groups0 = this._groups, groups1 = selection$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
1095 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
1096 if (node = group0[i] || group1[i]) {
1102 for (; j < m0; ++j) {
1103 merges[j] = groups0[j];
1106 return new Selection(merges, this._parents);
1109 function selection_order() {
1111 for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
1112 for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
1113 if (node = group[i]) {
1114 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
1123 function selection_sort(compare) {
1124 if (!compare) compare = ascending$1;
1126 function compareNode(a, b) {
1127 return a && b ? compare(a.__data__, b.__data__) : !a - !b;
1130 for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
1131 for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
1132 if (node = group[i]) {
1133 sortgroup[i] = node;
1136 sortgroup.sort(compareNode);
1139 return new Selection(sortgroups, this._parents).order();
1142 function ascending$1(a, b) {
1143 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
1146 function selection_call() {
1147 var callback = arguments[0];
1148 arguments[0] = this;
1149 callback.apply(null, arguments);
1153 function selection_nodes() {
1154 var nodes = new Array(this.size()), i = -1;
1155 this.each(function() { nodes[++i] = this; });
1159 function selection_node() {
1161 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1162 for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
1163 var node = group[i];
1164 if (node) return node;
1171 function selection_size() {
1173 this.each(function() { ++size; });
1177 function selection_empty() {
1178 return !this.node();
1181 function selection_each(callback) {
1183 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1184 for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
1185 if (node = group[i]) callback.call(node, node.__data__, i, group);
1192 function attrRemove(name) {
1194 this.removeAttribute(name);
1198 function attrRemoveNS(fullname) {
1200 this.removeAttributeNS(fullname.space, fullname.local);
1204 function attrConstant(name, value) {
1206 this.setAttribute(name, value);
1210 function attrConstantNS(fullname, value) {
1212 this.setAttributeNS(fullname.space, fullname.local, value);
1216 function attrFunction(name, value) {
1218 var v = value.apply(this, arguments);
1219 if (v == null) this.removeAttribute(name);
1220 else this.setAttribute(name, v);
1224 function attrFunctionNS(fullname, value) {
1226 var v = value.apply(this, arguments);
1227 if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
1228 else this.setAttributeNS(fullname.space, fullname.local, v);
1232 function selection_attr(name, value) {
1233 var fullname = namespace(name);
1235 if (arguments.length < 2) {
1236 var node = this.node();
1237 return fullname.local
1238 ? node.getAttributeNS(fullname.space, fullname.local)
1239 : node.getAttribute(fullname);
1242 return this.each((value == null
1243 ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
1244 ? (fullname.local ? attrFunctionNS : attrFunction)
1245 : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
1248 function defaultView(node) {
1249 return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
1250 || (node.document && node) // node is a Window
1251 || node.defaultView; // node is a Document
1254 function styleRemove(name) {
1256 this.style.removeProperty(name);
1260 function styleConstant(name, value, priority) {
1262 this.style.setProperty(name, value, priority);
1266 function styleFunction(name, value, priority) {
1268 var v = value.apply(this, arguments);
1269 if (v == null) this.style.removeProperty(name);
1270 else this.style.setProperty(name, v, priority);
1274 function selection_style(name, value, priority) {
1275 return arguments.length > 1
1276 ? this.each((value == null
1277 ? styleRemove : typeof value === "function"
1279 : styleConstant)(name, value, priority == null ? "" : priority))
1280 : styleValue(this.node(), name);
1283 function styleValue(node, name) {
1284 return node.style.getPropertyValue(name)
1285 || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
1288 function propertyRemove(name) {
1294 function propertyConstant(name, value) {
1300 function propertyFunction(name, value) {
1302 var v = value.apply(this, arguments);
1303 if (v == null) delete this[name];
1304 else this[name] = v;
1308 function selection_property(name, value) {
1309 return arguments.length > 1
1310 ? this.each((value == null
1311 ? propertyRemove : typeof value === "function"
1313 : propertyConstant)(name, value))
1314 : this.node()[name];
1317 function classArray(string) {
1318 return string.trim().split(/^|\s+/);
1321 function classList(node) {
1322 return node.classList || new ClassList(node);
1325 function ClassList(node) {
1327 this._names = classArray(node.getAttribute("class") || "");
1330 ClassList.prototype = {
1331 add: function(name) {
1332 var i = this._names.indexOf(name);
1334 this._names.push(name);
1335 this._node.setAttribute("class", this._names.join(" "));
1338 remove: function(name) {
1339 var i = this._names.indexOf(name);
1341 this._names.splice(i, 1);
1342 this._node.setAttribute("class", this._names.join(" "));
1345 contains: function(name) {
1346 return this._names.indexOf(name) >= 0;
1350 function classedAdd(node, names) {
1351 var list = classList(node), i = -1, n = names.length;
1352 while (++i < n) list.add(names[i]);
1355 function classedRemove(node, names) {
1356 var list = classList(node), i = -1, n = names.length;
1357 while (++i < n) list.remove(names[i]);
1360 function classedTrue(names) {
1362 classedAdd(this, names);
1366 function classedFalse(names) {
1368 classedRemove(this, names);
1372 function classedFunction(names, value) {
1374 (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
1378 function selection_classed(name, value) {
1379 var names = classArray(name + "");
1381 if (arguments.length < 2) {
1382 var list = classList(this.node()), i = -1, n = names.length;
1383 while (++i < n) if (!list.contains(names[i])) return false;
1387 return this.each((typeof value === "function"
1388 ? classedFunction : value
1390 : classedFalse)(names, value));
1393 function textRemove() {
1394 this.textContent = "";
1397 function textConstant(value) {
1399 this.textContent = value;
1403 function textFunction(value) {
1405 var v = value.apply(this, arguments);
1406 this.textContent = v == null ? "" : v;
1410 function selection_text(value) {
1411 return arguments.length
1412 ? this.each(value == null
1413 ? textRemove : (typeof value === "function"
1415 : textConstant)(value))
1416 : this.node().textContent;
1419 function htmlRemove() {
1420 this.innerHTML = "";
1423 function htmlConstant(value) {
1425 this.innerHTML = value;
1429 function htmlFunction(value) {
1431 var v = value.apply(this, arguments);
1432 this.innerHTML = v == null ? "" : v;
1436 function selection_html(value) {
1437 return arguments.length
1438 ? this.each(value == null
1439 ? htmlRemove : (typeof value === "function"
1441 : htmlConstant)(value))
1442 : this.node().innerHTML;
1446 if (this.nextSibling) this.parentNode.appendChild(this);
1449 function selection_raise() {
1450 return this.each(raise);
1454 if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
1457 function selection_lower() {
1458 return this.each(lower);
1461 function selection_append(name) {
1462 var create = typeof name === "function" ? name : creator(name);
1463 return this.select(function() {
1464 return this.appendChild(create.apply(this, arguments));
1468 function constantNull() {
1472 function selection_insert(name, before) {
1473 var create = typeof name === "function" ? name : creator(name),
1474 select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
1475 return this.select(function() {
1476 return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
1481 var parent = this.parentNode;
1482 if (parent) parent.removeChild(this);
1485 function selection_remove() {
1486 return this.each(remove);
1489 function selection_cloneShallow() {
1490 return this.parentNode.insertBefore(this.cloneNode(false), this.nextSibling);
1493 function selection_cloneDeep() {
1494 return this.parentNode.insertBefore(this.cloneNode(true), this.nextSibling);
1497 function selection_clone(deep) {
1498 return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
1501 function selection_datum(value) {
1502 return arguments.length
1503 ? this.property("__data__", value)
1504 : this.node().__data__;
1507 var filterEvents = {};
1509 exports.event = null;
1511 if (typeof document !== "undefined") {
1512 var element$1 = document.documentElement;
1513 if (!("onmouseenter" in element$1)) {
1514 filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
1518 function filterContextListener(listener, index, group) {
1519 listener = contextListener(listener, index, group);
1520 return function(event) {
1521 var related = event.relatedTarget;
1522 if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
1523 listener.call(this, event);
1528 function contextListener(listener, index, group) {
1529 return function(event1) {
1530 var event0 = exports.event; // Events can be reentrant (e.g., focus).
1531 exports.event = event1;
1533 listener.call(this, this.__data__, index, group);
1535 exports.event = event0;
1540 function parseTypenames$1(typenames) {
1541 return typenames.trim().split(/^|\s+/).map(function(t) {
1542 var name = "", i = t.indexOf(".");
1543 if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
1544 return {type: t, name: name};
1548 function onRemove(typename) {
1552 for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
1553 if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
1554 this.removeEventListener(o.type, o.listener, o.capture);
1559 if (++i) on.length = i;
1560 else delete this.__on;
1564 function onAdd(typename, value, capture) {
1565 var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
1566 return function(d, i, group) {
1567 var on = this.__on, o, listener = wrap(value, i, group);
1568 if (on) for (var j = 0, m = on.length; j < m; ++j) {
1569 if ((o = on[j]).type === typename.type && o.name === typename.name) {
1570 this.removeEventListener(o.type, o.listener, o.capture);
1571 this.addEventListener(o.type, o.listener = listener, o.capture = capture);
1576 this.addEventListener(typename.type, listener, capture);
1577 o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
1578 if (!on) this.__on = [o];
1583 function selection_on(typename, value, capture) {
1584 var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
1586 if (arguments.length < 2) {
1587 var on = this.node().__on;
1588 if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
1589 for (i = 0, o = on[j]; i < n; ++i) {
1590 if ((t = typenames[i]).type === o.type && t.name === o.name) {
1598 on = value ? onAdd : onRemove;
1599 if (capture == null) capture = false;
1600 for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
1604 function customEvent(event1, listener, that, args) {
1605 var event0 = exports.event;
1606 event1.sourceEvent = exports.event;
1607 exports.event = event1;
1609 return listener.apply(that, args);
1611 exports.event = event0;
1615 function dispatchEvent(node, type, params) {
1616 var window = defaultView(node),
1617 event = window.CustomEvent;
1619 if (typeof event === "function") {
1620 event = new event(type, params);
1622 event = window.document.createEvent("Event");
1623 if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
1624 else event.initEvent(type, false, false);
1627 node.dispatchEvent(event);
1630 function dispatchConstant(type, params) {
1632 return dispatchEvent(this, type, params);
1636 function dispatchFunction(type, params) {
1638 return dispatchEvent(this, type, params.apply(this, arguments));
1642 function selection_dispatch(type, params) {
1643 return this.each((typeof params === "function"
1645 : dispatchConstant)(type, params));
1650 function Selection(groups, parents) {
1651 this._groups = groups;
1652 this._parents = parents;
1655 function selection() {
1656 return new Selection([[document.documentElement]], root);
1659 Selection.prototype = selection.prototype = {
1660 constructor: Selection,
1661 select: selection_select,
1662 selectAll: selection_selectAll,
1663 filter: selection_filter,
1664 data: selection_data,
1665 enter: selection_enter,
1666 exit: selection_exit,
1667 merge: selection_merge,
1668 order: selection_order,
1669 sort: selection_sort,
1670 call: selection_call,
1671 nodes: selection_nodes,
1672 node: selection_node,
1673 size: selection_size,
1674 empty: selection_empty,
1675 each: selection_each,
1676 attr: selection_attr,
1677 style: selection_style,
1678 property: selection_property,
1679 classed: selection_classed,
1680 text: selection_text,
1681 html: selection_html,
1682 raise: selection_raise,
1683 lower: selection_lower,
1684 append: selection_append,
1685 insert: selection_insert,
1686 remove: selection_remove,
1687 clone: selection_clone,
1688 datum: selection_datum,
1690 dispatch: selection_dispatch
1693 function select(selector) {
1694 return typeof selector === "string"
1695 ? new Selection([[document.querySelector(selector)]], [document.documentElement])
1696 : new Selection([[selector]], root);
1699 function create(name) {
1700 return select(creator(name).call(document.documentElement));
1710 this._ = "@" + (++nextId).toString(36);
1713 Local.prototype = local.prototype = {
1715 get: function(node) {
1717 while (!(id in node)) if (!(node = node.parentNode)) return;
1720 set: function(node, value) {
1721 return node[this._] = value;
1723 remove: function(node) {
1724 return this._ in node && delete node[this._];
1726 toString: function() {
1731 function sourceEvent() {
1732 var current = exports.event, source;
1733 while (source = current.sourceEvent) current = source;
1737 function point(node, event) {
1738 var svg = node.ownerSVGElement || node;
1740 if (svg.createSVGPoint) {
1741 var point = svg.createSVGPoint();
1742 point.x = event.clientX, point.y = event.clientY;
1743 point = point.matrixTransform(node.getScreenCTM().inverse());
1744 return [point.x, point.y];
1747 var rect = node.getBoundingClientRect();
1748 return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
1751 function mouse(node) {
1752 var event = sourceEvent();
1753 if (event.changedTouches) event = event.changedTouches[0];
1754 return point(node, event);
1757 function selectAll(selector) {
1758 return typeof selector === "string"
1759 ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
1760 : new Selection([selector == null ? [] : selector], root);
1763 function touch(node, touches, identifier) {
1764 if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
1766 for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
1767 if ((touch = touches[i]).identifier === identifier) {
1768 return point(node, touch);
1775 function touches(node, touches) {
1776 if (touches == null) touches = sourceEvent().touches;
1778 for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
1779 points[i] = point(node, touches[i]);
1785 function nopropagation() {
1786 exports.event.stopImmediatePropagation();
1789 function noevent() {
1790 exports.event.preventDefault();
1791 exports.event.stopImmediatePropagation();
1794 function dragDisable(view) {
1795 var root = view.document.documentElement,
1796 selection$$1 = select(view).on("dragstart.drag", noevent, true);
1797 if ("onselectstart" in root) {
1798 selection$$1.on("selectstart.drag", noevent, true);
1800 root.__noselect = root.style.MozUserSelect;
1801 root.style.MozUserSelect = "none";
1805 function yesdrag(view, noclick) {
1806 var root = view.document.documentElement,
1807 selection$$1 = select(view).on("dragstart.drag", null);
1809 selection$$1.on("click.drag", noevent, true);
1810 setTimeout(function() { selection$$1.on("click.drag", null); }, 0);
1812 if ("onselectstart" in root) {
1813 selection$$1.on("selectstart.drag", null);
1815 root.style.MozUserSelect = root.__noselect;
1816 delete root.__noselect;
1820 function constant$2(x) {
1826 function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
1827 this.target = target;
1829 this.subject = subject;
1830 this.identifier = id;
1831 this.active = active;
1839 DragEvent.prototype.on = function() {
1840 var value = this._.on.apply(this._, arguments);
1841 return value === this._ ? this : value;
1844 // Ignore right-click, since that should open the context menu.
1845 function defaultFilter() {
1846 return !exports.event.button;
1849 function defaultContainer() {
1850 return this.parentNode;
1853 function defaultSubject(d) {
1854 return d == null ? {x: exports.event.x, y: exports.event.y} : d;
1857 function defaultTouchable() {
1858 return "ontouchstart" in this;
1862 var filter = defaultFilter,
1863 container = defaultContainer,
1864 subject = defaultSubject,
1865 touchable = defaultTouchable,
1867 listeners = dispatch("start", "drag", "end"),
1875 function drag(selection$$1) {
1877 .on("mousedown.drag", mousedowned)
1879 .on("touchstart.drag", touchstarted)
1880 .on("touchmove.drag", touchmoved)
1881 .on("touchend.drag touchcancel.drag", touchended)
1882 .style("touch-action", "none")
1883 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
1886 function mousedowned() {
1887 if (touchending || !filter.apply(this, arguments)) return;
1888 var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
1889 if (!gesture) return;
1890 select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
1891 dragDisable(exports.event.view);
1893 mousemoving = false;
1894 mousedownx = exports.event.clientX;
1895 mousedowny = exports.event.clientY;
1899 function mousemoved() {
1902 var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
1903 mousemoving = dx * dx + dy * dy > clickDistance2;
1905 gestures.mouse("drag");
1908 function mouseupped() {
1909 select(exports.event.view).on("mousemove.drag mouseup.drag", null);
1910 yesdrag(exports.event.view, mousemoving);
1912 gestures.mouse("end");
1915 function touchstarted() {
1916 if (!filter.apply(this, arguments)) return;
1917 var touches$$1 = exports.event.changedTouches,
1918 c = container.apply(this, arguments),
1919 n = touches$$1.length, i, gesture;
1921 for (i = 0; i < n; ++i) {
1922 if (gesture = beforestart(touches$$1[i].identifier, c, touch, this, arguments)) {
1929 function touchmoved() {
1930 var touches$$1 = exports.event.changedTouches,
1931 n = touches$$1.length, i, gesture;
1933 for (i = 0; i < n; ++i) {
1934 if (gesture = gestures[touches$$1[i].identifier]) {
1941 function touchended() {
1942 var touches$$1 = exports.event.changedTouches,
1943 n = touches$$1.length, i, gesture;
1945 if (touchending) clearTimeout(touchending);
1946 touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
1947 for (i = 0; i < n; ++i) {
1948 if (gesture = gestures[touches$$1[i].identifier]) {
1955 function beforestart(id, container, point$$1, that, args) {
1956 var p = point$$1(container, id), s, dx, dy,
1957 sublisteners = listeners.copy();
1959 if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
1960 if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
1961 dx = s.x - p[0] || 0;
1962 dy = s.y - p[1] || 0;
1966 return function gesture(type) {
1969 case "start": gestures[id] = gesture, n = active++; break;
1970 case "end": delete gestures[id], --active; // nobreak
1971 case "drag": p = point$$1(container, id), n = active; break;
1973 customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);
1977 drag.filter = function(_) {
1978 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
1981 drag.container = function(_) {
1982 return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
1985 drag.subject = function(_) {
1986 return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
1989 drag.touchable = function(_) {
1990 return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
1993 drag.on = function() {
1994 var value = listeners.on.apply(listeners, arguments);
1995 return value === listeners ? drag : value;
1998 drag.clickDistance = function(_) {
1999 return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
2005 function define(constructor, factory, prototype) {
2006 constructor.prototype = factory.prototype = prototype;
2007 prototype.constructor = constructor;
2010 function extend(parent, definition) {
2011 var prototype = Object.create(parent.prototype);
2012 for (var key in definition) prototype[key] = definition[key];
2019 var brighter = 1 / darker;
2021 var reI = "\\s*([+-]?\\d+)\\s*",
2022 reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
2023 reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
2024 reHex3 = /^#([0-9a-f]{3})$/,
2025 reHex6 = /^#([0-9a-f]{6})$/,
2026 reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
2027 reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
2028 reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
2029 reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
2030 reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
2031 reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
2034 aliceblue: 0xf0f8ff,
2035 antiquewhite: 0xfaebd7,
2037 aquamarine: 0x7fffd4,
2042 blanchedalmond: 0xffebcd,
2044 blueviolet: 0x8a2be2,
2046 burlywood: 0xdeb887,
2047 cadetblue: 0x5f9ea0,
2048 chartreuse: 0x7fff00,
2049 chocolate: 0xd2691e,
2051 cornflowerblue: 0x6495ed,
2057 darkgoldenrod: 0xb8860b,
2059 darkgreen: 0x006400,
2061 darkkhaki: 0xbdb76b,
2062 darkmagenta: 0x8b008b,
2063 darkolivegreen: 0x556b2f,
2064 darkorange: 0xff8c00,
2065 darkorchid: 0x9932cc,
2067 darksalmon: 0xe9967a,
2068 darkseagreen: 0x8fbc8f,
2069 darkslateblue: 0x483d8b,
2070 darkslategray: 0x2f4f4f,
2071 darkslategrey: 0x2f4f4f,
2072 darkturquoise: 0x00ced1,
2073 darkviolet: 0x9400d3,
2075 deepskyblue: 0x00bfff,
2078 dodgerblue: 0x1e90ff,
2079 firebrick: 0xb22222,
2080 floralwhite: 0xfffaf0,
2081 forestgreen: 0x228b22,
2083 gainsboro: 0xdcdcdc,
2084 ghostwhite: 0xf8f8ff,
2086 goldenrod: 0xdaa520,
2089 greenyellow: 0xadff2f,
2093 indianred: 0xcd5c5c,
2098 lavenderblush: 0xfff0f5,
2099 lawngreen: 0x7cfc00,
2100 lemonchiffon: 0xfffacd,
2101 lightblue: 0xadd8e6,
2102 lightcoral: 0xf08080,
2103 lightcyan: 0xe0ffff,
2104 lightgoldenrodyellow: 0xfafad2,
2105 lightgray: 0xd3d3d3,
2106 lightgreen: 0x90ee90,
2107 lightgrey: 0xd3d3d3,
2108 lightpink: 0xffb6c1,
2109 lightsalmon: 0xffa07a,
2110 lightseagreen: 0x20b2aa,
2111 lightskyblue: 0x87cefa,
2112 lightslategray: 0x778899,
2113 lightslategrey: 0x778899,
2114 lightsteelblue: 0xb0c4de,
2115 lightyellow: 0xffffe0,
2117 limegreen: 0x32cd32,
2121 mediumaquamarine: 0x66cdaa,
2122 mediumblue: 0x0000cd,
2123 mediumorchid: 0xba55d3,
2124 mediumpurple: 0x9370db,
2125 mediumseagreen: 0x3cb371,
2126 mediumslateblue: 0x7b68ee,
2127 mediumspringgreen: 0x00fa9a,
2128 mediumturquoise: 0x48d1cc,
2129 mediumvioletred: 0xc71585,
2130 midnightblue: 0x191970,
2131 mintcream: 0xf5fffa,
2132 mistyrose: 0xffe4e1,
2134 navajowhite: 0xffdead,
2138 olivedrab: 0x6b8e23,
2140 orangered: 0xff4500,
2142 palegoldenrod: 0xeee8aa,
2143 palegreen: 0x98fb98,
2144 paleturquoise: 0xafeeee,
2145 palevioletred: 0xdb7093,
2146 papayawhip: 0xffefd5,
2147 peachpuff: 0xffdab9,
2151 powderblue: 0xb0e0e6,
2153 rebeccapurple: 0x663399,
2155 rosybrown: 0xbc8f8f,
2156 royalblue: 0x4169e1,
2157 saddlebrown: 0x8b4513,
2159 sandybrown: 0xf4a460,
2165 slateblue: 0x6a5acd,
2166 slategray: 0x708090,
2167 slategrey: 0x708090,
2169 springgreen: 0x00ff7f,
2170 steelblue: 0x4682b4,
2175 turquoise: 0x40e0d0,
2179 whitesmoke: 0xf5f5f5,
2181 yellowgreen: 0x9acd32
2184 define(Color, color, {
2185 displayable: function() {
2186 return this.rgb().displayable();
2189 return this.rgb().hex();
2191 toString: function() {
2192 return this.rgb() + "";
2196 function color(format) {
2198 format = (format + "").trim().toLowerCase();
2199 return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)) // #f00
2200 : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
2201 : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
2202 : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
2203 : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
2204 : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
2205 : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
2206 : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
2207 : named.hasOwnProperty(format) ? rgbn(named[format])
2208 : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
2213 return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
2216 function rgba(r, g, b, a) {
2217 if (a <= 0) r = g = b = NaN;
2218 return new Rgb(r, g, b, a);
2221 function rgbConvert(o) {
2222 if (!(o instanceof Color)) o = color(o);
2223 if (!o) return new Rgb;
2225 return new Rgb(o.r, o.g, o.b, o.opacity);
2228 function rgb(r, g, b, opacity) {
2229 return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
2232 function Rgb(r, g, b, opacity) {
2236 this.opacity = +opacity;
2239 define(Rgb, rgb, extend(Color, {
2240 brighter: function(k) {
2241 k = k == null ? brighter : Math.pow(brighter, k);
2242 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2244 darker: function(k) {
2245 k = k == null ? darker : Math.pow(darker, k);
2246 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2251 displayable: function() {
2252 return (0 <= this.r && this.r <= 255)
2253 && (0 <= this.g && this.g <= 255)
2254 && (0 <= this.b && this.b <= 255)
2255 && (0 <= this.opacity && this.opacity <= 1);
2258 return "#" + hex(this.r) + hex(this.g) + hex(this.b);
2260 toString: function() {
2261 var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
2262 return (a === 1 ? "rgb(" : "rgba(")
2263 + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
2264 + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
2265 + Math.max(0, Math.min(255, Math.round(this.b) || 0))
2266 + (a === 1 ? ")" : ", " + a + ")");
2270 function hex(value) {
2271 value = Math.max(0, Math.min(255, Math.round(value) || 0));
2272 return (value < 16 ? "0" : "") + value.toString(16);
2275 function hsla(h, s, l, a) {
2276 if (a <= 0) h = s = l = NaN;
2277 else if (l <= 0 || l >= 1) h = s = NaN;
2278 else if (s <= 0) h = NaN;
2279 return new Hsl(h, s, l, a);
2282 function hslConvert(o) {
2283 if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
2284 if (!(o instanceof Color)) o = color(o);
2285 if (!o) return new Hsl;
2286 if (o instanceof Hsl) return o;
2291 min = Math.min(r, g, b),
2292 max = Math.max(r, g, b),
2295 l = (max + min) / 2;
2297 if (r === max) h = (g - b) / s + (g < b) * 6;
2298 else if (g === max) h = (b - r) / s + 2;
2299 else h = (r - g) / s + 4;
2300 s /= l < 0.5 ? max + min : 2 - max - min;
2303 s = l > 0 && l < 1 ? 0 : h;
2305 return new Hsl(h, s, l, o.opacity);
2308 function hsl(h, s, l, opacity) {
2309 return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
2312 function Hsl(h, s, l, opacity) {
2316 this.opacity = +opacity;
2319 define(Hsl, hsl, extend(Color, {
2320 brighter: function(k) {
2321 k = k == null ? brighter : Math.pow(brighter, k);
2322 return new Hsl(this.h, this.s, this.l * k, this.opacity);
2324 darker: function(k) {
2325 k = k == null ? darker : Math.pow(darker, k);
2326 return new Hsl(this.h, this.s, this.l * k, this.opacity);
2329 var h = this.h % 360 + (this.h < 0) * 360,
2330 s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
2332 m2 = l + (l < 0.5 ? l : 1 - l) * s,
2335 hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
2337 hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
2341 displayable: function() {
2342 return (0 <= this.s && this.s <= 1 || isNaN(this.s))
2343 && (0 <= this.l && this.l <= 1)
2344 && (0 <= this.opacity && this.opacity <= 1);
2348 /* From FvD 13.37, CSS Color Module Level 3 */
2349 function hsl2rgb(h, m1, m2) {
2350 return (h < 60 ? m1 + (m2 - m1) * h / 60
2352 : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
2356 var deg2rad = Math.PI / 180;
2357 var rad2deg = 180 / Math.PI;
2359 // https://beta.observablehq.com/@mbostock/lab-and-rgb
2369 function labConvert(o) {
2370 if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
2371 if (o instanceof Hcl) {
2372 if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
2373 var h = o.h * deg2rad;
2374 return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
2376 if (!(o instanceof Rgb)) o = rgbConvert(o);
2377 var r = rgb2lrgb(o.r),
2380 y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
2381 if (r === g && g === b) x = z = y; else {
2382 x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
2383 z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
2385 return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
2388 function gray(l, opacity) {
2389 return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
2392 function lab(l, a, b, opacity) {
2393 return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
2396 function Lab(l, a, b, opacity) {
2400 this.opacity = +opacity;
2403 define(Lab, lab, extend(Color, {
2404 brighter: function(k) {
2405 return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
2407 darker: function(k) {
2408 return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
2411 var y = (this.l + 16) / 116,
2412 x = isNaN(this.a) ? y : y + this.a / 500,
2413 z = isNaN(this.b) ? y : y - this.b / 200;
2414 x = Xn * lab2xyz(x);
2415 y = Yn * lab2xyz(y);
2416 z = Zn * lab2xyz(z);
2418 lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
2419 lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
2420 lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
2426 function xyz2lab(t) {
2427 return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
2430 function lab2xyz(t) {
2431 return t > t1 ? t * t * t : t2 * (t - t0);
2434 function lrgb2rgb(x) {
2435 return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
2438 function rgb2lrgb(x) {
2439 return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
2442 function hclConvert(o) {
2443 if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
2444 if (!(o instanceof Lab)) o = labConvert(o);
2445 if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0, o.l, o.opacity);
2446 var h = Math.atan2(o.b, o.a) * rad2deg;
2447 return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
2450 function lch(l, c, h, opacity) {
2451 return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
2454 function hcl(h, c, l, opacity) {
2455 return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
2458 function Hcl(h, c, l, opacity) {
2462 this.opacity = +opacity;
2465 define(Hcl, hcl, extend(Color, {
2466 brighter: function(k) {
2467 return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
2469 darker: function(k) {
2470 return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
2473 return labConvert(this).rgb();
2484 BC_DA = B * C - D * A;
2486 function cubehelixConvert(o) {
2487 if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
2488 if (!(o instanceof Rgb)) o = rgbConvert(o);
2492 l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
2494 k = (E * (g - l) - C * bl) / D,
2495 s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
2496 h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
2497 return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
2500 function cubehelix(h, s, l, opacity) {
2501 return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
2504 function Cubehelix(h, s, l, opacity) {
2508 this.opacity = +opacity;
2511 define(Cubehelix, cubehelix, extend(Color, {
2512 brighter: function(k) {
2513 k = k == null ? brighter : Math.pow(brighter, k);
2514 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2516 darker: function(k) {
2517 k = k == null ? darker : Math.pow(darker, k);
2518 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2521 var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
2523 a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
2527 255 * (l + a * (A * cosh + B * sinh)),
2528 255 * (l + a * (C * cosh + D * sinh)),
2529 255 * (l + a * (E * cosh)),
2535 function basis(t1, v0, v1, v2, v3) {
2536 var t2 = t1 * t1, t3 = t2 * t1;
2537 return ((1 - 3 * t1 + 3 * t2 - t3) * v0
2538 + (4 - 6 * t2 + 3 * t3) * v1
2539 + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
2543 function basis$1(values) {
2544 var n = values.length - 1;
2545 return function(t) {
2546 var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
2549 v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
2550 v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
2551 return basis((t - i / n) * n, v0, v1, v2, v3);
2555 function basisClosed(values) {
2556 var n = values.length;
2557 return function(t) {
2558 var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
2559 v0 = values[(i + n - 1) % n],
2561 v2 = values[(i + 1) % n],
2562 v3 = values[(i + 2) % n];
2563 return basis((t - i / n) * n, v0, v1, v2, v3);
2567 function constant$3(x) {
2573 function linear(a, d) {
2574 return function(t) {
2579 function exponential(a, b, y) {
2580 return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
2581 return Math.pow(a + t * b, y);
2585 function hue(a, b) {
2587 return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
2591 return (y = +y) === 1 ? nogamma : function(a, b) {
2592 return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
2596 function nogamma(a, b) {
2598 return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
2601 var interpolateRgb = (function rgbGamma(y) {
2602 var color$$1 = gamma(y);
2604 function rgb$$1(start, end) {
2605 var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
2606 g = color$$1(start.g, end.g),
2607 b = color$$1(start.b, end.b),
2608 opacity = nogamma(start.opacity, end.opacity);
2609 return function(t) {
2613 start.opacity = opacity(t);
2618 rgb$$1.gamma = rgbGamma;
2623 function rgbSpline(spline) {
2624 return function(colors) {
2625 var n = colors.length,
2630 for (i = 0; i < n; ++i) {
2631 color$$1 = rgb(colors[i]);
2632 r[i] = color$$1.r || 0;
2633 g[i] = color$$1.g || 0;
2634 b[i] = color$$1.b || 0;
2639 color$$1.opacity = 1;
2640 return function(t) {
2644 return color$$1 + "";
2649 var rgbBasis = rgbSpline(basis$1);
2650 var rgbBasisClosed = rgbSpline(basisClosed);
2652 function array$1(a, b) {
2653 var nb = b ? b.length : 0,
2654 na = a ? Math.min(nb, a.length) : 0,
2659 for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
2660 for (; i < nb; ++i) c[i] = b[i];
2662 return function(t) {
2663 for (i = 0; i < na; ++i) c[i] = x[i](t);
2668 function date(a, b) {
2670 return a = +a, b -= a, function(t) {
2671 return d.setTime(a + b * t), d;
2675 function reinterpolate(a, b) {
2676 return a = +a, b -= a, function(t) {
2681 function object(a, b) {
2686 if (a === null || typeof a !== "object") a = {};
2687 if (b === null || typeof b !== "object") b = {};
2691 i[k] = interpolateValue(a[k], b[k]);
2697 return function(t) {
2698 for (k in i) c[k] = i[k](t);
2703 var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
2704 reB = new RegExp(reA.source, "g");
2713 return function(t) {
2718 function interpolateString(a, b) {
2719 var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
2720 am, // current match in a
2721 bm, // current match in b
2722 bs, // string preceding current number in b, if any
2723 i = -1, // index in s
2724 s = [], // string constants and placeholders
2725 q = []; // number interpolators
2727 // Coerce inputs to strings.
2728 a = a + "", b = b + "";
2730 // Interpolate pairs of numbers in a & b.
2731 while ((am = reA.exec(a))
2732 && (bm = reB.exec(b))) {
2733 if ((bs = bm.index) > bi) { // a string precedes the next number in b
2734 bs = b.slice(bi, bs);
2735 if (s[i]) s[i] += bs; // coalesce with previous string
2738 if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
2739 if (s[i]) s[i] += bm; // coalesce with previous string
2741 } else { // interpolate non-matching numbers
2743 q.push({i: i, x: reinterpolate(am, bm)});
2748 // Add remains of b.
2749 if (bi < b.length) {
2751 if (s[i]) s[i] += bs; // coalesce with previous string
2755 // Special optimization for only a single match.
2756 // Otherwise, interpolate each of the numbers and rejoin the string.
2757 return s.length < 2 ? (q[0]
2760 : (b = q.length, function(t) {
2761 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
2766 function interpolateValue(a, b) {
2767 var t = typeof b, c;
2768 return b == null || t === "boolean" ? constant$3(b)
2769 : (t === "number" ? reinterpolate
2770 : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
2771 : b instanceof color ? interpolateRgb
2772 : b instanceof Date ? date
2773 : Array.isArray(b) ? array$1
2774 : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
2775 : reinterpolate)(a, b);
2778 function interpolateRound(a, b) {
2779 return a = +a, b -= a, function(t) {
2780 return Math.round(a + b * t);
2784 var degrees = 180 / Math.PI;
2795 function decompose(a, b, c, d, e, f) {
2796 var scaleX, scaleY, skewX;
2797 if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
2798 if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
2799 if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
2800 if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
2804 rotate: Math.atan2(b, a) * degrees,
2805 skewX: Math.atan(skewX) * degrees,
2816 function parseCss(value) {
2817 if (value === "none") return identity$2;
2818 if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
2819 cssNode.style.transform = value;
2820 value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
2821 cssRoot.removeChild(cssNode);
2822 value = value.slice(7, -1).split(",");
2823 return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
2826 function parseSvg(value) {
2827 if (value == null) return identity$2;
2828 if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
2829 svgNode.setAttribute("transform", value);
2830 if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
2831 value = value.matrix;
2832 return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
2835 function interpolateTransform(parse, pxComma, pxParen, degParen) {
2838 return s.length ? s.pop() + " " : "";
2841 function translate(xa, ya, xb, yb, s, q) {
2842 if (xa !== xb || ya !== yb) {
2843 var i = s.push("translate(", null, pxComma, null, pxParen);
2844 q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
2845 } else if (xb || yb) {
2846 s.push("translate(" + xb + pxComma + yb + pxParen);
2850 function rotate(a, b, s, q) {
2852 if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
2853 q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: reinterpolate(a, b)});
2855 s.push(pop(s) + "rotate(" + b + degParen);
2859 function skewX(a, b, s, q) {
2861 q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: reinterpolate(a, b)});
2863 s.push(pop(s) + "skewX(" + b + degParen);
2867 function scale(xa, ya, xb, yb, s, q) {
2868 if (xa !== xb || ya !== yb) {
2869 var i = s.push(pop(s) + "scale(", null, ",", null, ")");
2870 q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
2871 } else if (xb !== 1 || yb !== 1) {
2872 s.push(pop(s) + "scale(" + xb + "," + yb + ")");
2876 return function(a, b) {
2877 var s = [], // string constants and placeholders
2878 q = []; // number interpolators
2879 a = parse(a), b = parse(b);
2880 translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
2881 rotate(a.rotate, b.rotate, s, q);
2882 skewX(a.skewX, b.skewX, s, q);
2883 scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
2885 return function(t) {
2886 var i = -1, n = q.length, o;
2887 while (++i < n) s[(o = q[i]).i] = o.x(t);
2893 var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
2894 var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
2896 var rho = Math.SQRT2,
2902 return ((x = Math.exp(x)) + 1 / x) / 2;
2906 return ((x = Math.exp(x)) - 1 / x) / 2;
2910 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
2913 // p0 = [ux0, uy0, w0]
2914 // p1 = [ux1, uy1, w1]
2915 function interpolateZoom(p0, p1) {
2916 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
2917 ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
2920 d2 = dx * dx + dy * dy,
2924 // Special case for u0 ≅ u1.
2925 if (d2 < epsilon2) {
2926 S = Math.log(w1 / w0) / rho;
2931 w0 * Math.exp(rho * t * S)
2938 var d1 = Math.sqrt(d2),
2939 b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
2940 b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
2941 r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
2942 r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
2943 S = (r1 - r0) / rho;
2947 u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
2951 w0 * coshr0 / cosh(rho * s + r0)
2956 i.duration = S * 1000;
2961 function hsl$1(hue$$1) {
2962 return function(start, end) {
2963 var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
2964 s = nogamma(start.s, end.s),
2965 l = nogamma(start.l, end.l),
2966 opacity = nogamma(start.opacity, end.opacity);
2967 return function(t) {
2971 start.opacity = opacity(t);
2977 var hsl$2 = hsl$1(hue);
2978 var hslLong = hsl$1(nogamma);
2980 function lab$1(start, end) {
2981 var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
2982 a = nogamma(start.a, end.a),
2983 b = nogamma(start.b, end.b),
2984 opacity = nogamma(start.opacity, end.opacity);
2985 return function(t) {
2989 start.opacity = opacity(t);
2994 function hcl$1(hue$$1) {
2995 return function(start, end) {
2996 var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
2997 c = nogamma(start.c, end.c),
2998 l = nogamma(start.l, end.l),
2999 opacity = nogamma(start.opacity, end.opacity);
3000 return function(t) {
3004 start.opacity = opacity(t);
3010 var hcl$2 = hcl$1(hue);
3011 var hclLong = hcl$1(nogamma);
3013 function cubehelix$1(hue$$1) {
3014 return (function cubehelixGamma(y) {
3017 function cubehelix$$1(start, end) {
3018 var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
3019 s = nogamma(start.s, end.s),
3020 l = nogamma(start.l, end.l),
3021 opacity = nogamma(start.opacity, end.opacity);
3022 return function(t) {
3025 start.l = l(Math.pow(t, y));
3026 start.opacity = opacity(t);
3031 cubehelix$$1.gamma = cubehelixGamma;
3033 return cubehelix$$1;
3037 var cubehelix$2 = cubehelix$1(hue);
3038 var cubehelixLong = cubehelix$1(nogamma);
3040 function piecewise(interpolate, values) {
3041 var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
3042 while (i < n) I[i] = interpolate(v, v = values[++i]);
3043 return function(t) {
3044 var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
3049 function quantize(interpolator, n) {
3050 var samples = new Array(n);
3051 for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
3055 var frame = 0, // is an animation frame pending?
3056 timeout = 0, // is a timeout pending?
3057 interval = 0, // are any timers active?
3058 pokeDelay = 1000, // how frequently we check for clock skew
3064 clock = typeof performance === "object" && performance.now ? performance : Date,
3065 setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
3068 return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
3071 function clearNow() {
3081 Timer.prototype = timer.prototype = {
3083 restart: function(callback, delay, time) {
3084 if (typeof callback !== "function") throw new TypeError("callback is not a function");
3085 time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
3086 if (!this._next && taskTail !== this) {
3087 if (taskTail) taskTail._next = this;
3088 else taskHead = this;
3091 this._call = callback;
3098 this._time = Infinity;
3104 function timer(callback, delay, time) {
3106 t.restart(callback, delay, time);
3110 function timerFlush() {
3111 now(); // Get the current time, if not already set.
3112 ++frame; // Pretend we’ve set an alarm, if we haven’t already.
3113 var t = taskHead, e;
3115 if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
3122 clockNow = (clockLast = clock.now()) + clockSkew;
3123 frame = timeout = 0;
3134 var now = clock.now(), delay = now - clockLast;
3135 if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
3139 var t0, t1 = taskHead, t2, time = Infinity;
3142 if (time > t1._time) time = t1._time;
3143 t0 = t1, t1 = t1._next;
3145 t2 = t1._next, t1._next = null;
3146 t1 = t0 ? t0._next = t2 : taskHead = t2;
3153 function sleep(time) {
3154 if (frame) return; // Soonest alarm already set, or will be.
3155 if (timeout) timeout = clearTimeout(timeout);
3156 var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
3158 if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
3159 if (interval) interval = clearInterval(interval);
3161 if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
3162 frame = 1, setFrame(wake);
3166 function timeout$1(callback, delay, time) {
3168 delay = delay == null ? 0 : +delay;
3169 t.restart(function(elapsed) {
3171 callback(elapsed + delay);
3176 function interval$1(callback, delay, time) {
3177 var t = new Timer, total = delay;
3178 if (delay == null) return t.restart(callback, delay, time), t;
3179 delay = +delay, time = time == null ? now() : +time;
3180 t.restart(function tick(elapsed) {
3182 t.restart(tick, total += delay, time);
3188 var emptyOn = dispatch("start", "end", "interrupt");
3189 var emptyTween = [];
3199 function schedule(node, name, id, index, group, timing) {
3200 var schedules = node.__transition;
3201 if (!schedules) node.__transition = {};
3202 else if (id in schedules) return;
3203 create$1(node, id, {
3205 index: index, // For context during callback.
3206 group: group, // For context during callback.
3210 delay: timing.delay,
3211 duration: timing.duration,
3218 function init(node, id) {
3219 var schedule = get$1(node, id);
3220 if (schedule.state > CREATED) throw new Error("too late; already scheduled");
3224 function set$1(node, id) {
3225 var schedule = get$1(node, id);
3226 if (schedule.state > STARTING) throw new Error("too late; already started");
3230 function get$1(node, id) {
3231 var schedule = node.__transition;
3232 if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
3236 function create$1(node, id, self) {
3237 var schedules = node.__transition,
3240 // Initialize the self timer when the transition is created.
3241 // Note the actual delay is not known until the first callback!
3242 schedules[id] = self;
3243 self.timer = timer(schedule, 0, self.time);
3245 function schedule(elapsed) {
3246 self.state = SCHEDULED;
3247 self.timer.restart(start, self.delay, self.time);
3249 // If the elapsed delay is less than our first sleep, start immediately.
3250 if (self.delay <= elapsed) start(elapsed - self.delay);
3253 function start(elapsed) {
3256 // If the state is not SCHEDULED, then we previously errored on start.
3257 if (self.state !== SCHEDULED) return stop();
3259 for (i in schedules) {
3261 if (o.name !== self.name) continue;
3263 // While this element already has a starting transition during this frame,
3264 // defer starting an interrupting transition until that transition has a
3265 // chance to tick (and possibly end); see d3/d3-transition#54!
3266 if (o.state === STARTED) return timeout$1(start);
3268 // Interrupt the active transition, if any.
3269 // Dispatch the interrupt event.
3270 if (o.state === RUNNING) {
3273 o.on.call("interrupt", node, node.__data__, o.index, o.group);
3274 delete schedules[i];
3277 // Cancel any pre-empted transitions. No interrupt event is dispatched
3278 // because the cancelled transitions never started. Note that this also
3279 // removes this transition from the pending list!
3283 delete schedules[i];
3287 // Defer the first tick to end of the current frame; see d3/d3#1576.
3288 // Note the transition may be canceled after start and before the first tick!
3289 // Note this must be scheduled before the start event; see d3/d3-transition#16!
3290 // Assuming this is successful, subsequent callbacks go straight to tick.
3291 timeout$1(function() {
3292 if (self.state === STARTED) {
3293 self.state = RUNNING;
3294 self.timer.restart(tick, self.delay, self.time);
3299 // Dispatch the start event.
3300 // Note this must be done before the tween are initialized.
3301 self.state = STARTING;
3302 self.on.call("start", node, node.__data__, self.index, self.group);
3303 if (self.state !== STARTING) return; // interrupted
3304 self.state = STARTED;
3306 // Initialize the tween, deleting null tween.
3307 tween = new Array(n = self.tween.length);
3308 for (i = 0, j = -1; i < n; ++i) {
3309 if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
3313 tween.length = j + 1;
3316 function tick(elapsed) {
3317 var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
3322 tween[i].call(null, t);
3325 // Dispatch the end event.
3326 if (self.state === ENDING) {
3327 self.on.call("end", node, node.__data__, self.index, self.group);
3335 delete schedules[id];
3336 for (var i in schedules) return; // eslint-disable-line no-unused-vars
3337 delete node.__transition;
3341 function interrupt(node, name) {
3342 var schedules = node.__transition,
3348 if (!schedules) return;
3350 name = name == null ? null : name + "";
3352 for (i in schedules) {
3353 if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
3354 active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
3355 schedule$$1.state = ENDED;
3356 schedule$$1.timer.stop();
3357 if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
3358 delete schedules[i];
3361 if (empty) delete node.__transition;
3364 function selection_interrupt(name) {
3365 return this.each(function() {
3366 interrupt(this, name);
3370 function tweenRemove(id, name) {
3373 var schedule$$1 = set$1(this, id),
3374 tween = schedule$$1.tween;
3376 // If this node shared tween with the previous node,
3377 // just assign the updated shared tween and we’re done!
3378 // Otherwise, copy-on-write.
3379 if (tween !== tween0) {
3380 tween1 = tween0 = tween;
3381 for (var i = 0, n = tween1.length; i < n; ++i) {
3382 if (tween1[i].name === name) {
3383 tween1 = tween1.slice();
3384 tween1.splice(i, 1);
3390 schedule$$1.tween = tween1;
3394 function tweenFunction(id, name, value) {
3396 if (typeof value !== "function") throw new Error;
3398 var schedule$$1 = set$1(this, id),
3399 tween = schedule$$1.tween;
3401 // If this node shared tween with the previous node,
3402 // just assign the updated shared tween and we’re done!
3403 // Otherwise, copy-on-write.
3404 if (tween !== tween0) {
3405 tween1 = (tween0 = tween).slice();
3406 for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
3407 if (tween1[i].name === name) {
3412 if (i === n) tween1.push(t);
3415 schedule$$1.tween = tween1;
3419 function transition_tween(name, value) {
3424 if (arguments.length < 2) {
3425 var tween = get$1(this.node(), id).tween;
3426 for (var i = 0, n = tween.length, t; i < n; ++i) {
3427 if ((t = tween[i]).name === name) {
3434 return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
3437 function tweenValue(transition, name, value) {
3438 var id = transition._id;
3440 transition.each(function() {
3441 var schedule$$1 = set$1(this, id);
3442 (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
3445 return function(node) {
3446 return get$1(node, id).value[name];
3450 function interpolate(a, b) {
3452 return (typeof b === "number" ? reinterpolate
3453 : b instanceof color ? interpolateRgb
3454 : (c = color(b)) ? (b = c, interpolateRgb)
3455 : interpolateString)(a, b);
3458 function attrRemove$1(name) {
3460 this.removeAttribute(name);
3464 function attrRemoveNS$1(fullname) {
3466 this.removeAttributeNS(fullname.space, fullname.local);
3470 function attrConstant$1(name, interpolate$$1, value1) {
3474 var value0 = this.getAttribute(name);
3475 return value0 === value1 ? null
3476 : value0 === value00 ? interpolate0
3477 : interpolate0 = interpolate$$1(value00 = value0, value1);
3481 function attrConstantNS$1(fullname, interpolate$$1, value1) {
3485 var value0 = this.getAttributeNS(fullname.space, fullname.local);
3486 return value0 === value1 ? null
3487 : value0 === value00 ? interpolate0
3488 : interpolate0 = interpolate$$1(value00 = value0, value1);
3492 function attrFunction$1(name, interpolate$$1, value) {
3497 var value0, value1 = value(this);
3498 if (value1 == null) return void this.removeAttribute(name);
3499 value0 = this.getAttribute(name);
3500 return value0 === value1 ? null
3501 : value0 === value00 && value1 === value10 ? interpolate0
3502 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3506 function attrFunctionNS$1(fullname, interpolate$$1, value) {
3511 var value0, value1 = value(this);
3512 if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
3513 value0 = this.getAttributeNS(fullname.space, fullname.local);
3514 return value0 === value1 ? null
3515 : value0 === value00 && value1 === value10 ? interpolate0
3516 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3520 function transition_attr(name, value) {
3521 var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
3522 return this.attrTween(name, typeof value === "function"
3523 ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
3524 : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
3525 : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
3528 function attrTweenNS(fullname, value) {
3530 var node = this, i = value.apply(node, arguments);
3531 return i && function(t) {
3532 node.setAttributeNS(fullname.space, fullname.local, i(t));
3535 tween._value = value;
3539 function attrTween(name, value) {
3541 var node = this, i = value.apply(node, arguments);
3542 return i && function(t) {
3543 node.setAttribute(name, i(t));
3546 tween._value = value;
3550 function transition_attrTween(name, value) {
3551 var key = "attr." + name;
3552 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3553 if (value == null) return this.tween(key, null);
3554 if (typeof value !== "function") throw new Error;
3555 var fullname = namespace(name);
3556 return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
3559 function delayFunction(id, value) {
3561 init(this, id).delay = +value.apply(this, arguments);
3565 function delayConstant(id, value) {
3566 return value = +value, function() {
3567 init(this, id).delay = value;
3571 function transition_delay(value) {
3574 return arguments.length
3575 ? this.each((typeof value === "function"
3577 : delayConstant)(id, value))
3578 : get$1(this.node(), id).delay;
3581 function durationFunction(id, value) {
3583 set$1(this, id).duration = +value.apply(this, arguments);
3587 function durationConstant(id, value) {
3588 return value = +value, function() {
3589 set$1(this, id).duration = value;
3593 function transition_duration(value) {
3596 return arguments.length
3597 ? this.each((typeof value === "function"
3599 : durationConstant)(id, value))
3600 : get$1(this.node(), id).duration;
3603 function easeConstant(id, value) {
3604 if (typeof value !== "function") throw new Error;
3606 set$1(this, id).ease = value;
3610 function transition_ease(value) {
3613 return arguments.length
3614 ? this.each(easeConstant(id, value))
3615 : get$1(this.node(), id).ease;
3618 function transition_filter(match) {
3619 if (typeof match !== "function") match = matcher$1(match);
3621 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3622 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
3623 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
3624 subgroup.push(node);
3629 return new Transition(subgroups, this._parents, this._name, this._id);
3632 function transition_merge(transition$$1) {
3633 if (transition$$1._id !== this._id) throw new Error;
3635 for (var groups0 = this._groups, groups1 = transition$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
3636 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
3637 if (node = group0[i] || group1[i]) {
3643 for (; j < m0; ++j) {
3644 merges[j] = groups0[j];
3647 return new Transition(merges, this._parents, this._name, this._id);
3650 function start(name) {
3651 return (name + "").trim().split(/^|\s+/).every(function(t) {
3652 var i = t.indexOf(".");
3653 if (i >= 0) t = t.slice(0, i);
3654 return !t || t === "start";
3658 function onFunction(id, name, listener) {
3659 var on0, on1, sit = start(name) ? init : set$1;
3661 var schedule$$1 = sit(this, id),
3662 on = schedule$$1.on;
3664 // If this node shared a dispatch with the previous node,
3665 // just assign the updated shared dispatch and we’re done!
3666 // Otherwise, copy-on-write.
3667 if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
3669 schedule$$1.on = on1;
3673 function transition_on(name, listener) {
3676 return arguments.length < 2
3677 ? get$1(this.node(), id).on.on(name)
3678 : this.each(onFunction(id, name, listener));
3681 function removeFunction(id) {
3683 var parent = this.parentNode;
3684 for (var i in this.__transition) if (+i !== id) return;
3685 if (parent) parent.removeChild(this);
3689 function transition_remove() {
3690 return this.on("end.remove", removeFunction(this._id));
3693 function transition_select(select$$1) {
3694 var name = this._name,
3697 if (typeof select$$1 !== "function") select$$1 = selector(select$$1);
3699 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3700 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
3701 if ((node = group[i]) && (subnode = select$$1.call(node, node.__data__, i, group))) {
3702 if ("__data__" in node) subnode.__data__ = node.__data__;
3703 subgroup[i] = subnode;
3704 schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
3709 return new Transition(subgroups, this._parents, name, id);
3712 function transition_selectAll(select$$1) {
3713 var name = this._name,
3716 if (typeof select$$1 !== "function") select$$1 = selectorAll(select$$1);
3718 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
3719 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3720 if (node = group[i]) {
3721 for (var children = select$$1.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
3722 if (child = children[k]) {
3723 schedule(child, name, id, k, children, inherit);
3726 subgroups.push(children);
3732 return new Transition(subgroups, parents, name, id);
3735 var Selection$1 = selection.prototype.constructor;
3737 function transition_selection() {
3738 return new Selection$1(this._groups, this._parents);
3741 function styleRemove$1(name, interpolate$$1) {
3746 var value0 = styleValue(this, name),
3747 value1 = (this.style.removeProperty(name), styleValue(this, name));
3748 return value0 === value1 ? null
3749 : value0 === value00 && value1 === value10 ? interpolate0
3750 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3754 function styleRemoveEnd(name) {
3756 this.style.removeProperty(name);
3760 function styleConstant$1(name, interpolate$$1, value1) {
3764 var value0 = styleValue(this, name);
3765 return value0 === value1 ? null
3766 : value0 === value00 ? interpolate0
3767 : interpolate0 = interpolate$$1(value00 = value0, value1);
3771 function styleFunction$1(name, interpolate$$1, value) {
3776 var value0 = styleValue(this, name),
3777 value1 = value(this);
3778 if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
3779 return value0 === value1 ? null
3780 : value0 === value00 && value1 === value10 ? interpolate0
3781 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3785 function transition_style(name, value, priority) {
3786 var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
3787 return value == null ? this
3788 .styleTween(name, styleRemove$1(name, i))
3789 .on("end.style." + name, styleRemoveEnd(name))
3790 : this.styleTween(name, typeof value === "function"
3791 ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
3792 : styleConstant$1(name, i, value + ""), priority);
3795 function styleTween(name, value, priority) {
3797 var node = this, i = value.apply(node, arguments);
3798 return i && function(t) {
3799 node.style.setProperty(name, i(t), priority);
3802 tween._value = value;
3806 function transition_styleTween(name, value, priority) {
3807 var key = "style." + (name += "");
3808 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3809 if (value == null) return this.tween(key, null);
3810 if (typeof value !== "function") throw new Error;
3811 return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
3814 function textConstant$1(value) {
3816 this.textContent = value;
3820 function textFunction$1(value) {
3822 var value1 = value(this);
3823 this.textContent = value1 == null ? "" : value1;
3827 function transition_text(value) {
3828 return this.tween("text", typeof value === "function"
3829 ? textFunction$1(tweenValue(this, "text", value))
3830 : textConstant$1(value == null ? "" : value + ""));
3833 function transition_transition() {
3834 var name = this._name,
3838 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
3839 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3840 if (node = group[i]) {
3841 var inherit = get$1(node, id0);
3842 schedule(node, name, id1, i, group, {
3843 time: inherit.time + inherit.delay + inherit.duration,
3845 duration: inherit.duration,
3852 return new Transition(groups, this._parents, name, id1);
3857 function Transition(groups, parents, name, id) {
3858 this._groups = groups;
3859 this._parents = parents;
3864 function transition(name) {
3865 return selection().transition(name);
3872 var selection_prototype = selection.prototype;
3874 Transition.prototype = transition.prototype = {
3875 constructor: Transition,
3876 select: transition_select,
3877 selectAll: transition_selectAll,
3878 filter: transition_filter,
3879 merge: transition_merge,
3880 selection: transition_selection,
3881 transition: transition_transition,
3882 call: selection_prototype.call,
3883 nodes: selection_prototype.nodes,
3884 node: selection_prototype.node,
3885 size: selection_prototype.size,
3886 empty: selection_prototype.empty,
3887 each: selection_prototype.each,
3889 attr: transition_attr,
3890 attrTween: transition_attrTween,
3891 style: transition_style,
3892 styleTween: transition_styleTween,
3893 text: transition_text,
3894 remove: transition_remove,
3895 tween: transition_tween,
3896 delay: transition_delay,
3897 duration: transition_duration,
3898 ease: transition_ease
3901 function linear$1(t) {
3905 function quadIn(t) {
3909 function quadOut(t) {
3913 function quadInOut(t) {
3914 return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
3917 function cubicIn(t) {
3921 function cubicOut(t) {
3922 return --t * t * t + 1;
3925 function cubicInOut(t) {
3926 return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
3931 var polyIn = (function custom(e) {
3934 function polyIn(t) {
3935 return Math.pow(t, e);
3938 polyIn.exponent = custom;
3943 var polyOut = (function custom(e) {
3946 function polyOut(t) {
3947 return 1 - Math.pow(1 - t, e);
3950 polyOut.exponent = custom;
3955 var polyInOut = (function custom(e) {
3958 function polyInOut(t) {
3959 return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
3962 polyInOut.exponent = custom;
3971 return 1 - Math.cos(t * halfPi);
3974 function sinOut(t) {
3975 return Math.sin(t * halfPi);
3978 function sinInOut(t) {
3979 return (1 - Math.cos(pi * t)) / 2;
3983 return Math.pow(2, 10 * t - 10);
3986 function expOut(t) {
3987 return 1 - Math.pow(2, -10 * t);
3990 function expInOut(t) {
3991 return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
3994 function circleIn(t) {
3995 return 1 - Math.sqrt(1 - t * t);
3998 function circleOut(t) {
3999 return Math.sqrt(1 - --t * t);
4002 function circleInOut(t) {
4003 return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
4017 function bounceIn(t) {
4018 return 1 - bounceOut(1 - t);
4021 function bounceOut(t) {
4022 return (t = +t) < b1 ? b0 * t * t : t < b3 ? b0 * (t -= b2) * t + b4 : t < b6 ? b0 * (t -= b5) * t + b7 : b0 * (t -= b8) * t + b9;
4025 function bounceInOut(t) {
4026 return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
4029 var overshoot = 1.70158;
4031 var backIn = (function custom(s) {
4034 function backIn(t) {
4035 return t * t * ((s + 1) * t - s);
4038 backIn.overshoot = custom;
4043 var backOut = (function custom(s) {
4046 function backOut(t) {
4047 return --t * t * ((s + 1) * t + s) + 1;
4050 backOut.overshoot = custom;
4055 var backInOut = (function custom(s) {
4058 function backInOut(t) {
4059 return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
4062 backInOut.overshoot = custom;
4067 var tau = 2 * Math.PI,
4071 var elasticIn = (function custom(a, p) {
4072 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4074 function elasticIn(t) {
4075 return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
4078 elasticIn.amplitude = function(a) { return custom(a, p * tau); };
4079 elasticIn.period = function(p) { return custom(a, p); };
4082 })(amplitude, period);
4084 var elasticOut = (function custom(a, p) {
4085 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4087 function elasticOut(t) {
4088 return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
4091 elasticOut.amplitude = function(a) { return custom(a, p * tau); };
4092 elasticOut.period = function(p) { return custom(a, p); };
4095 })(amplitude, period);
4097 var elasticInOut = (function custom(a, p) {
4098 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4100 function elasticInOut(t) {
4101 return ((t = t * 2 - 1) < 0
4102 ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
4103 : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
4106 elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
4107 elasticInOut.period = function(p) { return custom(a, p); };
4109 return elasticInOut;
4110 })(amplitude, period);
4112 var defaultTiming = {
4113 time: null, // Set on use.
4119 function inherit(node, id) {
4121 while (!(timing = node.__transition) || !(timing = timing[id])) {
4122 if (!(node = node.parentNode)) {
4123 return defaultTiming.time = now(), defaultTiming;
4129 function selection_transition(name) {
4133 if (name instanceof Transition) {
4134 id = name._id, name = name._name;
4136 id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
4139 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
4140 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
4141 if (node = group[i]) {
4142 schedule(node, name, id, i, group, timing || inherit(node, id));
4147 return new Transition(groups, this._parents, name, id);
4150 selection.prototype.interrupt = selection_interrupt;
4151 selection.prototype.transition = selection_transition;
4153 var root$1 = [null];
4155 function active(node, name) {
4156 var schedules = node.__transition,
4161 name = name == null ? null : name + "";
4162 for (i in schedules) {
4163 if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
4164 return new Transition([[node]], root$1, name, +i);
4172 function constant$4(x) {
4178 function BrushEvent(target, type, selection) {
4179 this.target = target;
4181 this.selection = selection;
4184 function nopropagation$1() {
4185 exports.event.stopImmediatePropagation();
4188 function noevent$1() {
4189 exports.event.preventDefault();
4190 exports.event.stopImmediatePropagation();
4193 var MODE_DRAG = {name: "drag"},
4194 MODE_SPACE = {name: "space"},
4195 MODE_HANDLE = {name: "handle"},
4196 MODE_CENTER = {name: "center"};
4200 handles: ["e", "w"].map(type),
4201 input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
4202 output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
4207 handles: ["n", "s"].map(type),
4208 input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
4209 output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
4214 handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
4215 input: function(xy) { return xy; },
4216 output: function(xy) { return xy; }
4220 overlay: "crosshair",
4280 // Ignore right-click, since that should open the context menu.
4281 function defaultFilter$1() {
4282 return !exports.event.button;
4285 function defaultExtent() {
4286 var svg = this.ownerSVGElement || this;
4287 return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
4290 // Like d3.local, but with the name “__brush” rather than auto-generated.
4291 function local$1(node) {
4292 while (!node.__brush) if (!(node = node.parentNode)) return;
4293 return node.__brush;
4296 function empty$1(extent) {
4297 return extent[0][0] === extent[1][0]
4298 || extent[0][1] === extent[1][1];
4301 function brushSelection(node) {
4302 var state = node.__brush;
4303 return state ? state.dim.output(state.selection) : null;
4318 function brush$1(dim) {
4319 var extent = defaultExtent,
4320 filter = defaultFilter$1,
4321 listeners = dispatch(brush, "start", "brush", "end"),
4325 function brush(group) {
4327 .property("__brush", initialize)
4328 .selectAll(".overlay")
4329 .data([type("overlay")]);
4331 overlay.enter().append("rect")
4332 .attr("class", "overlay")
4333 .attr("pointer-events", "all")
4334 .attr("cursor", cursors.overlay)
4337 var extent = local$1(this).extent;
4339 .attr("x", extent[0][0])
4340 .attr("y", extent[0][1])
4341 .attr("width", extent[1][0] - extent[0][0])
4342 .attr("height", extent[1][1] - extent[0][1]);
4345 group.selectAll(".selection")
4346 .data([type("selection")])
4347 .enter().append("rect")
4348 .attr("class", "selection")
4349 .attr("cursor", cursors.selection)
4350 .attr("fill", "#777")
4351 .attr("fill-opacity", 0.3)
4352 .attr("stroke", "#fff")
4353 .attr("shape-rendering", "crispEdges");
4355 var handle = group.selectAll(".handle")
4356 .data(dim.handles, function(d) { return d.type; });
4358 handle.exit().remove();
4360 handle.enter().append("rect")
4361 .attr("class", function(d) { return "handle handle--" + d.type; })
4362 .attr("cursor", function(d) { return cursors[d.type]; });
4366 .attr("fill", "none")
4367 .attr("pointer-events", "all")
4368 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
4369 .on("mousedown.brush touchstart.brush", started);
4372 brush.move = function(group, selection$$1) {
4373 if (group.selection) {
4375 .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
4376 .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
4377 .tween("brush", function() {
4379 state = that.__brush,
4380 emit = emitter(that, arguments),
4381 selection0 = state.selection,
4382 selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(this, arguments) : selection$$1, state.extent),
4383 i = interpolateValue(selection0, selection1);
4386 state.selection = t === 1 && empty$1(selection1) ? null : i(t);
4391 return selection0 && selection1 ? tween : tween(1);
4398 state = that.__brush,
4399 selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(that, args) : selection$$1, state.extent),
4400 emit = emitter(that, args).beforestart();
4403 state.selection = selection1 == null || empty$1(selection1) ? null : selection1;
4405 emit.start().brush().end();
4411 var group = select(this),
4412 selection$$1 = local$1(this).selection;
4415 group.selectAll(".selection")
4416 .style("display", null)
4417 .attr("x", selection$$1[0][0])
4418 .attr("y", selection$$1[0][1])
4419 .attr("width", selection$$1[1][0] - selection$$1[0][0])
4420 .attr("height", selection$$1[1][1] - selection$$1[0][1]);
4422 group.selectAll(".handle")
4423 .style("display", null)
4424 .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection$$1[1][0] - handleSize / 2 : selection$$1[0][0] - handleSize / 2; })
4425 .attr("y", function(d) { return d.type[0] === "s" ? selection$$1[1][1] - handleSize / 2 : selection$$1[0][1] - handleSize / 2; })
4426 .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection$$1[1][0] - selection$$1[0][0] + handleSize : handleSize; })
4427 .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection$$1[1][1] - selection$$1[0][1] + handleSize : handleSize; });
4431 group.selectAll(".selection,.handle")
4432 .style("display", "none")
4435 .attr("width", null)
4436 .attr("height", null);
4440 function emitter(that, args) {
4441 return that.__brush.emitter || new Emitter(that, args);
4444 function Emitter(that, args) {
4447 this.state = that.__brush;
4451 Emitter.prototype = {
4452 beforestart: function() {
4453 if (++this.active === 1) this.state.emitter = this, this.starting = true;
4457 if (this.starting) this.starting = false, this.emit("start");
4465 if (--this.active === 0) delete this.state.emitter, this.emit("end");
4468 emit: function(type) {
4469 customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
4473 function started() {
4474 if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
4475 else if (touchending) return;
4476 if (!filter.apply(this, arguments)) return;
4479 type = exports.event.target.__data__.type,
4480 mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
4481 signX = dim === Y ? null : signsX[type],
4482 signY = dim === X ? null : signsY[type],
4483 state = local$1(that),
4484 extent = state.extent,
4485 selection$$1 = state.selection,
4486 W = extent[0][0], w0, w1,
4487 N = extent[0][1], n0, n1,
4488 E = extent[1][0], e0, e1,
4489 S = extent[1][1], s0, s1,
4493 shifting = signX && signY && exports.event.shiftKey,
4496 point0 = mouse(that),
4498 emit = emitter(that, arguments).beforestart();
4500 if (type === "overlay") {
4501 state.selection = selection$$1 = [
4502 [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
4503 [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
4506 w0 = selection$$1[0][0];
4507 n0 = selection$$1[0][1];
4508 e0 = selection$$1[1][0];
4509 s0 = selection$$1[1][1];
4517 var group = select(that)
4518 .attr("pointer-events", "none");
4520 var overlay = group.selectAll(".overlay")
4521 .attr("cursor", cursors[type]);
4523 if (exports.event.touches) {
4525 .on("touchmove.brush", moved, true)
4526 .on("touchend.brush touchcancel.brush", ended, true);
4528 var view = select(exports.event.view)
4529 .on("keydown.brush", keydowned, true)
4530 .on("keyup.brush", keyupped, true)
4531 .on("mousemove.brush", moved, true)
4532 .on("mouseup.brush", ended, true);
4534 dragDisable(exports.event.view);
4543 var point1 = mouse(that);
4544 if (shifting && !lockX && !lockY) {
4545 if (Math.abs(point1[0] - point$$1[0]) > Math.abs(point1[1] - point$$1[1])) lockY = true;
4557 dx = point$$1[0] - point0[0];
4558 dy = point$$1[1] - point0[1];
4563 if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
4564 if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
4568 if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
4569 else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
4570 if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
4571 else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
4575 if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
4576 if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
4583 t = w0, w0 = e0, e0 = t;
4584 t = w1, w1 = e1, e1 = t;
4585 if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
4590 t = n0, n0 = s0, s0 = t;
4591 t = n1, n1 = s1, s1 = t;
4592 if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
4595 if (state.selection) selection$$1 = state.selection; // May be set by brush.move!
4596 if (lockX) w1 = selection$$1[0][0], e1 = selection$$1[1][0];
4597 if (lockY) n1 = selection$$1[0][1], s1 = selection$$1[1][1];
4599 if (selection$$1[0][0] !== w1
4600 || selection$$1[0][1] !== n1
4601 || selection$$1[1][0] !== e1
4602 || selection$$1[1][1] !== s1) {
4603 state.selection = [[w1, n1], [e1, s1]];
4611 if (exports.event.touches) {
4612 if (exports.event.touches.length) return;
4613 if (touchending) clearTimeout(touchending);
4614 touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
4615 group.on("touchmove.brush touchend.brush touchcancel.brush", null);
4617 yesdrag(exports.event.view, moving);
4618 view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
4620 group.attr("pointer-events", "all");
4621 overlay.attr("cursor", cursors.overlay);
4622 if (state.selection) selection$$1 = state.selection; // May be set by brush.move (on start)!
4623 if (empty$1(selection$$1)) state.selection = null, redraw.call(that);
4627 function keydowned() {
4628 switch (exports.event.keyCode) {
4630 shifting = signX && signY;
4634 if (mode === MODE_HANDLE) {
4635 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4636 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4642 case 32: { // SPACE; takes priority over ALT
4643 if (mode === MODE_HANDLE || mode === MODE_CENTER) {
4644 if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
4645 if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
4647 overlay.attr("cursor", cursors.selection);
4657 function keyupped() {
4658 switch (exports.event.keyCode) {
4661 lockX = lockY = shifting = false;
4667 if (mode === MODE_CENTER) {
4668 if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4669 if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4676 if (mode === MODE_SPACE) {
4677 if (exports.event.altKey) {
4678 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4679 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4682 if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4683 if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4686 overlay.attr("cursor", cursors[type]);
4697 function initialize() {
4698 var state = this.__brush || {selection: null};
4699 state.extent = extent.apply(this, arguments);
4704 brush.extent = function(_) {
4705 return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
4708 brush.filter = function(_) {
4709 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
4712 brush.handleSize = function(_) {
4713 return arguments.length ? (handleSize = +_, brush) : handleSize;
4716 brush.on = function() {
4717 var value = listeners.on.apply(listeners, arguments);
4718 return value === listeners ? brush : value;
4727 var halfPi$1 = pi$1 / 2;
4728 var tau$1 = pi$1 * 2;
4729 var max$1 = Math.max;
4731 function compareValue(compare) {
4732 return function(a, b) {
4734 a.source.value + a.target.value,
4735 b.source.value + b.target.value
4743 sortSubgroups = null,
4746 function chord(matrix) {
4747 var n = matrix.length,
4749 groupIndex = sequence(n),
4752 groups = chords.groups = new Array(n),
4753 subgroups = new Array(n * n),
4762 k = 0, i = -1; while (++i < n) {
4763 x = 0, j = -1; while (++j < n) {
4767 subgroupIndex.push(sequence(n));
4772 if (sortGroups) groupIndex.sort(function(a, b) {
4773 return sortGroups(groupSums[a], groupSums[b]);
4777 if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
4778 d.sort(function(a, b) {
4779 return sortSubgroups(matrix[i][a], matrix[i][b]);
4783 // Convert the sum to scaling factor for [0, 2pi].
4784 // TODO Allow start and end angle to be specified?
4785 // TODO Allow padding to be specified as percentage?
4786 k = max$1(0, tau$1 - padAngle * n) / k;
4787 dx = k ? padAngle : tau$1 / n;
4789 // Compute the start and end angle for each group and subgroup.
4790 // Note: Opera has a bug reordering object literal properties!
4791 x = 0, i = -1; while (++i < n) {
4792 x0 = x, j = -1; while (++j < n) {
4793 var di = groupIndex[i],
4794 dj = subgroupIndex[di][j],
4798 subgroups[dj * n + di] = {
4810 value: groupSums[di]
4815 // Generate chords for each (non-empty) subgroup-subgroup link.
4816 i = -1; while (++i < n) {
4817 j = i - 1; while (++j < n) {
4818 var source = subgroups[j * n + i],
4819 target = subgroups[i * n + j];
4820 if (source.value || target.value) {
4821 chords.push(source.value < target.value
4822 ? {source: target, target: source}
4823 : {source: source, target: target});
4828 return sortChords ? chords.sort(sortChords) : chords;
4831 chord.padAngle = function(_) {
4832 return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
4835 chord.sortGroups = function(_) {
4836 return arguments.length ? (sortGroups = _, chord) : sortGroups;
4839 chord.sortSubgroups = function(_) {
4840 return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
4843 chord.sortChords = function(_) {
4844 return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
4850 var slice$2 = Array.prototype.slice;
4852 function constant$5(x) {
4861 tauEpsilon = tau$2 - epsilon$1;
4864 this._x0 = this._y0 = // start of current subpath
4865 this._x1 = this._y1 = null; // end of current subpath
4873 Path.prototype = path.prototype = {
4875 moveTo: function(x, y) {
4876 this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
4878 closePath: function() {
4879 if (this._x1 !== null) {
4880 this._x1 = this._x0, this._y1 = this._y0;
4884 lineTo: function(x, y) {
4885 this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
4887 quadraticCurveTo: function(x1, y1, x, y) {
4888 this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
4890 bezierCurveTo: function(x1, y1, x2, y2, x, y) {
4891 this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
4893 arcTo: function(x1, y1, x2, y2, r) {
4894 x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
4901 l01_2 = x01 * x01 + y01 * y01;
4903 // Is the radius negative? Error.
4904 if (r < 0) throw new Error("negative radius: " + r);
4906 // Is this path empty? Move to (x1,y1).
4907 if (this._x1 === null) {
4908 this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
4911 // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
4912 else if (!(l01_2 > epsilon$1)) {}
4914 // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
4915 // Equivalently, is (x1,y1) coincident with (x2,y2)?
4916 // Or, is the radius zero? Line to (x1,y1).
4917 else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
4918 this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
4921 // Otherwise, draw an arc!
4925 l21_2 = x21 * x21 + y21 * y21,
4926 l20_2 = x20 * x20 + y20 * y20,
4927 l21 = Math.sqrt(l21_2),
4928 l01 = Math.sqrt(l01_2),
4929 l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
4933 // If the start tangent is not coincident with (x0,y0), line to.
4934 if (Math.abs(t01 - 1) > epsilon$1) {
4935 this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
4938 this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
4941 arc: function(x, y, r, a0, a1, ccw) {
4942 x = +x, y = +y, r = +r;
4943 var dx = r * Math.cos(a0),
4944 dy = r * Math.sin(a0),
4948 da = ccw ? a0 - a1 : a1 - a0;
4950 // Is the radius negative? Error.
4951 if (r < 0) throw new Error("negative radius: " + r);
4953 // Is this path empty? Move to (x0,y0).
4954 if (this._x1 === null) {
4955 this._ += "M" + x0 + "," + y0;
4958 // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
4959 else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
4960 this._ += "L" + x0 + "," + y0;
4963 // Is this arc empty? We’re done.
4966 // Does the angle go the wrong way? Flip the direction.
4967 if (da < 0) da = da % tau$2 + tau$2;
4969 // Is this a complete circle? Draw two arcs to complete the circle.
4970 if (da > tauEpsilon) {
4971 this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
4974 // Is this arc non-empty? Draw an arc!
4975 else if (da > epsilon$1) {
4976 this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
4979 rect: function(x, y, w, h) {
4980 this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
4982 toString: function() {
4987 function defaultSource(d) {
4991 function defaultTarget(d) {
4995 function defaultRadius(d) {
4999 function defaultStartAngle(d) {
5000 return d.startAngle;
5003 function defaultEndAngle(d) {
5008 var source = defaultSource,
5009 target = defaultTarget,
5010 radius = defaultRadius,
5011 startAngle = defaultStartAngle,
5012 endAngle = defaultEndAngle,
5017 argv = slice$2.call(arguments),
5018 s = source.apply(this, argv),
5019 t = target.apply(this, argv),
5020 sr = +radius.apply(this, (argv[0] = s, argv)),
5021 sa0 = startAngle.apply(this, argv) - halfPi$1,
5022 sa1 = endAngle.apply(this, argv) - halfPi$1,
5023 sx0 = sr * cos(sa0),
5024 sy0 = sr * sin(sa0),
5025 tr = +radius.apply(this, (argv[0] = t, argv)),
5026 ta0 = startAngle.apply(this, argv) - halfPi$1,
5027 ta1 = endAngle.apply(this, argv) - halfPi$1;
5029 if (!context) context = buffer = path();
5031 context.moveTo(sx0, sy0);
5032 context.arc(0, 0, sr, sa0, sa1);
5033 if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
5034 context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
5035 context.arc(0, 0, tr, ta0, ta1);
5037 context.quadraticCurveTo(0, 0, sx0, sy0);
5038 context.closePath();
5040 if (buffer) return context = null, buffer + "" || null;
5043 ribbon.radius = function(_) {
5044 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
5047 ribbon.startAngle = function(_) {
5048 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
5051 ribbon.endAngle = function(_) {
5052 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
5055 ribbon.source = function(_) {
5056 return arguments.length ? (source = _, ribbon) : source;
5059 ribbon.target = function(_) {
5060 return arguments.length ? (target = _, ribbon) : target;
5063 ribbon.context = function(_) {
5064 return arguments.length ? (context = _ == null ? null : _, ribbon) : context;
5074 Map.prototype = map$1.prototype = {
5076 has: function(key) {
5077 return (prefix + key) in this;
5079 get: function(key) {
5080 return this[prefix + key];
5082 set: function(key, value) {
5083 this[prefix + key] = value;
5086 remove: function(key) {
5087 var property = prefix + key;
5088 return property in this && delete this[property];
5091 for (var property in this) if (property[0] === prefix) delete this[property];
5095 for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
5098 values: function() {
5100 for (var property in this) if (property[0] === prefix) values.push(this[property]);
5103 entries: function() {
5105 for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
5110 for (var property in this) if (property[0] === prefix) ++size;
5114 for (var property in this) if (property[0] === prefix) return false;
5118 for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
5122 function map$1(object, f) {
5125 // Copy constructor.
5126 if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
5128 // Index array by numeric index or specified key function.
5129 else if (Array.isArray(object)) {
5134 if (f == null) while (++i < n) map.set(i, object[i]);
5135 else while (++i < n) map.set(f(o = object[i], i, object), o);
5138 // Convert object to map.
5139 else if (object) for (var key in object) map.set(key, object[key]);
5151 function apply(array, depth, createResult, setResult) {
5152 if (depth >= keys.length) {
5153 if (sortValues != null) array.sort(sortValues);
5154 return rollup != null ? rollup(array) : array;
5159 key = keys[depth++],
5162 valuesByKey = map$1(),
5164 result = createResult();
5167 if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
5170 valuesByKey.set(keyValue, [value]);
5174 valuesByKey.each(function(values, key) {
5175 setResult(result, key, apply(values, depth, createResult, setResult));
5181 function entries(map, depth) {
5182 if (++depth > keys.length) return map;
5183 var array, sortKey = sortKeys[depth - 1];
5184 if (rollup != null && depth >= keys.length) array = map.entries();
5185 else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
5186 return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
5190 object: function(array) { return apply(array, 0, createObject, setObject); },
5191 map: function(array) { return apply(array, 0, createMap, setMap); },
5192 entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
5193 key: function(d) { keys.push(d); return nest; },
5194 sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
5195 sortValues: function(order) { sortValues = order; return nest; },
5196 rollup: function(f) { rollup = f; return nest; }
5200 function createObject() {
5204 function setObject(object, key, value) {
5205 object[key] = value;
5208 function createMap() {
5212 function setMap(map, key, value) {
5213 map.set(key, value);
5218 var proto = map$1.prototype;
5220 Set.prototype = set$2.prototype = {
5223 add: function(value) {
5225 this[prefix + value] = value;
5228 remove: proto.remove,
5236 function set$2(object, f) {
5239 // Copy constructor.
5240 if (object instanceof Set) object.each(function(value) { set.add(value); });
5242 // Otherwise, assume it’s an array.
5244 var i = -1, n = object.length;
5245 if (f == null) while (++i < n) set.add(object[i]);
5246 else while (++i < n) set.add(f(object[i], i, object));
5252 function keys(map) {
5254 for (var key in map) keys.push(key);
5258 function values(map) {
5260 for (var key in map) values.push(map[key]);
5264 function entries(map) {
5266 for (var key in map) entries.push({key: key, value: map[key]});
5270 var array$2 = Array.prototype;
5272 var slice$3 = array$2.slice;
5274 function ascending$2(a, b) {
5278 function area(ring) {
5279 var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
5280 while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
5284 function constant$6(x) {
5290 function contains(ring, hole) {
5291 var i = -1, n = hole.length, c;
5292 while (++i < n) if (c = ringContains(ring, hole[i])) return c;
5296 function ringContains(ring, point) {
5297 var x = point[0], y = point[1], contains = -1;
5298 for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
5299 var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
5300 if (segmentContains(pi, pj, point)) return 0;
5301 if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
5306 function segmentContains(a, b, c) {
5307 var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
5310 function collinear(a, b, c) {
5311 return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
5314 function within(p, q, r) {
5315 return p <= q && q <= r || r <= q && q <= p;
5318 function noop$1() {}
5322 [[[1.0, 1.5], [0.5, 1.0]]],
5323 [[[1.5, 1.0], [1.0, 1.5]]],
5324 [[[1.5, 1.0], [0.5, 1.0]]],
5325 [[[1.0, 0.5], [1.5, 1.0]]],
5326 [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
5327 [[[1.0, 0.5], [1.0, 1.5]]],
5328 [[[1.0, 0.5], [0.5, 1.0]]],
5329 [[[0.5, 1.0], [1.0, 0.5]]],
5330 [[[1.0, 1.5], [1.0, 0.5]]],
5331 [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
5332 [[[1.5, 1.0], [1.0, 0.5]]],
5333 [[[0.5, 1.0], [1.5, 1.0]]],
5334 [[[1.0, 1.5], [1.5, 1.0]]],
5335 [[[0.5, 1.0], [1.0, 1.5]]],
5339 function contours() {
5342 threshold$$1 = thresholdSturges,
5343 smooth = smoothLinear;
5345 function contours(values) {
5346 var tz = threshold$$1(values);
5348 // Convert number of thresholds into uniform thresholds.
5349 if (!Array.isArray(tz)) {
5350 var domain = extent(values), start = domain[0], stop = domain[1];
5351 tz = tickStep(start, stop, tz);
5352 tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
5354 tz = tz.slice().sort(ascending$2);
5357 return tz.map(function(value) {
5358 return contour(values, value);
5362 // Accumulate, smooth contour rings, assign holes to exterior rings.
5363 // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
5364 function contour(values, value) {
5368 isorings(values, value, function(ring) {
5369 smooth(ring, values, value);
5370 if (area(ring) > 0) polygons.push([ring]);
5371 else holes.push(ring);
5374 holes.forEach(function(hole) {
5375 for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
5376 if (contains((polygon = polygons[i])[0], hole) !== -1) {
5384 type: "MultiPolygon",
5386 coordinates: polygons
5390 // Marching squares with isolines stitched into rings.
5391 // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
5392 function isorings(values, value, callback) {
5393 var fragmentByStart = new Array,
5394 fragmentByEnd = new Array,
5395 x, y, t0, t1, t2, t3;
5397 // Special case for the first row (y = -1, t2 = t3 = 0).
5399 t1 = values[0] >= value;
5400 cases[t1 << 1].forEach(stitch);
5401 while (++x < dx - 1) {
5402 t0 = t1, t1 = values[x + 1] >= value;
5403 cases[t0 | t1 << 1].forEach(stitch);
5405 cases[t1 << 0].forEach(stitch);
5407 // General case for the intermediate rows.
5408 while (++y < dy - 1) {
5410 t1 = values[y * dx + dx] >= value;
5411 t2 = values[y * dx] >= value;
5412 cases[t1 << 1 | t2 << 2].forEach(stitch);
5413 while (++x < dx - 1) {
5414 t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
5415 t3 = t2, t2 = values[y * dx + x + 1] >= value;
5416 cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
5418 cases[t1 | t2 << 3].forEach(stitch);
5421 // Special case for the last row (y = dy - 1, t0 = t1 = 0).
5423 t2 = values[y * dx] >= value;
5424 cases[t2 << 2].forEach(stitch);
5425 while (++x < dx - 1) {
5426 t3 = t2, t2 = values[y * dx + x + 1] >= value;
5427 cases[t2 << 2 | t3 << 3].forEach(stitch);
5429 cases[t2 << 3].forEach(stitch);
5431 function stitch(line) {
5432 var start = [line[0][0] + x, line[0][1] + y],
5433 end = [line[1][0] + x, line[1][1] + y],
5434 startIndex = index(start),
5435 endIndex = index(end),
5437 if (f = fragmentByEnd[startIndex]) {
5438 if (g = fragmentByStart[endIndex]) {
5439 delete fragmentByEnd[f.end];
5440 delete fragmentByStart[g.start];
5445 fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
5448 delete fragmentByEnd[f.end];
5450 fragmentByEnd[f.end = endIndex] = f;
5452 } else if (f = fragmentByStart[endIndex]) {
5453 if (g = fragmentByEnd[startIndex]) {
5454 delete fragmentByStart[f.start];
5455 delete fragmentByEnd[g.end];
5460 fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
5463 delete fragmentByStart[f.start];
5464 f.ring.unshift(start);
5465 fragmentByStart[f.start = startIndex] = f;
5468 fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
5473 function index(point) {
5474 return point[0] * 2 + point[1] * (dx + 1) * 4;
5477 function smoothLinear(ring, values, value) {
5478 ring.forEach(function(point) {
5484 v1 = values[yt * dx + xt];
5485 if (x > 0 && x < dx && xt === x) {
5486 v0 = values[yt * dx + xt - 1];
5487 point[0] = x + (value - v0) / (v1 - v0) - 0.5;
5489 if (y > 0 && y < dy && yt === y) {
5490 v0 = values[(yt - 1) * dx + xt];
5491 point[1] = y + (value - v0) / (v1 - v0) - 0.5;
5496 contours.contour = contour;
5498 contours.size = function(_) {
5499 if (!arguments.length) return [dx, dy];
5500 var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
5501 if (!(_0 > 0) || !(_1 > 0)) throw new Error("invalid size");
5502 return dx = _0, dy = _1, contours;
5505 contours.thresholds = function(_) {
5506 return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold$$1;
5509 contours.smooth = function(_) {
5510 return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
5516 // TODO Optimize edge cases.
5517 // TODO Optimize index calculation.
5518 // TODO Optimize arguments.
5519 function blurX(source, target, r) {
5520 var n = source.width,
5523 for (var j = 0; j < m; ++j) {
5524 for (var i = 0, sr = 0; i < n + r; ++i) {
5526 sr += source.data[i + j * n];
5530 sr -= source.data[i - w + j * n];
5532 target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
5538 // TODO Optimize edge cases.
5539 // TODO Optimize index calculation.
5540 // TODO Optimize arguments.
5541 function blurY(source, target, r) {
5542 var n = source.width,
5545 for (var i = 0; i < n; ++i) {
5546 for (var j = 0, sr = 0; j < m + r; ++j) {
5548 sr += source.data[i + j * n];
5552 sr -= source.data[i + (j - w) * n];
5554 target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
5560 function defaultX(d) {
5564 function defaultY(d) {
5568 function density() {
5573 r = 20, // blur radius
5574 k = 2, // log2(grid cell size)
5575 o = r * 3, // grid offset, to pad for blur
5576 n = (dx + o * 2) >> k, // grid width
5577 m = (dy + o * 2) >> k, // grid height
5578 threshold$$1 = constant$6(20);
5580 function density(data) {
5581 var values0 = new Float32Array(n * m),
5582 values1 = new Float32Array(n * m);
5584 data.forEach(function(d, i, data) {
5585 var xi = (x(d, i, data) + o) >> k,
5586 yi = (y(d, i, data) + o) >> k;
5587 if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
5588 ++values0[xi + yi * n];
5593 blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
5594 blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
5595 blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
5596 blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
5597 blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
5598 blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
5600 var tz = threshold$$1(values0);
5602 // Convert number of thresholds into uniform thresholds.
5603 if (!Array.isArray(tz)) {
5604 var stop = max(values0);
5605 tz = tickStep(0, stop, tz);
5606 tz = sequence(0, Math.floor(stop / tz) * tz, tz);
5617 function transform(geometry) {
5618 geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
5619 geometry.coordinates.forEach(transformPolygon);
5623 function transformPolygon(coordinates) {
5624 coordinates.forEach(transformRing);
5627 function transformRing(coordinates) {
5628 coordinates.forEach(transformPoint);
5632 function transformPoint(coordinates) {
5633 coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
5634 coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
5639 n = (dx + o * 2) >> k;
5640 m = (dy + o * 2) >> k;
5644 density.x = function(_) {
5645 return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
5648 density.y = function(_) {
5649 return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
5652 density.size = function(_) {
5653 if (!arguments.length) return [dx, dy];
5654 var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
5655 if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
5656 return dx = _0, dy = _1, resize();
5659 density.cellSize = function(_) {
5660 if (!arguments.length) return 1 << k;
5661 if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
5662 return k = Math.floor(Math.log(_) / Math.LN2), resize();
5665 density.thresholds = function(_) {
5666 return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold$$1;
5669 density.bandwidth = function(_) {
5670 if (!arguments.length) return Math.sqrt(r * (r + 1));
5671 if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
5672 return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
5684 function objectConverter(columns) {
5685 return new Function("d", "return {" + columns.map(function(name, i) {
5686 return JSON.stringify(name) + ": d[" + i + "]";
5687 }).join(",") + "}");
5690 function customConverter(columns, f) {
5691 var object = objectConverter(columns);
5692 return function(row, i) {
5693 return f(object(row), i, columns);
5697 // Compute unique columns in order of discovery.
5698 function inferColumns(rows) {
5699 var columnSet = Object.create(null),
5702 rows.forEach(function(row) {
5703 for (var column in row) {
5704 if (!(column in columnSet)) {
5705 columns.push(columnSet[column] = column);
5713 function dsvFormat(delimiter) {
5714 var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
5715 DELIMITER = delimiter.charCodeAt(0);
5717 function parse(text, f) {
5718 var convert, columns, rows = parseRows(text, function(row, i) {
5719 if (convert) return convert(row, i - 1);
5720 columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
5722 rows.columns = columns || [];
5726 function parseRows(text, f) {
5727 var rows = [], // output rows
5729 I = 0, // current character index
5730 n = 0, // current line number
5732 eof = N <= 0, // current token followed by EOF?
5733 eol = false; // current token followed by EOL?
5735 // Strip the trailing newline.
5736 if (text.charCodeAt(N - 1) === NEWLINE) --N;
5737 if (text.charCodeAt(N - 1) === RETURN) --N;
5740 if (eof) return EOF;
5741 if (eol) return eol = false, EOL;
5745 if (text.charCodeAt(j) === QUOTE) {
5746 while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
5747 if ((i = I) >= N) eof = true;
5748 else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
5749 else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5750 return text.slice(j + 1, i - 1).replace(/""/g, "\"");
5753 // Find next delimiter or newline.
5755 if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
5756 else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5757 else if (c !== DELIMITER) continue;
5758 return text.slice(j, i);
5761 // Return last token before EOF.
5762 return eof = true, text.slice(j, N);
5765 while ((t = token()) !== EOF) {
5767 while (t !== EOL && t !== EOF) row.push(t), t = token();
5768 if (f && (row = f(row, n++)) == null) continue;
5775 function format(rows, columns) {
5776 if (columns == null) columns = inferColumns(rows);
5777 return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
5778 return columns.map(function(column) {
5779 return formatValue(row[column]);
5784 function formatRows(rows) {
5785 return rows.map(formatRow).join("\n");
5788 function formatRow(row) {
5789 return row.map(formatValue).join(delimiter);
5792 function formatValue(text) {
5793 return text == null ? ""
5794 : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
5800 parseRows: parseRows,
5802 formatRows: formatRows
5806 var csv = dsvFormat(",");
5808 var csvParse = csv.parse;
5809 var csvParseRows = csv.parseRows;
5810 var csvFormat = csv.format;
5811 var csvFormatRows = csv.formatRows;
5813 var tsv = dsvFormat("\t");
5815 var tsvParse = tsv.parse;
5816 var tsvParseRows = tsv.parseRows;
5817 var tsvFormat = tsv.format;
5818 var tsvFormatRows = tsv.formatRows;
5820 function responseBlob(response) {
5821 if (!response.ok) throw new Error(response.status + " " + response.statusText);
5822 return response.blob();
5825 function blob(input, init) {
5826 return fetch(input, init).then(responseBlob);
5829 function responseArrayBuffer(response) {
5830 if (!response.ok) throw new Error(response.status + " " + response.statusText);
5831 return response.arrayBuffer();
5834 function buffer(input, init) {
5835 return fetch(input, init).then(responseArrayBuffer);
5838 function responseText(response) {
5839 if (!response.ok) throw new Error(response.status + " " + response.statusText);
5840 return response.text();
5843 function text(input, init) {
5844 return fetch(input, init).then(responseText);
5847 function dsvParse(parse) {
5848 return function(input, init, row) {
5849 if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
5850 return text(input, init).then(function(response) {
5851 return parse(response, row);
5856 function dsv(delimiter, input, init, row) {
5857 if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
5858 var format = dsvFormat(delimiter);
5859 return text(input, init).then(function(response) {
5860 return format.parse(response, row);
5864 var csv$1 = dsvParse(csvParse);
5865 var tsv$1 = dsvParse(tsvParse);
5867 function image(input, init) {
5868 return new Promise(function(resolve, reject) {
5869 var image = new Image;
5870 for (var key in init) image[key] = init[key];
5871 image.onerror = reject;
5872 image.onload = function() { resolve(image); };
5877 function responseJson(response) {
5878 if (!response.ok) throw new Error(response.status + " " + response.statusText);
5879 return response.json();
5882 function json(input, init) {
5883 return fetch(input, init).then(responseJson);
5886 function parser(type) {
5887 return function(input, init) {
5888 return text(input, init).then(function(text$$1) {
5889 return (new DOMParser).parseFromString(text$$1, type);
5894 var xml = parser("application/xml");
5896 var html = parser("text/html");
5898 var svg = parser("image/svg+xml");
5900 function center$1(x, y) {
5903 if (x == null) x = 0;
5904 if (y == null) y = 0;
5913 for (i = 0; i < n; ++i) {
5914 node = nodes[i], sx += node.x, sy += node.y;
5917 for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
5918 node = nodes[i], node.x -= sx, node.y -= sy;
5922 force.initialize = function(_) {
5926 force.x = function(_) {
5927 return arguments.length ? (x = +_, force) : x;
5930 force.y = function(_) {
5931 return arguments.length ? (y = +_, force) : y;
5937 function constant$7(x) {
5944 return (Math.random() - 0.5) * 1e-6;
5947 function tree_add(d) {
5948 var x = +this._x.call(null, d),
5949 y = +this._y.call(null, d);
5950 return add(this.cover(x, y), x, y, d);
5953 function add(tree, x, y, d) {
5954 if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
5972 // If the tree is empty, initialize the root as a leaf.
5973 if (!node) return tree._root = leaf, tree;
5975 // Find the existing leaf for the new point, or add it.
5976 while (node.length) {
5977 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
5978 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
5979 if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
5982 // Is the new point is exactly coincident with the existing point?
5983 xp = +tree._x.call(null, node.data);
5984 yp = +tree._y.call(null, node.data);
5985 if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
5987 // Otherwise, split the leaf node until the old and new point are separated.
5989 parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
5990 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
5991 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
5992 } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
5993 return parent[j] = node, parent[i] = leaf, tree;
5996 function addAll(data) {
5997 var d, i, n = data.length,
6007 // Compute the points and their extent.
6008 for (i = 0; i < n; ++i) {
6009 if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
6018 // If there were no (valid) points, inherit the existing extent.
6019 if (x1 < x0) x0 = this._x0, x1 = this._x1;
6020 if (y1 < y0) y0 = this._y0, y1 = this._y1;
6022 // Expand the tree to cover the new points.
6023 this.cover(x0, y0).cover(x1, y1);
6025 // Add the new points.
6026 for (i = 0; i < n; ++i) {
6027 add(this, xz[i], yz[i], data[i]);
6033 function tree_cover(x, y) {
6034 if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
6041 // If the quadtree has no extent, initialize them.
6042 // Integer extent are necessary so that if we later double the extent,
6043 // the existing quadrant boundaries don’t change due to floating point error!
6045 x1 = (x0 = Math.floor(x)) + 1;
6046 y1 = (y0 = Math.floor(y)) + 1;
6049 // Otherwise, double repeatedly to cover.
6050 else if (x0 > x || x > x1 || y0 > y || y > y1) {
6056 switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
6058 do parent = new Array(4), parent[i] = node, node = parent;
6059 while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
6063 do parent = new Array(4), parent[i] = node, node = parent;
6064 while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
6068 do parent = new Array(4), parent[i] = node, node = parent;
6069 while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
6073 do parent = new Array(4), parent[i] = node, node = parent;
6074 while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
6079 if (this._root && this._root.length) this._root = node;
6082 // If the quadtree covers the point already, just return.
6092 function tree_data() {
6094 this.visit(function(node) {
6095 if (!node.length) do data.push(node.data); while (node = node.next)
6100 function tree_extent(_) {
6101 return arguments.length
6102 ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
6103 : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
6106 function Quad(node, x0, y0, x1, y1) {
6114 function tree_find(x, y, radius) {
6129 if (node) quads.push(new Quad(node, x0, y0, x3, y3));
6130 if (radius == null) radius = Infinity;
6132 x0 = x - radius, y0 = y - radius;
6133 x3 = x + radius, y3 = y + radius;
6137 while (q = quads.pop()) {
6139 // Stop searching if this quadrant can’t contain a closer node.
6140 if (!(node = q.node)
6144 || (y2 = q.y1) < y0) continue;
6146 // Bisect the current quadrant.
6148 var xm = (x1 + x2) / 2,
6152 new Quad(node[3], xm, ym, x2, y2),
6153 new Quad(node[2], x1, ym, xm, y2),
6154 new Quad(node[1], xm, y1, x2, ym),
6155 new Quad(node[0], x1, y1, xm, ym)
6158 // Visit the closest quadrant first.
6159 if (i = (y >= ym) << 1 | (x >= xm)) {
6160 q = quads[quads.length - 1];
6161 quads[quads.length - 1] = quads[quads.length - 1 - i];
6162 quads[quads.length - 1 - i] = q;
6166 // Visit this point. (Visiting coincident points isn’t necessary!)
6168 var dx = x - +this._x.call(null, node.data),
6169 dy = y - +this._y.call(null, node.data),
6170 d2 = dx * dx + dy * dy;
6172 var d = Math.sqrt(radius = d2);
6173 x0 = x - d, y0 = y - d;
6174 x3 = x + d, y3 = y + d;
6183 function tree_remove(d) {
6184 if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
6204 // If the tree is empty, initialize the root as a leaf.
6205 if (!node) return this;
6207 // Find the leaf node for the point.
6208 // While descending, also retain the deepest parent with a non-removed sibling.
6209 if (node.length) while (true) {
6210 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
6211 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
6212 if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
6213 if (!node.length) break;
6214 if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
6217 // Find the point to remove.
6218 while (node.data !== d) if (!(previous = node, node = node.next)) return this;
6219 if (next = node.next) delete node.next;
6221 // If there are multiple coincident points, remove just the point.
6222 if (previous) return next ? previous.next = next : delete previous.next, this;
6224 // If this is the root point, remove it.
6225 if (!parent) return this._root = next, this;
6227 // Remove this leaf.
6228 next ? parent[i] = next : delete parent[i];
6230 // If the parent now contains exactly one leaf, collapse superfluous parents.
6231 if ((node = parent[0] || parent[1] || parent[2] || parent[3])
6232 && node === (parent[3] || parent[2] || parent[1] || parent[0])
6234 if (retainer) retainer[j] = node;
6235 else this._root = node;
6241 function removeAll(data) {
6242 for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
6246 function tree_root() {
6250 function tree_size() {
6252 this.visit(function(node) {
6253 if (!node.length) do ++size; while (node = node.next)
6258 function tree_visit(callback) {
6259 var quads = [], q, node = this._root, child, x0, y0, x1, y1;
6260 if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
6261 while (q = quads.pop()) {
6262 if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
6263 var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
6264 if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
6265 if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
6266 if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
6267 if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
6273 function tree_visitAfter(callback) {
6274 var quads = [], next = [], q;
6275 if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
6276 while (q = quads.pop()) {
6279 var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
6280 if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
6281 if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
6282 if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
6283 if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
6287 while (q = next.pop()) {
6288 callback(q.node, q.x0, q.y0, q.x1, q.y1);
6293 function defaultX$1(d) {
6297 function tree_x(_) {
6298 return arguments.length ? (this._x = _, this) : this._x;
6301 function defaultY$1(d) {
6305 function tree_y(_) {
6306 return arguments.length ? (this._y = _, this) : this._y;
6309 function quadtree(nodes, x, y) {
6310 var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
6311 return nodes == null ? tree : tree.addAll(nodes);
6314 function Quadtree(x, y, x0, y0, x1, y1) {
6321 this._root = undefined;
6324 function leaf_copy(leaf) {
6325 var copy = {data: leaf.data}, next = copy;
6326 while (leaf = leaf.next) next = next.next = {data: leaf.data};
6330 var treeProto = quadtree.prototype = Quadtree.prototype;
6332 treeProto.copy = function() {
6333 var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
6338 if (!node) return copy;
6340 if (!node.length) return copy._root = leaf_copy(node), copy;
6342 nodes = [{source: node, target: copy._root = new Array(4)}];
6343 while (node = nodes.pop()) {
6344 for (var i = 0; i < 4; ++i) {
6345 if (child = node.source[i]) {
6346 if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
6347 else node.target[i] = leaf_copy(child);
6355 treeProto.add = tree_add;
6356 treeProto.addAll = addAll;
6357 treeProto.cover = tree_cover;
6358 treeProto.data = tree_data;
6359 treeProto.extent = tree_extent;
6360 treeProto.find = tree_find;
6361 treeProto.remove = tree_remove;
6362 treeProto.removeAll = removeAll;
6363 treeProto.root = tree_root;
6364 treeProto.size = tree_size;
6365 treeProto.visit = tree_visit;
6366 treeProto.visitAfter = tree_visitAfter;
6367 treeProto.x = tree_x;
6368 treeProto.y = tree_y;
6378 function collide(radius) {
6384 if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
6387 var i, n = nodes.length,
6395 for (var k = 0; k < iterations; ++k) {
6396 tree = quadtree(nodes, x, y).visitAfter(prepare);
6397 for (i = 0; i < n; ++i) {
6399 ri = radii[node.index], ri2 = ri * ri;
6400 xi = node.x + node.vx;
6401 yi = node.y + node.vy;
6406 function apply(quad, x0, y0, x1, y1) {
6407 var data = quad.data, rj = quad.r, r = ri + rj;
6409 if (data.index > node.index) {
6410 var x = xi - data.x - data.vx,
6411 y = yi - data.y - data.vy,
6414 if (x === 0) x = jiggle(), l += x * x;
6415 if (y === 0) y = jiggle(), l += y * y;
6416 l = (r - (l = Math.sqrt(l))) / l * strength;
6417 node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
6418 node.vy += (y *= l) * r;
6419 data.vx -= x * (r = 1 - r);
6425 return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
6429 function prepare(quad) {
6430 if (quad.data) return quad.r = radii[quad.data.index];
6431 for (var i = quad.r = 0; i < 4; ++i) {
6432 if (quad[i] && quad[i].r > quad.r) {
6438 function initialize() {
6440 var i, n = nodes.length, node;
6441 radii = new Array(n);
6442 for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
6445 force.initialize = function(_) {
6450 force.iterations = function(_) {
6451 return arguments.length ? (iterations = +_, force) : iterations;
6454 force.strength = function(_) {
6455 return arguments.length ? (strength = +_, force) : strength;
6458 force.radius = function(_) {
6459 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
6469 function find(nodeById, nodeId) {
6470 var node = nodeById.get(nodeId);
6471 if (!node) throw new Error("missing: " + nodeId);
6475 function link(links) {
6477 strength = defaultStrength,
6479 distance = constant$7(30),
6486 if (links == null) links = [];
6488 function defaultStrength(link) {
6489 return 1 / Math.min(count[link.source.index], count[link.target.index]);
6492 function force(alpha) {
6493 for (var k = 0, n = links.length; k < iterations; ++k) {
6494 for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
6495 link = links[i], source = link.source, target = link.target;
6496 x = target.x + target.vx - source.x - source.vx || jiggle();
6497 y = target.y + target.vy - source.y - source.vy || jiggle();
6498 l = Math.sqrt(x * x + y * y);
6499 l = (l - distances[i]) / l * alpha * strengths[i];
6501 target.vx -= x * (b = bias[i]);
6503 source.vx += x * (b = 1 - b);
6509 function initialize() {
6515 nodeById = map$1(nodes, id),
6518 for (i = 0, count = new Array(n); i < m; ++i) {
6519 link = links[i], link.index = i;
6520 if (typeof link.source !== "object") link.source = find(nodeById, link.source);
6521 if (typeof link.target !== "object") link.target = find(nodeById, link.target);
6522 count[link.source.index] = (count[link.source.index] || 0) + 1;
6523 count[link.target.index] = (count[link.target.index] || 0) + 1;
6526 for (i = 0, bias = new Array(m); i < m; ++i) {
6527 link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
6530 strengths = new Array(m), initializeStrength();
6531 distances = new Array(m), initializeDistance();
6534 function initializeStrength() {
6537 for (var i = 0, n = links.length; i < n; ++i) {
6538 strengths[i] = +strength(links[i], i, links);
6542 function initializeDistance() {
6545 for (var i = 0, n = links.length; i < n; ++i) {
6546 distances[i] = +distance(links[i], i, links);
6550 force.initialize = function(_) {
6555 force.links = function(_) {
6556 return arguments.length ? (links = _, initialize(), force) : links;
6559 force.id = function(_) {
6560 return arguments.length ? (id = _, force) : id;
6563 force.iterations = function(_) {
6564 return arguments.length ? (iterations = +_, force) : iterations;
6567 force.strength = function(_) {
6568 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
6571 force.distance = function(_) {
6572 return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
6586 var initialRadius = 10,
6587 initialAngle = Math.PI * (3 - Math.sqrt(5));
6589 function simulation(nodes) {
6593 alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
6595 velocityDecay = 0.6,
6597 stepper = timer(step),
6598 event = dispatch("tick", "end");
6600 if (nodes == null) nodes = [];
6604 event.call("tick", simulation);
6605 if (alpha < alphaMin) {
6607 event.call("end", simulation);
6612 var i, n = nodes.length, node;
6614 alpha += (alphaTarget - alpha) * alphaDecay;
6616 forces.each(function(force) {
6620 for (i = 0; i < n; ++i) {
6622 if (node.fx == null) node.x += node.vx *= velocityDecay;
6623 else node.x = node.fx, node.vx = 0;
6624 if (node.fy == null) node.y += node.vy *= velocityDecay;
6625 else node.y = node.fy, node.vy = 0;
6629 function initializeNodes() {
6630 for (var i = 0, n = nodes.length, node; i < n; ++i) {
6631 node = nodes[i], node.index = i;
6632 if (isNaN(node.x) || isNaN(node.y)) {
6633 var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
6634 node.x = radius * Math.cos(angle);
6635 node.y = radius * Math.sin(angle);
6637 if (isNaN(node.vx) || isNaN(node.vy)) {
6638 node.vx = node.vy = 0;
6643 function initializeForce(force) {
6644 if (force.initialize) force.initialize(nodes);
6650 return simulation = {
6653 restart: function() {
6654 return stepper.restart(step), simulation;
6658 return stepper.stop(), simulation;
6661 nodes: function(_) {
6662 return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
6665 alpha: function(_) {
6666 return arguments.length ? (alpha = +_, simulation) : alpha;
6669 alphaMin: function(_) {
6670 return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
6673 alphaDecay: function(_) {
6674 return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
6677 alphaTarget: function(_) {
6678 return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
6681 velocityDecay: function(_) {
6682 return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
6685 force: function(name, _) {
6686 return arguments.length > 1 ? (_ == null ? forces.remove(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name);
6689 find: function(x, y, radius) {
6698 if (radius == null) radius = Infinity;
6699 else radius *= radius;
6701 for (i = 0; i < n; ++i) {
6705 d2 = dx * dx + dy * dy;
6706 if (d2 < radius) closest = node, radius = d2;
6712 on: function(name, _) {
6713 return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
6718 function manyBody() {
6722 strength = constant$7(-30),
6725 distanceMax2 = Infinity,
6729 var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
6730 for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
6733 function initialize() {
6735 var i, n = nodes.length, node;
6736 strengths = new Array(n);
6737 for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
6740 function accumulate(quad) {
6741 var strength = 0, q, c, weight = 0, x, y, i;
6743 // For internal nodes, accumulate forces from child quadrants.
6745 for (x = y = i = 0; i < 4; ++i) {
6746 if ((q = quad[i]) && (c = Math.abs(q.value))) {
6747 strength += q.value, weight += c, x += c * q.x, y += c * q.y;
6750 quad.x = x / weight;
6751 quad.y = y / weight;
6754 // For leaf nodes, accumulate forces from coincident quadrants.
6759 do strength += strengths[q.data.index];
6763 quad.value = strength;
6766 function apply(quad, x1, _, x2) {
6767 if (!quad.value) return true;
6769 var x = quad.x - node.x,
6770 y = quad.y - node.y,
6774 // Apply the Barnes-Hut approximation if possible.
6775 // Limit forces for very close nodes; randomize direction if coincident.
6776 if (w * w / theta2 < l) {
6777 if (l < distanceMax2) {
6778 if (x === 0) x = jiggle(), l += x * x;
6779 if (y === 0) y = jiggle(), l += y * y;
6780 if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
6781 node.vx += x * quad.value * alpha / l;
6782 node.vy += y * quad.value * alpha / l;
6787 // Otherwise, process points directly.
6788 else if (quad.length || l >= distanceMax2) return;
6790 // Limit forces for very close nodes; randomize direction if coincident.
6791 if (quad.data !== node || quad.next) {
6792 if (x === 0) x = jiggle(), l += x * x;
6793 if (y === 0) y = jiggle(), l += y * y;
6794 if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
6797 do if (quad.data !== node) {
6798 w = strengths[quad.data.index] * alpha / l;
6801 } while (quad = quad.next);
6804 force.initialize = function(_) {
6809 force.strength = function(_) {
6810 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
6813 force.distanceMin = function(_) {
6814 return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
6817 force.distanceMax = function(_) {
6818 return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
6821 force.theta = function(_) {
6822 return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
6828 function radial(radius, x, y) {
6830 strength = constant$7(0.1),
6834 if (typeof radius !== "function") radius = constant$7(+radius);
6835 if (x == null) x = 0;
6836 if (y == null) y = 0;
6838 function force(alpha) {
6839 for (var i = 0, n = nodes.length; i < n; ++i) {
6840 var node = nodes[i],
6841 dx = node.x - x || 1e-6,
6842 dy = node.y - y || 1e-6,
6843 r = Math.sqrt(dx * dx + dy * dy),
6844 k = (radiuses[i] - r) * strengths[i] * alpha / r;
6850 function initialize() {
6852 var i, n = nodes.length;
6853 strengths = new Array(n);
6854 radiuses = new Array(n);
6855 for (i = 0; i < n; ++i) {
6856 radiuses[i] = +radius(nodes[i], i, nodes);
6857 strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
6861 force.initialize = function(_) {
6862 nodes = _, initialize();
6865 force.strength = function(_) {
6866 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
6869 force.radius = function(_) {
6870 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
6873 force.x = function(_) {
6874 return arguments.length ? (x = +_, force) : x;
6877 force.y = function(_) {
6878 return arguments.length ? (y = +_, force) : y;
6885 var strength = constant$7(0.1),
6890 if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
6892 function force(alpha) {
6893 for (var i = 0, n = nodes.length, node; i < n; ++i) {
6894 node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
6898 function initialize() {
6900 var i, n = nodes.length;
6901 strengths = new Array(n);
6903 for (i = 0; i < n; ++i) {
6904 strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
6908 force.initialize = function(_) {
6913 force.strength = function(_) {
6914 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
6917 force.x = function(_) {
6918 return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
6925 var strength = constant$7(0.1),
6930 if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
6932 function force(alpha) {
6933 for (var i = 0, n = nodes.length, node; i < n; ++i) {
6934 node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
6938 function initialize() {
6940 var i, n = nodes.length;
6941 strengths = new Array(n);
6943 for (i = 0; i < n; ++i) {
6944 strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
6948 force.initialize = function(_) {
6953 force.strength = function(_) {
6954 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
6957 force.y = function(_) {
6958 return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
6964 // Computes the decimal coefficient and exponent of the specified number x with
6965 // significant digits p, where x is positive and p is in [1, 21] or undefined.
6966 // For example, formatDecimal(1.23) returns ["123", 0].
6967 function formatDecimal(x, p) {
6968 if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
6969 var i, coefficient = x.slice(0, i);
6971 // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
6972 // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
6974 coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
6979 function exponent$1(x) {
6980 return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
6983 function formatGroup(grouping, thousands) {
6984 return function(value, width) {
6985 var i = value.length,
6991 while (i > 0 && g > 0) {
6992 if (length + g + 1 > width) g = Math.max(1, width - length);
6993 t.push(value.substring(i -= g, i + g));
6994 if ((length += g + 1) > width) break;
6995 g = grouping[j = (j + 1) % grouping.length];
6998 return t.reverse().join(thousands);
7002 function formatNumerals(numerals) {
7003 return function(value) {
7004 return value.replace(/[0-9]/g, function(i) {
7005 return numerals[+i];
7010 // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
7011 var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
7013 function formatSpecifier(specifier) {
7014 return new FormatSpecifier(specifier);
7017 formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
7019 function FormatSpecifier(specifier) {
7020 if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
7022 this.fill = match[1] || " ";
7023 this.align = match[2] || ">";
7024 this.sign = match[3] || "-";
7025 this.symbol = match[4] || "";
7026 this.zero = !!match[5];
7027 this.width = match[6] && +match[6];
7028 this.comma = !!match[7];
7029 this.precision = match[8] && +match[8].slice(1);
7030 this.trim = !!match[9];
7031 this.type = match[10] || "";
7034 FormatSpecifier.prototype.toString = function() {
7039 + (this.zero ? "0" : "")
7040 + (this.width == null ? "" : Math.max(1, this.width | 0))
7041 + (this.comma ? "," : "")
7042 + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
7043 + (this.trim ? "~" : "")
7047 // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
7048 function formatTrim(s) {
7049 out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
7051 case ".": i0 = i1 = i; break;
7052 case "0": if (i0 === 0) i0 = i; i1 = i; break;
7053 default: if (i0 > 0) { if (!+s[i]) break out; i0 = 0; } break;
7056 return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
7061 function formatPrefixAuto(x, p) {
7062 var d = formatDecimal(x, p);
7063 if (!d) return x + "";
7064 var coefficient = d[0],
7066 i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
7067 n = coefficient.length;
7068 return i === n ? coefficient
7069 : i > n ? coefficient + new Array(i - n + 1).join("0")
7070 : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
7071 : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
7074 function formatRounded(x, p) {
7075 var d = formatDecimal(x, p);
7076 if (!d) return x + "";
7077 var coefficient = d[0],
7079 return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
7080 : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
7081 : coefficient + new Array(exponent - coefficient.length + 2).join("0");
7085 "%": function(x, p) { return (x * 100).toFixed(p); },
7086 "b": function(x) { return Math.round(x).toString(2); },
7087 "c": function(x) { return x + ""; },
7088 "d": function(x) { return Math.round(x).toString(10); },
7089 "e": function(x, p) { return x.toExponential(p); },
7090 "f": function(x, p) { return x.toFixed(p); },
7091 "g": function(x, p) { return x.toPrecision(p); },
7092 "o": function(x) { return Math.round(x).toString(8); },
7093 "p": function(x, p) { return formatRounded(x * 100, p); },
7095 "s": formatPrefixAuto,
7096 "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
7097 "x": function(x) { return Math.round(x).toString(16); }
7100 function identity$3(x) {
7104 var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
7106 function formatLocale(locale) {
7107 var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
7108 currency = locale.currency,
7109 decimal = locale.decimal,
7110 numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
7111 percent = locale.percent || "%";
7113 function newFormat(specifier) {
7114 specifier = formatSpecifier(specifier);
7116 var fill = specifier.fill,
7117 align = specifier.align,
7118 sign = specifier.sign,
7119 symbol = specifier.symbol,
7120 zero = specifier.zero,
7121 width = specifier.width,
7122 comma = specifier.comma,
7123 precision = specifier.precision,
7124 trim = specifier.trim,
7125 type = specifier.type;
7127 // The "n" type is an alias for ",g".
7128 if (type === "n") comma = true, type = "g";
7130 // The "" type, and any invalid type, is an alias for ".12~g".
7131 else if (!formatTypes[type]) precision == null && (precision = 12), trim = true, type = "g";
7133 // If zero fill is specified, padding goes after sign and before digits.
7134 if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
7136 // Compute the prefix and suffix.
7137 // For SI-prefix, the suffix is lazily computed.
7138 var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
7139 suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
7141 // What format function should we use?
7142 // Is this an integer type?
7143 // Can this type generate exponential notation?
7144 var formatType = formatTypes[type],
7145 maybeSuffix = /[defgprs%]/.test(type);
7147 // Set the default precision if not specified,
7148 // or clamp the specified precision to the supported range.
7149 // For significant precision, it must be in [1, 21].
7150 // For fixed precision, it must be in [0, 20].
7151 precision = precision == null ? 6
7152 : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
7153 : Math.max(0, Math.min(20, precision));
7155 function format(value) {
7156 var valuePrefix = prefix,
7157 valueSuffix = suffix,
7161 valueSuffix = formatType(value) + valueSuffix;
7166 // Perform the initial formatting.
7167 var valueNegative = value < 0;
7168 value = formatType(Math.abs(value), precision);
7170 // Trim insignificant zeros.
7171 if (trim) value = formatTrim(value);
7173 // If a negative value rounds to zero during formatting, treat as positive.
7174 if (valueNegative && +value === 0) valueNegative = false;
7176 // Compute the prefix and suffix.
7177 valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
7178 valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
7180 // Break the formatted value into the integer “value” part that can be
7181 // grouped, and fractional or exponential “suffix” part that is not.
7183 i = -1, n = value.length;
7185 if (c = value.charCodeAt(i), 48 > c || c > 57) {
7186 valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
7187 value = value.slice(0, i);
7194 // If the fill character is not "0", grouping is applied before padding.
7195 if (comma && !zero) value = group(value, Infinity);
7197 // Compute the padding.
7198 var length = valuePrefix.length + value.length + valueSuffix.length,
7199 padding = length < width ? new Array(width - length + 1).join(fill) : "";
7201 // If the fill character is "0", grouping is applied after padding.
7202 if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
7204 // Reconstruct the final output based on the desired alignment.
7206 case "<": value = valuePrefix + value + valueSuffix + padding; break;
7207 case "=": value = valuePrefix + padding + value + valueSuffix; break;
7208 case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
7209 default: value = padding + valuePrefix + value + valueSuffix; break;
7212 return numerals(value);
7215 format.toString = function() {
7216 return specifier + "";
7222 function formatPrefix(specifier, value) {
7223 var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
7224 e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
7225 k = Math.pow(10, -e),
7226 prefix = prefixes[8 + e / 3];
7227 return function(value) {
7228 return f(k * value) + prefix;
7234 formatPrefix: formatPrefix
7247 function defaultLocale(definition) {
7248 locale = formatLocale(definition);
7249 exports.format = locale.format;
7250 exports.formatPrefix = locale.formatPrefix;
7254 function precisionFixed(step) {
7255 return Math.max(0, -exponent$1(Math.abs(step)));
7258 function precisionPrefix(step, value) {
7259 return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
7262 function precisionRound(step, max) {
7263 step = Math.abs(step), max = Math.abs(max) - step;
7264 return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
7267 // Adds floating point numbers with twice the normal precision.
7268 // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
7269 // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
7271 // Code adapted from GeographicLib by Charles F. F. Karney,
7272 // http://geographiclib.sourceforge.net/
7285 this.s = // rounded value
7286 this.t = 0; // exact error
7289 add$1(temp, y, this.t);
7290 add$1(this, temp.s, this.s);
7291 if (this.s) this.t += temp.t;
7292 else this.s = temp.t;
7294 valueOf: function() {
7299 var temp = new Adder;
7301 function add$1(adder, a, b) {
7302 var x = adder.s = a + b,
7305 adder.t = (a - av) + (b - bv);
7308 var epsilon$2 = 1e-6;
7309 var epsilon2$1 = 1e-12;
7311 var halfPi$2 = pi$3 / 2;
7312 var quarterPi = pi$3 / 4;
7313 var tau$3 = pi$3 * 2;
7315 var degrees$1 = 180 / pi$3;
7316 var radians = pi$3 / 180;
7319 var atan = Math.atan;
7320 var atan2 = Math.atan2;
7321 var cos$1 = Math.cos;
7322 var ceil = Math.ceil;
7326 var sin$1 = Math.sin;
7327 var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
7328 var sqrt = Math.sqrt;
7332 return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
7336 return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
7339 function haversin(x) {
7340 return (x = sin$1(x / 2)) * x;
7343 function noop$2() {}
7345 function streamGeometry(geometry, stream) {
7346 if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
7347 streamGeometryType[geometry.type](geometry, stream);
7351 var streamObjectType = {
7352 Feature: function(object, stream) {
7353 streamGeometry(object.geometry, stream);
7355 FeatureCollection: function(object, stream) {
7356 var features = object.features, i = -1, n = features.length;
7357 while (++i < n) streamGeometry(features[i].geometry, stream);
7361 var streamGeometryType = {
7362 Sphere: function(object, stream) {
7365 Point: function(object, stream) {
7366 object = object.coordinates;
7367 stream.point(object[0], object[1], object[2]);
7369 MultiPoint: function(object, stream) {
7370 var coordinates = object.coordinates, i = -1, n = coordinates.length;
7371 while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
7373 LineString: function(object, stream) {
7374 streamLine(object.coordinates, stream, 0);
7376 MultiLineString: function(object, stream) {
7377 var coordinates = object.coordinates, i = -1, n = coordinates.length;
7378 while (++i < n) streamLine(coordinates[i], stream, 0);
7380 Polygon: function(object, stream) {
7381 streamPolygon(object.coordinates, stream);
7383 MultiPolygon: function(object, stream) {
7384 var coordinates = object.coordinates, i = -1, n = coordinates.length;
7385 while (++i < n) streamPolygon(coordinates[i], stream);
7387 GeometryCollection: function(object, stream) {
7388 var geometries = object.geometries, i = -1, n = geometries.length;
7389 while (++i < n) streamGeometry(geometries[i], stream);
7393 function streamLine(coordinates, stream, closed) {
7394 var i = -1, n = coordinates.length - closed, coordinate;
7396 while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
7400 function streamPolygon(coordinates, stream) {
7401 var i = -1, n = coordinates.length;
7402 stream.polygonStart();
7403 while (++i < n) streamLine(coordinates[i], stream, 1);
7404 stream.polygonEnd();
7407 function geoStream(object, stream) {
7408 if (object && streamObjectType.hasOwnProperty(object.type)) {
7409 streamObjectType[object.type](object, stream);
7411 streamGeometry(object, stream);
7415 var areaRingSum = adder();
7417 var areaSum = adder(),
7428 polygonStart: function() {
7429 areaRingSum.reset();
7430 areaStream.lineStart = areaRingStart;
7431 areaStream.lineEnd = areaRingEnd;
7433 polygonEnd: function() {
7434 var areaRing = +areaRingSum;
7435 areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
7436 this.lineStart = this.lineEnd = this.point = noop$2;
7438 sphere: function() {
7443 function areaRingStart() {
7444 areaStream.point = areaPointFirst;
7447 function areaRingEnd() {
7448 areaPoint(lambda00, phi00);
7451 function areaPointFirst(lambda, phi) {
7452 areaStream.point = areaPoint;
7453 lambda00 = lambda, phi00 = phi;
7454 lambda *= radians, phi *= radians;
7455 lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
7458 function areaPoint(lambda, phi) {
7459 lambda *= radians, phi *= radians;
7460 phi = phi / 2 + quarterPi; // half the angular distance from south pole
7462 // Spherical excess E for a spherical triangle with vertices: south pole,
7463 // previous point, current point. Uses a formula derived from Cagnoli’s
7464 // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
7465 var dLambda = lambda - lambda0,
7466 sdLambda = dLambda >= 0 ? 1 : -1,
7467 adLambda = sdLambda * dLambda,
7468 cosPhi = cos$1(phi),
7469 sinPhi = sin$1(phi),
7470 k = sinPhi0 * sinPhi,
7471 u = cosPhi0 * cosPhi + k * cos$1(adLambda),
7472 v = k * sdLambda * sin$1(adLambda);
7473 areaRingSum.add(atan2(v, u));
7475 // Advance the previous points.
7476 lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
7479 function area$1(object) {
7481 geoStream(object, areaStream);
7485 function spherical(cartesian) {
7486 return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
7489 function cartesian(spherical) {
7490 var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
7491 return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
7494 function cartesianDot(a, b) {
7495 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
7498 function cartesianCross(a, b) {
7499 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]];
7503 function cartesianAddInPlace(a, b) {
7504 a[0] += b[0], a[1] += b[1], a[2] += b[2];
7507 function cartesianScale(vector, k) {
7508 return [vector[0] * k, vector[1] * k, vector[2] * k];
7512 function cartesianNormalizeInPlace(d) {
7513 var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
7514 d[0] /= l, d[1] /= l, d[2] /= l;
7517 var lambda0$1, phi0, lambda1, phi1, // bounds
7518 lambda2, // previous lambda-coordinate
7519 lambda00$1, phi00$1, // first point
7520 p0, // previous 3D point
7525 var boundsStream = {
7527 lineStart: boundsLineStart,
7528 lineEnd: boundsLineEnd,
7529 polygonStart: function() {
7530 boundsStream.point = boundsRingPoint;
7531 boundsStream.lineStart = boundsRingStart;
7532 boundsStream.lineEnd = boundsRingEnd;
7534 areaStream.polygonStart();
7536 polygonEnd: function() {
7537 areaStream.polygonEnd();
7538 boundsStream.point = boundsPoint;
7539 boundsStream.lineStart = boundsLineStart;
7540 boundsStream.lineEnd = boundsLineEnd;
7541 if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
7542 else if (deltaSum > epsilon$2) phi1 = 90;
7543 else if (deltaSum < -epsilon$2) phi0 = -90;
7544 range[0] = lambda0$1, range[1] = lambda1;
7548 function boundsPoint(lambda, phi) {
7549 ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7550 if (phi < phi0) phi0 = phi;
7551 if (phi > phi1) phi1 = phi;
7554 function linePoint(lambda, phi) {
7555 var p = cartesian([lambda * radians, phi * radians]);
7557 var normal = cartesianCross(p0, p),
7558 equatorial = [normal[1], -normal[0], 0],
7559 inflection = cartesianCross(equatorial, normal);
7560 cartesianNormalizeInPlace(inflection);
7561 inflection = spherical(inflection);
7562 var delta = lambda - lambda2,
7563 sign$$1 = delta > 0 ? 1 : -1,
7564 lambdai = inflection[0] * degrees$1 * sign$$1,
7566 antimeridian = abs(delta) > 180;
7567 if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
7568 phii = inflection[1] * degrees$1;
7569 if (phii > phi1) phi1 = phii;
7570 } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
7571 phii = -inflection[1] * degrees$1;
7572 if (phii < phi0) phi0 = phii;
7574 if (phi < phi0) phi0 = phi;
7575 if (phi > phi1) phi1 = phi;
7578 if (lambda < lambda2) {
7579 if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7581 if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7584 if (lambda1 >= lambda0$1) {
7585 if (lambda < lambda0$1) lambda0$1 = lambda;
7586 if (lambda > lambda1) lambda1 = lambda;
7588 if (lambda > lambda2) {
7589 if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7591 if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7596 ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7598 if (phi < phi0) phi0 = phi;
7599 if (phi > phi1) phi1 = phi;
7600 p0 = p, lambda2 = lambda;
7603 function boundsLineStart() {
7604 boundsStream.point = linePoint;
7607 function boundsLineEnd() {
7608 range[0] = lambda0$1, range[1] = lambda1;
7609 boundsStream.point = boundsPoint;
7613 function boundsRingPoint(lambda, phi) {
7615 var delta = lambda - lambda2;
7616 deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
7618 lambda00$1 = lambda, phi00$1 = phi;
7620 areaStream.point(lambda, phi);
7621 linePoint(lambda, phi);
7624 function boundsRingStart() {
7625 areaStream.lineStart();
7628 function boundsRingEnd() {
7629 boundsRingPoint(lambda00$1, phi00$1);
7630 areaStream.lineEnd();
7631 if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
7632 range[0] = lambda0$1, range[1] = lambda1;
7636 // Finds the left-right distance between two longitudes.
7637 // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
7638 // the distance between ±180° to be 360°.
7639 function angle(lambda0, lambda1) {
7640 return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
7643 function rangeCompare(a, b) {
7647 function rangeContains(range, x) {
7648 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
7651 function bounds(feature) {
7652 var i, n, a, b, merged, deltaMax, delta;
7654 phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
7656 geoStream(feature, boundsStream);
7658 // First, sort ranges by their minimum longitudes.
7659 if (n = ranges.length) {
7660 ranges.sort(rangeCompare);
7662 // Then, merge any ranges that overlap.
7663 for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
7665 if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
7666 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
7667 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
7673 // Finally, find the largest gap between the merged ranges.
7674 // The final bounding box will be the inverse of this gap.
7675 for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
7677 if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
7681 ranges = range = null;
7683 return lambda0$1 === Infinity || phi0 === Infinity
7684 ? [[NaN, NaN], [NaN, NaN]]
7685 : [[lambda0$1, phi0], [lambda1, phi1]];
7692 lambda00$2, phi00$2, // first point
7693 x0, y0, z0; // previous point
7695 var centroidStream = {
7697 point: centroidPoint,
7698 lineStart: centroidLineStart,
7699 lineEnd: centroidLineEnd,
7700 polygonStart: function() {
7701 centroidStream.lineStart = centroidRingStart;
7702 centroidStream.lineEnd = centroidRingEnd;
7704 polygonEnd: function() {
7705 centroidStream.lineStart = centroidLineStart;
7706 centroidStream.lineEnd = centroidLineEnd;
7710 // Arithmetic mean of Cartesian vectors.
7711 function centroidPoint(lambda, phi) {
7712 lambda *= radians, phi *= radians;
7713 var cosPhi = cos$1(phi);
7714 centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
7717 function centroidPointCartesian(x, y, z) {
7719 X0 += (x - X0) / W0;
7720 Y0 += (y - Y0) / W0;
7721 Z0 += (z - Z0) / W0;
7724 function centroidLineStart() {
7725 centroidStream.point = centroidLinePointFirst;
7728 function centroidLinePointFirst(lambda, phi) {
7729 lambda *= radians, phi *= radians;
7730 var cosPhi = cos$1(phi);
7731 x0 = cosPhi * cos$1(lambda);
7732 y0 = cosPhi * sin$1(lambda);
7734 centroidStream.point = centroidLinePoint;
7735 centroidPointCartesian(x0, y0, z0);
7738 function centroidLinePoint(lambda, phi) {
7739 lambda *= radians, phi *= radians;
7740 var cosPhi = cos$1(phi),
7741 x = cosPhi * cos$1(lambda),
7742 y = cosPhi * sin$1(lambda),
7744 w = atan2(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);
7746 X1 += w * (x0 + (x0 = x));
7747 Y1 += w * (y0 + (y0 = y));
7748 Z1 += w * (z0 + (z0 = z));
7749 centroidPointCartesian(x0, y0, z0);
7752 function centroidLineEnd() {
7753 centroidStream.point = centroidPoint;
7756 // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
7757 // J. Applied Mechanics 42, 239 (1975).
7758 function centroidRingStart() {
7759 centroidStream.point = centroidRingPointFirst;
7762 function centroidRingEnd() {
7763 centroidRingPoint(lambda00$2, phi00$2);
7764 centroidStream.point = centroidPoint;
7767 function centroidRingPointFirst(lambda, phi) {
7768 lambda00$2 = lambda, phi00$2 = phi;
7769 lambda *= radians, phi *= radians;
7770 centroidStream.point = centroidRingPoint;
7771 var cosPhi = cos$1(phi);
7772 x0 = cosPhi * cos$1(lambda);
7773 y0 = cosPhi * sin$1(lambda);
7775 centroidPointCartesian(x0, y0, z0);
7778 function centroidRingPoint(lambda, phi) {
7779 lambda *= radians, phi *= radians;
7780 var cosPhi = cos$1(phi),
7781 x = cosPhi * cos$1(lambda),
7782 y = cosPhi * sin$1(lambda),
7784 cx = y0 * z - z0 * y,
7785 cy = z0 * x - x0 * z,
7786 cz = x0 * y - y0 * x,
7787 m = sqrt(cx * cx + cy * cy + cz * cz),
7788 w = asin(m), // line weight = angle
7789 v = m && -w / m; // area weight multiplier
7794 X1 += w * (x0 + (x0 = x));
7795 Y1 += w * (y0 + (y0 = y));
7796 Z1 += w * (z0 + (z0 = z));
7797 centroidPointCartesian(x0, y0, z0);
7800 function centroid(object) {
7805 geoStream(object, centroidStream);
7810 m = x * x + y * y + z * z;
7812 // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
7813 if (m < epsilon2$1) {
7814 x = X1, y = Y1, z = Z1;
7815 // If the feature has zero length, fall back to arithmetic mean of point vectors.
7816 if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
7817 m = x * x + y * y + z * z;
7818 // If the feature still has an undefined ccentroid, then return.
7819 if (m < epsilon2$1) return [NaN, NaN];
7822 return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
7825 function constant$8(x) {
7831 function compose(a, b) {
7833 function compose(x, y) {
7834 return x = a(x, y), b(x[0], x[1]);
7837 if (a.invert && b.invert) compose.invert = function(x, y) {
7838 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
7844 function rotationIdentity(lambda, phi) {
7845 return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
7848 rotationIdentity.invert = rotationIdentity;
7850 function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
7851 return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
7852 : rotationLambda(deltaLambda))
7853 : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
7854 : rotationIdentity);
7857 function forwardRotationLambda(deltaLambda) {
7858 return function(lambda, phi) {
7859 return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
7863 function rotationLambda(deltaLambda) {
7864 var rotation = forwardRotationLambda(deltaLambda);
7865 rotation.invert = forwardRotationLambda(-deltaLambda);
7869 function rotationPhiGamma(deltaPhi, deltaGamma) {
7870 var cosDeltaPhi = cos$1(deltaPhi),
7871 sinDeltaPhi = sin$1(deltaPhi),
7872 cosDeltaGamma = cos$1(deltaGamma),
7873 sinDeltaGamma = sin$1(deltaGamma);
7875 function rotation(lambda, phi) {
7876 var cosPhi = cos$1(phi),
7877 x = cos$1(lambda) * cosPhi,
7878 y = sin$1(lambda) * cosPhi,
7880 k = z * cosDeltaPhi + x * sinDeltaPhi;
7882 atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
7883 asin(k * cosDeltaGamma + y * sinDeltaGamma)
7887 rotation.invert = function(lambda, phi) {
7888 var cosPhi = cos$1(phi),
7889 x = cos$1(lambda) * cosPhi,
7890 y = sin$1(lambda) * cosPhi,
7892 k = z * cosDeltaGamma - y * sinDeltaGamma;
7894 atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
7895 asin(k * cosDeltaPhi - x * sinDeltaPhi)
7902 function rotation(rotate) {
7903 rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
7905 function forward(coordinates) {
7906 coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
7907 return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
7910 forward.invert = function(coordinates) {
7911 coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
7912 return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
7918 // Generates a circle centered at [0°, 0°], with a given radius and precision.
7919 function circleStream(stream, radius, delta, direction, t0, t1) {
7921 var cosRadius = cos$1(radius),
7922 sinRadius = sin$1(radius),
7923 step = direction * delta;
7925 t0 = radius + direction * tau$3;
7926 t1 = radius - step / 2;
7928 t0 = circleRadius(cosRadius, t0);
7929 t1 = circleRadius(cosRadius, t1);
7930 if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
7932 for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
7933 point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
7934 stream.point(point[0], point[1]);
7938 // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
7939 function circleRadius(cosRadius, point) {
7940 point = cartesian(point), point[0] -= cosRadius;
7941 cartesianNormalizeInPlace(point);
7942 var radius = acos(-point[1]);
7943 return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
7947 var center = constant$8([0, 0]),
7948 radius = constant$8(90),
7949 precision = constant$8(6),
7952 stream = {point: point};
7954 function point(x, y) {
7955 ring.push(x = rotate(x, y));
7956 x[0] *= degrees$1, x[1] *= degrees$1;
7960 var c = center.apply(this, arguments),
7961 r = radius.apply(this, arguments) * radians,
7962 p = precision.apply(this, arguments) * radians;
7964 rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
7965 circleStream(stream, r, p, 1);
7966 c = {type: "Polygon", coordinates: [ring]};
7967 ring = rotate = null;
7971 circle.center = function(_) {
7972 return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
7975 circle.radius = function(_) {
7976 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
7979 circle.precision = function(_) {
7980 return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
7986 function clipBuffer() {
7990 point: function(x, y) {
7993 lineStart: function() {
7994 lines.push(line = []);
7997 rejoin: function() {
7998 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
8000 result: function() {
8009 function pointEqual(a, b) {
8010 return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
8013 function Intersection(point, points, other, entry) {
8016 this.o = other; // another intersection
8017 this.e = entry; // is an entry?
8018 this.v = false; // visited
8019 this.n = this.p = null; // next & previous
8022 // A generalized polygon clipping algorithm: given a polygon that has been cut
8023 // into its visible line segments, and rejoins the segments by interpolating
8024 // along the clip edge.
8025 function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
8031 segments.forEach(function(segment) {
8032 if ((n = segment.length - 1) <= 0) return;
8033 var n, p0 = segment[0], p1 = segment[n], x;
8035 // If the first and last points of a segment are coincident, then treat as a
8036 // closed ring. TODO if all rings are closed, then the winding order of the
8037 // exterior ring should be checked.
8038 if (pointEqual(p0, p1)) {
8040 for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
8045 subject.push(x = new Intersection(p0, segment, null, true));
8046 clip.push(x.o = new Intersection(p0, null, x, false));
8047 subject.push(x = new Intersection(p1, segment, null, false));
8048 clip.push(x.o = new Intersection(p1, null, x, true));
8051 if (!subject.length) return;
8053 clip.sort(compareIntersection);
8057 for (i = 0, n = clip.length; i < n; ++i) {
8058 clip[i].e = startInside = !startInside;
8061 var start = subject[0],
8066 // Find first unvisited intersection.
8067 var current = start,
8069 while (current.v) if ((current = current.n) === start) return;
8073 current.v = current.o.v = true;
8076 for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
8078 interpolate(current.x, current.n.x, 1, stream);
8080 current = current.n;
8083 points = current.p.z;
8084 for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
8086 interpolate(current.x, current.p.x, -1, stream);
8088 current = current.p;
8090 current = current.o;
8092 isSubject = !isSubject;
8093 } while (!current.v);
8098 function link$1(array) {
8099 if (!(n = array.length)) return;
8113 var sum$1 = adder();
8115 function polygonContains(polygon, point) {
8116 var lambda = point[0],
8118 sinPhi = sin$1(phi),
8119 normal = [sin$1(lambda), -cos$1(lambda), 0],
8125 if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
8126 else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
8128 for (var i = 0, n = polygon.length; i < n; ++i) {
8129 if (!(m = (ring = polygon[i]).length)) continue;
8132 point0 = ring[m - 1],
8133 lambda0 = point0[0],
8134 phi0 = point0[1] / 2 + quarterPi,
8135 sinPhi0 = sin$1(phi0),
8136 cosPhi0 = cos$1(phi0);
8138 for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
8139 var point1 = ring[j],
8140 lambda1 = point1[0],
8141 phi1 = point1[1] / 2 + quarterPi,
8142 sinPhi1 = sin$1(phi1),
8143 cosPhi1 = cos$1(phi1),
8144 delta = lambda1 - lambda0,
8145 sign$$1 = delta >= 0 ? 1 : -1,
8146 absDelta = sign$$1 * delta,
8147 antimeridian = absDelta > pi$3,
8148 k = sinPhi0 * sinPhi1;
8150 sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
8151 angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
8153 // Are the longitudes either side of the point’s meridian (lambda),
8154 // and are the latitudes smaller than the parallel (phi)?
8155 if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
8156 var arc = cartesianCross(cartesian(point0), cartesian(point1));
8157 cartesianNormalizeInPlace(arc);
8158 var intersection = cartesianCross(normal, arc);
8159 cartesianNormalizeInPlace(intersection);
8160 var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
8161 if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
8162 winding += antimeridian ^ delta >= 0 ? 1 : -1;
8168 // First, determine whether the South pole is inside or outside:
8171 // * the polygon winds around it in a clockwise direction.
8172 // * the polygon does not (cumulatively) wind around it, but has a negative
8173 // (counter-clockwise) area.
8175 // Second, count the (signed) number of times a segment crosses a lambda
8176 // from the point to the South pole. If it is zero, then the point is the
8177 // same side as the South pole.
8179 return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
8182 function clip(pointVisible, clipLine, interpolate, start) {
8183 return function(sink) {
8184 var line = clipLine(sink),
8185 ringBuffer = clipBuffer(),
8186 ringSink = clipLine(ringBuffer),
8187 polygonStarted = false,
8194 lineStart: lineStart,
8196 polygonStart: function() {
8197 clip.point = pointRing;
8198 clip.lineStart = ringStart;
8199 clip.lineEnd = ringEnd;
8203 polygonEnd: function() {
8205 clip.lineStart = lineStart;
8206 clip.lineEnd = lineEnd;
8207 segments = merge(segments);
8208 var startInside = polygonContains(polygon, start);
8209 if (segments.length) {
8210 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
8211 clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
8212 } else if (startInside) {
8213 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
8215 interpolate(null, null, 1, sink);
8218 if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
8219 segments = polygon = null;
8221 sphere: function() {
8222 sink.polygonStart();
8224 interpolate(null, null, 1, sink);
8230 function point(lambda, phi) {
8231 if (pointVisible(lambda, phi)) sink.point(lambda, phi);
8234 function pointLine(lambda, phi) {
8235 line.point(lambda, phi);
8238 function lineStart() {
8239 clip.point = pointLine;
8243 function lineEnd() {
8248 function pointRing(lambda, phi) {
8249 ring.push([lambda, phi]);
8250 ringSink.point(lambda, phi);
8253 function ringStart() {
8254 ringSink.lineStart();
8258 function ringEnd() {
8259 pointRing(ring[0][0], ring[0][1]);
8262 var clean = ringSink.clean(),
8263 ringSegments = ringBuffer.result(),
8264 i, n = ringSegments.length, m,
8274 // No intersections.
8276 segment = ringSegments[0];
8277 if ((m = segment.length - 1) > 0) {
8278 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
8280 for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
8286 // Rejoin connected segments.
8287 // TODO reuse ringBuffer.rejoin()?
8288 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
8290 segments.push(ringSegments.filter(validSegment));
8297 function validSegment(segment) {
8298 return segment.length > 1;
8301 // Intersections are sorted along the clip edge. For both antimeridian cutting
8302 // and circle clipping, the same comparison is used.
8303 function compareIntersection(a, b) {
8304 return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
8305 - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
8308 var clipAntimeridian = clip(
8309 function() { return true; },
8310 clipAntimeridianLine,
8311 clipAntimeridianInterpolate,
8315 // Takes a line and cuts into visible segments. Return values: 0 - there were
8316 // intersections or the line was empty; 1 - no intersections; 2 - there were
8317 // intersections, and the first and last segments should be rejoined.
8318 function clipAntimeridianLine(stream) {
8322 clean; // no intersections
8325 lineStart: function() {
8329 point: function(lambda1, phi1) {
8330 var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
8331 delta = abs(lambda1 - lambda0);
8332 if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
8333 stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
8334 stream.point(sign0, phi0);
8337 stream.point(sign1, phi0);
8338 stream.point(lambda1, phi0);
8340 } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
8341 if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
8342 if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
8343 phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
8344 stream.point(sign0, phi0);
8347 stream.point(sign1, phi0);
8350 stream.point(lambda0 = lambda1, phi0 = phi1);
8353 lineEnd: function() {
8355 lambda0 = phi0 = NaN;
8358 return 2 - clean; // if intersections, rejoin first and last segments
8363 function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
8366 sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
8367 return abs(sinLambda0Lambda1) > epsilon$2
8368 ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
8369 - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
8370 / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
8371 : (phi0 + phi1) / 2;
8374 function clipAntimeridianInterpolate(from, to, direction, stream) {
8377 phi = direction * halfPi$2;
8378 stream.point(-pi$3, phi);
8379 stream.point(0, phi);
8380 stream.point(pi$3, phi);
8381 stream.point(pi$3, 0);
8382 stream.point(pi$3, -phi);
8383 stream.point(0, -phi);
8384 stream.point(-pi$3, -phi);
8385 stream.point(-pi$3, 0);
8386 stream.point(-pi$3, phi);
8387 } else if (abs(from[0] - to[0]) > epsilon$2) {
8388 var lambda = from[0] < to[0] ? pi$3 : -pi$3;
8389 phi = direction * lambda / 2;
8390 stream.point(-lambda, phi);
8391 stream.point(0, phi);
8392 stream.point(lambda, phi);
8394 stream.point(to[0], to[1]);
8398 function clipCircle(radius) {
8399 var cr = cos$1(radius),
8400 delta = 6 * radians,
8401 smallRadius = cr > 0,
8402 notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
8404 function interpolate(from, to, direction, stream) {
8405 circleStream(stream, radius, delta, direction, from, to);
8408 function visible(lambda, phi) {
8409 return cos$1(lambda) * cos$1(phi) > cr;
8412 // Takes a line and cuts into visible segments. Return values used for polygon
8413 // clipping: 0 - there were intersections or the line was empty; 1 - no
8414 // intersections 2 - there were intersections, and the first and last segments
8415 // should be rejoined.
8416 function clipLine(stream) {
8417 var point0, // previous point
8418 c0, // code for previous point
8419 v0, // visibility of previous point
8420 v00, // visibility of first point
8421 clean; // no intersections
8423 lineStart: function() {
8427 point: function(lambda, phi) {
8428 var point1 = [lambda, phi],
8430 v = visible(lambda, phi),
8432 ? v ? 0 : code(lambda, phi)
8433 : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
8434 if (!point0 && (v00 = v0 = v)) stream.lineStart();
8435 // Handle degeneracies.
8436 // TODO ignore if not clipping polygons.
8438 point2 = intersect(point0, point1);
8439 if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
8440 point1[0] += epsilon$2;
8441 point1[1] += epsilon$2;
8442 v = visible(point1[0], point1[1]);
8450 point2 = intersect(point1, point0);
8451 stream.point(point2[0], point2[1]);
8454 point2 = intersect(point0, point1);
8455 stream.point(point2[0], point2[1]);
8459 } else if (notHemisphere && point0 && smallRadius ^ v) {
8461 // If the codes for two points are different, or are both zero,
8462 // and there this segment intersects with the small circle.
8463 if (!(c & c0) && (t = intersect(point1, point0, true))) {
8467 stream.point(t[0][0], t[0][1]);
8468 stream.point(t[1][0], t[1][1]);
8471 stream.point(t[1][0], t[1][1]);
8474 stream.point(t[0][0], t[0][1]);
8478 if (v && (!point0 || !pointEqual(point0, point1))) {
8479 stream.point(point1[0], point1[1]);
8481 point0 = point1, v0 = v, c0 = c;
8483 lineEnd: function() {
8484 if (v0) stream.lineEnd();
8487 // Rejoin first and last segments if there were intersections and the first
8488 // and last points were visible.
8490 return clean | ((v00 && v0) << 1);
8495 // Intersects the great circle between a and b with the clip circle.
8496 function intersect(a, b, two) {
8497 var pa = cartesian(a),
8500 // We have two planes, n1.p = d1 and n2.p = d2.
8501 // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
8502 var n1 = [1, 0, 0], // normal
8503 n2 = cartesianCross(pa, pb),
8504 n2n2 = cartesianDot(n2, n2),
8505 n1n2 = n2[0], // cartesianDot(n1, n2),
8506 determinant = n2n2 - n1n2 * n1n2;
8508 // Two polar points.
8509 if (!determinant) return !two && a;
8511 var c1 = cr * n2n2 / determinant,
8512 c2 = -cr * n1n2 / determinant,
8513 n1xn2 = cartesianCross(n1, n2),
8514 A = cartesianScale(n1, c1),
8515 B = cartesianScale(n2, c2);
8516 cartesianAddInPlace(A, B);
8518 // Solve |p(t)|^2 = 1.
8520 w = cartesianDot(A, u),
8521 uu = cartesianDot(u, u),
8522 t2 = w * w - uu * (cartesianDot(A, A) - 1);
8527 q = cartesianScale(u, (-w - t) / uu);
8528 cartesianAddInPlace(q, A);
8533 // Two intersection points.
8540 if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
8542 var delta = lambda1 - lambda0,
8543 polar = abs(delta - pi$3) < epsilon$2,
8544 meridian = polar || delta < epsilon$2;
8546 if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
8548 // Check that the first point is between a and b.
8551 ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
8552 : phi0 <= q[1] && q[1] <= phi1
8553 : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
8554 var q1 = cartesianScale(u, (-w + t) / uu);
8555 cartesianAddInPlace(q1, A);
8556 return [q, spherical(q1)];
8560 // Generates a 4-bit vector representing the location of a point relative to
8561 // the small circle's bounding box.
8562 function code(lambda, phi) {
8563 var r = smallRadius ? radius : pi$3 - radius,
8565 if (lambda < -r) code |= 1; // left
8566 else if (lambda > r) code |= 2; // right
8567 if (phi < -r) code |= 4; // below
8568 else if (phi > r) code |= 8; // above
8572 return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
8575 function clipLine(a, b, x0, y0, x1, y1) {
8587 if (!dx && r > 0) return;
8592 } else if (dx > 0) {
8598 if (!dx && r < 0) return;
8603 } else if (dx > 0) {
8609 if (!dy && r > 0) return;
8614 } else if (dy > 0) {
8620 if (!dy && r < 0) return;
8625 } else if (dy > 0) {
8630 if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
8631 if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
8635 var clipMax = 1e9, clipMin = -clipMax;
8637 // TODO Use d3-polygon’s polygonContains here for the ring check?
8638 // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
8640 function clipRectangle(x0, y0, x1, y1) {
8642 function visible(x, y) {
8643 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
8646 function interpolate(from, to, direction, stream) {
8649 || (a = corner(from, direction)) !== (a1 = corner(to, direction))
8650 || comparePoint(from, to) < 0 ^ direction > 0) {
8651 do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
8652 while ((a = (a + direction + 4) % 4) !== a1);
8654 stream.point(to[0], to[1]);
8658 function corner(p, direction) {
8659 return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
8660 : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
8661 : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
8662 : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
8665 function compareIntersection(a, b) {
8666 return comparePoint(a.x, b.x);
8669 function comparePoint(a, b) {
8670 var ca = corner(a, 1),
8672 return ca !== cb ? ca - cb
8673 : ca === 0 ? b[1] - a[1]
8674 : ca === 1 ? a[0] - b[0]
8675 : ca === 2 ? a[1] - b[1]
8679 return function(stream) {
8680 var activeStream = stream,
8681 bufferStream = clipBuffer(),
8685 x__, y__, v__, // first point
8686 x_, y_, v_, // previous point
8692 lineStart: lineStart,
8694 polygonStart: polygonStart,
8695 polygonEnd: polygonEnd
8698 function point(x, y) {
8699 if (visible(x, y)) activeStream.point(x, y);
8702 function polygonInside() {
8705 for (var i = 0, n = polygon.length; i < n; ++i) {
8706 for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
8707 a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
8708 if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
8709 else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
8716 // Buffer geometry within a polygon and then clip it en masse.
8717 function polygonStart() {
8718 activeStream = bufferStream, segments = [], polygon = [], clean = true;
8721 function polygonEnd() {
8722 var startInside = polygonInside(),
8723 cleanInside = clean && startInside,
8724 visible = (segments = merge(segments)).length;
8725 if (cleanInside || visible) {
8726 stream.polygonStart();
8729 interpolate(null, null, 1, stream);
8733 clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
8735 stream.polygonEnd();
8737 activeStream = stream, segments = polygon = ring = null;
8740 function lineStart() {
8741 clipStream.point = linePoint;
8742 if (polygon) polygon.push(ring = []);
8748 // TODO rather than special-case polygons, simply handle them separately.
8749 // Ideally, coincident intersection points should be jittered to avoid
8751 function lineEnd() {
8753 linePoint(x__, y__);
8754 if (v__ && v_) bufferStream.rejoin();
8755 segments.push(bufferStream.result());
8757 clipStream.point = point;
8758 if (v_) activeStream.lineEnd();
8761 function linePoint(x, y) {
8762 var v = visible(x, y);
8763 if (polygon) ring.push([x, y]);
8765 x__ = x, y__ = y, v__ = v;
8768 activeStream.lineStart();
8769 activeStream.point(x, y);
8772 if (v && v_) activeStream.point(x, y);
8774 var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
8775 b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
8776 if (clipLine(a, b, x0, y0, x1, y1)) {
8778 activeStream.lineStart();
8779 activeStream.point(a[0], a[1]);
8781 activeStream.point(b[0], b[1]);
8782 if (!v) activeStream.lineEnd();
8785 activeStream.lineStart();
8786 activeStream.point(x, y);
8791 x_ = x, y_ = y, v_ = v;
8798 function extent$1() {
8808 stream: function(stream) {
8809 return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
8811 extent: function(_) {
8812 return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
8817 var lengthSum = adder(),
8822 var lengthStream = {
8825 lineStart: lengthLineStart,
8827 polygonStart: noop$2,
8831 function lengthLineStart() {
8832 lengthStream.point = lengthPointFirst;
8833 lengthStream.lineEnd = lengthLineEnd;
8836 function lengthLineEnd() {
8837 lengthStream.point = lengthStream.lineEnd = noop$2;
8840 function lengthPointFirst(lambda, phi) {
8841 lambda *= radians, phi *= radians;
8842 lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
8843 lengthStream.point = lengthPoint;
8846 function lengthPoint(lambda, phi) {
8847 lambda *= radians, phi *= radians;
8848 var sinPhi = sin$1(phi),
8849 cosPhi = cos$1(phi),
8850 delta = abs(lambda - lambda0$2),
8851 cosDelta = cos$1(delta),
8852 sinDelta = sin$1(delta),
8853 x = cosPhi * sinDelta,
8854 y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
8855 z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
8856 lengthSum.add(atan2(sqrt(x * x + y * y), z));
8857 lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
8860 function length$1(object) {
8862 geoStream(object, lengthStream);
8866 var coordinates = [null, null],
8867 object$1 = {type: "LineString", coordinates: coordinates};
8869 function distance(a, b) {
8872 return length$1(object$1);
8875 var containsObjectType = {
8876 Feature: function(object, point) {
8877 return containsGeometry(object.geometry, point);
8879 FeatureCollection: function(object, point) {
8880 var features = object.features, i = -1, n = features.length;
8881 while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
8886 var containsGeometryType = {
8887 Sphere: function() {
8890 Point: function(object, point) {
8891 return containsPoint(object.coordinates, point);
8893 MultiPoint: function(object, point) {
8894 var coordinates = object.coordinates, i = -1, n = coordinates.length;
8895 while (++i < n) if (containsPoint(coordinates[i], point)) return true;
8898 LineString: function(object, point) {
8899 return containsLine(object.coordinates, point);
8901 MultiLineString: function(object, point) {
8902 var coordinates = object.coordinates, i = -1, n = coordinates.length;
8903 while (++i < n) if (containsLine(coordinates[i], point)) return true;
8906 Polygon: function(object, point) {
8907 return containsPolygon(object.coordinates, point);
8909 MultiPolygon: function(object, point) {
8910 var coordinates = object.coordinates, i = -1, n = coordinates.length;
8911 while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
8914 GeometryCollection: function(object, point) {
8915 var geometries = object.geometries, i = -1, n = geometries.length;
8916 while (++i < n) if (containsGeometry(geometries[i], point)) return true;
8921 function containsGeometry(geometry, point) {
8922 return geometry && containsGeometryType.hasOwnProperty(geometry.type)
8923 ? containsGeometryType[geometry.type](geometry, point)
8927 function containsPoint(coordinates, point) {
8928 return distance(coordinates, point) === 0;
8931 function containsLine(coordinates, point) {
8932 var ab = distance(coordinates[0], coordinates[1]),
8933 ao = distance(coordinates[0], point),
8934 ob = distance(point, coordinates[1]);
8935 return ao + ob <= ab + epsilon$2;
8938 function containsPolygon(coordinates, point) {
8939 return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
8942 function ringRadians(ring) {
8943 return ring = ring.map(pointRadians), ring.pop(), ring;
8946 function pointRadians(point) {
8947 return [point[0] * radians, point[1] * radians];
8950 function contains$1(object, point) {
8951 return (object && containsObjectType.hasOwnProperty(object.type)
8952 ? containsObjectType[object.type]
8953 : containsGeometry)(object, point);
8956 function graticuleX(y0, y1, dy) {
8957 var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
8958 return function(x) { return y.map(function(y) { return [x, y]; }); };
8961 function graticuleY(x0, x1, dx) {
8962 var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
8963 return function(y) { return x.map(function(x) { return [x, y]; }); };
8966 function graticule() {
8969 dx = 10, dy = dx, DX = 90, DY = 360,
8973 function graticule() {
8974 return {type: "MultiLineString", coordinates: lines()};
8978 return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
8979 .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
8980 .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
8981 .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
8984 graticule.lines = function() {
8985 return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
8988 graticule.outline = function() {
8994 X(X1).reverse().slice(1),
8995 Y(Y0).reverse().slice(1))
9000 graticule.extent = function(_) {
9001 if (!arguments.length) return graticule.extentMinor();
9002 return graticule.extentMajor(_).extentMinor(_);
9005 graticule.extentMajor = function(_) {
9006 if (!arguments.length) return [[X0, Y0], [X1, Y1]];
9007 X0 = +_[0][0], X1 = +_[1][0];
9008 Y0 = +_[0][1], Y1 = +_[1][1];
9009 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
9010 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
9011 return graticule.precision(precision);
9014 graticule.extentMinor = function(_) {
9015 if (!arguments.length) return [[x0, y0], [x1, y1]];
9016 x0 = +_[0][0], x1 = +_[1][0];
9017 y0 = +_[0][1], y1 = +_[1][1];
9018 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
9019 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
9020 return graticule.precision(precision);
9023 graticule.step = function(_) {
9024 if (!arguments.length) return graticule.stepMinor();
9025 return graticule.stepMajor(_).stepMinor(_);
9028 graticule.stepMajor = function(_) {
9029 if (!arguments.length) return [DX, DY];
9030 DX = +_[0], DY = +_[1];
9034 graticule.stepMinor = function(_) {
9035 if (!arguments.length) return [dx, dy];
9036 dx = +_[0], dy = +_[1];
9040 graticule.precision = function(_) {
9041 if (!arguments.length) return precision;
9043 x = graticuleX(y0, y1, 90);
9044 y = graticuleY(x0, x1, precision);
9045 X = graticuleX(Y0, Y1, 90);
9046 Y = graticuleY(X0, X1, precision);
9051 .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
9052 .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
9055 function graticule10() {
9056 return graticule()();
9059 function interpolate$1(a, b) {
9060 var x0 = a[0] * radians,
9061 y0 = a[1] * radians,
9062 x1 = b[0] * radians,
9063 y1 = b[1] * radians,
9068 kx0 = cy0 * cos$1(x0),
9069 ky0 = cy0 * sin$1(x0),
9070 kx1 = cy1 * cos$1(x1),
9071 ky1 = cy1 * sin$1(x1),
9072 d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
9075 var interpolate = d ? function(t) {
9076 var B = sin$1(t *= d) / k,
9077 A = sin$1(d - t) / k,
9078 x = A * kx0 + B * kx1,
9079 y = A * ky0 + B * ky1,
9080 z = A * sy0 + B * sy1;
9082 atan2(y, x) * degrees$1,
9083 atan2(z, sqrt(x * x + y * y)) * degrees$1
9086 return [x0 * degrees$1, y0 * degrees$1];
9089 interpolate.distance = d;
9094 function identity$4(x) {
9098 var areaSum$1 = adder(),
9099 areaRingSum$1 = adder(),
9105 var areaStream$1 = {
9109 polygonStart: function() {
9110 areaStream$1.lineStart = areaRingStart$1;
9111 areaStream$1.lineEnd = areaRingEnd$1;
9113 polygonEnd: function() {
9114 areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
9115 areaSum$1.add(abs(areaRingSum$1));
9116 areaRingSum$1.reset();
9118 result: function() {
9119 var area = areaSum$1 / 2;
9125 function areaRingStart$1() {
9126 areaStream$1.point = areaPointFirst$1;
9129 function areaPointFirst$1(x, y) {
9130 areaStream$1.point = areaPoint$1;
9131 x00 = x0$1 = x, y00 = y0$1 = y;
9134 function areaPoint$1(x, y) {
9135 areaRingSum$1.add(y0$1 * x - x0$1 * y);
9139 function areaRingEnd$1() {
9140 areaPoint$1(x00, y00);
9143 var x0$2 = Infinity,
9148 var boundsStream$1 = {
9149 point: boundsPoint$1,
9152 polygonStart: noop$2,
9154 result: function() {
9155 var bounds = [[x0$2, y0$2], [x1, y1]];
9156 x1 = y1 = -(y0$2 = x0$2 = Infinity);
9161 function boundsPoint$1(x, y) {
9162 if (x < x0$2) x0$2 = x;
9164 if (y < y0$2) y0$2 = y;
9168 // TODO Enforce positive area for exterior, negative area for interior?
9184 var centroidStream$1 = {
9185 point: centroidPoint$1,
9186 lineStart: centroidLineStart$1,
9187 lineEnd: centroidLineEnd$1,
9188 polygonStart: function() {
9189 centroidStream$1.lineStart = centroidRingStart$1;
9190 centroidStream$1.lineEnd = centroidRingEnd$1;
9192 polygonEnd: function() {
9193 centroidStream$1.point = centroidPoint$1;
9194 centroidStream$1.lineStart = centroidLineStart$1;
9195 centroidStream$1.lineEnd = centroidLineEnd$1;
9197 result: function() {
9198 var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
9199 : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
9200 : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
9202 X0$1 = Y0$1 = Z0$1 =
9203 X1$1 = Y1$1 = Z1$1 =
9204 X2$1 = Y2$1 = Z2$1 = 0;
9209 function centroidPoint$1(x, y) {
9215 function centroidLineStart$1() {
9216 centroidStream$1.point = centroidPointFirstLine;
9219 function centroidPointFirstLine(x, y) {
9220 centroidStream$1.point = centroidPointLine;
9221 centroidPoint$1(x0$3 = x, y0$3 = y);
9224 function centroidPointLine(x, y) {
9225 var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
9226 X1$1 += z * (x0$3 + x) / 2;
9227 Y1$1 += z * (y0$3 + y) / 2;
9229 centroidPoint$1(x0$3 = x, y0$3 = y);
9232 function centroidLineEnd$1() {
9233 centroidStream$1.point = centroidPoint$1;
9236 function centroidRingStart$1() {
9237 centroidStream$1.point = centroidPointFirstRing;
9240 function centroidRingEnd$1() {
9241 centroidPointRing(x00$1, y00$1);
9244 function centroidPointFirstRing(x, y) {
9245 centroidStream$1.point = centroidPointRing;
9246 centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
9249 function centroidPointRing(x, y) {
9252 z = sqrt(dx * dx + dy * dy);
9254 X1$1 += z * (x0$3 + x) / 2;
9255 Y1$1 += z * (y0$3 + y) / 2;
9258 z = y0$3 * x - x0$3 * y;
9259 X2$1 += z * (x0$3 + x);
9260 Y2$1 += z * (y0$3 + y);
9262 centroidPoint$1(x0$3 = x, y0$3 = y);
9265 function PathContext(context) {
9266 this._context = context;
9269 PathContext.prototype = {
9271 pointRadius: function(_) {
9272 return this._radius = _, this;
9274 polygonStart: function() {
9277 polygonEnd: function() {
9280 lineStart: function() {
9283 lineEnd: function() {
9284 if (this._line === 0) this._context.closePath();
9287 point: function(x, y) {
9288 switch (this._point) {
9290 this._context.moveTo(x, y);
9295 this._context.lineTo(x, y);
9299 this._context.moveTo(x + this._radius, y);
9300 this._context.arc(x, y, this._radius, 0, tau$3);
9308 var lengthSum$1 = adder(),
9315 var lengthStream$1 = {
9317 lineStart: function() {
9318 lengthStream$1.point = lengthPointFirst$1;
9320 lineEnd: function() {
9321 if (lengthRing) lengthPoint$1(x00$2, y00$2);
9322 lengthStream$1.point = noop$2;
9324 polygonStart: function() {
9327 polygonEnd: function() {
9330 result: function() {
9331 var length = +lengthSum$1;
9332 lengthSum$1.reset();
9337 function lengthPointFirst$1(x, y) {
9338 lengthStream$1.point = lengthPoint$1;
9339 x00$2 = x0$4 = x, y00$2 = y0$4 = y;
9342 function lengthPoint$1(x, y) {
9343 x0$4 -= x, y0$4 -= y;
9344 lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
9348 function PathString() {
9352 PathString.prototype = {
9354 _circle: circle$1(4.5),
9355 pointRadius: function(_) {
9356 if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
9359 polygonStart: function() {
9362 polygonEnd: function() {
9365 lineStart: function() {
9368 lineEnd: function() {
9369 if (this._line === 0) this._string.push("Z");
9372 point: function(x, y) {
9373 switch (this._point) {
9375 this._string.push("M", x, ",", y);
9380 this._string.push("L", x, ",", y);
9384 if (this._circle == null) this._circle = circle$1(this._radius);
9385 this._string.push("M", x, ",", y, this._circle);
9390 result: function() {
9391 if (this._string.length) {
9392 var result = this._string.join("");
9401 function circle$1(radius) {
9402 return "m0," + radius
9403 + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
9404 + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
9408 function index$1(projection, context) {
9409 var pointRadius = 4.5,
9413 function path(object) {
9415 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
9416 geoStream(object, projectionStream(contextStream));
9418 return contextStream.result();
9421 path.area = function(object) {
9422 geoStream(object, projectionStream(areaStream$1));
9423 return areaStream$1.result();
9426 path.measure = function(object) {
9427 geoStream(object, projectionStream(lengthStream$1));
9428 return lengthStream$1.result();
9431 path.bounds = function(object) {
9432 geoStream(object, projectionStream(boundsStream$1));
9433 return boundsStream$1.result();
9436 path.centroid = function(object) {
9437 geoStream(object, projectionStream(centroidStream$1));
9438 return centroidStream$1.result();
9441 path.projection = function(_) {
9442 return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
9445 path.context = function(_) {
9446 if (!arguments.length) return context;
9447 contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
9448 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
9452 path.pointRadius = function(_) {
9453 if (!arguments.length) return pointRadius;
9454 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
9458 return path.projection(projection).context(context);
9461 function transform(methods) {
9463 stream: transformer(methods)
9467 function transformer(methods) {
9468 return function(stream) {
9469 var s = new TransformStream;
9470 for (var key in methods) s[key] = methods[key];
9476 function TransformStream() {}
9478 TransformStream.prototype = {
9479 constructor: TransformStream,
9480 point: function(x, y) { this.stream.point(x, y); },
9481 sphere: function() { this.stream.sphere(); },
9482 lineStart: function() { this.stream.lineStart(); },
9483 lineEnd: function() { this.stream.lineEnd(); },
9484 polygonStart: function() { this.stream.polygonStart(); },
9485 polygonEnd: function() { this.stream.polygonEnd(); }
9488 function fit(projection, fitBounds, object) {
9489 var clip = projection.clipExtent && projection.clipExtent();
9490 projection.scale(150).translate([0, 0]);
9491 if (clip != null) projection.clipExtent(null);
9492 geoStream(object, projection.stream(boundsStream$1));
9493 fitBounds(boundsStream$1.result());
9494 if (clip != null) projection.clipExtent(clip);
9498 function fitExtent(projection, extent, object) {
9499 return fit(projection, function(b) {
9500 var w = extent[1][0] - extent[0][0],
9501 h = extent[1][1] - extent[0][1],
9502 k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
9503 x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
9504 y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
9505 projection.scale(150 * k).translate([x, y]);
9509 function fitSize(projection, size, object) {
9510 return fitExtent(projection, [[0, 0], size], object);
9513 function fitWidth(projection, width, object) {
9514 return fit(projection, function(b) {
9516 k = w / (b[1][0] - b[0][0]),
9517 x = (w - k * (b[1][0] + b[0][0])) / 2,
9519 projection.scale(150 * k).translate([x, y]);
9523 function fitHeight(projection, height, object) {
9524 return fit(projection, function(b) {
9526 k = h / (b[1][1] - b[0][1]),
9528 y = (h - k * (b[1][1] + b[0][1])) / 2;
9529 projection.scale(150 * k).translate([x, y]);
9533 var maxDepth = 16, // maximum depth of subdivision
9534 cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
9536 function resample(project, delta2) {
9537 return +delta2 ? resample$1(project, delta2) : resampleNone(project);
9540 function resampleNone(project) {
9541 return transformer({
9542 point: function(x, y) {
9544 this.stream.point(x[0], x[1]);
9549 function resample$1(project, delta2) {
9551 function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
9554 d2 = dx * dx + dy * dy;
9555 if (d2 > 4 * delta2 && depth--) {
9559 m = sqrt(a * a + b * b + c * c),
9560 phi2 = asin(c /= m),
9561 lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
9562 p = project(lambda2, phi2),
9567 dz = dy * dx2 - dx * dy2;
9568 if (dz * dz / d2 > delta2 // perpendicular projected distance
9569 || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
9570 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
9571 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
9572 stream.point(x2, y2);
9573 resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
9577 return function(stream) {
9578 var lambda00, x00, y00, a00, b00, c00, // first point
9579 lambda0, x0, y0, a0, b0, c0; // previous point
9581 var resampleStream = {
9583 lineStart: lineStart,
9585 polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
9586 polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
9589 function point(x, y) {
9591 stream.point(x[0], x[1]);
9594 function lineStart() {
9596 resampleStream.point = linePoint;
9600 function linePoint(lambda, phi) {
9601 var c = cartesian([lambda, phi]), p = project(lambda, phi);
9602 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x0 = p[0], y0 = p[1], lambda0 = lambda, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
9603 stream.point(x0, y0);
9606 function lineEnd() {
9607 resampleStream.point = point;
9611 function ringStart() {
9613 resampleStream.point = ringPoint;
9614 resampleStream.lineEnd = ringEnd;
9617 function ringPoint(lambda, phi) {
9618 linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
9619 resampleStream.point = linePoint;
9622 function ringEnd() {
9623 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
9624 resampleStream.lineEnd = lineEnd;
9628 return resampleStream;
9632 var transformRadians = transformer({
9633 point: function(x, y) {
9634 this.stream.point(x * radians, y * radians);
9638 function transformRotate(rotate) {
9639 return transformer({
9640 point: function(x, y) {
9641 var r = rotate(x, y);
9642 return this.stream.point(r[0], r[1]);
9647 function scaleTranslate(k, dx, dy) {
9648 function transform$$1(x, y) {
9649 return [dx + k * x, dy - k * y];
9651 transform$$1.invert = function(x, y) {
9652 return [(x - dx) / k, (dy - y) / k];
9654 return transform$$1;
9657 function scaleTranslateRotate(k, dx, dy, alpha) {
9658 var cosAlpha = cos$1(alpha),
9659 sinAlpha = sin$1(alpha),
9664 ci = (sinAlpha * dy - cosAlpha * dx) / k,
9665 fi = (sinAlpha * dx + cosAlpha * dy) / k;
9666 function transform$$1(x, y) {
9667 return [a * x - b * y + dx, dy - b * x - a * y];
9669 transform$$1.invert = function(x, y) {
9670 return [ai * x - bi * y + ci, fi - bi * x - ai * y];
9672 return transform$$1;
9675 function projection(project) {
9676 return projectionMutator(function() { return project; })();
9679 function projectionMutator(projectAt) {
9682 x = 480, y = 250, // translate
9683 lambda = 0, phi = 0, // center
9684 deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
9685 alpha = 0, // post-rotate
9686 theta = null, preclip = clipAntimeridian, // pre-clip angle
9687 x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
9688 delta2 = 0.5, // precision
9691 projectRotateTransform,
9695 function projection(point) {
9696 return projectRotateTransform(point[0] * radians, point[1] * radians);
9699 function invert(point) {
9700 point = projectRotateTransform.invert(point[0], point[1]);
9701 return point && [point[0] * degrees$1, point[1] * degrees$1];
9704 projection.stream = function(stream) {
9705 return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
9708 projection.preclip = function(_) {
9709 return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
9712 projection.postclip = function(_) {
9713 return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
9716 projection.clipAngle = function(_) {
9717 return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
9720 projection.clipExtent = function(_) {
9721 return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
9724 projection.scale = function(_) {
9725 return arguments.length ? (k = +_, recenter()) : k;
9728 projection.translate = function(_) {
9729 return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
9732 projection.center = function(_) {
9733 return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
9736 projection.rotate = function(_) {
9737 return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees$1, deltaPhi * degrees$1, deltaGamma * degrees$1];
9740 projection.angle = function(_) {
9741 return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
9744 projection.precision = function(_) {
9745 return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
9748 projection.fitExtent = function(extent, object) {
9749 return fitExtent(projection, extent, object);
9752 projection.fitSize = function(size, object) {
9753 return fitSize(projection, size, object);
9756 projection.fitWidth = function(width, object) {
9757 return fitWidth(projection, width, object);
9760 projection.fitHeight = function(height, object) {
9761 return fitHeight(projection, height, object);
9764 function recenter() {
9765 var center = scaleTranslateRotate(k, 0, 0, alpha).apply(null, project(lambda, phi)),
9766 transform$$1 = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], alpha);
9767 rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
9768 projectTransform = compose(project, transform$$1);
9769 projectRotateTransform = compose(rotate, projectTransform);
9770 projectResample = resample(projectTransform, delta2);
9775 cache = cacheStream = null;
9780 project = projectAt.apply(this, arguments);
9781 projection.invert = project.invert && invert;
9786 function conicProjection(projectAt) {
9789 m = projectionMutator(projectAt),
9792 p.parallels = function(_) {
9793 return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
9799 function cylindricalEqualAreaRaw(phi0) {
9800 var cosPhi0 = cos$1(phi0);
9802 function forward(lambda, phi) {
9803 return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
9806 forward.invert = function(x, y) {
9807 return [x / cosPhi0, asin(y * cosPhi0)];
9813 function conicEqualAreaRaw(y0, y1) {
9814 var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
9816 // Are the parallels symmetrical around the Equator?
9817 if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
9819 var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
9821 function project(x, y) {
9822 var r = sqrt(c - 2 * n * sin$1(y)) / n;
9823 return [r * sin$1(x *= n), r0 - r * cos$1(x)];
9826 project.invert = function(x, y) {
9828 return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
9834 function conicEqualArea() {
9835 return conicProjection(conicEqualAreaRaw)
9837 .center([0, 33.6442]);
9841 return conicEqualArea()
9842 .parallels([29.5, 45.5])
9844 .translate([480, 250])
9846 .center([-0.6, 38.7]);
9849 // The projections must have mutually exclusive clip regions on the sphere,
9850 // as this will avoid emitting interleaving lines and polygons.
9851 function multiplex(streams) {
9852 var n = streams.length;
9854 point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
9855 sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
9856 lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
9857 lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
9858 polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
9859 polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
9863 // A composite projection for the United States, configured by default for
9864 // 960×500. The projection also works quite well at 960×600 if you change the
9865 // scale to 1285 and adjust the translate accordingly. The set of standard
9866 // parallels for each region comes from USGS, which is published here:
9867 // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
9868 function albersUsa() {
9871 lower48 = albers(), lower48Point,
9872 alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
9873 hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
9874 point, pointStream = {point: function(x, y) { point = [x, y]; }};
9876 function albersUsa(coordinates) {
9877 var x = coordinates[0], y = coordinates[1];
9878 return point = null, (lower48Point.point(x, y), point)
9879 || (alaskaPoint.point(x, y), point)
9880 || (hawaiiPoint.point(x, y), point);
9883 albersUsa.invert = function(coordinates) {
9884 var k = lower48.scale(),
9885 t = lower48.translate(),
9886 x = (coordinates[0] - t[0]) / k,
9887 y = (coordinates[1] - t[1]) / k;
9888 return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
9889 : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
9890 : lower48).invert(coordinates);
9893 albersUsa.stream = function(stream) {
9894 return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
9897 albersUsa.precision = function(_) {
9898 if (!arguments.length) return lower48.precision();
9899 lower48.precision(_), alaska.precision(_), hawaii.precision(_);
9903 albersUsa.scale = function(_) {
9904 if (!arguments.length) return lower48.scale();
9905 lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
9906 return albersUsa.translate(lower48.translate());
9909 albersUsa.translate = function(_) {
9910 if (!arguments.length) return lower48.translate();
9911 var k = lower48.scale(), x = +_[0], y = +_[1];
9913 lower48Point = lower48
9915 .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
9916 .stream(pointStream);
9918 alaskaPoint = alaska
9919 .translate([x - 0.307 * k, y + 0.201 * k])
9920 .clipExtent([[x - 0.425 * k + epsilon$2, y + 0.120 * k + epsilon$2], [x - 0.214 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
9921 .stream(pointStream);
9923 hawaiiPoint = hawaii
9924 .translate([x - 0.205 * k, y + 0.212 * k])
9925 .clipExtent([[x - 0.214 * k + epsilon$2, y + 0.166 * k + epsilon$2], [x - 0.115 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
9926 .stream(pointStream);
9931 albersUsa.fitExtent = function(extent, object) {
9932 return fitExtent(albersUsa, extent, object);
9935 albersUsa.fitSize = function(size, object) {
9936 return fitSize(albersUsa, size, object);
9939 albersUsa.fitWidth = function(width, object) {
9940 return fitWidth(albersUsa, width, object);
9943 albersUsa.fitHeight = function(height, object) {
9944 return fitHeight(albersUsa, height, object);
9948 cache = cacheStream = null;
9952 return albersUsa.scale(1070);
9955 function azimuthalRaw(scale) {
9956 return function(x, y) {
9967 function azimuthalInvert(angle) {
9968 return function(x, y) {
9969 var z = sqrt(x * x + y * y),
9974 atan2(x * sc, z * cc),
9975 asin(z && y * sc / z)
9980 var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
9981 return sqrt(2 / (1 + cxcy));
9984 azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
9985 return 2 * asin(z / 2);
9988 function azimuthalEqualArea() {
9989 return projection(azimuthalEqualAreaRaw)
9991 .clipAngle(180 - 1e-3);
9994 var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
9995 return (c = acos(c)) && c / sin$1(c);
9998 azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
10002 function azimuthalEquidistant() {
10003 return projection(azimuthalEquidistantRaw)
10005 .clipAngle(180 - 1e-3);
10008 function mercatorRaw(lambda, phi) {
10009 return [lambda, log(tan((halfPi$2 + phi) / 2))];
10012 mercatorRaw.invert = function(x, y) {
10013 return [x, 2 * atan(exp(y)) - halfPi$2];
10016 function mercator() {
10017 return mercatorProjection(mercatorRaw)
10018 .scale(961 / tau$3);
10021 function mercatorProjection(project) {
10022 var m = projection(project),
10025 translate = m.translate,
10026 clipExtent = m.clipExtent,
10027 x0 = null, y0, x1, y1; // clip extent
10029 m.scale = function(_) {
10030 return arguments.length ? (scale(_), reclip()) : scale();
10033 m.translate = function(_) {
10034 return arguments.length ? (translate(_), reclip()) : translate();
10037 m.center = function(_) {
10038 return arguments.length ? (center(_), reclip()) : center();
10041 m.clipExtent = function(_) {
10042 return arguments.length ? (_ == null ? x0 = y0 = x1 = y1 = null : (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reclip()) : x0 == null ? null : [[x0, y0], [x1, y1]];
10045 function reclip() {
10046 var k = pi$3 * scale(),
10047 t = m(rotation(m.rotate()).invert([0, 0]));
10048 return clipExtent(x0 == null
10049 ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
10050 ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
10051 : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
10058 return tan((halfPi$2 + y) / 2);
10061 function conicConformalRaw(y0, y1) {
10062 var cy0 = cos$1(y0),
10063 n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
10064 f = cy0 * pow(tany(y0), n) / n;
10066 if (!n) return mercatorRaw;
10068 function project(x, y) {
10069 if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
10070 else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
10071 var r = f / pow(tany(y), n);
10072 return [r * sin$1(n * x), f - r * cos$1(n * x)];
10075 project.invert = function(x, y) {
10076 var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
10077 return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
10083 function conicConformal() {
10084 return conicProjection(conicConformalRaw)
10086 .parallels([30, 30]);
10089 function equirectangularRaw(lambda, phi) {
10090 return [lambda, phi];
10093 equirectangularRaw.invert = equirectangularRaw;
10095 function equirectangular() {
10096 return projection(equirectangularRaw)
10100 function conicEquidistantRaw(y0, y1) {
10101 var cy0 = cos$1(y0),
10102 n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
10105 if (abs(n) < epsilon$2) return equirectangularRaw;
10107 function project(x, y) {
10108 var gy = g - y, nx = n * x;
10109 return [gy * sin$1(nx), g - gy * cos$1(nx)];
10112 project.invert = function(x, y) {
10114 return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
10120 function conicEquidistant() {
10121 return conicProjection(conicEquidistantRaw)
10123 .center([0, 13.9389]);
10126 function gnomonicRaw(x, y) {
10127 var cy = cos$1(y), k = cos$1(x) * cy;
10128 return [cy * sin$1(x) / k, sin$1(y) / k];
10131 gnomonicRaw.invert = azimuthalInvert(atan);
10133 function gnomonic() {
10134 return projection(gnomonicRaw)
10139 function scaleTranslate$1(kx, ky, tx, ty) {
10140 return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
10141 point: function(x, y) {
10142 this.stream.point(x * kx + tx, y * ky + ty);
10147 function identity$5() {
10148 var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
10149 x0 = null, y0, x1, y1, // clip extent
10150 postclip = identity$4,
10156 cache = cacheStream = null;
10160 return projection = {
10161 stream: function(stream) {
10162 return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
10164 postclip: function(_) {
10165 return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
10167 clipExtent: function(_) {
10168 return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
10170 scale: function(_) {
10171 return arguments.length ? (transform$$1 = scaleTranslate$1((k = +_) * sx, k * sy, tx, ty), reset()) : k;
10173 translate: function(_) {
10174 return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
10176 reflectX: function(_) {
10177 return arguments.length ? (transform$$1 = scaleTranslate$1(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
10179 reflectY: function(_) {
10180 return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
10182 fitExtent: function(extent, object) {
10183 return fitExtent(projection, extent, object);
10185 fitSize: function(size, object) {
10186 return fitSize(projection, size, object);
10188 fitWidth: function(width, object) {
10189 return fitWidth(projection, width, object);
10191 fitHeight: function(height, object) {
10192 return fitHeight(projection, height, object);
10197 function naturalEarth1Raw(lambda, phi) {
10198 var phi2 = phi * phi, phi4 = phi2 * phi2;
10200 lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
10201 phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
10205 naturalEarth1Raw.invert = function(x, y) {
10206 var phi = y, i = 25, delta;
10208 var phi2 = phi * phi, phi4 = phi2 * phi2;
10209 phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
10210 (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
10211 } while (abs(delta) > epsilon$2 && --i > 0);
10213 x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
10218 function naturalEarth1() {
10219 return projection(naturalEarth1Raw)
10223 function orthographicRaw(x, y) {
10224 return [cos$1(y) * sin$1(x), sin$1(y)];
10227 orthographicRaw.invert = azimuthalInvert(asin);
10229 function orthographic() {
10230 return projection(orthographicRaw)
10232 .clipAngle(90 + epsilon$2);
10235 function stereographicRaw(x, y) {
10236 var cy = cos$1(y), k = 1 + cos$1(x) * cy;
10237 return [cy * sin$1(x) / k, sin$1(y) / k];
10240 stereographicRaw.invert = azimuthalInvert(function(z) {
10241 return 2 * atan(z);
10244 function stereographic() {
10245 return projection(stereographicRaw)
10250 function transverseMercatorRaw(lambda, phi) {
10251 return [log(tan((halfPi$2 + phi) / 2)), -lambda];
10254 transverseMercatorRaw.invert = function(x, y) {
10255 return [-y, 2 * atan(exp(x)) - halfPi$2];
10258 function transverseMercator() {
10259 var m = mercatorProjection(transverseMercatorRaw),
10263 m.center = function(_) {
10264 return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
10267 m.rotate = function(_) {
10268 return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
10271 return rotate([0, 0, 90])
10275 function defaultSeparation(a, b) {
10276 return a.parent === b.parent ? 1 : 2;
10279 function meanX(children) {
10280 return children.reduce(meanXReduce, 0) / children.length;
10283 function meanXReduce(x, c) {
10287 function maxY(children) {
10288 return 1 + children.reduce(maxYReduce, 0);
10291 function maxYReduce(y, c) {
10292 return Math.max(y, c.y);
10295 function leafLeft(node) {
10297 while (children = node.children) node = children[0];
10301 function leafRight(node) {
10303 while (children = node.children) node = children[children.length - 1];
10307 function cluster() {
10308 var separation = defaultSeparation,
10313 function cluster(root) {
10317 // First walk, computing the initial x & y values.
10318 root.eachAfter(function(node) {
10319 var children = node.children;
10321 node.x = meanX(children);
10322 node.y = maxY(children);
10324 node.x = previousNode ? x += separation(node, previousNode) : 0;
10326 previousNode = node;
10330 var left = leafLeft(root),
10331 right = leafRight(root),
10332 x0 = left.x - separation(left, right) / 2,
10333 x1 = right.x + separation(right, left) / 2;
10335 // Second walk, normalizing x & y to the desired size.
10336 return root.eachAfter(nodeSize ? function(node) {
10337 node.x = (node.x - root.x) * dx;
10338 node.y = (root.y - node.y) * dy;
10339 } : function(node) {
10340 node.x = (node.x - x0) / (x1 - x0) * dx;
10341 node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
10345 cluster.separation = function(x) {
10346 return arguments.length ? (separation = x, cluster) : separation;
10349 cluster.size = function(x) {
10350 return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
10353 cluster.nodeSize = function(x) {
10354 return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
10360 function count(node) {
10362 children = node.children,
10363 i = children && children.length;
10365 else while (--i >= 0) sum += children[i].value;
10369 function node_count() {
10370 return this.eachAfter(count);
10373 function node_each(callback) {
10374 var node = this, current, next = [node], children, i, n;
10376 current = next.reverse(), next = [];
10377 while (node = current.pop()) {
10378 callback(node), children = node.children;
10379 if (children) for (i = 0, n = children.length; i < n; ++i) {
10380 next.push(children[i]);
10383 } while (next.length);
10387 function node_eachBefore(callback) {
10388 var node = this, nodes = [node], children, i;
10389 while (node = nodes.pop()) {
10390 callback(node), children = node.children;
10391 if (children) for (i = children.length - 1; i >= 0; --i) {
10392 nodes.push(children[i]);
10398 function node_eachAfter(callback) {
10399 var node = this, nodes = [node], next = [], children, i, n;
10400 while (node = nodes.pop()) {
10401 next.push(node), children = node.children;
10402 if (children) for (i = 0, n = children.length; i < n; ++i) {
10403 nodes.push(children[i]);
10406 while (node = next.pop()) {
10412 function node_sum(value) {
10413 return this.eachAfter(function(node) {
10414 var sum = +value(node.data) || 0,
10415 children = node.children,
10416 i = children && children.length;
10417 while (--i >= 0) sum += children[i].value;
10422 function node_sort(compare) {
10423 return this.eachBefore(function(node) {
10424 if (node.children) {
10425 node.children.sort(compare);
10430 function node_path(end) {
10432 ancestor = leastCommonAncestor(start, end),
10434 while (start !== ancestor) {
10435 start = start.parent;
10438 var k = nodes.length;
10439 while (end !== ancestor) {
10440 nodes.splice(k, 0, end);
10446 function leastCommonAncestor(a, b) {
10447 if (a === b) return a;
10448 var aNodes = a.ancestors(),
10449 bNodes = b.ancestors(),
10461 function node_ancestors() {
10462 var node = this, nodes = [node];
10463 while (node = node.parent) {
10469 function node_descendants() {
10471 this.each(function(node) {
10477 function node_leaves() {
10479 this.eachBefore(function(node) {
10480 if (!node.children) {
10487 function node_links() {
10488 var root = this, links = [];
10489 root.each(function(node) {
10490 if (node !== root) { // Don’t include the root’s parent, if any.
10491 links.push({source: node.parent, target: node});
10497 function hierarchy(data, children) {
10498 var root = new Node(data),
10499 valued = +data.value && (root.value = data.value),
10507 if (children == null) children = defaultChildren;
10509 while (node = nodes.pop()) {
10510 if (valued) node.value = +node.data.value;
10511 if ((childs = children(node.data)) && (n = childs.length)) {
10512 node.children = new Array(n);
10513 for (i = n - 1; i >= 0; --i) {
10514 nodes.push(child = node.children[i] = new Node(childs[i]));
10515 child.parent = node;
10516 child.depth = node.depth + 1;
10521 return root.eachBefore(computeHeight);
10524 function node_copy() {
10525 return hierarchy(this).eachBefore(copyData);
10528 function defaultChildren(d) {
10532 function copyData(node) {
10533 node.data = node.data.data;
10536 function computeHeight(node) {
10538 do node.height = height;
10539 while ((node = node.parent) && (node.height < ++height));
10542 function Node(data) {
10546 this.parent = null;
10549 Node.prototype = hierarchy.prototype = {
10553 eachAfter: node_eachAfter,
10554 eachBefore: node_eachBefore,
10558 ancestors: node_ancestors,
10559 descendants: node_descendants,
10560 leaves: node_leaves,
10565 var slice$4 = Array.prototype.slice;
10567 function shuffle$1(array) {
10568 var m = array.length,
10573 i = Math.random() * m-- | 0;
10575 array[m] = array[i];
10582 function enclose(circles) {
10583 var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
10587 if (e && enclosesWeak(e, p)) ++i;
10588 else e = encloseBasis(B = extendBasis(B, p)), i = 0;
10594 function extendBasis(B, p) {
10597 if (enclosesWeakAll(p, B)) return [p];
10599 // If we get here then B must have at least one element.
10600 for (i = 0; i < B.length; ++i) {
10601 if (enclosesNot(p, B[i])
10602 && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
10607 // If we get here then B must have at least two elements.
10608 for (i = 0; i < B.length - 1; ++i) {
10609 for (j = i + 1; j < B.length; ++j) {
10610 if (enclosesNot(encloseBasis2(B[i], B[j]), p)
10611 && enclosesNot(encloseBasis2(B[i], p), B[j])
10612 && enclosesNot(encloseBasis2(B[j], p), B[i])
10613 && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
10614 return [B[i], B[j], p];
10619 // If we get here then something is very wrong.
10623 function enclosesNot(a, b) {
10624 var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
10625 return dr < 0 || dr * dr < dx * dx + dy * dy;
10628 function enclosesWeak(a, b) {
10629 var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
10630 return dr > 0 && dr * dr > dx * dx + dy * dy;
10633 function enclosesWeakAll(a, B) {
10634 for (var i = 0; i < B.length; ++i) {
10635 if (!enclosesWeak(a, B[i])) {
10642 function encloseBasis(B) {
10643 switch (B.length) {
10644 case 1: return encloseBasis1(B[0]);
10645 case 2: return encloseBasis2(B[0], B[1]);
10646 case 3: return encloseBasis3(B[0], B[1], B[2]);
10650 function encloseBasis1(a) {
10658 function encloseBasis2(a, b) {
10659 var x1 = a.x, y1 = a.y, r1 = a.r,
10660 x2 = b.x, y2 = b.y, r2 = b.r,
10661 x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
10662 l = Math.sqrt(x21 * x21 + y21 * y21);
10664 x: (x1 + x2 + x21 / l * r21) / 2,
10665 y: (y1 + y2 + y21 / l * r21) / 2,
10666 r: (l + r1 + r2) / 2
10670 function encloseBasis3(a, b, c) {
10671 var x1 = a.x, y1 = a.y, r1 = a.r,
10672 x2 = b.x, y2 = b.y, r2 = b.r,
10673 x3 = c.x, y3 = c.y, r3 = c.r,
10680 d1 = x1 * x1 + y1 * y1 - r1 * r1,
10681 d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
10682 d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
10683 ab = a3 * b2 - a2 * b3,
10684 xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
10685 xb = (b3 * c2 - b2 * c3) / ab,
10686 ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
10687 yb = (a2 * c3 - a3 * c2) / ab,
10688 A = xb * xb + yb * yb - 1,
10689 B = 2 * (r1 + xa * xb + ya * yb),
10690 C = xa * xa + ya * ya - r1 * r1,
10691 r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
10693 x: x1 + xa + xb * r,
10694 y: y1 + ya + yb * r,
10699 function place(b, a, c) {
10700 var dx = b.x - a.x, x, a2,
10701 dy = b.y - a.y, y, b2,
10702 d2 = dx * dx + dy * dy;
10704 a2 = a.r + c.r, a2 *= a2;
10705 b2 = b.r + c.r, b2 *= b2;
10707 x = (d2 + b2 - a2) / (2 * d2);
10708 y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
10709 c.x = b.x - x * dx - y * dy;
10710 c.y = b.y - x * dy + y * dx;
10712 x = (d2 + a2 - b2) / (2 * d2);
10713 y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
10714 c.x = a.x + x * dx - y * dy;
10715 c.y = a.y + x * dy + y * dx;
10723 function intersects(a, b) {
10724 var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
10725 return dr > 0 && dr * dr > dx * dx + dy * dy;
10728 function score(node) {
10732 dx = (a.x * b.r + b.x * a.r) / ab,
10733 dy = (a.y * b.r + b.y * a.r) / ab;
10734 return dx * dx + dy * dy;
10737 function Node$1(circle) {
10740 this.previous = null;
10743 function packEnclose(circles) {
10744 if (!(n = circles.length)) return 0;
10746 var a, b, c, n, aa, ca, i, j, k, sj, sk;
10748 // Place the first circle.
10749 a = circles[0], a.x = 0, a.y = 0;
10750 if (!(n > 1)) return a.r;
10752 // Place the second circle.
10753 b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
10754 if (!(n > 2)) return a.r + b.r;
10756 // Place the third circle.
10757 place(b, a, c = circles[2]);
10759 // Initialize the front-chain using the first three circles a, b and c.
10760 a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
10761 a.next = c.previous = b;
10762 b.next = a.previous = c;
10763 c.next = b.previous = a;
10765 // Attempt to place each remaining circle…
10766 pack: for (i = 3; i < n; ++i) {
10767 place(a._, b._, c = circles[i]), c = new Node$1(c);
10769 // Find the closest intersecting circle on the front-chain, if any.
10770 // “Closeness” is determined by linear distance along the front-chain.
10771 // “Ahead” or “behind” is likewise determined by linear distance.
10772 j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
10775 if (intersects(j._, c._)) {
10776 b = j, a.next = b, b.previous = a, --i;
10779 sj += j._.r, j = j.next;
10781 if (intersects(k._, c._)) {
10782 a = k, a.next = b, b.previous = a, --i;
10785 sk += k._.r, k = k.previous;
10787 } while (j !== k.next);
10789 // Success! Insert the new circle c between a and b.
10790 c.previous = a, c.next = b, a.next = b.previous = b = c;
10792 // Compute the new closest circle pair to the centroid.
10794 while ((c = c.next) !== b) {
10795 if ((ca = score(c)) < aa) {
10802 // Compute the enclosing circle of the front chain.
10803 a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
10805 // Translate the circles to put the enclosing circle around the origin.
10806 for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
10811 function siblings(circles) {
10812 packEnclose(circles);
10816 function optional(f) {
10817 return f == null ? null : required(f);
10820 function required(f) {
10821 if (typeof f !== "function") throw new Error;
10825 function constantZero() {
10829 function constant$9(x) {
10830 return function() {
10835 function defaultRadius$1(d) {
10836 return Math.sqrt(d.value);
10839 function index$2() {
10843 padding = constantZero;
10845 function pack(root) {
10846 root.x = dx / 2, root.y = dy / 2;
10848 root.eachBefore(radiusLeaf(radius))
10849 .eachAfter(packChildren(padding, 0.5))
10850 .eachBefore(translateChild(1));
10852 root.eachBefore(radiusLeaf(defaultRadius$1))
10853 .eachAfter(packChildren(constantZero, 1))
10854 .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
10855 .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
10860 pack.radius = function(x) {
10861 return arguments.length ? (radius = optional(x), pack) : radius;
10864 pack.size = function(x) {
10865 return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
10868 pack.padding = function(x) {
10869 return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
10875 function radiusLeaf(radius) {
10876 return function(node) {
10877 if (!node.children) {
10878 node.r = Math.max(0, +radius(node) || 0);
10883 function packChildren(padding, k) {
10884 return function(node) {
10885 if (children = node.children) {
10888 n = children.length,
10889 r = padding(node) * k || 0,
10892 if (r) for (i = 0; i < n; ++i) children[i].r += r;
10893 e = packEnclose(children);
10894 if (r) for (i = 0; i < n; ++i) children[i].r -= r;
10900 function translateChild(k) {
10901 return function(node) {
10902 var parent = node.parent;
10905 node.x = parent.x + k * node.x;
10906 node.y = parent.y + k * node.y;
10911 function roundNode(node) {
10912 node.x0 = Math.round(node.x0);
10913 node.y0 = Math.round(node.y0);
10914 node.x1 = Math.round(node.x1);
10915 node.y1 = Math.round(node.y1);
10918 function treemapDice(parent, x0, y0, x1, y1) {
10919 var nodes = parent.children,
10923 k = parent.value && (x1 - x0) / parent.value;
10926 node = nodes[i], node.y0 = y0, node.y1 = y1;
10927 node.x0 = x0, node.x1 = x0 += node.value * k;
10931 function partition() {
10937 function partition(root) {
10938 var n = root.height + 1;
10943 root.eachBefore(positionNode(dy, n));
10944 if (round) root.eachBefore(roundNode);
10948 function positionNode(dy, n) {
10949 return function(node) {
10950 if (node.children) {
10951 treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
10955 x1 = node.x1 - padding,
10956 y1 = node.y1 - padding;
10957 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
10958 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
10966 partition.round = function(x) {
10967 return arguments.length ? (round = !!x, partition) : round;
10970 partition.size = function(x) {
10971 return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
10974 partition.padding = function(x) {
10975 return arguments.length ? (padding = +x, partition) : padding;
10981 var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
10982 preroot = {depth: -1},
10985 function defaultId(d) {
10989 function defaultParentId(d) {
10993 function stratify() {
10994 var id = defaultId,
10995 parentId = defaultParentId;
10997 function stratify(data) {
11004 nodes = new Array(n),
11009 for (i = 0; i < n; ++i) {
11010 d = data[i], node = nodes[i] = new Node(d);
11011 if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
11012 nodeKey = keyPrefix$1 + (node.id = nodeId);
11013 nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
11017 for (i = 0; i < n; ++i) {
11018 node = nodes[i], nodeId = parentId(data[i], i, data);
11019 if (nodeId == null || !(nodeId += "")) {
11020 if (root) throw new Error("multiple roots");
11023 parent = nodeByKey[keyPrefix$1 + nodeId];
11024 if (!parent) throw new Error("missing: " + nodeId);
11025 if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
11026 if (parent.children) parent.children.push(node);
11027 else parent.children = [node];
11028 node.parent = parent;
11032 if (!root) throw new Error("no root");
11033 root.parent = preroot;
11034 root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
11035 root.parent = null;
11036 if (n > 0) throw new Error("cycle");
11041 stratify.id = function(x) {
11042 return arguments.length ? (id = required(x), stratify) : id;
11045 stratify.parentId = function(x) {
11046 return arguments.length ? (parentId = required(x), stratify) : parentId;
11052 function defaultSeparation$1(a, b) {
11053 return a.parent === b.parent ? 1 : 2;
11056 // function radialSeparation(a, b) {
11057 // return (a.parent === b.parent ? 1 : 2) / a.depth;
11060 // This function is used to traverse the left contour of a subtree (or
11061 // subforest). It returns the successor of v on this contour. This successor is
11062 // either given by the leftmost child of v or by the thread of v. The function
11063 // returns null if and only if v is on the highest level of its subtree.
11064 function nextLeft(v) {
11065 var children = v.children;
11066 return children ? children[0] : v.t;
11069 // This function works analogously to nextLeft.
11070 function nextRight(v) {
11071 var children = v.children;
11072 return children ? children[children.length - 1] : v.t;
11075 // Shifts the current subtree rooted at w+. This is done by increasing
11076 // prelim(w+) and mod(w+) by shift.
11077 function moveSubtree(wm, wp, shift) {
11078 var change = shift / (wp.i - wm.i);
11086 // All other shifts, applied to the smaller subtrees between w- and w+, are
11087 // performed by this function. To prepare the shifts, we have to adjust
11088 // change(w+), shift(w+), and change(w-).
11089 function executeShifts(v) {
11092 children = v.children,
11093 i = children.length,
11099 shift += w.s + (change += w.c);
11103 // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
11104 // returns the specified (default) ancestor.
11105 function nextAncestor(vim, v, ancestor) {
11106 return vim.a.parent === v.parent ? vim.a : ancestor;
11109 function TreeNode(node, i) {
11111 this.parent = null;
11112 this.children = null;
11113 this.A = null; // default ancestor
11114 this.a = this; // ancestor
11115 this.z = 0; // prelim
11117 this.c = 0; // change
11118 this.s = 0; // shift
11119 this.t = null; // thread
11120 this.i = i; // number
11123 TreeNode.prototype = Object.create(Node.prototype);
11125 function treeRoot(root) {
11126 var tree = new TreeNode(root, 0),
11134 while (node = nodes.pop()) {
11135 if (children = node._.children) {
11136 node.children = new Array(n = children.length);
11137 for (i = n - 1; i >= 0; --i) {
11138 nodes.push(child = node.children[i] = new TreeNode(children[i], i));
11139 child.parent = node;
11144 (tree.parent = new TreeNode(null, 0)).children = [tree];
11148 // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
11150 var separation = defaultSeparation$1,
11155 function tree(root) {
11156 var t = treeRoot(root);
11158 // Compute the layout using Buchheim et al.’s algorithm.
11159 t.eachAfter(firstWalk), t.parent.m = -t.z;
11160 t.eachBefore(secondWalk);
11162 // If a fixed node size is specified, scale x and y.
11163 if (nodeSize) root.eachBefore(sizeNode);
11165 // If a fixed tree size is specified, scale x and y based on the extent.
11166 // Compute the left-most, right-most, and depth-most nodes for extents.
11171 root.eachBefore(function(node) {
11172 if (node.x < left.x) left = node;
11173 if (node.x > right.x) right = node;
11174 if (node.depth > bottom.depth) bottom = node;
11176 var s = left === right ? 1 : separation(left, right) / 2,
11178 kx = dx / (right.x + s + tx),
11179 ky = dy / (bottom.depth || 1);
11180 root.eachBefore(function(node) {
11181 node.x = (node.x + tx) * kx;
11182 node.y = node.depth * ky;
11189 // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
11190 // applied recursively to the children of v, as well as the function
11191 // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
11192 // node v is placed to the midpoint of its outermost children.
11193 function firstWalk(v) {
11194 var children = v.children,
11195 siblings = v.parent.children,
11196 w = v.i ? siblings[v.i - 1] : null;
11199 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
11201 v.z = w.z + separation(v._, w._);
11202 v.m = v.z - midpoint;
11207 v.z = w.z + separation(v._, w._);
11209 v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
11212 // Computes all real x-coordinates by summing up the modifiers recursively.
11213 function secondWalk(v) {
11214 v._.x = v.z + v.parent.m;
11218 // The core of the algorithm. Here, a new subtree is combined with the
11219 // previous subtrees. Threads are used to traverse the inside and outside
11220 // contours of the left and right subtree up to the highest common level. The
11221 // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
11222 // superscript o means outside and i means inside, the subscript - means left
11223 // subtree and + means right subtree. For summing up the modifiers along the
11224 // contour, we use respective variables si+, si-, so-, and so+. Whenever two
11225 // nodes of the inside contours conflict, we compute the left one of the
11226 // greatest uncommon ancestors using the function ANCESTOR and call MOVE
11227 // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
11228 // Finally, we add a new thread (if necessary).
11229 function apportion(v, w, ancestor) {
11234 vom = vip.parent.children[0],
11240 while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
11241 vom = nextLeft(vom);
11242 vop = nextRight(vop);
11244 shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
11246 moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
11255 if (vim && !nextRight(vop)) {
11257 vop.m += sim - sop;
11259 if (vip && !nextLeft(vom)) {
11261 vom.m += sip - som;
11268 function sizeNode(node) {
11270 node.y = node.depth * dy;
11273 tree.separation = function(x) {
11274 return arguments.length ? (separation = x, tree) : separation;
11277 tree.size = function(x) {
11278 return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
11281 tree.nodeSize = function(x) {
11282 return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
11288 function treemapSlice(parent, x0, y0, x1, y1) {
11289 var nodes = parent.children,
11293 k = parent.value && (y1 - y0) / parent.value;
11296 node = nodes[i], node.x0 = x0, node.x1 = x1;
11297 node.y0 = y0, node.y1 = y0 += node.value * k;
11301 var phi = (1 + Math.sqrt(5)) / 2;
11303 function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
11305 nodes = parent.children,
11312 value = parent.value,
11322 dx = x1 - x0, dy = y1 - y0;
11324 // Find the next non-empty node.
11325 do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
11326 minValue = maxValue = sumValue;
11327 alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
11328 beta = sumValue * sumValue * alpha;
11329 minRatio = Math.max(maxValue / beta, beta / minValue);
11331 // Keep adding nodes while the aspect ratio maintains or improves.
11332 for (; i1 < n; ++i1) {
11333 sumValue += nodeValue = nodes[i1].value;
11334 if (nodeValue < minValue) minValue = nodeValue;
11335 if (nodeValue > maxValue) maxValue = nodeValue;
11336 beta = sumValue * sumValue * alpha;
11337 newRatio = Math.max(maxValue / beta, beta / minValue);
11338 if (newRatio > minRatio) { sumValue -= nodeValue; break; }
11339 minRatio = newRatio;
11342 // Position and record the row orientation.
11343 rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
11344 if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
11345 else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
11346 value -= sumValue, i0 = i1;
11352 var squarify = (function custom(ratio) {
11354 function squarify(parent, x0, y0, x1, y1) {
11355 squarifyRatio(ratio, parent, x0, y0, x1, y1);
11358 squarify.ratio = function(x) {
11359 return custom((x = +x) > 1 ? x : 1);
11365 function index$3() {
11366 var tile = squarify,
11370 paddingStack = [0],
11371 paddingInner = constantZero,
11372 paddingTop = constantZero,
11373 paddingRight = constantZero,
11374 paddingBottom = constantZero,
11375 paddingLeft = constantZero;
11377 function treemap(root) {
11382 root.eachBefore(positionNode);
11383 paddingStack = [0];
11384 if (round) root.eachBefore(roundNode);
11388 function positionNode(node) {
11389 var p = paddingStack[node.depth],
11394 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
11395 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
11400 if (node.children) {
11401 p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
11402 x0 += paddingLeft(node) - p;
11403 y0 += paddingTop(node) - p;
11404 x1 -= paddingRight(node) - p;
11405 y1 -= paddingBottom(node) - p;
11406 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
11407 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
11408 tile(node, x0, y0, x1, y1);
11412 treemap.round = function(x) {
11413 return arguments.length ? (round = !!x, treemap) : round;
11416 treemap.size = function(x) {
11417 return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
11420 treemap.tile = function(x) {
11421 return arguments.length ? (tile = required(x), treemap) : tile;
11424 treemap.padding = function(x) {
11425 return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
11428 treemap.paddingInner = function(x) {
11429 return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
11432 treemap.paddingOuter = function(x) {
11433 return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
11436 treemap.paddingTop = function(x) {
11437 return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
11440 treemap.paddingRight = function(x) {
11441 return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
11444 treemap.paddingBottom = function(x) {
11445 return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
11448 treemap.paddingLeft = function(x) {
11449 return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
11455 function binary(parent, x0, y0, x1, y1) {
11456 var nodes = parent.children,
11457 i, n = nodes.length,
11458 sum, sums = new Array(n + 1);
11460 for (sums[0] = sum = i = 0; i < n; ++i) {
11461 sums[i + 1] = sum += nodes[i].value;
11464 partition(0, n, parent.value, x0, y0, x1, y1);
11466 function partition(i, j, value, x0, y0, x1, y1) {
11468 var node = nodes[i];
11469 node.x0 = x0, node.y0 = y0;
11470 node.x1 = x1, node.y1 = y1;
11474 var valueOffset = sums[i],
11475 valueTarget = (value / 2) + valueOffset,
11480 var mid = k + hi >>> 1;
11481 if (sums[mid] < valueTarget) k = mid + 1;
11485 if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
11487 var valueLeft = sums[k] - valueOffset,
11488 valueRight = value - valueLeft;
11490 if ((x1 - x0) > (y1 - y0)) {
11491 var xk = (x0 * valueRight + x1 * valueLeft) / value;
11492 partition(i, k, valueLeft, x0, y0, xk, y1);
11493 partition(k, j, valueRight, xk, y0, x1, y1);
11495 var yk = (y0 * valueRight + y1 * valueLeft) / value;
11496 partition(i, k, valueLeft, x0, y0, x1, yk);
11497 partition(k, j, valueRight, x0, yk, x1, y1);
11502 function sliceDice(parent, x0, y0, x1, y1) {
11503 (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
11506 var resquarify = (function custom(ratio) {
11508 function resquarify(parent, x0, y0, x1, y1) {
11509 if ((rows = parent._squarify) && (rows.ratio === ratio)) {
11517 value = parent.value;
11520 row = rows[j], nodes = row.children;
11521 for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
11522 if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
11523 else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
11524 value -= row.value;
11527 parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
11528 rows.ratio = ratio;
11532 resquarify.ratio = function(x) {
11533 return custom((x = +x) > 1 ? x : 1);
11539 function area$2(polygon) {
11541 n = polygon.length,
11543 b = polygon[n - 1],
11549 area += a[1] * b[0] - a[0] * b[1];
11555 function centroid$1(polygon) {
11557 n = polygon.length,
11561 b = polygon[n - 1],
11568 k += c = a[0] * b[1] - b[0] * a[1];
11569 x += (a[0] + b[0]) * c;
11570 y += (a[1] + b[1]) * c;
11573 return k *= 3, [x / k, y / k];
11576 // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
11577 // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
11578 // right, +y is up). Returns a positive value if ABC is counter-clockwise,
11579 // negative if clockwise, and zero if the points are collinear.
11580 function cross$1(a, b, c) {
11581 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
11584 function lexicographicOrder(a, b) {
11585 return a[0] - b[0] || a[1] - b[1];
11588 // Computes the upper convex hull per the monotone chain algorithm.
11589 // Assumes points.length >= 3, is sorted by x, unique in y.
11590 // Returns an array of indices into points in left-to-right order.
11591 function computeUpperHullIndexes(points) {
11592 var n = points.length,
11596 for (var i = 2; i < n; ++i) {
11597 while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
11598 indexes[size++] = i;
11601 return indexes.slice(0, size); // remove popped points
11604 function hull(points) {
11605 if ((n = points.length) < 3) return null;
11609 sortedPoints = new Array(n),
11610 flippedPoints = new Array(n);
11612 for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
11613 sortedPoints.sort(lexicographicOrder);
11614 for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
11616 var upperIndexes = computeUpperHullIndexes(sortedPoints),
11617 lowerIndexes = computeUpperHullIndexes(flippedPoints);
11619 // Construct the hull polygon, removing possible duplicate endpoints.
11620 var skipLeft = lowerIndexes[0] === upperIndexes[0],
11621 skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
11624 // Add upper hull in right-to-l order.
11625 // Then add lower hull in left-to-right order.
11626 for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
11627 for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
11632 function contains$2(polygon, point) {
11633 var n = polygon.length,
11634 p = polygon[n - 1],
11635 x = point[0], y = point[1],
11636 x0 = p[0], y0 = p[1],
11640 for (var i = 0; i < n; ++i) {
11641 p = polygon[i], x1 = p[0], y1 = p[1];
11642 if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
11649 function length$2(polygon) {
11651 n = polygon.length,
11652 b = polygon[n - 1],
11667 perimeter += Math.sqrt(xa * xa + ya * ya);
11673 function defaultSource$1() {
11674 return Math.random();
11677 var uniform = (function sourceRandomUniform(source) {
11678 function randomUniform(min, max) {
11679 min = min == null ? 0 : +min;
11680 max = max == null ? 1 : +max;
11681 if (arguments.length === 1) max = min, min = 0;
11683 return function() {
11684 return source() * max + min;
11688 randomUniform.source = sourceRandomUniform;
11690 return randomUniform;
11691 })(defaultSource$1);
11693 var normal = (function sourceRandomNormal(source) {
11694 function randomNormal(mu, sigma) {
11696 mu = mu == null ? 0 : +mu;
11697 sigma = sigma == null ? 1 : +sigma;
11698 return function() {
11701 // If available, use the second previously-generated uniform random.
11702 if (x != null) y = x, x = null;
11704 // Otherwise, generate a new x and y.
11706 x = source() * 2 - 1;
11707 y = source() * 2 - 1;
11709 } while (!r || r > 1);
11711 return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
11715 randomNormal.source = sourceRandomNormal;
11717 return randomNormal;
11718 })(defaultSource$1);
11720 var logNormal = (function sourceRandomLogNormal(source) {
11721 function randomLogNormal() {
11722 var randomNormal = normal.source(source).apply(this, arguments);
11723 return function() {
11724 return Math.exp(randomNormal());
11728 randomLogNormal.source = sourceRandomLogNormal;
11730 return randomLogNormal;
11731 })(defaultSource$1);
11733 var irwinHall = (function sourceRandomIrwinHall(source) {
11734 function randomIrwinHall(n) {
11735 return function() {
11736 for (var sum = 0, i = 0; i < n; ++i) sum += source();
11741 randomIrwinHall.source = sourceRandomIrwinHall;
11743 return randomIrwinHall;
11744 })(defaultSource$1);
11746 var bates = (function sourceRandomBates(source) {
11747 function randomBates(n) {
11748 var randomIrwinHall = irwinHall.source(source)(n);
11749 return function() {
11750 return randomIrwinHall() / n;
11754 randomBates.source = sourceRandomBates;
11756 return randomBates;
11757 })(defaultSource$1);
11759 var exponential$1 = (function sourceRandomExponential(source) {
11760 function randomExponential(lambda) {
11761 return function() {
11762 return -Math.log(1 - source()) / lambda;
11766 randomExponential.source = sourceRandomExponential;
11768 return randomExponential;
11769 })(defaultSource$1);
11771 var array$3 = Array.prototype;
11773 var map$2 = array$3.map;
11774 var slice$5 = array$3.slice;
11776 var implicit = {name: "implicit"};
11778 function ordinal(range) {
11779 var index = map$1(),
11781 unknown = implicit;
11783 range = range == null ? [] : slice$5.call(range);
11785 function scale(d) {
11786 var key = d + "", i = index.get(key);
11788 if (unknown !== implicit) return unknown;
11789 index.set(key, i = domain.push(d));
11791 return range[(i - 1) % range.length];
11794 scale.domain = function(_) {
11795 if (!arguments.length) return domain.slice();
11796 domain = [], index = map$1();
11797 var i = -1, n = _.length, d, key;
11798 while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
11802 scale.range = function(_) {
11803 return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
11806 scale.unknown = function(_) {
11807 return arguments.length ? (unknown = _, scale) : unknown;
11810 scale.copy = function() {
11821 var scale = ordinal().unknown(undefined),
11822 domain = scale.domain,
11823 ordinalRange = scale.range,
11832 delete scale.unknown;
11834 function rescale() {
11835 var n = domain().length,
11836 reverse = range$$1[1] < range$$1[0],
11837 start = range$$1[reverse - 0],
11838 stop = range$$1[1 - reverse];
11839 step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
11840 if (round) step = Math.floor(step);
11841 start += (stop - start - step * (n - paddingInner)) * align;
11842 bandwidth = step * (1 - paddingInner);
11843 if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
11844 var values = sequence(n).map(function(i) { return start + step * i; });
11845 return ordinalRange(reverse ? values.reverse() : values);
11848 scale.domain = function(_) {
11849 return arguments.length ? (domain(_), rescale()) : domain();
11852 scale.range = function(_) {
11853 return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
11856 scale.rangeRound = function(_) {
11857 return range$$1 = [+_[0], +_[1]], round = true, rescale();
11860 scale.bandwidth = function() {
11864 scale.step = function() {
11868 scale.round = function(_) {
11869 return arguments.length ? (round = !!_, rescale()) : round;
11872 scale.padding = function(_) {
11873 return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
11876 scale.paddingInner = function(_) {
11877 return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
11880 scale.paddingOuter = function(_) {
11881 return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
11884 scale.align = function(_) {
11885 return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
11888 scale.copy = function() {
11893 .paddingInner(paddingInner)
11894 .paddingOuter(paddingOuter)
11901 function pointish(scale) {
11902 var copy = scale.copy;
11904 scale.padding = scale.paddingOuter;
11905 delete scale.paddingInner;
11906 delete scale.paddingOuter;
11908 scale.copy = function() {
11909 return pointish(copy());
11915 function point$1() {
11916 return pointish(band().paddingInner(1));
11919 function constant$10(x) {
11920 return function() {
11925 function number$2(x) {
11931 function deinterpolateLinear(a, b) {
11932 return (b -= (a = +a))
11933 ? function(x) { return (x - a) / b; }
11937 function deinterpolateClamp(deinterpolate) {
11938 return function(a, b) {
11939 var d = deinterpolate(a = +a, b = +b);
11940 return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
11944 function reinterpolateClamp(reinterpolate$$1) {
11945 return function(a, b) {
11946 var r = reinterpolate$$1(a = +a, b = +b);
11947 return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
11951 function bimap(domain, range, deinterpolate, reinterpolate$$1) {
11952 var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
11953 if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate$$1(r1, r0);
11954 else d0 = deinterpolate(d0, d1), r0 = reinterpolate$$1(r0, r1);
11955 return function(x) { return r0(d0(x)); };
11958 function polymap(domain, range, deinterpolate, reinterpolate$$1) {
11959 var j = Math.min(domain.length, range.length) - 1,
11964 // Reverse descending domains.
11965 if (domain[j] < domain[0]) {
11966 domain = domain.slice().reverse();
11967 range = range.slice().reverse();
11971 d[i] = deinterpolate(domain[i], domain[i + 1]);
11972 r[i] = reinterpolate$$1(range[i], range[i + 1]);
11975 return function(x) {
11976 var i = bisectRight(domain, x, 1, j) - 1;
11977 return r[i](d[i](x));
11981 function copy(source, target) {
11983 .domain(source.domain())
11984 .range(source.range())
11985 .interpolate(source.interpolate())
11986 .clamp(source.clamp());
11989 // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
11990 // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
11991 function continuous(deinterpolate, reinterpolate$$1) {
11994 interpolate$$1 = interpolateValue,
12000 function rescale() {
12001 piecewise$$1 = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
12002 output = input = null;
12006 function scale(x) {
12007 return (output || (output = piecewise$$1(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
12010 scale.invert = function(y) {
12011 return (input || (input = piecewise$$1(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate$$1) : reinterpolate$$1)))(+y);
12014 scale.domain = function(_) {
12015 return arguments.length ? (domain = map$2.call(_, number$2), rescale()) : domain.slice();
12018 scale.range = function(_) {
12019 return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
12022 scale.rangeRound = function(_) {
12023 return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
12026 scale.clamp = function(_) {
12027 return arguments.length ? (clamp = !!_, rescale()) : clamp;
12030 scale.interpolate = function(_) {
12031 return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
12037 function tickFormat(domain, count, specifier) {
12038 var start = domain[0],
12039 stop = domain[domain.length - 1],
12040 step = tickStep(start, stop, count == null ? 10 : count),
12042 specifier = formatSpecifier(specifier == null ? ",f" : specifier);
12043 switch (specifier.type) {
12045 var value = Math.max(Math.abs(start), Math.abs(stop));
12046 if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
12047 return exports.formatPrefix(specifier, value);
12054 if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
12059 if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
12063 return exports.format(specifier);
12066 function linearish(scale) {
12067 var domain = scale.domain;
12069 scale.ticks = function(count) {
12071 return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
12074 scale.tickFormat = function(count, specifier) {
12075 return tickFormat(domain(), count, specifier);
12078 scale.nice = function(count) {
12079 if (count == null) count = 10;
12088 if (stop < start) {
12089 step = start, start = stop, stop = step;
12090 step = i0, i0 = i1, i1 = step;
12093 step = tickIncrement(start, stop, count);
12096 start = Math.floor(start / step) * step;
12097 stop = Math.ceil(stop / step) * step;
12098 step = tickIncrement(start, stop, count);
12099 } else if (step < 0) {
12100 start = Math.ceil(start * step) / step;
12101 stop = Math.floor(stop * step) / step;
12102 step = tickIncrement(start, stop, count);
12106 d[i0] = Math.floor(start / step) * step;
12107 d[i1] = Math.ceil(stop / step) * step;
12109 } else if (step < 0) {
12110 d[i0] = Math.ceil(start * step) / step;
12111 d[i1] = Math.floor(stop * step) / step;
12121 function linear$2() {
12122 var scale = continuous(deinterpolateLinear, reinterpolate);
12124 scale.copy = function() {
12125 return copy(scale, linear$2());
12128 return linearish(scale);
12131 function identity$6() {
12132 var domain = [0, 1];
12134 function scale(x) {
12138 scale.invert = scale;
12140 scale.domain = scale.range = function(_) {
12141 return arguments.length ? (domain = map$2.call(_, number$2), scale) : domain.slice();
12144 scale.copy = function() {
12145 return identity$6().domain(domain);
12148 return linearish(scale);
12151 function nice(domain, interval) {
12152 domain = domain.slice();
12155 i1 = domain.length - 1,
12161 t = i0, i0 = i1, i1 = t;
12162 t = x0, x0 = x1, x1 = t;
12165 domain[i0] = interval.floor(x0);
12166 domain[i1] = interval.ceil(x1);
12170 function deinterpolate(a, b) {
12171 return (b = Math.log(b / a))
12172 ? function(x) { return Math.log(x / a) / b; }
12176 function reinterpolate$1(a, b) {
12178 ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
12179 : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
12182 function pow10(x) {
12183 return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
12186 function powp(base) {
12187 return base === 10 ? pow10
12188 : base === Math.E ? Math.exp
12189 : function(x) { return Math.pow(base, x); };
12192 function logp(base) {
12193 return base === Math.E ? Math.log
12194 : base === 10 && Math.log10
12195 || base === 2 && Math.log2
12196 || (base = Math.log(base), function(x) { return Math.log(x) / base; });
12199 function reflect(f) {
12200 return function(x) {
12206 var scale = continuous(deinterpolate, reinterpolate$1).domain([1, 10]),
12207 domain = scale.domain,
12212 function rescale() {
12213 logs = logp(base), pows = powp(base);
12214 if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
12218 scale.base = function(_) {
12219 return arguments.length ? (base = +_, rescale()) : base;
12222 scale.domain = function(_) {
12223 return arguments.length ? (domain(_), rescale()) : domain();
12226 scale.ticks = function(count) {
12229 v = d[d.length - 1],
12232 if (r = v < u) i = u, u = v, v = i;
12239 n = count == null ? 10 : +count,
12242 if (!(base % 1) && j - i < n) {
12243 i = Math.round(i) - 1, j = Math.round(j) + 1;
12244 if (u > 0) for (; i < j; ++i) {
12245 for (k = 1, p = pows(i); k < base; ++k) {
12247 if (t < u) continue;
12251 } else for (; i < j; ++i) {
12252 for (k = base - 1, p = pows(i); k >= 1; --k) {
12254 if (t < u) continue;
12260 z = ticks(i, j, Math.min(j - i, n)).map(pows);
12263 return r ? z.reverse() : z;
12266 scale.tickFormat = function(count, specifier) {
12267 if (specifier == null) specifier = base === 10 ? ".0e" : ",";
12268 if (typeof specifier !== "function") specifier = exports.format(specifier);
12269 if (count === Infinity) return specifier;
12270 if (count == null) count = 10;
12271 var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
12272 return function(d) {
12273 var i = d / pows(Math.round(logs(d)));
12274 if (i * base < base - 0.5) i *= base;
12275 return i <= k ? specifier(d) : "";
12279 scale.nice = function() {
12280 return domain(nice(domain(), {
12281 floor: function(x) { return pows(Math.floor(logs(x))); },
12282 ceil: function(x) { return pows(Math.ceil(logs(x))); }
12286 scale.copy = function() {
12287 return copy(scale, log$1().base(base));
12293 function raise$1(x, exponent) {
12294 return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
12299 scale = continuous(deinterpolate, reinterpolate),
12300 domain = scale.domain;
12302 function deinterpolate(a, b) {
12303 return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
12304 ? function(x) { return (raise$1(x, exponent) - a) / b; }
12308 function reinterpolate(a, b) {
12309 b = raise$1(b, exponent) - (a = raise$1(a, exponent));
12310 return function(t) { return raise$1(a + b * t, 1 / exponent); };
12313 scale.exponent = function(_) {
12314 return arguments.length ? (exponent = +_, domain(domain())) : exponent;
12317 scale.copy = function() {
12318 return copy(scale, pow$1().exponent(exponent));
12321 return linearish(scale);
12324 function sqrt$1() {
12325 return pow$1().exponent(0.5);
12328 function quantile$$1() {
12333 function rescale() {
12334 var i = 0, n = Math.max(1, range.length);
12335 thresholds = new Array(n - 1);
12336 while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
12340 function scale(x) {
12341 if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
12344 scale.invertExtent = function(y) {
12345 var i = range.indexOf(y);
12346 return i < 0 ? [NaN, NaN] : [
12347 i > 0 ? thresholds[i - 1] : domain[0],
12348 i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
12352 scale.domain = function(_) {
12353 if (!arguments.length) return domain.slice();
12355 for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
12356 domain.sort(ascending);
12360 scale.range = function(_) {
12361 return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
12364 scale.quantiles = function() {
12365 return thresholds.slice();
12368 scale.copy = function() {
12369 return quantile$$1()
12377 function quantize$1() {
12384 function scale(x) {
12385 if (x <= x) return range[bisectRight(domain, x, 0, n)];
12388 function rescale() {
12390 domain = new Array(n);
12391 while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
12395 scale.domain = function(_) {
12396 return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
12399 scale.range = function(_) {
12400 return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
12403 scale.invertExtent = function(y) {
12404 var i = range.indexOf(y);
12405 return i < 0 ? [NaN, NaN]
12406 : i < 1 ? [x0, domain[0]]
12407 : i >= n ? [domain[n - 1], x1]
12408 : [domain[i - 1], domain[i]];
12411 scale.copy = function() {
12412 return quantize$1()
12417 return linearish(scale);
12420 function threshold$1() {
12421 var domain = [0.5],
12425 function scale(x) {
12426 if (x <= x) return range[bisectRight(domain, x, 0, n)];
12429 scale.domain = function(_) {
12430 return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
12433 scale.range = function(_) {
12434 return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
12437 scale.invertExtent = function(y) {
12438 var i = range.indexOf(y);
12439 return [domain[i - 1], domain[i]];
12442 scale.copy = function() {
12443 return threshold$1()
12451 var t0$1 = new Date,
12454 function newInterval(floori, offseti, count, field) {
12456 function interval(date) {
12457 return floori(date = new Date(+date)), date;
12460 interval.floor = interval;
12462 interval.ceil = function(date) {
12463 return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
12466 interval.round = function(date) {
12467 var d0 = interval(date),
12468 d1 = interval.ceil(date);
12469 return date - d0 < d1 - date ? d0 : d1;
12472 interval.offset = function(date, step) {
12473 return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
12476 interval.range = function(start, stop, step) {
12477 var range = [], previous;
12478 start = interval.ceil(start);
12479 step = step == null ? 1 : Math.floor(step);
12480 if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
12481 do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
12482 while (previous < start && start < stop);
12486 interval.filter = function(test) {
12487 return newInterval(function(date) {
12488 if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
12489 }, function(date, step) {
12490 if (date >= date) {
12491 if (step < 0) while (++step <= 0) {
12492 while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
12493 } else while (--step >= 0) {
12494 while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
12501 interval.count = function(start, end) {
12502 t0$1.setTime(+start), t1$1.setTime(+end);
12503 floori(t0$1), floori(t1$1);
12504 return Math.floor(count(t0$1, t1$1));
12507 interval.every = function(step) {
12508 step = Math.floor(step);
12509 return !isFinite(step) || !(step > 0) ? null
12510 : !(step > 1) ? interval
12511 : interval.filter(field
12512 ? function(d) { return field(d) % step === 0; }
12513 : function(d) { return interval.count(0, d) % step === 0; });
12520 var millisecond = newInterval(function() {
12522 }, function(date, step) {
12523 date.setTime(+date + step);
12524 }, function(start, end) {
12525 return end - start;
12528 // An optimized implementation for this simple case.
12529 millisecond.every = function(k) {
12531 if (!isFinite(k) || !(k > 0)) return null;
12532 if (!(k > 1)) return millisecond;
12533 return newInterval(function(date) {
12534 date.setTime(Math.floor(date / k) * k);
12535 }, function(date, step) {
12536 date.setTime(+date + step * k);
12537 }, function(start, end) {
12538 return (end - start) / k;
12541 var milliseconds = millisecond.range;
12543 var durationSecond = 1e3;
12544 var durationMinute = 6e4;
12545 var durationHour = 36e5;
12546 var durationDay = 864e5;
12547 var durationWeek = 6048e5;
12549 var second = newInterval(function(date) {
12550 date.setTime(Math.floor(date / durationSecond) * durationSecond);
12551 }, function(date, step) {
12552 date.setTime(+date + step * durationSecond);
12553 }, function(start, end) {
12554 return (end - start) / durationSecond;
12555 }, function(date) {
12556 return date.getUTCSeconds();
12558 var seconds = second.range;
12560 var minute = newInterval(function(date) {
12561 date.setTime(Math.floor(date / durationMinute) * durationMinute);
12562 }, function(date, step) {
12563 date.setTime(+date + step * durationMinute);
12564 }, function(start, end) {
12565 return (end - start) / durationMinute;
12566 }, function(date) {
12567 return date.getMinutes();
12569 var minutes = minute.range;
12571 var hour = newInterval(function(date) {
12572 var offset = date.getTimezoneOffset() * durationMinute % durationHour;
12573 if (offset < 0) offset += durationHour;
12574 date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
12575 }, function(date, step) {
12576 date.setTime(+date + step * durationHour);
12577 }, function(start, end) {
12578 return (end - start) / durationHour;
12579 }, function(date) {
12580 return date.getHours();
12582 var hours = hour.range;
12584 var day = newInterval(function(date) {
12585 date.setHours(0, 0, 0, 0);
12586 }, function(date, step) {
12587 date.setDate(date.getDate() + step);
12588 }, function(start, end) {
12589 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
12590 }, function(date) {
12591 return date.getDate() - 1;
12593 var days = day.range;
12595 function weekday(i) {
12596 return newInterval(function(date) {
12597 date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
12598 date.setHours(0, 0, 0, 0);
12599 }, function(date, step) {
12600 date.setDate(date.getDate() + step * 7);
12601 }, function(start, end) {
12602 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
12606 var sunday = weekday(0);
12607 var monday = weekday(1);
12608 var tuesday = weekday(2);
12609 var wednesday = weekday(3);
12610 var thursday = weekday(4);
12611 var friday = weekday(5);
12612 var saturday = weekday(6);
12614 var sundays = sunday.range;
12615 var mondays = monday.range;
12616 var tuesdays = tuesday.range;
12617 var wednesdays = wednesday.range;
12618 var thursdays = thursday.range;
12619 var fridays = friday.range;
12620 var saturdays = saturday.range;
12622 var month = newInterval(function(date) {
12624 date.setHours(0, 0, 0, 0);
12625 }, function(date, step) {
12626 date.setMonth(date.getMonth() + step);
12627 }, function(start, end) {
12628 return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
12629 }, function(date) {
12630 return date.getMonth();
12632 var months = month.range;
12634 var year = newInterval(function(date) {
12635 date.setMonth(0, 1);
12636 date.setHours(0, 0, 0, 0);
12637 }, function(date, step) {
12638 date.setFullYear(date.getFullYear() + step);
12639 }, function(start, end) {
12640 return end.getFullYear() - start.getFullYear();
12641 }, function(date) {
12642 return date.getFullYear();
12645 // An optimized implementation for this simple case.
12646 year.every = function(k) {
12647 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
12648 date.setFullYear(Math.floor(date.getFullYear() / k) * k);
12649 date.setMonth(0, 1);
12650 date.setHours(0, 0, 0, 0);
12651 }, function(date, step) {
12652 date.setFullYear(date.getFullYear() + step * k);
12655 var years = year.range;
12657 var utcMinute = newInterval(function(date) {
12658 date.setUTCSeconds(0, 0);
12659 }, function(date, step) {
12660 date.setTime(+date + step * durationMinute);
12661 }, function(start, end) {
12662 return (end - start) / durationMinute;
12663 }, function(date) {
12664 return date.getUTCMinutes();
12666 var utcMinutes = utcMinute.range;
12668 var utcHour = newInterval(function(date) {
12669 date.setUTCMinutes(0, 0, 0);
12670 }, function(date, step) {
12671 date.setTime(+date + step * durationHour);
12672 }, function(start, end) {
12673 return (end - start) / durationHour;
12674 }, function(date) {
12675 return date.getUTCHours();
12677 var utcHours = utcHour.range;
12679 var utcDay = newInterval(function(date) {
12680 date.setUTCHours(0, 0, 0, 0);
12681 }, function(date, step) {
12682 date.setUTCDate(date.getUTCDate() + step);
12683 }, function(start, end) {
12684 return (end - start) / durationDay;
12685 }, function(date) {
12686 return date.getUTCDate() - 1;
12688 var utcDays = utcDay.range;
12690 function utcWeekday(i) {
12691 return newInterval(function(date) {
12692 date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
12693 date.setUTCHours(0, 0, 0, 0);
12694 }, function(date, step) {
12695 date.setUTCDate(date.getUTCDate() + step * 7);
12696 }, function(start, end) {
12697 return (end - start) / durationWeek;
12701 var utcSunday = utcWeekday(0);
12702 var utcMonday = utcWeekday(1);
12703 var utcTuesday = utcWeekday(2);
12704 var utcWednesday = utcWeekday(3);
12705 var utcThursday = utcWeekday(4);
12706 var utcFriday = utcWeekday(5);
12707 var utcSaturday = utcWeekday(6);
12709 var utcSundays = utcSunday.range;
12710 var utcMondays = utcMonday.range;
12711 var utcTuesdays = utcTuesday.range;
12712 var utcWednesdays = utcWednesday.range;
12713 var utcThursdays = utcThursday.range;
12714 var utcFridays = utcFriday.range;
12715 var utcSaturdays = utcSaturday.range;
12717 var utcMonth = newInterval(function(date) {
12718 date.setUTCDate(1);
12719 date.setUTCHours(0, 0, 0, 0);
12720 }, function(date, step) {
12721 date.setUTCMonth(date.getUTCMonth() + step);
12722 }, function(start, end) {
12723 return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
12724 }, function(date) {
12725 return date.getUTCMonth();
12727 var utcMonths = utcMonth.range;
12729 var utcYear = newInterval(function(date) {
12730 date.setUTCMonth(0, 1);
12731 date.setUTCHours(0, 0, 0, 0);
12732 }, function(date, step) {
12733 date.setUTCFullYear(date.getUTCFullYear() + step);
12734 }, function(start, end) {
12735 return end.getUTCFullYear() - start.getUTCFullYear();
12736 }, function(date) {
12737 return date.getUTCFullYear();
12740 // An optimized implementation for this simple case.
12741 utcYear.every = function(k) {
12742 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
12743 date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
12744 date.setUTCMonth(0, 1);
12745 date.setUTCHours(0, 0, 0, 0);
12746 }, function(date, step) {
12747 date.setUTCFullYear(date.getUTCFullYear() + step * k);
12750 var utcYears = utcYear.range;
12752 function localDate(d) {
12753 if (0 <= d.y && d.y < 100) {
12754 var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
12755 date.setFullYear(d.y);
12758 return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
12761 function utcDate(d) {
12762 if (0 <= d.y && d.y < 100) {
12763 var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
12764 date.setUTCFullYear(d.y);
12767 return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
12770 function newYear(y) {
12771 return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
12774 function formatLocale$1(locale) {
12775 var locale_dateTime = locale.dateTime,
12776 locale_date = locale.date,
12777 locale_time = locale.time,
12778 locale_periods = locale.periods,
12779 locale_weekdays = locale.days,
12780 locale_shortWeekdays = locale.shortDays,
12781 locale_months = locale.months,
12782 locale_shortMonths = locale.shortMonths;
12784 var periodRe = formatRe(locale_periods),
12785 periodLookup = formatLookup(locale_periods),
12786 weekdayRe = formatRe(locale_weekdays),
12787 weekdayLookup = formatLookup(locale_weekdays),
12788 shortWeekdayRe = formatRe(locale_shortWeekdays),
12789 shortWeekdayLookup = formatLookup(locale_shortWeekdays),
12790 monthRe = formatRe(locale_months),
12791 monthLookup = formatLookup(locale_months),
12792 shortMonthRe = formatRe(locale_shortMonths),
12793 shortMonthLookup = formatLookup(locale_shortMonths);
12796 "a": formatShortWeekday,
12797 "A": formatWeekday,
12798 "b": formatShortMonth,
12801 "d": formatDayOfMonth,
12802 "e": formatDayOfMonth,
12803 "f": formatMicroseconds,
12806 "j": formatDayOfYear,
12807 "L": formatMilliseconds,
12808 "m": formatMonthNumber,
12809 "M": formatMinutes,
12811 "Q": formatUnixTimestamp,
12812 "s": formatUnixTimestampSeconds,
12813 "S": formatSeconds,
12814 "u": formatWeekdayNumberMonday,
12815 "U": formatWeekNumberSunday,
12816 "V": formatWeekNumberISO,
12817 "w": formatWeekdayNumberSunday,
12818 "W": formatWeekNumberMonday,
12822 "Y": formatFullYear,
12824 "%": formatLiteralPercent
12828 "a": formatUTCShortWeekday,
12829 "A": formatUTCWeekday,
12830 "b": formatUTCShortMonth,
12831 "B": formatUTCMonth,
12833 "d": formatUTCDayOfMonth,
12834 "e": formatUTCDayOfMonth,
12835 "f": formatUTCMicroseconds,
12836 "H": formatUTCHour24,
12837 "I": formatUTCHour12,
12838 "j": formatUTCDayOfYear,
12839 "L": formatUTCMilliseconds,
12840 "m": formatUTCMonthNumber,
12841 "M": formatUTCMinutes,
12842 "p": formatUTCPeriod,
12843 "Q": formatUnixTimestamp,
12844 "s": formatUnixTimestampSeconds,
12845 "S": formatUTCSeconds,
12846 "u": formatUTCWeekdayNumberMonday,
12847 "U": formatUTCWeekNumberSunday,
12848 "V": formatUTCWeekNumberISO,
12849 "w": formatUTCWeekdayNumberSunday,
12850 "W": formatUTCWeekNumberMonday,
12853 "y": formatUTCYear,
12854 "Y": formatUTCFullYear,
12855 "Z": formatUTCZone,
12856 "%": formatLiteralPercent
12860 "a": parseShortWeekday,
12862 "b": parseShortMonth,
12864 "c": parseLocaleDateTime,
12865 "d": parseDayOfMonth,
12866 "e": parseDayOfMonth,
12867 "f": parseMicroseconds,
12870 "j": parseDayOfYear,
12871 "L": parseMilliseconds,
12872 "m": parseMonthNumber,
12875 "Q": parseUnixTimestamp,
12876 "s": parseUnixTimestampSeconds,
12878 "u": parseWeekdayNumberMonday,
12879 "U": parseWeekNumberSunday,
12880 "V": parseWeekNumberISO,
12881 "w": parseWeekdayNumberSunday,
12882 "W": parseWeekNumberMonday,
12883 "x": parseLocaleDate,
12884 "X": parseLocaleTime,
12886 "Y": parseFullYear,
12888 "%": parseLiteralPercent
12891 // These recursive directive definitions must be deferred.
12892 formats.x = newFormat(locale_date, formats);
12893 formats.X = newFormat(locale_time, formats);
12894 formats.c = newFormat(locale_dateTime, formats);
12895 utcFormats.x = newFormat(locale_date, utcFormats);
12896 utcFormats.X = newFormat(locale_time, utcFormats);
12897 utcFormats.c = newFormat(locale_dateTime, utcFormats);
12899 function newFormat(specifier, formats) {
12900 return function(date) {
12904 n = specifier.length,
12909 if (!(date instanceof Date)) date = new Date(+date);
12912 if (specifier.charCodeAt(i) === 37) {
12913 string.push(specifier.slice(j, i));
12914 if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
12915 else pad = c === "e" ? " " : "0";
12916 if (format = formats[c]) c = format(date, pad);
12922 string.push(specifier.slice(j, i));
12923 return string.join("");
12927 function newParse(specifier, newDate) {
12928 return function(string) {
12929 var d = newYear(1900),
12930 i = parseSpecifier(d, specifier, string += "", 0),
12932 if (i != string.length) return null;
12934 // If a UNIX timestamp is specified, return it.
12935 if ("Q" in d) return new Date(d.Q);
12937 // The am-pm flag is 0 for AM, and 1 for PM.
12938 if ("p" in d) d.H = d.H % 12 + d.p * 12;
12940 // Convert day-of-week and week-of-year to day-of-year.
12942 if (d.V < 1 || d.V > 53) return null;
12943 if (!("w" in d)) d.w = 1;
12945 week = utcDate(newYear(d.y)), day$$1 = week.getUTCDay();
12946 week = day$$1 > 4 || day$$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
12947 week = utcDay.offset(week, (d.V - 1) * 7);
12948 d.y = week.getUTCFullYear();
12949 d.m = week.getUTCMonth();
12950 d.d = week.getUTCDate() + (d.w + 6) % 7;
12952 week = newDate(newYear(d.y)), day$$1 = week.getDay();
12953 week = day$$1 > 4 || day$$1 === 0 ? monday.ceil(week) : monday(week);
12954 week = day.offset(week, (d.V - 1) * 7);
12955 d.y = week.getFullYear();
12956 d.m = week.getMonth();
12957 d.d = week.getDate() + (d.w + 6) % 7;
12959 } else if ("W" in d || "U" in d) {
12960 if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
12961 day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
12963 d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day$$1 + 5) % 7 : d.w + d.U * 7 - (day$$1 + 6) % 7;
12966 // If a time zone is specified, all fields are interpreted as UTC and then
12967 // offset according to the specified time zone.
12969 d.H += d.Z / 100 | 0;
12974 // Otherwise, all fields are in local time.
12979 function parseSpecifier(d, specifier, string, j) {
12981 n = specifier.length,
12987 if (j >= m) return -1;
12988 c = specifier.charCodeAt(i++);
12990 c = specifier.charAt(i++);
12991 parse = parses[c in pads ? specifier.charAt(i++) : c];
12992 if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
12993 } else if (c != string.charCodeAt(j++)) {
13001 function parsePeriod(d, string, i) {
13002 var n = periodRe.exec(string.slice(i));
13003 return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13006 function parseShortWeekday(d, string, i) {
13007 var n = shortWeekdayRe.exec(string.slice(i));
13008 return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13011 function parseWeekday(d, string, i) {
13012 var n = weekdayRe.exec(string.slice(i));
13013 return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13016 function parseShortMonth(d, string, i) {
13017 var n = shortMonthRe.exec(string.slice(i));
13018 return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13021 function parseMonth(d, string, i) {
13022 var n = monthRe.exec(string.slice(i));
13023 return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13026 function parseLocaleDateTime(d, string, i) {
13027 return parseSpecifier(d, locale_dateTime, string, i);
13030 function parseLocaleDate(d, string, i) {
13031 return parseSpecifier(d, locale_date, string, i);
13034 function parseLocaleTime(d, string, i) {
13035 return parseSpecifier(d, locale_time, string, i);
13038 function formatShortWeekday(d) {
13039 return locale_shortWeekdays[d.getDay()];
13042 function formatWeekday(d) {
13043 return locale_weekdays[d.getDay()];
13046 function formatShortMonth(d) {
13047 return locale_shortMonths[d.getMonth()];
13050 function formatMonth(d) {
13051 return locale_months[d.getMonth()];
13054 function formatPeriod(d) {
13055 return locale_periods[+(d.getHours() >= 12)];
13058 function formatUTCShortWeekday(d) {
13059 return locale_shortWeekdays[d.getUTCDay()];
13062 function formatUTCWeekday(d) {
13063 return locale_weekdays[d.getUTCDay()];
13066 function formatUTCShortMonth(d) {
13067 return locale_shortMonths[d.getUTCMonth()];
13070 function formatUTCMonth(d) {
13071 return locale_months[d.getUTCMonth()];
13074 function formatUTCPeriod(d) {
13075 return locale_periods[+(d.getUTCHours() >= 12)];
13079 format: function(specifier) {
13080 var f = newFormat(specifier += "", formats);
13081 f.toString = function() { return specifier; };
13084 parse: function(specifier) {
13085 var p = newParse(specifier += "", localDate);
13086 p.toString = function() { return specifier; };
13089 utcFormat: function(specifier) {
13090 var f = newFormat(specifier += "", utcFormats);
13091 f.toString = function() { return specifier; };
13094 utcParse: function(specifier) {
13095 var p = newParse(specifier, utcDate);
13096 p.toString = function() { return specifier; };
13102 var pads = {"-": "", "_": " ", "0": "0"},
13103 numberRe = /^\s*\d+/, // note: ignores next directive
13105 requoteRe = /[\\^$*+?|[\]().{}]/g;
13107 function pad(value, fill, width) {
13108 var sign = value < 0 ? "-" : "",
13109 string = (sign ? -value : value) + "",
13110 length = string.length;
13111 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
13114 function requote(s) {
13115 return s.replace(requoteRe, "\\$&");
13118 function formatRe(names) {
13119 return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
13122 function formatLookup(names) {
13123 var map = {}, i = -1, n = names.length;
13124 while (++i < n) map[names[i].toLowerCase()] = i;
13128 function parseWeekdayNumberSunday(d, string, i) {
13129 var n = numberRe.exec(string.slice(i, i + 1));
13130 return n ? (d.w = +n[0], i + n[0].length) : -1;
13133 function parseWeekdayNumberMonday(d, string, i) {
13134 var n = numberRe.exec(string.slice(i, i + 1));
13135 return n ? (d.u = +n[0], i + n[0].length) : -1;
13138 function parseWeekNumberSunday(d, string, i) {
13139 var n = numberRe.exec(string.slice(i, i + 2));
13140 return n ? (d.U = +n[0], i + n[0].length) : -1;
13143 function parseWeekNumberISO(d, string, i) {
13144 var n = numberRe.exec(string.slice(i, i + 2));
13145 return n ? (d.V = +n[0], i + n[0].length) : -1;
13148 function parseWeekNumberMonday(d, string, i) {
13149 var n = numberRe.exec(string.slice(i, i + 2));
13150 return n ? (d.W = +n[0], i + n[0].length) : -1;
13153 function parseFullYear(d, string, i) {
13154 var n = numberRe.exec(string.slice(i, i + 4));
13155 return n ? (d.y = +n[0], i + n[0].length) : -1;
13158 function parseYear(d, string, i) {
13159 var n = numberRe.exec(string.slice(i, i + 2));
13160 return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
13163 function parseZone(d, string, i) {
13164 var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
13165 return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
13168 function parseMonthNumber(d, string, i) {
13169 var n = numberRe.exec(string.slice(i, i + 2));
13170 return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
13173 function parseDayOfMonth(d, string, i) {
13174 var n = numberRe.exec(string.slice(i, i + 2));
13175 return n ? (d.d = +n[0], i + n[0].length) : -1;
13178 function parseDayOfYear(d, string, i) {
13179 var n = numberRe.exec(string.slice(i, i + 3));
13180 return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
13183 function parseHour24(d, string, i) {
13184 var n = numberRe.exec(string.slice(i, i + 2));
13185 return n ? (d.H = +n[0], i + n[0].length) : -1;
13188 function parseMinutes(d, string, i) {
13189 var n = numberRe.exec(string.slice(i, i + 2));
13190 return n ? (d.M = +n[0], i + n[0].length) : -1;
13193 function parseSeconds(d, string, i) {
13194 var n = numberRe.exec(string.slice(i, i + 2));
13195 return n ? (d.S = +n[0], i + n[0].length) : -1;
13198 function parseMilliseconds(d, string, i) {
13199 var n = numberRe.exec(string.slice(i, i + 3));
13200 return n ? (d.L = +n[0], i + n[0].length) : -1;
13203 function parseMicroseconds(d, string, i) {
13204 var n = numberRe.exec(string.slice(i, i + 6));
13205 return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
13208 function parseLiteralPercent(d, string, i) {
13209 var n = percentRe.exec(string.slice(i, i + 1));
13210 return n ? i + n[0].length : -1;
13213 function parseUnixTimestamp(d, string, i) {
13214 var n = numberRe.exec(string.slice(i));
13215 return n ? (d.Q = +n[0], i + n[0].length) : -1;
13218 function parseUnixTimestampSeconds(d, string, i) {
13219 var n = numberRe.exec(string.slice(i));
13220 return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
13223 function formatDayOfMonth(d, p) {
13224 return pad(d.getDate(), p, 2);
13227 function formatHour24(d, p) {
13228 return pad(d.getHours(), p, 2);
13231 function formatHour12(d, p) {
13232 return pad(d.getHours() % 12 || 12, p, 2);
13235 function formatDayOfYear(d, p) {
13236 return pad(1 + day.count(year(d), d), p, 3);
13239 function formatMilliseconds(d, p) {
13240 return pad(d.getMilliseconds(), p, 3);
13243 function formatMicroseconds(d, p) {
13244 return formatMilliseconds(d, p) + "000";
13247 function formatMonthNumber(d, p) {
13248 return pad(d.getMonth() + 1, p, 2);
13251 function formatMinutes(d, p) {
13252 return pad(d.getMinutes(), p, 2);
13255 function formatSeconds(d, p) {
13256 return pad(d.getSeconds(), p, 2);
13259 function formatWeekdayNumberMonday(d) {
13260 var day$$1 = d.getDay();
13261 return day$$1 === 0 ? 7 : day$$1;
13264 function formatWeekNumberSunday(d, p) {
13265 return pad(sunday.count(year(d), d), p, 2);
13268 function formatWeekNumberISO(d, p) {
13269 var day$$1 = d.getDay();
13270 d = (day$$1 >= 4 || day$$1 === 0) ? thursday(d) : thursday.ceil(d);
13271 return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
13274 function formatWeekdayNumberSunday(d) {
13278 function formatWeekNumberMonday(d, p) {
13279 return pad(monday.count(year(d), d), p, 2);
13282 function formatYear(d, p) {
13283 return pad(d.getFullYear() % 100, p, 2);
13286 function formatFullYear(d, p) {
13287 return pad(d.getFullYear() % 10000, p, 4);
13290 function formatZone(d) {
13291 var z = d.getTimezoneOffset();
13292 return (z > 0 ? "-" : (z *= -1, "+"))
13293 + pad(z / 60 | 0, "0", 2)
13294 + pad(z % 60, "0", 2);
13297 function formatUTCDayOfMonth(d, p) {
13298 return pad(d.getUTCDate(), p, 2);
13301 function formatUTCHour24(d, p) {
13302 return pad(d.getUTCHours(), p, 2);
13305 function formatUTCHour12(d, p) {
13306 return pad(d.getUTCHours() % 12 || 12, p, 2);
13309 function formatUTCDayOfYear(d, p) {
13310 return pad(1 + utcDay.count(utcYear(d), d), p, 3);
13313 function formatUTCMilliseconds(d, p) {
13314 return pad(d.getUTCMilliseconds(), p, 3);
13317 function formatUTCMicroseconds(d, p) {
13318 return formatUTCMilliseconds(d, p) + "000";
13321 function formatUTCMonthNumber(d, p) {
13322 return pad(d.getUTCMonth() + 1, p, 2);
13325 function formatUTCMinutes(d, p) {
13326 return pad(d.getUTCMinutes(), p, 2);
13329 function formatUTCSeconds(d, p) {
13330 return pad(d.getUTCSeconds(), p, 2);
13333 function formatUTCWeekdayNumberMonday(d) {
13334 var dow = d.getUTCDay();
13335 return dow === 0 ? 7 : dow;
13338 function formatUTCWeekNumberSunday(d, p) {
13339 return pad(utcSunday.count(utcYear(d), d), p, 2);
13342 function formatUTCWeekNumberISO(d, p) {
13343 var day$$1 = d.getUTCDay();
13344 d = (day$$1 >= 4 || day$$1 === 0) ? utcThursday(d) : utcThursday.ceil(d);
13345 return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
13348 function formatUTCWeekdayNumberSunday(d) {
13349 return d.getUTCDay();
13352 function formatUTCWeekNumberMonday(d, p) {
13353 return pad(utcMonday.count(utcYear(d), d), p, 2);
13356 function formatUTCYear(d, p) {
13357 return pad(d.getUTCFullYear() % 100, p, 2);
13360 function formatUTCFullYear(d, p) {
13361 return pad(d.getUTCFullYear() % 10000, p, 4);
13364 function formatUTCZone() {
13368 function formatLiteralPercent() {
13372 function formatUnixTimestamp(d) {
13376 function formatUnixTimestampSeconds(d) {
13377 return Math.floor(+d / 1000);
13383 dateTime: "%x, %X",
13384 date: "%-m/%-d/%Y",
13385 time: "%-I:%M:%S %p",
13386 periods: ["AM", "PM"],
13387 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
13388 shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
13389 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
13390 shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
13393 function defaultLocale$1(definition) {
13394 locale$1 = formatLocale$1(definition);
13395 exports.timeFormat = locale$1.format;
13396 exports.timeParse = locale$1.parse;
13397 exports.utcFormat = locale$1.utcFormat;
13398 exports.utcParse = locale$1.utcParse;
13402 var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
13404 function formatIsoNative(date) {
13405 return date.toISOString();
13408 var formatIso = Date.prototype.toISOString
13410 : exports.utcFormat(isoSpecifier);
13412 function parseIsoNative(string) {
13413 var date = new Date(string);
13414 return isNaN(date) ? null : date;
13417 var parseIso = +new Date("2000-01-01T00:00:00.000Z")
13419 : exports.utcParse(isoSpecifier);
13421 var durationSecond$1 = 1000,
13422 durationMinute$1 = durationSecond$1 * 60,
13423 durationHour$1 = durationMinute$1 * 60,
13424 durationDay$1 = durationHour$1 * 24,
13425 durationWeek$1 = durationDay$1 * 7,
13426 durationMonth = durationDay$1 * 30,
13427 durationYear = durationDay$1 * 365;
13429 function date$1(t) {
13430 return new Date(t);
13433 function number$3(t) {
13434 return t instanceof Date ? +t : +new Date(+t);
13437 function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
13438 var scale = continuous(deinterpolateLinear, reinterpolate),
13439 invert = scale.invert,
13440 domain = scale.domain;
13442 var formatMillisecond = format(".%L"),
13443 formatSecond = format(":%S"),
13444 formatMinute = format("%I:%M"),
13445 formatHour = format("%I %p"),
13446 formatDay = format("%a %d"),
13447 formatWeek = format("%b %d"),
13448 formatMonth = format("%B"),
13449 formatYear = format("%Y");
13451 var tickIntervals = [
13452 [second$$1, 1, durationSecond$1],
13453 [second$$1, 5, 5 * durationSecond$1],
13454 [second$$1, 15, 15 * durationSecond$1],
13455 [second$$1, 30, 30 * durationSecond$1],
13456 [minute$$1, 1, durationMinute$1],
13457 [minute$$1, 5, 5 * durationMinute$1],
13458 [minute$$1, 15, 15 * durationMinute$1],
13459 [minute$$1, 30, 30 * durationMinute$1],
13460 [ hour$$1, 1, durationHour$1 ],
13461 [ hour$$1, 3, 3 * durationHour$1 ],
13462 [ hour$$1, 6, 6 * durationHour$1 ],
13463 [ hour$$1, 12, 12 * durationHour$1 ],
13464 [ day$$1, 1, durationDay$1 ],
13465 [ day$$1, 2, 2 * durationDay$1 ],
13466 [ week, 1, durationWeek$1 ],
13467 [ month$$1, 1, durationMonth ],
13468 [ month$$1, 3, 3 * durationMonth ],
13469 [ year$$1, 1, durationYear ]
13472 function tickFormat(date$$1) {
13473 return (second$$1(date$$1) < date$$1 ? formatMillisecond
13474 : minute$$1(date$$1) < date$$1 ? formatSecond
13475 : hour$$1(date$$1) < date$$1 ? formatMinute
13476 : day$$1(date$$1) < date$$1 ? formatHour
13477 : month$$1(date$$1) < date$$1 ? (week(date$$1) < date$$1 ? formatDay : formatWeek)
13478 : year$$1(date$$1) < date$$1 ? formatMonth
13479 : formatYear)(date$$1);
13482 function tickInterval(interval, start, stop, step) {
13483 if (interval == null) interval = 10;
13485 // If a desired tick count is specified, pick a reasonable tick interval
13486 // based on the extent of the domain and a rough estimate of tick size.
13487 // Otherwise, assume interval is already a time interval and use it.
13488 if (typeof interval === "number") {
13489 var target = Math.abs(stop - start) / interval,
13490 i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
13491 if (i === tickIntervals.length) {
13492 step = tickStep(start / durationYear, stop / durationYear, interval);
13493 interval = year$$1;
13495 i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
13499 step = Math.max(tickStep(start, stop, interval), 1);
13500 interval = millisecond$$1;
13504 return step == null ? interval : interval.every(step);
13507 scale.invert = function(y) {
13508 return new Date(invert(y));
13511 scale.domain = function(_) {
13512 return arguments.length ? domain(map$2.call(_, number$3)) : domain().map(date$1);
13515 scale.ticks = function(interval, step) {
13518 t1 = d[d.length - 1],
13521 if (r) t = t0, t0 = t1, t1 = t;
13522 t = tickInterval(interval, t0, t1, step);
13523 t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
13524 return r ? t.reverse() : t;
13527 scale.tickFormat = function(count, specifier) {
13528 return specifier == null ? tickFormat : format(specifier);
13531 scale.nice = function(interval, step) {
13533 return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
13534 ? domain(nice(d, interval))
13538 scale.copy = function() {
13539 return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
13546 return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
13549 function utcTime() {
13550 return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
13553 function sequential(interpolator) {
13559 function scale(x) {
13560 var t = (x - x0) * k10;
13561 return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
13564 scale.domain = function(_) {
13565 return arguments.length ? (x0 = +_[0], x1 = +_[1], k10 = x0 === x1 ? 0 : 1 / (x1 - x0), scale) : [x0, x1];
13568 scale.clamp = function(_) {
13569 return arguments.length ? (clamp = !!_, scale) : clamp;
13572 scale.interpolator = function(_) {
13573 return arguments.length ? (interpolator = _, scale) : interpolator;
13576 scale.copy = function() {
13577 return sequential(interpolator).domain([x0, x1]).clamp(clamp);
13580 return linearish(scale);
13583 function diverging(interpolator) {
13591 function scale(x) {
13592 var t = 0.5 + ((x = +x) - x1) * (x < x1 ? k10 : k21);
13593 return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
13596 scale.domain = function(_) {
13597 return arguments.length ? (x0 = +_[0], x1 = +_[1], x2 = +_[2], k10 = x0 === x1 ? 0 : 0.5 / (x1 - x0), k21 = x1 === x2 ? 0 : 0.5 / (x2 - x1), scale) : [x0, x1, x2];
13600 scale.clamp = function(_) {
13601 return arguments.length ? (clamp = !!_, scale) : clamp;
13604 scale.interpolator = function(_) {
13605 return arguments.length ? (interpolator = _, scale) : interpolator;
13608 scale.copy = function() {
13609 return diverging(interpolator).domain([x0, x1, x2]).clamp(clamp);
13612 return linearish(scale);
13615 function colors(specifier) {
13616 var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
13617 while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
13621 var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
13623 var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
13625 var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
13627 var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
13629 var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
13631 var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
13633 var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
13635 var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
13637 var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
13639 function ramp(scheme) {
13640 return rgbBasis(scheme[scheme.length - 1]);
13643 var scheme = new Array(3).concat(
13644 "d8b365f5f5f55ab4ac",
13645 "a6611adfc27d80cdc1018571",
13646 "a6611adfc27df5f5f580cdc1018571",
13647 "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
13648 "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
13649 "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
13650 "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
13651 "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
13652 "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
13655 var BrBG = ramp(scheme);
13657 var scheme$1 = new Array(3).concat(
13658 "af8dc3f7f7f77fbf7b",
13659 "7b3294c2a5cfa6dba0008837",
13660 "7b3294c2a5cff7f7f7a6dba0008837",
13661 "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
13662 "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
13663 "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
13664 "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
13665 "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
13666 "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
13669 var PRGn = ramp(scheme$1);
13671 var scheme$2 = new Array(3).concat(
13672 "e9a3c9f7f7f7a1d76a",
13673 "d01c8bf1b6dab8e1864dac26",
13674 "d01c8bf1b6daf7f7f7b8e1864dac26",
13675 "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
13676 "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
13677 "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
13678 "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
13679 "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
13680 "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
13683 var PiYG = ramp(scheme$2);
13685 var scheme$3 = new Array(3).concat(
13686 "998ec3f7f7f7f1a340",
13687 "5e3c99b2abd2fdb863e66101",
13688 "5e3c99b2abd2f7f7f7fdb863e66101",
13689 "542788998ec3d8daebfee0b6f1a340b35806",
13690 "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
13691 "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
13692 "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
13693 "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
13694 "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
13697 var PuOr = ramp(scheme$3);
13699 var scheme$4 = new Array(3).concat(
13700 "ef8a62f7f7f767a9cf",
13701 "ca0020f4a58292c5de0571b0",
13702 "ca0020f4a582f7f7f792c5de0571b0",
13703 "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
13704 "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
13705 "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
13706 "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
13707 "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
13708 "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
13711 var RdBu = ramp(scheme$4);
13713 var scheme$5 = new Array(3).concat(
13714 "ef8a62ffffff999999",
13715 "ca0020f4a582bababa404040",
13716 "ca0020f4a582ffffffbababa404040",
13717 "b2182bef8a62fddbc7e0e0e09999994d4d4d",
13718 "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
13719 "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
13720 "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
13721 "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
13722 "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
13725 var RdGy = ramp(scheme$5);
13727 var scheme$6 = new Array(3).concat(
13728 "fc8d59ffffbf91bfdb",
13729 "d7191cfdae61abd9e92c7bb6",
13730 "d7191cfdae61ffffbfabd9e92c7bb6",
13731 "d73027fc8d59fee090e0f3f891bfdb4575b4",
13732 "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
13733 "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
13734 "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
13735 "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
13736 "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
13739 var RdYlBu = ramp(scheme$6);
13741 var scheme$7 = new Array(3).concat(
13742 "fc8d59ffffbf91cf60",
13743 "d7191cfdae61a6d96a1a9641",
13744 "d7191cfdae61ffffbfa6d96a1a9641",
13745 "d73027fc8d59fee08bd9ef8b91cf601a9850",
13746 "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
13747 "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
13748 "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
13749 "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
13750 "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
13753 var RdYlGn = ramp(scheme$7);
13755 var scheme$8 = new Array(3).concat(
13756 "fc8d59ffffbf99d594",
13757 "d7191cfdae61abdda42b83ba",
13758 "d7191cfdae61ffffbfabdda42b83ba",
13759 "d53e4ffc8d59fee08be6f59899d5943288bd",
13760 "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
13761 "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
13762 "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
13763 "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
13764 "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
13767 var Spectral = ramp(scheme$8);
13769 var scheme$9 = new Array(3).concat(
13770 "e5f5f999d8c92ca25f",
13771 "edf8fbb2e2e266c2a4238b45",
13772 "edf8fbb2e2e266c2a42ca25f006d2c",
13773 "edf8fbccece699d8c966c2a42ca25f006d2c",
13774 "edf8fbccece699d8c966c2a441ae76238b45005824",
13775 "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
13776 "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
13779 var BuGn = ramp(scheme$9);
13781 var scheme$10 = new Array(3).concat(
13782 "e0ecf49ebcda8856a7",
13783 "edf8fbb3cde38c96c688419d",
13784 "edf8fbb3cde38c96c68856a7810f7c",
13785 "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
13786 "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
13787 "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
13788 "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
13791 var BuPu = ramp(scheme$10);
13793 var scheme$11 = new Array(3).concat(
13794 "e0f3dba8ddb543a2ca",
13795 "f0f9e8bae4bc7bccc42b8cbe",
13796 "f0f9e8bae4bc7bccc443a2ca0868ac",
13797 "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
13798 "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
13799 "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
13800 "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
13803 var GnBu = ramp(scheme$11);
13805 var scheme$12 = new Array(3).concat(
13806 "fee8c8fdbb84e34a33",
13807 "fef0d9fdcc8afc8d59d7301f",
13808 "fef0d9fdcc8afc8d59e34a33b30000",
13809 "fef0d9fdd49efdbb84fc8d59e34a33b30000",
13810 "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
13811 "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
13812 "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
13815 var OrRd = ramp(scheme$12);
13817 var scheme$13 = new Array(3).concat(
13818 "ece2f0a6bddb1c9099",
13819 "f6eff7bdc9e167a9cf02818a",
13820 "f6eff7bdc9e167a9cf1c9099016c59",
13821 "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
13822 "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
13823 "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
13824 "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
13827 var PuBuGn = ramp(scheme$13);
13829 var scheme$14 = new Array(3).concat(
13830 "ece7f2a6bddb2b8cbe",
13831 "f1eef6bdc9e174a9cf0570b0",
13832 "f1eef6bdc9e174a9cf2b8cbe045a8d",
13833 "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
13834 "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
13835 "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
13836 "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
13839 var PuBu = ramp(scheme$14);
13841 var scheme$15 = new Array(3).concat(
13842 "e7e1efc994c7dd1c77",
13843 "f1eef6d7b5d8df65b0ce1256",
13844 "f1eef6d7b5d8df65b0dd1c77980043",
13845 "f1eef6d4b9dac994c7df65b0dd1c77980043",
13846 "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
13847 "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
13848 "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
13851 var PuRd = ramp(scheme$15);
13853 var scheme$16 = new Array(3).concat(
13854 "fde0ddfa9fb5c51b8a",
13855 "feebe2fbb4b9f768a1ae017e",
13856 "feebe2fbb4b9f768a1c51b8a7a0177",
13857 "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
13858 "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
13859 "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
13860 "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
13863 var RdPu = ramp(scheme$16);
13865 var scheme$17 = new Array(3).concat(
13866 "edf8b17fcdbb2c7fb8",
13867 "ffffcca1dab441b6c4225ea8",
13868 "ffffcca1dab441b6c42c7fb8253494",
13869 "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
13870 "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
13871 "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
13872 "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
13875 var YlGnBu = ramp(scheme$17);
13877 var scheme$18 = new Array(3).concat(
13878 "f7fcb9addd8e31a354",
13879 "ffffccc2e69978c679238443",
13880 "ffffccc2e69978c67931a354006837",
13881 "ffffccd9f0a3addd8e78c67931a354006837",
13882 "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
13883 "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
13884 "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
13887 var YlGn = ramp(scheme$18);
13889 var scheme$19 = new Array(3).concat(
13890 "fff7bcfec44fd95f0e",
13891 "ffffd4fed98efe9929cc4c02",
13892 "ffffd4fed98efe9929d95f0e993404",
13893 "ffffd4fee391fec44ffe9929d95f0e993404",
13894 "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
13895 "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
13896 "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
13899 var YlOrBr = ramp(scheme$19);
13901 var scheme$20 = new Array(3).concat(
13902 "ffeda0feb24cf03b20",
13903 "ffffb2fecc5cfd8d3ce31a1c",
13904 "ffffb2fecc5cfd8d3cf03b20bd0026",
13905 "ffffb2fed976feb24cfd8d3cf03b20bd0026",
13906 "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
13907 "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
13908 "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
13911 var YlOrRd = ramp(scheme$20);
13913 var scheme$21 = new Array(3).concat(
13914 "deebf79ecae13182bd",
13915 "eff3ffbdd7e76baed62171b5",
13916 "eff3ffbdd7e76baed63182bd08519c",
13917 "eff3ffc6dbef9ecae16baed63182bd08519c",
13918 "eff3ffc6dbef9ecae16baed64292c62171b5084594",
13919 "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
13920 "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
13923 var Blues = ramp(scheme$21);
13925 var scheme$22 = new Array(3).concat(
13926 "e5f5e0a1d99b31a354",
13927 "edf8e9bae4b374c476238b45",
13928 "edf8e9bae4b374c47631a354006d2c",
13929 "edf8e9c7e9c0a1d99b74c47631a354006d2c",
13930 "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
13931 "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
13932 "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
13935 var Greens = ramp(scheme$22);
13937 var scheme$23 = new Array(3).concat(
13938 "f0f0f0bdbdbd636363",
13939 "f7f7f7cccccc969696525252",
13940 "f7f7f7cccccc969696636363252525",
13941 "f7f7f7d9d9d9bdbdbd969696636363252525",
13942 "f7f7f7d9d9d9bdbdbd969696737373525252252525",
13943 "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
13944 "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
13947 var Greys = ramp(scheme$23);
13949 var scheme$24 = new Array(3).concat(
13950 "efedf5bcbddc756bb1",
13951 "f2f0f7cbc9e29e9ac86a51a3",
13952 "f2f0f7cbc9e29e9ac8756bb154278f",
13953 "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
13954 "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
13955 "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
13956 "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
13959 var Purples = ramp(scheme$24);
13961 var scheme$25 = new Array(3).concat(
13962 "fee0d2fc9272de2d26",
13963 "fee5d9fcae91fb6a4acb181d",
13964 "fee5d9fcae91fb6a4ade2d26a50f15",
13965 "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
13966 "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
13967 "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
13968 "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
13971 var Reds = ramp(scheme$25);
13973 var scheme$26 = new Array(3).concat(
13974 "fee6cefdae6be6550d",
13975 "feeddefdbe85fd8d3cd94701",
13976 "feeddefdbe85fd8d3ce6550da63603",
13977 "feeddefdd0a2fdae6bfd8d3ce6550da63603",
13978 "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
13979 "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
13980 "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
13983 var Oranges = ramp(scheme$26);
13985 var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
13987 var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
13989 var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
13991 var c = cubehelix();
13993 function rainbow(t) {
13994 if (t < 0 || t > 1) t -= Math.floor(t);
13995 var ts = Math.abs(t - 0.5);
13996 c.h = 360 * t - 100;
13997 c.s = 1.5 - 1.5 * ts;
13998 c.l = 0.8 - 0.9 * ts;
14003 pi_1_3 = Math.PI / 3,
14004 pi_2_3 = Math.PI * 2 / 3;
14006 function sinebow(t) {
14008 t = (0.5 - t) * Math.PI;
14009 c$1.r = 255 * (x = Math.sin(t)) * x;
14010 c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
14011 c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
14015 function ramp$1(range) {
14016 var n = range.length;
14017 return function(t) {
14018 return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
14022 var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
14024 var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
14026 var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
14028 var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
14030 function constant$11(x) {
14031 return function constant() {
14036 var abs$1 = Math.abs;
14037 var atan2$1 = Math.atan2;
14038 var cos$2 = Math.cos;
14039 var max$2 = Math.max;
14040 var min$1 = Math.min;
14041 var sin$2 = Math.sin;
14042 var sqrt$2 = Math.sqrt;
14044 var epsilon$3 = 1e-12;
14045 var pi$4 = Math.PI;
14046 var halfPi$3 = pi$4 / 2;
14047 var tau$4 = 2 * pi$4;
14049 function acos$1(x) {
14050 return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
14053 function asin$1(x) {
14054 return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
14057 function arcInnerRadius(d) {
14058 return d.innerRadius;
14061 function arcOuterRadius(d) {
14062 return d.outerRadius;
14065 function arcStartAngle(d) {
14066 return d.startAngle;
14069 function arcEndAngle(d) {
14073 function arcPadAngle(d) {
14074 return d && d.padAngle; // Note: optional!
14077 function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
14078 var x10 = x1 - x0, y10 = y1 - y0,
14079 x32 = x3 - x2, y32 = y3 - y2,
14080 t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
14081 return [x0 + t * x10, y0 + t * y10];
14084 // Compute perpendicular offset line of length rc.
14085 // http://mathworld.wolfram.com/Circle-LineIntersection.html
14086 function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
14089 lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
14096 x00 = (x11 + x10) / 2,
14097 y00 = (y11 + y10) / 2,
14100 d2 = dx * dx + dy * dy,
14102 D = x11 * y10 - x10 * y11,
14103 d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
14104 cx0 = (D * dy - dx * d) / d2,
14105 cy0 = (-D * dx - dy * d) / d2,
14106 cx1 = (D * dy + dx * d) / d2,
14107 cy1 = (-D * dx + dy * d) / d2,
14113 // Pick the closer of the two intersection points.
14114 // TODO Is there a faster way to determine which intersection to use?
14115 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
14122 x11: cx0 * (r1 / r - 1),
14123 y11: cy0 * (r1 / r - 1)
14128 var innerRadius = arcInnerRadius,
14129 outerRadius = arcOuterRadius,
14130 cornerRadius = constant$11(0),
14132 startAngle = arcStartAngle,
14133 endAngle = arcEndAngle,
14134 padAngle = arcPadAngle,
14140 r0 = +innerRadius.apply(this, arguments),
14141 r1 = +outerRadius.apply(this, arguments),
14142 a0 = startAngle.apply(this, arguments) - halfPi$3,
14143 a1 = endAngle.apply(this, arguments) - halfPi$3,
14144 da = abs$1(a1 - a0),
14147 if (!context) context = buffer = path();
14149 // Ensure that the outer radius is always larger than the inner radius.
14150 if (r1 < r0) r = r1, r1 = r0, r0 = r;
14153 if (!(r1 > epsilon$3)) context.moveTo(0, 0);
14155 // Or is it a circle or annulus?
14156 else if (da > tau$4 - epsilon$3) {
14157 context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
14158 context.arc(0, 0, r1, a0, a1, !cw);
14159 if (r0 > epsilon$3) {
14160 context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
14161 context.arc(0, 0, r0, a1, a0, cw);
14165 // Or is it a circular or annular sector?
14173 ap = padAngle.apply(this, arguments) / 2,
14174 rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
14175 rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
14181 // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
14182 if (rp > epsilon$3) {
14183 var p0 = asin$1(rp / r0 * sin$2(ap)),
14184 p1 = asin$1(rp / r1 * sin$2(ap));
14185 if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
14186 else da0 = 0, a00 = a10 = (a0 + a1) / 2;
14187 if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
14188 else da1 = 0, a01 = a11 = (a0 + a1) / 2;
14191 var x01 = r1 * cos$2(a01),
14192 y01 = r1 * sin$2(a01),
14193 x10 = r0 * cos$2(a10),
14194 y10 = r0 * sin$2(a10);
14196 // Apply rounded corners?
14197 if (rc > epsilon$3) {
14198 var x11 = r1 * cos$2(a11),
14199 y11 = r1 * sin$2(a11),
14200 x00 = r0 * cos$2(a00),
14201 y00 = r0 * sin$2(a00);
14203 // Restrict the corner radius according to the sector angle.
14205 var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
14210 kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
14211 lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
14212 rc0 = min$1(rc, (r0 - lc) / (kc - 1));
14213 rc1 = min$1(rc, (r1 - lc) / (kc + 1));
14217 // Is the sector collapsed to a line?
14218 if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
14220 // Does the sector’s outer ring have rounded corners?
14221 else if (rc1 > epsilon$3) {
14222 t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
14223 t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
14225 context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
14227 // Have the corners merged?
14228 if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
14230 // Otherwise, draw the two corners and the ring.
14232 context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
14233 context.arc(0, 0, r1, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
14234 context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
14238 // Or is the outer ring just a circular arc?
14239 else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
14241 // Is there no inner ring, and it’s a circular sector?
14242 // Or perhaps it’s an annular sector collapsed due to padding?
14243 if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
14245 // Does the sector’s inner ring (or point) have rounded corners?
14246 else if (rc0 > epsilon$3) {
14247 t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
14248 t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
14250 context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
14252 // Have the corners merged?
14253 if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
14255 // Otherwise, draw the two corners and the ring.
14257 context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
14258 context.arc(0, 0, r0, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), cw);
14259 context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
14263 // Or is the inner ring just a circular arc?
14264 else context.arc(0, 0, r0, a10, a00, cw);
14267 context.closePath();
14269 if (buffer) return context = null, buffer + "" || null;
14272 arc.centroid = function() {
14273 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
14274 a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
14275 return [cos$2(a) * r, sin$2(a) * r];
14278 arc.innerRadius = function(_) {
14279 return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : innerRadius;
14282 arc.outerRadius = function(_) {
14283 return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : outerRadius;
14286 arc.cornerRadius = function(_) {
14287 return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : cornerRadius;
14290 arc.padRadius = function(_) {
14291 return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), arc) : padRadius;
14294 arc.startAngle = function(_) {
14295 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : startAngle;
14298 arc.endAngle = function(_) {
14299 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : endAngle;
14302 arc.padAngle = function(_) {
14303 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : padAngle;
14306 arc.context = function(_) {
14307 return arguments.length ? (context = _ == null ? null : _, arc) : context;
14313 function Linear(context) {
14314 this._context = context;
14317 Linear.prototype = {
14318 areaStart: function() {
14321 areaEnd: function() {
14324 lineStart: function() {
14327 lineEnd: function() {
14328 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14329 this._line = 1 - this._line;
14331 point: function(x, y) {
14333 switch (this._point) {
14334 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14335 case 1: this._point = 2; // proceed
14336 default: this._context.lineTo(x, y); break;
14341 function curveLinear(context) {
14342 return new Linear(context);
14356 defined = constant$11(true),
14358 curve = curveLinear,
14361 function line(data) {
14368 if (context == null) output = curve(buffer = path());
14370 for (i = 0; i <= n; ++i) {
14371 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
14372 if (defined0 = !defined0) output.lineStart();
14373 else output.lineEnd();
14375 if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
14378 if (buffer) return output = null, buffer + "" || null;
14381 line.x = function(_) {
14382 return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), line) : x$$1;
14385 line.y = function(_) {
14386 return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), line) : y$$1;
14389 line.defined = function(_) {
14390 return arguments.length ? (defined = typeof _ === "function" ? _ : constant$11(!!_), line) : defined;
14393 line.curve = function(_) {
14394 return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
14397 line.context = function(_) {
14398 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
14404 function area$3() {
14407 y0 = constant$11(0),
14409 defined = constant$11(true),
14411 curve = curveLinear,
14414 function area(data) {
14422 x0z = new Array(n),
14423 y0z = new Array(n);
14425 if (context == null) output = curve(buffer = path());
14427 for (i = 0; i <= n; ++i) {
14428 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
14429 if (defined0 = !defined0) {
14431 output.areaStart();
14432 output.lineStart();
14435 output.lineStart();
14436 for (k = i - 1; k >= j; --k) {
14437 output.point(x0z[k], y0z[k]);
14444 x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
14445 output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
14449 if (buffer) return output = null, buffer + "" || null;
14452 function arealine() {
14453 return line().defined(defined).curve(curve).context(context);
14456 area.x = function(_) {
14457 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$11(+_), x1 = null, area) : x0;
14460 area.x0 = function(_) {
14461 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$11(+_), area) : x0;
14464 area.x1 = function(_) {
14465 return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), area) : x1;
14468 area.y = function(_) {
14469 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$11(+_), y1 = null, area) : y0;
14472 area.y0 = function(_) {
14473 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$11(+_), area) : y0;
14476 area.y1 = function(_) {
14477 return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), area) : y1;
14481 area.lineY0 = function() {
14482 return arealine().x(x0).y(y0);
14485 area.lineY1 = function() {
14486 return arealine().x(x0).y(y1);
14489 area.lineX1 = function() {
14490 return arealine().x(x1).y(y0);
14493 area.defined = function(_) {
14494 return arguments.length ? (defined = typeof _ === "function" ? _ : constant$11(!!_), area) : defined;
14497 area.curve = function(_) {
14498 return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
14501 area.context = function(_) {
14502 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
14508 function descending$1(a, b) {
14509 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
14512 function identity$7(d) {
14517 var value = identity$7,
14518 sortValues = descending$1,
14520 startAngle = constant$11(0),
14521 endAngle = constant$11(tau$4),
14522 padAngle = constant$11(0);
14524 function pie(data) {
14530 index = new Array(n),
14531 arcs = new Array(n),
14532 a0 = +startAngle.apply(this, arguments),
14533 da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
14535 p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
14536 pa = p * (da < 0 ? -1 : 1),
14539 for (i = 0; i < n; ++i) {
14540 if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
14545 // Optionally sort the arcs by previously-computed values or by data.
14546 if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
14547 else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
14549 // Compute the arcs! They are stored in the original data's order.
14550 for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
14551 j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
14564 pie.value = function(_) {
14565 return arguments.length ? (value = typeof _ === "function" ? _ : constant$11(+_), pie) : value;
14568 pie.sortValues = function(_) {
14569 return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
14572 pie.sort = function(_) {
14573 return arguments.length ? (sort = _, sortValues = null, pie) : sort;
14576 pie.startAngle = function(_) {
14577 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : startAngle;
14580 pie.endAngle = function(_) {
14581 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : endAngle;
14584 pie.padAngle = function(_) {
14585 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : padAngle;
14591 var curveRadialLinear = curveRadial(curveLinear);
14593 function Radial(curve) {
14594 this._curve = curve;
14597 Radial.prototype = {
14598 areaStart: function() {
14599 this._curve.areaStart();
14601 areaEnd: function() {
14602 this._curve.areaEnd();
14604 lineStart: function() {
14605 this._curve.lineStart();
14607 lineEnd: function() {
14608 this._curve.lineEnd();
14610 point: function(a, r) {
14611 this._curve.point(r * Math.sin(a), r * -Math.cos(a));
14615 function curveRadial(curve) {
14617 function radial(context) {
14618 return new Radial(curve(context));
14621 radial._curve = curve;
14626 function lineRadial(l) {
14629 l.angle = l.x, delete l.x;
14630 l.radius = l.y, delete l.y;
14632 l.curve = function(_) {
14633 return arguments.length ? c(curveRadial(_)) : c()._curve;
14639 function lineRadial$1() {
14640 return lineRadial(line().curve(curveRadialLinear));
14643 function areaRadial() {
14644 var a = area$3().curve(curveRadialLinear),
14651 a.angle = a.x, delete a.x;
14652 a.startAngle = a.x0, delete a.x0;
14653 a.endAngle = a.x1, delete a.x1;
14654 a.radius = a.y, delete a.y;
14655 a.innerRadius = a.y0, delete a.y0;
14656 a.outerRadius = a.y1, delete a.y1;
14657 a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
14658 a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
14659 a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
14660 a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
14662 a.curve = function(_) {
14663 return arguments.length ? c(curveRadial(_)) : c()._curve;
14669 function pointRadial(x, y) {
14670 return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
14673 var slice$6 = Array.prototype.slice;
14675 function linkSource(d) {
14679 function linkTarget(d) {
14683 function link$2(curve) {
14684 var source = linkSource,
14685 target = linkTarget,
14691 var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
14692 if (!context) context = buffer = path();
14693 curve(context, +x$$1.apply(this, (argv[0] = s, argv)), +y$$1.apply(this, argv), +x$$1.apply(this, (argv[0] = t, argv)), +y$$1.apply(this, argv));
14694 if (buffer) return context = null, buffer + "" || null;
14697 link.source = function(_) {
14698 return arguments.length ? (source = _, link) : source;
14701 link.target = function(_) {
14702 return arguments.length ? (target = _, link) : target;
14705 link.x = function(_) {
14706 return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), link) : x$$1;
14709 link.y = function(_) {
14710 return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), link) : y$$1;
14713 link.context = function(_) {
14714 return arguments.length ? (context = _ == null ? null : _, link) : context;
14720 function curveHorizontal(context, x0, y0, x1, y1) {
14721 context.moveTo(x0, y0);
14722 context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
14725 function curveVertical(context, x0, y0, x1, y1) {
14726 context.moveTo(x0, y0);
14727 context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
14730 function curveRadial$1(context, x0, y0, x1, y1) {
14731 var p0 = pointRadial(x0, y0),
14732 p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
14733 p2 = pointRadial(x1, y0),
14734 p3 = pointRadial(x1, y1);
14735 context.moveTo(p0[0], p0[1]);
14736 context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
14739 function linkHorizontal() {
14740 return link$2(curveHorizontal);
14743 function linkVertical() {
14744 return link$2(curveVertical);
14747 function linkRadial() {
14748 var l = link$2(curveRadial$1);
14749 l.angle = l.x, delete l.x;
14750 l.radius = l.y, delete l.y;
14755 draw: function(context, size) {
14756 var r = Math.sqrt(size / pi$4);
14757 context.moveTo(r, 0);
14758 context.arc(0, 0, r, 0, tau$4);
14763 draw: function(context, size) {
14764 var r = Math.sqrt(size / 5) / 2;
14765 context.moveTo(-3 * r, -r);
14766 context.lineTo(-r, -r);
14767 context.lineTo(-r, -3 * r);
14768 context.lineTo(r, -3 * r);
14769 context.lineTo(r, -r);
14770 context.lineTo(3 * r, -r);
14771 context.lineTo(3 * r, r);
14772 context.lineTo(r, r);
14773 context.lineTo(r, 3 * r);
14774 context.lineTo(-r, 3 * r);
14775 context.lineTo(-r, r);
14776 context.lineTo(-3 * r, r);
14777 context.closePath();
14781 var tan30 = Math.sqrt(1 / 3),
14782 tan30_2 = tan30 * 2;
14785 draw: function(context, size) {
14786 var y = Math.sqrt(size / tan30_2),
14788 context.moveTo(0, -y);
14789 context.lineTo(x, 0);
14790 context.lineTo(0, y);
14791 context.lineTo(-x, 0);
14792 context.closePath();
14796 var ka = 0.89081309152928522810,
14797 kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
14798 kx = Math.sin(tau$4 / 10) * kr,
14799 ky = -Math.cos(tau$4 / 10) * kr;
14802 draw: function(context, size) {
14803 var r = Math.sqrt(size * ka),
14806 context.moveTo(0, -r);
14807 context.lineTo(x, y);
14808 for (var i = 1; i < 5; ++i) {
14809 var a = tau$4 * i / 5,
14812 context.lineTo(s * r, -c * r);
14813 context.lineTo(c * x - s * y, s * x + c * y);
14815 context.closePath();
14820 draw: function(context, size) {
14821 var w = Math.sqrt(size),
14823 context.rect(x, x, w, w);
14827 var sqrt3 = Math.sqrt(3);
14830 draw: function(context, size) {
14831 var y = -Math.sqrt(size / (sqrt3 * 3));
14832 context.moveTo(0, y * 2);
14833 context.lineTo(-sqrt3 * y, -y);
14834 context.lineTo(sqrt3 * y, -y);
14835 context.closePath();
14840 s = Math.sqrt(3) / 2,
14841 k = 1 / Math.sqrt(12),
14842 a = (k / 2 + 1) * 3;
14845 draw: function(context, size) {
14846 var r = Math.sqrt(size / a),
14853 context.moveTo(x0, y0);
14854 context.lineTo(x1, y1);
14855 context.lineTo(x2, y2);
14856 context.lineTo(c$2 * x0 - s * y0, s * x0 + c$2 * y0);
14857 context.lineTo(c$2 * x1 - s * y1, s * x1 + c$2 * y1);
14858 context.lineTo(c$2 * x2 - s * y2, s * x2 + c$2 * y2);
14859 context.lineTo(c$2 * x0 + s * y0, c$2 * y0 - s * x0);
14860 context.lineTo(c$2 * x1 + s * y1, c$2 * y1 - s * x1);
14861 context.lineTo(c$2 * x2 + s * y2, c$2 * y2 - s * x2);
14862 context.closePath();
14876 function symbol() {
14877 var type = constant$11(circle$2),
14878 size = constant$11(64),
14881 function symbol() {
14883 if (!context) context = buffer = path();
14884 type.apply(this, arguments).draw(context, +size.apply(this, arguments));
14885 if (buffer) return context = null, buffer + "" || null;
14888 symbol.type = function(_) {
14889 return arguments.length ? (type = typeof _ === "function" ? _ : constant$11(_), symbol) : type;
14892 symbol.size = function(_) {
14893 return arguments.length ? (size = typeof _ === "function" ? _ : constant$11(+_), symbol) : size;
14896 symbol.context = function(_) {
14897 return arguments.length ? (context = _ == null ? null : _, symbol) : context;
14903 function noop$3() {}
14905 function point$2(that, x, y) {
14906 that._context.bezierCurveTo(
14907 (2 * that._x0 + that._x1) / 3,
14908 (2 * that._y0 + that._y1) / 3,
14909 (that._x0 + 2 * that._x1) / 3,
14910 (that._y0 + 2 * that._y1) / 3,
14911 (that._x0 + 4 * that._x1 + x) / 6,
14912 (that._y0 + 4 * that._y1 + y) / 6
14916 function Basis(context) {
14917 this._context = context;
14920 Basis.prototype = {
14921 areaStart: function() {
14924 areaEnd: function() {
14927 lineStart: function() {
14928 this._x0 = this._x1 =
14929 this._y0 = this._y1 = NaN;
14932 lineEnd: function() {
14933 switch (this._point) {
14934 case 3: point$2(this, this._x1, this._y1); // proceed
14935 case 2: this._context.lineTo(this._x1, this._y1); break;
14937 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14938 this._line = 1 - this._line;
14940 point: function(x, y) {
14942 switch (this._point) {
14943 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14944 case 1: this._point = 2; break;
14945 case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
14946 default: point$2(this, x, y); break;
14948 this._x0 = this._x1, this._x1 = x;
14949 this._y0 = this._y1, this._y1 = y;
14953 function basis$2(context) {
14954 return new Basis(context);
14957 function BasisClosed(context) {
14958 this._context = context;
14961 BasisClosed.prototype = {
14964 lineStart: function() {
14965 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
14966 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
14969 lineEnd: function() {
14970 switch (this._point) {
14972 this._context.moveTo(this._x2, this._y2);
14973 this._context.closePath();
14977 this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
14978 this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
14979 this._context.closePath();
14983 this.point(this._x2, this._y2);
14984 this.point(this._x3, this._y3);
14985 this.point(this._x4, this._y4);
14990 point: function(x, y) {
14992 switch (this._point) {
14993 case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
14994 case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
14995 case 2: this._point = 3; this._x4 = x, this._y4 = y; this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6); break;
14996 default: point$2(this, x, y); break;
14998 this._x0 = this._x1, this._x1 = x;
14999 this._y0 = this._y1, this._y1 = y;
15003 function basisClosed$1(context) {
15004 return new BasisClosed(context);
15007 function BasisOpen(context) {
15008 this._context = context;
15011 BasisOpen.prototype = {
15012 areaStart: function() {
15015 areaEnd: function() {
15018 lineStart: function() {
15019 this._x0 = this._x1 =
15020 this._y0 = this._y1 = NaN;
15023 lineEnd: function() {
15024 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
15025 this._line = 1 - this._line;
15027 point: function(x, y) {
15029 switch (this._point) {
15030 case 0: this._point = 1; break;
15031 case 1: this._point = 2; break;
15032 case 2: this._point = 3; var x0 = (this._x0 + 4 * this._x1 + x) / 6, y0 = (this._y0 + 4 * this._y1 + y) / 6; this._line ? this._context.lineTo(x0, y0) : this._context.moveTo(x0, y0); break;
15033 case 3: this._point = 4; // proceed
15034 default: point$2(this, x, y); break;
15036 this._x0 = this._x1, this._x1 = x;
15037 this._y0 = this._y1, this._y1 = y;
15041 function basisOpen(context) {
15042 return new BasisOpen(context);
15045 function Bundle(context, beta) {
15046 this._basis = new Basis(context);
15050 Bundle.prototype = {
15051 lineStart: function() {
15054 this._basis.lineStart();
15056 lineEnd: function() {
15072 this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
15073 this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
15078 this._x = this._y = null;
15079 this._basis.lineEnd();
15081 point: function(x, y) {
15087 var bundle = (function custom(beta) {
15089 function bundle(context) {
15090 return beta === 1 ? new Basis(context) : new Bundle(context, beta);
15093 bundle.beta = function(beta) {
15094 return custom(+beta);
15100 function point$3(that, x, y) {
15101 that._context.bezierCurveTo(
15102 that._x1 + that._k * (that._x2 - that._x0),
15103 that._y1 + that._k * (that._y2 - that._y0),
15104 that._x2 + that._k * (that._x1 - x),
15105 that._y2 + that._k * (that._y1 - y),
15111 function Cardinal(context, tension) {
15112 this._context = context;
15113 this._k = (1 - tension) / 6;
15116 Cardinal.prototype = {
15117 areaStart: function() {
15120 areaEnd: function() {
15123 lineStart: function() {
15124 this._x0 = this._x1 = this._x2 =
15125 this._y0 = this._y1 = this._y2 = NaN;
15128 lineEnd: function() {
15129 switch (this._point) {
15130 case 2: this._context.lineTo(this._x2, this._y2); break;
15131 case 3: point$3(this, this._x1, this._y1); break;
15133 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15134 this._line = 1 - this._line;
15136 point: function(x, y) {
15138 switch (this._point) {
15139 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15140 case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
15141 case 2: this._point = 3; // proceed
15142 default: point$3(this, x, y); break;
15144 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15145 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15149 var cardinal = (function custom(tension) {
15151 function cardinal(context) {
15152 return new Cardinal(context, tension);
15155 cardinal.tension = function(tension) {
15156 return custom(+tension);
15162 function CardinalClosed(context, tension) {
15163 this._context = context;
15164 this._k = (1 - tension) / 6;
15167 CardinalClosed.prototype = {
15170 lineStart: function() {
15171 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
15172 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
15175 lineEnd: function() {
15176 switch (this._point) {
15178 this._context.moveTo(this._x3, this._y3);
15179 this._context.closePath();
15183 this._context.lineTo(this._x3, this._y3);
15184 this._context.closePath();
15188 this.point(this._x3, this._y3);
15189 this.point(this._x4, this._y4);
15190 this.point(this._x5, this._y5);
15195 point: function(x, y) {
15197 switch (this._point) {
15198 case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
15199 case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
15200 case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
15201 default: point$3(this, x, y); break;
15203 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15204 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15208 var cardinalClosed = (function custom(tension) {
15210 function cardinal$$1(context) {
15211 return new CardinalClosed(context, tension);
15214 cardinal$$1.tension = function(tension) {
15215 return custom(+tension);
15218 return cardinal$$1;
15221 function CardinalOpen(context, tension) {
15222 this._context = context;
15223 this._k = (1 - tension) / 6;
15226 CardinalOpen.prototype = {
15227 areaStart: function() {
15230 areaEnd: function() {
15233 lineStart: function() {
15234 this._x0 = this._x1 = this._x2 =
15235 this._y0 = this._y1 = this._y2 = NaN;
15238 lineEnd: function() {
15239 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
15240 this._line = 1 - this._line;
15242 point: function(x, y) {
15244 switch (this._point) {
15245 case 0: this._point = 1; break;
15246 case 1: this._point = 2; break;
15247 case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
15248 case 3: this._point = 4; // proceed
15249 default: point$3(this, x, y); break;
15251 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15252 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15256 var cardinalOpen = (function custom(tension) {
15258 function cardinal$$1(context) {
15259 return new CardinalOpen(context, tension);
15262 cardinal$$1.tension = function(tension) {
15263 return custom(+tension);
15266 return cardinal$$1;
15269 function point$4(that, x, y) {
15275 if (that._l01_a > epsilon$3) {
15276 var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
15277 n = 3 * that._l01_a * (that._l01_a + that._l12_a);
15278 x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
15279 y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
15282 if (that._l23_a > epsilon$3) {
15283 var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
15284 m = 3 * that._l23_a * (that._l23_a + that._l12_a);
15285 x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
15286 y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
15289 that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
15292 function CatmullRom(context, alpha) {
15293 this._context = context;
15294 this._alpha = alpha;
15297 CatmullRom.prototype = {
15298 areaStart: function() {
15301 areaEnd: function() {
15304 lineStart: function() {
15305 this._x0 = this._x1 = this._x2 =
15306 this._y0 = this._y1 = this._y2 = NaN;
15307 this._l01_a = this._l12_a = this._l23_a =
15308 this._l01_2a = this._l12_2a = this._l23_2a =
15311 lineEnd: function() {
15312 switch (this._point) {
15313 case 2: this._context.lineTo(this._x2, this._y2); break;
15314 case 3: this.point(this._x2, this._y2); break;
15316 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15317 this._line = 1 - this._line;
15319 point: function(x, y) {
15323 var x23 = this._x2 - x,
15324 y23 = this._y2 - y;
15325 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
15328 switch (this._point) {
15329 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15330 case 1: this._point = 2; break;
15331 case 2: this._point = 3; // proceed
15332 default: point$4(this, x, y); break;
15335 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
15336 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
15337 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15338 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15342 var catmullRom = (function custom(alpha) {
15344 function catmullRom(context) {
15345 return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
15348 catmullRom.alpha = function(alpha) {
15349 return custom(+alpha);
15355 function CatmullRomClosed(context, alpha) {
15356 this._context = context;
15357 this._alpha = alpha;
15360 CatmullRomClosed.prototype = {
15363 lineStart: function() {
15364 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
15365 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
15366 this._l01_a = this._l12_a = this._l23_a =
15367 this._l01_2a = this._l12_2a = this._l23_2a =
15370 lineEnd: function() {
15371 switch (this._point) {
15373 this._context.moveTo(this._x3, this._y3);
15374 this._context.closePath();
15378 this._context.lineTo(this._x3, this._y3);
15379 this._context.closePath();
15383 this.point(this._x3, this._y3);
15384 this.point(this._x4, this._y4);
15385 this.point(this._x5, this._y5);
15390 point: function(x, y) {
15394 var x23 = this._x2 - x,
15395 y23 = this._y2 - y;
15396 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
15399 switch (this._point) {
15400 case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
15401 case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
15402 case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
15403 default: point$4(this, x, y); break;
15406 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
15407 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
15408 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15409 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15413 var catmullRomClosed = (function custom(alpha) {
15415 function catmullRom$$1(context) {
15416 return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
15419 catmullRom$$1.alpha = function(alpha) {
15420 return custom(+alpha);
15423 return catmullRom$$1;
15426 function CatmullRomOpen(context, alpha) {
15427 this._context = context;
15428 this._alpha = alpha;
15431 CatmullRomOpen.prototype = {
15432 areaStart: function() {
15435 areaEnd: function() {
15438 lineStart: function() {
15439 this._x0 = this._x1 = this._x2 =
15440 this._y0 = this._y1 = this._y2 = NaN;
15441 this._l01_a = this._l12_a = this._l23_a =
15442 this._l01_2a = this._l12_2a = this._l23_2a =
15445 lineEnd: function() {
15446 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
15447 this._line = 1 - this._line;
15449 point: function(x, y) {
15453 var x23 = this._x2 - x,
15454 y23 = this._y2 - y;
15455 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
15458 switch (this._point) {
15459 case 0: this._point = 1; break;
15460 case 1: this._point = 2; break;
15461 case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
15462 case 3: this._point = 4; // proceed
15463 default: point$4(this, x, y); break;
15466 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
15467 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
15468 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15469 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15473 var catmullRomOpen = (function custom(alpha) {
15475 function catmullRom$$1(context) {
15476 return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
15479 catmullRom$$1.alpha = function(alpha) {
15480 return custom(+alpha);
15483 return catmullRom$$1;
15486 function LinearClosed(context) {
15487 this._context = context;
15490 LinearClosed.prototype = {
15493 lineStart: function() {
15496 lineEnd: function() {
15497 if (this._point) this._context.closePath();
15499 point: function(x, y) {
15501 if (this._point) this._context.lineTo(x, y);
15502 else this._point = 1, this._context.moveTo(x, y);
15506 function linearClosed(context) {
15507 return new LinearClosed(context);
15510 function sign$1(x) {
15511 return x < 0 ? -1 : 1;
15514 // Calculate the slopes of the tangents (Hermite-type interpolation) based on
15515 // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
15516 // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
15517 // NOV(II), P. 443, 1990.
15518 function slope3(that, x2, y2) {
15519 var h0 = that._x1 - that._x0,
15520 h1 = x2 - that._x1,
15521 s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
15522 s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
15523 p = (s0 * h1 + s1 * h0) / (h0 + h1);
15524 return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
15527 // Calculate a one-sided slope.
15528 function slope2(that, t) {
15529 var h = that._x1 - that._x0;
15530 return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
15533 // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
15534 // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
15535 // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
15536 function point$5(that, t0, t1) {
15541 dx = (x1 - x0) / 3;
15542 that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
15545 function MonotoneX(context) {
15546 this._context = context;
15549 MonotoneX.prototype = {
15550 areaStart: function() {
15553 areaEnd: function() {
15556 lineStart: function() {
15557 this._x0 = this._x1 =
15558 this._y0 = this._y1 =
15562 lineEnd: function() {
15563 switch (this._point) {
15564 case 2: this._context.lineTo(this._x1, this._y1); break;
15565 case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
15567 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15568 this._line = 1 - this._line;
15570 point: function(x, y) {
15574 if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
15575 switch (this._point) {
15576 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15577 case 1: this._point = 2; break;
15578 case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
15579 default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
15582 this._x0 = this._x1, this._x1 = x;
15583 this._y0 = this._y1, this._y1 = y;
15588 function MonotoneY(context) {
15589 this._context = new ReflectContext(context);
15592 (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
15593 MonotoneX.prototype.point.call(this, y, x);
15596 function ReflectContext(context) {
15597 this._context = context;
15600 ReflectContext.prototype = {
15601 moveTo: function(x, y) { this._context.moveTo(y, x); },
15602 closePath: function() { this._context.closePath(); },
15603 lineTo: function(x, y) { this._context.lineTo(y, x); },
15604 bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
15607 function monotoneX(context) {
15608 return new MonotoneX(context);
15611 function monotoneY(context) {
15612 return new MonotoneY(context);
15615 function Natural(context) {
15616 this._context = context;
15619 Natural.prototype = {
15620 areaStart: function() {
15623 areaEnd: function() {
15626 lineStart: function() {
15630 lineEnd: function() {
15636 this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
15638 this._context.lineTo(x[1], y[1]);
15640 var px = controlPoints(x),
15641 py = controlPoints(y);
15642 for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
15643 this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
15648 if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
15649 this._line = 1 - this._line;
15650 this._x = this._y = null;
15652 point: function(x, y) {
15658 // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
15659 function controlPoints(x) {
15666 a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
15667 for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
15668 a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
15669 for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
15670 a[n - 1] = r[n - 1] / b[n - 1];
15671 for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
15672 b[n - 1] = (x[n] + a[n - 1]) / 2;
15673 for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
15677 function natural(context) {
15678 return new Natural(context);
15681 function Step(context, t) {
15682 this._context = context;
15687 areaStart: function() {
15690 areaEnd: function() {
15693 lineStart: function() {
15694 this._x = this._y = NaN;
15697 lineEnd: function() {
15698 if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
15699 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15700 if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
15702 point: function(x, y) {
15704 switch (this._point) {
15705 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15706 case 1: this._point = 2; // proceed
15708 if (this._t <= 0) {
15709 this._context.lineTo(this._x, y);
15710 this._context.lineTo(x, y);
15712 var x1 = this._x * (1 - this._t) + x * this._t;
15713 this._context.lineTo(x1, this._y);
15714 this._context.lineTo(x1, y);
15719 this._x = x, this._y = y;
15723 function step(context) {
15724 return new Step(context, 0.5);
15727 function stepBefore(context) {
15728 return new Step(context, 0);
15731 function stepAfter(context) {
15732 return new Step(context, 1);
15735 function none$1(series, order) {
15736 if (!((n = series.length) > 1)) return;
15737 for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
15738 s0 = s1, s1 = series[order[i]];
15739 for (j = 0; j < m; ++j) {
15740 s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
15745 function none$2(series) {
15746 var n = series.length, o = new Array(n);
15747 while (--n >= 0) o[n] = n;
15751 function stackValue(d, key) {
15756 var keys = constant$11([]),
15759 value = stackValue;
15761 function stack(data) {
15762 var kz = keys.apply(this, arguments),
15769 for (i = 0; i < n; ++i) {
15770 for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
15771 si[j] = sij = [0, +value(data[j], ki, j, data)];
15772 sij.data = data[j];
15777 for (i = 0, oz = order(sz); i < n; ++i) {
15778 sz[oz[i]].index = i;
15785 stack.keys = function(_) {
15786 return arguments.length ? (keys = typeof _ === "function" ? _ : constant$11(slice$6.call(_)), stack) : keys;
15789 stack.value = function(_) {
15790 return arguments.length ? (value = typeof _ === "function" ? _ : constant$11(+_), stack) : value;
15793 stack.order = function(_) {
15794 return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$11(slice$6.call(_)), stack) : order;
15797 stack.offset = function(_) {
15798 return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
15804 function expand(series, order) {
15805 if (!((n = series.length) > 0)) return;
15806 for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
15807 for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
15808 if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
15810 none$1(series, order);
15813 function diverging$1(series, order) {
15814 if (!((n = series.length) > 1)) return;
15815 for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
15816 for (yp = yn = 0, i = 0; i < n; ++i) {
15817 if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
15818 d[0] = yp, d[1] = yp += dy;
15819 } else if (dy < 0) {
15820 d[1] = yn, d[0] = yn += dy;
15828 function silhouette(series, order) {
15829 if (!((n = series.length) > 0)) return;
15830 for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
15831 for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
15832 s0[j][1] += s0[j][0] = -y / 2;
15834 none$1(series, order);
15837 function wiggle(series, order) {
15838 if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
15839 for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
15840 for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
15841 var si = series[order[i]],
15842 sij0 = si[j][1] || 0,
15843 sij1 = si[j - 1][1] || 0,
15844 s3 = (sij0 - sij1) / 2;
15845 for (var k = 0; k < i; ++k) {
15846 var sk = series[order[k]],
15847 skj0 = sk[j][1] || 0,
15848 skj1 = sk[j - 1][1] || 0;
15851 s1 += sij0, s2 += s3 * sij0;
15853 s0[j - 1][1] += s0[j - 1][0] = y;
15854 if (s1) y -= s2 / s1;
15856 s0[j - 1][1] += s0[j - 1][0] = y;
15857 none$1(series, order);
15860 function ascending$3(series) {
15861 var sums = series.map(sum$2);
15862 return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
15865 function sum$2(series) {
15866 var s = 0, i = -1, n = series.length, v;
15867 while (++i < n) if (v = +series[i][1]) s += v;
15871 function descending$2(series) {
15872 return ascending$3(series).reverse();
15875 function insideOut(series) {
15876 var n = series.length,
15879 sums = series.map(sum$2),
15880 order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
15886 for (i = 0; i < n; ++i) {
15888 if (top < bottom) {
15897 return bottoms.reverse().concat(tops);
15900 function reverse(series) {
15901 return none$2(series).reverse();
15904 function constant$12(x) {
15905 return function() {
15918 function RedBlackTree() {
15919 this._ = null; // root node
15922 function RedBlackNode(node) {
15923 node.U = // parent node
15924 node.C = // color - true for red, false for black
15925 node.L = // left node
15926 node.R = // right node
15927 node.P = // previous node
15928 node.N = null; // next node
15931 RedBlackTree.prototype = {
15932 constructor: RedBlackTree,
15934 insert: function(after, node) {
15935 var parent, grandpa, uncle;
15940 if (after.N) after.N.P = node;
15944 while (after.L) after = after.L;
15950 } else if (this._) {
15951 after = RedBlackFirst(this._);
15954 after.P = after.L = node;
15957 node.P = node.N = null;
15961 node.L = node.R = null;
15966 while (parent && parent.C) {
15967 grandpa = parent.U;
15968 if (parent === grandpa.L) {
15970 if (uncle && uncle.C) {
15971 parent.C = uncle.C = false;
15975 if (after === parent.R) {
15976 RedBlackRotateLeft(this, parent);
15982 RedBlackRotateRight(this, grandpa);
15986 if (uncle && uncle.C) {
15987 parent.C = uncle.C = false;
15991 if (after === parent.L) {
15992 RedBlackRotateRight(this, parent);
15998 RedBlackRotateLeft(this, grandpa);
16006 remove: function(node) {
16007 if (node.N) node.N.P = node.P;
16008 if (node.P) node.P.N = node.N;
16009 node.N = node.P = null;
16011 var parent = node.U,
16018 if (!left) next = right;
16019 else if (!right) next = left;
16020 else next = RedBlackFirst(right);
16023 if (parent.L === node) parent.L = next;
16024 else parent.R = next;
16029 if (left && right) {
16034 if (next !== right) {
16051 if (node) node.U = parent;
16053 if (node && node.C) { node.C = false; return; }
16056 if (node === this._) break;
16057 if (node === parent.L) {
16058 sibling = parent.R;
16062 RedBlackRotateLeft(this, parent);
16063 sibling = parent.R;
16065 if ((sibling.L && sibling.L.C)
16066 || (sibling.R && sibling.R.C)) {
16067 if (!sibling.R || !sibling.R.C) {
16068 sibling.L.C = false;
16070 RedBlackRotateRight(this, sibling);
16071 sibling = parent.R;
16073 sibling.C = parent.C;
16074 parent.C = sibling.R.C = false;
16075 RedBlackRotateLeft(this, parent);
16080 sibling = parent.L;
16084 RedBlackRotateRight(this, parent);
16085 sibling = parent.L;
16087 if ((sibling.L && sibling.L.C)
16088 || (sibling.R && sibling.R.C)) {
16089 if (!sibling.L || !sibling.L.C) {
16090 sibling.R.C = false;
16092 RedBlackRotateLeft(this, sibling);
16093 sibling = parent.L;
16095 sibling.C = parent.C;
16096 parent.C = sibling.L.C = false;
16097 RedBlackRotateRight(this, parent);
16107 if (node) node.C = false;
16111 function RedBlackRotateLeft(tree, node) {
16117 if (parent.L === p) parent.L = q;
16126 if (p.R) p.R.U = p;
16130 function RedBlackRotateRight(tree, node) {
16136 if (parent.L === p) parent.L = q;
16145 if (p.L) p.L.U = p;
16149 function RedBlackFirst(node) {
16150 while (node.L) node = node.L;
16154 function createEdge(left, right, v0, v1) {
16155 var edge = [null, null],
16156 index = edges.push(edge) - 1;
16158 edge.right = right;
16159 if (v0) setEdgeEnd(edge, left, right, v0);
16160 if (v1) setEdgeEnd(edge, right, left, v1);
16161 cells[left.index].halfedges.push(index);
16162 cells[right.index].halfedges.push(index);
16166 function createBorderEdge(left, v0, v1) {
16167 var edge = [v0, v1];
16172 function setEdgeEnd(edge, left, right, vertex) {
16173 if (!edge[0] && !edge[1]) {
16176 edge.right = right;
16177 } else if (edge.left === right) {
16184 // Liang–Barsky line clipping.
16185 function clipEdge(edge, x0, y0, x1, y1) {
16199 if (!dx && r > 0) return;
16202 if (r < t0) return;
16203 if (r < t1) t1 = r;
16204 } else if (dx > 0) {
16205 if (r > t1) return;
16206 if (r > t0) t0 = r;
16210 if (!dx && r < 0) return;
16213 if (r > t1) return;
16214 if (r > t0) t0 = r;
16215 } else if (dx > 0) {
16216 if (r < t0) return;
16217 if (r < t1) t1 = r;
16221 if (!dy && r > 0) return;
16224 if (r < t0) return;
16225 if (r < t1) t1 = r;
16226 } else if (dy > 0) {
16227 if (r > t1) return;
16228 if (r > t0) t0 = r;
16232 if (!dy && r < 0) return;
16235 if (r > t1) return;
16236 if (r > t0) t0 = r;
16237 } else if (dy > 0) {
16238 if (r < t0) return;
16239 if (r < t1) t1 = r;
16242 if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
16244 if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
16245 if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
16249 function connectEdge(edge, x0, y0, x1, y1) {
16251 if (v1) return true;
16255 right = edge.right,
16260 fx = (lx + rx) / 2,
16261 fy = (ly + ry) / 2,
16266 if (fx < x0 || fx >= x1) return;
16268 if (!v0) v0 = [fx, y0];
16269 else if (v0[1] >= y1) return;
16272 if (!v0) v0 = [fx, y1];
16273 else if (v0[1] < y0) return;
16277 fm = (lx - rx) / (ry - ly);
16279 if (fm < -1 || fm > 1) {
16281 if (!v0) v0 = [(y0 - fb) / fm, y0];
16282 else if (v0[1] >= y1) return;
16283 v1 = [(y1 - fb) / fm, y1];
16285 if (!v0) v0 = [(y1 - fb) / fm, y1];
16286 else if (v0[1] < y0) return;
16287 v1 = [(y0 - fb) / fm, y0];
16291 if (!v0) v0 = [x0, fm * x0 + fb];
16292 else if (v0[0] >= x1) return;
16293 v1 = [x1, fm * x1 + fb];
16295 if (!v0) v0 = [x1, fm * x1 + fb];
16296 else if (v0[0] < x0) return;
16297 v1 = [x0, fm * x0 + fb];
16307 function clipEdges(x0, y0, x1, y1) {
16308 var i = edges.length,
16312 if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
16313 || !clipEdge(edge, x0, y0, x1, y1)
16314 || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
16315 || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
16321 function createCell(site) {
16322 return cells[site.index] = {
16328 function cellHalfedgeAngle(cell, edge) {
16329 var site = cell.site,
16332 if (site === vb) vb = va, va = site;
16333 if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
16334 if (site === va) va = edge[1], vb = edge[0];
16335 else va = edge[0], vb = edge[1];
16336 return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
16339 function cellHalfedgeStart(cell, edge) {
16340 return edge[+(edge.left !== cell.site)];
16343 function cellHalfedgeEnd(cell, edge) {
16344 return edge[+(edge.left === cell.site)];
16347 function sortCellHalfedges() {
16348 for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
16349 if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
16350 var index = new Array(m),
16351 array = new Array(m);
16352 for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
16353 index.sort(function(i, j) { return array[j] - array[i]; });
16354 for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
16355 for (j = 0; j < m; ++j) halfedges[j] = array[j];
16360 function clipCells(x0, y0, x1, y1) {
16361 var nCells = cells.length,
16376 for (iCell = 0; iCell < nCells; ++iCell) {
16377 if (cell = cells[iCell]) {
16379 halfedges = cell.halfedges;
16380 iHalfedge = halfedges.length;
16382 // Remove any dangling clipped edges.
16383 while (iHalfedge--) {
16384 if (!edges[halfedges[iHalfedge]]) {
16385 halfedges.splice(iHalfedge, 1);
16389 // Insert any border edges as necessary.
16390 iHalfedge = 0, nHalfedges = halfedges.length;
16391 while (iHalfedge < nHalfedges) {
16392 end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
16393 start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
16394 if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
16395 halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
16396 Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
16397 : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
16398 : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
16399 : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
16405 if (nHalfedges) cover = false;
16409 // If there weren’t any edges, have the closest site cover the extent.
16410 // It doesn’t matter which corner of the extent we measure!
16412 var dx, dy, d2, dc = Infinity;
16414 for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
16415 if (cell = cells[iCell]) {
16419 d2 = dx * dx + dy * dy;
16420 if (d2 < dc) dc = d2, cover = cell;
16425 var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
16426 cover.halfedges.push(
16427 edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
16428 edges.push(createBorderEdge(site, v01, v11)) - 1,
16429 edges.push(createBorderEdge(site, v11, v10)) - 1,
16430 edges.push(createBorderEdge(site, v10, v00)) - 1
16435 // Lastly delete any cells with no edges; these were entirely clipped.
16436 for (iCell = 0; iCell < nCells; ++iCell) {
16437 if (cell = cells[iCell]) {
16438 if (!cell.halfedges.length) {
16439 delete cells[iCell];
16445 var circlePool = [];
16449 function Circle() {
16450 RedBlackNode(this);
16458 function attachCircle(arc) {
16462 if (!lArc || !rArc) return;
16464 var lSite = lArc.site,
16468 if (lSite === rSite) return;
16472 ax = lSite[0] - bx,
16473 ay = lSite[1] - by,
16474 cx = rSite[0] - bx,
16475 cy = rSite[1] - by;
16477 var d = 2 * (ax * cy - ay * cx);
16478 if (d >= -epsilon2$2) return;
16480 var ha = ax * ax + ay * ay,
16481 hc = cx * cx + cy * cy,
16482 x = (cy * ha - ay * hc) / d,
16483 y = (ax * hc - cx * ha) / d;
16485 var circle = circlePool.pop() || new Circle;
16487 circle.site = cSite;
16489 circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
16491 arc.circle = circle;
16497 if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
16498 if (node.L) node = node.L;
16499 else { before = node.P; break; }
16501 if (node.R) node = node.R;
16502 else { before = node; break; }
16506 circles.insert(before, circle);
16507 if (!before) firstCircle = circle;
16510 function detachCircle(arc) {
16511 var circle = arc.circle;
16513 if (!circle.P) firstCircle = circle.N;
16514 circles.remove(circle);
16515 circlePool.push(circle);
16516 RedBlackNode(circle);
16521 var beachPool = [];
16524 RedBlackNode(this);
16527 this.circle = null;
16530 function createBeach(site) {
16531 var beach = beachPool.pop() || new Beach;
16536 function detachBeach(beach) {
16537 detachCircle(beach);
16538 beaches.remove(beach);
16539 beachPool.push(beach);
16540 RedBlackNode(beach);
16543 function removeBeach(beach) {
16544 var circle = beach.circle,
16548 previous = beach.P,
16550 disappearing = [beach];
16552 detachBeach(beach);
16554 var lArc = previous;
16556 && Math.abs(x - lArc.circle.x) < epsilon$4
16557 && Math.abs(y - lArc.circle.cy) < epsilon$4) {
16559 disappearing.unshift(lArc);
16564 disappearing.unshift(lArc);
16565 detachCircle(lArc);
16569 && Math.abs(x - rArc.circle.x) < epsilon$4
16570 && Math.abs(y - rArc.circle.cy) < epsilon$4) {
16572 disappearing.push(rArc);
16577 disappearing.push(rArc);
16578 detachCircle(rArc);
16580 var nArcs = disappearing.length,
16582 for (iArc = 1; iArc < nArcs; ++iArc) {
16583 rArc = disappearing[iArc];
16584 lArc = disappearing[iArc - 1];
16585 setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
16588 lArc = disappearing[0];
16589 rArc = disappearing[nArcs - 1];
16590 rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
16592 attachCircle(lArc);
16593 attachCircle(rArc);
16596 function addBeach(site) {
16598 directrix = site[1],
16606 dxl = leftBreakPoint(node, directrix) - x;
16607 if (dxl > epsilon$4) node = node.L; else {
16608 dxr = x - rightBreakPoint(node, directrix);
16609 if (dxr > epsilon$4) {
16616 if (dxl > -epsilon$4) {
16619 } else if (dxr > -epsilon$4) {
16623 lArc = rArc = node;
16631 var newArc = createBeach(site);
16632 beaches.insert(lArc, newArc);
16634 if (!lArc && !rArc) return;
16636 if (lArc === rArc) {
16637 detachCircle(lArc);
16638 rArc = createBeach(lArc.site);
16639 beaches.insert(newArc, rArc);
16640 newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
16641 attachCircle(lArc);
16642 attachCircle(rArc);
16646 if (!rArc) { // && lArc
16647 newArc.edge = createEdge(lArc.site, newArc.site);
16651 // else lArc !== rArc
16652 detachCircle(lArc);
16653 detachCircle(rArc);
16655 var lSite = lArc.site,
16661 cx = rSite[0] - ax,
16662 cy = rSite[1] - ay,
16663 d = 2 * (bx * cy - by * cx),
16664 hb = bx * bx + by * by,
16665 hc = cx * cx + cy * cy,
16666 vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
16668 setEdgeEnd(rArc.edge, lSite, rSite, vertex);
16669 newArc.edge = createEdge(lSite, site, null, vertex);
16670 rArc.edge = createEdge(site, rSite, null, vertex);
16671 attachCircle(lArc);
16672 attachCircle(rArc);
16675 function leftBreakPoint(arc, directrix) {
16676 var site = arc.site,
16679 pby2 = rfocy - directrix;
16681 if (!pby2) return rfocx;
16684 if (!lArc) return -Infinity;
16687 var lfocx = site[0],
16689 plby2 = lfocy - directrix;
16691 if (!plby2) return lfocx;
16693 var hl = lfocx - rfocx,
16694 aby2 = 1 / pby2 - 1 / plby2,
16697 if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
16699 return (rfocx + lfocx) / 2;
16702 function rightBreakPoint(arc, directrix) {
16704 if (rArc) return leftBreakPoint(rArc, directrix);
16705 var site = arc.site;
16706 return site[1] === directrix ? site[0] : Infinity;
16709 var epsilon$4 = 1e-6;
16710 var epsilon2$2 = 1e-12;
16716 function triangleArea(a, b, c) {
16717 return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
16720 function lexicographic(a, b) {
16725 function Diagram(sites, extent) {
16726 var site = sites.sort(lexicographic).pop(),
16732 cells = new Array(sites.length);
16733 beaches = new RedBlackTree;
16734 circles = new RedBlackTree;
16737 circle = firstCircle;
16738 if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
16739 if (site[0] !== x || site[1] !== y) {
16741 x = site[0], y = site[1];
16743 site = sites.pop();
16744 } else if (circle) {
16745 removeBeach(circle.arc);
16751 sortCellHalfedges();
16754 var x0 = +extent[0][0],
16755 y0 = +extent[0][1],
16756 x1 = +extent[1][0],
16757 y1 = +extent[1][1];
16758 clipEdges(x0, y0, x1, y1);
16759 clipCells(x0, y0, x1, y1);
16762 this.edges = edges;
16763 this.cells = cells;
16771 Diagram.prototype = {
16772 constructor: Diagram,
16774 polygons: function() {
16775 var edges = this.edges;
16777 return this.cells.map(function(cell) {
16778 var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
16779 polygon.data = cell.site.data;
16784 triangles: function() {
16785 var triangles = [],
16786 edges = this.edges;
16788 this.cells.forEach(function(cell, i) {
16789 if (!(m = (halfedges = cell.halfedges).length)) return;
16790 var site = cell.site,
16795 e1 = edges[halfedges[m - 1]],
16796 s1 = e1.left === site ? e1.right : e1.left;
16800 e1 = edges[halfedges[j]];
16801 s1 = e1.left === site ? e1.right : e1.left;
16802 if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
16803 triangles.push([site.data, s0.data, s1.data]);
16811 links: function() {
16812 return this.edges.filter(function(edge) {
16814 }).map(function(edge) {
16816 source: edge.left.data,
16817 target: edge.right.data
16822 find: function(x, y, radius) {
16823 var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
16825 // Use the previously-found cell, or start with an arbitrary one.
16826 while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
16827 var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
16829 // Traverse the half-edges to find a closer cell, if any.
16831 cell = that.cells[i0 = i1], i1 = null;
16832 cell.halfedges.forEach(function(e) {
16833 var edge = that.edges[e], v = edge.left;
16834 if ((v === cell.site || !v) && !(v = edge.right)) return;
16835 var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
16836 if (v2 < d2) d2 = v2, i1 = v.index;
16838 } while (i1 !== null);
16842 return radius == null || d2 <= radius * radius ? cell.site : null;
16846 function voronoi() {
16851 function voronoi(data) {
16852 return new Diagram(data.map(function(d, i) {
16853 var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
16860 voronoi.polygons = function(data) {
16861 return voronoi(data).polygons();
16864 voronoi.links = function(data) {
16865 return voronoi(data).links();
16868 voronoi.triangles = function(data) {
16869 return voronoi(data).triangles();
16872 voronoi.x = function(_) {
16873 return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$12(+_), voronoi) : x$$1;
16876 voronoi.y = function(_) {
16877 return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$12(+_), voronoi) : y$$1;
16880 voronoi.extent = function(_) {
16881 return arguments.length ? (extent = _ == null ? null : [[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]], voronoi) : extent && [[extent[0][0], extent[0][1]], [extent[1][0], extent[1][1]]];
16884 voronoi.size = function(_) {
16885 return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
16891 function constant$13(x) {
16892 return function() {
16897 function ZoomEvent(target, type, transform) {
16898 this.target = target;
16900 this.transform = transform;
16903 function Transform(k, x, y) {
16909 Transform.prototype = {
16910 constructor: Transform,
16911 scale: function(k) {
16912 return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
16914 translate: function(x, y) {
16915 return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
16917 apply: function(point) {
16918 return [point[0] * this.k + this.x, point[1] * this.k + this.y];
16920 applyX: function(x) {
16921 return x * this.k + this.x;
16923 applyY: function(y) {
16924 return y * this.k + this.y;
16926 invert: function(location) {
16927 return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
16929 invertX: function(x) {
16930 return (x - this.x) / this.k;
16932 invertY: function(y) {
16933 return (y - this.y) / this.k;
16935 rescaleX: function(x) {
16936 return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
16938 rescaleY: function(y) {
16939 return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
16941 toString: function() {
16942 return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
16946 var identity$8 = new Transform(1, 0, 0);
16948 transform$1.prototype = Transform.prototype;
16950 function transform$1(node) {
16951 return node.__zoom || identity$8;
16954 function nopropagation$2() {
16955 exports.event.stopImmediatePropagation();
16958 function noevent$2() {
16959 exports.event.preventDefault();
16960 exports.event.stopImmediatePropagation();
16963 // Ignore right-click, since that should open the context menu.
16964 function defaultFilter$2() {
16965 return !exports.event.button;
16968 function defaultExtent$1() {
16969 var e = this, w, h;
16970 if (e instanceof SVGElement) {
16971 e = e.ownerSVGElement || e;
16972 w = e.width.baseVal.value;
16973 h = e.height.baseVal.value;
16976 h = e.clientHeight;
16978 return [[0, 0], [w, h]];
16981 function defaultTransform() {
16982 return this.__zoom || identity$8;
16985 function defaultWheelDelta() {
16986 return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
16989 function defaultTouchable$1() {
16990 return "ontouchstart" in this;
16993 function defaultConstrain(transform, extent, translateExtent) {
16994 var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
16995 dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
16996 dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
16997 dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
16998 return transform.translate(
16999 dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
17000 dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
17005 var filter = defaultFilter$2,
17006 extent = defaultExtent$1,
17007 constrain = defaultConstrain,
17008 wheelDelta = defaultWheelDelta,
17009 touchable = defaultTouchable$1,
17010 scaleExtent = [0, Infinity],
17011 translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
17013 interpolate = interpolateZoom,
17015 listeners = dispatch("start", "zoom", "end"),
17020 clickDistance2 = 0;
17022 function zoom(selection$$1) {
17024 .property("__zoom", defaultTransform)
17025 .on("wheel.zoom", wheeled)
17026 .on("mousedown.zoom", mousedowned)
17027 .on("dblclick.zoom", dblclicked)
17029 .on("touchstart.zoom", touchstarted)
17030 .on("touchmove.zoom", touchmoved)
17031 .on("touchend.zoom touchcancel.zoom", touchended)
17032 .style("touch-action", "none")
17033 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
17036 zoom.transform = function(collection, transform) {
17037 var selection$$1 = collection.selection ? collection.selection() : collection;
17038 selection$$1.property("__zoom", defaultTransform);
17039 if (collection !== selection$$1) {
17040 schedule(collection, transform);
17042 selection$$1.interrupt().each(function() {
17043 gesture(this, arguments)
17045 .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
17051 zoom.scaleBy = function(selection$$1, k) {
17052 zoom.scaleTo(selection$$1, function() {
17053 var k0 = this.__zoom.k,
17054 k1 = typeof k === "function" ? k.apply(this, arguments) : k;
17059 zoom.scaleTo = function(selection$$1, k) {
17060 zoom.transform(selection$$1, function() {
17061 var e = extent.apply(this, arguments),
17064 p1 = t0.invert(p0),
17065 k1 = typeof k === "function" ? k.apply(this, arguments) : k;
17066 return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
17070 zoom.translateBy = function(selection$$1, x, y) {
17071 zoom.transform(selection$$1, function() {
17072 return constrain(this.__zoom.translate(
17073 typeof x === "function" ? x.apply(this, arguments) : x,
17074 typeof y === "function" ? y.apply(this, arguments) : y
17075 ), extent.apply(this, arguments), translateExtent);
17079 zoom.translateTo = function(selection$$1, x, y) {
17080 zoom.transform(selection$$1, function() {
17081 var e = extent.apply(this, arguments),
17084 return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
17085 typeof x === "function" ? -x.apply(this, arguments) : -x,
17086 typeof y === "function" ? -y.apply(this, arguments) : -y
17087 ), e, translateExtent);
17091 function scale(transform, k) {
17092 k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
17093 return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
17096 function translate(transform, p0, p1) {
17097 var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
17098 return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
17101 function centroid(extent) {
17102 return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
17105 function schedule(transition$$1, transform, center) {
17107 .on("start.zoom", function() { gesture(this, arguments).start(); })
17108 .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
17109 .tween("zoom", function() {
17112 g = gesture(that, args),
17113 e = extent.apply(that, args),
17114 p = center || centroid(e),
17115 w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
17117 b = typeof transform === "function" ? transform.apply(that, args) : transform,
17118 i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
17119 return function(t) {
17120 if (t === 1) t = b; // Avoid rounding error on end.
17121 else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
17127 function gesture(that, args) {
17128 for (var i = 0, n = gestures.length, g; i < n; ++i) {
17129 if ((g = gestures[i]).that === that) {
17133 return new Gesture(that, args);
17136 function Gesture(that, args) {
17141 this.extent = extent.apply(that, args);
17144 Gesture.prototype = {
17145 start: function() {
17146 if (++this.active === 1) {
17147 this.index = gestures.push(this) - 1;
17148 this.emit("start");
17152 zoom: function(key, transform) {
17153 if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
17154 if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
17155 if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
17156 this.that.__zoom = transform;
17161 if (--this.active === 0) {
17162 gestures.splice(this.index, 1);
17168 emit: function(type) {
17169 customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
17173 function wheeled() {
17174 if (!filter.apply(this, arguments)) return;
17175 var g = gesture(this, arguments),
17177 k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
17180 // If the mouse is in the same location as before, reuse it.
17181 // If there were recent wheel events, reset the wheel idle timeout.
17183 if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
17184 g.mouse[1] = t.invert(g.mouse[0] = p);
17186 clearTimeout(g.wheel);
17189 // If this wheel event won’t trigger a transform change, ignore it.
17190 else if (t.k === k) return;
17192 // Otherwise, capture the mouse point and location at the start.
17194 g.mouse = [p, t.invert(p)];
17200 g.wheel = setTimeout(wheelidled, wheelDelay);
17201 g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
17203 function wheelidled() {
17209 function mousedowned() {
17210 if (touchending || !filter.apply(this, arguments)) return;
17211 var g = gesture(this, arguments),
17212 v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
17214 x0 = exports.event.clientX,
17215 y0 = exports.event.clientY;
17217 dragDisable(exports.event.view);
17219 g.mouse = [p, this.__zoom.invert(p)];
17223 function mousemoved() {
17226 var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
17227 g.moved = dx * dx + dy * dy > clickDistance2;
17229 g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
17232 function mouseupped() {
17233 v.on("mousemove.zoom mouseup.zoom", null);
17234 yesdrag(exports.event.view, g.moved);
17240 function dblclicked() {
17241 if (!filter.apply(this, arguments)) return;
17242 var t0 = this.__zoom,
17244 p1 = t0.invert(p0),
17245 k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
17246 t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
17249 if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
17250 else select(this).call(zoom.transform, t1);
17253 function touchstarted() {
17254 if (!filter.apply(this, arguments)) return;
17255 var g = gesture(this, arguments),
17256 touches$$1 = exports.event.changedTouches,
17258 n = touches$$1.length, i, t, p;
17261 for (i = 0; i < n; ++i) {
17262 t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
17263 p = [p, this.__zoom.invert(p), t.identifier];
17264 if (!g.touch0) g.touch0 = p, started = true;
17265 else if (!g.touch1) g.touch1 = p;
17268 // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
17269 if (touchstarting) {
17270 touchstarting = clearTimeout(touchstarting);
17273 p = select(this).on("dblclick.zoom");
17274 if (p) p.apply(this, arguments);
17280 touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
17286 function touchmoved() {
17287 var g = gesture(this, arguments),
17288 touches$$1 = exports.event.changedTouches,
17289 n = touches$$1.length, i, t, p, l;
17292 if (touchstarting) touchstarting = clearTimeout(touchstarting);
17293 for (i = 0; i < n; ++i) {
17294 t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
17295 if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
17296 else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
17300 var p0 = g.touch0[0], l0 = g.touch0[1],
17301 p1 = g.touch1[0], l1 = g.touch1[1],
17302 dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
17303 dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
17304 t = scale(t, Math.sqrt(dp / dl));
17305 p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
17306 l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
17308 else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
17310 g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
17313 function touchended() {
17314 var g = gesture(this, arguments),
17315 touches$$1 = exports.event.changedTouches,
17316 n = touches$$1.length, i, t;
17319 if (touchending) clearTimeout(touchending);
17320 touchending = setTimeout(function() { touchending = null; }, touchDelay);
17321 for (i = 0; i < n; ++i) {
17323 if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
17324 else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
17326 if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
17327 if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
17331 zoom.wheelDelta = function(_) {
17332 return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$13(+_), zoom) : wheelDelta;
17335 zoom.filter = function(_) {
17336 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$13(!!_), zoom) : filter;
17339 zoom.touchable = function(_) {
17340 return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$13(!!_), zoom) : touchable;
17343 zoom.extent = function(_) {
17344 return arguments.length ? (extent = typeof _ === "function" ? _ : constant$13([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
17347 zoom.scaleExtent = function(_) {
17348 return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
17351 zoom.translateExtent = function(_) {
17352 return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];
17355 zoom.constrain = function(_) {
17356 return arguments.length ? (constrain = _, zoom) : constrain;
17359 zoom.duration = function(_) {
17360 return arguments.length ? (duration = +_, zoom) : duration;
17363 zoom.interpolate = function(_) {
17364 return arguments.length ? (interpolate = _, zoom) : interpolate;
17367 zoom.on = function() {
17368 var value = listeners.on.apply(listeners, arguments);
17369 return value === listeners ? zoom : value;
17372 zoom.clickDistance = function(_) {
17373 return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
17379 exports.version = version;
17380 exports.bisect = bisectRight;
17381 exports.bisectRight = bisectRight;
17382 exports.bisectLeft = bisectLeft;
17383 exports.ascending = ascending;
17384 exports.bisector = bisector;
17385 exports.cross = cross;
17386 exports.descending = descending;
17387 exports.deviation = deviation;
17388 exports.extent = extent;
17389 exports.histogram = histogram;
17390 exports.thresholdFreedmanDiaconis = freedmanDiaconis;
17391 exports.thresholdScott = scott;
17392 exports.thresholdSturges = thresholdSturges;
17394 exports.mean = mean;
17395 exports.median = median;
17396 exports.merge = merge;
17398 exports.pairs = pairs;
17399 exports.permute = permute;
17400 exports.quantile = threshold;
17401 exports.range = sequence;
17402 exports.scan = scan;
17403 exports.shuffle = shuffle;
17405 exports.ticks = ticks;
17406 exports.tickIncrement = tickIncrement;
17407 exports.tickStep = tickStep;
17408 exports.transpose = transpose;
17409 exports.variance = variance;
17411 exports.axisTop = axisTop;
17412 exports.axisRight = axisRight;
17413 exports.axisBottom = axisBottom;
17414 exports.axisLeft = axisLeft;
17415 exports.brush = brush;
17416 exports.brushX = brushX;
17417 exports.brushY = brushY;
17418 exports.brushSelection = brushSelection;
17419 exports.chord = chord;
17420 exports.ribbon = ribbon;
17421 exports.nest = nest;
17422 exports.set = set$2;
17423 exports.map = map$1;
17424 exports.keys = keys;
17425 exports.values = values;
17426 exports.entries = entries;
17427 exports.color = color;
17433 exports.gray = gray;
17434 exports.cubehelix = cubehelix;
17435 exports.contours = contours;
17436 exports.contourDensity = density;
17437 exports.dispatch = dispatch;
17438 exports.drag = drag;
17439 exports.dragDisable = dragDisable;
17440 exports.dragEnable = yesdrag;
17441 exports.dsvFormat = dsvFormat;
17442 exports.csvParse = csvParse;
17443 exports.csvParseRows = csvParseRows;
17444 exports.csvFormat = csvFormat;
17445 exports.csvFormatRows = csvFormatRows;
17446 exports.tsvParse = tsvParse;
17447 exports.tsvParseRows = tsvParseRows;
17448 exports.tsvFormat = tsvFormat;
17449 exports.tsvFormatRows = tsvFormatRows;
17450 exports.easeLinear = linear$1;
17451 exports.easeQuad = quadInOut;
17452 exports.easeQuadIn = quadIn;
17453 exports.easeQuadOut = quadOut;
17454 exports.easeQuadInOut = quadInOut;
17455 exports.easeCubic = cubicInOut;
17456 exports.easeCubicIn = cubicIn;
17457 exports.easeCubicOut = cubicOut;
17458 exports.easeCubicInOut = cubicInOut;
17459 exports.easePoly = polyInOut;
17460 exports.easePolyIn = polyIn;
17461 exports.easePolyOut = polyOut;
17462 exports.easePolyInOut = polyInOut;
17463 exports.easeSin = sinInOut;
17464 exports.easeSinIn = sinIn;
17465 exports.easeSinOut = sinOut;
17466 exports.easeSinInOut = sinInOut;
17467 exports.easeExp = expInOut;
17468 exports.easeExpIn = expIn;
17469 exports.easeExpOut = expOut;
17470 exports.easeExpInOut = expInOut;
17471 exports.easeCircle = circleInOut;
17472 exports.easeCircleIn = circleIn;
17473 exports.easeCircleOut = circleOut;
17474 exports.easeCircleInOut = circleInOut;
17475 exports.easeBounce = bounceOut;
17476 exports.easeBounceIn = bounceIn;
17477 exports.easeBounceOut = bounceOut;
17478 exports.easeBounceInOut = bounceInOut;
17479 exports.easeBack = backInOut;
17480 exports.easeBackIn = backIn;
17481 exports.easeBackOut = backOut;
17482 exports.easeBackInOut = backInOut;
17483 exports.easeElastic = elasticOut;
17484 exports.easeElasticIn = elasticIn;
17485 exports.easeElasticOut = elasticOut;
17486 exports.easeElasticInOut = elasticInOut;
17487 exports.blob = blob;
17488 exports.buffer = buffer;
17490 exports.csv = csv$1;
17491 exports.tsv = tsv$1;
17492 exports.image = image;
17493 exports.json = json;
17494 exports.text = text;
17496 exports.html = html;
17498 exports.forceCenter = center$1;
17499 exports.forceCollide = collide;
17500 exports.forceLink = link;
17501 exports.forceManyBody = manyBody;
17502 exports.forceRadial = radial;
17503 exports.forceSimulation = simulation;
17504 exports.forceX = x$2;
17505 exports.forceY = y$2;
17506 exports.formatDefaultLocale = defaultLocale;
17507 exports.formatLocale = formatLocale;
17508 exports.formatSpecifier = formatSpecifier;
17509 exports.precisionFixed = precisionFixed;
17510 exports.precisionPrefix = precisionPrefix;
17511 exports.precisionRound = precisionRound;
17512 exports.geoArea = area$1;
17513 exports.geoBounds = bounds;
17514 exports.geoCentroid = centroid;
17515 exports.geoCircle = circle;
17516 exports.geoClipAntimeridian = clipAntimeridian;
17517 exports.geoClipCircle = clipCircle;
17518 exports.geoClipExtent = extent$1;
17519 exports.geoClipRectangle = clipRectangle;
17520 exports.geoContains = contains$1;
17521 exports.geoDistance = distance;
17522 exports.geoGraticule = graticule;
17523 exports.geoGraticule10 = graticule10;
17524 exports.geoInterpolate = interpolate$1;
17525 exports.geoLength = length$1;
17526 exports.geoPath = index$1;
17527 exports.geoAlbers = albers;
17528 exports.geoAlbersUsa = albersUsa;
17529 exports.geoAzimuthalEqualArea = azimuthalEqualArea;
17530 exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
17531 exports.geoAzimuthalEquidistant = azimuthalEquidistant;
17532 exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
17533 exports.geoConicConformal = conicConformal;
17534 exports.geoConicConformalRaw = conicConformalRaw;
17535 exports.geoConicEqualArea = conicEqualArea;
17536 exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
17537 exports.geoConicEquidistant = conicEquidistant;
17538 exports.geoConicEquidistantRaw = conicEquidistantRaw;
17539 exports.geoEquirectangular = equirectangular;
17540 exports.geoEquirectangularRaw = equirectangularRaw;
17541 exports.geoGnomonic = gnomonic;
17542 exports.geoGnomonicRaw = gnomonicRaw;
17543 exports.geoIdentity = identity$5;
17544 exports.geoProjection = projection;
17545 exports.geoProjectionMutator = projectionMutator;
17546 exports.geoMercator = mercator;
17547 exports.geoMercatorRaw = mercatorRaw;
17548 exports.geoNaturalEarth1 = naturalEarth1;
17549 exports.geoNaturalEarth1Raw = naturalEarth1Raw;
17550 exports.geoOrthographic = orthographic;
17551 exports.geoOrthographicRaw = orthographicRaw;
17552 exports.geoStereographic = stereographic;
17553 exports.geoStereographicRaw = stereographicRaw;
17554 exports.geoTransverseMercator = transverseMercator;
17555 exports.geoTransverseMercatorRaw = transverseMercatorRaw;
17556 exports.geoRotation = rotation;
17557 exports.geoStream = geoStream;
17558 exports.geoTransform = transform;
17559 exports.cluster = cluster;
17560 exports.hierarchy = hierarchy;
17561 exports.pack = index$2;
17562 exports.packSiblings = siblings;
17563 exports.packEnclose = enclose;
17564 exports.partition = partition;
17565 exports.stratify = stratify;
17566 exports.tree = tree;
17567 exports.treemap = index$3;
17568 exports.treemapBinary = binary;
17569 exports.treemapDice = treemapDice;
17570 exports.treemapSlice = treemapSlice;
17571 exports.treemapSliceDice = sliceDice;
17572 exports.treemapSquarify = squarify;
17573 exports.treemapResquarify = resquarify;
17574 exports.interpolate = interpolateValue;
17575 exports.interpolateArray = array$1;
17576 exports.interpolateBasis = basis$1;
17577 exports.interpolateBasisClosed = basisClosed;
17578 exports.interpolateDate = date;
17579 exports.interpolateNumber = reinterpolate;
17580 exports.interpolateObject = object;
17581 exports.interpolateRound = interpolateRound;
17582 exports.interpolateString = interpolateString;
17583 exports.interpolateTransformCss = interpolateTransformCss;
17584 exports.interpolateTransformSvg = interpolateTransformSvg;
17585 exports.interpolateZoom = interpolateZoom;
17586 exports.interpolateRgb = interpolateRgb;
17587 exports.interpolateRgbBasis = rgbBasis;
17588 exports.interpolateRgbBasisClosed = rgbBasisClosed;
17589 exports.interpolateHsl = hsl$2;
17590 exports.interpolateHslLong = hslLong;
17591 exports.interpolateLab = lab$1;
17592 exports.interpolateHcl = hcl$2;
17593 exports.interpolateHclLong = hclLong;
17594 exports.interpolateCubehelix = cubehelix$2;
17595 exports.interpolateCubehelixLong = cubehelixLong;
17596 exports.piecewise = piecewise;
17597 exports.quantize = quantize;
17598 exports.path = path;
17599 exports.polygonArea = area$2;
17600 exports.polygonCentroid = centroid$1;
17601 exports.polygonHull = hull;
17602 exports.polygonContains = contains$2;
17603 exports.polygonLength = length$2;
17604 exports.quadtree = quadtree;
17605 exports.randomUniform = uniform;
17606 exports.randomNormal = normal;
17607 exports.randomLogNormal = logNormal;
17608 exports.randomBates = bates;
17609 exports.randomIrwinHall = irwinHall;
17610 exports.randomExponential = exponential$1;
17611 exports.scaleBand = band;
17612 exports.scalePoint = point$1;
17613 exports.scaleIdentity = identity$6;
17614 exports.scaleLinear = linear$2;
17615 exports.scaleLog = log$1;
17616 exports.scaleOrdinal = ordinal;
17617 exports.scaleImplicit = implicit;
17618 exports.scalePow = pow$1;
17619 exports.scaleSqrt = sqrt$1;
17620 exports.scaleQuantile = quantile$$1;
17621 exports.scaleQuantize = quantize$1;
17622 exports.scaleThreshold = threshold$1;
17623 exports.scaleTime = time;
17624 exports.scaleUtc = utcTime;
17625 exports.scaleSequential = sequential;
17626 exports.scaleDiverging = diverging;
17627 exports.schemeCategory10 = category10;
17628 exports.schemeAccent = Accent;
17629 exports.schemeDark2 = Dark2;
17630 exports.schemePaired = Paired;
17631 exports.schemePastel1 = Pastel1;
17632 exports.schemePastel2 = Pastel2;
17633 exports.schemeSet1 = Set1;
17634 exports.schemeSet2 = Set2;
17635 exports.schemeSet3 = Set3;
17636 exports.interpolateBrBG = BrBG;
17637 exports.schemeBrBG = scheme;
17638 exports.interpolatePRGn = PRGn;
17639 exports.schemePRGn = scheme$1;
17640 exports.interpolatePiYG = PiYG;
17641 exports.schemePiYG = scheme$2;
17642 exports.interpolatePuOr = PuOr;
17643 exports.schemePuOr = scheme$3;
17644 exports.interpolateRdBu = RdBu;
17645 exports.schemeRdBu = scheme$4;
17646 exports.interpolateRdGy = RdGy;
17647 exports.schemeRdGy = scheme$5;
17648 exports.interpolateRdYlBu = RdYlBu;
17649 exports.schemeRdYlBu = scheme$6;
17650 exports.interpolateRdYlGn = RdYlGn;
17651 exports.schemeRdYlGn = scheme$7;
17652 exports.interpolateSpectral = Spectral;
17653 exports.schemeSpectral = scheme$8;
17654 exports.interpolateBuGn = BuGn;
17655 exports.schemeBuGn = scheme$9;
17656 exports.interpolateBuPu = BuPu;
17657 exports.schemeBuPu = scheme$10;
17658 exports.interpolateGnBu = GnBu;
17659 exports.schemeGnBu = scheme$11;
17660 exports.interpolateOrRd = OrRd;
17661 exports.schemeOrRd = scheme$12;
17662 exports.interpolatePuBuGn = PuBuGn;
17663 exports.schemePuBuGn = scheme$13;
17664 exports.interpolatePuBu = PuBu;
17665 exports.schemePuBu = scheme$14;
17666 exports.interpolatePuRd = PuRd;
17667 exports.schemePuRd = scheme$15;
17668 exports.interpolateRdPu = RdPu;
17669 exports.schemeRdPu = scheme$16;
17670 exports.interpolateYlGnBu = YlGnBu;
17671 exports.schemeYlGnBu = scheme$17;
17672 exports.interpolateYlGn = YlGn;
17673 exports.schemeYlGn = scheme$18;
17674 exports.interpolateYlOrBr = YlOrBr;
17675 exports.schemeYlOrBr = scheme$19;
17676 exports.interpolateYlOrRd = YlOrRd;
17677 exports.schemeYlOrRd = scheme$20;
17678 exports.interpolateBlues = Blues;
17679 exports.schemeBlues = scheme$21;
17680 exports.interpolateGreens = Greens;
17681 exports.schemeGreens = scheme$22;
17682 exports.interpolateGreys = Greys;
17683 exports.schemeGreys = scheme$23;
17684 exports.interpolatePurples = Purples;
17685 exports.schemePurples = scheme$24;
17686 exports.interpolateReds = Reds;
17687 exports.schemeReds = scheme$25;
17688 exports.interpolateOranges = Oranges;
17689 exports.schemeOranges = scheme$26;
17690 exports.interpolateCubehelixDefault = cubehelix$3;
17691 exports.interpolateRainbow = rainbow;
17692 exports.interpolateWarm = warm;
17693 exports.interpolateCool = cool;
17694 exports.interpolateSinebow = sinebow;
17695 exports.interpolateViridis = viridis;
17696 exports.interpolateMagma = magma;
17697 exports.interpolateInferno = inferno;
17698 exports.interpolatePlasma = plasma;
17699 exports.create = create;
17700 exports.creator = creator;
17701 exports.local = local;
17702 exports.matcher = matcher$1;
17703 exports.mouse = mouse;
17704 exports.namespace = namespace;
17705 exports.namespaces = namespaces;
17706 exports.clientPoint = point;
17707 exports.select = select;
17708 exports.selectAll = selectAll;
17709 exports.selection = selection;
17710 exports.selector = selector;
17711 exports.selectorAll = selectorAll;
17712 exports.style = styleValue;
17713 exports.touch = touch;
17714 exports.touches = touches;
17715 exports.window = defaultView;
17716 exports.customEvent = customEvent;
17718 exports.area = area$3;
17719 exports.line = line;
17721 exports.areaRadial = areaRadial;
17722 exports.radialArea = areaRadial;
17723 exports.lineRadial = lineRadial$1;
17724 exports.radialLine = lineRadial$1;
17725 exports.pointRadial = pointRadial;
17726 exports.linkHorizontal = linkHorizontal;
17727 exports.linkVertical = linkVertical;
17728 exports.linkRadial = linkRadial;
17729 exports.symbol = symbol;
17730 exports.symbols = symbols;
17731 exports.symbolCircle = circle$2;
17732 exports.symbolCross = cross$2;
17733 exports.symbolDiamond = diamond;
17734 exports.symbolSquare = square;
17735 exports.symbolStar = star;
17736 exports.symbolTriangle = triangle;
17737 exports.symbolWye = wye;
17738 exports.curveBasisClosed = basisClosed$1;
17739 exports.curveBasisOpen = basisOpen;
17740 exports.curveBasis = basis$2;
17741 exports.curveBundle = bundle;
17742 exports.curveCardinalClosed = cardinalClosed;
17743 exports.curveCardinalOpen = cardinalOpen;
17744 exports.curveCardinal = cardinal;
17745 exports.curveCatmullRomClosed = catmullRomClosed;
17746 exports.curveCatmullRomOpen = catmullRomOpen;
17747 exports.curveCatmullRom = catmullRom;
17748 exports.curveLinearClosed = linearClosed;
17749 exports.curveLinear = curveLinear;
17750 exports.curveMonotoneX = monotoneX;
17751 exports.curveMonotoneY = monotoneY;
17752 exports.curveNatural = natural;
17753 exports.curveStep = step;
17754 exports.curveStepAfter = stepAfter;
17755 exports.curveStepBefore = stepBefore;
17756 exports.stack = stack;
17757 exports.stackOffsetExpand = expand;
17758 exports.stackOffsetDiverging = diverging$1;
17759 exports.stackOffsetNone = none$1;
17760 exports.stackOffsetSilhouette = silhouette;
17761 exports.stackOffsetWiggle = wiggle;
17762 exports.stackOrderAscending = ascending$3;
17763 exports.stackOrderDescending = descending$2;
17764 exports.stackOrderInsideOut = insideOut;
17765 exports.stackOrderNone = none$2;
17766 exports.stackOrderReverse = reverse;
17767 exports.timeInterval = newInterval;
17768 exports.timeMillisecond = millisecond;
17769 exports.timeMilliseconds = milliseconds;
17770 exports.utcMillisecond = millisecond;
17771 exports.utcMilliseconds = milliseconds;
17772 exports.timeSecond = second;
17773 exports.timeSeconds = seconds;
17774 exports.utcSecond = second;
17775 exports.utcSeconds = seconds;
17776 exports.timeMinute = minute;
17777 exports.timeMinutes = minutes;
17778 exports.timeHour = hour;
17779 exports.timeHours = hours;
17780 exports.timeDay = day;
17781 exports.timeDays = days;
17782 exports.timeWeek = sunday;
17783 exports.timeWeeks = sundays;
17784 exports.timeSunday = sunday;
17785 exports.timeSundays = sundays;
17786 exports.timeMonday = monday;
17787 exports.timeMondays = mondays;
17788 exports.timeTuesday = tuesday;
17789 exports.timeTuesdays = tuesdays;
17790 exports.timeWednesday = wednesday;
17791 exports.timeWednesdays = wednesdays;
17792 exports.timeThursday = thursday;
17793 exports.timeThursdays = thursdays;
17794 exports.timeFriday = friday;
17795 exports.timeFridays = fridays;
17796 exports.timeSaturday = saturday;
17797 exports.timeSaturdays = saturdays;
17798 exports.timeMonth = month;
17799 exports.timeMonths = months;
17800 exports.timeYear = year;
17801 exports.timeYears = years;
17802 exports.utcMinute = utcMinute;
17803 exports.utcMinutes = utcMinutes;
17804 exports.utcHour = utcHour;
17805 exports.utcHours = utcHours;
17806 exports.utcDay = utcDay;
17807 exports.utcDays = utcDays;
17808 exports.utcWeek = utcSunday;
17809 exports.utcWeeks = utcSundays;
17810 exports.utcSunday = utcSunday;
17811 exports.utcSundays = utcSundays;
17812 exports.utcMonday = utcMonday;
17813 exports.utcMondays = utcMondays;
17814 exports.utcTuesday = utcTuesday;
17815 exports.utcTuesdays = utcTuesdays;
17816 exports.utcWednesday = utcWednesday;
17817 exports.utcWednesdays = utcWednesdays;
17818 exports.utcThursday = utcThursday;
17819 exports.utcThursdays = utcThursdays;
17820 exports.utcFriday = utcFriday;
17821 exports.utcFridays = utcFridays;
17822 exports.utcSaturday = utcSaturday;
17823 exports.utcSaturdays = utcSaturdays;
17824 exports.utcMonth = utcMonth;
17825 exports.utcMonths = utcMonths;
17826 exports.utcYear = utcYear;
17827 exports.utcYears = utcYears;
17828 exports.timeFormatDefaultLocale = defaultLocale$1;
17829 exports.timeFormatLocale = formatLocale$1;
17830 exports.isoFormat = formatIso;
17831 exports.isoParse = parseIso;
17833 exports.timer = timer;
17834 exports.timerFlush = timerFlush;
17835 exports.timeout = timeout$1;
17836 exports.interval = interval$1;
17837 exports.transition = transition;
17838 exports.active = active;
17839 exports.interrupt = interrupt;
17840 exports.voronoi = voronoi;
17841 exports.zoom = zoom;
17842 exports.zoomTransform = transform$1;
17843 exports.zoomIdentity = identity$8;
17845 Object.defineProperty(exports, '__esModule', { value: true });