diagram-vue

A Vue 3 SVG-based diagram component library.
2,508 104
Install
npm install diagram-vue
Latest Version:0.4.0
Vue:3
Older releases:2
License:MIT
Last Updated:Aug 11, 2026
Links: GitHub  ·  npm
Maintainer: pb10005

diagram-vue

A Vue 3 SVG-based diagram component library.

npm version npm

Demo | Data Specification

Installation

npm install diagram-vue

Quick Start

Ready-to-use Editor (DiagramEditor)

The simplest way to get started. Includes toolbar, modals, import/export, and SVG download.

<template>
  <DiagramEditor v-model="graph" />
</template>

<script setup>
import { ref } from 'vue'
import { DiagramEditor } from 'diagram-vue'
import 'diagram-vue/dist/diagram.css'

const graph = ref({
  width: 1200,
  height: 800,
  background: '#f8fafc',
  showGrid: false,
  nodes: [],
  links: []
})
</script>
DiagramEditor Props
Prop Type Default Description
modelValue GraphData { width: 2000, height: 1000, nodes: [], links: [] } Graph data (use with v-model)
DiagramEditor Events
Event Payload Description
update:modelValue GraphData Emitted on any data change
nodeClicked string Clicked node ID
linkClicked string Clicked link ID
nodeRemoved string Removed node ID
linkRemoved string Removed link ID

Custom Implementation (Diagram)

Use the Diagram component directly for full control over editing logic.

<template>
  <Diagram
    :width="1200"
    :height="800"
    background="#f8fafc"
    :showGrid="false"
    scale="1"
    :fluid="false"
    :nodes="graph.nodes"
    :links="graph.links"
    :editable="editable"
    :labels="{
      edit: 'Edit',
      remove: 'Remove',
      link: 'Link',
      select: 'Select',
      cancel: 'Cancel',
      copy: 'Copy'
    }"
    @editNode="handleEditNode"
    @editLink="handleEditLink"
    @nodeClicked="handleNodeClicked"
    @linkClicked="handleLinkClicked"
    @nodeRemoved="handleNodeRemoved"
    @linkRemoved="handleLinkRemoved"
    @linkAdded="handleLinkAdded"
    @nodeCopied="handleNodeCopied"
  />
</template>

<script setup>
import { ref } from 'vue'
import { Diagram } from 'diagram-vue'
import 'diagram-vue/dist/diagram.css'

const editable = ref(false)
const graph = ref({ nodes: [], links: [] })

function handleEditNode(node) { /* open your edit modal */ }
function handleEditLink(link) { /* open your edit modal */ }
function handleNodeClicked(id) { console.log('node clicked:', id) }
function handleLinkClicked(id) { console.log('link clicked:', id) }
function handleNodeRemoved(id) {
  graph.value.nodes = graph.value.nodes.filter(n => n.id !== id)
}
function handleLinkRemoved(id) {
  graph.value.links = graph.value.links.filter(l => l.id !== id)
}
function handleLinkAdded(link) { graph.value.links.push(link) }
function handleNodeCopied(node) { graph.value.nodes.push(node) }
</script>
Diagram Props
Prop Type Default Description
width Number — Canvas width in pixels
height Number — Canvas height in pixels
scale String '1' Display scale ('0.5' / '1' / '1.5' / '2')
background String — Background color (hex or CSS color)
showGrid Boolean false Show dot grid
nodes DiagramNode[] — Array of node objects
links DiagramLink[] — Array of link objects
editable Boolean false Enable edit mode (drag, add links, etc.)
labels DiagramLabels — Button label strings
fluid Boolean false Stretch to fill container width
Diagram Events
Event Payload Description
editNode DiagramNode Edit button clicked on a node
editLink DiagramLink Edit button clicked on a link
nodeClicked string Node was clicked
linkClicked string Link was clicked
nodeRemoved string Node was deleted
linkRemoved string Link was deleted
linkAdded { id, source, destination, point } New link created between nodes
nodeCopied DiagramNode Node was duplicated

TypeScript Support

Type definitions are included. Import from the package source:

import type { GraphData, DiagramNode, DiagramLink, DiagramLabels } from 'diagram-vue/src/types'

See src/types.ts for the full interface definitions.


AI Agent Usage

AI agents can generate diagram data programmatically as JSON and pass it to DiagramEditor or Diagram.

Minimal valid graph

{
  "width": 1200,
  "height": 800,
  "background": "#f8fafc",
  "showGrid": false,
  "nodes": [
    {
      "id": "node1",
      "shape": "rectangle",
      "width": 150,
      "height": 60,
      "rx": 6,
      "ry": 6,
      "stroke": "#93c5fd",
      "strokeWeight": 1,
      "opacity": 1,
      "content": {
        "text": "Hello",
        "color": "#dbeafe",
        "fontColor": "#1e3a5f",
        "fontSize": 13,
        "fontWeight": "normal"
      },
      "point": { "x": 100, "y": 100 }
    }
  ],
  "links": []
}

Generating unique IDs

Node and link IDs must be unique strings. A simple approach:

const id = Date.now().toString(16) + Math.floor(Math.random() * 1e6).toString(16)

See DATA_SPECIFICATION.md for the complete JSON schema.


Get SVG as String

const svg = document.getElementById('svg-diagram-show-area').innerHTML

Development

npm install
npm run dev          # Start demo app (Vite dev server)
npm run build        # Build library to dist/
npm run build:app    # Build demo app
npm run test:unit    # Run unit tests
npm run lint         # Lint source files

Related Packages

vue-json-tree-view

a JSON Tree View Component in Vue.js

380,792 473
@v-c/picker

picker ui component for vue

57,185 32
vue-frame-crm

vue components for crm system

15,005
kokk

A beautiful way to create a documentation from markdown, and insert a vue compon...

10,142 49
vue-desktop

A UI library for building admin panel website.

4,851 540

Version History

Version Released Vue License
0.4.0 ^3.4.0 MIT
0.3.3 ^2.5.17 MIT
0.3.2 ^2.5.17 MIT
0.3.0 ^2.5.17 MIT
0.2.3 ^2.5.17 MIT