import"./index.es.min.CZjstcJ6.js";import{p as O}from"./treemap-KMMF4GRG--FdijCcy.BPiam5wc.js";import"./reduce-BFKSG9Rs.zv3q4g-a.js";import{s as F,g as I,v as R,t as S,a as E,b as D,_ as o,aj as P,A as _,G as v,H as z,I as C,l as G,ao as N}from"./katex-D8o5-F7C.d_mIDReB.js";import{p as V}from"./chunk-4BX2VUAB-eAYYj1bL._QIYqV1t.js";import"./framework.Cre9sSJa.js";import"./index.BYYR_MCp.js";import"./index.Dyt75KH8.js";import"./flatten-CfPhNHUL.BEJm0GLS.js";var x={showLegend:!0,ticks:5,max:null,min:0,graticule:"circle"},M={axes:[],curves:[],options:x},c=structuredClone(M),B=z.radar,W=o(()=>v({...B,...C().radar}),"getConfig"),w=o(()=>c.axes,"getAxes"),H=o(()=>c.curves,"getCurves"),U=o(()=>c.options,"getOptions"),Z=o(a=>{c.axes=a.map(e=>({name:e.name,label:e.label??e.name}))},"setAxes"),k=o(a=>{c.curves=a.map(e=>({name:e.name,label:e.label??e.name,entries:q(e.entries)}))},"setCurves"),q=o(a=>{if(a[0].axis==null)return a.map(t=>t.value);let e=w();if(e.length===0)throw Error("Axes must be populated before curves for reference entries");return e.map(t=>{let r=a.find(i=>{var l;return((l=i.axis)==null?void 0:l.$refText)===t.name});if(r===void 0)throw Error("Missing entry for axis "+t.label);return r.value})},"computeCurveEntries"),h={getAxes:w,getCurves:H,getOptions:U,setAxes:Z,setCurves:k,setOptions:o(a=>{var t,r,i,l,n;let e=a.reduce((s,d)=>(s[d.name]=d,s),{});c.options={showLegend:((t=e.showLegend)==null?void 0:t.value)??x.showLegend,ticks:((r=e.ticks)==null?void 0:r.value)??x.ticks,max:((i=e.max)==null?void 0:i.value)??x.max,min:((l=e.min)==null?void 0:l.value)??x.min,graticule:((n=e.graticule)==null?void 0:n.value)??x.graticule}},"setOptions"),getConfig:W,clear:o(()=>{_(),c=structuredClone(M)},"clear"),setAccTitle:D,getAccTitle:E,setDiagramTitle:S,getDiagramTitle:R,getAccDescription:I,setAccDescription:F},J=o(a=>{V(a,h);let{axes:e,curves:t,options:r}=a;h.setAxes(e),h.setCurves(t),h.setOptions(r)},"populate"),K={parse:o(async a=>{let e=await O("radar",a);G.debug(e),J(e)},"parse")},Q=o((a,e,t,r)=>{let i=r.db,l=i.getAxes(),n=i.getCurves(),s=i.getOptions(),d=i.getConfig(),p=i.getDiagramTitle(),g=X(P(e),d),u=s.max??Math.max(...n.map($=>Math.max(...$.entries))),m=s.min,f=Math.min(d.width,d.height)/2;Y(g,l,f,s.ticks,s.graticule),j(g,l,f,d),b(g,l,n,m,u,s.graticule,d),T(g,n,s.showLegend,d),g.append("text").attr("class","radarTitle").text(p).attr("x",0).attr("y",-d.height/2-d.marginTop)},"draw"),X=o((a,e)=>{let t=e.width+e.marginLeft+e.marginRight,r=e.height+e.marginTop+e.marginBottom,i={x:e.marginLeft+e.width/2,y:e.marginTop+e.height/2};return a.attr("viewbox",`0 0 ${t} ${r}`).attr("width",t).attr("height",r),a.append("g").attr("transform",`translate(${i.x}, ${i.y})`)},"drawFrame"),Y=o((a,e,t,r,i)=>{if(i==="circle")for(let l=0;l<r;l++){let n=t*(l+1)/r;a.append("circle").attr("r",n).attr("class","radarGraticule")}else if(i==="polygon"){let l=e.length;for(let n=0;n<r;n++){let s=t*(n+1)/r,d=e.map((p,g)=>{let u=2*g*Math.PI/l-Math.PI/2;return`${s*Math.cos(u)},${s*Math.sin(u)}`}).join(" ");a.append("polygon").attr("points",d).attr("class","radarGraticule")}}},"drawGraticule"),j=o((a,e,t,r)=>{let i=e.length;for(let l=0;l<i;l++){let n=e[l].label,s=2*l*Math.PI/i-Math.PI/2;a.append("line").attr("x1",0).attr("y1",0).attr("x2",t*r.axisScaleFactor*Math.cos(s)).attr("y2",t*r.axisScaleFactor*Math.sin(s)).attr("class","radarAxisLine"),a.append("text").text(n).attr("x",t*r.axisLabelFactor*Math.cos(s)).attr("y",t*r.axisLabelFactor*Math.sin(s)).attr("class","radarAxisLabel")}},"drawAxes");function b(a,e,t,r,i,l,n){let s=e.length,d=Math.min(n.width,n.height)/2;t.forEach((p,g)=>{if(p.entries.length!==s)return;let u=p.entries.map((m,f)=>{let $=2*Math.PI*f/s-Math.PI/2,y=L(m,r,i,d);return{x:y*Math.cos($),y:y*Math.sin($)}});l==="circle"?a.append("path").attr("d",A(u,n.curveTension)).attr("class",`radarCurve-${g}`):l==="polygon"&&a.append("polygon").attr("points",u.map(m=>`${m.x},${m.y}`).join(" ")).attr("class",`radarCurve-${g}`)})}o(b,"drawCurves");function L(a,e,t,r){return r*(Math.min(Math.max(a,e),t)-e)/(t-e)}o(L,"relativeRadius");function A(a,e){let t=a.length,r=`M${a[0].x},${a[0].y}`;for(let i=0;i<t;i++){let l=a[(i-1+t)%t],n=a[i],s=a[(i+1)%t],d=a[(i+2)%t],p={x:n.x+(s.x-l.x)*e,y:n.y+(s.y-l.y)*e},g={x:s.x-(d.x-n.x)*e,y:s.y-(d.y-n.y)*e};r+=` C${p.x},${p.y} ${g.x},${g.y} ${s.x},${s.y}`}return`${r} Z`}o(A,"closedRoundCurve");function T(a,e,t,r){if(!t)return;let i=(r.width/2+r.marginRight)*3/4,l=-(r.height/2+r.marginTop)*3/4;e.forEach((n,s)=>{let d=a.append("g").attr("transform",`translate(${i}, ${l+s*20})`);d.append("rect").attr("width",12).attr("height",12).attr("class",`radarLegendBox-${s}`),d.append("text").attr("x",16).attr("y",0).attr("class","radarLegendText").text(n.label)})}o(T,"drawLegend");var ee={draw:Q},te=o((a,e)=>{let t="";for(let r=0;r<a.THEME_COLOR_LIMIT;r++){let i=a[`cScale${r}`];t+=`
		.radarCurve-${r} {
			color: ${i};
			fill: ${i};
			fill-opacity: ${e.curveOpacity};
			stroke: ${i};
			stroke-width: ${e.curveStrokeWidth};
		}
		.radarLegendBox-${r} {
			fill: ${i};
			fill-opacity: ${e.curveOpacity};
			stroke: ${i};
		}
		`}return t},"genIndexStyles"),ae=o(a=>{let e=v(N(),C().themeVariables);return{themeVariables:e,radarOptions:v(e.radar,a)}},"buildRadarStyleOptions"),ue={parser:K,db:h,renderer:ee,styles:o(({radar:a}={})=>{let{themeVariables:e,radarOptions:t}=ae(a);return`
	.radarTitle {
		font-size: ${e.fontSize};
		color: ${e.titleColor};
		dominant-baseline: hanging;
		text-anchor: middle;
	}
	.radarAxisLine {
		stroke: ${t.axisColor};
		stroke-width: ${t.axisStrokeWidth};
	}
	.radarAxisLabel {
		dominant-baseline: middle;
		text-anchor: middle;
		font-size: ${t.axisLabelFontSize}px;
		color: ${t.axisColor};
	}
	.radarGraticule {
		fill: ${t.graticuleColor};
		fill-opacity: ${t.graticuleOpacity};
		stroke: ${t.graticuleColor};
		stroke-width: ${t.graticuleStrokeWidth};
	}
	.radarLegendText {
		text-anchor: start;
		font-size: ${t.legendFontSize}px;
		dominant-baseline: hanging;
	}
	${te(e,t)}
	`},"styles")};export{ue as diagram};
