forked from rwth-acis/OCD-Web-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.html
1491 lines (1415 loc) · 74.2 KB
/
graph.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>
<html>
<!-- Displays detailed information on a single graph. Allows OCD algorithm execution. -->
<head>
<title>OCD - Graph</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="CSS/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="CSS/layout.css">
<!-- TODO: Possibly omit https: again from the urls before pushing. Though this seems to be best practice now anyways -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://npmcdn.com/[email protected]/dist/js/tether.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="JS/bootstrap.min.js"></script>
<script src="JS/jquery.session.js"></script>
<script src="JS/contentHandler.js"></script>
<script src="JS/ServiceAPI/b64.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/graphTableHandler.js"></script>
<script src="JS/jquery.tablesorter.js"></script>
<script src="JS/jquery.panzoom.js"></script>
<script src="JS/jquery.mousewheel.js"></script>
<script src="JS/simulation/jsonRequestHandler.js"></script>
<script src="JS/simulation/simulationForm.js"></script>
<script src="JS/force-graph/force-graph.js"></script>
<script src="JS/force-graph/3d-force-graph.js"></script>
<script src="JS/[email protected]/lib/web.js"></script>
<script src="JS/FileSaver.js"></script>
<script type="text/javascript">
/* Id of the graph */
var graphId = getUrlVar("id");
/* Graph meta information in xml format */
var graphMetaXml;
/* Graph structure in edge list format */
var graphProperties;
/* Graph structure in JSON format */
var jsonGraph;
var forceGraph;
var have3D;
var nodeName = "";
var keysPressed = new Map();
/* 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');
/* Graph visualization in SVG format */
var highlightNodes = new Set();
var highlightLinks = new Set();
var rightClickNode = null;
var rightClickLink = null;
var visualization;
/* Names of all OCD algorithms */
var algorithmNames;
/* Names of all centrality measures */
var centralityMeasureNames;
/* Names of all centrality simulations */
var centralitySimulationNames;
/* Principal eigenvalue of the grapph's adjacency matrix */
var eigenvalue;
/* Executed after page loading */
$(document).ready(function () {
/* Identifiers for the graph information to be displayed */
var cells = ["Name", "NodeCount", "EdgeCount", "D", "W", "Z", "N", "L", "C", "R"];
/* Requests the graph meta information */
sendRequest("get", "graphs/" + graphId + "?outputFormat=META_XML", "",
/* Response handler */
function (response) {
/* Stores graph meta information and adds it to the graph header */
graphMetaXml = response;
var name = $(graphMetaXml).find('Name').text();
var nodes = $(graphMetaXml).find('NodeCount').text();
var edges = $(graphMetaXml).find('EdgeCount').text();
/* Graph types */
var types = [];
$(graphMetaXml).children('Types').find('Type').each(function () {
types.push($(this).text());
});
var directed = $.inArray("DIRECTED", types);
var weighted = $.inArray("WEIGHTED", types);
var description = "A";
if (directed == -1 && weighted == -1)
description += " simple ";
if (directed > -1)
description += " directed ";
if (weighted > -1)
description += " weighted ";
description += ' network with ' + nodes + ' nodes and ' + edges + ' links.';
$('#graphHeader').html(getHeadLine(name, description));
$('#graphCovers').html('<a href="covers.html?graphId=' + graphId + '">Covers</a>');
$('#graphSimulations').html('<a href="cooperation_simulations.html?graphId=' + graphId + '">Simulations</a>');
$('#graphCentralities').html('<a href="centralities.html?graphId=' + graphId + '">Centralities</a>');
$('#graphDelete').html('<a onclick="deleteGraph()" href="#">Delete</a>');
/* Registers components and event handlers */
registerCollapsable("#propertiesCollapsable", propertiesCollapsableHandler);
registerCollapsable("#edgeListCollapsable", edgeListCollapsableHandler);
registerCollapsable("#visualizationCollapsable", visualizationCollapsableHandler);
registerCollapsable("#runAlgorithmCollapsable", runAlgorithmCollapsableHandler);
registerCollapsable("#runSimulationCollapsable", runSimulationCollapsableHandler);
registerCollapsable("#runCentralityCalculationCollapsable", runCentralityCalculationCollapsableHandler);
registerCollapsable("#runCentralitySimulationCollapsable", runCentralitySimulationCollapsableHandler);
},
/* Error handler */
function (errorData) {
/*
* GraphIds request failed
*/
showConnectionErrorMessage("Graph was not received.");
}, "text");
/*
* Run algorithm form listener.
*/
$('#runAlgorithmForm').submit(function () {
var algo = $('#algorithm').val();
if (algo !== getSelectOptionVal()) {
var params = getParameterXml("#algorithmParameterDiv");
var coverName = $("#coverName").val();
var contentWeighting = $("#contentWeighting").is(':checked');
if (coverName === "") {
showErrorMessage('Please define a cover name.');
window.scrollTo(0, 0);
return;
}
/* Requests an algorithm execution */
//console.log("post" + " " + "covers/graphs/" + graphId
// + "/algorithms?algorithm=" + algo + "&name=" + coverName + "&contentWeighting=" + contentWeighting + " " + params);
sendRequest("post", "covers/graphs/" + graphId
+ "/algorithms?algorithm=" + algo + "&name=" + coverName + "&contentWeighting=" + contentWeighting, params,
/* Response handler */
function (response) {
window.location.href = 'index.html';
},
/* Error handler */
function (errorData) {
/*
* Run algorithm request failed
*/
showConnectionErrorMessage("Algorithm request failed.");
});
}
return false;
});
/*
* Run centrality calculation form listener.
*/
$('#runCentralityCalculationForm').submit(function () {
var c_algo = $('#centralityMeasure').val();
if (c_algo !== getSelectOptionVal()) {
var params = getParameterXml("#centralityMeasureParameterDiv");
sendRequest("post", "centrality/graphs/" + graphId
+ "/algorithms?algorithm=" + c_algo, params,
/* Response handler */
function (response) {
//window.location.href = 'index.html';
},
/* Error handler */
function (errorData) {
/*
* Run centrality calculation request failed
*/
if (errorData.includes("Show Error")) {
var errorSplit = errorData.split(":");
showErrorMessage(errorSplit[errorSplit.length - 1]);
window.scrollTo(0, 0);
} else {
showConnectionErrorMessage("Centrality calculation request failed.");
}
});
} else {
showErrorMessage("Please select a centrality measure.");
window.scrollTo(0, 0);
}
return false;
});
/*
* Run centrality simulation form listener.
*/
$('#runCentralitySimulationForm').submit(function () {
var sim = $('#centralitySimulation').val();
if (sim !== getSelectOptionVal()) {
var params = getParameterXml("#centralitySimulationParameterDiv");
var runs = 1;
if ($('#multipleRuns').prop("checked")) {
runs = $('#runsInput').val();
}
var counter;
for (counter = 0; counter < runs; counter++) {
sendRequest("post", "centrality/simulation/graphs/" + graphId
+ "?simulation=" + sim + "&runs=" + runs, params,
/* Response handler */
function (response) {
//window.location.href = 'index.html';
},
/* Error handler */
function (errorData) {
/*
* Run centrality simulation request failed
*/
if (errorData.includes("Show Error")) {
var errorSplit = errorData.split(":");
showErrorMessage(errorSplit[errorSplit.length - 1]);
window.scrollTo(0, 0);
} else {
showConnectionErrorMessage("Centrality simulation request failed.");
}
});
}
} else {
showErrorMessage("Please select a centrality simulation.");
window.scrollTo(0, 0);
}
return false;
});
$('#centralityMeasure').change(function () {
$('#annotationDiv').hide();
});
$('#centralityInfo').click(function () {
var measureName = $('#centralityMeasure').val();
if (measureName == getSelectOptionVal()) {
window.location.href = "centralities_info.html";
} else {
window.location.href = "centralities_info.html?measureName=" + measureName.replace(/ /g, "_");
}
});
$('#centralitySimulationInfo').click(function () {
var simulationName = $('#centralitySimulation').val();
if (simulationName == getSelectOptionVal()) {
window.location.href = "centrality_simulations_info.html";
} else {
window.location.href = "centrality_simulations_info.html?simulationName=" + simulationName.replace(/ /g, "_");
}
});
});
/* Requests the names of all OCD algorithms.
* Then executes a callback function */
function getAlgorithmNames(callback) {
sendRequest("get", "algorithms", "",
/* Response handler */
function (response) {
algorithmNames = response;
if (typeof callback !== 'undefined') {
callback();
}
},
/* Error handler */
function (errorData) {
/*
* OCD algorithm request failed
*/
showConnectionErrorMessage("Algorithm names were not received.");
});
}
/* Requests the names of all centrality measures.
* Then executes a callback function */
function getCentralityMeasureNames(callback) {
sendRequest("get", "centralities", "",
/* Response handler */
function (response) {
centralityMeasureNames = response;
if (typeof callback !== 'undefined') {
callback();
}
},
/* Error handler */
function (errorData) {
/*
* Centrality measure name request failed
*/
showConnectionErrorMessage("Centrality measure names were not received.");
});
}
/* Requests the names of all centrality simulations.
* Then executes a callback function */
function getCentralitySimulationNames(callback) {
sendRequest("get", "centralitysimulations", "",
/* Response handler */
function (response) {
centralitySimulationNames = response;
if (typeof callback !== 'undefined') {
callback();
}
},
/* Error handler */
function (errorData) {
/*
* Centrality simulation name request failed
*/
showConnectionErrorMessage("Simulation names were not received.");
});
}
/* Requests all parameter names for a given algorithm.
* Then executes a calllback function */
function getAlgorithmParameters(algorithmName, callback) {
sendRequest("get", "algorithms/" + algorithmName + "/parameters/default", "",
/* Response handler */
function (response) {
if (typeof callback !== 'undefined') {
callback(response);
}
},
/* Error handler */
function (errorData) {
/*
* GraphIds request failed
*/
showConnectionErrorMessage("Algorithm parameters were not received.");
});
}
/* Requests all parameter names for a given centrality measure.
* Then executes a calllback function */
function getCentralityMeasureParameters(centralityMeasureName, callback) {
sendRequest("get", "centralities/" + centralityMeasureName + "/parameters/default", "",
/* Response handler */
function (response) {
$('#annotationText').html("");
if (centralityMeasureName == "Katz Centrality") {
displayEigenvalue();
}
var graphSize = $(graphMetaXml).find('NodeCount').text();
if (graphSize > 200 && (centralityMeasureName == "Katz Centrality" || centralityMeasureName == "Current-Flow Closeness" || centralityMeasureName == "Current-Flow Betweenness")) {
$('#annotationText').append("<p>Warning: The computation of this measure may take a long time on this graph.</p>");
$('#annotationDiv').show();
}
if (typeof callback !== 'undefined') {
callback(response);
}
},
/* Error handler */
function (errorData) {
/*
* Centrality measure parameter request failed
*/
showConnectionErrorMessage("Centrality measure parameters were not received.");
});
}
/* Requests all parameter names for a given centrality simulation.
* Then executes a calllback function */
function getCentralitySimulationParameters(centralitySimulationName, callback) {
sendRequest("get", "centralitysimulations/" + centralitySimulationName + "/parameters/default", "",
/* Response handler */
function (response) {
if (typeof callback !== 'undefined') {
callback(response);
}
},
/* Error handler */
function (errorData) {
/*
* Centrality simulation parameter request failed
*/
showConnectionErrorMessage("Centrality simulation parameters were not received.");
});
}
/* Handles the collapsable element for the algorithm execution. */
function runAlgorithmCollapsableHandler() {
if (typeof algorithmNames === 'undefined') {
/* Adds all algorithm names to the form */
getAlgorithmNames(function () {
$(algorithmNames).find('Name').each(function () {
if ($(this).text() !== 'UNDEFINED' && $(this).text() !== 'GROUND_TRUTH') {
$("#algorithm").append(
'<option value="' + $(this).text()
+ '">' + parseEnumName($(this).text()) + '</option>');
}
});
});
/* Registers the parameter component for the contentHandler */
registerParameterSelect("#algorithm", "#algorithmParameterDiv", getAlgorithmParameters);
}
}
/* Handles the collapsable element for the algorithm execution. */
function runSimulationCollapsableHandler() {
if (typeof algorithmNames === 'undefined') {
/* Adds all algorithm names to the form */
getAlgorithmNames(function () {
$(algorithmNames).find('Name').each(function () {
if ($(this).text() !== 'UNDEFINED' && $(this).text() !== 'GROUND_TRUTH') {
$("#algorithm").append(
'<option value="' + $(this).text()
+ '">' + parseEnumName($(this).text()) + '</option>');
}
});
});
}
}
/* Handles the collapsable element for the centrality calculation. */
function runCentralityCalculationCollapsableHandler() {
if (typeof centralityMeasureNames === 'undefined') {
/* Adds all centrality measure names to the form */
getCentralityMeasureNames(function () {
$(centralityMeasureNames).find('Name').each(function () {
if ($(this).text() !== 'Undefined') {
$("#centralityMeasure").append(
'<option value="' + $(this).text()
+ '">' + $(this).text() + '</option>');
}
});
});
/* Registers the parameter component for the contentHandler */
registerParameterSelect("#centralityMeasure", "#centralityMeasureParameterDiv", getCentralityMeasureParameters);
}
}
/* Handles the collapsable element for the centrality simulation. */
function runCentralitySimulationCollapsableHandler() {
if (typeof centralitySimulationNames === 'undefined') {
/* Adds all centrality simulation names to the form */
getCentralitySimulationNames(function () {
$(centralitySimulationNames).find('Name').each(function () {
if ($(this).text() !== 'Undefined') {
$("#centralitySimulation").append(
'<option value="' + $(this).text()
+ '">' + $(this).text() + '</option>');
}
});
});
$('#multipleRuns').change(function () {
$('#runsInput').toggleClass("hidden");
});
/* Registers the parameter component for the contentHandler */
registerParameterSelect("#centralitySimulation", "#centralitySimulationParameterDiv", getCentralitySimulationParameters);
}
}
/* Requests and stores the properties of the graph.
* Then executes a callback function */
function getProperties(callback) {
sendRequest("get", "graphs/" + graphId + "?outputFormat=PROPERTIES_XML", "",
/* Response handler */
function (response) {
graphProperties = response;
if (typeof callback !== 'undefined') {
callback();
}
},
/* Error handler */
function (errorData) {
/*
* GraphIds request failed
*/
showConnectionErrorMessage("Graph Properties was not received.");
}, "text");
}
/* Requests and stores the edge list of the graph.
* Then executes a callback function */
function getEdgeList(callback) {
sendRequest("get", "graphs/" + graphId + "?outputFormat=WEIGHTED_EDGE_LIST", "",
/* Response handler */
function (response) {
graphEdgeList = response;
if (typeof callback !== 'undefined') {
callback();
}
},
/* Error handler */
function (errorData) {
/*
* GraphIds request failed
*/
showConnectionErrorMessage("Graph was not received.");
}, "text");
}
/* Handles the collapsable element for the properties. */
function propertiesCollapsableHandler() {
if (typeof graphProperties === 'undefined') {
/* Requests the edge list */
getProperties(function () {
/* Adds properties information to a table */
var properties = $(graphProperties).children();
for (i = 0; i < properties.length; i++) {
var name = $(properties)[i].nodeName;
var value = $(graphProperties).find($(properties)[i].nodeName).text();
if (name !== 'ID' && name !== 'NAME') {
name = name.replace("_", " ");
var row = '<tr>'
+ '<td>' + name + '</td>'
+ '<td>' + value + '</td>'
+ '</tr>';
$("#graphPropertiesTable tbody").append(row);
}
}
});
}
}
/* Handles the collapsable element for the edge list. */
function edgeListCollapsableHandler() {
if (typeof graphEdgeList === 'undefined') {
/* Requests the edge list */
getEdgeList(function () {
/* Adds the edge list information to a table */
var lines = graphEdgeList.split('\n');
$.each(lines, function (key, line) {
var parts = line.split(' ');
if ($(parts).length === 3) {
var row = '<tr>'
+ '<td>' + parts[0] + '</td>'
+ '<td>' + parts[1] + '</td>'
+ '<td>' + parts[2] + '</td>'
+ '</tr>';
$("#graphEdgeTable tbody").append(row);
}
});
$("#graphEdgeTable").tablesorter({sortList: [[0, 0], [1, 0]]});
});
}
}
/* 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)
{
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')) {
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/graph/" + graphId + "/outputFormat/JSON/layout/ORGANIC", "",
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');
}
}
}
/* Builds a force graph from json data */
function buildGraph() {
let graph = JSON.parse(jsonGraph);
let degree = new Map();
let outgoingNeighbours = new Map();
let styles = []
for (let node of graph.nodes) {
degree[node.id] = 0;
outgoingNeighbours[node.id] = [];
}
for (let edge of graph.links) {
degree[edge.source] += 1;
outgoingNeighbours[edge.source].push(edge.target);
styles.push(edge.style);
}
if (have3D === false) {
forceGraph = ForceGraph()
(document.getElementById('forceVisualizationGraphic'))
.backgroundColor("#fafafa")
.graphData(graph)
.nodeId('id')
.nodeLabel('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) {
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));
}
})
.onNodeRightClick(node => {
highlightNodes.clear();
highlightLinks.clear();
if (node !== rightClickNode) {
if (node) {
highlightNodes.add(node.id);
outgoingNeighbours[node.id].forEach(neighbor => highlightNodes.add(neighbor));
graph.links.forEach(link => {
if (link.source.id === node.id) {
highlightLinks.add(link)
}
});
}
rightClickNode = node;
} else {
rightClickNode = null;
}
rightClickLink = null;
})
.nodeVal(function (node) {
return Math.log(degree[node.id] + 1)
} /*<= 14 ? degree[node.id] : 14}*/)
.nodeColor(function (node) {
if (highlightNodes.has(node.id)) {
return ((node === rightClickNode) ? '#f54a06' : '#fd970d');
} else {
return '#3183ba';
}
})
.linkSource('source')
.onLinkRightClick(link => {
//console.log(link);
highlightNodes.clear();
highlightLinks.clear();
if (link !== rightClickLink) {
if (link) {
highlightLinks.add(link);
highlightNodes.add(link.source.id);
highlightNodes.add(link.target.id);
}
rightClickLink = link;
rightClickNode = null;
} else {
rightClickLink = null;
rightClickNode = null;
}
})
.linkLineDash(function (link) {
if (styles[link.index] === 1) {
return [10, 10]
} else if (styles[link.index] === 2) {
return [5, 5]
}
})
.linkWidth(link => highlightLinks.has(link) ? 2.5 : 1.5)
.linkColor(link => highlightLinks.has(link) ? "rgba(145,217,65,0.6)" : "rgba(219,219,219,0.85)")
.linkDirectionalArrowLength(5)
.linkDirectionalArrowRelPos(1)
.linkTarget('target')
.nodeCanvasObjectMode(node => highlightNodes.has(node.id) ? 'after' : undefined)
.cooldownTicks(200);
} else {
forceGraph = ForceGraph3D()
(document.getElementById('forceVisualizationGraphic'))
.graphData(graph)
.nodeId('id')
.nodeLabel('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));
}
})
.onNodeRightClick(node => {
highlightNodes.clear();
highlightLinks.clear();
if (node !== rightClickNode) {
if (node) {
highlightNodes.add(node.id);
outgoingNeighbours[node.id].forEach(neighbor => highlightNodes.add(neighbor));
graph.links.forEach(link => {
if (link.source.id === node.id) {
highlightLinks.add(link)
}
});