This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathNetwork.vue
81 lines (77 loc) · 1.76 KB
/
Network.vue
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
<script>
import vis from 'vis';
export default {
name: 'non-vue-network',
render (h) {
return h('div', {
attrs: {
class: 'container'
}
})
},
props: ['dataPromise'],
mounted() {
Promise.all(this.dataPromise).then(data => {
let graph_roots = data.map(function (i) {
return i.result.graph_roots;
});
// Flatten array (made like list comprehension)
graph_roots = graph_roots.flat();
let pkgs = data.map(function (i) {
return i.result.pkgs;
});
// Idem
pkgs = pkgs.flat();
// Filter out duplicate dependencies (by name)
let uniqDeps = pkgs.filter((v, i, a) =>
a.findIndex(t => (t.name === v.name)) === i);
return {'graph_roots': graph_roots, 'pkgs': uniqDeps};
})
.then(data => {
let nodes = [];
let edges = [];
let pkgGroup = [];
for (let pkg of data.pkgs)
{
if (data.graph_roots.includes(pkg.name)) {
pkgGroup = 'roots';
} else {
pkgGroup = 'higher-order';
}
nodes.push({id: pkg.name, label: pkg.name, group: pkgGroup});
if (pkg.depends)
{
for (let dep of pkg.depends)
{
edges.push({from: pkg.name, to: dep.split(" ")[0]})
}
}
}
var container = this.$el;
var graphData = {
nodes: nodes,
edges: edges
};
var options = {
autoResize: true,
edges: {
arrows: 'to'
},
groups: {
roots: {color: 'pink'}
},
layout: {
randomSeed: 123
}
};
new vis.Network(container, graphData, options);
});
},
};
</script>
<style>
.container {
height: 70vh;
width: 100%;
}
</style>