From bbb4fd0656efbe45456acd2c23938b99454d9b62 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 21 Dec 2022 21:39:06 -0500 Subject: [PATCH] tighten up the graph merging code a little bit more (#107) --- ui/src/console/visualizer/graph.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ui/src/console/visualizer/graph.js b/ui/src/console/visualizer/graph.js index df2dc5c3..74f1a88f 100644 --- a/ui/src/console/visualizer/graph.js +++ b/ui/src/console/visualizer/graph.js @@ -51,18 +51,23 @@ export const mergeGraph = (oldGraph, newOverview) => { newGraph.nodes = sortNodes(newGraph.nodes); if(nodesEqual(oldGraph.nodes, newGraph.nodes)) { + // if the list of nodes is equal, the graph hasn't changed; we can just return the oldGraph and save the + // physics headaches in the visualizer. return oldGraph; } - console.log("nodes not equal"); + // we're going to need to recompute a new graph... but we want to maintain the instances that already exist... // we want to preserve nodes that exist in the new graph, and remove those that don't. let outputNodes = oldGraph.nodes.filter(oldNode => newGraph.nodes.find(newNode => newNode.id === oldNode.id)); let outputLinks = oldGraph.nodes.filter(oldLink => newGraph.links.find(newLink => newLink.target === oldLink.target && newLink.source === oldLink.source)); + // and then do the opposite; add any nodes that are in newGraph that are missing from oldGraph. outputNodes.push(...newGraph.nodes.filter(newNode => !outputNodes.find(oldNode => oldNode.id === newNode.id))); outputLinks.push(...newGraph.links.filter(newLink => !outputLinks.find(oldLink => oldLink.target === newLink.target && oldLink.source === newLink.source))); + return { + // we need a new outer object, to trigger react to refresh the view correctly. nodes: sortNodes(outputNodes), links: outputLinks };