forked from sutthidaAlizzabeth/BSI-Visualisation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawer copy.js
executable file
·169 lines (151 loc) · 5.29 KB
/
drawer copy.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
$(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.includes("nucleotide biosynthesis")) {
color = '#FCB1ED';
}
else if(cytosol[i].pathway.includes("cell wall biosynthesis")){
color = '#FCB1ED';
}
else if (cytosol[i].pathway.includes("pentose phosphate")) {
color = '#FCB1ED'; //ผิด
}
else if (cytosol[i].pathway.includes("respiration")) {
color = '#FCB1ED'; //ผิด
}
else if (cytosol[i].pathway.includes("amino acid biosynthesis")) {
color = '#FCB1ED'; //ผิด
}
else if (cytosol[i].pathway.includes("fatty acid biosynthesis")) {
color = '#FCB1ED'; //ผิด
}
else if (cytosol[i].abbr.startsWith("T")) {//transporter
color = '#FCB1ED'; //ผิด
}
else if (cytosol[i].abbr.startsWith("E")) {//external
color = '#000000';
}
//create node with source and target -------------------------------
var sourceData;
//set source node
//if there is substance value in array
if (cytosol[i].substance != undefined) {
sourceData = {
"data" : {
"id" : cytosol[i].substance + '-' + cytosol[i].abbr,
"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].abbr,
"nc": color,
"shape" : 'ellipse',
"width" : 5,
"height" : 5
}
};
}
source.push(sourceData);
var targetData;
//set target node
//if there is product value in array
if (cytosol[i].product != undefined) {
targetData = {
"data" : {
"id" : cytosol[i].abbr + '-' + cytosol[i].product,
"nc": color,
"shape" : 'ellipse',
"width" : 15,
"height" : 15
}
};
}
else{// if there is no substance value in arry, so flux will be source
targetData = {
"data" : {
"id" : cytosol[i].abbr,
"nc": color,
"shape" : 'ellipse',
"width" : 5,
"height" : 5
}
};
}
target.push(targetData);
// Create edge ----------------------------------------------
var edgeData;
//edge between substance and flux
if (cytosol[i].substance != undefined) {
edgeData = {
"data" : {
"id": cytosol[i].substance + '-' + cytosol[i].name,
"weight": 4,
"source": cytosol[i].substance,
"target": cytosol[i].abbr,
"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": 4,
"source": cytosol[i].abbr,
"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(id)',
'color' : '#000',
'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': '#000',
'source-arrow-color': '#000',
'target-arrow-color': '#000',
'curve-style': 'bezier'
}),
layout: {
name: 'cose',
// roots: '#a',
rows: 1,
directed: true
}
});
});