1 // https://d3js.org Version 4.12.0. Copyright 2017 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';
8 var version = "4.12.0";
10 var ascending = function(a, b) {
11 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
14 var bisector = function(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 var pairs = function(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 var cross = function(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 var descending = function(a, b) {
82 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
85 var number = function(x) {
86 return x === null ? NaN : +x;
89 var variance = function(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 var deviation = function(array, f) {
122 var v = variance(array, f);
123 return v ? Math.sqrt(v) : v;
126 var extent = function(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 var constant = function(x) {
175 var identity = function(x) {
179 var sequence = function(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);
194 var e5 = Math.sqrt(10);
195 var e2 = Math.sqrt(2);
197 var ticks = function(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 var sturges = function(values) {
246 return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
249 var histogram = function() {
250 var value = identity,
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 var threshold = function(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 var freedmanDiaconis = function(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 var scott = function(values, min, max) {
335 return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
338 var max = function(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 var mean = function(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 var median = function(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 var merge = function(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 var min = function(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 var permute = function(array, indexes) {
480 var i = indexes.length, permutes = new Array(i);
481 while (i--) permutes[i] = array[indexes[i]];
485 var scan = function(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 var shuffle = function(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 var sum = function(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 var transpose = function(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];
554 var zip = function() {
555 return transpose(arguments);
558 var slice$1 = Array.prototype.slice;
560 var identity$1 = function(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 var namespace = function(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 var creator = function(name) {
852 var fullname = namespace(name);
853 return (fullname.local
855 : creatorInherit)(fullname);
865 this._ = "@" + (++nextId).toString(36);
868 Local.prototype = local$1.prototype = {
870 get: function(node) {
872 while (!(id in node)) if (!(node = node.parentNode)) return;
875 set: function(node, value) {
876 return node[this._] = value;
878 remove: function(node) {
879 return this._ in node && delete node[this._];
881 toString: function() {
886 var matcher = function(selector) {
888 return this.matches(selector);
892 if (typeof document !== "undefined") {
893 var element = document.documentElement;
894 if (!element.matches) {
895 var vendorMatches = element.webkitMatchesSelector
896 || element.msMatchesSelector
897 || element.mozMatchesSelector
898 || element.oMatchesSelector;
899 matcher = function(selector) {
901 return vendorMatches.call(this, selector);
907 var matcher$1 = matcher;
909 var filterEvents = {};
911 exports.event = null;
913 if (typeof document !== "undefined") {
914 var element$1 = document.documentElement;
915 if (!("onmouseenter" in element$1)) {
916 filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
920 function filterContextListener(listener, index, group) {
921 listener = contextListener(listener, index, group);
922 return function(event) {
923 var related = event.relatedTarget;
924 if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
925 listener.call(this, event);
930 function contextListener(listener, index, group) {
931 return function(event1) {
932 var event0 = exports.event; // Events can be reentrant (e.g., focus).
933 exports.event = event1;
935 listener.call(this, this.__data__, index, group);
937 exports.event = event0;
942 function parseTypenames$1(typenames) {
943 return typenames.trim().split(/^|\s+/).map(function(t) {
944 var name = "", i = t.indexOf(".");
945 if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
946 return {type: t, name: name};
950 function onRemove(typename) {
954 for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
955 if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
956 this.removeEventListener(o.type, o.listener, o.capture);
961 if (++i) on.length = i;
962 else delete this.__on;
966 function onAdd(typename, value, capture) {
967 var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
968 return function(d, i, group) {
969 var on = this.__on, o, listener = wrap(value, i, group);
970 if (on) for (var j = 0, m = on.length; j < m; ++j) {
971 if ((o = on[j]).type === typename.type && o.name === typename.name) {
972 this.removeEventListener(o.type, o.listener, o.capture);
973 this.addEventListener(o.type, o.listener = listener, o.capture = capture);
978 this.addEventListener(typename.type, listener, capture);
979 o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
980 if (!on) this.__on = [o];
985 var selection_on = function(typename, value, capture) {
986 var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
988 if (arguments.length < 2) {
989 var on = this.node().__on;
990 if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
991 for (i = 0, o = on[j]; i < n; ++i) {
992 if ((t = typenames[i]).type === o.type && t.name === o.name) {
1000 on = value ? onAdd : onRemove;
1001 if (capture == null) capture = false;
1002 for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
1006 function customEvent(event1, listener, that, args) {
1007 var event0 = exports.event;
1008 event1.sourceEvent = exports.event;
1009 exports.event = event1;
1011 return listener.apply(that, args);
1013 exports.event = event0;
1017 var sourceEvent = function() {
1018 var current = exports.event, source;
1019 while (source = current.sourceEvent) current = source;
1023 var point = function(node, event) {
1024 var svg = node.ownerSVGElement || node;
1026 if (svg.createSVGPoint) {
1027 var point = svg.createSVGPoint();
1028 point.x = event.clientX, point.y = event.clientY;
1029 point = point.matrixTransform(node.getScreenCTM().inverse());
1030 return [point.x, point.y];
1033 var rect = node.getBoundingClientRect();
1034 return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
1037 var mouse = function(node) {
1038 var event = sourceEvent();
1039 if (event.changedTouches) event = event.changedTouches[0];
1040 return point(node, event);
1045 var selector = function(selector) {
1046 return selector == null ? none : function() {
1047 return this.querySelector(selector);
1051 var selection_select = function(select) {
1052 if (typeof select !== "function") select = selector(select);
1054 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
1055 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
1056 if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
1057 if ("__data__" in node) subnode.__data__ = node.__data__;
1058 subgroup[i] = subnode;
1063 return new Selection(subgroups, this._parents);
1066 function empty$1() {
1070 var selectorAll = function(selector) {
1071 return selector == null ? empty$1 : function() {
1072 return this.querySelectorAll(selector);
1076 var selection_selectAll = function(select) {
1077 if (typeof select !== "function") select = selectorAll(select);
1079 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
1080 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
1081 if (node = group[i]) {
1082 subgroups.push(select.call(node, node.__data__, i, group));
1088 return new Selection(subgroups, parents);
1091 var selection_filter = function(match) {
1092 if (typeof match !== "function") match = matcher$1(match);
1094 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
1095 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
1096 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
1097 subgroup.push(node);
1102 return new Selection(subgroups, this._parents);
1105 var sparse = function(update) {
1106 return new Array(update.length);
1109 var selection_enter = function() {
1110 return new Selection(this._enter || this._groups.map(sparse), this._parents);
1113 function EnterNode(parent, datum) {
1114 this.ownerDocument = parent.ownerDocument;
1115 this.namespaceURI = parent.namespaceURI;
1117 this._parent = parent;
1118 this.__data__ = datum;
1121 EnterNode.prototype = {
1122 constructor: EnterNode,
1123 appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
1124 insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
1125 querySelector: function(selector) { return this._parent.querySelector(selector); },
1126 querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
1129 var constant$1 = function(x) {
1135 var keyPrefix = "$"; // Protect against keys like “__proto__”.
1137 function bindIndex(parent, group, enter, update, exit, data) {
1140 groupLength = group.length,
1141 dataLength = data.length;
1143 // Put any non-null nodes that fit into update.
1144 // Put any null nodes into enter.
1145 // Put any remaining data into enter.
1146 for (; i < dataLength; ++i) {
1147 if (node = group[i]) {
1148 node.__data__ = data[i];
1151 enter[i] = new EnterNode(parent, data[i]);
1155 // Put any non-null nodes that don’t fit into exit.
1156 for (; i < groupLength; ++i) {
1157 if (node = group[i]) {
1163 function bindKey(parent, group, enter, update, exit, data, key) {
1166 nodeByKeyValue = {},
1167 groupLength = group.length,
1168 dataLength = data.length,
1169 keyValues = new Array(groupLength),
1172 // Compute the key for each node.
1173 // If multiple nodes have the same key, the duplicates are added to exit.
1174 for (i = 0; i < groupLength; ++i) {
1175 if (node = group[i]) {
1176 keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
1177 if (keyValue in nodeByKeyValue) {
1180 nodeByKeyValue[keyValue] = node;
1185 // Compute the key for each datum.
1186 // If there a node associated with this key, join and add it to update.
1187 // If there is not (or the key is a duplicate), add it to enter.
1188 for (i = 0; i < dataLength; ++i) {
1189 keyValue = keyPrefix + key.call(parent, data[i], i, data);
1190 if (node = nodeByKeyValue[keyValue]) {
1192 node.__data__ = data[i];
1193 nodeByKeyValue[keyValue] = null;
1195 enter[i] = new EnterNode(parent, data[i]);
1199 // Add any remaining nodes that were not bound to data to exit.
1200 for (i = 0; i < groupLength; ++i) {
1201 if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
1207 var selection_data = function(value, key) {
1209 data = new Array(this.size()), j = -1;
1210 this.each(function(d) { data[++j] = d; });
1214 var bind = key ? bindKey : bindIndex,
1215 parents = this._parents,
1216 groups = this._groups;
1218 if (typeof value !== "function") value = constant$1(value);
1220 for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
1221 var parent = parents[j],
1223 groupLength = group.length,
1224 data = value.call(parent, parent && parent.__data__, j, parents),
1225 dataLength = data.length,
1226 enterGroup = enter[j] = new Array(dataLength),
1227 updateGroup = update[j] = new Array(dataLength),
1228 exitGroup = exit[j] = new Array(groupLength);
1230 bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
1232 // Now connect the enter nodes to their following update node, such that
1233 // appendChild can insert the materialized enter node before this node,
1234 // rather than at the end of the parent node.
1235 for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
1236 if (previous = enterGroup[i0]) {
1237 if (i0 >= i1) i1 = i0 + 1;
1238 while (!(next = updateGroup[i1]) && ++i1 < dataLength);
1239 previous._next = next || null;
1244 update = new Selection(update, parents);
1245 update._enter = enter;
1246 update._exit = exit;
1250 var selection_exit = function() {
1251 return new Selection(this._exit || this._groups.map(sparse), this._parents);
1254 var selection_merge = function(selection$$1) {
1256 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) {
1257 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
1258 if (node = group0[i] || group1[i]) {
1264 for (; j < m0; ++j) {
1265 merges[j] = groups0[j];
1268 return new Selection(merges, this._parents);
1271 var selection_order = function() {
1273 for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
1274 for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
1275 if (node = group[i]) {
1276 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
1285 var selection_sort = function(compare) {
1286 if (!compare) compare = ascending$1;
1288 function compareNode(a, b) {
1289 return a && b ? compare(a.__data__, b.__data__) : !a - !b;
1292 for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
1293 for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
1294 if (node = group[i]) {
1295 sortgroup[i] = node;
1298 sortgroup.sort(compareNode);
1301 return new Selection(sortgroups, this._parents).order();
1304 function ascending$1(a, b) {
1305 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
1308 var selection_call = function() {
1309 var callback = arguments[0];
1310 arguments[0] = this;
1311 callback.apply(null, arguments);
1315 var selection_nodes = function() {
1316 var nodes = new Array(this.size()), i = -1;
1317 this.each(function() { nodes[++i] = this; });
1321 var selection_node = function() {
1323 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1324 for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
1325 var node = group[i];
1326 if (node) return node;
1333 var selection_size = function() {
1335 this.each(function() { ++size; });
1339 var selection_empty = function() {
1340 return !this.node();
1343 var selection_each = function(callback) {
1345 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1346 for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
1347 if (node = group[i]) callback.call(node, node.__data__, i, group);
1354 function attrRemove(name) {
1356 this.removeAttribute(name);
1360 function attrRemoveNS(fullname) {
1362 this.removeAttributeNS(fullname.space, fullname.local);
1366 function attrConstant(name, value) {
1368 this.setAttribute(name, value);
1372 function attrConstantNS(fullname, value) {
1374 this.setAttributeNS(fullname.space, fullname.local, value);
1378 function attrFunction(name, value) {
1380 var v = value.apply(this, arguments);
1381 if (v == null) this.removeAttribute(name);
1382 else this.setAttribute(name, v);
1386 function attrFunctionNS(fullname, value) {
1388 var v = value.apply(this, arguments);
1389 if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
1390 else this.setAttributeNS(fullname.space, fullname.local, v);
1394 var selection_attr = function(name, value) {
1395 var fullname = namespace(name);
1397 if (arguments.length < 2) {
1398 var node = this.node();
1399 return fullname.local
1400 ? node.getAttributeNS(fullname.space, fullname.local)
1401 : node.getAttribute(fullname);
1404 return this.each((value == null
1405 ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
1406 ? (fullname.local ? attrFunctionNS : attrFunction)
1407 : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
1410 var defaultView = function(node) {
1411 return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
1412 || (node.document && node) // node is a Window
1413 || node.defaultView; // node is a Document
1416 function styleRemove(name) {
1418 this.style.removeProperty(name);
1422 function styleConstant(name, value, priority) {
1424 this.style.setProperty(name, value, priority);
1428 function styleFunction(name, value, priority) {
1430 var v = value.apply(this, arguments);
1431 if (v == null) this.style.removeProperty(name);
1432 else this.style.setProperty(name, v, priority);
1436 var selection_style = function(name, value, priority) {
1437 return arguments.length > 1
1438 ? this.each((value == null
1439 ? styleRemove : typeof value === "function"
1441 : styleConstant)(name, value, priority == null ? "" : priority))
1442 : styleValue(this.node(), name);
1445 function styleValue(node, name) {
1446 return node.style.getPropertyValue(name)
1447 || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
1450 function propertyRemove(name) {
1456 function propertyConstant(name, value) {
1462 function propertyFunction(name, value) {
1464 var v = value.apply(this, arguments);
1465 if (v == null) delete this[name];
1466 else this[name] = v;
1470 var selection_property = function(name, value) {
1471 return arguments.length > 1
1472 ? this.each((value == null
1473 ? propertyRemove : typeof value === "function"
1475 : propertyConstant)(name, value))
1476 : this.node()[name];
1479 function classArray(string) {
1480 return string.trim().split(/^|\s+/);
1483 function classList(node) {
1484 return node.classList || new ClassList(node);
1487 function ClassList(node) {
1489 this._names = classArray(node.getAttribute("class") || "");
1492 ClassList.prototype = {
1493 add: function(name) {
1494 var i = this._names.indexOf(name);
1496 this._names.push(name);
1497 this._node.setAttribute("class", this._names.join(" "));
1500 remove: function(name) {
1501 var i = this._names.indexOf(name);
1503 this._names.splice(i, 1);
1504 this._node.setAttribute("class", this._names.join(" "));
1507 contains: function(name) {
1508 return this._names.indexOf(name) >= 0;
1512 function classedAdd(node, names) {
1513 var list = classList(node), i = -1, n = names.length;
1514 while (++i < n) list.add(names[i]);
1517 function classedRemove(node, names) {
1518 var list = classList(node), i = -1, n = names.length;
1519 while (++i < n) list.remove(names[i]);
1522 function classedTrue(names) {
1524 classedAdd(this, names);
1528 function classedFalse(names) {
1530 classedRemove(this, names);
1534 function classedFunction(names, value) {
1536 (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
1540 var selection_classed = function(name, value) {
1541 var names = classArray(name + "");
1543 if (arguments.length < 2) {
1544 var list = classList(this.node()), i = -1, n = names.length;
1545 while (++i < n) if (!list.contains(names[i])) return false;
1549 return this.each((typeof value === "function"
1550 ? classedFunction : value
1552 : classedFalse)(names, value));
1555 function textRemove() {
1556 this.textContent = "";
1559 function textConstant(value) {
1561 this.textContent = value;
1565 function textFunction(value) {
1567 var v = value.apply(this, arguments);
1568 this.textContent = v == null ? "" : v;
1572 var selection_text = function(value) {
1573 return arguments.length
1574 ? this.each(value == null
1575 ? textRemove : (typeof value === "function"
1577 : textConstant)(value))
1578 : this.node().textContent;
1581 function htmlRemove() {
1582 this.innerHTML = "";
1585 function htmlConstant(value) {
1587 this.innerHTML = value;
1591 function htmlFunction(value) {
1593 var v = value.apply(this, arguments);
1594 this.innerHTML = v == null ? "" : v;
1598 var selection_html = function(value) {
1599 return arguments.length
1600 ? this.each(value == null
1601 ? htmlRemove : (typeof value === "function"
1603 : htmlConstant)(value))
1604 : this.node().innerHTML;
1608 if (this.nextSibling) this.parentNode.appendChild(this);
1611 var selection_raise = function() {
1612 return this.each(raise);
1616 if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
1619 var selection_lower = function() {
1620 return this.each(lower);
1623 var selection_append = function(name) {
1624 var create = typeof name === "function" ? name : creator(name);
1625 return this.select(function() {
1626 return this.appendChild(create.apply(this, arguments));
1630 function constantNull() {
1634 var selection_insert = function(name, before) {
1635 var create = typeof name === "function" ? name : creator(name),
1636 select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
1637 return this.select(function() {
1638 return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
1643 var parent = this.parentNode;
1644 if (parent) parent.removeChild(this);
1647 var selection_remove = function() {
1648 return this.each(remove);
1651 var selection_datum = function(value) {
1652 return arguments.length
1653 ? this.property("__data__", value)
1654 : this.node().__data__;
1657 function dispatchEvent(node, type, params) {
1658 var window = defaultView(node),
1659 event = window.CustomEvent;
1661 if (typeof event === "function") {
1662 event = new event(type, params);
1664 event = window.document.createEvent("Event");
1665 if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
1666 else event.initEvent(type, false, false);
1669 node.dispatchEvent(event);
1672 function dispatchConstant(type, params) {
1674 return dispatchEvent(this, type, params);
1678 function dispatchFunction(type, params) {
1680 return dispatchEvent(this, type, params.apply(this, arguments));
1684 var selection_dispatch = function(type, params) {
1685 return this.each((typeof params === "function"
1687 : dispatchConstant)(type, params));
1692 function Selection(groups, parents) {
1693 this._groups = groups;
1694 this._parents = parents;
1697 function selection() {
1698 return new Selection([[document.documentElement]], root);
1701 Selection.prototype = selection.prototype = {
1702 constructor: Selection,
1703 select: selection_select,
1704 selectAll: selection_selectAll,
1705 filter: selection_filter,
1706 data: selection_data,
1707 enter: selection_enter,
1708 exit: selection_exit,
1709 merge: selection_merge,
1710 order: selection_order,
1711 sort: selection_sort,
1712 call: selection_call,
1713 nodes: selection_nodes,
1714 node: selection_node,
1715 size: selection_size,
1716 empty: selection_empty,
1717 each: selection_each,
1718 attr: selection_attr,
1719 style: selection_style,
1720 property: selection_property,
1721 classed: selection_classed,
1722 text: selection_text,
1723 html: selection_html,
1724 raise: selection_raise,
1725 lower: selection_lower,
1726 append: selection_append,
1727 insert: selection_insert,
1728 remove: selection_remove,
1729 datum: selection_datum,
1731 dispatch: selection_dispatch
1734 var select = function(selector) {
1735 return typeof selector === "string"
1736 ? new Selection([[document.querySelector(selector)]], [document.documentElement])
1737 : new Selection([[selector]], root);
1740 var selectAll = function(selector) {
1741 return typeof selector === "string"
1742 ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
1743 : new Selection([selector == null ? [] : selector], root);
1746 var touch = function(node, touches, identifier) {
1747 if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
1749 for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
1750 if ((touch = touches[i]).identifier === identifier) {
1751 return point(node, touch);
1758 var touches = function(node, touches) {
1759 if (touches == null) touches = sourceEvent().touches;
1761 for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
1762 points[i] = point(node, touches[i]);
1768 function nopropagation() {
1769 exports.event.stopImmediatePropagation();
1772 var noevent = function() {
1773 exports.event.preventDefault();
1774 exports.event.stopImmediatePropagation();
1777 var dragDisable = function(view) {
1778 var root = view.document.documentElement,
1779 selection = select(view).on("dragstart.drag", noevent, true);
1780 if ("onselectstart" in root) {
1781 selection.on("selectstart.drag", noevent, true);
1783 root.__noselect = root.style.MozUserSelect;
1784 root.style.MozUserSelect = "none";
1788 function yesdrag(view, noclick) {
1789 var root = view.document.documentElement,
1790 selection = select(view).on("dragstart.drag", null);
1792 selection.on("click.drag", noevent, true);
1793 setTimeout(function() { selection.on("click.drag", null); }, 0);
1795 if ("onselectstart" in root) {
1796 selection.on("selectstart.drag", null);
1798 root.style.MozUserSelect = root.__noselect;
1799 delete root.__noselect;
1803 var constant$2 = function(x) {
1809 function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
1810 this.target = target;
1812 this.subject = subject;
1813 this.identifier = id;
1814 this.active = active;
1822 DragEvent.prototype.on = function() {
1823 var value = this._.on.apply(this._, arguments);
1824 return value === this._ ? this : value;
1827 // Ignore right-click, since that should open the context menu.
1828 function defaultFilter$1() {
1829 return !exports.event.button;
1832 function defaultContainer() {
1833 return this.parentNode;
1836 function defaultSubject(d) {
1837 return d == null ? {x: exports.event.x, y: exports.event.y} : d;
1840 function defaultTouchable() {
1841 return "ontouchstart" in this;
1844 var drag = function() {
1845 var filter = defaultFilter$1,
1846 container = defaultContainer,
1847 subject = defaultSubject,
1848 touchable = defaultTouchable,
1850 listeners = dispatch("start", "drag", "end"),
1858 function drag(selection) {
1860 .on("mousedown.drag", mousedowned)
1862 .on("touchstart.drag", touchstarted)
1863 .on("touchmove.drag", touchmoved)
1864 .on("touchend.drag touchcancel.drag", touchended)
1865 .style("touch-action", "none")
1866 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
1869 function mousedowned() {
1870 if (touchending || !filter.apply(this, arguments)) return;
1871 var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
1872 if (!gesture) return;
1873 select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
1874 dragDisable(exports.event.view);
1876 mousemoving = false;
1877 mousedownx = exports.event.clientX;
1878 mousedowny = exports.event.clientY;
1882 function mousemoved() {
1885 var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
1886 mousemoving = dx * dx + dy * dy > clickDistance2;
1888 gestures.mouse("drag");
1891 function mouseupped() {
1892 select(exports.event.view).on("mousemove.drag mouseup.drag", null);
1893 yesdrag(exports.event.view, mousemoving);
1895 gestures.mouse("end");
1898 function touchstarted() {
1899 if (!filter.apply(this, arguments)) return;
1900 var touches = exports.event.changedTouches,
1901 c = container.apply(this, arguments),
1902 n = touches.length, i, gesture;
1904 for (i = 0; i < n; ++i) {
1905 if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
1912 function touchmoved() {
1913 var touches = exports.event.changedTouches,
1914 n = touches.length, i, gesture;
1916 for (i = 0; i < n; ++i) {
1917 if (gesture = gestures[touches[i].identifier]) {
1924 function touchended() {
1925 var touches = exports.event.changedTouches,
1926 n = touches.length, i, gesture;
1928 if (touchending) clearTimeout(touchending);
1929 touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
1930 for (i = 0; i < n; ++i) {
1931 if (gesture = gestures[touches[i].identifier]) {
1938 function beforestart(id, container, point, that, args) {
1939 var p = point(container, id), s, dx, dy,
1940 sublisteners = listeners.copy();
1942 if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
1943 if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
1944 dx = s.x - p[0] || 0;
1945 dy = s.y - p[1] || 0;
1949 return function gesture(type) {
1952 case "start": gestures[id] = gesture, n = active++; break;
1953 case "end": delete gestures[id], --active; // nobreak
1954 case "drag": p = point(container, id), n = active; break;
1956 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]);
1960 drag.filter = function(_) {
1961 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
1964 drag.container = function(_) {
1965 return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
1968 drag.subject = function(_) {
1969 return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
1972 drag.touchable = function(_) {
1973 return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
1976 drag.on = function() {
1977 var value = listeners.on.apply(listeners, arguments);
1978 return value === listeners ? drag : value;
1981 drag.clickDistance = function(_) {
1982 return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
1988 var define = function(constructor, factory, prototype) {
1989 constructor.prototype = factory.prototype = prototype;
1990 prototype.constructor = constructor;
1993 function extend(parent, definition) {
1994 var prototype = Object.create(parent.prototype);
1995 for (var key in definition) prototype[key] = definition[key];
2002 var brighter = 1 / darker;
2004 var reI = "\\s*([+-]?\\d+)\\s*";
2005 var reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*";
2006 var reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*";
2007 var reHex3 = /^#([0-9a-f]{3})$/;
2008 var reHex6 = /^#([0-9a-f]{6})$/;
2009 var reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$");
2010 var reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$");
2011 var reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$");
2012 var reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$");
2013 var reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$");
2014 var reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
2017 aliceblue: 0xf0f8ff,
2018 antiquewhite: 0xfaebd7,
2020 aquamarine: 0x7fffd4,
2025 blanchedalmond: 0xffebcd,
2027 blueviolet: 0x8a2be2,
2029 burlywood: 0xdeb887,
2030 cadetblue: 0x5f9ea0,
2031 chartreuse: 0x7fff00,
2032 chocolate: 0xd2691e,
2034 cornflowerblue: 0x6495ed,
2040 darkgoldenrod: 0xb8860b,
2042 darkgreen: 0x006400,
2044 darkkhaki: 0xbdb76b,
2045 darkmagenta: 0x8b008b,
2046 darkolivegreen: 0x556b2f,
2047 darkorange: 0xff8c00,
2048 darkorchid: 0x9932cc,
2050 darksalmon: 0xe9967a,
2051 darkseagreen: 0x8fbc8f,
2052 darkslateblue: 0x483d8b,
2053 darkslategray: 0x2f4f4f,
2054 darkslategrey: 0x2f4f4f,
2055 darkturquoise: 0x00ced1,
2056 darkviolet: 0x9400d3,
2058 deepskyblue: 0x00bfff,
2061 dodgerblue: 0x1e90ff,
2062 firebrick: 0xb22222,
2063 floralwhite: 0xfffaf0,
2064 forestgreen: 0x228b22,
2066 gainsboro: 0xdcdcdc,
2067 ghostwhite: 0xf8f8ff,
2069 goldenrod: 0xdaa520,
2072 greenyellow: 0xadff2f,
2076 indianred: 0xcd5c5c,
2081 lavenderblush: 0xfff0f5,
2082 lawngreen: 0x7cfc00,
2083 lemonchiffon: 0xfffacd,
2084 lightblue: 0xadd8e6,
2085 lightcoral: 0xf08080,
2086 lightcyan: 0xe0ffff,
2087 lightgoldenrodyellow: 0xfafad2,
2088 lightgray: 0xd3d3d3,
2089 lightgreen: 0x90ee90,
2090 lightgrey: 0xd3d3d3,
2091 lightpink: 0xffb6c1,
2092 lightsalmon: 0xffa07a,
2093 lightseagreen: 0x20b2aa,
2094 lightskyblue: 0x87cefa,
2095 lightslategray: 0x778899,
2096 lightslategrey: 0x778899,
2097 lightsteelblue: 0xb0c4de,
2098 lightyellow: 0xffffe0,
2100 limegreen: 0x32cd32,
2104 mediumaquamarine: 0x66cdaa,
2105 mediumblue: 0x0000cd,
2106 mediumorchid: 0xba55d3,
2107 mediumpurple: 0x9370db,
2108 mediumseagreen: 0x3cb371,
2109 mediumslateblue: 0x7b68ee,
2110 mediumspringgreen: 0x00fa9a,
2111 mediumturquoise: 0x48d1cc,
2112 mediumvioletred: 0xc71585,
2113 midnightblue: 0x191970,
2114 mintcream: 0xf5fffa,
2115 mistyrose: 0xffe4e1,
2117 navajowhite: 0xffdead,
2121 olivedrab: 0x6b8e23,
2123 orangered: 0xff4500,
2125 palegoldenrod: 0xeee8aa,
2126 palegreen: 0x98fb98,
2127 paleturquoise: 0xafeeee,
2128 palevioletred: 0xdb7093,
2129 papayawhip: 0xffefd5,
2130 peachpuff: 0xffdab9,
2134 powderblue: 0xb0e0e6,
2136 rebeccapurple: 0x663399,
2138 rosybrown: 0xbc8f8f,
2139 royalblue: 0x4169e1,
2140 saddlebrown: 0x8b4513,
2142 sandybrown: 0xf4a460,
2148 slateblue: 0x6a5acd,
2149 slategray: 0x708090,
2150 slategrey: 0x708090,
2152 springgreen: 0x00ff7f,
2153 steelblue: 0x4682b4,
2158 turquoise: 0x40e0d0,
2162 whitesmoke: 0xf5f5f5,
2164 yellowgreen: 0x9acd32
2167 define(Color, color, {
2168 displayable: function() {
2169 return this.rgb().displayable();
2171 toString: function() {
2172 return this.rgb() + "";
2176 function color(format) {
2178 format = (format + "").trim().toLowerCase();
2179 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
2180 : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
2181 : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
2182 : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
2183 : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
2184 : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
2185 : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
2186 : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
2187 : named.hasOwnProperty(format) ? rgbn(named[format])
2188 : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
2193 return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
2196 function rgba(r, g, b, a) {
2197 if (a <= 0) r = g = b = NaN;
2198 return new Rgb(r, g, b, a);
2201 function rgbConvert(o) {
2202 if (!(o instanceof Color)) o = color(o);
2203 if (!o) return new Rgb;
2205 return new Rgb(o.r, o.g, o.b, o.opacity);
2208 function rgb(r, g, b, opacity) {
2209 return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
2212 function Rgb(r, g, b, opacity) {
2216 this.opacity = +opacity;
2219 define(Rgb, rgb, extend(Color, {
2220 brighter: function(k) {
2221 k = k == null ? brighter : Math.pow(brighter, k);
2222 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2224 darker: function(k) {
2225 k = k == null ? darker : Math.pow(darker, k);
2226 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2231 displayable: function() {
2232 return (0 <= this.r && this.r <= 255)
2233 && (0 <= this.g && this.g <= 255)
2234 && (0 <= this.b && this.b <= 255)
2235 && (0 <= this.opacity && this.opacity <= 1);
2237 toString: function() {
2238 var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
2239 return (a === 1 ? "rgb(" : "rgba(")
2240 + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
2241 + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
2242 + Math.max(0, Math.min(255, Math.round(this.b) || 0))
2243 + (a === 1 ? ")" : ", " + a + ")");
2247 function hsla(h, s, l, a) {
2248 if (a <= 0) h = s = l = NaN;
2249 else if (l <= 0 || l >= 1) h = s = NaN;
2250 else if (s <= 0) h = NaN;
2251 return new Hsl(h, s, l, a);
2254 function hslConvert(o) {
2255 if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
2256 if (!(o instanceof Color)) o = color(o);
2257 if (!o) return new Hsl;
2258 if (o instanceof Hsl) return o;
2263 min = Math.min(r, g, b),
2264 max = Math.max(r, g, b),
2267 l = (max + min) / 2;
2269 if (r === max) h = (g - b) / s + (g < b) * 6;
2270 else if (g === max) h = (b - r) / s + 2;
2271 else h = (r - g) / s + 4;
2272 s /= l < 0.5 ? max + min : 2 - max - min;
2275 s = l > 0 && l < 1 ? 0 : h;
2277 return new Hsl(h, s, l, o.opacity);
2280 function hsl(h, s, l, opacity) {
2281 return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
2284 function Hsl(h, s, l, opacity) {
2288 this.opacity = +opacity;
2291 define(Hsl, hsl, extend(Color, {
2292 brighter: function(k) {
2293 k = k == null ? brighter : Math.pow(brighter, k);
2294 return new Hsl(this.h, this.s, this.l * k, this.opacity);
2296 darker: function(k) {
2297 k = k == null ? darker : Math.pow(darker, k);
2298 return new Hsl(this.h, this.s, this.l * k, this.opacity);
2301 var h = this.h % 360 + (this.h < 0) * 360,
2302 s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
2304 m2 = l + (l < 0.5 ? l : 1 - l) * s,
2307 hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
2309 hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
2313 displayable: function() {
2314 return (0 <= this.s && this.s <= 1 || isNaN(this.s))
2315 && (0 <= this.l && this.l <= 1)
2316 && (0 <= this.opacity && this.opacity <= 1);
2320 /* From FvD 13.37, CSS Color Module Level 3 */
2321 function hsl2rgb(h, m1, m2) {
2322 return (h < 60 ? m1 + (m2 - m1) * h / 60
2324 : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
2328 var deg2rad = Math.PI / 180;
2329 var rad2deg = 180 / Math.PI;
2337 var t2 = 3 * t1 * t1;
2338 var t3 = t1 * t1 * t1;
2340 function labConvert(o) {
2341 if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
2342 if (o instanceof Hcl) {
2343 var h = o.h * deg2rad;
2344 return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
2346 if (!(o instanceof Rgb)) o = rgbConvert(o);
2347 var b = rgb2xyz(o.r),
2350 x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
2351 y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
2352 z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
2353 return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
2356 function lab(l, a, b, opacity) {
2357 return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
2360 function Lab(l, a, b, opacity) {
2364 this.opacity = +opacity;
2367 define(Lab, lab, extend(Color, {
2368 brighter: function(k) {
2369 return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
2371 darker: function(k) {
2372 return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
2375 var y = (this.l + 16) / 116,
2376 x = isNaN(this.a) ? y : y + this.a / 500,
2377 z = isNaN(this.b) ? y : y - this.b / 200;
2378 y = Yn * lab2xyz(y);
2379 x = Xn * lab2xyz(x);
2380 z = Zn * lab2xyz(z);
2382 xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
2383 xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
2384 xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
2390 function xyz2lab(t) {
2391 return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
2394 function lab2xyz(t) {
2395 return t > t1 ? t * t * t : t2 * (t - t0);
2398 function xyz2rgb(x) {
2399 return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
2402 function rgb2xyz(x) {
2403 return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
2406 function hclConvert(o) {
2407 if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
2408 if (!(o instanceof Lab)) o = labConvert(o);
2409 var h = Math.atan2(o.b, o.a) * rad2deg;
2410 return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
2413 function hcl(h, c, l, opacity) {
2414 return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
2417 function Hcl(h, c, l, opacity) {
2421 this.opacity = +opacity;
2424 define(Hcl, hcl, extend(Color, {
2425 brighter: function(k) {
2426 return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
2428 darker: function(k) {
2429 return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
2432 return labConvert(this).rgb();
2443 var BC_DA = B * C - D * A;
2445 function cubehelixConvert(o) {
2446 if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
2447 if (!(o instanceof Rgb)) o = rgbConvert(o);
2451 l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
2453 k = (E * (g - l) - C * bl) / D,
2454 s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
2455 h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
2456 return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
2459 function cubehelix(h, s, l, opacity) {
2460 return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
2463 function Cubehelix(h, s, l, opacity) {
2467 this.opacity = +opacity;
2470 define(Cubehelix, cubehelix, extend(Color, {
2471 brighter: function(k) {
2472 k = k == null ? brighter : Math.pow(brighter, k);
2473 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2475 darker: function(k) {
2476 k = k == null ? darker : Math.pow(darker, k);
2477 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2480 var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
2482 a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
2486 255 * (l + a * (A * cosh + B * sinh)),
2487 255 * (l + a * (C * cosh + D * sinh)),
2488 255 * (l + a * (E * cosh)),
2494 function basis(t1, v0, v1, v2, v3) {
2495 var t2 = t1 * t1, t3 = t2 * t1;
2496 return ((1 - 3 * t1 + 3 * t2 - t3) * v0
2497 + (4 - 6 * t2 + 3 * t3) * v1
2498 + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
2502 var basis$1 = function(values) {
2503 var n = values.length - 1;
2504 return function(t) {
2505 var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
2508 v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
2509 v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
2510 return basis((t - i / n) * n, v0, v1, v2, v3);
2514 var basisClosed = function(values) {
2515 var n = values.length;
2516 return function(t) {
2517 var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
2518 v0 = values[(i + n - 1) % n],
2520 v2 = values[(i + 1) % n],
2521 v3 = values[(i + 2) % n];
2522 return basis((t - i / n) * n, v0, v1, v2, v3);
2526 var constant$3 = function(x) {
2532 function linear(a, d) {
2533 return function(t) {
2538 function exponential(a, b, y) {
2539 return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
2540 return Math.pow(a + t * b, y);
2544 function hue(a, b) {
2546 return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
2550 return (y = +y) === 1 ? nogamma : function(a, b) {
2551 return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
2555 function nogamma(a, b) {
2557 return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
2560 var interpolateRgb = (function rgbGamma(y) {
2561 var color$$1 = gamma(y);
2563 function rgb$$1(start, end) {
2564 var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
2565 g = color$$1(start.g, end.g),
2566 b = color$$1(start.b, end.b),
2567 opacity = nogamma(start.opacity, end.opacity);
2568 return function(t) {
2572 start.opacity = opacity(t);
2577 rgb$$1.gamma = rgbGamma;
2582 function rgbSpline(spline) {
2583 return function(colors) {
2584 var n = colors.length,
2589 for (i = 0; i < n; ++i) {
2590 color$$1 = rgb(colors[i]);
2591 r[i] = color$$1.r || 0;
2592 g[i] = color$$1.g || 0;
2593 b[i] = color$$1.b || 0;
2598 color$$1.opacity = 1;
2599 return function(t) {
2603 return color$$1 + "";
2608 var rgbBasis = rgbSpline(basis$1);
2609 var rgbBasisClosed = rgbSpline(basisClosed);
2611 var array$1 = function(a, b) {
2612 var nb = b ? b.length : 0,
2613 na = a ? Math.min(nb, a.length) : 0,
2618 for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
2619 for (; i < nb; ++i) c[i] = b[i];
2621 return function(t) {
2622 for (i = 0; i < na; ++i) c[i] = x[i](t);
2627 var date = function(a, b) {
2629 return a = +a, b -= a, function(t) {
2630 return d.setTime(a + b * t), d;
2634 var reinterpolate = function(a, b) {
2635 return a = +a, b -= a, function(t) {
2640 var object = function(a, b) {
2645 if (a === null || typeof a !== "object") a = {};
2646 if (b === null || typeof b !== "object") b = {};
2650 i[k] = interpolateValue(a[k], b[k]);
2656 return function(t) {
2657 for (k in i) c[k] = i[k](t);
2662 var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
2663 var reB = new RegExp(reA.source, "g");
2672 return function(t) {
2677 var interpolateString = function(a, b) {
2678 var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
2679 am, // current match in a
2680 bm, // current match in b
2681 bs, // string preceding current number in b, if any
2682 i = -1, // index in s
2683 s = [], // string constants and placeholders
2684 q = []; // number interpolators
2686 // Coerce inputs to strings.
2687 a = a + "", b = b + "";
2689 // Interpolate pairs of numbers in a & b.
2690 while ((am = reA.exec(a))
2691 && (bm = reB.exec(b))) {
2692 if ((bs = bm.index) > bi) { // a string precedes the next number in b
2693 bs = b.slice(bi, bs);
2694 if (s[i]) s[i] += bs; // coalesce with previous string
2697 if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
2698 if (s[i]) s[i] += bm; // coalesce with previous string
2700 } else { // interpolate non-matching numbers
2702 q.push({i: i, x: reinterpolate(am, bm)});
2707 // Add remains of b.
2708 if (bi < b.length) {
2710 if (s[i]) s[i] += bs; // coalesce with previous string
2714 // Special optimization for only a single match.
2715 // Otherwise, interpolate each of the numbers and rejoin the string.
2716 return s.length < 2 ? (q[0]
2719 : (b = q.length, function(t) {
2720 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
2725 var interpolateValue = function(a, b) {
2726 var t = typeof b, c;
2727 return b == null || t === "boolean" ? constant$3(b)
2728 : (t === "number" ? reinterpolate
2729 : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
2730 : b instanceof color ? interpolateRgb
2731 : b instanceof Date ? date
2732 : Array.isArray(b) ? array$1
2733 : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
2734 : reinterpolate)(a, b);
2737 var interpolateRound = function(a, b) {
2738 return a = +a, b -= a, function(t) {
2739 return Math.round(a + b * t);
2743 var degrees = 180 / Math.PI;
2754 var decompose = function(a, b, c, d, e, f) {
2755 var scaleX, scaleY, skewX;
2756 if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
2757 if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
2758 if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
2759 if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
2763 rotate: Math.atan2(b, a) * degrees,
2764 skewX: Math.atan(skewX) * degrees,
2775 function parseCss(value) {
2776 if (value === "none") return identity$2;
2777 if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
2778 cssNode.style.transform = value;
2779 value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
2780 cssRoot.removeChild(cssNode);
2781 value = value.slice(7, -1).split(",");
2782 return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
2785 function parseSvg(value) {
2786 if (value == null) return identity$2;
2787 if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
2788 svgNode.setAttribute("transform", value);
2789 if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
2790 value = value.matrix;
2791 return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
2794 function interpolateTransform(parse, pxComma, pxParen, degParen) {
2797 return s.length ? s.pop() + " " : "";
2800 function translate(xa, ya, xb, yb, s, q) {
2801 if (xa !== xb || ya !== yb) {
2802 var i = s.push("translate(", null, pxComma, null, pxParen);
2803 q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
2804 } else if (xb || yb) {
2805 s.push("translate(" + xb + pxComma + yb + pxParen);
2809 function rotate(a, b, s, q) {
2811 if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
2812 q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: reinterpolate(a, b)});
2814 s.push(pop(s) + "rotate(" + b + degParen);
2818 function skewX(a, b, s, q) {
2820 q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: reinterpolate(a, b)});
2822 s.push(pop(s) + "skewX(" + b + degParen);
2826 function scale(xa, ya, xb, yb, s, q) {
2827 if (xa !== xb || ya !== yb) {
2828 var i = s.push(pop(s) + "scale(", null, ",", null, ")");
2829 q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
2830 } else if (xb !== 1 || yb !== 1) {
2831 s.push(pop(s) + "scale(" + xb + "," + yb + ")");
2835 return function(a, b) {
2836 var s = [], // string constants and placeholders
2837 q = []; // number interpolators
2838 a = parse(a), b = parse(b);
2839 translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
2840 rotate(a.rotate, b.rotate, s, q);
2841 skewX(a.skewX, b.skewX, s, q);
2842 scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
2844 return function(t) {
2845 var i = -1, n = q.length, o;
2846 while (++i < n) s[(o = q[i]).i] = o.x(t);
2852 var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
2853 var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
2855 var rho = Math.SQRT2;
2858 var epsilon2 = 1e-12;
2861 return ((x = Math.exp(x)) + 1 / x) / 2;
2865 return ((x = Math.exp(x)) - 1 / x) / 2;
2869 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
2872 // p0 = [ux0, uy0, w0]
2873 // p1 = [ux1, uy1, w1]
2874 var interpolateZoom = function(p0, p1) {
2875 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
2876 ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
2879 d2 = dx * dx + dy * dy,
2883 // Special case for u0 ≅ u1.
2884 if (d2 < epsilon2) {
2885 S = Math.log(w1 / w0) / rho;
2890 w0 * Math.exp(rho * t * S)
2897 var d1 = Math.sqrt(d2),
2898 b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
2899 b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
2900 r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
2901 r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
2902 S = (r1 - r0) / rho;
2906 u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
2910 w0 * coshr0 / cosh(rho * s + r0)
2915 i.duration = S * 1000;
2920 function hsl$1(hue$$1) {
2921 return function(start, end) {
2922 var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
2923 s = nogamma(start.s, end.s),
2924 l = nogamma(start.l, end.l),
2925 opacity = nogamma(start.opacity, end.opacity);
2926 return function(t) {
2930 start.opacity = opacity(t);
2936 var hsl$2 = hsl$1(hue);
2937 var hslLong = hsl$1(nogamma);
2939 function lab$1(start, end) {
2940 var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
2941 a = nogamma(start.a, end.a),
2942 b = nogamma(start.b, end.b),
2943 opacity = nogamma(start.opacity, end.opacity);
2944 return function(t) {
2948 start.opacity = opacity(t);
2953 function hcl$1(hue$$1) {
2954 return function(start, end) {
2955 var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
2956 c = nogamma(start.c, end.c),
2957 l = nogamma(start.l, end.l),
2958 opacity = nogamma(start.opacity, end.opacity);
2959 return function(t) {
2963 start.opacity = opacity(t);
2969 var hcl$2 = hcl$1(hue);
2970 var hclLong = hcl$1(nogamma);
2972 function cubehelix$1(hue$$1) {
2973 return (function cubehelixGamma(y) {
2976 function cubehelix$$1(start, end) {
2977 var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
2978 s = nogamma(start.s, end.s),
2979 l = nogamma(start.l, end.l),
2980 opacity = nogamma(start.opacity, end.opacity);
2981 return function(t) {
2984 start.l = l(Math.pow(t, y));
2985 start.opacity = opacity(t);
2990 cubehelix$$1.gamma = cubehelixGamma;
2992 return cubehelix$$1;
2996 var cubehelix$2 = cubehelix$1(hue);
2997 var cubehelixLong = cubehelix$1(nogamma);
2999 var quantize = function(interpolator, n) {
3000 var samples = new Array(n);
3001 for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
3008 var pokeDelay = 1000;
3014 var clock = typeof performance === "object" && performance.now ? performance : Date;
3015 var setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
3018 return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
3021 function clearNow() {
3031 Timer.prototype = timer.prototype = {
3033 restart: function(callback, delay, time) {
3034 if (typeof callback !== "function") throw new TypeError("callback is not a function");
3035 time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
3036 if (!this._next && taskTail !== this) {
3037 if (taskTail) taskTail._next = this;
3038 else taskHead = this;
3041 this._call = callback;
3048 this._time = Infinity;
3054 function timer(callback, delay, time) {
3056 t.restart(callback, delay, time);
3060 function timerFlush() {
3061 now(); // Get the current time, if not already set.
3062 ++frame; // Pretend we’ve set an alarm, if we haven’t already.
3063 var t = taskHead, e;
3065 if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
3072 clockNow = (clockLast = clock.now()) + clockSkew;
3073 frame = timeout = 0;
3084 var now = clock.now(), delay = now - clockLast;
3085 if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
3089 var t0, t1 = taskHead, t2, time = Infinity;
3092 if (time > t1._time) time = t1._time;
3093 t0 = t1, t1 = t1._next;
3095 t2 = t1._next, t1._next = null;
3096 t1 = t0 ? t0._next = t2 : taskHead = t2;
3103 function sleep(time) {
3104 if (frame) return; // Soonest alarm already set, or will be.
3105 if (timeout) timeout = clearTimeout(timeout);
3106 var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
3108 if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
3109 if (interval) interval = clearInterval(interval);
3111 if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
3112 frame = 1, setFrame(wake);
3116 var timeout$1 = function(callback, delay, time) {
3118 delay = delay == null ? 0 : +delay;
3119 t.restart(function(elapsed) {
3121 callback(elapsed + delay);
3126 var interval$1 = function(callback, delay, time) {
3127 var t = new Timer, total = delay;
3128 if (delay == null) return t.restart(callback, delay, time), t;
3129 delay = +delay, time = time == null ? now() : +time;
3130 t.restart(function tick(elapsed) {
3132 t.restart(tick, total += delay, time);
3138 var emptyOn = dispatch("start", "end", "interrupt");
3139 var emptyTween = [];
3149 var schedule = function(node, name, id, index, group, timing) {
3150 var schedules = node.__transition;
3151 if (!schedules) node.__transition = {};
3152 else if (id in schedules) return;
3155 index: index, // For context during callback.
3156 group: group, // For context during callback.
3160 delay: timing.delay,
3161 duration: timing.duration,
3168 function init(node, id) {
3169 var schedule = get$1(node, id);
3170 if (schedule.state > CREATED) throw new Error("too late; already scheduled");
3174 function set$1(node, id) {
3175 var schedule = get$1(node, id);
3176 if (schedule.state > STARTING) throw new Error("too late; already started");
3180 function get$1(node, id) {
3181 var schedule = node.__transition;
3182 if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
3186 function create(node, id, self) {
3187 var schedules = node.__transition,
3190 // Initialize the self timer when the transition is created.
3191 // Note the actual delay is not known until the first callback!
3192 schedules[id] = self;
3193 self.timer = timer(schedule, 0, self.time);
3195 function schedule(elapsed) {
3196 self.state = SCHEDULED;
3197 self.timer.restart(start, self.delay, self.time);
3199 // If the elapsed delay is less than our first sleep, start immediately.
3200 if (self.delay <= elapsed) start(elapsed - self.delay);
3203 function start(elapsed) {
3206 // If the state is not SCHEDULED, then we previously errored on start.
3207 if (self.state !== SCHEDULED) return stop();
3209 for (i in schedules) {
3211 if (o.name !== self.name) continue;
3213 // While this element already has a starting transition during this frame,
3214 // defer starting an interrupting transition until that transition has a
3215 // chance to tick (and possibly end); see d3/d3-transition#54!
3216 if (o.state === STARTED) return timeout$1(start);
3218 // Interrupt the active transition, if any.
3219 // Dispatch the interrupt event.
3220 if (o.state === RUNNING) {
3223 o.on.call("interrupt", node, node.__data__, o.index, o.group);
3224 delete schedules[i];
3227 // Cancel any pre-empted transitions. No interrupt event is dispatched
3228 // because the cancelled transitions never started. Note that this also
3229 // removes this transition from the pending list!
3233 delete schedules[i];
3237 // Defer the first tick to end of the current frame; see d3/d3#1576.
3238 // Note the transition may be canceled after start and before the first tick!
3239 // Note this must be scheduled before the start event; see d3/d3-transition#16!
3240 // Assuming this is successful, subsequent callbacks go straight to tick.
3241 timeout$1(function() {
3242 if (self.state === STARTED) {
3243 self.state = RUNNING;
3244 self.timer.restart(tick, self.delay, self.time);
3249 // Dispatch the start event.
3250 // Note this must be done before the tween are initialized.
3251 self.state = STARTING;
3252 self.on.call("start", node, node.__data__, self.index, self.group);
3253 if (self.state !== STARTING) return; // interrupted
3254 self.state = STARTED;
3256 // Initialize the tween, deleting null tween.
3257 tween = new Array(n = self.tween.length);
3258 for (i = 0, j = -1; i < n; ++i) {
3259 if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
3263 tween.length = j + 1;
3266 function tick(elapsed) {
3267 var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
3272 tween[i].call(null, t);
3275 // Dispatch the end event.
3276 if (self.state === ENDING) {
3277 self.on.call("end", node, node.__data__, self.index, self.group);
3285 delete schedules[id];
3286 for (var i in schedules) return; // eslint-disable-line no-unused-vars
3287 delete node.__transition;
3291 var interrupt = function(node, name) {
3292 var schedules = node.__transition,
3298 if (!schedules) return;
3300 name = name == null ? null : name + "";
3302 for (i in schedules) {
3303 if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
3304 active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
3305 schedule$$1.state = ENDED;
3306 schedule$$1.timer.stop();
3307 if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
3308 delete schedules[i];
3311 if (empty) delete node.__transition;
3314 var selection_interrupt = function(name) {
3315 return this.each(function() {
3316 interrupt(this, name);
3320 function tweenRemove(id, name) {
3323 var schedule$$1 = set$1(this, id),
3324 tween = schedule$$1.tween;
3326 // If this node shared tween with the previous node,
3327 // just assign the updated shared tween and we’re done!
3328 // Otherwise, copy-on-write.
3329 if (tween !== tween0) {
3330 tween1 = tween0 = tween;
3331 for (var i = 0, n = tween1.length; i < n; ++i) {
3332 if (tween1[i].name === name) {
3333 tween1 = tween1.slice();
3334 tween1.splice(i, 1);
3340 schedule$$1.tween = tween1;
3344 function tweenFunction(id, name, value) {
3346 if (typeof value !== "function") throw new Error;
3348 var schedule$$1 = set$1(this, id),
3349 tween = schedule$$1.tween;
3351 // If this node shared tween with the previous node,
3352 // just assign the updated shared tween and we’re done!
3353 // Otherwise, copy-on-write.
3354 if (tween !== tween0) {
3355 tween1 = (tween0 = tween).slice();
3356 for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
3357 if (tween1[i].name === name) {
3362 if (i === n) tween1.push(t);
3365 schedule$$1.tween = tween1;
3369 var transition_tween = function(name, value) {
3374 if (arguments.length < 2) {
3375 var tween = get$1(this.node(), id).tween;
3376 for (var i = 0, n = tween.length, t; i < n; ++i) {
3377 if ((t = tween[i]).name === name) {
3384 return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
3387 function tweenValue(transition, name, value) {
3388 var id = transition._id;
3390 transition.each(function() {
3391 var schedule$$1 = set$1(this, id);
3392 (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
3395 return function(node) {
3396 return get$1(node, id).value[name];
3400 var interpolate = function(a, b) {
3402 return (typeof b === "number" ? reinterpolate
3403 : b instanceof color ? interpolateRgb
3404 : (c = color(b)) ? (b = c, interpolateRgb)
3405 : interpolateString)(a, b);
3408 function attrRemove$1(name) {
3410 this.removeAttribute(name);
3414 function attrRemoveNS$1(fullname) {
3416 this.removeAttributeNS(fullname.space, fullname.local);
3420 function attrConstant$1(name, interpolate$$1, value1) {
3424 var value0 = this.getAttribute(name);
3425 return value0 === value1 ? null
3426 : value0 === value00 ? interpolate0
3427 : interpolate0 = interpolate$$1(value00 = value0, value1);
3431 function attrConstantNS$1(fullname, interpolate$$1, value1) {
3435 var value0 = this.getAttributeNS(fullname.space, fullname.local);
3436 return value0 === value1 ? null
3437 : value0 === value00 ? interpolate0
3438 : interpolate0 = interpolate$$1(value00 = value0, value1);
3442 function attrFunction$1(name, interpolate$$1, value) {
3447 var value0, value1 = value(this);
3448 if (value1 == null) return void this.removeAttribute(name);
3449 value0 = this.getAttribute(name);
3450 return value0 === value1 ? null
3451 : value0 === value00 && value1 === value10 ? interpolate0
3452 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3456 function attrFunctionNS$1(fullname, interpolate$$1, value) {
3461 var value0, value1 = value(this);
3462 if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
3463 value0 = this.getAttributeNS(fullname.space, fullname.local);
3464 return value0 === value1 ? null
3465 : value0 === value00 && value1 === value10 ? interpolate0
3466 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3470 var transition_attr = function(name, value) {
3471 var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
3472 return this.attrTween(name, typeof value === "function"
3473 ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
3474 : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
3475 : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
3478 function attrTweenNS(fullname, value) {
3480 var node = this, i = value.apply(node, arguments);
3481 return i && function(t) {
3482 node.setAttributeNS(fullname.space, fullname.local, i(t));
3485 tween._value = value;
3489 function attrTween(name, value) {
3491 var node = this, i = value.apply(node, arguments);
3492 return i && function(t) {
3493 node.setAttribute(name, i(t));
3496 tween._value = value;
3500 var transition_attrTween = function(name, value) {
3501 var key = "attr." + name;
3502 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3503 if (value == null) return this.tween(key, null);
3504 if (typeof value !== "function") throw new Error;
3505 var fullname = namespace(name);
3506 return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
3509 function delayFunction(id, value) {
3511 init(this, id).delay = +value.apply(this, arguments);
3515 function delayConstant(id, value) {
3516 return value = +value, function() {
3517 init(this, id).delay = value;
3521 var transition_delay = function(value) {
3524 return arguments.length
3525 ? this.each((typeof value === "function"
3527 : delayConstant)(id, value))
3528 : get$1(this.node(), id).delay;
3531 function durationFunction(id, value) {
3533 set$1(this, id).duration = +value.apply(this, arguments);
3537 function durationConstant(id, value) {
3538 return value = +value, function() {
3539 set$1(this, id).duration = value;
3543 var transition_duration = function(value) {
3546 return arguments.length
3547 ? this.each((typeof value === "function"
3549 : durationConstant)(id, value))
3550 : get$1(this.node(), id).duration;
3553 function easeConstant(id, value) {
3554 if (typeof value !== "function") throw new Error;
3556 set$1(this, id).ease = value;
3560 var transition_ease = function(value) {
3563 return arguments.length
3564 ? this.each(easeConstant(id, value))
3565 : get$1(this.node(), id).ease;
3568 var transition_filter = function(match) {
3569 if (typeof match !== "function") match = matcher$1(match);
3571 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3572 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
3573 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
3574 subgroup.push(node);
3579 return new Transition(subgroups, this._parents, this._name, this._id);
3582 var transition_merge = function(transition$$1) {
3583 if (transition$$1._id !== this._id) throw new Error;
3585 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) {
3586 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
3587 if (node = group0[i] || group1[i]) {
3593 for (; j < m0; ++j) {
3594 merges[j] = groups0[j];
3597 return new Transition(merges, this._parents, this._name, this._id);
3600 function start(name) {
3601 return (name + "").trim().split(/^|\s+/).every(function(t) {
3602 var i = t.indexOf(".");
3603 if (i >= 0) t = t.slice(0, i);
3604 return !t || t === "start";
3608 function onFunction(id, name, listener) {
3609 var on0, on1, sit = start(name) ? init : set$1;
3611 var schedule$$1 = sit(this, id),
3612 on = schedule$$1.on;
3614 // If this node shared a dispatch with the previous node,
3615 // just assign the updated shared dispatch and we’re done!
3616 // Otherwise, copy-on-write.
3617 if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
3619 schedule$$1.on = on1;
3623 var transition_on = function(name, listener) {
3626 return arguments.length < 2
3627 ? get$1(this.node(), id).on.on(name)
3628 : this.each(onFunction(id, name, listener));
3631 function removeFunction(id) {
3633 var parent = this.parentNode;
3634 for (var i in this.__transition) if (+i !== id) return;
3635 if (parent) parent.removeChild(this);
3639 var transition_remove = function() {
3640 return this.on("end.remove", removeFunction(this._id));
3643 var transition_select = function(select) {
3644 var name = this._name,
3647 if (typeof select !== "function") select = selector(select);
3649 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3650 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
3651 if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
3652 if ("__data__" in node) subnode.__data__ = node.__data__;
3653 subgroup[i] = subnode;
3654 schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
3659 return new Transition(subgroups, this._parents, name, id);
3662 var transition_selectAll = function(select) {
3663 var name = this._name,
3666 if (typeof select !== "function") select = selectorAll(select);
3668 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
3669 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3670 if (node = group[i]) {
3671 for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
3672 if (child = children[k]) {
3673 schedule(child, name, id, k, children, inherit);
3676 subgroups.push(children);
3682 return new Transition(subgroups, parents, name, id);
3685 var Selection$1 = selection.prototype.constructor;
3687 var transition_selection = function() {
3688 return new Selection$1(this._groups, this._parents);
3691 function styleRemove$1(name, interpolate$$1) {
3696 var value0 = styleValue(this, name),
3697 value1 = (this.style.removeProperty(name), styleValue(this, name));
3698 return value0 === value1 ? null
3699 : value0 === value00 && value1 === value10 ? interpolate0
3700 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3704 function styleRemoveEnd(name) {
3706 this.style.removeProperty(name);
3710 function styleConstant$1(name, interpolate$$1, value1) {
3714 var value0 = styleValue(this, name);
3715 return value0 === value1 ? null
3716 : value0 === value00 ? interpolate0
3717 : interpolate0 = interpolate$$1(value00 = value0, value1);
3721 function styleFunction$1(name, interpolate$$1, value) {
3726 var value0 = styleValue(this, name),
3727 value1 = value(this);
3728 if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
3729 return value0 === value1 ? null
3730 : value0 === value00 && value1 === value10 ? interpolate0
3731 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3735 var transition_style = function(name, value, priority) {
3736 var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
3737 return value == null ? this
3738 .styleTween(name, styleRemove$1(name, i))
3739 .on("end.style." + name, styleRemoveEnd(name))
3740 : this.styleTween(name, typeof value === "function"
3741 ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
3742 : styleConstant$1(name, i, value + ""), priority);
3745 function styleTween(name, value, priority) {
3747 var node = this, i = value.apply(node, arguments);
3748 return i && function(t) {
3749 node.style.setProperty(name, i(t), priority);
3752 tween._value = value;
3756 var transition_styleTween = function(name, value, priority) {
3757 var key = "style." + (name += "");
3758 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3759 if (value == null) return this.tween(key, null);
3760 if (typeof value !== "function") throw new Error;
3761 return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
3764 function textConstant$1(value) {
3766 this.textContent = value;
3770 function textFunction$1(value) {
3772 var value1 = value(this);
3773 this.textContent = value1 == null ? "" : value1;
3777 var transition_text = function(value) {
3778 return this.tween("text", typeof value === "function"
3779 ? textFunction$1(tweenValue(this, "text", value))
3780 : textConstant$1(value == null ? "" : value + ""));
3783 var transition_transition = function() {
3784 var name = this._name,
3788 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
3789 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3790 if (node = group[i]) {
3791 var inherit = get$1(node, id0);
3792 schedule(node, name, id1, i, group, {
3793 time: inherit.time + inherit.delay + inherit.duration,
3795 duration: inherit.duration,
3802 return new Transition(groups, this._parents, name, id1);
3807 function Transition(groups, parents, name, id) {
3808 this._groups = groups;
3809 this._parents = parents;
3814 function transition(name) {
3815 return selection().transition(name);
3822 var selection_prototype = selection.prototype;
3824 Transition.prototype = transition.prototype = {
3825 constructor: Transition,
3826 select: transition_select,
3827 selectAll: transition_selectAll,
3828 filter: transition_filter,
3829 merge: transition_merge,
3830 selection: transition_selection,
3831 transition: transition_transition,
3832 call: selection_prototype.call,
3833 nodes: selection_prototype.nodes,
3834 node: selection_prototype.node,
3835 size: selection_prototype.size,
3836 empty: selection_prototype.empty,
3837 each: selection_prototype.each,
3839 attr: transition_attr,
3840 attrTween: transition_attrTween,
3841 style: transition_style,
3842 styleTween: transition_styleTween,
3843 text: transition_text,
3844 remove: transition_remove,
3845 tween: transition_tween,
3846 delay: transition_delay,
3847 duration: transition_duration,
3848 ease: transition_ease
3851 function linear$1(t) {
3855 function quadIn(t) {
3859 function quadOut(t) {
3863 function quadInOut(t) {
3864 return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
3867 function cubicIn(t) {
3871 function cubicOut(t) {
3872 return --t * t * t + 1;
3875 function cubicInOut(t) {
3876 return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
3881 var polyIn = (function custom(e) {
3884 function polyIn(t) {
3885 return Math.pow(t, e);
3888 polyIn.exponent = custom;
3893 var polyOut = (function custom(e) {
3896 function polyOut(t) {
3897 return 1 - Math.pow(1 - t, e);
3900 polyOut.exponent = custom;
3905 var polyInOut = (function custom(e) {
3908 function polyInOut(t) {
3909 return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
3912 polyInOut.exponent = custom;
3918 var halfPi = pi / 2;
3921 return 1 - Math.cos(t * halfPi);
3924 function sinOut(t) {
3925 return Math.sin(t * halfPi);
3928 function sinInOut(t) {
3929 return (1 - Math.cos(pi * t)) / 2;
3933 return Math.pow(2, 10 * t - 10);
3936 function expOut(t) {
3937 return 1 - Math.pow(2, -10 * t);
3940 function expInOut(t) {
3941 return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
3944 function circleIn(t) {
3945 return 1 - Math.sqrt(1 - t * t);
3948 function circleOut(t) {
3949 return Math.sqrt(1 - --t * t);
3952 function circleInOut(t) {
3953 return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
3965 var b0 = 1 / b1 / b1;
3967 function bounceIn(t) {
3968 return 1 - bounceOut(1 - t);
3971 function bounceOut(t) {
3972 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;
3975 function bounceInOut(t) {
3976 return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
3979 var overshoot = 1.70158;
3981 var backIn = (function custom(s) {
3984 function backIn(t) {
3985 return t * t * ((s + 1) * t - s);
3988 backIn.overshoot = custom;
3993 var backOut = (function custom(s) {
3996 function backOut(t) {
3997 return --t * t * ((s + 1) * t + s) + 1;
4000 backOut.overshoot = custom;
4005 var backInOut = (function custom(s) {
4008 function backInOut(t) {
4009 return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
4012 backInOut.overshoot = custom;
4017 var tau = 2 * Math.PI;
4021 var elasticIn = (function custom(a, p) {
4022 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4024 function elasticIn(t) {
4025 return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
4028 elasticIn.amplitude = function(a) { return custom(a, p * tau); };
4029 elasticIn.period = function(p) { return custom(a, p); };
4032 })(amplitude, period);
4034 var elasticOut = (function custom(a, p) {
4035 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4037 function elasticOut(t) {
4038 return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
4041 elasticOut.amplitude = function(a) { return custom(a, p * tau); };
4042 elasticOut.period = function(p) { return custom(a, p); };
4045 })(amplitude, period);
4047 var elasticInOut = (function custom(a, p) {
4048 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4050 function elasticInOut(t) {
4051 return ((t = t * 2 - 1) < 0
4052 ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
4053 : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
4056 elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
4057 elasticInOut.period = function(p) { return custom(a, p); };
4059 return elasticInOut;
4060 })(amplitude, period);
4062 var defaultTiming = {
4063 time: null, // Set on use.
4069 function inherit(node, id) {
4071 while (!(timing = node.__transition) || !(timing = timing[id])) {
4072 if (!(node = node.parentNode)) {
4073 return defaultTiming.time = now(), defaultTiming;
4079 var selection_transition = function(name) {
4083 if (name instanceof Transition) {
4084 id = name._id, name = name._name;
4086 id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
4089 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
4090 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
4091 if (node = group[i]) {
4092 schedule(node, name, id, i, group, timing || inherit(node, id));
4097 return new Transition(groups, this._parents, name, id);
4100 selection.prototype.interrupt = selection_interrupt;
4101 selection.prototype.transition = selection_transition;
4103 var root$1 = [null];
4105 var active = function(node, name) {
4106 var schedules = node.__transition,
4111 name = name == null ? null : name + "";
4112 for (i in schedules) {
4113 if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
4114 return new Transition([[node]], root$1, name, +i);
4122 var constant$4 = function(x) {
4128 var BrushEvent = function(target, type, selection) {
4129 this.target = target;
4131 this.selection = selection;
4134 function nopropagation$1() {
4135 exports.event.stopImmediatePropagation();
4138 var noevent$1 = function() {
4139 exports.event.preventDefault();
4140 exports.event.stopImmediatePropagation();
4143 var MODE_DRAG = {name: "drag"};
4144 var MODE_SPACE = {name: "space"};
4145 var MODE_HANDLE = {name: "handle"};
4146 var MODE_CENTER = {name: "center"};
4150 handles: ["e", "w"].map(type),
4151 input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
4152 output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
4157 handles: ["n", "s"].map(type),
4158 input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
4159 output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
4164 handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
4165 input: function(xy) { return xy; },
4166 output: function(xy) { return xy; }
4170 overlay: "crosshair",
4230 // Ignore right-click, since that should open the context menu.
4231 function defaultFilter() {
4232 return !exports.event.button;
4235 function defaultExtent() {
4236 var svg = this.ownerSVGElement || this;
4237 return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
4240 // Like d3.local, but with the name “__brush” rather than auto-generated.
4241 function local(node) {
4242 while (!node.__brush) if (!(node = node.parentNode)) return;
4243 return node.__brush;
4246 function empty(extent) {
4247 return extent[0][0] === extent[1][0]
4248 || extent[0][1] === extent[1][1];
4251 function brushSelection(node) {
4252 var state = node.__brush;
4253 return state ? state.dim.output(state.selection) : null;
4264 var brush = function() {
4268 function brush$1(dim) {
4269 var extent = defaultExtent,
4270 filter = defaultFilter,
4271 listeners = dispatch(brush, "start", "brush", "end"),
4275 function brush(group) {
4277 .property("__brush", initialize)
4278 .selectAll(".overlay")
4279 .data([type("overlay")]);
4281 overlay.enter().append("rect")
4282 .attr("class", "overlay")
4283 .attr("pointer-events", "all")
4284 .attr("cursor", cursors.overlay)
4287 var extent = local(this).extent;
4289 .attr("x", extent[0][0])
4290 .attr("y", extent[0][1])
4291 .attr("width", extent[1][0] - extent[0][0])
4292 .attr("height", extent[1][1] - extent[0][1]);
4295 group.selectAll(".selection")
4296 .data([type("selection")])
4297 .enter().append("rect")
4298 .attr("class", "selection")
4299 .attr("cursor", cursors.selection)
4300 .attr("fill", "#777")
4301 .attr("fill-opacity", 0.3)
4302 .attr("stroke", "#fff")
4303 .attr("shape-rendering", "crispEdges");
4305 var handle = group.selectAll(".handle")
4306 .data(dim.handles, function(d) { return d.type; });
4308 handle.exit().remove();
4310 handle.enter().append("rect")
4311 .attr("class", function(d) { return "handle handle--" + d.type; })
4312 .attr("cursor", function(d) { return cursors[d.type]; });
4316 .attr("fill", "none")
4317 .attr("pointer-events", "all")
4318 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
4319 .on("mousedown.brush touchstart.brush", started);
4322 brush.move = function(group, selection) {
4323 if (group.selection) {
4325 .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
4326 .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
4327 .tween("brush", function() {
4329 state = that.__brush,
4330 emit = emitter(that, arguments),
4331 selection0 = state.selection,
4332 selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
4333 i = interpolateValue(selection0, selection1);
4336 state.selection = t === 1 && empty(selection1) ? null : i(t);
4341 return selection0 && selection1 ? tween : tween(1);
4348 state = that.__brush,
4349 selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
4350 emit = emitter(that, args).beforestart();
4353 state.selection = selection1 == null || empty(selection1) ? null : selection1;
4355 emit.start().brush().end();
4361 var group = select(this),
4362 selection = local(this).selection;
4365 group.selectAll(".selection")
4366 .style("display", null)
4367 .attr("x", selection[0][0])
4368 .attr("y", selection[0][1])
4369 .attr("width", selection[1][0] - selection[0][0])
4370 .attr("height", selection[1][1] - selection[0][1]);
4372 group.selectAll(".handle")
4373 .style("display", null)
4374 .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
4375 .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
4376 .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
4377 .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
4381 group.selectAll(".selection,.handle")
4382 .style("display", "none")
4385 .attr("width", null)
4386 .attr("height", null);
4390 function emitter(that, args) {
4391 return that.__brush.emitter || new Emitter(that, args);
4394 function Emitter(that, args) {
4397 this.state = that.__brush;
4401 Emitter.prototype = {
4402 beforestart: function() {
4403 if (++this.active === 1) this.state.emitter = this, this.starting = true;
4407 if (this.starting) this.starting = false, this.emit("start");
4415 if (--this.active === 0) delete this.state.emitter, this.emit("end");
4418 emit: function(type) {
4419 customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
4423 function started() {
4424 if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
4425 else if (touchending) return;
4426 if (!filter.apply(this, arguments)) return;
4429 type = exports.event.target.__data__.type,
4430 mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
4431 signX = dim === Y ? null : signsX[type],
4432 signY = dim === X ? null : signsY[type],
4433 state = local(that),
4434 extent = state.extent,
4435 selection = state.selection,
4436 W = extent[0][0], w0, w1,
4437 N = extent[0][1], n0, n1,
4438 E = extent[1][0], e0, e1,
4439 S = extent[1][1], s0, s1,
4443 shifting = signX && signY && exports.event.shiftKey,
4446 point0 = mouse(that),
4448 emit = emitter(that, arguments).beforestart();
4450 if (type === "overlay") {
4451 state.selection = selection = [
4452 [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
4453 [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
4456 w0 = selection[0][0];
4457 n0 = selection[0][1];
4458 e0 = selection[1][0];
4459 s0 = selection[1][1];
4467 var group = select(that)
4468 .attr("pointer-events", "none");
4470 var overlay = group.selectAll(".overlay")
4471 .attr("cursor", cursors[type]);
4473 if (exports.event.touches) {
4475 .on("touchmove.brush", moved, true)
4476 .on("touchend.brush touchcancel.brush", ended, true);
4478 var view = select(exports.event.view)
4479 .on("keydown.brush", keydowned, true)
4480 .on("keyup.brush", keyupped, true)
4481 .on("mousemove.brush", moved, true)
4482 .on("mouseup.brush", ended, true);
4484 dragDisable(exports.event.view);
4493 var point1 = mouse(that);
4494 if (shifting && !lockX && !lockY) {
4495 if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
4507 dx = point[0] - point0[0];
4508 dy = point[1] - point0[1];
4513 if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
4514 if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
4518 if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
4519 else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
4520 if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
4521 else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
4525 if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
4526 if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
4533 t = w0, w0 = e0, e0 = t;
4534 t = w1, w1 = e1, e1 = t;
4535 if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
4540 t = n0, n0 = s0, s0 = t;
4541 t = n1, n1 = s1, s1 = t;
4542 if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
4545 if (state.selection) selection = state.selection; // May be set by brush.move!
4546 if (lockX) w1 = selection[0][0], e1 = selection[1][0];
4547 if (lockY) n1 = selection[0][1], s1 = selection[1][1];
4549 if (selection[0][0] !== w1
4550 || selection[0][1] !== n1
4551 || selection[1][0] !== e1
4552 || selection[1][1] !== s1) {
4553 state.selection = [[w1, n1], [e1, s1]];
4561 if (exports.event.touches) {
4562 if (exports.event.touches.length) return;
4563 if (touchending) clearTimeout(touchending);
4564 touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
4565 group.on("touchmove.brush touchend.brush touchcancel.brush", null);
4567 yesdrag(exports.event.view, moving);
4568 view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
4570 group.attr("pointer-events", "all");
4571 overlay.attr("cursor", cursors.overlay);
4572 if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
4573 if (empty(selection)) state.selection = null, redraw.call(that);
4577 function keydowned() {
4578 switch (exports.event.keyCode) {
4580 shifting = signX && signY;
4584 if (mode === MODE_HANDLE) {
4585 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4586 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4592 case 32: { // SPACE; takes priority over ALT
4593 if (mode === MODE_HANDLE || mode === MODE_CENTER) {
4594 if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
4595 if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
4597 overlay.attr("cursor", cursors.selection);
4607 function keyupped() {
4608 switch (exports.event.keyCode) {
4611 lockX = lockY = shifting = false;
4617 if (mode === MODE_CENTER) {
4618 if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4619 if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4626 if (mode === MODE_SPACE) {
4627 if (exports.event.altKey) {
4628 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4629 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4632 if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4633 if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4636 overlay.attr("cursor", cursors[type]);
4647 function initialize() {
4648 var state = this.__brush || {selection: null};
4649 state.extent = extent.apply(this, arguments);
4654 brush.extent = function(_) {
4655 return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
4658 brush.filter = function(_) {
4659 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
4662 brush.handleSize = function(_) {
4663 return arguments.length ? (handleSize = +_, brush) : handleSize;
4666 brush.on = function() {
4667 var value = listeners.on.apply(listeners, arguments);
4668 return value === listeners ? brush : value;
4677 var halfPi$1 = pi$1 / 2;
4678 var tau$1 = pi$1 * 2;
4679 var max$1 = Math.max;
4681 function compareValue(compare) {
4682 return function(a, b) {
4684 a.source.value + a.target.value,
4685 b.source.value + b.target.value
4690 var chord = function() {
4693 sortSubgroups = null,
4696 function chord(matrix) {
4697 var n = matrix.length,
4699 groupIndex = sequence(n),
4702 groups = chords.groups = new Array(n),
4703 subgroups = new Array(n * n),
4712 k = 0, i = -1; while (++i < n) {
4713 x = 0, j = -1; while (++j < n) {
4717 subgroupIndex.push(sequence(n));
4722 if (sortGroups) groupIndex.sort(function(a, b) {
4723 return sortGroups(groupSums[a], groupSums[b]);
4727 if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
4728 d.sort(function(a, b) {
4729 return sortSubgroups(matrix[i][a], matrix[i][b]);
4733 // Convert the sum to scaling factor for [0, 2pi].
4734 // TODO Allow start and end angle to be specified?
4735 // TODO Allow padding to be specified as percentage?
4736 k = max$1(0, tau$1 - padAngle * n) / k;
4737 dx = k ? padAngle : tau$1 / n;
4739 // Compute the start and end angle for each group and subgroup.
4740 // Note: Opera has a bug reordering object literal properties!
4741 x = 0, i = -1; while (++i < n) {
4742 x0 = x, j = -1; while (++j < n) {
4743 var di = groupIndex[i],
4744 dj = subgroupIndex[di][j],
4748 subgroups[dj * n + di] = {
4760 value: groupSums[di]
4765 // Generate chords for each (non-empty) subgroup-subgroup link.
4766 i = -1; while (++i < n) {
4767 j = i - 1; while (++j < n) {
4768 var source = subgroups[j * n + i],
4769 target = subgroups[i * n + j];
4770 if (source.value || target.value) {
4771 chords.push(source.value < target.value
4772 ? {source: target, target: source}
4773 : {source: source, target: target});
4778 return sortChords ? chords.sort(sortChords) : chords;
4781 chord.padAngle = function(_) {
4782 return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
4785 chord.sortGroups = function(_) {
4786 return arguments.length ? (sortGroups = _, chord) : sortGroups;
4789 chord.sortSubgroups = function(_) {
4790 return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
4793 chord.sortChords = function(_) {
4794 return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
4800 var slice$2 = Array.prototype.slice;
4802 var constant$5 = function(x) {
4809 var tau$2 = 2 * pi$2;
4810 var epsilon$1 = 1e-6;
4811 var tauEpsilon = tau$2 - epsilon$1;
4814 this._x0 = this._y0 = // start of current subpath
4815 this._x1 = this._y1 = null; // end of current subpath
4823 Path.prototype = path.prototype = {
4825 moveTo: function(x, y) {
4826 this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
4828 closePath: function() {
4829 if (this._x1 !== null) {
4830 this._x1 = this._x0, this._y1 = this._y0;
4834 lineTo: function(x, y) {
4835 this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
4837 quadraticCurveTo: function(x1, y1, x, y) {
4838 this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
4840 bezierCurveTo: function(x1, y1, x2, y2, x, y) {
4841 this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
4843 arcTo: function(x1, y1, x2, y2, r) {
4844 x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
4851 l01_2 = x01 * x01 + y01 * y01;
4853 // Is the radius negative? Error.
4854 if (r < 0) throw new Error("negative radius: " + r);
4856 // Is this path empty? Move to (x1,y1).
4857 if (this._x1 === null) {
4858 this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
4861 // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
4862 else if (!(l01_2 > epsilon$1)) {}
4864 // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
4865 // Equivalently, is (x1,y1) coincident with (x2,y2)?
4866 // Or, is the radius zero? Line to (x1,y1).
4867 else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
4868 this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
4871 // Otherwise, draw an arc!
4875 l21_2 = x21 * x21 + y21 * y21,
4876 l20_2 = x20 * x20 + y20 * y20,
4877 l21 = Math.sqrt(l21_2),
4878 l01 = Math.sqrt(l01_2),
4879 l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
4883 // If the start tangent is not coincident with (x0,y0), line to.
4884 if (Math.abs(t01 - 1) > epsilon$1) {
4885 this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
4888 this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
4891 arc: function(x, y, r, a0, a1, ccw) {
4892 x = +x, y = +y, r = +r;
4893 var dx = r * Math.cos(a0),
4894 dy = r * Math.sin(a0),
4898 da = ccw ? a0 - a1 : a1 - a0;
4900 // Is the radius negative? Error.
4901 if (r < 0) throw new Error("negative radius: " + r);
4903 // Is this path empty? Move to (x0,y0).
4904 if (this._x1 === null) {
4905 this._ += "M" + x0 + "," + y0;
4908 // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
4909 else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
4910 this._ += "L" + x0 + "," + y0;
4913 // Is this arc empty? We’re done.
4916 // Does the angle go the wrong way? Flip the direction.
4917 if (da < 0) da = da % tau$2 + tau$2;
4919 // Is this a complete circle? Draw two arcs to complete the circle.
4920 if (da > tauEpsilon) {
4921 this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
4924 // Is this arc non-empty? Draw an arc!
4925 else if (da > epsilon$1) {
4926 this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
4929 rect: function(x, y, w, h) {
4930 this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
4932 toString: function() {
4937 function defaultSource(d) {
4941 function defaultTarget(d) {
4945 function defaultRadius(d) {
4949 function defaultStartAngle(d) {
4950 return d.startAngle;
4953 function defaultEndAngle(d) {
4957 var ribbon = function() {
4958 var source = defaultSource,
4959 target = defaultTarget,
4960 radius = defaultRadius,
4961 startAngle = defaultStartAngle,
4962 endAngle = defaultEndAngle,
4967 argv = slice$2.call(arguments),
4968 s = source.apply(this, argv),
4969 t = target.apply(this, argv),
4970 sr = +radius.apply(this, (argv[0] = s, argv)),
4971 sa0 = startAngle.apply(this, argv) - halfPi$1,
4972 sa1 = endAngle.apply(this, argv) - halfPi$1,
4973 sx0 = sr * cos(sa0),
4974 sy0 = sr * sin(sa0),
4975 tr = +radius.apply(this, (argv[0] = t, argv)),
4976 ta0 = startAngle.apply(this, argv) - halfPi$1,
4977 ta1 = endAngle.apply(this, argv) - halfPi$1;
4979 if (!context) context = buffer = path();
4981 context.moveTo(sx0, sy0);
4982 context.arc(0, 0, sr, sa0, sa1);
4983 if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
4984 context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
4985 context.arc(0, 0, tr, ta0, ta1);
4987 context.quadraticCurveTo(0, 0, sx0, sy0);
4988 context.closePath();
4990 if (buffer) return context = null, buffer + "" || null;
4993 ribbon.radius = function(_) {
4994 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
4997 ribbon.startAngle = function(_) {
4998 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
5001 ribbon.endAngle = function(_) {
5002 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
5005 ribbon.source = function(_) {
5006 return arguments.length ? (source = _, ribbon) : source;
5009 ribbon.target = function(_) {
5010 return arguments.length ? (target = _, ribbon) : target;
5013 ribbon.context = function(_) {
5014 return arguments.length ? (context = _ == null ? null : _, ribbon) : context;
5024 Map.prototype = map$1.prototype = {
5026 has: function(key) {
5027 return (prefix + key) in this;
5029 get: function(key) {
5030 return this[prefix + key];
5032 set: function(key, value) {
5033 this[prefix + key] = value;
5036 remove: function(key) {
5037 var property = prefix + key;
5038 return property in this && delete this[property];
5041 for (var property in this) if (property[0] === prefix) delete this[property];
5045 for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
5048 values: function() {
5050 for (var property in this) if (property[0] === prefix) values.push(this[property]);
5053 entries: function() {
5055 for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
5060 for (var property in this) if (property[0] === prefix) ++size;
5064 for (var property in this) if (property[0] === prefix) return false;
5068 for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
5072 function map$1(object, f) {
5075 // Copy constructor.
5076 if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
5078 // Index array by numeric index or specified key function.
5079 else if (Array.isArray(object)) {
5084 if (f == null) while (++i < n) map.set(i, object[i]);
5085 else while (++i < n) map.set(f(o = object[i], i, object), o);
5088 // Convert object to map.
5089 else if (object) for (var key in object) map.set(key, object[key]);
5094 var nest = function() {
5101 function apply(array, depth, createResult, setResult) {
5102 if (depth >= keys.length) {
5103 if (sortValues != null) array.sort(sortValues);
5104 return rollup != null ? rollup(array) : array;
5109 key = keys[depth++],
5112 valuesByKey = map$1(),
5114 result = createResult();
5117 if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
5120 valuesByKey.set(keyValue, [value]);
5124 valuesByKey.each(function(values, key) {
5125 setResult(result, key, apply(values, depth, createResult, setResult));
5131 function entries(map, depth) {
5132 if (++depth > keys.length) return map;
5133 var array, sortKey = sortKeys[depth - 1];
5134 if (rollup != null && depth >= keys.length) array = map.entries();
5135 else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
5136 return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
5140 object: function(array) { return apply(array, 0, createObject, setObject); },
5141 map: function(array) { return apply(array, 0, createMap, setMap); },
5142 entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
5143 key: function(d) { keys.push(d); return nest; },
5144 sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
5145 sortValues: function(order) { sortValues = order; return nest; },
5146 rollup: function(f) { rollup = f; return nest; }
5150 function createObject() {
5154 function setObject(object, key, value) {
5155 object[key] = value;
5158 function createMap() {
5162 function setMap(map, key, value) {
5163 map.set(key, value);
5168 var proto = map$1.prototype;
5170 Set.prototype = set$2.prototype = {
5173 add: function(value) {
5175 this[prefix + value] = value;
5178 remove: proto.remove,
5186 function set$2(object, f) {
5189 // Copy constructor.
5190 if (object instanceof Set) object.each(function(value) { set.add(value); });
5192 // Otherwise, assume it’s an array.
5194 var i = -1, n = object.length;
5195 if (f == null) while (++i < n) set.add(object[i]);
5196 else while (++i < n) set.add(f(object[i], i, object));
5202 var keys = function(map) {
5204 for (var key in map) keys.push(key);
5208 var values = function(map) {
5210 for (var key in map) values.push(map[key]);
5214 var entries = function(map) {
5216 for (var key in map) entries.push({key: key, value: map[key]});
5226 function objectConverter(columns) {
5227 return new Function("d", "return {" + columns.map(function(name, i) {
5228 return JSON.stringify(name) + ": d[" + i + "]";
5229 }).join(",") + "}");
5232 function customConverter(columns, f) {
5233 var object = objectConverter(columns);
5234 return function(row, i) {
5235 return f(object(row), i, columns);
5239 // Compute unique columns in order of discovery.
5240 function inferColumns(rows) {
5241 var columnSet = Object.create(null),
5244 rows.forEach(function(row) {
5245 for (var column in row) {
5246 if (!(column in columnSet)) {
5247 columns.push(columnSet[column] = column);
5255 var dsv = function(delimiter) {
5256 var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
5257 DELIMITER = delimiter.charCodeAt(0);
5259 function parse(text, f) {
5260 var convert, columns, rows = parseRows(text, function(row, i) {
5261 if (convert) return convert(row, i - 1);
5262 columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
5264 rows.columns = columns || [];
5268 function parseRows(text, f) {
5269 var rows = [], // output rows
5271 I = 0, // current character index
5272 n = 0, // current line number
5274 eof = N <= 0, // current token followed by EOF?
5275 eol = false; // current token followed by EOL?
5277 // Strip the trailing newline.
5278 if (text.charCodeAt(N - 1) === NEWLINE) --N;
5279 if (text.charCodeAt(N - 1) === RETURN) --N;
5282 if (eof) return EOF;
5283 if (eol) return eol = false, EOL;
5287 if (text.charCodeAt(j) === QUOTE) {
5288 while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
5289 if ((i = I) >= N) eof = true;
5290 else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
5291 else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5292 return text.slice(j + 1, i - 1).replace(/""/g, "\"");
5295 // Find next delimiter or newline.
5297 if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
5298 else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5299 else if (c !== DELIMITER) continue;
5300 return text.slice(j, i);
5303 // Return last token before EOF.
5304 return eof = true, text.slice(j, N);
5307 while ((t = token()) !== EOF) {
5309 while (t !== EOL && t !== EOF) row.push(t), t = token();
5310 if (f && (row = f(row, n++)) == null) continue;
5317 function format(rows, columns) {
5318 if (columns == null) columns = inferColumns(rows);
5319 return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
5320 return columns.map(function(column) {
5321 return formatValue(row[column]);
5326 function formatRows(rows) {
5327 return rows.map(formatRow).join("\n");
5330 function formatRow(row) {
5331 return row.map(formatValue).join(delimiter);
5334 function formatValue(text) {
5335 return text == null ? ""
5336 : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
5342 parseRows: parseRows,
5344 formatRows: formatRows
5350 var csvParse = csv.parse;
5351 var csvParseRows = csv.parseRows;
5352 var csvFormat = csv.format;
5353 var csvFormatRows = csv.formatRows;
5355 var tsv = dsv("\t");
5357 var tsvParse = tsv.parse;
5358 var tsvParseRows = tsv.parseRows;
5359 var tsvFormat = tsv.format;
5360 var tsvFormatRows = tsv.formatRows;
5362 var center$1 = function(x, y) {
5365 if (x == null) x = 0;
5366 if (y == null) y = 0;
5375 for (i = 0; i < n; ++i) {
5376 node = nodes[i], sx += node.x, sy += node.y;
5379 for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
5380 node = nodes[i], node.x -= sx, node.y -= sy;
5384 force.initialize = function(_) {
5388 force.x = function(_) {
5389 return arguments.length ? (x = +_, force) : x;
5392 force.y = function(_) {
5393 return arguments.length ? (y = +_, force) : y;
5399 var constant$6 = function(x) {
5405 var jiggle = function() {
5406 return (Math.random() - 0.5) * 1e-6;
5409 var tree_add = function(d) {
5410 var x = +this._x.call(null, d),
5411 y = +this._y.call(null, d);
5412 return add(this.cover(x, y), x, y, d);
5415 function add(tree, x, y, d) {
5416 if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
5434 // If the tree is empty, initialize the root as a leaf.
5435 if (!node) return tree._root = leaf, tree;
5437 // Find the existing leaf for the new point, or add it.
5438 while (node.length) {
5439 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
5440 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
5441 if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
5444 // Is the new point is exactly coincident with the existing point?
5445 xp = +tree._x.call(null, node.data);
5446 yp = +tree._y.call(null, node.data);
5447 if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
5449 // Otherwise, split the leaf node until the old and new point are separated.
5451 parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
5452 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
5453 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
5454 } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
5455 return parent[j] = node, parent[i] = leaf, tree;
5458 function addAll(data) {
5459 var d, i, n = data.length,
5469 // Compute the points and their extent.
5470 for (i = 0; i < n; ++i) {
5471 if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
5480 // If there were no (valid) points, inherit the existing extent.
5481 if (x1 < x0) x0 = this._x0, x1 = this._x1;
5482 if (y1 < y0) y0 = this._y0, y1 = this._y1;
5484 // Expand the tree to cover the new points.
5485 this.cover(x0, y0).cover(x1, y1);
5487 // Add the new points.
5488 for (i = 0; i < n; ++i) {
5489 add(this, xz[i], yz[i], data[i]);
5495 var tree_cover = function(x, y) {
5496 if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
5503 // If the quadtree has no extent, initialize them.
5504 // Integer extent are necessary so that if we later double the extent,
5505 // the existing quadrant boundaries don’t change due to floating point error!
5507 x1 = (x0 = Math.floor(x)) + 1;
5508 y1 = (y0 = Math.floor(y)) + 1;
5511 // Otherwise, double repeatedly to cover.
5512 else if (x0 > x || x > x1 || y0 > y || y > y1) {
5518 switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
5520 do parent = new Array(4), parent[i] = node, node = parent;
5521 while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
5525 do parent = new Array(4), parent[i] = node, node = parent;
5526 while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
5530 do parent = new Array(4), parent[i] = node, node = parent;
5531 while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
5535 do parent = new Array(4), parent[i] = node, node = parent;
5536 while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
5541 if (this._root && this._root.length) this._root = node;
5544 // If the quadtree covers the point already, just return.
5554 var tree_data = function() {
5556 this.visit(function(node) {
5557 if (!node.length) do data.push(node.data); while (node = node.next)
5562 var tree_extent = function(_) {
5563 return arguments.length
5564 ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
5565 : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
5568 var Quad = function(node, x0, y0, x1, y1) {
5576 var tree_find = function(x, y, radius) {
5591 if (node) quads.push(new Quad(node, x0, y0, x3, y3));
5592 if (radius == null) radius = Infinity;
5594 x0 = x - radius, y0 = y - radius;
5595 x3 = x + radius, y3 = y + radius;
5599 while (q = quads.pop()) {
5601 // Stop searching if this quadrant can’t contain a closer node.
5602 if (!(node = q.node)
5606 || (y2 = q.y1) < y0) continue;
5608 // Bisect the current quadrant.
5610 var xm = (x1 + x2) / 2,
5614 new Quad(node[3], xm, ym, x2, y2),
5615 new Quad(node[2], x1, ym, xm, y2),
5616 new Quad(node[1], xm, y1, x2, ym),
5617 new Quad(node[0], x1, y1, xm, ym)
5620 // Visit the closest quadrant first.
5621 if (i = (y >= ym) << 1 | (x >= xm)) {
5622 q = quads[quads.length - 1];
5623 quads[quads.length - 1] = quads[quads.length - 1 - i];
5624 quads[quads.length - 1 - i] = q;
5628 // Visit this point. (Visiting coincident points isn’t necessary!)
5630 var dx = x - +this._x.call(null, node.data),
5631 dy = y - +this._y.call(null, node.data),
5632 d2 = dx * dx + dy * dy;
5634 var d = Math.sqrt(radius = d2);
5635 x0 = x - d, y0 = y - d;
5636 x3 = x + d, y3 = y + d;
5645 var tree_remove = function(d) {
5646 if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
5666 // If the tree is empty, initialize the root as a leaf.
5667 if (!node) return this;
5669 // Find the leaf node for the point.
5670 // While descending, also retain the deepest parent with a non-removed sibling.
5671 if (node.length) while (true) {
5672 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
5673 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
5674 if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
5675 if (!node.length) break;
5676 if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
5679 // Find the point to remove.
5680 while (node.data !== d) if (!(previous = node, node = node.next)) return this;
5681 if (next = node.next) delete node.next;
5683 // If there are multiple coincident points, remove just the point.
5684 if (previous) return next ? previous.next = next : delete previous.next, this;
5686 // If this is the root point, remove it.
5687 if (!parent) return this._root = next, this;
5689 // Remove this leaf.
5690 next ? parent[i] = next : delete parent[i];
5692 // If the parent now contains exactly one leaf, collapse superfluous parents.
5693 if ((node = parent[0] || parent[1] || parent[2] || parent[3])
5694 && node === (parent[3] || parent[2] || parent[1] || parent[0])
5696 if (retainer) retainer[j] = node;
5697 else this._root = node;
5703 function removeAll(data) {
5704 for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
5708 var tree_root = function() {
5712 var tree_size = function() {
5714 this.visit(function(node) {
5715 if (!node.length) do ++size; while (node = node.next)
5720 var tree_visit = function(callback) {
5721 var quads = [], q, node = this._root, child, x0, y0, x1, y1;
5722 if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
5723 while (q = quads.pop()) {
5724 if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
5725 var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
5726 if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
5727 if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
5728 if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
5729 if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
5735 var tree_visitAfter = function(callback) {
5736 var quads = [], next = [], q;
5737 if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
5738 while (q = quads.pop()) {
5741 var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
5742 if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
5743 if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
5744 if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
5745 if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
5749 while (q = next.pop()) {
5750 callback(q.node, q.x0, q.y0, q.x1, q.y1);
5755 function defaultX(d) {
5759 var tree_x = function(_) {
5760 return arguments.length ? (this._x = _, this) : this._x;
5763 function defaultY(d) {
5767 var tree_y = function(_) {
5768 return arguments.length ? (this._y = _, this) : this._y;
5771 function quadtree(nodes, x, y) {
5772 var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
5773 return nodes == null ? tree : tree.addAll(nodes);
5776 function Quadtree(x, y, x0, y0, x1, y1) {
5783 this._root = undefined;
5786 function leaf_copy(leaf) {
5787 var copy = {data: leaf.data}, next = copy;
5788 while (leaf = leaf.next) next = next.next = {data: leaf.data};
5792 var treeProto = quadtree.prototype = Quadtree.prototype;
5794 treeProto.copy = function() {
5795 var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
5800 if (!node) return copy;
5802 if (!node.length) return copy._root = leaf_copy(node), copy;
5804 nodes = [{source: node, target: copy._root = new Array(4)}];
5805 while (node = nodes.pop()) {
5806 for (var i = 0; i < 4; ++i) {
5807 if (child = node.source[i]) {
5808 if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
5809 else node.target[i] = leaf_copy(child);
5817 treeProto.add = tree_add;
5818 treeProto.addAll = addAll;
5819 treeProto.cover = tree_cover;
5820 treeProto.data = tree_data;
5821 treeProto.extent = tree_extent;
5822 treeProto.find = tree_find;
5823 treeProto.remove = tree_remove;
5824 treeProto.removeAll = removeAll;
5825 treeProto.root = tree_root;
5826 treeProto.size = tree_size;
5827 treeProto.visit = tree_visit;
5828 treeProto.visitAfter = tree_visitAfter;
5829 treeProto.x = tree_x;
5830 treeProto.y = tree_y;
5840 var collide = function(radius) {
5846 if (typeof radius !== "function") radius = constant$6(radius == null ? 1 : +radius);
5849 var i, n = nodes.length,
5857 for (var k = 0; k < iterations; ++k) {
5858 tree = quadtree(nodes, x, y).visitAfter(prepare);
5859 for (i = 0; i < n; ++i) {
5861 ri = radii[node.index], ri2 = ri * ri;
5862 xi = node.x + node.vx;
5863 yi = node.y + node.vy;
5868 function apply(quad, x0, y0, x1, y1) {
5869 var data = quad.data, rj = quad.r, r = ri + rj;
5871 if (data.index > node.index) {
5872 var x = xi - data.x - data.vx,
5873 y = yi - data.y - data.vy,
5876 if (x === 0) x = jiggle(), l += x * x;
5877 if (y === 0) y = jiggle(), l += y * y;
5878 l = (r - (l = Math.sqrt(l))) / l * strength;
5879 node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
5880 node.vy += (y *= l) * r;
5881 data.vx -= x * (r = 1 - r);
5887 return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
5891 function prepare(quad) {
5892 if (quad.data) return quad.r = radii[quad.data.index];
5893 for (var i = quad.r = 0; i < 4; ++i) {
5894 if (quad[i] && quad[i].r > quad.r) {
5900 function initialize() {
5902 var i, n = nodes.length, node;
5903 radii = new Array(n);
5904 for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
5907 force.initialize = function(_) {
5912 force.iterations = function(_) {
5913 return arguments.length ? (iterations = +_, force) : iterations;
5916 force.strength = function(_) {
5917 return arguments.length ? (strength = +_, force) : strength;
5920 force.radius = function(_) {
5921 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
5931 function find(nodeById, nodeId) {
5932 var node = nodeById.get(nodeId);
5933 if (!node) throw new Error("missing: " + nodeId);
5937 var link = function(links) {
5939 strength = defaultStrength,
5941 distance = constant$6(30),
5948 if (links == null) links = [];
5950 function defaultStrength(link) {
5951 return 1 / Math.min(count[link.source.index], count[link.target.index]);
5954 function force(alpha) {
5955 for (var k = 0, n = links.length; k < iterations; ++k) {
5956 for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
5957 link = links[i], source = link.source, target = link.target;
5958 x = target.x + target.vx - source.x - source.vx || jiggle();
5959 y = target.y + target.vy - source.y - source.vy || jiggle();
5960 l = Math.sqrt(x * x + y * y);
5961 l = (l - distances[i]) / l * alpha * strengths[i];
5963 target.vx -= x * (b = bias[i]);
5965 source.vx += x * (b = 1 - b);
5971 function initialize() {
5977 nodeById = map$1(nodes, id),
5980 for (i = 0, count = new Array(n); i < m; ++i) {
5981 link = links[i], link.index = i;
5982 if (typeof link.source !== "object") link.source = find(nodeById, link.source);
5983 if (typeof link.target !== "object") link.target = find(nodeById, link.target);
5984 count[link.source.index] = (count[link.source.index] || 0) + 1;
5985 count[link.target.index] = (count[link.target.index] || 0) + 1;
5988 for (i = 0, bias = new Array(m); i < m; ++i) {
5989 link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
5992 strengths = new Array(m), initializeStrength();
5993 distances = new Array(m), initializeDistance();
5996 function initializeStrength() {
5999 for (var i = 0, n = links.length; i < n; ++i) {
6000 strengths[i] = +strength(links[i], i, links);
6004 function initializeDistance() {
6007 for (var i = 0, n = links.length; i < n; ++i) {
6008 distances[i] = +distance(links[i], i, links);
6012 force.initialize = function(_) {
6017 force.links = function(_) {
6018 return arguments.length ? (links = _, initialize(), force) : links;
6021 force.id = function(_) {
6022 return arguments.length ? (id = _, force) : id;
6025 force.iterations = function(_) {
6026 return arguments.length ? (iterations = +_, force) : iterations;
6029 force.strength = function(_) {
6030 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initializeStrength(), force) : strength;
6033 force.distance = function(_) {
6034 return arguments.length ? (distance = typeof _ === "function" ? _ : constant$6(+_), initializeDistance(), force) : distance;
6048 var initialRadius = 10;
6049 var initialAngle = Math.PI * (3 - Math.sqrt(5));
6051 var simulation = function(nodes) {
6055 alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
6057 velocityDecay = 0.6,
6059 stepper = timer(step),
6060 event = dispatch("tick", "end");
6062 if (nodes == null) nodes = [];
6066 event.call("tick", simulation);
6067 if (alpha < alphaMin) {
6069 event.call("end", simulation);
6074 var i, n = nodes.length, node;
6076 alpha += (alphaTarget - alpha) * alphaDecay;
6078 forces.each(function(force) {
6082 for (i = 0; i < n; ++i) {
6084 if (node.fx == null) node.x += node.vx *= velocityDecay;
6085 else node.x = node.fx, node.vx = 0;
6086 if (node.fy == null) node.y += node.vy *= velocityDecay;
6087 else node.y = node.fy, node.vy = 0;
6091 function initializeNodes() {
6092 for (var i = 0, n = nodes.length, node; i < n; ++i) {
6093 node = nodes[i], node.index = i;
6094 if (isNaN(node.x) || isNaN(node.y)) {
6095 var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
6096 node.x = radius * Math.cos(angle);
6097 node.y = radius * Math.sin(angle);
6099 if (isNaN(node.vx) || isNaN(node.vy)) {
6100 node.vx = node.vy = 0;
6105 function initializeForce(force) {
6106 if (force.initialize) force.initialize(nodes);
6112 return simulation = {
6115 restart: function() {
6116 return stepper.restart(step), simulation;
6120 return stepper.stop(), simulation;
6123 nodes: function(_) {
6124 return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
6127 alpha: function(_) {
6128 return arguments.length ? (alpha = +_, simulation) : alpha;
6131 alphaMin: function(_) {
6132 return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
6135 alphaDecay: function(_) {
6136 return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
6139 alphaTarget: function(_) {
6140 return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
6143 velocityDecay: function(_) {
6144 return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
6147 force: function(name, _) {
6148 return arguments.length > 1 ? (_ == null ? forces.remove(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name);
6151 find: function(x, y, radius) {
6160 if (radius == null) radius = Infinity;
6161 else radius *= radius;
6163 for (i = 0; i < n; ++i) {
6167 d2 = dx * dx + dy * dy;
6168 if (d2 < radius) closest = node, radius = d2;
6174 on: function(name, _) {
6175 return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
6180 var manyBody = function() {
6184 strength = constant$6(-30),
6187 distanceMax2 = Infinity,
6191 var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
6192 for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
6195 function initialize() {
6197 var i, n = nodes.length, node;
6198 strengths = new Array(n);
6199 for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
6202 function accumulate(quad) {
6203 var strength = 0, q, c, weight = 0, x, y, i;
6205 // For internal nodes, accumulate forces from child quadrants.
6207 for (x = y = i = 0; i < 4; ++i) {
6208 if ((q = quad[i]) && (c = Math.abs(q.value))) {
6209 strength += q.value, weight += c, x += c * q.x, y += c * q.y;
6212 quad.x = x / weight;
6213 quad.y = y / weight;
6216 // For leaf nodes, accumulate forces from coincident quadrants.
6221 do strength += strengths[q.data.index];
6225 quad.value = strength;
6228 function apply(quad, x1, _, x2) {
6229 if (!quad.value) return true;
6231 var x = quad.x - node.x,
6232 y = quad.y - node.y,
6236 // Apply the Barnes-Hut approximation if possible.
6237 // Limit forces for very close nodes; randomize direction if coincident.
6238 if (w * w / theta2 < l) {
6239 if (l < distanceMax2) {
6240 if (x === 0) x = jiggle(), l += x * x;
6241 if (y === 0) y = jiggle(), l += y * y;
6242 if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
6243 node.vx += x * quad.value * alpha / l;
6244 node.vy += y * quad.value * alpha / l;
6249 // Otherwise, process points directly.
6250 else if (quad.length || l >= distanceMax2) return;
6252 // Limit forces for very close nodes; randomize direction if coincident.
6253 if (quad.data !== node || quad.next) {
6254 if (x === 0) x = jiggle(), l += x * x;
6255 if (y === 0) y = jiggle(), l += y * y;
6256 if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
6259 do if (quad.data !== node) {
6260 w = strengths[quad.data.index] * alpha / l;
6263 } while (quad = quad.next);
6266 force.initialize = function(_) {
6271 force.strength = function(_) {
6272 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
6275 force.distanceMin = function(_) {
6276 return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
6279 force.distanceMax = function(_) {
6280 return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
6283 force.theta = function(_) {
6284 return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
6290 var radial = function(radius, x, y) {
6292 strength = constant$6(0.1),
6296 if (typeof radius !== "function") radius = constant$6(+radius);
6297 if (x == null) x = 0;
6298 if (y == null) y = 0;
6300 function force(alpha) {
6301 for (var i = 0, n = nodes.length; i < n; ++i) {
6302 var node = nodes[i],
6303 dx = node.x - x || 1e-6,
6304 dy = node.y - y || 1e-6,
6305 r = Math.sqrt(dx * dx + dy * dy),
6306 k = (radiuses[i] - r) * strengths[i] * alpha / r;
6312 function initialize() {
6314 var i, n = nodes.length;
6315 strengths = new Array(n);
6316 radiuses = new Array(n);
6317 for (i = 0; i < n; ++i) {
6318 radiuses[i] = +radius(nodes[i], i, nodes);
6319 strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
6323 force.initialize = function(_) {
6324 nodes = _, initialize();
6327 force.strength = function(_) {
6328 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
6331 force.radius = function(_) {
6332 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
6335 force.x = function(_) {
6336 return arguments.length ? (x = +_, force) : x;
6339 force.y = function(_) {
6340 return arguments.length ? (y = +_, force) : y;
6346 var x$2 = function(x) {
6347 var strength = constant$6(0.1),
6352 if (typeof x !== "function") x = constant$6(x == null ? 0 : +x);
6354 function force(alpha) {
6355 for (var i = 0, n = nodes.length, node; i < n; ++i) {
6356 node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
6360 function initialize() {
6362 var i, n = nodes.length;
6363 strengths = new Array(n);
6365 for (i = 0; i < n; ++i) {
6366 strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
6370 force.initialize = function(_) {
6375 force.strength = function(_) {
6376 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
6379 force.x = function(_) {
6380 return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : x;
6386 var y$2 = function(y) {
6387 var strength = constant$6(0.1),
6392 if (typeof y !== "function") y = constant$6(y == null ? 0 : +y);
6394 function force(alpha) {
6395 for (var i = 0, n = nodes.length, node; i < n; ++i) {
6396 node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
6400 function initialize() {
6402 var i, n = nodes.length;
6403 strengths = new Array(n);
6405 for (i = 0; i < n; ++i) {
6406 strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
6410 force.initialize = function(_) {
6415 force.strength = function(_) {
6416 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
6419 force.y = function(_) {
6420 return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : y;
6426 // Computes the decimal coefficient and exponent of the specified number x with
6427 // significant digits p, where x is positive and p is in [1, 21] or undefined.
6428 // For example, formatDecimal(1.23) returns ["123", 0].
6429 var formatDecimal = function(x, p) {
6430 if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
6431 var i, coefficient = x.slice(0, i);
6433 // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
6434 // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
6436 coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
6441 var exponent$1 = function(x) {
6442 return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
6445 var formatGroup = function(grouping, thousands) {
6446 return function(value, width) {
6447 var i = value.length,
6453 while (i > 0 && g > 0) {
6454 if (length + g + 1 > width) g = Math.max(1, width - length);
6455 t.push(value.substring(i -= g, i + g));
6456 if ((length += g + 1) > width) break;
6457 g = grouping[j = (j + 1) % grouping.length];
6460 return t.reverse().join(thousands);
6464 var formatNumerals = function(numerals) {
6465 return function(value) {
6466 return value.replace(/[0-9]/g, function(i) {
6467 return numerals[+i];
6472 var formatDefault = function(x, p) {
6473 x = x.toPrecision(p);
6475 out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
6477 case ".": i0 = i1 = i; break;
6478 case "0": if (i0 === 0) i0 = i; i1 = i; break;
6479 case "e": break out;
6480 default: if (i0 > 0) i0 = 0; break;
6484 return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
6489 var formatPrefixAuto = function(x, p) {
6490 var d = formatDecimal(x, p);
6491 if (!d) return x + "";
6492 var coefficient = d[0],
6494 i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
6495 n = coefficient.length;
6496 return i === n ? coefficient
6497 : i > n ? coefficient + new Array(i - n + 1).join("0")
6498 : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
6499 : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
6502 var formatRounded = function(x, p) {
6503 var d = formatDecimal(x, p);
6504 if (!d) return x + "";
6505 var coefficient = d[0],
6507 return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
6508 : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
6509 : coefficient + new Array(exponent - coefficient.length + 2).join("0");
6514 "%": function(x, p) { return (x * 100).toFixed(p); },
6515 "b": function(x) { return Math.round(x).toString(2); },
6516 "c": function(x) { return x + ""; },
6517 "d": function(x) { return Math.round(x).toString(10); },
6518 "e": function(x, p) { return x.toExponential(p); },
6519 "f": function(x, p) { return x.toFixed(p); },
6520 "g": function(x, p) { return x.toPrecision(p); },
6521 "o": function(x) { return Math.round(x).toString(8); },
6522 "p": function(x, p) { return formatRounded(x * 100, p); },
6524 "s": formatPrefixAuto,
6525 "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
6526 "x": function(x) { return Math.round(x).toString(16); }
6529 // [[fill]align][sign][symbol][0][width][,][.precision][type]
6530 var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
6532 function formatSpecifier(specifier) {
6533 return new FormatSpecifier(specifier);
6536 formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
6538 function FormatSpecifier(specifier) {
6539 if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
6542 fill = match[1] || " ",
6543 align = match[2] || ">",
6544 sign = match[3] || "-",
6545 symbol = match[4] || "",
6547 width = match[6] && +match[6],
6549 precision = match[8] && +match[8].slice(1),
6550 type = match[9] || "";
6552 // The "n" type is an alias for ",g".
6553 if (type === "n") comma = true, type = "g";
6555 // Map invalid types to the default format.
6556 else if (!formatTypes[type]) type = "";
6558 // If zero fill is specified, padding goes after sign and before digits.
6559 if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
6564 this.symbol = symbol;
6568 this.precision = precision;
6572 FormatSpecifier.prototype.toString = function() {
6577 + (this.zero ? "0" : "")
6578 + (this.width == null ? "" : Math.max(1, this.width | 0))
6579 + (this.comma ? "," : "")
6580 + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
6584 var identity$3 = function(x) {
6588 var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
6590 var formatLocale = function(locale) {
6591 var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
6592 currency = locale.currency,
6593 decimal = locale.decimal,
6594 numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
6595 percent = locale.percent || "%";
6597 function newFormat(specifier) {
6598 specifier = formatSpecifier(specifier);
6600 var fill = specifier.fill,
6601 align = specifier.align,
6602 sign = specifier.sign,
6603 symbol = specifier.symbol,
6604 zero = specifier.zero,
6605 width = specifier.width,
6606 comma = specifier.comma,
6607 precision = specifier.precision,
6608 type = specifier.type;
6610 // Compute the prefix and suffix.
6611 // For SI-prefix, the suffix is lazily computed.
6612 var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
6613 suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
6615 // What format function should we use?
6616 // Is this an integer type?
6617 // Can this type generate exponential notation?
6618 var formatType = formatTypes[type],
6619 maybeSuffix = !type || /[defgprs%]/.test(type);
6621 // Set the default precision if not specified,
6622 // or clamp the specified precision to the supported range.
6623 // For significant precision, it must be in [1, 21].
6624 // For fixed precision, it must be in [0, 20].
6625 precision = precision == null ? (type ? 6 : 12)
6626 : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
6627 : Math.max(0, Math.min(20, precision));
6629 function format(value) {
6630 var valuePrefix = prefix,
6631 valueSuffix = suffix,
6635 valueSuffix = formatType(value) + valueSuffix;
6640 // Perform the initial formatting.
6641 var valueNegative = value < 0;
6642 value = formatType(Math.abs(value), precision);
6644 // If a negative value rounds to zero during formatting, treat as positive.
6645 if (valueNegative && +value === 0) valueNegative = false;
6647 // Compute the prefix and suffix.
6648 valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
6649 valueSuffix = valueSuffix + (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + (valueNegative && sign === "(" ? ")" : "");
6651 // Break the formatted value into the integer “value” part that can be
6652 // grouped, and fractional or exponential “suffix” part that is not.
6654 i = -1, n = value.length;
6656 if (c = value.charCodeAt(i), 48 > c || c > 57) {
6657 valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
6658 value = value.slice(0, i);
6665 // If the fill character is not "0", grouping is applied before padding.
6666 if (comma && !zero) value = group(value, Infinity);
6668 // Compute the padding.
6669 var length = valuePrefix.length + value.length + valueSuffix.length,
6670 padding = length < width ? new Array(width - length + 1).join(fill) : "";
6672 // If the fill character is "0", grouping is applied after padding.
6673 if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
6675 // Reconstruct the final output based on the desired alignment.
6677 case "<": value = valuePrefix + value + valueSuffix + padding; break;
6678 case "=": value = valuePrefix + padding + value + valueSuffix; break;
6679 case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
6680 default: value = padding + valuePrefix + value + valueSuffix; break;
6683 return numerals(value);
6686 format.toString = function() {
6687 return specifier + "";
6693 function formatPrefix(specifier, value) {
6694 var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
6695 e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
6696 k = Math.pow(10, -e),
6697 prefix = prefixes[8 + e / 3];
6698 return function(value) {
6699 return f(k * value) + prefix;
6705 formatPrefix: formatPrefix
6720 function defaultLocale(definition) {
6721 locale = formatLocale(definition);
6722 exports.format = locale.format;
6723 exports.formatPrefix = locale.formatPrefix;
6727 var precisionFixed = function(step) {
6728 return Math.max(0, -exponent$1(Math.abs(step)));
6731 var precisionPrefix = function(step, value) {
6732 return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
6735 var precisionRound = function(step, max) {
6736 step = Math.abs(step), max = Math.abs(max) - step;
6737 return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
6740 // Adds floating point numbers with twice the normal precision.
6741 // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
6742 // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
6744 // Code adapted from GeographicLib by Charles F. F. Karney,
6745 // http://geographiclib.sourceforge.net/
6747 var adder = function() {
6758 this.s = // rounded value
6759 this.t = 0; // exact error
6762 add$1(temp, y, this.t);
6763 add$1(this, temp.s, this.s);
6764 if (this.s) this.t += temp.t;
6765 else this.s = temp.t;
6767 valueOf: function() {
6772 var temp = new Adder;
6774 function add$1(adder, a, b) {
6775 var x = adder.s = a + b,
6778 adder.t = (a - av) + (b - bv);
6781 var epsilon$2 = 1e-6;
6782 var epsilon2$1 = 1e-12;
6784 var halfPi$2 = pi$3 / 2;
6785 var quarterPi = pi$3 / 4;
6786 var tau$3 = pi$3 * 2;
6788 var degrees$1 = 180 / pi$3;
6789 var radians = pi$3 / 180;
6792 var atan = Math.atan;
6793 var atan2 = Math.atan2;
6794 var cos$1 = Math.cos;
6795 var ceil = Math.ceil;
6800 var sin$1 = Math.sin;
6801 var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
6802 var sqrt = Math.sqrt;
6806 return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
6810 return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
6813 function haversin(x) {
6814 return (x = sin$1(x / 2)) * x;
6817 function noop$1() {}
6819 function streamGeometry(geometry, stream) {
6820 if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
6821 streamGeometryType[geometry.type](geometry, stream);
6825 var streamObjectType = {
6826 Feature: function(object, stream) {
6827 streamGeometry(object.geometry, stream);
6829 FeatureCollection: function(object, stream) {
6830 var features = object.features, i = -1, n = features.length;
6831 while (++i < n) streamGeometry(features[i].geometry, stream);
6835 var streamGeometryType = {
6836 Sphere: function(object, stream) {
6839 Point: function(object, stream) {
6840 object = object.coordinates;
6841 stream.point(object[0], object[1], object[2]);
6843 MultiPoint: function(object, stream) {
6844 var coordinates = object.coordinates, i = -1, n = coordinates.length;
6845 while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
6847 LineString: function(object, stream) {
6848 streamLine(object.coordinates, stream, 0);
6850 MultiLineString: function(object, stream) {
6851 var coordinates = object.coordinates, i = -1, n = coordinates.length;
6852 while (++i < n) streamLine(coordinates[i], stream, 0);
6854 Polygon: function(object, stream) {
6855 streamPolygon(object.coordinates, stream);
6857 MultiPolygon: function(object, stream) {
6858 var coordinates = object.coordinates, i = -1, n = coordinates.length;
6859 while (++i < n) streamPolygon(coordinates[i], stream);
6861 GeometryCollection: function(object, stream) {
6862 var geometries = object.geometries, i = -1, n = geometries.length;
6863 while (++i < n) streamGeometry(geometries[i], stream);
6867 function streamLine(coordinates, stream, closed) {
6868 var i = -1, n = coordinates.length - closed, coordinate;
6870 while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
6874 function streamPolygon(coordinates, stream) {
6875 var i = -1, n = coordinates.length;
6876 stream.polygonStart();
6877 while (++i < n) streamLine(coordinates[i], stream, 1);
6878 stream.polygonEnd();
6881 var geoStream = function(object, stream) {
6882 if (object && streamObjectType.hasOwnProperty(object.type)) {
6883 streamObjectType[object.type](object, stream);
6885 streamGeometry(object, stream);
6889 var areaRingSum = adder();
6891 var areaSum = adder();
6902 polygonStart: function() {
6903 areaRingSum.reset();
6904 areaStream.lineStart = areaRingStart;
6905 areaStream.lineEnd = areaRingEnd;
6907 polygonEnd: function() {
6908 var areaRing = +areaRingSum;
6909 areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
6910 this.lineStart = this.lineEnd = this.point = noop$1;
6912 sphere: function() {
6917 function areaRingStart() {
6918 areaStream.point = areaPointFirst;
6921 function areaRingEnd() {
6922 areaPoint(lambda00, phi00);
6925 function areaPointFirst(lambda, phi) {
6926 areaStream.point = areaPoint;
6927 lambda00 = lambda, phi00 = phi;
6928 lambda *= radians, phi *= radians;
6929 lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
6932 function areaPoint(lambda, phi) {
6933 lambda *= radians, phi *= radians;
6934 phi = phi / 2 + quarterPi; // half the angular distance from south pole
6936 // Spherical excess E for a spherical triangle with vertices: south pole,
6937 // previous point, current point. Uses a formula derived from Cagnoli’s
6938 // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
6939 var dLambda = lambda - lambda0,
6940 sdLambda = dLambda >= 0 ? 1 : -1,
6941 adLambda = sdLambda * dLambda,
6942 cosPhi = cos$1(phi),
6943 sinPhi = sin$1(phi),
6944 k = sinPhi0 * sinPhi,
6945 u = cosPhi0 * cosPhi + k * cos$1(adLambda),
6946 v = k * sdLambda * sin$1(adLambda);
6947 areaRingSum.add(atan2(v, u));
6949 // Advance the previous points.
6950 lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
6953 var area = function(object) {
6955 geoStream(object, areaStream);
6959 function spherical(cartesian) {
6960 return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
6963 function cartesian(spherical) {
6964 var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
6965 return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
6968 function cartesianDot(a, b) {
6969 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
6972 function cartesianCross(a, b) {
6973 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]];
6977 function cartesianAddInPlace(a, b) {
6978 a[0] += b[0], a[1] += b[1], a[2] += b[2];
6981 function cartesianScale(vector, k) {
6982 return [vector[0] * k, vector[1] * k, vector[2] * k];
6986 function cartesianNormalizeInPlace(d) {
6987 var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
6988 d[0] /= l, d[1] /= l, d[2] /= l;
6999 var deltaSum = adder();
7003 var boundsStream = {
7005 lineStart: boundsLineStart,
7006 lineEnd: boundsLineEnd,
7007 polygonStart: function() {
7008 boundsStream.point = boundsRingPoint;
7009 boundsStream.lineStart = boundsRingStart;
7010 boundsStream.lineEnd = boundsRingEnd;
7012 areaStream.polygonStart();
7014 polygonEnd: function() {
7015 areaStream.polygonEnd();
7016 boundsStream.point = boundsPoint;
7017 boundsStream.lineStart = boundsLineStart;
7018 boundsStream.lineEnd = boundsLineEnd;
7019 if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
7020 else if (deltaSum > epsilon$2) phi1 = 90;
7021 else if (deltaSum < -epsilon$2) phi0 = -90;
7022 range[0] = lambda0$1, range[1] = lambda1;
7026 function boundsPoint(lambda, phi) {
7027 ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7028 if (phi < phi0) phi0 = phi;
7029 if (phi > phi1) phi1 = phi;
7032 function linePoint(lambda, phi) {
7033 var p = cartesian([lambda * radians, phi * radians]);
7035 var normal = cartesianCross(p0, p),
7036 equatorial = [normal[1], -normal[0], 0],
7037 inflection = cartesianCross(equatorial, normal);
7038 cartesianNormalizeInPlace(inflection);
7039 inflection = spherical(inflection);
7040 var delta = lambda - lambda2,
7041 sign$$1 = delta > 0 ? 1 : -1,
7042 lambdai = inflection[0] * degrees$1 * sign$$1,
7044 antimeridian = abs(delta) > 180;
7045 if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
7046 phii = inflection[1] * degrees$1;
7047 if (phii > phi1) phi1 = phii;
7048 } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
7049 phii = -inflection[1] * degrees$1;
7050 if (phii < phi0) phi0 = phii;
7052 if (phi < phi0) phi0 = phi;
7053 if (phi > phi1) phi1 = phi;
7056 if (lambda < lambda2) {
7057 if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7059 if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7062 if (lambda1 >= lambda0$1) {
7063 if (lambda < lambda0$1) lambda0$1 = lambda;
7064 if (lambda > lambda1) lambda1 = lambda;
7066 if (lambda > lambda2) {
7067 if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7069 if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7074 ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7076 if (phi < phi0) phi0 = phi;
7077 if (phi > phi1) phi1 = phi;
7078 p0 = p, lambda2 = lambda;
7081 function boundsLineStart() {
7082 boundsStream.point = linePoint;
7085 function boundsLineEnd() {
7086 range[0] = lambda0$1, range[1] = lambda1;
7087 boundsStream.point = boundsPoint;
7091 function boundsRingPoint(lambda, phi) {
7093 var delta = lambda - lambda2;
7094 deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
7096 lambda00$1 = lambda, phi00$1 = phi;
7098 areaStream.point(lambda, phi);
7099 linePoint(lambda, phi);
7102 function boundsRingStart() {
7103 areaStream.lineStart();
7106 function boundsRingEnd() {
7107 boundsRingPoint(lambda00$1, phi00$1);
7108 areaStream.lineEnd();
7109 if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
7110 range[0] = lambda0$1, range[1] = lambda1;
7114 // Finds the left-right distance between two longitudes.
7115 // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
7116 // the distance between ±180° to be 360°.
7117 function angle(lambda0, lambda1) {
7118 return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
7121 function rangeCompare(a, b) {
7125 function rangeContains(range, x) {
7126 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
7129 var bounds = function(feature) {
7130 var i, n, a, b, merged, deltaMax, delta;
7132 phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
7134 geoStream(feature, boundsStream);
7136 // First, sort ranges by their minimum longitudes.
7137 if (n = ranges.length) {
7138 ranges.sort(rangeCompare);
7140 // Then, merge any ranges that overlap.
7141 for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
7143 if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
7144 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
7145 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
7151 // Finally, find the largest gap between the merged ranges.
7152 // The final bounding box will be the inverse of this gap.
7153 for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
7155 if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
7159 ranges = range = null;
7161 return lambda0$1 === Infinity || phi0 === Infinity
7162 ? [[NaN, NaN], [NaN, NaN]]
7163 : [[lambda0$1, phi0], [lambda1, phi1]];
7181 var z0; // previous point
7183 var centroidStream = {
7185 point: centroidPoint,
7186 lineStart: centroidLineStart,
7187 lineEnd: centroidLineEnd,
7188 polygonStart: function() {
7189 centroidStream.lineStart = centroidRingStart;
7190 centroidStream.lineEnd = centroidRingEnd;
7192 polygonEnd: function() {
7193 centroidStream.lineStart = centroidLineStart;
7194 centroidStream.lineEnd = centroidLineEnd;
7198 // Arithmetic mean of Cartesian vectors.
7199 function centroidPoint(lambda, phi) {
7200 lambda *= radians, phi *= radians;
7201 var cosPhi = cos$1(phi);
7202 centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
7205 function centroidPointCartesian(x, y, z) {
7207 X0 += (x - X0) / W0;
7208 Y0 += (y - Y0) / W0;
7209 Z0 += (z - Z0) / W0;
7212 function centroidLineStart() {
7213 centroidStream.point = centroidLinePointFirst;
7216 function centroidLinePointFirst(lambda, phi) {
7217 lambda *= radians, phi *= radians;
7218 var cosPhi = cos$1(phi);
7219 x0 = cosPhi * cos$1(lambda);
7220 y0 = cosPhi * sin$1(lambda);
7222 centroidStream.point = centroidLinePoint;
7223 centroidPointCartesian(x0, y0, z0);
7226 function centroidLinePoint(lambda, phi) {
7227 lambda *= radians, phi *= radians;
7228 var cosPhi = cos$1(phi),
7229 x = cosPhi * cos$1(lambda),
7230 y = cosPhi * sin$1(lambda),
7232 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);
7234 X1 += w * (x0 + (x0 = x));
7235 Y1 += w * (y0 + (y0 = y));
7236 Z1 += w * (z0 + (z0 = z));
7237 centroidPointCartesian(x0, y0, z0);
7240 function centroidLineEnd() {
7241 centroidStream.point = centroidPoint;
7244 // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
7245 // J. Applied Mechanics 42, 239 (1975).
7246 function centroidRingStart() {
7247 centroidStream.point = centroidRingPointFirst;
7250 function centroidRingEnd() {
7251 centroidRingPoint(lambda00$2, phi00$2);
7252 centroidStream.point = centroidPoint;
7255 function centroidRingPointFirst(lambda, phi) {
7256 lambda00$2 = lambda, phi00$2 = phi;
7257 lambda *= radians, phi *= radians;
7258 centroidStream.point = centroidRingPoint;
7259 var cosPhi = cos$1(phi);
7260 x0 = cosPhi * cos$1(lambda);
7261 y0 = cosPhi * sin$1(lambda);
7263 centroidPointCartesian(x0, y0, z0);
7266 function centroidRingPoint(lambda, phi) {
7267 lambda *= radians, phi *= radians;
7268 var cosPhi = cos$1(phi),
7269 x = cosPhi * cos$1(lambda),
7270 y = cosPhi * sin$1(lambda),
7272 cx = y0 * z - z0 * y,
7273 cy = z0 * x - x0 * z,
7274 cz = x0 * y - y0 * x,
7275 m = sqrt(cx * cx + cy * cy + cz * cz),
7276 w = asin(m), // line weight = angle
7277 v = m && -w / m; // area weight multiplier
7282 X1 += w * (x0 + (x0 = x));
7283 Y1 += w * (y0 + (y0 = y));
7284 Z1 += w * (z0 + (z0 = z));
7285 centroidPointCartesian(x0, y0, z0);
7288 var centroid = function(object) {
7293 geoStream(object, centroidStream);
7298 m = x * x + y * y + z * z;
7300 // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
7301 if (m < epsilon2$1) {
7302 x = X1, y = Y1, z = Z1;
7303 // If the feature has zero length, fall back to arithmetic mean of point vectors.
7304 if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
7305 m = x * x + y * y + z * z;
7306 // If the feature still has an undefined ccentroid, then return.
7307 if (m < epsilon2$1) return [NaN, NaN];
7310 return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
7313 var constant$7 = function(x) {
7319 var compose = function(a, b) {
7321 function compose(x, y) {
7322 return x = a(x, y), b(x[0], x[1]);
7325 if (a.invert && b.invert) compose.invert = function(x, y) {
7326 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
7332 function rotationIdentity(lambda, phi) {
7333 return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
7336 rotationIdentity.invert = rotationIdentity;
7338 function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
7339 return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
7340 : rotationLambda(deltaLambda))
7341 : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
7342 : rotationIdentity);
7345 function forwardRotationLambda(deltaLambda) {
7346 return function(lambda, phi) {
7347 return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
7351 function rotationLambda(deltaLambda) {
7352 var rotation = forwardRotationLambda(deltaLambda);
7353 rotation.invert = forwardRotationLambda(-deltaLambda);
7357 function rotationPhiGamma(deltaPhi, deltaGamma) {
7358 var cosDeltaPhi = cos$1(deltaPhi),
7359 sinDeltaPhi = sin$1(deltaPhi),
7360 cosDeltaGamma = cos$1(deltaGamma),
7361 sinDeltaGamma = sin$1(deltaGamma);
7363 function rotation(lambda, phi) {
7364 var cosPhi = cos$1(phi),
7365 x = cos$1(lambda) * cosPhi,
7366 y = sin$1(lambda) * cosPhi,
7368 k = z * cosDeltaPhi + x * sinDeltaPhi;
7370 atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
7371 asin(k * cosDeltaGamma + y * sinDeltaGamma)
7375 rotation.invert = function(lambda, phi) {
7376 var cosPhi = cos$1(phi),
7377 x = cos$1(lambda) * cosPhi,
7378 y = sin$1(lambda) * cosPhi,
7380 k = z * cosDeltaGamma - y * sinDeltaGamma;
7382 atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
7383 asin(k * cosDeltaPhi - x * sinDeltaPhi)
7390 var rotation = function(rotate) {
7391 rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
7393 function forward(coordinates) {
7394 coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
7395 return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
7398 forward.invert = function(coordinates) {
7399 coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
7400 return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
7406 // Generates a circle centered at [0°, 0°], with a given radius and precision.
7407 function circleStream(stream, radius, delta, direction, t0, t1) {
7409 var cosRadius = cos$1(radius),
7410 sinRadius = sin$1(radius),
7411 step = direction * delta;
7413 t0 = radius + direction * tau$3;
7414 t1 = radius - step / 2;
7416 t0 = circleRadius(cosRadius, t0);
7417 t1 = circleRadius(cosRadius, t1);
7418 if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
7420 for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
7421 point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
7422 stream.point(point[0], point[1]);
7426 // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
7427 function circleRadius(cosRadius, point) {
7428 point = cartesian(point), point[0] -= cosRadius;
7429 cartesianNormalizeInPlace(point);
7430 var radius = acos(-point[1]);
7431 return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
7434 var circle = function() {
7435 var center = constant$7([0, 0]),
7436 radius = constant$7(90),
7437 precision = constant$7(6),
7440 stream = {point: point};
7442 function point(x, y) {
7443 ring.push(x = rotate(x, y));
7444 x[0] *= degrees$1, x[1] *= degrees$1;
7448 var c = center.apply(this, arguments),
7449 r = radius.apply(this, arguments) * radians,
7450 p = precision.apply(this, arguments) * radians;
7452 rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
7453 circleStream(stream, r, p, 1);
7454 c = {type: "Polygon", coordinates: [ring]};
7455 ring = rotate = null;
7459 circle.center = function(_) {
7460 return arguments.length ? (center = typeof _ === "function" ? _ : constant$7([+_[0], +_[1]]), circle) : center;
7463 circle.radius = function(_) {
7464 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), circle) : radius;
7467 circle.precision = function(_) {
7468 return arguments.length ? (precision = typeof _ === "function" ? _ : constant$7(+_), circle) : precision;
7474 var clipBuffer = function() {
7478 point: function(x, y) {
7481 lineStart: function() {
7482 lines.push(line = []);
7485 rejoin: function() {
7486 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
7488 result: function() {
7497 var pointEqual = function(a, b) {
7498 return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
7501 function Intersection(point, points, other, entry) {
7504 this.o = other; // another intersection
7505 this.e = entry; // is an entry?
7506 this.v = false; // visited
7507 this.n = this.p = null; // next & previous
7510 // A generalized polygon clipping algorithm: given a polygon that has been cut
7511 // into its visible line segments, and rejoins the segments by interpolating
7512 // along the clip edge.
7513 var clipRejoin = function(segments, compareIntersection, startInside, interpolate, stream) {
7519 segments.forEach(function(segment) {
7520 if ((n = segment.length - 1) <= 0) return;
7521 var n, p0 = segment[0], p1 = segment[n], x;
7523 // If the first and last points of a segment are coincident, then treat as a
7524 // closed ring. TODO if all rings are closed, then the winding order of the
7525 // exterior ring should be checked.
7526 if (pointEqual(p0, p1)) {
7528 for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
7533 subject.push(x = new Intersection(p0, segment, null, true));
7534 clip.push(x.o = new Intersection(p0, null, x, false));
7535 subject.push(x = new Intersection(p1, segment, null, false));
7536 clip.push(x.o = new Intersection(p1, null, x, true));
7539 if (!subject.length) return;
7541 clip.sort(compareIntersection);
7545 for (i = 0, n = clip.length; i < n; ++i) {
7546 clip[i].e = startInside = !startInside;
7549 var start = subject[0],
7554 // Find first unvisited intersection.
7555 var current = start,
7557 while (current.v) if ((current = current.n) === start) return;
7561 current.v = current.o.v = true;
7564 for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
7566 interpolate(current.x, current.n.x, 1, stream);
7568 current = current.n;
7571 points = current.p.z;
7572 for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
7574 interpolate(current.x, current.p.x, -1, stream);
7576 current = current.p;
7578 current = current.o;
7580 isSubject = !isSubject;
7581 } while (!current.v);
7586 function link$1(array) {
7587 if (!(n = array.length)) return;
7601 var sum$1 = adder();
7603 var polygonContains = function(polygon, point) {
7604 var lambda = point[0],
7606 normal = [sin$1(lambda), -cos$1(lambda), 0],
7612 for (var i = 0, n = polygon.length; i < n; ++i) {
7613 if (!(m = (ring = polygon[i]).length)) continue;
7616 point0 = ring[m - 1],
7617 lambda0 = point0[0],
7618 phi0 = point0[1] / 2 + quarterPi,
7619 sinPhi0 = sin$1(phi0),
7620 cosPhi0 = cos$1(phi0);
7622 for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
7623 var point1 = ring[j],
7624 lambda1 = point1[0],
7625 phi1 = point1[1] / 2 + quarterPi,
7626 sinPhi1 = sin$1(phi1),
7627 cosPhi1 = cos$1(phi1),
7628 delta = lambda1 - lambda0,
7629 sign$$1 = delta >= 0 ? 1 : -1,
7630 absDelta = sign$$1 * delta,
7631 antimeridian = absDelta > pi$3,
7632 k = sinPhi0 * sinPhi1;
7634 sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
7635 angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
7637 // Are the longitudes either side of the point’s meridian (lambda),
7638 // and are the latitudes smaller than the parallel (phi)?
7639 if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
7640 var arc = cartesianCross(cartesian(point0), cartesian(point1));
7641 cartesianNormalizeInPlace(arc);
7642 var intersection = cartesianCross(normal, arc);
7643 cartesianNormalizeInPlace(intersection);
7644 var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
7645 if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
7646 winding += antimeridian ^ delta >= 0 ? 1 : -1;
7652 // First, determine whether the South pole is inside or outside:
7655 // * the polygon winds around it in a clockwise direction.
7656 // * the polygon does not (cumulatively) wind around it, but has a negative
7657 // (counter-clockwise) area.
7659 // Second, count the (signed) number of times a segment crosses a lambda
7660 // from the point to the South pole. If it is zero, then the point is the
7661 // same side as the South pole.
7663 return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
7666 var clip = function(pointVisible, clipLine, interpolate, start) {
7667 return function(sink) {
7668 var line = clipLine(sink),
7669 ringBuffer = clipBuffer(),
7670 ringSink = clipLine(ringBuffer),
7671 polygonStarted = false,
7678 lineStart: lineStart,
7680 polygonStart: function() {
7681 clip.point = pointRing;
7682 clip.lineStart = ringStart;
7683 clip.lineEnd = ringEnd;
7687 polygonEnd: function() {
7689 clip.lineStart = lineStart;
7690 clip.lineEnd = lineEnd;
7691 segments = merge(segments);
7692 var startInside = polygonContains(polygon, start);
7693 if (segments.length) {
7694 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
7695 clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
7696 } else if (startInside) {
7697 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
7699 interpolate(null, null, 1, sink);
7702 if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
7703 segments = polygon = null;
7705 sphere: function() {
7706 sink.polygonStart();
7708 interpolate(null, null, 1, sink);
7714 function point(lambda, phi) {
7715 if (pointVisible(lambda, phi)) sink.point(lambda, phi);
7718 function pointLine(lambda, phi) {
7719 line.point(lambda, phi);
7722 function lineStart() {
7723 clip.point = pointLine;
7727 function lineEnd() {
7732 function pointRing(lambda, phi) {
7733 ring.push([lambda, phi]);
7734 ringSink.point(lambda, phi);
7737 function ringStart() {
7738 ringSink.lineStart();
7742 function ringEnd() {
7743 pointRing(ring[0][0], ring[0][1]);
7746 var clean = ringSink.clean(),
7747 ringSegments = ringBuffer.result(),
7748 i, n = ringSegments.length, m,
7758 // No intersections.
7760 segment = ringSegments[0];
7761 if ((m = segment.length - 1) > 0) {
7762 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
7764 for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
7770 // Rejoin connected segments.
7771 // TODO reuse ringBuffer.rejoin()?
7772 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
7774 segments.push(ringSegments.filter(validSegment));
7781 function validSegment(segment) {
7782 return segment.length > 1;
7785 // Intersections are sorted along the clip edge. For both antimeridian cutting
7786 // and circle clipping, the same comparison is used.
7787 function compareIntersection(a, b) {
7788 return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
7789 - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
7792 var clipAntimeridian = clip(
7793 function() { return true; },
7794 clipAntimeridianLine,
7795 clipAntimeridianInterpolate,
7799 // Takes a line and cuts into visible segments. Return values: 0 - there were
7800 // intersections or the line was empty; 1 - no intersections; 2 - there were
7801 // intersections, and the first and last segments should be rejoined.
7802 function clipAntimeridianLine(stream) {
7806 clean; // no intersections
7809 lineStart: function() {
7813 point: function(lambda1, phi1) {
7814 var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
7815 delta = abs(lambda1 - lambda0);
7816 if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
7817 stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
7818 stream.point(sign0, phi0);
7821 stream.point(sign1, phi0);
7822 stream.point(lambda1, phi0);
7824 } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
7825 if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
7826 if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
7827 phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
7828 stream.point(sign0, phi0);
7831 stream.point(sign1, phi0);
7834 stream.point(lambda0 = lambda1, phi0 = phi1);
7837 lineEnd: function() {
7839 lambda0 = phi0 = NaN;
7842 return 2 - clean; // if intersections, rejoin first and last segments
7847 function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
7850 sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
7851 return abs(sinLambda0Lambda1) > epsilon$2
7852 ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
7853 - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
7854 / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
7855 : (phi0 + phi1) / 2;
7858 function clipAntimeridianInterpolate(from, to, direction, stream) {
7861 phi = direction * halfPi$2;
7862 stream.point(-pi$3, phi);
7863 stream.point(0, phi);
7864 stream.point(pi$3, phi);
7865 stream.point(pi$3, 0);
7866 stream.point(pi$3, -phi);
7867 stream.point(0, -phi);
7868 stream.point(-pi$3, -phi);
7869 stream.point(-pi$3, 0);
7870 stream.point(-pi$3, phi);
7871 } else if (abs(from[0] - to[0]) > epsilon$2) {
7872 var lambda = from[0] < to[0] ? pi$3 : -pi$3;
7873 phi = direction * lambda / 2;
7874 stream.point(-lambda, phi);
7875 stream.point(0, phi);
7876 stream.point(lambda, phi);
7878 stream.point(to[0], to[1]);
7882 var clipCircle = function(radius) {
7883 var cr = cos$1(radius),
7884 delta = 6 * radians,
7885 smallRadius = cr > 0,
7886 notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
7888 function interpolate(from, to, direction, stream) {
7889 circleStream(stream, radius, delta, direction, from, to);
7892 function visible(lambda, phi) {
7893 return cos$1(lambda) * cos$1(phi) > cr;
7896 // Takes a line and cuts into visible segments. Return values used for polygon
7897 // clipping: 0 - there were intersections or the line was empty; 1 - no
7898 // intersections 2 - there were intersections, and the first and last segments
7899 // should be rejoined.
7900 function clipLine(stream) {
7901 var point0, // previous point
7902 c0, // code for previous point
7903 v0, // visibility of previous point
7904 v00, // visibility of first point
7905 clean; // no intersections
7907 lineStart: function() {
7911 point: function(lambda, phi) {
7912 var point1 = [lambda, phi],
7914 v = visible(lambda, phi),
7916 ? v ? 0 : code(lambda, phi)
7917 : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
7918 if (!point0 && (v00 = v0 = v)) stream.lineStart();
7919 // Handle degeneracies.
7920 // TODO ignore if not clipping polygons.
7922 point2 = intersect(point0, point1);
7923 if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
7924 point1[0] += epsilon$2;
7925 point1[1] += epsilon$2;
7926 v = visible(point1[0], point1[1]);
7934 point2 = intersect(point1, point0);
7935 stream.point(point2[0], point2[1]);
7938 point2 = intersect(point0, point1);
7939 stream.point(point2[0], point2[1]);
7943 } else if (notHemisphere && point0 && smallRadius ^ v) {
7945 // If the codes for two points are different, or are both zero,
7946 // and there this segment intersects with the small circle.
7947 if (!(c & c0) && (t = intersect(point1, point0, true))) {
7951 stream.point(t[0][0], t[0][1]);
7952 stream.point(t[1][0], t[1][1]);
7955 stream.point(t[1][0], t[1][1]);
7958 stream.point(t[0][0], t[0][1]);
7962 if (v && (!point0 || !pointEqual(point0, point1))) {
7963 stream.point(point1[0], point1[1]);
7965 point0 = point1, v0 = v, c0 = c;
7967 lineEnd: function() {
7968 if (v0) stream.lineEnd();
7971 // Rejoin first and last segments if there were intersections and the first
7972 // and last points were visible.
7974 return clean | ((v00 && v0) << 1);
7979 // Intersects the great circle between a and b with the clip circle.
7980 function intersect(a, b, two) {
7981 var pa = cartesian(a),
7984 // We have two planes, n1.p = d1 and n2.p = d2.
7985 // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
7986 var n1 = [1, 0, 0], // normal
7987 n2 = cartesianCross(pa, pb),
7988 n2n2 = cartesianDot(n2, n2),
7989 n1n2 = n2[0], // cartesianDot(n1, n2),
7990 determinant = n2n2 - n1n2 * n1n2;
7992 // Two polar points.
7993 if (!determinant) return !two && a;
7995 var c1 = cr * n2n2 / determinant,
7996 c2 = -cr * n1n2 / determinant,
7997 n1xn2 = cartesianCross(n1, n2),
7998 A = cartesianScale(n1, c1),
7999 B = cartesianScale(n2, c2);
8000 cartesianAddInPlace(A, B);
8002 // Solve |p(t)|^2 = 1.
8004 w = cartesianDot(A, u),
8005 uu = cartesianDot(u, u),
8006 t2 = w * w - uu * (cartesianDot(A, A) - 1);
8011 q = cartesianScale(u, (-w - t) / uu);
8012 cartesianAddInPlace(q, A);
8017 // Two intersection points.
8024 if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
8026 var delta = lambda1 - lambda0,
8027 polar = abs(delta - pi$3) < epsilon$2,
8028 meridian = polar || delta < epsilon$2;
8030 if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
8032 // Check that the first point is between a and b.
8035 ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
8036 : phi0 <= q[1] && q[1] <= phi1
8037 : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
8038 var q1 = cartesianScale(u, (-w + t) / uu);
8039 cartesianAddInPlace(q1, A);
8040 return [q, spherical(q1)];
8044 // Generates a 4-bit vector representing the location of a point relative to
8045 // the small circle's bounding box.
8046 function code(lambda, phi) {
8047 var r = smallRadius ? radius : pi$3 - radius,
8049 if (lambda < -r) code |= 1; // left
8050 else if (lambda > r) code |= 2; // right
8051 if (phi < -r) code |= 4; // below
8052 else if (phi > r) code |= 8; // above
8056 return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
8059 var clipLine = function(a, b, x0, y0, x1, y1) {
8071 if (!dx && r > 0) return;
8076 } else if (dx > 0) {
8082 if (!dx && r < 0) return;
8087 } else if (dx > 0) {
8093 if (!dy && r > 0) return;
8098 } else if (dy > 0) {
8104 if (!dy && r < 0) return;
8109 } else if (dy > 0) {
8114 if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
8115 if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
8120 var clipMin = -clipMax;
8122 // TODO Use d3-polygon’s polygonContains here for the ring check?
8123 // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
8125 function clipRectangle(x0, y0, x1, y1) {
8127 function visible(x, y) {
8128 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
8131 function interpolate(from, to, direction, stream) {
8134 || (a = corner(from, direction)) !== (a1 = corner(to, direction))
8135 || comparePoint(from, to) < 0 ^ direction > 0) {
8136 do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
8137 while ((a = (a + direction + 4) % 4) !== a1);
8139 stream.point(to[0], to[1]);
8143 function corner(p, direction) {
8144 return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
8145 : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
8146 : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
8147 : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
8150 function compareIntersection(a, b) {
8151 return comparePoint(a.x, b.x);
8154 function comparePoint(a, b) {
8155 var ca = corner(a, 1),
8157 return ca !== cb ? ca - cb
8158 : ca === 0 ? b[1] - a[1]
8159 : ca === 1 ? a[0] - b[0]
8160 : ca === 2 ? a[1] - b[1]
8164 return function(stream) {
8165 var activeStream = stream,
8166 bufferStream = clipBuffer(),
8170 x__, y__, v__, // first point
8171 x_, y_, v_, // previous point
8177 lineStart: lineStart,
8179 polygonStart: polygonStart,
8180 polygonEnd: polygonEnd
8183 function point(x, y) {
8184 if (visible(x, y)) activeStream.point(x, y);
8187 function polygonInside() {
8190 for (var i = 0, n = polygon.length; i < n; ++i) {
8191 for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
8192 a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
8193 if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
8194 else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
8201 // Buffer geometry within a polygon and then clip it en masse.
8202 function polygonStart() {
8203 activeStream = bufferStream, segments = [], polygon = [], clean = true;
8206 function polygonEnd() {
8207 var startInside = polygonInside(),
8208 cleanInside = clean && startInside,
8209 visible = (segments = merge(segments)).length;
8210 if (cleanInside || visible) {
8211 stream.polygonStart();
8214 interpolate(null, null, 1, stream);
8218 clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
8220 stream.polygonEnd();
8222 activeStream = stream, segments = polygon = ring = null;
8225 function lineStart() {
8226 clipStream.point = linePoint;
8227 if (polygon) polygon.push(ring = []);
8233 // TODO rather than special-case polygons, simply handle them separately.
8234 // Ideally, coincident intersection points should be jittered to avoid
8236 function lineEnd() {
8238 linePoint(x__, y__);
8239 if (v__ && v_) bufferStream.rejoin();
8240 segments.push(bufferStream.result());
8242 clipStream.point = point;
8243 if (v_) activeStream.lineEnd();
8246 function linePoint(x, y) {
8247 var v = visible(x, y);
8248 if (polygon) ring.push([x, y]);
8250 x__ = x, y__ = y, v__ = v;
8253 activeStream.lineStart();
8254 activeStream.point(x, y);
8257 if (v && v_) activeStream.point(x, y);
8259 var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
8260 b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
8261 if (clipLine(a, b, x0, y0, x1, y1)) {
8263 activeStream.lineStart();
8264 activeStream.point(a[0], a[1]);
8266 activeStream.point(b[0], b[1]);
8267 if (!v) activeStream.lineEnd();
8270 activeStream.lineStart();
8271 activeStream.point(x, y);
8276 x_ = x, y_ = y, v_ = v;
8283 var extent$1 = function() {
8293 stream: function(stream) {
8294 return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
8296 extent: function(_) {
8297 return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
8302 var lengthSum = adder();
8307 var lengthStream = {
8310 lineStart: lengthLineStart,
8312 polygonStart: noop$1,
8316 function lengthLineStart() {
8317 lengthStream.point = lengthPointFirst;
8318 lengthStream.lineEnd = lengthLineEnd;
8321 function lengthLineEnd() {
8322 lengthStream.point = lengthStream.lineEnd = noop$1;
8325 function lengthPointFirst(lambda, phi) {
8326 lambda *= radians, phi *= radians;
8327 lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
8328 lengthStream.point = lengthPoint;
8331 function lengthPoint(lambda, phi) {
8332 lambda *= radians, phi *= radians;
8333 var sinPhi = sin$1(phi),
8334 cosPhi = cos$1(phi),
8335 delta = abs(lambda - lambda0$2),
8336 cosDelta = cos$1(delta),
8337 sinDelta = sin$1(delta),
8338 x = cosPhi * sinDelta,
8339 y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
8340 z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
8341 lengthSum.add(atan2(sqrt(x * x + y * y), z));
8342 lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
8345 var length$1 = function(object) {
8347 geoStream(object, lengthStream);
8351 var coordinates = [null, null];
8352 var object$1 = {type: "LineString", coordinates: coordinates};
8354 var distance = function(a, b) {
8357 return length$1(object$1);
8360 var containsObjectType = {
8361 Feature: function(object, point) {
8362 return containsGeometry(object.geometry, point);
8364 FeatureCollection: function(object, point) {
8365 var features = object.features, i = -1, n = features.length;
8366 while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
8371 var containsGeometryType = {
8372 Sphere: function() {
8375 Point: function(object, point) {
8376 return containsPoint(object.coordinates, point);
8378 MultiPoint: function(object, point) {
8379 var coordinates = object.coordinates, i = -1, n = coordinates.length;
8380 while (++i < n) if (containsPoint(coordinates[i], point)) return true;
8383 LineString: function(object, point) {
8384 return containsLine(object.coordinates, point);
8386 MultiLineString: function(object, point) {
8387 var coordinates = object.coordinates, i = -1, n = coordinates.length;
8388 while (++i < n) if (containsLine(coordinates[i], point)) return true;
8391 Polygon: function(object, point) {
8392 return containsPolygon(object.coordinates, point);
8394 MultiPolygon: function(object, point) {
8395 var coordinates = object.coordinates, i = -1, n = coordinates.length;
8396 while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
8399 GeometryCollection: function(object, point) {
8400 var geometries = object.geometries, i = -1, n = geometries.length;
8401 while (++i < n) if (containsGeometry(geometries[i], point)) return true;
8406 function containsGeometry(geometry, point) {
8407 return geometry && containsGeometryType.hasOwnProperty(geometry.type)
8408 ? containsGeometryType[geometry.type](geometry, point)
8412 function containsPoint(coordinates, point) {
8413 return distance(coordinates, point) === 0;
8416 function containsLine(coordinates, point) {
8417 var ab = distance(coordinates[0], coordinates[1]),
8418 ao = distance(coordinates[0], point),
8419 ob = distance(point, coordinates[1]);
8420 return ao + ob <= ab + epsilon$2;
8423 function containsPolygon(coordinates, point) {
8424 return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
8427 function ringRadians(ring) {
8428 return ring = ring.map(pointRadians), ring.pop(), ring;
8431 function pointRadians(point) {
8432 return [point[0] * radians, point[1] * radians];
8435 var contains = function(object, point) {
8436 return (object && containsObjectType.hasOwnProperty(object.type)
8437 ? containsObjectType[object.type]
8438 : containsGeometry)(object, point);
8441 function graticuleX(y0, y1, dy) {
8442 var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
8443 return function(x) { return y.map(function(y) { return [x, y]; }); };
8446 function graticuleY(x0, x1, dx) {
8447 var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
8448 return function(y) { return x.map(function(x) { return [x, y]; }); };
8451 function graticule() {
8454 dx = 10, dy = dx, DX = 90, DY = 360,
8458 function graticule() {
8459 return {type: "MultiLineString", coordinates: lines()};
8463 return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
8464 .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
8465 .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
8466 .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
8469 graticule.lines = function() {
8470 return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
8473 graticule.outline = function() {
8479 X(X1).reverse().slice(1),
8480 Y(Y0).reverse().slice(1))
8485 graticule.extent = function(_) {
8486 if (!arguments.length) return graticule.extentMinor();
8487 return graticule.extentMajor(_).extentMinor(_);
8490 graticule.extentMajor = function(_) {
8491 if (!arguments.length) return [[X0, Y0], [X1, Y1]];
8492 X0 = +_[0][0], X1 = +_[1][0];
8493 Y0 = +_[0][1], Y1 = +_[1][1];
8494 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
8495 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
8496 return graticule.precision(precision);
8499 graticule.extentMinor = function(_) {
8500 if (!arguments.length) return [[x0, y0], [x1, y1]];
8501 x0 = +_[0][0], x1 = +_[1][0];
8502 y0 = +_[0][1], y1 = +_[1][1];
8503 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
8504 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
8505 return graticule.precision(precision);
8508 graticule.step = function(_) {
8509 if (!arguments.length) return graticule.stepMinor();
8510 return graticule.stepMajor(_).stepMinor(_);
8513 graticule.stepMajor = function(_) {
8514 if (!arguments.length) return [DX, DY];
8515 DX = +_[0], DY = +_[1];
8519 graticule.stepMinor = function(_) {
8520 if (!arguments.length) return [dx, dy];
8521 dx = +_[0], dy = +_[1];
8525 graticule.precision = function(_) {
8526 if (!arguments.length) return precision;
8528 x = graticuleX(y0, y1, 90);
8529 y = graticuleY(x0, x1, precision);
8530 X = graticuleX(Y0, Y1, 90);
8531 Y = graticuleY(X0, X1, precision);
8536 .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
8537 .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
8540 function graticule10() {
8541 return graticule()();
8544 var interpolate$1 = function(a, b) {
8545 var x0 = a[0] * radians,
8546 y0 = a[1] * radians,
8547 x1 = b[0] * radians,
8548 y1 = b[1] * radians,
8553 kx0 = cy0 * cos$1(x0),
8554 ky0 = cy0 * sin$1(x0),
8555 kx1 = cy1 * cos$1(x1),
8556 ky1 = cy1 * sin$1(x1),
8557 d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
8560 var interpolate = d ? function(t) {
8561 var B = sin$1(t *= d) / k,
8562 A = sin$1(d - t) / k,
8563 x = A * kx0 + B * kx1,
8564 y = A * ky0 + B * ky1,
8565 z = A * sy0 + B * sy1;
8567 atan2(y, x) * degrees$1,
8568 atan2(z, sqrt(x * x + y * y)) * degrees$1
8571 return [x0 * degrees$1, y0 * degrees$1];
8574 interpolate.distance = d;
8579 var identity$4 = function(x) {
8583 var areaSum$1 = adder();
8584 var areaRingSum$1 = adder();
8590 var areaStream$1 = {
8594 polygonStart: function() {
8595 areaStream$1.lineStart = areaRingStart$1;
8596 areaStream$1.lineEnd = areaRingEnd$1;
8598 polygonEnd: function() {
8599 areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$1;
8600 areaSum$1.add(abs(areaRingSum$1));
8601 areaRingSum$1.reset();
8603 result: function() {
8604 var area = areaSum$1 / 2;
8610 function areaRingStart$1() {
8611 areaStream$1.point = areaPointFirst$1;
8614 function areaPointFirst$1(x, y) {
8615 areaStream$1.point = areaPoint$1;
8616 x00 = x0$1 = x, y00 = y0$1 = y;
8619 function areaPoint$1(x, y) {
8620 areaRingSum$1.add(y0$1 * x - x0$1 * y);
8624 function areaRingEnd$1() {
8625 areaPoint$1(x00, y00);
8628 var x0$2 = Infinity;
8633 var boundsStream$1 = {
8634 point: boundsPoint$1,
8637 polygonStart: noop$1,
8639 result: function() {
8640 var bounds = [[x0$2, y0$2], [x1, y1]];
8641 x1 = y1 = -(y0$2 = x0$2 = Infinity);
8646 function boundsPoint$1(x, y) {
8647 if (x < x0$2) x0$2 = x;
8649 if (y < y0$2) y0$2 = y;
8653 // TODO Enforce positive area for exterior, negative area for interior?
8669 var centroidStream$1 = {
8670 point: centroidPoint$1,
8671 lineStart: centroidLineStart$1,
8672 lineEnd: centroidLineEnd$1,
8673 polygonStart: function() {
8674 centroidStream$1.lineStart = centroidRingStart$1;
8675 centroidStream$1.lineEnd = centroidRingEnd$1;
8677 polygonEnd: function() {
8678 centroidStream$1.point = centroidPoint$1;
8679 centroidStream$1.lineStart = centroidLineStart$1;
8680 centroidStream$1.lineEnd = centroidLineEnd$1;
8682 result: function() {
8683 var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
8684 : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
8685 : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
8687 X0$1 = Y0$1 = Z0$1 =
8688 X1$1 = Y1$1 = Z1$1 =
8689 X2$1 = Y2$1 = Z2$1 = 0;
8694 function centroidPoint$1(x, y) {
8700 function centroidLineStart$1() {
8701 centroidStream$1.point = centroidPointFirstLine;
8704 function centroidPointFirstLine(x, y) {
8705 centroidStream$1.point = centroidPointLine;
8706 centroidPoint$1(x0$3 = x, y0$3 = y);
8709 function centroidPointLine(x, y) {
8710 var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
8711 X1$1 += z * (x0$3 + x) / 2;
8712 Y1$1 += z * (y0$3 + y) / 2;
8714 centroidPoint$1(x0$3 = x, y0$3 = y);
8717 function centroidLineEnd$1() {
8718 centroidStream$1.point = centroidPoint$1;
8721 function centroidRingStart$1() {
8722 centroidStream$1.point = centroidPointFirstRing;
8725 function centroidRingEnd$1() {
8726 centroidPointRing(x00$1, y00$1);
8729 function centroidPointFirstRing(x, y) {
8730 centroidStream$1.point = centroidPointRing;
8731 centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
8734 function centroidPointRing(x, y) {
8737 z = sqrt(dx * dx + dy * dy);
8739 X1$1 += z * (x0$3 + x) / 2;
8740 Y1$1 += z * (y0$3 + y) / 2;
8743 z = y0$3 * x - x0$3 * y;
8744 X2$1 += z * (x0$3 + x);
8745 Y2$1 += z * (y0$3 + y);
8747 centroidPoint$1(x0$3 = x, y0$3 = y);
8750 function PathContext(context) {
8751 this._context = context;
8754 PathContext.prototype = {
8756 pointRadius: function(_) {
8757 return this._radius = _, this;
8759 polygonStart: function() {
8762 polygonEnd: function() {
8765 lineStart: function() {
8768 lineEnd: function() {
8769 if (this._line === 0) this._context.closePath();
8772 point: function(x, y) {
8773 switch (this._point) {
8775 this._context.moveTo(x, y);
8780 this._context.lineTo(x, y);
8784 this._context.moveTo(x + this._radius, y);
8785 this._context.arc(x, y, this._radius, 0, tau$3);
8793 var lengthSum$1 = adder();
8800 var lengthStream$1 = {
8802 lineStart: function() {
8803 lengthStream$1.point = lengthPointFirst$1;
8805 lineEnd: function() {
8806 if (lengthRing) lengthPoint$1(x00$2, y00$2);
8807 lengthStream$1.point = noop$1;
8809 polygonStart: function() {
8812 polygonEnd: function() {
8815 result: function() {
8816 var length = +lengthSum$1;
8817 lengthSum$1.reset();
8822 function lengthPointFirst$1(x, y) {
8823 lengthStream$1.point = lengthPoint$1;
8824 x00$2 = x0$4 = x, y00$2 = y0$4 = y;
8827 function lengthPoint$1(x, y) {
8828 x0$4 -= x, y0$4 -= y;
8829 lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
8833 function PathString() {
8837 PathString.prototype = {
8839 _circle: circle$1(4.5),
8840 pointRadius: function(_) {
8841 if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
8844 polygonStart: function() {
8847 polygonEnd: function() {
8850 lineStart: function() {
8853 lineEnd: function() {
8854 if (this._line === 0) this._string.push("Z");
8857 point: function(x, y) {
8858 switch (this._point) {
8860 this._string.push("M", x, ",", y);
8865 this._string.push("L", x, ",", y);
8869 if (this._circle == null) this._circle = circle$1(this._radius);
8870 this._string.push("M", x, ",", y, this._circle);
8875 result: function() {
8876 if (this._string.length) {
8877 var result = this._string.join("");
8886 function circle$1(radius) {
8887 return "m0," + radius
8888 + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
8889 + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
8893 var index$1 = function(projection, context) {
8894 var pointRadius = 4.5,
8898 function path(object) {
8900 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
8901 geoStream(object, projectionStream(contextStream));
8903 return contextStream.result();
8906 path.area = function(object) {
8907 geoStream(object, projectionStream(areaStream$1));
8908 return areaStream$1.result();
8911 path.measure = function(object) {
8912 geoStream(object, projectionStream(lengthStream$1));
8913 return lengthStream$1.result();
8916 path.bounds = function(object) {
8917 geoStream(object, projectionStream(boundsStream$1));
8918 return boundsStream$1.result();
8921 path.centroid = function(object) {
8922 geoStream(object, projectionStream(centroidStream$1));
8923 return centroidStream$1.result();
8926 path.projection = function(_) {
8927 return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
8930 path.context = function(_) {
8931 if (!arguments.length) return context;
8932 contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
8933 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
8937 path.pointRadius = function(_) {
8938 if (!arguments.length) return pointRadius;
8939 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
8943 return path.projection(projection).context(context);
8946 var transform = function(methods) {
8948 stream: transformer(methods)
8952 function transformer(methods) {
8953 return function(stream) {
8954 var s = new TransformStream;
8955 for (var key in methods) s[key] = methods[key];
8961 function TransformStream() {}
8963 TransformStream.prototype = {
8964 constructor: TransformStream,
8965 point: function(x, y) { this.stream.point(x, y); },
8966 sphere: function() { this.stream.sphere(); },
8967 lineStart: function() { this.stream.lineStart(); },
8968 lineEnd: function() { this.stream.lineEnd(); },
8969 polygonStart: function() { this.stream.polygonStart(); },
8970 polygonEnd: function() { this.stream.polygonEnd(); }
8973 function fit(projection, fitBounds, object) {
8974 var clip = projection.clipExtent && projection.clipExtent();
8975 projection.scale(150).translate([0, 0]);
8976 if (clip != null) projection.clipExtent(null);
8977 geoStream(object, projection.stream(boundsStream$1));
8978 fitBounds(boundsStream$1.result());
8979 if (clip != null) projection.clipExtent(clip);
8983 function fitExtent(projection, extent, object) {
8984 return fit(projection, function(b) {
8985 var w = extent[1][0] - extent[0][0],
8986 h = extent[1][1] - extent[0][1],
8987 k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
8988 x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
8989 y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
8990 projection.scale(150 * k).translate([x, y]);
8994 function fitSize(projection, size, object) {
8995 return fitExtent(projection, [[0, 0], size], object);
8998 function fitWidth(projection, width, object) {
8999 return fit(projection, function(b) {
9001 k = w / (b[1][0] - b[0][0]),
9002 x = (w - k * (b[1][0] + b[0][0])) / 2,
9004 projection.scale(150 * k).translate([x, y]);
9008 function fitHeight(projection, height, object) {
9009 return fit(projection, function(b) {
9011 k = h / (b[1][1] - b[0][1]),
9013 y = (h - k * (b[1][1] + b[0][1])) / 2;
9014 projection.scale(150 * k).translate([x, y]);
9019 var cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
9021 var resample = function(project, delta2) {
9022 return +delta2 ? resample$1(project, delta2) : resampleNone(project);
9025 function resampleNone(project) {
9026 return transformer({
9027 point: function(x, y) {
9029 this.stream.point(x[0], x[1]);
9034 function resample$1(project, delta2) {
9036 function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
9039 d2 = dx * dx + dy * dy;
9040 if (d2 > 4 * delta2 && depth--) {
9044 m = sqrt(a * a + b * b + c * c),
9045 phi2 = asin(c /= m),
9046 lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
9047 p = project(lambda2, phi2),
9052 dz = dy * dx2 - dx * dy2;
9053 if (dz * dz / d2 > delta2 // perpendicular projected distance
9054 || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
9055 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
9056 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
9057 stream.point(x2, y2);
9058 resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
9062 return function(stream) {
9063 var lambda00, x00, y00, a00, b00, c00, // first point
9064 lambda0, x0, y0, a0, b0, c0; // previous point
9066 var resampleStream = {
9068 lineStart: lineStart,
9070 polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
9071 polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
9074 function point(x, y) {
9076 stream.point(x[0], x[1]);
9079 function lineStart() {
9081 resampleStream.point = linePoint;
9085 function linePoint(lambda, phi) {
9086 var c = cartesian([lambda, phi]), p = project(lambda, phi);
9087 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);
9088 stream.point(x0, y0);
9091 function lineEnd() {
9092 resampleStream.point = point;
9096 function ringStart() {
9098 resampleStream.point = ringPoint;
9099 resampleStream.lineEnd = ringEnd;
9102 function ringPoint(lambda, phi) {
9103 linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
9104 resampleStream.point = linePoint;
9107 function ringEnd() {
9108 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
9109 resampleStream.lineEnd = lineEnd;
9113 return resampleStream;
9117 var transformRadians = transformer({
9118 point: function(x, y) {
9119 this.stream.point(x * radians, y * radians);
9123 function transformRotate(rotate) {
9124 return transformer({
9125 point: function(x, y) {
9126 var r = rotate(x, y);
9127 return this.stream.point(r[0], r[1]);
9132 function projection(project) {
9133 return projectionMutator(function() { return project; })();
9136 function projectionMutator(projectAt) {
9139 x = 480, y = 250, // translate
9140 dx, dy, lambda = 0, phi = 0, // center
9141 deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, projectRotate, // rotate
9142 theta = null, preclip = clipAntimeridian, // clip angle
9143 x0 = null, y0, x1, y1, postclip = identity$4, // clip extent
9144 delta2 = 0.5, projectResample = resample(projectTransform, delta2), // precision
9148 function projection(point) {
9149 point = projectRotate(point[0] * radians, point[1] * radians);
9150 return [point[0] * k + dx, dy - point[1] * k];
9153 function invert(point) {
9154 point = projectRotate.invert((point[0] - dx) / k, (dy - point[1]) / k);
9155 return point && [point[0] * degrees$1, point[1] * degrees$1];
9158 function projectTransform(x, y) {
9159 return x = project(x, y), [x[0] * k + dx, dy - x[1] * k];
9162 projection.stream = function(stream) {
9163 return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
9166 projection.preclip = function(_) {
9167 return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
9170 projection.postclip = function(_) {
9171 return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
9174 projection.clipAngle = function(_) {
9175 return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
9178 projection.clipExtent = function(_) {
9179 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]];
9182 projection.scale = function(_) {
9183 return arguments.length ? (k = +_, recenter()) : k;
9186 projection.translate = function(_) {
9187 return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
9190 projection.center = function(_) {
9191 return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
9194 projection.rotate = function(_) {
9195 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];
9198 projection.precision = function(_) {
9199 return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
9202 projection.fitExtent = function(extent, object) {
9203 return fitExtent(projection, extent, object);
9206 projection.fitSize = function(size, object) {
9207 return fitSize(projection, size, object);
9210 projection.fitWidth = function(width, object) {
9211 return fitWidth(projection, width, object);
9214 projection.fitHeight = function(height, object) {
9215 return fitHeight(projection, height, object);
9218 function recenter() {
9219 projectRotate = compose(rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma), project);
9220 var center = project(lambda, phi);
9221 dx = x - center[0] * k;
9222 dy = y + center[1] * k;
9227 cache = cacheStream = null;
9232 project = projectAt.apply(this, arguments);
9233 projection.invert = project.invert && invert;
9238 function conicProjection(projectAt) {
9241 m = projectionMutator(projectAt),
9244 p.parallels = function(_) {
9245 return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
9251 function cylindricalEqualAreaRaw(phi0) {
9252 var cosPhi0 = cos$1(phi0);
9254 function forward(lambda, phi) {
9255 return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
9258 forward.invert = function(x, y) {
9259 return [x / cosPhi0, asin(y * cosPhi0)];
9265 function conicEqualAreaRaw(y0, y1) {
9266 var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
9268 // Are the parallels symmetrical around the Equator?
9269 if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
9271 var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
9273 function project(x, y) {
9274 var r = sqrt(c - 2 * n * sin$1(y)) / n;
9275 return [r * sin$1(x *= n), r0 - r * cos$1(x)];
9278 project.invert = function(x, y) {
9280 return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
9286 var conicEqualArea = function() {
9287 return conicProjection(conicEqualAreaRaw)
9289 .center([0, 33.6442]);
9292 var albers = function() {
9293 return conicEqualArea()
9294 .parallels([29.5, 45.5])
9296 .translate([480, 250])
9298 .center([-0.6, 38.7]);
9301 // The projections must have mutually exclusive clip regions on the sphere,
9302 // as this will avoid emitting interleaving lines and polygons.
9303 function multiplex(streams) {
9304 var n = streams.length;
9306 point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
9307 sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
9308 lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
9309 lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
9310 polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
9311 polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
9315 // A composite projection for the United States, configured by default for
9316 // 960×500. The projection also works quite well at 960×600 if you change the
9317 // scale to 1285 and adjust the translate accordingly. The set of standard
9318 // parallels for each region comes from USGS, which is published here:
9319 // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
9320 var albersUsa = function() {
9323 lower48 = albers(), lower48Point,
9324 alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
9325 hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
9326 point, pointStream = {point: function(x, y) { point = [x, y]; }};
9328 function albersUsa(coordinates) {
9329 var x = coordinates[0], y = coordinates[1];
9330 return point = null, (lower48Point.point(x, y), point)
9331 || (alaskaPoint.point(x, y), point)
9332 || (hawaiiPoint.point(x, y), point);
9335 albersUsa.invert = function(coordinates) {
9336 var k = lower48.scale(),
9337 t = lower48.translate(),
9338 x = (coordinates[0] - t[0]) / k,
9339 y = (coordinates[1] - t[1]) / k;
9340 return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
9341 : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
9342 : lower48).invert(coordinates);
9345 albersUsa.stream = function(stream) {
9346 return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
9349 albersUsa.precision = function(_) {
9350 if (!arguments.length) return lower48.precision();
9351 lower48.precision(_), alaska.precision(_), hawaii.precision(_);
9355 albersUsa.scale = function(_) {
9356 if (!arguments.length) return lower48.scale();
9357 lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
9358 return albersUsa.translate(lower48.translate());
9361 albersUsa.translate = function(_) {
9362 if (!arguments.length) return lower48.translate();
9363 var k = lower48.scale(), x = +_[0], y = +_[1];
9365 lower48Point = lower48
9367 .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
9368 .stream(pointStream);
9370 alaskaPoint = alaska
9371 .translate([x - 0.307 * k, y + 0.201 * k])
9372 .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]])
9373 .stream(pointStream);
9375 hawaiiPoint = hawaii
9376 .translate([x - 0.205 * k, y + 0.212 * k])
9377 .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]])
9378 .stream(pointStream);
9383 albersUsa.fitExtent = function(extent, object) {
9384 return fitExtent(albersUsa, extent, object);
9387 albersUsa.fitSize = function(size, object) {
9388 return fitSize(albersUsa, size, object);
9391 albersUsa.fitWidth = function(width, object) {
9392 return fitWidth(albersUsa, width, object);
9395 albersUsa.fitHeight = function(height, object) {
9396 return fitHeight(albersUsa, height, object);
9400 cache = cacheStream = null;
9404 return albersUsa.scale(1070);
9407 function azimuthalRaw(scale) {
9408 return function(x, y) {
9419 function azimuthalInvert(angle) {
9420 return function(x, y) {
9421 var z = sqrt(x * x + y * y),
9426 atan2(x * sc, z * cc),
9427 asin(z && y * sc / z)
9432 var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
9433 return sqrt(2 / (1 + cxcy));
9436 azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
9437 return 2 * asin(z / 2);
9440 var azimuthalEqualArea = function() {
9441 return projection(azimuthalEqualAreaRaw)
9443 .clipAngle(180 - 1e-3);
9446 var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
9447 return (c = acos(c)) && c / sin$1(c);
9450 azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
9454 var azimuthalEquidistant = function() {
9455 return projection(azimuthalEquidistantRaw)
9457 .clipAngle(180 - 1e-3);
9460 function mercatorRaw(lambda, phi) {
9461 return [lambda, log(tan((halfPi$2 + phi) / 2))];
9464 mercatorRaw.invert = function(x, y) {
9465 return [x, 2 * atan(exp(y)) - halfPi$2];
9468 var mercator = function() {
9469 return mercatorProjection(mercatorRaw)
9470 .scale(961 / tau$3);
9473 function mercatorProjection(project) {
9474 var m = projection(project),
9477 translate = m.translate,
9478 clipExtent = m.clipExtent,
9479 x0 = null, y0, x1, y1; // clip extent
9481 m.scale = function(_) {
9482 return arguments.length ? (scale(_), reclip()) : scale();
9485 m.translate = function(_) {
9486 return arguments.length ? (translate(_), reclip()) : translate();
9489 m.center = function(_) {
9490 return arguments.length ? (center(_), reclip()) : center();
9493 m.clipExtent = function(_) {
9494 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]];
9498 var k = pi$3 * scale(),
9499 t = m(rotation(m.rotate()).invert([0, 0]));
9500 return clipExtent(x0 == null
9501 ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
9502 ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
9503 : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
9510 return tan((halfPi$2 + y) / 2);
9513 function conicConformalRaw(y0, y1) {
9514 var cy0 = cos$1(y0),
9515 n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
9516 f = cy0 * pow(tany(y0), n) / n;
9518 if (!n) return mercatorRaw;
9520 function project(x, y) {
9521 if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
9522 else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
9523 var r = f / pow(tany(y), n);
9524 return [r * sin$1(n * x), f - r * cos$1(n * x)];
9527 project.invert = function(x, y) {
9528 var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
9529 return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
9535 var conicConformal = function() {
9536 return conicProjection(conicConformalRaw)
9538 .parallels([30, 30]);
9541 function equirectangularRaw(lambda, phi) {
9542 return [lambda, phi];
9545 equirectangularRaw.invert = equirectangularRaw;
9547 var equirectangular = function() {
9548 return projection(equirectangularRaw)
9552 function conicEquidistantRaw(y0, y1) {
9553 var cy0 = cos$1(y0),
9554 n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
9557 if (abs(n) < epsilon$2) return equirectangularRaw;
9559 function project(x, y) {
9560 var gy = g - y, nx = n * x;
9561 return [gy * sin$1(nx), g - gy * cos$1(nx)];
9564 project.invert = function(x, y) {
9566 return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
9572 var conicEquidistant = function() {
9573 return conicProjection(conicEquidistantRaw)
9575 .center([0, 13.9389]);
9578 function gnomonicRaw(x, y) {
9579 var cy = cos$1(y), k = cos$1(x) * cy;
9580 return [cy * sin$1(x) / k, sin$1(y) / k];
9583 gnomonicRaw.invert = azimuthalInvert(atan);
9585 var gnomonic = function() {
9586 return projection(gnomonicRaw)
9591 function scaleTranslate(kx, ky, tx, ty) {
9592 return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
9593 point: function(x, y) {
9594 this.stream.point(x * kx + tx, y * ky + ty);
9599 var identity$5 = function() {
9600 var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
9601 x0 = null, y0, x1, y1, // clip extent
9602 postclip = identity$4,
9608 cache = cacheStream = null;
9612 return projection = {
9613 stream: function(stream) {
9614 return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
9616 postclip: function(_) {
9617 return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
9619 clipExtent: function(_) {
9620 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]];
9622 scale: function(_) {
9623 return arguments.length ? (transform$$1 = scaleTranslate((k = +_) * sx, k * sy, tx, ty), reset()) : k;
9625 translate: function(_) {
9626 return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
9628 reflectX: function(_) {
9629 return arguments.length ? (transform$$1 = scaleTranslate(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
9631 reflectY: function(_) {
9632 return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
9634 fitExtent: function(extent, object) {
9635 return fitExtent(projection, extent, object);
9637 fitSize: function(size, object) {
9638 return fitSize(projection, size, object);
9640 fitWidth: function(width, object) {
9641 return fitWidth(projection, width, object);
9643 fitHeight: function(height, object) {
9644 return fitHeight(projection, height, object);
9649 function naturalEarth1Raw(lambda, phi) {
9650 var phi2 = phi * phi, phi4 = phi2 * phi2;
9652 lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
9653 phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
9657 naturalEarth1Raw.invert = function(x, y) {
9658 var phi = y, i = 25, delta;
9660 var phi2 = phi * phi, phi4 = phi2 * phi2;
9661 phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
9662 (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
9663 } while (abs(delta) > epsilon$2 && --i > 0);
9665 x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
9670 var naturalEarth1 = function() {
9671 return projection(naturalEarth1Raw)
9675 function orthographicRaw(x, y) {
9676 return [cos$1(y) * sin$1(x), sin$1(y)];
9679 orthographicRaw.invert = azimuthalInvert(asin);
9681 var orthographic = function() {
9682 return projection(orthographicRaw)
9684 .clipAngle(90 + epsilon$2);
9687 function stereographicRaw(x, y) {
9688 var cy = cos$1(y), k = 1 + cos$1(x) * cy;
9689 return [cy * sin$1(x) / k, sin$1(y) / k];
9692 stereographicRaw.invert = azimuthalInvert(function(z) {
9696 var stereographic = function() {
9697 return projection(stereographicRaw)
9702 function transverseMercatorRaw(lambda, phi) {
9703 return [log(tan((halfPi$2 + phi) / 2)), -lambda];
9706 transverseMercatorRaw.invert = function(x, y) {
9707 return [-y, 2 * atan(exp(x)) - halfPi$2];
9710 var transverseMercator = function() {
9711 var m = mercatorProjection(transverseMercatorRaw),
9715 m.center = function(_) {
9716 return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
9719 m.rotate = function(_) {
9720 return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
9723 return rotate([0, 0, 90])
9727 function defaultSeparation(a, b) {
9728 return a.parent === b.parent ? 1 : 2;
9731 function meanX(children) {
9732 return children.reduce(meanXReduce, 0) / children.length;
9735 function meanXReduce(x, c) {
9739 function maxY(children) {
9740 return 1 + children.reduce(maxYReduce, 0);
9743 function maxYReduce(y, c) {
9744 return Math.max(y, c.y);
9747 function leafLeft(node) {
9749 while (children = node.children) node = children[0];
9753 function leafRight(node) {
9755 while (children = node.children) node = children[children.length - 1];
9759 var cluster = function() {
9760 var separation = defaultSeparation,
9765 function cluster(root) {
9769 // First walk, computing the initial x & y values.
9770 root.eachAfter(function(node) {
9771 var children = node.children;
9773 node.x = meanX(children);
9774 node.y = maxY(children);
9776 node.x = previousNode ? x += separation(node, previousNode) : 0;
9778 previousNode = node;
9782 var left = leafLeft(root),
9783 right = leafRight(root),
9784 x0 = left.x - separation(left, right) / 2,
9785 x1 = right.x + separation(right, left) / 2;
9787 // Second walk, normalizing x & y to the desired size.
9788 return root.eachAfter(nodeSize ? function(node) {
9789 node.x = (node.x - root.x) * dx;
9790 node.y = (root.y - node.y) * dy;
9791 } : function(node) {
9792 node.x = (node.x - x0) / (x1 - x0) * dx;
9793 node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
9797 cluster.separation = function(x) {
9798 return arguments.length ? (separation = x, cluster) : separation;
9801 cluster.size = function(x) {
9802 return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
9805 cluster.nodeSize = function(x) {
9806 return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
9812 function count(node) {
9814 children = node.children,
9815 i = children && children.length;
9817 else while (--i >= 0) sum += children[i].value;
9821 var node_count = function() {
9822 return this.eachAfter(count);
9825 var node_each = function(callback) {
9826 var node = this, current, next = [node], children, i, n;
9828 current = next.reverse(), next = [];
9829 while (node = current.pop()) {
9830 callback(node), children = node.children;
9831 if (children) for (i = 0, n = children.length; i < n; ++i) {
9832 next.push(children[i]);
9835 } while (next.length);
9839 var node_eachBefore = function(callback) {
9840 var node = this, nodes = [node], children, i;
9841 while (node = nodes.pop()) {
9842 callback(node), children = node.children;
9843 if (children) for (i = children.length - 1; i >= 0; --i) {
9844 nodes.push(children[i]);
9850 var node_eachAfter = function(callback) {
9851 var node = this, nodes = [node], next = [], children, i, n;
9852 while (node = nodes.pop()) {
9853 next.push(node), children = node.children;
9854 if (children) for (i = 0, n = children.length; i < n; ++i) {
9855 nodes.push(children[i]);
9858 while (node = next.pop()) {
9864 var node_sum = function(value) {
9865 return this.eachAfter(function(node) {
9866 var sum = +value(node.data) || 0,
9867 children = node.children,
9868 i = children && children.length;
9869 while (--i >= 0) sum += children[i].value;
9874 var node_sort = function(compare) {
9875 return this.eachBefore(function(node) {
9876 if (node.children) {
9877 node.children.sort(compare);
9882 var node_path = function(end) {
9884 ancestor = leastCommonAncestor(start, end),
9886 while (start !== ancestor) {
9887 start = start.parent;
9890 var k = nodes.length;
9891 while (end !== ancestor) {
9892 nodes.splice(k, 0, end);
9898 function leastCommonAncestor(a, b) {
9899 if (a === b) return a;
9900 var aNodes = a.ancestors(),
9901 bNodes = b.ancestors(),
9913 var node_ancestors = function() {
9914 var node = this, nodes = [node];
9915 while (node = node.parent) {
9921 var node_descendants = function() {
9923 this.each(function(node) {
9929 var node_leaves = function() {
9931 this.eachBefore(function(node) {
9932 if (!node.children) {
9939 var node_links = function() {
9940 var root = this, links = [];
9941 root.each(function(node) {
9942 if (node !== root) { // Don’t include the root’s parent, if any.
9943 links.push({source: node.parent, target: node});
9949 function hierarchy(data, children) {
9950 var root = new Node(data),
9951 valued = +data.value && (root.value = data.value),
9959 if (children == null) children = defaultChildren;
9961 while (node = nodes.pop()) {
9962 if (valued) node.value = +node.data.value;
9963 if ((childs = children(node.data)) && (n = childs.length)) {
9964 node.children = new Array(n);
9965 for (i = n - 1; i >= 0; --i) {
9966 nodes.push(child = node.children[i] = new Node(childs[i]));
9967 child.parent = node;
9968 child.depth = node.depth + 1;
9973 return root.eachBefore(computeHeight);
9976 function node_copy() {
9977 return hierarchy(this).eachBefore(copyData);
9980 function defaultChildren(d) {
9984 function copyData(node) {
9985 node.data = node.data.data;
9988 function computeHeight(node) {
9990 do node.height = height;
9991 while ((node = node.parent) && (node.height < ++height));
9994 function Node(data) {
10001 Node.prototype = hierarchy.prototype = {
10005 eachAfter: node_eachAfter,
10006 eachBefore: node_eachBefore,
10010 ancestors: node_ancestors,
10011 descendants: node_descendants,
10012 leaves: node_leaves,
10017 var slice$3 = Array.prototype.slice;
10019 function shuffle$1(array) {
10020 var m = array.length,
10025 i = Math.random() * m-- | 0;
10027 array[m] = array[i];
10034 var enclose = function(circles) {
10035 var i = 0, n = (circles = shuffle$1(slice$3.call(circles))).length, B = [], p, e;
10039 if (e && enclosesWeak(e, p)) ++i;
10040 else e = encloseBasis(B = extendBasis(B, p)), i = 0;
10046 function extendBasis(B, p) {
10049 if (enclosesWeakAll(p, B)) return [p];
10051 // If we get here then B must have at least one element.
10052 for (i = 0; i < B.length; ++i) {
10053 if (enclosesNot(p, B[i])
10054 && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
10059 // If we get here then B must have at least two elements.
10060 for (i = 0; i < B.length - 1; ++i) {
10061 for (j = i + 1; j < B.length; ++j) {
10062 if (enclosesNot(encloseBasis2(B[i], B[j]), p)
10063 && enclosesNot(encloseBasis2(B[i], p), B[j])
10064 && enclosesNot(encloseBasis2(B[j], p), B[i])
10065 && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
10066 return [B[i], B[j], p];
10071 // If we get here then something is very wrong.
10075 function enclosesNot(a, b) {
10076 var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
10077 return dr < 0 || dr * dr < dx * dx + dy * dy;
10080 function enclosesWeak(a, b) {
10081 var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
10082 return dr > 0 && dr * dr > dx * dx + dy * dy;
10085 function enclosesWeakAll(a, B) {
10086 for (var i = 0; i < B.length; ++i) {
10087 if (!enclosesWeak(a, B[i])) {
10094 function encloseBasis(B) {
10095 switch (B.length) {
10096 case 1: return encloseBasis1(B[0]);
10097 case 2: return encloseBasis2(B[0], B[1]);
10098 case 3: return encloseBasis3(B[0], B[1], B[2]);
10102 function encloseBasis1(a) {
10110 function encloseBasis2(a, b) {
10111 var x1 = a.x, y1 = a.y, r1 = a.r,
10112 x2 = b.x, y2 = b.y, r2 = b.r,
10113 x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
10114 l = Math.sqrt(x21 * x21 + y21 * y21);
10116 x: (x1 + x2 + x21 / l * r21) / 2,
10117 y: (y1 + y2 + y21 / l * r21) / 2,
10118 r: (l + r1 + r2) / 2
10122 function encloseBasis3(a, b, c) {
10123 var x1 = a.x, y1 = a.y, r1 = a.r,
10124 x2 = b.x, y2 = b.y, r2 = b.r,
10125 x3 = c.x, y3 = c.y, r3 = c.r,
10132 d1 = x1 * x1 + y1 * y1 - r1 * r1,
10133 d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
10134 d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
10135 ab = a3 * b2 - a2 * b3,
10136 xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
10137 xb = (b3 * c2 - b2 * c3) / ab,
10138 ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
10139 yb = (a2 * c3 - a3 * c2) / ab,
10140 A = xb * xb + yb * yb - 1,
10141 B = 2 * (r1 + xa * xb + ya * yb),
10142 C = xa * xa + ya * ya - r1 * r1,
10143 r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
10145 x: x1 + xa + xb * r,
10146 y: y1 + ya + yb * r,
10151 function place(a, b, c) {
10158 dc = dx * dx + dy * dy;
10160 var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
10161 y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
10162 c.x = ax + x * dx + y * dy;
10163 c.y = ay + x * dy - y * dx;
10170 function intersects(a, b) {
10171 var dx = b.x - a.x,
10174 return dr * dr - 1e-6 > dx * dx + dy * dy;
10177 function score(node) {
10181 dx = (a.x * b.r + b.x * a.r) / ab,
10182 dy = (a.y * b.r + b.y * a.r) / ab;
10183 return dx * dx + dy * dy;
10186 function Node$1(circle) {
10189 this.previous = null;
10192 function packEnclose(circles) {
10193 if (!(n = circles.length)) return 0;
10195 var a, b, c, n, aa, ca, i, j, k, sj, sk;
10197 // Place the first circle.
10198 a = circles[0], a.x = 0, a.y = 0;
10199 if (!(n > 1)) return a.r;
10201 // Place the second circle.
10202 b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
10203 if (!(n > 2)) return a.r + b.r;
10205 // Place the third circle.
10206 place(b, a, c = circles[2]);
10208 // Initialize the front-chain using the first three circles a, b and c.
10209 a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
10210 a.next = c.previous = b;
10211 b.next = a.previous = c;
10212 c.next = b.previous = a;
10214 // Attempt to place each remaining circle…
10215 pack: for (i = 3; i < n; ++i) {
10216 place(a._, b._, c = circles[i]), c = new Node$1(c);
10218 // Find the closest intersecting circle on the front-chain, if any.
10219 // “Closeness” is determined by linear distance along the front-chain.
10220 // “Ahead” or “behind” is likewise determined by linear distance.
10221 j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
10224 if (intersects(j._, c._)) {
10225 b = j, a.next = b, b.previous = a, --i;
10228 sj += j._.r, j = j.next;
10230 if (intersects(k._, c._)) {
10231 a = k, a.next = b, b.previous = a, --i;
10234 sk += k._.r, k = k.previous;
10236 } while (j !== k.next);
10238 // Success! Insert the new circle c between a and b.
10239 c.previous = a, c.next = b, a.next = b.previous = b = c;
10241 // Compute the new closest circle pair to the centroid.
10243 while ((c = c.next) !== b) {
10244 if ((ca = score(c)) < aa) {
10251 // Compute the enclosing circle of the front chain.
10252 a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
10254 // Translate the circles to put the enclosing circle around the origin.
10255 for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
10260 var siblings = function(circles) {
10261 packEnclose(circles);
10265 function optional(f) {
10266 return f == null ? null : required(f);
10269 function required(f) {
10270 if (typeof f !== "function") throw new Error;
10274 function constantZero() {
10278 var constant$8 = function(x) {
10279 return function() {
10284 function defaultRadius$1(d) {
10285 return Math.sqrt(d.value);
10288 var index$2 = function() {
10292 padding = constantZero;
10294 function pack(root) {
10295 root.x = dx / 2, root.y = dy / 2;
10297 root.eachBefore(radiusLeaf(radius))
10298 .eachAfter(packChildren(padding, 0.5))
10299 .eachBefore(translateChild(1));
10301 root.eachBefore(radiusLeaf(defaultRadius$1))
10302 .eachAfter(packChildren(constantZero, 1))
10303 .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
10304 .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
10309 pack.radius = function(x) {
10310 return arguments.length ? (radius = optional(x), pack) : radius;
10313 pack.size = function(x) {
10314 return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
10317 pack.padding = function(x) {
10318 return arguments.length ? (padding = typeof x === "function" ? x : constant$8(+x), pack) : padding;
10324 function radiusLeaf(radius) {
10325 return function(node) {
10326 if (!node.children) {
10327 node.r = Math.max(0, +radius(node) || 0);
10332 function packChildren(padding, k) {
10333 return function(node) {
10334 if (children = node.children) {
10337 n = children.length,
10338 r = padding(node) * k || 0,
10341 if (r) for (i = 0; i < n; ++i) children[i].r += r;
10342 e = packEnclose(children);
10343 if (r) for (i = 0; i < n; ++i) children[i].r -= r;
10349 function translateChild(k) {
10350 return function(node) {
10351 var parent = node.parent;
10354 node.x = parent.x + k * node.x;
10355 node.y = parent.y + k * node.y;
10360 var roundNode = function(node) {
10361 node.x0 = Math.round(node.x0);
10362 node.y0 = Math.round(node.y0);
10363 node.x1 = Math.round(node.x1);
10364 node.y1 = Math.round(node.y1);
10367 var treemapDice = function(parent, x0, y0, x1, y1) {
10368 var nodes = parent.children,
10372 k = parent.value && (x1 - x0) / parent.value;
10375 node = nodes[i], node.y0 = y0, node.y1 = y1;
10376 node.x0 = x0, node.x1 = x0 += node.value * k;
10380 var partition = function() {
10386 function partition(root) {
10387 var n = root.height + 1;
10392 root.eachBefore(positionNode(dy, n));
10393 if (round) root.eachBefore(roundNode);
10397 function positionNode(dy, n) {
10398 return function(node) {
10399 if (node.children) {
10400 treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
10404 x1 = node.x1 - padding,
10405 y1 = node.y1 - padding;
10406 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
10407 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
10415 partition.round = function(x) {
10416 return arguments.length ? (round = !!x, partition) : round;
10419 partition.size = function(x) {
10420 return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
10423 partition.padding = function(x) {
10424 return arguments.length ? (padding = +x, partition) : padding;
10430 var keyPrefix$1 = "$";
10431 var preroot = {depth: -1};
10432 var ambiguous = {};
10434 function defaultId(d) {
10438 function defaultParentId(d) {
10442 var stratify = function() {
10443 var id = defaultId,
10444 parentId = defaultParentId;
10446 function stratify(data) {
10453 nodes = new Array(n),
10458 for (i = 0; i < n; ++i) {
10459 d = data[i], node = nodes[i] = new Node(d);
10460 if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
10461 nodeKey = keyPrefix$1 + (node.id = nodeId);
10462 nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
10466 for (i = 0; i < n; ++i) {
10467 node = nodes[i], nodeId = parentId(data[i], i, data);
10468 if (nodeId == null || !(nodeId += "")) {
10469 if (root) throw new Error("multiple roots");
10472 parent = nodeByKey[keyPrefix$1 + nodeId];
10473 if (!parent) throw new Error("missing: " + nodeId);
10474 if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
10475 if (parent.children) parent.children.push(node);
10476 else parent.children = [node];
10477 node.parent = parent;
10481 if (!root) throw new Error("no root");
10482 root.parent = preroot;
10483 root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
10484 root.parent = null;
10485 if (n > 0) throw new Error("cycle");
10490 stratify.id = function(x) {
10491 return arguments.length ? (id = required(x), stratify) : id;
10494 stratify.parentId = function(x) {
10495 return arguments.length ? (parentId = required(x), stratify) : parentId;
10501 function defaultSeparation$1(a, b) {
10502 return a.parent === b.parent ? 1 : 2;
10505 // function radialSeparation(a, b) {
10506 // return (a.parent === b.parent ? 1 : 2) / a.depth;
10509 // This function is used to traverse the left contour of a subtree (or
10510 // subforest). It returns the successor of v on this contour. This successor is
10511 // either given by the leftmost child of v or by the thread of v. The function
10512 // returns null if and only if v is on the highest level of its subtree.
10513 function nextLeft(v) {
10514 var children = v.children;
10515 return children ? children[0] : v.t;
10518 // This function works analogously to nextLeft.
10519 function nextRight(v) {
10520 var children = v.children;
10521 return children ? children[children.length - 1] : v.t;
10524 // Shifts the current subtree rooted at w+. This is done by increasing
10525 // prelim(w+) and mod(w+) by shift.
10526 function moveSubtree(wm, wp, shift) {
10527 var change = shift / (wp.i - wm.i);
10535 // All other shifts, applied to the smaller subtrees between w- and w+, are
10536 // performed by this function. To prepare the shifts, we have to adjust
10537 // change(w+), shift(w+), and change(w-).
10538 function executeShifts(v) {
10541 children = v.children,
10542 i = children.length,
10548 shift += w.s + (change += w.c);
10552 // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
10553 // returns the specified (default) ancestor.
10554 function nextAncestor(vim, v, ancestor) {
10555 return vim.a.parent === v.parent ? vim.a : ancestor;
10558 function TreeNode(node, i) {
10560 this.parent = null;
10561 this.children = null;
10562 this.A = null; // default ancestor
10563 this.a = this; // ancestor
10564 this.z = 0; // prelim
10566 this.c = 0; // change
10567 this.s = 0; // shift
10568 this.t = null; // thread
10569 this.i = i; // number
10572 TreeNode.prototype = Object.create(Node.prototype);
10574 function treeRoot(root) {
10575 var tree = new TreeNode(root, 0),
10583 while (node = nodes.pop()) {
10584 if (children = node._.children) {
10585 node.children = new Array(n = children.length);
10586 for (i = n - 1; i >= 0; --i) {
10587 nodes.push(child = node.children[i] = new TreeNode(children[i], i));
10588 child.parent = node;
10593 (tree.parent = new TreeNode(null, 0)).children = [tree];
10597 // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
10598 var tree = function() {
10599 var separation = defaultSeparation$1,
10604 function tree(root) {
10605 var t = treeRoot(root);
10607 // Compute the layout using Buchheim et al.’s algorithm.
10608 t.eachAfter(firstWalk), t.parent.m = -t.z;
10609 t.eachBefore(secondWalk);
10611 // If a fixed node size is specified, scale x and y.
10612 if (nodeSize) root.eachBefore(sizeNode);
10614 // If a fixed tree size is specified, scale x and y based on the extent.
10615 // Compute the left-most, right-most, and depth-most nodes for extents.
10620 root.eachBefore(function(node) {
10621 if (node.x < left.x) left = node;
10622 if (node.x > right.x) right = node;
10623 if (node.depth > bottom.depth) bottom = node;
10625 var s = left === right ? 1 : separation(left, right) / 2,
10627 kx = dx / (right.x + s + tx),
10628 ky = dy / (bottom.depth || 1);
10629 root.eachBefore(function(node) {
10630 node.x = (node.x + tx) * kx;
10631 node.y = node.depth * ky;
10638 // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
10639 // applied recursively to the children of v, as well as the function
10640 // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
10641 // node v is placed to the midpoint of its outermost children.
10642 function firstWalk(v) {
10643 var children = v.children,
10644 siblings = v.parent.children,
10645 w = v.i ? siblings[v.i - 1] : null;
10648 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
10650 v.z = w.z + separation(v._, w._);
10651 v.m = v.z - midpoint;
10656 v.z = w.z + separation(v._, w._);
10658 v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
10661 // Computes all real x-coordinates by summing up the modifiers recursively.
10662 function secondWalk(v) {
10663 v._.x = v.z + v.parent.m;
10667 // The core of the algorithm. Here, a new subtree is combined with the
10668 // previous subtrees. Threads are used to traverse the inside and outside
10669 // contours of the left and right subtree up to the highest common level. The
10670 // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
10671 // superscript o means outside and i means inside, the subscript - means left
10672 // subtree and + means right subtree. For summing up the modifiers along the
10673 // contour, we use respective variables si+, si-, so-, and so+. Whenever two
10674 // nodes of the inside contours conflict, we compute the left one of the
10675 // greatest uncommon ancestors using the function ANCESTOR and call MOVE
10676 // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
10677 // Finally, we add a new thread (if necessary).
10678 function apportion(v, w, ancestor) {
10683 vom = vip.parent.children[0],
10689 while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
10690 vom = nextLeft(vom);
10691 vop = nextRight(vop);
10693 shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
10695 moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
10704 if (vim && !nextRight(vop)) {
10706 vop.m += sim - sop;
10708 if (vip && !nextLeft(vom)) {
10710 vom.m += sip - som;
10717 function sizeNode(node) {
10719 node.y = node.depth * dy;
10722 tree.separation = function(x) {
10723 return arguments.length ? (separation = x, tree) : separation;
10726 tree.size = function(x) {
10727 return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
10730 tree.nodeSize = function(x) {
10731 return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
10737 var treemapSlice = function(parent, x0, y0, x1, y1) {
10738 var nodes = parent.children,
10742 k = parent.value && (y1 - y0) / parent.value;
10745 node = nodes[i], node.x0 = x0, node.x1 = x1;
10746 node.y0 = y0, node.y1 = y0 += node.value * k;
10750 var phi = (1 + Math.sqrt(5)) / 2;
10752 function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
10754 nodes = parent.children,
10761 value = parent.value,
10771 dx = x1 - x0, dy = y1 - y0;
10773 // Find the next non-empty node.
10774 do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
10775 minValue = maxValue = sumValue;
10776 alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
10777 beta = sumValue * sumValue * alpha;
10778 minRatio = Math.max(maxValue / beta, beta / minValue);
10780 // Keep adding nodes while the aspect ratio maintains or improves.
10781 for (; i1 < n; ++i1) {
10782 sumValue += nodeValue = nodes[i1].value;
10783 if (nodeValue < minValue) minValue = nodeValue;
10784 if (nodeValue > maxValue) maxValue = nodeValue;
10785 beta = sumValue * sumValue * alpha;
10786 newRatio = Math.max(maxValue / beta, beta / minValue);
10787 if (newRatio > minRatio) { sumValue -= nodeValue; break; }
10788 minRatio = newRatio;
10791 // Position and record the row orientation.
10792 rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
10793 if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
10794 else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
10795 value -= sumValue, i0 = i1;
10801 var squarify = (function custom(ratio) {
10803 function squarify(parent, x0, y0, x1, y1) {
10804 squarifyRatio(ratio, parent, x0, y0, x1, y1);
10807 squarify.ratio = function(x) {
10808 return custom((x = +x) > 1 ? x : 1);
10814 var index$3 = function() {
10815 var tile = squarify,
10819 paddingStack = [0],
10820 paddingInner = constantZero,
10821 paddingTop = constantZero,
10822 paddingRight = constantZero,
10823 paddingBottom = constantZero,
10824 paddingLeft = constantZero;
10826 function treemap(root) {
10831 root.eachBefore(positionNode);
10832 paddingStack = [0];
10833 if (round) root.eachBefore(roundNode);
10837 function positionNode(node) {
10838 var p = paddingStack[node.depth],
10843 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
10844 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
10849 if (node.children) {
10850 p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
10851 x0 += paddingLeft(node) - p;
10852 y0 += paddingTop(node) - p;
10853 x1 -= paddingRight(node) - p;
10854 y1 -= paddingBottom(node) - p;
10855 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
10856 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
10857 tile(node, x0, y0, x1, y1);
10861 treemap.round = function(x) {
10862 return arguments.length ? (round = !!x, treemap) : round;
10865 treemap.size = function(x) {
10866 return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
10869 treemap.tile = function(x) {
10870 return arguments.length ? (tile = required(x), treemap) : tile;
10873 treemap.padding = function(x) {
10874 return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
10877 treemap.paddingInner = function(x) {
10878 return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$8(+x), treemap) : paddingInner;
10881 treemap.paddingOuter = function(x) {
10882 return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
10885 treemap.paddingTop = function(x) {
10886 return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$8(+x), treemap) : paddingTop;
10889 treemap.paddingRight = function(x) {
10890 return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$8(+x), treemap) : paddingRight;
10893 treemap.paddingBottom = function(x) {
10894 return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$8(+x), treemap) : paddingBottom;
10897 treemap.paddingLeft = function(x) {
10898 return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$8(+x), treemap) : paddingLeft;
10904 var binary = function(parent, x0, y0, x1, y1) {
10905 var nodes = parent.children,
10906 i, n = nodes.length,
10907 sum, sums = new Array(n + 1);
10909 for (sums[0] = sum = i = 0; i < n; ++i) {
10910 sums[i + 1] = sum += nodes[i].value;
10913 partition(0, n, parent.value, x0, y0, x1, y1);
10915 function partition(i, j, value, x0, y0, x1, y1) {
10917 var node = nodes[i];
10918 node.x0 = x0, node.y0 = y0;
10919 node.x1 = x1, node.y1 = y1;
10923 var valueOffset = sums[i],
10924 valueTarget = (value / 2) + valueOffset,
10929 var mid = k + hi >>> 1;
10930 if (sums[mid] < valueTarget) k = mid + 1;
10934 if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
10936 var valueLeft = sums[k] - valueOffset,
10937 valueRight = value - valueLeft;
10939 if ((x1 - x0) > (y1 - y0)) {
10940 var xk = (x0 * valueRight + x1 * valueLeft) / value;
10941 partition(i, k, valueLeft, x0, y0, xk, y1);
10942 partition(k, j, valueRight, xk, y0, x1, y1);
10944 var yk = (y0 * valueRight + y1 * valueLeft) / value;
10945 partition(i, k, valueLeft, x0, y0, x1, yk);
10946 partition(k, j, valueRight, x0, yk, x1, y1);
10951 var sliceDice = function(parent, x0, y0, x1, y1) {
10952 (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
10955 var resquarify = (function custom(ratio) {
10957 function resquarify(parent, x0, y0, x1, y1) {
10958 if ((rows = parent._squarify) && (rows.ratio === ratio)) {
10966 value = parent.value;
10969 row = rows[j], nodes = row.children;
10970 for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
10971 if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
10972 else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
10973 value -= row.value;
10976 parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
10977 rows.ratio = ratio;
10981 resquarify.ratio = function(x) {
10982 return custom((x = +x) > 1 ? x : 1);
10988 var area$1 = function(polygon) {
10990 n = polygon.length,
10992 b = polygon[n - 1],
10998 area += a[1] * b[0] - a[0] * b[1];
11004 var centroid$1 = function(polygon) {
11006 n = polygon.length,
11010 b = polygon[n - 1],
11017 k += c = a[0] * b[1] - b[0] * a[1];
11018 x += (a[0] + b[0]) * c;
11019 y += (a[1] + b[1]) * c;
11022 return k *= 3, [x / k, y / k];
11025 // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
11026 // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
11027 // right, +y is up). Returns a positive value if ABC is counter-clockwise,
11028 // negative if clockwise, and zero if the points are collinear.
11029 var cross$1 = function(a, b, c) {
11030 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
11033 function lexicographicOrder(a, b) {
11034 return a[0] - b[0] || a[1] - b[1];
11037 // Computes the upper convex hull per the monotone chain algorithm.
11038 // Assumes points.length >= 3, is sorted by x, unique in y.
11039 // Returns an array of indices into points in left-to-right order.
11040 function computeUpperHullIndexes(points) {
11041 var n = points.length,
11045 for (var i = 2; i < n; ++i) {
11046 while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
11047 indexes[size++] = i;
11050 return indexes.slice(0, size); // remove popped points
11053 var hull = function(points) {
11054 if ((n = points.length) < 3) return null;
11058 sortedPoints = new Array(n),
11059 flippedPoints = new Array(n);
11061 for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
11062 sortedPoints.sort(lexicographicOrder);
11063 for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
11065 var upperIndexes = computeUpperHullIndexes(sortedPoints),
11066 lowerIndexes = computeUpperHullIndexes(flippedPoints);
11068 // Construct the hull polygon, removing possible duplicate endpoints.
11069 var skipLeft = lowerIndexes[0] === upperIndexes[0],
11070 skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
11073 // Add upper hull in right-to-l order.
11074 // Then add lower hull in left-to-right order.
11075 for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
11076 for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
11081 var contains$1 = function(polygon, point) {
11082 var n = polygon.length,
11083 p = polygon[n - 1],
11084 x = point[0], y = point[1],
11085 x0 = p[0], y0 = p[1],
11089 for (var i = 0; i < n; ++i) {
11090 p = polygon[i], x1 = p[0], y1 = p[1];
11091 if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
11098 var length$2 = function(polygon) {
11100 n = polygon.length,
11101 b = polygon[n - 1],
11116 perimeter += Math.sqrt(xa * xa + ya * ya);
11122 var slice$4 = [].slice;
11126 function Queue(size) {
11129 this._error = null;
11135 this._start = 0; // inside a synchronous task callback?
11138 Queue.prototype = queue.prototype = {
11139 constructor: Queue,
11140 defer: function(callback) {
11141 if (typeof callback !== "function") throw new Error("invalid callback");
11142 if (this._call) throw new Error("defer after await");
11143 if (this._error != null) return this;
11144 var t = slice$4.call(arguments, 1);
11146 ++this._waiting, this._tasks.push(t);
11150 abort: function() {
11151 if (this._error == null) abort(this, new Error("abort"));
11154 await: function(callback) {
11155 if (typeof callback !== "function") throw new Error("invalid callback");
11156 if (this._call) throw new Error("multiple await");
11157 this._call = function(error, results) { callback.apply(null, [error].concat(results)); };
11161 awaitAll: function(callback) {
11162 if (typeof callback !== "function") throw new Error("invalid callback");
11163 if (this._call) throw new Error("multiple await");
11164 this._call = callback;
11170 function poke$1(q) {
11172 try { start$1(q); } // let the current task complete
11174 if (q._tasks[q._ended + q._active - 1]) abort(q, e); // task errored synchronously
11175 else if (!q._data) throw e; // await callback errored synchronously
11180 function start$1(q) {
11181 while (q._start = q._waiting && q._active < q._size) {
11182 var i = q._ended + q._active,
11187 --q._waiting, ++q._active;
11188 t = c.apply(null, t);
11189 if (!q._tasks[i]) continue; // task finished synchronously
11190 q._tasks[i] = t || noabort;
11194 function end(q, i) {
11195 return function(e, r) {
11196 if (!q._tasks[i]) return; // ignore multiple callbacks
11197 --q._active, ++q._ended;
11198 q._tasks[i] = null;
11199 if (q._error != null) return; // ignore secondary errors
11204 if (q._waiting) poke$1(q);
11205 else maybeNotify(q);
11210 function abort(q, e) {
11211 var i = q._tasks.length, t;
11212 q._error = e; // ignore active callbacks
11213 q._data = undefined; // allow gc
11214 q._waiting = NaN; // prevent starting
11217 if (t = q._tasks[i]) {
11218 q._tasks[i] = null;
11221 catch (e) { /* ignore */ }
11226 q._active = NaN; // allow notification
11230 function maybeNotify(q) {
11231 if (!q._active && q._call) {
11233 q._data = undefined; // allow gc
11234 q._call(q._error, d);
11238 function queue(concurrency) {
11239 if (concurrency == null) concurrency = Infinity;
11240 else if (!((concurrency = +concurrency) >= 1)) throw new Error("invalid concurrency");
11241 return new Queue(concurrency);
11244 var defaultSource$1 = function() {
11245 return Math.random();
11248 var uniform = (function sourceRandomUniform(source) {
11249 function randomUniform(min, max) {
11250 min = min == null ? 0 : +min;
11251 max = max == null ? 1 : +max;
11252 if (arguments.length === 1) max = min, min = 0;
11254 return function() {
11255 return source() * max + min;
11259 randomUniform.source = sourceRandomUniform;
11261 return randomUniform;
11262 })(defaultSource$1);
11264 var normal = (function sourceRandomNormal(source) {
11265 function randomNormal(mu, sigma) {
11267 mu = mu == null ? 0 : +mu;
11268 sigma = sigma == null ? 1 : +sigma;
11269 return function() {
11272 // If available, use the second previously-generated uniform random.
11273 if (x != null) y = x, x = null;
11275 // Otherwise, generate a new x and y.
11277 x = source() * 2 - 1;
11278 y = source() * 2 - 1;
11280 } while (!r || r > 1);
11282 return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
11286 randomNormal.source = sourceRandomNormal;
11288 return randomNormal;
11289 })(defaultSource$1);
11291 var logNormal = (function sourceRandomLogNormal(source) {
11292 function randomLogNormal() {
11293 var randomNormal = normal.source(source).apply(this, arguments);
11294 return function() {
11295 return Math.exp(randomNormal());
11299 randomLogNormal.source = sourceRandomLogNormal;
11301 return randomLogNormal;
11302 })(defaultSource$1);
11304 var irwinHall = (function sourceRandomIrwinHall(source) {
11305 function randomIrwinHall(n) {
11306 return function() {
11307 for (var sum = 0, i = 0; i < n; ++i) sum += source();
11312 randomIrwinHall.source = sourceRandomIrwinHall;
11314 return randomIrwinHall;
11315 })(defaultSource$1);
11317 var bates = (function sourceRandomBates(source) {
11318 function randomBates(n) {
11319 var randomIrwinHall = irwinHall.source(source)(n);
11320 return function() {
11321 return randomIrwinHall() / n;
11325 randomBates.source = sourceRandomBates;
11327 return randomBates;
11328 })(defaultSource$1);
11330 var exponential$1 = (function sourceRandomExponential(source) {
11331 function randomExponential(lambda) {
11332 return function() {
11333 return -Math.log(1 - source()) / lambda;
11337 randomExponential.source = sourceRandomExponential;
11339 return randomExponential;
11340 })(defaultSource$1);
11342 var request = function(url, callback) {
11344 event = dispatch("beforesend", "progress", "load", "error"),
11347 xhr = new XMLHttpRequest,
11354 // If IE does not support CORS, use XDomainRequest.
11355 if (typeof XDomainRequest !== "undefined"
11356 && !("withCredentials" in xhr)
11357 && /^(http(s)?:)?\/\//.test(url)) xhr = new XDomainRequest;
11360 ? xhr.onload = xhr.onerror = xhr.ontimeout = respond
11361 : xhr.onreadystatechange = function(o) { xhr.readyState > 3 && respond(o); };
11363 function respond(o) {
11364 var status = xhr.status, result;
11365 if (!status && hasResponse(xhr)
11366 || status >= 200 && status < 300
11367 || status === 304) {
11370 result = response.call(request, xhr);
11372 event.call("error", request, e);
11378 event.call("load", request, result);
11380 event.call("error", request, o);
11384 xhr.onprogress = function(e) {
11385 event.call("progress", request, e);
11389 header: function(name, value) {
11390 name = (name + "").toLowerCase();
11391 if (arguments.length < 2) return headers.get(name);
11392 if (value == null) headers.remove(name);
11393 else headers.set(name, value + "");
11397 // If mimeType is non-null and no Accept header is set, a default is used.
11398 mimeType: function(value) {
11399 if (!arguments.length) return mimeType;
11400 mimeType = value == null ? null : value + "";
11404 // Specifies what type the response value should take;
11405 // for instance, arraybuffer, blob, document, or text.
11406 responseType: function(value) {
11407 if (!arguments.length) return responseType;
11408 responseType = value;
11412 timeout: function(value) {
11413 if (!arguments.length) return timeout;
11418 user: function(value) {
11419 return arguments.length < 1 ? user : (user = value == null ? null : value + "", request);
11422 password: function(value) {
11423 return arguments.length < 1 ? password : (password = value == null ? null : value + "", request);
11426 // Specify how to convert the response content to a specific type;
11427 // changes the callback value on "load" events.
11428 response: function(value) {
11433 // Alias for send("GET", …).
11434 get: function(data, callback) {
11435 return request.send("GET", data, callback);
11438 // Alias for send("POST", …).
11439 post: function(data, callback) {
11440 return request.send("POST", data, callback);
11443 // If callback is non-null, it will be used for error and load events.
11444 send: function(method, data, callback) {
11445 xhr.open(method, url, true, user, password);
11446 if (mimeType != null && !headers.has("accept")) headers.set("accept", mimeType + ",*/*");
11447 if (xhr.setRequestHeader) headers.each(function(value, name) { xhr.setRequestHeader(name, value); });
11448 if (mimeType != null && xhr.overrideMimeType) xhr.overrideMimeType(mimeType);
11449 if (responseType != null) xhr.responseType = responseType;
11450 if (timeout > 0) xhr.timeout = timeout;
11451 if (callback == null && typeof data === "function") callback = data, data = null;
11452 if (callback != null && callback.length === 1) callback = fixCallback(callback);
11453 if (callback != null) request.on("error", callback).on("load", function(xhr) { callback(null, xhr); });
11454 event.call("beforesend", request, xhr);
11455 xhr.send(data == null ? null : data);
11459 abort: function() {
11465 var value = event.on.apply(event, arguments);
11466 return value === event ? request : value;
11470 if (callback != null) {
11471 if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
11472 return request.get(callback);
11478 function fixCallback(callback) {
11479 return function(error, xhr) {
11480 callback(error == null ? xhr : null);
11484 function hasResponse(xhr) {
11485 var type = xhr.responseType;
11486 return type && type !== "text"
11487 ? xhr.response // null on error
11488 : xhr.responseText; // "" on error
11491 var type$1 = function(defaultMimeType, response) {
11492 return function(url, callback) {
11493 var r = request(url).mimeType(defaultMimeType).response(response);
11494 if (callback != null) {
11495 if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
11496 return r.get(callback);
11502 var html = type$1("text/html", function(xhr) {
11503 return document.createRange().createContextualFragment(xhr.responseText);
11506 var json = type$1("application/json", function(xhr) {
11507 return JSON.parse(xhr.responseText);
11510 var text = type$1("text/plain", function(xhr) {
11511 return xhr.responseText;
11514 var xml = type$1("application/xml", function(xhr) {
11515 var xml = xhr.responseXML;
11516 if (!xml) throw new Error("parse error");
11520 var dsv$1 = function(defaultMimeType, parse) {
11521 return function(url, row, callback) {
11522 if (arguments.length < 3) callback = row, row = null;
11523 var r = request(url).mimeType(defaultMimeType);
11524 r.row = function(_) { return arguments.length ? r.response(responseOf(parse, row = _)) : row; };
11526 return callback ? r.get(callback) : r;
11530 function responseOf(parse, row) {
11531 return function(request$$1) {
11532 return parse(request$$1.responseText, row);
11536 var csv$1 = dsv$1("text/csv", csvParse);
11538 var tsv$1 = dsv$1("text/tab-separated-values", tsvParse);
11540 var array$2 = Array.prototype;
11542 var map$3 = array$2.map;
11543 var slice$5 = array$2.slice;
11545 var implicit = {name: "implicit"};
11547 function ordinal(range) {
11548 var index = map$1(),
11550 unknown = implicit;
11552 range = range == null ? [] : slice$5.call(range);
11554 function scale(d) {
11555 var key = d + "", i = index.get(key);
11557 if (unknown !== implicit) return unknown;
11558 index.set(key, i = domain.push(d));
11560 return range[(i - 1) % range.length];
11563 scale.domain = function(_) {
11564 if (!arguments.length) return domain.slice();
11565 domain = [], index = map$1();
11566 var i = -1, n = _.length, d, key;
11567 while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
11571 scale.range = function(_) {
11572 return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
11575 scale.unknown = function(_) {
11576 return arguments.length ? (unknown = _, scale) : unknown;
11579 scale.copy = function() {
11590 var scale = ordinal().unknown(undefined),
11591 domain = scale.domain,
11592 ordinalRange = scale.range,
11601 delete scale.unknown;
11603 function rescale() {
11604 var n = domain().length,
11605 reverse = range$$1[1] < range$$1[0],
11606 start = range$$1[reverse - 0],
11607 stop = range$$1[1 - reverse];
11608 step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
11609 if (round) step = Math.floor(step);
11610 start += (stop - start - step * (n - paddingInner)) * align;
11611 bandwidth = step * (1 - paddingInner);
11612 if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
11613 var values = sequence(n).map(function(i) { return start + step * i; });
11614 return ordinalRange(reverse ? values.reverse() : values);
11617 scale.domain = function(_) {
11618 return arguments.length ? (domain(_), rescale()) : domain();
11621 scale.range = function(_) {
11622 return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
11625 scale.rangeRound = function(_) {
11626 return range$$1 = [+_[0], +_[1]], round = true, rescale();
11629 scale.bandwidth = function() {
11633 scale.step = function() {
11637 scale.round = function(_) {
11638 return arguments.length ? (round = !!_, rescale()) : round;
11641 scale.padding = function(_) {
11642 return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
11645 scale.paddingInner = function(_) {
11646 return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
11649 scale.paddingOuter = function(_) {
11650 return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
11653 scale.align = function(_) {
11654 return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
11657 scale.copy = function() {
11662 .paddingInner(paddingInner)
11663 .paddingOuter(paddingOuter)
11670 function pointish(scale) {
11671 var copy = scale.copy;
11673 scale.padding = scale.paddingOuter;
11674 delete scale.paddingInner;
11675 delete scale.paddingOuter;
11677 scale.copy = function() {
11678 return pointish(copy());
11684 function point$1() {
11685 return pointish(band().paddingInner(1));
11688 var constant$9 = function(x) {
11689 return function() {
11694 var number$2 = function(x) {
11700 function deinterpolateLinear(a, b) {
11701 return (b -= (a = +a))
11702 ? function(x) { return (x - a) / b; }
11706 function deinterpolateClamp(deinterpolate) {
11707 return function(a, b) {
11708 var d = deinterpolate(a = +a, b = +b);
11709 return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
11713 function reinterpolateClamp(reinterpolate) {
11714 return function(a, b) {
11715 var r = reinterpolate(a = +a, b = +b);
11716 return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
11720 function bimap(domain, range, deinterpolate, reinterpolate) {
11721 var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
11722 if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
11723 else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
11724 return function(x) { return r0(d0(x)); };
11727 function polymap(domain, range, deinterpolate, reinterpolate) {
11728 var j = Math.min(domain.length, range.length) - 1,
11733 // Reverse descending domains.
11734 if (domain[j] < domain[0]) {
11735 domain = domain.slice().reverse();
11736 range = range.slice().reverse();
11740 d[i] = deinterpolate(domain[i], domain[i + 1]);
11741 r[i] = reinterpolate(range[i], range[i + 1]);
11744 return function(x) {
11745 var i = bisectRight(domain, x, 1, j) - 1;
11746 return r[i](d[i](x));
11750 function copy(source, target) {
11752 .domain(source.domain())
11753 .range(source.range())
11754 .interpolate(source.interpolate())
11755 .clamp(source.clamp());
11758 // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
11759 // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
11760 function continuous(deinterpolate, reinterpolate) {
11763 interpolate$$1 = interpolateValue,
11769 function rescale() {
11770 piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
11771 output = input = null;
11775 function scale(x) {
11776 return (output || (output = piecewise(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
11779 scale.invert = function(y) {
11780 return (input || (input = piecewise(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
11783 scale.domain = function(_) {
11784 return arguments.length ? (domain = map$3.call(_, number$2), rescale()) : domain.slice();
11787 scale.range = function(_) {
11788 return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
11791 scale.rangeRound = function(_) {
11792 return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
11795 scale.clamp = function(_) {
11796 return arguments.length ? (clamp = !!_, rescale()) : clamp;
11799 scale.interpolate = function(_) {
11800 return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
11806 var tickFormat = function(domain, count, specifier) {
11807 var start = domain[0],
11808 stop = domain[domain.length - 1],
11809 step = tickStep(start, stop, count == null ? 10 : count),
11811 specifier = formatSpecifier(specifier == null ? ",f" : specifier);
11812 switch (specifier.type) {
11814 var value = Math.max(Math.abs(start), Math.abs(stop));
11815 if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
11816 return exports.formatPrefix(specifier, value);
11823 if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
11828 if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
11832 return exports.format(specifier);
11835 function linearish(scale) {
11836 var domain = scale.domain;
11838 scale.ticks = function(count) {
11840 return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
11843 scale.tickFormat = function(count, specifier) {
11844 return tickFormat(domain(), count, specifier);
11847 scale.nice = function(count) {
11848 if (count == null) count = 10;
11857 if (stop < start) {
11858 step = start, start = stop, stop = step;
11859 step = i0, i0 = i1, i1 = step;
11862 step = tickIncrement(start, stop, count);
11865 start = Math.floor(start / step) * step;
11866 stop = Math.ceil(stop / step) * step;
11867 step = tickIncrement(start, stop, count);
11868 } else if (step < 0) {
11869 start = Math.ceil(start * step) / step;
11870 stop = Math.floor(stop * step) / step;
11871 step = tickIncrement(start, stop, count);
11875 d[i0] = Math.floor(start / step) * step;
11876 d[i1] = Math.ceil(stop / step) * step;
11878 } else if (step < 0) {
11879 d[i0] = Math.ceil(start * step) / step;
11880 d[i1] = Math.floor(stop * step) / step;
11890 function linear$2() {
11891 var scale = continuous(deinterpolateLinear, reinterpolate);
11893 scale.copy = function() {
11894 return copy(scale, linear$2());
11897 return linearish(scale);
11900 function identity$6() {
11901 var domain = [0, 1];
11903 function scale(x) {
11907 scale.invert = scale;
11909 scale.domain = scale.range = function(_) {
11910 return arguments.length ? (domain = map$3.call(_, number$2), scale) : domain.slice();
11913 scale.copy = function() {
11914 return identity$6().domain(domain);
11917 return linearish(scale);
11920 var nice = function(domain, interval) {
11921 domain = domain.slice();
11924 i1 = domain.length - 1,
11930 t = i0, i0 = i1, i1 = t;
11931 t = x0, x0 = x1, x1 = t;
11934 domain[i0] = interval.floor(x0);
11935 domain[i1] = interval.ceil(x1);
11939 function deinterpolate(a, b) {
11940 return (b = Math.log(b / a))
11941 ? function(x) { return Math.log(x / a) / b; }
11945 function reinterpolate$1(a, b) {
11947 ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
11948 : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
11951 function pow10(x) {
11952 return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
11955 function powp(base) {
11956 return base === 10 ? pow10
11957 : base === Math.E ? Math.exp
11958 : function(x) { return Math.pow(base, x); };
11961 function logp(base) {
11962 return base === Math.E ? Math.log
11963 : base === 10 && Math.log10
11964 || base === 2 && Math.log2
11965 || (base = Math.log(base), function(x) { return Math.log(x) / base; });
11968 function reflect(f) {
11969 return function(x) {
11975 var scale = continuous(deinterpolate, reinterpolate$1).domain([1, 10]),
11976 domain = scale.domain,
11981 function rescale() {
11982 logs = logp(base), pows = powp(base);
11983 if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
11987 scale.base = function(_) {
11988 return arguments.length ? (base = +_, rescale()) : base;
11991 scale.domain = function(_) {
11992 return arguments.length ? (domain(_), rescale()) : domain();
11995 scale.ticks = function(count) {
11998 v = d[d.length - 1],
12001 if (r = v < u) i = u, u = v, v = i;
12008 n = count == null ? 10 : +count,
12011 if (!(base % 1) && j - i < n) {
12012 i = Math.round(i) - 1, j = Math.round(j) + 1;
12013 if (u > 0) for (; i < j; ++i) {
12014 for (k = 1, p = pows(i); k < base; ++k) {
12016 if (t < u) continue;
12020 } else for (; i < j; ++i) {
12021 for (k = base - 1, p = pows(i); k >= 1; --k) {
12023 if (t < u) continue;
12029 z = ticks(i, j, Math.min(j - i, n)).map(pows);
12032 return r ? z.reverse() : z;
12035 scale.tickFormat = function(count, specifier) {
12036 if (specifier == null) specifier = base === 10 ? ".0e" : ",";
12037 if (typeof specifier !== "function") specifier = exports.format(specifier);
12038 if (count === Infinity) return specifier;
12039 if (count == null) count = 10;
12040 var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
12041 return function(d) {
12042 var i = d / pows(Math.round(logs(d)));
12043 if (i * base < base - 0.5) i *= base;
12044 return i <= k ? specifier(d) : "";
12048 scale.nice = function() {
12049 return domain(nice(domain(), {
12050 floor: function(x) { return pows(Math.floor(logs(x))); },
12051 ceil: function(x) { return pows(Math.ceil(logs(x))); }
12055 scale.copy = function() {
12056 return copy(scale, log$1().base(base));
12062 function raise$1(x, exponent) {
12063 return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
12068 scale = continuous(deinterpolate, reinterpolate),
12069 domain = scale.domain;
12071 function deinterpolate(a, b) {
12072 return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
12073 ? function(x) { return (raise$1(x, exponent) - a) / b; }
12077 function reinterpolate(a, b) {
12078 b = raise$1(b, exponent) - (a = raise$1(a, exponent));
12079 return function(t) { return raise$1(a + b * t, 1 / exponent); };
12082 scale.exponent = function(_) {
12083 return arguments.length ? (exponent = +_, domain(domain())) : exponent;
12086 scale.copy = function() {
12087 return copy(scale, pow$1().exponent(exponent));
12090 return linearish(scale);
12093 function sqrt$1() {
12094 return pow$1().exponent(0.5);
12097 function quantile$$1() {
12102 function rescale() {
12103 var i = 0, n = Math.max(1, range.length);
12104 thresholds = new Array(n - 1);
12105 while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
12109 function scale(x) {
12110 if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
12113 scale.invertExtent = function(y) {
12114 var i = range.indexOf(y);
12115 return i < 0 ? [NaN, NaN] : [
12116 i > 0 ? thresholds[i - 1] : domain[0],
12117 i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
12121 scale.domain = function(_) {
12122 if (!arguments.length) return domain.slice();
12124 for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
12125 domain.sort(ascending);
12129 scale.range = function(_) {
12130 return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
12133 scale.quantiles = function() {
12134 return thresholds.slice();
12137 scale.copy = function() {
12138 return quantile$$1()
12146 function quantize$1() {
12153 function scale(x) {
12154 if (x <= x) return range[bisectRight(domain, x, 0, n)];
12157 function rescale() {
12159 domain = new Array(n);
12160 while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
12164 scale.domain = function(_) {
12165 return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
12168 scale.range = function(_) {
12169 return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
12172 scale.invertExtent = function(y) {
12173 var i = range.indexOf(y);
12174 return i < 0 ? [NaN, NaN]
12175 : i < 1 ? [x0, domain[0]]
12176 : i >= n ? [domain[n - 1], x1]
12177 : [domain[i - 1], domain[i]];
12180 scale.copy = function() {
12181 return quantize$1()
12186 return linearish(scale);
12189 function threshold$1() {
12190 var domain = [0.5],
12194 function scale(x) {
12195 if (x <= x) return range[bisectRight(domain, x, 0, n)];
12198 scale.domain = function(_) {
12199 return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
12202 scale.range = function(_) {
12203 return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
12206 scale.invertExtent = function(y) {
12207 var i = range.indexOf(y);
12208 return [domain[i - 1], domain[i]];
12211 scale.copy = function() {
12212 return threshold$1()
12220 var t0$1 = new Date;
12221 var t1$1 = new Date;
12223 function newInterval(floori, offseti, count, field) {
12225 function interval(date) {
12226 return floori(date = new Date(+date)), date;
12229 interval.floor = interval;
12231 interval.ceil = function(date) {
12232 return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
12235 interval.round = function(date) {
12236 var d0 = interval(date),
12237 d1 = interval.ceil(date);
12238 return date - d0 < d1 - date ? d0 : d1;
12241 interval.offset = function(date, step) {
12242 return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
12245 interval.range = function(start, stop, step) {
12246 var range = [], previous;
12247 start = interval.ceil(start);
12248 step = step == null ? 1 : Math.floor(step);
12249 if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
12250 do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
12251 while (previous < start && start < stop);
12255 interval.filter = function(test) {
12256 return newInterval(function(date) {
12257 if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
12258 }, function(date, step) {
12259 if (date >= date) {
12260 if (step < 0) while (++step <= 0) {
12261 while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
12262 } else while (--step >= 0) {
12263 while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
12270 interval.count = function(start, end) {
12271 t0$1.setTime(+start), t1$1.setTime(+end);
12272 floori(t0$1), floori(t1$1);
12273 return Math.floor(count(t0$1, t1$1));
12276 interval.every = function(step) {
12277 step = Math.floor(step);
12278 return !isFinite(step) || !(step > 0) ? null
12279 : !(step > 1) ? interval
12280 : interval.filter(field
12281 ? function(d) { return field(d) % step === 0; }
12282 : function(d) { return interval.count(0, d) % step === 0; });
12289 var millisecond = newInterval(function() {
12291 }, function(date, step) {
12292 date.setTime(+date + step);
12293 }, function(start, end) {
12294 return end - start;
12297 // An optimized implementation for this simple case.
12298 millisecond.every = function(k) {
12300 if (!isFinite(k) || !(k > 0)) return null;
12301 if (!(k > 1)) return millisecond;
12302 return newInterval(function(date) {
12303 date.setTime(Math.floor(date / k) * k);
12304 }, function(date, step) {
12305 date.setTime(+date + step * k);
12306 }, function(start, end) {
12307 return (end - start) / k;
12311 var milliseconds = millisecond.range;
12313 var durationSecond$1 = 1e3;
12314 var durationMinute$1 = 6e4;
12315 var durationHour$1 = 36e5;
12316 var durationDay$1 = 864e5;
12317 var durationWeek$1 = 6048e5;
12319 var second = newInterval(function(date) {
12320 date.setTime(Math.floor(date / durationSecond$1) * durationSecond$1);
12321 }, function(date, step) {
12322 date.setTime(+date + step * durationSecond$1);
12323 }, function(start, end) {
12324 return (end - start) / durationSecond$1;
12325 }, function(date) {
12326 return date.getUTCSeconds();
12329 var seconds = second.range;
12331 var minute = newInterval(function(date) {
12332 date.setTime(Math.floor(date / durationMinute$1) * durationMinute$1);
12333 }, function(date, step) {
12334 date.setTime(+date + step * durationMinute$1);
12335 }, function(start, end) {
12336 return (end - start) / durationMinute$1;
12337 }, function(date) {
12338 return date.getMinutes();
12341 var minutes = minute.range;
12343 var hour = newInterval(function(date) {
12344 var offset = date.getTimezoneOffset() * durationMinute$1 % durationHour$1;
12345 if (offset < 0) offset += durationHour$1;
12346 date.setTime(Math.floor((+date - offset) / durationHour$1) * durationHour$1 + offset);
12347 }, function(date, step) {
12348 date.setTime(+date + step * durationHour$1);
12349 }, function(start, end) {
12350 return (end - start) / durationHour$1;
12351 }, function(date) {
12352 return date.getHours();
12355 var hours = hour.range;
12357 var day = newInterval(function(date) {
12358 date.setHours(0, 0, 0, 0);
12359 }, function(date, step) {
12360 date.setDate(date.getDate() + step);
12361 }, function(start, end) {
12362 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationDay$1;
12363 }, function(date) {
12364 return date.getDate() - 1;
12367 var days = day.range;
12369 function weekday(i) {
12370 return newInterval(function(date) {
12371 date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
12372 date.setHours(0, 0, 0, 0);
12373 }, function(date, step) {
12374 date.setDate(date.getDate() + step * 7);
12375 }, function(start, end) {
12376 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationWeek$1;
12380 var sunday = weekday(0);
12381 var monday = weekday(1);
12382 var tuesday = weekday(2);
12383 var wednesday = weekday(3);
12384 var thursday = weekday(4);
12385 var friday = weekday(5);
12386 var saturday = weekday(6);
12388 var sundays = sunday.range;
12389 var mondays = monday.range;
12390 var tuesdays = tuesday.range;
12391 var wednesdays = wednesday.range;
12392 var thursdays = thursday.range;
12393 var fridays = friday.range;
12394 var saturdays = saturday.range;
12396 var month = newInterval(function(date) {
12398 date.setHours(0, 0, 0, 0);
12399 }, function(date, step) {
12400 date.setMonth(date.getMonth() + step);
12401 }, function(start, end) {
12402 return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
12403 }, function(date) {
12404 return date.getMonth();
12407 var months = month.range;
12409 var year = newInterval(function(date) {
12410 date.setMonth(0, 1);
12411 date.setHours(0, 0, 0, 0);
12412 }, function(date, step) {
12413 date.setFullYear(date.getFullYear() + step);
12414 }, function(start, end) {
12415 return end.getFullYear() - start.getFullYear();
12416 }, function(date) {
12417 return date.getFullYear();
12420 // An optimized implementation for this simple case.
12421 year.every = function(k) {
12422 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
12423 date.setFullYear(Math.floor(date.getFullYear() / k) * k);
12424 date.setMonth(0, 1);
12425 date.setHours(0, 0, 0, 0);
12426 }, function(date, step) {
12427 date.setFullYear(date.getFullYear() + step * k);
12431 var years = year.range;
12433 var utcMinute = newInterval(function(date) {
12434 date.setUTCSeconds(0, 0);
12435 }, function(date, step) {
12436 date.setTime(+date + step * durationMinute$1);
12437 }, function(start, end) {
12438 return (end - start) / durationMinute$1;
12439 }, function(date) {
12440 return date.getUTCMinutes();
12443 var utcMinutes = utcMinute.range;
12445 var utcHour = newInterval(function(date) {
12446 date.setUTCMinutes(0, 0, 0);
12447 }, function(date, step) {
12448 date.setTime(+date + step * durationHour$1);
12449 }, function(start, end) {
12450 return (end - start) / durationHour$1;
12451 }, function(date) {
12452 return date.getUTCHours();
12455 var utcHours = utcHour.range;
12457 var utcDay = newInterval(function(date) {
12458 date.setUTCHours(0, 0, 0, 0);
12459 }, function(date, step) {
12460 date.setUTCDate(date.getUTCDate() + step);
12461 }, function(start, end) {
12462 return (end - start) / durationDay$1;
12463 }, function(date) {
12464 return date.getUTCDate() - 1;
12467 var utcDays = utcDay.range;
12469 function utcWeekday(i) {
12470 return newInterval(function(date) {
12471 date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
12472 date.setUTCHours(0, 0, 0, 0);
12473 }, function(date, step) {
12474 date.setUTCDate(date.getUTCDate() + step * 7);
12475 }, function(start, end) {
12476 return (end - start) / durationWeek$1;
12480 var utcSunday = utcWeekday(0);
12481 var utcMonday = utcWeekday(1);
12482 var utcTuesday = utcWeekday(2);
12483 var utcWednesday = utcWeekday(3);
12484 var utcThursday = utcWeekday(4);
12485 var utcFriday = utcWeekday(5);
12486 var utcSaturday = utcWeekday(6);
12488 var utcSundays = utcSunday.range;
12489 var utcMondays = utcMonday.range;
12490 var utcTuesdays = utcTuesday.range;
12491 var utcWednesdays = utcWednesday.range;
12492 var utcThursdays = utcThursday.range;
12493 var utcFridays = utcFriday.range;
12494 var utcSaturdays = utcSaturday.range;
12496 var utcMonth = newInterval(function(date) {
12497 date.setUTCDate(1);
12498 date.setUTCHours(0, 0, 0, 0);
12499 }, function(date, step) {
12500 date.setUTCMonth(date.getUTCMonth() + step);
12501 }, function(start, end) {
12502 return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
12503 }, function(date) {
12504 return date.getUTCMonth();
12507 var utcMonths = utcMonth.range;
12509 var utcYear = newInterval(function(date) {
12510 date.setUTCMonth(0, 1);
12511 date.setUTCHours(0, 0, 0, 0);
12512 }, function(date, step) {
12513 date.setUTCFullYear(date.getUTCFullYear() + step);
12514 }, function(start, end) {
12515 return end.getUTCFullYear() - start.getUTCFullYear();
12516 }, function(date) {
12517 return date.getUTCFullYear();
12520 // An optimized implementation for this simple case.
12521 utcYear.every = function(k) {
12522 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
12523 date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
12524 date.setUTCMonth(0, 1);
12525 date.setUTCHours(0, 0, 0, 0);
12526 }, function(date, step) {
12527 date.setUTCFullYear(date.getUTCFullYear() + step * k);
12531 var utcYears = utcYear.range;
12533 function localDate(d) {
12534 if (0 <= d.y && d.y < 100) {
12535 var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
12536 date.setFullYear(d.y);
12539 return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
12542 function utcDate(d) {
12543 if (0 <= d.y && d.y < 100) {
12544 var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
12545 date.setUTCFullYear(d.y);
12548 return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
12551 function newYear(y) {
12552 return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
12555 function formatLocale$1(locale) {
12556 var locale_dateTime = locale.dateTime,
12557 locale_date = locale.date,
12558 locale_time = locale.time,
12559 locale_periods = locale.periods,
12560 locale_weekdays = locale.days,
12561 locale_shortWeekdays = locale.shortDays,
12562 locale_months = locale.months,
12563 locale_shortMonths = locale.shortMonths;
12565 var periodRe = formatRe(locale_periods),
12566 periodLookup = formatLookup(locale_periods),
12567 weekdayRe = formatRe(locale_weekdays),
12568 weekdayLookup = formatLookup(locale_weekdays),
12569 shortWeekdayRe = formatRe(locale_shortWeekdays),
12570 shortWeekdayLookup = formatLookup(locale_shortWeekdays),
12571 monthRe = formatRe(locale_months),
12572 monthLookup = formatLookup(locale_months),
12573 shortMonthRe = formatRe(locale_shortMonths),
12574 shortMonthLookup = formatLookup(locale_shortMonths);
12577 "a": formatShortWeekday,
12578 "A": formatWeekday,
12579 "b": formatShortMonth,
12582 "d": formatDayOfMonth,
12583 "e": formatDayOfMonth,
12584 "f": formatMicroseconds,
12587 "j": formatDayOfYear,
12588 "L": formatMilliseconds,
12589 "m": formatMonthNumber,
12590 "M": formatMinutes,
12592 "Q": formatUnixTimestamp,
12593 "s": formatUnixTimestampSeconds,
12594 "S": formatSeconds,
12595 "u": formatWeekdayNumberMonday,
12596 "U": formatWeekNumberSunday,
12597 "V": formatWeekNumberISO,
12598 "w": formatWeekdayNumberSunday,
12599 "W": formatWeekNumberMonday,
12603 "Y": formatFullYear,
12605 "%": formatLiteralPercent
12609 "a": formatUTCShortWeekday,
12610 "A": formatUTCWeekday,
12611 "b": formatUTCShortMonth,
12612 "B": formatUTCMonth,
12614 "d": formatUTCDayOfMonth,
12615 "e": formatUTCDayOfMonth,
12616 "f": formatUTCMicroseconds,
12617 "H": formatUTCHour24,
12618 "I": formatUTCHour12,
12619 "j": formatUTCDayOfYear,
12620 "L": formatUTCMilliseconds,
12621 "m": formatUTCMonthNumber,
12622 "M": formatUTCMinutes,
12623 "p": formatUTCPeriod,
12624 "Q": formatUnixTimestamp,
12625 "s": formatUnixTimestampSeconds,
12626 "S": formatUTCSeconds,
12627 "u": formatUTCWeekdayNumberMonday,
12628 "U": formatUTCWeekNumberSunday,
12629 "V": formatUTCWeekNumberISO,
12630 "w": formatUTCWeekdayNumberSunday,
12631 "W": formatUTCWeekNumberMonday,
12634 "y": formatUTCYear,
12635 "Y": formatUTCFullYear,
12636 "Z": formatUTCZone,
12637 "%": formatLiteralPercent
12641 "a": parseShortWeekday,
12643 "b": parseShortMonth,
12645 "c": parseLocaleDateTime,
12646 "d": parseDayOfMonth,
12647 "e": parseDayOfMonth,
12648 "f": parseMicroseconds,
12651 "j": parseDayOfYear,
12652 "L": parseMilliseconds,
12653 "m": parseMonthNumber,
12656 "Q": parseUnixTimestamp,
12657 "s": parseUnixTimestampSeconds,
12659 "u": parseWeekdayNumberMonday,
12660 "U": parseWeekNumberSunday,
12661 "V": parseWeekNumberISO,
12662 "w": parseWeekdayNumberSunday,
12663 "W": parseWeekNumberMonday,
12664 "x": parseLocaleDate,
12665 "X": parseLocaleTime,
12667 "Y": parseFullYear,
12669 "%": parseLiteralPercent
12672 // These recursive directive definitions must be deferred.
12673 formats.x = newFormat(locale_date, formats);
12674 formats.X = newFormat(locale_time, formats);
12675 formats.c = newFormat(locale_dateTime, formats);
12676 utcFormats.x = newFormat(locale_date, utcFormats);
12677 utcFormats.X = newFormat(locale_time, utcFormats);
12678 utcFormats.c = newFormat(locale_dateTime, utcFormats);
12680 function newFormat(specifier, formats) {
12681 return function(date) {
12685 n = specifier.length,
12690 if (!(date instanceof Date)) date = new Date(+date);
12693 if (specifier.charCodeAt(i) === 37) {
12694 string.push(specifier.slice(j, i));
12695 if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
12696 else pad = c === "e" ? " " : "0";
12697 if (format = formats[c]) c = format(date, pad);
12703 string.push(specifier.slice(j, i));
12704 return string.join("");
12708 function newParse(specifier, newDate) {
12709 return function(string) {
12710 var d = newYear(1900),
12711 i = parseSpecifier(d, specifier, string += "", 0),
12713 if (i != string.length) return null;
12715 // If a UNIX timestamp is specified, return it.
12716 if ("Q" in d) return new Date(d.Q);
12718 // The am-pm flag is 0 for AM, and 1 for PM.
12719 if ("p" in d) d.H = d.H % 12 + d.p * 12;
12721 // Convert day-of-week and week-of-year to day-of-year.
12723 if (d.V < 1 || d.V > 53) return null;
12724 if (!("w" in d)) d.w = 1;
12726 week = utcDate(newYear(d.y)), day$$1 = week.getUTCDay();
12727 week = day$$1 > 4 || day$$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
12728 week = utcDay.offset(week, (d.V - 1) * 7);
12729 d.y = week.getUTCFullYear();
12730 d.m = week.getUTCMonth();
12731 d.d = week.getUTCDate() + (d.w + 6) % 7;
12733 week = newDate(newYear(d.y)), day$$1 = week.getDay();
12734 week = day$$1 > 4 || day$$1 === 0 ? monday.ceil(week) : monday(week);
12735 week = day.offset(week, (d.V - 1) * 7);
12736 d.y = week.getFullYear();
12737 d.m = week.getMonth();
12738 d.d = week.getDate() + (d.w + 6) % 7;
12740 } else if ("W" in d || "U" in d) {
12741 if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
12742 day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
12744 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;
12747 // If a time zone is specified, all fields are interpreted as UTC and then
12748 // offset according to the specified time zone.
12750 d.H += d.Z / 100 | 0;
12755 // Otherwise, all fields are in local time.
12760 function parseSpecifier(d, specifier, string, j) {
12762 n = specifier.length,
12768 if (j >= m) return -1;
12769 c = specifier.charCodeAt(i++);
12771 c = specifier.charAt(i++);
12772 parse = parses[c in pads ? specifier.charAt(i++) : c];
12773 if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
12774 } else if (c != string.charCodeAt(j++)) {
12782 function parsePeriod(d, string, i) {
12783 var n = periodRe.exec(string.slice(i));
12784 return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12787 function parseShortWeekday(d, string, i) {
12788 var n = shortWeekdayRe.exec(string.slice(i));
12789 return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12792 function parseWeekday(d, string, i) {
12793 var n = weekdayRe.exec(string.slice(i));
12794 return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12797 function parseShortMonth(d, string, i) {
12798 var n = shortMonthRe.exec(string.slice(i));
12799 return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12802 function parseMonth(d, string, i) {
12803 var n = monthRe.exec(string.slice(i));
12804 return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12807 function parseLocaleDateTime(d, string, i) {
12808 return parseSpecifier(d, locale_dateTime, string, i);
12811 function parseLocaleDate(d, string, i) {
12812 return parseSpecifier(d, locale_date, string, i);
12815 function parseLocaleTime(d, string, i) {
12816 return parseSpecifier(d, locale_time, string, i);
12819 function formatShortWeekday(d) {
12820 return locale_shortWeekdays[d.getDay()];
12823 function formatWeekday(d) {
12824 return locale_weekdays[d.getDay()];
12827 function formatShortMonth(d) {
12828 return locale_shortMonths[d.getMonth()];
12831 function formatMonth(d) {
12832 return locale_months[d.getMonth()];
12835 function formatPeriod(d) {
12836 return locale_periods[+(d.getHours() >= 12)];
12839 function formatUTCShortWeekday(d) {
12840 return locale_shortWeekdays[d.getUTCDay()];
12843 function formatUTCWeekday(d) {
12844 return locale_weekdays[d.getUTCDay()];
12847 function formatUTCShortMonth(d) {
12848 return locale_shortMonths[d.getUTCMonth()];
12851 function formatUTCMonth(d) {
12852 return locale_months[d.getUTCMonth()];
12855 function formatUTCPeriod(d) {
12856 return locale_periods[+(d.getUTCHours() >= 12)];
12860 format: function(specifier) {
12861 var f = newFormat(specifier += "", formats);
12862 f.toString = function() { return specifier; };
12865 parse: function(specifier) {
12866 var p = newParse(specifier += "", localDate);
12867 p.toString = function() { return specifier; };
12870 utcFormat: function(specifier) {
12871 var f = newFormat(specifier += "", utcFormats);
12872 f.toString = function() { return specifier; };
12875 utcParse: function(specifier) {
12876 var p = newParse(specifier, utcDate);
12877 p.toString = function() { return specifier; };
12883 var pads = {"-": "", "_": " ", "0": "0"};
12884 var numberRe = /^\s*\d+/;
12885 var percentRe = /^%/;
12886 var requoteRe = /[\\^$*+?|[\]().{}]/g;
12888 function pad(value, fill, width) {
12889 var sign = value < 0 ? "-" : "",
12890 string = (sign ? -value : value) + "",
12891 length = string.length;
12892 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
12895 function requote(s) {
12896 return s.replace(requoteRe, "\\$&");
12899 function formatRe(names) {
12900 return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
12903 function formatLookup(names) {
12904 var map = {}, i = -1, n = names.length;
12905 while (++i < n) map[names[i].toLowerCase()] = i;
12909 function parseWeekdayNumberSunday(d, string, i) {
12910 var n = numberRe.exec(string.slice(i, i + 1));
12911 return n ? (d.w = +n[0], i + n[0].length) : -1;
12914 function parseWeekdayNumberMonday(d, string, i) {
12915 var n = numberRe.exec(string.slice(i, i + 1));
12916 return n ? (d.u = +n[0], i + n[0].length) : -1;
12919 function parseWeekNumberSunday(d, string, i) {
12920 var n = numberRe.exec(string.slice(i, i + 2));
12921 return n ? (d.U = +n[0], i + n[0].length) : -1;
12924 function parseWeekNumberISO(d, string, i) {
12925 var n = numberRe.exec(string.slice(i, i + 2));
12926 return n ? (d.V = +n[0], i + n[0].length) : -1;
12929 function parseWeekNumberMonday(d, string, i) {
12930 var n = numberRe.exec(string.slice(i, i + 2));
12931 return n ? (d.W = +n[0], i + n[0].length) : -1;
12934 function parseFullYear(d, string, i) {
12935 var n = numberRe.exec(string.slice(i, i + 4));
12936 return n ? (d.y = +n[0], i + n[0].length) : -1;
12939 function parseYear(d, string, i) {
12940 var n = numberRe.exec(string.slice(i, i + 2));
12941 return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
12944 function parseZone(d, string, i) {
12945 var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
12946 return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
12949 function parseMonthNumber(d, string, i) {
12950 var n = numberRe.exec(string.slice(i, i + 2));
12951 return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
12954 function parseDayOfMonth(d, string, i) {
12955 var n = numberRe.exec(string.slice(i, i + 2));
12956 return n ? (d.d = +n[0], i + n[0].length) : -1;
12959 function parseDayOfYear(d, string, i) {
12960 var n = numberRe.exec(string.slice(i, i + 3));
12961 return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
12964 function parseHour24(d, string, i) {
12965 var n = numberRe.exec(string.slice(i, i + 2));
12966 return n ? (d.H = +n[0], i + n[0].length) : -1;
12969 function parseMinutes(d, string, i) {
12970 var n = numberRe.exec(string.slice(i, i + 2));
12971 return n ? (d.M = +n[0], i + n[0].length) : -1;
12974 function parseSeconds(d, string, i) {
12975 var n = numberRe.exec(string.slice(i, i + 2));
12976 return n ? (d.S = +n[0], i + n[0].length) : -1;
12979 function parseMilliseconds(d, string, i) {
12980 var n = numberRe.exec(string.slice(i, i + 3));
12981 return n ? (d.L = +n[0], i + n[0].length) : -1;
12984 function parseMicroseconds(d, string, i) {
12985 var n = numberRe.exec(string.slice(i, i + 6));
12986 return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
12989 function parseLiteralPercent(d, string, i) {
12990 var n = percentRe.exec(string.slice(i, i + 1));
12991 return n ? i + n[0].length : -1;
12994 function parseUnixTimestamp(d, string, i) {
12995 var n = numberRe.exec(string.slice(i));
12996 return n ? (d.Q = +n[0], i + n[0].length) : -1;
12999 function parseUnixTimestampSeconds(d, string, i) {
13000 var n = numberRe.exec(string.slice(i));
13001 return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
13004 function formatDayOfMonth(d, p) {
13005 return pad(d.getDate(), p, 2);
13008 function formatHour24(d, p) {
13009 return pad(d.getHours(), p, 2);
13012 function formatHour12(d, p) {
13013 return pad(d.getHours() % 12 || 12, p, 2);
13016 function formatDayOfYear(d, p) {
13017 return pad(1 + day.count(year(d), d), p, 3);
13020 function formatMilliseconds(d, p) {
13021 return pad(d.getMilliseconds(), p, 3);
13024 function formatMicroseconds(d, p) {
13025 return formatMilliseconds(d, p) + "000";
13028 function formatMonthNumber(d, p) {
13029 return pad(d.getMonth() + 1, p, 2);
13032 function formatMinutes(d, p) {
13033 return pad(d.getMinutes(), p, 2);
13036 function formatSeconds(d, p) {
13037 return pad(d.getSeconds(), p, 2);
13040 function formatWeekdayNumberMonday(d) {
13041 var day$$1 = d.getDay();
13042 return day$$1 === 0 ? 7 : day$$1;
13045 function formatWeekNumberSunday(d, p) {
13046 return pad(sunday.count(year(d), d), p, 2);
13049 function formatWeekNumberISO(d, p) {
13050 var day$$1 = d.getDay();
13051 d = (day$$1 >= 4 || day$$1 === 0) ? thursday(d) : thursday.ceil(d);
13052 return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
13055 function formatWeekdayNumberSunday(d) {
13059 function formatWeekNumberMonday(d, p) {
13060 return pad(monday.count(year(d), d), p, 2);
13063 function formatYear(d, p) {
13064 return pad(d.getFullYear() % 100, p, 2);
13067 function formatFullYear(d, p) {
13068 return pad(d.getFullYear() % 10000, p, 4);
13071 function formatZone(d) {
13072 var z = d.getTimezoneOffset();
13073 return (z > 0 ? "-" : (z *= -1, "+"))
13074 + pad(z / 60 | 0, "0", 2)
13075 + pad(z % 60, "0", 2);
13078 function formatUTCDayOfMonth(d, p) {
13079 return pad(d.getUTCDate(), p, 2);
13082 function formatUTCHour24(d, p) {
13083 return pad(d.getUTCHours(), p, 2);
13086 function formatUTCHour12(d, p) {
13087 return pad(d.getUTCHours() % 12 || 12, p, 2);
13090 function formatUTCDayOfYear(d, p) {
13091 return pad(1 + utcDay.count(utcYear(d), d), p, 3);
13094 function formatUTCMilliseconds(d, p) {
13095 return pad(d.getUTCMilliseconds(), p, 3);
13098 function formatUTCMicroseconds(d, p) {
13099 return formatUTCMilliseconds(d, p) + "000";
13102 function formatUTCMonthNumber(d, p) {
13103 return pad(d.getUTCMonth() + 1, p, 2);
13106 function formatUTCMinutes(d, p) {
13107 return pad(d.getUTCMinutes(), p, 2);
13110 function formatUTCSeconds(d, p) {
13111 return pad(d.getUTCSeconds(), p, 2);
13114 function formatUTCWeekdayNumberMonday(d) {
13115 var dow = d.getUTCDay();
13116 return dow === 0 ? 7 : dow;
13119 function formatUTCWeekNumberSunday(d, p) {
13120 return pad(utcSunday.count(utcYear(d), d), p, 2);
13123 function formatUTCWeekNumberISO(d, p) {
13124 var day$$1 = d.getUTCDay();
13125 d = (day$$1 >= 4 || day$$1 === 0) ? utcThursday(d) : utcThursday.ceil(d);
13126 return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
13129 function formatUTCWeekdayNumberSunday(d) {
13130 return d.getUTCDay();
13133 function formatUTCWeekNumberMonday(d, p) {
13134 return pad(utcMonday.count(utcYear(d), d), p, 2);
13137 function formatUTCYear(d, p) {
13138 return pad(d.getUTCFullYear() % 100, p, 2);
13141 function formatUTCFullYear(d, p) {
13142 return pad(d.getUTCFullYear() % 10000, p, 4);
13145 function formatUTCZone() {
13149 function formatLiteralPercent() {
13153 function formatUnixTimestamp(d) {
13157 function formatUnixTimestampSeconds(d) {
13158 return Math.floor(+d / 1000);
13168 dateTime: "%x, %X",
13169 date: "%-m/%-d/%Y",
13170 time: "%-I:%M:%S %p",
13171 periods: ["AM", "PM"],
13172 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
13173 shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
13174 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
13175 shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
13178 function defaultLocale$1(definition) {
13179 locale$1 = formatLocale$1(definition);
13180 exports.timeFormat = locale$1.format;
13181 exports.timeParse = locale$1.parse;
13182 exports.utcFormat = locale$1.utcFormat;
13183 exports.utcParse = locale$1.utcParse;
13187 var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
13189 function formatIsoNative(date) {
13190 return date.toISOString();
13193 var formatIso = Date.prototype.toISOString
13195 : exports.utcFormat(isoSpecifier);
13197 function parseIsoNative(string) {
13198 var date = new Date(string);
13199 return isNaN(date) ? null : date;
13202 var parseIso = +new Date("2000-01-01T00:00:00.000Z")
13204 : exports.utcParse(isoSpecifier);
13206 var durationSecond = 1000;
13207 var durationMinute = durationSecond * 60;
13208 var durationHour = durationMinute * 60;
13209 var durationDay = durationHour * 24;
13210 var durationWeek = durationDay * 7;
13211 var durationMonth = durationDay * 30;
13212 var durationYear = durationDay * 365;
13214 function date$1(t) {
13215 return new Date(t);
13218 function number$3(t) {
13219 return t instanceof Date ? +t : +new Date(+t);
13222 function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
13223 var scale = continuous(deinterpolateLinear, reinterpolate),
13224 invert = scale.invert,
13225 domain = scale.domain;
13227 var formatMillisecond = format(".%L"),
13228 formatSecond = format(":%S"),
13229 formatMinute = format("%I:%M"),
13230 formatHour = format("%I %p"),
13231 formatDay = format("%a %d"),
13232 formatWeek = format("%b %d"),
13233 formatMonth = format("%B"),
13234 formatYear = format("%Y");
13236 var tickIntervals = [
13237 [second$$1, 1, durationSecond],
13238 [second$$1, 5, 5 * durationSecond],
13239 [second$$1, 15, 15 * durationSecond],
13240 [second$$1, 30, 30 * durationSecond],
13241 [minute$$1, 1, durationMinute],
13242 [minute$$1, 5, 5 * durationMinute],
13243 [minute$$1, 15, 15 * durationMinute],
13244 [minute$$1, 30, 30 * durationMinute],
13245 [ hour$$1, 1, durationHour ],
13246 [ hour$$1, 3, 3 * durationHour ],
13247 [ hour$$1, 6, 6 * durationHour ],
13248 [ hour$$1, 12, 12 * durationHour ],
13249 [ day$$1, 1, durationDay ],
13250 [ day$$1, 2, 2 * durationDay ],
13251 [ week, 1, durationWeek ],
13252 [ month$$1, 1, durationMonth ],
13253 [ month$$1, 3, 3 * durationMonth ],
13254 [ year$$1, 1, durationYear ]
13257 function tickFormat(date) {
13258 return (second$$1(date) < date ? formatMillisecond
13259 : minute$$1(date) < date ? formatSecond
13260 : hour$$1(date) < date ? formatMinute
13261 : day$$1(date) < date ? formatHour
13262 : month$$1(date) < date ? (week(date) < date ? formatDay : formatWeek)
13263 : year$$1(date) < date ? formatMonth
13264 : formatYear)(date);
13267 function tickInterval(interval, start, stop, step) {
13268 if (interval == null) interval = 10;
13270 // If a desired tick count is specified, pick a reasonable tick interval
13271 // based on the extent of the domain and a rough estimate of tick size.
13272 // Otherwise, assume interval is already a time interval and use it.
13273 if (typeof interval === "number") {
13274 var target = Math.abs(stop - start) / interval,
13275 i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
13276 if (i === tickIntervals.length) {
13277 step = tickStep(start / durationYear, stop / durationYear, interval);
13278 interval = year$$1;
13280 i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
13284 step = Math.max(tickStep(start, stop, interval), 1);
13285 interval = millisecond$$1;
13289 return step == null ? interval : interval.every(step);
13292 scale.invert = function(y) {
13293 return new Date(invert(y));
13296 scale.domain = function(_) {
13297 return arguments.length ? domain(map$3.call(_, number$3)) : domain().map(date$1);
13300 scale.ticks = function(interval, step) {
13303 t1 = d[d.length - 1],
13306 if (r) t = t0, t0 = t1, t1 = t;
13307 t = tickInterval(interval, t0, t1, step);
13308 t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
13309 return r ? t.reverse() : t;
13312 scale.tickFormat = function(count, specifier) {
13313 return specifier == null ? tickFormat : format(specifier);
13316 scale.nice = function(interval, step) {
13318 return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
13319 ? domain(nice(d, interval))
13323 scale.copy = function() {
13324 return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
13330 var time = function() {
13331 return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
13334 var utcTime = function() {
13335 return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
13338 var colors = function(s) {
13339 return s.match(/.{6}/g).map(function(x) {
13344 var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
13346 var category20b = colors("393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6");
13348 var category20c = colors("3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9");
13350 var category20 = colors("1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5");
13352 var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
13354 var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
13356 var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
13358 var rainbow = cubehelix();
13360 var rainbow$1 = function(t) {
13361 if (t < 0 || t > 1) t -= Math.floor(t);
13362 var ts = Math.abs(t - 0.5);
13363 rainbow.h = 360 * t - 100;
13364 rainbow.s = 1.5 - 1.5 * ts;
13365 rainbow.l = 0.8 - 0.9 * ts;
13366 return rainbow + "";
13369 function ramp(range) {
13370 var n = range.length;
13371 return function(t) {
13372 return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
13376 var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
13378 var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
13380 var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
13382 var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
13384 function sequential(interpolator) {
13389 function scale(x) {
13390 var t = (x - x0) / (x1 - x0);
13391 return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
13394 scale.domain = function(_) {
13395 return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1];
13398 scale.clamp = function(_) {
13399 return arguments.length ? (clamp = !!_, scale) : clamp;
13402 scale.interpolator = function(_) {
13403 return arguments.length ? (interpolator = _, scale) : interpolator;
13406 scale.copy = function() {
13407 return sequential(interpolator).domain([x0, x1]).clamp(clamp);
13410 return linearish(scale);
13413 var constant$10 = function(x) {
13414 return function constant() {
13419 var abs$1 = Math.abs;
13420 var atan2$1 = Math.atan2;
13421 var cos$2 = Math.cos;
13422 var max$2 = Math.max;
13423 var min$1 = Math.min;
13424 var sin$2 = Math.sin;
13425 var sqrt$2 = Math.sqrt;
13427 var epsilon$3 = 1e-12;
13428 var pi$4 = Math.PI;
13429 var halfPi$3 = pi$4 / 2;
13430 var tau$4 = 2 * pi$4;
13432 function acos$1(x) {
13433 return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
13436 function asin$1(x) {
13437 return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
13440 function arcInnerRadius(d) {
13441 return d.innerRadius;
13444 function arcOuterRadius(d) {
13445 return d.outerRadius;
13448 function arcStartAngle(d) {
13449 return d.startAngle;
13452 function arcEndAngle(d) {
13456 function arcPadAngle(d) {
13457 return d && d.padAngle; // Note: optional!
13460 function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
13461 var x10 = x1 - x0, y10 = y1 - y0,
13462 x32 = x3 - x2, y32 = y3 - y2,
13463 t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
13464 return [x0 + t * x10, y0 + t * y10];
13467 // Compute perpendicular offset line of length rc.
13468 // http://mathworld.wolfram.com/Circle-LineIntersection.html
13469 function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
13472 lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
13479 x00 = (x11 + x10) / 2,
13480 y00 = (y11 + y10) / 2,
13483 d2 = dx * dx + dy * dy,
13485 D = x11 * y10 - x10 * y11,
13486 d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
13487 cx0 = (D * dy - dx * d) / d2,
13488 cy0 = (-D * dx - dy * d) / d2,
13489 cx1 = (D * dy + dx * d) / d2,
13490 cy1 = (-D * dx + dy * d) / d2,
13496 // Pick the closer of the two intersection points.
13497 // TODO Is there a faster way to determine which intersection to use?
13498 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
13505 x11: cx0 * (r1 / r - 1),
13506 y11: cy0 * (r1 / r - 1)
13510 var arc = function() {
13511 var innerRadius = arcInnerRadius,
13512 outerRadius = arcOuterRadius,
13513 cornerRadius = constant$10(0),
13515 startAngle = arcStartAngle,
13516 endAngle = arcEndAngle,
13517 padAngle = arcPadAngle,
13523 r0 = +innerRadius.apply(this, arguments),
13524 r1 = +outerRadius.apply(this, arguments),
13525 a0 = startAngle.apply(this, arguments) - halfPi$3,
13526 a1 = endAngle.apply(this, arguments) - halfPi$3,
13527 da = abs$1(a1 - a0),
13530 if (!context) context = buffer = path();
13532 // Ensure that the outer radius is always larger than the inner radius.
13533 if (r1 < r0) r = r1, r1 = r0, r0 = r;
13536 if (!(r1 > epsilon$3)) context.moveTo(0, 0);
13538 // Or is it a circle or annulus?
13539 else if (da > tau$4 - epsilon$3) {
13540 context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
13541 context.arc(0, 0, r1, a0, a1, !cw);
13542 if (r0 > epsilon$3) {
13543 context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
13544 context.arc(0, 0, r0, a1, a0, cw);
13548 // Or is it a circular or annular sector?
13556 ap = padAngle.apply(this, arguments) / 2,
13557 rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
13558 rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
13564 // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
13565 if (rp > epsilon$3) {
13566 var p0 = asin$1(rp / r0 * sin$2(ap)),
13567 p1 = asin$1(rp / r1 * sin$2(ap));
13568 if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
13569 else da0 = 0, a00 = a10 = (a0 + a1) / 2;
13570 if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
13571 else da1 = 0, a01 = a11 = (a0 + a1) / 2;
13574 var x01 = r1 * cos$2(a01),
13575 y01 = r1 * sin$2(a01),
13576 x10 = r0 * cos$2(a10),
13577 y10 = r0 * sin$2(a10);
13579 // Apply rounded corners?
13580 if (rc > epsilon$3) {
13581 var x11 = r1 * cos$2(a11),
13582 y11 = r1 * sin$2(a11),
13583 x00 = r0 * cos$2(a00),
13584 y00 = r0 * sin$2(a00);
13586 // Restrict the corner radius according to the sector angle.
13588 var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
13593 kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
13594 lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
13595 rc0 = min$1(rc, (r0 - lc) / (kc - 1));
13596 rc1 = min$1(rc, (r1 - lc) / (kc + 1));
13600 // Is the sector collapsed to a line?
13601 if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
13603 // Does the sector’s outer ring have rounded corners?
13604 else if (rc1 > epsilon$3) {
13605 t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
13606 t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
13608 context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
13610 // Have the corners merged?
13611 if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
13613 // Otherwise, draw the two corners and the ring.
13615 context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
13616 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);
13617 context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
13621 // Or is the outer ring just a circular arc?
13622 else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
13624 // Is there no inner ring, and it’s a circular sector?
13625 // Or perhaps it’s an annular sector collapsed due to padding?
13626 if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
13628 // Does the sector’s inner ring (or point) have rounded corners?
13629 else if (rc0 > epsilon$3) {
13630 t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
13631 t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
13633 context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
13635 // Have the corners merged?
13636 if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
13638 // Otherwise, draw the two corners and the ring.
13640 context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
13641 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);
13642 context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
13646 // Or is the inner ring just a circular arc?
13647 else context.arc(0, 0, r0, a10, a00, cw);
13650 context.closePath();
13652 if (buffer) return context = null, buffer + "" || null;
13655 arc.centroid = function() {
13656 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
13657 a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
13658 return [cos$2(a) * r, sin$2(a) * r];
13661 arc.innerRadius = function(_) {
13662 return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : innerRadius;
13665 arc.outerRadius = function(_) {
13666 return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : outerRadius;
13669 arc.cornerRadius = function(_) {
13670 return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : cornerRadius;
13673 arc.padRadius = function(_) {
13674 return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), arc) : padRadius;
13677 arc.startAngle = function(_) {
13678 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : startAngle;
13681 arc.endAngle = function(_) {
13682 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : endAngle;
13685 arc.padAngle = function(_) {
13686 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : padAngle;
13689 arc.context = function(_) {
13690 return arguments.length ? (context = _ == null ? null : _, arc) : context;
13696 function Linear(context) {
13697 this._context = context;
13700 Linear.prototype = {
13701 areaStart: function() {
13704 areaEnd: function() {
13707 lineStart: function() {
13710 lineEnd: function() {
13711 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
13712 this._line = 1 - this._line;
13714 point: function(x, y) {
13716 switch (this._point) {
13717 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
13718 case 1: this._point = 2; // proceed
13719 default: this._context.lineTo(x, y); break;
13724 var curveLinear = function(context) {
13725 return new Linear(context);
13736 var line = function() {
13739 defined = constant$10(true),
13741 curve = curveLinear,
13744 function line(data) {
13751 if (context == null) output = curve(buffer = path());
13753 for (i = 0; i <= n; ++i) {
13754 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
13755 if (defined0 = !defined0) output.lineStart();
13756 else output.lineEnd();
13758 if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
13761 if (buffer) return output = null, buffer + "" || null;
13764 line.x = function(_) {
13765 return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : x$$1;
13768 line.y = function(_) {
13769 return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : y$$1;
13772 line.defined = function(_) {
13773 return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), line) : defined;
13776 line.curve = function(_) {
13777 return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
13780 line.context = function(_) {
13781 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
13787 var area$2 = function() {
13790 y0 = constant$10(0),
13792 defined = constant$10(true),
13794 curve = curveLinear,
13797 function area(data) {
13805 x0z = new Array(n),
13806 y0z = new Array(n);
13808 if (context == null) output = curve(buffer = path());
13810 for (i = 0; i <= n; ++i) {
13811 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
13812 if (defined0 = !defined0) {
13814 output.areaStart();
13815 output.lineStart();
13818 output.lineStart();
13819 for (k = i - 1; k >= j; --k) {
13820 output.point(x0z[k], y0z[k]);
13827 x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
13828 output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
13832 if (buffer) return output = null, buffer + "" || null;
13835 function arealine() {
13836 return line().defined(defined).curve(curve).context(context);
13839 area.x = function(_) {
13840 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), x1 = null, area) : x0;
13843 area.x0 = function(_) {
13844 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), area) : x0;
13847 area.x1 = function(_) {
13848 return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : x1;
13851 area.y = function(_) {
13852 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), y1 = null, area) : y0;
13855 area.y0 = function(_) {
13856 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), area) : y0;
13859 area.y1 = function(_) {
13860 return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : y1;
13864 area.lineY0 = function() {
13865 return arealine().x(x0).y(y0);
13868 area.lineY1 = function() {
13869 return arealine().x(x0).y(y1);
13872 area.lineX1 = function() {
13873 return arealine().x(x1).y(y0);
13876 area.defined = function(_) {
13877 return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), area) : defined;
13880 area.curve = function(_) {
13881 return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
13884 area.context = function(_) {
13885 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
13891 var descending$1 = function(a, b) {
13892 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
13895 var identity$7 = function(d) {
13899 var pie = function() {
13900 var value = identity$7,
13901 sortValues = descending$1,
13903 startAngle = constant$10(0),
13904 endAngle = constant$10(tau$4),
13905 padAngle = constant$10(0);
13907 function pie(data) {
13913 index = new Array(n),
13914 arcs = new Array(n),
13915 a0 = +startAngle.apply(this, arguments),
13916 da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
13918 p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
13919 pa = p * (da < 0 ? -1 : 1),
13922 for (i = 0; i < n; ++i) {
13923 if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
13928 // Optionally sort the arcs by previously-computed values or by data.
13929 if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
13930 else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
13932 // Compute the arcs! They are stored in the original data's order.
13933 for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
13934 j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
13947 pie.value = function(_) {
13948 return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), pie) : value;
13951 pie.sortValues = function(_) {
13952 return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
13955 pie.sort = function(_) {
13956 return arguments.length ? (sort = _, sortValues = null, pie) : sort;
13959 pie.startAngle = function(_) {
13960 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : startAngle;
13963 pie.endAngle = function(_) {
13964 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : endAngle;
13967 pie.padAngle = function(_) {
13968 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : padAngle;
13974 var curveRadialLinear = curveRadial(curveLinear);
13976 function Radial(curve) {
13977 this._curve = curve;
13980 Radial.prototype = {
13981 areaStart: function() {
13982 this._curve.areaStart();
13984 areaEnd: function() {
13985 this._curve.areaEnd();
13987 lineStart: function() {
13988 this._curve.lineStart();
13990 lineEnd: function() {
13991 this._curve.lineEnd();
13993 point: function(a, r) {
13994 this._curve.point(r * Math.sin(a), r * -Math.cos(a));
13998 function curveRadial(curve) {
14000 function radial(context) {
14001 return new Radial(curve(context));
14004 radial._curve = curve;
14009 function lineRadial(l) {
14012 l.angle = l.x, delete l.x;
14013 l.radius = l.y, delete l.y;
14015 l.curve = function(_) {
14016 return arguments.length ? c(curveRadial(_)) : c()._curve;
14022 var lineRadial$1 = function() {
14023 return lineRadial(line().curve(curveRadialLinear));
14026 var areaRadial = function() {
14027 var a = area$2().curve(curveRadialLinear),
14034 a.angle = a.x, delete a.x;
14035 a.startAngle = a.x0, delete a.x0;
14036 a.endAngle = a.x1, delete a.x1;
14037 a.radius = a.y, delete a.y;
14038 a.innerRadius = a.y0, delete a.y0;
14039 a.outerRadius = a.y1, delete a.y1;
14040 a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
14041 a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
14042 a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
14043 a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
14045 a.curve = function(_) {
14046 return arguments.length ? c(curveRadial(_)) : c()._curve;
14052 var pointRadial = function(x, y) {
14053 return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
14056 var slice$6 = Array.prototype.slice;
14058 function linkSource(d) {
14062 function linkTarget(d) {
14066 function link$2(curve) {
14067 var source = linkSource,
14068 target = linkTarget,
14074 var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
14075 if (!context) context = buffer = path();
14076 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));
14077 if (buffer) return context = null, buffer + "" || null;
14080 link.source = function(_) {
14081 return arguments.length ? (source = _, link) : source;
14084 link.target = function(_) {
14085 return arguments.length ? (target = _, link) : target;
14088 link.x = function(_) {
14089 return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : x$$1;
14092 link.y = function(_) {
14093 return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : y$$1;
14096 link.context = function(_) {
14097 return arguments.length ? (context = _ == null ? null : _, link) : context;
14103 function curveHorizontal(context, x0, y0, x1, y1) {
14104 context.moveTo(x0, y0);
14105 context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
14108 function curveVertical(context, x0, y0, x1, y1) {
14109 context.moveTo(x0, y0);
14110 context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
14113 function curveRadial$1(context, x0, y0, x1, y1) {
14114 var p0 = pointRadial(x0, y0),
14115 p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
14116 p2 = pointRadial(x1, y0),
14117 p3 = pointRadial(x1, y1);
14118 context.moveTo(p0[0], p0[1]);
14119 context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
14122 function linkHorizontal() {
14123 return link$2(curveHorizontal);
14126 function linkVertical() {
14127 return link$2(curveVertical);
14130 function linkRadial() {
14131 var l = link$2(curveRadial$1);
14132 l.angle = l.x, delete l.x;
14133 l.radius = l.y, delete l.y;
14138 draw: function(context, size) {
14139 var r = Math.sqrt(size / pi$4);
14140 context.moveTo(r, 0);
14141 context.arc(0, 0, r, 0, tau$4);
14146 draw: function(context, size) {
14147 var r = Math.sqrt(size / 5) / 2;
14148 context.moveTo(-3 * r, -r);
14149 context.lineTo(-r, -r);
14150 context.lineTo(-r, -3 * r);
14151 context.lineTo(r, -3 * r);
14152 context.lineTo(r, -r);
14153 context.lineTo(3 * r, -r);
14154 context.lineTo(3 * r, r);
14155 context.lineTo(r, r);
14156 context.lineTo(r, 3 * r);
14157 context.lineTo(-r, 3 * r);
14158 context.lineTo(-r, r);
14159 context.lineTo(-3 * r, r);
14160 context.closePath();
14164 var tan30 = Math.sqrt(1 / 3);
14165 var tan30_2 = tan30 * 2;
14168 draw: function(context, size) {
14169 var y = Math.sqrt(size / tan30_2),
14171 context.moveTo(0, -y);
14172 context.lineTo(x, 0);
14173 context.lineTo(0, y);
14174 context.lineTo(-x, 0);
14175 context.closePath();
14179 var ka = 0.89081309152928522810;
14180 var kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10);
14181 var kx = Math.sin(tau$4 / 10) * kr;
14182 var ky = -Math.cos(tau$4 / 10) * kr;
14185 draw: function(context, size) {
14186 var r = Math.sqrt(size * ka),
14189 context.moveTo(0, -r);
14190 context.lineTo(x, y);
14191 for (var i = 1; i < 5; ++i) {
14192 var a = tau$4 * i / 5,
14195 context.lineTo(s * r, -c * r);
14196 context.lineTo(c * x - s * y, s * x + c * y);
14198 context.closePath();
14203 draw: function(context, size) {
14204 var w = Math.sqrt(size),
14206 context.rect(x, x, w, w);
14210 var sqrt3 = Math.sqrt(3);
14213 draw: function(context, size) {
14214 var y = -Math.sqrt(size / (sqrt3 * 3));
14215 context.moveTo(0, y * 2);
14216 context.lineTo(-sqrt3 * y, -y);
14217 context.lineTo(sqrt3 * y, -y);
14218 context.closePath();
14223 var s = Math.sqrt(3) / 2;
14224 var k = 1 / Math.sqrt(12);
14225 var a = (k / 2 + 1) * 3;
14228 draw: function(context, size) {
14229 var r = Math.sqrt(size / a),
14236 context.moveTo(x0, y0);
14237 context.lineTo(x1, y1);
14238 context.lineTo(x2, y2);
14239 context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
14240 context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
14241 context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
14242 context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
14243 context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
14244 context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
14245 context.closePath();
14259 var symbol = function() {
14260 var type = constant$10(circle$2),
14261 size = constant$10(64),
14264 function symbol() {
14266 if (!context) context = buffer = path();
14267 type.apply(this, arguments).draw(context, +size.apply(this, arguments));
14268 if (buffer) return context = null, buffer + "" || null;
14271 symbol.type = function(_) {
14272 return arguments.length ? (type = typeof _ === "function" ? _ : constant$10(_), symbol) : type;
14275 symbol.size = function(_) {
14276 return arguments.length ? (size = typeof _ === "function" ? _ : constant$10(+_), symbol) : size;
14279 symbol.context = function(_) {
14280 return arguments.length ? (context = _ == null ? null : _, symbol) : context;
14286 var noop$2 = function() {};
14288 function point$2(that, x, y) {
14289 that._context.bezierCurveTo(
14290 (2 * that._x0 + that._x1) / 3,
14291 (2 * that._y0 + that._y1) / 3,
14292 (that._x0 + 2 * that._x1) / 3,
14293 (that._y0 + 2 * that._y1) / 3,
14294 (that._x0 + 4 * that._x1 + x) / 6,
14295 (that._y0 + 4 * that._y1 + y) / 6
14299 function Basis(context) {
14300 this._context = context;
14303 Basis.prototype = {
14304 areaStart: function() {
14307 areaEnd: function() {
14310 lineStart: function() {
14311 this._x0 = this._x1 =
14312 this._y0 = this._y1 = NaN;
14315 lineEnd: function() {
14316 switch (this._point) {
14317 case 3: point$2(this, this._x1, this._y1); // proceed
14318 case 2: this._context.lineTo(this._x1, this._y1); break;
14320 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14321 this._line = 1 - this._line;
14323 point: function(x, y) {
14325 switch (this._point) {
14326 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14327 case 1: this._point = 2; break;
14328 case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
14329 default: point$2(this, x, y); break;
14331 this._x0 = this._x1, this._x1 = x;
14332 this._y0 = this._y1, this._y1 = y;
14336 var basis$2 = function(context) {
14337 return new Basis(context);
14340 function BasisClosed(context) {
14341 this._context = context;
14344 BasisClosed.prototype = {
14347 lineStart: function() {
14348 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
14349 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
14352 lineEnd: function() {
14353 switch (this._point) {
14355 this._context.moveTo(this._x2, this._y2);
14356 this._context.closePath();
14360 this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
14361 this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
14362 this._context.closePath();
14366 this.point(this._x2, this._y2);
14367 this.point(this._x3, this._y3);
14368 this.point(this._x4, this._y4);
14373 point: function(x, y) {
14375 switch (this._point) {
14376 case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
14377 case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
14378 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;
14379 default: point$2(this, x, y); break;
14381 this._x0 = this._x1, this._x1 = x;
14382 this._y0 = this._y1, this._y1 = y;
14386 var basisClosed$1 = function(context) {
14387 return new BasisClosed(context);
14390 function BasisOpen(context) {
14391 this._context = context;
14394 BasisOpen.prototype = {
14395 areaStart: function() {
14398 areaEnd: function() {
14401 lineStart: function() {
14402 this._x0 = this._x1 =
14403 this._y0 = this._y1 = NaN;
14406 lineEnd: function() {
14407 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
14408 this._line = 1 - this._line;
14410 point: function(x, y) {
14412 switch (this._point) {
14413 case 0: this._point = 1; break;
14414 case 1: this._point = 2; break;
14415 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;
14416 case 3: this._point = 4; // proceed
14417 default: point$2(this, x, y); break;
14419 this._x0 = this._x1, this._x1 = x;
14420 this._y0 = this._y1, this._y1 = y;
14424 var basisOpen = function(context) {
14425 return new BasisOpen(context);
14428 function Bundle(context, beta) {
14429 this._basis = new Basis(context);
14433 Bundle.prototype = {
14434 lineStart: function() {
14437 this._basis.lineStart();
14439 lineEnd: function() {
14455 this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
14456 this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
14461 this._x = this._y = null;
14462 this._basis.lineEnd();
14464 point: function(x, y) {
14470 var bundle = (function custom(beta) {
14472 function bundle(context) {
14473 return beta === 1 ? new Basis(context) : new Bundle(context, beta);
14476 bundle.beta = function(beta) {
14477 return custom(+beta);
14483 function point$3(that, x, y) {
14484 that._context.bezierCurveTo(
14485 that._x1 + that._k * (that._x2 - that._x0),
14486 that._y1 + that._k * (that._y2 - that._y0),
14487 that._x2 + that._k * (that._x1 - x),
14488 that._y2 + that._k * (that._y1 - y),
14494 function Cardinal(context, tension) {
14495 this._context = context;
14496 this._k = (1 - tension) / 6;
14499 Cardinal.prototype = {
14500 areaStart: function() {
14503 areaEnd: function() {
14506 lineStart: function() {
14507 this._x0 = this._x1 = this._x2 =
14508 this._y0 = this._y1 = this._y2 = NaN;
14511 lineEnd: function() {
14512 switch (this._point) {
14513 case 2: this._context.lineTo(this._x2, this._y2); break;
14514 case 3: point$3(this, this._x1, this._y1); break;
14516 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14517 this._line = 1 - this._line;
14519 point: function(x, y) {
14521 switch (this._point) {
14522 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14523 case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
14524 case 2: this._point = 3; // proceed
14525 default: point$3(this, x, y); break;
14527 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14528 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14532 var cardinal = (function custom(tension) {
14534 function cardinal(context) {
14535 return new Cardinal(context, tension);
14538 cardinal.tension = function(tension) {
14539 return custom(+tension);
14545 function CardinalClosed(context, tension) {
14546 this._context = context;
14547 this._k = (1 - tension) / 6;
14550 CardinalClosed.prototype = {
14553 lineStart: function() {
14554 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
14555 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
14558 lineEnd: function() {
14559 switch (this._point) {
14561 this._context.moveTo(this._x3, this._y3);
14562 this._context.closePath();
14566 this._context.lineTo(this._x3, this._y3);
14567 this._context.closePath();
14571 this.point(this._x3, this._y3);
14572 this.point(this._x4, this._y4);
14573 this.point(this._x5, this._y5);
14578 point: function(x, y) {
14580 switch (this._point) {
14581 case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
14582 case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
14583 case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
14584 default: point$3(this, x, y); break;
14586 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14587 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14591 var cardinalClosed = (function custom(tension) {
14593 function cardinal$$1(context) {
14594 return new CardinalClosed(context, tension);
14597 cardinal$$1.tension = function(tension) {
14598 return custom(+tension);
14601 return cardinal$$1;
14604 function CardinalOpen(context, tension) {
14605 this._context = context;
14606 this._k = (1 - tension) / 6;
14609 CardinalOpen.prototype = {
14610 areaStart: function() {
14613 areaEnd: function() {
14616 lineStart: function() {
14617 this._x0 = this._x1 = this._x2 =
14618 this._y0 = this._y1 = this._y2 = NaN;
14621 lineEnd: function() {
14622 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
14623 this._line = 1 - this._line;
14625 point: function(x, y) {
14627 switch (this._point) {
14628 case 0: this._point = 1; break;
14629 case 1: this._point = 2; break;
14630 case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
14631 case 3: this._point = 4; // proceed
14632 default: point$3(this, x, y); break;
14634 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14635 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14639 var cardinalOpen = (function custom(tension) {
14641 function cardinal$$1(context) {
14642 return new CardinalOpen(context, tension);
14645 cardinal$$1.tension = function(tension) {
14646 return custom(+tension);
14649 return cardinal$$1;
14652 function point$4(that, x, y) {
14658 if (that._l01_a > epsilon$3) {
14659 var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
14660 n = 3 * that._l01_a * (that._l01_a + that._l12_a);
14661 x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
14662 y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
14665 if (that._l23_a > epsilon$3) {
14666 var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
14667 m = 3 * that._l23_a * (that._l23_a + that._l12_a);
14668 x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
14669 y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
14672 that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
14675 function CatmullRom(context, alpha) {
14676 this._context = context;
14677 this._alpha = alpha;
14680 CatmullRom.prototype = {
14681 areaStart: function() {
14684 areaEnd: function() {
14687 lineStart: function() {
14688 this._x0 = this._x1 = this._x2 =
14689 this._y0 = this._y1 = this._y2 = NaN;
14690 this._l01_a = this._l12_a = this._l23_a =
14691 this._l01_2a = this._l12_2a = this._l23_2a =
14694 lineEnd: function() {
14695 switch (this._point) {
14696 case 2: this._context.lineTo(this._x2, this._y2); break;
14697 case 3: this.point(this._x2, this._y2); break;
14699 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14700 this._line = 1 - this._line;
14702 point: function(x, y) {
14706 var x23 = this._x2 - x,
14707 y23 = this._y2 - y;
14708 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
14711 switch (this._point) {
14712 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14713 case 1: this._point = 2; break;
14714 case 2: this._point = 3; // proceed
14715 default: point$4(this, x, y); break;
14718 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
14719 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
14720 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14721 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14725 var catmullRom = (function custom(alpha) {
14727 function catmullRom(context) {
14728 return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
14731 catmullRom.alpha = function(alpha) {
14732 return custom(+alpha);
14738 function CatmullRomClosed(context, alpha) {
14739 this._context = context;
14740 this._alpha = alpha;
14743 CatmullRomClosed.prototype = {
14746 lineStart: function() {
14747 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
14748 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
14749 this._l01_a = this._l12_a = this._l23_a =
14750 this._l01_2a = this._l12_2a = this._l23_2a =
14753 lineEnd: function() {
14754 switch (this._point) {
14756 this._context.moveTo(this._x3, this._y3);
14757 this._context.closePath();
14761 this._context.lineTo(this._x3, this._y3);
14762 this._context.closePath();
14766 this.point(this._x3, this._y3);
14767 this.point(this._x4, this._y4);
14768 this.point(this._x5, this._y5);
14773 point: function(x, y) {
14777 var x23 = this._x2 - x,
14778 y23 = this._y2 - y;
14779 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
14782 switch (this._point) {
14783 case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
14784 case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
14785 case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
14786 default: point$4(this, x, y); break;
14789 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
14790 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
14791 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14792 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14796 var catmullRomClosed = (function custom(alpha) {
14798 function catmullRom$$1(context) {
14799 return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
14802 catmullRom$$1.alpha = function(alpha) {
14803 return custom(+alpha);
14806 return catmullRom$$1;
14809 function CatmullRomOpen(context, alpha) {
14810 this._context = context;
14811 this._alpha = alpha;
14814 CatmullRomOpen.prototype = {
14815 areaStart: function() {
14818 areaEnd: function() {
14821 lineStart: function() {
14822 this._x0 = this._x1 = this._x2 =
14823 this._y0 = this._y1 = this._y2 = NaN;
14824 this._l01_a = this._l12_a = this._l23_a =
14825 this._l01_2a = this._l12_2a = this._l23_2a =
14828 lineEnd: function() {
14829 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
14830 this._line = 1 - this._line;
14832 point: function(x, y) {
14836 var x23 = this._x2 - x,
14837 y23 = this._y2 - y;
14838 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
14841 switch (this._point) {
14842 case 0: this._point = 1; break;
14843 case 1: this._point = 2; break;
14844 case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
14845 case 3: this._point = 4; // proceed
14846 default: point$4(this, x, y); break;
14849 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
14850 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
14851 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14852 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14856 var catmullRomOpen = (function custom(alpha) {
14858 function catmullRom$$1(context) {
14859 return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
14862 catmullRom$$1.alpha = function(alpha) {
14863 return custom(+alpha);
14866 return catmullRom$$1;
14869 function LinearClosed(context) {
14870 this._context = context;
14873 LinearClosed.prototype = {
14876 lineStart: function() {
14879 lineEnd: function() {
14880 if (this._point) this._context.closePath();
14882 point: function(x, y) {
14884 if (this._point) this._context.lineTo(x, y);
14885 else this._point = 1, this._context.moveTo(x, y);
14889 var linearClosed = function(context) {
14890 return new LinearClosed(context);
14893 function sign$1(x) {
14894 return x < 0 ? -1 : 1;
14897 // Calculate the slopes of the tangents (Hermite-type interpolation) based on
14898 // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
14899 // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
14900 // NOV(II), P. 443, 1990.
14901 function slope3(that, x2, y2) {
14902 var h0 = that._x1 - that._x0,
14903 h1 = x2 - that._x1,
14904 s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
14905 s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
14906 p = (s0 * h1 + s1 * h0) / (h0 + h1);
14907 return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
14910 // Calculate a one-sided slope.
14911 function slope2(that, t) {
14912 var h = that._x1 - that._x0;
14913 return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
14916 // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
14917 // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
14918 // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
14919 function point$5(that, t0, t1) {
14924 dx = (x1 - x0) / 3;
14925 that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
14928 function MonotoneX(context) {
14929 this._context = context;
14932 MonotoneX.prototype = {
14933 areaStart: function() {
14936 areaEnd: function() {
14939 lineStart: function() {
14940 this._x0 = this._x1 =
14941 this._y0 = this._y1 =
14945 lineEnd: function() {
14946 switch (this._point) {
14947 case 2: this._context.lineTo(this._x1, this._y1); break;
14948 case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
14950 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14951 this._line = 1 - this._line;
14953 point: function(x, y) {
14957 if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
14958 switch (this._point) {
14959 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14960 case 1: this._point = 2; break;
14961 case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
14962 default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
14965 this._x0 = this._x1, this._x1 = x;
14966 this._y0 = this._y1, this._y1 = y;
14971 function MonotoneY(context) {
14972 this._context = new ReflectContext(context);
14975 (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
14976 MonotoneX.prototype.point.call(this, y, x);
14979 function ReflectContext(context) {
14980 this._context = context;
14983 ReflectContext.prototype = {
14984 moveTo: function(x, y) { this._context.moveTo(y, x); },
14985 closePath: function() { this._context.closePath(); },
14986 lineTo: function(x, y) { this._context.lineTo(y, x); },
14987 bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
14990 function monotoneX(context) {
14991 return new MonotoneX(context);
14994 function monotoneY(context) {
14995 return new MonotoneY(context);
14998 function Natural(context) {
14999 this._context = context;
15002 Natural.prototype = {
15003 areaStart: function() {
15006 areaEnd: function() {
15009 lineStart: function() {
15013 lineEnd: function() {
15019 this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
15021 this._context.lineTo(x[1], y[1]);
15023 var px = controlPoints(x),
15024 py = controlPoints(y);
15025 for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
15026 this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
15031 if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
15032 this._line = 1 - this._line;
15033 this._x = this._y = null;
15035 point: function(x, y) {
15041 // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
15042 function controlPoints(x) {
15049 a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
15050 for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
15051 a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
15052 for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
15053 a[n - 1] = r[n - 1] / b[n - 1];
15054 for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
15055 b[n - 1] = (x[n] + a[n - 1]) / 2;
15056 for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
15060 var natural = function(context) {
15061 return new Natural(context);
15064 function Step(context, t) {
15065 this._context = context;
15070 areaStart: function() {
15073 areaEnd: function() {
15076 lineStart: function() {
15077 this._x = this._y = NaN;
15080 lineEnd: function() {
15081 if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
15082 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15083 if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
15085 point: function(x, y) {
15087 switch (this._point) {
15088 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15089 case 1: this._point = 2; // proceed
15091 if (this._t <= 0) {
15092 this._context.lineTo(this._x, y);
15093 this._context.lineTo(x, y);
15095 var x1 = this._x * (1 - this._t) + x * this._t;
15096 this._context.lineTo(x1, this._y);
15097 this._context.lineTo(x1, y);
15102 this._x = x, this._y = y;
15106 var step = function(context) {
15107 return new Step(context, 0.5);
15110 function stepBefore(context) {
15111 return new Step(context, 0);
15114 function stepAfter(context) {
15115 return new Step(context, 1);
15118 var none$1 = function(series, order) {
15119 if (!((n = series.length) > 1)) return;
15120 for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
15121 s0 = s1, s1 = series[order[i]];
15122 for (j = 0; j < m; ++j) {
15123 s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
15128 var none$2 = function(series) {
15129 var n = series.length, o = new Array(n);
15130 while (--n >= 0) o[n] = n;
15134 function stackValue(d, key) {
15138 var stack = function() {
15139 var keys = constant$10([]),
15142 value = stackValue;
15144 function stack(data) {
15145 var kz = keys.apply(this, arguments),
15152 for (i = 0; i < n; ++i) {
15153 for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
15154 si[j] = sij = [0, +value(data[j], ki, j, data)];
15155 sij.data = data[j];
15160 for (i = 0, oz = order(sz); i < n; ++i) {
15161 sz[oz[i]].index = i;
15168 stack.keys = function(_) {
15169 return arguments.length ? (keys = typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : keys;
15172 stack.value = function(_) {
15173 return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), stack) : value;
15176 stack.order = function(_) {
15177 return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : order;
15180 stack.offset = function(_) {
15181 return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
15187 var expand = function(series, order) {
15188 if (!((n = series.length) > 0)) return;
15189 for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
15190 for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
15191 if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
15193 none$1(series, order);
15196 var diverging = function(series, order) {
15197 if (!((n = series.length) > 1)) return;
15198 for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
15199 for (yp = yn = 0, i = 0; i < n; ++i) {
15200 if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
15201 d[0] = yp, d[1] = yp += dy;
15202 } else if (dy < 0) {
15203 d[1] = yn, d[0] = yn += dy;
15211 var silhouette = function(series, order) {
15212 if (!((n = series.length) > 0)) return;
15213 for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
15214 for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
15215 s0[j][1] += s0[j][0] = -y / 2;
15217 none$1(series, order);
15220 var wiggle = function(series, order) {
15221 if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
15222 for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
15223 for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
15224 var si = series[order[i]],
15225 sij0 = si[j][1] || 0,
15226 sij1 = si[j - 1][1] || 0,
15227 s3 = (sij0 - sij1) / 2;
15228 for (var k = 0; k < i; ++k) {
15229 var sk = series[order[k]],
15230 skj0 = sk[j][1] || 0,
15231 skj1 = sk[j - 1][1] || 0;
15234 s1 += sij0, s2 += s3 * sij0;
15236 s0[j - 1][1] += s0[j - 1][0] = y;
15237 if (s1) y -= s2 / s1;
15239 s0[j - 1][1] += s0[j - 1][0] = y;
15240 none$1(series, order);
15243 var ascending$2 = function(series) {
15244 var sums = series.map(sum$2);
15245 return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
15248 function sum$2(series) {
15249 var s = 0, i = -1, n = series.length, v;
15250 while (++i < n) if (v = +series[i][1]) s += v;
15254 var descending$2 = function(series) {
15255 return ascending$2(series).reverse();
15258 var insideOut = function(series) {
15259 var n = series.length,
15262 sums = series.map(sum$2),
15263 order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
15269 for (i = 0; i < n; ++i) {
15271 if (top < bottom) {
15280 return bottoms.reverse().concat(tops);
15283 var reverse = function(series) {
15284 return none$2(series).reverse();
15287 var constant$11 = function(x) {
15288 return function() {
15301 function RedBlackTree() {
15302 this._ = null; // root node
15305 function RedBlackNode(node) {
15306 node.U = // parent node
15307 node.C = // color - true for red, false for black
15308 node.L = // left node
15309 node.R = // right node
15310 node.P = // previous node
15311 node.N = null; // next node
15314 RedBlackTree.prototype = {
15315 constructor: RedBlackTree,
15317 insert: function(after, node) {
15318 var parent, grandpa, uncle;
15323 if (after.N) after.N.P = node;
15327 while (after.L) after = after.L;
15333 } else if (this._) {
15334 after = RedBlackFirst(this._);
15337 after.P = after.L = node;
15340 node.P = node.N = null;
15344 node.L = node.R = null;
15349 while (parent && parent.C) {
15350 grandpa = parent.U;
15351 if (parent === grandpa.L) {
15353 if (uncle && uncle.C) {
15354 parent.C = uncle.C = false;
15358 if (after === parent.R) {
15359 RedBlackRotateLeft(this, parent);
15365 RedBlackRotateRight(this, grandpa);
15369 if (uncle && uncle.C) {
15370 parent.C = uncle.C = false;
15374 if (after === parent.L) {
15375 RedBlackRotateRight(this, parent);
15381 RedBlackRotateLeft(this, grandpa);
15389 remove: function(node) {
15390 if (node.N) node.N.P = node.P;
15391 if (node.P) node.P.N = node.N;
15392 node.N = node.P = null;
15394 var parent = node.U,
15401 if (!left) next = right;
15402 else if (!right) next = left;
15403 else next = RedBlackFirst(right);
15406 if (parent.L === node) parent.L = next;
15407 else parent.R = next;
15412 if (left && right) {
15417 if (next !== right) {
15434 if (node) node.U = parent;
15436 if (node && node.C) { node.C = false; return; }
15439 if (node === this._) break;
15440 if (node === parent.L) {
15441 sibling = parent.R;
15445 RedBlackRotateLeft(this, parent);
15446 sibling = parent.R;
15448 if ((sibling.L && sibling.L.C)
15449 || (sibling.R && sibling.R.C)) {
15450 if (!sibling.R || !sibling.R.C) {
15451 sibling.L.C = false;
15453 RedBlackRotateRight(this, sibling);
15454 sibling = parent.R;
15456 sibling.C = parent.C;
15457 parent.C = sibling.R.C = false;
15458 RedBlackRotateLeft(this, parent);
15463 sibling = parent.L;
15467 RedBlackRotateRight(this, parent);
15468 sibling = parent.L;
15470 if ((sibling.L && sibling.L.C)
15471 || (sibling.R && sibling.R.C)) {
15472 if (!sibling.L || !sibling.L.C) {
15473 sibling.R.C = false;
15475 RedBlackRotateLeft(this, sibling);
15476 sibling = parent.L;
15478 sibling.C = parent.C;
15479 parent.C = sibling.L.C = false;
15480 RedBlackRotateRight(this, parent);
15490 if (node) node.C = false;
15494 function RedBlackRotateLeft(tree, node) {
15500 if (parent.L === p) parent.L = q;
15509 if (p.R) p.R.U = p;
15513 function RedBlackRotateRight(tree, node) {
15519 if (parent.L === p) parent.L = q;
15528 if (p.L) p.L.U = p;
15532 function RedBlackFirst(node) {
15533 while (node.L) node = node.L;
15537 function createEdge(left, right, v0, v1) {
15538 var edge = [null, null],
15539 index = edges.push(edge) - 1;
15541 edge.right = right;
15542 if (v0) setEdgeEnd(edge, left, right, v0);
15543 if (v1) setEdgeEnd(edge, right, left, v1);
15544 cells[left.index].halfedges.push(index);
15545 cells[right.index].halfedges.push(index);
15549 function createBorderEdge(left, v0, v1) {
15550 var edge = [v0, v1];
15555 function setEdgeEnd(edge, left, right, vertex) {
15556 if (!edge[0] && !edge[1]) {
15559 edge.right = right;
15560 } else if (edge.left === right) {
15567 // Liang–Barsky line clipping.
15568 function clipEdge(edge, x0, y0, x1, y1) {
15582 if (!dx && r > 0) return;
15585 if (r < t0) return;
15586 if (r < t1) t1 = r;
15587 } else if (dx > 0) {
15588 if (r > t1) return;
15589 if (r > t0) t0 = r;
15593 if (!dx && r < 0) return;
15596 if (r > t1) return;
15597 if (r > t0) t0 = r;
15598 } else if (dx > 0) {
15599 if (r < t0) return;
15600 if (r < t1) t1 = r;
15604 if (!dy && r > 0) return;
15607 if (r < t0) return;
15608 if (r < t1) t1 = r;
15609 } else if (dy > 0) {
15610 if (r > t1) return;
15611 if (r > t0) t0 = r;
15615 if (!dy && r < 0) return;
15618 if (r > t1) return;
15619 if (r > t0) t0 = r;
15620 } else if (dy > 0) {
15621 if (r < t0) return;
15622 if (r < t1) t1 = r;
15625 if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
15627 if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
15628 if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
15632 function connectEdge(edge, x0, y0, x1, y1) {
15634 if (v1) return true;
15638 right = edge.right,
15643 fx = (lx + rx) / 2,
15644 fy = (ly + ry) / 2,
15649 if (fx < x0 || fx >= x1) return;
15651 if (!v0) v0 = [fx, y0];
15652 else if (v0[1] >= y1) return;
15655 if (!v0) v0 = [fx, y1];
15656 else if (v0[1] < y0) return;
15660 fm = (lx - rx) / (ry - ly);
15662 if (fm < -1 || fm > 1) {
15664 if (!v0) v0 = [(y0 - fb) / fm, y0];
15665 else if (v0[1] >= y1) return;
15666 v1 = [(y1 - fb) / fm, y1];
15668 if (!v0) v0 = [(y1 - fb) / fm, y1];
15669 else if (v0[1] < y0) return;
15670 v1 = [(y0 - fb) / fm, y0];
15674 if (!v0) v0 = [x0, fm * x0 + fb];
15675 else if (v0[0] >= x1) return;
15676 v1 = [x1, fm * x1 + fb];
15678 if (!v0) v0 = [x1, fm * x1 + fb];
15679 else if (v0[0] < x0) return;
15680 v1 = [x0, fm * x0 + fb];
15690 function clipEdges(x0, y0, x1, y1) {
15691 var i = edges.length,
15695 if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
15696 || !clipEdge(edge, x0, y0, x1, y1)
15697 || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
15698 || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
15704 function createCell(site) {
15705 return cells[site.index] = {
15711 function cellHalfedgeAngle(cell, edge) {
15712 var site = cell.site,
15715 if (site === vb) vb = va, va = site;
15716 if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
15717 if (site === va) va = edge[1], vb = edge[0];
15718 else va = edge[0], vb = edge[1];
15719 return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
15722 function cellHalfedgeStart(cell, edge) {
15723 return edge[+(edge.left !== cell.site)];
15726 function cellHalfedgeEnd(cell, edge) {
15727 return edge[+(edge.left === cell.site)];
15730 function sortCellHalfedges() {
15731 for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
15732 if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
15733 var index = new Array(m),
15734 array = new Array(m);
15735 for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
15736 index.sort(function(i, j) { return array[j] - array[i]; });
15737 for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
15738 for (j = 0; j < m; ++j) halfedges[j] = array[j];
15743 function clipCells(x0, y0, x1, y1) {
15744 var nCells = cells.length,
15759 for (iCell = 0; iCell < nCells; ++iCell) {
15760 if (cell = cells[iCell]) {
15762 halfedges = cell.halfedges;
15763 iHalfedge = halfedges.length;
15765 // Remove any dangling clipped edges.
15766 while (iHalfedge--) {
15767 if (!edges[halfedges[iHalfedge]]) {
15768 halfedges.splice(iHalfedge, 1);
15772 // Insert any border edges as necessary.
15773 iHalfedge = 0, nHalfedges = halfedges.length;
15774 while (iHalfedge < nHalfedges) {
15775 end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
15776 start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
15777 if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
15778 halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
15779 Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
15780 : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
15781 : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
15782 : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
15788 if (nHalfedges) cover = false;
15792 // If there weren’t any edges, have the closest site cover the extent.
15793 // It doesn’t matter which corner of the extent we measure!
15795 var dx, dy, d2, dc = Infinity;
15797 for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
15798 if (cell = cells[iCell]) {
15802 d2 = dx * dx + dy * dy;
15803 if (d2 < dc) dc = d2, cover = cell;
15808 var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
15809 cover.halfedges.push(
15810 edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
15811 edges.push(createBorderEdge(site, v01, v11)) - 1,
15812 edges.push(createBorderEdge(site, v11, v10)) - 1,
15813 edges.push(createBorderEdge(site, v10, v00)) - 1
15818 // Lastly delete any cells with no edges; these were entirely clipped.
15819 for (iCell = 0; iCell < nCells; ++iCell) {
15820 if (cell = cells[iCell]) {
15821 if (!cell.halfedges.length) {
15822 delete cells[iCell];
15828 var circlePool = [];
15832 function Circle() {
15833 RedBlackNode(this);
15841 function attachCircle(arc) {
15845 if (!lArc || !rArc) return;
15847 var lSite = lArc.site,
15851 if (lSite === rSite) return;
15855 ax = lSite[0] - bx,
15856 ay = lSite[1] - by,
15857 cx = rSite[0] - bx,
15858 cy = rSite[1] - by;
15860 var d = 2 * (ax * cy - ay * cx);
15861 if (d >= -epsilon2$2) return;
15863 var ha = ax * ax + ay * ay,
15864 hc = cx * cx + cy * cy,
15865 x = (cy * ha - ay * hc) / d,
15866 y = (ax * hc - cx * ha) / d;
15868 var circle = circlePool.pop() || new Circle;
15870 circle.site = cSite;
15872 circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
15874 arc.circle = circle;
15880 if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
15881 if (node.L) node = node.L;
15882 else { before = node.P; break; }
15884 if (node.R) node = node.R;
15885 else { before = node; break; }
15889 circles.insert(before, circle);
15890 if (!before) firstCircle = circle;
15893 function detachCircle(arc) {
15894 var circle = arc.circle;
15896 if (!circle.P) firstCircle = circle.N;
15897 circles.remove(circle);
15898 circlePool.push(circle);
15899 RedBlackNode(circle);
15904 var beachPool = [];
15907 RedBlackNode(this);
15910 this.circle = null;
15913 function createBeach(site) {
15914 var beach = beachPool.pop() || new Beach;
15919 function detachBeach(beach) {
15920 detachCircle(beach);
15921 beaches.remove(beach);
15922 beachPool.push(beach);
15923 RedBlackNode(beach);
15926 function removeBeach(beach) {
15927 var circle = beach.circle,
15931 previous = beach.P,
15933 disappearing = [beach];
15935 detachBeach(beach);
15937 var lArc = previous;
15939 && Math.abs(x - lArc.circle.x) < epsilon$4
15940 && Math.abs(y - lArc.circle.cy) < epsilon$4) {
15942 disappearing.unshift(lArc);
15947 disappearing.unshift(lArc);
15948 detachCircle(lArc);
15952 && Math.abs(x - rArc.circle.x) < epsilon$4
15953 && Math.abs(y - rArc.circle.cy) < epsilon$4) {
15955 disappearing.push(rArc);
15960 disappearing.push(rArc);
15961 detachCircle(rArc);
15963 var nArcs = disappearing.length,
15965 for (iArc = 1; iArc < nArcs; ++iArc) {
15966 rArc = disappearing[iArc];
15967 lArc = disappearing[iArc - 1];
15968 setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
15971 lArc = disappearing[0];
15972 rArc = disappearing[nArcs - 1];
15973 rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
15975 attachCircle(lArc);
15976 attachCircle(rArc);
15979 function addBeach(site) {
15981 directrix = site[1],
15989 dxl = leftBreakPoint(node, directrix) - x;
15990 if (dxl > epsilon$4) node = node.L; else {
15991 dxr = x - rightBreakPoint(node, directrix);
15992 if (dxr > epsilon$4) {
15999 if (dxl > -epsilon$4) {
16002 } else if (dxr > -epsilon$4) {
16006 lArc = rArc = node;
16014 var newArc = createBeach(site);
16015 beaches.insert(lArc, newArc);
16017 if (!lArc && !rArc) return;
16019 if (lArc === rArc) {
16020 detachCircle(lArc);
16021 rArc = createBeach(lArc.site);
16022 beaches.insert(newArc, rArc);
16023 newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
16024 attachCircle(lArc);
16025 attachCircle(rArc);
16029 if (!rArc) { // && lArc
16030 newArc.edge = createEdge(lArc.site, newArc.site);
16034 // else lArc !== rArc
16035 detachCircle(lArc);
16036 detachCircle(rArc);
16038 var lSite = lArc.site,
16044 cx = rSite[0] - ax,
16045 cy = rSite[1] - ay,
16046 d = 2 * (bx * cy - by * cx),
16047 hb = bx * bx + by * by,
16048 hc = cx * cx + cy * cy,
16049 vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
16051 setEdgeEnd(rArc.edge, lSite, rSite, vertex);
16052 newArc.edge = createEdge(lSite, site, null, vertex);
16053 rArc.edge = createEdge(site, rSite, null, vertex);
16054 attachCircle(lArc);
16055 attachCircle(rArc);
16058 function leftBreakPoint(arc, directrix) {
16059 var site = arc.site,
16062 pby2 = rfocy - directrix;
16064 if (!pby2) return rfocx;
16067 if (!lArc) return -Infinity;
16070 var lfocx = site[0],
16072 plby2 = lfocy - directrix;
16074 if (!plby2) return lfocx;
16076 var hl = lfocx - rfocx,
16077 aby2 = 1 / pby2 - 1 / plby2,
16080 if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
16082 return (rfocx + lfocx) / 2;
16085 function rightBreakPoint(arc, directrix) {
16087 if (rArc) return leftBreakPoint(rArc, directrix);
16088 var site = arc.site;
16089 return site[1] === directrix ? site[0] : Infinity;
16092 var epsilon$4 = 1e-6;
16093 var epsilon2$2 = 1e-12;
16099 function triangleArea(a, b, c) {
16100 return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
16103 function lexicographic(a, b) {
16108 function Diagram(sites, extent) {
16109 var site = sites.sort(lexicographic).pop(),
16115 cells = new Array(sites.length);
16116 beaches = new RedBlackTree;
16117 circles = new RedBlackTree;
16120 circle = firstCircle;
16121 if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
16122 if (site[0] !== x || site[1] !== y) {
16124 x = site[0], y = site[1];
16126 site = sites.pop();
16127 } else if (circle) {
16128 removeBeach(circle.arc);
16134 sortCellHalfedges();
16137 var x0 = +extent[0][0],
16138 y0 = +extent[0][1],
16139 x1 = +extent[1][0],
16140 y1 = +extent[1][1];
16141 clipEdges(x0, y0, x1, y1);
16142 clipCells(x0, y0, x1, y1);
16145 this.edges = edges;
16146 this.cells = cells;
16154 Diagram.prototype = {
16155 constructor: Diagram,
16157 polygons: function() {
16158 var edges = this.edges;
16160 return this.cells.map(function(cell) {
16161 var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
16162 polygon.data = cell.site.data;
16167 triangles: function() {
16168 var triangles = [],
16169 edges = this.edges;
16171 this.cells.forEach(function(cell, i) {
16172 if (!(m = (halfedges = cell.halfedges).length)) return;
16173 var site = cell.site,
16178 e1 = edges[halfedges[m - 1]],
16179 s1 = e1.left === site ? e1.right : e1.left;
16183 e1 = edges[halfedges[j]];
16184 s1 = e1.left === site ? e1.right : e1.left;
16185 if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
16186 triangles.push([site.data, s0.data, s1.data]);
16194 links: function() {
16195 return this.edges.filter(function(edge) {
16197 }).map(function(edge) {
16199 source: edge.left.data,
16200 target: edge.right.data
16205 find: function(x, y, radius) {
16206 var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
16208 // Use the previously-found cell, or start with an arbitrary one.
16209 while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
16210 var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
16212 // Traverse the half-edges to find a closer cell, if any.
16214 cell = that.cells[i0 = i1], i1 = null;
16215 cell.halfedges.forEach(function(e) {
16216 var edge = that.edges[e], v = edge.left;
16217 if ((v === cell.site || !v) && !(v = edge.right)) return;
16218 var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
16219 if (v2 < d2) d2 = v2, i1 = v.index;
16221 } while (i1 !== null);
16225 return radius == null || d2 <= radius * radius ? cell.site : null;
16229 var voronoi = function() {
16234 function voronoi(data) {
16235 return new Diagram(data.map(function(d, i) {
16236 var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
16243 voronoi.polygons = function(data) {
16244 return voronoi(data).polygons();
16247 voronoi.links = function(data) {
16248 return voronoi(data).links();
16251 voronoi.triangles = function(data) {
16252 return voronoi(data).triangles();
16255 voronoi.x = function(_) {
16256 return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : x$$1;
16259 voronoi.y = function(_) {
16260 return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : y$$1;
16263 voronoi.extent = function(_) {
16264 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]]];
16267 voronoi.size = function(_) {
16268 return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
16274 var constant$12 = function(x) {
16275 return function() {
16280 function ZoomEvent(target, type, transform) {
16281 this.target = target;
16283 this.transform = transform;
16286 function Transform(k, x, y) {
16292 Transform.prototype = {
16293 constructor: Transform,
16294 scale: function(k) {
16295 return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
16297 translate: function(x, y) {
16298 return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
16300 apply: function(point) {
16301 return [point[0] * this.k + this.x, point[1] * this.k + this.y];
16303 applyX: function(x) {
16304 return x * this.k + this.x;
16306 applyY: function(y) {
16307 return y * this.k + this.y;
16309 invert: function(location) {
16310 return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
16312 invertX: function(x) {
16313 return (x - this.x) / this.k;
16315 invertY: function(y) {
16316 return (y - this.y) / this.k;
16318 rescaleX: function(x) {
16319 return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
16321 rescaleY: function(y) {
16322 return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
16324 toString: function() {
16325 return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
16329 var identity$8 = new Transform(1, 0, 0);
16331 transform$1.prototype = Transform.prototype;
16333 function transform$1(node) {
16334 return node.__zoom || identity$8;
16337 function nopropagation$2() {
16338 exports.event.stopImmediatePropagation();
16341 var noevent$2 = function() {
16342 exports.event.preventDefault();
16343 exports.event.stopImmediatePropagation();
16346 // Ignore right-click, since that should open the context menu.
16347 function defaultFilter$2() {
16348 return !exports.event.button;
16351 function defaultExtent$1() {
16352 var e = this, w, h;
16353 if (e instanceof SVGElement) {
16354 e = e.ownerSVGElement || e;
16355 w = e.width.baseVal.value;
16356 h = e.height.baseVal.value;
16359 h = e.clientHeight;
16361 return [[0, 0], [w, h]];
16364 function defaultTransform() {
16365 return this.__zoom || identity$8;
16368 function defaultWheelDelta() {
16369 return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
16372 function defaultTouchable$1() {
16373 return "ontouchstart" in this;
16376 function defaultConstrain(transform$$1, extent, translateExtent) {
16377 var dx0 = transform$$1.invertX(extent[0][0]) - translateExtent[0][0],
16378 dx1 = transform$$1.invertX(extent[1][0]) - translateExtent[1][0],
16379 dy0 = transform$$1.invertY(extent[0][1]) - translateExtent[0][1],
16380 dy1 = transform$$1.invertY(extent[1][1]) - translateExtent[1][1];
16381 return transform$$1.translate(
16382 dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
16383 dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
16387 var zoom = function() {
16388 var filter = defaultFilter$2,
16389 extent = defaultExtent$1,
16390 constrain = defaultConstrain,
16391 wheelDelta = defaultWheelDelta,
16392 touchable = defaultTouchable$1,
16393 scaleExtent = [0, Infinity],
16394 translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
16396 interpolate = interpolateZoom,
16398 listeners = dispatch("start", "zoom", "end"),
16403 clickDistance2 = 0;
16405 function zoom(selection) {
16407 .property("__zoom", defaultTransform)
16408 .on("wheel.zoom", wheeled)
16409 .on("mousedown.zoom", mousedowned)
16410 .on("dblclick.zoom", dblclicked)
16412 .on("touchstart.zoom", touchstarted)
16413 .on("touchmove.zoom", touchmoved)
16414 .on("touchend.zoom touchcancel.zoom", touchended)
16415 .style("touch-action", "none")
16416 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
16419 zoom.transform = function(collection, transform$$1) {
16420 var selection = collection.selection ? collection.selection() : collection;
16421 selection.property("__zoom", defaultTransform);
16422 if (collection !== selection) {
16423 schedule(collection, transform$$1);
16425 selection.interrupt().each(function() {
16426 gesture(this, arguments)
16428 .zoom(null, typeof transform$$1 === "function" ? transform$$1.apply(this, arguments) : transform$$1)
16434 zoom.scaleBy = function(selection, k) {
16435 zoom.scaleTo(selection, function() {
16436 var k0 = this.__zoom.k,
16437 k1 = typeof k === "function" ? k.apply(this, arguments) : k;
16442 zoom.scaleTo = function(selection, k) {
16443 zoom.transform(selection, function() {
16444 var e = extent.apply(this, arguments),
16447 p1 = t0.invert(p0),
16448 k1 = typeof k === "function" ? k.apply(this, arguments) : k;
16449 return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
16453 zoom.translateBy = function(selection, x, y) {
16454 zoom.transform(selection, function() {
16455 return constrain(this.__zoom.translate(
16456 typeof x === "function" ? x.apply(this, arguments) : x,
16457 typeof y === "function" ? y.apply(this, arguments) : y
16458 ), extent.apply(this, arguments), translateExtent);
16462 zoom.translateTo = function(selection, x, y) {
16463 zoom.transform(selection, function() {
16464 var e = extent.apply(this, arguments),
16467 return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
16468 typeof x === "function" ? -x.apply(this, arguments) : -x,
16469 typeof y === "function" ? -y.apply(this, arguments) : -y
16470 ), e, translateExtent);
16474 function scale(transform$$1, k) {
16475 k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
16476 return k === transform$$1.k ? transform$$1 : new Transform(k, transform$$1.x, transform$$1.y);
16479 function translate(transform$$1, p0, p1) {
16480 var x = p0[0] - p1[0] * transform$$1.k, y = p0[1] - p1[1] * transform$$1.k;
16481 return x === transform$$1.x && y === transform$$1.y ? transform$$1 : new Transform(transform$$1.k, x, y);
16484 function centroid(extent) {
16485 return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
16488 function schedule(transition, transform$$1, center) {
16490 .on("start.zoom", function() { gesture(this, arguments).start(); })
16491 .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
16492 .tween("zoom", function() {
16495 g = gesture(that, args),
16496 e = extent.apply(that, args),
16497 p = center || centroid(e),
16498 w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
16500 b = typeof transform$$1 === "function" ? transform$$1.apply(that, args) : transform$$1,
16501 i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
16502 return function(t) {
16503 if (t === 1) t = b; // Avoid rounding error on end.
16504 else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
16510 function gesture(that, args) {
16511 for (var i = 0, n = gestures.length, g; i < n; ++i) {
16512 if ((g = gestures[i]).that === that) {
16516 return new Gesture(that, args);
16519 function Gesture(that, args) {
16524 this.extent = extent.apply(that, args);
16527 Gesture.prototype = {
16528 start: function() {
16529 if (++this.active === 1) {
16530 this.index = gestures.push(this) - 1;
16531 this.emit("start");
16535 zoom: function(key, transform$$1) {
16536 if (this.mouse && key !== "mouse") this.mouse[1] = transform$$1.invert(this.mouse[0]);
16537 if (this.touch0 && key !== "touch") this.touch0[1] = transform$$1.invert(this.touch0[0]);
16538 if (this.touch1 && key !== "touch") this.touch1[1] = transform$$1.invert(this.touch1[0]);
16539 this.that.__zoom = transform$$1;
16544 if (--this.active === 0) {
16545 gestures.splice(this.index, 1);
16551 emit: function(type) {
16552 customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
16556 function wheeled() {
16557 if (!filter.apply(this, arguments)) return;
16558 var g = gesture(this, arguments),
16560 k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
16563 // If the mouse is in the same location as before, reuse it.
16564 // If there were recent wheel events, reset the wheel idle timeout.
16566 if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
16567 g.mouse[1] = t.invert(g.mouse[0] = p);
16569 clearTimeout(g.wheel);
16572 // If this wheel event won’t trigger a transform change, ignore it.
16573 else if (t.k === k) return;
16575 // Otherwise, capture the mouse point and location at the start.
16577 g.mouse = [p, t.invert(p)];
16583 g.wheel = setTimeout(wheelidled, wheelDelay);
16584 g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
16586 function wheelidled() {
16592 function mousedowned() {
16593 if (touchending || !filter.apply(this, arguments)) return;
16594 var g = gesture(this, arguments),
16595 v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
16597 x0 = exports.event.clientX,
16598 y0 = exports.event.clientY;
16600 dragDisable(exports.event.view);
16602 g.mouse = [p, this.__zoom.invert(p)];
16606 function mousemoved() {
16609 var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
16610 g.moved = dx * dx + dy * dy > clickDistance2;
16612 g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
16615 function mouseupped() {
16616 v.on("mousemove.zoom mouseup.zoom", null);
16617 yesdrag(exports.event.view, g.moved);
16623 function dblclicked() {
16624 if (!filter.apply(this, arguments)) return;
16625 var t0 = this.__zoom,
16627 p1 = t0.invert(p0),
16628 k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
16629 t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
16632 if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
16633 else select(this).call(zoom.transform, t1);
16636 function touchstarted() {
16637 if (!filter.apply(this, arguments)) return;
16638 var g = gesture(this, arguments),
16639 touches = exports.event.changedTouches,
16641 n = touches.length, i, t, p;
16644 for (i = 0; i < n; ++i) {
16645 t = touches[i], p = touch(this, touches, t.identifier);
16646 p = [p, this.__zoom.invert(p), t.identifier];
16647 if (!g.touch0) g.touch0 = p, started = true;
16648 else if (!g.touch1) g.touch1 = p;
16651 // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
16652 if (touchstarting) {
16653 touchstarting = clearTimeout(touchstarting);
16656 p = select(this).on("dblclick.zoom");
16657 if (p) p.apply(this, arguments);
16663 touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
16669 function touchmoved() {
16670 var g = gesture(this, arguments),
16671 touches = exports.event.changedTouches,
16672 n = touches.length, i, t, p, l;
16675 if (touchstarting) touchstarting = clearTimeout(touchstarting);
16676 for (i = 0; i < n; ++i) {
16677 t = touches[i], p = touch(this, touches, t.identifier);
16678 if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
16679 else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
16683 var p0 = g.touch0[0], l0 = g.touch0[1],
16684 p1 = g.touch1[0], l1 = g.touch1[1],
16685 dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
16686 dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
16687 t = scale(t, Math.sqrt(dp / dl));
16688 p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
16689 l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
16691 else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
16693 g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
16696 function touchended() {
16697 var g = gesture(this, arguments),
16698 touches = exports.event.changedTouches,
16699 n = touches.length, i, t;
16702 if (touchending) clearTimeout(touchending);
16703 touchending = setTimeout(function() { touchending = null; }, touchDelay);
16704 for (i = 0; i < n; ++i) {
16706 if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
16707 else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
16709 if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
16710 if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
16714 zoom.wheelDelta = function(_) {
16715 return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$12(+_), zoom) : wheelDelta;
16718 zoom.filter = function(_) {
16719 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$12(!!_), zoom) : filter;
16722 zoom.touchable = function(_) {
16723 return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$12(!!_), zoom) : touchable;
16726 zoom.extent = function(_) {
16727 return arguments.length ? (extent = typeof _ === "function" ? _ : constant$12([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
16730 zoom.scaleExtent = function(_) {
16731 return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
16734 zoom.translateExtent = function(_) {
16735 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]]];
16738 zoom.constrain = function(_) {
16739 return arguments.length ? (constrain = _, zoom) : constrain;
16742 zoom.duration = function(_) {
16743 return arguments.length ? (duration = +_, zoom) : duration;
16746 zoom.interpolate = function(_) {
16747 return arguments.length ? (interpolate = _, zoom) : interpolate;
16750 zoom.on = function() {
16751 var value = listeners.on.apply(listeners, arguments);
16752 return value === listeners ? zoom : value;
16755 zoom.clickDistance = function(_) {
16756 return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
16762 exports.version = version;
16763 exports.bisect = bisectRight;
16764 exports.bisectRight = bisectRight;
16765 exports.bisectLeft = bisectLeft;
16766 exports.ascending = ascending;
16767 exports.bisector = bisector;
16768 exports.cross = cross;
16769 exports.descending = descending;
16770 exports.deviation = deviation;
16771 exports.extent = extent;
16772 exports.histogram = histogram;
16773 exports.thresholdFreedmanDiaconis = freedmanDiaconis;
16774 exports.thresholdScott = scott;
16775 exports.thresholdSturges = sturges;
16777 exports.mean = mean;
16778 exports.median = median;
16779 exports.merge = merge;
16781 exports.pairs = pairs;
16782 exports.permute = permute;
16783 exports.quantile = threshold;
16784 exports.range = sequence;
16785 exports.scan = scan;
16786 exports.shuffle = shuffle;
16788 exports.ticks = ticks;
16789 exports.tickIncrement = tickIncrement;
16790 exports.tickStep = tickStep;
16791 exports.transpose = transpose;
16792 exports.variance = variance;
16794 exports.axisTop = axisTop;
16795 exports.axisRight = axisRight;
16796 exports.axisBottom = axisBottom;
16797 exports.axisLeft = axisLeft;
16798 exports.brush = brush;
16799 exports.brushX = brushX;
16800 exports.brushY = brushY;
16801 exports.brushSelection = brushSelection;
16802 exports.chord = chord;
16803 exports.ribbon = ribbon;
16804 exports.nest = nest;
16805 exports.set = set$2;
16806 exports.map = map$1;
16807 exports.keys = keys;
16808 exports.values = values;
16809 exports.entries = entries;
16810 exports.color = color;
16815 exports.cubehelix = cubehelix;
16816 exports.dispatch = dispatch;
16817 exports.drag = drag;
16818 exports.dragDisable = dragDisable;
16819 exports.dragEnable = yesdrag;
16820 exports.dsvFormat = dsv;
16821 exports.csvParse = csvParse;
16822 exports.csvParseRows = csvParseRows;
16823 exports.csvFormat = csvFormat;
16824 exports.csvFormatRows = csvFormatRows;
16825 exports.tsvParse = tsvParse;
16826 exports.tsvParseRows = tsvParseRows;
16827 exports.tsvFormat = tsvFormat;
16828 exports.tsvFormatRows = tsvFormatRows;
16829 exports.easeLinear = linear$1;
16830 exports.easeQuad = quadInOut;
16831 exports.easeQuadIn = quadIn;
16832 exports.easeQuadOut = quadOut;
16833 exports.easeQuadInOut = quadInOut;
16834 exports.easeCubic = cubicInOut;
16835 exports.easeCubicIn = cubicIn;
16836 exports.easeCubicOut = cubicOut;
16837 exports.easeCubicInOut = cubicInOut;
16838 exports.easePoly = polyInOut;
16839 exports.easePolyIn = polyIn;
16840 exports.easePolyOut = polyOut;
16841 exports.easePolyInOut = polyInOut;
16842 exports.easeSin = sinInOut;
16843 exports.easeSinIn = sinIn;
16844 exports.easeSinOut = sinOut;
16845 exports.easeSinInOut = sinInOut;
16846 exports.easeExp = expInOut;
16847 exports.easeExpIn = expIn;
16848 exports.easeExpOut = expOut;
16849 exports.easeExpInOut = expInOut;
16850 exports.easeCircle = circleInOut;
16851 exports.easeCircleIn = circleIn;
16852 exports.easeCircleOut = circleOut;
16853 exports.easeCircleInOut = circleInOut;
16854 exports.easeBounce = bounceOut;
16855 exports.easeBounceIn = bounceIn;
16856 exports.easeBounceOut = bounceOut;
16857 exports.easeBounceInOut = bounceInOut;
16858 exports.easeBack = backInOut;
16859 exports.easeBackIn = backIn;
16860 exports.easeBackOut = backOut;
16861 exports.easeBackInOut = backInOut;
16862 exports.easeElastic = elasticOut;
16863 exports.easeElasticIn = elasticIn;
16864 exports.easeElasticOut = elasticOut;
16865 exports.easeElasticInOut = elasticInOut;
16866 exports.forceCenter = center$1;
16867 exports.forceCollide = collide;
16868 exports.forceLink = link;
16869 exports.forceManyBody = manyBody;
16870 exports.forceRadial = radial;
16871 exports.forceSimulation = simulation;
16872 exports.forceX = x$2;
16873 exports.forceY = y$2;
16874 exports.formatDefaultLocale = defaultLocale;
16875 exports.formatLocale = formatLocale;
16876 exports.formatSpecifier = formatSpecifier;
16877 exports.precisionFixed = precisionFixed;
16878 exports.precisionPrefix = precisionPrefix;
16879 exports.precisionRound = precisionRound;
16880 exports.geoArea = area;
16881 exports.geoBounds = bounds;
16882 exports.geoCentroid = centroid;
16883 exports.geoCircle = circle;
16884 exports.geoClipAntimeridian = clipAntimeridian;
16885 exports.geoClipCircle = clipCircle;
16886 exports.geoClipExtent = extent$1;
16887 exports.geoClipRectangle = clipRectangle;
16888 exports.geoContains = contains;
16889 exports.geoDistance = distance;
16890 exports.geoGraticule = graticule;
16891 exports.geoGraticule10 = graticule10;
16892 exports.geoInterpolate = interpolate$1;
16893 exports.geoLength = length$1;
16894 exports.geoPath = index$1;
16895 exports.geoAlbers = albers;
16896 exports.geoAlbersUsa = albersUsa;
16897 exports.geoAzimuthalEqualArea = azimuthalEqualArea;
16898 exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
16899 exports.geoAzimuthalEquidistant = azimuthalEquidistant;
16900 exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
16901 exports.geoConicConformal = conicConformal;
16902 exports.geoConicConformalRaw = conicConformalRaw;
16903 exports.geoConicEqualArea = conicEqualArea;
16904 exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
16905 exports.geoConicEquidistant = conicEquidistant;
16906 exports.geoConicEquidistantRaw = conicEquidistantRaw;
16907 exports.geoEquirectangular = equirectangular;
16908 exports.geoEquirectangularRaw = equirectangularRaw;
16909 exports.geoGnomonic = gnomonic;
16910 exports.geoGnomonicRaw = gnomonicRaw;
16911 exports.geoIdentity = identity$5;
16912 exports.geoProjection = projection;
16913 exports.geoProjectionMutator = projectionMutator;
16914 exports.geoMercator = mercator;
16915 exports.geoMercatorRaw = mercatorRaw;
16916 exports.geoNaturalEarth1 = naturalEarth1;
16917 exports.geoNaturalEarth1Raw = naturalEarth1Raw;
16918 exports.geoOrthographic = orthographic;
16919 exports.geoOrthographicRaw = orthographicRaw;
16920 exports.geoStereographic = stereographic;
16921 exports.geoStereographicRaw = stereographicRaw;
16922 exports.geoTransverseMercator = transverseMercator;
16923 exports.geoTransverseMercatorRaw = transverseMercatorRaw;
16924 exports.geoRotation = rotation;
16925 exports.geoStream = geoStream;
16926 exports.geoTransform = transform;
16927 exports.cluster = cluster;
16928 exports.hierarchy = hierarchy;
16929 exports.pack = index$2;
16930 exports.packSiblings = siblings;
16931 exports.packEnclose = enclose;
16932 exports.partition = partition;
16933 exports.stratify = stratify;
16934 exports.tree = tree;
16935 exports.treemap = index$3;
16936 exports.treemapBinary = binary;
16937 exports.treemapDice = treemapDice;
16938 exports.treemapSlice = treemapSlice;
16939 exports.treemapSliceDice = sliceDice;
16940 exports.treemapSquarify = squarify;
16941 exports.treemapResquarify = resquarify;
16942 exports.interpolate = interpolateValue;
16943 exports.interpolateArray = array$1;
16944 exports.interpolateBasis = basis$1;
16945 exports.interpolateBasisClosed = basisClosed;
16946 exports.interpolateDate = date;
16947 exports.interpolateNumber = reinterpolate;
16948 exports.interpolateObject = object;
16949 exports.interpolateRound = interpolateRound;
16950 exports.interpolateString = interpolateString;
16951 exports.interpolateTransformCss = interpolateTransformCss;
16952 exports.interpolateTransformSvg = interpolateTransformSvg;
16953 exports.interpolateZoom = interpolateZoom;
16954 exports.interpolateRgb = interpolateRgb;
16955 exports.interpolateRgbBasis = rgbBasis;
16956 exports.interpolateRgbBasisClosed = rgbBasisClosed;
16957 exports.interpolateHsl = hsl$2;
16958 exports.interpolateHslLong = hslLong;
16959 exports.interpolateLab = lab$1;
16960 exports.interpolateHcl = hcl$2;
16961 exports.interpolateHclLong = hclLong;
16962 exports.interpolateCubehelix = cubehelix$2;
16963 exports.interpolateCubehelixLong = cubehelixLong;
16964 exports.quantize = quantize;
16965 exports.path = path;
16966 exports.polygonArea = area$1;
16967 exports.polygonCentroid = centroid$1;
16968 exports.polygonHull = hull;
16969 exports.polygonContains = contains$1;
16970 exports.polygonLength = length$2;
16971 exports.quadtree = quadtree;
16972 exports.queue = queue;
16973 exports.randomUniform = uniform;
16974 exports.randomNormal = normal;
16975 exports.randomLogNormal = logNormal;
16976 exports.randomBates = bates;
16977 exports.randomIrwinHall = irwinHall;
16978 exports.randomExponential = exponential$1;
16979 exports.request = request;
16980 exports.html = html;
16981 exports.json = json;
16982 exports.text = text;
16984 exports.csv = csv$1;
16985 exports.tsv = tsv$1;
16986 exports.scaleBand = band;
16987 exports.scalePoint = point$1;
16988 exports.scaleIdentity = identity$6;
16989 exports.scaleLinear = linear$2;
16990 exports.scaleLog = log$1;
16991 exports.scaleOrdinal = ordinal;
16992 exports.scaleImplicit = implicit;
16993 exports.scalePow = pow$1;
16994 exports.scaleSqrt = sqrt$1;
16995 exports.scaleQuantile = quantile$$1;
16996 exports.scaleQuantize = quantize$1;
16997 exports.scaleThreshold = threshold$1;
16998 exports.scaleTime = time;
16999 exports.scaleUtc = utcTime;
17000 exports.schemeCategory10 = category10;
17001 exports.schemeCategory20b = category20b;
17002 exports.schemeCategory20c = category20c;
17003 exports.schemeCategory20 = category20;
17004 exports.interpolateCubehelixDefault = cubehelix$3;
17005 exports.interpolateRainbow = rainbow$1;
17006 exports.interpolateWarm = warm;
17007 exports.interpolateCool = cool;
17008 exports.interpolateViridis = viridis;
17009 exports.interpolateMagma = magma;
17010 exports.interpolateInferno = inferno;
17011 exports.interpolatePlasma = plasma;
17012 exports.scaleSequential = sequential;
17013 exports.creator = creator;
17014 exports.local = local$1;
17015 exports.matcher = matcher$1;
17016 exports.mouse = mouse;
17017 exports.namespace = namespace;
17018 exports.namespaces = namespaces;
17019 exports.clientPoint = point;
17020 exports.select = select;
17021 exports.selectAll = selectAll;
17022 exports.selection = selection;
17023 exports.selector = selector;
17024 exports.selectorAll = selectorAll;
17025 exports.style = styleValue;
17026 exports.touch = touch;
17027 exports.touches = touches;
17028 exports.window = defaultView;
17029 exports.customEvent = customEvent;
17031 exports.area = area$2;
17032 exports.line = line;
17034 exports.areaRadial = areaRadial;
17035 exports.radialArea = areaRadial;
17036 exports.lineRadial = lineRadial$1;
17037 exports.radialLine = lineRadial$1;
17038 exports.pointRadial = pointRadial;
17039 exports.linkHorizontal = linkHorizontal;
17040 exports.linkVertical = linkVertical;
17041 exports.linkRadial = linkRadial;
17042 exports.symbol = symbol;
17043 exports.symbols = symbols;
17044 exports.symbolCircle = circle$2;
17045 exports.symbolCross = cross$2;
17046 exports.symbolDiamond = diamond;
17047 exports.symbolSquare = square;
17048 exports.symbolStar = star;
17049 exports.symbolTriangle = triangle;
17050 exports.symbolWye = wye;
17051 exports.curveBasisClosed = basisClosed$1;
17052 exports.curveBasisOpen = basisOpen;
17053 exports.curveBasis = basis$2;
17054 exports.curveBundle = bundle;
17055 exports.curveCardinalClosed = cardinalClosed;
17056 exports.curveCardinalOpen = cardinalOpen;
17057 exports.curveCardinal = cardinal;
17058 exports.curveCatmullRomClosed = catmullRomClosed;
17059 exports.curveCatmullRomOpen = catmullRomOpen;
17060 exports.curveCatmullRom = catmullRom;
17061 exports.curveLinearClosed = linearClosed;
17062 exports.curveLinear = curveLinear;
17063 exports.curveMonotoneX = monotoneX;
17064 exports.curveMonotoneY = monotoneY;
17065 exports.curveNatural = natural;
17066 exports.curveStep = step;
17067 exports.curveStepAfter = stepAfter;
17068 exports.curveStepBefore = stepBefore;
17069 exports.stack = stack;
17070 exports.stackOffsetExpand = expand;
17071 exports.stackOffsetDiverging = diverging;
17072 exports.stackOffsetNone = none$1;
17073 exports.stackOffsetSilhouette = silhouette;
17074 exports.stackOffsetWiggle = wiggle;
17075 exports.stackOrderAscending = ascending$2;
17076 exports.stackOrderDescending = descending$2;
17077 exports.stackOrderInsideOut = insideOut;
17078 exports.stackOrderNone = none$2;
17079 exports.stackOrderReverse = reverse;
17080 exports.timeInterval = newInterval;
17081 exports.timeMillisecond = millisecond;
17082 exports.timeMilliseconds = milliseconds;
17083 exports.utcMillisecond = millisecond;
17084 exports.utcMilliseconds = milliseconds;
17085 exports.timeSecond = second;
17086 exports.timeSeconds = seconds;
17087 exports.utcSecond = second;
17088 exports.utcSeconds = seconds;
17089 exports.timeMinute = minute;
17090 exports.timeMinutes = minutes;
17091 exports.timeHour = hour;
17092 exports.timeHours = hours;
17093 exports.timeDay = day;
17094 exports.timeDays = days;
17095 exports.timeWeek = sunday;
17096 exports.timeWeeks = sundays;
17097 exports.timeSunday = sunday;
17098 exports.timeSundays = sundays;
17099 exports.timeMonday = monday;
17100 exports.timeMondays = mondays;
17101 exports.timeTuesday = tuesday;
17102 exports.timeTuesdays = tuesdays;
17103 exports.timeWednesday = wednesday;
17104 exports.timeWednesdays = wednesdays;
17105 exports.timeThursday = thursday;
17106 exports.timeThursdays = thursdays;
17107 exports.timeFriday = friday;
17108 exports.timeFridays = fridays;
17109 exports.timeSaturday = saturday;
17110 exports.timeSaturdays = saturdays;
17111 exports.timeMonth = month;
17112 exports.timeMonths = months;
17113 exports.timeYear = year;
17114 exports.timeYears = years;
17115 exports.utcMinute = utcMinute;
17116 exports.utcMinutes = utcMinutes;
17117 exports.utcHour = utcHour;
17118 exports.utcHours = utcHours;
17119 exports.utcDay = utcDay;
17120 exports.utcDays = utcDays;
17121 exports.utcWeek = utcSunday;
17122 exports.utcWeeks = utcSundays;
17123 exports.utcSunday = utcSunday;
17124 exports.utcSundays = utcSundays;
17125 exports.utcMonday = utcMonday;
17126 exports.utcMondays = utcMondays;
17127 exports.utcTuesday = utcTuesday;
17128 exports.utcTuesdays = utcTuesdays;
17129 exports.utcWednesday = utcWednesday;
17130 exports.utcWednesdays = utcWednesdays;
17131 exports.utcThursday = utcThursday;
17132 exports.utcThursdays = utcThursdays;
17133 exports.utcFriday = utcFriday;
17134 exports.utcFridays = utcFridays;
17135 exports.utcSaturday = utcSaturday;
17136 exports.utcSaturdays = utcSaturdays;
17137 exports.utcMonth = utcMonth;
17138 exports.utcMonths = utcMonths;
17139 exports.utcYear = utcYear;
17140 exports.utcYears = utcYears;
17141 exports.timeFormatDefaultLocale = defaultLocale$1;
17142 exports.timeFormatLocale = formatLocale$1;
17143 exports.isoFormat = formatIso;
17144 exports.isoParse = parseIso;
17146 exports.timer = timer;
17147 exports.timerFlush = timerFlush;
17148 exports.timeout = timeout$1;
17149 exports.interval = interval$1;
17150 exports.transition = transition;
17151 exports.active = active;
17152 exports.interrupt = interrupt;
17153 exports.voronoi = voronoi;
17154 exports.zoom = zoom;
17155 exports.zoomTransform = transform$1;
17156 exports.zoomIdentity = identity$8;
17158 Object.defineProperty(exports, '__esModule', { value: true });