md/assets/dagre-CQ6OS2HX-ymO5N3uj.js

5 lines
10 KiB
JavaScript
Raw Normal View History

import{_ as w,an as T,ao as F,ap as M,aq as Y,l as i,d as _,ar as j,as as H,at as q,S as z,au as O,av as K,aw as Q,ax as U,ay as V}from"./index-BDe2Eio8.js";import{G as k}from"./graph-C-GYha3a.js";import{l as W}from"./layout-ChNM8Phz.js";import{w as y}from"./json-u1FNPJnY.js";import"./reduce-BVk9EWQY.js";import"./min-neI8SDd-.js";var d=new Map,N=new Map,P=new Map,Z=w(()=>{N.clear(),P.clear(),d.clear()},"clear"),D=w((n,t)=>{const e=N.get(t)||[];return i.trace("In isDescendant",t," ",n," = ",e.includes(n)),e.includes(n)},"isDescendant"),$=w((n,t)=>{const e=N.get(t)||[];return i.info("Descendants of ",t," is ",e),i.info("Edge is ",n),n.v===t||n.w===t?!1:e?e.includes(n.v)||D(n.v,t)||D(n.w,t)||e.includes(n.w):(i.debug("Tilt, ",t,",not in descendants"),!1)},"edgeInCluster"),B=w((n,t,e,o)=>{i.warn("Copying children of ",n,"root",o,"data",t.node(n),o);const l=t.children(n)||[];n!==o&&l.push(n),i.warn("Copying (nodes) clusterId",n,"nodes",l),l.forEach(c=>{if(t.children(c).length>0)B(c,t,e,o);else{const r=t.node(c);i.info("cp ",c," to ",o," with parent ",n),e.setNode(c,r),o!==t.parent(c)&&(i.warn("Setting parent",c,t.parent(c)),e.setParent(c,t.parent(c))),n!==o&&c!==n?(i.debug("Setting parent",c,n),e.setParent(c,n)):(i.info("In copy ",n,"root",o,"data",t.node(n),o),i.debug("Not Setting parent for node=",c,"cluster!==rootId",n!==o,"node!==clusterId",c!==n));const g=t.edges(c);i.debug("Copying Edges",g),g.forEach(a=>{i.info("Edge",a);const u=t.edge(a.v,a.w,a.name);i.info("Edge data",u,o);try{$(a,o)?(i.info("Copying as ",a.v,a.w,u,a.name),e.setEdge(a.v,a.w,u,a.name),i.info("newGraph edges ",e.edges(),e.edge(e.edges()[0]))):i.info("Skipping copy of edge ",a.v,"-->",a.w," rootId: ",o," clusterId:",n)}catch(X){i.error(X)}})}i.debug("Removing node",c),t.removeNode(c)})},"copy"),J=w((n,t)=>{const e=t.children(n);let o=[...e];for(const l of e)P.set(l,n),o=[...o,...J(l,t)];return o},"extractDescendants"),L=w((n,t,e)=>{const o=n.edges().filter(a=>a.v===t||a.w===t),l=n.edges().filter(a=>a.v===e||a.w===e),c=o.map(a=>({v:a.v===t?e:a.v,w:a.w===t?t:a.w})),r=l.map(a=>({v:a.v,w:a.w}));return c.filter(a=>r.some(u=>a.v===u.v&&a.w===u.w))},"findCommonEdges"),C=w((n,t,e)=>{const o=t.children(n);if(i.trace("Searching children of id ",n,o),o.length<1)return n;let l;for(const c of o){const r=C(c,t,e),g=L(t,e,r);if(r)if(g.length>0)l=r;else return r}return l},"findNonClusterChild"),S=w(n=>!d.has(n)||!d.get(n).externalConnections?n:d.has(n)?d.get(n).id:n,"getAnchorId"),I=w((n,t)=>{if(!n||t>10){i.debug("Opting out, no graph ");return}else i.debug("Opting in, graph ");n.nodes().forEach(function(e){n.children(e).length>0&&(i.warn("Cluster identified",e," Replacement id in edges: ",C(e,n,e)),N.set(e,J(e,n)),d.set(e,{id:C(e,n,e),clusterData:n.node(e)}))}),n.nodes().forEach(function(e){const o=n.children(e),l=n.edges();o.length>0?(i.debug("Cluster identified",e,N),l.forEach(c=>{const r=D(c.v,e),g=D(c.w,e);r^g&&(i.warn("Edge: ",c," leaves cluster ",e),i.warn("Descendants of XXX ",e,": ",N.get(e)),d.get(e).externalConnections=!0)})):i.debug("Not a cluster ",e,N)});for(let e of d.keys()){const o=d.get(e).id,l=n.parent(o);l!==e&&d.has(l)&&!d.get(l).externalConnections&&(d.get(e).id=l)}n.edges().forEach(function(e){const o=n.edge(e);i.warn("Edge "+e.v+" -> "+e.w+": "+JSON.stringify(e)),i.warn("Edge "+e.v+" -> "+e.w+": "+JSON.stringify(n.edge(e)));let l=e.v,c=e.w;if(i.warn("Fix XXX",d,"ids:",e.v,e.w,"Translating: ",d.get(e.v)," --- ",d.get(e.w)),d.get(e.v)&&d.get(e.w)&&d.get(e.v)===d.get(e.w)){i.warn("Fixing and trying link to self - removing XXX",e.v,e.w,e.name),i.warn("Fixing and trying - removing XXX",e.v,e.w,e.name),l=S(e.v),c=S(e.w),n.removeEdge(e.v,e.w,e.name);const r=e.w+"---"+e.v+"---1",g=e.w+"---"+e.v+"---2";n.setNode(r,{domId:r,id:r,labelStyle:"",label:"",padding:0,shape:"labelRect",style:"",width:10,height:10}),n.setNode(g,{domId:g,id:g,labelStyle:"",padding:0,shape:"labelRect",style:"",width:10,height:10});const a=structuredClone(o),u=structuredClone(o),X=structuredClone(o);a.label="",a.arrowTypeEnd="none",a.id=e.name+"-cyclic-special-1",u.arrowTypeEnd="non
Node.id = `,f,`
data=`,v.height,`
Parent cluster`,l.height),t.setNode(l.id,v),t.parent(f)||(i.trace("Setting parent",f,l.id),t.setParent(f,l.id,v))}if(i.info("(Insert) Node XXX"+f+": "+JSON.stringify(t.node(f))),s!=null&&s.clusterNode){i.info("Cluster identified XBX",f,s.width,t.node(f));const{ranksep:v,nodesep:h}=t.graph();s.graph.setGraph({...s.graph.graph(),ranksep:v+25,nodesep:h});const E=await G(m,s.graph,e,o,t.node(f),c),b=E.elem;j(s,b),s.diff=E.diff||0,i.info("New compound node after recursive render XAX",f,"width",s.width,"height",s.height),H(b,s)}else t.children(f).length>0?(i.info("Cluster - the non recursive path XBX",f,s.id,s,s.width,"Graph:",t),i.info(C(s.id,t)),d.set(s.id,{id:C(s.id,t),node:s})):(i.trace("Node - the non recursive path XAX",f,s.id,s),await q(m,t.node(f),r))})),await w(async()=>{const f=t.edges().map(async function(s){const v=t.edge(s.v,s.w,s.name);i.info("Edge "+s.v+" -> "+s.w+": "+JSON.stringify(s)),i.info("Edge "+s.v+" -> "+s.w+": ",s," ",JSON.stringify(t.edge(s))),i.info("Fix",d,"ids:",s.v,s.w,"Translating: ",d.get(s.v),d.get(s.w)),await V(X,v)});await Promise.all(f)},"processEdges")(),i.info("Graph before layout:",JSON.stringify(y(t))),i.info("############################################# XXX"),i.info("### Layout ### XXX"),i.info("############################################# XXX"),W(t),i.info("Graph after layout:",JSON.stringify(y(t)));let p=0,{subGraphTitleTotalMargin:x}=z(c);return await Promise.all(ee(t).map(async function(f){var v;const s=t.node(f);if(i.info("Position XBX => "+f+": ("+s.x,","+s.y,") width: ",s.width," height: ",s.height),s!=null&&s.clusterNode)s.y+=x,i.info("A tainted cluster node XBX1",f,s.id,s.width,s.height,s.x,s.y,t.parent(f)),d.get(s.id).node=s,O(s);else if(t.children(f).length>0){i.info("A pure cluster node XBX1",f,s.id,s.x,s.y,s.width,s.height,t.parent(f)),s.height+=x,t.node(s.parentId);const h=(s==null?void 0:s.padding)/2||0,E=((v=s==null?void 0:s.labelBBox)==null?void 0:v.height)||0,b=E-h||0;i.debug("OffsetY",b,"labelHeight",E,"halfPadding",h),await K(a,s),d.get(s.id).node=s}else{const h=t.node(s.parentId);s.y+=x/2,i.info("A regular node XBX1 - using the padding",s.id,"parent",s.parentId,s.width,s.height,s.x,s.y,"offsetY",s.offsetY,"parent",h,h==null?void 0:h.offsetY,s),O(s)}})),t.edges().forEach(function(f){const s=t.edge(f);i.info("Edge "+f.v+" -> "+f.w+": "+JSON.stringify(s),s),s.points.forEach(b=>b.y+=x/2);const v=t.node(f.v);var h=t.node(f.w);const E=Q(u,s,d,e,v,h,o);U(s,E)}),t.nodes().forEach(function(f){const s=t.node(f);i.info(f,s.type,s.diff),s.isGroup&&(p=s.diff)}),i.warn("Returning from recursive render XAX",g,p),{elem:g,diff:p}},"recursiveRender"),ae=w(async(n,t)=>{var c,r,g,a,u,X;const e=new k({multigraph:!0,compound:!0}).setGraph({rankdir:n.direction,nodesep:((c=n.config)==null?void 0:c.nodeSpacing)||((g=(r=n.config)==null?void 0:r.flowchart)==null?void 0:g.nodeSpacing)||n.nodeSpacing,ranksep:((a=n.config)==null?void 0:a.rankSpacing)||((X=(u=n.config)==null?void 0:u.flowchart)==null?void 0:X.rankSpacing)||n.rankSpacing,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}}),o=t.select("g");T(o,n.markers,n.type,n.diagramId),F(),M(),Y(),Z(),n.nodes.forEach(m=>{e.setNode(m.id,{...m}),m.parentId&&e.setParent(m.id,m.parentId)}),i.debug("Edges:",n.edges),n.edges.forEach(m=>{e.setEdge(m.start,m.end,{...m},m.id)}),i.warn("Graph at first:",JSON.stringify(y(e))),I(e),i.warn("Graph after:",JSON.stringify(y(e)));const l=_();await G(o,e,n.type,n.diagramId,void 0,l)},"render");export{ae as render};