gridviz-smoothing 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +7 -0
- package/dist/gridviz-smoothing.js +34672 -0
- package/dist/gridviz-smoothing.min.js +1 -0
- package/package.json +58 -0
- package/src/KernelSmoothingOldStyle.js +221 -0
- package/src/KernelSmoothingStyle.js +115 -0
- package/src/KernelSmoothingWGLStyle.js +130 -0
- package/src/index.js +6 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.gviz_sm=n():t.gviz_sm=n()}(self,(()=>(()=>{"use strict";var t={d:(n,e)=>{for(var r in e)t.o(e,r)&&!t.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:e[r]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},n={};function e(){}function r(t){return null==t?e:function(){return this.querySelector(t)}}function i(){return[]}function o(t){return null==t?i:function(){return this.querySelectorAll(t)}}function a(t){return function(){return this.matches(t)}}function s(t){return function(n){return n.matches(t)}}t.r(n),t.d(n,{KernelSmoothingStyle:()=>fr});var u=Array.prototype.find;function c(){return this.firstElementChild}var l=Array.prototype.filter;function h(){return Array.from(this.children)}function f(t){return new Array(t.length)}function p(t,n){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=n}function d(t,n,e,r,i,o){for(var a,s=0,u=n.length,c=o.length;s<c;++s)(a=n[s])?(a.__data__=o[s],r[s]=a):e[s]=new p(t,o[s]);for(;s<u;++s)(a=n[s])&&(i[s]=a)}function m(t,n,e,r,i,o,a){var s,u,c,l=new Map,h=n.length,f=o.length,d=new Array(h);for(s=0;s<h;++s)(u=n[s])&&(d[s]=c=a.call(u,u.__data__,s,n)+"",l.has(c)?i[s]=u:l.set(c,u));for(s=0;s<f;++s)c=a.call(t,o[s],s,o)+"",(u=l.get(c))?(r[s]=u,u.__data__=o[s],l.delete(c)):e[s]=new p(t,o[s]);for(s=0;s<h;++s)(u=n[s])&&l.get(d[s])===u&&(i[s]=u)}function v(t){return t.__data__}function y(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function g(t,n){return t<n?-1:t>n?1:t>=n?0:NaN}p.prototype={constructor:p,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,n){return this._parent.insertBefore(t,n)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var w="http://www.w3.org/1999/xhtml";const _={svg:"http://www.w3.org/2000/svg",xhtml:w,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function x(t){var n=t+="",e=n.indexOf(":");return e>=0&&"xmlns"!==(n=t.slice(0,e))&&(t=t.slice(e+1)),_.hasOwnProperty(n)?{space:_[n],local:t}:t}function b(t){return function(){this.removeAttribute(t)}}function M(t){return function(){this.removeAttributeNS(t.space,t.local)}}function S(t,n){return function(){this.setAttribute(t,n)}}function k(t,n){return function(){this.setAttributeNS(t.space,t.local,n)}}function E(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttribute(t):this.setAttribute(t,e)}}function A(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,e)}}function N(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function z(t){return function(){this.style.removeProperty(t)}}function T(t,n,e){return function(){this.style.setProperty(t,n,e)}}function $(t,n,e){return function(){var r=n.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,e)}}function C(t,n){return t.style.getPropertyValue(n)||N(t).getComputedStyle(t,null).getPropertyValue(n)}function P(t){return function(){delete this[t]}}function Z(t,n){return function(){this[t]=n}}function j(t,n){return function(){var e=n.apply(this,arguments);null==e?delete this[t]:this[t]=e}}function O(t){return t.trim().split(/^|\s+/)}function X(t){return t.classList||new F(t)}function F(t){this._node=t,this._names=O(t.getAttribute("class")||"")}function Y(t,n){for(var e=X(t),r=-1,i=n.length;++r<i;)e.add(n[r])}function G(t,n){for(var e=X(t),r=-1,i=n.length;++r<i;)e.remove(n[r])}function R(t){return function(){Y(this,t)}}function q(t){return function(){G(this,t)}}function I(t,n){return function(){(n.apply(this,arguments)?Y:G)(this,t)}}function B(){this.textContent=""}function D(t){return function(){this.textContent=t}}function L(t){return function(){var n=t.apply(this,arguments);this.textContent=null==n?"":n}}function H(){this.innerHTML=""}function V(t){return function(){this.innerHTML=t}}function U(t){return function(){var n=t.apply(this,arguments);this.innerHTML=null==n?"":n}}function K(){this.nextSibling&&this.parentNode.appendChild(this)}function W(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Q(t){return function(){var n=this.ownerDocument,e=this.namespaceURI;return e===w&&n.documentElement.namespaceURI===w?n.createElement(t):n.createElementNS(e,t)}}function J(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function tt(t){var n=x(t);return(n.local?J:Q)(n)}function nt(){return null}function et(){var t=this.parentNode;t&&t.removeChild(this)}function rt(){var t=this.cloneNode(!1),n=this.parentNode;return n?n.insertBefore(t,this.nextSibling):t}function it(){var t=this.cloneNode(!0),n=this.parentNode;return n?n.insertBefore(t,this.nextSibling):t}function ot(t){return function(){var n=this.__on;if(n){for(var e,r=0,i=-1,o=n.length;r<o;++r)e=n[r],t.type&&e.type!==t.type||e.name!==t.name?n[++i]=e:this.removeEventListener(e.type,e.listener,e.options);++i?n.length=i:delete this.__on}}}function at(t,n,e){return function(){var r,i=this.__on,o=function(t){return function(n){t.call(this,n,this.__data__)}}(n);if(i)for(var a=0,s=i.length;a<s;++a)if((r=i[a]).type===t.type&&r.name===t.name)return this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=o,r.options=e),void(r.value=n);this.addEventListener(t.type,o,e),r={type:t.type,name:t.name,value:n,listener:o,options:e},i?i.push(r):this.__on=[r]}}function st(t,n,e){var r=N(t),i=r.CustomEvent;"function"==typeof i?i=new i(n,e):(i=r.document.createEvent("Event"),e?(i.initEvent(n,e.bubbles,e.cancelable),i.detail=e.detail):i.initEvent(n,!1,!1)),t.dispatchEvent(i)}function ut(t,n){return function(){return st(this,t,n)}}function ct(t,n){return function(){return st(this,t,n.apply(this,arguments))}}F.prototype={add:function(t){this._names.indexOf(t)<0&&(this._names.push(t),this._node.setAttribute("class",this._names.join(" ")))},remove:function(t){var n=this._names.indexOf(t);n>=0&&(this._names.splice(n,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var lt=[null];function ht(t,n){this._groups=t,this._parents=n}function ft(){return new ht([[document.documentElement]],lt)}ht.prototype=ft.prototype={constructor:ht,select:function(t){"function"!=typeof t&&(t=r(t));for(var n=this._groups,e=n.length,i=new Array(e),o=0;o<e;++o)for(var a,s,u=n[o],c=u.length,l=i[o]=new Array(c),h=0;h<c;++h)(a=u[h])&&(s=t.call(a,a.__data__,h,u))&&("__data__"in a&&(s.__data__=a.__data__),l[h]=s);return new ht(i,this._parents)},selectAll:function(t){t="function"==typeof t?function(t){return function(){return null==(n=t.apply(this,arguments))?[]:Array.isArray(n)?n:Array.from(n);var n}}(t):o(t);for(var n=this._groups,e=n.length,r=[],i=[],a=0;a<e;++a)for(var s,u=n[a],c=u.length,l=0;l<c;++l)(s=u[l])&&(r.push(t.call(s,s.__data__,l,u)),i.push(s));return new ht(r,i)},selectChild:function(t){return this.select(null==t?c:function(t){return function(){return u.call(this.children,t)}}("function"==typeof t?t:s(t)))},selectChildren:function(t){return this.selectAll(null==t?h:function(t){return function(){return l.call(this.children,t)}}("function"==typeof t?t:s(t)))},filter:function(t){"function"!=typeof t&&(t=a(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i<e;++i)for(var o,s=n[i],u=s.length,c=r[i]=[],l=0;l<u;++l)(o=s[l])&&t.call(o,o.__data__,l,s)&&c.push(o);return new ht(r,this._parents)},data:function(t,n){if(!arguments.length)return Array.from(this,v);var e,r=n?m:d,i=this._parents,o=this._groups;"function"!=typeof t&&(e=t,t=function(){return e});for(var a=o.length,s=new Array(a),u=new Array(a),c=new Array(a),l=0;l<a;++l){var h=i[l],f=o[l],p=f.length,g=y(t.call(h,h&&h.__data__,l,i)),w=g.length,_=u[l]=new Array(w),x=s[l]=new Array(w);r(h,f,_,x,c[l]=new Array(p),g,n);for(var b,M,S=0,k=0;S<w;++S)if(b=_[S]){for(S>=k&&(k=S+1);!(M=x[k])&&++k<w;);b._next=M||null}}return(s=new ht(s,i))._enter=u,s._exit=c,s},enter:function(){return new ht(this._enter||this._groups.map(f),this._parents)},exit:function(){return new ht(this._exit||this._groups.map(f),this._parents)},join:function(t,n,e){var r=this.enter(),i=this,o=this.exit();return"function"==typeof t?(r=t(r))&&(r=r.selection()):r=r.append(t+""),null!=n&&(i=n(i))&&(i=i.selection()),null==e?o.remove():e(o),r&&i?r.merge(i).order():i},merge:function(t){for(var n=t.selection?t.selection():t,e=this._groups,r=n._groups,i=e.length,o=r.length,a=Math.min(i,o),s=new Array(i),u=0;u<a;++u)for(var c,l=e[u],h=r[u],f=l.length,p=s[u]=new Array(f),d=0;d<f;++d)(c=l[d]||h[d])&&(p[d]=c);for(;u<i;++u)s[u]=e[u];return new ht(s,this._parents)},selection:function(){return this},order:function(){for(var t=this._groups,n=-1,e=t.length;++n<e;)for(var r,i=t[n],o=i.length-1,a=i[o];--o>=0;)(r=i[o])&&(a&&4^r.compareDocumentPosition(a)&&a.parentNode.insertBefore(r,a),a=r);return this},sort:function(t){function n(n,e){return n&&e?t(n.__data__,e.__data__):!n-!e}t||(t=g);for(var e=this._groups,r=e.length,i=new Array(r),o=0;o<r;++o){for(var a,s=e[o],u=s.length,c=i[o]=new Array(u),l=0;l<u;++l)(a=s[l])&&(c[l]=a);c.sort(n)}return new ht(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,n=0,e=t.length;n<e;++n)for(var r=t[n],i=0,o=r.length;i<o;++i){var a=r[i];if(a)return a}return null},size:function(){let t=0;for(const n of this)++t;return t},empty:function(){return!this.node()},each:function(t){for(var n=this._groups,e=0,r=n.length;e<r;++e)for(var i,o=n[e],a=0,s=o.length;a<s;++a)(i=o[a])&&t.call(i,i.__data__,a,o);return this},attr:function(t,n){var e=x(t);if(arguments.length<2){var r=this.node();return e.local?r.getAttributeNS(e.space,e.local):r.getAttribute(e)}return this.each((null==n?e.local?M:b:"function"==typeof n?e.local?A:E:e.local?k:S)(e,n))},style:function(t,n,e){return arguments.length>1?this.each((null==n?z:"function"==typeof n?$:T)(t,n,null==e?"":e)):C(this.node(),t)},property:function(t,n){return arguments.length>1?this.each((null==n?P:"function"==typeof n?j:Z)(t,n)):this.node()[t]},classed:function(t,n){var e=O(t+"");if(arguments.length<2){for(var r=X(this.node()),i=-1,o=e.length;++i<o;)if(!r.contains(e[i]))return!1;return!0}return this.each(("function"==typeof n?I:n?R:q)(e,n))},text:function(t){return arguments.length?this.each(null==t?B:("function"==typeof t?L:D)(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?H:("function"==typeof t?U:V)(t)):this.node().innerHTML},raise:function(){return this.each(K)},lower:function(){return this.each(W)},append:function(t){var n="function"==typeof t?t:tt(t);return this.select((function(){return this.appendChild(n.apply(this,arguments))}))},insert:function(t,n){var e="function"==typeof t?t:tt(t),i=null==n?nt:"function"==typeof n?n:r(n);return this.select((function(){return this.insertBefore(e.apply(this,arguments),i.apply(this,arguments)||null)}))},remove:function(){return this.each(et)},clone:function(t){return this.select(t?it:rt)},datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__},on:function(t,n,e){var r,i,o=function(t){return t.trim().split(/^|\s+/).map((function(t){var n="",e=t.indexOf(".");return e>=0&&(n=t.slice(e+1),t=t.slice(0,e)),{type:t,name:n}}))}(t+""),a=o.length;if(!(arguments.length<2)){for(s=n?at:ot,r=0;r<a;++r)this.each(s(o[r],n,e));return this}var s=this.node().__on;if(s)for(var u,c=0,l=s.length;c<l;++c)for(r=0,u=s[c];r<a;++r)if((i=o[r]).type===u.type&&i.name===u.name)return u.value},dispatch:function(t,n){return this.each(("function"==typeof n?ct:ut)(t,n))},[Symbol.iterator]:function*(){for(var t=this._groups,n=0,e=t.length;n<e;++n)for(var r,i=t[n],o=0,a=i.length;o<a;++o)(r=i[o])&&(yield r)}};const pt=ft;function dt(t){return"string"==typeof t?new ht([[document.querySelector(t)]],[document.documentElement]):new ht([[t]],lt)}var mt={value:()=>{}};function vt(){for(var t,n=0,e=arguments.length,r={};n<e;++n){if(!(t=arguments[n]+"")||t in r||/[\s.]/.test(t))throw new Error("illegal type: "+t);r[t]=[]}return new yt(r)}function yt(t){this._=t}function gt(t,n){for(var e,r=0,i=t.length;r<i;++r)if((e=t[r]).name===n)return e.value}function wt(t,n,e){for(var r=0,i=t.length;r<i;++r)if(t[r].name===n){t[r]=mt,t=t.slice(0,r).concat(t.slice(r+1));break}return null!=e&&t.push({name:n,value:e}),t}yt.prototype=vt.prototype={constructor:yt,on:function(t,n){var e,r,i=this._,o=(r=i,(t+"").trim().split(/^|\s+/).map((function(t){var n="",e=t.indexOf(".");if(e>=0&&(n=t.slice(e+1),t=t.slice(0,e)),t&&!r.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))),a=-1,s=o.length;if(!(arguments.length<2)){if(null!=n&&"function"!=typeof n)throw new Error("invalid callback: "+n);for(;++a<s;)if(e=(t=o[a]).type)i[e]=wt(i[e],t.name,n);else if(null==n)for(e in i)i[e]=wt(i[e],t.name,null);return this}for(;++a<s;)if((e=(t=o[a]).type)&&(e=gt(i[e],t.name)))return e},copy:function(){var t={},n=this._;for(var e in n)t[e]=n[e].slice();return new yt(t)},call:function(t,n){if((e=arguments.length-2)>0)for(var e,r,i=new Array(e),o=0;o<e;++o)i[o]=arguments[o+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(o=0,e=(r=this._[t]).length;o<e;++o)r[o].value.apply(n,i)},apply:function(t,n,e){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var r=this._[t],i=0,o=r.length;i<o;++i)r[i].value.apply(n,e)}};const _t=vt,xt={capture:!0,passive:!1};function bt(t){t.preventDefault(),t.stopImmediatePropagation()}function Mt(t){return((t=Math.exp(t))+1/t)/2}const St=function t(n,e,r){function i(t,i){var o,a,s=t[0],u=t[1],c=t[2],l=i[0],h=i[1],f=i[2],p=l-s,d=h-u,m=p*p+d*d;if(m<1e-12)a=Math.log(f/c)/n,o=function(t){return[s+t*p,u+t*d,c*Math.exp(n*t*a)]};else{var v=Math.sqrt(m),y=(f*f-c*c+r*m)/(2*c*e*v),g=(f*f-c*c-r*m)/(2*f*e*v),w=Math.log(Math.sqrt(y*y+1)-y),_=Math.log(Math.sqrt(g*g+1)-g);a=(_-w)/n,o=function(t){var r,i=t*a,o=Mt(w),l=c/(e*v)*(o*(r=n*i+w,((r=Math.exp(2*r))-1)/(r+1))-function(t){return((t=Math.exp(t))-1/t)/2}(w));return[s+l*p,u+l*d,c*o/Mt(n*i+w)]}}return o.duration=1e3*a*n/Math.SQRT2,o}return i.rho=function(n){var e=Math.max(.001,+n),r=e*e;return t(e,r,r*r)},i}(Math.SQRT2,2,4);function kt(t,n){if(t=function(t){let n;for(;n=t.sourceEvent;)t=n;return t}(t),void 0===n&&(n=t.currentTarget),n){var e=n.ownerSVGElement||n;if(e.createSVGPoint){var r=e.createSVGPoint();return r.x=t.clientX,r.y=t.clientY,[(r=r.matrixTransform(n.getScreenCTM().inverse())).x,r.y]}if(n.getBoundingClientRect){var i=n.getBoundingClientRect();return[t.clientX-i.left-n.clientLeft,t.clientY-i.top-n.clientTop]}}return[t.pageX,t.pageY]}var Et,At,Nt=0,zt=0,Tt=0,$t=1e3,Ct=0,Pt=0,Zt=0,jt="object"==typeof performance&&performance.now?performance:Date,Ot="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function Xt(){return Pt||(Ot(Ft),Pt=jt.now()+Zt)}function Ft(){Pt=0}function Yt(){this._call=this._time=this._next=null}function Gt(t,n,e){var r=new Yt;return r.restart(t,n,e),r}function Rt(){Pt=(Ct=jt.now())+Zt,Nt=zt=0;try{!function(){Xt(),++Nt;for(var t,n=Et;n;)(t=Pt-n._time)>=0&&n._call.call(void 0,t),n=n._next;--Nt}()}finally{Nt=0,function(){for(var t,n,e=Et,r=1/0;e;)e._call?(r>e._time&&(r=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:Et=n);At=t,It(r)}(),Pt=0}}function qt(){var t=jt.now(),n=t-Ct;n>$t&&(Zt-=n,Ct=t)}function It(t){Nt||(zt&&(zt=clearTimeout(zt)),t-Pt>24?(t<1/0&&(zt=setTimeout(Rt,t-jt.now()-Zt)),Tt&&(Tt=clearInterval(Tt))):(Tt||(Ct=jt.now(),Tt=setInterval(qt,$t)),Nt=1,Ot(Rt)))}function Bt(t,n,e){var r=new Yt;return n=null==n?0:+n,r.restart((e=>{r.stop(),t(e+n)}),n,e),r}Yt.prototype=Gt.prototype={constructor:Yt,restart:function(t,n,e){if("function"!=typeof t)throw new TypeError("callback is not a function");e=(null==e?Xt():+e)+(null==n?0:+n),this._next||At===this||(At?At._next=this:Et=this,At=this),this._call=t,this._time=e,It()},stop:function(){this._call&&(this._call=null,this._time=1/0,It())}};var Dt=_t("start","end","cancel","interrupt"),Lt=[],Ht=0,Vt=2,Ut=3,Kt=5,Wt=6;function Qt(t,n,e,r,i,o){var a=t.__transition;if(a){if(e in a)return}else t.__transition={};!function(t,n,e){var r,i=t.__transition;function o(u){var c,l,h,f;if(1!==e.state)return s();for(c in i)if((f=i[c]).name===e.name){if(f.state===Ut)return Bt(o);4===f.state?(f.state=Wt,f.timer.stop(),f.on.call("interrupt",t,t.__data__,f.index,f.group),delete i[c]):+c<n&&(f.state=Wt,f.timer.stop(),f.on.call("cancel",t,t.__data__,f.index,f.group),delete i[c])}if(Bt((function(){e.state===Ut&&(e.state=4,e.timer.restart(a,e.delay,e.time),a(u))})),e.state=Vt,e.on.call("start",t,t.__data__,e.index,e.group),e.state===Vt){for(e.state=Ut,r=new Array(h=e.tween.length),c=0,l=-1;c<h;++c)(f=e.tween[c].value.call(t,t.__data__,e.index,e.group))&&(r[++l]=f);r.length=l+1}}function a(n){for(var i=n<e.duration?e.ease.call(null,n/e.duration):(e.timer.restart(s),e.state=Kt,1),o=-1,a=r.length;++o<a;)r[o].call(t,i);e.state===Kt&&(e.on.call("end",t,t.__data__,e.index,e.group),s())}function s(){for(var r in e.state=Wt,e.timer.stop(),delete i[n],i)return;delete t.__transition}i[n]=e,e.timer=Gt((function(t){e.state=1,e.timer.restart(o,e.delay,e.time),e.delay<=t&&o(t-e.delay)}),0,e.time)}(t,e,{name:n,index:r,group:i,on:Dt,tween:Lt,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:Ht})}function Jt(t,n){var e=nn(t,n);if(e.state>Ht)throw new Error("too late; already scheduled");return e}function tn(t,n){var e=nn(t,n);if(e.state>Ut)throw new Error("too late; already running");return e}function nn(t,n){var e=t.__transition;if(!e||!(e=e[n]))throw new Error("transition not found");return e}function en(t,n){var e,r,i,o=t.__transition,a=!0;if(o){for(i in n=null==n?null:n+"",o)(e=o[i]).name===n?(r=e.state>Vt&&e.state<Kt,e.state=Wt,e.timer.stop(),e.on.call(r?"interrupt":"cancel",t,t.__data__,e.index,e.group),delete o[i]):a=!1;a&&delete t.__transition}}function rn(t,n){return t=+t,n=+n,function(e){return t*(1-e)+n*e}}var on,an=180/Math.PI,sn={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function un(t,n,e,r,i,o){var a,s,u;return(a=Math.sqrt(t*t+n*n))&&(t/=a,n/=a),(u=t*e+n*r)&&(e-=t*u,r-=n*u),(s=Math.sqrt(e*e+r*r))&&(e/=s,r/=s,u/=s),t*r<n*e&&(t=-t,n=-n,u=-u,a=-a),{translateX:i,translateY:o,rotate:Math.atan2(n,t)*an,skewX:Math.atan(u)*an,scaleX:a,scaleY:s}}function cn(t,n,e,r){function i(t){return t.length?t.pop()+" ":""}return function(o,a){var s=[],u=[];return o=t(o),a=t(a),function(t,r,i,o,a,s){if(t!==i||r!==o){var u=a.push("translate(",null,n,null,e);s.push({i:u-4,x:rn(t,i)},{i:u-2,x:rn(r,o)})}else(i||o)&&a.push("translate("+i+n+o+e)}(o.translateX,o.translateY,a.translateX,a.translateY,s,u),function(t,n,e,o){t!==n?(t-n>180?n+=360:n-t>180&&(t+=360),o.push({i:e.push(i(e)+"rotate(",null,r)-2,x:rn(t,n)})):n&&e.push(i(e)+"rotate("+n+r)}(o.rotate,a.rotate,s,u),function(t,n,e,o){t!==n?o.push({i:e.push(i(e)+"skewX(",null,r)-2,x:rn(t,n)}):n&&e.push(i(e)+"skewX("+n+r)}(o.skewX,a.skewX,s,u),function(t,n,e,r,o,a){if(t!==e||n!==r){var s=o.push(i(o)+"scale(",null,",",null,")");a.push({i:s-4,x:rn(t,e)},{i:s-2,x:rn(n,r)})}else 1===e&&1===r||o.push(i(o)+"scale("+e+","+r+")")}(o.scaleX,o.scaleY,a.scaleX,a.scaleY,s,u),o=a=null,function(t){for(var n,e=-1,r=u.length;++e<r;)s[(n=u[e]).i]=n.x(t);return s.join("")}}}var ln=cn((function(t){const n=new("function"==typeof DOMMatrix?DOMMatrix:WebKitCSSMatrix)(t+"");return n.isIdentity?sn:un(n.a,n.b,n.c,n.d,n.e,n.f)}),"px, ","px)","deg)"),hn=cn((function(t){return null==t?sn:(on||(on=document.createElementNS("http://www.w3.org/2000/svg","g")),on.setAttribute("transform",t),(t=on.transform.baseVal.consolidate())?un((t=t.matrix).a,t.b,t.c,t.d,t.e,t.f):sn)}),", ",")",")");function fn(t,n){var e,r;return function(){var i=tn(this,t),o=i.tween;if(o!==e)for(var a=0,s=(r=e=o).length;a<s;++a)if(r[a].name===n){(r=r.slice()).splice(a,1);break}i.tween=r}}function pn(t,n,e){var r,i;if("function"!=typeof e)throw new Error;return function(){var o=tn(this,t),a=o.tween;if(a!==r){i=(r=a).slice();for(var s={name:n,value:e},u=0,c=i.length;u<c;++u)if(i[u].name===n){i[u]=s;break}u===c&&i.push(s)}o.tween=i}}function dn(t,n,e){var r=t._id;return t.each((function(){var t=tn(this,r);(t.value||(t.value={}))[n]=e.apply(this,arguments)})),function(t){return nn(t,r).value[n]}}function mn(t,n,e){t.prototype=n.prototype=e,e.constructor=t}function vn(t,n){var e=Object.create(t.prototype);for(var r in n)e[r]=n[r];return e}function yn(){}var gn=.7,wn=1/gn,_n="\\s*([+-]?\\d+)\\s*",xn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",bn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Mn=/^#([0-9a-f]{3,8})$/,Sn=new RegExp(`^rgb\\(${_n},${_n},${_n}\\)$`),kn=new RegExp(`^rgb\\(${bn},${bn},${bn}\\)$`),En=new RegExp(`^rgba\\(${_n},${_n},${_n},${xn}\\)$`),An=new RegExp(`^rgba\\(${bn},${bn},${bn},${xn}\\)$`),Nn=new RegExp(`^hsl\\(${xn},${bn},${bn}\\)$`),zn=new RegExp(`^hsla\\(${xn},${bn},${bn},${xn}\\)$`),Tn={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 $n(){return this.rgb().formatHex()}function Cn(){return this.rgb().formatRgb()}function Pn(t){var n,e;return t=(t+"").trim().toLowerCase(),(n=Mn.exec(t))?(e=n[1].length,n=parseInt(n[1],16),6===e?Zn(n):3===e?new Xn(n>>8&15|n>>4&240,n>>4&15|240&n,(15&n)<<4|15&n,1):8===e?jn(n>>24&255,n>>16&255,n>>8&255,(255&n)/255):4===e?jn(n>>12&15|n>>8&240,n>>8&15|n>>4&240,n>>4&15|240&n,((15&n)<<4|15&n)/255):null):(n=Sn.exec(t))?new Xn(n[1],n[2],n[3],1):(n=kn.exec(t))?new Xn(255*n[1]/100,255*n[2]/100,255*n[3]/100,1):(n=En.exec(t))?jn(n[1],n[2],n[3],n[4]):(n=An.exec(t))?jn(255*n[1]/100,255*n[2]/100,255*n[3]/100,n[4]):(n=Nn.exec(t))?In(n[1],n[2]/100,n[3]/100,1):(n=zn.exec(t))?In(n[1],n[2]/100,n[3]/100,n[4]):Tn.hasOwnProperty(t)?Zn(Tn[t]):"transparent"===t?new Xn(NaN,NaN,NaN,0):null}function Zn(t){return new Xn(t>>16&255,t>>8&255,255&t,1)}function jn(t,n,e,r){return r<=0&&(t=n=e=NaN),new Xn(t,n,e,r)}function On(t,n,e,r){return 1===arguments.length?((i=t)instanceof yn||(i=Pn(i)),i?new Xn((i=i.rgb()).r,i.g,i.b,i.opacity):new Xn):new Xn(t,n,e,null==r?1:r);var i}function Xn(t,n,e,r){this.r=+t,this.g=+n,this.b=+e,this.opacity=+r}function Fn(){return`#${qn(this.r)}${qn(this.g)}${qn(this.b)}`}function Yn(){const t=Gn(this.opacity);return`${1===t?"rgb(":"rgba("}${Rn(this.r)}, ${Rn(this.g)}, ${Rn(this.b)}${1===t?")":`, ${t})`}`}function Gn(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function Rn(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function qn(t){return((t=Rn(t))<16?"0":"")+t.toString(16)}function In(t,n,e,r){return r<=0?t=n=e=NaN:e<=0||e>=1?t=n=NaN:n<=0&&(t=NaN),new Dn(t,n,e,r)}function Bn(t){if(t instanceof Dn)return new Dn(t.h,t.s,t.l,t.opacity);if(t instanceof yn||(t=Pn(t)),!t)return new Dn;if(t instanceof Dn)return t;var n=(t=t.rgb()).r/255,e=t.g/255,r=t.b/255,i=Math.min(n,e,r),o=Math.max(n,e,r),a=NaN,s=o-i,u=(o+i)/2;return s?(a=n===o?(e-r)/s+6*(e<r):e===o?(r-n)/s+2:(n-e)/s+4,s/=u<.5?o+i:2-o-i,a*=60):s=u>0&&u<1?0:a,new Dn(a,s,u,t.opacity)}function Dn(t,n,e,r){this.h=+t,this.s=+n,this.l=+e,this.opacity=+r}function Ln(t){return(t=(t||0)%360)<0?t+360:t}function Hn(t){return Math.max(0,Math.min(1,t||0))}function Vn(t,n,e){return 255*(t<60?n+(e-n)*t/60:t<180?e:t<240?n+(e-n)*(240-t)/60:n)}function Un(t,n,e,r,i){var o=t*t,a=o*t;return((1-3*t+3*o-a)*n+(4-6*o+3*a)*e+(1+3*t+3*o-3*a)*r+a*i)/6}mn(yn,Pn,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:$n,formatHex:$n,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Bn(this).formatHsl()},formatRgb:Cn,toString:Cn}),mn(Xn,On,vn(yn,{brighter(t){return t=null==t?wn:Math.pow(wn,t),new Xn(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?gn:Math.pow(gn,t),new Xn(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new Xn(Rn(this.r),Rn(this.g),Rn(this.b),Gn(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:Fn,formatHex:Fn,formatHex8:function(){return`#${qn(this.r)}${qn(this.g)}${qn(this.b)}${qn(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:Yn,toString:Yn})),mn(Dn,(function(t,n,e,r){return 1===arguments.length?Bn(t):new Dn(t,n,e,null==r?1:r)}),vn(yn,{brighter(t){return t=null==t?wn:Math.pow(wn,t),new Dn(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?gn:Math.pow(gn,t),new Dn(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),n=isNaN(t)||isNaN(this.s)?0:this.s,e=this.l,r=e+(e<.5?e:1-e)*n,i=2*e-r;return new Xn(Vn(t>=240?t-240:t+120,i,r),Vn(t,i,r),Vn(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new Dn(Ln(this.h),Hn(this.s),Hn(this.l),Gn(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=Gn(this.opacity);return`${1===t?"hsl(":"hsla("}${Ln(this.h)}, ${100*Hn(this.s)}%, ${100*Hn(this.l)}%${1===t?")":`, ${t})`}`}}));const Kn=t=>()=>t;function Wn(t,n){var e=n-t;return e?function(t,n){return function(e){return t+e*n}}(t,e):Kn(isNaN(t)?n:t)}const Qn=function t(n){var e=function(t){return 1==(t=+t)?Wn:function(n,e){return e-n?function(t,n,e){return t=Math.pow(t,e),n=Math.pow(n,e)-t,e=1/e,function(r){return Math.pow(t+r*n,e)}}(n,e,t):Kn(isNaN(n)?e:n)}}(n);function r(t,n){var r=e((t=On(t)).r,(n=On(n)).r),i=e(t.g,n.g),o=e(t.b,n.b),a=Wn(t.opacity,n.opacity);return function(n){return t.r=r(n),t.g=i(n),t.b=o(n),t.opacity=a(n),t+""}}return r.gamma=t,r}(1);function Jn(t){return function(n){var e,r,i=n.length,o=new Array(i),a=new Array(i),s=new Array(i);for(e=0;e<i;++e)r=On(n[e]),o[e]=r.r||0,a[e]=r.g||0,s[e]=r.b||0;return o=t(o),a=t(a),s=t(s),r.opacity=1,function(t){return r.r=o(t),r.g=a(t),r.b=s(t),r+""}}}Jn((function(t){var n=t.length-1;return function(e){var r=e<=0?e=0:e>=1?(e=1,n-1):Math.floor(e*n),i=t[r],o=t[r+1],a=r>0?t[r-1]:2*i-o,s=r<n-1?t[r+2]:2*o-i;return Un((e-r/n)*n,a,i,o,s)}})),Jn((function(t){var n=t.length;return function(e){var r=Math.floor(((e%=1)<0?++e:e)*n),i=t[(r+n-1)%n],o=t[r%n],a=t[(r+1)%n],s=t[(r+2)%n];return Un((e-r/n)*n,i,o,a,s)}}));var te=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,ne=new RegExp(te.source,"g");function ee(t,n){var e,r,i,o=te.lastIndex=ne.lastIndex=0,a=-1,s=[],u=[];for(t+="",n+="";(e=te.exec(t))&&(r=ne.exec(n));)(i=r.index)>o&&(i=n.slice(o,i),s[a]?s[a]+=i:s[++a]=i),(e=e[0])===(r=r[0])?s[a]?s[a]+=r:s[++a]=r:(s[++a]=null,u.push({i:a,x:rn(e,r)})),o=ne.lastIndex;return o<n.length&&(i=n.slice(o),s[a]?s[a]+=i:s[++a]=i),s.length<2?u[0]?function(t){return function(n){return t(n)+""}}(u[0].x):function(t){return function(){return t}}(n):(n=u.length,function(t){for(var e,r=0;r<n;++r)s[(e=u[r]).i]=e.x(t);return s.join("")})}function re(t,n){var e;return("number"==typeof n?rn:n instanceof Pn?Qn:(e=Pn(n))?(n=e,Qn):ee)(t,n)}function ie(t){return function(){this.removeAttribute(t)}}function oe(t){return function(){this.removeAttributeNS(t.space,t.local)}}function ae(t,n,e){var r,i,o=e+"";return function(){var a=this.getAttribute(t);return a===o?null:a===r?i:i=n(r=a,e)}}function se(t,n,e){var r,i,o=e+"";return function(){var a=this.getAttributeNS(t.space,t.local);return a===o?null:a===r?i:i=n(r=a,e)}}function ue(t,n,e){var r,i,o;return function(){var a,s,u=e(this);if(null!=u)return(a=this.getAttribute(t))===(s=u+"")?null:a===r&&s===i?o:(i=s,o=n(r=a,u));this.removeAttribute(t)}}function ce(t,n,e){var r,i,o;return function(){var a,s,u=e(this);if(null!=u)return(a=this.getAttributeNS(t.space,t.local))===(s=u+"")?null:a===r&&s===i?o:(i=s,o=n(r=a,u));this.removeAttributeNS(t.space,t.local)}}function le(t,n){var e,r;function i(){var i=n.apply(this,arguments);return i!==r&&(e=(r=i)&&function(t,n){return function(e){this.setAttributeNS(t.space,t.local,n.call(this,e))}}(t,i)),e}return i._value=n,i}function he(t,n){var e,r;function i(){var i=n.apply(this,arguments);return i!==r&&(e=(r=i)&&function(t,n){return function(e){this.setAttribute(t,n.call(this,e))}}(t,i)),e}return i._value=n,i}function fe(t,n){return function(){Jt(this,t).delay=+n.apply(this,arguments)}}function pe(t,n){return n=+n,function(){Jt(this,t).delay=n}}function de(t,n){return function(){tn(this,t).duration=+n.apply(this,arguments)}}function me(t,n){return n=+n,function(){tn(this,t).duration=n}}var ve=pt.prototype.constructor;function ye(t){return function(){this.style.removeProperty(t)}}var ge=0;function we(t,n,e,r){this._groups=t,this._parents=n,this._name=e,this._id=r}function _e(){return++ge}var xe=pt.prototype;we.prototype=function(t){return pt().transition(t)}.prototype={constructor:we,select:function(t){var n=this._name,e=this._id;"function"!=typeof t&&(t=r(t));for(var i=this._groups,o=i.length,a=new Array(o),s=0;s<o;++s)for(var u,c,l=i[s],h=l.length,f=a[s]=new Array(h),p=0;p<h;++p)(u=l[p])&&(c=t.call(u,u.__data__,p,l))&&("__data__"in u&&(c.__data__=u.__data__),f[p]=c,Qt(f[p],n,e,p,f,nn(u,e)));return new we(a,this._parents,n,e)},selectAll:function(t){var n=this._name,e=this._id;"function"!=typeof t&&(t=o(t));for(var r=this._groups,i=r.length,a=[],s=[],u=0;u<i;++u)for(var c,l=r[u],h=l.length,f=0;f<h;++f)if(c=l[f]){for(var p,d=t.call(c,c.__data__,f,l),m=nn(c,e),v=0,y=d.length;v<y;++v)(p=d[v])&&Qt(p,n,e,v,d,m);a.push(d),s.push(c)}return new we(a,s,n,e)},selectChild:xe.selectChild,selectChildren:xe.selectChildren,filter:function(t){"function"!=typeof t&&(t=a(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i<e;++i)for(var o,s=n[i],u=s.length,c=r[i]=[],l=0;l<u;++l)(o=s[l])&&t.call(o,o.__data__,l,s)&&c.push(o);return new we(r,this._parents,this._name,this._id)},merge:function(t){if(t._id!==this._id)throw new Error;for(var n=this._groups,e=t._groups,r=n.length,i=e.length,o=Math.min(r,i),a=new Array(r),s=0;s<o;++s)for(var u,c=n[s],l=e[s],h=c.length,f=a[s]=new Array(h),p=0;p<h;++p)(u=c[p]||l[p])&&(f[p]=u);for(;s<r;++s)a[s]=n[s];return new we(a,this._parents,this._name,this._id)},selection:function(){return new ve(this._groups,this._parents)},transition:function(){for(var t=this._name,n=this._id,e=_e(),r=this._groups,i=r.length,o=0;o<i;++o)for(var a,s=r[o],u=s.length,c=0;c<u;++c)if(a=s[c]){var l=nn(a,n);Qt(a,t,e,c,s,{time:l.time+l.delay+l.duration,delay:0,duration:l.duration,ease:l.ease})}return new we(r,this._parents,t,e)},call:xe.call,nodes:xe.nodes,node:xe.node,size:xe.size,empty:xe.empty,each:xe.each,on:function(t,n){var e=this._id;return arguments.length<2?nn(this.node(),e).on.on(t):this.each(function(t,n,e){var r,i,o=function(t){return(t+"").trim().split(/^|\s+/).every((function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||"start"===t}))}(n)?Jt:tn;return function(){var a=o(this,t),s=a.on;s!==r&&(i=(r=s).copy()).on(n,e),a.on=i}}(e,t,n))},attr:function(t,n){var e=x(t),r="transform"===e?hn:re;return this.attrTween(t,"function"==typeof n?(e.local?ce:ue)(e,r,dn(this,"attr."+t,n)):null==n?(e.local?oe:ie)(e):(e.local?se:ae)(e,r,n))},attrTween:function(t,n){var e="attr."+t;if(arguments.length<2)return(e=this.tween(e))&&e._value;if(null==n)return this.tween(e,null);if("function"!=typeof n)throw new Error;var r=x(t);return this.tween(e,(r.local?le:he)(r,n))},style:function(t,n,e){var r="transform"==(t+="")?ln:re;return null==n?this.styleTween(t,function(t,n){var e,r,i;return function(){var o=C(this,t),a=(this.style.removeProperty(t),C(this,t));return o===a?null:o===e&&a===r?i:i=n(e=o,r=a)}}(t,r)).on("end.style."+t,ye(t)):"function"==typeof n?this.styleTween(t,function(t,n,e){var r,i,o;return function(){var a=C(this,t),s=e(this),u=s+"";return null==s&&(this.style.removeProperty(t),u=s=C(this,t)),a===u?null:a===r&&u===i?o:(i=u,o=n(r=a,s))}}(t,r,dn(this,"style."+t,n))).each(function(t,n){var e,r,i,o,a="style."+n,s="end."+a;return function(){var u=tn(this,t),c=u.on,l=null==u.value[a]?o||(o=ye(n)):void 0;c===e&&i===l||(r=(e=c).copy()).on(s,i=l),u.on=r}}(this._id,t)):this.styleTween(t,function(t,n,e){var r,i,o=e+"";return function(){var a=C(this,t);return a===o?null:a===r?i:i=n(r=a,e)}}(t,r,n),e).on("end.style."+t,null)},styleTween:function(t,n,e){var r="style."+(t+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==n)return this.tween(r,null);if("function"!=typeof n)throw new Error;return this.tween(r,function(t,n,e){var r,i;function o(){var o=n.apply(this,arguments);return o!==i&&(r=(i=o)&&function(t,n,e){return function(r){this.style.setProperty(t,n.call(this,r),e)}}(t,o,e)),r}return o._value=n,o}(t,n,null==e?"":e))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var n=t(this);this.textContent=null==n?"":n}}(dn(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var n="text";if(arguments.length<1)return(n=this.tween(n))&&n._value;if(null==t)return this.tween(n,null);if("function"!=typeof t)throw new Error;return this.tween(n,function(t){var n,e;function r(){var r=t.apply(this,arguments);return r!==e&&(n=(e=r)&&function(t){return function(n){this.textContent=t.call(this,n)}}(r)),n}return r._value=t,r}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var n=this.parentNode;for(var e in this.__transition)if(+e!==t)return;n&&n.removeChild(this)}}(this._id))},tween:function(t,n){var e=this._id;if(t+="",arguments.length<2){for(var r,i=nn(this.node(),e).tween,o=0,a=i.length;o<a;++o)if((r=i[o]).name===t)return r.value;return null}return this.each((null==n?fn:pn)(e,t,n))},delay:function(t){var n=this._id;return arguments.length?this.each(("function"==typeof t?fe:pe)(n,t)):nn(this.node(),n).delay},duration:function(t){var n=this._id;return arguments.length?this.each(("function"==typeof t?de:me)(n,t)):nn(this.node(),n).duration},ease:function(t){var n=this._id;return arguments.length?this.each(function(t,n){if("function"!=typeof n)throw new Error;return function(){tn(this,t).ease=n}}(n,t)):nn(this.node(),n).ease},easeVarying:function(t){if("function"!=typeof t)throw new Error;return this.each(function(t,n){return function(){var e=n.apply(this,arguments);if("function"!=typeof e)throw new Error;tn(this,t).ease=e}}(this._id,t))},end:function(){var t,n,e=this,r=e._id,i=e.size();return new Promise((function(o,a){var s={value:a},u={value:function(){0==--i&&o()}};e.each((function(){var e=tn(this,r),i=e.on;i!==t&&((n=(t=i).copy())._.cancel.push(s),n._.interrupt.push(s),n._.end.push(u)),e.on=n})),0===i&&o()}))},[Symbol.iterator]:xe[Symbol.iterator]};var be={time:null,delay:0,duration:250,ease:function(t){return((t*=2)<=1?t*t*t:(t-=2)*t*t+2)/2}};function Me(t,n){for(var e;!(e=t.__transition)||!(e=e[n]);)if(!(t=t.parentNode))throw new Error(`transition ${n} not found`);return e}pt.prototype.interrupt=function(t){return this.each((function(){en(this,t)}))},pt.prototype.transition=function(t){var n,e;t instanceof we?(n=t._id,t=t._name):(n=_e(),(e=be).time=Xt(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,o=0;o<i;++o)for(var a,s=r[o],u=s.length,c=0;c<u;++c)(a=s[c])&&Qt(a,t,n,c,s,e||Me(a,n));return new we(r,this._parents,t,n)};const Se=t=>()=>t;function ke(t,{sourceEvent:n,target:e,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},target:{value:e,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function Ee(t,n,e){this.k=t,this.x=n,this.y=e}Ee.prototype={constructor:Ee,scale:function(t){return 1===t?this:new Ee(this.k*t,this.x,this.y)},translate:function(t,n){return 0===t&0===n?this:new Ee(this.k,this.x+this.k*t,this.y+this.k*n)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Ae=new Ee(1,0,0);function Ne(t){t.stopImmediatePropagation()}function ze(t){t.preventDefault(),t.stopImmediatePropagation()}function Te(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function $e(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||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]]:[[0,0],[t.clientWidth,t.clientHeight]]}function Ce(){return this.__zoom||Ae}function Pe(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function Ze(){return navigator.maxTouchPoints||"ontouchstart"in this}function je(t,n,e){var r=t.invertX(n[0][0])-e[0][0],i=t.invertX(n[1][0])-e[1][0],o=t.invertY(n[0][1])-e[0][1],a=t.invertY(n[1][1])-e[1][1];return t.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),a>o?(o+a)/2:Math.min(0,o)||Math.max(0,a))}Ee.prototype;class Oe{constructor(t,n,e,r){this.opts=r||{},this.canvas=t,this.w=this.canvas.offsetWidth,this.h=this.canvas.offsetHeight,this.canvas.width=this.w,this.canvas.height=this.h;const i=this.canvas.getContext("2d");if(!i)throw"Impossible to create canvas 2D context";if(this.ctx=i,this.center=n||{x:.5*this.w,y:.5*this.h},this.zf=e,this.backgroundColor=r.backgroundColor||"white",this.onZoomStartFun=r.onZoomStartFun,this.onZoomEndFun=r.onZoomEndFun,this.onZoomFun=r.onZoomFun,this.extGeo={xMin:NaN,xMax:NaN,yMin:NaN,yMax:NaN},this.updateExtentGeo(),!r.disableZoom){let t=Ae;(function(){var t,n,e,r=Te,i=$e,o=je,a=Pe,s=Ze,u=[0,1/0],c=[[-1/0,-1/0],[1/0,1/0]],l=250,h=St,f=_t("start","zoom","end"),p=500,d=150,m=0,v=10;function y(t){t.property("__zoom",Ce).on("wheel.zoom",S,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",E).filter(s).on("touchstart.zoom",A).on("touchmove.zoom",N).on("touchend.zoom touchcancel.zoom",z).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function g(t,n){return(n=Math.max(u[0],Math.min(u[1],n)))===t.k?t:new Ee(n,t.x,t.y)}function w(t,n,e){var r=n[0]-e[0]*t.k,i=n[1]-e[1]*t.k;return r===t.x&&i===t.y?t:new Ee(t.k,r,i)}function _(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function x(t,n,e,r){t.on("start.zoom",(function(){b(this,arguments).event(r).start()})).on("interrupt.zoom end.zoom",(function(){b(this,arguments).event(r).end()})).tween("zoom",(function(){var t=this,o=arguments,a=b(t,o).event(r),s=i.apply(t,o),u=null==e?_(s):"function"==typeof e?e.apply(t,o):e,c=Math.max(s[1][0]-s[0][0],s[1][1]-s[0][1]),l=t.__zoom,f="function"==typeof n?n.apply(t,o):n,p=h(l.invert(u).concat(c/l.k),f.invert(u).concat(c/f.k));return function(t){if(1===t)t=f;else{var n=p(t),e=c/n[2];t=new Ee(e,u[0]-n[0]*e,u[1]-n[1]*e)}a.zoom(null,t)}}))}function b(t,n,e){return!e&&t.__zooming||new M(t,n)}function M(t,n){this.that=t,this.args=n,this.active=0,this.sourceEvent=null,this.extent=i.apply(t,n),this.taps=0}function S(t,...n){if(r.apply(this,arguments)){var e=b(this,n).event(t),i=this.__zoom,s=Math.max(u[0],Math.min(u[1],i.k*Math.pow(2,a.apply(this,arguments)))),l=kt(t);if(e.wheel)e.mouse[0][0]===l[0]&&e.mouse[0][1]===l[1]||(e.mouse[1]=i.invert(e.mouse[0]=l)),clearTimeout(e.wheel);else{if(i.k===s)return;e.mouse=[l,i.invert(l)],en(this),e.start()}ze(t),e.wheel=setTimeout((function(){e.wheel=null,e.end()}),d),e.zoom("mouse",o(w(g(i,s),e.mouse[0],e.mouse[1]),e.extent,c))}}function k(t,...n){if(!e&&r.apply(this,arguments)){var i=t.currentTarget,a=b(this,n,!0).event(t),s=dt(t.view).on("mousemove.zoom",(function(t){if(ze(t),!a.moved){var n=t.clientX-l,e=t.clientY-h;a.moved=n*n+e*e>m}a.event(t).zoom("mouse",o(w(a.that.__zoom,a.mouse[0]=kt(t,i),a.mouse[1]),a.extent,c))}),!0).on("mouseup.zoom",(function(t){s.on("mousemove.zoom mouseup.zoom",null),function(t,n){var e=t.document.documentElement,r=dt(t).on("dragstart.drag",null);n&&(r.on("click.drag",bt,xt),setTimeout((function(){r.on("click.drag",null)}),0)),"onselectstart"in e?r.on("selectstart.drag",null):(e.style.MozUserSelect=e.__noselect,delete e.__noselect)}(t.view,a.moved),ze(t),a.event(t).end()}),!0),u=kt(t,i),l=t.clientX,h=t.clientY;!function(t){var n=t.document.documentElement,e=dt(t).on("dragstart.drag",bt,xt);"onselectstart"in n?e.on("selectstart.drag",bt,xt):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}(t.view),Ne(t),a.mouse=[u,this.__zoom.invert(u)],en(this),a.start()}}function E(t,...n){if(r.apply(this,arguments)){var e=this.__zoom,a=kt(t.changedTouches?t.changedTouches[0]:t,this),s=e.invert(a),u=e.k*(t.shiftKey?.5:2),h=o(w(g(e,u),a,s),i.apply(this,n),c);ze(t),l>0?dt(this).transition().duration(l).call(x,h,a,t):dt(this).call(y.transform,h,a,t)}}function A(e,...i){if(r.apply(this,arguments)){var o,a,s,u,c=e.touches,l=c.length,h=b(this,i,e.changedTouches.length===l).event(e);for(Ne(e),a=0;a<l;++a)u=[u=kt(s=c[a],this),this.__zoom.invert(u),s.identifier],h.touch0?h.touch1||h.touch0[2]===u[2]||(h.touch1=u,h.taps=0):(h.touch0=u,o=!0,h.taps=1+!!t);t&&(t=clearTimeout(t)),o&&(h.taps<2&&(n=u[0],t=setTimeout((function(){t=null}),p)),en(this),h.start())}}function N(t,...n){if(this.__zooming){var e,r,i,a,s=b(this,n).event(t),u=t.changedTouches,l=u.length;for(ze(t),e=0;e<l;++e)i=kt(r=u[e],this),s.touch0&&s.touch0[2]===r.identifier?s.touch0[0]=i:s.touch1&&s.touch1[2]===r.identifier&&(s.touch1[0]=i);if(r=s.that.__zoom,s.touch1){var h=s.touch0[0],f=s.touch0[1],p=s.touch1[0],d=s.touch1[1],m=(m=p[0]-h[0])*m+(m=p[1]-h[1])*m,v=(v=d[0]-f[0])*v+(v=d[1]-f[1])*v;r=g(r,Math.sqrt(m/v)),i=[(h[0]+p[0])/2,(h[1]+p[1])/2],a=[(f[0]+d[0])/2,(f[1]+d[1])/2]}else{if(!s.touch0)return;i=s.touch0[0],a=s.touch0[1]}s.zoom("touch",o(w(r,i,a),s.extent,c))}}function z(t,...r){if(this.__zooming){var i,o,a=b(this,r).event(t),s=t.changedTouches,u=s.length;for(Ne(t),e&&clearTimeout(e),e=setTimeout((function(){e=null}),p),i=0;i<u;++i)o=s[i],a.touch0&&a.touch0[2]===o.identifier?delete a.touch0:a.touch1&&a.touch1[2]===o.identifier&&delete a.touch1;if(a.touch1&&!a.touch0&&(a.touch0=a.touch1,delete a.touch1),a.touch0)a.touch0[1]=this.__zoom.invert(a.touch0[0]);else if(a.end(),2===a.taps&&(o=kt(o,this),Math.hypot(n[0]-o[0],n[1]-o[1])<v)){var c=dt(this).on("dblclick.zoom");c&&c.apply(this,arguments)}}}return y.transform=function(t,n,e,r){var i=t.selection?t.selection():t;i.property("__zoom",Ce),t!==i?x(t,n,e,r):i.interrupt().each((function(){b(this,arguments).event(r).start().zoom(null,"function"==typeof n?n.apply(this,arguments):n).end()}))},y.scaleBy=function(t,n,e,r){y.scaleTo(t,(function(){return this.__zoom.k*("function"==typeof n?n.apply(this,arguments):n)}),e,r)},y.scaleTo=function(t,n,e,r){y.transform(t,(function(){var t=i.apply(this,arguments),r=this.__zoom,a=null==e?_(t):"function"==typeof e?e.apply(this,arguments):e,s=r.invert(a),u="function"==typeof n?n.apply(this,arguments):n;return o(w(g(r,u),a,s),t,c)}),e,r)},y.translateBy=function(t,n,e,r){y.transform(t,(function(){return o(this.__zoom.translate("function"==typeof n?n.apply(this,arguments):n,"function"==typeof e?e.apply(this,arguments):e),i.apply(this,arguments),c)}),null,r)},y.translateTo=function(t,n,e,r,a){y.transform(t,(function(){var t=i.apply(this,arguments),a=this.__zoom,s=null==r?_(t):"function"==typeof r?r.apply(this,arguments):r;return o(Ae.translate(s[0],s[1]).scale(a.k).translate("function"==typeof n?-n.apply(this,arguments):-n,"function"==typeof e?-e.apply(this,arguments):-e),t,c)}),r,a)},M.prototype={event:function(t){return t&&(this.sourceEvent=t),this},start:function(){return 1==++this.active&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(t,n){return this.mouse&&"mouse"!==t&&(this.mouse[1]=n.invert(this.mouse[0])),this.touch0&&"touch"!==t&&(this.touch0[1]=n.invert(this.touch0[0])),this.touch1&&"touch"!==t&&(this.touch1[1]=n.invert(this.touch1[0])),this.that.__zoom=n,this.emit("zoom"),this},end:function(){return 0==--this.active&&(delete this.that.__zooming,this.emit("end")),this},emit:function(t){var n=dt(this.that).datum();f.call(t,this.that,new ke(t,{sourceEvent:this.sourceEvent,target:y,type:t,transform:this.that.__zoom,dispatch:f}),n)}},y.wheelDelta=function(t){return arguments.length?(a="function"==typeof t?t:Se(+t),y):a},y.filter=function(t){return arguments.length?(r="function"==typeof t?t:Se(!!t),y):r},y.touchable=function(t){return arguments.length?(s="function"==typeof t?t:Se(!!t),y):s},y.extent=function(t){return arguments.length?(i="function"==typeof t?t:Se([[+t[0][0],+t[0][1]],[+t[1][0],+t[1][1]]]),y):i},y.scaleExtent=function(t){return arguments.length?(u[0]=+t[0],u[1]=+t[1],y):[u[0],u[1]]},y.translateExtent=function(t){return arguments.length?(c[0][0]=+t[0][0],c[1][0]=+t[1][0],c[0][1]=+t[0][1],c[1][1]=+t[1][1],y):[[c[0][0],c[0][1]],[c[1][0],c[1][1]]]},y.constrain=function(t){return arguments.length?(o=t,y):o},y.duration=function(t){return arguments.length?(l=+t,y):l},y.interpolate=function(t){return arguments.length?(h=t,y):h},y.on=function(){var t=f.on.apply(f,arguments);return t===f?y:t},y.clickDistance=function(t){return arguments.length?(m=(t=+t)*t,y):Math.sqrt(m)},y.tapDistance=function(t){return arguments.length?(v=+t,y):v},y})().wheelDelta((t=>-t.deltaY*(1===t.deltaMode?.07:t.deltaMode?1:.004))).on("zoom",(n=>{const e=n.transform,r=t.k/e.k;if(1==r){const n=t.x-e.x,r=t.y-e.y;this.pan(n*this.getZf(),-r*this.getZf())}else{const t=n.sourceEvent;if(t instanceof WheelEvent)this.zoom(r,this.pixToGeoX(n.sourceEvent.offsetX),this.pixToGeoY(n.sourceEvent.offsetY));else if(t instanceof TouchEvent){let n=0,e=0;for(let r of t.targetTouches)n+=r.clientX,e+=r.clientY;n/=t.targetTouches.length,e/=t.targetTouches.length,this.zoom(r,this.pixToGeoX(n),this.pixToGeoY(e))}}t=e,this.onZoomFun&&this.onZoomFun(n)})).on("start",(t=>{this.canvasSave.c=document.createElement("canvas"),this.canvasSave.c.setAttribute("width",""+this.w),this.canvasSave.c.setAttribute("height",""+this.h),this.canvasSave.c.getContext("2d").drawImage(this.canvas,0,0),this.canvasSave.dx=0,this.canvasSave.dy=0,this.canvasSave.f=1,this.onZoomStartFun&&this.onZoomStartFun(t)})).on("end",(t=>{this.redraw(!0),this.canvasSave={c:null,dx:0,dy:0,f:1},this.onZoomEndFun&&this.onZoomEndFun(t)}))(dt(this.canvas))}this.zfExtent=[0,1/0],this.canvasSave={c:null,dx:0,dy:0,f:1}}setCenter(t){this.center=t}getCenter(){return this.center}setZf(t){this.zf=t,this.slider&&this.slider.attr("value",+this.zf)}getZf(){return this.zf}setZfExtent(t){this.zfExtent=t}getZfExtent(){return this.zfExtent}initCanvasTransform(){this.ctx.setTransform(1,0,0,1,0,0)}setCanvasTransform(){const t=1/this.getZf(),n=-this.center.x/this.getZf()+.5*this.w,e=this.center.y/this.getZf()+.5*this.h;this.ctx.setTransform(t,0,0,-t,n,e)}getWebGLTransform(){const t=2/(this.w*this.getZf()),n=2/(this.h*this.getZf());return[t,0,0,0,n,0,-t*this.center.x,-n*this.center.y,1]}redraw(t=!0){throw new Error("Method redraw not implemented.")}clear(t="white"){this.opts.transparentBackground?this.ctx.clearRect(0,0,this.w,this.h):(this.ctx&&(this.ctx.fillStyle=t),this.ctx.fillRect(0,0,this.w,this.h))}pan(t=0,n=0){this.center.x+=t,this.center.y+=n,this.updateExtentGeo(),this.canvasSave.c&&(this.canvasSave.dx-=t/this.getZf(),this.canvasSave.dy+=n/this.getZf(),this.clear(this.backgroundColor),this.ctx.drawImage(this.canvasSave.c,this.canvasSave.dx,this.canvasSave.dy))}zoom(t=1,n=this.center.x,e=this.center.y){if(this.zfExtent[0]==this.getZf()&&t<=1)return;if(this.zfExtent[1]==this.getZf()&&t>=1)return;const r=t*this.getZf();r<this.zfExtent[0]&&(t=this.zfExtent[0]/this.getZf()),r>this.zfExtent[1]&&(t=this.zfExtent[1]/this.getZf()),this.setZf(t*this.getZf());const i=(n-this.center.x)*(1-t);this.center.x+=i;const o=(e-this.center.y)*(1-t);this.center.y+=o,this.updateExtentGeo(),this.canvasSave.c&&(this.clear(this.backgroundColor),this.canvasSave.f/=t,this.canvasSave.dx=this.geoToPixX(n)*(1-this.canvasSave.f),this.canvasSave.dy=this.geoToPixY(e)*(1-this.canvasSave.f),this.clear(this.backgroundColor),this.ctx.drawImage(this.canvasSave.c,this.canvasSave.dx,this.canvasSave.dy,this.canvasSave.f*this.canvasSave.c.width,this.canvasSave.f*this.canvasSave.c.height))}updateExtentGeo(t=20){return this.extGeo={xMin:this.pixToGeoX(-t),xMax:this.pixToGeoX(this.w+t),yMin:this.pixToGeoY(this.h+t),yMax:this.pixToGeoY(-t)},this.extGeo}toDraw(t){return!(t.x<this.extGeo.xMin||t.x>this.extGeo.xMax||t.y<this.extGeo.yMin||t.y>this.extGeo.yMax)}geoToPixX(t){return(t-this.center.x)/this.getZf()+.5*this.w}geoToPixY(t){return-(t-this.center.y)/this.getZf()+.5*this.h}pixToGeoX(t){return(t-.5*this.w)*this.getZf()+this.center.x}pixToGeoY(t){return-(t-.5*this.h)*this.getZf()+this.center.y}setViewFromURL(){const t=Oe.getParameterByName("x"),n=Oe.getParameterByName("y"),e=Oe.getParameterByName("z"),r=this.getCenter();null==t||null==t||isNaN(+t)||(r.x=+t),null==n||null==n||isNaN(+n)||(r.y=+n),null==e||null==e||isNaN(+e)||this.setZf(+e)}addZoomSlider(t,n){(n=n||{}).width=n.width||"30px",n.height=n.height||"300px";const e=dt("#"+t);if(e.empty())return console.error("Could not find div element to build zoom slider. Id: "+t),this;const r=this;return this.slider=e.append("input").attr("type","range").attr("min",this.getZfExtent()[0]).attr("max",this.getZfExtent()[1]).attr("value",this.getZf()).on("input",(function(t){if(!this||!this.value)return;const n=+this.value;dt(this).attr("value",n),r.setZf(n),r.redraw()})).style("width",n.width).style("height",n.height).style("opacity",.7).on("mouseover",(function(t){dt(this).style("opacity",1)})).on("mouseout",(function(t){dt(this).style("opacity",.7)})).style("-webkit-appearance","slider-vertical").style("writing-mode","bt-lr").attr("orient","vertical").style("background","lightgray").style("outline","none").style("-webkit-transition",".2s").style("transition","opacity .2s"),this}static getParameterByName(t){t=t.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var n=new RegExp("[\\?&]"+t+"=([^&#]*)").exec(location.search);return n?decodeURIComponent(n[1].replace(/\+/g," ")):null}}class Xe{constructor(t){if(t=t||{},this.filter=t.filter||(()=>!0),this.offset=t.offset||((t,n,e)=>({dx:0,dy:0})),this.minZoom=t.minZoom||0,this.maxZoom=t.maxZoom||1/0,this.minZoom>=this.maxZoom)throw new Error("Unexpected zoom limits for layer. Zoom min should be smaller than zoom max.");this.legends=[]}draw(t,n,e){throw new Error("Method draw not implemented.")}getOffset(){return this.offset}setOffset(t){return this.offset=t,this}updateLegends(t){for(const n of this.legends)n.update(t);return this}static getStatistics(t,n,e){if(!t||0==t.length)return;let r=1/0,i=-1/0;for(const o of t){const t=+n(o);e&&!t||(t<r&&(r=t),t>i&&(i=t))}return{min:r,max:i}}}function Fe(t,n){if((e=(t=n?t.toExponential(n-1):t.toExponential()).indexOf("e"))<0)return null;var e,r=t.slice(0,e);return[r.length>1?r[0]+r.slice(2):r,+t.slice(e+1)]}var Ye,Ge=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Re(t){if(!(n=Ge.exec(t)))throw new Error("invalid format: "+t);var n;return new qe({fill:n[1],align:n[2],sign:n[3],symbol:n[4],zero:n[5],width:n[6],comma:n[7],precision:n[8]&&n[8].slice(1),trim:n[9],type:n[10]})}function qe(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function Ie(t,n){var e=Fe(t,n);if(!e)return t+"";var r=e[0],i=e[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}Re.prototype=qe.prototype,qe.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};const Be={"%":(t,n)=>(100*t).toFixed(n),b:t=>Math.round(t).toString(2),c:t=>t+"",d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:(t,n)=>t.toExponential(n),f:(t,n)=>t.toFixed(n),g:(t,n)=>t.toPrecision(n),o:t=>Math.round(t).toString(8),p:(t,n)=>Ie(100*t,n),r:Ie,s:function(t,n){var e=Fe(t,n);if(!e)return t+"";var r=e[0],i=e[1],o=i-(Ye=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,a=r.length;return o===a?r:o>a?r+new Array(o-a+1).join("0"):o>0?r.slice(0,o)+"."+r.slice(o):"0."+new Array(1-o).join("0")+Fe(t,Math.max(0,n+o-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function De(t){return t}var Le,He=Array.prototype.map,Ve=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Ue(t){return Le=function(t){var n,e,r=void 0===t.grouping||void 0===t.thousands?De:(n=He.call(t.grouping,Number),e=t.thousands+"",function(t,r){for(var i=t.length,o=[],a=0,s=n[0],u=0;i>0&&s>0&&(u+s+1>r&&(s=Math.max(1,r-u)),o.push(t.substring(i-=s,i+s)),!((u+=s+1)>r));)s=n[a=(a+1)%n.length];return o.reverse().join(e)}),i=void 0===t.currency?"":t.currency[0]+"",o=void 0===t.currency?"":t.currency[1]+"",a=void 0===t.decimal?".":t.decimal+"",s=void 0===t.numerals?De:function(t){return function(n){return n.replace(/[0-9]/g,(function(n){return t[+n]}))}}(He.call(t.numerals,String)),u=void 0===t.percent?"%":t.percent+"",c=void 0===t.minus?"−":t.minus+"",l=void 0===t.nan?"NaN":t.nan+"";function h(t){var n=(t=Re(t)).fill,e=t.align,h=t.sign,f=t.symbol,p=t.zero,d=t.width,m=t.comma,v=t.precision,y=t.trim,g=t.type;"n"===g?(m=!0,g="g"):Be[g]||(void 0===v&&(v=12),y=!0,g="g"),(p||"0"===n&&"="===e)&&(p=!0,n="0",e="=");var w="$"===f?i:"#"===f&&/[boxX]/.test(g)?"0"+g.toLowerCase():"",_="$"===f?o:/[%p]/.test(g)?u:"",x=Be[g],b=/[defgprs%]/.test(g);function M(t){var i,o,u,f=w,M=_;if("c"===g)M=x(t)+M,t="";else{var S=(t=+t)<0||1/t<0;if(t=isNaN(t)?l:x(Math.abs(t),v),y&&(t=function(t){t:for(var n,e=t.length,r=1,i=-1;r<e;++r)switch(t[r]){case".":i=n=r;break;case"0":0===i&&(i=r),n=r;break;default:if(!+t[r])break t;i>0&&(i=0)}return i>0?t.slice(0,i)+t.slice(n+1):t}(t)),S&&0==+t&&"+"!==h&&(S=!1),f=(S?"("===h?h:c:"-"===h||"("===h?"":h)+f,M=("s"===g?Ve[8+Ye/3]:"")+M+(S&&"("===h?")":""),b)for(i=-1,o=t.length;++i<o;)if(48>(u=t.charCodeAt(i))||u>57){M=(46===u?a+t.slice(i+1):t.slice(i))+M,t=t.slice(0,i);break}}m&&!p&&(t=r(t,1/0));var k=f.length+t.length+M.length,E=k<d?new Array(d-k+1).join(n):"";switch(m&&p&&(t=r(E+t,E.length?d-M.length:1/0),E=""),e){case"<":t=f+t+M+E;break;case"=":t=f+E+t+M;break;case"^":t=E.slice(0,k=E.length>>1)+f+t+M+E.slice(k);break;default:t=E+f+t+M}return s(t)}return v=void 0===v?6:/[gprs]/.test(g)?Math.max(1,Math.min(21,v)):Math.max(0,Math.min(20,v)),M.toString=function(){return t+""},M}return{format:h,formatPrefix:function(t,n){var e,r=h(((t=Re(t)).type="f",t)),i=3*Math.max(-8,Math.min(8,Math.floor((e=n,((e=Fe(Math.abs(e)))?e[1]:NaN)/3)))),o=Math.pow(10,-i),a=Ve[8+i/3];return function(t){return r(o*t)+a}}}}(t),Le.format,Le.formatPrefix,Le}function Ke(t,n){return null==t?n:"function"==typeof t?t:n=>n[t]}function We(t,n=!1){const e=new Float64Array(5),r=new Float64Array(4);!function(t,n,e){const r=Float64Array.of(.84,1.8675,.84,-1.8675,-.34015,-.1299,-.34015,.1299),i=Math.exp(-1.783/e),o=Math.exp(-1.723/e),a=.6318/e,s=1.997/e,u=Float64Array.of(-i*Math.cos(a),i*Math.sin(a),-i*Math.cos(-a),i*Math.sin(-a),-o*Math.cos(s),o*Math.sin(s),-o*Math.cos(-s),o*Math.sin(-s)),c=2.5066282746310007*e,l=Float64Array.of(r[0],r[1],0,0,0,0,0,0),h=Float64Array.of(1,0,u[0],u[1],0,0,0,0,0,0);let f,p;for(p=2;p<8;p+=2){for(l[p]=u[p]*l[p-2]-u[p+1]*l[p-1],l[p+1]=u[p]*l[p-1]+u[p+1]*l[p-2],f=p-2;f>0;f-=2)l[f]+=u[p]*l[f-2]-u[p+1]*l[f-1],l[f+1]+=u[p]*l[f-1]+u[p+1]*l[f-2];for(f=0;f<=p;f+=2)l[f]+=r[p]*h[f]-r[p+1]*h[f+1],l[f+1]+=r[p]*h[f+1]+r[p+1]*h[f];for(h[p+2]=u[p]*h[p]-u[p+1]*h[p+1],h[p+3]=u[p]*h[p+1]+u[p+1]*h[p],f=p;f>0;f-=2)h[f]+=u[p]*h[f-2]-u[p+1]*h[f-1],h[f+1]+=u[p]*h[f-1]+u[p+1]*h[f-2]}for(p=0;p<4;++p)f=p<<1,n[p]=l[f]/c,t[p+1]=h[f+2]}(e,r,t);const i=Float64Array.of(0,r[1]-e[1]*r[0],r[2]-e[2]*r[0],r[3]-e[3]*r[0],-e[4]*r[0]),o=1+e[1]+e[2]+e[3]+e[4];return{sigma:t,negative:n,a:e,b_causal:r,b_anticausal:i,sum_causal:(r[0]+r[1]+r[2]+r[3])/o,sum_anticausal:(i[1]+i[2]+i[3]+i[4])/o}}function Qe(t,n,e,r=1,i=new Float64Array(e),o=new Float64Array(e),a=new Float64Array(5),s=i,u=Je){const c=2*r,l=3*r,h=4*r,f=r*e;let p,d;for(u(i,n,e,r,t.b_causal,3,t.a,4,t.sum_causal,a,t.sigma),d=4,p=h;d<e;++d,p+=r)i[d]=t.b_causal[0]*n[p]+t.b_causal[1]*n[p-r]+t.b_causal[2]*n[p-c]+t.b_causal[3]*n[p-l]-t.a[1]*i[d-1]-t.a[2]*i[d-2]-t.a[3]*i[d-3]-t.a[4]*i[d-4];for(u(o,n,e,-r,t.b_anticausal,4,t.a,4,t.sum_anticausal,a,t.sigma),d=4,p=f-5*r;d<e;++d,p-=r)o[d]=t.b_anticausal[1]*n[p+r]+t.b_anticausal[2]*n[p+c]+t.b_anticausal[3]*n[p+l]+t.b_anticausal[4]*n[p+h]-t.a[1]*o[d-1]-t.a[2]*o[d-2]-t.a[3]*o[d-3]-t.a[4]*o[d-4];if(t.negative)for(d=0,p=0;d<e;++d,p+=r)s[p]=i[d]+o[e-d-1];else for(d=0,p=0;d<e;++d,p+=r)s[p]=Math.max(0,i[d]+o[e-d-1]);return s}function Je(t,n,e,r,i,o,a,s,u,c){const l=Math.abs(r)*e,h=r<0?l+r:0;let f,p,d;for(p=0;p<s;++p)for(c[p]=p<=o?i[p]:0,d=1;d<=s&&d<=p;++d)c[p]-=a[d]*c[p-d];for(d=0;d<s;++d)for(t[d]=0,p=1;p<=d;++p)f=h+r*p,f>=0&&f<l&&(t[d]+=c[d-p]*n[f]);const m=n[h];if(m>0)for(d=0;d<s;++d)t[d]+=c[d]*m}function tr(t,n,e=0){const r=t.length;let i,o;for(let e=0;e<r;++e){const r=n(t[e],e,t);null!=r&&(void 0===i?r>=r&&(i=o=r):(r<i&&(i=r),r>o&&(o=r)))}return[i-e,o+e]}function nr(t,n){const e=t.length;for(let r=0;r<e;++r)t[r]>n&&(n=t[r]);return n}function er(t,n){const e=t.length;for(let r=0;r<e;++r)t[r]<n&&(n=t[r]);return n}function rr(t,n){const e=t.map(n).filter((t=>null!=t&&t>=t));e.sort(((t,n)=>t-n));const r=function(t){const n=t.length;let e,r=0,i=0,o=0;for(let a=0;a<n;++a){const n=t[a];e=n-i,i+=e/++r,o+=e*(n-i)}return r>1?Math.sqrt(o/(r-1)):NaN}(e),i=ir(e,.25),o=ir(e,.75),a=e.length,s=(o-i)/1.34;return 1.06*(Math.min(r,s)||r||Math.abs(i)||1)*Math.pow(a,-.2)}function ir(t,n){const e=t.length;if(!e)return NaN;if((n=+n)<=0||e<2)return t[0];if(n>=1)return t[e-1];const r=(e-1)*n,i=Math.floor(r),o=t[i];return o+(t[i+1]-o)*(r-i)}function or(t,n={}){const{adjust:e=1,pad:r=3,bins:i=[256,256]}=n,o=Ke(n.x,(t=>t[0])),a=Ke(n.y,(t=>t[1])),s=Ke(n.weight,(()=>1/t.length));let[u=e*rr(t,o),c=e*rr(t,a)]=ar(n.bandwidth);const[[l,h]=tr(t,o,r*u),[f,p]=tr(t,a,r*c)]=null==(d=n.extent)?[void 0,void 0]:"number"==typeof d[0]?[d,d]:d;var d;const[m,v]=ar(i),y=function(t,n,e,r,i,o,a,s,u,c){const l=new Float64Array(a*c),h=(a-1)/(o-i),f=(c-1)/(u-s);for(let o=0;o<t.length;++o){const u=t[o],p=n(u,o,t),d=e(u,o,t),m=r(u,o,t);if(!(Number.isFinite(p)&&Number.isFinite(d)&&Number.isFinite(m)))continue;const v=(p-i)*h,y=Math.floor(v),g=y+1,w=(d-s)*f,_=Math.floor(w),x=_+1;0<=y&&g<a?0<=_&&x<c?(l[y+_*a]+=(g-v)*(x-w)*m,l[y+x*a]+=(g-v)*(w-_)*m,l[g+_*a]+=(v-y)*(x-w)*m,l[g+x*a]+=(v-y)*(w-_)*m):-1===_?(l[y+x*a]+=(g-v)*(w-_)*m,l[g+x*a]+=(v-y)*(w-_)*m):x===c&&(l[g+_*a]+=(v-y)*(x-w)*m,l[y+_*a]+=(g-v)*(x-w)*m):-1===y?0<=_&&x<c?(l[g+_*a]+=(v-y)*(x-w)*m,l[g+x*a]+=(v-y)*(w-_)*m):-1===_?l[g+x*a]+=(v-y)*(w-_)*m:x===c&&(l[g+_*a]+=(v-y)*(x-w)*m):g===a&&(0<=_&&x<c?(l[y+_*a]+=(g-v)*(x-w)*m,l[y+x*a]+=(g-v)*(w-_)*m):-1===_?l[y+x*a]+=(g-v)*(w-_)*m:x===c&&(l[y+_*a]+=(g-v)*(x-w)*m))}return l}(t,o,a,s,l,h,m,f,p,v),g=(h-l)/(m-1),w=(p-f)/(v-1),_=y.some((t=>t<0));let x,b=We(u/g,_),M=We(c/w,_);function*S(t="x",n="y",e="z"){const r=k.grid(),i=1/(g*w);for(let o=0,a=0;a<v;++a)for(let s=0;s<m;++s,++o)yield{[t]:l+s*g,[n]:f+a*w,[e]:r[o]*i}}const k={[Symbol.iterator]:S,points:S,grid:()=>x||(x=function(t,n,e,[r,i]){const o=new Float64Array(Math.max(r,i)),a=new Float64Array(Math.max(r,i)),s=new Float64Array(5),u=new Float64Array(e.length);for(let n=0,c=0;n<i;++n,c+=r){const n=u.subarray(c);Qe(t,e.subarray(c),r,1,o,a,s,n)}for(let t=0;t<r;++t){const e=u.subarray(t);Qe(n,e,i,r,o,a,s,e)}return u}(b,M,y,[m,v])),extent:()=>[[l,h],[f,p]],heatmap:({color:t,clamp:n,canvas:e,maxColors:r}={})=>function(t,n,e,r=(t=>({r:0,g:0,b:0,opacity:t})),[i,o]=[er(t,0),nr(t,0)],a=function(t,n){if("undefined"!=typeof document){const e=document.createElement("canvas");return e.setAttribute("width",t),e.setAttribute("height",n),e}throw"Can not create a canvas instance, provide a canvas as a parameter."}(n,e),s=256){const u=1/(o-i),c=a.getContext("2d"),l=c.getImageData(0,0,n,e),h=l.data,f=s-1,p=function(t,n){const e=new Uint8ClampedArray(4*(t+1));for(let r=0;r<=t;++r){const i=n(r/t),{r:o,g:a,b:s,opacity:u=1}="string"==typeof i?On(i):i,c=r<<2;e[c+0]=o,e[c+1]=a,e[c+2]=s,e[c+3]=255*u|0}return e}(f,r);for(let r=0,o=0;r<e;++r)for(let a=0,s=(e-r-1)*n;a<n;++a,o+=4){const n=f*Math.min(1,Math.max(t[a+s]-i,0)*u)<<2;h[o+0]=p[n+0],h[o+1]=p[n+1],h[o+2]=p[n+2],h[o+3]=p[n+3]}return c.putImageData(l,0,0),a}(k.grid(),m,v,t,n,e,r),bandwidth(t){if(arguments.length){const[n,e]=ar(t);return n!==u&&(x=null,b=We((u=n)/g,_)),e!==c&&(x=null,M=We((c=e)/w,_)),k}return[u,c]}};return k}function ar(t){return null==t?[void 0,void 0]:"number"==typeof t?[t,t]:t}function sr(t){return sr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},sr(t)}function ur(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=new Array(n);e<n;e++)r[e]=t[e];return r}function cr(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,i=function(t,n){if("object"!==sr(t)||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!==sr(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key),"symbol"===sr(i)?i:String(i)),r)}var i}function lr(t,n){return lr=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},lr(t,n)}function hr(t){return hr=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},hr(t)}Ue({thousands:",",grouping:[3],currency:["$",""]}),Oe.getParameterByName,Ue({decimal:".",thousands:" ",grouping:[3],currency:["","€"]});var fr=function(t){!function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),n&&lr(t,n)}(a,t);var n,e,r,i,o=(r=a,i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,n=hr(r);if(i){var e=hr(this).constructor;t=Reflect.construct(n,arguments,e)}else t=n.apply(this,arguments);return function(t,n){if(n&&("object"===sr(n)||"function"==typeof n))return n;if(void 0!==n)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(this,t)});function a(t){var n;return function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,a),n=o.call(this,t),t=t||{},n.value=t.value,n.sigma=t.sigma,n.factor=t.factor||2,n.filterSm=t.filterSm,n.sCol=t.sCol||"ksmval",n.styles=t.styles||[],n}return n=a,(e=[{key:"draw",value:function(t,n,e){var r=this;if(this.filter&&(t=t.filter(this.filter)),t&&0!=t.length){var i=this.sigma(n,e.zf),o=Math.ceil(e.w/this.factor),a=Math.ceil(e.h/this.factor),s=[[e.pixToGeoX(0),e.pixToGeoX(o*this.factor)],[e.pixToGeoY(a*this.factor),e.pixToGeoY(0)]],u=or(t,{x:function(t){return t.x+n/2},y:function(t){return t.y+n/2},weight:function(t){return r.value(t)},bins:[o,a],bandwidth:i,extent:s}).grid(),c=(s[0][1]-s[0][0])/o;t=[];for(var l=0;l<u.length;l++){var h=u[l];if(!this.filterSm||this.filterSm(h)){var f=Math.floor(l/o),p=l%o,d={x:s[0][0]+p*c,y:s[1][0]+f*c};d[this.sCol]=h,t.push(d)}}var m,v=function(t,n){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=function(t,n){if(t){if("string"==typeof t)return ur(t,n);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?ur(t,n):void 0}}(t))||n&&t&&"number"==typeof t.length){e&&(t=e);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return a=t.done,t},e:function(t){s=!0,o=t},f:function(){try{a||null==e.return||e.return()}finally{if(s)throw o}}}}(this.styles);try{for(v.s();!(m=v.n()).done;)m.value.draw(t,c,e)}catch(t){v.e(t)}finally{v.f()}}}}])&&cr(n.prototype,e),Object.defineProperty(n,"prototype",{writable:!1}),a}(Xe);return n})()));
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gridviz-smoothing",
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"homepage": "https://github.com/eurostat/gridviz-smoothing",
|
|
7
|
+
"author": "Joseph Davies, Julien Gaffuri",
|
|
8
|
+
"license": "EUPL-1.2",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/eurostat/gridviz-smoothing.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/eurostat/gridviz-smoothing/issues",
|
|
15
|
+
"email": "Joseph.DAVIES@ext.ec.europa.eu"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "dist/gridviz-smoothing.min.js",
|
|
19
|
+
"module": "dist/gridviz-smoothing.min.js",
|
|
20
|
+
"exports": {
|
|
21
|
+
"umd": "./dist/gridviz-smoothing.min.js",
|
|
22
|
+
"default": "./src/index.js"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"start": "export NODE_OPTIONS=--openssl-legacy-provider && webpack --config webpack.config.dev.cjs",
|
|
26
|
+
"start-dev": "webpack --config webpack.config.dev.cjs",
|
|
27
|
+
"server": "webpack serve -c webpack.config.dev.js --static ./",
|
|
28
|
+
"doc": "./node_modules/.bin/jsdoc src/ src/dataset src/legend src/style -d docs/jsdoc",
|
|
29
|
+
"build-prod": "webpack --config webpack.config.prod.cjs",
|
|
30
|
+
"test": "jest"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist/**/*.js",
|
|
34
|
+
"src/**/*.js"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"gridviz": "^2.0.33",
|
|
38
|
+
"fast-kde": "^0.2.1"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@babel/core": "^7.9.0",
|
|
42
|
+
"@babel/plugin-transform-runtime": "^7.12.1",
|
|
43
|
+
"@babel/preset-env": "^7.9.0",
|
|
44
|
+
"@babel/runtime": "^7.12.1",
|
|
45
|
+
"babel-loader": "^8.1.0",
|
|
46
|
+
"jest": "^26.6.1",
|
|
47
|
+
"jshint": "^2.12.0",
|
|
48
|
+
"prettier": "2.8.8",
|
|
49
|
+
"puppeteer": "^9.1.1",
|
|
50
|
+
"webpack": "^5.75.0",
|
|
51
|
+
"webpack-cli": "^5.0.0",
|
|
52
|
+
"webpack-dev-server": "^4.11.1",
|
|
53
|
+
"webpack-livereload-plugin": "^3.0.2"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=14"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
import { Style } from '../Style.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A style representing the cell as a smoothed layer, to smoothing local variations and show main trends across space.
|
|
8
|
+
*
|
|
9
|
+
* @author Julien Gaffuri
|
|
10
|
+
*/
|
|
11
|
+
export class KernelSmoothingStyle extends Style {
|
|
12
|
+
//bandwidth
|
|
13
|
+
// https://observablehq.com/@uwdata/fast-kde
|
|
14
|
+
// https://observablehq.com/d/3127b6d89ada959f
|
|
15
|
+
//TODO use https://github.com/uwdata/fast-kde ?
|
|
16
|
+
//TODO https://observablehq.com/@sahilchinoy/areal-interpolation-iii ?
|
|
17
|
+
|
|
18
|
+
/** @param {object} opts */
|
|
19
|
+
constructor(opts) {
|
|
20
|
+
super(opts)
|
|
21
|
+
opts = opts || {}
|
|
22
|
+
|
|
23
|
+
/** A function specifying the value to consider for each cell. This is the value to smooth.
|
|
24
|
+
* @type {function(import("../Dataset").Cell):number} */
|
|
25
|
+
this.value = opts.value
|
|
26
|
+
|
|
27
|
+
/** The smoothing parameter, in geo unit. The larger, the more smoothed.
|
|
28
|
+
* @type {function(number,number):number}
|
|
29
|
+
*/
|
|
30
|
+
this.sigma = opts.sigma // (r, zf)=>...
|
|
31
|
+
|
|
32
|
+
/** The styles to represent the smoothed cells.
|
|
33
|
+
* @type {Array.<Style>}
|
|
34
|
+
*/
|
|
35
|
+
this.styles = opts.styles
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Compute the kernel matrix, that is the matrix of the weights.
|
|
40
|
+
* One quadrant is necessary only, since it is symetrical (along both x and y axes).
|
|
41
|
+
* @param {number} s Sigma (in grid pixel !)
|
|
42
|
+
* @returns {Array.<Array<number>>}
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
getKernelMatrix(s) {
|
|
46
|
+
//the size of the kernel: lets limit that to ~3 times the standard deviation, as an approximation.
|
|
47
|
+
const kernelSize = Math.floor(3.25 * s)
|
|
48
|
+
|
|
49
|
+
//pre-compute coefficient for gaussian computation, to avoid computing them every time.
|
|
50
|
+
const c2 = 2 * s * s
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The gaussian function. TODO expose that function as a parameter, to use other kernels ?
|
|
54
|
+
* @param {number} x
|
|
55
|
+
* @param {number} y
|
|
56
|
+
* @returns {number}
|
|
57
|
+
*/
|
|
58
|
+
const gaussian = (x, y) => (c2 != 0 ? Math.exp(-(x * x + y * y) / c2) : x == 0 && y == 0 ? 1 : 0) //dirac case
|
|
59
|
+
|
|
60
|
+
/** @type {Array.<Array<number>>} */
|
|
61
|
+
const kw = []
|
|
62
|
+
for (let wi = 0; wi <= kernelSize; wi++) {
|
|
63
|
+
/** @type {Array<number>} */
|
|
64
|
+
const col = []
|
|
65
|
+
for (let wj = 0; wj <= kernelSize; wj++) {
|
|
66
|
+
//compute weight at wi,wj
|
|
67
|
+
col.push(gaussian(wi, wj))
|
|
68
|
+
}
|
|
69
|
+
kw.push(col)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
//debug: show values
|
|
74
|
+
for (let wj = kernelSize-1; wj >=0; wj--) {
|
|
75
|
+
let st = "";
|
|
76
|
+
for (let wi = 0; wi <= kernelSize; wi++) {
|
|
77
|
+
st += " " + Math.floor(kw[wi][wj].w *1000) /1000
|
|
78
|
+
}
|
|
79
|
+
console.log(st)
|
|
80
|
+
}*/
|
|
81
|
+
|
|
82
|
+
return kw
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Compute kernel smoothing of some cells.
|
|
87
|
+
*
|
|
88
|
+
* @private
|
|
89
|
+
* @param {Array.<import("../Dataset").Cell>} cells The cells to be smoothed.
|
|
90
|
+
* @param {import("../Dataset").Envelope} e Geo envelope to consider.
|
|
91
|
+
* @param {number} r Resolution, in geo unit.
|
|
92
|
+
* @param {number} s Sigma (in grid pixel !)
|
|
93
|
+
* @returns {Array.<import("../Dataset").Cell>} The list of cells, including the initial ones and the ones with smoothed values, in "ksmval" property.
|
|
94
|
+
*/
|
|
95
|
+
kernelSmoothing(cells, e, r, s) {
|
|
96
|
+
//filter
|
|
97
|
+
if (this.filter) cells = cells.filter(this.filter)
|
|
98
|
+
|
|
99
|
+
const wThr = 0.01 //gaussian weights below this value will be ignored
|
|
100
|
+
|
|
101
|
+
//compute extent, in grid position
|
|
102
|
+
const xMin = Math.floor(e.xMin / r) * r
|
|
103
|
+
const xMax = Math.floor(e.xMax / r) * r
|
|
104
|
+
const yMin = Math.floor(e.yMin / r) * r
|
|
105
|
+
const yMax = Math.floor(e.yMax / r) * r
|
|
106
|
+
|
|
107
|
+
//compute matrix dimensions
|
|
108
|
+
const nbX = (xMax - xMin) / r + 1
|
|
109
|
+
const nbY = (yMax - yMin) / r + 1
|
|
110
|
+
|
|
111
|
+
//initialise smoothed value to 0
|
|
112
|
+
for (const c of cells) c['ksmval'] = 0
|
|
113
|
+
|
|
114
|
+
//make matrix. add input cells by i/j (grid position)
|
|
115
|
+
const index = {}
|
|
116
|
+
for (const c of cells) {
|
|
117
|
+
// i,j of the cell
|
|
118
|
+
const i = Math.floor((c.x - xMin) / r)
|
|
119
|
+
const j = Math.floor((c.y - yMin) / r)
|
|
120
|
+
if (!index[i]) index[i] = {}
|
|
121
|
+
index[i][j] = c
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Check that the cell i,j is within the frame */
|
|
125
|
+
const isWithinFrame = (i, j) => i >= 0 && i < nbX && j >= 0 && j < nbY
|
|
126
|
+
|
|
127
|
+
//get kernel matrix
|
|
128
|
+
/** @type {Array.<Array.<number>>} */
|
|
129
|
+
const kernelMatrix = this.getKernelMatrix(s)
|
|
130
|
+
const kernelSize = kernelMatrix.length
|
|
131
|
+
|
|
132
|
+
//compute summ of the weights over entire kernel window
|
|
133
|
+
/** @type {number} */
|
|
134
|
+
let sumWeights = 0
|
|
135
|
+
for (let ki = 1 - kernelSize; ki < kernelSize; ki++) {
|
|
136
|
+
for (let kj = 1 - kernelSize; kj < kernelSize; kj++) {
|
|
137
|
+
let w = kernelMatrix[Math.abs(ki)][Math.abs(kj)]
|
|
138
|
+
if (w < wThr) continue
|
|
139
|
+
sumWeights += w
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Add v as a contribution to the cell i,j */
|
|
144
|
+
const addContributionTo = (i, j, v) => {
|
|
145
|
+
//get cell at (i,j)
|
|
146
|
+
const c_ = index[i] ? index[i][j] : undefined
|
|
147
|
+
|
|
148
|
+
if (c_) {
|
|
149
|
+
//cell exists: add contribution
|
|
150
|
+
if (c_.ksmval) c_.ksmval += v
|
|
151
|
+
else c_.ksmval = v
|
|
152
|
+
} else {
|
|
153
|
+
//cell does not exist: create a new one with the smoothed value
|
|
154
|
+
if (!index[i]) index[i] = {}
|
|
155
|
+
index[i][j] = { x: xMin + i * r, y: yMin + j * r, ksmval: v }
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//compute smoothing, input cell by input cell
|
|
160
|
+
for (const c of cells) {
|
|
161
|
+
/** get value of cell c
|
|
162
|
+
* @type {number} */
|
|
163
|
+
const val = this.value(c)
|
|
164
|
+
if (!val) continue
|
|
165
|
+
|
|
166
|
+
//cell matrix coordinates
|
|
167
|
+
const i = Math.floor((c.x - xMin) / r)
|
|
168
|
+
const j = Math.floor((c.y - yMin) / r)
|
|
169
|
+
|
|
170
|
+
//add contributions to smoothed values
|
|
171
|
+
for (let ki = 1 - kernelSize; ki < kernelSize; ki++) {
|
|
172
|
+
for (let kj = 1 - kernelSize; kj < kernelSize; kj++) {
|
|
173
|
+
//check cell is within the frame
|
|
174
|
+
if (!isWithinFrame(i + ki, j + kj)) continue
|
|
175
|
+
|
|
176
|
+
//get contribution (ki,kj)
|
|
177
|
+
let w = kernelMatrix[Math.abs(ki)][Math.abs(kj)]
|
|
178
|
+
if (!w || w < wThr) continue
|
|
179
|
+
let v = w * val
|
|
180
|
+
if (!v) continue
|
|
181
|
+
v /= sumWeights
|
|
182
|
+
if (!v) continue
|
|
183
|
+
|
|
184
|
+
//add contribution
|
|
185
|
+
addContributionTo(i + ki, j + kj, v)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
//make output list
|
|
191
|
+
const out = []
|
|
192
|
+
for (let i of Object.keys(index)) for (const j of Object.keys(index[i])) out.push(index[i][j])
|
|
193
|
+
|
|
194
|
+
return out
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Draw the smoothed cells depending on the list of styles specified.
|
|
199
|
+
*
|
|
200
|
+
* @param {Array.<import("../Dataset").Cell>} cells
|
|
201
|
+
* @param {number} r
|
|
202
|
+
* @param {import("../GeoCanvas").GeoCanvas} cg
|
|
203
|
+
*/
|
|
204
|
+
draw(cells, r, cg) {
|
|
205
|
+
if (!cells || cells.length == 0) return
|
|
206
|
+
|
|
207
|
+
//get smoothing param in geo unit
|
|
208
|
+
/** @type {number} */
|
|
209
|
+
const sG = this.sigma(r, cg.zf)
|
|
210
|
+
|
|
211
|
+
//apply kernel smoothing
|
|
212
|
+
cells = this.kernelSmoothing(cells, cg.extGeo, r, sG / r)
|
|
213
|
+
|
|
214
|
+
//draw smoothed cells from styles
|
|
215
|
+
for (let s of this.styles) s.draw(cells, r, cg)
|
|
216
|
+
|
|
217
|
+
//update legends
|
|
218
|
+
//for (let s of this.styles)
|
|
219
|
+
// s.updateLegends({ style: s, r: r, zf: cg.getZf() });
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
import { Style } from 'gridviz'
|
|
5
|
+
import { density2d } from 'fast-kde'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A style representing the cell as a smoothed layer, to smoothing local variations and show main trends across space.
|
|
9
|
+
*
|
|
10
|
+
* @author Julien Gaffuri
|
|
11
|
+
*/
|
|
12
|
+
export class KernelSmoothingStyle extends Style {
|
|
13
|
+
// https://observablehq.com/d/5dd1cb5e4d21c021
|
|
14
|
+
// https://observablehq.com/@uwdata/fast-kde
|
|
15
|
+
// https://observablehq.com/d/3127b6d89ada959f
|
|
16
|
+
//TODO https://observablehq.com/@sahilchinoy/areal-interpolation-iii ?
|
|
17
|
+
|
|
18
|
+
/** @param {object} opts */
|
|
19
|
+
constructor(opts) {
|
|
20
|
+
super(opts)
|
|
21
|
+
opts = opts || {}
|
|
22
|
+
|
|
23
|
+
/** A function returning the value to consider for each cell. This is the value to be smoothed.
|
|
24
|
+
*/
|
|
25
|
+
this.value = opts.value
|
|
26
|
+
|
|
27
|
+
/** The smoothing parameter, in geo unit. The larger, the more smoothed.
|
|
28
|
+
* @type {function(number,number):number}
|
|
29
|
+
*/
|
|
30
|
+
this.sigma = opts.sigma // (r, zf)=>...
|
|
31
|
+
|
|
32
|
+
/** A factor to adjust the smoothed grid resolution.
|
|
33
|
+
* When set to 1, the smoothed grid is exactly the screen resolution.
|
|
34
|
+
* Set to 2 to degrade the resolution to a factor 2.
|
|
35
|
+
* The higher, the more pixelised and the faster to compute.
|
|
36
|
+
* @type { number }
|
|
37
|
+
*/
|
|
38
|
+
this.factor = opts.factor || 2
|
|
39
|
+
|
|
40
|
+
/** A filter function to filter the smoothed cells based on their smoothed value.
|
|
41
|
+
* Return true to keep the cell, false otherwise.
|
|
42
|
+
* @type { function(number):boolean }
|
|
43
|
+
*/
|
|
44
|
+
this.filterSm = opts.filterSm
|
|
45
|
+
|
|
46
|
+
/** The name of the attribute where the smoothed value is stored in the output smoothed grid.
|
|
47
|
+
* @type { string }
|
|
48
|
+
*/
|
|
49
|
+
this.sCol = opts.sCol || 'ksmval'
|
|
50
|
+
|
|
51
|
+
/** The styles to represent the smoothed grid.
|
|
52
|
+
* @type {Array.<Style>}
|
|
53
|
+
*/
|
|
54
|
+
this.styles = opts.styles || []
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Draw the smoothed cells depending on the list of styles specified.
|
|
59
|
+
*
|
|
60
|
+
* @param {object} cells
|
|
61
|
+
* @param {number} r
|
|
62
|
+
* @param {object} cg
|
|
63
|
+
*/
|
|
64
|
+
draw(cells, r, cg) {
|
|
65
|
+
//filter
|
|
66
|
+
if (this.filter) cells = cells.filter(this.filter)
|
|
67
|
+
|
|
68
|
+
if (!cells || cells.length == 0) return
|
|
69
|
+
|
|
70
|
+
//get smoothing param in geo unit
|
|
71
|
+
/** @type {number} */
|
|
72
|
+
const sG = this.sigma(r, cg.zf)
|
|
73
|
+
|
|
74
|
+
//compute smoothed grid dimensions
|
|
75
|
+
const nbX = Math.ceil(cg.w / this.factor)
|
|
76
|
+
const nbY = Math.ceil(cg.h / this.factor)
|
|
77
|
+
//compute smoothed grid geo extent
|
|
78
|
+
const e_ = [
|
|
79
|
+
[cg.pixToGeoX(0), cg.pixToGeoX(nbX * this.factor)],
|
|
80
|
+
[cg.pixToGeoY(nbY * this.factor), cg.pixToGeoY(0)],
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
//compute smoothed grid
|
|
84
|
+
let g = density2d(cells, {
|
|
85
|
+
x: (c) => c.x + r / 2,
|
|
86
|
+
y: (c) => c.y + r / 2,
|
|
87
|
+
weight: (c) => this.value(c),
|
|
88
|
+
bins: [nbX, nbY],
|
|
89
|
+
bandwidth: sG,
|
|
90
|
+
extent: e_,
|
|
91
|
+
}).grid()
|
|
92
|
+
|
|
93
|
+
//compute the resolution of the smoothed grid
|
|
94
|
+
const resSmoothed = (e_[0][1] - e_[0][0]) / nbX
|
|
95
|
+
|
|
96
|
+
//make smoothed cells
|
|
97
|
+
cells = []
|
|
98
|
+
for (let ind = 0; ind < g.length; ind++) {
|
|
99
|
+
const v = g[ind]
|
|
100
|
+
if (this.filterSm && !this.filterSm(v)) continue
|
|
101
|
+
const row = Math.floor(ind / nbX)
|
|
102
|
+
const col = ind % nbX
|
|
103
|
+
const c = { x: e_[0][0] + col * resSmoothed, y: e_[1][0] + row * resSmoothed }
|
|
104
|
+
c[this.sCol] = v
|
|
105
|
+
cells.push(c)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//draw smoothed cells from styles
|
|
109
|
+
for (let s of this.styles) s.draw(cells, resSmoothed, cg)
|
|
110
|
+
|
|
111
|
+
//update legends
|
|
112
|
+
//for (let s of this.styles)
|
|
113
|
+
// s.updateLegends({ style: s, r: r, zf: cg.getZf() });
|
|
114
|
+
}
|
|
115
|
+
}
|