Graflow: better refresh & clear, better EIC example, tension field
This commit is contained in:
21
bzGraflow.js
21
bzGraflow.js
@@ -5,6 +5,7 @@ class BZgraflow extends Buildoz{
|
||||
this.defaultAttrs = { tension: 100 }
|
||||
this.stagedNodes = { }
|
||||
this.stagedWires = { }
|
||||
this.arrowDefs = null
|
||||
}
|
||||
static _loadedNodeStyles = new Set() // Allow multi instances or re-loadNodes, but avoid reinjecting same styles !
|
||||
|
||||
@@ -71,8 +72,9 @@ class BZgraflow extends Buildoz{
|
||||
this.nodesRegistry = {}
|
||||
for(const tpl of doc.querySelectorAll('template')){
|
||||
if(tpl.id=='svg-arrows'){
|
||||
this.wiresContainer.appendChild(tpl.querySelector('defs').cloneNode(true))
|
||||
this.arrowDefined = true
|
||||
this.arrowDefs = tpl.querySelector('defs').cloneNode(true)
|
||||
console.log(this.arrowDefs)
|
||||
this.wiresContainer.appendChild(this.arrowDefs)
|
||||
} else {
|
||||
const rootEl = tpl.content.querySelector('.bzgf-node')
|
||||
if(!rootEl) continue
|
||||
@@ -118,15 +120,23 @@ class BZgraflow extends Buildoz{
|
||||
this.stagedWires[id] = document.createElementNS('http://www.w3.org/2000/svg', 'path')
|
||||
this.stagedWires[id].setAttribute('d', path)
|
||||
this.stagedWires[id].setAttribute('fill', 'none')
|
||||
if(this.arrowDefined && link.endArrow) this.stagedWires[id].setAttribute('marker-end','url(#arrow)')
|
||||
if(this.arrowDefined && link.startArrow) this.stagedWires[id].setAttribute('marker-start','url(#arrow)')
|
||||
if(this.arrowDefs && link.endArrow) this.stagedWires[id].setAttribute('marker-end','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].dataset.id = id
|
||||
this.wiresContainer.append(this.stagedWires[id])
|
||||
return(this.stagedWires[id])
|
||||
}
|
||||
|
||||
|
||||
clear(){
|
||||
this.nodesContainer.innerHTML = ''
|
||||
this.wiresContainer.innerHTML = ''
|
||||
if(this.arrowDefs) this.wiresContainer.appendChild(this.arrowDefs)
|
||||
}
|
||||
|
||||
refresh(){
|
||||
this.clear()
|
||||
let forceAutoplace = false
|
||||
for(const node of this.flow.nodes){
|
||||
if((!node.coords) || (!node.coords.x) ||(!node.coords.y)) forceAutoplace=true
|
||||
@@ -145,7 +155,6 @@ class BZgraflow extends Buildoz{
|
||||
}
|
||||
|
||||
bezier(idNode1, idPort1, idNode2, idPort2, tensionMin=60) {
|
||||
|
||||
const svgRect = this.wiresContainer.getBoundingClientRect()
|
||||
const node1 = this.stagedNodes[idNode1]
|
||||
const port1 = node1.ports[idPort1]
|
||||
@@ -175,7 +184,7 @@ class BZgraflow extends Buildoz{
|
||||
let c1y = y1 + (dirVect[port1.direction].y * tension)
|
||||
let c2x = x2 + (dirVect[port2.direction].x * tension)
|
||||
let c2y = y2 + (dirVect[port2.direction].y * tension)
|
||||
if((idNode1==idNode2) && (idPort1==idPort2)){ // Special case of self-loop: correct intermediary points
|
||||
if((idNode1==idNode2) && (idPort1==idPort2)){ // Special case of self-loop: spread a bit intermediary points
|
||||
if(['n', 's'].includes(port1.direction)) {
|
||||
c1x += tension
|
||||
c2x -= tension
|
||||
|
||||
Reference in New Issue
Block a user