-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphGroup.js
More file actions
44 lines (41 loc) · 1.02 KB
/
GraphGroup.js
File metadata and controls
44 lines (41 loc) · 1.02 KB
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
class GraphGroup {
constructor() {
this.nodes = [];
}
resolve(nodesByLabel) {
for (let label of this.nodeLabels.values()) {
for (let node of nodesByLabel.get(label)) {
this.nodes.push(node);
node.groups.add(this);
}
}
}
setPageRank() {
// All members of a group get the rank of the maximum member, so the
// initial positions will put them all near each other
let maxRank = 0;
for (let node of this.nodes) {
maxRank = Math.max(maxRank, node.pageRank);
}
for (let node of this.nodes) {
node.pageRank = maxRank;
}
}
static process(item) {
let group = new GraphGroup();
group.id = item.id;
group.label = item.label;
group.labelId = item.labelObj ? item.labelObj.id : null;
group.nodeLabels = new Set();
for (let member of item.members) {
if (member.label == '') {
continue;
}
group.nodeLabels.add(member.label);
}
if (group.nodeLabels.size == 0) {
return null;
}
return group;
}
}