Cytoscape Angular
October 5, 2025 ยท View on GitHub
Modern Angular 20+ component library for Cytoscape graph visualization
A production-ready Angular library providing sophisticated graph visualization capabilities using Cytoscape.js.
Check out the demo.
๐ Key Features
- ๐ฏ Modern Angular 20 - Built with the latest Angular features: signals, standalone components, and proper RxJS patterns
- ๐ Dynamic Forms - Sophisticated form system that automatically adapts based on graph layout type
- โก Signal-Based - Reactive state management using Angular signals for optimal performance
- ๐จ Material Design - Beautiful UI components using Angular Material
- ๐ช Type-Safe - Full TypeScript support with comprehensive type definitions
- ๐งช Well-Tested - Extensive test coverage with Jasmine and Karma
- ๐ข Production-Ready - Professional code patterns suitable for enterprise applications
๐ Technical Features
- Dynamic Form Generation - Forms that change based on configuration metadata (see
FluidFormComponent) - Signal-Based Architecture - Modern reactive patterns with Angular signals
- Standalone Components - Latest Angular architecture without NgModules
- Type-Safe Configuration - Self-describing components with type-safe metadata
- Professional Testing - Comprehensive unit and integration tests
๐ Quick Start
Installation
npm install cytoscape-angular cytoscape cytoscape-dagre
npm install @angular/material @angular/cdk
Basic Usage
import { Component, signal } from '@angular/core';
import {
CytoscapeGraphComponent,
CytoscapeGraphToolbarComponent,
GridLayoutOptions
} from 'cytoscape-angular';
@Component({
selector: 'app-root',
standalone: true,
imports: [CytoscapeGraphComponent, CytoscapeGraphToolbarComponent],
template: `
<cyng-cytoscape-graph
[nodes]="nodes()"
[edges]="edges()"
[layoutOptions]="layoutOptions()"
/>
<cyng-cytoscape-graph-toolbar
[(layoutOptions)]="layoutOptions"
[nodes]="nodes()"
[edges]="edges()"
/>
`
})
export class AppComponent {
nodes = signal([
{ data: { id: 'a', label: 'Node A' } },
{ data: { id: 'b', label: 'Node B' } }
]);
edges = signal([
{ data: { id: 'ab', source: 'a', target: 'b' } }
]);
layoutOptions = signal(new GridLayoutOptions());
}
๐ Components
CytoscapeGraphComponent
The main graph visualization component.
<cyng-cytoscape-graph
[nodes]="nodes()"
[edges]="edges()"
[style]="styles()"
[layoutOptions]="layout()"
[debug]="true"
(graphReady)="onReady($event)"
/>
Key Methods:
centerElements(selector: string)- Center elements matching selectorzoomToElement(selector: string, level?: number)- Zoom to specific elementgetCytoscapeInstance()- Get underlying Cytoscape instance
CytoscapeGraphToolbarComponent
Toolbar with layout and styling controls.
<cyng-cytoscape-graph-toolbar
[(layoutOptions)]="layoutOptions"
[(styles)]="styles"
[nodes]="nodes()"
[edges]="edges()"
[direction]="'row'"
(styleSelectorChange)="onSelectorChange($event)"
/>
CytoscapeLayoutToolComponent
Layout configuration with dynamic forms.
<cyng-cytoscape-layout-tool
[(layoutOptions)]="layoutOptions"
/>
Supported Layouts:
- Grid - Regular grid pattern
- Circle - Circular arrangement
- Concentric - Concentric circles
- Breadth-First - Hierarchical tree
- CoSE - Force-directed
- Dagre - Directed acyclic graph
- Random - Random positions
- Preset - Predefined positions
FluidFormComponent
Metadata-based Dynamic Forms ๐ฏ
A dynamic form generator that creates forms from metadata, driving the graph options for each graph type.
<cyng-fluid-form
[(model)]="layoutOptions"
[formInfo]="formInfo"
/>
Dynamic Form Fetures:
- Type-Safe - Infers field types from model
- Dynamic - Form changes based on configuration
- Reactive - Two-way binding with signals
- Validatable - Built-in validation support
- Conditional - Shows/hides fields based on model state
๐๏ธ Architecture
Uses Signals
// โ
Signals for state management
readonly nodes = signal<NodeDefinition[]>([]);
// โ
Computed values
readonly nodeCount = computed(() => this.nodes().length);
// โ
Signal-based inputs
readonly debug = input(false);
// โ
Model signals for two-way binding
readonly layoutOptions = model<LayoutOptions>({...});
// โ
ViewChild as signals
readonly graph = viewChild<CytoscapeGraphComponent>('graph');
RxJS Usage
// โ
takeUntilDestroyed for automatic cleanup
effect(() => {
this.http.get(url)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(...);
});
Standalone Architecture
@Component({
selector: 'cyng-graph',
standalone: true, // โ
No NgModules
imports: [CommonModule, MatButtonModule],
...
})
๐งช Testing
Run the comprehensive test suite:
# Test library
npm run test:lib
# Test demo
npm run test:demo
# CI mode with coverage
npm run test:ci
Test Coverage Includes:
- Component rendering
- Signal reactivity
- Form generation
- Graph interactions
- Layout algorithms
- Style application
๐ฆ Building
# Build library
npm run build
# Build production library
npm run build:prod
# Watch mode for development
npm run watch
๐จ Demo Application
Run the sophisticated demo showcasing all features:
npm start
Navigate to http://localhost:4200
Demo Features:
- Interactive TGF-ฮฒ biological pathway
- Real-time layout switching
- Dynamic form updates
- Professional styling
- Comprehensive examples
๐ข Production Ready
This library includes:
- โ Strict TypeScript configuration
- โ ESLint with Angular rules
- โ Comprehensive test coverage
- โ Production build optimization
- โ Tree-shakeable exports
- โ Proper error handling
- โ Accessibility support
- โ Documentation
๐ License
MIT License - see LICENSE file for details
๐จโ๐ป Author
Michael Bushe - Mindful Software
๐ Acknowledgments
- Cytoscape.js - Powerful graph visualization library
- Angular - Amazing framework
- Angular Material - Beautiful components
Built with โค๏ธ using Angular 20 by Michael Bushe of Mindful Software