Skip to content

Commit

Permalink
Graph component #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Scobiform committed Apr 20, 2024
1 parent a1deb55 commit 65af7ba
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions templates/graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 65af7ba

Please sign in to comment.