-
Notifications
You must be signed in to change notification settings - Fork 851
/
Copy pathindex.html
57 lines (46 loc) · 1.56 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
55
56
57
<head>
<style> body { margin: 0; } </style>
<script src="//unpkg.com/3d-force-graph"></script>
<!-- <script src="../../dist/3d-force-graph.js"></script> -->
</head>
<body>
<div id="3d-graph"></div>
<script type="module">
import { GUI } from 'https://esm.sh/dat.gui';
// Create Random tree
const N = 20;
const gData = {
nodes: [...Array(N).keys()].map(i => ({ id: i })),
links: [...Array(N).keys()]
.filter(id => id)
.map(id => ({
source: id,
target: Math.round(Math.random() * (id-1)),
color: id % 2
}))
};
const graph = new ForceGraph3D(document.getElementById('3d-graph'))
.nodeLabel(node => node.id)
.linkColor(link => link.color ? 'red' : 'green' )
.linkOpacity(1)
.graphData(gData);
const linkForce = graph
.d3Force('link')
.distance(link => link.color ? settings.redDistance : settings.greenDistance);
//Define GUI
const Settings = function() {
this.redDistance = 20;
this.greenDistance = 20;
};
const settings = new Settings();
const gui = new GUI();
const controllerOne = gui.add(settings, 'redDistance', 0, 100);
const controllerTwo = gui.add(settings, 'greenDistance', 0, 100);
controllerOne.onChange(updateLinkDistance);
controllerTwo.onChange(updateLinkDistance);
function updateLinkDistance() {
linkForce.distance(link => link.color ? settings.redDistance : settings.greenDistance);
graph.numDimensions(3); // Re-heat simulation
}
</script>
</body>