@groww-tech/react-charts
Version:
React charts library tailored as per Groww needs
2 lines (1 loc) • 9.92 kB
JavaScript
var n=Math.PI,t=2*n,i=1e-6,e=t-i;function u(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function r(){return new u}function l(n){return function(){return n}}u.prototype=r.prototype={constructor:u,moveTo:function(n,t){this._+="M"+(this._x0=this._x1=+n)+","+(this._y0=this._y1=+t)},closePath:function(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")},lineTo:function(n,t){this._+="L"+(this._x1=+n)+","+(this._y1=+t)},quadraticCurveTo:function(n,t,i,e){this._+="Q"+ +n+","+ +t+","+(this._x1=+i)+","+(this._y1=+e)},bezierCurveTo:function(n,t,i,e,u,r){this._+="C"+ +n+","+ +t+","+ +i+","+ +e+","+(this._x1=+u)+","+(this._y1=+r)},arcTo:function(t,e,u,r,l){t=+t,e=+e,u=+u,r=+r,l=+l;var o=this._x1,c=this._y1,a=u-t,s=r-e,h=o-t,f=c-e,y=h*h+f*f;if(l<0)throw new Error("negative radius: "+l);if(null===this._x1)this._+="M"+(this._x1=t)+","+(this._y1=e);else if(y>i)if(Math.abs(f*a-s*h)>i&&l){var x=u-o,p=r-c,_=a*a+s*s,d=x*x+p*p,g=Math.sqrt(_),v=Math.sqrt(y),A=l*Math.tan((n-Math.acos((_+y-d)/(2*g*v)))/2),M=A/v,T=A/g;Math.abs(M-1)>i&&(this._+="L"+(t+M*h)+","+(e+M*f)),this._+="A"+l+","+l+",0,0,"+ +(f*x>h*p)+","+(this._x1=t+T*a)+","+(this._y1=e+T*s)}else this._+="L"+(this._x1=t)+","+(this._y1=e);else;},arc:function(u,r,l,o,c,a){u=+u,r=+r,a=!!a;var s=(l=+l)*Math.cos(o),h=l*Math.sin(o),f=u+s,y=r+h,x=1^a,p=a?o-c:c-o;if(l<0)throw new Error("negative radius: "+l);null===this._x1?this._+="M"+f+","+y:(Math.abs(this._x1-f)>i||Math.abs(this._y1-y)>i)&&(this._+="L"+f+","+y),l&&(p<0&&(p=p%t+t),p>e?this._+="A"+l+","+l+",0,1,"+x+","+(u-s)+","+(r-h)+"A"+l+","+l+",0,1,"+x+","+(this._x1=f)+","+(this._y1=y):p>i&&(this._+="A"+l+","+l+",0,"+ +(p>=n)+","+x+","+(this._x1=u+l*Math.cos(c))+","+(this._y1=r+l*Math.sin(c))))},rect:function(n,t,i,e){this._+="M"+(this._x0=this._x1=+n)+","+(this._y0=this._y1=+t)+"h"+ +i+"v"+ +e+"h"+-i+"Z"},toString:function(){return this._}};var o=Math.abs,c=Math.atan2,a=Math.cos,s=Math.max,h=Math.min,f=Math.sin,y=Math.sqrt,x=1e-12,p=Math.PI,_=p/2,d=2*p;function g(n){return n>=1?_:n<=-1?-_:Math.asin(n)}function v(n){return n.innerRadius}function A(n){return n.outerRadius}function M(n){return n.startAngle}function T(n){return n.endAngle}function R(n){return n&&n.padAngle}function m(n,t,i,e,u,r,l){var o=n-i,c=t-e,a=(l?r:-r)/y(o*o+c*c),h=a*c,f=-a*o,x=n+h,p=t+f,_=i+h,d=e+f,g=(x+_)/2,v=(p+d)/2,A=_-x,M=d-p,T=A*A+M*M,R=u-r,m=x*d-_*p,w=(M<0?-1:1)*y(s(0,R*R*T-m*m)),b=(m*M-A*w)/T,E=(-m*A-M*w)/T,S=(m*M+A*w)/T,P=(-m*A+M*w)/T,q=b-g,L=E-v,N=S-g,C=P-v;return q*q+L*L>N*N+C*C&&(b=S,E=P),{cx:b,cy:E,x01:-h,y01:-f,x11:b*(u/R-1),y11:E*(u/R-1)}}function w(){var n=v,t=A,i=l(0),e=null,u=M,s=T,w=R,b=null;function E(){var l,v,A=+n.apply(this,arguments),M=+t.apply(this,arguments),T=u.apply(this,arguments)-_,R=s.apply(this,arguments)-_,E=o(R-T),S=R>T;if(b||(b=l=r()),M<A&&(v=M,M=A,A=v),M>x)if(E>d-x)b.moveTo(M*a(T),M*f(T)),b.arc(0,0,M,T,R,!S),A>x&&(b.moveTo(A*a(R),A*f(R)),b.arc(0,0,A,R,T,S));else{var P,q,L=T,N=R,C=T,V=R,I=E,X=E,Y=w.apply(this,arguments)/2,Z=Y>x&&(e?+e.apply(this,arguments):y(A*A+M*M)),k=h(o(M-A)/2,+i.apply(this,arguments)),z=k,Q=k;if(Z>x){var j=g(Z/A*f(Y)),B=g(Z/M*f(Y));(I-=2*j)>x?(C+=j*=S?1:-1,V-=j):(I=0,C=V=(T+R)/2),(X-=2*B)>x?(L+=B*=S?1:-1,N-=B):(X=0,L=N=(T+R)/2)}var D=M*a(L),F=M*f(L),G=A*a(V),H=A*f(V);if(k>x){var J,K=M*a(N),O=M*f(N),U=A*a(C),W=A*f(C);if(E<p&&(J=function(n,t,i,e,u,r,l,o){var c=i-n,a=e-t,s=l-u,h=o-r,f=h*c-s*a;if(!(f*f<x))return[n+(f=(s*(t-r)-h*(n-u))/f)*c,t+f*a]}(D,F,U,W,K,O,G,H))){var $=D-J[0],nn=F-J[1],tn=K-J[0],en=O-J[1],un=1/f(function(n){return n>1?0:n<-1?p:Math.acos(n)}(($*tn+nn*en)/(y($*$+nn*nn)*y(tn*tn+en*en)))/2),rn=y(J[0]*J[0]+J[1]*J[1]);z=h(k,(A-rn)/(un-1)),Q=h(k,(M-rn)/(un+1))}}X>x?Q>x?(P=m(U,W,D,F,M,Q,S),q=m(K,O,G,H,M,Q,S),b.moveTo(P.cx+P.x01,P.cy+P.y01),Q<k?b.arc(P.cx,P.cy,Q,c(P.y01,P.x01),c(q.y01,q.x01),!S):(b.arc(P.cx,P.cy,Q,c(P.y01,P.x01),c(P.y11,P.x11),!S),b.arc(0,0,M,c(P.cy+P.y11,P.cx+P.x11),c(q.cy+q.y11,q.cx+q.x11),!S),b.arc(q.cx,q.cy,Q,c(q.y11,q.x11),c(q.y01,q.x01),!S))):(b.moveTo(D,F),b.arc(0,0,M,L,N,!S)):b.moveTo(D,F),A>x&&I>x?z>x?(P=m(G,H,K,O,A,-z,S),q=m(D,F,U,W,A,-z,S),b.lineTo(P.cx+P.x01,P.cy+P.y01),z<k?b.arc(P.cx,P.cy,z,c(P.y01,P.x01),c(q.y01,q.x01),!S):(b.arc(P.cx,P.cy,z,c(P.y01,P.x01),c(P.y11,P.x11),!S),b.arc(0,0,A,c(P.cy+P.y11,P.cx+P.x11),c(q.cy+q.y11,q.cx+q.x11),S),b.arc(q.cx,q.cy,z,c(q.y11,q.x11),c(q.y01,q.x01),!S))):b.arc(0,0,A,V,C,S):b.lineTo(G,H)}else b.moveTo(0,0);if(b.closePath(),l)return b=null,l+""||null}return E.centroid=function(){var i=(+n.apply(this,arguments)+ +t.apply(this,arguments))/2,e=(+u.apply(this,arguments)+ +s.apply(this,arguments))/2-p/2;return[a(e)*i,f(e)*i]},E.innerRadius=function(t){return arguments.length?(n="function"==typeof t?t:l(+t),E):n},E.outerRadius=function(n){return arguments.length?(t="function"==typeof n?n:l(+n),E):t},E.cornerRadius=function(n){return arguments.length?(i="function"==typeof n?n:l(+n),E):i},E.padRadius=function(n){return arguments.length?(e=null==n?null:"function"==typeof n?n:l(+n),E):e},E.startAngle=function(n){return arguments.length?(u="function"==typeof n?n:l(+n),E):u},E.endAngle=function(n){return arguments.length?(s="function"==typeof n?n:l(+n),E):s},E.padAngle=function(n){return arguments.length?(w="function"==typeof n?n:l(+n),E):w},E.context=function(n){return arguments.length?(b=null==n?null:n,E):b},E}function b(n){this._context=n}function E(n){return new b(n)}function S(n){return n[0]}function P(n){return n[1]}function q(){var n=S,t=null,i=l(0),e=P,u=l(!0),o=null,c=E,a=null;function s(l){var s,h,f,y,x,p=l.length,_=!1,d=new Array(p),g=new Array(p);for(null==o&&(a=c(x=r())),s=0;s<=p;++s){if(!(s<p&&u(y=l[s],s,l))===_)if(_=!_)h=s,a.areaStart(),a.lineStart();else{for(a.lineEnd(),a.lineStart(),f=s-1;f>=h;--f)a.point(d[f],g[f]);a.lineEnd(),a.areaEnd()}_&&(d[s]=+n(y,s,l),g[s]=+i(y,s,l),a.point(t?+t(y,s,l):d[s],e?+e(y,s,l):g[s]))}if(x)return a=null,x+""||null}function h(){return function(){var n=S,t=P,i=l(!0),e=null,u=E,o=null;function c(l){var c,a,s,h=l.length,f=!1;for(null==e&&(o=u(s=r())),c=0;c<=h;++c)!(c<h&&i(a=l[c],c,l))===f&&((f=!f)?o.lineStart():o.lineEnd()),f&&o.point(+n(a,c,l),+t(a,c,l));if(s)return o=null,s+""||null}return c.x=function(t){return arguments.length?(n="function"==typeof t?t:l(+t),c):n},c.y=function(n){return arguments.length?(t="function"==typeof n?n:l(+n),c):t},c.defined=function(n){return arguments.length?(i="function"==typeof n?n:l(!!n),c):i},c.curve=function(n){return arguments.length?(u=n,null!=e&&(o=u(e)),c):u},c.context=function(n){return arguments.length?(null==n?e=o=null:o=u(e=n),c):e},c}().defined(u).curve(c).context(o)}return s.x=function(i){return arguments.length?(n="function"==typeof i?i:l(+i),t=null,s):n},s.x0=function(t){return arguments.length?(n="function"==typeof t?t:l(+t),s):n},s.x1=function(n){return arguments.length?(t=null==n?null:"function"==typeof n?n:l(+n),s):t},s.y=function(n){return arguments.length?(i="function"==typeof n?n:l(+n),e=null,s):i},s.y0=function(n){return arguments.length?(i="function"==typeof n?n:l(+n),s):i},s.y1=function(n){return arguments.length?(e=null==n?null:"function"==typeof n?n:l(+n),s):e},s.lineX0=s.lineY0=function(){return h().x(n).y(i)},s.lineY1=function(){return h().x(n).y(e)},s.lineX1=function(){return h().x(t).y(i)},s.defined=function(n){return arguments.length?(u="function"==typeof n?n:l(!!n),s):u},s.curve=function(n){return arguments.length?(c=n,null!=o&&(a=c(o)),s):c},s.context=function(n){return arguments.length?(null==n?o=a=null:a=c(o=n),s):o},s}function L(n,t){return t<n?-1:t>n?1:t>=n?0:NaN}function N(n){return n}function C(n,t){n(t)}function V(n){var t=void 0===n?{}:n,i=t.innerRadius,e=t.outerRadius,u=t.cornerRadius,r=t.startAngle,l=t.endAngle,o=t.padAngle,c=t.padRadius,a=w();return null!=i&&C(a.innerRadius,i),null!=e&&C(a.outerRadius,e),null!=u&&C(a.cornerRadius,u),null!=r&&C(a.startAngle,r),null!=l&&C(a.endAngle,l),null!=o&&C(a.padAngle,o),null!=c&&C(a.padRadius,c),a}function I(n){var t=void 0===n?{}:n,i=t.x,e=t.x0,u=t.x1,r=t.y,l=t.y0,o=t.y1,c=t.defined,a=t.curve,s=q();return i&&C(s.x,i),e&&C(s.x0,e),u&&C(s.x1,u),r&&C(s.y,r),l&&C(s.y0,l),o&&C(s.y1,o),c&&s.defined(c),a&&s.curve(a),s}function X(n){var t=void 0===n?{}:n,i=t.startAngle,e=t.endAngle,u=t.padAngle,r=t.value,o=t.sort,c=t.sortValues,a=function(){var n=N,t=L,i=null,e=l(0),u=l(d),r=l(0);function o(l){var o,c,a,s,h,f=l.length,y=0,x=new Array(f),p=new Array(f),_=+e.apply(this,arguments),g=Math.min(d,Math.max(-d,u.apply(this,arguments)-_)),v=Math.min(Math.abs(g)/f,r.apply(this,arguments)),A=v*(g<0?-1:1);for(o=0;o<f;++o)(h=p[x[o]=o]=+n(l[o],o,l))>0&&(y+=h);for(null!=t?x.sort(function(n,i){return t(p[n],p[i])}):null!=i&&x.sort(function(n,t){return i(l[n],l[t])}),o=0,a=y?(g-f*A)/y:0;o<f;++o,_=s)c=x[o],s=_+((h=p[c])>0?h*a:0)+A,p[c]={data:l[c],index:o,value:h,startAngle:_,endAngle:s,padAngle:v};return p}return o.value=function(t){return arguments.length?(n="function"==typeof t?t:l(+t),o):n},o.sortValues=function(n){return arguments.length?(t=n,i=null,o):t},o.sort=function(n){return arguments.length?(i=n,t=null,o):i},o.startAngle=function(n){return arguments.length?(e="function"==typeof n?n:l(+n),o):e},o.endAngle=function(n){return arguments.length?(u="function"==typeof n?n:l(+n),o):u},o.padAngle=function(n){return arguments.length?(r="function"==typeof n?n:l(+n),o):r},o}();return(null===o||null!=o)&&a.sort(o),(null===c||null!=c)&&a.sortValues(c),null!=r&&a.value(r),null!=u&&C(a.padAngle,u),null!=i&&C(a.startAngle,i),null!=e&&C(a.endAngle,e),a}b.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(n,t){switch(n=+n,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(n,t):this._context.moveTo(n,t);break;case 1:this._point=2;default:this._context.lineTo(n,t)}}};export{I as a,V as b,X as p};