import{K as Q,aA as Y,L as tt,aB as et,O as at,aD as rt,a as p,ah as z,N as nt,m as it,az as st,an as ot,w as lt,n as ct,F as ut}from"./mermaid.core-8qjHlhCB.js";import{p as pt}from"./chunk-4BX2VUAB-3NxUSAZt.js";import{p as dt}from"./wardley-L42UT6IY-CKJh2fVX.js";import"./index-Cirud96V.js";import{d as _}from"./arc-DtxbFlka.js";import{o as gt}from"./ordinal-BQ3KlzSu.js";import{h as S,E as R,c as ft}from"./step-CWvwoXpJ.js";import"./purify.es-CLGrRn1w.js";import"./init-BFKUnIhM.js";function ht(t,a){return a<t?-1:a>t?1:a>=t?0:NaN}function mt(t){return t}function vt(){var t=mt,a=ht,f=null,w=S(0),s=S(R),d=S(0);function o(e){var n,l=(e=ft(e)).length,g,h,v=0,c=new Array(l),i=new Array(l),x=+w.apply(this,arguments),y=Math.min(R,Math.max(-R,s.apply(this,arguments)-x)),m,C=Math.min(Math.abs(y)/l,d.apply(this,arguments)),$=C*(y<0?-1:1),u;for(n=0;n<l;++n)(u=i[c[n]=n]=+t(e[n],n,e))>0&&(v+=u);for(a!=null?c.sort(function(A,D){return a(i[A],i[D])}):f!=null&&c.sort(function(A,D){return f(e[A],e[D])}),n=0,h=v?(y-l*$)/v:0;n<l;++n,x=m)g=c[n],u=i[g],m=x+(u>0?u*h:0)+$,i[g]={data:e[g],index:n,value:u,startAngle:x,endAngle:m,padAngle:C};return i}return o.value=function(e){return arguments.length?(t=typeof e=="function"?e:S(+e),o):t},o.sortValues=function(e){return arguments.length?(a=e,f=null,o):a},o.sort=function(e){return arguments.length?(f=e,a=null,o):f},o.startAngle=function(e){return arguments.length?(w=typeof e=="function"?e:S(+e),o):w},o.endAngle=function(e){return arguments.length?(s=typeof e=="function"?e:S(+e),o):s},o.padAngle=function(e){return arguments.length?(d=typeof e=="function"?e:S(+e),o):d},o}var xt=ut.pie,F={sections:new Map,showData:!1},T=F.sections,W=F.showData,St=structuredClone(xt),wt=p(()=>structuredClone(St),"getConfig"),yt=p(()=>{T=new Map,W=F.showData,ct()},"clear"),At=p(({label:t,value:a})=>{if(a<0)throw new Error(`"${t}" has invalid value: ${a}. Negative values are not allowed in pie charts. All slice values must be >= 0.`);T.has(t)||(T.set(t,a),z.debug(`added new section: ${t}, with value: ${a}`))},"addSection"),Dt=p(()=>T,"getSections"),Ct=p(t=>{W=t},"setShowData"),$t=p(()=>W,"getShowData"),V={getConfig:wt,clear:yt,setDiagramTitle:rt,getDiagramTitle:at,setAccTitle:et,getAccTitle:tt,setAccDescription:Y,getAccDescription:Q,addSection:At,getSections:Dt,setShowData:Ct,getShowData:$t},Tt=p((t,a)=>{pt(t,a),a.setShowData(t.showData),t.sections.map(a.addSection)},"populateDb"),Et={parse:p(async t=>{const a=await dt("pie",t);z.debug(a),Tt(a,V)},"parse")},kt=p(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"),Mt=kt,bt=p(t=>{const a=[...t.values()].reduce((s,d)=>s+d,0),f=[...t.entries()].map(([s,d])=>({label:s,value:d})).filter(s=>s.value/a*100>=1);return vt().value(s=>s.value).sort(null)(f)},"createPieArcs"),Rt=p((t,a,f,w)=>{var P;z.debug(`rendering pie chart
`+t);const s=w.db,d=nt(),o=it(s.getConfig(),d.pie),e=40,n=18,l=4,g=450,h=g,v=st(a),c=v.append("g");c.attr("transform","translate("+h/2+","+g/2+")");const{themeVariables:i}=d;let[x]=ot(i.pieOuterStrokeWidth);x??(x=2);const y=o.textPosition,m=Math.min(h,g)/2-e,C=_().innerRadius(0).outerRadius(m),$=_().innerRadius(m*y).outerRadius(m*y);c.append("circle").attr("cx",0).attr("cy",0).attr("r",m+x/2).attr("class","pieOuterCircle");const u=s.getSections(),A=bt(u),D=[i.pie1,i.pie2,i.pie3,i.pie4,i.pie5,i.pie6,i.pie7,i.pie8,i.pie9,i.pie10,i.pie11,i.pie12];let E=0;u.forEach(r=>{E+=r});const L=A.filter(r=>(r.data.value/E*100).toFixed(0)!=="0"),k=gt(D).domain([...u.keys()]);c.selectAll("mySlices").data(L).enter().append("path").attr("d",C).attr("fill",r=>k(r.data.label)).attr("class","pieCircle"),c.selectAll("mySlices").data(L).enter().append("text").text(r=>(r.data.value/E*100).toFixed(0)+"%").attr("transform",r=>"translate("+$.centroid(r)+")").style("text-anchor","middle").attr("class","slice");const U=c.append("text").text(s.getDiagramTitle()).attr("x",0).attr("y",-400/2).attr("class","pieTitleText"),N=[...u.entries()].map(([r,b])=>({label:r,value:b})),M=c.selectAll(".legend").data(N).enter().append("g").attr("class","legend").attr("transform",(r,b)=>{const I=n+l,q=I*N.length/2,H=12*n,J=b*I-q;return"translate("+H+","+J+")"});M.append("rect").attr("width",n).attr("height",n).style("fill",r=>k(r.label)).style("stroke",r=>k(r.label)),M.append("text").attr("x",n+l).attr("y",n-l).text(r=>s.getShowData()?`${r.label} [${r.value}]`:r.label);const j=Math.max(...M.selectAll("text").nodes().map(r=>(r==null?void 0:r.getBoundingClientRect().width)??0)),K=h+e+n+l+j,B=((P=U.node())==null?void 0:P.getBoundingClientRect().width)??0,X=h/2-B/2,Z=h/2+B/2,G=Math.min(0,X),O=Math.max(K,Z)-G;v.attr("viewBox",`${G} 0 ${O} ${g}`),lt(v,g,O,o.useMaxWidth)},"draw"),zt={draw:Rt},Vt={parser:Et,db:V,renderer:zt,styles:Mt};export{Vt as diagram};
