Registry / web-framework / vue-cytoscape

vue-cytoscape

JSON →
library1.0.8jsnpmunverified

vue-cytoscape is a Vue.js component library that provides declarative integration with the powerful Cytoscape.js graph visualization library. It allows developers to build interactive graph UIs using Vue components like <VueCytoscape>, <CyNode>, and <CyEdge>. The current stable version is 1.0.8, with recent updates (v1.0.7) focusing on reactivity for element data and positions. While no explicit release cadence is documented, the changelog indicates active development and feature improvements across minor versions. Key differentiators include first-class TypeScript support, the ability to manage multiple independent Cytoscape instances within a Vue application, and a Vue-idiomatic v-on directive events API for handling graph interactions. The library transitioned significantly in v1.x from direct instance access and configuration-based element creation to a more robust, component-based approach, leveraging Vue's reactivity system effectively.

npm install vue-cytoscape
INSTALL
IMPORT
SIG · VUE-CYTOSCAPE
V
vue-cytoscape
web-frameworkjavascriptv1.0.8
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

VueCytoscape
import { VueCytoscape } from 'vue-cytoscape'
import VueCytoscape from 'vue-cytoscape'
The primary component for rendering Cytoscape instances. It is a named export, not a default export.
CyNode
import { CyNode } from 'vue-cytoscape'
import { Node } from 'vue-cytoscape'
Component for declaratively defining individual graph nodes within the VueCytoscape component. Ensure correct casing.
CyEdge
import { CyEdge } from 'vue-cytoscape'
import { Edge } from 'vue-cytoscape'
Component for declaratively defining graph edges, typically used alongside CyNode components.
Cytoscape Core Type
import type { Core } from 'cytoscape'
For type-hinting the Cytoscape core instance, especially when using lifecycle hooks like `afterCreated`.

This quickstart demonstrates how to set up a basic Vue 3 application using vue-cytoscape, rendering a graph with two nodes and one edge. It showcases the component-based approach using <CyNode> and <CyEdge> for elements, custom styling, and how to access the Cytoscape core instance via the afterCreated lifecycle hook to register event listeners.

<script setup lang="ts"> import { ref, onMounted } from 'vue'; import { VueCytoscape, CyNode, CyEdge } from 'vue-cytoscape'; import type { Core } from 'cytoscape'; const cyRef = ref<Core | null>(null); const elements = ref([ { data: { id: 'one', label: 'Node 1' }, position: { x: 0, y: 0 } }, { data: { id: 'two', label: 'Node 2' }, position: { x: 100, y: 0 } }, { data: { source: 'one', target: 'two', label: 'Edge 1-2' } } ]); const afterCreated = (cy: Core) => { cyRef.value = cy; console.log('Cytoscape instance created:', cy); cy.on('tap', 'node', (evt) => { const node = evt.target; console.log('Tapped on node:', node.id()); }); }; onMounted(() => { if (cyRef.value) { console.log('Current Cytoscape instance:', cyRef.value); } }); </script> <template> <div style="width: 100%; height: 400px; border: 1px solid #ccc;"> <VueCytoscape :config="{ style: [{ selector: 'node', style: { 'label': 'data(label)' } }, { selector: 'edge', style: { 'label': 'data(label)', 'curve-style': 'bezier', 'target-arrow-shape': 'triangle' } }] }" @afterCreated="afterCreated" > <CyNode v-for="node in elements.filter(el => !el.data.source)" :key="node.data.id" :id="node.data.id" :position="node.position" :data="node.data" /> <CyEdge v-for="edge in elements.filter(el => el.data.source)" :key="`${edge.data.source}-${edge.data.target}`" :source="edge.data.source" :target="edge.data.target" :data="edge.data" /> </VueCytoscape> </div> </template>
Debug
Known issues
breakingDirect access to the Cytoscape instance via `this.$cytoscape.instance` has been removed in v1.x.
fix
Use the 'afterCreated' lifecycle hook on the `<VueCytoscape>` component to obtain and store the Cytoscape core instance. This instance should then be passed explicitly to any child components or methods that require it.
affects: >=1.0.0
breakingCreating graph elements by passing a `config.elements` array directly to the `<VueCytoscape>` component is discouraged in v1.x.
fix
Migrate to the component-based API by using `<CyNode>` and `<CyEdge>` as children of `<VueCytoscape>` for declarative element management. This approach leverages Vue's reactivity system more effectively.
affects: >=1.0.0
breakingDOM reflection capabilities, which automatically synchronized direct Cytoscape instance changes back to Vue components, were removed in v1.x.
fix
Ensure all graph element mutations (additions, removals, updates) are managed through the `<CyNode>` and `<CyEdge>` components to leverage Vue's reactivity system. Direct manipulation of the Cytoscape instance will no longer automatically update the Vue component state or UI.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'instance')
Attempting to access the deprecated `this.$cytoscape.instance` property from a Vue component method or lifecycle hook in v1.x.
fix
Pass the Cytoscape core instance received in the `afterCreated` hook to child components or methods that need it. The instance is no longer globally accessible via `$cytoscape.instance`.
[Vue warn]: Failed to resolve component: cy-node
The `<CyNode>` or `<CyEdge>` components are not correctly imported or registered in the Vue component where they are being used, or are misspelled.
fix
Ensure `import { CyNode, CyEdge } from 'vue-cytoscape'` is present in your script block and the components are correctly used within the template with proper casing.
Graph elements not appearing or not reactive after direct Cytoscape manipulation.
Modifying graph elements directly via the Cytoscape core instance (e.g., `cy.add()`, `cy.$('#id').remove()`) without using the `<CyNode>` or `<CyEdge>` components, which no longer trigger DOM reflection in v1.x.
fix
Always manage graph elements (nodes and edges) through the `<CyNode>` and `<CyEdge>` components within the `<VueCytoscape>` component to ensure changes are reactive and reflected in the Vue component tree.
Upgrade
Version history
1.0.8latest on npm
Audit
Dependencies
cytoscaperequiredRuntime dependency for the core graph visualization engine.
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
vue-cytoscape — npm install vue-cytoscape · libregistry