Skip to content

Commit 9b09155

Browse files
committed
fix: fix hiding nodes
1 parent c7682a9 commit 9b09155

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

src/site/_includes/components/graphScript.njk

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,27 @@ function filterLocalGraphData(graphData, depth) {
4242
4343
currentNode.current = true;
4444
45+
// Hidden nodes (home page, index/hub pages like the-shelf or entity-index)
46+
// are never rendered, but they're linked from a huge number of pages. If we
47+
// let BFS walk through them as ordinary hops, they silently bridge otherwise
48+
// unrelated parts of the graph together — the hidden hop then gets dropped
49+
// from the output, leaving nodes that appear with no visible path to the
50+
// current node. So a hidden node can only ever be a traversal *endpoint*
51+
// (reached from, never walked through), except the current node itself,
52+
// whose own direct links must still count even if it happens to be hidden
53+
// (e.g. viewing the local graph on the home page).
54+
const hiddenIds = new Set(Object.values(allNodes).filter(n => n.hide).map(n => n.id));
55+
const canBridge = id => id === currentNode.id || !hiddenIds.has(id);
56+
4557
// Build an id-based adjacency map so we can walk out to arbitrary depth
4658
const adjacency = {};
4759
for (const l of allLinks) {
60+
if (!canBridge(l.source) || !canBridge(l.target)) continue;
4861
(adjacency[l.source] = adjacency[l.source] || new Set()).add(l.target);
4962
(adjacency[l.target] = adjacency[l.target] || new Set()).add(l.source);
5063
}
5164
5265
// BFS out from the current node up to `depth` hops
53-
const directNeighborIds = adjacency[currentNode.id] || new Set();
5466
const visited = new Set([currentNode.id]);
5567
let frontier = new Set([currentNode.id]);
5668
for (let i = 0; i < depth && frontier.size > 0; i++) {
@@ -66,20 +78,7 @@ function filterLocalGraphData(graphData, depth) {
6678
frontier = next;
6779
}
6880
69-
const nodes = Object.values(allNodes).filter(n => {
70-
if (n.hide) return false;
71-
return visited.has(n.id);
72-
});
73-
74-
// If current node is not home, exclude the home node unless it's a direct neighbor
75-
if (!currentNode.home) {
76-
const homeNode = nodes.find(n => n.home);
77-
if (homeNode && !directNeighborIds.has(homeNode.id)) {
78-
const idx = nodes.indexOf(homeNode);
79-
if (idx > -1) nodes.splice(idx, 1);
80-
}
81-
}
82-
81+
const nodes = Object.values(allNodes).filter(n => !n.hide && visited.has(n.id));
8382
const ids = nodes.map(n => n.id);
8483
return {
8584
nodes,

0 commit comments

Comments
 (0)