graflow: improved parent align: correction on parents if fakenodes
This commit is contained in:
27
bzGraflow.js
27
bzGraflow.js
@@ -729,6 +729,8 @@ class BZgraflow extends Buildoz{
|
||||
if(orientation=='horizontal'){
|
||||
const fakeNodeHeight = 10
|
||||
const parentsY = {}
|
||||
const nodeY = {}
|
||||
const nodeX = {}
|
||||
let x = gapx
|
||||
for(const [idx, layer] of layers.entries()){
|
||||
let wMax = this.getMaxWidth(layer)
|
||||
@@ -771,17 +773,32 @@ class BZgraflow extends Buildoz{
|
||||
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
|
||||
}
|
||||
// Never increment parentsY for fake nodes: they're placeholders and must not disalign real children
|
||||
y = Math.max(y, placedY + gapy + fakeNodeHeight)
|
||||
}
|
||||
parentsY[nid] = placedY
|
||||
nodeY[nid] = placedY
|
||||
nodeX[nid] = x
|
||||
}
|
||||
x += wMax + gapx
|
||||
}
|
||||
// Correct parent positions: when fake nodes pushed children down, align parents with their first real child
|
||||
if(align == 'parent'){
|
||||
for(let idx = 1; idx < layers.length; idx++){
|
||||
const layer = layers[idx]
|
||||
const prevLayer = layers[idx - 1]
|
||||
for(const pid of prevLayer){
|
||||
if(pid.startsWith('longLinkPlaceHolder_')) continue
|
||||
const firstRealChild = layer.find(nid =>
|
||||
!nid.startsWith('longLinkPlaceHolder_') && nid in parents && parents[nid][0] === pid
|
||||
)
|
||||
if(firstRealChild && nodeY[pid] !== nodeY[firstRealChild]){
|
||||
this.moveNode(pid, nodeX[pid], nodeY[firstRealChild], orientation, tween, null, token)
|
||||
nodeY[pid] = nodeY[firstRealChild]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(orientation=='vertical'){
|
||||
const fakeNodeWidth = 10
|
||||
let y = gapy
|
||||
|
||||
Reference in New Issue
Block a user