MCPcopy Index your code
hub / github.com/MrBlenny/react-flow-chart

github.com/MrBlenny/react-flow-chart @0.0.14

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.0.14 ↗ · + Follow
1,183 symbols 3,086 edges 84 files 0 documented · 0% updated 3y ago0.0.14 · 2020-06-28★ 1,55470 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

React Flow Chart

CircleCI

  • [X] Dragabble Nodes and Canvas
  • [x] Create curved links between ports
  • [x] Custom components for Canvas, Links, Ports, Nodes
  • [X] React state container
  • [X] Update state on Select/Hover nodes, ports and links
  • [x] Base functionality complete
  • [X] Stable NPM version
  • [X] Scroll/Pinch canvas to zoom
  • [ ] Ctrl+z/Ctrl+y history
  • [X] Read-only mode
  • [ ] Redux state container
  • [ ] Arrow heads on links
  • [ ] 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

Extension points exported contracts — how you extend this code

IFlowChartWithStateProps (Interface)
(no doc)
src/container/FlowChartWithState.tsx
IOnDragNodeInput (Interface)
(no doc)
src/types/functions.ts
IPortsGroupDefaultProps (Interface)
(no doc)
src/components/PortsGroup/PortsGroup.default.tsx
ISidebarItemProps (Interface)
(no doc)
stories/components/SidebarItem.tsx
IOnDragCanvasInput (Interface)
(no doc)
src/types/functions.ts
ICanvasInnerDefaultProps (Interface)
(no doc)
src/components/Canvas/CanvasInner.default.tsx
IOnDragNodeStopInput (Interface)
(no doc)
src/types/functions.ts
ICanvasOuterDefaultProps (Interface)
(no doc)
src/components/Canvas/CanvasOuter.default.tsx

Core symbols most depended-on inside this repo

has
called by 149
docs/vendors~main.0e8543e4e3ea607d4dde.bundle.js
x
called by 94
docs/vendors~main.0e8543e4e3ea607d4dde.bundle.js
isArray
called by 81
docs/vendors~main.0e8543e4e3ea607d4dde.bundle.js
isObject
called by 70
docs/vendors~main.0e8543e4e3ea607d4dde.bundle.js
Type
called by 64
docs/vendors~main.0e8543e4e3ea607d4dde.bundle.js
defineProperty
called by 57
docs/vendors~main.0e8543e4e3ea607d4dde.bundle.js
defineProperties
called by 57
docs/vendors~main.0e8543e4e3ea607d4dde.bundle.js
_assertThisInitialized
called by 57
docs/vendors~main.0e8543e4e3ea607d4dde.bundle.js

Shape

Function 1,100
Interface 38
Method 25
Class 20

Languages

TypeScript100%

Modules by API surface

docs/vendors~main.0e8543e4e3ea607d4dde.bundle.js1,004 symbols
src/container/actions.ts22 symbols
docs/main.0e8543e4e3ea607d4dde.bundle.js22 symbols
src/types/functions.ts12 symbols
src/components/Port/Port.wrapper.tsx11 symbols
stories/utils/throttleRender.tsx9 symbols
src/components/Canvas/Canvas.wrapper.tsx8 symbols
src/container/FlowChartWithState.tsx5 symbols
src/components/Link/utils/generateCurvePath.ts5 symbols
src/components/FlowChart/FlowChart.tsx5 symbols
stories/CustomNodeInner.tsx4 symbols
stories/Zoom.tsx3 symbols

For agents

$ claude mcp add react-flow-chart \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page