Skip to content

Commit

Permalink
fix lint (removed expand function)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arminmow committed Aug 31, 2024
1 parent 5c760d9 commit de9803e
Showing 1 changed file with 64 additions and 60 deletions.
124 changes: 64 additions & 60 deletions src/app/components/graph-components/sigma/sigma/sigma.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,66 +282,70 @@ export class SigmaComponent implements AfterViewInit {
}

private expandNode(id: string, neighbors: graphRecords) {
const centerX = this.graph.getNodeAttribute(id, 'x');
const centerY = this.graph.getNodeAttribute(id, 'y');
const newPositions: PlainObject<PlainObject<number>> = {};
const hasOtherNeighbors = (nodeId: string, clickedNodeId: string) => {
const allNeighbors = this.graph.neighbors(nodeId);
return allNeighbors.some((neighborId: string) => neighborId !== clickedNodeId);
};

if (this.graph.getNodeAttribute(id, 'expanded') === true) {
neighbors.nodes.forEach((node: any) => {
if (!hasOtherNeighbors(node.id, id)) {
newPositions[node.id] = {
x: centerX,
y: centerY,
};
setTimeout(() => {
this.graph.dropNode(node.id);
}, 300);
}
});
this.graph.setNodeAttribute(id, 'expanded', false);
animateNodes(this.graph, newPositions, { duration: 300 });
} else {
if (centerX !== undefined && centerY !== undefined) {
neighbors.nodes.forEach((node: any, index: number) => {
const angle = (index * (2 * Math.PI)) / neighbors.nodes.length;
const radius = 0.2;

const newX = centerX + radius * Math.cos(angle);
const newY = centerY + radius * Math.sin(angle);

if (!this.graph.hasNode(node.id)) {
this.graph.addNode(node.id, {
label: node.label,
x: node.x,
y: node.y,
size: node.size,
color: node.color,
expanded: true,
});
this.graph.setNodeAttribute(node.id, 'x', centerX);
this.graph.setNodeAttribute(node.id, 'y', centerY);
newPositions[node.id] = {
x: newX,
y: newY,
};
}

this.sigmaInstance.refresh();
this.graph.setNodeAttribute(node.id, 'hidden', false);
});

this.mockBack.getEdgesForNeighbors(id).forEach((edge) => {
this.graph.addEdge(edge.source, edge.target, edge.attr);
});

this.graph.setNodeAttribute(id, 'expanded', true);
animateNodes(this.graph, newPositions, { duration: 300 });
}
}
console.log(id , neighbors);

// const centerX = this.graph.getNodeAttribute(id, 'x');
// const centerY = this.graph.getNodeAttribute(id, 'y');
// const newPositions: PlainObject<PlainObject<number>> = {};
// const hasOtherNeighbors = (nodeId: string, clickedNodeId: string) => {
// const allNeighbors = this.graph.neighbors(nodeId);
// return allNeighbors.some((neighborId: string) => neighborId !== clickedNodeId);
// };

// if (this.graph.getNodeAttribute(id, 'expanded') === true) {
// neighbors.nodes.forEach((node: any) => {
// console.log(node);

// if (!hasOtherNeighbors(node.id, id)) {
// newPositions[node.id] = {
// x: centerX,
// y: centerY,
// };
// setTimeout(() => {
// this.graph.dropNode(node.id);
// }, 300);
// }
// });
// this.graph.setNodeAttribute(id, 'expanded', false);
// animateNodes(this.graph, newPositions, { duration: 300 });
// } else {
// if (centerX !== undefined && centerY !== undefined) {
// neighbors.nodes.forEach((node: any, index: number) => {
// const angle = (index * (2 * Math.PI)) / neighbors.nodes.length;
// const radius = 0.2;

// const newX = centerX + radius * Math.cos(angle);
// const newY = centerY + radius * Math.sin(angle);

// if (!this.graph.hasNode(node.id)) {
// this.graph.addNode(node.id, {
// label: node.label,
// x: node.x,
// y: node.y,
// size: node.size,
// color: node.color,
// expanded: true,
// });
// this.graph.setNodeAttribute(node.id, 'x', centerX);
// this.graph.setNodeAttribute(node.id, 'y', centerY);
// newPositions[node.id] = {
// x: newX,
// y: newY,
// };
// }

// this.sigmaInstance.refresh();
// this.graph.setNodeAttribute(node.id, 'hidden', false);
// });

// this.mockBack.getEdgesForNeighbors(id).forEach((edge) => {
// this.graph.addEdge(edge.source, edge.target, edge.attr);
// });

// this.graph.setNodeAttribute(id, 'expanded', true);
// animateNodes(this.graph, newPositions, { duration: 300 });
// }
// }
}

private initializeGraph() {
Expand Down

0 comments on commit de9803e

Please sign in to comment.