diff --git a/src/common/graph/graph.ts b/src/common/graph/graph.ts index 429341bbb6b197a55ff9cf96c52d1e198046ecee..f9acc6772965e269d3de2dcafc3e80727ce7464e 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);