mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-26 21:12:51 +08:00
2 lines
6.0 KiB
JavaScript
2 lines
6.0 KiB
JavaScript
import{r as an,j as K}from"./vendor-react-Bf71BWbF.js";import{u as cn,eH as fn}from"./index-CXHBmSa5.js";import{u as gn,i as hn,e as pn,C as yn}from"./layout-BRLew_nj.js";import{w as dn,c as T,a as mn}from"./array-C0P64tl-.js";const on=Math.abs,w=Math.atan2,k=Math.cos,xn=Math.max,rn=Math.min,b=Math.sin,F=Math.sqrt,S=1e-12,V=Math.PI,X=V/2,W=2*V;function vn(t){return t>1?0:t<-1?V:Math.acos(t)}function ln(t){return t>=1?X:t<=-1?-X:Math.asin(t)}function An(t){return t.innerRadius}function Mn(t){return t.outerRadius}function Rn(t){return t.startAngle}function wn(t){return t.endAngle}function Pn(t){return t&&t.padAngle}function Tn(t,h,v,P,x,A,p,n){var f=v-t,u=P-h,e=p-x,y=n-A,r=y*f-e*u;if(!(r*r<S))return r=(e*(h-A)-y*(t-x))/r,[t+r*f,h+r*u]}function U(t,h,v,P,x,A,p){var n=t-v,f=h-P,u=(p?A:-A)/F(n*n+f*f),e=u*f,y=-u*n,r=t+e,a=h+y,g=v+e,d=P+y,j=(r+g)/2,c=(a+d)/2,m=g-r,o=d-a,l=m*m+o*o,M=x-A,R=r*d-g*a,D=(o<0?-1:1)*F(xn(0,M*M*l-R*R)),I=(R*o-m*D)/l,B=(-R*m-o*D)/l,L=(R*o+m*D)/l,$=(-R*m+o*D)/l,E=I-j,s=B-c,i=L-j,N=$-c;return E*E+s*s>i*i+N*N&&(I=L,B=$),{cx:I,cy:B,x01:-e,y01:-y,x11:I*(x/M-1),y11:B*(x/M-1)}}function jn(){var t=An,h=Mn,v=T(0),P=null,x=Rn,A=wn,p=Pn,n=null,f=dn(u);function u(){var e,y,r=+t.apply(this,arguments),a=+h.apply(this,arguments),g=x.apply(this,arguments)-X,d=A.apply(this,arguments)-X,j=on(d-g),c=d>g;if(n||(n=e=f()),a<r&&(y=a,a=r,r=y),!(a>S))n.moveTo(0,0);else if(j>W-S)n.moveTo(a*k(g),a*b(g)),n.arc(0,0,a,g,d,!c),r>S&&(n.moveTo(r*k(d),r*b(d)),n.arc(0,0,r,d,g,c));else{var m=g,o=d,l=g,M=d,R=j,D=j,I=p.apply(this,arguments)/2,B=I>S&&(P?+P.apply(this,arguments):F(r*r+a*a)),L=rn(on(a-r)/2,+v.apply(this,arguments)),$=L,E=L,s,i;if(B>S){var N=ln(B/r*b(I)),H=ln(B/a*b(I));(R-=N*2)>S?(N*=c?1:-1,l+=N,M-=N):(R=0,l=M=(g+d)/2),(D-=H*2)>S?(H*=c?1:-1,m+=H,o-=H):(D=0,m=o=(g+d)/2)}var q=a*k(m),z=a*b(m),O=r*k(M),G=r*b(M);if(L>S){var J=a*k(o),Q=a*b(o),Y=r*k(l),Z=r*b(l),C;if(j<V)if(C=Tn(q,z,Y,Z,J,Q,O,G)){var _=q-C[0],nn=z-C[1],en=J-C[0],tn=Q-C[1],sn=1/b(vn((_*en+nn*tn)/(F(_*_+nn*nn)*F(en*en+tn*tn)))/2),un=F(C[0]*C[0]+C[1]*C[1]);$=rn(L,(r-un)/(sn-1)),E=rn(L,(a-un)/(sn+1))}else $=E=0}D>S?E>S?(s=U(Y,Z,q,z,a,E,c),i=U(J,Q,O,G,a,E,c),n.moveTo(s.cx+s.x01,s.cy+s.y01),E<L?n.arc(s.cx,s.cy,E,w(s.y01,s.x01),w(i.y01,i.x01),!c):(n.arc(s.cx,s.cy,E,w(s.y01,s.x01),w(s.y11,s.x11),!c),n.arc(0,0,a,w(s.cy+s.y11,s.cx+s.x11),w(i.cy+i.y11,i.cx+i.x11),!c),n.arc(i.cx,i.cy,E,w(i.y11,i.x11),w(i.y01,i.x01),!c))):(n.moveTo(q,z),n.arc(0,0,a,m,o,!c)):n.moveTo(q,z),!(r>S)||!(R>S)?n.lineTo(O,G):$>S?(s=U(O,G,J,Q,r,-$,c),i=U(q,z,Y,Z,r,-$,c),n.lineTo(s.cx+s.x01,s.cy+s.y01),$<L?n.arc(s.cx,s.cy,$,w(s.y01,s.x01),w(i.y01,i.x01),!c):(n.arc(s.cx,s.cy,$,w(s.y01,s.x01),w(s.y11,s.x11),!c),n.arc(0,0,r,w(s.cy+s.y11,s.cx+s.x11),w(i.cy+i.y11,i.cx+i.x11),c),n.arc(i.cx,i.cy,$,w(i.y11,i.x11),w(i.y01,i.x01),!c))):n.arc(0,0,r,M,l,c)}if(n.closePath(),e)return n=null,e+""||null}return u.centroid=function(){var e=(+t.apply(this,arguments)+ +h.apply(this,arguments))/2,y=(+x.apply(this,arguments)+ +A.apply(this,arguments))/2-V/2;return[k(y)*e,b(y)*e]},u.innerRadius=function(e){return arguments.length?(t=typeof e=="function"?e:T(+e),u):t},u.outerRadius=function(e){return arguments.length?(h=typeof e=="function"?e:T(+e),u):h},u.cornerRadius=function(e){return arguments.length?(v=typeof e=="function"?e:T(+e),u):v},u.padRadius=function(e){return arguments.length?(P=e==null?null:typeof e=="function"?e:T(+e),u):P},u.startAngle=function(e){return arguments.length?(x=typeof e=="function"?e:T(+e),u):x},u.endAngle=function(e){return arguments.length?(A=typeof e=="function"?e:T(+e),u):A},u.padAngle=function(e){return arguments.length?(p=typeof e=="function"?e:T(+e),u):p},u.context=function(e){return arguments.length?(n=e??null,u):n},u}function Sn(t,h){return h<t?-1:h>t?1:h>=t?0:NaN}function $n(t){return t}function En(){var t=$n,h=Sn,v=null,P=T(0),x=T(W),A=T(0);function p(n){var f,u=(n=mn(n)).length,e,y,r=0,a=new Array(u),g=new Array(u),d=+P.apply(this,arguments),j=Math.min(W,Math.max(-W,x.apply(this,arguments)-d)),c,m=Math.min(Math.abs(j)/u,A.apply(this,arguments)),o=m*(j<0?-1:1),l;for(f=0;f<u;++f)(l=g[a[f]=f]=+t(n[f],f,n))>0&&(r+=l);for(h!=null?a.sort(function(M,R){return h(g[M],g[R])}):v!=null&&a.sort(function(M,R){return v(n[M],n[R])}),f=0,y=r?(j-u*o)/r:0;f<u;++f,d=c)e=a[f],l=g[e],c=d+(l>0?l*y:0)+o,g[e]={data:n[e],index:f,value:l,startAngle:d,endAngle:c,padAngle:m};return g}return p.value=function(n){return arguments.length?(t=typeof n=="function"?n:T(+n),p):t},p.sortValues=function(n){return arguments.length?(h=n,v=null,p):h},p.sort=function(n){return arguments.length?(v=n,h=null,p):v},p.startAngle=function(n){return arguments.length?(P=typeof n=="function"?n:T(+n),p):P},p.endAngle=function(n){return arguments.length?(x=typeof n=="function"?n:T(+n),p):x},p.padAngle=function(n){return arguments.length?(A=typeof n=="function"?n:T(+n),p):A},p}function In({label:t,rows:h}){const v=cn(),[P,x]=fn(Math.round,120),{tip:A,showAt:p,hide:n}=gn(),[f,u]=an.useState(null),e=h.filter(o=>o.value!==null&&o.value>0),y=x?.width??0,r=x?.height??0,a=hn(e.map(o=>o.value)),g=En().sort(null).value((o,l)=>a[l])(e),d=jn().innerRadius(44).outerRadius(56).digits(3),j=o=>u(o),c=()=>{u(null),n()};an.useLayoutEffect(()=>{const o=f===null?void 0:g[f];if(!o||f===null){n();return}const l=e[f],[M,R]=d.centroid(o);p({x:Math.round((y/2+M)*1e4)/1e4,y:Math.round((r/2+R)*1e4)/1e4,width:y,bounds:{x:0,y:0,width:y,height:r},lines:[`${l.name}${v("ui.labelSeparator")}${v("ui.share",{bytes:l.text,percent:String(l.value)})}`]})});const m=pn(e.length,j,c);return K.jsxs("div",{ref:P,style:{height:"100%",width:"100%",position:"relative"},onPointerLeave:m.onPointerLeave,children:[K.jsx(yn,{tip:A}),x&&K.jsx("svg",{className:"rp-activity-surface",width:y,height:r,viewBox:`0 0 ${y} ${r}`,style:{display:"block"},role:"application","aria-label":t,tabIndex:0,onFocus:m.onFocus,onBlur:m.onBlur,onKeyDown:m.onKeyDown,children:K.jsx("g",{transform:`translate(${y/2},${r/2})`,children:g.map((o,l)=>K.jsx("path",{d:d({...o,endAngle:Math.min(o.endAngle,o.startAngle+359.999*Math.PI/180)})??void 0,fill:e[l].color,stroke:"none",onPointerEnter:()=>j(l),onPointerLeave:m.onPointerLeave},e[l].name))})})]})}export{In as DonutPlot};
|