From 677dcbdbccf4d9203cc276744e083f29f4424ba9 Mon Sep 17 00:00:00 2001 From: AlexIchenskiy Date: Wed, 13 Mar 2024 10:53:18 +0100 Subject: [PATCH] New: Add removal functions --- src/models/graph.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/models/graph.ts b/src/models/graph.ts index a28c7bf..af351c0 100644 --- a/src/models/graph.ts +++ b/src/models/graph.ts @@ -263,7 +263,6 @@ export class Graph implements IGraph) { const nodeIds = data.nodeIds ?? []; const edgeIds = data.edgeIds ?? []; @@ -274,7 +273,35 @@ export class Graph implements IGraph node.id); + const edgeIds = this._edges.getAll().map((edge) => edge.id); + + this._removeNodes(nodeIds); + this._removeEdges(edgeIds); + + if (this._settings && this._settings.onRemoveData) { + this._settings.onRemoveData({ nodeIds, edgeIds }); + } + } + + removeAllEdges() { + const edgeIds = this._edges.getAll().map((edge) => edge.id); + + this._removeEdges(edgeIds); + + if (this._settings && this._settings.onRemoveData) { + this._settings.onRemoveData({ edgeIds }); + } + } + + removeAllNodes() { + this.removeAll(); } isEqual(graph: Graph): boolean {