UNPKG

vitepress-mermaid-preview

Version:

Mermaid preview for vitepress

31 lines (30 loc) 5.1 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("./chunk-353BL4L5-DxnmASPI.cjs"),t=require("./component-EjRj2lD0.cjs"),I=require("./mermaid-parser.core-BVAOqJFG.cjs"),F=require("./arc-BnBVmS1n.cjs"),q=require("./ordinal-CagbB1m8.cjs");function B(e,n){return n<e?-1:n>e?1:n>=e?0:NaN}function V(e){return e}function j(){var e=V,n=B,m=null,s=t.constant(0),g=t.constant(t.tau),y=t.constant(0);function o(a){var r,c=(a=t.array(a)).length,d,x,h=0,u=new Array(c),i=new Array(c),v=+s.apply(this,arguments),A=Math.min(t.tau,Math.max(-t.tau,g.apply(this,arguments)-v)),f,T=Math.min(Math.abs(A)/c,y.apply(this,arguments)),_=T*(A<0?-1:1),p;for(r=0;r<c;++r)(p=i[u[r]=r]=+e(a[r],r,a))>0&&(h+=p);for(n!=null?u.sort(function(S,D){return n(i[S],i[D])}):m!=null&&u.sort(function(S,D){return m(a[S],a[D])}),r=0,x=h?(A-c*_)/h:0;r<c;++r,v=f)d=u[r],p=i[d],f=v+(p>0?p*x:0)+_,i[d]={data:a[d],index:r,value:p,startAngle:v,endAngle:f,padAngle:T};return i}return o.value=function(a){return arguments.length?(e=typeof a=="function"?a:t.constant(+a),o):e},o.sortValues=function(a){return arguments.length?(n=a,m=null,o):n},o.sort=function(a){return arguments.length?(m=a,n=null,o):m},o.startAngle=function(a){return arguments.length?(s=typeof a=="function"?a:t.constant(+a),o):s},o.endAngle=function(a){return arguments.length?(g=typeof a=="function"?a:t.constant(+a),o):g},o.padAngle=function(a){return arguments.length?(y=typeof a=="function"?a:t.constant(+a),o):y},o}var U=t.defaultConfig_default.pie,E={sections:new Map,showData:!1},k=E.sections,M=E.showData,Z=structuredClone(U),H=t.__name(()=>structuredClone(Z),"getConfig"),J=t.__name(()=>{k=new Map,M=E.showData,t.clear()},"clear"),K=t.__name(({label:e,value:n})=>{k.has(e)||(k.set(e,n),t.log.debug(`added new section: ${e}, with value: ${n}`))},"addSection"),Q=t.__name(()=>k,"getSections"),X=t.__name(e=>{M=e},"setShowData"),Y=t.__name(()=>M,"getShowData"),G={getConfig:H,clear:J,setDiagramTitle:t.setDiagramTitle,getDiagramTitle:t.getDiagramTitle,setAccTitle:t.setAccTitle,getAccTitle:t.getAccTitle,setAccDescription:t.setAccDescription,getAccDescription:t.getAccDescription,addSection:K,getSections:Q,setShowData:X,getShowData:Y},ee=t.__name((e,n)=>{R.populateCommonDb(e,n),n.setShowData(e.showData),e.sections.map(n.addSection)},"populateDb"),te={parse:t.__name(async e=>{const n=await I.parse("pie",e);t.log.debug(n),ee(n,G)},"parse")},ae=t.__name(e=>` .pieCircle{ stroke: ${e.pieStrokeColor}; stroke-width : ${e.pieStrokeWidth}; opacity : ${e.pieOpacity}; } .pieOuterCircle{ stroke: ${e.pieOuterStrokeColor}; stroke-width: ${e.pieOuterStrokeWidth}; fill: none; } .pieTitleText { text-anchor: middle; font-size: ${e.pieTitleTextSize}; fill: ${e.pieTitleTextColor}; font-family: ${e.fontFamily}; } .slice { font-family: ${e.fontFamily}; fill: ${e.pieSectionTextColor}; font-size:${e.pieSectionTextSize}; // fill: white; } .legend text { fill: ${e.pieLegendTextColor}; font-family: ${e.fontFamily}; font-size: ${e.pieLegendTextSize}; } `,"getStyles"),ne=ae,re=t.__name(e=>{const n=[...e.entries()].map(s=>({label:s[0],value:s[1]})).sort((s,g)=>g.value-s.value);return j().value(s=>s.value)(n)},"createPieArcs"),ie=t.__name((e,n,m,s)=>{t.log.debug(`rendering pie chart `+e);const g=s.db,y=t.getConfig2(),o=t.cleanAndMerge(g.getConfig(),y.pie),a=40,r=18,c=4,d=450,x=d,h=t.selectSvgElement(n),u=h.append("g");u.attr("transform","translate("+x/2+","+d/2+")");const{themeVariables:i}=y;let[v]=t.parseFontSize(i.pieOuterStrokeWidth);v??=2;const A=o.textPosition,f=Math.min(x,d)/2-a,T=F.d3arc().innerRadius(0).outerRadius(f),_=F.d3arc().innerRadius(f*A).outerRadius(f*A);u.append("circle").attr("cx",0).attr("cy",0).attr("r",f+v/2).attr("class","pieOuterCircle");const p=g.getSections(),S=re(p),D=[i.pie1,i.pie2,i.pie3,i.pie4,i.pie5,i.pie6,i.pie7,i.pie8,i.pie9,i.pie10,i.pie11,i.pie12],w=q.ordinal(D);u.selectAll("mySlices").data(S).enter().append("path").attr("d",T).attr("fill",l=>w(l.data.label)).attr("class","pieCircle");let z=0;p.forEach(l=>{z+=l}),u.selectAll("mySlices").data(S).enter().append("text").text(l=>(l.data.value/z*100).toFixed(0)+"%").attr("transform",l=>"translate("+_.centroid(l)+")").style("text-anchor","middle").attr("class","slice"),u.append("text").text(g.getDiagramTitle()).attr("x",0).attr("y",-400/2).attr("class","pieTitleText");const b=u.selectAll(".legend").data(w.domain()).enter().append("g").attr("class","legend").attr("transform",(l,C)=>{const $=r+c,O=$*w.domain().length/2,W=12*r,N=C*$-O;return"translate("+W+","+N+")"});b.append("rect").attr("width",r).attr("height",r).style("fill",w).style("stroke",w),b.data(S).append("text").attr("x",r+c).attr("y",r-c).text(l=>{const{label:C,value:$}=l.data;return g.getShowData()?`${C} [${$}]`:C});const L=Math.max(...b.selectAll("text").nodes().map(l=>l?.getBoundingClientRect().width??0)),P=x+a+r+c+L;h.attr("viewBox",`0 0 ${P} ${d}`),t.configureSvgSize(h,d,P,o.useMaxWidth)},"draw"),oe={draw:ie},se={parser:te,db:G,renderer:oe,styles:ne};exports.diagram=se;