mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-26 20:22:51 +08:00
2 lines
6.2 KiB
JavaScript
2 lines
6.2 KiB
JavaScript
import{r as n,j as t}from"./vendor-react-64fcanlc.js";import{u as e,f as r}from"./index-XeGFdFb3.js";import{aW as o,b4 as a,aZ as i,a$ as l}from"./activity-7OeQMmIs.js";import{w as u,c,a as s}from"./array-C0VuvQyb.js";import"./_commonjsHelpers-CXUWDbkB.js";import"./nodes-Bm1vmvln.js";import"./AppearanceControls-Q-jHRGz9.js";import"./ItemText-Bvif-kkw.js";import"./logs-DNePHVHd.js";import"./Select-OqnbuzuK.js";const f=Math.abs,h=Math.atan2,y=Math.cos,p=Math.max,d=Math.min,x=Math.sin,g=Math.sqrt,v=1e-12,m=Math.PI,M=m/2,A=2*m;function j(n){return n>=1?M:n<=-1?-M:Math.asin(n)}function w(n){return n.innerRadius}function b(n){return n.outerRadius}function P(n){return n.startAngle}function T(n){return n.endAngle}function R(n){return n&&n.padAngle}function L(n,t,e,r,o,a,i){var l=n-e,u=t-r,c=(i?a:-a)/g(l*l+u*u),s=c*u,f=-c*l,h=n+s,y=t+f,d=e+s,x=r+f,v=(h+d)/2,m=(y+x)/2,M=d-h,A=x-y,j=M*M+A*A,w=o-a,b=h*x-d*y,P=(A<0?-1:1)*g(p(0,w*w*j-b*b)),T=(b*A-M*P)/j,R=(-b*M-A*P)/j,L=(b*A+M*P)/j,$=(-b*M+A*P)/j,I=T-v,k=R-m,B=L-v,K=$-m;return I*I+k*k>B*B+K*K&&(T=L,R=$),{cx:T,cy:R,x01:-s,y01:-f,x11:T*(o/w-1),y11:R*(o/w-1)}}function $(){var n=w,t=b,e=c(0),r=null,o=P,a=T,i=R,l=null,s=u(p);function p(){var u,c,p,w=+n.apply(this,arguments),b=+t.apply(this,arguments),P=o.apply(this,arguments)-M,T=a.apply(this,arguments)-M,R=f(T-P),$=T>P;if(l||(l=u=s()),b<w&&(c=b,b=w,w=c),b>v)if(R>A-v)l.moveTo(b*y(P),b*x(P)),l.arc(0,0,b,P,T,!$),w>v&&(l.moveTo(w*y(T),w*x(T)),l.arc(0,0,w,T,P,$));else{var I,k,B=P,K=T,N=P,S=T,D=R,E=R,F=i.apply(this,arguments)/2,q=F>v&&(r?+r.apply(this,arguments):g(w*w+b*b)),C=d(f(b-w)/2,+e.apply(this,arguments)),H=C,V=C;if(q>v){var W=j(q/w*x(F)),Z=j(q/b*x(F));(D-=2*W)>v?(N+=W*=$?1:-1,S-=W):(D=0,N=S=(P+T)/2),(E-=2*Z)>v?(B+=Z*=$?1:-1,K-=Z):(E=0,B=K=(P+T)/2)}var _=b*y(B),z=b*x(B),G=w*y(S),J=w*x(S);if(C>v){var O,Q=b*y(K),U=b*x(K),X=w*y(N),Y=w*x(N);if(R<m)if(O=function(n,t,e,r,o,a,i,l){var u=e-n,c=r-t,s=i-o,f=l-a,h=f*u-s*c;if(!(h*h<v))return[n+(h=(s*(t-a)-f*(n-o))/h)*u,t+h*c]}(_,z,X,Y,Q,U,G,J)){var nn=_-O[0],tn=z-O[1],en=Q-O[0],rn=U-O[1],on=1/x(((p=(nn*en+tn*rn)/(g(nn*nn+tn*tn)*g(en*en+rn*rn)))>1?0:p<-1?m:Math.acos(p))/2),an=g(O[0]*O[0]+O[1]*O[1]);H=d(C,(w-an)/(on-1)),V=d(C,(b-an)/(on+1))}else H=V=0}E>v?V>v?(I=L(X,Y,_,z,b,V,$),k=L(Q,U,G,J,b,V,$),l.moveTo(I.cx+I.x01,I.cy+I.y01),V<C?l.arc(I.cx,I.cy,V,h(I.y01,I.x01),h(k.y01,k.x01),!$):(l.arc(I.cx,I.cy,V,h(I.y01,I.x01),h(I.y11,I.x11),!$),l.arc(0,0,b,h(I.cy+I.y11,I.cx+I.x11),h(k.cy+k.y11,k.cx+k.x11),!$),l.arc(k.cx,k.cy,V,h(k.y11,k.x11),h(k.y01,k.x01),!$))):(l.moveTo(_,z),l.arc(0,0,b,B,K,!$)):l.moveTo(_,z),w>v&&D>v?H>v?(I=L(G,J,Q,U,w,-H,$),k=L(_,z,X,Y,w,-H,$),l.lineTo(I.cx+I.x01,I.cy+I.y01),H<C?l.arc(I.cx,I.cy,H,h(I.y01,I.x01),h(k.y01,k.x01),!$):(l.arc(I.cx,I.cy,H,h(I.y01,I.x01),h(I.y11,I.x11),!$),l.arc(0,0,w,h(I.cy+I.y11,I.cx+I.x11),h(k.cy+k.y11,k.cx+k.x11),$),l.arc(k.cx,k.cy,H,h(k.y11,k.x11),h(k.y01,k.x01),!$))):l.arc(0,0,w,S,N,$):l.lineTo(G,J)}else l.moveTo(0,0);if(l.closePath(),u)return l=null,u+""||null}return p.centroid=function(){var e=(+n.apply(this,arguments)+ +t.apply(this,arguments))/2,r=(+o.apply(this,arguments)+ +a.apply(this,arguments))/2-m/2;return[y(r)*e,x(r)*e]},p.innerRadius=function(t){return arguments.length?(n="function"==typeof t?t:c(+t),p):n},p.outerRadius=function(n){return arguments.length?(t="function"==typeof n?n:c(+n),p):t},p.cornerRadius=function(n){return arguments.length?(e="function"==typeof n?n:c(+n),p):e},p.padRadius=function(n){return arguments.length?(r=null==n?null:"function"==typeof n?n:c(+n),p):r},p.startAngle=function(n){return arguments.length?(o="function"==typeof n?n:c(+n),p):o},p.endAngle=function(n){return arguments.length?(a="function"==typeof n?n:c(+n),p):a},p.padAngle=function(n){return arguments.length?(i="function"==typeof n?n:c(+n),p):i},p.context=function(n){return arguments.length?(l=null==n?null:n,p):l},p}function I(n,t){return t<n?-1:t>n?1:t>=n?0:NaN}function k(n){return n}function B({label:u,rows:f}){const h=e(),[y,p]=r(Math.round,120),{tip:d,showAt:x,hide:g}=o(),[v,m]=n.useState(null),M=f.filter(n=>null!==n.value&&n.value>0),j=p?.width??0,w=p?.height??0,b=a(M.map(n=>n.value)),P=function(){var n=k,t=I,e=null,r=c(0),o=c(A),a=c(0);function i(i){var l,u,c,f,h,y=(i=s(i)).length,p=0,d=new Array(y),x=new Array(y),g=+r.apply(this,arguments),v=Math.min(A,Math.max(-A,o.apply(this,arguments)-g)),m=Math.min(Math.abs(v)/y,a.apply(this,arguments)),M=m*(v<0?-1:1);for(l=0;l<y;++l)(h=x[d[l]=l]=+n(i[l],l,i))>0&&(p+=h);for(null!=t?d.sort(function(n,e){return t(x[n],x[e])}):null!=e&&d.sort(function(n,t){return e(i[n],i[t])}),l=0,c=p?(v-y*M)/p:0;l<y;++l,g=f)u=d[l],f=g+((h=x[u])>0?h*c:0)+M,x[u]={data:i[u],index:l,value:h,startAngle:g,endAngle:f,padAngle:m};return x}return i.value=function(t){return arguments.length?(n="function"==typeof t?t:c(+t),i):n},i.sortValues=function(n){return arguments.length?(t=n,e=null,i):t},i.sort=function(n){return arguments.length?(e=n,t=null,i):e},i.startAngle=function(n){return arguments.length?(r="function"==typeof n?n:c(+n),i):r},i.endAngle=function(n){return arguments.length?(o="function"==typeof n?n:c(+n),i):o},i.padAngle=function(n){return arguments.length?(a="function"==typeof n?n:c(+n),i):a},i}().sort(null).value((n,t)=>b[t])(M),T=Math.min(j,w)/2,R=$().innerRadius(T*(44/56)).outerRadius(T).digits(3),L=n=>m(n);n.useLayoutEffect(()=>{const n=null===v?void 0:P[v];if(!n||null===v)return void g();const t=M[v],[e,r]=R.centroid(n);x({x:Math.round(1e4*(j/2+e))/1e4,y:Math.round(1e4*(w/2+r))/1e4,width:j,bounds:{x:0,y:0,width:j,height:w},lines:[h("ui.valuePair",{label:t.name,value:h("ui.share",{bytes:t.text,percent:String(t.value)})})]})});const B=i(M.length,L,()=>{m(null),g()});return t.jsxs("div",{ref:y,style:{height:"100%",width:"100%",position:"relative"},onPointerLeave:B.onPointerLeave,children:[t.jsx(l,{tip:d}),p&&t.jsx("svg",{className:"rp-activity-surface",width:j,height:w,viewBox:`0 0 ${j} ${w}`,style:{display:"block"},role:M.length?"application":"img","aria-label":u,tabIndex:M.length?0:void 0,onFocus:M.length?B.onFocus:void 0,onBlur:B.onBlur,onKeyDown:M.length?B.onKeyDown:void 0,children:t.jsx("g",{transform:`translate(${j/2},${w/2})`,children:P.map((n,e)=>t.jsx("path",{d:R({...n,endAngle:Math.min(n.endAngle,n.startAngle+359.999*Math.PI/180)})??void 0,fill:M[e].color,stroke:"none",onPointerEnter:()=>L(e),onPointerLeave:B.onPointerLeave},M[e].name))})})]})}export{B as DonutPlot};
|