From 65af7ba0fcb975de58be45eb162621b5fe215b8c Mon Sep 17 00:00:00 2001 From: Scobiform Date: Sat, 20 Apr 2024 21:45:50 +0200 Subject: [PATCH] Graph component #1 --- templates/graph.html | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/templates/graph.html b/templates/graph.html index 1180dd9..4977563 100644 --- a/templates/graph.html +++ b/templates/graph.html @@ -343,32 +343,33 @@ // Filter links to include only those whose source and target are in visibleNodes const filteredLinks = graphData.links.filter(link => { + let sourceId = (typeof link.source === 'object') ? link.source.id : link.source; + let targetId = (typeof link.target === 'object') ? link.target.id : link.target; + return visibleNodes.has(sourceId) && visibleNodes.has(targetId); + }); + + // Ensure that nodes linked to visible 'instance' nodes also become visible, if relevant + if (filterType === 'follower-and-instances' || filterType === 'following-and-instances' || filterType === 'instances') { + filteredLinks.forEach(link => { let sourceId = (typeof link.source === 'object') ? link.source.id : link.source; let targetId = (typeof link.target === 'object') ? link.target.id : link.target; - return visibleNodes.has(sourceId) && visibleNodes.has(targetId); + if (graphData.nodes.find(node => node.id === sourceId && node.type === 'instance') || + graphData.nodes.find(node => node.id === targetId && node.type === 'instance')) { + visibleNodes.add(sourceId); + visibleNodes.add(targetId); + } }); + } - // Ensure that nodes linked to visible 'instance' nodes also become visible, if relevant - if (filterType === 'follower-and-instances' || filterType === 'following-and-instances' || filterType === 'instances') { - filteredLinks.forEach(link => { - let sourceId = (typeof link.source === 'object') ? link.source.id : link.source; - let targetId = (typeof link.target === 'object') ? link.target.id : link.target; - if (graphData.nodes.find(node => node.id === sourceId && node.type === 'instance') || - graphData.nodes.find(node => node.id === targetId && node.type === 'instance')) { - visibleNodes.add(sourceId); - visibleNodes.add(targetId); - } - }); - } - - // Prepare the filtered data for nodes and links - const filteredData = { - nodes: graphData.nodes.filter(node => visibleNodes.has(node.id)), - links: filteredLinks - }; + // Prepare the filtered data for nodes and links + const filteredData = { + nodes: graphData.nodes.filter(node => visibleNodes.has(node.id)), + links: filteredLinks + }; - graph.graphData(filteredData); - } + // Update the graph with the filtered data + graph.graphData(filteredData); +} // Prepare the filtered data for nodes and links.