graflow: better (live) implementation of getLink + warning anti dbl-link
This commit is contained in:
16
bzGraflow.js
16
bzGraflow.js
@@ -402,9 +402,13 @@ class BZgraflow extends Buildoz{
|
||||
return(this.stagedNodes[nid])
|
||||
}
|
||||
|
||||
addWire(link){ console.log('addWire', link)
|
||||
addWire(link){
|
||||
const [idNode1, idPort1] = link.from
|
||||
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 id = `${idNode1}_${idNode2}`
|
||||
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)')
|
||||
this.stagedWires[id].classList.add('bzgf-wire')
|
||||
this.stagedWires[id].dataset.id = id
|
||||
this.stagedWires[id].link = link
|
||||
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)) {
|
||||
this.flow.links.push(link)
|
||||
@@ -1022,12 +1027,9 @@ class BZgraflow extends Buildoz{
|
||||
}
|
||||
|
||||
getLink(nid1, nid2){
|
||||
let lnk = null
|
||||
lnk = this.flow.links.find(item => ((item.from[0]==nid1) && (item.to[0]==nid2)))
|
||||
if(!lnk) {
|
||||
lnk = this._virtualLinks?.get(`${nid1}__${nid2}`)
|
||||
}
|
||||
return(lnk)
|
||||
const wire = this.stagedWires[`${nid1}_${nid2}`]
|
||||
if(wire?.link) return wire.link
|
||||
return this._virtualLinks?.get(`${nid1}__${nid2}`) ?? null
|
||||
}
|
||||
|
||||
buildGraphStructures(nodes, links, includeLinkIndexes = false) {
|
||||
|
||||
Reference in New Issue
Block a user