import"./index.es.min.CZjstcJ6.js";import{p as P}from"./treemap-KMMF4GRG--FdijCcy.BPiam5wc.js";import"./reduce-BFKSG9Rs.zv3q4g-a.js";import{g as N,s as R,a as L,b as W,v as B,t as I,_ as p,l as F,c as j,G,aj as U,al as V,e as H,A as q,H as J,am as h,an as K}from"./katex-D8o5-F7C.d_mIDReB.js";import{o as Q}from"./ordinal-DOM6Fa9P.XmCBZysb.js";import{a as E,t as _}from"./arc-BqlAOiZb.BxhGD7fv.js";import{p as X}from"./chunk-4BX2VUAB-eAYYj1bL._QIYqV1t.js";import"./framework.Cre9sSJa.js";import"./index.BYYR_MCp.js";import"./index.Dyt75KH8.js";import"./flatten-CfPhNHUL.BEJm0GLS.js";import"./init-hAkIK9Bd.DALLPRap.js";function Y(t,a){return a<t?-1:a>t?1:a>=t?0:NaN}function Z(t){return t}function tt(){var t=Z,a=Y,d=null,s=h(0),o=h(_),y=h(0);function n(e){var l,i=(e=K(e)).length,g,A,D=0,x=Array(i),u=Array(i),S=+s.apply(this,arguments),b=Math.min(_,Math.max(-_,o.apply(this,arguments)-S)),f,T=Math.min(Math.abs(b)/i,y.apply(this,arguments)),v=T*(b<0?-1:1),c;for(l=0;l<i;++l)(c=u[x[l]=l]=+t(e[l],l,e))>0&&(D+=c);for(a==null?d!=null&&x.sort(function(m,w){return d(e[m],e[w])}):x.sort(function(m,w){return a(u[m],u[w])}),l=0,A=D?(b-i*v)/D:0;l<i;++l,S=f)g=x[l],c=u[g],f=S+(c>0?c*A:0)+v,u[g]={data:e[g],index:l,value:c,startAngle:S,endAngle:f,padAngle:T};return u}return n.value=function(e){return arguments.length?(t=typeof e=="function"?e:h(+e),n):t},n.sortValues=function(e){return arguments.length?(a=e,d=null,n):a},n.sort=function(e){return arguments.length?(d=e,a=null,n):d},n.startAngle=function(e){return arguments.length?(s=typeof e=="function"?e:h(+e),n):s},n.endAngle=function(e){return arguments.length?(o=typeof e=="function"?e:h(+e),n):o},n.padAngle=function(e){return arguments.length?(y=typeof e=="function"?e:h(+e),n):y},n}var et=J.pie,M={sections:new Map,showData:!1},$=M.sections,k=M.showData,at=structuredClone(et),z={getConfig:p(()=>structuredClone(at),"getConfig"),clear:p(()=>{$=new Map,k=M.showData,q()},"clear"),setDiagramTitle:I,getDiagramTitle:B,setAccTitle:W,getAccTitle:L,setAccDescription:R,getAccDescription:N,addSection:p(({label:t,value:a})=>{if(a<0)throw Error(`"${t}" has invalid value: ${a}. Negative values are not allowed in pie charts. All slice values must be >= 0.`);$.has(t)||($.set(t,a),F.debug(`added new section: ${t}, with value: ${a}`))},"addSection"),getSections:p(()=>$,"getSections"),setShowData:p(t=>{k=t},"setShowData"),getShowData:p(()=>k,"getShowData")},rt=p((t,a)=>{X(t,a),a.setShowData(t.showData),t.sections.map(a.addSection)},"populateDb"),it={parse:p(async t=>{let a=await P("pie",t);F.debug(a),rt(a,z)},"parse")},lt=p(t=>`
  .pieCircle{
    stroke: ${t.pieStrokeColor};
    stroke-width : ${t.pieStrokeWidth};
    opacity : ${t.pieOpacity};
  }
  .pieOuterCircle{
    stroke: ${t.pieOuterStrokeColor};
    stroke-width: ${t.pieOuterStrokeWidth};
    fill: none;
  }
  .pieTitleText {
    text-anchor: middle;
    font-size: ${t.pieTitleTextSize};
    fill: ${t.pieTitleTextColor};
    font-family: ${t.fontFamily};
  }
  .slice {
    font-family: ${t.fontFamily};
    fill: ${t.pieSectionTextColor};
    font-size:${t.pieSectionTextSize};
    // fill: white;
  }
  .legend text {
    fill: ${t.pieLegendTextColor};
    font-family: ${t.fontFamily};
    font-size: ${t.pieLegendTextSize};
  }
`,"getStyles"),nt=p(t=>{let a=[...t.values()].reduce((s,o)=>s+o,0),d=[...t.entries()].map(([s,o])=>({label:s,value:o})).filter(s=>s.value/a*100>=1).sort((s,o)=>o.value-s.value);return tt().value(s=>s.value)(d)},"createPieArcs"),St={parser:it,db:z,renderer:{draw:p((t,a,d,s)=>{F.debug(`rendering pie chart
`+t);let o=s.db,y=j(),n=G(o.getConfig(),y.pie),e=U(a),l=e.append("g");l.attr("transform","translate(225,225)");let{themeVariables:i}=y,[g]=V(i.pieOuterStrokeWidth);g??(g=2);let A=n.textPosition,D=E().innerRadius(0).outerRadius(185),x=E().innerRadius(185*A).outerRadius(185*A);l.append("circle").attr("cx",0).attr("cy",0).attr("r",185+g/2).attr("class","pieOuterCircle");let u=o.getSections(),S=nt(u),b=[i.pie1,i.pie2,i.pie3,i.pie4,i.pie5,i.pie6,i.pie7,i.pie8,i.pie9,i.pie10,i.pie11,i.pie12],f=0;u.forEach(r=>{f+=r});let T=S.filter(r=>(r.data.value/f*100).toFixed(0)!=="0"),v=Q(b);l.selectAll("mySlices").data(T).enter().append("path").attr("d",D).attr("fill",r=>v(r.data.label)).attr("class","pieCircle"),l.selectAll("mySlices").data(T).enter().append("text").text(r=>(r.data.value/f*100).toFixed(0)+"%").attr("transform",r=>"translate("+x.centroid(r)+")").style("text-anchor","middle").attr("class","slice"),l.append("text").text(o.getDiagramTitle()).attr("x",0).attr("y",-400/2).attr("class","pieTitleText");let c=[...u.entries()].map(([r,C])=>({label:r,value:C})),m=l.selectAll(".legend").data(c).enter().append("g").attr("class","legend").attr("transform",(r,C)=>{let O=22*c.length/2;return"translate(216,"+(C*22-O)+")"});m.append("rect").attr("width",18).attr("height",18).style("fill",r=>v(r.label)).style("stroke",r=>v(r.label)),m.append("text").attr("x",22).attr("y",14).text(r=>o.getShowData()?`${r.label} [${r.value}]`:r.label);let w=512+Math.max(...m.selectAll("text").nodes().map(r=>(r==null?void 0:r.getBoundingClientRect().width)??0));e.attr("viewBox",`0 0 ${w} 450`),H(e,450,w,n.useMaxWidth)},"draw")},styles:lt};export{St as diagram};
