0.32.0 • Published 6 months ago

flowchart-vue v0.32.0

Weekly downloads
243
License
MIT
Repository
github
Last release
6 months ago

Flowchart

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

NPM

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>
0.32.0

6 months ago

0.31.0

6 months ago

0.30.0

1 year ago

0.29.2

1 year ago

0.29.1

1 year ago

0.29.0

2 years ago

0.27.0

2 years ago

0.28.0

2 years ago

0.25.1

2 years ago

0.25.0

2 years ago

0.23.0

2 years ago

0.21.0

2 years ago

0.26.0

2 years ago

0.24.0

2 years ago

0.22.0

2 years ago

0.20.0

2 years ago

0.19.2

3 years ago

0.19.1

3 years ago

0.18.1

3 years ago

0.17.1

3 years ago

0.16.1

3 years ago

0.15.4

3 years ago

0.15.3

3 years ago

0.15.2

4 years ago

0.15.1

4 years ago

0.14.6

4 years ago

0.14.5

4 years ago

0.14.4

4 years ago

0.14.3

4 years ago

0.14.2

4 years ago

0.14.1

4 years ago

0.13.12

4 years ago

0.13.11

4 years ago

0.13.9

4 years ago

0.13.10

4 years ago

0.13.8

4 years ago

0.13.7

4 years ago

0.13.6

4 years ago

0.13.4

4 years ago

0.13.5

4 years ago

0.13.3

4 years ago

0.13.2

4 years ago

0.13.1

4 years ago

0.12.1

4 years ago

0.11.1

4 years ago

0.10.2

4 years ago

0.10.1

4 years ago

0.9.1

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.7.1

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.5.1

4 years ago

0.4.1

4 years ago

0.2.1

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago