-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph-explorer.html
More file actions
167 lines (147 loc) · 7.84 KB
/
graph-explorer.html
File metadata and controls
167 lines (147 loc) · 7.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<html>
<head>
<title>Kuhlmann Knowledge Graph</title>
<script src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #1a1a2e; color: #eee; }
#graph { width: 100%; height: 100vh; }
#controls { position: fixed; top: 16px; left: 16px; z-index: 10; display: flex; gap: 8px; flex-wrap: wrap; max-width: 70%; }
#controls button { padding: 6px 14px; border: 1px solid #444; border-radius: 20px; background: #16213e; color: #eee; cursor: pointer; font-size: 13px; transition: all 0.2s; white-space: nowrap; }
#controls button:hover { background: #0f3460; }
#controls button.active { background: #e74c3c; border-color: #e74c3c; }
#controls .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
#search { position: fixed; top: 16px; right: 16px; z-index: 10; }
#search input { padding: 8px 16px; border: 1px solid #444; border-radius: 20px; background: #16213e; color: #eee; font-size: 14px; width: 220px; outline: none; }
#search input:focus { border-color: #e74c3c; }
#info {
position: fixed; bottom: 16px; left: 16px; z-index: 10;
background: rgba(22,33,62,0.97); border: 1px solid #444; border-radius: 12px;
padding: 20px; max-width: 400px; max-height: 55vh; overflow-y: auto;
display: none; font-size: 13px; line-height: 1.6;
box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
#info .close { position: absolute; top: 10px; right: 14px; cursor: pointer; color: #888; font-size: 20px; }
#info .close:hover { color: #fff; }
#info h3 { color: #e74c3c; margin-bottom: 4px; font-size: 18px; }
#info .group-badge { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 11px; margin-bottom: 12px; }
#info .fact-row { padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.06); display: flex; gap: 8px; }
#info .fact-row:last-child { border-bottom: none; }
#info .fact-icon { flex-shrink: 0; width: 20px; text-align: center; }
#info .fact-key { color: #888; min-width: 80px; flex-shrink: 0; }
#info .fact-value { color: #ddd; word-break: break-word; }
#info .connections { margin-top: 12px; padding-top: 12px; border-top: 1px solid #333; }
#info .connections h4 { color: #888; font-size: 12px; text-transform: uppercase; margin-bottom: 6px; }
#info .conn-link { color: #3498db; cursor: pointer; text-decoration: none; }
#info .conn-link:hover { text-decoration: underline; }
#info .conn-pred { color: #666; font-size: 12px; }
#stats { position: fixed; bottom: 16px; right: 16px; z-index: 10; background: rgba(22,33,62,0.9); border: 1px solid #333; border-radius: 8px; padding: 10px 16px; font-size: 12px; color: #888; }
</style>
</head>
<body>
<div id="controls"></div>
<div id="search"><input type="text" placeholder="Search people..." id="searchInput"></div>
<div id="graph"></div>
<div id="info"><span class="close" onclick="document.getElementById('info').style.display='none'">×</span><div id="infoContent"></div></div>
<div id="stats"></div>
<script>
let network, allNodes, allEdges, nodeDataset, edgeDataset;
const groups = {};
const groupColors = {};
fetch('./graph-data.json').then(r => r.json()).then(data => {
allNodes = data.nodes;
allEdges = data.edges;
allNodes.forEach(n => {
if (!groups[n.group]) { groups[n.group] = 0; groupColors[n.group] = n.color; }
groups[n.group]++;
});
const ctrl = document.getElementById('controls');
ctrl.innerHTML = '<button class="active" onclick="filterGroup(null, this)">All (' + allNodes.length + ')</button>';
Object.entries(groups).sort((a,b) => b[1] - a[1]).forEach(([g, cnt]) => {
ctrl.innerHTML += `<button onclick="filterGroup('${g}', this)"><span class="dot" style="background:${groupColors[g]}"></span>${g} (${cnt})</button>`;
});
document.getElementById('stats').innerHTML = `${allNodes.length} people · ${allEdges.length} connections · Knowledge Graph v2 + Activation`;
nodeDataset = new vis.DataSet(allNodes.map(n => ({...n, title: n.title || n.id})));
edgeDataset = new vis.DataSet(allEdges);
network = new vis.Network(document.getElementById('graph'), { nodes: nodeDataset, edges: edgeDataset }, {
physics: {
solver: 'forceAtlas2Based',
forceAtlas2Based: { gravitationalConstant: -80, centralGravity: 0.01, springLength: 150, springConstant: 0.04, damping: 0.5 },
stabilization: { iterations: 250 }
},
interaction: { hover: true, tooltipDelay: 300, navigationButtons: false, keyboard: true },
edges: { smooth: { type: 'continuous' }, width: 1.5 },
nodes: { shape: 'dot', borderWidth: 2, shadow: { enabled: true, size: 10 }, font: { color: '#ddd' } }
});
network.on('click', function(params) {
if (params.nodes.length > 0) showInfo(params.nodes[0]);
});
});
function filterGroup(group, btn) {
document.querySelectorAll('#controls button').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
if (!group) {
nodeDataset.clear(); nodeDataset.add(allNodes);
edgeDataset.clear(); edgeDataset.add(allEdges);
} else {
const ids = new Set(allNodes.filter(n => n.group === group).map(n => n.id));
allEdges.forEach(e => { if (ids.has(e.from)) ids.add(e.to); if (ids.has(e.to)) ids.add(e.from); });
nodeDataset.clear(); nodeDataset.add(allNodes.filter(n => ids.has(n.id)));
edgeDataset.clear(); edgeDataset.add(allEdges.filter(e => ids.has(e.from) && ids.has(e.to)));
}
network.fit({ animation: true });
}
function showInfo(nodeId) {
const node = allNodes.find(n => n.id === nodeId);
if (!node) return;
const conns = allEdges.filter(e => e.from === nodeId || e.to === nodeId);
let html = `<h3>${node.id}</h3>`;
html += `<div class="group-badge" style="background:${node.color}33; color:${node.color}; border:1px solid ${node.color}66">${node.group}</div>`;
if (node.facts && node.facts.length > 0) {
html += '<div style="margin-top:8px">';
node.facts.forEach(f => {
html += `<div class="fact-row">
<span class="fact-icon">${f.icon}</span>
<span class="fact-key">${f.key}</span>
<span class="fact-value">${f.value}</span>
</div>`;
});
html += '</div>';
}
if (conns.length > 0) {
html += '<div class="connections"><h4>Connections (' + conns.length + ')</h4>';
conns.forEach(e => {
const other = e.from === nodeId ? e.to : e.from;
const dir = e.from === nodeId ? '→' : '←';
html += `<div>${dir} <span class="conn-link" onclick="focusNode('${other}')">${other}</span> <span class="conn-pred">(${e.label})</span></div>`;
});
html += '</div>';
}
document.getElementById('infoContent').innerHTML = html;
document.getElementById('info').style.display = 'block';
}
function focusNode(nodeId) {
network.focus(nodeId, { scale: 1.5, animation: true });
network.selectNodes([nodeId]);
showInfo(nodeId);
}
document.getElementById('searchInput').addEventListener('input', function(e) {
const q = e.target.value.toLowerCase();
if (!q) {
nodeDataset.clear(); nodeDataset.add(allNodes);
edgeDataset.clear(); edgeDataset.add(allEdges);
return;
}
const matches = allNodes.filter(n => n.id.toLowerCase().includes(q));
if (matches.length > 0) {
const ids = new Set(matches.map(n => n.id));
allEdges.forEach(e => { if (ids.has(e.from)) ids.add(e.to); if (ids.has(e.to)) ids.add(e.from); });
nodeDataset.clear(); nodeDataset.add(allNodes.filter(n => ids.has(n.id)));
edgeDataset.clear(); edgeDataset.add(allEdges.filter(e => ids.has(e.from) && ids.has(e.to)));
network.fit({ animation: true });
}
});
</script>
</body>
</html>