Skip to content

Commit 348bb5e

Browse files
committed
Multiline adjlists now working in cytoscape.
1 parent 93778bf commit 348bb5e

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

src/fileWrite.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,43 @@ function makeAdjlist(nodeList){
2121
var adjlist = '';
2222

2323
//Go through each vertex and add it's edges to the adjlist
24-
for(var i=0; i<nodeList.length; i++){
25-
var edges = nodeList[i].adjacencies;
24+
for(var i = 0; i < nodeList.length; i++){
25+
var edges = nodeList[i].connectedEdges();
2626
var numEdges = edges.length;
2727

28-
//Add the header
29-
adjlist = adjlist + i.toString() + ' ' + numEdges.toString() + '\r\n';
28+
//Check if the user has made a label
29+
if(nodeList[i].style('label') !== ''){
30+
//Add the header
31+
adjlist = adjlist + nodeList[i].style('label') + ' ' + numEdges.toString() + '\r\n';
32+
}
33+
else{
34+
adjlist = adjlist + nodeList[i].data('id') + ' ' + numEdges.toString() + '\r\n';
35+
}
3036

3137
//Add each edge
3238
for(var k=0; k<numEdges; k++){
33-
adjlist = adjlist + edges[k].index.toString() + '\r\n';
39+
40+
//Check if the target is the node itself and use the source instead
41+
if(edges[k].data('target') === nodeList[i].data('id')){
42+
var targetLabel = cy.getElementById(edges[k].data('source')).style('label');
43+
44+
if(targetLabel !== ''){
45+
adjlist = adjlist + targetLabel + '\r\n';
46+
}
47+
else{
48+
adjlist = adjlist + edges[k].data('source') + '\r\n';
49+
}
50+
}
51+
else{
52+
var targetLabel = cy.getElementById(edges[k].data('target')).style('label');
53+
54+
if(targetLabel !== ''){
55+
adjlist = adjlist + targetLabel + '\r\n';
56+
}
57+
else{
58+
adjlist = adjlist + edges[k].data('target') + '\r\n';
59+
}
60+
}
3461
}
3562
}
3663

@@ -44,7 +71,7 @@ function writeGraphAdjlist(){
4471

4572
dialog.setContext(document);
4673
dialog.saveFileDialog(function(fileName){
47-
var adjlist = makeAdjlist(nodes);
74+
var adjlist = makeAdjlist(cy.nodes());
4875

4976
fs.writeFile(fileName, adjlist, function(err){
5077
if(err) throw err;

0 commit comments

Comments
 (0)