-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryVisualizer.html
More file actions
172 lines (158 loc) · 5.36 KB
/
Copy pathMemoryVisualizer.html
File metadata and controls
172 lines (158 loc) · 5.36 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
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Byte's Memory Graph</title>
<!-- Use vis-network for graph visualization -->
<script type="text/javascript" src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
<style>
body {
font-family: 'Inter', -apple-system, sans-serif;
background-color: #121212;
color: #ffffff;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
height: 100vh;
}
#header {
padding: 20px;
background-color: #1e1e1e;
box-shadow: 0 4px 6px rgba(0,0,0,0.3);
z-index: 10;
display: flex;
justify-content: space-between;
align-items: center;
}
h1 {
margin: 0;
font-size: 1.5rem;
color: #00e676;
}
.instructions {
font-size: 0.9rem;
color: #aaaaaa;
margin-top: 5px;
}
input[type="file"] {
background: #333;
padding: 10px;
border-radius: 8px;
border: 1px solid #555;
color: white;
cursor: pointer;
}
#mynetwork {
flex-grow: 1;
width: 100%;
height: 100%;
background-color: #000000;
}
/* Custom scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #121212; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
</style>
</head>
<body>
<div id="header">
<div>
<h1>Byte's Memory Graph Visualizer</h1>
<div class="instructions">Select the <b>memory_graph.json</b> file (located in ~/Documents/DesktopPet/memory_graph.json)</div>
</div>
<input type="file" id="fileInput" accept=".json" />
</div>
<div id="mynetwork"></div>
<script type="text/javascript">
// Create an empty network
var container = document.getElementById('mynetwork');
var nodes = new vis.DataSet([]);
var edges = new vis.DataSet([]);
var data = { nodes: nodes, edges: edges };
var options = {
nodes: {
shape: 'dot',
size: 20,
font: {
size: 16,
color: '#ffffff',
face: 'Inter, sans-serif'
},
borderWidth: 2,
color: {
background: '#1f2937',
border: '#00e676',
highlight: { background: '#00e676', border: '#ffffff' }
}
},
edges: {
width: 2,
font: {
size: 12,
color: '#aaaaaa',
align: 'middle'
},
color: { color: '#555555', highlight: '#00e676' },
arrows: {
to: { enabled: true, scaleFactor: 0.5 }
},
smooth: { type: 'continuous' }
},
physics: {
barnesHut: { gravitationalConstant: -30000, centralGravity: 0.3, springLength: 150 },
stabilization: { iterations: 200 }
}
};
var network = new vis.Network(container, data, options);
// Handle File Upload
document.getElementById('fileInput').addEventListener('change', function(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
try {
const facts = JSON.parse(e.target.result);
processGraphData(facts);
} catch (err) {
alert("Error parsing JSON. Make sure it is the correct memory_graph.json file.");
console.error(err);
}
};
reader.readAsText(file);
});
function processGraphData(facts) {
nodes.clear();
edges.clear();
let nodeSet = new Set();
let newNodes = [];
let newEdges = [];
facts.forEach(fact => {
let subject = fact.subject;
let object = fact.object;
let predicate = fact.predicate;
// Add unique nodes
if (!nodeSet.has(subject)) {
nodeSet.add(subject);
let color = subject.toLowerCase() === 'rule' ? '#ef4444' : '#3b82f6';
newNodes.push({ id: subject, label: subject, color: { background: color, border: '#ffffff' } });
}
if (!nodeSet.has(object)) {
nodeSet.add(object);
newNodes.push({ id: object, label: object });
}
// Add edge
newEdges.push({
from: subject,
to: object,
label: predicate
});
});
nodes.add(newNodes);
edges.add(newEdges);
network.fit();
}
</script>
</body>
</html>