graflow: align parent

This commit is contained in:
STEINNI
2026-03-06 20:14:35 +00:00
parent bcb76e197e
commit 6408d3377b

View File

@@ -728,6 +728,7 @@ class BZgraflow extends Buildoz{
// Finally place everything
if(orientation=='horizontal'){
const fakeNodeHeight = 10
const parentsY = {}
let x = gapx
for(const [idx, layer] of layers.entries()){
let wMax = this.getMaxWidth(layer)
@@ -742,21 +743,42 @@ class BZgraflow extends Buildoz{
case 'last':
y = maxHeight - layerHeights[idx] + gapy
break
case 'auto':
//TODO
case 'parent': // y will be absolutely positioned by the parent(s) but have fallback for 1st layer
y = ((maxHeight - layerHeights[idx]) / 2) + gapy
break
}
for(const nid of layer){
let placedY
if(!nid.startsWith('longLinkPlaceHolder_')) {
const bb = this.stagedNodes[nid].getBoundingClientRect()
const nodeHeight = this.stagedNodes[nid].offsetHeight || bb.height
if((align == 'parent') && (nid in parents) && (parents[nid][0] in parentsY)) {
y = Math.max(parentsY[parents[nid][0]], y) //TODO handle multiple parents with avg
console.log('parent', nid, parents[nid], parentsY[parents[nid][0]])
}
placedY = y
this.moveNode(nid, x, y, orientation, tween, null, token)
y += gapy + (this.stagedNodes[nid].offsetHeight || bb.height)
if((align == 'parent') && (nid in parents) && (parents[nid][0] in parentsY)) {
parentsY[parents[nid][0]] += gapy + nodeHeight
} else {
y += gapy + nodeHeight
}
y = Math.max(y, placedY + gapy + nodeHeight)
} else {
if((align == 'parent') && (nid in parents) && (parents[nid][0] in parentsY)) {
y = Math.max(parentsY[parents[nid][0]], y)
}
placedY = y
this.addFakeNode(nid, x, y, wMax*0.75, fakeNodeHeight)
this.moveNode(nid, x, y, orientation, tween, null, token)
if((align == 'parent') && (nid in parents) && (parents[nid][0] in parentsY)) {
parentsY[parents[nid][0]] += gapy + fakeNodeHeight
} else {
y += gapy + fakeNodeHeight
}
y = Math.max(y, placedY + gapy + fakeNodeHeight)
}
parentsY[nid] = placedY
}
x += wMax + gapx
}
@@ -765,7 +787,21 @@ class BZgraflow extends Buildoz{
let y = gapy
for(const [idx, layer] of layers.entries()){
let hMax = this.getMaxHeight(layer)
let x = ((maxWidth - layerWidths[idx]) / 2) + gapx
let x = 0
switch(align){
case 'center':
x = ((maxWidth - layerWidths[idx]) / 2) + gapx
break
case 'first':
x = gapx
break
case 'last':
x = maxWidth - layerWidths[idx] + gapx
break
case 'parent': // x will be absolutely positioned by the parent(s)
//TODO
break
}
for(const nid of layer){
if(!nid.startsWith('longLinkPlaceHolder_')){
const bb = this.stagedNodes[nid].getBoundingClientRect()