2 var version = "4.13.0";
4 function ascending(a, b) {
5 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
8 function bisector(compare) {
9 if (compare.length === 1) compare = ascendingComparator(compare);
11 left: function(a, x, lo, hi) {
12 if (lo == null) lo = 0;
13 if (hi == null) hi = a.length;
15 var mid = lo + hi >>> 1;
16 if (compare(a[mid], x) < 0) lo = mid + 1;
21 right: function(a, x, lo, hi) {
22 if (lo == null) lo = 0;
23 if (hi == null) hi = a.length;
25 var mid = lo + hi >>> 1;
26 if (compare(a[mid], x) > 0) hi = mid;
34 function ascendingComparator(f) {
35 return function(d, x) {
36 return ascending(f(d), x);
40 var ascendingBisect = bisector(ascending);
41 var bisectRight = ascendingBisect.right;
42 var bisectLeft = ascendingBisect.left;
44 function pairs(array, f) {
45 if (f == null) f = pair;
46 var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
47 while (i < n) pairs[i] = f(p, p = array[++i]);
55 function cross(values0, values1, reduce) {
56 var n0 = values0.length,
58 values = new Array(n0 * n1),
64 if (reduce == null) reduce = pair;
66 for (i0 = i = 0; i0 < n0; ++i0) {
67 for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
68 values[i] = reduce(value0, values1[i1]);
75 function d3_descending(a, b) {
76 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
80 return x === null ? NaN : +x;
83 function variance(values, valueof) {
84 var n = values.length,
92 if (valueof == null) {
94 if (!isNaN(value = number(values[i]))) {
97 sum += delta * (value - mean);
104 if (!isNaN(value = number(valueof(values[i], i, values)))) {
105 delta = value - mean;
107 sum += delta * (value - mean);
112 if (m > 1) return sum / (m - 1);
115 function deviation(array, f) {
116 var v = variance(array, f);
117 return v ? Math.sqrt(v) : v;
120 function extent(values, valueof) {
121 var n = values.length,
127 if (valueof == null) {
128 while (++i < n) { // Find the first comparable value.
129 if ((value = values[i]) != null && value >= value) {
131 while (++i < n) { // Compare the remaining values.
132 if ((value = values[i]) != null) {
133 if (min > value) min = value;
134 if (max < value) max = value;
142 while (++i < n) { // Find the first comparable value.
143 if ((value = valueof(values[i], i, values)) != null && value >= value) {
145 while (++i < n) { // Compare the remaining values.
146 if ((value = valueof(values[i], i, values)) != null) {
147 if (min > value) min = value;
148 if (max < value) max = value;
158 var array = Array.prototype;
160 var slice = array.slice;
163 function constant(x) {
169 function identity(x) {
173 function range(start, stop, step) {
174 start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
177 n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
178 range = new Array(n);
181 range[i] = start + i * step;
187 var e10 = Math.sqrt(50),
191 function ticks(start, stop, count) {
198 stop = +stop, start = +start, count = +count;
199 if (start === stop && count > 0) return [start];
200 if (reverse = stop < start) n = start, start = stop, stop = n;
201 if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
204 start = Math.ceil(start / step);
205 stop = Math.floor(stop / step);
206 ticks = new Array(n = Math.ceil(stop - start + 1));
207 while (++i < n) ticks[i] = (start + i) * step;
209 start = Math.floor(start * step);
210 stop = Math.ceil(stop * step);
211 ticks = new Array(n = Math.ceil(start - stop + 1));
212 while (++i < n) ticks[i] = (start - i) / step;
215 if (reverse) ticks.reverse();
220 function tickIncrement(start, stop, count) {
221 var step = (stop - start) / Math.max(0, count),
222 power = Math.floor(Math.log(step) / Math.LN10),
223 error = step / Math.pow(10, power);
225 ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
226 : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
229 function tickStep(start, stop, count) {
230 var step0 = Math.abs(stop - start) / Math.max(0, count),
231 step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
232 error = step0 / step1;
233 if (error >= e10) step1 *= 10;
234 else if (error >= e5) step1 *= 5;
235 else if (error >= e2) step1 *= 2;
236 return stop < start ? -step1 : step1;
239 function sturges(values) {
240 return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
243 function histogram() {
244 var value = identity,
248 function histogram(data) {
252 values = new Array(n);
254 for (i = 0; i < n; ++i) {
255 values[i] = value(data[i], i, data);
258 var xz = domain(values),
261 tz = threshold(values, x0, x1);
263 // Convert number of thresholds into uniform thresholds.
264 if (!Array.isArray(tz)) {
265 tz = tickStep(x0, x1, tz);
266 tz = range(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive
269 // Remove any thresholds outside the domain.
271 while (tz[0] <= x0) tz.shift(), --m;
272 while (tz[m - 1] > x1) tz.pop(), --m;
274 var bins = new Array(m + 1),
278 for (i = 0; i <= m; ++i) {
280 bin.x0 = i > 0 ? tz[i - 1] : x0;
281 bin.x1 = i < m ? tz[i] : x1;
284 // Assign data to bins by value, ignoring any outside the domain.
285 for (i = 0; i < n; ++i) {
287 if (x0 <= x && x <= x1) {
288 bins[bisectRight(tz, x, 0, m)].push(data[i]);
295 histogram.value = function(_) {
296 return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
299 histogram.domain = function(_) {
300 return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
303 histogram.thresholds = function(_) {
304 return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
310 function threshold(values, p, valueof) {
311 if (valueof == null) valueof = number;
312 if (!(n = values.length)) return;
313 if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
314 if (p >= 1) return +valueof(values[n - 1], n - 1, values);
318 value0 = +valueof(values[i0], i0, values),
319 value1 = +valueof(values[i0 + 1], i0 + 1, values);
320 return value0 + (value1 - value0) * (i - i0);
323 function freedmanDiaconis(values, min, max) {
324 values = map.call(values, number).sort(ascending);
325 return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
328 function scott(values, min, max) {
329 return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
332 function max(values, valueof) {
333 var n = values.length,
338 if (valueof == null) {
339 while (++i < n) { // Find the first comparable value.
340 if ((value = values[i]) != null && value >= value) {
342 while (++i < n) { // Compare the remaining values.
343 if ((value = values[i]) != null && value > max) {
352 while (++i < n) { // Find the first comparable value.
353 if ((value = valueof(values[i], i, values)) != null && value >= value) {
355 while (++i < n) { // Compare the remaining values.
356 if ((value = valueof(values[i], i, values)) != null && value > max) {
367 function mean(values, valueof) {
368 var n = values.length,
374 if (valueof == null) {
376 if (!isNaN(value = number(values[i]))) sum += value;
383 if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
388 if (m) return sum / m;
391 function d3_median(values, valueof) {
392 var n = values.length,
397 if (valueof == null) {
399 if (!isNaN(value = number(values[i]))) {
407 if (!isNaN(value = number(valueof(values[i], i, values)))) {
413 return threshold(numbers.sort(ascending), 0.5);
416 function merge(arrays) {
417 var n = arrays.length,
424 while (++i < n) j += arrays[i].length;
425 merged = new Array(j);
431 merged[--j] = array[m];
438 function min(values, valueof) {
439 var n = values.length,
444 if (valueof == null) {
445 while (++i < n) { // Find the first comparable value.
446 if ((value = values[i]) != null && value >= value) {
448 while (++i < n) { // Compare the remaining values.
449 if ((value = values[i]) != null && min > value) {
458 while (++i < n) { // Find the first comparable value.
459 if ((value = valueof(values[i], i, values)) != null && value >= value) {
461 while (++i < n) { // Compare the remaining values.
462 if ((value = valueof(values[i], i, values)) != null && min > value) {
473 function permute(array, indexes) {
474 var i = indexes.length, permutes = new Array(i);
475 while (i--) permutes[i] = array[indexes[i]];
479 function scan(values, compare) {
480 if (!(n = values.length)) return;
487 if (compare == null) compare = ascending;
490 if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
495 if (compare(xj, xj) === 0) return j;
498 function shuffle(array, i0, i1) {
499 var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
504 i = Math.random() * m-- | 0;
506 array[m + i0] = array[i + i0];
513 function sum(values, valueof) {
514 var n = values.length,
519 if (valueof == null) {
521 if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
527 if (value = +valueof(values[i], i, values)) sum += value;
534 function transpose(matrix) {
535 if (!(n = matrix.length)) return [];
536 for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
537 for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
538 row[j] = matrix[j][i];
549 return transpose(arguments);
552 var slice$1 = Array.prototype.slice;
554 function identity$1(x) {
564 function translateX(x) {
565 return "translate(" + (x + 0.5) + ",0)";
568 function translateY(y) {
569 return "translate(0," + (y + 0.5) + ")";
572 function number$1(scale) {
578 function center(scale) {
579 var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
580 if (scale.round()) offset = Math.round(offset);
582 return +scale(d) + offset;
586 function entering() {
590 function axis(orient, scale) {
591 var tickArguments = [],
597 k = orient === top || orient === left ? -1 : 1,
598 x = orient === left || orient === right ? "x" : "y",
599 transform = orient === top || orient === bottom ? translateX : translateY;
601 function axis(context) {
602 var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
603 format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
604 spacing = Math.max(tickSizeInner, 0) + tickPadding,
605 range = scale.range(),
606 range0 = +range[0] + 0.5,
607 range1 = +range[range.length - 1] + 0.5,
608 position = (scale.bandwidth ? center : number$1)(scale.copy()),
609 selection = context.selection ? context.selection() : context,
610 path = selection.selectAll(".domain").data([null]),
611 tick = selection.selectAll(".tick").data(values, scale).order(),
612 tickExit = tick.exit(),
613 tickEnter = tick.enter().append("g").attr("class", "tick"),
614 line = tick.select("line"),
615 text = tick.select("text");
617 path = path.merge(path.enter().insert("path", ".tick")
618 .attr("class", "domain")
619 .attr("stroke", "#000"));
621 tick = tick.merge(tickEnter);
623 line = line.merge(tickEnter.append("line")
624 .attr("stroke", "#000")
625 .attr(x + "2", k * tickSizeInner));
627 text = text.merge(tickEnter.append("text")
628 .attr("fill", "#000")
629 .attr(x, k * spacing)
630 .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
632 if (context !== selection) {
633 path = path.transition(context);
634 tick = tick.transition(context);
635 line = line.transition(context);
636 text = text.transition(context);
638 tickExit = tickExit.transition(context)
639 .attr("opacity", epsilon)
640 .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
643 .attr("opacity", epsilon)
644 .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
650 .attr("d", orient === left || orient == right
651 ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
652 : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
656 .attr("transform", function(d) { return transform(position(d)); });
659 .attr(x + "2", k * tickSizeInner);
662 .attr(x, k * spacing)
665 selection.filter(entering)
666 .attr("fill", "none")
667 .attr("font-size", 10)
668 .attr("font-family", "sans-serif")
669 .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
672 .each(function() { this.__axis = position; });
675 axis.scale = function(_) {
676 return arguments.length ? (scale = _, axis) : scale;
679 axis.ticks = function() {
680 return tickArguments = slice$1.call(arguments), axis;
683 axis.tickArguments = function(_) {
684 return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
687 axis.tickValues = function(_) {
688 return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
691 axis.tickFormat = function(_) {
692 return arguments.length ? (tickFormat = _, axis) : tickFormat;
695 axis.tickSize = function(_) {
696 return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
699 axis.tickSizeInner = function(_) {
700 return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
703 axis.tickSizeOuter = function(_) {
704 return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
707 axis.tickPadding = function(_) {
708 return arguments.length ? (tickPadding = +_, axis) : tickPadding;
714 function axisTop(scale) {
715 return axis(top, scale);
718 function axisRight(scale) {
719 return axis(right, scale);
722 function axisBottom(scale) {
723 return axis(bottom, scale);
726 function axisLeft(scale) {
727 return axis(left, scale);
730 var noop = {value: function() {}};
732 function dispatch() {
733 for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
734 if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
737 return new Dispatch(_);
740 function Dispatch(_) {
744 function parseTypenames(typenames, types) {
745 return typenames.trim().split(/^|\s+/).map(function(t) {
746 var name = "", i = t.indexOf(".");
747 if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
748 if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
749 return {type: t, name: name};
753 Dispatch.prototype = dispatch.prototype = {
754 constructor: Dispatch,
755 on: function(typename, callback) {
757 T = parseTypenames(typename + "", _),
762 // If no callback was specified, return the callback of the given type and name.
763 if (arguments.length < 2) {
764 while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
768 // If a type was specified, set the callback for the given type and name.
769 // Otherwise, if a null callback was specified, remove callbacks of the given name.
770 if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
772 if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
773 else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
779 var copy = {}, _ = this._;
780 for (var t in _) copy[t] = _[t].slice();
781 return new Dispatch(copy);
783 call: function(type, that) {
784 if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
785 if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
786 for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
788 apply: function(type, that, args) {
789 if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
790 for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
794 function get(type, name) {
795 for (var i = 0, n = type.length, c; i < n; ++i) {
796 if ((c = type[i]).name === name) {
802 function set(type, name, callback) {
803 for (var i = 0, n = type.length; i < n; ++i) {
804 if (type[i].name === name) {
805 type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
809 if (callback != null) type.push({name: name, value: callback});
813 var xhtml = "http://www.w3.org/1999/xhtml";
816 svg: "http://www.w3.org/2000/svg",
818 xlink: "http://www.w3.org/1999/xlink",
819 xml: "http://www.w3.org/XML/1998/namespace",
820 xmlns: "http://www.w3.org/2000/xmlns/"
823 function namespace(name) {
824 var prefix = name += "", i = prefix.indexOf(":");
825 if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
826 return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
829 function creatorInherit(name) {
831 var document = this.ownerDocument,
832 uri = this.namespaceURI;
833 return uri === xhtml && document.documentElement.namespaceURI === xhtml
834 ? document.createElement(name)
835 : document.createElementNS(uri, name);
839 function creatorFixed(fullname) {
841 return this.ownerDocument.createElementNS(fullname.space, fullname.local);
845 function creator(name) {
846 var fullname = namespace(name);
847 return (fullname.local
849 : creatorInherit)(fullname);
854 function selector(selector) {
855 return selector == null ? none : function() {
856 return this.querySelector(selector);
860 function selection_select(select) {
861 if (typeof select !== "function") select = selector(select);
863 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
864 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
865 if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
866 if ("__data__" in node) subnode.__data__ = node.__data__;
867 subgroup[i] = subnode;
872 return new Selection(subgroups, this._parents);
879 function selectorAll(selector) {
880 return selector == null ? empty : function() {
881 return this.querySelectorAll(selector);
885 function selection_selectAll(select) {
886 if (typeof select !== "function") select = selectorAll(select);
888 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
889 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
890 if (node = group[i]) {
891 subgroups.push(select.call(node, node.__data__, i, group));
897 return new Selection(subgroups, parents);
900 var matcher = function(selector) {
902 return this.matches(selector);
906 if (typeof document !== "undefined") {
907 var element = document.documentElement;
908 if (!element.matches) {
909 var vendorMatches = element.webkitMatchesSelector
910 || element.msMatchesSelector
911 || element.mozMatchesSelector
912 || element.oMatchesSelector;
913 matcher = function(selector) {
915 return vendorMatches.call(this, selector);
921 var matcher$1 = matcher;
923 function selection_filter(match) {
924 if (typeof match !== "function") match = matcher$1(match);
926 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
927 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
928 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
934 return new Selection(subgroups, this._parents);
937 function sparse(update) {
938 return new Array(update.length);
941 function selection_enter() {
942 return new Selection(this._enter || this._groups.map(sparse), this._parents);
945 function EnterNode(parent, datum) {
946 this.ownerDocument = parent.ownerDocument;
947 this.namespaceURI = parent.namespaceURI;
949 this._parent = parent;
950 this.__data__ = datum;
953 EnterNode.prototype = {
954 constructor: EnterNode,
955 appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
956 insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
957 querySelector: function(selector) { return this._parent.querySelector(selector); },
958 querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
961 function constant$1(x) {
967 var keyPrefix = "$"; // Protect against keys like “__proto__”.
969 function bindIndex(parent, group, enter, update, exit, data) {
972 groupLength = group.length,
973 dataLength = data.length;
975 // Put any non-null nodes that fit into update.
976 // Put any null nodes into enter.
977 // Put any remaining data into enter.
978 for (; i < dataLength; ++i) {
979 if (node = group[i]) {
980 node.__data__ = data[i];
983 enter[i] = new EnterNode(parent, data[i]);
987 // Put any non-null nodes that don’t fit into exit.
988 for (; i < groupLength; ++i) {
989 if (node = group[i]) {
995 function bindKey(parent, group, enter, update, exit, data, key) {
999 groupLength = group.length,
1000 dataLength = data.length,
1001 keyValues = new Array(groupLength),
1004 // Compute the key for each node.
1005 // If multiple nodes have the same key, the duplicates are added to exit.
1006 for (i = 0; i < groupLength; ++i) {
1007 if (node = group[i]) {
1008 keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
1009 if (keyValue in nodeByKeyValue) {
1012 nodeByKeyValue[keyValue] = node;
1017 // Compute the key for each datum.
1018 // If there a node associated with this key, join and add it to update.
1019 // If there is not (or the key is a duplicate), add it to enter.
1020 for (i = 0; i < dataLength; ++i) {
1021 keyValue = keyPrefix + key.call(parent, data[i], i, data);
1022 if (node = nodeByKeyValue[keyValue]) {
1024 node.__data__ = data[i];
1025 nodeByKeyValue[keyValue] = null;
1027 enter[i] = new EnterNode(parent, data[i]);
1031 // Add any remaining nodes that were not bound to data to exit.
1032 for (i = 0; i < groupLength; ++i) {
1033 if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
1039 function selection_data(value, key) {
1041 data = new Array(this.size()), j = -1;
1042 this.each(function(d) { data[++j] = d; });
1046 var bind = key ? bindKey : bindIndex,
1047 parents = this._parents,
1048 groups = this._groups;
1050 if (typeof value !== "function") value = constant$1(value);
1052 for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
1053 var parent = parents[j],
1055 groupLength = group.length,
1056 data = value.call(parent, parent && parent.__data__, j, parents),
1057 dataLength = data.length,
1058 enterGroup = enter[j] = new Array(dataLength),
1059 updateGroup = update[j] = new Array(dataLength),
1060 exitGroup = exit[j] = new Array(groupLength);
1062 bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
1064 // Now connect the enter nodes to their following update node, such that
1065 // appendChild can insert the materialized enter node before this node,
1066 // rather than at the end of the parent node.
1067 for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
1068 if (previous = enterGroup[i0]) {
1069 if (i0 >= i1) i1 = i0 + 1;
1070 while (!(next = updateGroup[i1]) && ++i1 < dataLength);
1071 previous._next = next || null;
1076 update = new Selection(update, parents);
1077 update._enter = enter;
1078 update._exit = exit;
1082 function selection_exit() {
1083 return new Selection(this._exit || this._groups.map(sparse), this._parents);
1086 function selection_merge(selection$$1) {
1088 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) {
1089 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
1090 if (node = group0[i] || group1[i]) {
1096 for (; j < m0; ++j) {
1097 merges[j] = groups0[j];
1100 return new Selection(merges, this._parents);
1103 function selection_order() {
1105 for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
1106 for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
1107 if (node = group[i]) {
1108 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
1117 function selection_sort(compare) {
1118 if (!compare) compare = ascending$1;
1120 function compareNode(a, b) {
1121 return a && b ? compare(a.__data__, b.__data__) : !a - !b;
1124 for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
1125 for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
1126 if (node = group[i]) {
1127 sortgroup[i] = node;
1130 sortgroup.sort(compareNode);
1133 return new Selection(sortgroups, this._parents).order();
1136 function ascending$1(a, b) {
1137 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
1140 function selection_call() {
1141 var callback = arguments[0];
1142 arguments[0] = this;
1143 callback.apply(null, arguments);
1147 function selection_nodes() {
1148 var nodes = new Array(this.size()), i = -1;
1149 this.each(function() { nodes[++i] = this; });
1153 function selection_node() {
1155 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1156 for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
1157 var node = group[i];
1158 if (node) return node;
1165 function selection_size() {
1167 this.each(function() { ++size; });
1171 function selection_empty() {
1172 return !this.node();
1175 function selection_each(callback) {
1177 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1178 for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
1179 if (node = group[i]) callback.call(node, node.__data__, i, group);
1186 function attrRemove(name) {
1188 this.removeAttribute(name);
1192 function attrRemoveNS(fullname) {
1194 this.removeAttributeNS(fullname.space, fullname.local);
1198 function attrConstant(name, value) {
1200 this.setAttribute(name, value);
1204 function attrConstantNS(fullname, value) {
1206 this.setAttributeNS(fullname.space, fullname.local, value);
1210 function attrFunction(name, value) {
1212 var v = value.apply(this, arguments);
1213 if (v == null) this.removeAttribute(name);
1214 else this.setAttribute(name, v);
1218 function attrFunctionNS(fullname, value) {
1220 var v = value.apply(this, arguments);
1221 if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
1222 else this.setAttributeNS(fullname.space, fullname.local, v);
1226 function selection_attr(name, value) {
1227 var fullname = namespace(name);
1229 if (arguments.length < 2) {
1230 var node = this.node();
1231 return fullname.local
1232 ? node.getAttributeNS(fullname.space, fullname.local)
1233 : node.getAttribute(fullname);
1236 return this.each((value == null
1237 ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
1238 ? (fullname.local ? attrFunctionNS : attrFunction)
1239 : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
1242 function defaultView(node) {
1243 return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
1244 || (node.document && node) // node is a Window
1245 || node.defaultView; // node is a Document
1248 function styleRemove(name) {
1250 this.style.removeProperty(name);
1254 function styleConstant(name, value, priority) {
1256 this.style.setProperty(name, value, priority);
1260 function styleFunction(name, value, priority) {
1262 var v = value.apply(this, arguments);
1263 if (v == null) this.style.removeProperty(name);
1264 else this.style.setProperty(name, v, priority);
1268 function selection_style(name, value, priority) {
1269 return arguments.length > 1
1270 ? this.each((value == null
1271 ? styleRemove : typeof value === "function"
1273 : styleConstant)(name, value, priority == null ? "" : priority))
1274 : styleValue(this.node(), name);
1277 function styleValue(node, name) {
1278 return node.style.getPropertyValue(name)
1279 || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
1282 function propertyRemove(name) {
1288 function propertyConstant(name, value) {
1294 function propertyFunction(name, value) {
1296 var v = value.apply(this, arguments);
1297 if (v == null) delete this[name];
1298 else this[name] = v;
1302 function selection_property(name, value) {
1303 return arguments.length > 1
1304 ? this.each((value == null
1305 ? propertyRemove : typeof value === "function"
1307 : propertyConstant)(name, value))
1308 : this.node()[name];
1311 function classArray(string) {
1312 return string.trim().split(/^|\s+/);
1315 function classList(node) {
1316 return node.classList || new ClassList(node);
1319 function ClassList(node) {
1321 this._names = classArray(node.getAttribute("class") || "");
1324 ClassList.prototype = {
1325 add: function(name) {
1326 var i = this._names.indexOf(name);
1328 this._names.push(name);
1329 this._node.setAttribute("class", this._names.join(" "));
1332 remove: function(name) {
1333 var i = this._names.indexOf(name);
1335 this._names.splice(i, 1);
1336 this._node.setAttribute("class", this._names.join(" "));
1339 contains: function(name) {
1340 return this._names.indexOf(name) >= 0;
1344 function classedAdd(node, names) {
1345 var list = classList(node), i = -1, n = names.length;
1346 while (++i < n) list.add(names[i]);
1349 function classedRemove(node, names) {
1350 var list = classList(node), i = -1, n = names.length;
1351 while (++i < n) list.remove(names[i]);
1354 function classedTrue(names) {
1356 classedAdd(this, names);
1360 function classedFalse(names) {
1362 classedRemove(this, names);
1366 function classedFunction(names, value) {
1368 (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
1372 function selection_classed(name, value) {
1373 var names = classArray(name + "");
1375 if (arguments.length < 2) {
1376 var list = classList(this.node()), i = -1, n = names.length;
1377 while (++i < n) if (!list.contains(names[i])) return false;
1381 return this.each((typeof value === "function"
1382 ? classedFunction : value
1384 : classedFalse)(names, value));
1387 function textRemove() {
1388 this.textContent = "";
1391 function textConstant(value) {
1393 this.textContent = value;
1397 function textFunction(value) {
1399 var v = value.apply(this, arguments);
1400 this.textContent = v == null ? "" : v;
1404 function selection_text(value) {
1405 return arguments.length
1406 ? this.each(value == null
1407 ? textRemove : (typeof value === "function"
1409 : textConstant)(value))
1410 : this.node().textContent;
1413 function htmlRemove() {
1414 this.innerHTML = "";
1417 function htmlConstant(value) {
1419 this.innerHTML = value;
1423 function htmlFunction(value) {
1425 var v = value.apply(this, arguments);
1426 this.innerHTML = v == null ? "" : v;
1430 function selection_html(value) {
1431 return arguments.length
1432 ? this.each(value == null
1433 ? htmlRemove : (typeof value === "function"
1435 : htmlConstant)(value))
1436 : this.node().innerHTML;
1440 if (this.nextSibling) this.parentNode.appendChild(this);
1443 function selection_raise() {
1444 return this.each(raise);
1448 if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
1451 function selection_lower() {
1452 return this.each(lower);
1455 function selection_append(name) {
1456 var create = typeof name === "function" ? name : creator(name);
1457 return this.select(function() {
1458 return this.appendChild(create.apply(this, arguments));
1462 function constantNull() {
1466 function selection_insert(name, before) {
1467 var create = typeof name === "function" ? name : creator(name),
1468 select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
1469 return this.select(function() {
1470 return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
1475 var parent = this.parentNode;
1476 if (parent) parent.removeChild(this);
1479 function selection_remove() {
1480 return this.each(remove);
1483 function selection_cloneShallow() {
1484 return this.parentNode.insertBefore(this.cloneNode(false), this.nextSibling);
1487 function selection_cloneDeep() {
1488 return this.parentNode.insertBefore(this.cloneNode(true), this.nextSibling);
1491 function selection_clone(deep) {
1492 return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
1495 function selection_datum(value) {
1496 return arguments.length
1497 ? this.property("__data__", value)
1498 : this.node().__data__;
1501 var filterEvents = {};
1505 if (typeof document !== "undefined") {
1506 var element$1 = document.documentElement;
1507 if (!("onmouseenter" in element$1)) {
1508 filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
1512 function filterContextListener(listener, index, group) {
1513 listener = contextListener(listener, index, group);
1514 return function(event) {
1515 var related = event.relatedTarget;
1516 if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
1517 listener.call(this, event);
1522 function contextListener(listener, index, group) {
1523 return function(event1) {
1524 var event0 = event; // Events can be reentrant (e.g., focus).
1527 listener.call(this, this.__data__, index, group);
1534 function parseTypenames$1(typenames) {
1535 return typenames.trim().split(/^|\s+/).map(function(t) {
1536 var name = "", i = t.indexOf(".");
1537 if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
1538 return {type: t, name: name};
1542 function onRemove(typename) {
1546 for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
1547 if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
1548 this.removeEventListener(o.type, o.listener, o.capture);
1553 if (++i) on.length = i;
1554 else delete this.__on;
1558 function onAdd(typename, value, capture) {
1559 var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
1560 return function(d, i, group) {
1561 var on = this.__on, o, listener = wrap(value, i, group);
1562 if (on) for (var j = 0, m = on.length; j < m; ++j) {
1563 if ((o = on[j]).type === typename.type && o.name === typename.name) {
1564 this.removeEventListener(o.type, o.listener, o.capture);
1565 this.addEventListener(o.type, o.listener = listener, o.capture = capture);
1570 this.addEventListener(typename.type, listener, capture);
1571 o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
1572 if (!on) this.__on = [o];
1577 function selection_on(typename, value, capture) {
1578 var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
1580 if (arguments.length < 2) {
1581 var on = this.node().__on;
1582 if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
1583 for (i = 0, o = on[j]; i < n; ++i) {
1584 if ((t = typenames[i]).type === o.type && t.name === o.name) {
1592 on = value ? onAdd : onRemove;
1593 if (capture == null) capture = false;
1594 for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
1598 function customEvent(event1, listener, that, args) {
1600 event1.sourceEvent = event;
1603 return listener.apply(that, args);
1609 function dispatchEvent(node, type, params) {
1610 var window = defaultView(node),
1611 event = window.CustomEvent;
1613 if (typeof event === "function") {
1614 event = new event(type, params);
1616 event = window.document.createEvent("Event");
1617 if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
1618 else event.initEvent(type, false, false);
1621 node.dispatchEvent(event);
1624 function dispatchConstant(type, params) {
1626 return dispatchEvent(this, type, params);
1630 function dispatchFunction(type, params) {
1632 return dispatchEvent(this, type, params.apply(this, arguments));
1636 function selection_dispatch(type, params) {
1637 return this.each((typeof params === "function"
1639 : dispatchConstant)(type, params));
1644 function Selection(groups, parents) {
1645 this._groups = groups;
1646 this._parents = parents;
1649 function selection() {
1650 return new Selection([[document.documentElement]], root);
1653 Selection.prototype = selection.prototype = {
1654 constructor: Selection,
1655 select: selection_select,
1656 selectAll: selection_selectAll,
1657 filter: selection_filter,
1658 data: selection_data,
1659 enter: selection_enter,
1660 exit: selection_exit,
1661 merge: selection_merge,
1662 order: selection_order,
1663 sort: selection_sort,
1664 call: selection_call,
1665 nodes: selection_nodes,
1666 node: selection_node,
1667 size: selection_size,
1668 empty: selection_empty,
1669 each: selection_each,
1670 attr: selection_attr,
1671 style: selection_style,
1672 property: selection_property,
1673 classed: selection_classed,
1674 text: selection_text,
1675 html: selection_html,
1676 raise: selection_raise,
1677 lower: selection_lower,
1678 append: selection_append,
1679 insert: selection_insert,
1680 remove: selection_remove,
1681 clone: selection_clone,
1682 datum: selection_datum,
1684 dispatch: selection_dispatch
1687 function select(selector) {
1688 return typeof selector === "string"
1689 ? new Selection([[document.querySelector(selector)]], [document.documentElement])
1690 : new Selection([[selector]], root);
1693 function create(name) {
1694 return select(creator(name).call(document.documentElement));
1704 this._ = "@" + (++nextId).toString(36);
1707 Local.prototype = local.prototype = {
1709 get: function(node) {
1711 while (!(id in node)) if (!(node = node.parentNode)) return;
1714 set: function(node, value) {
1715 return node[this._] = value;
1717 remove: function(node) {
1718 return this._ in node && delete node[this._];
1720 toString: function() {
1725 function sourceEvent() {
1726 var current = event, source;
1727 while (source = current.sourceEvent) current = source;
1731 function point(node, event) {
1732 var svg = node.ownerSVGElement || node;
1734 if (svg.createSVGPoint) {
1735 var point = svg.createSVGPoint();
1736 point.x = event.clientX, point.y = event.clientY;
1737 point = point.matrixTransform(node.getScreenCTM().inverse());
1738 return [point.x, point.y];
1741 var rect = node.getBoundingClientRect();
1742 return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
1745 function mouse(node) {
1746 var event = sourceEvent();
1747 if (event.changedTouches) event = event.changedTouches[0];
1748 return point(node, event);
1751 function d3_selectAll(selector) {
1752 return typeof selector === "string"
1753 ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
1754 : new Selection([selector == null ? [] : selector], root);
1757 function touch(node, touches, identifier) {
1758 if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
1760 for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
1761 if ((touch = touches[i]).identifier === identifier) {
1762 return point(node, touch);
1769 function d3_touches(node, touches) {
1770 if (touches == null) touches = sourceEvent().touches;
1772 for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
1773 points[i] = point(node, touches[i]);
1779 function nopropagation() {
1780 event.stopImmediatePropagation();
1783 function noevent() {
1784 event.preventDefault();
1785 event.stopImmediatePropagation();
1788 function nodrag(view) {
1789 var root = view.document.documentElement,
1790 selection$$1 = select(view).on("dragstart.drag", noevent, true);
1791 if ("onselectstart" in root) {
1792 selection$$1.on("selectstart.drag", noevent, true);
1794 root.__noselect = root.style.MozUserSelect;
1795 root.style.MozUserSelect = "none";
1799 function yesdrag(view, noclick) {
1800 var root = view.document.documentElement,
1801 selection$$1 = select(view).on("dragstart.drag", null);
1803 selection$$1.on("click.drag", noevent, true);
1804 setTimeout(function() { selection$$1.on("click.drag", null); }, 0);
1806 if ("onselectstart" in root) {
1807 selection$$1.on("selectstart.drag", null);
1809 root.style.MozUserSelect = root.__noselect;
1810 delete root.__noselect;
1814 function constant$2(x) {
1820 function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
1821 this.target = target;
1823 this.subject = subject;
1824 this.identifier = id;
1825 this.active = active;
1833 DragEvent.prototype.on = function() {
1834 var value = this._.on.apply(this._, arguments);
1835 return value === this._ ? this : value;
1838 // Ignore right-click, since that should open the context menu.
1839 function defaultFilter() {
1840 return !event.button;
1843 function defaultContainer() {
1844 return this.parentNode;
1847 function defaultSubject(d) {
1848 return d == null ? {x: event.x, y: event.y} : d;
1851 function defaultTouchable() {
1852 return "ontouchstart" in this;
1856 var filter = defaultFilter,
1857 container = defaultContainer,
1858 subject = defaultSubject,
1859 touchable = defaultTouchable,
1861 listeners = dispatch("start", "drag", "end"),
1869 function drag(selection$$1) {
1871 .on("mousedown.drag", mousedowned)
1873 .on("touchstart.drag", touchstarted)
1874 .on("touchmove.drag", touchmoved)
1875 .on("touchend.drag touchcancel.drag", touchended)
1876 .style("touch-action", "none")
1877 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
1880 function mousedowned() {
1881 if (touchending || !filter.apply(this, arguments)) return;
1882 var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
1883 if (!gesture) return;
1884 select(event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
1887 mousemoving = false;
1888 mousedownx = event.clientX;
1889 mousedowny = event.clientY;
1893 function mousemoved() {
1896 var dx = event.clientX - mousedownx, dy = event.clientY - mousedowny;
1897 mousemoving = dx * dx + dy * dy > clickDistance2;
1899 gestures.mouse("drag");
1902 function mouseupped() {
1903 select(event.view).on("mousemove.drag mouseup.drag", null);
1904 yesdrag(event.view, mousemoving);
1906 gestures.mouse("end");
1909 function touchstarted() {
1910 if (!filter.apply(this, arguments)) return;
1911 var touches = event.changedTouches,
1912 c = container.apply(this, arguments),
1913 n = touches.length, i, gesture;
1915 for (i = 0; i < n; ++i) {
1916 if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
1923 function touchmoved() {
1924 var touches = event.changedTouches,
1925 n = touches.length, i, gesture;
1927 for (i = 0; i < n; ++i) {
1928 if (gesture = gestures[touches[i].identifier]) {
1935 function touchended() {
1936 var touches = event.changedTouches,
1937 n = touches.length, i, gesture;
1939 if (touchending) clearTimeout(touchending);
1940 touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
1941 for (i = 0; i < n; ++i) {
1942 if (gesture = gestures[touches[i].identifier]) {
1949 function beforestart(id, container, point$$1, that, args) {
1950 var p = point$$1(container, id), s, dx, dy,
1951 sublisteners = listeners.copy();
1953 if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
1954 if ((event.subject = s = subject.apply(that, args)) == null) return false;
1955 dx = s.x - p[0] || 0;
1956 dy = s.y - p[1] || 0;
1960 return function gesture(type) {
1963 case "start": gestures[id] = gesture, n = active++; break;
1964 case "end": delete gestures[id], --active; // nobreak
1965 case "drag": p = point$$1(container, id), n = active; break;
1967 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]);
1971 drag.filter = function(_) {
1972 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
1975 drag.container = function(_) {
1976 return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
1979 drag.subject = function(_) {
1980 return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
1983 drag.touchable = function(_) {
1984 return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
1987 drag.on = function() {
1988 var value = listeners.on.apply(listeners, arguments);
1989 return value === listeners ? drag : value;
1992 drag.clickDistance = function(_) {
1993 return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
1999 function define(constructor, factory, prototype) {
2000 constructor.prototype = factory.prototype = prototype;
2001 prototype.constructor = constructor;
2004 function extend(parent, definition) {
2005 var prototype = Object.create(parent.prototype);
2006 for (var key in definition) prototype[key] = definition[key];
2013 var brighter = 1 / darker;
2015 var reI = "\\s*([+-]?\\d+)\\s*",
2016 reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
2017 reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
2018 reHex3 = /^#([0-9a-f]{3})$/,
2019 reHex6 = /^#([0-9a-f]{6})$/,
2020 reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
2021 reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
2022 reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
2023 reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
2024 reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
2025 reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
2028 aliceblue: 0xf0f8ff,
2029 antiquewhite: 0xfaebd7,
2031 aquamarine: 0x7fffd4,
2036 blanchedalmond: 0xffebcd,
2038 blueviolet: 0x8a2be2,
2040 burlywood: 0xdeb887,
2041 cadetblue: 0x5f9ea0,
2042 chartreuse: 0x7fff00,
2043 chocolate: 0xd2691e,
2045 cornflowerblue: 0x6495ed,
2051 darkgoldenrod: 0xb8860b,
2053 darkgreen: 0x006400,
2055 darkkhaki: 0xbdb76b,
2056 darkmagenta: 0x8b008b,
2057 darkolivegreen: 0x556b2f,
2058 darkorange: 0xff8c00,
2059 darkorchid: 0x9932cc,
2061 darksalmon: 0xe9967a,
2062 darkseagreen: 0x8fbc8f,
2063 darkslateblue: 0x483d8b,
2064 darkslategray: 0x2f4f4f,
2065 darkslategrey: 0x2f4f4f,
2066 darkturquoise: 0x00ced1,
2067 darkviolet: 0x9400d3,
2069 deepskyblue: 0x00bfff,
2072 dodgerblue: 0x1e90ff,
2073 firebrick: 0xb22222,
2074 floralwhite: 0xfffaf0,
2075 forestgreen: 0x228b22,
2077 gainsboro: 0xdcdcdc,
2078 ghostwhite: 0xf8f8ff,
2080 goldenrod: 0xdaa520,
2083 greenyellow: 0xadff2f,
2087 indianred: 0xcd5c5c,
2092 lavenderblush: 0xfff0f5,
2093 lawngreen: 0x7cfc00,
2094 lemonchiffon: 0xfffacd,
2095 lightblue: 0xadd8e6,
2096 lightcoral: 0xf08080,
2097 lightcyan: 0xe0ffff,
2098 lightgoldenrodyellow: 0xfafad2,
2099 lightgray: 0xd3d3d3,
2100 lightgreen: 0x90ee90,
2101 lightgrey: 0xd3d3d3,
2102 lightpink: 0xffb6c1,
2103 lightsalmon: 0xffa07a,
2104 lightseagreen: 0x20b2aa,
2105 lightskyblue: 0x87cefa,
2106 lightslategray: 0x778899,
2107 lightslategrey: 0x778899,
2108 lightsteelblue: 0xb0c4de,
2109 lightyellow: 0xffffe0,
2111 limegreen: 0x32cd32,
2115 mediumaquamarine: 0x66cdaa,
2116 mediumblue: 0x0000cd,
2117 mediumorchid: 0xba55d3,
2118 mediumpurple: 0x9370db,
2119 mediumseagreen: 0x3cb371,
2120 mediumslateblue: 0x7b68ee,
2121 mediumspringgreen: 0x00fa9a,
2122 mediumturquoise: 0x48d1cc,
2123 mediumvioletred: 0xc71585,
2124 midnightblue: 0x191970,
2125 mintcream: 0xf5fffa,
2126 mistyrose: 0xffe4e1,
2128 navajowhite: 0xffdead,
2132 olivedrab: 0x6b8e23,
2134 orangered: 0xff4500,
2136 palegoldenrod: 0xeee8aa,
2137 palegreen: 0x98fb98,
2138 paleturquoise: 0xafeeee,
2139 palevioletred: 0xdb7093,
2140 papayawhip: 0xffefd5,
2141 peachpuff: 0xffdab9,
2145 powderblue: 0xb0e0e6,
2147 rebeccapurple: 0x663399,
2149 rosybrown: 0xbc8f8f,
2150 royalblue: 0x4169e1,
2151 saddlebrown: 0x8b4513,
2153 sandybrown: 0xf4a460,
2159 slateblue: 0x6a5acd,
2160 slategray: 0x708090,
2161 slategrey: 0x708090,
2163 springgreen: 0x00ff7f,
2164 steelblue: 0x4682b4,
2169 turquoise: 0x40e0d0,
2173 whitesmoke: 0xf5f5f5,
2175 yellowgreen: 0x9acd32
2178 define(Color, color, {
2179 displayable: function() {
2180 return this.rgb().displayable();
2182 toString: function() {
2183 return this.rgb() + "";
2187 function color(format) {
2189 format = (format + "").trim().toLowerCase();
2190 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
2191 : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
2192 : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
2193 : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
2194 : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
2195 : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
2196 : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
2197 : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
2198 : named.hasOwnProperty(format) ? rgbn(named[format])
2199 : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
2204 return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
2207 function rgba(r, g, b, a) {
2208 if (a <= 0) r = g = b = NaN;
2209 return new Rgb(r, g, b, a);
2212 function rgbConvert(o) {
2213 if (!(o instanceof Color)) o = color(o);
2214 if (!o) return new Rgb;
2216 return new Rgb(o.r, o.g, o.b, o.opacity);
2219 function rgb(r, g, b, opacity) {
2220 return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
2223 function Rgb(r, g, b, opacity) {
2227 this.opacity = +opacity;
2230 define(Rgb, rgb, extend(Color, {
2231 brighter: function(k) {
2232 k = k == null ? brighter : Math.pow(brighter, k);
2233 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2235 darker: function(k) {
2236 k = k == null ? darker : Math.pow(darker, k);
2237 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2242 displayable: function() {
2243 return (0 <= this.r && this.r <= 255)
2244 && (0 <= this.g && this.g <= 255)
2245 && (0 <= this.b && this.b <= 255)
2246 && (0 <= this.opacity && this.opacity <= 1);
2248 toString: function() {
2249 var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
2250 return (a === 1 ? "rgb(" : "rgba(")
2251 + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
2252 + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
2253 + Math.max(0, Math.min(255, Math.round(this.b) || 0))
2254 + (a === 1 ? ")" : ", " + a + ")");
2258 function hsla(h, s, l, a) {
2259 if (a <= 0) h = s = l = NaN;
2260 else if (l <= 0 || l >= 1) h = s = NaN;
2261 else if (s <= 0) h = NaN;
2262 return new Hsl(h, s, l, a);
2265 function hslConvert(o) {
2266 if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
2267 if (!(o instanceof Color)) o = color(o);
2268 if (!o) return new Hsl;
2269 if (o instanceof Hsl) return o;
2274 min = Math.min(r, g, b),
2275 max = Math.max(r, g, b),
2278 l = (max + min) / 2;
2280 if (r === max) h = (g - b) / s + (g < b) * 6;
2281 else if (g === max) h = (b - r) / s + 2;
2282 else h = (r - g) / s + 4;
2283 s /= l < 0.5 ? max + min : 2 - max - min;
2286 s = l > 0 && l < 1 ? 0 : h;
2288 return new Hsl(h, s, l, o.opacity);
2291 function hsl(h, s, l, opacity) {
2292 return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
2295 function Hsl(h, s, l, opacity) {
2299 this.opacity = +opacity;
2302 define(Hsl, hsl, extend(Color, {
2303 brighter: function(k) {
2304 k = k == null ? brighter : Math.pow(brighter, k);
2305 return new Hsl(this.h, this.s, this.l * k, this.opacity);
2307 darker: function(k) {
2308 k = k == null ? darker : Math.pow(darker, k);
2309 return new Hsl(this.h, this.s, this.l * k, this.opacity);
2312 var h = this.h % 360 + (this.h < 0) * 360,
2313 s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
2315 m2 = l + (l < 0.5 ? l : 1 - l) * s,
2318 hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
2320 hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
2324 displayable: function() {
2325 return (0 <= this.s && this.s <= 1 || isNaN(this.s))
2326 && (0 <= this.l && this.l <= 1)
2327 && (0 <= this.opacity && this.opacity <= 1);
2331 /* From FvD 13.37, CSS Color Module Level 3 */
2332 function hsl2rgb(h, m1, m2) {
2333 return (h < 60 ? m1 + (m2 - m1) * h / 60
2335 : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
2339 var deg2rad = Math.PI / 180;
2340 var rad2deg = 180 / Math.PI;
2343 Xn = 0.950470, // D65 standard referent
2351 function labConvert(o) {
2352 if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
2353 if (o instanceof Hcl) {
2354 var h = o.h * deg2rad;
2355 return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
2357 if (!(o instanceof Rgb)) o = rgbConvert(o);
2358 var b = rgb2xyz(o.r),
2361 x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
2362 y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
2363 z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
2364 return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
2367 function lab(l, a, b, opacity) {
2368 return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
2371 function Lab(l, a, b, opacity) {
2375 this.opacity = +opacity;
2378 define(Lab, lab, extend(Color, {
2379 brighter: function(k) {
2380 return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
2382 darker: function(k) {
2383 return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
2386 var y = (this.l + 16) / 116,
2387 x = isNaN(this.a) ? y : y + this.a / 500,
2388 z = isNaN(this.b) ? y : y - this.b / 200;
2389 y = Yn * lab2xyz(y);
2390 x = Xn * lab2xyz(x);
2391 z = Zn * lab2xyz(z);
2393 xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
2394 xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
2395 xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
2401 function xyz2lab(t) {
2402 return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
2405 function lab2xyz(t) {
2406 return t > t1 ? t * t * t : t2 * (t - t0);
2409 function xyz2rgb(x) {
2410 return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
2413 function rgb2xyz(x) {
2414 return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
2417 function hclConvert(o) {
2418 if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
2419 if (!(o instanceof Lab)) o = labConvert(o);
2420 var h = Math.atan2(o.b, o.a) * rad2deg;
2421 return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
2424 function hcl(h, c, l, opacity) {
2425 return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
2428 function Hcl(h, c, l, opacity) {
2432 this.opacity = +opacity;
2435 define(Hcl, hcl, extend(Color, {
2436 brighter: function(k) {
2437 return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
2439 darker: function(k) {
2440 return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
2443 return labConvert(this).rgb();
2454 BC_DA = B * C - D * A;
2456 function cubehelixConvert(o) {
2457 if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
2458 if (!(o instanceof Rgb)) o = rgbConvert(o);
2462 l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
2464 k = (E * (g - l) - C * bl) / D,
2465 s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
2466 h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
2467 return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
2470 function cubehelix(h, s, l, opacity) {
2471 return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
2474 function Cubehelix(h, s, l, opacity) {
2478 this.opacity = +opacity;
2481 define(Cubehelix, cubehelix, extend(Color, {
2482 brighter: function(k) {
2483 k = k == null ? brighter : Math.pow(brighter, k);
2484 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2486 darker: function(k) {
2487 k = k == null ? darker : Math.pow(darker, k);
2488 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2491 var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
2493 a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
2497 255 * (l + a * (A * cosh + B * sinh)),
2498 255 * (l + a * (C * cosh + D * sinh)),
2499 255 * (l + a * (E * cosh)),
2505 function basis(t1, v0, v1, v2, v3) {
2506 var t2 = t1 * t1, t3 = t2 * t1;
2507 return ((1 - 3 * t1 + 3 * t2 - t3) * v0
2508 + (4 - 6 * t2 + 3 * t3) * v1
2509 + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
2513 function basis$1(values) {
2514 var n = values.length - 1;
2515 return function(t) {
2516 var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
2519 v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
2520 v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
2521 return basis((t - i / n) * n, v0, v1, v2, v3);
2525 function basisClosed(values) {
2526 var n = values.length;
2527 return function(t) {
2528 var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
2529 v0 = values[(i + n - 1) % n],
2531 v2 = values[(i + 1) % n],
2532 v3 = values[(i + 2) % n];
2533 return basis((t - i / n) * n, v0, v1, v2, v3);
2537 function constant$3(x) {
2543 function linear(a, d) {
2544 return function(t) {
2549 function exponential(a, b, y) {
2550 return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
2551 return Math.pow(a + t * b, y);
2555 function hue(a, b) {
2557 return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
2561 return (y = +y) === 1 ? nogamma : function(a, b) {
2562 return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
2566 function nogamma(a, b) {
2568 return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
2571 var interpolateRgb = (function rgbGamma(y) {
2572 var color$$1 = gamma(y);
2574 function rgb$$1(start, end) {
2575 var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
2576 g = color$$1(start.g, end.g),
2577 b = color$$1(start.b, end.b),
2578 opacity = nogamma(start.opacity, end.opacity);
2579 return function(t) {
2583 start.opacity = opacity(t);
2588 rgb$$1.gamma = rgbGamma;
2593 function rgbSpline(spline) {
2594 return function(colors) {
2595 var n = colors.length,
2600 for (i = 0; i < n; ++i) {
2601 color$$1 = rgb(colors[i]);
2602 r[i] = color$$1.r || 0;
2603 g[i] = color$$1.g || 0;
2604 b[i] = color$$1.b || 0;
2609 color$$1.opacity = 1;
2610 return function(t) {
2614 return color$$1 + "";
2619 var rgbBasis = rgbSpline(basis$1);
2620 var rgbBasisClosed = rgbSpline(basisClosed);
2622 function array$1(a, b) {
2623 var nb = b ? b.length : 0,
2624 na = a ? Math.min(nb, a.length) : 0,
2629 for (i = 0; i < na; ++i) x[i] = interpolate(a[i], b[i]);
2630 for (; i < nb; ++i) c[i] = b[i];
2632 return function(t) {
2633 for (i = 0; i < na; ++i) c[i] = x[i](t);
2638 function date(a, b) {
2640 return a = +a, b -= a, function(t) {
2641 return d.setTime(a + b * t), d;
2645 function interpolateNumber(a, b) {
2646 return a = +a, b -= a, function(t) {
2651 function object(a, b) {
2656 if (a === null || typeof a !== "object") a = {};
2657 if (b === null || typeof b !== "object") b = {};
2661 i[k] = interpolate(a[k], b[k]);
2667 return function(t) {
2668 for (k in i) c[k] = i[k](t);
2673 var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
2674 reB = new RegExp(reA.source, "g");
2683 return function(t) {
2688 function interpolateString(a, b) {
2689 var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
2690 am, // current match in a
2691 bm, // current match in b
2692 bs, // string preceding current number in b, if any
2693 i = -1, // index in s
2694 s = [], // string constants and placeholders
2695 q = []; // number interpolators
2697 // Coerce inputs to strings.
2698 a = a + "", b = b + "";
2700 // Interpolate pairs of numbers in a & b.
2701 while ((am = reA.exec(a))
2702 && (bm = reB.exec(b))) {
2703 if ((bs = bm.index) > bi) { // a string precedes the next number in b
2704 bs = b.slice(bi, bs);
2705 if (s[i]) s[i] += bs; // coalesce with previous string
2708 if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
2709 if (s[i]) s[i] += bm; // coalesce with previous string
2711 } else { // interpolate non-matching numbers
2713 q.push({i: i, x: interpolateNumber(am, bm)});
2718 // Add remains of b.
2719 if (bi < b.length) {
2721 if (s[i]) s[i] += bs; // coalesce with previous string
2725 // Special optimization for only a single match.
2726 // Otherwise, interpolate each of the numbers and rejoin the string.
2727 return s.length < 2 ? (q[0]
2730 : (b = q.length, function(t) {
2731 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
2736 function interpolate(a, b) {
2737 var t = typeof b, c;
2738 return b == null || t === "boolean" ? constant$3(b)
2739 : (t === "number" ? interpolateNumber
2740 : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
2741 : b instanceof color ? interpolateRgb
2742 : b instanceof Date ? date
2743 : Array.isArray(b) ? array$1
2744 : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
2745 : interpolateNumber)(a, b);
2748 function interpolateRound(a, b) {
2749 return a = +a, b -= a, function(t) {
2750 return Math.round(a + b * t);
2754 var degrees = 180 / Math.PI;
2765 function decompose(a, b, c, d, e, f) {
2766 var scaleX, scaleY, skewX;
2767 if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
2768 if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
2769 if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
2770 if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
2774 rotate: Math.atan2(b, a) * degrees,
2775 skewX: Math.atan(skewX) * degrees,
2786 function parseCss(value) {
2787 if (value === "none") return identity$2;
2788 if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
2789 cssNode.style.transform = value;
2790 value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
2791 cssRoot.removeChild(cssNode);
2792 value = value.slice(7, -1).split(",");
2793 return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
2796 function parseSvg(value) {
2797 if (value == null) return identity$2;
2798 if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
2799 svgNode.setAttribute("transform", value);
2800 if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
2801 value = value.matrix;
2802 return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
2805 function interpolateTransform(parse, pxComma, pxParen, degParen) {
2808 return s.length ? s.pop() + " " : "";
2811 function translate(xa, ya, xb, yb, s, q) {
2812 if (xa !== xb || ya !== yb) {
2813 var i = s.push("translate(", null, pxComma, null, pxParen);
2814 q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
2815 } else if (xb || yb) {
2816 s.push("translate(" + xb + pxComma + yb + pxParen);
2820 function rotate(a, b, s, q) {
2822 if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
2823 q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
2825 s.push(pop(s) + "rotate(" + b + degParen);
2829 function skewX(a, b, s, q) {
2831 q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
2833 s.push(pop(s) + "skewX(" + b + degParen);
2837 function scale(xa, ya, xb, yb, s, q) {
2838 if (xa !== xb || ya !== yb) {
2839 var i = s.push(pop(s) + "scale(", null, ",", null, ")");
2840 q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
2841 } else if (xb !== 1 || yb !== 1) {
2842 s.push(pop(s) + "scale(" + xb + "," + yb + ")");
2846 return function(a, b) {
2847 var s = [], // string constants and placeholders
2848 q = []; // number interpolators
2849 a = parse(a), b = parse(b);
2850 translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
2851 rotate(a.rotate, b.rotate, s, q);
2852 skewX(a.skewX, b.skewX, s, q);
2853 scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
2855 return function(t) {
2856 var i = -1, n = q.length, o;
2857 while (++i < n) s[(o = q[i]).i] = o.x(t);
2863 var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
2864 var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
2866 var rho = Math.SQRT2,
2872 return ((x = Math.exp(x)) + 1 / x) / 2;
2876 return ((x = Math.exp(x)) - 1 / x) / 2;
2880 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
2883 // p0 = [ux0, uy0, w0]
2884 // p1 = [ux1, uy1, w1]
2885 function interpolateZoom(p0, p1) {
2886 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
2887 ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
2890 d2 = dx * dx + dy * dy,
2894 // Special case for u0 ≅ u1.
2895 if (d2 < epsilon2) {
2896 S = Math.log(w1 / w0) / rho;
2901 w0 * Math.exp(rho * t * S)
2908 var d1 = Math.sqrt(d2),
2909 b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
2910 b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
2911 r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
2912 r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
2913 S = (r1 - r0) / rho;
2917 u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
2921 w0 * coshr0 / cosh(rho * s + r0)
2926 i.duration = S * 1000;
2931 function hsl$1(hue$$1) {
2932 return function(start, end) {
2933 var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
2934 s = nogamma(start.s, end.s),
2935 l = nogamma(start.l, end.l),
2936 opacity = nogamma(start.opacity, end.opacity);
2937 return function(t) {
2941 start.opacity = opacity(t);
2947 var hsl$2 = hsl$1(hue);
2948 var hslLong = hsl$1(nogamma);
2950 function lab$1(start, end) {
2951 var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
2952 a = nogamma(start.a, end.a),
2953 b = nogamma(start.b, end.b),
2954 opacity = nogamma(start.opacity, end.opacity);
2955 return function(t) {
2959 start.opacity = opacity(t);
2964 function hcl$1(hue$$1) {
2965 return function(start, end) {
2966 var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
2967 c = nogamma(start.c, end.c),
2968 l = nogamma(start.l, end.l),
2969 opacity = nogamma(start.opacity, end.opacity);
2970 return function(t) {
2974 start.opacity = opacity(t);
2980 var hcl$2 = hcl$1(hue);
2981 var hclLong = hcl$1(nogamma);
2983 function cubehelix$1(hue$$1) {
2984 return (function cubehelixGamma(y) {
2987 function cubehelix$$1(start, end) {
2988 var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
2989 s = nogamma(start.s, end.s),
2990 l = nogamma(start.l, end.l),
2991 opacity = nogamma(start.opacity, end.opacity);
2992 return function(t) {
2995 start.l = l(Math.pow(t, y));
2996 start.opacity = opacity(t);
3001 cubehelix$$1.gamma = cubehelixGamma;
3003 return cubehelix$$1;
3007 var cubehelix$2 = cubehelix$1(hue);
3008 var cubehelixLong = cubehelix$1(nogamma);
3010 function d3_quantize(interpolator, n) {
3011 var samples = new Array(n);
3012 for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
3016 var frame = 0, // is an animation frame pending?
3017 timeout = 0, // is a timeout pending?
3018 interval = 0, // are any timers active?
3019 pokeDelay = 1000, // how frequently we check for clock skew
3025 clock = typeof performance === "object" && performance.now ? performance : Date,
3026 setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
3029 return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
3032 function clearNow() {
3042 Timer.prototype = timer.prototype = {
3044 restart: function(callback, delay, time) {
3045 if (typeof callback !== "function") throw new TypeError("callback is not a function");
3046 time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
3047 if (!this._next && taskTail !== this) {
3048 if (taskTail) taskTail._next = this;
3049 else taskHead = this;
3052 this._call = callback;
3059 this._time = Infinity;
3065 function timer(callback, delay, time) {
3067 t.restart(callback, delay, time);
3071 function timerFlush() {
3072 now(); // Get the current time, if not already set.
3073 ++frame; // Pretend we’ve set an alarm, if we haven’t already.
3074 var t = taskHead, e;
3076 if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
3083 clockNow = (clockLast = clock.now()) + clockSkew;
3084 frame = timeout = 0;
3095 var now = clock.now(), delay = now - clockLast;
3096 if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
3100 var t0, t1 = taskHead, t2, time = Infinity;
3103 if (time > t1._time) time = t1._time;
3104 t0 = t1, t1 = t1._next;
3106 t2 = t1._next, t1._next = null;
3107 t1 = t0 ? t0._next = t2 : taskHead = t2;
3114 function sleep(time) {
3115 if (frame) return; // Soonest alarm already set, or will be.
3116 if (timeout) timeout = clearTimeout(timeout);
3117 var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
3119 if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
3120 if (interval) interval = clearInterval(interval);
3122 if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
3123 frame = 1, setFrame(wake);
3127 function timeout$1(callback, delay, time) {
3129 delay = delay == null ? 0 : +delay;
3130 t.restart(function(elapsed) {
3132 callback(elapsed + delay);
3137 function interval$1(callback, delay, time) {
3138 var t = new Timer, total = delay;
3139 if (delay == null) return t.restart(callback, delay, time), t;
3140 delay = +delay, time = time == null ? now() : +time;
3141 t.restart(function tick(elapsed) {
3143 t.restart(tick, total += delay, time);
3149 var emptyOn = dispatch("start", "end", "interrupt");
3150 var emptyTween = [];
3160 function schedule(node, name, id, index, group, timing) {
3161 var schedules = node.__transition;
3162 if (!schedules) node.__transition = {};
3163 else if (id in schedules) return;
3164 create$1(node, id, {
3166 index: index, // For context during callback.
3167 group: group, // For context during callback.
3171 delay: timing.delay,
3172 duration: timing.duration,
3179 function init(node, id) {
3180 var schedule = get$1(node, id);
3181 if (schedule.state > CREATED) throw new Error("too late; already scheduled");
3185 function set$1(node, id) {
3186 var schedule = get$1(node, id);
3187 if (schedule.state > STARTING) throw new Error("too late; already started");
3191 function get$1(node, id) {
3192 var schedule = node.__transition;
3193 if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
3197 function create$1(node, id, self) {
3198 var schedules = node.__transition,
3201 // Initialize the self timer when the transition is created.
3202 // Note the actual delay is not known until the first callback!
3203 schedules[id] = self;
3204 self.timer = timer(schedule, 0, self.time);
3206 function schedule(elapsed) {
3207 self.state = SCHEDULED;
3208 self.timer.restart(start, self.delay, self.time);
3210 // If the elapsed delay is less than our first sleep, start immediately.
3211 if (self.delay <= elapsed) start(elapsed - self.delay);
3214 function start(elapsed) {
3217 // If the state is not SCHEDULED, then we previously errored on start.
3218 if (self.state !== SCHEDULED) return stop();
3220 for (i in schedules) {
3222 if (o.name !== self.name) continue;
3224 // While this element already has a starting transition during this frame,
3225 // defer starting an interrupting transition until that transition has a
3226 // chance to tick (and possibly end); see d3/d3-transition#54!
3227 if (o.state === STARTED) return timeout$1(start);
3229 // Interrupt the active transition, if any.
3230 // Dispatch the interrupt event.
3231 if (o.state === RUNNING) {
3234 o.on.call("interrupt", node, node.__data__, o.index, o.group);
3235 delete schedules[i];
3238 // Cancel any pre-empted transitions. No interrupt event is dispatched
3239 // because the cancelled transitions never started. Note that this also
3240 // removes this transition from the pending list!
3244 delete schedules[i];
3248 // Defer the first tick to end of the current frame; see d3/d3#1576.
3249 // Note the transition may be canceled after start and before the first tick!
3250 // Note this must be scheduled before the start event; see d3/d3-transition#16!
3251 // Assuming this is successful, subsequent callbacks go straight to tick.
3252 timeout$1(function() {
3253 if (self.state === STARTED) {
3254 self.state = RUNNING;
3255 self.timer.restart(tick, self.delay, self.time);
3260 // Dispatch the start event.
3261 // Note this must be done before the tween are initialized.
3262 self.state = STARTING;
3263 self.on.call("start", node, node.__data__, self.index, self.group);
3264 if (self.state !== STARTING) return; // interrupted
3265 self.state = STARTED;
3267 // Initialize the tween, deleting null tween.
3268 tween = new Array(n = self.tween.length);
3269 for (i = 0, j = -1; i < n; ++i) {
3270 if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
3274 tween.length = j + 1;
3277 function tick(elapsed) {
3278 var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
3283 tween[i].call(null, t);
3286 // Dispatch the end event.
3287 if (self.state === ENDING) {
3288 self.on.call("end", node, node.__data__, self.index, self.group);
3296 delete schedules[id];
3297 for (var i in schedules) return; // eslint-disable-line no-unused-vars
3298 delete node.__transition;
3302 function interrupt(node, name) {
3303 var schedules = node.__transition,
3309 if (!schedules) return;
3311 name = name == null ? null : name + "";
3313 for (i in schedules) {
3314 if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
3315 active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
3316 schedule$$1.state = ENDED;
3317 schedule$$1.timer.stop();
3318 if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
3319 delete schedules[i];
3322 if (empty) delete node.__transition;
3325 function selection_interrupt(name) {
3326 return this.each(function() {
3327 interrupt(this, name);
3331 function tweenRemove(id, name) {
3334 var schedule$$1 = set$1(this, id),
3335 tween = schedule$$1.tween;
3337 // If this node shared tween with the previous node,
3338 // just assign the updated shared tween and we’re done!
3339 // Otherwise, copy-on-write.
3340 if (tween !== tween0) {
3341 tween1 = tween0 = tween;
3342 for (var i = 0, n = tween1.length; i < n; ++i) {
3343 if (tween1[i].name === name) {
3344 tween1 = tween1.slice();
3345 tween1.splice(i, 1);
3351 schedule$$1.tween = tween1;
3355 function tweenFunction(id, name, value) {
3357 if (typeof value !== "function") throw new Error;
3359 var schedule$$1 = set$1(this, id),
3360 tween = schedule$$1.tween;
3362 // If this node shared tween with the previous node,
3363 // just assign the updated shared tween and we’re done!
3364 // Otherwise, copy-on-write.
3365 if (tween !== tween0) {
3366 tween1 = (tween0 = tween).slice();
3367 for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
3368 if (tween1[i].name === name) {
3373 if (i === n) tween1.push(t);
3376 schedule$$1.tween = tween1;
3380 function transition_tween(name, value) {
3385 if (arguments.length < 2) {
3386 var tween = get$1(this.node(), id).tween;
3387 for (var i = 0, n = tween.length, t; i < n; ++i) {
3388 if ((t = tween[i]).name === name) {
3395 return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
3398 function tweenValue(transition, name, value) {
3399 var id = transition._id;
3401 transition.each(function() {
3402 var schedule$$1 = set$1(this, id);
3403 (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
3406 return function(node) {
3407 return get$1(node, id).value[name];
3411 function interpolate$1(a, b) {
3413 return (typeof b === "number" ? interpolateNumber
3414 : b instanceof color ? interpolateRgb
3415 : (c = color(b)) ? (b = c, interpolateRgb)
3416 : interpolateString)(a, b);
3419 function attrRemove$1(name) {
3421 this.removeAttribute(name);
3425 function attrRemoveNS$1(fullname) {
3427 this.removeAttributeNS(fullname.space, fullname.local);
3431 function attrConstant$1(name, interpolate$$1, value1) {
3435 var value0 = this.getAttribute(name);
3436 return value0 === value1 ? null
3437 : value0 === value00 ? interpolate0
3438 : interpolate0 = interpolate$$1(value00 = value0, value1);
3442 function attrConstantNS$1(fullname, interpolate$$1, value1) {
3446 var value0 = this.getAttributeNS(fullname.space, fullname.local);
3447 return value0 === value1 ? null
3448 : value0 === value00 ? interpolate0
3449 : interpolate0 = interpolate$$1(value00 = value0, value1);
3453 function attrFunction$1(name, interpolate$$1, value) {
3458 var value0, value1 = value(this);
3459 if (value1 == null) return void this.removeAttribute(name);
3460 value0 = this.getAttribute(name);
3461 return value0 === value1 ? null
3462 : value0 === value00 && value1 === value10 ? interpolate0
3463 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3467 function attrFunctionNS$1(fullname, interpolate$$1, value) {
3472 var value0, value1 = value(this);
3473 if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
3474 value0 = this.getAttributeNS(fullname.space, fullname.local);
3475 return value0 === value1 ? null
3476 : value0 === value00 && value1 === value10 ? interpolate0
3477 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3481 function transition_attr(name, value) {
3482 var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate$1;
3483 return this.attrTween(name, typeof value === "function"
3484 ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
3485 : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
3486 : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
3489 function attrTweenNS(fullname, value) {
3491 var node = this, i = value.apply(node, arguments);
3492 return i && function(t) {
3493 node.setAttributeNS(fullname.space, fullname.local, i(t));
3496 tween._value = value;
3500 function attrTween(name, value) {
3502 var node = this, i = value.apply(node, arguments);
3503 return i && function(t) {
3504 node.setAttribute(name, i(t));
3507 tween._value = value;
3511 function transition_attrTween(name, value) {
3512 var key = "attr." + name;
3513 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3514 if (value == null) return this.tween(key, null);
3515 if (typeof value !== "function") throw new Error;
3516 var fullname = namespace(name);
3517 return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
3520 function delayFunction(id, value) {
3522 init(this, id).delay = +value.apply(this, arguments);
3526 function delayConstant(id, value) {
3527 return value = +value, function() {
3528 init(this, id).delay = value;
3532 function transition_delay(value) {
3535 return arguments.length
3536 ? this.each((typeof value === "function"
3538 : delayConstant)(id, value))
3539 : get$1(this.node(), id).delay;
3542 function durationFunction(id, value) {
3544 set$1(this, id).duration = +value.apply(this, arguments);
3548 function durationConstant(id, value) {
3549 return value = +value, function() {
3550 set$1(this, id).duration = value;
3554 function transition_duration(value) {
3557 return arguments.length
3558 ? this.each((typeof value === "function"
3560 : durationConstant)(id, value))
3561 : get$1(this.node(), id).duration;
3564 function easeConstant(id, value) {
3565 if (typeof value !== "function") throw new Error;
3567 set$1(this, id).ease = value;
3571 function transition_ease(value) {
3574 return arguments.length
3575 ? this.each(easeConstant(id, value))
3576 : get$1(this.node(), id).ease;
3579 function transition_filter(match) {
3580 if (typeof match !== "function") match = matcher$1(match);
3582 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3583 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
3584 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
3585 subgroup.push(node);
3590 return new Transition(subgroups, this._parents, this._name, this._id);
3593 function transition_merge(transition$$1) {
3594 if (transition$$1._id !== this._id) throw new Error;
3596 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) {
3597 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
3598 if (node = group0[i] || group1[i]) {
3604 for (; j < m0; ++j) {
3605 merges[j] = groups0[j];
3608 return new Transition(merges, this._parents, this._name, this._id);
3611 function start(name) {
3612 return (name + "").trim().split(/^|\s+/).every(function(t) {
3613 var i = t.indexOf(".");
3614 if (i >= 0) t = t.slice(0, i);
3615 return !t || t === "start";
3619 function onFunction(id, name, listener) {
3620 var on0, on1, sit = start(name) ? init : set$1;
3622 var schedule$$1 = sit(this, id),
3623 on = schedule$$1.on;
3625 // If this node shared a dispatch with the previous node,
3626 // just assign the updated shared dispatch and we’re done!
3627 // Otherwise, copy-on-write.
3628 if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
3630 schedule$$1.on = on1;
3634 function transition_on(name, listener) {
3637 return arguments.length < 2
3638 ? get$1(this.node(), id).on.on(name)
3639 : this.each(onFunction(id, name, listener));
3642 function removeFunction(id) {
3644 var parent = this.parentNode;
3645 for (var i in this.__transition) if (+i !== id) return;
3646 if (parent) parent.removeChild(this);
3650 function transition_remove() {
3651 return this.on("end.remove", removeFunction(this._id));
3654 function transition_select(select$$1) {
3655 var name = this._name,
3658 if (typeof select$$1 !== "function") select$$1 = selector(select$$1);
3660 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3661 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
3662 if ((node = group[i]) && (subnode = select$$1.call(node, node.__data__, i, group))) {
3663 if ("__data__" in node) subnode.__data__ = node.__data__;
3664 subgroup[i] = subnode;
3665 schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
3670 return new Transition(subgroups, this._parents, name, id);
3673 function transition_selectAll(select$$1) {
3674 var name = this._name,
3677 if (typeof select$$1 !== "function") select$$1 = selectorAll(select$$1);
3679 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
3680 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3681 if (node = group[i]) {
3682 for (var children = select$$1.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
3683 if (child = children[k]) {
3684 schedule(child, name, id, k, children, inherit);
3687 subgroups.push(children);
3693 return new Transition(subgroups, parents, name, id);
3696 var Selection$1 = selection.prototype.constructor;
3698 function transition_selection() {
3699 return new Selection$1(this._groups, this._parents);
3702 function styleRemove$1(name, interpolate$$1) {
3707 var value0 = styleValue(this, name),
3708 value1 = (this.style.removeProperty(name), styleValue(this, name));
3709 return value0 === value1 ? null
3710 : value0 === value00 && value1 === value10 ? interpolate0
3711 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3715 function styleRemoveEnd(name) {
3717 this.style.removeProperty(name);
3721 function styleConstant$1(name, interpolate$$1, value1) {
3725 var value0 = styleValue(this, name);
3726 return value0 === value1 ? null
3727 : value0 === value00 ? interpolate0
3728 : interpolate0 = interpolate$$1(value00 = value0, value1);
3732 function styleFunction$1(name, interpolate$$1, value) {
3737 var value0 = styleValue(this, name),
3738 value1 = value(this);
3739 if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
3740 return value0 === value1 ? null
3741 : value0 === value00 && value1 === value10 ? interpolate0
3742 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3746 function transition_style(name, value, priority) {
3747 var i = (name += "") === "transform" ? interpolateTransformCss : interpolate$1;
3748 return value == null ? this
3749 .styleTween(name, styleRemove$1(name, i))
3750 .on("end.style." + name, styleRemoveEnd(name))
3751 : this.styleTween(name, typeof value === "function"
3752 ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
3753 : styleConstant$1(name, i, value + ""), priority);
3756 function styleTween(name, value, priority) {
3758 var node = this, i = value.apply(node, arguments);
3759 return i && function(t) {
3760 node.style.setProperty(name, i(t), priority);
3763 tween._value = value;
3767 function transition_styleTween(name, value, priority) {
3768 var key = "style." + (name += "");
3769 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3770 if (value == null) return this.tween(key, null);
3771 if (typeof value !== "function") throw new Error;
3772 return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
3775 function textConstant$1(value) {
3777 this.textContent = value;
3781 function textFunction$1(value) {
3783 var value1 = value(this);
3784 this.textContent = value1 == null ? "" : value1;
3788 function transition_text(value) {
3789 return this.tween("text", typeof value === "function"
3790 ? textFunction$1(tweenValue(this, "text", value))
3791 : textConstant$1(value == null ? "" : value + ""));
3794 function transition_transition() {
3795 var name = this._name,
3799 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
3800 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3801 if (node = group[i]) {
3802 var inherit = get$1(node, id0);
3803 schedule(node, name, id1, i, group, {
3804 time: inherit.time + inherit.delay + inherit.duration,
3806 duration: inherit.duration,
3813 return new Transition(groups, this._parents, name, id1);
3818 function Transition(groups, parents, name, id) {
3819 this._groups = groups;
3820 this._parents = parents;
3825 function transition(name) {
3826 return selection().transition(name);
3833 var selection_prototype = selection.prototype;
3835 Transition.prototype = transition.prototype = {
3836 constructor: Transition,
3837 select: transition_select,
3838 selectAll: transition_selectAll,
3839 filter: transition_filter,
3840 merge: transition_merge,
3841 selection: transition_selection,
3842 transition: transition_transition,
3843 call: selection_prototype.call,
3844 nodes: selection_prototype.nodes,
3845 node: selection_prototype.node,
3846 size: selection_prototype.size,
3847 empty: selection_prototype.empty,
3848 each: selection_prototype.each,
3850 attr: transition_attr,
3851 attrTween: transition_attrTween,
3852 style: transition_style,
3853 styleTween: transition_styleTween,
3854 text: transition_text,
3855 remove: transition_remove,
3856 tween: transition_tween,
3857 delay: transition_delay,
3858 duration: transition_duration,
3859 ease: transition_ease
3862 function linear$1(t) {
3866 function quadIn(t) {
3870 function quadOut(t) {
3874 function quadInOut(t) {
3875 return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
3878 function cubicIn(t) {
3882 function cubicOut(t) {
3883 return --t * t * t + 1;
3886 function cubicInOut(t) {
3887 return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
3892 var polyIn = (function custom(e) {
3895 function polyIn(t) {
3896 return Math.pow(t, e);
3899 polyIn.exponent = custom;
3904 var polyOut = (function custom(e) {
3907 function polyOut(t) {
3908 return 1 - Math.pow(1 - t, e);
3911 polyOut.exponent = custom;
3916 var polyInOut = (function custom(e) {
3919 function polyInOut(t) {
3920 return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
3923 polyInOut.exponent = custom;
3932 return 1 - Math.cos(t * halfPi);
3935 function sinOut(t) {
3936 return Math.sin(t * halfPi);
3939 function sinInOut(t) {
3940 return (1 - Math.cos(pi * t)) / 2;
3944 return Math.pow(2, 10 * t - 10);
3947 function expOut(t) {
3948 return 1 - Math.pow(2, -10 * t);
3951 function expInOut(t) {
3952 return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
3955 function circleIn(t) {
3956 return 1 - Math.sqrt(1 - t * t);
3959 function circleOut(t) {
3960 return Math.sqrt(1 - --t * t);
3963 function circleInOut(t) {
3964 return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
3978 function bounceIn(t) {
3979 return 1 - bounceOut(1 - t);
3982 function bounceOut(t) {
3983 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;
3986 function bounceInOut(t) {
3987 return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
3990 var overshoot = 1.70158;
3992 var backIn = (function custom(s) {
3995 function backIn(t) {
3996 return t * t * ((s + 1) * t - s);
3999 backIn.overshoot = custom;
4004 var backOut = (function custom(s) {
4007 function backOut(t) {
4008 return --t * t * ((s + 1) * t + s) + 1;
4011 backOut.overshoot = custom;
4016 var backInOut = (function custom(s) {
4019 function backInOut(t) {
4020 return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
4023 backInOut.overshoot = custom;
4028 var tau = 2 * Math.PI,
4032 var elasticIn = (function custom(a, p) {
4033 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4035 function elasticIn(t) {
4036 return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
4039 elasticIn.amplitude = function(a) { return custom(a, p * tau); };
4040 elasticIn.period = function(p) { return custom(a, p); };
4043 })(amplitude, period);
4045 var elasticOut = (function custom(a, p) {
4046 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4048 function elasticOut(t) {
4049 return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
4052 elasticOut.amplitude = function(a) { return custom(a, p * tau); };
4053 elasticOut.period = function(p) { return custom(a, p); };
4056 })(amplitude, period);
4058 var elasticInOut = (function custom(a, p) {
4059 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4061 function elasticInOut(t) {
4062 return ((t = t * 2 - 1) < 0
4063 ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
4064 : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
4067 elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
4068 elasticInOut.period = function(p) { return custom(a, p); };
4070 return elasticInOut;
4071 })(amplitude, period);
4073 var defaultTiming = {
4074 time: null, // Set on use.
4080 function inherit(node, id) {
4082 while (!(timing = node.__transition) || !(timing = timing[id])) {
4083 if (!(node = node.parentNode)) {
4084 return defaultTiming.time = now(), defaultTiming;
4090 function selection_transition(name) {
4094 if (name instanceof Transition) {
4095 id = name._id, name = name._name;
4097 id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
4100 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
4101 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
4102 if (node = group[i]) {
4103 schedule(node, name, id, i, group, timing || inherit(node, id));
4108 return new Transition(groups, this._parents, name, id);
4111 selection.prototype.interrupt = selection_interrupt;
4112 selection.prototype.transition = selection_transition;
4114 var root$1 = [null];
4116 function active(node, name) {
4117 var schedules = node.__transition,
4122 name = name == null ? null : name + "";
4123 for (i in schedules) {
4124 if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
4125 return new Transition([[node]], root$1, name, +i);
4133 function constant$4(x) {
4139 function BrushEvent(target, type, selection) {
4140 this.target = target;
4142 this.selection = selection;
4145 function nopropagation$1() {
4146 event.stopImmediatePropagation();
4149 function noevent$1() {
4150 event.preventDefault();
4151 event.stopImmediatePropagation();
4154 var MODE_DRAG = {name: "drag"},
4155 MODE_SPACE = {name: "space"},
4156 MODE_HANDLE = {name: "handle"},
4157 MODE_CENTER = {name: "center"};
4161 handles: ["e", "w"].map(type),
4162 input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
4163 output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
4168 handles: ["n", "s"].map(type),
4169 input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
4170 output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
4175 handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
4176 input: function(xy) { return xy; },
4177 output: function(xy) { return xy; }
4181 overlay: "crosshair",
4241 // Ignore right-click, since that should open the context menu.
4242 function defaultFilter$1() {
4243 return !event.button;
4246 function defaultExtent() {
4247 var svg = this.ownerSVGElement || this;
4248 return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
4251 // Like d3.local, but with the name “__brush” rather than auto-generated.
4252 function local$1(node) {
4253 while (!node.__brush) if (!(node = node.parentNode)) return;
4254 return node.__brush;
4257 function empty$1(extent) {
4258 return extent[0][0] === extent[1][0]
4259 || extent[0][1] === extent[1][1];
4262 function brushSelection(node) {
4263 var state = node.__brush;
4264 return state ? state.dim.output(state.selection) : null;
4279 function brush$1(dim) {
4280 var extent = defaultExtent,
4281 filter = defaultFilter$1,
4282 listeners = dispatch(brush, "start", "brush", "end"),
4286 function brush(group) {
4288 .property("__brush", initialize)
4289 .selectAll(".overlay")
4290 .data([type("overlay")]);
4292 overlay.enter().append("rect")
4293 .attr("class", "overlay")
4294 .attr("pointer-events", "all")
4295 .attr("cursor", cursors.overlay)
4298 var extent = local$1(this).extent;
4300 .attr("x", extent[0][0])
4301 .attr("y", extent[0][1])
4302 .attr("width", extent[1][0] - extent[0][0])
4303 .attr("height", extent[1][1] - extent[0][1]);
4306 group.selectAll(".selection")
4307 .data([type("selection")])
4308 .enter().append("rect")
4309 .attr("class", "selection")
4310 .attr("cursor", cursors.selection)
4311 .attr("fill", "#777")
4312 .attr("fill-opacity", 0.3)
4313 .attr("stroke", "#fff")
4314 .attr("shape-rendering", "crispEdges");
4316 var handle = group.selectAll(".handle")
4317 .data(dim.handles, function(d) { return d.type; });
4319 handle.exit().remove();
4321 handle.enter().append("rect")
4322 .attr("class", function(d) { return "handle handle--" + d.type; })
4323 .attr("cursor", function(d) { return cursors[d.type]; });
4327 .attr("fill", "none")
4328 .attr("pointer-events", "all")
4329 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
4330 .on("mousedown.brush touchstart.brush", started);
4333 brush.move = function(group, selection$$1) {
4334 if (group.selection) {
4336 .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
4337 .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
4338 .tween("brush", function() {
4340 state = that.__brush,
4341 emit = emitter(that, arguments),
4342 selection0 = state.selection,
4343 selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(this, arguments) : selection$$1, state.extent),
4344 i = interpolate(selection0, selection1);
4347 state.selection = t === 1 && empty$1(selection1) ? null : i(t);
4352 return selection0 && selection1 ? tween : tween(1);
4359 state = that.__brush,
4360 selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(that, args) : selection$$1, state.extent),
4361 emit = emitter(that, args).beforestart();
4364 state.selection = selection1 == null || empty$1(selection1) ? null : selection1;
4366 emit.start().brush().end();
4372 var group = select(this),
4373 selection$$1 = local$1(this).selection;
4376 group.selectAll(".selection")
4377 .style("display", null)
4378 .attr("x", selection$$1[0][0])
4379 .attr("y", selection$$1[0][1])
4380 .attr("width", selection$$1[1][0] - selection$$1[0][0])
4381 .attr("height", selection$$1[1][1] - selection$$1[0][1]);
4383 group.selectAll(".handle")
4384 .style("display", null)
4385 .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection$$1[1][0] - handleSize / 2 : selection$$1[0][0] - handleSize / 2; })
4386 .attr("y", function(d) { return d.type[0] === "s" ? selection$$1[1][1] - handleSize / 2 : selection$$1[0][1] - handleSize / 2; })
4387 .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection$$1[1][0] - selection$$1[0][0] + handleSize : handleSize; })
4388 .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection$$1[1][1] - selection$$1[0][1] + handleSize : handleSize; });
4392 group.selectAll(".selection,.handle")
4393 .style("display", "none")
4396 .attr("width", null)
4397 .attr("height", null);
4401 function emitter(that, args) {
4402 return that.__brush.emitter || new Emitter(that, args);
4405 function Emitter(that, args) {
4408 this.state = that.__brush;
4412 Emitter.prototype = {
4413 beforestart: function() {
4414 if (++this.active === 1) this.state.emitter = this, this.starting = true;
4418 if (this.starting) this.starting = false, this.emit("start");
4426 if (--this.active === 0) delete this.state.emitter, this.emit("end");
4429 emit: function(type) {
4430 customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
4434 function started() {
4435 if (event.touches) { if (event.changedTouches.length < event.touches.length) return noevent$1(); }
4436 else if (touchending) return;
4437 if (!filter.apply(this, arguments)) return;
4440 type = event.target.__data__.type,
4441 mode = (event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (event.altKey ? MODE_CENTER : MODE_HANDLE),
4442 signX = dim === Y ? null : signsX[type],
4443 signY = dim === X ? null : signsY[type],
4444 state = local$1(that),
4445 extent = state.extent,
4446 selection$$1 = state.selection,
4447 W = extent[0][0], w0, w1,
4448 N = extent[0][1], n0, n1,
4449 E = extent[1][0], e0, e1,
4450 S = extent[1][1], s0, s1,
4454 shifting = signX && signY && event.shiftKey,
4457 point0 = mouse(that),
4459 emit = emitter(that, arguments).beforestart();
4461 if (type === "overlay") {
4462 state.selection = selection$$1 = [
4463 [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
4464 [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
4467 w0 = selection$$1[0][0];
4468 n0 = selection$$1[0][1];
4469 e0 = selection$$1[1][0];
4470 s0 = selection$$1[1][1];
4478 var group = select(that)
4479 .attr("pointer-events", "none");
4481 var overlay = group.selectAll(".overlay")
4482 .attr("cursor", cursors[type]);
4484 if (event.touches) {
4486 .on("touchmove.brush", moved, true)
4487 .on("touchend.brush touchcancel.brush", ended, true);
4489 var view = select(event.view)
4490 .on("keydown.brush", keydowned, true)
4491 .on("keyup.brush", keyupped, true)
4492 .on("mousemove.brush", moved, true)
4493 .on("mouseup.brush", ended, true);
4504 var point1 = mouse(that);
4505 if (shifting && !lockX && !lockY) {
4506 if (Math.abs(point1[0] - point$$1[0]) > Math.abs(point1[1] - point$$1[1])) lockY = true;
4518 dx = point$$1[0] - point0[0];
4519 dy = point$$1[1] - point0[1];
4524 if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
4525 if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
4529 if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
4530 else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
4531 if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
4532 else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
4536 if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
4537 if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
4544 t = w0, w0 = e0, e0 = t;
4545 t = w1, w1 = e1, e1 = t;
4546 if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
4551 t = n0, n0 = s0, s0 = t;
4552 t = n1, n1 = s1, s1 = t;
4553 if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
4556 if (state.selection) selection$$1 = state.selection; // May be set by brush.move!
4557 if (lockX) w1 = selection$$1[0][0], e1 = selection$$1[1][0];
4558 if (lockY) n1 = selection$$1[0][1], s1 = selection$$1[1][1];
4560 if (selection$$1[0][0] !== w1
4561 || selection$$1[0][1] !== n1
4562 || selection$$1[1][0] !== e1
4563 || selection$$1[1][1] !== s1) {
4564 state.selection = [[w1, n1], [e1, s1]];
4572 if (event.touches) {
4573 if (event.touches.length) return;
4574 if (touchending) clearTimeout(touchending);
4575 touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
4576 group.on("touchmove.brush touchend.brush touchcancel.brush", null);
4578 yesdrag(event.view, moving);
4579 view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
4581 group.attr("pointer-events", "all");
4582 overlay.attr("cursor", cursors.overlay);
4583 if (state.selection) selection$$1 = state.selection; // May be set by brush.move (on start)!
4584 if (empty$1(selection$$1)) state.selection = null, redraw.call(that);
4588 function keydowned() {
4589 switch (event.keyCode) {
4591 shifting = signX && signY;
4595 if (mode === MODE_HANDLE) {
4596 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4597 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4603 case 32: { // SPACE; takes priority over ALT
4604 if (mode === MODE_HANDLE || mode === MODE_CENTER) {
4605 if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
4606 if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
4608 overlay.attr("cursor", cursors.selection);
4618 function keyupped() {
4619 switch (event.keyCode) {
4622 lockX = lockY = shifting = false;
4628 if (mode === MODE_CENTER) {
4629 if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4630 if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4637 if (mode === MODE_SPACE) {
4639 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4640 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4643 if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4644 if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4647 overlay.attr("cursor", cursors[type]);
4658 function initialize() {
4659 var state = this.__brush || {selection: null};
4660 state.extent = extent.apply(this, arguments);
4665 brush.extent = function(_) {
4666 return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
4669 brush.filter = function(_) {
4670 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
4673 brush.handleSize = function(_) {
4674 return arguments.length ? (handleSize = +_, brush) : handleSize;
4677 brush.on = function() {
4678 var value = listeners.on.apply(listeners, arguments);
4679 return value === listeners ? brush : value;
4688 var halfPi$1 = pi$1 / 2;
4689 var tau$1 = pi$1 * 2;
4690 var max$1 = Math.max;
4692 function compareValue(compare) {
4693 return function(a, b) {
4695 a.source.value + a.target.value,