forked from island99/Visual-Knowledge-Graph-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
526 lines (443 loc) · 15.5 KB
/
index.html
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<title>Knowledge Base</title>
<style type="text/css">
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
}
#property {
width: 94%;
height: 29%;
}
#proul {
height: 100%;
overflow-y: auto;
overflow-x: hidden;
}
#proul::-webkit-scrollbar {
width: 4px;
/*height: 4px;*/
}
#proul::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 5px rgba(255, 255, 255, 0.9);
background: rgba(255, 255, 255, 0.1);
}
#proul::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 5px rgba(255, 255, 255, 0.9);
border-radius: 0;
background: rgba(255, 255, 255, 0.1);
}
.autocomplete-suggestions {
max-height: 200px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
border: 1px solid #999;
background: #efefef;
cursor: default;
overflow: auto;
-webkit-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
-moz-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
}
.autocomplete-suggestion {
padding: 2px 5px;
white-space: nowrap;
overflow: hidden;
}
.autocomplete-no-suggestion {
padding: 2px 5px;
}
.autocomplete-selected {
background: #efefef;
}
.autocomplete-suggestions strong {
font-weight: bold;
color: #000;
}
.autocomplete-group {
padding: 2px 5px;
}
.autocomplete-group strong {
font-weight: bold;
font-size: 16px;
color: #000;
display: block;
border-bottom: 1px solid #000;
}
#input_div {
padding: 2% 2% 2% 2%;
text-align: center;
font-size: 16px;
}
input,
input:focus {
outline: medium;
text-align: center;
margin: auto;
line-height: 40px;
width: 40%;
background: #efefef;
border-radius: 40px;
border: none;
}
.btn {
width: 8%;
}
.sidebar {
padding-left: 1%;
color: #eee;
width: 24%;
position: absolute;
left: 0;
top: 8%;
height: 92%;
transition: all 0.2s ease 0s;
background-color: #0b2838;
}
.sidebar ul {
font-size: small;
}
.main {
background-color: #0b2838;
overflow: hidden;
position: absolute;
left: 25%;
right: 0;
top: 8%;
height: 92%;
transition: all 0.2s ease 0s;
}
.big-page .sidebar {
left: -25%;
}
.big-page .main {
left: 0;
}
#banner {
color: #fff;
width: 100%;
background: #0d1c25;
height: 8%;
display: block;
opacity: 0.85;
}
canvas {
background-color: #0b2838;
}
.link {
margin-top: 10px;
display: inline-block;
overflow: hidden;
}
.link button {
font-size: 16px;
padding: 10px 10px;
border: 2px solid transparent;
background-color: #0d1c25;
}
.entity_btn,
.rela_btn,
.entity_rela_btn,
.banner_btn {
width: 30%;
border-radius: 5px;
color: #efefef;
padding: 8px 20px;
margin: 8px 5px;
background-color: #0b2838;
text-decoration: none;
border: 2px solid transparent;
cursor: pointer
}
.banner_btn {
width: 120px;
display: inline-block;
font-weight: bolder;
}
.selected {
margin: 10px;
border-color: #eee !important;
/* background-color: "#eee"; */
}
</style>
</head>
<body>
<script type="text/javascript" src="js/src/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/src/g6.min.js"></script>
<script type="text/javascript" src="js/src/axios.min.js"></script>
<script type="text/javascript" src="js/src/jquery.autocomplete.js"></script>
<script type="text/javascript" src="js/formattrans.js"></script>
<!-- /* 图的画布容器 */ -->
<div id="banner">
<!-- <h1>攻击工具知识图谱</h1> -->
<div class="link">
<button class="banner_btn selected" id="side_change">Sidebar</button>
</div>
</div>
<div>
<div id='slider' class="sidebar">
<!-- <div id='entity'>
<h4>主要实体类型查询</h4>
</div> -->
<div id='entity'>
<h3>Node Labels</h3>
</div>
<div id="entity_rela">
<h3>Relationships of Nodes </h3>
</div>
<div id='relation'>
<h3>Relationship Types</h3>
</div>
<div id="property">
<h3>Show Properties</h3>
<div id="proul">
</div>
</div>
</div>
<div class="main">
<div id="input_div">
<input type="text" placeholder="Please enter key words..." name="country" id="autocomplete" />
</div>
<div id="mountNode"></div>
</div>
</div>
<script>
const config = {
ip: 'http://' + window.location.hostname.toString(),
port: 3000,
}
// console.log(config)
const color_set = ["#dd6b66",
"#759aa0",
"#e69d87",
"#8dc1a9",
"#ea7e53",
"#eedd78",
"#73a373",
"#73b9bc",
"#7289ab",
"#91ca8c",
"#f49f42"
]
// autocomplete
window.onload = async function() {
const person_info = {
category: 'Person',
search_type: 'name',
}
const movie_info = {
category: 'Movie',
search_type: 'title',
}
const Person_Teams = await getData(`MATCH (n:${person_info.category}) RETURN n.${person_info.search_type}`);
const Movie_Teams = await getData(`MATCH (n:${movie_info.category}) RETURN n.${movie_info.search_type}`);
var p = $.map(Person_Teams, function(team) {
return {
value: team,
data: person_info
};
});
var m = $.map(Movie_Teams, function(team) {
return {
value: team,
data: movie_info
};
});
var teams = p.concat(m);
// Initialize autocomplete with local lookup:
$('#autocomplete').devbridgeAutocomplete({
lookup: teams,
minChars: 1,
onSelect: function(suggestion) {
console.log(suggestion.data);
readNeo4j(suggestion, 3);
},
showNoSuggestionNotice: true,
noSuggestionNotice: 'Sorry.. Try other keywords...',
groupBy: 'category'
});
var entity_list = await getData(`MATCH(n) RETURN distinct labels(n), count(n)`);
var rela_list = await getData(`MATCH p=()-[r]->() RETURN distinct type(r), count(r)`);
// console.log(entity_list);
for (let entity in entity_list) {
$('#entity').append(`<button class="entity_btn" onclick="readNeo4j(this,0)" name='${entity_list[entity][0]}'><b>${entity_list[entity][0]}</b> (${entity_list[entity][1]})</button>`);
$('#entity_rela').append(`<button class="entity_rela_btn" onclick="readNeo4j(this,1)" name='${entity_list[entity][0]}'><b>${entity_list[entity][0]}</b> (${entity_list[entity][1]})</button>`);
}
for (let relation in rela_list) {
$('#relation').append(`<button class="rela_btn" onclick="readNeo4j(this,4)" name='${rela_list[relation][0]}'><b>${rela_list[relation][0]}</b> (${rela_list[relation][1]})</button>`);
}
};
function readNeo4j(node, mode) {
console.log(node);
// show entities
if (mode == 0) {
console.log(node);
var q = `MATCH p=(n:${node.name}) RETURN n,labels(n) LIMIT 100`;
// show relationships of entity
} else if (mode == 1) {
var q = `MATCH p=(n:${node.name})-[a]-(x) RETURN n,labels(n),a,type(a),x,labels(x) LIMIT 100`;
// show relationships
} else if (mode == 4) {
var q = `MATCH p=(n)-[r:${node.name}]->(x) RETURN n,labels(n),r,type(r),x,labels(x) LIMIT 25`;
// Doble click to expand
} else if (mode == 2) {
var q = `MATCH (n)-[a]-(x) WHERE id(n)=${node.id} RETURN n,labels(n),a,type(a),x,labels(x) LIMIT 100`;
$('#autocomplete').val(node.label);
//Search from Search Box
} else if (mode == 3) {
var q = `MATCH (n:${node.data.category}{${node.data.search_type}:'${node.value}'})-[a]-(x) RETURN n,labels(n),a,type(a),x,labels(x)`;
// console.log(q);
$('#autocomplete').val(node.value);
}
return new Promise((resolve, reject) => {
// console.log(`${config.ip}:${config.port}/all`);
axios.get(`${config.ip}:${config.port}/all`, {
params: {
query: q
}
}).then(res => {
console.log(res.data)
content = nodesFoldToD3(res.data);
// console.log(content)
content = JSON.parse(content);
var data = content;
// console.log(data);
changeStyle(data)
graph.data(data);
graph.render();
// console.log(content);
}).catch(err => {
console.log(err)
})
});
}
function toggleSidebar() {
$("body").toggleClass("big-page");
var obj = this;
$(obj).toggleClass("selected");
return false;
}
$("#side_change").click(toggleSidebar);
async function getFromNeo4j(para) {
return await axios.get(`${config.ip}:${config.port}/all?query=${para}`)
}
async function getData(para) {
let neo4jData = await getFromNeo4j(para);
return neo4jData.data.data
// return group_Teams
}
</script>
<script>
// G6 action
G6.registerBehavior('node-activate', {
getDefaultCfg() {
return {
multiple: true
};
},
getEvents() {
return {
'node:mouseenter': 'onMouseenter',
'node:dblclick': 'onDblclick'
};
},
onMouseenter(e) {
$('#proul').children().remove();
var pros = $.extend({}, e.item.getModel().properties);
for (var p in pros) {
$('#proul').append(
'<ul class="pro_slider"><li><b>' + p + ' : </b> ' + pros[p] + '</li>')
};
},
onDblclick(e) {
readNeo4j(e.item.getModel(), 2)
// console.log(e.item.getModel());
}
});
const graph = new G6.Graph({
container: 'mountNode',
width: window.screen.availWidth,
height: document.body.clientHeight,
modes: {
default: ['drag-node', 'node-activate'],
},
layout: {
type: 'force',
center: [window.screen.availWidth * 0.45, document.body.clientHeight * 0.4],
preventOverlap: true,
linkDistance: 180,
},
defaultNode: {
size: 28,
color: '#5B8FF9',
style: {
lineWidth: 2,
fill: '',
stroke: '',
},
label: 'node-label',
labelCfg: {
position: 'top',
style: {
fill: '#ddd',
},
}
},
defaultEdge: {
size: 1,
color: '#aaa',
label: 'node-label',
labelCfg: {
style: {
fill: '#ddd',
stroke: '',
},
},
}
});
function changeStyle(data) {
const nodes = data.nodes;
nodes.forEach((node) => {
if (!node.style) {
node.style = {};
}
node.style = {
fill: color_set[node.id % color_set.length],
stroke: '',
};
switch (
node.properties.type // Configure the graph based on the 'type' of nodes
) {
case ('Person'):
{
node.size = 32;
break;
}
}
});
}
function refreshDragedNodePosition(e) {
const model = e.item.get('model');
model.fx = e.x;
model.fy = e.y;
}
graph.on('node:dragstart', (e) => {
graph.layout();
refreshDragedNodePosition(e);
});
graph.on('node:drag', (e) => {
refreshDragedNodePosition(e);
});
</script>
</body>
</html>