Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
cytoscape-fcose
Advanced tools
The fCoSE layout for Cytoscape.js by Bilkent with fast compound node placement
The cytoscape-fcose package is an extension for Cytoscape.js that provides a layout algorithm for graph visualization. It is designed to handle large-scale graphs efficiently and offers features like compound nodes, multi-level nesting, and more.
Basic Layout
This code initializes a Cytoscape instance with a basic graph containing two nodes and one edge, and applies the fcose layout algorithm to it.
const cy = cytoscape({
container: document.getElementById('cy'),
elements: [
{ data: { id: 'a' } },
{ data: { id: 'b' } },
{ data: { id: 'ab', source: 'a', target: 'b' } }
],
style: [
{
selector: 'node',
style: {
'background-color': '#666',
'label': 'data(id)'
}
},
{
selector: 'edge',
style: {
'width': 3,
'line-color': '#ccc'
}
}
],
layout: {
name: 'fcose'
}
});
Compound Nodes
This code demonstrates the use of compound nodes, where nodes 'b' and 'c' are children of node 'a'. The fcose layout algorithm is applied to arrange the nodes.
const cy = cytoscape({
container: document.getElementById('cy'),
elements: [
{ data: { id: 'a' } },
{ data: { id: 'b', parent: 'a' } },
{ data: { id: 'c', parent: 'a' } },
{ data: { id: 'ab', source: 'b', target: 'c' } }
],
style: [
{
selector: 'node',
style: {
'background-color': '#666',
'label': 'data(id)'
}
},
{
selector: 'edge',
style: {
'width': 3,
'line-color': '#ccc'
}
}
],
layout: {
name: 'fcose'
}
});
Custom Layout Options
This code shows how to customize the fcose layout options, including setting the quality to 'proof', enabling randomization, and adding animation with a duration of 1000 milliseconds.
const cy = cytoscape({
container: document.getElementById('cy'),
elements: [
{ data: { id: 'a' } },
{ data: { id: 'b' } },
{ data: { id: 'ab', source: 'a', target: 'b' } }
],
style: [
{
selector: 'node',
style: {
'background-color': '#666',
'label': 'data(id)'
}
},
{
selector: 'edge',
style: {
'width': 3,
'line-color': '#ccc'
}
}
],
layout: {
name: 'fcose',
quality: 'proof',
randomize: true,
animate: true,
animationDuration: 1000
}
});
The cytoscape-cola package provides a layout algorithm based on the Cola.js library, which is also designed for handling large-scale graphs. It offers features like constraint-based layout and support for compound nodes. Compared to cytoscape-fcose, it focuses more on constraint-based layouts and may offer different performance characteristics.
The cytoscape-dagre package provides a layout algorithm based on the Dagre library, which is optimized for directed acyclic graphs (DAGs). It is particularly useful for hierarchical layouts. While cytoscape-fcose is more general-purpose, cytoscape-dagre excels in scenarios where a clear hierarchical structure is needed.
The cytoscape-cose-bilkent package offers a layout algorithm similar to fcose but with different optimization strategies and performance characteristics. It is also designed for large-scale graphs and supports compound nodes. The main difference lies in the specific heuristics and optimizations used in the layout process.
fCoSE (fast Compound Spring Embedder) is a faster version of our earlier compound spring embedder algorithm named CoSE, implemented as a Cytoscape.js extension by i-Vis Lab in Bilkent University (demo, compound demo)
fCoSE layout algorithm combines the speed of spectral layout with the aesthetics of force-directed layout. fCoSE runs up to 10 times as fast as CoSE while achieving similar aesthetics. In addition, fCoSE supports varying (non-uniform) node dimensions similar to its predecessor CoSE.
Please cite the following when you use this layout until an fCoSE publication is available:
U. Dogrusoz, E. Giral, A. Cetintas, A. Civril, and E. Demir, "A Layout Algorithm For Undirected Compound Graphs", Information Sciences, 179, pp. 980-994, 2009.
A. Civril, M. Magdon-Ismail, and E. Bocek-Rivele, "SSDE: Fast Graph Drawing Using Sampled Spectral Distance Embedding", International Symposium on Graph Drawing, pp. 30-41, 2006.
Download the library:
npm install cytoscape-fcose
,bower install cytoscape-fcose
, orImport the library as appropriate for your project:
ES import:
import cytoscape from 'cytoscape';
import fcose from 'cytoscape-fcose';
cytoscape.use( fcose );
CommonJS require:
let cytoscape = require('cytoscape');
let fcose = require('cytoscape-fcose');
cytoscape.use( fcose ); // register extension
AMD:
require(['cytoscape', 'cytoscape-fcose'], function( cytoscape, fcose ){
fcose( cytoscape ); // register extension
});
Plain HTML/JS has the extension registered for you automatically, because no require()
is needed. Just add the following files:
<script src="https://unpkg.com/numeric/numeric-1.2.6.js"></script>
<script src="https://unpkg.com/layout-base/layout-base.js"></script>
<script src="https://unpkg.com/cose-base/cose-base.js"></script>
<script src="cytoscape-fcose.js"></script>
When calling the layout, e.g. cy.layout({ name: 'fcose', ... })
, the following options are supported:
var defaultOptions = {
// 'draft', 'default' or 'proof'
// - "draft" only applies spectral layout
// - "default" improves the quality with incremental layout (fast cooling rate)
// - "proof" improves the quality with incremental layout (slow cooling rate)
quality: "default",
// Use random node positions at beginning of layout
// if this is set to false, then quality option must be "proof"
randomize: true,
// Whether or not to animate the layout
animate: true,
// Duration of animation in ms, if enabled
animationDuration: 1000,
// Easing of animation, if enabled
animationEasing: undefined,
// Fit the viewport to the repositioned nodes
fit: true,
// Padding around layout
padding: 30,
// Whether to include labels in node dimensions. Valid in "proof" quality
nodeDimensionsIncludeLabels: false,
// Whether or not simple nodes (non-compound nodes) are of uniform dimensions
uniformNodeDimensions: false,
// Whether to pack disconnected components - valid only if randomize: true
packComponents: true,
/* spectral layout options */
// False for random, true for greedy sampling
samplingType: true,
// Sample size to construct distance matrix
sampleSize: 25,
// Separation amount between nodes
nodeSeparation: 75,
// Power iteration tolerance
piTol: 0.0000001,
/* incremental layout options */
// Node repulsion (non overlapping) multiplier
nodeRepulsion: 4500,
// Ideal edge (non nested) length
idealEdgeLength: 50,
// Divisor to compute edge forces
edgeElasticity: 0.45,
// Nesting factor (multiplier) to compute ideal edge length for nested edges
nestingFactor: 0.1,
// Maximum number of iterations to perform
numIter: 2500,
// For enabling tiling
tile: true,
// Represents the amount of the vertical space to put between the zero degree members during the tiling operation(can also be a function)
tilingPaddingVertical: 10,
// Represents the amount of the horizontal space to put between the zero degree members during the tiling operation(can also be a function)
tilingPaddingHorizontal: 10,
// Gravity force (constant)
gravity: 0.25,
// Gravity range (constant) for compounds
gravityRangeCompound: 1.5,
// Gravity force (constant) for compounds
gravityCompound: 1.0,
// Gravity range (constant)
gravityRange: 3.8,
// Initial cooling factor for incremental layout
initialEnergyOnIncremental: 0.3,
/* layout event callbacks */
ready: () => {}, // on layoutready
stop: () => {} // on layoutstop
};
npm run test
: Run Mocha tests in ./test
npm run build
: Build ./src/**
into cytoscape-fcose.js
npm run watch
: Automatically build on changes with live reloading (N.b. you must already have an HTTP server running)npm run dev
: Automatically build on changes with live reloading with webpack dev servernpm run lint
: Run eslint on the sourceN.b. all builds use babel, so modern ES features can be used in the src
.
This project is set up to automatically be published to npm and bower. To publish:
npm run build:release
git commit -am "Build for release"
npm version major|minor|patch
git push && git push --tags
npm publish .
bower register cytoscape-fcose https://github.com/iVis-at-Bilkent/cytoscape.js-fcose.git
FAQs
The fCoSE layout for Cytoscape.js by Bilkent with fast compound node placement
The npm package cytoscape-fcose receives a total of 217,748 weekly downloads. As such, cytoscape-fcose popularity was classified as popular.
We found that cytoscape-fcose demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.