diagram-2AECGRRQ-BOerWzpU.js 5.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import{g3 as k,df as R,dr as I,g6 as E,dg as F,g4 as _,aa as l,g1 as D,bZ as z,bY as y,dm as C,cK as G,eV as P,dJ as V,cb as W}from"./admin-ZywPplgI.js";import{p as B}from"./chunk-4BX2VUAB-DHxgaJWa.js";import{p as H}from"./wardley-L42UT6IY-YUA8xAT4.js";var m={showLegend:!0,ticks:5,max:null,min:0,graticule:"circle"},b={axes:[],curves:[],options:m},x=structuredClone(b),j=G.radar,Y=l(()=>y({...j,...C().radar}),"getConfig"),w=l(()=>x.axes,"getAxes"),Z=l(()=>x.curves,"getCurves"),J=l(()=>x.options,"getOptions"),K=l(a=>{x.axes=a.map(t=>({name:t.name,label:t.label??t.name}))},"setAxes"),N=l(a=>{x.curves=a.map(t=>({name:t.name,label:t.label??t.name,entries:U(t.entries)}))},"setCurves"),U=l(a=>{if(a[0].axis==null)return a.map(e=>e.value);const t=w();if(t.length===0)throw new Error("Axes must be populated before curves for reference entries");return t.map(e=>{const r=a.find(s=>s.axis?.$refText===e.name);if(r===void 0)throw new Error("Missing entry for axis "+e.label);return r.value})},"computeCurveEntries"),X=l(a=>{const t=a.reduce((e,r)=>(e[r.name]=r,e),{});x.options={showLegend:t.showLegend?.value??m.showLegend,ticks:t.ticks?.value??m.ticks,max:t.max?.value??m.max,min:t.min?.value??m.min,graticule:t.graticule?.value??m.graticule}},"setOptions"),q=l(()=>{z(),x=structuredClone(b)},"clear"),$={getAxes:w,getCurves:Z,getOptions:J,setAxes:K,setCurves:N,setOptions:X,getConfig:Y,clear:q,setAccTitle:_,getAccTitle:F,setDiagramTitle:E,getDiagramTitle:I,getAccDescription:R,setAccDescription:k},Q=l(a=>{B(a,$);const{axes:t,curves:e,options:r}=a;$.setAxes(t),$.setCurves(e),$.setOptions(r)},"populate"),tt={parse:l(async a=>{const t=await H("radar",a);P.debug(t),Q(t)},"parse")},et=l((a,t,e,r)=>{const s=r.db,o=s.getAxes(),i=s.getCurves(),n=s.getOptions(),c=s.getConfig(),d=s.getDiagramTitle(),p=D(t),u=at(p,c),g=n.max??Math.max(...i.map(f=>Math.max(...f.entries))),h=n.min,v=Math.min(c.width,c.height)/2;rt(u,o,v,n.ticks,n.graticule),st(u,o,v,c),M(u,o,i,h,g,n.graticule,c),T(u,i,n.showLegend,c),u.append("text").attr("class","radarTitle").text(d).attr("x",0).attr("y",-c.height/2-c.marginTop)},"draw"),at=l((a,t)=>{const e=t.width+t.marginLeft+t.marginRight,r=t.height+t.marginTop+t.marginBottom,s={x:t.marginLeft+t.width/2,y:t.marginTop+t.height/2};return W(a,r,e,t.useMaxWidth??!0),a.attr("viewBox",`0 0 ${e} ${r}`),a.append("g").attr("transform",`translate(${s.x}, ${s.y})`)},"drawFrame"),rt=l((a,t,e,r,s)=>{if(s==="circle")for(let o=0;o<r;o++){const i=e*(o+1)/r;a.append("circle").attr("r",i).attr("class","radarGraticule")}else if(s==="polygon"){const o=t.length;for(let i=0;i<r;i++){const n=e*(i+1)/r,c=t.map((d,p)=>{const u=2*p*Math.PI/o-Math.PI/2,g=n*Math.cos(u),h=n*Math.sin(u);return`${g},${h}`}).join(" ");a.append("polygon").attr("points",c).attr("class","radarGraticule")}}},"drawGraticule"),st=l((a,t,e,r)=>{const s=t.length;for(let o=0;o<s;o++){const i=t[o].label,n=2*o*Math.PI/s-Math.PI/2;a.append("line").attr("x1",0).attr("y1",0).attr("x2",e*r.axisScaleFactor*Math.cos(n)).attr("y2",e*r.axisScaleFactor*Math.sin(n)).attr("class","radarAxisLine"),a.append("text").text(i).attr("x",e*r.axisLabelFactor*Math.cos(n)).attr("y",e*r.axisLabelFactor*Math.sin(n)).attr("class","radarAxisLabel")}},"drawAxes");function M(a,t,e,r,s,o,i){const n=t.length,c=Math.min(i.width,i.height)/2;e.forEach((d,p)=>{if(d.entries.length!==n)return;const u=d.entries.map((g,h)=>{const v=2*Math.PI*h/n-Math.PI/2,f=A(g,r,s,c),S=f*Math.cos(v),O=f*Math.sin(v);return{x:S,y:O}});o==="circle"?a.append("path").attr("d",L(u,i.curveTension)).attr("class",`radarCurve-${p}`):o==="polygon"&&a.append("polygon").attr("points",u.map(g=>`${g.x},${g.y}`).join(" ")).attr("class",`radarCurve-${p}`)})}l(M,"drawCurves");function A(a,t,e,r){const s=Math.min(Math.max(a,t),e);return r*(s-t)/(e-t)}l(A,"relativeRadius");function L(a,t){const e=a.length;let r=`M${a[0].x},${a[0].y}`;for(let s=0;s<e;s++){const o=a[(s-1+e)%e],i=a[s],n=a[(s+1)%e],c=a[(s+2)%e],d={x:i.x+(n.x-o.x)*t,y:i.y+(n.y-o.y)*t},p={x:n.x-(c.x-i.x)*t,y:n.y-(c.y-i.y)*t};r+=` C${d.x},${d.y} ${p.x},${p.y} ${n.x},${n.y}`}return`${r} Z`}l(L,"closedRoundCurve");function T(a,t,e,r){if(!e)return;const s=(r.width/2+r.marginRight)*3/4,o=-(r.height/2+r.marginTop)*3/4,i=20;t.forEach((n,c)=>{const d=a.append("g").attr("transform",`translate(${s}, ${o+c*i})`);d.append("rect").attr("width",12).attr("height",12).attr("class",`radarLegendBox-${c}`),d.append("text").attr("x",16).attr("y",0).attr("class","radarLegendText").text(n.label)})}l(T,"drawLegend");var nt={draw:et},ot=l((a,t)=>{let e="";for(let r=0;r<a.THEME_COLOR_LIMIT;r++){const s=a[`cScale${r}`];e+=`
  2. .radarCurve-${r} {
  3. color: ${s};
  4. fill: ${s};
  5. fill-opacity: ${t.curveOpacity};
  6. stroke: ${s};
  7. stroke-width: ${t.curveStrokeWidth};
  8. }
  9. .radarLegendBox-${r} {
  10. fill: ${s};
  11. fill-opacity: ${t.curveOpacity};
  12. stroke: ${s};
  13. }
  14. `}return e},"genIndexStyles"),it=l(a=>{const t=V(),e=C(),r=y(t,e.themeVariables),s=y(r.radar,a);return{themeVariables:r,radarOptions:s}},"buildRadarStyleOptions"),lt=l(({radar:a}={})=>{const{themeVariables:t,radarOptions:e}=it(a);return`
  15. .radarTitle {
  16. font-size: ${t.fontSize};
  17. color: ${t.titleColor};
  18. dominant-baseline: hanging;
  19. text-anchor: middle;
  20. }
  21. .radarAxisLine {
  22. stroke: ${e.axisColor};
  23. stroke-width: ${e.axisStrokeWidth};
  24. }
  25. .radarAxisLabel {
  26. dominant-baseline: middle;
  27. text-anchor: middle;
  28. font-size: ${e.axisLabelFontSize}px;
  29. color: ${e.axisColor};
  30. }
  31. .radarGraticule {
  32. fill: ${e.graticuleColor};
  33. fill-opacity: ${e.graticuleOpacity};
  34. stroke: ${e.graticuleColor};
  35. stroke-width: ${e.graticuleStrokeWidth};
  36. }
  37. .radarLegendText {
  38. text-anchor: start;
  39. font-size: ${e.legendFontSize}px;
  40. dominant-baseline: hanging;
  41. }
  42. ${ot(t,e)}
  43. `},"styles"),pt={parser:tt,db:$,renderer:nt,styles:lt};export{pt as diagram};