Cytoscape
by eserlan
Master Cytoscape.js for graph visualization, including Svelte 5 integration, sci-fi styling, custom layouts, and interaction patterns. Use when building relationship maps, node-link diagrams, or interactive network visualizations.
Skill Details
Repository Files
1 file in this skill directory
name: cytoscape description: Master Cytoscape.js for graph visualization, including Svelte 5 integration, sci-fi styling, custom layouts, and interaction patterns. Use when building relationship maps, node-link diagrams, or interactive network visualizations.
Cytoscape Graph Visualization
Master the art of creating high-performance, aesthetically striking network visualizations using Cytoscape.js, with a focus on Svelte 5 integration and the "Codex Arcana" sci-fi aesthetic.
Core Patterns
1. Svelte 5 Integration
Manage Cytoscape lifecycle and reactivity using Svelte 5 $effect and onMount.
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
import cytoscape, { type Core } from 'cytoscape';
let container: HTMLElement;
let cy: Core | undefined = $state();
let { elements } = $props();
onMount(() => {
cy = cytoscape({
container,
elements,
style: [ /* styles */ ],
layout: { name: 'cose' }
});
});
onDestroy(() => {
cy?.destroy();
});
// Reactive updates
$effect(() => {
if (cy && elements) {
cy.elements().remove();
cy.add(elements);
cy.layout({ name: 'cose', animate: true }).run();
}
});
</script>
<div bind:this={container} class="w-full h-full"></div>
2. Sci-Fi "Terminal" Styling
Embrace a high-contrast, glowing aesthetic. Use dark backgrounds with vibrant green or amber accents.
| Feature | Pattern |
|---|---|
| Node Shape | round-rectangle or diamond for sci-fi feel. |
| Node Label | Use text-valign: bottom and text-margin-y for a data-readout look. |
| Edge Style | bezier curves with triangle arrows. Keep lines thin and subtle. |
| Overlays | Use overlay-color and overlay-opacity for glowing selection effects. |
Example Sci-Fi Style:
const SCIFI_STYLE = [
{
selector: "node",
style: {
"background-color": "#022c22",
"border-width": 1,
"border-color": "#15803d",
label: "data(label)",
color: "#86efac",
"font-family": "Inter, monospace",
"font-size": 10,
"text-transform": "uppercase",
},
},
{
selector: "edge",
style: {
"line-color": "#14532d",
"target-arrow-shape": "triangle",
"curve-style": "bezier",
opacity: 0.6,
},
},
];
3. Layout Strategies
- Cose: Good for organic, balanced layouts.
- Circle/GridLayout: Use for structured overviews or specific groupings.
- Fcose/Cola: Advanced force-directed layouts for complex networks (require plugins).
- Manual: Use
metadata.coordinatesif entities have fixed positions.
Interaction Patterns
Selection & Focus
Animate the view when a node is selected to provide feedback.
cy.on("tap", "node", (evt) => {
const node = evt.target;
cy.animate({
center: { eles: node },
zoom: 1.5,
duration: 500,
easing: "ease-out-cubic",
});
});
Connection Management
Implement a "Connect Mode" to allow users to link nodes visually.
- Tap Source -> Tap Target -> Save relationship.
- Visual feedback via classes (e.g.,
.selected-source).
Performance Guidelines
- Batch Updates: Use
cy.batch()when performing many operations. - Selective Layouts: Only run layouts when elements change significantly, not on every prop update.
- Hardware Acceleration: Cytoscape uses Canvas, which is generally performant, but keep texture usage low.
Best Practices
- Lifecycle Management: Always
destroy()the instance inonDestroy. - Viewport Handling: Use
cy.fit()andcy.resize()to ensure the graph looks good on all screens. - Data Transformation: Use a separate
Transformerutility to map domain objects (Entities) to Cytoscape elements. - Overlay Elements: Use HTML/CSS overlays for UI (zoom controls, legends) instead of rendering them in the Canvas.
Related Skills
Attack Tree Construction
Build comprehensive attack trees to visualize threat paths. Use when mapping attack scenarios, identifying defense gaps, or communicating security risks to stakeholders.
Grafana Dashboards
Create and manage production Grafana dashboards for real-time visualization of system and application metrics. Use when building monitoring dashboards, visualizing metrics, or creating operational observability interfaces.
Matplotlib
Foundational plotting library. Create line plots, scatter, bar, histograms, heatmaps, 3D, subplots, export PNG/PDF/SVG, for scientific visualization and publication figures.
Scientific Visualization
Create publication figures with matplotlib/seaborn/plotly. Multi-panel layouts, error bars, significance markers, colorblind-safe, export PDF/EPS/TIFF, for journal-ready scientific plots.
Seaborn
Statistical visualization. Scatter, box, violin, heatmaps, pair plots, regression, correlation matrices, KDE, faceted plots, for exploratory analysis and publication figures.
Shap
Model interpretability and explainability using SHAP (SHapley Additive exPlanations). Use this skill when explaining machine learning model predictions, computing feature importance, generating SHAP plots (waterfall, beeswarm, bar, scatter, force, heatmap), debugging models, analyzing model bias or fairness, comparing models, or implementing explainable AI. Works with tree-based models (XGBoost, LightGBM, Random Forest), deep learning (TensorFlow, PyTorch), linear models, and any black-box model
Pydeseq2
Differential gene expression analysis (Python DESeq2). Identify DE genes from bulk RNA-seq counts, Wald tests, FDR correction, volcano/MA plots, for RNA-seq analysis.
Query Writing
For writing and executing SQL queries - from simple single-table queries to complex multi-table JOINs and aggregations
Pydeseq2
Differential gene expression analysis (Python DESeq2). Identify DE genes from bulk RNA-seq counts, Wald tests, FDR correction, volcano/MA plots, for RNA-seq analysis.
Scientific Visualization
Meta-skill for publication-ready figures. Use when creating journal submission figures requiring multi-panel layouts, significance annotations, error bars, colorblind-safe palettes, and specific journal formatting (Nature, Science, Cell). Orchestrates matplotlib/seaborn/plotly with publication styles. For quick exploration use seaborn or plotly directly.
