forked from rwth-acis/OCD-Web-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cover.html
1186 lines (1133 loc) · 63.5 KB
/
cover.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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!-- Displays detailed information on a single cover. Allows OCD metric execution. -->
<html>
<head>
<title>OCD - Cover</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="CSS/layout.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//npmcdn.com/[email protected]/dist/js/tether.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="JS/contentHandler.js"></script>
<script src="node_modules/js-base64/base64.js"></script>
<script src="JS/ServiceAPI/moduleHelper.js"></script>
<script src="JS/ServiceAPI/serviceAPI.js"></script>
<script src="JS/requestHandler.js"></script>
<script src="JS/coverTableHandler.js"></script>
<script src="node_modules/tablesorter/dist/js/jquery.tablesorter.min.js"></script>
<script src="node_modules/jquery.panzoom/dist/jquery.panzoom.min.js"></script>
<script src="node_modules/jquery.mousewheel/jquery.mousewheel.js"></script>
<script src="node_modules/three/build/three.min.js"></script>
<script src="node_modules/force-graph/dist/force-graph.min.js"></script>
<script src="node_modules/3d-force-graph/dist/3d-force-graph.min.js"></script>
<script src="node_modules/three/examples/js/renderers/CSS2DRenderer.js"></script>
<script src="node_modules/arangojs/lib/web.js"></script>
<script src="node_modules/file-saver/dist/FileSaver.min.js"></script>
<script type="text/javascript">
/* Id of the corresponding graph */
var graphId = getUrlVar("graphId");
/* Id of the cover */
var coverId = getUrlVar("coverId");
/* Meta Data Xml */
var coverMetaXml;
/* Meta Data Xmls of corresponding ground truth candidates (for metric execution) */
var groundTruthMetasXml;
// var coverDefaultXml;
/* Graph structure in JSON format */
var jsonGraph;
var forceGraph;
var have3D;
var haveNodeNames = false;
var nodeName = "";
var keysPressed = new Map();
var rightClickLink = null;
/* Database Information */
var arangoUser = localStorage.getItem("arangoUser@WebOCD");
var arangoPass = localStorage.getItem("arangoPass@WebOCD");
var arangoDataBase = localStorage.getItem("arangoDataBase@WebOCD");
var arangoCollection = localStorage.getItem("arangoCollection@WebOCD");
//Testserver: http://ocd-web-client.duckdns.org:7071
//Server ginkgo from rwth: http://ginkgo.informatik.rwth-aachen.de:8529
const db = new arangojs.Database('http://127.0.0.1:8529');
/* SVG for Visualization */
var visualization;
/* Maximum ground truth candidates (for metric execution) displayed per page */
var COVERS_PER_PAGE = 20;
/* Current page of ground truth candidates (for metric execution) */
var pageNumber = 0;
/* Default select option value */
var selectOptionVal = "SELECT";
/* Default select option code */
var selectOptionStr = '<option value=' + selectOptionVal + '>--SELECT--</option>';
/* Metric names */
var metricNames;
$(document).ready(function() {
/* Identifiers for meta information to be displayed */
var cells = ["Name", "Graph", "CreationMethod", "Communities", "R", ".xml", ".txt"];
/* Requests cover meta information */
sendRequest("get", "covers/" + coverId + "/graphs/" + graphId + "?outputFormat=META_XML", "",
/* Response handler */
function(response) {
/*
* Init meta table
*/
coverMetaXml = response;
appendCoverRow($('#coverMetaTable'), coverMetaXml, cells);
/*
* Init run metric collapsable
*/
$("#metricType").append(
selectOptionStr
+ '<option value="statistical">Statistical Measure</option>'
+ '<option value="knowledgedriven">Knowledge Driven Measure</option>'
);
/*
* Init metrics table
*/
$(coverMetaXml).find("Metric").each(function() {
var name = $(this).find('Type');
name = name.attr("displayName");
var status = $(this).find('Status').text();
if(status === 'COMPLETED') {
status = '<img class="icon" src="IMG/open-iconic/svg/check.svg" alt="y">';
}
else {
status = '<img class="icon" src="IMG/open-iconic/svg/x.svg" alt="y">';
}
var value = parseFloat($(this).find('Value').text());
value = value.toFixed(4);
/* Create table row */
var row = '<tr>'
+ '<td>' + name + '</td>'
+ '<td>' + status + '</td>'
+ '<td>' + value + '</td>'
+ '</tr>';
$("#metricsTable tbody").append(row);
});
/*
* Register events/components
*/
registerCoverTable("#coverMetaTable");
//registerCollapsable("#metricsCollapsable", metricsCollapsableHandler);
registerCollapsable("#metricsCollapsable");
registerCollapsable("#visualizationCollapsable", visualizationCollapsableHandler);
registerCollapsable("#runMetricCollapsable");
registerParameterSelect("#metric", "#metricParameterRow", getMetricParameters);
},
/* Error handler */
function(errorData) {
/*
* Cover request failed
*/
showConnectionErrorMessage("Cover was not received.", errorData);
}, "text");
/*
* Submit listener for the run metric form.
*/
$('#runMetricForm').submit(function(){
if($("#metricType").val() === selectOptionVal) {
showErrorMessage('Please select a metric type.');
return;
}
else if($("#metric").val() === selectOptionVal) {
showErrorMessage('Please select a metric.');
return;
}
if($("#metricType").val() === "knowledgedriven") {
var coverId = $("input[name='coverSelect']:checked").val();
if(typeof coverId === 'undefined') {
showErrorMessage('Please select a ground truth cover.');
return;
}
/* Request knowledge driven measure execution */
else {
runKnowledgeDrivenMeasure();
}
}
else if($("#metricType").val() === "statistical") {
/* Request statistical measure execution */
runStatisticalMeasure();
}
else {
/* Should not happen */
buttonSubmitEnd("runMetricBtn");
showErrorMessage('Client Error.');
return;
}
});
/*
* Change listener for the metric type in the run metric form.
* Executed when a new metric type is selected.
*/
$("#metricType").change(function() {
$("#metric").empty();
/* Hides ground truth covers */
$(".selectorWrapper").css("display", "none");
$("#metricType option:selected").each(function() {
/* A real metric (i.e. not the default option) is selected */
if($(this).val() !== selectOptionVal) {
getMetrics(function() {
$("#metric").append(selectOptionStr);
$(metricNames).find('Name').each(function() {
$("#metric").append(
'<option value="' + $(this).text()
+ '">' + $(this).attr("displayName") + '</option>');
});
});
if($(this).val() === "knowledgedriven") {
/* Displays ground truth covers */
loadCoverTable();
$(".selectorWrapper").css("display", "block");
}
else if($(this).val() === "statistical") {
}
else {
showErrorMessage("Client Error");
}
$("#objectCreatorRow").css("display", "table-row");
}
else {
$("#objectCreatorRow").css("display", "none");
}
$("#metricParameterRow").empty();
});
});
});
/* Requests the execution of a knowledge driven measure */
function runKnowledgeDrivenMeasure() {
var groundTruthId = $("input[name='coverSelect']:checked").val();
var params = getParameterXml("#metricParams");
buttonSubmitStart("runMetricBtn");
sendRequest("post", "covers/" + coverId + "/graphs/" + graphId +
"/metrics/knowledgedriven/groundtruth/"
+ groundTruthId + "?metricType=" + $('#metric').val(), params,
/* Response handler */
function(response) {
window.location.href = "index.html";
},
/* Error handler */
function(errorData) {
/*
* Run metric request failed
*/
buttonSubmitEnd("runMetricBtn");
showConnectionErrorMessage("Metric request failed.", errorData);
});
}
/* Requests the execution of a statistical measure */
function runStatisticalMeasure() {
var params = getParameterXml("#metricParams");
buttonSubmitStart("runMetricBtn");
sendRequest("post", "covers/" + coverId + "/graphs/" + graphId
+ "/metrics/statistical?metricType=" + $('#metric').val()
, params,
/* Response handler */
function(response) {
window.location.href = "index.html";
},
/* Error handler */
function(errorData) {
/*
* Run metric request failed
*/
buttonSubmitEnd("runMetricBtn");
showConnectionErrorMessage("Metric request failed.", errorData);
});
}
/* Requests and stores the names of the parameters of a given metric
* Then executes a callback function */
function getMetricParameters(metricName, callback) {
sendRequest("get", "metrics/" + metricName + "/parameters/default", "",
/* Response handler */
function(response) {
if(typeof callback !== 'undefined') {
callback(response);
}
},
/* Error handler */
function(errorData) {
/*
* GraphIds request failed
*/
showConnectionErrorMessage("Metric parameters were not received.", errorData);
});
}
/* Requests and stores the names of all metrics (of a certain metric type)
* Then executes a callback function */
function getMetrics(callback) {
sendRequest("get", "metrics/" + $("#metricType").val(), "",
/* Response handler */
function(response) {
metricNames = response;
if(typeof callback !== 'undefined') {
callback();
}
},
/* Error handler */
function(errorData) {
/*
* Request failed
*/
showConnectionErrorMessage("Metric names were not received.", errorData);
});
}
/* Requests a potential ground truth covers and adds them to a table */
function loadCoverTable() {
/* Initializes table */
$('#coverTable tbody').empty();
$('.pageNumWrapper').empty();
$('.pageNumWrapper').append(pageNumber);
var firstIndex = COVERS_PER_PAGE * pageNumber;
/* Identifiers of the information to be displayed */
var cells = ["Name", "Graph", "CreationMethod", "Communities", "C", "Select"];
/* Requests the covers */
sendRequest("get", "covers?graphId=" + graphId + "&executionStatuses=COMPLETED&includeMeta=TRUE&firstIndex=" + firstIndex + "&length=" + COVERS_PER_PAGE , "",
/* Response handler */
function(groundTruthMetasXml) {
/*
* CoverMetas request succeeded
*/
if($(groundTruthMetasXml).find("Id").length === 0 && pageNumber > 0) {
pageNumber--;
loadCoverTable();
}
/* Adds each cover to the table */
$(groundTruthMetasXml).find("Cover").each(function() {
appendCoverRow($('#coverTable'), $(this), cells);
});
/*
* Sort Table
*/
try {
$("#coverTable").tablesorter({sortList: [[0,0]],
headers: { 6: {sorter: false}, 7: {sorter: false}}});
} catch(err) { /* table empty */ }
registerCoverTable("#coverTable");
},
/* Error handler */
function(errorData) {
/*
* Ground truth cover request failed
*/
showConnectionErrorMessage("Ground truth cover metas were not received.", errorData);
});
/* Listener to show the next page of ground truth covers */
$('.pageLeft').click(function(){
if(pageNumber > 0) {
pageNumber--;
loadCoverTable();
}
});
/* Listener to show the previous page of ground truth covers */
$('.pageRight').click(function(){
pageNumber++;
loadCoverTable();
});
}
// function metricsCollapsableHandler() {
// if(typeof coverDefaultXml === 'undefined') {
// getDefaultXml(function() {
// /*
// * Init metrics table
// */
// $(coverDefaultXml).find("Metric").each(function() {
// var name = $(this).find('Type');
// name = name.attr("displayName");
// var status = $(this).find('Status').text();
// if(status === 'COMPLETED') {
// status = '<img class="icon" src="IMG/open-iconic/svg/check.svg" alt="y">';
// }
// else {
// status = '<img class="icon" src="IMG/open-iconic/svg/x.svg" alt="y">';
// }
// var value = parseFloat($(this).find('Value').text());
// value = value.toFixed(4);
// var row = '<tr>'
// + '<td>' + name + '</td>'
// + '<td>' + status + '</td>'
// + '<td>' + value + '</td>'
// + '</tr>';
// $("#metricsTable tbody").append(row);
// });
// });
// }
// }
/* Requests the default / general information about the cover
* Then executes a callback function */
function getDefaultXml(callback) {
/* Sends a request for the cover information */
sendRequest("get", "covers/" + coverId + "/graph/" + graphId + "/outputFormat/DEFAULT_XML", "",
/* Response handler */
function(response) {
coverDefaultXml = response;
if(typeof callback !== 'undefined') {
callback();
}
},
/* Error handler */
function(errorData) {
/*
* GraphIds request failed
*/
showConnectionErrorMessage("Cover was not received.", errorData);
}, "text");
}
/* Handles what happens on the visualization type Button presses */
function buttonClick(number) {
$(document).ready(function () {
let svgVizScroll = document.getElementById("visualizationZoomer");
let svgViz = document.getElementById("visualizationContent");
let forceViz = document.getElementById("forceVisualizationContent");
highlightNodes = new Set();
highlightLinks = new Set();
if (number === 0) {
forceViz.style.display = "none";
svgViz.style.display = "inherit";
svgVizScroll.style.display = "inline";
} else if (number === 1 || number === 2) {
forceViz.style.display = "inherit";
if (typeof forceGraph !== "undefined") {
forceGraph.width($('.forceVisualizationContent').width());
forceGraph.height($('.forceVisualizationContent').height());
}
svgViz.style.display = "none";
svgVizScroll.style.display = "none";
if (number === 1 && (have3D === true || typeof have3D === "undefined")) {
have3D = false;
//console.log("2D");
if (typeof forceGraph !== "undefined") {
forceGraph._destructor();
}
getJSON();
} else if (number === 2 && (have3D === false || typeof have3D === "undefined")) {
have3D = true;
//console.log("3D");
if (typeof forceGraph !== "undefined") {
forceGraph._destructor();
}
getJSON();
}
}
})
}
/* Resizes the graph canvas on fullscreen close. Done in own eventListener to do it after the automatic resize of the containing div*/
document.addEventListener('fullscreenchange', (event) => {
// document.fullscreenElement will point to the element that
// is in fullscreen mode if there is one. If there isn't one,
// the value of the property is null.
if (typeof document.fullscreenElement !== "undefined") {
var elem = document.getElementById('forceVisualizationContent');
if (typeof forceGraph !== "undefined") {
forceGraph.width($('.forceVisualizationContent').width());
forceGraph.height($('.forceVisualizationContent').height());
}
}
});
/* Listener for Ctrl+C presses */
document.addEventListener('keydown', (e) => {
if(e.code === "KeyC" || e.code === "ControlLeft") {
keysPressed.set(e.code,true);
}
});
/* Handles fullscreen events on press of the F key over a force graph and pressing enter for search, nodeSearch on enter, and nodeName copy on Ctrl+C */
document.addEventListener('keyup', (e) => {
if (e.code === "KeyF" && window.innerHeight !== screen.height && $('#forceVisualizationGraphic:hover').length !== 0 && document.getElementById("nodeSearchFormDropDown").classList.contains("show") === false && document.getElementById("toolsFormDropDown").classList.contains("show") === false)
{
var elem = document.getElementById('forceVisualizationContent');
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) { /* Firefox */
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { /* IE/Edge */
elem.msRequestFullscreen();
}
if (typeof forceGraph !== "undefined") {
forceGraph.width(screen.width);
forceGraph.height(screen.height);
}
}
else if(e.code === "KeyF" && window.innerHeight === screen.height)
{
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) { /* Firefox */
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) { /* IE/Edge */
document.msExitFullscreen();
}
}
else if(e.code === "Enter")
{
if(document.getElementById("nodeSearchFormDropDown").classList.contains("show") && document.activeElement === document.getElementById("nodeSearchForm")) {
nodeSearch();
}
else if(document.getElementById("toolsFormDropDown").classList.contains("show") && document.activeElement === document.getElementById("saveJsonForm")) {
saveJSON();
}
}
else if((e.code === "KeyC" || e.code === "ControlLeft") && $('#forceVisualizationGraphic:hover').length !== 0)
{
if(keysPressed.get("KeyC") === true && keysPressed.get("ControlLeft") === true) {
if(document.getElementById("nodeSearchFormDropDown").classList.contains("show") === false) {
searchDropDown();
}
document.getElementById("nodeSearchForm").value = nodeName;
document.getElementById("nodeSearchForm").select();
document.execCommand("copy", false, document.getElementById("nodeSearchForm").value);
}
keysPressed.set(e.code, false);
}
});
/* Opens the dropdown menu for entering database information */
function databaseInfoDropDown() {
// Close other menu
let dropdowns = document.getElementsByClassName("nodeSearchFormDropDown");
let i;
for (i = 0; i < dropdowns.length; i++) {
let openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
dropdowns = document.getElementsByClassName("toolsFormDropDown");
for (i = 0; i < dropdowns.length; i++) {
let openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
document.getElementById("dataBaseDropDownContent").classList.toggle("show");
}
/* Opens the search bar for nodes */
function searchDropDown() {
document.getElementById("nodeSearchForm").style.backgroundColor = "#f1f1f1";
document.getElementById("nodeSearchForm").placeholder = "Node Name";
// Close other menu
let dropdowns = document.getElementsByClassName("dataBaseDropDownContent");
let i;
for (i = 0; i < dropdowns.length; i++) {
let openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
dropdowns = document.getElementsByClassName("toolsFormDropDown");
for (i = 0; i < dropdowns.length; i++) {
let openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
document.getElementById("nodeSearchFormDropDown").classList.toggle("show");
}
/* Opens the tool bar(s) */
function toolsDropDownDots() {
// Close other menus
let dropdowns = document.getElementsByClassName("dataBaseDropDownContent");
let i;
for (i = 0; i < dropdowns.length; i++) {
let openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
dropdowns = document.getElementsByClassName("nodeSearchFormDropDown");
for (i = 0; i < dropdowns.length; i++) {
let openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
document.getElementById("toolsFormDropDown").classList.toggle("show");
}
function databaseInfoSubmit() {
arangoUser = $("#arangoUser").val();
arangoPass = $("#arangoPass").val();
arangoDataBase = $("#arangoDataBase").val();
arangoCollection = $("#arangoCollection").val();
localStorage.setItem("arangoUser@WebOCD",arangoUser);
localStorage.setItem("arangoPass@WebOCD",arangoPass);
localStorage.setItem("arangoDataBase@WebOCD",arangoDataBase);
localStorage.setItem("arangoCollection@WebOCD",arangoCollection);
var dropdowns = document.getElementsByClassName("dataBaseDropDownContent");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropDownOpenButton') && !event.target.matches('.dataBaseDropDownContentForm') && !event.target.matches('.nodeSearchForm') && !event.target.matches('.nodeSearchButton')
&& !event.target.matches('.toolsDropDownDots') && event.target.className !== 'tool-dot' && !event.target.matches('.saveJsonForm') && !event.target.matches('.nodeNameDisplayButton')){
var dropdowns = document.getElementsByClassName("dataBaseDropDownContent");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
dropdowns = document.getElementsByClassName("nodeSearchFormDropDown");
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
dropdowns = document.getElementsByClassName("toolsFormDropDown");
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
/* Let the camera look at a specified node (if found) */
function nodeSearch(){
if (typeof forceGraph !== "undefined") {
let searchNodeName = $("#nodeSearchForm").val();
for(let node of forceGraph.graphData().nodes)
{
if(node.name === searchNodeName)
{
if(have3D === false) {
forceGraph.centerAt(node.x, node.y);
forceGraph.zoom(9, 200);
searchNodeName = undefined;
} else {
const distance = 40;
const distRatio = 1 + distance/Math.hypot(node.x, node.y, node.z);
forceGraph.cameraPosition({ x: node.x * distRatio, y: node.y * distRatio, z: node.z * distRatio}, node, 250);
searchNodeName = undefined;
}
}
}
if (typeof searchNodeName !== "undefined" && searchNodeName !== "") {
document.getElementById("nodeSearchForm").style.backgroundColor = "#e58c8c";
document.getElementById("nodeSearchForm").placeholder = "Not found";
} else {
document.getElementById("nodeSearchForm").style.backgroundColor = "#f1f1f1";
document.getElementById("nodeSearchForm").placeholder = "Node Name";
let dropdowns = document.getElementsByClassName("nodeSearchFormDropDown");
for (let i = 0; i < dropdowns.length; i++) {
let openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
document.getElementById("nodeSearchForm").value = "";
}
}
/* Save the Graph in JSON format */
function saveJSON() {
let fileName = $("#saveJsonForm").val();
if(typeof jsonGraph === 'undefined') {
sendRequest("get", "visualization/cover/" + coverId + "/graph/" + graphId + "/outputFormat/JSON/layout/ORGANIC/paint/PREDEFINED_COLORS", "",
function (response) {
jsonGraph = response;
const blob = new Blob([jsonGraph],
{ type: "application/json" });
saveAs(blob, fileName + ".json");
});
}
else {
const blob = new Blob([jsonGraph],
{ type: "application/json" });
saveAs(blob, fileName + ".json");
}
let dropdowns = document.getElementsByClassName("toolsFormDropDown");
for (let i = 0; i < dropdowns.length; i++) {
let openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
function NodeNameDisplayHandler () {
haveNodeNames = !haveNodeNames;
if(have3D === true) {
forceGraph
.nodeOpacity(haveNodeNames === true ? .5 : 1)
.nodeThreeObject(forceGraph.nodeThreeObject())
}
}
/* Builds a force graph from json data */
function buildGraph() {
var graph = JSON.parse(jsonGraph);
var sizes = new Map();
var colors = new Map();
for (let node of graph.nodes) {
sizes[node.id] = node.size;
colors[node.id] = node.color;
}
if (have3D === false) {
forceGraph = ForceGraph()
(document.getElementById('forceVisualizationGraphic'))
.nodeCanvasObjectMode( () => 'after')
.backgroundColor("#fafafa")
.graphData(graph)
.nodeId('id')
.nodeLabel((node) => haveNodeNames !== true ? node.name : "")
.onNodeHover(node => {
if (node != null) {
nodeName = node.name;
}
})
.onNodeClick(node => {
if (arangoDataBase !== "" && arangoDataBase !== null
&& arangoUser !== "" && arangoUser !== null
&& arangoPass !== null
&& arangoCollection !== "" && arangoCollection !== null) {
db.useDatabase(arangoDataBase);
db.useBasicAuth(arangoUser, arangoPass);
const docCollection = db.collection(arangoCollection);
docCollection.document(node.name, true).then(function (doc) {
let nodeWindow = window.open("", '_blank');
if (doc != null) {
//console.log(JSON.stringify(doc, null, ' '));
let docStr = JSON.stringify(doc, null, ' ');
docStr = docStr.replace(/\n/g, "<br />");
nodeWindow.document.write("<pre>" + docStr + "</pre>");
} else {
nodeWindow.document.write("<pre>" + "Object was not found" + "</pre>");
}
}).catch((err) => console.error(err));
}
})
.nodeVal(function (node) {
return sizes[node.id] - 19
})
.nodeColor(function (node) {
return colors[node.id];
})
.nodeCanvasObject((node, ctx, globalScale) => {
if(haveNodeNames === true) {
const label = node.name;
const fontSize = 12/globalScale;
ctx.font = `${fontSize}px Sans-Serif`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillStyle = 'rgba(0, 0, 0, 1)';
ctx.fillText(label, node.x, node.y);
}
})
.onNodeDragEnd(node => {
node.fx = node.x;
node.fy = node.y;
})
.onNodeRightClick(node => {
//TODO: Seem a bit slow after restoring, check original forces/velocity
node.fx = null;
node.fy = null;
})
.linkSource('source')
.onLinkRightClick(link => {
if (link !== rightClickLink) {
rightClickLink = link;
} else {
rightClickLink = null;
}
})
.linkWidth(link => link === rightClickLink ? 2.5 : 1.5)
.linkColor(link => link === rightClickLink ? "rgba(145,217,65,0.6)" : "rgba(219,219,219,0.85)")
.linkDirectionalArrowLength(5)
.linkDirectionalArrowRelPos(1)
.linkTarget('target')
.cooldownTicks(200);
} else {
forceGraph = ForceGraph3D({
extraRenderers: [new THREE.CSS2DRenderer()]
})
(document.getElementById('forceVisualizationGraphic'))
.graphData(graph)
.nodeId('id')
.nodeLabel((node) => haveNodeNames !== true ? node.name : "")
.onNodeHover(node => {
if (node != null) {
nodeName = node.name;
}
})
.onNodeClick(node => {
if (arangoDataBase !== "" && arangoDataBase !== null
&& arangoUser !== "" && arangoUser !== null
&& arangoPass !== null
&& arangoCollection !== "" && arangoCollection !== null) {
db.useDatabase(arangoDataBase);
db.useBasicAuth(arangoUser, arangoPass);
const docCollection = db.collection(arangoCollection);
docCollection.document(node.name, true).then(function (doc) {
let nodeWindow = window.open("", '_blank');
if (doc != null) {
//console.log(JSON.stringify(doc, null, ' '));
let docStr = JSON.stringify(doc, null, ' ');
docStr = docStr.replace(/\n/g, "<br />");
nodeWindow.document.write("<pre>" + docStr + "</pre>");
} else {
nodeWindow.document.write("<pre>" + "Object was not found" + "</pre>");
}
}).catch((err) => console.error(err));
}
})
.nodeVal(function (node) {
return sizes[node.id] - 19 > 0 ? sizes[node.id] - 19 : 1;
})
.nodeThreeObject(node => {
if(haveNodeNames === true) {
const nodeEl = document.createElement('div');
nodeEl.textContent = node.name;
nodeEl.style.color = "#ffffff";//node.color;
nodeEl.className = 'node-label';
return new THREE.CSS2DObject(nodeEl);
}
})
.nodeThreeObjectExtend(true)
.nodeColor(function (node) {
return colors[node.id];
})
.nodeOpacity(haveNodeNames === true ? .5 : 1)
.onNodeDragEnd(node => {
node.fx = node.x;
node.fy = node.y;
node.fz = node.z;
})
.onNodeRightClick(node => {
//TODO: Seem a bit slow after restoring, check original forces/velocity
node.fx = null;
node.fy = null;
node.fz = null;
})
.linkSource('source')
.onLinkRightClick(link => {
if (link !== rightClickLink) {
rightClickLink = link;
} else {
rightClickLink = null;
}
forceGraph
.linkColor(forceGraph.linkColor())
.linkWidth(forceGraph.linkWidth())
})
.linkOpacity(0.35)
.linkColor(link => link === rightClickLink ? "rgba(126,234,10,0.85)" : "#dedede")
.linkWidth(link => link === rightClickLink ? 2 : 0)
.linkDirectionalArrowLength(4)
.linkDirectionalArrowRelPos(1)
.linkTarget('target')
.cooldownTicks(200);
}
forceGraph.width($('.forceVisualizationContent').width());
forceGraph.height($('.forceVisualizationContent').height());
}
/* Requests and stores a JSON representation of the graph and then builds it */
function getJSON() {
if(typeof jsonGraph === 'undefined') {
sendRequest("get", "visualization/cover/" + coverId + "/graph/" + graphId + "/outputFormat/JSON/layout/ORGANIC/paint/PREDEFINED_COLORS", "",
function (response) {
jsonGraph = response;
buildGraph();
},
/* Error handler */
function (errorData) {
/*
* GraphIds request failed
*/
showConnectionErrorMessage("Visualization was not received.", errorData);
});
}
else {
buildGraph();
}
}
/* Handles the collapsable element for the graph visualization */
function visualizationCollapsableHandler() {
/* Requests the graph visualization */
if (typeof visualization === 'undefined') {
getVisualization();
}
/* Registers the visualization for panzoom */
var $panzoom = $('body').find('.visualizationGraphic').panzoom({
$zoomRange: $('body').find(".visualizationZoomer"),
increment: 0.9,
contain: 'invert',
maxScale: 10,
minScale: 1
});
$panzoom.on('mousewheel', function (e) {
e.preventDefault();
var delta = e.delta || e.originalEvent.wheelDelta;
var zoomOut = delta ? delta < 0 : e.originalEvent.deltaY > 0;
$panzoom.panzoom('zoom', zoomOut, {
increment: 0.1,
animate: false,
focal: e
});
});
}
/* Requests and stores the visualization of the cover */
function getVisualization() {
/* Requests the visualization */
sendRequest("get", "visualization/cover/" + coverId + "/graph/"
+ graphId + "/outputFormat/SVG/layout/ORGANIC/paint/PREDEFINED_COLORS", "",
/* Response handler */
function(response) {
visualization = response;
$('.visualizationGraphic').append(visualization);
},
/* Error handler */
function(errorData) {
/*
* Visualization request failed
*/
showConnectionErrorMessage("Visualization was not received.", errorData);
});
}
</script>
</head>
<body>
<div id="wrapper">
<div id="contentWrapper">
<div id="content">
<!-- Container for display of error messages -->
<div id="errorMessageWrapper">
<div id="errorMessage"></div>
</div>
<!-- Cover meta information table -->
<div id="coverHeader" class="col-sm-12 col-md-12 coverColor">
</div>
<div class="tableWrapper">
<table id="coverMetaTable">
<thead>
<tr>
<th class="hidden" title="CoverId"></th>
<th class="hidden" title="GraphId"></th>
<th width="300" title="Cover Name" class="sortable">
Name
<img class="icon iconBtn" src="IMG/open-iconic/svg/sort-ascending.svg" alt="d">
</th>
<th width="300" title="Graph Name" class="sortable">
Graph
<img class="icon iconBtn" src="IMG/open-iconic/svg/sort-ascending.svg" alt="d">
</th>
<th width="300" title="Algorithm Name" class="sortable">
Creation Method
<img class="icon iconBtn" src="IMG/open-iconic/svg/sort-ascending.svg" alt="d">
</th>
<th width="100" title="Community Count" class="sortable">
Communities
<img class="icon iconBtn" src="IMG/open-iconic/svg/sort-ascending.svg" alt="d">
</th>
<th width="20" title="Remove Cover">
R
</th>
<th width="50" title="Save Cover XML">
.xml
</th>
<th width="30" title="Save Cover Matrix">
.txt
</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<!-- Collapsable element for metric value display -->
<div id="metricsCollapsable" class="collapsable">
<div class="collapsableHeader">