import{c as e}from"./chunk-4KE642ED-DDvPuFrd.js";import{p as t}from"./treemap-KMMF4GRG-7ORZ52ND-Br-M8qul.js";import{$ as a,G as i,U as l,H as r,e as n,j as s,m 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-BCkSasan.js";import"./chunk-OMTJKCYW-B6LfB1Nw.js";var $=S.pie,v={sections:new Map,showData:!1},y=v.sections,b=v.showData,D=structuredClone($),T={getConfig:o(()=>structuredClone(D),"getConfig"),clear:o(()=>{y=new Map,b=v.showData,x()},"clear"),setDiagramTitle:s,getDiagramTitle:n,setAccTitle:r,getAccTitle:l,setAccDescription:i,getAccDescription:a,addSection:o(({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:o(()=>y,"getSections"),setShowData:o(e=>{b=e},"setShowData"),getShowData:o(()=>b,"getShowData")},C=o((t,a)=>{e(t,a),a.setShowData(t.showData),t.sections.map(a.addSection)},"populateDb"),k={parse:o(async e=>{let a=await t("pie",e);p.debug(a),C(a,T)},"parse")},A=o(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=o(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=o((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-Jp9b5oiS.js.map
