New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-flowchart-designer

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-flowchart-designer

A lightweight component to design flowcharts. Check out the [demo](https://d5y3kk.csb.app/) for some examples.

latest
Source
npmnpm
Version
2.0.2
Version published
Weekly downloads
1
Maintainers
0
Weekly downloads
 
Created
Source

A lightweight component to design flowcharts. Check out the demo for some examples.

Features

  • Different shapes of nodes.
  • Add/Remove/Move nodes
  • Add/Remove/Reshape links between nodes
  • Enable/Disable adding/editting/removing links
  • Zoom and Pan
  • Raw or typed input/output

Screenshot of ImageAnnotator

Usage

Install react-flowchart-designer using npm.

npm install react-flowchart-designer

Then you can just import the component and its hook:

import { Flowchart, useFlowchart } from 'react-flowchart-designer';

and use it as below:

const { setHandles, flowchart } = useFlowchart();
<button onClick={() => { flowchart.addRectNode(50, 50, 'my node') }}>Add Node</button>
<Flowchart setHandles={setHandles} width='700px' height='400px' editable={true} />

Clicking the button creates a new node at x = 50, y = 50. Drag the orange square from one node to another to add links.

Mouse and Keyboard events

  • click: Edit/Stop Edit Links - Select Node/Link
  • double click: Edit Node/Link text
  • mouse wheel: Zoom
  • mouse drag: Pan - Move Node/Link
  • Delete key: Delete Node/Link

Loading/Saving a Flowchart

Load/save a flowchart using the data model below:

const load = () => {
  let nodes = [
    { id: 1, text: 'node1', X: 50, Y: 50 },
    { id: 2, text: 'node2', X: 150, Y: 50 },
  ];
  let links = [
    { from: 1, to: 2 },
    { from: 2, to: 2 },
  ];
  flowchart.addNodes(nodes, links);
}

const save = () => console.log(flowchart.getData()) // { nodes: […], links: […] }
<button onClick={load}>Load</button>
<button onClick={save}>Save</button>

Props

The following props can be defined on Flowchart:

PropTypeDescriptionDefault
width *stringFlowchart width
height *stringFlowchart height
editablebooleanEnable/Disable adding/removing linksfalse
onReadyFlowchartHandles => anyWhen the flowchart is mounted

(*) required props

Handles

You can access the handles using the Flowchart object as follows:

<button onClick={() => { flowchart!.addRhomNode(100, 100, txt) }}>Add Rhombus Node</button>

Below is a list of all handles:

HandleTypeDescription
addRectNode(left: number, top: number, text: string, id?: number, color?: string) => numberAdds a rectangle node at (left, top), returns its id
addCircleNode(left: number, top: number, text: string, id?: number, color?: string) => numberAdds a circle node at (left, top), returns its id
addRhomNode(left: number, top: number, text: string, id?: number, color?: string) => numberAdds a rhombus node at (left, top), returns its id
addNodes(nodes: NodeData[], links?: LinkData[]) => voidAdds multiple nodes and links (see Loading a Flowchart)
getData() => { nodes: NodeData[], links: LinkData[] }Gets all nodes and links (see Saving a Flowchart)
changeLinkType(id: number, type: string) => voidChanges the type of a link (solid/dashed)

Node

Below is the data model for nodes:

PropTypeDescriptionDefault
idnumberNode identifier
X *numberThe x position of the node
Y *numberThe y position of the node
text *stringNode text
colorstringNode colorwhite
shapestringNode shape can be rectangle, circle, or rhombusrectangle

(*) required props

Below is the data model for links:

PropTypeDescriptionDefault
from *numberThe id of the origin node
to *numberThe id of the destination node
textstringLink label
typestringLink type (solid/dashed)solid
metaobjectInformation about the shape of the link

(*) required props

Contributing

  • Fork the project.
  • Make changes.
  • Run the project in development mode: npm run ladle.
  • Write your own tests and/or update existing ones in src/flowchart/test dir.
  • Check the new features and changes using flowchart.stories.tsx or your own Stories (*.stories.tsx).
  • Update README with appropriate docs.
  • Commit and PR

Dependencies

React Flowchart has no dependency. However the following peer dependencies must be specified by your project in order to avoid version conflicts: react, react-dom. NPM will not automatically install these for you but it will show you a warning message with instructions on how to install them.

Keywords

react

FAQs

Package last updated on 08 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts