CoSE-Bilkent Layout for Cytoscape.js

4.1.0 · active · verified Tue Apr 21

Cytoscape-cose-bilkent provides an advanced Compound Spring Embedder (CoSE) layout algorithm for the Cytoscape.js graph visualization library. Developed by the i-Vis Lab at Bilkent University, it is specifically designed to handle complex compound graphs with nested structures and supports non-uniform node dimensions, which is a key differentiator from simpler layout algorithms. The current stable version is 4.1.0. The package has seen performance improvements (e.g., v3.0.0) and architectural changes (v4.1.0) for better modularity. It maintains an active release cadence, primarily focusing on compatibility with Cytoscape.js and continuous improvements to its layout quality and speed. Its primary purpose is to produce aesthetically pleasing and readable layouts for graphs, particularly those with hierarchical or grouped components, by intelligently managing node repulsion, edge elasticity, and gravitational forces.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes a Cytoscape.js instance with a simple graph, including compound nodes, then registers and applies the `cose-bilkent` layout with common configuration options, demonstrating its ability to arrange nested structures.

import cytoscape from 'cytoscape';
import coseBilkent from 'cytoscape-cose-bilkent';

// Register the cose-bilkent layout extension with Cytoscape.js
cytoscape.use(coseBilkent);

const cy = cytoscape({
  container: document.getElementById('cy'), // Assumes a div with id='cy' exists
  elements: [
    { data: { id: 'a' } },
    { data: { id: 'b' } },
    { data: { id: 'c' } },
    { data: { id: 'parent1' } },
    { data: { id: 'd', parent: 'parent1' } },
    { data: { id: 'e', parent: 'parent1' } },
    { data: { id: 'f' } },
    { data: { id: 'ab', source: 'a', target: 'b' } },
    { data: { id: 'ac', source: 'a', target: 'c' } },
    { data: { id: 'ce', source: 'c', target: 'e' } },
    { data: { id: 'df', source: 'd', target: 'f' } },
  ],
  style: [
    {
      selector: 'node',
      style: {
        'background-color': '#11479e',
        'label': 'data(id)',
      },
    },
    {
      selector: 'node:parent',
      style: {
        'background-opacity': 0.3,
        'background-color': '#ccc',
      },
    },
    {
      selector: 'edge',
      style: {
        'width': 4,
        'line-color': '#9dbaea',
        'target-arrow-color': '#9dbaea',
        'target-arrow-shape': 'triangle',
        'curve-style': 'bezier',
      },
    },
  ],
  layout: {
    name: 'preset' // Initial layout, will be overridden by cose-bilkent
  }
});

// Apply the cose-bilkent layout
cy.layout({
  name: 'cose-bilkent',
  nodeDimensionsIncludeLabels: true,
  fit: true,
  padding: 20,
  randomize: true,
  nodeRepulsion: 4500,
  idealEdgeLength: 50,
  edgeElasticity: 0.45,
  nestingFactor: 0.1,
  gravity: 0.25,
  numIter: 2500,
  tile: true,
  animate: 'end',
  animationDuration: 500,
  quality: 'default' // 'draft', 'default', 'proof'
}).run();

view raw JSON →