Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@mrblenny/react-flow-chart

MrBlenny20kMIT0.0.14TypeScript support: included

A flexible, stateless flow chart library for react.

readme

React Flow Chart

CircleCI

  • <input checked="" disabled="" type="checkbox"> Dragabble Nodes and Canvas
  • <input checked="" disabled="" type="checkbox"> Create curved links between ports
  • <input checked="" disabled="" type="checkbox"> Custom components for Canvas, Links, Ports, Nodes
  • <input checked="" disabled="" type="checkbox"> React state container
  • <input checked="" disabled="" type="checkbox"> Update state on Select/Hover nodes, ports and links
  • <input checked="" disabled="" type="checkbox"> Base functionality complete
  • <input checked="" disabled="" type="checkbox"> Stable NPM version
  • <input checked="" disabled="" type="checkbox"> Scroll/Pinch canvas to zoom
  • <input disabled="" type="checkbox"> Ctrl+z/Ctrl+y history
  • <input checked="" disabled="" type="checkbox"> Read-only mode
  • <input disabled="" type="checkbox"> Redux state container
  • <input disabled="" type="checkbox"> Arrow heads on links
  • <input disabled="" type="checkbox"> Docs

Storybook Demo

CodeSandbox Demo

This project aims to build a highly customisable, declarative flow chart library. Critically, you control the state. Pick from Redux, MobX, React or any other state managment library - simply pass in the current state and hook up the callbacks.

For example:

demo

Data Stucture

The flow chart is designed as a collection of Nodes, Ports and Links. You can specify your own custom properties, making this format quite flexible. See types/chart.ts. Note, nodes, ports and links should have a unique id.

Example


export const chart: IChart = {
  offset: {
    x: 0,
    y: 0,
  },
  scale: 1,
  nodes: {
    node1: {
      id: 'node1',
      type: 'output-only',
      position: {
        x: 300,
        y: 100,
      },
      ports: {
        port1: {
          id: 'port1',
          type: 'output',
          properties: {
            value: 'yes',
          },
        },
        port2: {
          id: 'port2',
          type: 'output',
          properties: {
            value: 'no',
          },
        },
      },
    },
    node2: {
      id: 'node2',
      type: 'input-output',
      position: {
        x: 300,
        y: 300,
      },
      ports: {
        port1: {
          id: 'port1',
          type: 'input',
        },
        port2: {
          id: 'port2',
          type: 'output',
        },
      },
    },
  },
  links: {
    link1: {
      id: 'link1',
      from: {
        nodeId: 'node1',
        portId: 'port2',
      },
      to: {
        nodeId: 'node2',
        portId: 'port1',
      },
    },
  },
  selected: {},
  hovered: {},
}

This will produce a simple 2 noded chart which looks like:

Demo

Basic Usage

npm i @mrblenny/react-flow-chart

Most components/types are available as a root level export. Check the storybook demo for more examples.

import { FlowChartWithState } from "@mrblenny/react-flow-chart";

const chartSimple = {
  offset: {
    x: 0,
    y: 0
  },
  nodes: {
    node1: {
      id: "node1",
      type: "output-only",
      position: {
        x: 300,
        y: 100
      },
      ports: {
        port1: {
          id: "port1",
          type: "output",
          properties: {
            value: "yes"
          }
        },
        port2: {
          id: "port2",
          type: "output",
          properties: {
            value: "no"
          }
        }
      }
    },
    node2: {
      id: "node2",
      type: "input-output",
      position: {
        x: 300,
        y: 300
      },
      ports: {
        port1: {
          id: "port1",
          type: "input"
        },
        port2: {
          id: "port2",
          type: "output"
        }
      }
    },
  },
  links: {
    link1: {
      id: "link1",
      from: {
        nodeId: "node1",
        portId: "port2"
      },
      to: {
        nodeId: "node2",
        portId: "port1"
      },
    },
  },
  selected: {},
  hovered: {}
};

const Example = (
  <FlowChartWithState initialValue={chartSimple} />
);

With Internal State

stories/InternalReactState.tsx

With External State

stories/ExternalReactState.tsx

Readonly Mode

stories/ReadonlyMode.tsx

Other Demos

stories/ExternalReactState.tsx

Contributing

If you're interested in helping out, let me know.

In particular, would be great to get a hand with docs and redux / mobx integrations.

Development

npm install
npm run start:storybook

changelog

Changelog

[Unreleased]

[0.0.14] - 2020-06-28

Fixed

  • Drag and drop nodes now reflects the correct position when zoomed ajuhos
  • Fixed some link positioning errors ajuhos
  • Fix canvas drop creating 2 nodes IdealSystemsMCP
  • Remove depricated findDOMNode method IdealSystemsMCP

Added

[0.0.13] - 2020-05-09

Fixed

  • Nodes is view calculation was wrong if the chart was zoomed leading to the nodes not displaying.
  • Moved styled-components to a peer dependency
  • Do not send click even when drag finishes crsven

[0.0.12] - 2020-04-27

Fixed

Added

  • Use the data.id if it exists on the drag and drop data transfer object NoyTse
  • Add an onNodeDoubkeClick handler jetmar
  • Add properties.linkColor support to the default link component ielijose
  • Zoom support! ielijose

Breaking

  • Readonly mode will no longer disable canvas drag parasg1999
  • Updated styled components to ^5.1.0 ophirg
  • Zoom is enabled by default
  • Chart state must have now have a scale property

[0.0.11] - 2020-03-02

Fixed

  • Fixed an issue with onDrag errors

[0.0.10] - 2020-03-02

Added

  • smartRouting mode dmitrygalperin
  • Pass node into ports to enable customisation fenech
  • Add nodeMouseEnter and nodeMouseLeave callbacks fenech
  • Add onDragCanvasStop and onDragNodeStop callbacks lordi

[0.0.9] - 2020-01-18

Fixed

  • The onNodeClick action will no longer be called when dragging fenech
  • Fix data consistency when snapToGrid is on/off sinan
  • Update node size when size changes in the DOM zetavg
  • Prevent links and ports displaying as active when in readonly mode.

Breaking

  • Updated styled components to ^5.0.0 yuyokk

[0.0.8] - 2019-10-20

Fixed

  • Readonly mode should prevent link edits loonyuni
  • Only call onCanvasDrop if data exists in drop event loonyuni
  • Improve CustomNode storybook example timbrunette
  • Fixed an error that was being thown when creating links in readonly mode

[0.0.7] - 2019-08-22

Added

  • Readonly mode yukai-w
  • Offset position to dropped item position phlickey
  • snapToGrid and gridSize config options msteinmn
  • validateLink config function msteinmn
  • misc other fixes msteinmn
  • Config object that is accessible by all components and actions

Breaking

  • Changed the callback type signatures so they are always objects rather than functions with params. If you use custom callbacks, these will need to be updated.

[0.0.6] - 2019-04-30

Added

  • Upgrade Typescript and Storybook.
  • Prevent re-rendering for nodes and links that are not in use. alexkuz PR7
  • Render only nodes currently visible for user. alexkuz PR7
  • Fix calculating link position when canvas is not positioned in top left corner. alexkuz PR7

Breaking

  • Added a new onNodeSizeChange action that is required for calculating which nodes are visible. If you are using external state, this will need to be implemented.

[0.0.5] - 2019-04-02

Added

  • Fixed a bug where links would not work on firefox tantayou999

[0.0.4] - 2019-03-24

Added

  • Start keeping a changelog
  • Remove storybook and lodash from from dist alexcuz PR5