-
Notifications
You must be signed in to change notification settings - Fork 0
/
3dGraph.html
81 lines (76 loc) · 3.31 KB
/
3dGraph.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
78
79
80
81
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Digital Viez - ViezKorpus als Netzwerk</title>
<!-- Favicon-->
<link rel="icon" type="image/x-icon" href="assets/img/icons/faviconOrange/original-orange.png" />
<link rel="apple-touch-icon" sizes="180x180" href="assets/img/icons/faviconOrange/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="assets/img/icons/faviconOrange/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="assets/img/icons/faviconOrange/favicon-16x16.png">
<!-- JS Packages -->
<script src="//unpkg.com/three"></script>
<script src="//unpkg.com/three-spritetext"></script>
<script src="//unpkg.com/3d-force-graph"></script>
<link href="css/styles.css" rel="stylesheet" />
</head>
<body>
<div id="3d-graph"></div>
<div style="position: absolute;
top: 0;
right: 0;
padding: 10px;">
<label for="selectMenu"></label><select id="selectMenu" class="btn btn-primary" onchange = "displayGraph()">
<option value="Erzaehlung" selected="selected">Erzählungen und Interviews</option>
<option value="Etymologie">Etymologie</option>
<option value="Geschichte">Geschichte</option>
<option value="Herstellung">Herstellung und Obstanbau</option>
<option value="Porz">Porz</option>
<option value="Poesie">Poesie</option>
<option value="Suche">Suchanfrage „Viez“</option>
<option value="Sonstiges">Sonstiges</option>
</select>
</div>
<script>
const displayGraph = () => {
let selected = document.getElementById('selectMenu').selectedIndex;
let subCorpus = (document.getElementsByTagName('option')[selected].value);
let toggleFilter = false
const Graph = ForceGraph3D({ rendererConfig: { antialias: true }})
(document.getElementById('3d-graph'))
Graph.renderer().setPixelRatio(window.devicePixelRatio)
Graph.backgroundColor('#f8f9fa')
Graph.jsonUrl('json/'+subCorpus+'.json')
Graph.showNavInfo(false)
Graph.nodeLabel('')
Graph.nodeThreeObject(node => {
const sprite = new SpriteText(node.name);
sprite.material.depthWrite = false;
sprite.color = node.group;
sprite.textHeight = 1.5*parseFloat(node.val);
return sprite;
})
Graph.linkColor(link => link.group)
Graph.linkWidth("weight")
Graph.linkOpacity(0.2)
Graph.onNodeClick(node => {
if (toggleFilter) {
Graph.nodeVisibility(true)
Graph.linkVisibility(true)
} else {
const color = node.group;
const{ nodes, links } = Graph.graphData();
let filteredNodes = nodes.filter(n => n.group === color);
let filteredLinks = links.filter(l => l.group === color);
Graph.nodeVisibility(node => filteredNodes.some(el => el === node));
Graph.linkVisibility(link => filteredLinks.some(el => (el.source === link.source && el.target === link.target)))
}
toggleFilter = !toggleFilter;
});
// Spread nodes a little wider
Graph.d3Force('charge').strength(-380);
}
displayGraph('Erzaehlung')
</script>
</body>
</html>