Socket
Socket
Sign inDemoInstall

cytoscape-cose-bilkent

Package Overview
Dependencies
Maintainers
7
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cytoscape-cose-bilkent - npm Package Compare versions

Comparing version 2.1.0 to 3.0.0

nbproject/private/private.properties

12

gulpfile.js

@@ -19,3 +19,2 @@ var gulp = require('gulp');

var source = require('vinyl-source-stream');
var notifier = require('node-notifier');
var derequire = require('gulp-derequire');

@@ -56,8 +55,7 @@ var server = require('http-server');

return ( b
// can't use babel because cose-bilkent does just use pure functions in workers...
// .transform( babelify.configure({
// presets: ['es2015'],
// ignore: 'node_modules/**/*',
// sourceMaps: 'inline'
// }) )
.transform( babelify.configure({
presets: ['es2015'],
ignore: 'node_modules/**/*',
sourceMaps: 'inline'
}) )
) ;

@@ -64,0 +62,0 @@ };

{
"name": "cytoscape-cose-bilkent",
"version": "2.1.0",
"version": "3.0.0",
"description": "The CoSE layout for Cytoscape.js by Bilkent",

@@ -22,2 +22,5 @@ "main": "src/index.js",

"homepage": "https://github.com/cytoscape/cytoscape.js-cose-bilkent",
"dependencies": {
"linkedlist": "^1.0.1"
},
"devDependencies": {

@@ -24,0 +27,0 @@ "babel-preset-es2015": "^6.16.0",

@@ -7,3 +7,3 @@ cytoscape-cose-bilkent

The CoSE layout for Cytoscape.js by the [i-Vis group](http://cs.bilkent.edu.tr/~ivis/) in Bilkent University. Please cite the following when using this layout:
The CoSE layout for Cytoscape.js by the [i-Vis Lab](http://cs.bilkent.edu.tr/~ivis/) in Bilkent University. Please cite the following when using this layout:

@@ -14,3 +14,3 @@ U. Dogrusoz, E. Giral, A. Cetintas, A. Civril, and E. Demir, "[A Layout Algorithm For Undirected Compound Graphs](http://www.sciencedirect.com/science/article/pii/S0020025508004799)", Information Sciences, 179, pp. 980-994, 2009.

Click [here](https://rawgit.com/cytoscape/cytoscape.js-cose-bilkent/unstable/demo.html) (simple) or [here](https://rawgit.com/cytoscape/cytoscape.js-cose-bilkent/unstable/demo-compound.html) (compound) for demos
Click [here](https://rawgit.com/cytoscape/cytoscape.js-cose-bilkent/master/demo.html) (simple) or [here](https://rawgit.com/cytoscape/cytoscape.js-cose-bilkent/master/demo-compound.html) (compound) for demos

@@ -20,2 +20,3 @@ ## Dependencies

* Cytoscape.js ^2.4.0 || ^3.0.0
* Versions after 2.0.4 are not compatible with versions before Cytoscape.js 3.1.0

@@ -49,2 +50,3 @@

Please note that Cytoscape.js rendering option *styleEnabled* must be true, if layout is running in headless mode.

@@ -51,0 +53,0 @@ ## API

@@ -95,2 +95,3 @@ var FDLayout = require('./FDLayout');

this.calcIdealEdgeLengths();
if (!this.incremental)

@@ -102,3 +103,2 @@ {

if (forest.length > 0)
{

@@ -110,2 +110,4 @@ this.positionNodesRadially(forest);

{
// Reduce the trees when incremental mode is not enabled and graph is not a forest
this.reduceTrees();
this.positionNodesRandomly();

@@ -124,11 +126,21 @@ }

if (this.totalIterations === this.maxIterations) {
return true; // Layout is not ended return true
if (this.totalIterations === this.maxIterations && !this.isTreeGrowing && !this.isGrowthFinished) {
if(this.prunedNodesAll.length > 0){
this.isTreeGrowing = true;
}
else {
return true;
}
}
if (this.totalIterations % FDLayoutConstants.CONVERGENCE_CHECK_PERIOD == 0)
if (this.totalIterations % FDLayoutConstants.CONVERGENCE_CHECK_PERIOD == 0 && !this.isTreeGrowing && !this.isGrowthFinished)
{
if (this.isConverged())
{
return true; // Layout is not ended return true
if(this.prunedNodesAll.length > 0){
this.isTreeGrowing = true;
}
else {
return true;
}
}

@@ -139,4 +151,35 @@

this.animationPeriod = Math.ceil(this.initialAnimationPeriod * Math.sqrt(this.coolingFactor));
}
// Operations while tree is growing again
if(this.isTreeGrowing){
if(this.growTreeIterations % 10 == 0){
if(this.prunedNodesAll.length > 0) {
this.graphManager.updateBounds();
this.updateGrid();
this.growTree(this.prunedNodesAll, this.isFirstGrowth);
this.graphManager.updateBounds();
this.updateGrid();
this.coolingFactor = FDLayoutConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL;
}
else {
this.isTreeGrowing = false;
this.isGrowthFinished = true;
}
}
this.growTreeIterations++;
}
// Operations after growth is finished
if(this.isGrowthFinished){
if (this.isConverged())
{
return true;
}
if(this.afterGrowthIterations % 10 == 0){
this.graphManager.updateBounds();
this.updateGrid();
}
this.coolingFactor = FDLayoutConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL * ((100 - this.afterGrowthIterations) / 100);
this.afterGrowthIterations++;
}
this.totalDisplacement = 0;

@@ -217,3 +260,3 @@ this.graphManager.updateBounds();

for(i = 0; i < allNodes.length; i++)
for(var i = 0; i < allNodes.length; i++)
{

@@ -223,3 +266,3 @@ node = allNodes[i];

}
}
};

@@ -226,0 +269,0 @@ CoSELayout.prototype.createBendpoints = function () {

@@ -6,3 +6,3 @@ var Layout = require('./Layout');

var IMath = require('./IMath');
var HashSet = require('./HashSet');
var Integer = require('./Integer');

@@ -52,2 +52,10 @@ function FDLayout() {

this.useFRGridVariant = FDLayoutConstants.DEFAULT_USE_SMART_REPULSION_RANGE_CALCULATION;
this.grid = [];
// variables for tree reduction support
this.prunedNodesAll = [];
this.growTreeIterations = 0;
this.afterGrowthIterations = 0;
this.isTreeGrowing = false;
this.isGrowthFinished = false;
};

@@ -138,15 +146,8 @@

{
if (this.totalIterations % FDLayoutConstants.GRID_CALCULATION_CHECK_PERIOD == 1)
{
var grid = this.calcGrid(this.graphManager.getRoot());
// put all nodes to proper grid cells
for (i = 0; i < lNodes.length; i++)
{
nodeA = lNodes[i];
this.addNodeToGrid(nodeA, grid, this.graphManager.getRoot().getLeft(), this.graphManager.getRoot().getTop());
}
if ((this.totalIterations % FDLayoutConstants.GRID_CALCULATION_CHECK_PERIOD == 1 && !this.isTreeGrowing && !this.isGrowthFinished))
{
this.updateGrid();
}
processedNodeSet = new HashSet();
processedNodeSet = new Set();

@@ -157,10 +158,8 @@ // calculate repulsion forces between each nodes and its surrounding

nodeA = lNodes[i];
this.calculateRepulsionForceOfANode(grid, nodeA, processedNodeSet);
this.calculateRepulsionForceOfANode(nodeA, processedNodeSet);
processedNodeSet.add(nodeA);
}
}
else
{
for (i = 0; i < lNodes.length; i++)

@@ -188,7 +187,10 @@ {

var node;
var allNodes = new Set(this.getAllNodes());
var lNodes = this.getAllNodesToApplyGravitation();
var intersection = lNodes.filter(x => allNodes.has(x));
for (var i = 0; i < lNodes.length; i++)
for (var i = 0; i < intersection.length; i++)
{
node = lNodes[i];
node = intersection[i];
this.calcGravitationalForce(node);

@@ -431,3 +433,3 @@ }

FDLayout.prototype.addNodeToGrid = function (v, grid, left, top){
FDLayout.prototype.addNodeToGrid = function (v, left, top){

@@ -448,3 +450,3 @@ var startX = 0;

{
grid[i][j].push(v);
this.grid[i][j].push(v);
v.setGridCoordinates(startX, finishX, startY, finishY);

@@ -456,9 +458,26 @@ }

FDLayout.prototype.calculateRepulsionForceOfANode = function (grid, nodeA, processedNodeSet){
FDLayout.prototype.updateGrid = function() {
var i;
var nodeA;
var lNodes = this.getAllNodes();
if (this.totalIterations % FDLayoutConstants.GRID_CALCULATION_CHECK_PERIOD == 1)
this.grid = this.calcGrid(this.graphManager.getRoot());
// put all nodes to proper grid cells
for (i = 0; i < lNodes.length; i++)
{
var surrounding = new HashSet();
nodeA = lNodes[i];
this.addNodeToGrid(nodeA, this.graphManager.getRoot().getLeft(), this.graphManager.getRoot().getTop());
}
};
FDLayout.prototype.calculateRepulsionForceOfANode = function (nodeA, processedNodeSet){
if ((this.totalIterations % FDLayoutConstants.GRID_CALCULATION_CHECK_PERIOD == 1 && !this.isTreeGrowing && !this.isGrowthFinished) || (this.growTreeIterations % 10 == 1 && this.isTreeGrowing) || (this.afterGrowthIterations % 10 == 1 && this.isGrowthFinished))
{
var surrounding = new Set();
nodeA.surrounding = new Array();
var nodeB;
var grid = this.grid;

@@ -483,3 +502,3 @@ for (var i = (nodeA.startX - 1); i < (nodeA.finishX + 2); i++)

// nodeA and nodeB has already been calculated
if (!processedNodeSet.contains(nodeB) && !surrounding.contains(nodeB))
if (!processedNodeSet.has(nodeB) && !surrounding.has(nodeB))
{

@@ -504,3 +523,3 @@ var distanceX = Math.abs(nodeA.getCenterX()-nodeB.getCenterX()) -

surrounding.addAllTo(nodeA.surrounding);
nodeA.surrounding = [...surrounding];

@@ -518,2 +537,210 @@ }

// -----------------------------------------------------------------------------
// Section: Tree Reduction methods
// -----------------------------------------------------------------------------
// Reduce trees
FDLayout.prototype.reduceTrees = function ()
{
var prunedNodesAll = [];
var containsLeaf = true;
var node;
while(containsLeaf) {
var allNodes = this.graphManager.getAllNodes();
var prunedNodesInStepTemp = [];
containsLeaf = false;
for (var i = 0; i < allNodes.length; i++) {
node = allNodes[i];
if(node.getEdges().length == 1 && !node.getEdges()[0].isInterGraph && node.getChild() == null){
prunedNodesInStepTemp.push([node, node.getEdges()[0], node.getOwner()]);
containsLeaf = true;
}
}
if(containsLeaf == true){
var prunedNodesInStep = [];
for(var j = 0; j < prunedNodesInStepTemp.length; j++){
if(prunedNodesInStepTemp[j][0].getEdges().length == 1){
prunedNodesInStep.push(prunedNodesInStepTemp[j]);
prunedNodesInStepTemp[j][0].getOwner().remove(prunedNodesInStepTemp[j][0]);
}
}
prunedNodesAll.push(prunedNodesInStep);
this.graphManager.resetAllNodes();
this.graphManager.resetAllEdges();
}
}
this.prunedNodesAll = prunedNodesAll;
};
// Grow tree one step
FDLayout.prototype.growTree = function(prunedNodesAll, isFirstGrowth)
{
var lengthOfPrunedNodesInStep = prunedNodesAll.length;
var prunedNodesInStep = prunedNodesAll[lengthOfPrunedNodesInStep - 1];
var nodeData;
for(var i = 0; i < prunedNodesInStep.length; i++){
nodeData = prunedNodesInStep[i];
this.findPlaceforPrunedNode(nodeData);
nodeData[2].add(nodeData[0]);
nodeData[2].add(nodeData[1], nodeData[1].source, nodeData[1].target);
}
prunedNodesAll.splice(prunedNodesAll.length-1, 1);
this.graphManager.resetAllNodes();
this.graphManager.resetAllEdges();
};
// Find an appropriate position to replace pruned node, this method can be improved
FDLayout.prototype.findPlaceforPrunedNode = function(nodeData){
var gridForPrunedNode;
var nodeToConnect;
var prunedNode = nodeData[0];
if(prunedNode == nodeData[1].source){
nodeToConnect = nodeData[1].target;
}
else {
nodeToConnect = nodeData[1].source;
}
var startGridX = nodeToConnect.startX;
var finishGridX = nodeToConnect.finishX;
var startGridY = nodeToConnect.startY;
var finishGridY = nodeToConnect.finishY;
var upNodeCount = 0;
var downNodeCount = 0;
var rightNodeCount = 0;
var leftNodeCount = 0;
var controlRegions = [upNodeCount, rightNodeCount, downNodeCount, leftNodeCount]
if(startGridY > 0){
for(var i = startGridX; i <= finishGridX; i++ ){
controlRegions[0] += (this.grid[i][startGridY - 1].length + this.grid[i][startGridY].length - 1);
}
}
if(finishGridX < this.grid.length - 1){
for(var i = startGridY; i <= finishGridY; i++ ){
controlRegions[1] += (this.grid[finishGridX + 1][i].length + this.grid[finishGridX][i].length - 1);
}
}
if(finishGridY < this.grid[0].length - 1){
for(var i = startGridX; i <= finishGridX; i++ ){
controlRegions[2] += (this.grid[i][finishGridY + 1].length + this.grid[i][finishGridY].length - 1);
}
}
if(startGridX > 0){
for(var i = startGridY; i <= finishGridY; i++ ){
controlRegions[3] += (this.grid[startGridX - 1][i].length + this.grid[startGridX][i].length - 1);
}
}
var min = Integer.MAX_VALUE;
var minCount;
var minIndex;
for(var j = 0; j < controlRegions.length; j++){
if(controlRegions[j] < min){
min = controlRegions[j];
minCount = 1;
minIndex = j;
}
else if(controlRegions[j] == min){
minCount++;
}
}
if(minCount == 3 && min == 0){
if(controlRegions[0] == 0 && controlRegions[1] == 0 && controlRegions[2] == 0){
gridForPrunedNode = 1;
}
else if(controlRegions[0] == 0 && controlRegions[1] == 0 && controlRegions[3] == 0){
gridForPrunedNode = 0;
}
else if(controlRegions[0] == 0 && controlRegions[2] == 0 && controlRegions[3] == 0){
gridForPrunedNode = 3;
}
else if(controlRegions[1] == 0 && controlRegions[2] == 0 && controlRegions[3] == 0){
gridForPrunedNode = 2;
}
}
else if(minCount == 2 && min == 0){
var random = Math.floor(Math.random() * 2);
if(controlRegions[0] == 0 && controlRegions[1] == 0){;
if(random == 0){
gridForPrunedNode = 0;
}
else{
gridForPrunedNode = 1;
}
}
else if(controlRegions[0] == 0 && controlRegions[2] == 0){
if(random == 0){
gridForPrunedNode = 0;
}
else{
gridForPrunedNode = 2;
}
}
else if(controlRegions[0] == 0 && controlRegions[3] == 0){
if(random == 0){
gridForPrunedNode = 0;
}
else{
gridForPrunedNode = 3;
}
}
else if(controlRegions[1] == 0 && controlRegions[2] == 0){
if(random == 0){
gridForPrunedNode = 1;
}
else{
gridForPrunedNode = 2;
}
}
else if(controlRegions[1] == 0 && controlRegions[3] == 0){
if(random == 0){
gridForPrunedNode = 1;
}
else{
gridForPrunedNode = 3;
}
}
else {
if(random == 0){
gridForPrunedNode = 2;
}
else{
gridForPrunedNode = 3;
}
}
}
else if(minCount == 4 && min == 0){
var random = Math.floor(Math.random() * 4);
gridForPrunedNode = random;
}
else {
gridForPrunedNode = minIndex;
}
if(gridForPrunedNode == 0) {
prunedNode.setCenter(nodeToConnect.getCenterX(),
nodeToConnect.getCenterY() - nodeToConnect.getHeight()/2 - FDLayoutConstants.DEFAULT_EDGE_LENGTH - prunedNode.getHeight()/2);
}
else if(gridForPrunedNode == 1) {
prunedNode.setCenter(nodeToConnect.getCenterX() + nodeToConnect.getWidth()/2 + FDLayoutConstants.DEFAULT_EDGE_LENGTH + prunedNode.getWidth()/2,
nodeToConnect.getCenterY());
}
else if(gridForPrunedNode == 2) {
prunedNode.setCenter(nodeToConnect.getCenterX(),
nodeToConnect.getCenterY() + nodeToConnect.getHeight()/2 + FDLayoutConstants.DEFAULT_EDGE_LENGTH + prunedNode.getHeight()/2);
}
else {
prunedNode.setCenter(nodeToConnect.getCenterX() - nodeToConnect.getWidth()/2 - FDLayoutConstants.DEFAULT_EDGE_LENGTH - prunedNode.getWidth()/2,
nodeToConnect.getCenterY());
}
};
module.exports = FDLayout;

@@ -22,3 +22,3 @@ var LayoutConstants = require('./LayoutConstants');

FDLayoutConstants.DEFAULT_USE_SMART_REPULSION_RANGE_CALCULATION = true;
FDLayoutConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL = 0.8;
FDLayoutConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL = 0.5;
FDLayoutConstants.MAX_NODE_DISPLACEMENT_INCREMENTAL = 100.0;

@@ -25,0 +25,0 @@ FDLayoutConstants.MAX_NODE_DISPLACEMENT = FDLayoutConstants.MAX_NODE_DISPLACEMENT_INCREMENTAL * 3;

@@ -79,3 +79,3 @@ 'use strict';

// Initial cooling factor for incremental layout
initialEnergyOnIncremental: 0.8
initialEnergyOnIncremental: 0.5
};

@@ -143,2 +143,4 @@

self.stopped = false;
this.cy = this.options.cy;

@@ -162,4 +164,6 @@

var targetNode = this.idToLNode[edge.data("target")];
var e1 = gm.add(layout.newEdge(), sourceNode, targetNode);
e1.id = edge.id();
if(sourceNode.getEdgesBetween(targetNode).length == 0){
var e1 = gm.add(layout.newEdge(), sourceNode, targetNode);
e1.id = edge.id();
}
}

@@ -201,3 +205,3 @@

for( var i = 0; i < ticksPerFrame && !isDone; i++ ){
isDone = self.layout.tick();
isDone = self.stopped || self.layout.tick();
}

@@ -251,7 +255,18 @@

temp = temp.parent()[0];
if(temp == undefined){
break;
}
}
return {
x: pNode.x,
y: pNode.y
};
if(pNode != null){
return {
x: pNode.x,
y: pNode.y
};
}
else{
return {
x: ele.x,
y: ele.y
};
}
});

@@ -278,9 +293,3 @@

*/
if(this.options.animate == 'end'){
setTimeout(function() {
self.options.eles.nodes().not(":parent").layoutPositions(self, self.options, getPositions); // Use layout positions to reposition the nodes it considers the options parameter
ready = false;
}, 0);
}
else if(this.options.animate == false){
if(this.options.animate !== "during"){
self.options.eles.nodes().not(":parent").layoutPositions(self, self.options, getPositions); // Use layout positions to reposition the nodes it considers the options parameter

@@ -320,3 +329,2 @@ ready = false;

var theChild = children[i];
this.options.eles.nodes().length;
var children_of_children = theChild.children();

@@ -382,4 +390,2 @@ var theNode;

this.stopped = true;
this.trigger('layoutstop');

@@ -386,0 +392,0 @@ return this; // chaining

@@ -264,5 +264,5 @@ var LayoutConstants = require('./LayoutConstants');

this.layoutQuality = LayoutConstants.DEFAULT_QUALITY;
this.animationDuringLayout = LayoutConstants.DEFAULT_ANIMATION_ON_LAYOUT;
this.animationDuringLayout = LayoutConstants.DEFAULT_ANIMATION_DURING_LAYOUT;
this.animationPeriod = LayoutConstants.DEFAULT_ANIMATION_PERIOD;
this.animationOnLayout = LayoutConstants.DEFAULT_ANIMATION_DURING_LAYOUT;
this.animationOnLayout = LayoutConstants.DEFAULT_ANIMATION_ON_LAYOUT;
this.incremental = LayoutConstants.DEFAULT_INCREMENTAL;

@@ -275,3 +275,3 @@ this.createBendsAsNeeded = LayoutConstants.DEFAULT_CREATE_BENDS_AS_NEEDED;

{
animationOnLayout = false;
this.animationOnLayout = false;
}

@@ -278,0 +278,0 @@ };

@@ -10,2 +10,3 @@ var LGraphObject = require('./LGraphObject');

var Point = require('./Point');
var LinkedList = require('linkedlist');

@@ -420,3 +421,3 @@ function LGraph(parent, obj2, vGraph) {

var toBeVisited = [];
var toBeVisited = new LinkedList();
var visited = new HashSet();

@@ -426,3 +427,6 @@ var currentNode = this.nodes[0];

var currentNeighbor;
toBeVisited = toBeVisited.concat(currentNode.withChildren());
var childrenOfNode = currentNode.withChildren();
childrenOfNode.forEach(function(node) {
toBeVisited.push(node);
});

@@ -447,3 +451,7 @@ while (toBeVisited.length > 0)

{
toBeVisited = toBeVisited.concat(currentNeighbor.withChildren());
var childrenOfNeighbor = currentNeighbor.withChildren();
childrenOfNeighbor.forEach(function(node) {
toBeVisited.push(node);
});
}

@@ -450,0 +458,0 @@ }

@@ -50,7 +50,7 @@ var LGraphObject = require('./LGraphObject');

{
if (this.owner != null) {
if (!(this.owner == null || this.owner.getNodes().indexOf(this) > -1)) {
throw "assert failed";
}
}
// if (this.owner != null) {
// if (!(this.owner == null || this.owner.getNodes().indexOf(this) > -1)) {
// throw "assert failed";
// }
// }

@@ -205,6 +205,7 @@ return this.owner;

{
var withNeighborsList = [];
var withNeighborsList = new Set();
var childNode;
var children;
withNeighborsList.push(this);
withNeighborsList.add(this);

@@ -217,4 +218,6 @@ if (this.child != null)

childNode = nodes[i];
withNeighborsList = withNeighborsList.concat(childNode.withChildren());
children = childNode.withChildren();
children.forEach(function(node) {
withNeighborsList.add(node);
});
}

@@ -221,0 +224,0 @@ }

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc