From 9728a7c9f821dfa37a096d141414e946d7987fd5 Mon Sep 17 00:00:00 2001 From: Matthias Konitzny <konitzny@ibr.cs.tu-bs.de> Date: Wed, 21 Sep 2022 11:40:53 +0200 Subject: [PATCH] Changed default object group behavior. --- src/common/graph/graph.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/common/graph/graph.ts b/src/common/graph/graph.ts index 429341b..f9acc67 100644 --- a/src/common/graph/graph.ts +++ b/src/common/graph/graph.ts @@ -40,7 +40,6 @@ export class Graph public nodes: Node[]; public links: Link[]; public objectGroups: NodeType[]; - private defaultGroup: NodeType; public initialized: boolean; public idToObjectGroup: Map<number, NodeType>; @@ -140,18 +139,17 @@ export class Graph return this; } + /** + * Makes sure a default object group exists, if there is no object group. + * @private + */ private createDefaultObjectGroupIfNeeded() { - const defaultGroup = this.objectGroups.find( - (group) => group.name == "Default" - ); - if (defaultGroup == undefined) { - this.defaultGroup = this.createObjectGroup({ + if (this.objectGroups.length == 0) { + this.createObjectGroup({ id: ++this.nextObjectGroupId, name: "Default", color: "#000000", }); - } else { - this.defaultGroup = defaultGroup; } } @@ -204,7 +202,7 @@ export class Graph const node = new Node(); node.fromSerializedObject(data); const group = this.idToObjectGroup.get(data.type); - node.type = group != undefined ? group : this.defaultGroup; + node.type = group != undefined ? group : this.objectGroups[0]; node.neighbors = []; node.links = []; this.addNode(node); -- GitLab