reorder layers 1.0 (not with ports yet)
This commit is contained in:
45
bzGraflow.js
45
bzGraflow.js
@@ -155,30 +155,24 @@ class BZgraflow extends Buildoz{
|
|||||||
})
|
})
|
||||||
|
|
||||||
const layers = this.computeLayers(this.flow.nodes, parents)
|
const layers = this.computeLayers(this.flow.nodes, parents)
|
||||||
// const maxLayers = Math.max(...layers.map(item=>item.length))
|
|
||||||
let maxHeight = 0
|
let maxHeight = 0
|
||||||
const layerHeights = []
|
const layerHeights = []
|
||||||
|
const indexes = {} // Todo: a
|
||||||
for(const layer of layers){
|
for(const layer of layers){
|
||||||
let totHeight = 0
|
let totHeight = 0
|
||||||
for(const nid of layer){
|
for(const [idx, nid] of layer.entries()){
|
||||||
const bb = this.stagedNodes[nid].getBoundingClientRect()
|
const bb = this.stagedNodes[nid].getBoundingClientRect()
|
||||||
totHeight += bb.height+gapy
|
totHeight += bb.height+gapy
|
||||||
|
indexes[nid] = idx
|
||||||
}
|
}
|
||||||
if(totHeight>maxHeight) maxHeight = totHeight
|
if(totHeight>maxHeight) maxHeight = totHeight
|
||||||
layerHeights.push(totHeight)
|
layerHeights.push(totHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.reorderLayers(layers, parents, indexes)
|
||||||
|
|
||||||
let x = gapx
|
let x = gapx
|
||||||
for(const [idx, layer] of layers.entries()){
|
for(const [idx, layer] of layers.entries()){
|
||||||
for(const nid of layer){
|
|
||||||
// some parents can be in far layers, but at least one is in the prev layer (by definition of layer)
|
|
||||||
const localParent = parents[nid].find((nid => layers[idx-1].includes(nid)))
|
|
||||||
if(localParent){ //undefined for 1st node
|
|
||||||
const ports = this.stagedNodes[localParent].ports
|
|
||||||
console.log(`parent of ${nid} is ${localParent}`, ports)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let wMax = 0
|
let wMax = 0
|
||||||
let y = ((maxHeight - layerHeights[idx]) / 2) + gapy
|
let y = ((maxHeight - layerHeights[idx]) / 2) + gapy
|
||||||
for(const nid of layer){
|
for(const nid of layer){
|
||||||
@@ -191,7 +185,32 @@ class BZgraflow extends Buildoz{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
moveNode(nid, destx, desty, duration = 200) {
|
reorderLayers(layers, parents, indexes){
|
||||||
|
const swap = (vect, todo) => {
|
||||||
|
for(const s of todo){
|
||||||
|
[vect[s[0]], vect[s[1]]] = [vect[s[1]], vect[s[0]]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(const [lidx, layer] of layers.entries()){
|
||||||
|
if(lidx==0) continue
|
||||||
|
const toSwap = []
|
||||||
|
for(let i=0; i<layer.length; i++){
|
||||||
|
const nid1 = layer[i]
|
||||||
|
// some parents can be in far layers, but at least one is in the prev layer (by definition of layer)
|
||||||
|
const pnid1 = parents[nid1].find((nid => layers[lidx-1].includes(nid)))
|
||||||
|
for(let j=i+1; j<layer.length; j++){
|
||||||
|
const nid2 = layer[j]
|
||||||
|
const pnid2 = parents[nid2].find((nid => layers[lidx-1].includes(nid)))
|
||||||
|
if(((indexes[pnid1] - indexes[pnid2]) * (indexes[nid1] - indexes[nid2])) < 0) { // crossing !
|
||||||
|
toSwap.push([i, j])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
swap(layer, toSwap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
moveNode(nid, destx, desty, duration = 200, cb) {
|
||||||
const t0 = performance.now()
|
const t0 = performance.now()
|
||||||
const bb = this.stagedNodes[nid].getBoundingClientRect()
|
const bb = this.stagedNodes[nid].getBoundingClientRect()
|
||||||
const x0=bb.x
|
const x0=bb.x
|
||||||
@@ -275,5 +294,3 @@ class BZgraflow extends Buildoz{
|
|||||||
|
|
||||||
}
|
}
|
||||||
Buildoz.define('graflow', BZgraflow)
|
Buildoz.define('graflow', BZgraflow)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user