@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
29 lines • 34.5 kB
JavaScript
// Copyright 2010-2015 Mike Bostock
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of contributors may be used to
// endorse or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
var pi=Math.PI,tau=2*pi,epsilon=1e-6,tauEpsilon=tau-epsilon;function Path(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function path(){return new Path}function constant(t){return function(){return t}}Path.prototype=path.prototype={constructor:Path,moveTo:function(t,n){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+n)},closePath:function(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")},lineTo:function(t,n){this._+="L"+(this._x1=+t)+","+(this._y1=+n)},quadraticCurveTo:function(t,n,i,e){this._+="Q"+ +t+","+ +n+","+(this._x1=+i)+","+(this._y1=+e)},bezierCurveTo:function(t,n,i,e,s,o){this._+="C"+ +t+","+ +n+","+ +i+","+ +e+","+(this._x1=+s)+","+(this._y1=+o)},arcTo:function(t,n,i,e,s){t=+t,n=+n,i=+i,e=+e,s=+s;var o=this._x1,a=this._y1,h=i-t,r=e-n,_=o-t,l=a-n,c=_*_+l*l;if(s<0)throw new Error("negative radius: "+s);if(null===this._x1)this._+="M"+(this._x1=t)+","+(this._y1=n);else if(c>epsilon)if(Math.abs(l*h-r*_)>epsilon&&s){var u=i-o,f=e-a,p=h*h+r*r,x=u*u+f*f,y=Math.sqrt(p),d=Math.sqrt(c),v=s*Math.tan((pi-Math.acos((p+c-x)/(2*y*d)))/2),g=v/d,T=v/y;Math.abs(g-1)>epsilon&&(this._+="L"+(t+g*_)+","+(n+g*l)),this._+="A"+s+","+s+",0,0,"+ +(l*u>_*f)+","+(this._x1=t+T*h)+","+(this._y1=n+T*r)}else this._+="L"+(this._x1=t)+","+(this._y1=n);else;},arc:function(t,n,i,e,s,o){t=+t,n=+n,o=!!o;var a=(i=+i)*Math.cos(e),h=i*Math.sin(e),r=t+a,_=n+h,l=1^o,c=o?e-s:s-e;if(i<0)throw new Error("negative radius: "+i);null===this._x1?this._+="M"+r+","+_:(Math.abs(this._x1-r)>epsilon||Math.abs(this._y1-_)>epsilon)&&(this._+="L"+r+","+_),i&&(c<0&&(c=c%tau+tau),c>tauEpsilon?this._+="A"+i+","+i+",0,1,"+l+","+(t-a)+","+(n-h)+"A"+i+","+i+",0,1,"+l+","+(this._x1=r)+","+(this._y1=_):c>epsilon&&(this._+="A"+i+","+i+",0,"+ +(c>=pi)+","+l+","+(this._x1=t+i*Math.cos(s))+","+(this._y1=n+i*Math.sin(s))))},rect:function(t,n,i,e){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+n)+"h"+ +i+"v"+ +e+"h"+-i+"Z"},toString:function(){return this._}};var abs=Math.abs,atan2=Math.atan2,cos=Math.cos,max=Math.max,min=Math.min,sin=Math.sin,sqrt=Math.sqrt,epsilon$1=1e-12,pi$1=Math.PI,halfPi=pi$1/2,tau$1=2*pi$1;function acos(t){return t>1?0:t<-1?pi$1:Math.acos(t)}function asin(t){return t>=1?halfPi:t<=-1?-halfPi:Math.asin(t)}function arcInnerRadius(t){return t.innerRadius}function arcOuterRadius(t){return t.outerRadius}function arcStartAngle(t){return t.startAngle}function arcEndAngle(t){return t.endAngle}function arcPadAngle(t){return t&&t.padAngle}function intersect(t,n,i,e,s,o,a,h){var r=i-t,_=e-n,l=a-s,c=h-o,u=c*r-l*_;if(!(u*u<epsilon$1))return[t+(u=(l*(n-o)-c*(t-s))/u)*r,n+u*_]}function cornerTangents(t,n,i,e,s,o,a){var h=t-i,r=n-e,_=(a?o:-o)/sqrt(h*h+r*r),l=_*r,c=-_*h,u=t+l,f=n+c,p=i+l,x=e+c,y=(u+p)/2,d=(f+x)/2,v=p-u,g=x-f,T=v*v+g*g,m=s-o,b=u*x-p*f,k=(g<0?-1:1)*sqrt(max(0,m*m*T-b*b)),w=(b*g-v*k)/T,M=(-b*v-g*k)/T,C=(b*g+v*k)/T,R=(-b*v+g*k)/T,$=w-y,S=M-d,N=C-y,E=R-d;return $*$+S*S>N*N+E*E&&(w=C,M=R),{cx:w,cy:M,x01:-l,y01:-c,x11:w*(s/m-1),y11:M*(s/m-1)}}function arc(){var t=arcInnerRadius,n=arcOuterRadius,i=constant(0),e=null,s=arcStartAngle,o=arcEndAngle,a=arcPadAngle,h=null;function r(){var r,_,l=+t.apply(this,arguments),c=+n.apply(this,arguments),u=s.apply(this,arguments)-halfPi,f=o.apply(this,arguments)-halfPi,p=abs(f-u),x=f>u;if(h||(h=r=path()),c<l&&(_=c,c=l,l=_),c>epsilon$1)if(p>tau$1-epsilon$1)h.moveTo(c*cos(u),c*sin(u)),h.arc(0,0,c,u,f,!x),l>epsilon$1&&(h.moveTo(l*cos(f),l*sin(f)),h.arc(0,0,l,f,u,x));else{var y,d,v=u,g=f,T=u,m=f,b=p,k=p,w=a.apply(this,arguments)/2,M=w>epsilon$1&&(e?+e.apply(this,arguments):sqrt(l*l+c*c)),C=min(abs(c-l)/2,+i.apply(this,arguments)),R=C,$=C;if(M>epsilon$1){var S=asin(M/l*sin(w)),N=asin(M/c*sin(w));(b-=2*S)>epsilon$1?(T+=S*=x?1:-1,m-=S):(b=0,T=m=(u+f)/2),(k-=2*N)>epsilon$1?(v+=N*=x?1:-1,g-=N):(k=0,v=g=(u+f)/2)}var E=c*cos(v),A=c*sin(v),P=l*cos(m),O=l*sin(m);if(C>epsilon$1){var q,B=c*cos(g),L=c*sin(g),z=l*cos(T),X=l*sin(T);if(p<pi$1&&(q=intersect(E,A,z,X,B,L,P,O))){var Y=E-q[0],I=A-q[1],V=B-q[0],H=L-q[1],D=1/sin(acos((Y*V+I*H)/(sqrt(Y*Y+I*I)*sqrt(V*V+H*H)))/2),W=sqrt(q[0]*q[0]+q[1]*q[1]);R=min(C,(l-W)/(D-1)),$=min(C,(c-W)/(D+1))}}k>epsilon$1?$>epsilon$1?(y=cornerTangents(z,X,E,A,c,$,x),d=cornerTangents(B,L,P,O,c,$,x),h.moveTo(y.cx+y.x01,y.cy+y.y01),$<C?h.arc(y.cx,y.cy,$,atan2(y.y01,y.x01),atan2(d.y01,d.x01),!x):(h.arc(y.cx,y.cy,$,atan2(y.y01,y.x01),atan2(y.y11,y.x11),!x),h.arc(0,0,c,atan2(y.cy+y.y11,y.cx+y.x11),atan2(d.cy+d.y11,d.cx+d.x11),!x),h.arc(d.cx,d.cy,$,atan2(d.y11,d.x11),atan2(d.y01,d.x01),!x))):(h.moveTo(E,A),h.arc(0,0,c,v,g,!x)):h.moveTo(E,A),l>epsilon$1&&b>epsilon$1?R>epsilon$1?(y=cornerTangents(P,O,B,L,l,-R,x),d=cornerTangents(E,A,z,X,l,-R,x),h.lineTo(y.cx+y.x01,y.cy+y.y01),R<C?h.arc(y.cx,y.cy,R,atan2(y.y01,y.x01),atan2(d.y01,d.x01),!x):(h.arc(y.cx,y.cy,R,atan2(y.y01,y.x01),atan2(y.y11,y.x11),!x),h.arc(0,0,l,atan2(y.cy+y.y11,y.cx+y.x11),atan2(d.cy+d.y11,d.cx+d.x11),x),h.arc(d.cx,d.cy,R,atan2(d.y11,d.x11),atan2(d.y01,d.x01),!x))):h.arc(0,0,l,m,T,x):h.lineTo(P,O)}else h.moveTo(0,0);if(h.closePath(),r)return h=null,r+""||null}return r.centroid=function(){var i=(+t.apply(this,arguments)+ +n.apply(this,arguments))/2,e=(+s.apply(this,arguments)+ +o.apply(this,arguments))/2-pi$1/2;return[cos(e)*i,sin(e)*i]},r.innerRadius=function(n){return arguments.length?(t="function"==typeof n?n:constant(+n),r):t},r.outerRadius=function(t){return arguments.length?(n="function"==typeof t?t:constant(+t),r):n},r.cornerRadius=function(t){return arguments.length?(i="function"==typeof t?t:constant(+t),r):i},r.padRadius=function(t){return arguments.length?(e=null==t?null:"function"==typeof t?t:constant(+t),r):e},r.startAngle=function(t){return arguments.length?(s="function"==typeof t?t:constant(+t),r):s},r.endAngle=function(t){return arguments.length?(o="function"==typeof t?t:constant(+t),r):o},r.padAngle=function(t){return arguments.length?(a="function"==typeof t?t:constant(+t),r):a},r.context=function(t){return arguments.length?(h=null==t?null:t,r):h},r}function Linear(t){this._context=t}function curveLinear(t){return new Linear(t)}function x(t){return t[0]}function y(t){return t[1]}function line(){var t=x,n=y,i=constant(!0),e=null,s=curveLinear,o=null;function a(a){var h,r,_,l=a.length,c=!1;for(null==e&&(o=s(_=path())),h=0;h<=l;++h)!(h<l&&i(r=a[h],h,a))===c&&((c=!c)?o.lineStart():o.lineEnd()),c&&o.point(+t(r,h,a),+n(r,h,a));if(_)return o=null,_+""||null}return a.x=function(n){return arguments.length?(t="function"==typeof n?n:constant(+n),a):t},a.y=function(t){return arguments.length?(n="function"==typeof t?t:constant(+t),a):n},a.defined=function(t){return arguments.length?(i="function"==typeof t?t:constant(!!t),a):i},a.curve=function(t){return arguments.length?(s=t,null!=e&&(o=s(e)),a):s},a.context=function(t){return arguments.length?(null==t?e=o=null:o=s(e=t),a):e},a}function area(){var t=x,n=null,i=constant(0),e=y,s=constant(!0),o=null,a=curveLinear,h=null;function r(r){var _,l,c,u,f,p=r.length,x=!1,y=new Array(p),d=new Array(p);for(null==o&&(h=a(f=path())),_=0;_<=p;++_){if(!(_<p&&s(u=r[_],_,r))===x)if(x=!x)l=_,h.areaStart(),h.lineStart();else{for(h.lineEnd(),h.lineStart(),c=_-1;c>=l;--c)h.point(y[c],d[c]);h.lineEnd(),h.areaEnd()}x&&(y[_]=+t(u,_,r),d[_]=+i(u,_,r),h.point(n?+n(u,_,r):y[_],e?+e(u,_,r):d[_]))}if(f)return h=null,f+""||null}function _(){return line().defined(s).curve(a).context(o)}return r.x=function(i){return arguments.length?(t="function"==typeof i?i:constant(+i),n=null,r):t},r.x0=function(n){return arguments.length?(t="function"==typeof n?n:constant(+n),r):t},r.x1=function(t){return arguments.length?(n=null==t?null:"function"==typeof t?t:constant(+t),r):n},r.y=function(t){return arguments.length?(i="function"==typeof t?t:constant(+t),e=null,r):i},r.y0=function(t){return arguments.length?(i="function"==typeof t?t:constant(+t),r):i},r.y1=function(t){return arguments.length?(e=null==t?null:"function"==typeof t?t:constant(+t),r):e},r.lineX0=r.lineY0=function(){return _().x(t).y(i)},r.lineY1=function(){return _().x(t).y(e)},r.lineX1=function(){return _().x(n).y(i)},r.defined=function(t){return arguments.length?(s="function"==typeof t?t:constant(!!t),r):s},r.curve=function(t){return arguments.length?(a=t,null!=o&&(h=a(o)),r):a},r.context=function(t){return arguments.length?(null==t?o=h=null:h=a(o=t),r):o},r}function descending(t,n){return n<t?-1:n>t?1:n>=t?0:NaN}function identity(t){return t}function pie(){var t=identity,n=descending,i=null,e=constant(0),s=constant(tau$1),o=constant(0);function a(a){var h,r,_,l,c,u=a.length,f=0,p=new Array(u),x=new Array(u),y=+e.apply(this,arguments),d=Math.min(tau$1,Math.max(-tau$1,s.apply(this,arguments)-y)),v=Math.min(Math.abs(d)/u,o.apply(this,arguments)),g=v*(d<0?-1:1);for(h=0;h<u;++h)(c=x[p[h]=h]=+t(a[h],h,a))>0&&(f+=c);for(null!=n?p.sort((function(t,i){return n(x[t],x[i])})):null!=i&&p.sort((function(t,n){return i(a[t],a[n])})),h=0,_=f?(d-u*g)/f:0;h<u;++h,y=l)r=p[h],l=y+((c=x[r])>0?c*_:0)+g,x[r]={data:a[r],index:h,value:c,startAngle:y,endAngle:l,padAngle:v};return x}return a.value=function(n){return arguments.length?(t="function"==typeof n?n:constant(+n),a):t},a.sortValues=function(t){return arguments.length?(n=t,i=null,a):n},a.sort=function(t){return arguments.length?(i=t,n=null,a):i},a.startAngle=function(t){return arguments.length?(e="function"==typeof t?t:constant(+t),a):e},a.endAngle=function(t){return arguments.length?(s="function"==typeof t?t:constant(+t),a):s},a.padAngle=function(t){return arguments.length?(o="function"==typeof t?t:constant(+t),a):o},a}Linear.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;default:this._context.lineTo(t,n)}}};var curveRadialLinear=curveRadial(curveLinear);function Radial(t){this._curve=t}function curveRadial(t){function n(n){return new Radial(t(n))}return n._curve=t,n}function lineRadial(t){var n=t.curve;return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t.curve=function(t){return arguments.length?n(curveRadial(t)):n()._curve},t}function lineRadial$1(){return lineRadial(line().curve(curveRadialLinear))}function areaRadial(){var t=area().curve(curveRadialLinear),n=t.curve,i=t.lineX0,e=t.lineX1,s=t.lineY0,o=t.lineY1;return t.angle=t.x,delete t.x,t.startAngle=t.x0,delete t.x0,t.endAngle=t.x1,delete t.x1,t.radius=t.y,delete t.y,t.innerRadius=t.y0,delete t.y0,t.outerRadius=t.y1,delete t.y1,t.lineStartAngle=function(){return lineRadial(i())},delete t.lineX0,t.lineEndAngle=function(){return lineRadial(e())},delete t.lineX1,t.lineInnerRadius=function(){return lineRadial(s())},delete t.lineY0,t.lineOuterRadius=function(){return lineRadial(o())},delete t.lineY1,t.curve=function(t){return arguments.length?n(curveRadial(t)):n()._curve},t}function pointRadial(t,n){return[(n=+n)*Math.cos(t-=Math.PI/2),n*Math.sin(t)]}Radial.prototype={areaStart:function(){this._curve.areaStart()},areaEnd:function(){this._curve.areaEnd()},lineStart:function(){this._curve.lineStart()},lineEnd:function(){this._curve.lineEnd()},point:function(t,n){this._curve.point(n*Math.sin(t),n*-Math.cos(t))}};var slice=Array.prototype.slice;function linkSource(t){return t.source}function linkTarget(t){return t.target}function link(t){var n=linkSource,i=linkTarget,e=x,s=y,o=null;function a(){var a,h=slice.call(arguments),r=n.apply(this,h),_=i.apply(this,h);if(o||(o=a=path()),t(o,+e.apply(this,(h[0]=r,h)),+s.apply(this,h),+e.apply(this,(h[0]=_,h)),+s.apply(this,h)),a)return o=null,a+""||null}return a.source=function(t){return arguments.length?(n=t,a):n},a.target=function(t){return arguments.length?(i=t,a):i},a.x=function(t){return arguments.length?(e="function"==typeof t?t:constant(+t),a):e},a.y=function(t){return arguments.length?(s="function"==typeof t?t:constant(+t),a):s},a.context=function(t){return arguments.length?(o=null==t?null:t,a):o},a}function curveHorizontal(t,n,i,e,s){t.moveTo(n,i),t.bezierCurveTo(n=(n+e)/2,i,n,s,e,s)}function curveVertical(t,n,i,e,s){t.moveTo(n,i),t.bezierCurveTo(n,i=(i+s)/2,e,i,e,s)}function curveRadial$1(t,n,i,e,s){var o=pointRadial(n,i),a=pointRadial(n,i=(i+s)/2),h=pointRadial(e,i),r=pointRadial(e,s);t.moveTo(o[0],o[1]),t.bezierCurveTo(a[0],a[1],h[0],h[1],r[0],r[1])}function linkHorizontal(){return link(curveHorizontal)}function linkVertical(){return link(curveVertical)}function linkRadial(){var t=link(curveRadial$1);return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t}var circle={draw:function(t,n){var i=Math.sqrt(n/pi$1);t.moveTo(i,0),t.arc(0,0,i,0,tau$1)}},cross={draw:function(t,n){var i=Math.sqrt(n/5)/2;t.moveTo(-3*i,-i),t.lineTo(-i,-i),t.lineTo(-i,-3*i),t.lineTo(i,-3*i),t.lineTo(i,-i),t.lineTo(3*i,-i),t.lineTo(3*i,i),t.lineTo(i,i),t.lineTo(i,3*i),t.lineTo(-i,3*i),t.lineTo(-i,i),t.lineTo(-3*i,i),t.closePath()}},tan30=Math.sqrt(1/3),tan30_2=2*tan30,diamond={draw:function(t,n){var i=Math.sqrt(n/tan30_2),e=i*tan30;t.moveTo(0,-i),t.lineTo(e,0),t.lineTo(0,i),t.lineTo(-e,0),t.closePath()}},ka=.8908130915292852,kr=Math.sin(pi$1/10)/Math.sin(7*pi$1/10),kx=Math.sin(tau$1/10)*kr,ky=-Math.cos(tau$1/10)*kr,star={draw:function(t,n){var i=Math.sqrt(n*ka),e=kx*i,s=ky*i;t.moveTo(0,-i),t.lineTo(e,s);for(var o=1;o<5;++o){var a=tau$1*o/5,h=Math.cos(a),r=Math.sin(a);t.lineTo(r*i,-h*i),t.lineTo(h*e-r*s,r*e+h*s)}t.closePath()}},square={draw:function(t,n){var i=Math.sqrt(n),e=-i/2;t.rect(e,e,i,i)}},sqrt3=Math.sqrt(3),triangle={draw:function(t,n){var i=-Math.sqrt(n/(3*sqrt3));t.moveTo(0,2*i),t.lineTo(-sqrt3*i,-i),t.lineTo(sqrt3*i,-i),t.closePath()}},c=-.5,s=Math.sqrt(3)/2,k=1/Math.sqrt(12),a=3*(k/2+1),wye={draw:function(t,n){var i=Math.sqrt(n/a),e=i/2,o=i*k,h=e,r=i*k+i,_=-h,l=r;t.moveTo(e,o),t.lineTo(h,r),t.lineTo(_,l),t.lineTo(c*e-s*o,s*e+c*o),t.lineTo(c*h-s*r,s*h+c*r),t.lineTo(c*_-s*l,s*_+c*l),t.lineTo(c*e+s*o,c*o-s*e),t.lineTo(c*h+s*r,c*r-s*h),t.lineTo(c*_+s*l,c*l-s*_),t.closePath()}},symbols=[circle,cross,diamond,square,star,triangle,wye];function symbol(){var t=constant(circle),n=constant(64),i=null;function e(){var e;if(i||(i=e=path()),t.apply(this,arguments).draw(i,+n.apply(this,arguments)),e)return i=null,e+""||null}return e.type=function(n){return arguments.length?(t="function"==typeof n?n:constant(n),e):t},e.size=function(t){return arguments.length?(n="function"==typeof t?t:constant(+t),e):n},e.context=function(t){return arguments.length?(i=null==t?null:t,e):i},e}function noop(){}function point(t,n,i){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+n)/6,(t._y0+4*t._y1+i)/6)}function Basis(t){this._context=t}function basis(t){return new Basis(t)}function BasisClosed(t){this._context=t}function basisClosed(t){return new BasisClosed(t)}function BasisOpen(t){this._context=t}function basisOpen(t){return new BasisOpen(t)}function Bundle(t,n){this._basis=new Basis(t),this._beta=n}Basis.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:point(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:point(this,t,n)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=n}},BasisClosed.prototype={areaStart:noop,areaEnd:noop,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x2,this._y2),this._context.closePath();break;case 2:this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break;case 3:this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4)}},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._x2=t,this._y2=n;break;case 1:this._point=2,this._x3=t,this._y3=n;break;case 2:this._point=3,this._x4=t,this._y4=n,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+n)/6);break;default:point(this,t,n)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=n}},BasisOpen.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var i=(this._x0+4*this._x1+t)/6,e=(this._y0+4*this._y1+n)/6;this._line?this._context.lineTo(i,e):this._context.moveTo(i,e);break;case 3:this._point=4;default:point(this,t,n)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=n}},Bundle.prototype={lineStart:function(){this._x=[],this._y=[],this._basis.lineStart()},lineEnd:function(){var t=this._x,n=this._y,i=t.length-1;if(i>0)for(var e,s=t[0],o=n[0],a=t[i]-s,h=n[i]-o,r=-1;++r<=i;)e=r/i,this._basis.point(this._beta*t[r]+(1-this._beta)*(s+e*a),this._beta*n[r]+(1-this._beta)*(o+e*h));this._x=this._y=null,this._basis.lineEnd()},point:function(t,n){this._x.push(+t),this._y.push(+n)}};var bundle=function t(n){function i(t){return 1===n?new Basis(t):new Bundle(t,n)}return i.beta=function(n){return t(+n)},i}(.85);function point$1(t,n,i){t._context.bezierCurveTo(t._x1+t._k*(t._x2-t._x0),t._y1+t._k*(t._y2-t._y0),t._x2+t._k*(t._x1-n),t._y2+t._k*(t._y1-i),t._x2,t._y2)}function Cardinal(t,n){this._context=t,this._k=(1-n)/6}Cardinal.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:point$1(this,this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2,this._x1=t,this._y1=n;break;case 2:this._point=3;default:point$1(this,t,n)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var cardinal=function t(n){function i(t){return new Cardinal(t,n)}return i.tension=function(n){return t(+n)},i}(0);function CardinalClosed(t,n){this._context=t,this._k=(1-n)/6}CardinalClosed.prototype={areaStart:noop,areaEnd:noop,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._x3=t,this._y3=n;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=n);break;case 2:this._point=3,this._x5=t,this._y5=n;break;default:point$1(this,t,n)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var cardinalClosed=function t(n){function i(t){return new CardinalClosed(t,n)}return i.tension=function(n){return t(+n)},i}(0);function CardinalOpen(t,n){this._context=t,this._k=(1-n)/6}CardinalOpen.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:point$1(this,t,n)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var cardinalOpen=function t(n){function i(t){return new CardinalOpen(t,n)}return i.tension=function(n){return t(+n)},i}(0);function point$2(t,n,i){var e=t._x1,s=t._y1,o=t._x2,a=t._y2;if(t._l01_a>epsilon$1){var h=2*t._l01_2a+3*t._l01_a*t._l12_a+t._l12_2a,r=3*t._l01_a*(t._l01_a+t._l12_a);e=(e*h-t._x0*t._l12_2a+t._x2*t._l01_2a)/r,s=(s*h-t._y0*t._l12_2a+t._y2*t._l01_2a)/r}if(t._l23_a>epsilon$1){var _=2*t._l23_2a+3*t._l23_a*t._l12_a+t._l12_2a,l=3*t._l23_a*(t._l23_a+t._l12_a);o=(o*_+t._x1*t._l23_2a-n*t._l12_2a)/l,a=(a*_+t._y1*t._l23_2a-i*t._l12_2a)/l}t._context.bezierCurveTo(e,s,o,a,t._x2,t._y2)}function CatmullRom(t,n){this._context=t,this._alpha=n}CatmullRom.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:this.point(this._x2,this._y2)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){if(t=+t,n=+n,this._point){var i=this._x2-t,e=this._y2-n;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(i*i+e*e,this._alpha))}switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;break;case 2:this._point=3;default:point$2(this,t,n)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var catmullRom=function t(n){function i(t){return n?new CatmullRom(t,n):new Cardinal(t,0)}return i.alpha=function(n){return t(+n)},i}(.5);function CatmullRomClosed(t,n){this._context=t,this._alpha=n}CatmullRomClosed.prototype={areaStart:noop,areaEnd:noop,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,n){if(t=+t,n=+n,this._point){var i=this._x2-t,e=this._y2-n;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(i*i+e*e,this._alpha))}switch(this._point){case 0:this._point=1,this._x3=t,this._y3=n;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=n);break;case 2:this._point=3,this._x5=t,this._y5=n;break;default:point$2(this,t,n)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var catmullRomClosed=function t(n){function i(t){return n?new CatmullRomClosed(t,n):new CardinalClosed(t,0)}return i.alpha=function(n){return t(+n)},i}(.5);function CatmullRomOpen(t,n){this._context=t,this._alpha=n}CatmullRomOpen.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){if(t=+t,n=+n,this._point){var i=this._x2-t,e=this._y2-n;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(i*i+e*e,this._alpha))}switch(this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:point$2(this,t,n)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var catmullRomOpen=function t(n){function i(t){return n?new CatmullRomOpen(t,n):new CardinalOpen(t,0)}return i.alpha=function(n){return t(+n)},i}(.5);function LinearClosed(t){this._context=t}function linearClosed(t){return new LinearClosed(t)}function sign(t){return t<0?-1:1}function slope3(t,n,i){var e=t._x1-t._x0,s=n-t._x1,o=(t._y1-t._y0)/(e||s<0&&-0),a=(i-t._y1)/(s||e<0&&-0),h=(o*s+a*e)/(e+s);return(sign(o)+sign(a))*Math.min(Math.abs(o),Math.abs(a),.5*Math.abs(h))||0}function slope2(t,n){var i=t._x1-t._x0;return i?(3*(t._y1-t._y0)/i-n)/2:n}function point$3(t,n,i){var e=t._x0,s=t._y0,o=t._x1,a=t._y1,h=(o-e)/3;t._context.bezierCurveTo(e+h,s+h*n,o-h,a-h*i,o,a)}function MonotoneX(t){this._context=t}function MonotoneY(t){this._context=new ReflectContext(t)}function ReflectContext(t){this._context=t}function monotoneX(t){return new MonotoneX(t)}function monotoneY(t){return new MonotoneY(t)}function Natural(t){this._context=t}function controlPoints(t){var n,i,e=t.length-1,s=new Array(e),o=new Array(e),a=new Array(e);for(s[0]=0,o[0]=2,a[0]=t[0]+2*t[1],n=1;n<e-1;++n)s[n]=1,o[n]=4,a[n]=4*t[n]+2*t[n+1];for(s[e-1]=2,o[e-1]=7,a[e-1]=8*t[e-1]+t[e],n=1;n<e;++n)i=s[n]/o[n-1],o[n]-=i,a[n]-=i*a[n-1];for(s[e-1]=a[e-1]/o[e-1],n=e-2;n>=0;--n)s[n]=(a[n]-s[n+1])/o[n];for(o[e-1]=(t[e]+s[e-1])/2,n=0;n<e-1;++n)o[n]=2*t[n+1]-s[n+1];return[s,o]}function natural(t){return new Natural(t)}function Step(t,n){this._context=t,this._t=n}function step(t){return new Step(t,.5)}function stepBefore(t){return new Step(t,0)}function stepAfter(t){return new Step(t,1)}function none(t,n){if((s=t.length)>1)for(var i,e,s,o=1,a=t[n[0]],h=a.length;o<s;++o)for(e=a,a=t[n[o]],i=0;i<h;++i)a[i][1]+=a[i][0]=isNaN(e[i][1])?e[i][0]:e[i][1]}function none$1(t){for(var n=t.length,i=new Array(n);--n>=0;)i[n]=n;return i}function stackValue(t,n){return t[n]}function stack(){var t=constant([]),n=none$1,i=none,e=stackValue;function s(s){var o,a,h=t.apply(this,arguments),r=s.length,_=h.length,l=new Array(_);for(o=0;o<_;++o){for(var c,u=h[o],f=l[o]=new Array(r),p=0;p<r;++p)f[p]=c=[0,+e(s[p],u,p,s)],c.data=s[p];f.key=u}for(o=0,a=n(l);o<_;++o)l[a[o]].index=o;return i(l,a),l}return s.keys=function(n){return arguments.length?(t="function"==typeof n?n:constant(slice.call(n)),s):t},s.value=function(t){return arguments.length?(e="function"==typeof t?t:constant(+t),s):e},s.order=function(t){return arguments.length?(n=null==t?none$1:"function"==typeof t?t:constant(slice.call(t)),s):n},s.offset=function(t){return arguments.length?(i=null==t?none:t,s):i},s}function expand(t,n){if((e=t.length)>0){for(var i,e,s,o=0,a=t[0].length;o<a;++o){for(s=i=0;i<e;++i)s+=t[i][o][1]||0;if(s)for(i=0;i<e;++i)t[i][o][1]/=s}none(t,n)}}function diverging(t,n){if((h=t.length)>0)for(var i,e,s,o,a,h,r=0,_=t[n[0]].length;r<_;++r)for(o=a=0,i=0;i<h;++i)(s=(e=t[n[i]][r])[1]-e[0])>0?(e[0]=o,e[1]=o+=s):s<0?(e[1]=a,e[0]=a+=s):(e[0]=0,e[1]=s)}function silhouette(t,n){if((i=t.length)>0){for(var i,e=0,s=t[n[0]],o=s.length;e<o;++e){for(var a=0,h=0;a<i;++a)h+=t[a][e][1]||0;s[e][1]+=s[e][0]=-h/2}none(t,n)}}function wiggle(t,n){if((s=t.length)>0&&(e=(i=t[n[0]]).length)>0){for(var i,e,s,o=0,a=1;a<e;++a){for(var h=0,r=0,_=0;h<s;++h){for(var l=t[n[h]],c=l[a][1]||0,u=(c-(l[a-1][1]||0))/2,f=0;f<h;++f){var p=t[n[f]];u+=(p[a][1]||0)-(p[a-1][1]||0)}r+=c,_+=u*c}i[a-1][1]+=i[a-1][0]=o,r&&(o-=_/r)}i[a-1][1]+=i[a-1][0]=o,none(t,n)}}function appearance(t){var n=t.map(peak);return none$1(t).sort((function(t,i){return n[t]-n[i]}))}function peak(t){for(var n,i=-1,e=0,s=t.length,o=-1/0;++i<s;)(n=+t[i][1])>o&&(o=n,e=i);return e}function ascending(t){var n=t.map(sum);return none$1(t).sort((function(t,i){return n[t]-n[i]}))}function sum(t){for(var n,i=0,e=-1,s=t.length;++e<s;)(n=+t[e][1])&&(i+=n);return i}function descending$1(t){return ascending(t).reverse()}function insideOut(t){var n,i,e=t.length,s=t.map(sum),o=appearance(t),a=0,h=0,r=[],_=[];for(n=0;n<e;++n)i=o[n],a<h?(a+=s[i],r.push(i)):(h+=s[i],_.push(i));return _.reverse().concat(r)}function reverse(t){return none$1(t).reverse()}LinearClosed.prototype={areaStart:noop,areaEnd:noop,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(t,n){t=+t,n=+n,this._point?this._context.lineTo(t,n):(this._point=1,this._context.moveTo(t,n))}},MonotoneX.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:point$3(this,this._t0,slope2(this,this._t0))}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){var i=NaN;if(n=+n,(t=+t)!==this._x1||n!==this._y1){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;break;case 2:this._point=3,point$3(this,slope2(this,i=slope3(this,t,n)),i);break;default:point$3(this,this._t0,i=slope3(this,t,n))}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=n,this._t0=i}}},(MonotoneY.prototype=Object.create(MonotoneX.prototype)).point=function(t,n){MonotoneX.prototype.point.call(this,n,t)},ReflectContext.prototype={moveTo:function(t,n){this._context.moveTo(n,t)},closePath:function(){this._context.closePath()},lineTo:function(t,n){this._context.lineTo(n,t)},bezierCurveTo:function(t,n,i,e,s,o){this._context.bezierCurveTo(n,t,e,i,o,s)}},Natural.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var t=this._x,n=this._y,i=t.length;if(i)if(this._line?this._context.lineTo(t[0],n[0]):this._context.moveTo(t[0],n[0]),2===i)this._context.lineTo(t[1],n[1]);else for(var e=controlPoints(t),s=controlPoints(n),o=0,a=1;a<i;++o,++a)this._context.bezierCurveTo(e[0][o],s[0][o],e[1][o],s[1][o],t[a],n[a]);(this._line||0!==this._line&&1===i)&&this._context.closePath(),this._line=1-this._line,this._x=this._y=null},point:function(t,n){this._x.push(+t),this._y.push(+n)}},Step.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&2===this._point&&this._context.lineTo(this._x,this._y),(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,n),this._context.lineTo(t,n);else{var i=this._x*(1-this._t)+t*this._t;this._context.lineTo(i,this._y),this._context.lineTo(i,n)}}this._x=t,this._y=n}};export{arc,area,areaRadial,basis as curveBasis,basisClosed as curveBasisClosed,basisOpen as curveBasisOpen,bundle as curveBundle,cardinal as curveCardinal,cardinalClosed as curveCardinalClosed,cardinalOpen as curveCardinalOpen,catmullRom as curveCatmullRom,catmullRomClosed as curveCatmullRomClosed,catmullRomOpen as curveCatmullRomOpen,curveLinear,linearClosed as curveLinearClosed,monotoneX as curveMonotoneX,monotoneY as curveMonotoneY,natural as curveNatural,step as curveStep,stepAfter as curveStepAfter,stepBefore as curveStepBefore,line,lineRadial$1 as lineRadial,linkHorizontal,linkRadial,linkVertical,pie,pointRadial,areaRadial as radialArea,lineRadial$1 as radialLine,stack,diverging as stackOffsetDiverging,expand as stackOffsetExpand,none as stackOffsetNone,silhouette as stackOffsetSilhouette,wiggle as stackOffsetWiggle,appearance as stackOrderAppearance,ascending as stackOrderAscending,descending$1 as stackOrderDescending,insideOut as stackOrderInsideOut,none$1 as stackOrderNone,reverse as stackOrderReverse,symbol,circle as symbolCircle,cross as symbolCross,diamond as symbolDiamond,square as symbolSquare,star as symbolStar,triangle as symbolTriangle,wye as symbolWye,symbols};