Cytoscape

by eserlan

skill

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.coordinates if 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

  1. Batch Updates: Use cy.batch() when performing many operations.
  2. Selective Layouts: Only run layouts when elements change significantly, not on every prop update.
  3. Hardware Acceleration: Cytoscape uses Canvas, which is generally performant, but keep texture usage low.

Best Practices

  1. Lifecycle Management: Always destroy() the instance in onDestroy.
  2. Viewport Handling: Use cy.fit() and cy.resize() to ensure the graph looks good on all screens.
  3. Data Transformation: Use a separate Transformer utility to map domain objects (Entities) to Cytoscape elements.
  4. 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.

skill

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.

skill

Matplotlib

Foundational plotting library. Create line plots, scatter, bar, histograms, heatmaps, 3D, subplots, export PNG/PDF/SVG, for scientific visualization and publication figures.

skill

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.

skill

Seaborn

Statistical visualization. Scatter, box, violin, heatmaps, pair plots, regression, correlation matrices, KDE, faceted plots, for exploratory analysis and publication figures.

skill

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

skill

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.

skill

Query Writing

For writing and executing SQL queries - from simple single-table queries to complex multi-table JOINs and aggregations

skill

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.

skill

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.

skill

Skill Information

Category:Skill
Last Updated:1/26/2026