-
Notifications
You must be signed in to change notification settings - Fork 0
/
KnowledgeGraph.html
77 lines (67 loc) · 2.77 KB
/
KnowledgeGraph.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Graph Visualization</title>
<script src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<input type="text" id="nodeLabelInput">
<div>
<input type="file" id="fileInput" accept=".json">
<button id="downloadButton">Download Graph Data</button>
</div>
<div>
<input type="text" id="searchInput" placeholder="Search for a node..." />
<button id="searchButton">Search</button>
</div>
<div id="mynetwork"></div>
<!-- Include External JavaScript Files -->
<script src="presentation.js"></script>
<script src="modification.js"></script>
<script src="creation.js"></script>
<script>
var network, nodes;
document.addEventListener('DOMContentLoaded', function () {
var container = document.getElementById('mynetwork');
var data = { nodes: new vis.DataSet([]), edges: new vis.DataSet([]) };
var options = {};
network = new vis.Network(container, data, options);
nodes = data.nodes;
setupEventListeners();
document.getElementById('searchButton').addEventListener('click', async function () {
var userInput = document.getElementById('searchInput').value;
var graph = exportGraphData(network)
try {
const response = await fetch('http://localhost:3000/ask', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userInput, graph })
});
const data = await response.json();
console.log(data.suggestions);
// Process the suggestions to update the graph
} catch (error) {
console.error('Failed to fetch from backend:', error);
}
});
// Setup the download functionality
document.getElementById('downloadButton').addEventListener('click', function () {
downloadGraphData(network);
});
document.getElementById('fileInput').addEventListener('change', function (event) {
var reader = new FileReader();
reader.onload = function (e) {
var contents = e.target.result;
var json = JSON.parse(contents);
initializeGraph();
processFile(json);
setupEventListeners();
};
reader.readAsText(event.target.files[0]);
});
});
</script>
</body>
</html>