-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.html
49 lines (42 loc) · 1.35 KB
/
index.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
<head>
<style> body { margin: 0; } </style>
<script src="//unpkg.com/aframe"></script>
<script src="//unpkg.com/@ar-js-org/ar.js"></script>
<script src="//unpkg.com/3d-force-graph-ar"></script>
<!--<script src="../../dist/3d-force-graph-ar.js"></script>-->
</head>
<body>
<div id="3d-graph"></div>
<script>
const initData = {
nodes: [ {id: 0 } ],
links: []
};
const Graph = ForceGraphAR()
(document.getElementById("3d-graph"))
.graphData(initData)
.nodeRelSize(10)
.linkWidth(3)
.nodeOpacity(0.9)
.linkOpacity(0.4)
.nodeColor(() => 'firebrick')
.linkColor(() => 'darkgrey')
.onNodeClick(removeNode);
setInterval(() => {
const { nodes, links } = Graph.graphData();
const id = nodes.length;
Graph.graphData({
nodes: [...nodes, { id }],
links: [...links, { source: id, target: Math.round(Math.random() * (id-1)) }]
});
}, 1000);
//
function removeNode(node) {
let { nodes, links } = Graph.graphData();
links = links.filter(l => l.source !== node && l.target !== node); // Remove links attached to node
nodes.splice(node.id, 1); // Remove node
nodes.forEach((n, idx) => { n.id = idx; }); // Reset node ids to array index
Graph.graphData({ nodes, links });
}
</script>
</body>