import"./_Uint8Array-D5Z9rM2X.js";import"./isSymbol-xTSywenE.js";import"./_arrayMap-DQI2GUNb.js";import"./toString-CBnct2wx.js";import"./toNumber-CTOPJrpu.js";import"./toInteger-Bor4StOs.js";import"./isArrayLikeObject-DKyJYtr8.js";import"./_getTag-CVRrQL_Q.js";import"./_baseUniq-YWmHDCnr.js";import"./_baseIsEqual-BF8660ot.js";import"./chunk-4KMFLZZN-ByJDCN5Q.js";import"./_toKey-Di_xoXjD.js";import"./memoize-CAcr7Wct.js";import"./get-BYzWDFJH.js";import"./_baseFlatten-8yEsQJi9.js";import"./_basePickBy-W59-WIft.js";import"./merge-BgA7kxZb.js";import"./_baseSlice-B27Cqkm6.js";import"./_arrayReduce-DDpPg0Qh.js";import"./clone-CgXpsEJc.js";import"./_baseEach-Xz5DR2cc.js";import"./hasIn-WaG0qjy7.js";import"./_baseProperty-CIKnF2iY.js";import"./_createAggregator-DL8RwNg0.js";import"./min-hz9WUEOx.js";import"./_baseMap-DMMHaI20.js";import"./isEmpty-z92iM7uZ.js";import"./_baseSet-BlAtwuhp.js";import"./preload-helper-BpItL31i.js";import"./main-CD7jouuS.js";import{n as W}from"./ordinal-B8Ce3bue.js";import"./purify.es-D83HMRRD.js";import"./timer-9ePNNBwU.js";import"./src-D-O4qgKm.js";import{r as h}from"./path-DE1VIUo_.js";import{p as k}from"./math-Cpuq8NJh.js";import{t as F}from"./arc-K25O4dmk.js";import{t as _}from"./array-pmtsE1gt.js";import"./step-DCnHyPDa.js";import{i as B,p as P}from"./chunk-S3R3BYOJ-uZNU-Kd7.js";import"./init-PHOs_KoL.js";import{n as s,r as M}from"./src-Ci62OB0C.js";import{B as L,C as V,U as j,_ as U,a as q,b as G,c as H,d as I,v as J,z as K}from"./chunk-ABZYJK2D-D-T6tPym.js";import{t as Q}from"./chunk-EXTU4WIE-DwsJ54Id.js";import"./dist-D3R7S_yk.js";import"./chunk-JEIROHC2-CdhV7PKh.js";import"./chunk-BN7GFLIU-BYSfwhAl.js";import"./chunk-T44TD3VJ-C-v8PEdO.js";import"./chunk-KMC2YHZD-CqzrHQLs.js";import"./chunk-WFWHJNB7-BUr8j7nr.js";import"./chunk-WFRQ32O7-BDpPnmW5.js";import"./chunk-XRWGC2XP-B3B1fnQJ.js";import{t as X}from"./chunk-4BX2VUAB-BDDhRllH.js";import{t as Y}from"./mermaid-parser.core-DX_Wqjrp.js";function Z(t,r){return r<t?-1:r>t?1:r>=t?0:NaN}function tt(t){return t}function et(){var t=tt,r=Z,c=null,n=h(0),p=h(k),x=h(0);function l(e){var o,a=(e=_(e)).length,d,b,$=0,y=Array(a),m=Array(a),v=+n.apply(this,arguments),A=Math.min(k,Math.max(-k,p.apply(this,arguments)-v)),f,T=Math.min(Math.abs(A)/a,x.apply(this,arguments)),w=T*(A<0?-1:1),u;for(o=0;o<a;++o)(u=m[y[o]=o]=+t(e[o],o,e))>0&&($+=u);for(r==null?c!=null&&y.sort(function(g,S){return c(e[g],e[S])}):y.sort(function(g,S){return r(m[g],m[S])}),o=0,b=$?(A-a*w)/$:0;o<a;++o,v=f)d=y[o],u=m[d],f=v+(u>0?u*b:0)+w,m[d]={data:e[d],index:o,value:u,startAngle:v,endAngle:f,padAngle:T};return m}return l.value=function(e){return arguments.length?(t=typeof e=="function"?e:h(+e),l):t},l.sortValues=function(e){return arguments.length?(r=e,c=null,l):r},l.sort=function(e){return arguments.length?(c=e,r=null,l):c},l.startAngle=function(e){return arguments.length?(n=typeof e=="function"?e:h(+e),l):n},l.endAngle=function(e){return arguments.length?(p=typeof e=="function"?e:h(+e),l):p},l.padAngle=function(e){return arguments.length?(x=typeof e=="function"?e:h(+e),l):x},l}var R=I.pie,O={sections:new Map,showData:!1,config:R},C=O.sections,z=O.showData,rt=structuredClone(R),E={getConfig:s(()=>structuredClone(rt),"getConfig"),clear:s(()=>{C=new Map,z=O.showData,q()},"clear"),setDiagramTitle:j,getDiagramTitle:V,setAccTitle:L,getAccTitle:J,setAccDescription:K,getAccDescription:U,addSection:s(({label:t,value:r})=>{if(r<0)throw Error(`"${t}" has invalid value: ${r}. Negative values are not allowed in pie charts. All slice values must be >= 0.`);C.has(t)||(C.set(t,r),M.debug(`added new section: ${t}, with value: ${r}`))},"addSection"),getSections:s(()=>C,"getSections"),setShowData:s(t=>{z=t},"setShowData"),getShowData:s(()=>z,"getShowData")},it=s((t,r)=>{X(t,r),r.setShowData(t.showData),t.sections.map(r.addSection)},"populateDb"),at={parse:s(async t=>{let r=await Y("pie",t);M.debug(r),it(r,E)},"parse")},ot=s(t=>`
  .pieCircle{
    stroke: ${t.pieStrokeColor};
    stroke-width : ${t.pieStrokeWidth};
    opacity : ${t.pieOpacity};
  }
  .pieOuterCircle{
    stroke: ${t.pieOuterStrokeColor};
    stroke-width: ${t.pieOuterStrokeWidth};
    fill: none;
  }
  .pieTitleText {
    text-anchor: middle;
    font-size: ${t.pieTitleTextSize};
    fill: ${t.pieTitleTextColor};
    font-family: ${t.fontFamily};
  }
  .slice {
    font-family: ${t.fontFamily};
    fill: ${t.pieSectionTextColor};
    font-size:${t.pieSectionTextSize};
    // fill: white;
  }
  .legend text {
    fill: ${t.pieLegendTextColor};
    font-family: ${t.fontFamily};
    font-size: ${t.pieLegendTextSize};
  }
`,"getStyles"),lt=s(t=>{let r=[...t.values()].reduce((n,p)=>n+p,0),c=[...t.entries()].map(([n,p])=>({label:n,value:p})).filter(n=>n.value/r*100>=1).sort((n,p)=>p.value-n.value);return et().value(n=>n.value)(c)},"createPieArcs"),nt={parser:at,db:E,renderer:{draw:s((t,r,c,n)=>{M.debug(`rendering pie chart
`+t);let p=n.db,x=G(),l=B(p.getConfig(),x.pie),e=Q(r),o=e.append("g");o.attr("transform","translate(225,225)");let{themeVariables:a}=x,[d]=P(a.pieOuterStrokeWidth);d??(d=2);let b=l.textPosition,$=F().innerRadius(0).outerRadius(185),y=F().innerRadius(185*b).outerRadius(185*b);o.append("circle").attr("cx",0).attr("cy",0).attr("r",185+d/2).attr("class","pieOuterCircle");let m=p.getSections(),v=lt(m),A=[a.pie1,a.pie2,a.pie3,a.pie4,a.pie5,a.pie6,a.pie7,a.pie8,a.pie9,a.pie10,a.pie11,a.pie12],f=0;m.forEach(i=>{f+=i});let T=v.filter(i=>(i.data.value/f*100).toFixed(0)!=="0"),w=W(A);o.selectAll("mySlices").data(T).enter().append("path").attr("d",$).attr("fill",i=>w(i.data.label)).attr("class","pieCircle"),o.selectAll("mySlices").data(T).enter().append("text").text(i=>(i.data.value/f*100).toFixed(0)+"%").attr("transform",i=>"translate("+y.centroid(i)+")").style("text-anchor","middle").attr("class","slice"),o.append("text").text(p.getDiagramTitle()).attr("x",0).attr("y",-400/2).attr("class","pieTitleText");let u=[...m.entries()].map(([i,D])=>({label:i,value:D})),g=o.selectAll(".legend").data(u).enter().append("g").attr("class","legend").attr("transform",(i,D)=>{let N=22*u.length/2;return"translate(216,"+(D*22-N)+")"});g.append("rect").attr("width",18).attr("height",18).style("fill",i=>w(i.label)).style("stroke",i=>w(i.label)),g.append("text").attr("x",22).attr("y",14).text(i=>p.getShowData()?`${i.label} [${i.value}]`:i.label);let S=512+Math.max(...g.selectAll("text").nodes().map(i=>(i==null?void 0:i.getBoundingClientRect().width)??0));e.attr("viewBox",`0 0 ${S} 450`),H(e,450,S,l.useMaxWidth)},"draw")},styles:ot};export{nt as diagram};
