diff --git a/src/Eagle.ts b/src/Eagle.ts index 4abc1dc2b..059b86d2c 100644 --- a/src/Eagle.ts +++ b/src/Eagle.ts @@ -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 @@ -1686,6 +1687,7 @@ export class Eagle { // clone the logical graph const lg_clone : LogicalGraph = ( obj).clone(); lg_clone.fileInfo().updateEagleInfo(); + const jsonString: string = LogicalGraph.toOJSJsonString(lg_clone, false); this._saveDiagramToGit(repository, fileType, filePath, fileName, fileInfo, commitMessage, jsonString); @@ -1883,6 +1885,7 @@ export class Eagle { this._handleLoadingErrors(errorsWarnings, file.name, file.repository.service); // center graph + GraphRenderer.translateLegacyGraph() this.centerGraph(); // check graph diff --git a/src/GraphRenderer.ts b/src/GraphRenderer.ts index f151348c1..b4da2925f 100644 --- a/src/GraphRenderer.ts +++ b/src/GraphRenderer.ts @@ -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){ @@ -771,7 +770,6 @@ export class GraphRenderer { } }) } - let findConstructId let orderedContructList:Node[] = [] @@ -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; @@ -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(); } @@ -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(); diff --git a/src/LogicalGraph.ts b/src/LogicalGraph.ts index feab16809..37f1815d0 100644 --- a/src/LogicalGraph.ts +++ b/src/LogicalGraph.ts @@ -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); @@ -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){