-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·121 lines (100 loc) · 3.09 KB
/
index.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
function findCyclesMain() {
enable_result();
document.getElementById("enumerated_cycles").value = "Calculating...";
var find_just_one_cycle = !document.getElementById("enumerate_all").checked;
var schema = document.getElementById("schema_text").value + "\n";
const jsObj = convert(schema);
const graph = convertToGraph(jsObj);
var _vertices = [];
var _edges = [];
cy = []; // empty if its not the first time
var incrementedge = 0;
for(var vertex in graph.graph)
{
// added for graph drawing purposes.
//{ data: { id: 'a' } },
//{ data: { id: 'a"e', weight: 1, source: 'a', target: 'e' } },
//console.log(graph.graph[vertex].vertexID);
_vertices.push({data:{id: graph.graph[vertex].vertexID}});
for(var edge in graph.graph[vertex].referenceList)
{
var label = graph.graph[vertex].referenceList[edge].label;
var referenceID = graph.graph[vertex].referenceList[edge].reference.vertexID;
_edges.push({data:{id:(incrementedge++)+label, weight:1 ,source:vertex, target:referenceID}});
}
}
var cy = cytoscape({
container: document.getElementById('cy'),
boxSelectionEnabled: true,
autounselectify: true,
style: cytoscape.stylesheet()
.selector('node')
.css({
'content': 'data(id)'
})
.selector('edge')
.css({
'curve-style': 'bezier',
'target-arrow-shape': 'triangle',
'width': 5,
'line-color': '#ddd',
'target-arrow-color': '#555'
})
.selector('.highlighted')
.css({
'background-color': '#61bffc',
'line-color': '#61bffc',
'target-arrow-color': '#61bffc',
'transition-property': 'background-color, line-color, target-arrow-color',
'transition-duration': '0.5s'
}),
elements: {
nodes: _vertices,
//{ data: { id: 'a' } },
edges: _edges
//{ data: { id: 'a"e', weight: 1, source: 'a', target: 'e' } },
},
styleEnabled : true,
gravity: 1,
/*
layout: {
name: 'cose',
directed: true,
roots: '#a',
padding: 10,
}*/layout: {
stop: function () {
},
name: 'cose',
animate: 'end',
nodeSep: 20, // >>>>>>YOUR TARGET PROPERTY<<<<<<<
animationEasing: 'ease-out',
animationDuration: 2000
}});
const res = detectCycles(graph.graph, find_just_one_cycle);
if(res.foundCycle) {
document.getElementById("label_output").textContent = ("Found cycles");
}
else {
document.getElementById("label_output").textContent = ("Found no cycles");
}
document.getElementById("enumerated_cycles").value = "";
// create graph here!
for( var sc in res.cycles) {
var string = "{ ";
for ( var vert in res.cycles[sc] ) {
string += res.cycles[sc][vert]["vertex"].vertexID;
if( res.cycles[sc][vert]["refLabel"] === "#interface_ref") {
string += " <~implements~ ";
}
else if (res.cycles[sc][vert]["refLabel"] === "#union_ref") {
string += " -union-> ";
}
else string += " -[" + res.cycles[sc][vert]["refLabel"] + "]-> ";
//string += ", ";
}
string = string.slice(0,-7);
string += " }";
document.getElementById("enumerated_cycles").value += string + "\n\n";
}
}