-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CELE-32 style: Lint graphRendering code
- Loading branch information
1 parent
8369397
commit ba77ed4
Showing
3 changed files
with
65 additions
and
66 deletions.
There are no files selected for viewing
98 changes: 50 additions & 48 deletions
98
applications/visualizer/frontend/src/helpers/twoD/graphRendering.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,60 @@ | ||
// src/helpers/twoD/graphDiffUtils.ts | ||
import type { Core } from "cytoscape"; | ||
import { createEdge, createNode } from "./twoDHelpers"; | ||
|
||
export const computeGraphDifferences = (cy: Core, connections: any[], workspace: any) => { | ||
const currentNodes = new Set(cy.nodes().map((node) => node.id())); | ||
const currentEdges = new Set(cy.edges().map((edge) => edge.id())); | ||
|
||
const newNodes = new Set<string>(); | ||
const newEdges = new Set<string>(); | ||
|
||
const nodesToAdd: any[] = []; | ||
const nodesToRemove: any[] = []; | ||
const edgesToAdd: any[] = []; | ||
const edgesToRemove: any[] = []; | ||
|
||
// Compute new nodes and edges based on the current connections and workspace state | ||
const filteredActiveNeurons = Array.from(workspace.activeNeurons).filter((neuronId: string) => { | ||
const neuron = workspace.availableNeurons[neuronId]; | ||
if (!neuron) { | ||
return false; | ||
import type { Core, ElementDefinition, CollectionReturnValue } from 'cytoscape'; | ||
import { createEdge, createNode } from './twoDHelpers'; | ||
import {Connection} from "../../rest"; | ||
import {Workspace} from "../../models"; | ||
|
||
export const computeGraphDifferences = (cy: Core, connections: Connection[], workspace: Workspace) => { | ||
const currentNodes = new Set(cy.nodes().map(node => node.id())); | ||
const currentEdges = new Set(cy.edges().map(edge => edge.id())); | ||
|
||
const newNodes = new Set<string>(); | ||
const newEdges = new Set<string>(); | ||
|
||
const nodesToAdd: ElementDefinition[] = []; | ||
const nodesToRemove: CollectionReturnValue = cy.collection(); | ||
const edgesToAdd: ElementDefinition[] = []; | ||
const edgesToRemove: CollectionReturnValue = cy.collection(); | ||
|
||
// Compute new nodes and edges based on the current connections and workspace state | ||
const filteredActiveNeurons = Array.from(workspace.activeNeurons).filter((neuronId: string) => { | ||
const neuron = workspace.availableNeurons[neuronId]; | ||
if (!neuron) { | ||
return false; | ||
} | ||
const nclass = neuron.nclass; | ||
if (neuronId === nclass) { | ||
return true; | ||
} | ||
return !(workspace.activeNeurons.has(neuronId) && workspace.activeNeurons.has(nclass)); | ||
}); | ||
|
||
for (const nodeId of filteredActiveNeurons) { | ||
newNodes.add(nodeId); | ||
if (!currentNodes.has(nodeId)) { | ||
nodesToAdd.push(createNode(nodeId, workspace.selectedNeurons.has(nodeId))); | ||
} | ||
} | ||
const nclass = neuron.nclass; | ||
if (neuronId === nclass) { | ||
return true; | ||
} | ||
return !(workspace.activeNeurons.has(neuronId) && workspace.activeNeurons.has(nclass)); | ||
}); | ||
|
||
filteredActiveNeurons.forEach((nodeId: string) => { | ||
newNodes.add(nodeId); | ||
if (!currentNodes.has(nodeId)) { | ||
nodesToAdd.push(createNode(nodeId, workspace.selectedNeurons.has(nodeId))); | ||
} | ||
}); | ||
|
||
currentNodes.forEach((nodeId) => { | ||
if (!newNodes.has(nodeId)) { | ||
nodesToRemove.push(cy.getElementById(nodeId)); | ||
for (const nodeId of currentNodes) { | ||
if (!newNodes.has(nodeId)) { | ||
nodesToRemove.merge(cy.getElementById(nodeId)); | ||
} | ||
} | ||
}); | ||
|
||
connections.forEach((conn) => { | ||
const edgeId = `${conn.pre}-${conn.post}`; | ||
newEdges.add(edgeId); | ||
if (!currentEdges.has(edgeId)) { | ||
edgesToAdd.push(createEdge(conn)); | ||
for (const conn of connections) { | ||
const edgeId = `${conn.pre}-${conn.post}`; | ||
newEdges.add(edgeId); | ||
if (!currentEdges.has(edgeId)) { | ||
edgesToAdd.push(createEdge(conn)); | ||
} | ||
} | ||
}); | ||
|
||
currentEdges.forEach((edgeId) => { | ||
if (!newEdges.has(edgeId)) { | ||
edgesToRemove.push(cy.getElementById(edgeId)); | ||
for (const edgeId of currentEdges) { | ||
if (!newEdges.has(edgeId)) { | ||
edgesToRemove.merge(cy.getElementById(edgeId)); | ||
} | ||
} | ||
}); | ||
|
||
return { nodesToAdd, nodesToRemove: cy.collection(nodesToRemove), edgesToAdd, edgesToRemove: cy.collection(edgesToRemove) }; | ||
return { nodesToAdd, nodesToRemove, edgesToAdd, edgesToRemove }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters