import{p as t}from"./chunk-4BMEZGHF-BJE2KQd1.js";import{_ as e,g as a,s as n,a as i,b as r,q as s,p as o,l,c as p,E as c,I as d,O as u,d as f,y as m,G as g}from"./mermaid-Blgp1cRh.js";import{p as h}from"./radar-MK3ICKWK-DtrH6Aqw.js";import"./transform-CdY8z5kT.js";import{d as x}from"./arc-B5qYPUYs.js";import{o as y}from"./ordinal-DDUp3AbE.js";import{b as w,t as S,n as $}from"./step-xJWGRC3d.js";import"./index-CFExNDlA.js";import"./_baseEach-B1XKlx78.js";import"./_baseUniq-HE4jn4Ss.js";import"./min-bBChx8P1.js";import"./_baseMap-BiNc5OKS.js";import"./clone-Dg2IE_6L.js";import"./init-DLRA0X12.js";function b(t,e){return e<t?-1:e>t?1:e>=t?0:NaN}function A(t){return t}var T=g.pie,v={sections:new Map,showData:!1},C=v.sections,D=v.showData,j=structuredClone(T),k={getConfig:e((()=>structuredClone(j)),"getConfig"),clear:e((()=>{C=new Map,D=v.showData,m()}),"clear"),setDiagramTitle:o,getDiagramTitle:s,setAccTitle:r,getAccTitle:i,setAccDescription:n,getAccDescription:a,addSection:e((({label:t,value:e})=>{C.has(t)||(C.set(t,e),l.debug(`added new section: ${t}, with value: ${e}`))}),"addSection"),getSections:e((()=>C),"getSections"),setShowData:e((t=>{D=t}),"setShowData"),getShowData:e((()=>D),"getShowData")},M=e(((e,a)=>{t(e,a),a.setShowData(e.showData),e.sections.map(a.addSection)}),"populateDb"),O={parse:e((async t=>{const e=await h("pie",t);l.debug(e),M(e,k)}),"parse")},z=e((t=>`\n  .pieCircle{\n    stroke: ${t.pieStrokeColor};\n    stroke-width : ${t.pieStrokeWidth};\n    opacity : ${t.pieOpacity};\n  }\n  .pieOuterCircle{\n    stroke: ${t.pieOuterStrokeColor};\n    stroke-width: ${t.pieOuterStrokeWidth};\n    fill: none;\n  }\n  .pieTitleText {\n    text-anchor: middle;\n    font-size: ${t.pieTitleTextSize};\n    fill: ${t.pieTitleTextColor};\n    font-family: ${t.fontFamily};\n  }\n  .slice {\n    font-family: ${t.fontFamily};\n    fill: ${t.pieSectionTextColor};\n    font-size:${t.pieSectionTextSize};\n    // fill: white;\n  }\n  .legend text {\n    fill: ${t.pieLegendTextColor};\n    font-family: ${t.fontFamily};\n    font-size: ${t.pieLegendTextSize};\n  }\n`),"getStyles"),W=e((t=>{const e=[...t.entries()].map((t=>({label:t[0],value:t[1]}))).sort(((t,e)=>e.value-t.value));return function(){var t=A,e=b,a=null,n=w(0),i=w(S),r=w(0);function s(s){var o,l,p,c,d,u=(s=$(s)).length,f=0,m=new Array(u),g=new Array(u),h=+n.apply(this,arguments),x=Math.min(S,Math.max(-S,i.apply(this,arguments)-h)),y=Math.min(Math.abs(x)/u,r.apply(this,arguments)),w=y*(x<0?-1:1);for(o=0;o<u;++o)(d=g[m[o]=o]=+t(s[o],o,s))>0&&(f+=d);for(null!=e?m.sort((function(t,a){return e(g[t],g[a])})):null!=a&&m.sort((function(t,e){return a(s[t],s[e])})),o=0,p=f?(x-u*w)/f:0;o<u;++o,h=c)l=m[o],c=h+((d=g[l])>0?d*p:0)+w,g[l]={data:s[l],index:o,value:d,startAngle:h,endAngle:c,padAngle:y};return g}return s.value=function(e){return arguments.length?(t="function"==typeof e?e:w(+e),s):t},s.sortValues=function(t){return arguments.length?(e=t,a=null,s):e},s.sort=function(t){return arguments.length?(a=t,e=null,s):a},s.startAngle=function(t){return arguments.length?(n="function"==typeof t?t:w(+t),s):n},s.endAngle=function(t){return arguments.length?(i="function"==typeof t?t:w(+t),s):i},s.padAngle=function(t){return arguments.length?(r="function"==typeof t?t:w(+t),s):r},s}().value((t=>t.value))(e)}),"createPieArcs"),F={parser:O,db:k,renderer:{draw:e(((t,e,a,n)=>{l.debug("rendering pie chart\n"+t);const i=n.db,r=p(),s=c(i.getConfig(),r.pie),o=18,m=450,g=m,h=d(e),w=h.append("g");w.attr("transform","translate(225,225)");const{themeVariables:S}=r;let[$]=u(S.pieOuterStrokeWidth);$??($=2);const b=s.textPosition,A=Math.min(g,m)/2-40,T=x().innerRadius(0).outerRadius(A),v=x().innerRadius(A*b).outerRadius(A*b);w.append("circle").attr("cx",0).attr("cy",0).attr("r",A+$/2).attr("class","pieOuterCircle");const C=i.getSections(),D=W(C),j=[S.pie1,S.pie2,S.pie3,S.pie4,S.pie5,S.pie6,S.pie7,S.pie8,S.pie9,S.pie10,S.pie11,S.pie12],k=y(j);w.selectAll("mySlices").data(D).enter().append("path").attr("d",T).attr("fill",(t=>k(t.data.label))).attr("class","pieCircle");let M=0;C.forEach((t=>{M+=t})),w.selectAll("mySlices").data(D).enter().append("text").text((t=>(t.data.value/M*100).toFixed(0)+"%")).attr("transform",(t=>"translate("+v.centroid(t)+")")).style("text-anchor","middle").attr("class","slice"),w.append("text").text(i.getDiagramTitle()).attr("x",0).attr("y",-200).attr("class","pieTitleText");const O=w.selectAll(".legend").data(k.domain()).enter().append("g").attr("class","legend").attr("transform",((t,e)=>"translate(216,"+(22*e-22*k.domain().length/2)+")"));O.append("rect").attr("width",o).attr("height",o).style("fill",k).style("stroke",k),O.data(D).append("text").attr("x",22).attr("y",14).text((t=>{const{label:e,value:a}=t.data;return i.getShowData()?`${e} [${a}]`:e}));const z=512+Math.max(...O.selectAll("text").nodes().map((t=>(null==t?void 0:t.getBoundingClientRect().width)??0)));h.attr("viewBox",`0 0 ${z} 450`),f(h,m,z,s.useMaxWidth)}),"draw")},styles:z};export{F as diagram};
