forked from KusaReMKN/mantela-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmantela.js
85 lines (75 loc) · 2.05 KB
/
mantela.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
'use strict';
const nodes = [];
const edges = [];
async function
main(first)
{
if (!first)
return;
const queue = [ first ];
const visited = [];
while (queue.length > 0) {
try {
const cur = queue.shift();
const k = await (await fetch(cur, { mode: 'cors' })).json();
const me = {
id: k.aboutMe.identifier,
label: k.aboutMe.name,
};
if (!nodes.some(q => q.id === me.id)) {
nodes.push(me);
}
if (visited.some(e => e === me.id))
continue;
visited.push(me.id);
k.extensions.forEach(e => {
const node = {
id: me.id + Math.random(),
label: e.name,
color: 'orange',
};
nodes.push(node);
const edge = {
from: me.id,
to: node.id,
label: e.extension,
};
edges.push(edge);
});
k.providers.forEach(e => {
if (!nodes.some(q => q.id === e.identifier)) {
const node = {
id: e.identifier,
label: e.name,
};
nodes.push(node);
}
const edge = {
from: me.id,
to: e.identifier,
label: e.prefix,
};
edges.push(edge);
queue.push(e.mantela);
});
} catch (e) {
console.error(e)
}
}
const container = document.getElementById('mandala');
const data = {
nodes: nodes,
edges: edges,
};
const options = {
edges: {
arrows: 'to',
},
};
new vis.Network(container, data, options);
}
const q = (new URLSearchParams(document.location.search)).get('first');
if (q) {
first.value = q;
main(first.value);
}