Skip to content

Commit

Permalink
Apply tiling to single nodes if packing is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
hasanbalci committed Oct 2, 2019
1 parent 6bae72c commit 0d95400
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 4 deletions.
41 changes: 39 additions & 2 deletions cytoscape-fcose.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,46 @@ var Layout = function () {
}
});
} else {
var toBeTiledNodes = cy.collection();
if (options.tile) {
var nodeIndexes = new Map();
var _xCoords2 = [];
var _yCoords2 = [];
var count = 0;
var tempSpectralResult = { nodeIndexes: nodeIndexes, xCoords: _xCoords2, yCoords: _yCoords2 };
var indexesToBeDeleted = [];
components.forEach(function (component, index) {
if (component.edges().length == 0) {
component.nodes().forEach(function (node, i) {
toBeTiledNodes.merge(component.nodes()[i]);
if (!node.isParent()) {
tempSpectralResult.nodeIndexes.set(component.nodes()[i].id(), count++);
tempSpectralResult.xCoords.push(component.nodes()[0].position().x);
tempSpectralResult.yCoords.push(component.nodes()[0].position().y);
}
});
indexesToBeDeleted.push(index);
}
});
if (toBeTiledNodes.length > 1) {
components.push(toBeTiledNodes);
for (var i = indexesToBeDeleted.length - 1; i >= 0; i--) {
components.splice(indexesToBeDeleted[i], 1);
spectralResult.splice(indexesToBeDeleted[i], 1);
};
spectralResult.push(tempSpectralResult);
}
}
components.forEach(function (component, index) {
options.eles = component;
coseResult.push(coseLayout(options, spectralResult[index]));
if (options.tile) {
if (!(component.edges().length == 0 && toBeTiledNodes.length == 1)) {
options.eles = component;
coseResult.push(coseLayout(options, spectralResult[index]));
}
} else {
options.eles = component;
coseResult.push(coseLayout(options, spectralResult[index]));
}
});
}
} else {
Expand Down
42 changes: 40 additions & 2 deletions src/fcose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,47 @@ class Layout {
});
}
else{
let toBeTiledNodes = cy.collection();
if(options.tile){
let nodeIndexes = new Map();
let xCoords = [];
let yCoords = [];
let count = 0;
let tempSpectralResult = {nodeIndexes: nodeIndexes, xCoords: xCoords, yCoords: yCoords};
let indexesToBeDeleted = [];
components.forEach(function(component, index){
if(component.edges().length == 0){
component.nodes().forEach(function(node, i){
toBeTiledNodes.merge(component.nodes()[i]);
if(!node.isParent()){
tempSpectralResult.nodeIndexes.set(component.nodes()[i].id(), count++);
tempSpectralResult.xCoords.push(component.nodes()[0].position().x);
tempSpectralResult.yCoords.push(component.nodes()[0].position().y);
}
});
indexesToBeDeleted.push(index);
}
});
if(toBeTiledNodes.length > 1){
components.push(toBeTiledNodes);
for(let i = indexesToBeDeleted.length-1; i >= 0; i--){
components.splice(indexesToBeDeleted[i], 1);
spectralResult.splice(indexesToBeDeleted[i], 1);
};
spectralResult.push(tempSpectralResult);
}
}
components.forEach(function(component, index){
options.eles = component;
coseResult.push(coseLayout(options, spectralResult[index]));
if(options.tile){
if(!(component.edges().length == 0 && toBeTiledNodes.length == 1)){
options.eles = component;
coseResult.push(coseLayout(options, spectralResult[index]));
}
}
else{
options.eles = component;
coseResult.push(coseLayout(options, spectralResult[index]));
}
});
}
}
Expand Down

0 comments on commit 0d95400

Please sign in to comment.