UNPKG

phylotree

Version:

A JavaScript library for developing applications and interactive visualizations involving [phylogenetic trees](https://en.wikipedia.org/wiki/Phylogenetic_tree), written as an extension of the [D3](http://d3js.org) [hierarchy layout](https://github.com/d3/

1 lines 146 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("underscore"),require("xml2js"),require("lodash")):"function"==typeof define&&define.amd?define(["exports","underscore","xml2js","lodash"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).phylotree=t.phylotree||{},t._,t.xml2js,t._$1)}(this,function(t,e,n,r){"use strict";function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}}),e.default=t,Object.freeze(e)}var a=i(e),o=i(r);function s(t,e){return null==t||null==e?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function l(t,e){return null==t||null==e?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function u(t){let e,n,r;function i(t,r,i=0,a=t.length){if(i<a){if(0!==e(r,r))return a;do{const e=i+a>>>1;n(t[e],r)<0?i=e+1:a=e}while(i<a)}return i}return 2!==t.length?(e=s,n=(e,n)=>s(t(e),n),r=(e,n)=>t(e)-n):(e=t===s||t===l?t:c,n=t,r=t),{left:i,center:function(t,e,n=0,a=t.length){const o=i(t,e,n,a-1);return o>n&&r(t[o-1],e)>-r(t[o],e)?o-1:o},right:function(t,r,i=0,a=t.length){if(i<a){if(0!==e(r,r))return a;do{const e=i+a>>>1;n(t[e],r)<=0?i=e+1:a=e}while(i<a)}return i}}}function c(){return 0}const h=u(s).right;u(function(t){return null===t?NaN:+t}).center;var f=h;const d=Math.sqrt(50),p=Math.sqrt(10),_=Math.sqrt(2);function g(t,e,n){const r=(e-t)/Math.max(0,n),i=Math.floor(Math.log10(r)),a=r/Math.pow(10,i),o=a>=d?10:a>=p?5:a>=_?2:1;let s,l,u;return i<0?(u=Math.pow(10,-i)/o,s=Math.round(t*u),l=Math.round(e*u),s/u<t&&++s,l/u>e&&--l,u=-u):(u=Math.pow(10,i)*o,s=Math.round(t/u),l=Math.round(e/u),s*u<t&&++s,l*u>e&&--l),l<s&&.5<=n&&n<2?g(t,e,2*n):[s,l,u]}function m(t,e,n){return g(t=+t,e=+e,n=+n)[2]}function v(t){return t}var y=1e-6;function b(t){return"translate("+t+",0)"}function w(t){return"translate(0,"+t+")"}function x(t){return e=>+t(e)}function M(t,e){return e=Math.max(0,t.bandwidth()-2*e)/2,t.round()&&(e=Math.round(e)),n=>+t(n)+e}function k(){return!this.__axis}function N(t,e){var n=[],r=null,i=null,a=6,o=6,s=3,l="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,u=1===t||4===t?-1:1,c=4===t||2===t?"x":"y",h=1===t||3===t?b:w;function f(f){var d=null==r?e.ticks?e.ticks.apply(e,n):e.domain():r,p=null==i?e.tickFormat?e.tickFormat.apply(e,n):v:i,_=Math.max(a,0)+s,g=e.range(),m=+g[0]+l,b=+g[g.length-1]+l,w=(e.bandwidth?M:x)(e.copy(),l),N=f.selection?f.selection():f,T=N.selectAll(".domain").data([null]),A=N.selectAll(".tick").data(d,e).order(),z=A.exit(),S=A.enter().append("g").attr("class","tick"),E=A.select("line"),C=A.select("text");T=T.merge(T.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),A=A.merge(S),E=E.merge(S.append("line").attr("stroke","currentColor").attr(c+"2",u*a)),C=C.merge(S.append("text").attr("fill","currentColor").attr(c,u*_).attr("dy",1===t?"0em":3===t?"0.71em":"0.32em")),f!==N&&(T=T.transition(f),A=A.transition(f),E=E.transition(f),C=C.transition(f),z=z.transition(f).attr("opacity",y).attr("transform",function(t){return isFinite(t=w(t))?h(t+l):this.getAttribute("transform")}),S.attr("opacity",y).attr("transform",function(t){var e=this.parentNode.__axis;return h((e&&isFinite(e=e(t))?e:w(t))+l)})),z.remove(),T.attr("d",4===t||2===t?o?"M"+u*o+","+m+"H"+l+"V"+b+"H"+u*o:"M"+l+","+m+"V"+b:o?"M"+m+","+u*o+"V"+l+"H"+b+"V"+u*o:"M"+m+","+l+"H"+b),A.attr("opacity",1).attr("transform",function(t){return h(w(t)+l)}),E.attr(c+"2",u*a),C.attr(c,u*_).text(p),N.filter(k).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",2===t?"start":4===t?"end":"middle"),N.each(function(){this.__axis=w})}return f.scale=function(t){return arguments.length?(e=t,f):e},f.ticks=function(){return n=Array.from(arguments),f},f.tickArguments=function(t){return arguments.length?(n=null==t?[]:Array.from(t),f):n.slice()},f.tickValues=function(t){return arguments.length?(r=null==t?null:Array.from(t),f):r&&r.slice()},f.tickFormat=function(t){return arguments.length?(i=t,f):i},f.tickSize=function(t){return arguments.length?(a=o=+t,f):a},f.tickSizeInner=function(t){return arguments.length?(a=+t,f):a},f.tickSizeOuter=function(t){return arguments.length?(o=+t,f):o},f.tickPadding=function(t){return arguments.length?(s=+t,f):s},f.offset=function(t){return arguments.length?(l=+t,f):l},f}var T={value:()=>{}};function A(){for(var t,e=0,n=arguments.length,r={};e<n;++e){if(!(t=arguments[e]+"")||t in r||/[\s.]/.test(t))throw new Error("illegal type: "+t);r[t]=[]}return new z(r)}function z(t){this._=t}function S(t,e){for(var n,r=0,i=t.length;r<i;++r)if((n=t[r]).name===e)return n.value}function E(t,e,n){for(var r=0,i=t.length;r<i;++r)if(t[r].name===e){t[r]=T,t=t.slice(0,r).concat(t.slice(r+1));break}return null!=n&&t.push({name:e,value:n}),t}z.prototype=A.prototype={constructor:z,on:function(t,e){var n,r,i=this._,a=(r=i,(t+"").trim().split(/^|\s+/).map(function(t){var e="",n=t.indexOf(".");if(n>=0&&(e=t.slice(n+1),t=t.slice(0,n)),t&&!r.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}})),o=-1,s=a.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++o<s;)if(n=(t=a[o]).type)i[n]=E(i[n],t.name,e);else if(null==e)for(n in i)i[n]=E(i[n],t.name,null);return this}for(;++o<s;)if((n=(t=a[o]).type)&&(n=S(i[n],t.name)))return n},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new z(t)},call:function(t,e){if((n=arguments.length-2)>0)for(var n,r,i=new Array(n),a=0;a<n;++a)i[a]=arguments[a+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(a=0,n=(r=this._[t]).length;a<n;++a)r[a].value.apply(e,i)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var r=this._[t],i=0,a=r.length;i<a;++i)r[i].value.apply(e,n)}};var C="http://www.w3.org/1999/xhtml",$={svg:"http://www.w3.org/2000/svg",xhtml:C,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function D(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),$.hasOwnProperty(e)?{space:$[e],local:t}:t}function L(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===C&&e.documentElement.namespaceURI===C?e.createElement(t):e.createElementNS(n,t)}}function U(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function P(t){var e=D(t);return(e.local?U:L)(e)}function H(){}function O(t){return null==t?H:function(){return this.querySelector(t)}}function j(){return[]}function F(t){return null==t?j:function(){return this.querySelectorAll(t)}}function Y(t){return function(){return function(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}(t.apply(this,arguments))}}function R(t){return function(){return this.matches(t)}}function I(t){return function(e){return e.matches(t)}}var q=Array.prototype.find;function B(){return this.firstElementChild}var V=Array.prototype.filter;function X(){return Array.from(this.children)}function W(t){return new Array(t.length)}function Z(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function G(t,e,n,r,i,a){for(var o,s=0,l=e.length,u=a.length;s<u;++s)(o=e[s])?(o.__data__=a[s],r[s]=o):n[s]=new Z(t,a[s]);for(;s<l;++s)(o=e[s])&&(i[s]=o)}function K(t,e,n,r,i,a,o){var s,l,u,c=new Map,h=e.length,f=a.length,d=new Array(h);for(s=0;s<h;++s)(l=e[s])&&(d[s]=u=o.call(l,l.__data__,s,e)+"",c.has(u)?i[s]=l:c.set(u,l));for(s=0;s<f;++s)u=o.call(t,a[s],s,a)+"",(l=c.get(u))?(r[s]=l,l.__data__=a[s],c.delete(u)):n[s]=new Z(t,a[s]);for(s=0;s<h;++s)(l=e[s])&&c.get(d[s])===l&&(i[s]=l)}function Q(t){return t.__data__}function J(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function tt(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}function et(t){return function(){this.removeAttribute(t)}}function nt(t){return function(){this.removeAttributeNS(t.space,t.local)}}function rt(t,e){return function(){this.setAttribute(t,e)}}function it(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function at(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function ot(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function st(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function lt(t){return function(){this.style.removeProperty(t)}}function ut(t,e,n){return function(){this.style.setProperty(t,e,n)}}function ct(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}function ht(t,e){return t.style.getPropertyValue(e)||st(t).getComputedStyle(t,null).getPropertyValue(e)}function ft(t){return function(){delete this[t]}}function dt(t,e){return function(){this[t]=e}}function pt(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function _t(t){return t.trim().split(/^|\s+/)}function gt(t){return t.classList||new mt(t)}function mt(t){this._node=t,this._names=_t(t.getAttribute("class")||"")}function vt(t,e){for(var n=gt(t),r=-1,i=e.length;++r<i;)n.add(e[r])}function yt(t,e){for(var n=gt(t),r=-1,i=e.length;++r<i;)n.remove(e[r])}function bt(t){return function(){vt(this,t)}}function wt(t){return function(){yt(this,t)}}function xt(t,e){return function(){(e.apply(this,arguments)?vt:yt)(this,t)}}function Mt(){this.textContent=""}function kt(t){return function(){this.textContent=t}}function Nt(t){return function(){var e=t.apply(this,arguments);this.textContent=null==e?"":e}}function Tt(){this.innerHTML=""}function At(t){return function(){this.innerHTML=t}}function zt(t){return function(){var e=t.apply(this,arguments);this.innerHTML=null==e?"":e}}function St(){this.nextSibling&&this.parentNode.appendChild(this)}function Et(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Ct(){return null}function $t(){var t=this.parentNode;t&&t.removeChild(this)}function Dt(){var t=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function Lt(){var t=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function Ut(t){return function(){var e=this.__on;if(e){for(var n,r=0,i=-1,a=e.length;r<a;++r)n=e[r],t.type&&n.type!==t.type||n.name!==t.name?e[++i]=n:this.removeEventListener(n.type,n.listener,n.options);++i?e.length=i:delete this.__on}}}function Pt(t,e,n){return function(){var r,i=this.__on,a=function(t){return function(e){t.call(this,e,this.__data__)}}(e);if(i)for(var o=0,s=i.length;o<s;++o)if((r=i[o]).type===t.type&&r.name===t.name)return this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=a,r.options=n),void(r.value=e);this.addEventListener(t.type,a,n),r={type:t.type,name:t.name,value:e,listener:a,options:n},i?i.push(r):this.__on=[r]}}function Ht(t,e,n){var r=st(t),i=r.CustomEvent;"function"==typeof i?i=new i(e,n):(i=r.document.createEvent("Event"),n?(i.initEvent(e,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(e,!1,!1)),t.dispatchEvent(i)}function Ot(t,e){return function(){return Ht(this,t,e)}}function jt(t,e){return function(){return Ht(this,t,e.apply(this,arguments))}}Z.prototype={constructor:Z,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}},mt.prototype={add:function(t){this._names.indexOf(t)<0&&(this._names.push(t),this._node.setAttribute("class",this._names.join(" ")))},remove:function(t){var e=this._names.indexOf(t);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var Ft=[null];function Yt(t,e){this._groups=t,this._parents=e}function Rt(){return new Yt([[document.documentElement]],Ft)}function It(t){return"string"==typeof t?new Yt([[document.querySelector(t)]],[document.documentElement]):new Yt([[t]],Ft)}function qt(t,e){if(t=function(t){let e;for(;e=t.sourceEvent;)t=e;return t}(t),void 0===e&&(e=t.currentTarget),e){var n=e.ownerSVGElement||e;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=t.clientX,r.y=t.clientY,[(r=r.matrixTransform(e.getScreenCTM().inverse())).x,r.y]}if(e.getBoundingClientRect){var i=e.getBoundingClientRect();return[t.clientX-i.left-e.clientLeft,t.clientY-i.top-e.clientTop]}}return[t.pageX,t.pageY]}Yt.prototype=Rt.prototype={constructor:Yt,select:function(t){"function"!=typeof t&&(t=O(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i<n;++i)for(var a,o,s=e[i],l=s.length,u=r[i]=new Array(l),c=0;c<l;++c)(a=s[c])&&(o=t.call(a,a.__data__,c,s))&&("__data__"in a&&(o.__data__=a.__data__),u[c]=o);return new Yt(r,this._parents)},selectAll:function(t){t="function"==typeof t?Y(t):F(t);for(var e=this._groups,n=e.length,r=[],i=[],a=0;a<n;++a)for(var o,s=e[a],l=s.length,u=0;u<l;++u)(o=s[u])&&(r.push(t.call(o,o.__data__,u,s)),i.push(o));return new Yt(r,i)},selectChild:function(t){return this.select(null==t?B:function(t){return function(){return q.call(this.children,t)}}("function"==typeof t?t:I(t)))},selectChildren:function(t){return this.selectAll(null==t?X:function(t){return function(){return V.call(this.children,t)}}("function"==typeof t?t:I(t)))},filter:function(t){"function"!=typeof t&&(t=R(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i<n;++i)for(var a,o=e[i],s=o.length,l=r[i]=[],u=0;u<s;++u)(a=o[u])&&t.call(a,a.__data__,u,o)&&l.push(a);return new Yt(r,this._parents)},data:function(t,e){if(!arguments.length)return Array.from(this,Q);var n=e?K:G,r=this._parents,i=this._groups;"function"!=typeof t&&(t=function(t){return function(){return t}}(t));for(var a=i.length,o=new Array(a),s=new Array(a),l=new Array(a),u=0;u<a;++u){var c=r[u],h=i[u],f=h.length,d=J(t.call(c,c&&c.__data__,u,r)),p=d.length,_=s[u]=new Array(p),g=o[u]=new Array(p);n(c,h,_,g,l[u]=new Array(f),d,e);for(var m,v,y=0,b=0;y<p;++y)if(m=_[y]){for(y>=b&&(b=y+1);!(v=g[b])&&++b<p;);m._next=v||null}}return(o=new Yt(o,r))._enter=s,o._exit=l,o},enter:function(){return new Yt(this._enter||this._groups.map(W),this._parents)},exit:function(){return new Yt(this._exit||this._groups.map(W),this._parents)},join:function(t,e,n){var r=this.enter(),i=this,a=this.exit();return"function"==typeof t?(r=t(r))&&(r=r.selection()):r=r.append(t+""),null!=e&&(i=e(i))&&(i=i.selection()),null==n?a.remove():n(a),r&&i?r.merge(i).order():i},merge:function(t){for(var e=t.selection?t.selection():t,n=this._groups,r=e._groups,i=n.length,a=r.length,o=Math.min(i,a),s=new Array(i),l=0;l<o;++l)for(var u,c=n[l],h=r[l],f=c.length,d=s[l]=new Array(f),p=0;p<f;++p)(u=c[p]||h[p])&&(d[p]=u);for(;l<i;++l)s[l]=n[l];return new Yt(s,this._parents)},selection:function(){return this},order:function(){for(var t=this._groups,e=-1,n=t.length;++e<n;)for(var r,i=t[e],a=i.length-1,o=i[a];--a>=0;)(r=i[a])&&(o&&4^r.compareDocumentPosition(o)&&o.parentNode.insertBefore(r,o),o=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=tt);for(var n=this._groups,r=n.length,i=new Array(r),a=0;a<r;++a){for(var o,s=n[a],l=s.length,u=i[a]=new Array(l),c=0;c<l;++c)(o=s[c])&&(u[c]=o);u.sort(e)}return new Yt(i,this._parents).order()},call:function(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this},nodes:function(){return Array.from(this)},node:function(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var r=t[e],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null},size:function(){let t=0;for(const e of this)++t;return t},empty:function(){return!this.node()},each:function(t){for(var e=this._groups,n=0,r=e.length;n<r;++n)for(var i,a=e[n],o=0,s=a.length;o<s;++o)(i=a[o])&&t.call(i,i.__data__,o,a);return this},attr:function(t,e){var n=D(t);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((null==e?n.local?nt:et:"function"==typeof e?n.local?ot:at:n.local?it:rt)(n,e))},style:function(t,e,n){return arguments.length>1?this.each((null==e?lt:"function"==typeof e?ct:ut)(t,e,null==n?"":n)):ht(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?ft:"function"==typeof e?pt:dt)(t,e)):this.node()[t]},classed:function(t,e){var n=_t(t+"");if(arguments.length<2){for(var r=gt(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each(("function"==typeof e?xt:e?bt:wt)(n,e))},text:function(t){return arguments.length?this.each(null==t?Mt:("function"==typeof t?Nt:kt)(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?Tt:("function"==typeof t?zt:At)(t)):this.node().innerHTML},raise:function(){return this.each(St)},lower:function(){return this.each(Et)},append:function(t){var e="function"==typeof t?t:P(t);return this.select(function(){return this.appendChild(e.apply(this,arguments))})},insert:function(t,e){var n="function"==typeof t?t:P(t),r=null==e?Ct:"function"==typeof e?e:O(e);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})},remove:function(){return this.each($t)},clone:function(t){return this.select(t?Lt:Dt)},datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__},on:function(t,e,n){var r,i,a=function(t){return t.trim().split(/^|\s+/).map(function(t){var e="",n=t.indexOf(".");return n>=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}})}(t+""),o=a.length;if(!(arguments.length<2)){for(s=e?Pt:Ut,r=0;r<o;++r)this.each(s(a[r],e,n));return this}var s=this.node().__on;if(s)for(var l,u=0,c=s.length;u<c;++u)for(r=0,l=s[u];r<o;++r)if((i=a[r]).type===l.type&&i.name===l.name)return l.value},dispatch:function(t,e){return this.each(("function"==typeof e?jt:Ot)(t,e))},[Symbol.iterator]:function*(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var r,i=t[e],a=0,o=i.length;a<o;++a)(r=i[a])&&(yield r)}};const Bt={capture:!0,passive:!1};function Vt(t){t.preventDefault(),t.stopImmediatePropagation()}function Xt(t){var e=t.document.documentElement,n=It(t).on("dragstart.drag",Vt,Bt);"onselectstart"in e?n.on("selectstart.drag",Vt,Bt):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function Wt(t,e){var n=t.document.documentElement,r=It(t).on("dragstart.drag",null);e&&(r.on("click.drag",Vt,Bt),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}function Zt(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function Gt(t,e){var n=Object.create(t.prototype);for(var r in e)n[r]=e[r];return n}function Kt(){}var Qt=.7,Jt=1/Qt,te="\\s*([+-]?\\d+)\\s*",ee="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",ne="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",re=/^#([0-9a-f]{3,8})$/,ie=new RegExp(`^rgb\\(${te},${te},${te}\\)$`),ae=new RegExp(`^rgb\\(${ne},${ne},${ne}\\)$`),oe=new RegExp(`^rgba\\(${te},${te},${te},${ee}\\)$`),se=new RegExp(`^rgba\\(${ne},${ne},${ne},${ee}\\)$`),le=new RegExp(`^hsl\\(${ee},${ne},${ne}\\)$`),ue=new RegExp(`^hsla\\(${ee},${ne},${ne},${ee}\\)$`),ce={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function he(){return this.rgb().formatHex()}function fe(){return this.rgb().formatRgb()}function de(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=re.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?pe(e):3===n?new me(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?_e(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?_e(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=ie.exec(t))?new me(e[1],e[2],e[3],1):(e=ae.exec(t))?new me(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=oe.exec(t))?_e(e[1],e[2],e[3],e[4]):(e=se.exec(t))?_e(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=le.exec(t))?Me(e[1],e[2]/100,e[3]/100,1):(e=ue.exec(t))?Me(e[1],e[2]/100,e[3]/100,e[4]):ce.hasOwnProperty(t)?pe(ce[t]):"transparent"===t?new me(NaN,NaN,NaN,0):null}function pe(t){return new me(t>>16&255,t>>8&255,255&t,1)}function _e(t,e,n,r){return r<=0&&(t=e=n=NaN),new me(t,e,n,r)}function ge(t,e,n,r){return 1===arguments.length?((i=t)instanceof Kt||(i=de(i)),i?new me((i=i.rgb()).r,i.g,i.b,i.opacity):new me):new me(t,e,n,null==r?1:r);var i}function me(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function ve(){return`#${xe(this.r)}${xe(this.g)}${xe(this.b)}`}function ye(){const t=be(this.opacity);return`${1===t?"rgb(":"rgba("}${we(this.r)}, ${we(this.g)}, ${we(this.b)}${1===t?")":`, ${t})`}`}function be(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function we(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function xe(t){return((t=we(t))<16?"0":"")+t.toString(16)}function Me(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Ne(t,e,n,r)}function ke(t){if(t instanceof Ne)return new Ne(t.h,t.s,t.l,t.opacity);if(t instanceof Kt||(t=de(t)),!t)return new Ne;if(t instanceof Ne)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),o=NaN,s=a-i,l=(a+i)/2;return s?(o=e===a?(n-r)/s+6*(n<r):n===a?(r-e)/s+2:(e-n)/s+4,s/=l<.5?a+i:2-a-i,o*=60):s=l>0&&l<1?0:o,new Ne(o,s,l,t.opacity)}function Ne(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function Te(t){return(t=(t||0)%360)<0?t+360:t}function Ae(t){return Math.max(0,Math.min(1,t||0))}function ze(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}Zt(Kt,de,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:he,formatHex:he,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return ke(this).formatHsl()},formatRgb:fe,toString:fe}),Zt(me,ge,Gt(Kt,{brighter(t){return t=null==t?Jt:Math.pow(Jt,t),new me(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Qt:Math.pow(Qt,t),new me(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new me(we(this.r),we(this.g),we(this.b),be(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:ve,formatHex:ve,formatHex8:function(){return`#${xe(this.r)}${xe(this.g)}${xe(this.b)}${xe(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:ye,toString:ye})),Zt(Ne,function(t,e,n,r){return 1===arguments.length?ke(t):new Ne(t,e,n,null==r?1:r)},Gt(Kt,{brighter(t){return t=null==t?Jt:Math.pow(Jt,t),new Ne(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Qt:Math.pow(Qt,t),new Ne(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new me(ze(t>=240?t-240:t+120,i,r),ze(t,i,r),ze(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new Ne(Te(this.h),Ae(this.s),Ae(this.l),be(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=be(this.opacity);return`${1===t?"hsl(":"hsla("}${Te(this.h)}, ${100*Ae(this.s)}%, ${100*Ae(this.l)}%${1===t?")":`, ${t})`}`}}));var Se=t=>()=>t;function Ee(t){return 1===(t=+t)?Ce:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):Se(isNaN(e)?n:e)}}function Ce(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):Se(isNaN(t)?e:t)}var $e=function t(e){var n=Ee(e);function r(t,e){var r=n((t=ge(t)).r,(e=ge(e)).r),i=n(t.g,e.g),a=n(t.b,e.b),o=Ce(t.opacity,e.opacity);return function(e){return t.r=r(e),t.g=i(e),t.b=a(e),t.opacity=o(e),t+""}}return r.gamma=t,r}(1);function De(t,e){e||(e=[]);var n,r=t?Math.min(e.length,t.length):0,i=e.slice();return function(a){for(n=0;n<r;++n)i[n]=t[n]*(1-a)+e[n]*a;return i}}function Le(t,e){var n,r=e?e.length:0,i=t?Math.min(r,t.length):0,a=new Array(i),o=new Array(r);for(n=0;n<i;++n)a[n]=Ye(t[n],e[n]);for(;n<r;++n)o[n]=e[n];return function(t){for(n=0;n<i;++n)o[n]=a[n](t);return o}}function Ue(t,e){var n=new Date;return t=+t,e=+e,function(r){return n.setTime(t*(1-r)+e*r),n}}function Pe(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}function He(t,e){var n,r={},i={};for(n in null!==t&&"object"==typeof t||(t={}),null!==e&&"object"==typeof e||(e={}),e)n in t?r[n]=Ye(t[n],e[n]):i[n]=e[n];return function(t){for(n in r)i[n]=r[n](t);return i}}var Oe=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,je=new RegExp(Oe.source,"g");function Fe(t,e){var n,r,i,a=Oe.lastIndex=je.lastIndex=0,o=-1,s=[],l=[];for(t+="",e+="";(n=Oe.exec(t))&&(r=je.exec(e));)(i=r.index)>a&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(n=n[0])===(r=r[0])?s[o]?s[o]+=r:s[++o]=r:(s[++o]=null,l.push({i:o,x:Pe(n,r)})),a=je.lastIndex;return a<e.length&&(i=e.slice(a),s[o]?s[o]+=i:s[++o]=i),s.length<2?l[0]?function(t){return function(e){return t(e)+""}}(l[0].x):function(t){return function(){return t}}(e):(e=l.length,function(t){for(var n,r=0;r<e;++r)s[(n=l[r]).i]=n.x(t);return s.join("")})}function Ye(t,e){var n,r=typeof e;return null==e||"boolean"===r?Se(e):("number"===r?Pe:"string"===r?(n=de(e))?(e=n,$e):Fe:e instanceof de?$e:e instanceof Date?Ue:function(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}(e)?De:Array.isArray(e)?Le:"function"!=typeof e.valueOf&&"function"!=typeof e.toString||isNaN(e)?He:Pe)(t,e)}function Re(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}var Ie,qe=180/Math.PI,Be={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Ve(t,e,n,r,i,a){var o,s,l;return(o=Math.sqrt(t*t+e*e))&&(t/=o,e/=o),(l=t*n+e*r)&&(n-=t*l,r-=e*l),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,l/=s),t*r<e*n&&(t=-t,e=-e,l=-l,o=-o),{translateX:i,translateY:a,rotate:Math.atan2(e,t)*qe,skewX:Math.atan(l)*qe,scaleX:o,scaleY:s}}function Xe(t,e,n,r){function i(t){return t.length?t.pop()+" ":""}return function(a,o){var s=[],l=[];return a=t(a),o=t(o),function(t,r,i,a,o,s){if(t!==i||r!==a){var l=o.push("translate(",null,e,null,n);s.push({i:l-4,x:Pe(t,i)},{i:l-2,x:Pe(r,a)})}else(i||a)&&o.push("translate("+i+e+a+n)}(a.translateX,a.translateY,o.translateX,o.translateY,s,l),function(t,e,n,a){t!==e?(t-e>180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(i(n)+"rotate(",null,r)-2,x:Pe(t,e)})):e&&n.push(i(n)+"rotate("+e+r)}(a.rotate,o.rotate,s,l),function(t,e,n,a){t!==e?a.push({i:n.push(i(n)+"skewX(",null,r)-2,x:Pe(t,e)}):e&&n.push(i(n)+"skewX("+e+r)}(a.skewX,o.skewX,s,l),function(t,e,n,r,a,o){if(t!==n||e!==r){var s=a.push(i(a)+"scale(",null,",",null,")");o.push({i:s-4,x:Pe(t,n)},{i:s-2,x:Pe(e,r)})}else 1===n&&1===r||a.push(i(a)+"scale("+n+","+r+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,l),a=o=null,function(t){for(var e,n=-1,r=l.length;++n<r;)s[(e=l[n]).i]=e.x(t);return s.join("")}}}var We=Xe(function(t){const e=new("function"==typeof DOMMatrix?DOMMatrix:WebKitCSSMatrix)(t+"");return e.isIdentity?Be:Ve(e.a,e.b,e.c,e.d,e.e,e.f)},"px, ","px)","deg)"),Ze=Xe(function(t){return null==t?Be:(Ie||(Ie=document.createElementNS("http://www.w3.org/2000/svg","g")),Ie.setAttribute("transform",t),(t=Ie.transform.baseVal.consolidate())?Ve((t=t.matrix).a,t.b,t.c,t.d,t.e,t.f):Be)},", ",")",")");function Ge(t){return((t=Math.exp(t))+1/t)/2}var Ke,Qe,Je=function t(e,n,r){function i(t,i){var a,o,s=t[0],l=t[1],u=t[2],c=i[0],h=i[1],f=i[2],d=c-s,p=h-l,_=d*d+p*p;if(_<1e-12)o=Math.log(f/u)/e,a=function(t){return[s+t*d,l+t*p,u*Math.exp(e*t*o)]};else{var g=Math.sqrt(_),m=(f*f-u*u+r*_)/(2*u*n*g),v=(f*f-u*u-r*_)/(2*f*n*g),y=Math.log(Math.sqrt(m*m+1)-m),b=Math.log(Math.sqrt(v*v+1)-v);o=(b-y)/e,a=function(t){var r=t*o,i=Ge(y),a=u/(n*g)*(i*function(t){return((t=Math.exp(2*t))-1)/(t+1)}(e*r+y)-function(t){return((t=Math.exp(t))-1/t)/2}(y));return[s+a*d,l+a*p,u*i/Ge(e*r+y)]}}return a.duration=1e3*o*e/Math.SQRT2,a}return i.rho=function(e){var n=Math.max(.001,+e),r=n*n;return t(n,r,r*r)},i}(Math.SQRT2,2,4),tn=0,en=0,nn=0,rn=0,an=0,on=0,sn="object"==typeof performance&&performance.now?performance:Date,ln="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function un(){return an||(ln(cn),an=sn.now()+on)}function cn(){an=0}function hn(){this._call=this._time=this._next=null}function fn(t,e,n){var r=new hn;return r.restart(t,e,n),r}function dn(){an=(rn=sn.now())+on,tn=en=0;try{!function(){un(),++tn;for(var t,e=Ke;e;)(t=an-e._time)>=0&&e._call.call(void 0,t),e=e._next;--tn}()}finally{tn=0,function(){var t,e,n=Ke,r=1/0;for(;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:Ke=e);Qe=t,_n(r)}(),an=0}}function pn(){var t=sn.now(),e=t-rn;e>1e3&&(on-=e,rn=t)}function _n(t){tn||(en&&(en=clearTimeout(en)),t-an>24?(t<1/0&&(en=setTimeout(dn,t-sn.now()-on)),nn&&(nn=clearInterval(nn))):(nn||(rn=sn.now(),nn=setInterval(pn,1e3)),tn=1,ln(dn)))}function gn(t,e,n){var r=new hn;return e=null==e?0:+e,r.restart(n=>{r.stop(),t(n+e)},e,n),r}hn.prototype=fn.prototype={constructor:hn,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?un():+n)+(null==e?0:+e),this._next||Qe===this||(Qe?Qe._next=this:Ke=this,Qe=this),this._call=t,this._time=n,_n()},stop:function(){this._call&&(this._call=null,this._time=1/0,_n())}};var mn=A("start","end","cancel","interrupt"),vn=[];function yn(t,e,n,r,i,a){var o=t.__transition;if(o){if(n in o)return}else t.__transition={};!function(t,e,n){var r,i=t.__transition;function a(t){n.state=1,n.timer.restart(o,n.delay,n.time),n.delay<=t&&o(t-n.delay)}function o(a){var u,c,h,f;if(1!==n.state)return l();for(u in i)if((f=i[u]).name===n.name){if(3===f.state)return gn(o);4===f.state?(f.state=6,f.timer.stop(),f.on.call("interrupt",t,t.__data__,f.index,f.group),delete i[u]):+u<e&&(f.state=6,f.timer.stop(),f.on.call("cancel",t,t.__data__,f.index,f.group),delete i[u])}if(gn(function(){3===n.state&&(n.state=4,n.timer.restart(s,n.delay,n.time),s(a))}),n.state=2,n.on.call("start",t,t.__data__,n.index,n.group),2===n.state){for(n.state=3,r=new Array(h=n.tween.length),u=0,c=-1;u<h;++u)(f=n.tween[u].value.call(t,t.__data__,n.index,n.group))&&(r[++c]=f);r.length=c+1}}function s(e){for(var i=e<n.duration?n.ease.call(null,e/n.duration):(n.timer.restart(l),n.state=5,1),a=-1,o=r.length;++a<o;)r[a].call(t,i);5===n.state&&(n.on.call("end",t,t.__data__,n.index,n.group),l())}function l(){for(var r in n.state=6,n.timer.stop(),delete i[e],i)return;delete t.__transition}i[e]=n,n.timer=fn(a,0,n.time)}(t,n,{name:e,index:r,group:i,on:mn,tween:vn,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:0})}function bn(t,e){var n=xn(t,e);if(n.state>0)throw new Error("too late; already scheduled");return n}function wn(t,e){var n=xn(t,e);if(n.state>3)throw new Error("too late; already running");return n}function xn(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function Mn(t,e){var n,r,i,a=t.__transition,o=!0;if(a){for(i in e=null==e?null:e+"",a)(n=a[i]).name===e?(r=n.state>2&&n.state<5,n.state=6,n.timer.stop(),n.on.call(r?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete a[i]):o=!1;o&&delete t.__transition}}function kn(t,e){var n,r;return function(){var i=wn(this,t),a=i.tween;if(a!==n)for(var o=0,s=(r=n=a).length;o<s;++o)if(r[o].name===e){(r=r.slice()).splice(o,1);break}i.tween=r}}function Nn(t,e,n){var r,i;if("function"!=typeof n)throw new Error;return function(){var a=wn(this,t),o=a.tween;if(o!==r){i=(r=o).slice();for(var s={name:e,value:n},l=0,u=i.length;l<u;++l)if(i[l].name===e){i[l]=s;break}l===u&&i.push(s)}a.tween=i}}function Tn(t,e,n){var r=t._id;return t.each(function(){var t=wn(this,r);(t.value||(t.value={}))[e]=n.apply(this,arguments)}),function(t){return xn(t,r).value[e]}}function An(t,e){var n;return("number"==typeof e?Pe:e instanceof de?$e:(n=de(e))?(e=n,$e):Fe)(t,e)}function zn(t){return function(){this.removeAttribute(t)}}function Sn(t){return function(){this.removeAttributeNS(t.space,t.local)}}function En(t,e,n){var r,i,a=n+"";return function(){var o=this.getAttribute(t);return o===a?null:o===r?i:i=e(r=o,n)}}function Cn(t,e,n){var r,i,a=n+"";return function(){var o=this.getAttributeNS(t.space,t.local);return o===a?null:o===r?i:i=e(r=o,n)}}function $n(t,e,n){var r,i,a;return function(){var o,s,l=n(this);if(null!=l)return(o=this.getAttribute(t))===(s=l+"")?null:o===r&&s===i?a:(i=s,a=e(r=o,l));this.removeAttribute(t)}}function Dn(t,e,n){var r,i,a;return function(){var o,s,l=n(this);if(null!=l)return(o=this.getAttributeNS(t.space,t.local))===(s=l+"")?null:o===r&&s===i?a:(i=s,a=e(r=o,l));this.removeAttributeNS(t.space,t.local)}}function Ln(t,e){var n,r;function i(){var i=e.apply(this,arguments);return i!==r&&(n=(r=i)&&function(t,e){return function(n){this.setAttributeNS(t.space,t.local,e.call(this,n))}}(t,i)),n}return i._value=e,i}function Un(t,e){var n,r;function i(){var i=e.apply(this,arguments);return i!==r&&(n=(r=i)&&function(t,e){return function(n){this.setAttribute(t,e.call(this,n))}}(t,i)),n}return i._value=e,i}function Pn(t,e){return function(){bn(this,t).delay=+e.apply(this,arguments)}}function Hn(t,e){return e=+e,function(){bn(this,t).delay=e}}function On(t,e){return function(){wn(this,t).duration=+e.apply(this,arguments)}}function jn(t,e){return e=+e,function(){wn(this,t).duration=e}}var Fn=Rt.prototype.constructor;function Yn(t){return function(){this.style.removeProperty(t)}}var Rn=0;function In(t,e,n,r){this._groups=t,this._parents=e,this._name=n,this._id=r}function qn(){return++Rn}var Bn=Rt.prototype;In.prototype={constructor:In,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=O(t));for(var r=this._groups,i=r.length,a=new Array(i),o=0;o<i;++o)for(var s,l,u=r[o],c=u.length,h=a[o]=new Array(c),f=0;f<c;++f)(s=u[f])&&(l=t.call(s,s.__data__,f,u))&&("__data__"in s&&(l.__data__=s.__data__),h[f]=l,yn(h[f],e,n,f,h,xn(s,n)));return new In(a,this._parents,e,n)},selectAll:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=F(t));for(var r=this._groups,i=r.length,a=[],o=[],s=0;s<i;++s)for(var l,u=r[s],c=u.length,h=0;h<c;++h)if(l=u[h]){for(var f,d=t.call(l,l.__data__,h,u),p=xn(l,n),_=0,g=d.length;_<g;++_)(f=d[_])&&yn(f,e,n,_,d,p);a.push(d),o.push(l)}return new In(a,o,e,n)},selectChild:Bn.selectChild,selectChildren:Bn.selectChildren,filter:function(t){"function"!=typeof t&&(t=R(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i<n;++i)for(var a,o=e[i],s=o.length,l=r[i]=[],u=0;u<s;++u)(a=o[u])&&t.call(a,a.__data__,u,o)&&l.push(a);return new In(r,this._parents,this._name,this._id)},merge:function(t){if(t._id!==this._id)throw new Error;for(var e=this._groups,n=t._groups,r=e.length,i=n.length,a=Math.min(r,i),o=new Array(r),s=0;s<a;++s)for(var l,u=e[s],c=n[s],h=u.length,f=o[s]=new Array(h),d=0;d<h;++d)(l=u[d]||c[d])&&(f[d]=l);for(;s<r;++s)o[s]=e[s];return new In(o,this._parents,this._name,this._id)},selection:function(){return new Fn(this._groups,this._parents)},transition:function(){for(var t=this._name,e=this._id,n=qn(),r=this._groups,i=r.length,a=0;a<i;++a)for(var o,s=r[a],l=s.length,u=0;u<l;++u)if(o=s[u]){var c=xn(o,e);yn(o,t,n,u,s,{time:c.time+c.delay+c.duration,delay:0,duration:c.duration,ease:c.ease})}return new In(r,this._parents,t,n)},call:Bn.call,nodes:Bn.nodes,node:Bn.node,size:Bn.size,empty:Bn.empty,each:Bn.each,on:function(t,e){var n=this._id;return arguments.length<2?xn(this.node(),n).on.on(t):this.each(function(t,e,n){var r,i,a=function(t){return(t+"").trim().split(/^|\s+/).every(function(t){var e=t.indexOf(".");return e>=0&&(t=t.slice(0,e)),!t||"start"===t})}(e)?bn:wn;return function(){var o=a(this,t),s=o.on;s!==r&&(i=(r=s).copy()).on(e,n),o.on=i}}(n,t,e))},attr:function(t,e){var n=D(t),r="transform"===n?Ze:An;return this.attrTween(t,"function"==typeof e?(n.local?Dn:$n)(n,r,Tn(this,"attr."+t,e)):null==e?(n.local?Sn:zn)(n):(n.local?Cn:En)(n,r,e))},attrTween:function(t,e){var n="attr."+t;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;var r=D(t);return this.tween(n,(r.local?Ln:Un)(r,e))},style:function(t,e,n){var r="transform"==(t+="")?We:An;return null==e?this.styleTween(t,function(t,e){var n,r,i;return function(){var a=ht(this,t),o=(this.style.removeProperty(t),ht(this,t));return a===o?null:a===n&&o===r?i:i=e(n=a,r=o)}}(t,r)).on("end.style."+t,Yn(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var r,i,a;return function(){var o=ht(this,t),s=n(this),l=s+"";return null==s&&(this.style.removeProperty(t),l=s=ht(this,t)),o===l?null:o===r&&l===i?a:(i=l,a=e(r=o,s))}}(t,r,Tn(this,"style."+t,e))).each(function(t,e){var n,r,i,a,o="style."+e,s="end."+o;return function(){var l=wn(this,t),u=l.on,c=null==l.value[o]?a||(a=Yn(e)):void 0;u===n&&i===c||(r=(n=u).copy()).on(s,i=c),l.on=r}}(this._id,t)):this.styleTween(t,function(t,e,n){var r,i,a=n+"";return function(){var o=ht(this,t);return o===a?null:o===r?i:i=e(r=o,n)}}(t,r,e),n).on("end.style."+t,null)},styleTween:function(t,e,n){var r="style."+(t+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==e)return this.tween(r,null);if("function"!=typeof e)throw new Error;return this.tween(r,function(t,e,n){var r,i;function a(){var a=e.apply(this,arguments);return a!==i&&(r=(i=a)&&function(t,e,n){return function(r){this.style.setProperty(t,e.call(this,r),n)}}(t,a,n)),r}return a._value=e,a}(t,e,null==n?"":n))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var e=t(this);this.textContent=null==e?"":e}}(Tn(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(null==t)return this.tween(e,null);if("function"!=typeof t)throw new Error;return this.tween(e,function(t){var e,n;function r(){var r=t.apply(this,arguments);return r!==n&&(e=(n=r)&&function(t){return function(e){this.textContent=t.call(this,e)}}(r)),e}return r._value=t,r}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var e=this.parentNode;for(var n in this.__transition)if(+n!==t)return;e&&e.removeChild(this)}}(this._id))},tween:function(t,e){var n=this._id;if(t+="",arguments.length<2){for(var r,i=xn(this.node(),n).tween,a=0,o=i.length;a<o;++a)if((r=i[a]).name===t)return r.value;return null}return this.each((null==e?kn:Nn)(n,t,e))},delay:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?Pn:Hn)(e,t)):xn(this.node(),e).delay},duration:function(t){var e=this._id;return arguments.length?this.each(("function"==typeof t?On:jn)(e,t)):xn(this.node(),e).duration},ease:function(t){var e=this._id;return arguments.length?this.each(function(t,e){if("function"!=typeof e)throw new Error;return function(){wn(this,t).ease=e}}(e,t)):xn(this.node(),e).ease},easeVarying:function(t){if("function"!=typeof t)throw new Error;return this.each(function(t,e){return function(){var n=e.apply(this,arguments);if("function"!=typeof n)throw new Error;wn(this,t).ease=n}}(this._id,t))},end:function(){var t,e,n=this,r=n._id,i=n.size();return new Promise(function(a,o){var s={value:o},l={value:function(){0===--i&&a()}};n.each(function(){var n=wn(this,r),i=n.on;i!==t&&((e=(t=i).copy())._.cancel.push(s),e._.interrupt.push(s),e._.end.push(l)),n.on=e}),0===i&&a()})},[Symbol.iterator]:Bn[Symbol.iterator]};var Vn={time:null,delay:0,duration:250,ease:function(t){return((t*=2)<=1?t*t*t:(t-=2)*t*t+2)/2}};function Xn(t,e){for(var n;!(n=t.__transition)||!(n=n[e]);)if(!(t=t.parentNode))throw new Error(`transition ${e} not found`);return n}Rt.prototype.interrupt=function(t){return this.each(function(){Mn(this,t)})},Rt.prototype.transition=function(t){var e,n;t instanceof In?(e=t._id,t=t._name):(e=qn(),(n=Vn).time=un(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,a=0;a<i;++a)for(var o,s=r[a],l=s.length,u=0;u<l;++u)(o=s[u])&&yn(o,t,e,u,s,n||Xn(o,e));return new In(r,this._parents,t,e)};var Wn=t=>()=>t;function Zn(t,{sourceEvent:e,target:n,selection:r,mode:i,dispatch:a}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},selection:{value:r,enumerable:!0,configurable:!0},mode:{value:i,enumerable:!0,configurable:!0},_:{value:a}})}function Gn(t){t.preventDefault(),t.stopImmediatePropagation()}var Kn={name:"drag"},Qn={name:"space"},Jn={name:"handle"},tr={name:"center"};const{abs:er,max:nr,min:rr}=Math;function ir(t){return[+t[0],+t[1]]}function ar(t){return[ir(t[0]),ir(t[1])]}var or={name:"x",handles:["w","e"].map(pr),input:function(t,e){return null==t?null:[[+t[0],e[0][1]],[+t[1],e[1][1]]]},output:function(t){return t&&[t[0][0],t[1][0]]}},sr={name:"y",handles:["n","s"].map(pr),input:function(t,e){return null==t?null:[[e[0][0],+t[0]],[e[1][0],+t[1]]]},output:function(t){return t&&[t[0][1],t[1][1]]}},lr={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(pr),input:function(t){return null==t?null:ar(t)},output:function(t){return t}},ur={overlay:"crosshair",selection:"move",n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},cr={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},hr={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},fr={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},dr={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function pr(t){return{type:t}}function _r(t){return!t.ctrlKey&&!t.button}function gr(){var t=this.ownerSVGElement||this;return t.hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]}function mr(){return navigator.maxTouchPoints||"ontouchstart"in this}function vr(t){for(;!t.__brush;)if(!(t=t.parentNode))return;return t.__brush}function yr(){return function(t){var e,n=gr,r=_r,i=mr,a=!0,o=A("start","brush","end"),s=6;function l(e){var n=e.property("__brush",_).selectAll(".overlay").data([pr("overlay")]);n.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",ur.overlay).merge(n).each(function(){var t=vr(this).extent;It(this).attr("x",t[0][0]).attr("y",t[0][1]).attr("width",t[1][0]-t[0][0]).attr("height",t[1][1]-t[0][1])}),e.selectAll(".selection").data([pr("selection")]).enter().append("rect").attr("class","selection").attr("cursor",ur.selection).attr("fill","#777").attr("fill-opacity",.3).attr("stroke","#fff").attr("shape-rendering","crispEdges");var r=e.selectAll(".handle").data(t.handles,function(t){return t.type});r.exit().remove(),r.enter().append("rect").attr("class",function(t){return"handle handle--"+t.type}).attr("cursor",function(t){return ur[t.type]}),e.each(u).attr("fill","none").attr("pointer-events","all").on("mousedown.brush",f).filter(i).on("touchstart.brush",f).on("touchmove.brush",d).on("touchend.brush touchcancel.brush",p).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function u(){var t=It(this),e=vr(this).selection;e?(t.selectAll(".selection").style("display",null).attr("x",e[0][0]).attr("y",e[0][1]).attr("width",e[1][0]-e[0][0]).attr("height",e[1][1]-e[0][1]),t.selectAll(".handle").style("display",null).attr("x",function(t){return"e"===t.type[t.type.length-1]?e[1][0]-s/2:e[0][0]-s/2}).attr("y",function(t){return"s"===t.type[0]?e[1][1]-s/2:e[0][1]-s/2}).attr("width",function(t){return"n"===t.type||"s"===t.type?e[1][0]-e[0][0]+s:s}).attr("height",function(t){return"e"===t.type||"w"===t.type?e[1][1]-e[0][1]+s:s})):t.selectAll(".selection,.handle").style("display","none").attr("x",null).attr("y",null).attr("width",null).attr("height",null)}function c(t,e,n){var r=t.__brush.emitter;return!r||n&&r.clean?new h(t,e,n):r}function h(t,e,n){this.that=t,this.args=e,this.state=t.__brush,this.active=0,this.clean=n}function f(n){if((!e||n.touches)&&r.apply(this,arguments)){var i,o,s,l,h,f,d,p,_,g,m,v=this,y=n.target.__data__.type,b="selection"===(a&&n.metaKey?y="overlay":y)?Kn:a&&n.altKey?tr:Jn,w=t===sr?null:fr[y],x=t===or?null:dr[y],M=vr(v),k=M.extent,N=M.selection,T=k[0][0],A=k[0][1],z=k[1][0],S=k[1][1],E=0,C=0,$=w&&x&&a&&n.shiftKey,D=Array.from(n.touches||[n],t=>{const e=t.identifier;return(t=qt(t,v)).point0=t.slice(),t.identifier=e,t});Mn(v);var L=c(v,arguments,!0).beforestart();if("overlay"===y){N&&(_=!0);const e=[D[0],D[1]||D[0]];M.selection=N=[[i=t===sr?T:rr(e[0][0],e[1][0]),s=t===or?A:rr(e[0][1],e[1][1])],[h=t===sr?z:nr(e[0][0],e[1][0]),d=t===or?S:nr(e[0][1],e[1][1])]],D.length>1&&j(n)}else i=N[0][0],s=N[0][1],h=N[1][0],d=N[1][1];o=i,l=s,f=h,p=d;var U=It(v).attr("pointer-events","none"),P=U.selectAll(".overlay").attr("cursor",ur[y]);if(n.touches)L.moved=O,L.ended=F;else{var H=It(n.view).on("mousemove.brush",O,!0).on("mouseup.brush",F,!0);a&&H.on("keydown.brush",Y,!0).on("keyup.brush",R,!0),Xt(n.view)}u.call(v),L.start(n,b.name)}function O(t){for(const e of t.changedTouches||[t])for(const t of D)t.identifier===e.identifier&&(t.cur=qt(e,v));if($&&!g&&!m&&1===D.length){const t=D[0];er(t.cur[0]-t[0])>er(t.cur[1]-t[1])?m=!0:g=!0}for(const t of D)t.cur&&(t[0]=t.cur[0],t[1]=t.cur[1]);_=!0,Gn(t),j(t)}function j(t){const e=D[0],n=e.point0;var r;switch(E=e[0]-n[0],C=e[1]-n[1],b){case Qn:case Kn:w&&(E=nr(T-i,rr(z-h,E)),o=i+E,f=h+E),x&&(C=nr(A-s,rr(S-d,C)),l=s+C,p=d+C);break;case Jn:D[1]?(w&&(o=nr(T,rr(z,D[0][0])),f=nr(T,rr(z,D[1][0])),w=1),x&&(l=nr(A,rr(S,D[0][1])),p=nr(A,rr(S,D[1][1])),x=1)):(w<0?(E=nr(T-i,rr(z-i,E)),o=i+E,f=h):w>0&&(E=nr(T-h,rr(z-h,E)),o=i,f=h+E),x<0?(C=nr(A-s,rr(S-s,C)),l=s+C,p=d):x>0&&(C=nr(A-d,rr(S-d,C)),l=s,p=d+C));break;case tr:w&&(o=nr(T,rr(z,i-E*w)),f=nr(T,rr(z,h+E*w))),x&&(l=nr(A,rr(S,s-C*x)),p=nr(A,rr(S,d+C*x)))}f<o&&(w*=-1,r=i,i=h,h=r,r=o,o=f,f=r,y in cr&&P.attr("cursor",ur[y=cr[y]])),p<l&&(x*=-1,r=s,s=d,d=r,r=l,l=p,p=r,y in hr&&P.attr("cursor",ur[y=hr[y]])),M.selection&&(N=M.selection),g&&(o=N[0][0],f=N[1][0]),m&&(l=N[0][1],p=N[1][1]),N[0][0]===o&&N[0][1]===l&&N[1][0]===f&&N[1][1]===p||(M.selection=[[o,l],[f,p]],u.call(v),L.brush(t,b.name))}function F(t){if(function(t){t.stopImmediatePropagation()}(t),t.touches){if(t.touches.length)return;e&&clearTimeout(e),e=setTimeout(function(){e=null},500)}else Wt(t.view,_),H.on("keydown.brush keyup.brush mousemove.brush mouseup.brush",null);U.attr("pointer-events","all"),P.attr("cursor",ur.overlay),M.selection&&(N=M.selection),function(t){return t[0][0]===t[1][0]||t[0][1]===t[1][1]}(N)&&(M.selection=null,u.call(v)),L.end(t,b.name)}function Y(t){switch(t.keyCode){case 16:$=w&&x;break;case 18:b===Jn&&(w&&(h=f-E*w,i=o+E*w),x&&(d=p-C*x,s=l+C*x),b=tr,j(t));break;case 32:b!==Jn&&b!==tr||(w<0?h=f-E:w>0&&(i=o-E),x<0?d=p-C:x>0&&(s=l-C),b=Qn,P.attr("cursor",ur.selection),j(t));break;default:return}Gn(t)}function R(t){switch(t.keyCode){case 16:$&&(g=m=$=!1,j(t));break;case 18:b===tr&&(w<0?h=f:w>0&&(i=o),x<0?d=p:x>0&&(s=l),b=Jn,j(t));break;case 32:b===Qn&&(t.altKey?(w&&(h=f-E*w,i=o+E*w),x&&(d=p-C*x,s=l+C*x),b=tr):(w<0?h=f:w>0&&(i=o),x<0?d=p:x>0&&(s=l),b=Jn),P.attr("cursor",ur[y]),j(t));break;default:return}Gn(t)}}function