vitepress-mermaid-preview
Version:
Mermaid preview for vitepress
44 lines (43 loc) • 6.14 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("./chunk-353BL4L5-DxnmASPI.cjs"),n=require("./component-EjRj2lD0.cjs"),O=require("./mermaid-parser.core-BVAOqJFG.cjs");var h={showLegend:!0,ticks:5,max:null,min:0,graticule:"circle"},y={axes:[],curves:[],options:h},p=structuredClone(y),S=n.defaultConfig_default.radar,k=n.__name(()=>n.cleanAndMerge({...S,...n.getConfig().radar}),"getConfig"),f=n.__name(()=>p.axes,"getAxes"),D=n.__name(()=>p.curves,"getCurves"),R=n.__name(()=>p.options,"getOptions"),I=n.__name(a=>{p.axes=a.map(e=>({name:e.name,label:e.label??e.name}))},"setAxes"),E=n.__name(a=>{p.curves=a.map(e=>({name:e.name,label:e.label??e.name,entries:F(e.entries)}))},"setCurves"),F=n.__name(a=>{if(a[0].axis==null)return a.map(t=>t.value);const e=f();if(e.length===0)throw new Error("Axes must be populated before curves for reference entries");return e.map(t=>{const r=a.find(s=>s.axis?.$refText===t.name);if(r===void 0)throw new Error("Missing entry for axis "+t.label);return r.value})},"computeCurveEntries"),P=n.__name(a=>{const e=a.reduce((t,r)=>(t[r.name]=r,t),{});p.options={showLegend:e.showLegend?.value??h.showLegend,ticks:e.ticks?.value??h.ticks,max:e.max?.value??h.max,min:e.min?.value??h.min,graticule:e.graticule?.value??h.graticule}},"setOptions"),G=n.__name(()=>{n.clear(),p=structuredClone(y)},"clear"),_={getAxes:f,getCurves:D,getOptions:R,setAxes:I,setCurves:E,setOptions:P,getConfig:k,clear:G,setAccTitle:n.setAccTitle,getAccTitle:n.getAccTitle,setDiagramTitle:n.setDiagramTitle,getDiagramTitle:n.getDiagramTitle,getAccDescription:n.getAccDescription,setAccDescription:n.setAccDescription},z=n.__name(a=>{T.populateCommonDb(a,_);const{axes:e,curves:t,options:r}=a;_.setAxes(e),_.setCurves(t),_.setOptions(r)},"populate"),B={parse:n.__name(async a=>{const e=await O.parse("radar",a);n.log.debug(e),z(e)},"parse")},V=n.__name((a,e,t,r)=>{const s=r.db,i=s.getAxes(),l=s.getCurves(),o=s.getOptions(),c=s.getConfig(),d=s.getDiagramTitle(),u=n.selectSvgElement(e),m=W(u,c),g=o.max??Math.max(...l.map($=>Math.max(...$.entries))),x=o.min,v=Math.min(c.width,c.height)/2;j(m,i,v,o.ticks,o.graticule),q(m,i,v,c),C(m,i,l,x,g,o.graticule,c),A(m,l,o.showLegend,c),m.append("text").attr("class","radarTitle").text(d).attr("x",0).attr("y",-c.height/2-c.marginTop)},"draw"),W=n.__name((a,e)=>{const t=e.width+e.marginLeft+e.marginRight,r=e.height+e.marginTop+e.marginBottom,s={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(${s.x}, ${s.y})`)},"drawFrame"),j=n.__name((a,e,t,r,s)=>{if(s==="circle")for(let i=0;i<r;i++){const l=t*(i+1)/r;a.append("circle").attr("r",l).attr("class","radarGraticule")}else if(s==="polygon"){const i=e.length;for(let l=0;l<r;l++){const o=t*(l+1)/r,c=e.map((d,u)=>{const m=2*u*Math.PI/i-Math.PI/2,g=o*Math.cos(m),x=o*Math.sin(m);return`${g},${x}`}).join(" ");a.append("polygon").attr("points",c).attr("class","radarGraticule")}}},"drawGraticule"),q=n.__name((a,e,t,r)=>{const s=e.length;for(let i=0;i<s;i++){const l=e[i].label,o=2*i*Math.PI/s-Math.PI/2;a.append("line").attr("x1",0).attr("y1",0).attr("x2",t*r.axisScaleFactor*Math.cos(o)).attr("y2",t*r.axisScaleFactor*Math.sin(o)).attr("class","radarAxisLine"),a.append("text").text(l).attr("x",t*r.axisLabelFactor*Math.cos(o)).attr("y",t*r.axisLabelFactor*Math.sin(o)).attr("class","radarAxisLabel")}},"drawAxes");function C(a,e,t,r,s,i,l){const o=e.length,c=Math.min(l.width,l.height)/2;t.forEach((d,u)=>{if(d.entries.length!==o)return;const m=d.entries.map((g,x)=>{const v=2*Math.PI*x/o-Math.PI/2,$=w(g,r,s,c),M=$*Math.cos(v),L=$*Math.sin(v);return{x:M,y:L}});i==="circle"?a.append("path").attr("d",b(m,l.curveTension)).attr("class",`radarCurve-${u}`):i==="polygon"&&a.append("polygon").attr("points",m.map(g=>`${g.x},${g.y}`).join(" ")).attr("class",`radarCurve-${u}`)})}n.__name(C,"drawCurves");function w(a,e,t,r){const s=Math.min(Math.max(a,e),t);return r*(s-e)/(t-e)}n.__name(w,"relativeRadius");function b(a,e){const t=a.length;let r=`M${a[0].x},${a[0].y}`;for(let s=0;s<t;s++){const i=a[(s-1+t)%t],l=a[s],o=a[(s+1)%t],c=a[(s+2)%t],d={x:l.x+(o.x-i.x)*e,y:l.y+(o.y-i.y)*e},u={x:o.x-(c.x-l.x)*e,y:o.y-(c.y-l.y)*e};r+=` C${d.x},${d.y} ${u.x},${u.y} ${o.x},${o.y}`}return`${r} Z`}n.__name(b,"closedRoundCurve");function A(a,e,t,r){if(!t)return;const s=(r.width/2+r.marginRight)*3/4,i=-(r.height/2+r.marginTop)*3/4,l=20;e.forEach((o,c)=>{const d=a.append("g").attr("transform",`translate(${s}, ${i+c*l})`);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(o.label)})}n.__name(A,"drawLegend");var H={draw:V},N=n.__name((a,e)=>{let t="";for(let r=0;r<a.THEME_COLOR_LIMIT;r++){const s=a[`cScale${r}`];t+=`
.radarCurve-${r} {
color: ${s};
fill: ${s};
fill-opacity: ${e.curveOpacity};
stroke: ${s};
stroke-width: ${e.curveStrokeWidth};
}
.radarLegendBox-${r} {
fill: ${s};
fill-opacity: ${e.curveOpacity};
stroke: ${s};
}
`}return t},"genIndexStyles"),U=n.__name(a=>{const e=n.getThemeVariables3(),t=n.getConfig(),r=n.cleanAndMerge(e,t.themeVariables),s=n.cleanAndMerge(r.radar,a);return{themeVariables:r,radarOptions:s}},"buildRadarStyleOptions"),X=n.__name(({radar:a}={})=>{const{themeVariables:e,radarOptions:t}=U(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;
}
${N(e,t)}
`},"styles"),Y={parser:B,db:_,renderer:H,styles:X};exports.diagram=Y;