Skip to content

Commit

Permalink
wip commit of centering constructs
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Wicenec committed Nov 21, 2023
1 parent 337f8d4 commit 7203ea8
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 20 deletions.
72 changes: 72 additions & 0 deletions src/GraphRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,78 @@ export class GraphRenderer {
}
}

static centerConstructs = (construct:Node, graphNodes:Node[]) :void => {
//BIG WIP
let constructsList : Node[]=[]
if(construct === null){
graphNodes.forEach(function(node){
if(node.isConstruct()){
constructsList.push(node)
}
})
}

let findConstructId
let orderedContructList:Node[] = []

constructsList.forEach(function(x){
if(x.getParentKey()===null){
let finished = false // while there are child construct found in this construct nest group

findConstructId = x.getKey()
orderedContructList.unshift(x)
while(!finished){
let found = false
for(const entry of constructsList){
if(entry.getParentKey() === findConstructId){
orderedContructList.unshift(entry)
findConstructId = entry.getKey()
found = true
}
}
if(!found){
finished = false
}
}
}
})

orderedContructList.forEach(function(constr){

let minX : number = Number.MAX_VALUE;
let minY : number = Number.MAX_VALUE;
let maxX : number = -Number.MAX_VALUE;
let maxY : number = -Number.MAX_VALUE;
for (const node of graphNodes){

if (!node.isEmbedded() && node.getParentKey() === constr.getKey()){
if (node.getPosition().x - node.getRadius() < minX){
minX = node.getPosition().x - node.getRadius();
}
if (node.getPosition().y - node.getRadius() < minY){
minY = node.getPosition().y - node.getRadius();
}
if (node.getPosition().x + node.getRadius() > maxX){
maxX = node.getPosition().x + node.getRadius();
}
if (node.getPosition().y + node.getRadius() > maxY){
maxY = node.getPosition().y + node.getRadius();
}
}
}
// determine the centroid of the graph
const centroidX = minX + ((maxX - minX) / 2);
const centroidY = minY + ((maxY - minY) / 2);


console.log('setting center',constr.getName(),centroidX,centroidY)
constr.setPosition(centroidX,centroidY)

GraphRenderer.resizeConstruct(constr)

})
}

static moveChildNodes = (node: Node, deltax : number, deltay : number) : void => {
const eagle = Eagle.getInstance();

Expand Down
41 changes: 21 additions & 20 deletions src/LogicalGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,31 +169,32 @@ export class LogicalGraph {
}
})

result.getNodes().forEach(function(node){
if(node.isConstruct()&&!node.isEmbedded()){

let numChildren :number = 0;
// loop through all children - compute centroid
let sumX :number = 0;
let sumY :number = 0;
GraphRenderer.centerConstructs(null,result.getNodes())
// result.getNodes().forEach(function(node){
// if(node.isConstruct()&&!node.isEmbedded()){

// let numChildren :number = 0;
// // loop through all children - compute centroid
// let sumX :number = 0;
// let sumY :number = 0;

for (const x of result.getNodes()){
console.log(node.getName(),x.getName(),node.getKey(),x.getParentKey())
// for (const x of result.getNodes()){
// console.log(node.getName(),x.getName(),node.getKey(),x.getParentKey())

if (!x.isEmbedded() && x.getParentKey() === node.getKey()){
sumX += x.getPosition().x;
sumY += x.getPosition().y;
// if (!x.isEmbedded() && x.getParentKey() === node.getKey()){
// sumX += x.getPosition().x;
// sumY += x.getPosition().y;

numChildren++
}
// numChildren++
// }

}
console.log('setting center',node.getName(),sumX,sumY,numChildren,sumX/numChildren,sumY/numChildren)
node.setPosition(sumX/numChildren,sumY/numChildren)
// }
// console.log('setting center',node.getName(),sumX,sumY,numChildren,sumX/numChildren,sumY/numChildren)
// node.setPosition(sumX/numChildren,sumY/numChildren)

GraphRenderer.resizeConstruct(node)
}
})
// GraphRenderer.resizeConstruct(node)
// }
// })
}

// add edges
Expand Down

0 comments on commit 7203ea8

Please sign in to comment.