forked from sutthidaAlizzabeth/BSI-Visualisation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
concentric_drawer.js
executable file
·185 lines (162 loc) · 5.76 KB
/
concentric_drawer.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
$(function() {
var source = new Array();
var target = new Array();
var edges = new Array();
//get each data from object
for (i = 0; i < cytosol.length; i++) {
//separate pathway by color of node
//color for node of sucrose/starch metabolism pathway
var color = '#DF013A';
if (cytosol[i].pathway == "nucleotide biosynthesis pathway") {
color = '#FCB1ED';
} else if (cytosol[i].pathway == "cell wall biosynthesis pathway") {
color = '#B20FC8';
} else if (cytosol[i].pathway == "pentose phosphate pathway") {
color = '#305CF8';
} else if (cytosol[i].pathway == "respiration pathway pathway") {
color = '#59F0F8';
} else if (cytosol[i].pathway == "amino acid biosynthesis pathway") {
color = '#59F87E';
} else if (cytosol[i].pathway == "fatty acid biosynthesis pathway") {
color = '#FF983E';
} else if (cytosol[i].abbr.startsWith("T") == true) { //transporter
color = '#FBF97C';
} else if (cytosol[i].abbr.startsWith("E") == true) { //external
color = '#000000';
};
//create node with source and target -------------------------------
var sourceData;
var targetData;
//set source node
//if there is substance value in array
if (cytosol[i].substance != undefined) {
sourceData = {
"data": {
"id": cytosol[i].substance,
"content": '',
"nc": '#959090',
"shape": 'ellipse',
"width": 5,
"height": 5
}
};
targetData = {
"data": {
"id": cytosol[i].reaction,
"content": cytosol[i].name,
"nc": color,
"shape": 'ellipse',
"width": 15,
"height": 15
}
};
} else { // if there is no substance value in arry, so flux will be source
sourceData = {
"data": {
"id": cytosol[i].reaction,
"content": cytosol[i].name,
"nc": color,
"shape": 'ellipse',
"width": 15,
"height": 15
}
};
targetData = {
"data": {
"id": cytosol[i].product,
"content": '',
"nc": '#959090',
"shape": 'ellipse',
"width": 5,
"height": 5
}
};
}
source.push(sourceData);
target.push(targetData);
// Create edge ----------------------------------------------
var edgeData;
//edge between substance and flux
if (cytosol[i].substance != undefined) {
edgeData = {
"data": {
"id": cytosol[i].name + '-' + cytosol[i].substance,
"weight": 1,
"source": cytosol[i].substance,
"target": cytosol[i].reaction,
"target_arrow": cytosol[i].target_arrow,
"source_arrow": cytosol[i].source_arrow
}
};
} else { //edge between flux and product
edgeData = {
"data": {
"id": cytosol[i].name + '-' + cytosol[i].product,
"weight": 1,
"source": cytosol[i].reaction,
"target": cytosol[i].product,
"target_arrow": cytosol[i].target_arrow,
"source_arrow": cytosol[i].source_arrow
}
};
}
edges.push(edgeData);
}
nodes = target.concat(source);
// Draw graph -----------------------------------------------------------
var cy = cytoscape({
container: document.getElementById('cy'), // container to render in
boxSelectionEnabled: false,
autounselectify: true,
elements: {
nodes: nodes,
edges: edges
},
style: cytoscape.stylesheet()
.selector('node')
.css({
'content': 'data(content)',
'color': '#000',
'width': 'data(width)',
'height': 'data(height)',
'background-color': 'data(nc)',
'shape': 'data(shape)'
})
.selector('edge')
.css({
'target-arrow-shape': 'data(target_arrow)',
'source-arrow-shape': 'data(source_arrow)',
'width': "data(weight)",
'line-color': '#DCD9D9',
'haystack-radius': 5,
'source-arrow-color': '#DCD9D9',
'target-arrow-color': '#DCD9D9',
'curve-style': 'bezier'
}),
layout: {
name: 'concentric',
concentric: function( node ){
return node.degree();
},
levelWidth: function( nodes ){
return 2;
}
}
});
cy.elements().qtip({
content: function() {
return this.id()
},
position: {
my: 'top center',
at: 'bottom center'
},
style: {
classes: 'qtip-bootstrap',
tip: {
width: 16,
height: 8
}
}
});
});