import{t as e}from"./ordinal-3qmO7xdp.js";import{t}from"./arc-EVcD9KCQ.js";import{An as n,Dn as r,En as i,Hn as a,On as o,Vn as s,Vt as c,Wn as l,Wt as u,an as d,in as f,ir as p,jn as m,nt as h,rr as g,st as _,wn as v,xn as y}from"./index-CQjDndvX.js";import{t as b}from"./mermaid-parser.core-BA94RXK1.js";import{t as x}from"./chunk-4BX2VUAB-CWoklDfR.js";function S(e,t){return t<e?-1:t>e?1:t>=e?0:NaN}function C(e){return e}function w(){var e=C,t=S,n=null,r=d(0),i=d(f),a=d(0);function o(o){var s,c=(o=u(o)).length,l,d,p=0,m=Array(c),h=Array(c),g=+r.apply(this,arguments),_=Math.min(f,Math.max(-f,i.apply(this,arguments)-g)),v,y=Math.min(Math.abs(_)/c,a.apply(this,arguments)),b=y*(_<0?-1:1),x;for(s=0;s<c;++s)(x=h[m[s]=s]=+e(o[s],s,o))>0&&(p+=x);for(t==null?n!=null&&m.sort(function(e,t){return n(o[e],o[t])}):m.sort(function(e,n){return t(h[e],h[n])}),s=0,d=p?(_-c*b)/p:0;s<c;++s,g=v)l=m[s],x=h[l],v=g+(x>0?x*d:0)+b,h[l]={data:o[l],index:s,value:x,startAngle:g,endAngle:v,padAngle:y};return h}return o.value=function(t){return arguments.length?(e=typeof t==`function`?t:d(+t),o):e},o.sortValues=function(e){return arguments.length?(t=e,n=null,o):t},o.sort=function(e){return arguments.length?(n=e,t=null,o):n},o.startAngle=function(e){return arguments.length?(r=typeof e==`function`?e:d(+e),o):r},o.endAngle=function(e){return arguments.length?(i=typeof e==`function`?e:d(+e),o):i},o.padAngle=function(e){return arguments.length?(a=typeof e==`function`?e:d(+e),o):a},o}var T=i.pie,E={sections:new Map,showData:!1,config:T},D=E.sections,O=E.showData,k=structuredClone(T),A={getConfig:g(()=>structuredClone(k),`getConfig`),clear:g(()=>{D=new Map,O=E.showData,y()},`clear`),setDiagramTitle:l,getDiagramTitle:m,setAccTitle:a,getAccTitle:o,setAccDescription:s,getAccDescription:r,addSection:g(({label:e,value:t})=>{if(t<0)throw Error(`"${e}" has invalid value: ${t}. Negative values are not allowed in pie charts. All slice values must be >= 0.`);D.has(e)||(D.set(e,t),p.debug(`added new section: ${e}, with value: ${t}`))},`addSection`),getSections:g(()=>D,`getSections`),setShowData:g(e=>{O=e},`setShowData`),getShowData:g(()=>O,`getShowData`)},j=g((e,t)=>{x(e,t),t.setShowData(e.showData),e.sections.map(t.addSection)},`populateDb`),M={parse:g(async e=>{let t=await b(`pie`,e);p.debug(t),j(t,A)},`parse`)},N=g(e=>`
  .pieCircle{
    stroke: ${e.pieStrokeColor};
    stroke-width : ${e.pieStrokeWidth};
    opacity : ${e.pieOpacity};
  }
  .pieOuterCircle{
    stroke: ${e.pieOuterStrokeColor};
    stroke-width: ${e.pieOuterStrokeWidth};
    fill: none;
  }
  .pieTitleText {
    text-anchor: middle;
    font-size: ${e.pieTitleTextSize};
    fill: ${e.pieTitleTextColor};
    font-family: ${e.fontFamily};
  }
  .slice {
    font-family: ${e.fontFamily};
    fill: ${e.pieSectionTextColor};
    font-size:${e.pieSectionTextSize};
    // fill: white;
  }
  .legend text {
    fill: ${e.pieLegendTextColor};
    font-family: ${e.fontFamily};
    font-size: ${e.pieLegendTextSize};
  }
`,`getStyles`),P=g(e=>{let t=[...e.values()].reduce((e,t)=>e+t,0),n=[...e.entries()].map(([e,t])=>({label:e,value:t})).filter(e=>e.value/t*100>=1);return w().value(e=>e.value).sort(null)(n)},`createPieArcs`),F={parser:M,db:A,renderer:{draw:g((r,i,a,o)=>{p.debug(`rendering pie chart
`+r);let s=o.db,l=n(),u=h(s.getConfig(),l.pie),d=c(i),f=d.append(`g`);f.attr(`transform`,`translate(225,225)`);let{themeVariables:m}=l,[g]=_(m.pieOuterStrokeWidth);g??=2;let y=u.textPosition,b=t().innerRadius(0).outerRadius(185),x=t().innerRadius(185*y).outerRadius(185*y);f.append(`circle`).attr(`cx`,0).attr(`cy`,0).attr(`r`,185+g/2).attr(`class`,`pieOuterCircle`);let S=s.getSections(),C=P(S),w=[m.pie1,m.pie2,m.pie3,m.pie4,m.pie5,m.pie6,m.pie7,m.pie8,m.pie9,m.pie10,m.pie11,m.pie12],T=0;S.forEach(e=>{T+=e});let E=C.filter(e=>(e.data.value/T*100).toFixed(0)!==`0`),D=e(w).domain([...S.keys()]);f.selectAll(`mySlices`).data(E).enter().append(`path`).attr(`d`,b).attr(`fill`,e=>D(e.data.label)).attr(`class`,`pieCircle`),f.selectAll(`mySlices`).data(E).enter().append(`text`).text(e=>(e.data.value/T*100).toFixed(0)+`%`).attr(`transform`,e=>`translate(`+x.centroid(e)+`)`).style(`text-anchor`,`middle`).attr(`class`,`slice`);let O=f.append(`text`).text(s.getDiagramTitle()).attr(`x`,0).attr(`y`,-400/2).attr(`class`,`pieTitleText`),k=[...S.entries()].map(([e,t])=>({label:e,value:t})),A=f.selectAll(`.legend`).data(k).enter().append(`g`).attr(`class`,`legend`).attr(`transform`,(e,t)=>{let n=22*k.length/2;return`translate(216,`+(t*22-n)+`)`});A.append(`rect`).attr(`width`,18).attr(`height`,18).style(`fill`,e=>D(e.label)).style(`stroke`,e=>D(e.label)),A.append(`text`).attr(`x`,22).attr(`y`,14).text(e=>s.getShowData()?`${e.label} [${e.value}]`:e.label);let j=512+Math.max(...A.selectAll(`text`).nodes().map(e=>e?.getBoundingClientRect().width??0)),M=O.node()?.getBoundingClientRect().width??0,N=450/2-M/2,F=450/2+M/2,I=Math.min(0,N),L=Math.max(j,F)-I;d.attr(`viewBox`,`${I} 0 ${L} 450`),v(d,450,L,u.useMaxWidth)},`draw`)},styles:N};export{F as diagram};