Home

Awesome

Flowchart

Flowchart & Flowchart designer component for Vue.js(flowchart-react for React.js).

NPM

<img width="801" alt="image" src="https://user-images.githubusercontent.com/5696485/156284211-1bd18756-d785-440a-8292-4fdeb89fca5b.png">

Usage

yarn add flowchart-vue
<template>
    <div id="app">
        <button type="button" @click="$refs.chart.add({id: +new Date(), x: 10, y: 10, name: 'New', type: 'operation', approvers: []})">
            Add
        </button>
        <button type="button" @click="$refs.chart.remove()">
            Del
        </button>
        <button type="button" @click="$refs.chart.editCurrent()">
            Edit
        </button>
        <button type="button" @click="$refs.chart.save()">
            Save
        </button>
        <button type="button" v-if="showRemovingConfirmation" @click="confirmRemoving">
            Confirm removing
        </button>
        <button type="button" v-if="showRemovingConfirmation" @click="showRemovingConfirmation = false">
            Reject removing
        </button>
        <flowchart :nodes="nodes" 
                   :connections="connections" 
                   :remove-requires-confirmation="true"
                   @editnode="handleEditNode"
                   @dblclick="handleDblClick" 
                   @editconnection="handleEditConnection"
                   @removeconfirmationrequired="initRemovingConfirmation"
                   @save="handleChartSave" ref="chart">
        </flowchart>
    </div>
</template>
<script>
  import Vue from 'vue';
  import FlowChart from 'flowchart-vue';

  Vue.use(FlowChart);

  export default {
    name: 'App',
    data: function() {
      return {
        nodes: [
          // Basic fields
          {id: 1, x: 140, y: 270, name: 'Start', type: 'start'},
          // You can add any generic fields to node, for example: description
          // It will be passed to @save, @editnode
          {id: 2, x: 540, y: 270, name: 'End', type: 'end', description: 'I\'m here'},
        ],
        connections: [
          {
            source: {id: 1, position: 'right'},
            destination: {id: 2, position: 'left'},
            id: 1,
            type: 'pass',
          },
        ],
        showRemovingConfirmation: false,
      };
    },
    methods: {
      handleChartSave(nodes, connections) {
        // axios.post(url, {nodes, connections}).then(resp => {
        //   this.nodes = resp.data.nodes;
        //   this.connections = resp.data.connections;
        //   // Flowchart will refresh after this.nodes and this.connections changed
        // });
      },
      handleEditNode(node) {
        if (node.id === 2) {
          console.log(node.description);
        }
      },
      handleEditConnection(connection) {
      },
      handleDblClick(position) {
        this.$refs.chart.add({
          id: +new Date(),
          x: position.x,
          y: position.y,
          name: 'New',
          type: 'operation',
          approvers: [],
        });
      },
      initRemovingConfirmation() {
        this.showRemovingConfirmation = true;
      },
      confirmRemoving() {
        this.$refs.chart.confirmRemove();
        this.showRemovingConfirmation = false;
      }
    }
  };
</script>

See more at src/views/App.vue.

Demo

API

Props

PropertyDescriptionTypeDefault
nodesCollection of nodesArray[{id: 1, x: 140, y: 270, name: 'Start', type: 'start'}, {id: 2, x: 540, y: 270, name: 'End', type: 'end'}]
connectionsCollection of connectionsArray[{source: {id: 1, position: 'right'}, destination: {id: 2, position: 'left'}, id: 1, type: 'pass', }]
widthWidth of canvasString | Number800
heightHeight of canvasString | Number600
localeDisplay language, available values: 'en', 'zh'String'en'
readonlyRead-onlyBooleanfalse
renderCustom render functionnull
readOnlyPermissionsAllows to specify more granular read-only mode permissionsObject{ allowDragNodes: false, allowSave: false, allowAddNodes: false, allowEditNodes: false, allowEditConnections: false, allowDblClick: false, allowRemove: false }

Events

EventDescriptionHandler
editnodeNode double-click event(node) => void
editconnectionConnection double-click event(connection) => void
saveSave event(nodes, connections) => void
dblclickBackground double-click event(position: {x: number, y: number}) => void
connectConnect event(connection, nodes, connections) => void
disconnectDisconnect event(connection, nodes, connections) => void
addAdd node event(node, nodes, connections) => void
deleteDelete node event(node, nodes, connections) => void
selectSelect node eventnodes => void
selectconnectionSelect connection eventconnections => void
renderNode render event, children is a collection of svg elements(node: Node, children: { header, title, body, content }) => vod
nodesdraggedNotifies which nodes dragging just ended(nodes) => void
removeConfirmationRequiredNotifies that remove confirmation required. Pass nodes and connections selected to remove(nodes, connections) => void
movediffNotifies about change in chart view position(diff: {x: number, y: number}) => void

Properties.Node

PropertyDescription        TypeDefault
idIDNumber+new Date()
xHorizontal position of nodeNumber-
yVertical position of nodeNumber-
typeType of nodeString'operation'
widthWidth of nodeNumber120
heightHeight of nodeNumber60
approversApprovers of node, eg: [{name: 'admin'}]Array[]
connectorsDefines which connectors should be renderedArray['top', 'right', 'bottom', 'left']
themeDefines colors for specified node elementsObject{ borderColor: "#bbbbbb", borderColorSelected: "#666666", headerTextColor: "black", headerBackgroundColor: "#f1f3f4", bodyBackgroundColor: "white", bodyTextColor: "black" }

Properties.Connection

PropertyDescription        TypeDefault
idIDNumber+new Date()
sourceSource of connectionObject-
destinationDestination of connectionObject-
typeType of connectionStringpass

Properties.Connection.Source & Properties.Connection.Destination

PropertyDescription        TypeDefault
idNode idObject-
positionStarting/Ending position of nodeObject-

Slot

If you want you can pass value as slot. It allows you to add new UI elements to chart playground. These slot elements aren't selectable - are ignored while selection. Moreover actions on click and on double click are disabled in area filled by passed elements. You can use this functionality to e.g. in quite easy way add toolbar inside.

<flowchart ...>
  <div id="toolbox" style="position: absolute; bottom: 0; left: 0; width: 100%; height: 50px; 
                           display: flex; align-items: center; 
                           background-color: rgba(225, 225, 225, 0.7);">
    <button @click="$refs.chart.remove()">Delete(Del)</button>
    <button @click="$refs.chart.editCurrent()">
      Edit(Double-click node)
    </button>
    <button @click="$refs.chart.save()">Save</button>
  </div>
</flowchart>