vargrapher=grapher||{};vardagre=window.dagre;grapher.Graph=class{constructor(compound,layout){this._layout=layout;this._isCompound=compound;this._nodes=newMap;this._edges=newMap;this._children={};this._children["\0"]={};this._parent={}}setNode(node){constkey=node.name;constvalue=this._nodes.get(key);if(value){value.label=node}else{this._nodes.set(key,{v:key,label:node});if(this._isCompound){this._parent[key]="\0";this._children[key]={};this._children["\0"][key]=true}}}setEdge(edge){if(!this._nodes.has(edge.v)){thrownewgrapher.Error("Invalid edge '"+JSON.stringify(edge.v)+"'.")}if(!this._nodes.has(edge.w)){thrownewgrapher.Error("Invalid edge '"+JSON.stringify(edge.w)+"'.")}constkey=edge.v+":"+edge.w;if(!this._edges.has(key)){this._edges.set(key,{v:edge.v,w:edge.w,label:edge})}}setParent(node,parent){if(!this._isCompound){thrownewError("Cannot set parent in a non-compound graph")}parent+="";for(letancestor=parent;ancestor;ancestor=this.parent(ancestor)){if(ancestor===node){thrownewError("Setting "+parent+" as parent of "+node+" would create a cycle")}}deletethis._children[this._parent[node]][node];this._parent[node]=parent;this._children[parent][node]=true;returnthis}getnodes(){returnthis._nodes}hasNode(key){returnthis._nodes.has(key)}node(key){returnthis._nodes.get(key)}getedges(){returnthis._edges}parent(key){if(this._isCompound){constparent=this._parent[key];if(parent!=="\0"){returnparent}}returnnull}children(key){key=key===undefined?"\0":key;if(this._isCompound){constchildren=this._children[key];if(children){returnObject.keys(children)}}elseif(key==="\0"){returnthis.nodes.keys()}elseif(this.hasNode(key)){return[]}returnnull}build(document,origin){constcreateGroup=name=>{constelement=document.createElementNS("http://www.w3.org/2000/svg","g");element.setAttribute("id",name);element.setAttribute("class",name);origin.appendChild(element);returnelement};constclusterGroup=createGroup("clusters");constedgePathGroup=createGroup("edge-paths");constedgeLabelGroup=createGroup("edge-labels");constnodeGroup=createGroup("nodes");constedgePathGroupDefs=document.createElementNS("http://www.w3.org/2000/svg","defs");edgePathGroup.appendChild(edgePathGroupDefs);constmarker=id=>{constelement=document.createElementNS("http://www.w3.org/2000/svg","marker");element.setAttribute("id",id);element.setAttribute("viewBox","0 0 10 10");element.setAttribute("refX",9);element.setAttribute("refY",5);element.setAttribute("markerUnits","strokeWidth");element.setAttribute("markerWidth",8);element.setAttribute("markerHeight",6);element.setAttribute("orient","auto");constmarkerPath=document.createElementNS("http://www.w3.org/2000/svg","path");markerPath.setAttribute("d","M 0 0 L 10 5 L 0 10 L 4 5 z");markerPath.style.setProperty("stroke-width",1);element.appendChild(markerPath);returnelement};edgePathGroupDefs.appendChild(marker("arrowhead"));edgePathGroupDefs.appendChild(marker("arrowhead-select"));edgePathGroupDefs.appendChild(marker("arrowhead-hover"));for(constnodeIdofthis.nodes.keys()){constentry=this.node(nodeId);constnode=entry.label;if(this.children(nodeId).length==0){node.build(document,nodeGroup)}else{node.rectangle=document.createElementNS("http://www.w3.org/2000/svg","rect");if(node.rx){node.rectangle.setAttribute("rx",entry.rx)}if(node.ry){node.rectangle.setAttribute("ry",entry.ry)}node.element=document.createElementNS("http://www.w3.org/2000/svg","g");node.element.setAttribute("class","cluster");node.element.appendChild(node.rectangle);clusterGroup.appendChild(node.element)}}for(constedgeofthis.edges.values()){edge.label.build(document,edgePathGroup,edgeLabelGroup)}}measure(){for(constkeyofthis.nodes.keys()){constentry=this.node(key);if(this.children(key).length==0){constnode=entry.label;node.measure()}}}layout(){dagre.layout(this,this._layout);for(constkeyofthis.nodes.keys()){constentry=this.node(key);if(this.children(key).length==0){constnode=entry.label;node.layout()}}}update(){for(constnodeIdofthis.nodes.keys()){if(this.children(nodeId).length==0){constentry=this.node(no