Skip to content

Commit

Permalink
translating and centering constructs for legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Wicenec committed Nov 22, 2023
1 parent 7203ea8 commit a196f7b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 47 deletions.
3 changes: 3 additions & 0 deletions src/Eagle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ export class Eagle {
this.logicalGraph(lg);

// center graph
GraphRenderer.translateLegacyGraph()
this.centerGraph();

// update the activeFileInfo with details of the repository the file was loaded from
Expand Down Expand Up @@ -1686,6 +1687,7 @@ export class Eagle {
// clone the logical graph
const lg_clone : LogicalGraph = (<LogicalGraph> obj).clone();
lg_clone.fileInfo().updateEagleInfo();

const jsonString: string = LogicalGraph.toOJSJsonString(lg_clone, false);

this._saveDiagramToGit(repository, fileType, filePath, fileName, fileInfo, commitMessage, jsonString);
Expand Down Expand Up @@ -1883,6 +1885,7 @@ export class Eagle {
this._handleLoadingErrors(errorsWarnings, file.name, file.repository.service);

// center graph
GraphRenderer.translateLegacyGraph()
this.centerGraph();

// check graph
Expand Down
30 changes: 23 additions & 7 deletions src/GraphRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,6 @@ export class GraphRenderer {
}

static centerConstructs = (construct:Node, graphNodes:Node[]) :void => {
//BIG WIP
let constructsList : Node[]=[]
if(construct === null){
graphNodes.forEach(function(node){
Expand All @@ -771,7 +770,6 @@ export class GraphRenderer {
}
})
}

let findConstructId
let orderedContructList:Node[] = []

Expand All @@ -791,13 +789,14 @@ export class GraphRenderer {
}
}
if(!found){
finished = false
finished = true
}
}
}
})

orderedContructList.forEach(function(constr){
let childCount = 0

let minX : number = Number.MAX_VALUE;
let minY : number = Number.MAX_VALUE;
Expand All @@ -806,6 +805,7 @@ export class GraphRenderer {
for (const node of graphNodes){

if (!node.isEmbedded() && node.getParentKey() === constr.getKey()){
childCount++
if (node.getPosition().x - node.getRadius() < minX){
minX = node.getPosition().x - node.getRadius();
}
Expand All @@ -820,19 +820,35 @@ export class GraphRenderer {
}
}
}

if(childCount === 0){
return
}

// 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 translateLegacyGraph = () : void =>{
const eagle = Eagle.getInstance();

//we are moving each node by half its radius to counter the fact that the new graph renderer treats the node's visual center as node position, previously the node position was in its top left.
if(GraphRenderer.legacyGraph){
//we need to calculate the construct radius in relation to it's children
eagle.logicalGraph().getNodes().forEach(function(node){
if(!node.isConstruct()&&!node.isEmbedded()){
node.setPosition(node.getPosition().x+node.getRadius()/2,node.getPosition().y + node.getRadius()/2,false)
}
})
GraphRenderer.centerConstructs(null,eagle.logicalGraph().getNodes())
}
}

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

Expand Down
40 changes: 0 additions & 40 deletions src/LogicalGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,44 +159,6 @@ export class LogicalGraph {
}
}


//we are moving each node by half its radius to counter the fact that the new graph renderer treats the node's visual center as node position, previously the node position was in its top left.
if(GraphRenderer.legacyGraph){
//we need to calculate the construct radius in relation to it's children
result.getNodes().forEach(function(node){
if(!node.isConstruct()&&!node.isEmbedded()){
node.setPosition(node.getPosition().x+node.getRadius()/2,node.getPosition().y + node.getRadius()/2,false)
}
})

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())

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

// numChildren++
// }

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

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

// add edges
for (const linkData of dataObject.linkDataArray){
const newEdge = Edge.fromOJSJson(linkData, errorsWarnings);
Expand Down Expand Up @@ -396,12 +358,10 @@ export class LogicalGraph {

findNodeByKey = (key : number) : Node => {
for (let i = this.nodes().length - 1; i >= 0 ; i--){

// check if the node itself has a matching key
if (this.nodes()[i].getKey() === key){
return this.nodes()[i];
}

// check if the node's inputApp has a matching key
if (this.nodes()[i].hasInputApplication()){
if (this.nodes()[i].getInputApplication().getKey() === key){
Expand Down

0 comments on commit a196f7b

Please sign in to comment.