UNPKG

ruru

Version:

Grafast-flavoured GraphiQL distribution

2 lines 4.43 kB
export const __webpack_esm_id__=3097;export const __webpack_esm_ids__=[3097];export const __webpack_esm_modules__={15348(e,t,a){function i(e,t){e.accDescr&&t.setAccDescription?.(e.accDescr),e.accTitle&&t.setAccTitle?.(e.accTitle),e.title&&t.setDiagramTitle?.(e.title)}a.r(t),a.d(t,{populateCommonDb:()=>i}),(0,a(60162).__name)(i,"populateCommonDb")},23097(e,t,a){a.r(t),a.d(t,{diagram:()=>C});var i=a(92329),n=a(15348),l=a(82029),r=a(54141),o=a(60162),s=a(73744),c=a(79806),p=r.defaultConfig_default.pie,d={sections:new Map,showData:!1,config:p},g=d.sections,m=d.showData,u=structuredClone(p),_=(0,o.__name)(()=>structuredClone(u),"getConfig"),f=(0,o.__name)(()=>{g=new Map,m=d.showData,(0,r.clear)()},"clear"),h=(0,o.__name)(({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.`);g.has(e)||(g.set(e,t),o.log.debug(`added new section: ${e}, with value: ${t}`))},"addSection"),x=(0,o.__name)(()=>g,"getSections"),w=(0,o.__name)(e=>{m=e},"setShowData"),S=(0,o.__name)(()=>m,"getShowData"),D={getConfig:_,clear:f,setDiagramTitle:r.setDiagramTitle,getDiagramTitle:r.getDiagramTitle,setAccTitle:r.setAccTitle,getAccTitle:r.getAccTitle,setAccDescription:r.setAccDescription,getAccDescription:r.getAccDescription,addSection:h,getSections:x,setShowData:w,getShowData:S},T=(0,o.__name)((e,t)=>{(0,n.populateCommonDb)(e,t),t.setShowData(e.showData),e.sections.map(t.addSection)},"populateDb"),b={parse:(0,o.__name)(async e=>{const t=await(0,s.parse)("pie",e);o.log.debug(t),T(t,D)},"parse")},v=(0,o.__name)(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"),$=(0,o.__name)(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.pie)().value(e=>e.value)(a)},"createPieArcs"),C={parser:b,db:D,renderer:{draw:(0,o.__name)((e,t,a,n)=>{o.log.debug("rendering pie chart\n"+e);const s=n.db,p=(0,r.getConfig2)(),d=(0,l.cleanAndMerge)(s.getConfig(),p.pie),g=(0,i.selectSvgElement)(t),m=g.append("g");m.attr("transform","translate(225,225)");const{themeVariables:u}=p;let[_]=(0,l.parseFontSize)(u.pieOuterStrokeWidth);_??=2;const f=d.textPosition,h=Math.min(450,450)/2-40,x=(0,c.arc)().innerRadius(0).outerRadius(h),w=(0,c.arc)().innerRadius(h*f).outerRadius(h*f);m.append("circle").attr("cx",0).attr("cy",0).attr("r",h+_/2).attr("class","pieOuterCircle");const S=s.getSections(),D=$(S),T=[u.pie1,u.pie2,u.pie3,u.pie4,u.pie5,u.pie6,u.pie7,u.pie8,u.pie9,u.pie10,u.pie11,u.pie12];let b=0;S.forEach(e=>{b+=e});const v=D.filter(e=>"0"!==(e.data.value/b*100).toFixed(0)),C=(0,c.scaleOrdinal)(T);m.selectAll("mySlices").data(v).enter().append("path").attr("d",x).attr("fill",e=>C(e.data.label)).attr("class","pieCircle"),m.selectAll("mySlices").data(v).enter().append("text").text(e=>(e.data.value/b*100).toFixed(0)+"%").attr("transform",e=>"translate("+w.centroid(e)+")").style("text-anchor","middle").attr("class","slice"),m.append("text").text(s.getDiagramTitle()).attr("x",0).attr("y",-200).attr("class","pieTitleText");const y=[...S.entries()].map(([e,t])=>({label:e,value:t})),A=m.selectAll(".legend").data(y).enter().append("g").attr("class","legend").attr("transform",(e,t)=>"translate(216,"+(22*t-22*y.length/2)+")");A.append("rect").attr("width",18).attr("height",18).style("fill",e=>C(e.label)).style("stroke",e=>C(e.label)),A.append("text").attr("x",22).attr("y",14).text(e=>s.getShowData()?`${e.label} [${e.value}]`:e.label);const k=512+Math.max(...A.selectAll("text").nodes().map(e=>e?.getBoundingClientRect().width??0));g.attr("viewBox",`0 0 ${k} 450`),(0,r.configureSvgSize)(g,450,k,d.useMaxWidth)},"draw")},styles:v}}}; //# sourceMappingURL=3097.js.map