import{c as e}from"./chunk-4KE642ED-D2VUabb0.js";import{p as t}from"./treemap-KMMF4GRG-7ORZ52ND-DFBaIa1s.js";import{m as a,$ as i,G as l,U as r,H as n,e as s,j as o,p,a as d,L as c,a6 as u,a8 as g,a9 as h,aa as m,W as f,N as x,ab as w,r as S}from"./index-BDq3hoFe.js";import"./chunk-OMTJKCYW-D0VGaEv2.js";var $=S.pie,v={sections:new Map,showData:!1},y=v.sections,b=v.showData,D=structuredClone($),T={getConfig:a(()=>structuredClone(D),"getConfig"),clear:a(()=>{y=new Map,b=v.showData,x()},"clear"),setDiagramTitle:o,getDiagramTitle:s,setAccTitle:n,getAccTitle:r,setAccDescription:l,getAccDescription:i,addSection:a(({label:e,value:t})=>{if(t<0)throw new Error(`"${e}" has invalid value: ${t}. Negative values are not allowed in pie charts. All slice values must be >= 0.`);y.has(e)||(y.set(e,t),p.debug(`added new section: ${e}, with value: ${t}`))},"addSection"),getSections:a(()=>y,"getSections"),setShowData:a(e=>{b=e},"setShowData"),getShowData:a(()=>b,"getShowData")},C=a((t,a)=>{e(t,a),a.setShowData(t.showData),t.sections.map(a.addSection)},"populateDb"),k={parse:a(async e=>{let a=await t("pie",e);p.debug(a),C(a,T)},"parse")},A=a(e=>`\n  .pieCircle{\n    stroke: ${e.pieStrokeColor};\n    stroke-width : ${e.pieStrokeWidth};\n    opacity : ${e.pieOpacity};\n  }\n  .pieOuterCircle{\n    stroke: ${e.pieOuterStrokeColor};\n    stroke-width: ${e.pieOuterStrokeWidth};\n    fill: none;\n  }\n  .pieTitleText {\n    text-anchor: middle;\n    font-size: ${e.pieTitleTextSize};\n    fill: ${e.pieTitleTextColor};\n    font-family: ${e.fontFamily};\n  }\n  .slice {\n    font-family: ${e.fontFamily};\n    fill: ${e.pieSectionTextColor};\n    font-size:${e.pieSectionTextSize};\n    // fill: white;\n  }\n  .legend text {\n    fill: ${e.pieLegendTextColor};\n    font-family: ${e.fontFamily};\n    font-size: ${e.pieLegendTextSize};\n  }\n`,"getStyles"),M=a(e=>{let t=[...e.values()].reduce((e,t)=>e+t,0),a=[...e.entries()].map(([e,t])=>({label:e,value:t})).filter(e=>e.value/t*100>=1).sort((e,t)=>t.value-e.value);return w().value(e=>e.value)(a)},"createPieArcs"),O=a((e,t,a,i)=>{p.debug("rendering pie chart\n"+e);let l=i.db,r=d(),n=c(l.getConfig(),r.pie),s=18,o=450,x=o,w=u(t),S=w.append("g");S.attr("transform","translate(225,225)");let{themeVariables:$}=r,[v]=g($.pieOuterStrokeWidth);v??=2;let y=n.textPosition,b=Math.min(x,o)/2-40,D=h().innerRadius(0).outerRadius(b),T=h().innerRadius(b*y).outerRadius(b*y);S.append("circle").attr("cx",0).attr("cy",0).attr("r",b+v/2).attr("class","pieOuterCircle");let C=l.getSections(),k=M(C),A=[$.pie1,$.pie2,$.pie3,$.pie4,$.pie5,$.pie6,$.pie7,$.pie8,$.pie9,$.pie10,$.pie11,$.pie12],O=0;C.forEach(e=>{O+=e});let R=k.filter(e=>"0"!==(e.data.value/O*100).toFixed(0)),z=m(A);S.selectAll("mySlices").data(R).enter().append("path").attr("d",D).attr("fill",e=>z(e.data.label)).attr("class","pieCircle"),S.selectAll("mySlices").data(R).enter().append("text").text(e=>(e.data.value/O*100).toFixed(0)+"%").attr("transform",e=>"translate("+T.centroid(e)+")").style("text-anchor","middle").attr("class","slice"),S.append("text").text(l.getDiagramTitle()).attr("x",0).attr("y",-200).attr("class","pieTitleText");let F=[...C.entries()].map(([e,t])=>({label:e,value:t})),W=S.selectAll(".legend").data(F).enter().append("g").attr("class","legend").attr("transform",(e,t)=>"translate(216,"+(22*t-22*F.length/2)+")");W.append("rect").attr("width",s).attr("height",s).style("fill",e=>z(e.label)).style("stroke",e=>z(e.label)),W.append("text").attr("x",22).attr("y",14).text(e=>l.getShowData()?`${e.label} [${e.value}]`:e.label);let j=512+Math.max(...W.selectAll("text").nodes().map(e=>e?.getBoundingClientRect().width??0));w.attr("viewBox",`0 0 ${j} 450`),f(w,o,j,n.useMaxWidth)},"draw"),R={parser:k,db:T,renderer:{draw:O},styles:A};export{R as diagram};
//# sourceMappingURL=pieDiagram-QB62DFGK-mcumhtSU.js.map
