-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.js
191 lines (172 loc) · 5.99 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// JQuery inits
function compareEntities(a, b) {
if(a['country'] == b['country'] && a['type'] == b['type'] && a['id'] == b['id']) {
return true;
} else {
return false;
}
};
function entityInList(list, e1) {
var found = false;
list.forEach(function(e2){
if(compareEntities(e1, e2)) {
found = true;
}
});
return found;
};
function buildGraph(seed) {
seed.forEach(function(e){
if(e['type'] == 'le') {
//find all relations
related_parties = entities[e['country']][e['type']][e['id']]['persons'];
//check wether they should be added to graph
related_parties.forEach(function(rp){
if(entityInList(seed, rp)) {
seed.push(rp);
}
});
}
});
};
$(document).ready(function() {
$('#openGraph').click(function () {
$('#dialog').dialog({
height: 800,
width: '80%',
}).dialog('open');
return false;
} );
output = "";
for (var le in AT_legal_entities) {
output += AT_legal_entities[le]['name'];
}
//Create nodes for graph
nodes = [];
nodes_AT_legal_entities = Object.keys(AT_legal_entities).map(function(le) {
var e = AT_legal_entities[le];
return {id: le, group: 'lE', label: e['name'], title: e['code'] ? 'AT FN ' + e['code'] : ''};
});
nodes = nodes.concat(nodes_AT_legal_entities);
nodes_AT_natural_persons = Object.keys(AT_natural_persons).map(function(np) {
var e = AT_natural_persons[np];
return {id: np, group: 'nP', label: e['name'], title: 'AT ' + (e['birthday'] ? e['birthday'] : '')};
});
nodes = nodes.concat(nodes_AT_natural_persons);
nodes_DE_legal_entities = Object.keys(DE_legal_entities).map(function(le) {
var e = DE_legal_entities[le];
return {id: le, group: 'lE', label: e['name'], title: e['code'] ? 'DE HRB ' + e['code'] : ''};
});
nodes = nodes.concat(nodes_DE_legal_entities);
nodes_DE_natural_persons = Object.keys(DE_natural_persons).map(function(np) {
var e = DE_natural_persons[np];
return {id: np, group: 'nP', label: e['name'], title: 'DE ' + (e['birthday'] ? e['birthday'] : '')};
});
nodes = nodes.concat(nodes_DE_natural_persons);
// TODO: Take care of correct encoding of
nodes_UA_legal_entities = Object.keys(UA_legal_entities).map(function(le) {
var e = UA_legal_entities[le];
return {id: le, group: 'lE', label: e['short_name'], title: e['code'] ? 'UA ' + e['code'] : ''};
});
nodes = nodes.concat(nodes_UA_legal_entities);
nodes_UA_natural_persons = Object.keys(UA_natural_persons).map(function(np) {
var e = UA_natural_persons[np];
return {id: np, group: 'nP', label: e['name'], title: e['location'] ? e['location'] : ''};
});
nodes = nodes.concat(nodes_UA_natural_persons);
//Create edges for graph
edges = [];
edges_AT = [].concat.apply(
[],
Object.keys(AT_legal_entities).map(function(le){
e = AT_legal_entities[le];
persons = e['persons'] ? e['persons'] : [];
return persons.map(function(p){
p_new = {};
p_new['to'] = parseInt(le);
p_new['from'] = p['id'];
p_new['label'] = p['role'];
p_new['title'] = p['from'] ? 'since ' + p['from'] : '';
p_new['title'] += p['to'] ? ' until ' + p['to'] : '';
return p_new;
});
})
);
edges = edges.concat(edges_AT);
edges_DE = [].concat.apply(
[],
Object.keys(DE_legal_entities).map(function(le){
e = DE_legal_entities[le];
persons = e['persons'] ? e['persons'] : [];
return persons.map(function(p){
p_new = {};
p_new['to'] = parseInt(le);
p_new['from'] = p['id'];
p_new['label'] = p['role'];
p_new['title'] = p['from'] ? 'since ' + p['from'] : '';
p_new['title'] += p['to'] ? ' until ' + p['to'] : '';
return p_new;
});
})
);
edges = edges.concat(edges_DE);
edges_UA = [].concat.apply(
[],
Object.keys(UA_legal_entities).map(function(le){
e = UA_legal_entities[le];
persons = e['persons'] ? e['persons'] : [];
return persons.map(function(p){
p_new = {};
p_new['to'] = parseInt(le);
p_new['from'] = p['id'];
p_new['label'] = p['role'];
p_new['title'] = p['from'] ? 'since ' + p['from'] : '';
p_new['title'] += p['to'] ? ' until ' + p['to'] : '';
return p_new;
});
})
);
edges = edges.concat(edges_UA);
// provide the data in the vis format
data = {
nodes: new vis.DataSet(nodes),
edges: new vis.DataSet(edges),
};
var options = {
groups: {
nP: {
color: {background: 'black'},
borderWidth: 3,
shape: 'icon',
icon: {
face: 'FontAwesome',
code: '\uf007',
size: 50,
color: 'black',
},
},
lE: {
color: {background: 'white', border: 'blue'},
borderWidth: 3,
},
further: {
color: {background: 'red', border: 'black'},
shape: 'diamond',
label: 'more',
},
test: {
color: 'red',
},
},
edges: {
arrows: 'to',
},
layout: {
hierarchical: false,
improvedLayout: true,
},
};
var container = document.getElementById('relationship_graph');
var network = new vis.Network(container, data, options);
network.fit();
});