-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrhizome.js
95 lines (83 loc) · 2 KB
/
rhizome.js
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
var svg = d3.select("#rhizome");
// width = +svg.attr("width"),
// height = +svg.attr("height");
var width = 5000;
var height = 5000;
var dataQuery = svg.attr("data-query");
// horrible globvar but will do until the inevitable refactoring...
var links = null;
// var color = d3.scaleOrdinal(d3.schemeCategory10);
function color(type) {
switch (type) {
case "person":
return "#f8efc6";
break;
case "group":
return "#e7eef6";
break;
case "organisation":
return "#cae9e3";
break;
default:
return "#000";
}
}
function size(type) {
switch (type) {
case "person":
return "10";
break;
default:
return "18";
}
}
function rad(type) {
switch (type) {
case "person":
return "40";
break;
default:
return "50";
}
}
function title(str) {
return str.replace(/\b\S/g, function(t) { return t.toUpperCase() });
}
var node = null;
var min_zoom = 0.1;
var max_zoom = 6;
var link_colour_default = '#999';
var link_colour_highlight = 'red';
var jsonPull = "rhizome-json.php";
if (dataQuery) {
jsonPull += "?"+dataQuery;
}
d3.json(jsonPull, function(error, graph) {
if (error) throw error;
var memberLinks = graph.links.memberOf;
var alumLinks = graph.links.alumOf;
links = d3.merge([memberLinks, alumLinks]);
const gData = {
nodes: graph.nodes,
links: links
}
const Graph = ForceGraph3D()
(document.getElementById('rhizome'))
.graphData(gData)
.nodeAutoColorBy('type')
.nodeThreeObject(node => {
// This block copied from @vasturiano's demo
// use a sphere as a drag handle
const obj = new THREE.Mesh(
new THREE.SphereGeometry(10),
new THREE.MeshBasicMaterial({ depthWrite: false, transparent: true, opacity: 0 })
);
// add text sprite as child
const sprite = new SpriteText(node.name);
sprite.color = node.color;
sprite.textHeight = 8;
obj.add(sprite);
return obj;
});;
Graph.d3Force('charge').strength(-150);
});