livebook/static/assets/chunk-YUYS2C7W.js
2024-02-01 06:36:01 +00:00

2 lines
11 KiB
JavaScript

import{a as _,b as O,d as k,e as y,f as F,g as G,h as U,i as T,l as A,m as $,n as H,o as M}from"./chunk-H7BULRRH.js";import{b as R}from"./chunk-K2SHFXEF.js";import{a as L,d as D,f as x,j as J,k as P}from"./chunk-3RMNQ3JB.js";import{Ga as n,Ja as E,h as B,kb as N}from"./chunk-PXCFCI5A.js";function m(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Y(e),edges:Z(e)};return x(e.graph())||(t.value=L(e.graph())),t}function Y(e){return D(e.nodes(),function(t){var i=e.node(t),r=e.parent(t),s={v:t};return x(i)||(s.value=i),x(r)||(s.parent=r),s})}function Z(e){return D(e.edges(),function(t){var i=e.edge(t),r={v:t.v,w:t.w};return x(t.name)||(r.name=t.name),x(i)||(r.value=i),r})}var f={},g={},V={},tt=()=>{g={},V={},f={}},S=(e,t)=>(n.trace("In isDecendant",t," ",e," = ",g[t].includes(e)),!!g[t].includes(e)),et=(e,t)=>(n.info("Decendants of ",t," is ",g[t]),n.info("Edge is ",e),e.v===t||e.w===t?!1:g[t]?g[t].includes(e.v)||S(e.v,t)||S(e.w,t)||g[t].includes(e.w):(n.debug("Tilt, ",t,",not in decendants"),!1)),j=(e,t,i,r)=>{n.warn("Copying children of ",e,"root",r,"data",t.node(e),r);let s=t.children(e)||[];e!==r&&s.push(e),n.warn("Copying (nodes) clusterId",e,"nodes",s),s.forEach(c=>{if(t.children(c).length>0)j(c,t,i,r);else{let d=t.node(c);n.info("cp ",c," to ",r," with parent ",e),i.setNode(c,d),r!==t.parent(c)&&(n.warn("Setting parent",c,t.parent(c)),i.setParent(c,t.parent(c))),e!==r&&c!==e?(n.debug("Setting parent",c,e),i.setParent(c,e)):(n.info("In copy ",e,"root",r,"data",t.node(e),r),n.debug("Not Setting parent for node=",c,"cluster!==rootId",e!==r,"node!==clusterId",c!==e));let l=t.edges(c);n.debug("Copying Edges",l),l.forEach(h=>{n.info("Edge",h);let u=t.edge(h.v,h.w,h.name);n.info("Edge data",u,r);try{et(h,r)?(n.info("Copying as ",h.v,h.w,u,h.name),i.setEdge(h.v,h.w,u,h.name),n.info("newGraph edges ",i.edges(),i.edge(i.edges()[0]))):n.info("Skipping copy of edge ",h.v,"-->",h.w," rootId: ",r," clusterId:",e)}catch(w){n.error(w)}})}n.debug("Removing node",c),t.removeNode(c)})},W=(e,t)=>{let i=t.children(e),r=[...i];for(let s of i)V[s]=e,r=[...r,...W(s,t)];return r},p=(e,t)=>{n.trace("Searching",e);let i=t.children(e);if(n.trace("Searching children of id ",e,i),i.length<1)return n.trace("This is a valid node",e),e;for(let r of i){let s=p(r,t);if(s)return n.trace("Found replacement for",e," => ",s),s}},X=e=>!f[e]||!f[e].externalConnections?e:f[e]?f[e].id:e,it=(e,t)=>{if(!e||t>10){n.debug("Opting out, no graph ");return}else n.debug("Opting in, graph ");e.nodes().forEach(function(i){e.children(i).length>0&&(n.warn("Cluster identified",i," Replacement id in edges: ",p(i,e)),g[i]=W(i,e),f[i]={id:p(i,e),clusterData:e.node(i)})}),e.nodes().forEach(function(i){let r=e.children(i),s=e.edges();r.length>0?(n.debug("Cluster identified",i,g),s.forEach(c=>{if(c.v!==i&&c.w!==i){let d=S(c.v,i),l=S(c.w,i);d^l&&(n.warn("Edge: ",c," leaves cluster ",i),n.warn("Decendants of XXX ",i,": ",g[i]),f[i].externalConnections=!0)}})):n.debug("Not a cluster ",i,g)}),e.edges().forEach(function(i){let r=e.edge(i);n.warn("Edge "+i.v+" -> "+i.w+": "+JSON.stringify(i)),n.warn("Edge "+i.v+" -> "+i.w+": "+JSON.stringify(e.edge(i)));let s=i.v,c=i.w;if(n.warn("Fix XXX",f,"ids:",i.v,i.w,"Translating: ",f[i.v]," --- ",f[i.w]),f[i.v]&&f[i.w]&&f[i.v]===f[i.w]){n.warn("Fixing and trixing link to self - removing XXX",i.v,i.w,i.name),n.warn("Fixing and trixing - removing XXX",i.v,i.w,i.name),s=X(i.v),c=X(i.w),e.removeEdge(i.v,i.w,i.name);let d=i.w+"---"+i.v;e.setNode(d,{domId:d,id:d,labelStyle:"",labelText:r.label,padding:0,shape:"labelRect",style:""});let l=structuredClone(r),h=structuredClone(r);l.label="",l.arrowTypeEnd="none",h.label="",l.fromCluster=i.v,h.toCluster=i.v,e.setEdge(s,d,l,i.name+"-cyclic-special"),e.setEdge(d,c,h,i.name+"-cyclic-special")}else(f[i.v]||f[i.w])&&(n.warn("Fixing and trixing - removing XXX",i.v,i.w,i.name),s=X(i.v),c=X(i.w),e.removeEdge(i.v,i.w,i.name),s!==i.v&&(r.fromCluster=i.v),c!==i.w&&(r.toCluster=i.w),n.warn("Fix Replacing with XXX",s,c,i.name),e.setEdge(s,c,r,i.name))}),n.warn("Adjusted Graph",m(e)),q(e,0),n.trace(f)},q=(e,t)=>{if(n.warn("extractor - ",t,m(e),e.children("D")),t>10){n.error("Bailing out");return}let i=e.nodes(),r=!1;for(let s of i){let c=e.children(s);r=r||c.length>0}if(!r){n.debug("Done, no node has children",e.nodes());return}n.debug("Nodes = ",i,t);for(let s of i)if(n.debug("Extracting node",s,f,f[s]&&!f[s].externalConnections,!e.parent(s),e.node(s),e.children("D")," Depth ",t),!f[s])n.debug("Not a cluster",s,t);else if(!f[s].externalConnections&&e.children(s)&&e.children(s).length>0){n.warn("Cluster without external connections, without a parent and with children",s,t);let d=e.graph().rankdir==="TB"?"LR":"TB";f[s]&&f[s].clusterData&&f[s].clusterData.dir&&(d=f[s].clusterData.dir,n.warn("Fixing dir",f[s].clusterData.dir,d));let l=new J({multigraph:!0,compound:!0}).setGraph({rankdir:d,nodesep:50,ranksep:50,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});n.warn("Old graph before copy",m(e)),j(s,e,l,s),e.setNode(s,{clusterNode:!0,id:s,clusterData:f[s].clusterData,labelText:f[s].labelText,graph:l}),n.warn("New graph after copy node: (",s,")",m(l)),n.debug("Old graph after copy",m(e))}else n.warn("Cluster ** ",s," **not meeting the criteria !externalConnections:",!f[s].externalConnections," no parent: ",!e.parent(s)," children ",e.children(s)&&e.children(s).length>0,e.children("D"),t),n.debug(f);i=e.nodes(),n.warn("New list of nodes",i);for(let s of i){let c=e.node(s);n.warn(" Now next level",s,c),c.clusterNode&&q(c.graph,t+1)}},z=(e,t)=>{if(t.length===0)return[];let i=Object.assign(t);return t.forEach(r=>{let s=e.children(r),c=z(e,s);i=[...i,...c]}),i},nt=e=>z(e,e.children()),st=(e,t)=>{n.info("Creating subgraph rect for ",t.id,t);let i=e.insert("g").attr("class","cluster"+(t.class?" "+t.class:"")).attr("id",t.id),r=i.insert("rect",":first-child"),s=E(N().flowchart.htmlLabels),c=i.insert("g").attr("class","cluster-label"),d=t.labelType==="markdown"?R(c,t.labelText,{style:t.labelStyle,useHtmlLabels:s}):c.node().appendChild(O(t.labelText,t.labelStyle,void 0,!0)),l=d.getBBox();if(E(N().flowchart.htmlLabels)){let a=d.children[0],o=B(d);l=a.getBoundingClientRect(),o.attr("width",l.width),o.attr("height",l.height)}let h=0*t.padding,u=h/2,w=t.width<=l.width+h?l.width+h:t.width;t.width<=l.width+h?t.diff=(l.width-t.width)/2-t.padding/2:t.diff=-t.padding/2,n.trace("Data ",t,JSON.stringify(t)),r.attr("style",t.style).attr("rx",t.rx).attr("ry",t.ry).attr("x",t.x-w/2).attr("y",t.y-t.height/2-u).attr("width",w).attr("height",t.height+h),s?c.attr("transform","translate("+(t.x-l.width/2)+", "+(t.y-t.height/2)+")"):c.attr("transform","translate("+t.x+", "+(t.y-t.height/2)+")");let v=r.node().getBBox();return t.width=v.width,t.height=v.height,t.intersect=function(a){return y(t,a)},i},rt=(e,t)=>{let i=e.insert("g").attr("class","note-cluster").attr("id",t.id),r=i.insert("rect",":first-child"),s=0*t.padding,c=s/2;r.attr("rx",t.rx).attr("ry",t.ry).attr("x",t.x-t.width/2-c).attr("y",t.y-t.height/2-c).attr("width",t.width+s).attr("height",t.height+s).attr("fill","none");let d=r.node().getBBox();return t.width=d.width,t.height=d.height,t.intersect=function(l){return y(t,l)},i},at=(e,t)=>{let i=e.insert("g").attr("class",t.classes).attr("id",t.id),r=i.insert("rect",":first-child"),s=i.insert("g").attr("class","cluster-label"),c=i.append("rect"),d=s.node().appendChild(O(t.labelText,t.labelStyle,void 0,!0)),l=d.getBBox();if(E(N().flowchart.htmlLabels)){let a=d.children[0],o=B(d);l=a.getBoundingClientRect(),o.attr("width",l.width),o.attr("height",l.height)}l=d.getBBox();let h=0*t.padding,u=h/2,w=t.width<=l.width+t.padding?l.width+t.padding:t.width;t.width<=l.width+t.padding?t.diff=(l.width+t.padding*0-t.width)/2:t.diff=-t.padding/2,r.attr("class","outer").attr("x",t.x-w/2-u).attr("y",t.y-t.height/2-u).attr("width",w+h).attr("height",t.height+h),c.attr("class","inner").attr("x",t.x-w/2-u).attr("y",t.y-t.height/2-u+l.height-1).attr("width",w+h).attr("height",t.height+h-l.height-3),s.attr("transform","translate("+(t.x-l.width/2)+", "+(t.y-t.height/2-t.padding/3+(E(N().flowchart.htmlLabels)?5:3))+")");let v=r.node().getBBox();return t.height=v.height,t.intersect=function(a){return y(t,a)},i},ct=(e,t)=>{let i=e.insert("g").attr("class",t.classes).attr("id",t.id),r=i.insert("rect",":first-child"),s=0*t.padding,c=s/2;r.attr("class","divider").attr("x",t.x-t.width/2-c).attr("y",t.y-t.height/2).attr("width",t.width+s).attr("height",t.height+s);let d=r.node().getBBox();return t.width=d.width,t.height=d.height,t.diff=-t.padding/2,t.intersect=function(l){return y(t,l)},i},ot={rect:st,roundedWithTitle:at,noteGroup:rt,divider:ct},K={},lt=(e,t)=>{n.trace("Inserting cluster");let i=t.shape||"rect";K[t.id]=ot[i](e,t)},ft=()=>{K={}},Q=async(e,t,i,r,s)=>{n.info("Graph in recursive render: XXX",m(t),s);let c=t.graph().rankdir;n.trace("Dir in recursive render - dir:",c);let d=e.insert("g").attr("class","root");t.nodes()?n.info("Recursive render XXX",t.nodes()):n.info("No nodes found for",t),t.edges().length>0&&n.trace("Recursive edges",t.edge(t.edges()[0]));let l=d.insert("g").attr("class","clusters"),h=d.insert("g").attr("class","edgePaths"),u=d.insert("g").attr("class","edgeLabels"),w=d.insert("g").attr("class","nodes");await Promise.all(t.nodes().map(async function(a){let o=t.node(a);if(s!==void 0){let b=JSON.parse(JSON.stringify(s.clusterData));n.info("Setting data for cluster XXX (",a,") ",b,s),t.setNode(s.id,b),t.parent(a)||(n.trace("Setting parent",a,s.id),t.setParent(a,s.id,b))}if(n.info("(Insert) Node XXX"+a+": "+JSON.stringify(t.node(a))),o&&o.clusterNode){n.info("Cluster identified",a,o.width,t.node(a));let b=await Q(w,o.graph,i,r,t.node(a)),C=b.elem;k(o,C),o.diff=b.diff||0,n.info("Node bounds (abc123)",a,o,o.width,o.x,o.y),G(C,o),n.warn("Recursive render complete ",C,o)}else t.children(a).length>0?(n.info("Cluster - the non recursive path XXX",a,o.id,o,t),n.info(p(o.id,t)),f[o.id]={id:p(o.id,t),node:o}):(n.info("Node - the non recursive path",a,o.id,o),await F(w,t.node(a),c))})),t.edges().forEach(function(a){let o=t.edge(a.v,a.w,a.name);n.info("Edge "+a.v+" -> "+a.w+": "+JSON.stringify(a)),n.info("Edge "+a.v+" -> "+a.w+": ",a," ",JSON.stringify(t.edge(a))),n.info("Fix",f,"ids:",a.v,a.w,"Translateing: ",f[a.v],f[a.w]),$(u,o)}),t.edges().forEach(function(a){n.info("Edge "+a.v+" -> "+a.w+": "+JSON.stringify(a))}),n.info("#############################################"),n.info("### Layout ###"),n.info("#############################################"),n.info(t),P(t),n.info("Graph after layout:",m(t));let v=0;return nt(t).forEach(function(a){let o=t.node(a);n.info("Position "+a+": "+JSON.stringify(t.node(a))),n.info("Position "+a+": ("+o.x,","+o.y,") width: ",o.width," height: ",o.height),o&&o.clusterNode?T(o):t.children(a).length>0?(lt(l,o),f[o.id].node=o):T(o)}),t.edges().forEach(function(a){let o=t.edge(a);n.info("Edge "+a.v+" -> "+a.w+": "+JSON.stringify(o),o);let b=M(h,a,o,f,i,t,r);H(o,b)}),t.nodes().forEach(function(a){let o=t.node(a);n.info(a,o.type,o.diff),o.type==="group"&&(v=o.diff)}),{elem:d,diff:v}},yt=async(e,t,i,r,s)=>{_(e,i,r,s),U(),A(),ft(),tt(),n.warn("Graph at first:",JSON.stringify(m(t))),it(t),n.warn("Graph after:",JSON.stringify(m(t))),await Q(e,t,r,s)};export{yt as a};