Git Product home page Git Product logo

flowchart-vue's Introduction

Flowchart

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

NPM

image

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

Property Description Type Default
nodes Collection of nodes Array [{id: 1, x: 140, y: 270, name: 'Start', type: 'start'}, {id: 2, x: 540, y: 270, name: 'End', type: 'end'}]
connections Collection of connections Array [{source: {id: 1, position: 'right'}, destination: {id: 2, position: 'left'}, id: 1, type: 'pass', }]
width Width of canvas String | Number 800
height Height of canvas String | Number 600
locale Display language, available values: 'en', 'zh' String 'en'
readonly Read-only Boolean false
render Custom render function null
readOnlyPermissions Allows to specify more granular read-only mode permissions Object { allowDragNodes: false, allowSave: false, allowAddNodes: false, allowEditNodes: false, allowEditConnections: false, allowDblClick: false, allowRemove: false }

Events

Event Description Handler
editnode Node double-click event (node) => void
editconnection Connection double-click event (connection) => void
save Save event (nodes, connections) => void
dblclick Background double-click event (position: {x: number, y: number}) => void
connect Connect event (connection, nodes, connections) => void
disconnect Disconnect event (connection, nodes, connections) => void
add Add node event (node, nodes, connections) => void
delete Delete node event (node, nodes, connections) => void
select Select node event nodes => void
selectconnection Select connection event connections => void
render Node render event, children is a collection of svg elements (node: Node, children: { header, title, body, content }) => vod
nodesdragged Notifies which nodes dragging just ended (nodes) => void
removeConfirmationRequired Notifies that remove confirmation required. Pass nodes and connections selected to remove (nodes, connections) => void
movediff Notifies about change in chart view position (diff: {x: number, y: number}) => void

Properties.Node

Property Description         Type Default
id ID Number +new Date()
x Horizontal position of node Number -
y Vertical position of node Number -
type Type of node String 'operation'
width Width of node Number 120
height Height of node Number 60
approvers Approvers of node, eg: [{name: 'admin'}] Array []
connectors Defines which connectors should be rendered Array ['top', 'right', 'bottom', 'left']
theme Defines colors for specified node elements Object { borderColor: "#bbbbbb", borderColorSelected: "#666666", headerTextColor: "black", headerBackgroundColor: "#f1f3f4", bodyBackgroundColor: "white", bodyTextColor: "black" }

Properties.Connection

Property Description         Type Default
id ID Number +new Date()
source Source of connection Object -
destination Destination of connection Object -
type Type of connection String pass

Properties.Connection.Source & Properties.Connection.Destination

Property Description         Type Default
id Node id Object -
position Starting/Ending position of node Object -

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>

flowchart-vue's People

Contributors

dependabot[bot] avatar hrenly avatar iamppz avatar mrzygood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flowchart-vue's Issues

Is it possible to add labels for the connections?

Hello, I am new to the library so trying to use this in one of my Nuxt/Vuejs applications but I wanted to know if there is any possibility to include the labels for each connection that has been created using this library?

I would like to create the connections for the nodes dynamically based on user preference. For each of the connector I would like to have 3 labels something like this:

Screenshot 2021-11-08 at 08 48 06

Can someone please let me know if it's possible and how to achieve the same?

feat: Custom SVG / Component as Node

Is your feature request related to a problem? Please describe.
Rendering custom SVG/Component through node's prop.

Describe the solution you'd like
I have a set of icons/components that I would love to use as a display for some of the nodes.

Describe alternatives you've considered
None as of the moment as there's no exposed API to achieve this state.

Additional context
I have already forked the project, I will try to implement the feature there, and I more than happy to contribute to this wonderful project if it will be deemed appropriate.

Generic data field for nodes

Hey Joyce,

great work! I've check quiet a lot of flowchart libraries and yours is the closest to my needs.

One thing that would really help me would be to have a generic data field in each node where I could put whatever I want (title in another language, content, etc.) and that doesn't necessarily need to be displayed on the screen. It could be edited on a sidebar on a click event on the node for example.

That would be really helpful, I hope you can build it :)

Scrolling functionality with bigger charts

When charts exceed the max-width and/or height we have no ability to navigate the canvas, i.e.scrolling?
Bigger flowcharts unfortunately won't fit. Is there any solution known for this need.?

Drawing a polygon

I want to draw a diamond with following code:

let body = g.append("polygon");
  body.attr("class", "body")
  body.attr("cx", node.x + node.width / 2);
  body.attr("cy", node.y + node.height / 2);
  body.attr("rx", node.width / 2);
  body.attr("ry", node.height / 2);
  body.style("fill", "white");
  body.style("stroke-width", "1px");
  body.attr("points", "69.445,125 125,28.774 180.556,125 125,221.227");
  body.classed(node.type, true);
  body.attr("stroke", borderColor);

This will draw diamond as expected, but the issue here is that now polygon is fixed on and is not affected by drag event. Even, connector dots appear away from the polygon. When I click on polygon and start the drag event, connector dots move but the polygon is not moving.

Am I missing something here?

Customise own node (add dropdowns in the node's title and body)

Hi! I would like to customise the node and add dropdowns for the title and body (where the approvers are shown). How do I proceed with this? I saw from the past issues that we can customise the nodes in a render function but I noted that it has been removed in the later commits. Thanks!

how i can use delete node property?

I need below functionality

select node -> click on button ->get all details of selected node (editnode function is already used)
(i want to delete that node from chart and database )
kindly please help

Is there a way to draw the "Nodes" and "Connections" dynamically on the chart based on user preference?

I am new to flowchart-vue and trying to create a simple application that consists of just Nodes and Connectors. All I want to do is let the user draw the Nodes anywhere on the Chart based on the click of the Add Node button and create the connections between them using the Add Connector button. I want users to create as many as Nodes and Connectors based on their requirements.

I have completed my sourcecode so far: CodeSandbox

I tried a couple of things but nothing seems to work for me. Can you please explain if this is possible? If so can you guide me on what to do? Following is something I am trying to achieve:
CPT2111081018-1920x930

Bug: mouseup event doesn't work

Describe the bug
mouseup event doesn't work in Flowchart.vue .
When the Process function "handleChartMouseDown($event)" of event mousedown is activated, one of nodes is selected. When the left click of mouse is up, handleChartMouseUp is not activated. Why ? Is it a bug? Because of the async feature of function handleChartMouseUp ?

Expected behavior
I wish that you can refind the problem and solve it.

Lines are overlapping on nodes.

Describe the bug
Connecting between two nodes is overlapping on another node if there is any node in between.

To Reproduce
I tried to connect the D4 to J6, in between there is J8 and connection line is overlapping
Please check the below screen shot.

Expected behavior
The connection line between the D4 and J6 should go from above or below the J8 node.

Screenshots
image

vue3 do not can work ?

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Add element to g

How do I add a new item to the root group of a node? I haven't found how to do this in recent versions.
image

Title render on task fails (px missing)

Hey nice work first ;)
i noticed that the task node titles are not rendered correctly. the rect is not given a style (width/height).

to reproduce you can have a look at the demo.

i think the missing part ist on flowchart component at line 86
current: style('width', node.width);
should be: style('width', node.width + 'px').style('height','20px');

Complex custom node

I'm looking for something like your project to build a conversational bot builder for Telegram Messanger. The library you developing is very nice for me.

Please tell me еру way, how I can create more complex custom nodes like described in the attached image.

Here I show a simple message with three inline buttons. A button can be connected only to one message, but the message can be triggered by any number of buttons from other messages.

image

求求了,把文档写清楚点。完全不知道有些字段的参数怎么填 比如 approvers

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Drag canvas out of svg area

Canvas (start, end, operation) can be dragged out of the svg area.
To Reproduce
Steps to reproduce the behavior:

  1. Go to https://joyceworks.github.io/flowchart-vue/
  2. Click on Start
  3. Drag Start out of the svg area
  4. Start is 'lost'

Expected behavior
svg area should have boundaries (therefore canvas cannot exit svg area) or svg area should be scrollable
flowchart-boundaries

Small typo in example in README.md

Describe the bug
A small typo in

To Reproduce
Steps to reproduce the behavior:

  1. Read README.md:

    handleChartSave(nodes, connections) {
    // axios.post(url, {nodes, connection}).then(resp => { // <===============
    // this.nodes = resp.nodes;
    // this.connections = resp.connections;
    // // Flowchart will refresh after this.nodes and this.connections changed
    // });

Expected behavior

  1. Should be:

    handleChartSave(nodes, connections) {
    // axios.post(url, {nodes, connections}).then(resp => { // <===============
    // this.nodes = resp.nodes;
    // this.connections = resp.connections;
    // // Flowchart will refresh after this.nodes and this.connections changed
    // });

How can I block reverse arrow?

Hello, @iamppz,

I want the to user can't draw a reverse arrow. How can I prevent this?

image

Also, how can I force use start and end to the? And the user shouldn't multiple connections to one node, how can I prevent this too?

I would be very happy if you can explain how I can make these requests.

Thanks.

style of nodes

hello,
is there a way to style the nodes? (for example change their shape and color)

In place edit for a node on flow chart

Can we provide in place edit for a node on the flow chart ? Something like, when double click happens on a rect, it should provide an in place text edit field instead of popup.

Thanks

call back events

is there any call back events for node creation, deletion ,connection creation and connection deletion?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.