From acd651eea66e6120155fce7b2fcf36c2ffe44be5 Mon Sep 17 00:00:00 2001 From: jrmartin Date: Thu, 17 Feb 2022 13:59:54 -0800 Subject: [PATCH] #1295 Fix Term Context graph for classification --- components/interface/VFBGraph/QueryParser.js | 29 +++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/components/interface/VFBGraph/QueryParser.js b/components/interface/VFBGraph/QueryParser.js index 38414ce5e..e3f191527 100644 --- a/components/interface/VFBGraph/QueryParser.js +++ b/components/interface/VFBGraph/QueryParser.js @@ -60,21 +60,24 @@ export function queryParser (e) { let targetNode = nodesMap.get(n[i].target); if (targetNode !== undefined) { - // Create new link for graph - let link = { source: sourceNode, name : n[i].label, target: targetNode, targetNode: targetNode }; - links.push( link ); + let match = links.find( link => ( link.target === sourceNode && link.source === targetNode ) || ( link.target === targetNode && link.source === sourceNode )); + if ( !match ){ + // Create new link for graph + let link = { source: sourceNode, name : n[i].label, target: targetNode, targetNode: targetNode }; + links.push( link ); - // Assign neighbors to nodes and links - !sourceNode.neighbors && (sourceNode.neighbors = []); - !targetNode.neighbors && (targetNode.neighbors = []); - sourceNode.neighbors.push(targetNode); - targetNode.neighbors.push(sourceNode); + // Assign neighbors to nodes and links + !sourceNode.neighbors && (sourceNode.neighbors = []); + !targetNode.neighbors && (targetNode.neighbors = []); + sourceNode.neighbors.push(targetNode); + targetNode.neighbors.push(sourceNode); - // Assign links to nodes - !sourceNode.links && (sourceNode.links = []); - !targetNode.links && (targetNode.links = []); - sourceNode.links.push(link); - targetNode.links.push(link); + // Assign links to nodes + !sourceNode.links && (sourceNode.links = []); + !targetNode.links && (targetNode.links = []); + sourceNode.links.push(link); + targetNode.links.push(link); + } } } }