Skip to content
Snippets Groups Projects
Commit c9f3cee1 authored by Matthias Konitzny's avatar Matthias Konitzny :fire:
Browse files

Fixed node filtering.

parent d5affe13
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,10 @@ export class Graph ...@@ -44,6 +44,10 @@ export class Graph
private idToNode: Map<number, Node>; private idToNode: Map<number, Node>;
private idToLink: Map<number, Link>; private idToLink: Map<number, Link>;
private nextNodeId = 0;
private nextLinkId = 0;
private nextObjectGroupId = 0;
/** /**
* Creates a new Graph object. * Creates a new Graph object.
* Make sure the nodes and links are connected to the correct objects before calling this method! * Make sure the nodes and links are connected to the correct objects before calling this method!
...@@ -71,20 +75,31 @@ export class Graph ...@@ -71,20 +75,31 @@ export class Graph
}); });
this.connectElementsToGraph(); this.connectElementsToGraph();
this.updateNodeData();
this.initializeIdGeneration();
} }
protected reset() { protected reset() {
this.nodes = []; this.nodes = [];
this.links = []; this.links = [];
this.objectGroups = [];
this.nameToObjectGroup = new Map<string, NodeType>(); this.nameToObjectGroup = new Map<string, NodeType>();
this.idToNode = new Map<number, Node>(); this.idToNode = new Map<number, Node>();
this.idToLink = new Map<number, Link>(); this.idToLink = new Map<number, Link>();
} }
private initializeIdGeneration() {
this.nextNodeId = Math.max(...this.nodes.map((node) => node.id)) + 1;
this.nextLinkId = Math.max(...this.links.map((link) => link.id)) + 1;
this.nextObjectGroupId = Math.max(
...this.objectGroups.map((group) => group.id)
);
}
/** /**
* Sets the correct graph object for all the graph elements in data. * Sets the correct graph object for all the graph elements in data.
*/ */
connectElementsToGraph() { private connectElementsToGraph() {
this.nodes.forEach((n) => (n.graph = this)); this.nodes.forEach((n) => (n.graph = this));
this.links.forEach((l) => { this.links.forEach((l) => {
l.graph = this; l.graph = this;
...@@ -158,6 +173,11 @@ export class Graph ...@@ -158,6 +173,11 @@ export class Graph
* Creates a 'neighbors' and 'links' array for each node object. * Creates a 'neighbors' and 'links' array for each node object.
*/ */
private updateNodeData(): Link[] { private updateNodeData(): Link[] {
this.nodes.forEach((node) => {
node.links = [];
node.neighbors = [];
});
this.links.forEach((link) => { this.links.forEach((link) => {
const a = link.source; const a = link.source;
const b = link.target; const b = link.target;
...@@ -178,7 +198,9 @@ export class Graph ...@@ -178,7 +198,9 @@ export class Graph
} }
private addNode(node: Node) { private addNode(node: Node) {
node.id = this.nodes.length; if (this.idToNode.has(node.id)) {
node.id = this.nextNodeId++;
}
this.nodes.push(node); this.nodes.push(node);
this.idToNode.set(node.id, node); this.idToNode.set(node.id, node);
} }
...@@ -223,13 +245,18 @@ export class Graph ...@@ -223,13 +245,18 @@ export class Graph
} }
private addObjectGroup(group: NodeType) { private addObjectGroup(group: NodeType) {
group.id = this.objectGroups.length; // if (this.nameToObjectGroup.has(group.id)) {
//
// }
group.id = this.nextObjectGroupId++;
this.objectGroups.push(group); this.objectGroups.push(group);
this.nameToObjectGroup.set(group.name, group); // TODO: Replace with id this.nameToObjectGroup.set(group.name, group); // TODO: Replace with id
} }
private addLink(link: Link) { private addLink(link: Link) {
link.id = this.links.length; if (this.idToLink.has(link.id)) {
link.id = this.nextLinkId++;
}
this.links.push(link); this.links.push(link);
this.idToLink.set(link.id, link); this.idToLink.set(link.id, link);
} }
......
...@@ -88,6 +88,7 @@ class Display extends React.Component< ...@@ -88,6 +88,7 @@ class Display extends React.Component<
handleNodeFilter(visibility: Map<string, boolean>) { handleNodeFilter(visibility: Map<string, boolean>) {
const graph = this.graph.view(visibility); const graph = this.graph.view(visibility);
graph.removeFloatingNodes();
this.setState({ graph: graph }); this.setState({ graph: graph });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment