import{t as e}from"./arc-D81purZA.js";import{$ as t,$t as n,En as r,I as i,Kt as a,Mt as o,On as s,Qt as c,V as l,X as u,Yt as d,Zt as f,fn as p,hn as m,mt as h,nn as g,pn as _,pt as v,tn as y}from"./index-D6r_eLun.js";import{n as b}from"./mermaid-parser.core-BItfoGLM.js";import{t as x}from"./chunk-JWPE2WC7-BBxS46F4.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,n=S,r=null,i=h(0),a=h(v),o=h(0);function s(s){var c,l=(s=t(s)).length,u,d,f=0,p=Array(l),m=Array(l),h=+i.apply(this,arguments),g=Math.min(v,Math.max(-v,a.apply(this,arguments)-h)),_,y=Math.min(Math.abs(g)/l,o.apply(this,arguments)),b=y*(g<0?-1:1),x;for(c=0;c<l;++c)(x=m[p[c]=c]=+e(s[c],c,s))>0&&(f+=x);for(n==null?r!=null&&p.sort(function(e,t){return r(s[e],s[t])}):p.sort(function(e,t){return n(m[e],m[t])}),c=0,d=f?(g-l*b)/f:0;c<l;++c,h=_)u=p[c],x=m[u],_=h+(x>0?x*d:0)+b,m[u]={data:s[u],index:c,value:x,startAngle:h,endAngle:_,padAngle:y};return m}return s.value=function(t){return arguments.length?(e=typeof t==`function`?t:h(+t),s):e},s.sortValues=function(e){return arguments.length?(n=e,r=null,s):n},s.sort=function(e){return arguments.length?(r=e,n=null,s):r},s.startAngle=function(e){return arguments.length?(i=typeof e==`function`?e:h(+e),s):i},s.endAngle=function(e){return arguments.length?(a=typeof e==`function`?e:h(+e),s):a},s.padAngle=function(e){return arguments.length?(o=typeof e==`function`?e:h(+e),s):o},s}var T=f.pie,E={sections:new Map,showData:!1,config:T},D=E.sections,O=E.showData,k=structuredClone(T),A={getConfig:s(()=>structuredClone(k),`getConfig`),clear:s(()=>{D=new Map,O=E.showData,a()},`clear`),setDiagramTitle:m,getDiagramTitle:g,setAccTitle:_,getAccTitle:n,setAccDescription:p,getAccDescription:c,addSection:s(({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),r.debug(`added new section: ${e}, with value: ${t}`))},`addSection`),getSections:s(()=>D,`getSections`),setShowData:s(e=>{O=e},`setShowData`),getShowData:s(()=>O,`getShowData`)},j=s((e,t)=>{x(e,t),t.setShowData(e.showData),e.sections.map(t.addSection)},`populateDb`),M={parse:s(async e=>{let t=await b(`pie`,e);r.debug(t),j(t,A)},`parse`)},N=s(e=>`
  .pieCircle{
    stroke: ${e.pieStrokeColor};
    stroke-width : ${e.pieStrokeWidth};
    opacity : ${e.pieOpacity};
  }
  .pieCircle.highlighted{
    scale: 1.05;
    opacity: 1;
  }
  .pieCircle.highlightedOnHover:hover{
    transition-duration: 250ms;
    scale: 1.05;
    opacity: 1;
  }
  .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=s(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:s((t,n,a,s)=>{r.debug(`rendering pie chart
`+t);let c=s.db,f=y(),p=i(c.getConfig(),f.pie),m=u(n),h=m.append(`g`);h.attr(`transform`,`translate(225,225)`);let{themeVariables:g}=f,[_]=l(g.pieOuterStrokeWidth);_??=2;let v=p.legendPosition,b=p.textPosition,x=p.donutHole>0&&p.donutHole<=.9?p.donutHole:0,S=e().innerRadius(x*185).outerRadius(185),C=e().innerRadius(185*b).outerRadius(185*b),w=h.append(`g`);w.append(`circle`).attr(`cx`,0).attr(`cy`,0).attr(`r`,185+_/2).attr(`class`,`pieOuterCircle`);let T=c.getSections(),E=P(T),D=[g.pie1,g.pie2,g.pie3,g.pie4,g.pie5,g.pie6,g.pie7,g.pie8,g.pie9,g.pie10,g.pie11,g.pie12],O=0;T.forEach(e=>{O+=e});let k=E.filter(e=>(e.data.value/O*100).toFixed(0)!==`0`),A=o(D).domain([...T.keys()]);w.selectAll(`mySlices`).data(k).enter().append(`path`).attr(`d`,S).attr(`fill`,e=>A(e.data.label)).attr(`class`,e=>{let t=`pieCircle`;return p.highlightSlice===`hover`?t+=` highlightedOnHover`:p.highlightSlice===e.data.label&&(t+=` highlighted`),t}),w.selectAll(`mySlices`).data(k).enter().append(`text`).text(e=>(e.data.value/O*100).toFixed(0)+`%`).attr(`transform`,e=>`translate(`+C.centroid(e)+`)`).style(`text-anchor`,`middle`).attr(`class`,`slice`);let j=h.append(`text`).text(c.getDiagramTitle()).attr(`x`,0).attr(`y`,-400/2).attr(`class`,`pieTitleText`),M=[...T.entries()].map(([e,t])=>({label:e,value:t})),N=h.selectAll(`.legend`).data(M).enter().append(`g`).attr(`class`,`legend`);N.append(`rect`).attr(`width`,18).attr(`height`,18).style(`fill`,e=>A(e.label)).style(`stroke`,e=>A(e.label)),N.append(`text`).attr(`x`,22).attr(`y`,14).text(e=>c.getShowData()?`${e.label} [${e.value}]`:e.label);let F=Math.max(...N.selectAll(`text`).nodes().map(e=>e?.getBoundingClientRect().width??0)),I=450,L=490,R=M.length*22;switch(v){case`center`:N.attr(`transform`,(e,t)=>{let n=22*M.length/2,r=-F/2-22,i=t*22-n;return`translate(`+r+`,`+i+`)`});break;case`top`:I+=R,N.attr(`transform`,(e,t)=>`translate(${-F/2-22}, ${t*22-185})`),w.attr(`transform`,()=>`translate(0, ${R+22})`);break;case`bottom`:I+=R,N.attr(`transform`,(e,t)=>{let n=-F/2-22,r=t*22- -207;return`translate(`+n+`,`+r+`)`});break;case`left`:L+=22+F,N.attr(`transform`,(e,t)=>{let n=22*M.length/2;return`translate(-207,`+(t*22-n)+`)`}),w.attr(`transform`,()=>`translate(${F+18+4}, 0)`);break;default:L+=22+F,N.attr(`transform`,(e,t)=>{let n=22*M.length/2;return`translate(216,`+(t*22-n)+`)`});break}let z=j.node()?.getBoundingClientRect().width??0,B=450/2-z/2,V=450/2+z/2,H=Math.min(0,B),U=Math.max(L,V)-H;m.attr(`viewBox`,`${H} 0 ${U} ${I}`),d(m,I,U,p.useMaxWidth)},`draw`)},styles:N};export{F as diagram};