graflow horiz + vert + fixed border & scroll issues

This commit is contained in:
STEINNI
2025-12-27 21:39:33 +00:00
parent 6730324380
commit 16332d053f
2 changed files with 55 additions and 28 deletions

View File

@@ -15,13 +15,17 @@ class BZgraflow extends Buildoz{
console.warn('BZgraflow: No flow URL !?')
return
}
this.loadFlow(flowUrl) // Let it load async while we coat
this.loadFlow(flowUrl) // Let it load async while we coat
this.mainContainer = document.createElement('div')
this.mainContainer.classList.add('bzgf-main-container')
this.nodesContainer = document.createElement('div')
this.nodesContainer.classList.add('bzgf-nodes-container')
this.wiresContainer = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
this.wiresContainer.setAttribute('overflow','visible')
this.wiresContainer.classList.add('bzgf-wires-container')
this.append(this.wiresContainer)
this.append(this.nodesContainer)
this.mainContainer.append(this.wiresContainer)
this.mainContainer.append(this.nodesContainer)
this.append(this.mainContainer)
}
async loadFlow(url){
@@ -114,16 +118,17 @@ class BZgraflow extends Buildoz{
e: { x: 1, y: 0 },
w: { x: -1, y: 0 },
}
const svgRect = this.wiresContainer.getBoundingClientRect()
const node1 = this.stagedNodes[idNode1]
const port1 = node1.ports[idPort1]
const node2 = this.stagedNodes[idNode2]
const port2 = node2.ports[idPort2]
const bb1 = port1.el.getBoundingClientRect()
const bb2 = port2.el.getBoundingClientRect()
const x1 = Math.floor(bb1.x + (bb1.width/2))
const y1 = Math.floor(bb1.y + (bb1.height/2))
const x2 = Math.floor(bb2.x + (bb2.width/2))
const y2 = Math.floor(bb2.y + (bb2.height/2))
const x1 = Math.floor(bb1.x + (bb1.width/2)) - svgRect.left
const y1 = Math.floor(bb1.y + (bb1.height/2)) - svgRect.top
const x2 = Math.floor(bb2.x + (bb2.width/2)) - svgRect.left
const y2 = Math.floor(bb2.y + (bb2.height/2)) - svgRect.top
const dist = Math.abs(x2 - x1) + Math.abs(y2 - y1)
let tension = dist * 0.4
if(tension < tensionMin) tension = tensionMin
@@ -137,11 +142,8 @@ class BZgraflow extends Buildoz{
}
autoPlace(orientation = 'horizontal', gapx = 80, gapy = 30){
if(!['horizontal', 'vertical'].includes(orientation)) return
const parents = {}
const adj = {}
this.flow.nodes.forEach(n => {
parents[n.id] = []
adj[n.id] = []
@@ -155,33 +157,51 @@ class BZgraflow extends Buildoz{
})
const layers = this.computeLayers(this.flow.nodes, parents)
let maxHeight = 0
const layerHeights = []
let maxHeight = 0; let maxWidth = 0
const layerHeights = []; const layerWidths = [];
const indexes = {} // Todo: a
for(const layer of layers){
let totHeight = 0
let totHeight = 0; let totWidth = 0
for(const [idx, nid] of layer.entries()){
const bb = this.stagedNodes[nid].getBoundingClientRect()
totHeight += bb.height+gapy
totHeight += bb.height + gapy
totWidth += bb.width + gapx
indexes[nid] = idx
}
if(totHeight>maxHeight) maxHeight = totHeight
layerHeights.push(totHeight)
if(totWidth>maxWidth) maxWidth = totWidth
layerWidths.push(totWidth)
}
this.reorderLayers(layers, parents, indexes)
let x = gapx
for(const [idx, layer] of layers.entries()){
let wMax = 0
let y = ((maxHeight - layerHeights[idx]) / 2) + gapy
for(const nid of layer){
const bb = this.stagedNodes[nid].getBoundingClientRect()
wMax = (bb.width > wMax) ? bb.width : wMax
this.moveNode(nid, x, y, 1000)
y += gapy + bb.height
if(orientation=='horizontal'){
let x = gapx
for(const [idx, layer] of layers.entries()){
let wMax = 0
let y = ((maxHeight - layerHeights[idx]) / 2) + gapy
for(const nid of layer){
const bb = this.stagedNodes[nid].getBoundingClientRect()
wMax = (bb.width > wMax) ? bb.width : wMax
this.moveNode(nid, x, y, 1000)
y += gapy + bb.height
}
x += wMax + gapx
}
x += wMax + gapx
} else if(orientation=='vertical'){
let y = gapy
for(const [idx, layer] of layers.entries()){
let hMax = 0
let x = ((maxWidth - layerWidths[idx]) / 2) + gapx
for(const nid of layer){
const bb = this.stagedNodes[nid].getBoundingClientRect()
hMax = (bb.height > hMax) ? bb.width : hMax
this.moveNode(nid, x, y, 1000)
x += gapx + bb.width
}
y += hMax + gapy
}
}
}