Skip to content

Commit

Permalink
legacy graph conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Wicenec committed Nov 20, 2023
1 parent 6438b5d commit 337f8d4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 32 deletions.
15 changes: 0 additions & 15 deletions src/Eagle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,6 @@ export class Eagle {
console.error("Not implemented!");
}

// resizeConstructs = () : void => {
// // debug - resize a few times, to avoid the need to resize from leaves upwards
// for (let i = 0 ; i < 10 ; i++){
// for (const node of this.logicalGraph().getNodes()){
// if (node.isGroup()){
// GraphRenderer.resizeConstruct(node, true);
// }
// }
// }
// }

centerGraph = () : void => {
const that = this
setTimeout(function(){
Expand Down Expand Up @@ -772,8 +761,6 @@ export class Eagle {
// center graph
this.centerGraph();

// this.resizeConstructs();

// update the activeFileInfo with details of the repository the file was loaded from
if (fileFullPath !== ""){
this.updateLogicalGraphFileInfo(Eagle.RepositoryService.File, "", "", Utils.getFilePathFromFullPath(fileFullPath), Utils.getFileNameFromFullPath(fileFullPath));
Expand Down Expand Up @@ -1895,8 +1882,6 @@ export class Eagle {
// show errors/warnings
this._handleLoadingErrors(errorsWarnings, file.name, file.repository.service);

// this.resizeConstructs();

// center graph
this.centerGraph();

Expand Down
18 changes: 1 addition & 17 deletions src/GraphRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export class GraphRenderer {

static mousePosX : ko.Observable<number> = ko.observable(-1);
static mousePosY : ko.Observable<number> = ko.observable(-1);
static legacyGraph : boolean = false; //used for marking a graph when its nodes dont have a radius set. in this case we will do some conversion

static renderDraggingPortEdge : ko.Observable<boolean> = ko.observable(false);

Expand Down Expand Up @@ -715,15 +716,13 @@ export class GraphRenderer {
if (oldParent !== null){
// moved out of a construct
$('#'+oldParent.getId()).addClass('transition')
// eagle.resizeConstructs();
}
// recalculate size of parent (or oldParent)
if (parent === null){

} else {
// moved into or within a construct
$('#'+parent.getId()).removeClass('transition')
// eagle.resizeConstructs();
}

} else {
Expand Down Expand Up @@ -830,21 +829,6 @@ export class GraphRenderer {
static resizeConstruct = (construct: Node, allowMovement: boolean = false): void => {
const eagle = Eagle.getInstance();
let maxDistance = 0;
let numChildren = 0;
// loop through all children - compute centroid
if (allowMovement){
let sumX = 0;
let sumY = 0;

for (const node of eagle.logicalGraph().getNodes()){
if (!node.isEmbedded && node.getParentKey() === construct.getKey()){
sumX += node.getPosition().x;
sumY += node.getPosition().y;

numChildren = numChildren + 1;
}
}
}

// loop through all children - find distance from center of construct
for (const node of eagle.logicalGraph().getNodes()){
Expand Down
39 changes: 39 additions & 0 deletions src/LogicalGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { Node } from './Node';
import { RepositoryFile } from './RepositoryFile';
import { Setting } from './Setting';
import { Utils } from './Utils';
import { GraphRenderer } from './GraphRenderer';

export class LogicalGraph {
fileInfo : ko.Observable<FileInfo>;
Expand Down Expand Up @@ -133,6 +134,7 @@ export class LogicalGraph {

const newKey = Utils.findNewKey(combinedKeys);


extraUsedKeys.push(newKey);
return newKey;
});
Expand All @@ -157,6 +159,43 @@ 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)
}
})

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
4 changes: 4 additions & 0 deletions src/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,10 @@ export class Node {
node.description(nodeData.description);
}

if(node.getRadius()===0){
GraphRenderer.legacyGraph = true
}

// get size (if exists)
let width = GraphConfig.NORMAL_NODE_RADIUS;
let height = GraphConfig.NORMAL_NODE_RADIUS;
Expand Down

0 comments on commit 337f8d4

Please sign in to comment.