-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
54 lines (48 loc) · 1.73 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
50
51
52
53
54
<html>
<style>
body {
margin: 0
}
</style>
<head>
<script src='//unpkg.com/3d-force-graph'></script>
</head>
<body>
<div id='graph'></div>
<script type='module'>
const Graph = ForceGraph3D()
(document.getElementById('graph'))
.jsonUrl('./data/graph/civ.json')
.nodeLabel('id')
.nodeAutoColorBy('Type')
.linkAutoColorBy('Type')
.linkLabel('Type')
.linkOpacity(0.3)
.linkDirectionalArrowLength(5)
.linkDirectionalArrowRelPos(1)
.onNodeClick(node => { // click to focus on the node
const distance = 40;
const distRatio = 1 + distance / Math.hypot(node.x, node.y, node.z);
Graph.cameraPosition(
{ x: node.x * distRatio, y: node.y * distRatio, z: node.z * distRatio },
node, 3000
)
})
.onLinkClick(link => { // click to fly to the source node
const distance = 40;
const distRatio = 1 + distance / Math.hypot(link.source.x, link.source.y, link.source.z);
Graph.cameraPosition(
{ x: link.source.x * distRatio, y: link.source.y * distRatio, z: link.source.z * distRatio },
link.source, 3000
);
});
// add effect
import { UnrealBloomPass } from '//cdn.skypack.dev/three/examples/jsm/postprocessing/UnrealBloomPass.js';
const bloomPass = new UnrealBloomPass();
bloomPass.strength = 1;
bloomPass.radius = 0.5;
bloomPass.threshold = 0.1;
Graph.postProcessingComposer().addPass(bloomPass);
</script>
</body>
</html>