mermaid
Version:
Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.
25 lines (24 loc) • 11.6 kB
JavaScript
import{a as ye}from"./chunk-V3KJR4XU.mjs";import{a as ue}from"./chunk-Y5O5OPKC.mjs";import"./chunk-3T2MNPEU.mjs";import"./chunk-MLQVGYRW.mjs";import"./chunk-QX7LGXZU.mjs";import"./chunk-22SYA5HA.mjs";import"./chunk-YZG4BXY6.mjs";import"./chunk-NRRTYJAG.mjs";import"./chunk-CVBX6EWK.mjs";import"./chunk-RXM7Z7NK.mjs";import"./chunk-HI3EPXIC.mjs";import"./chunk-5NYYYZGL.mjs";import"./chunk-H7BX327W.mjs";import{a as he}from"./chunk-R2KH53MI.mjs";import"./chunk-LIEGGFIX.mjs";import"./chunk-LLWYPJEZ.mjs";import"./chunk-2FTYKNOQ.mjs";import"./chunk-36VM3LGA.mjs";import"./chunk-44AU3KAP.mjs";import{a as Se}from"./chunk-S4TE5DX6.mjs";import{c as ge,d as w}from"./chunk-JGXDHUYS.mjs";import{o as W}from"./chunk-QADHU5CF.mjs";import"./chunk-ZZ52EIBP.mjs";import{P as se,T as le,U as oe,V as ne,W as ie,X as ce,Y as pe,Z as me,h as ae,j as re,u as L}from"./chunk-FE53TMRB.mjs";import{b as k,h as E,j as P,k as de,l as fe,m as I}from"./chunk-L2B47AAZ.mjs";import{a as p}from"./chunk-QVIEFLGF.mjs";var F=class{constructor(){this.nodes=[];this.levels=new Map;this.outerNodes=[];this.classes=new Map;this.setAccTitle=oe;this.getAccTitle=ne;this.setDiagramTitle=pe;this.getDiagramTitle=me;this.getAccDescription=ce;this.setAccDescription=ie}static{p(this,"TreeMapDB")}getNodes(){return this.nodes}getConfig(){let r=re,i=L();return W({...r.treemap,...i.treemap??{}})}addNode(r,i){this.nodes.push(r),this.levels.set(r,i),i===0&&(this.outerNodes.push(r),this.root??=r)}getRoot(){return{name:"",children:this.outerNodes}}addClass(r,i){let l=this.classes.get(r)??{id:r,styles:[],textStyles:[]},o=i.replace(/\\,/g,"\xA7\xA7\xA7").replace(/,/g,";").replace(/§§§/g,",").split(";");o&&o.forEach(s=>{ge(s)&&(l?.textStyles?l.textStyles.push(s):l.textStyles=[s]),l?.styles?l.styles.push(s):l.styles=[s]}),this.classes.set(r,l)}getClasses(){return this.classes}getStylesForClass(r){return this.classes.get(r)?.styles??[]}clear(){le(),this.nodes=[],this.levels=new Map,this.outerNodes=[],this.classes=new Map,this.root=void 0}};function be(m){if(!m.length)return[];let r=[],i=[];return m.forEach(l=>{let o={name:l.name,children:l.type==="Leaf"?void 0:[]};for(o.classSelector=l?.classSelector,l?.cssCompiledStyles&&(o.cssCompiledStyles=l.cssCompiledStyles),l.type==="Leaf"&&l.value!==void 0&&(o.value=l.value);i.length>0&&i[i.length-1].level>=l.level;)i.pop();if(i.length===0)r.push(o);else{let s=i[i.length-1].node;s.children?s.children.push(o):s.children=[o]}l.type!=="Leaf"&&i.push({node:o,level:l.level})}),r}p(be,"buildHierarchy");var Pe=p((m,r)=>{ye(m,r);let i=[];for(let s of m.TreemapRows??[])s.$type==="ClassDefStatement"&&r.addClass(s.className??"",s.styleText??"");for(let s of m.TreemapRows??[]){let d=s.item;if(!d)continue;let f=s.indent?parseInt(s.indent):0,R=Fe(d),a=d.classSelector?r.getStylesForClass(d.classSelector):[],z=a.length>0?a:void 0,x={level:f,name:R,type:d.$type,value:d.value,classSelector:d.classSelector,cssCompiledStyles:z};i.push(x)}let l=be(i),o=p((s,d)=>{for(let f of s)r.addNode(f,d),f.children&&f.children.length>0&&o(f.children,d+1)},"addNodesRecursively");o(l,0)},"populate"),Fe=p(m=>m.name?String(m.name):"","getItemName"),Y={parser:{yy:void 0},parse:p(async m=>{try{let i=await ue("treemap",m);k.debug("Treemap AST:",i);let l=Y.parser?.yy;if(!(l instanceof F))throw new Error("parser.parser?.yy was not a TreemapDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.");Pe(i,l)}catch(r){throw k.error("Error parsing treemap:",r),r}},"parse")};var Ae=10,A=10,B=25,ze=p((m,r,i,l)=>{let o=l.db,s=o.getConfig(),d=s.padding??Ae,f=o.getDiagramTitle(),R=o.getRoot(),{themeVariables:a}=L();if(!R)return;let z=f?30:0,x=Se(r),q=s.nodeWidth?s.nodeWidth*A:960,U=s.nodeHeight?s.nodeHeight*A:500,G=q,J=U+z;x.attr("viewBox",`0 0 ${G} ${J}`),se(x,J,G,s.useMaxWidth);let T;try{let e=s.valueFormat||",";if(e==="$0,0")T=p(t=>"$"+P(",")(t),"valueFormat");else if(e.startsWith("$")&&e.includes(",")){let t=/\.\d+/.exec(e),n=t?t[0]:"";T=p(g=>"$"+P(","+n)(g),"valueFormat")}else if(e.startsWith("$")){let t=e.substring(1);T=p(n=>"$"+P(t||"")(n),"valueFormat")}else T=P(e)}catch(e){k.error("Error creating format function:",e),T=P(",")}let M=I().range(["transparent",a.cScale0,a.cScale1,a.cScale2,a.cScale3,a.cScale4,a.cScale5,a.cScale6,a.cScale7,a.cScale8,a.cScale9,a.cScale10,a.cScale11]),Ce=I().range(["transparent",a.cScalePeer0,a.cScalePeer1,a.cScalePeer2,a.cScalePeer3,a.cScalePeer4,a.cScalePeer5,a.cScalePeer6,a.cScalePeer7,a.cScalePeer8,a.cScalePeer9,a.cScalePeer10,a.cScalePeer11]),H=I().range([a.cScaleLabel0,a.cScaleLabel1,a.cScaleLabel2,a.cScaleLabel3,a.cScaleLabel4,a.cScaleLabel5,a.cScaleLabel6,a.cScaleLabel7,a.cScaleLabel8,a.cScaleLabel9,a.cScaleLabel10,a.cScaleLabel11]);f&&x.append("text").attr("x",G/2).attr("y",z/2).attr("class","treemapTitle").attr("text-anchor","middle").attr("dominant-baseline","middle").text(f);let K=x.append("g").attr("transform",`translate(0, ${z})`).attr("class","treemapContainer"),De=de(R).sum(e=>e.value??0).sort((e,t)=>(t.value??0)-(e.value??0)),Q=fe().size([q,U]).paddingTop(e=>e.children&&e.children.length>0?B+A:0).paddingInner(d).paddingLeft(e=>e.children&&e.children.length>0?A:0).paddingRight(e=>e.children&&e.children.length>0?A:0).paddingBottom(e=>e.children&&e.children.length>0?A:0).round(!0)(De),ve=Q.descendants().filter(e=>e.children&&e.children.length>0),V=K.selectAll(".treemapSection").data(ve).enter().append("g").attr("class","treemapSection").attr("transform",e=>`translate(${e.x0},${e.y0})`);V.append("rect").attr("width",e=>e.x1-e.x0).attr("height",B).attr("class","treemapSectionHeader").attr("fill","none").attr("fill-opacity",.6).attr("stroke-width",.6).attr("style",e=>e.depth===0?"display: none;":""),V.append("clipPath").attr("id",(e,t)=>`clip-section-${r}-${t}`).append("rect").attr("width",e=>Math.max(0,e.x1-e.x0-12)).attr("height",B),V.append("rect").attr("width",e=>e.x1-e.x0).attr("height",e=>e.y1-e.y0).attr("class",(e,t)=>`treemapSection section${t}`).attr("fill",e=>M(e.data.name)).attr("fill-opacity",.6).attr("stroke",e=>Ce(e.data.name)).attr("stroke-width",2).attr("stroke-opacity",.4).attr("style",e=>{if(e.depth===0)return"display: none;";let t=w({cssCompiledStyles:e.data.cssCompiledStyles});return t.nodeStyles+";"+t.borderStyles.join(";")}),V.append("text").attr("class","treemapSectionLabel").attr("x",6).attr("y",B/2).attr("dominant-baseline","middle").text(e=>e.depth===0?"":e.data.name).attr("font-weight","bold").attr("clip-path",(e,t)=>`url(#clip-section-${r}-${t})`).attr("style",e=>{if(e.depth===0)return"display: none;";let t="dominant-baseline: middle; font-size: 12px; fill:"+H(e.data.name)+"; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;",n=w({cssCompiledStyles:e.data.cssCompiledStyles});return t+n.labelStyles.replace("color:","fill:")}).each(function(e){if(e.depth===0)return;let t=E(this),n=e.data.name;t.text(n);let g=e.x1-e.x0,u=6,h;s.showValues!==!1&&e.value?h=g-10-30-10-u:h=g-u-6;let c=Math.max(15,h),D=t.node();if(D.getComputedTextLength()>c){let v=n;for(;v.length>0;){if(v=n.substring(0,v.length-1),v.length===0){t.text("..."),D.getComputedTextLength()>c&&t.text("");break}if(t.text(v+"..."),D.getComputedTextLength()<=c)break}}}),s.showValues!==!1&&V.append("text").attr("class","treemapSectionValue").attr("x",e=>e.x1-e.x0-10).attr("y",B/2).attr("text-anchor","end").attr("dominant-baseline","middle").text(e=>e.value?T(e.value):"").attr("font-style","italic").attr("style",e=>{if(e.depth===0)return"display: none;";let t="text-anchor: end; dominant-baseline: middle; font-size: 10px; fill:"+H(e.data.name)+"; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;",n=w({cssCompiledStyles:e.data.cssCompiledStyles});return t+n.labelStyles.replace("color:","fill:")});let Z=Q.leaves(),S=Z.length>20,we=S?16:38,_=S?14:28,N=S?4:8,$=S?4:6,O=S?2:4,ee=S?8:10,X=S?1:2,j=K.selectAll(".treemapLeafGroup").data(Z).enter().append("g").attr("class",(e,t)=>`treemapNode treemapLeafGroup leaf${t}${e.data.classSelector?` ${e.data.classSelector}`:""}x`).attr("transform",e=>`translate(${e.x0},${e.y0})`);j.append("rect").attr("width",e=>e.x1-e.x0).attr("height",e=>e.y1-e.y0).attr("class","treemapLeaf").attr("fill",e=>e.parent?M(e.parent.data.name):M(e.data.name)).attr("style",e=>w({cssCompiledStyles:e.data.cssCompiledStyles}).nodeStyles).attr("fill-opacity",.3).attr("stroke",e=>e.parent?M(e.parent.data.name):M(e.data.name)).attr("stroke-width",3),j.append("clipPath").attr("id",(e,t)=>`clip-${r}-${t}`).append("rect").attr("width",e=>Math.max(0,e.x1-e.x0-4)).attr("height",e=>Math.max(0,e.y1-e.y0-4)),j.append("text").attr("class","treemapLabel").attr("x",e=>(e.x1-e.x0)/2).attr("y",e=>(e.y1-e.y0)/2).attr("style",e=>{let t=`text-anchor: middle; dominant-baseline: middle; font-size: ${we}px;fill:`+H(e.data.name)+";",n=w({cssCompiledStyles:e.data.cssCompiledStyles});return t+n.labelStyles.replace("color:","fill:")}).attr("clip-path",(e,t)=>`url(#clip-${r}-${t})`).text(e=>e.data.name).each(function(e){let t=E(this),n=e.x1-e.x0,g=e.y1-e.y0,u=t.node(),h=n-2*O,C=g-2*O;if(h<ee||C<ee){t.style("display","none");return}let c=parseInt(t.style("font-size"),10),D=.6;for(;u.getComputedTextLength()>h&&c>N;)c--,t.style("font-size",`${c}px`);let y=Math.max($,Math.min(_,Math.round(c*D))),b=c+X+y;for(;b>C&&c>N&&(c--,y=Math.max($,Math.min(_,Math.round(c*D))),!(y<$&&c===N));)t.style("font-size",`${c}px`),b=c+X+y,y<=$&&b>C;t.style("font-size",`${c}px`),S?(c<N||C<N)&&t.style("display","none"):(u.getComputedTextLength()>h||c<N||C<c)&&t.style("display","none")}),s.showValues!==!1&&j.append("text").attr("class","treemapValue").attr("x",t=>(t.x1-t.x0)/2).attr("y",function(t){return(t.y1-t.y0)/2}).attr("style",t=>{let n=`text-anchor: middle; dominant-baseline: hanging; font-size: ${_}px;fill:`+H(t.data.name)+";",g=w({cssCompiledStyles:t.data.cssCompiledStyles});return n+g.labelStyles.replace("color:","fill:")}).attr("clip-path",(t,n)=>`url(#clip-${r}-${n})`).text(t=>t.value?T(t.value):"").each(function(t){let n=E(this),g=this.parentNode;if(!g){n.style("display","none");return}let u=E(g).select(".treemapLabel");if(u.empty()||u.style("display")==="none"){n.style("display","none");return}let h=parseFloat(u.style("font-size")),c=Math.max($,Math.min(_,Math.round(h*.6)));n.style("font-size",`${c}px`);let y=(t.y1-t.y0)/2+h/2+X;n.attr("y",y);let b=t.x1-t.x0,te=t.y1-t.y0-4,Le=b-2*O;n.node().getComputedTextLength()>Le||y+c>te||c<$?n.style("display","none"):n.style("display",null)});let Ne=s.diagramPadding??8;he(x,Ne,"flowchart",s?.useMaxWidth||!1)},"draw"),Me=p(function(m,r){return r.db.getClasses()},"getClasses"),xe={draw:ze,getClasses:Me};var Ve={sectionStrokeColor:"black",sectionStrokeWidth:"1",sectionFillColor:"#efefef",leafStrokeColor:"black",leafStrokeWidth:"1",leafFillColor:"#efefef",labelFontSize:"12px",valueFontSize:"10px",titleFontSize:"14px"},ke=p(({treemap:m}={})=>{let r=ae(),i=L(),l=W(r,i.themeVariables),o=W(Ve,m),s=o.titleColor??l.titleColor,d=o.labelColor??l.textColor,f=o.valueColor??l.textColor;return`
.treemapNode.section {
stroke: ${o.sectionStrokeColor};
stroke-width: ${o.sectionStrokeWidth};
fill: ${o.sectionFillColor};
}
.treemapNode.leaf {
stroke: ${o.leafStrokeColor};
stroke-width: ${o.leafStrokeWidth};
fill: ${o.leafFillColor};
}
.treemapLabel {
fill: ${d};
font-size: ${o.labelFontSize};
}
.treemapValue {
fill: ${f};
font-size: ${o.valueFontSize};
}
.treemapTitle {
fill: ${s};
font-size: ${o.titleFontSize};
}
`},"getStyles"),Te=ke;var St={parser:Y,get db(){return new F},renderer:xe,styles:Te};export{St as diagram};