-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.js
79 lines (65 loc) · 2 KB
/
graph.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
(async function () {
const getData = async () => {
const response = await fetch('data/pages.jsonl');
if (!response.ok) throw new Error(`failed to fetch pages with status ${response.status}`);
const text = await response.text();
const jsonStrs = text.split('\n');
const nodes = [];
const edges = [];
jsonStrs.forEach(str => {
if (str.length > 1) {
const page = JSON.parse(str);
nodes.push({ id: page.id, label: page.url });
for (const outId in page.outPages.internal) {
edges.push({ source: page.id, target: outId });
}
}
});
return {
nodes,
edges
};
};
const data = await getData();
cytoscape({
container: document.getElementById('graph'),
elements: {
nodes: data.nodes.map(node => {
return { data: node }
}),
edges: data.edges.map(edge => {
return { data: { id: edge.source + edge.target, source: edge.source, target: edge.target } }
})
},
layout: {
name: 'concentric',
concentric: function( node ){
return node.degree();
},
levelWidth: function( nodes ){
return 25;
}
},
style: [
{
selector: 'node',
style: {
'content': 'data(label)',
'height': 20,
'width': 20,
'background-color': '#30c9bc'
}
},
{
selector: 'edge',
style: {
'curve-style': 'haystack',
'haystack-radius': 0,
'width': 5,
'opacity': 0.5,
'line-color': '#a8eae5'
}
}
],
});
})();