graflow: better (live) implementation of getLink + warning anti dbl-link

This commit is contained in:
STEINNI
2026-03-11 18:22:17 +00:00
parent 9c032b9b0b
commit 34e3989ef6

View File

@@ -402,9 +402,13 @@ class BZgraflow extends Buildoz{
return(this.stagedNodes[nid]) return(this.stagedNodes[nid])
} }
addWire(link){ console.log('addWire', link) addWire(link){
const [idNode1, idPort1] = link.from const [idNode1, idPort1] = link.from
const [idNode2, idPort2] = link.to const [idNode2, idPort2] = link.to
if(this.getLink(idNode1,idNode2)) {
console.warn('Current version of graflow does not allow multiple wires between same nodes',this.getLink(idNode1,idNode2),idNode1,idNode2)
return
}
const path = this.linkNodes(idNode1, idPort1, idNode2, idPort2) const path = this.linkNodes(idNode1, idPort1, idNode2, idPort2)
const id = `${idNode1}_${idNode2}` const id = `${idNode1}_${idNode2}`
this.stagedWires[id] = document.createElementNS('http://www.w3.org/2000/svg', 'path') this.stagedWires[id] = document.createElementNS('http://www.w3.org/2000/svg', 'path')
@@ -414,6 +418,7 @@ class BZgraflow extends Buildoz{
if(this.arrowDefs && link.startArrow) this.stagedWires[id].setAttribute('marker-start','url(#arrow)') if(this.arrowDefs && link.startArrow) this.stagedWires[id].setAttribute('marker-start','url(#arrow)')
this.stagedWires[id].classList.add('bzgf-wire') this.stagedWires[id].classList.add('bzgf-wire')
this.stagedWires[id].dataset.id = id this.stagedWires[id].dataset.id = id
this.stagedWires[id].link = link
this.wiresContainer.append(this.stagedWires[id]) this.wiresContainer.append(this.stagedWires[id])
if(!this.flow.links.find(l => l.from[0] === idNode1 && l.from[1] === idPort1 && l.to[0] === idNode2 && l.to[1] === idPort2)) { if(!this.flow.links.find(l => l.from[0] === idNode1 && l.from[1] === idPort1 && l.to[0] === idNode2 && l.to[1] === idPort2)) {
this.flow.links.push(link) this.flow.links.push(link)
@@ -1022,12 +1027,9 @@ class BZgraflow extends Buildoz{
} }
getLink(nid1, nid2){ getLink(nid1, nid2){
let lnk = null const wire = this.stagedWires[`${nid1}_${nid2}`]
lnk = this.flow.links.find(item => ((item.from[0]==nid1) && (item.to[0]==nid2))) if(wire?.link) return wire.link
if(!lnk) { return this._virtualLinks?.get(`${nid1}__${nid2}`) ?? null
lnk = this._virtualLinks?.get(`${nid1}__${nid2}`)
}
return(lnk)
} }
buildGraphStructures(nodes, links, includeLinkIndexes = false) { buildGraphStructures(nodes, links, includeLinkIndexes = false) {