From 35c363ad57e15ac1e8c7d93bc6bc5fa0d0775257 Mon Sep 17 00:00:00 2001 From: mgfcf <m.giller@tu-braunschweig.de> Date: Sun, 19 Sep 2021 19:25:48 +0200 Subject: [PATCH] Fixed undo/redo --- editor/js/graph.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/editor/js/graph.js b/editor/js/graph.js index 86184dd..29badad 100644 --- a/editor/js/graph.js +++ b/editor/js/graph.js @@ -65,7 +65,7 @@ export class Graph extends ManagedData { } getLinkColor(link) { - return this.getLinkTypeColor(link[LINK_TYPE]) + return this.getLinkTypeColor(link[LINK_TYPE]); } getLinkTypeColor(linkClass) { @@ -223,10 +223,18 @@ export class Graph extends ManagedData { getCleanLink(link, simulationParameters) { var cleanLink = {}; - // Source and target nodes - // Node ids will be converted to complete node objects on running graphs, gotta convert back - cleanLink[LINK_SOURCE] = link[LINK_SOURCE][NODE_ID]; - cleanLink[LINK_TARGET] = link[LINK_TARGET][NODE_ID]; + // Assuming that all nodes are valid, there are two possible formats + // 1. source and target are node objects + if (link[LINK_SOURCE][NODE_ID] !== undefined) { + // Source and target nodes + // Node ids will be converted to complete node objects on running graphs, gotta convert back + cleanLink[LINK_SOURCE] = link[LINK_SOURCE][NODE_ID]; + cleanLink[LINK_TARGET] = link[LINK_TARGET][NODE_ID]; + } else { + // 2. source and target are just node ids + cleanLink[LINK_SOURCE] = link[LINK_SOURCE]; + cleanLink[LINK_TARGET] = link[LINK_TARGET]; + } // Other parameters LINK_PARAMS.forEach((param) => { -- GitLab