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'){
|
if(orientation=='horizontal'){
|
||||||
const fakeNodeHeight = 10
|
const fakeNodeHeight = 10
|
||||||
const parentsY = {}
|
const parentsY = {}
|
||||||
|
const nodeY = {}
|
||||||
|
const nodeX = {}
|
||||||
let x = gapx
|
let x = gapx
|
||||||
for(const [idx, layer] of layers.entries()){
|
for(const [idx, layer] of layers.entries()){
|
||||||
let wMax = this.getMaxWidth(layer)
|
let wMax = this.getMaxWidth(layer)
|
||||||
@@ -771,17 +773,32 @@ class BZgraflow extends Buildoz{
|
|||||||
placedY = y
|
placedY = y
|
||||||
this.addFakeNode(nid, x, y, wMax*0.75, fakeNodeHeight)
|
this.addFakeNode(nid, x, y, wMax*0.75, fakeNodeHeight)
|
||||||
this.moveNode(nid, x, y, orientation, tween, null, token)
|
this.moveNode(nid, x, y, orientation, tween, null, token)
|
||||||
if((align == 'parent') && (nid in parents) && (parents[nid][0] in parentsY)) {
|
// Never increment parentsY for fake nodes: they're placeholders and must not disalign real children
|
||||||
parentsY[parents[nid][0]] += gapy + fakeNodeHeight
|
|
||||||
} else {
|
|
||||||
y += gapy + fakeNodeHeight
|
|
||||||
}
|
|
||||||
y = Math.max(y, placedY + gapy + fakeNodeHeight)
|
y = Math.max(y, placedY + gapy + fakeNodeHeight)
|
||||||
}
|
}
|
||||||
parentsY[nid] = placedY
|
parentsY[nid] = placedY
|
||||||
|
nodeY[nid] = placedY
|
||||||
|
nodeX[nid] = x
|
||||||
}
|
}
|
||||||
x += wMax + gapx
|
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'){
|
} else if(orientation=='vertical'){
|
||||||
const fakeNodeWidth = 10
|
const fakeNodeWidth = 10
|
||||||
let y = gapy
|
let y = gapy
|
||||||
|
|||||||
Reference in New Issue
Block a user