openrag/assets/js/9412.74eee71d.js
2025-10-27 14:28:45 +00:00

1 line
No EOL
3.8 KiB
JavaScript

"use strict";(self.webpackChunkopenrag_docs=self.webpackChunkopenrag_docs||[]).push([[9412],{9412:(e,t,a)=>{a.d(t,{diagram:()=>T});var i=a(3590),l=a(5871),n=a(3226),r=a(7633),s=a(797),o=a(8731),c=a(451),p=r.UI.pie,d={sections:new Map,showData:!1,config:p},u=d.sections,g=d.showData,h=structuredClone(p),f=(0,s.K2)(()=>structuredClone(h),"getConfig"),m=(0,s.K2)(()=>{u=new Map,g=d.showData,(0,r.IU)()},"clear"),w=(0,s.K2)(({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.`);u.has(e)||(u.set(e,t),s.Rm.debug(`added new section: ${e}, with value: ${t}`))},"addSection"),x=(0,s.K2)(()=>u,"getSections"),S=(0,s.K2)(e=>{g=e},"setShowData"),$=(0,s.K2)(()=>g,"getShowData"),v={getConfig:f,clear:m,setDiagramTitle:r.ke,getDiagramTitle:r.ab,setAccTitle:r.SV,getAccTitle:r.iN,setAccDescription:r.EI,getAccDescription:r.m7,addSection:w,getSections:x,setShowData:S,getShowData:$},b=(0,s.K2)((e,t)=>{(0,l.S)(e,t),t.setShowData(e.showData),e.sections.map(t.addSection)},"populateDb"),y={parse:(0,s.K2)(async e=>{const t=await(0,o.qg)("pie",e);s.Rm.debug(t),b(t,v)},"parse")},D=(0,s.K2)(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"),C=(0,s.K2)(e=>{const 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(0,c.rLf)().value(e=>e.value)(a)},"createPieArcs"),T={parser:y,db:v,renderer:{draw:(0,s.K2)((e,t,a,l)=>{s.Rm.debug("rendering pie chart\n"+e);const o=l.db,p=(0,r.D7)(),d=(0,n.$t)(o.getConfig(),p.pie),u=18,g=450,h=g,f=(0,i.D)(t),m=f.append("g");m.attr("transform","translate(225,225)");const{themeVariables:w}=p;let[x]=(0,n.I5)(w.pieOuterStrokeWidth);x??=2;const S=d.textPosition,$=Math.min(h,g)/2-40,v=(0,c.JLW)().innerRadius(0).outerRadius($),b=(0,c.JLW)().innerRadius($*S).outerRadius($*S);m.append("circle").attr("cx",0).attr("cy",0).attr("r",$+x/2).attr("class","pieOuterCircle");const y=o.getSections(),D=C(y),T=[w.pie1,w.pie2,w.pie3,w.pie4,w.pie5,w.pie6,w.pie7,w.pie8,w.pie9,w.pie10,w.pie11,w.pie12];let k=0;y.forEach(e=>{k+=e});const K=D.filter(e=>"0"!==(e.data.value/k*100).toFixed(0)),A=(0,c.UMr)(T);m.selectAll("mySlices").data(K).enter().append("path").attr("d",v).attr("fill",e=>A(e.data.label)).attr("class","pieCircle"),m.selectAll("mySlices").data(K).enter().append("text").text(e=>(e.data.value/k*100).toFixed(0)+"%").attr("transform",e=>"translate("+b.centroid(e)+")").style("text-anchor","middle").attr("class","slice"),m.append("text").text(o.getDiagramTitle()).attr("x",0).attr("y",-200).attr("class","pieTitleText");const R=[...y.entries()].map(([e,t])=>({label:e,value:t})),z=m.selectAll(".legend").data(R).enter().append("g").attr("class","legend").attr("transform",(e,t)=>"translate(216,"+(22*t-22*R.length/2)+")");z.append("rect").attr("width",u).attr("height",u).style("fill",e=>A(e.label)).style("stroke",e=>A(e.label)),z.append("text").attr("x",22).attr("y",14).text(e=>o.getShowData()?`${e.label} [${e.value}]`:e.label);const M=512+Math.max(...z.selectAll("text").nodes().map(e=>e?.getBoundingClientRect().width??0));f.attr("viewBox",`0 0 ${M} 450`),(0,r.a$)(f,g,M,d.useMaxWidth)},"draw")},styles:D}}}]);