From 0d954003b4526e68a1422511614d702b1b0af074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Balc=C4=B1?= Date: Wed, 2 Oct 2019 17:21:42 +0300 Subject: [PATCH] Apply tiling to single nodes if packing is enabled --- cytoscape-fcose.js | 41 +++++++++++++++++++++++++++++++++++++++-- src/fcose/index.js | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/cytoscape-fcose.js b/cytoscape-fcose.js index c588430..88be0b7 100644 --- a/cytoscape-fcose.js +++ b/cytoscape-fcose.js @@ -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 { diff --git a/src/fcose/index.js b/src/fcose/index.js index b37b8d2..ab716d7 100644 --- a/src/fcose/index.js +++ b/src/fcose/index.js @@ -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])); + } }); } }