Flowchart
- A glimpse of all main features of the Flowchart.
- The detailed description of these features are provided in respective sections.
Building Blocks
The following are the basic building blocks required to render a flowchart:
-
elements
: An array of elements where eachelement
must have following fields:id
: ID of the elementtype
: type of element, a config corresponding to this type must be present inelementTypeConfigs
settings
: This object must containposition
(row, column in terms of diagram container) andstyle
left
: The absolute left position in pixelstop
: The absolute top position in pixelswidth
: The width of element in pixelsheight
: The height of element
Note: If
autolayout
is enabled, then placement of nodes is calculated automatically, hence can provide any values ofleft
,top
andsettings.position
Eg:
{id: 'node-1',type: 'ACTION',settings: { position: { row: 1, column: 1 }, style: {} },left: 20,top: 20,width: 128height: 48,} -
connections
: An array of connections where eachconnection
must have following fields:id
: ID of connectiontype
: It must beSEQUENCE_FLOW
sourceActivityId
: ID of source elementtargetActivityId
: ID of target element
Eg:
{id: 'node-1__node-2',type: 'SEQUENCE_FLOW',sourceActivityId: 'node-1',targetActivityId: 'node-2'} -
elementTypeConfigs
: An object which defines config for each unique elementtype
and also for connection (SEQUENCE_FLOW). Each config of element must have following fields:renderer
: The component which is used to render the element. It acceptselement
,index
andonAction
EntityClass
: Should either beBaseElement
orConnection
adapter
: It takes partial element and any values and returns the complete element, mainly used to create new element of this type.width
: The common width for all elements of this typeheight
: The common height for all elements of this type
Eg:
{ACTION:{renderer: ({element, index, onAction}) => <div>{element.id}</div>,EntityClass: BaseElement,adapter: (element, params) => ({ ...element, ...params, type: 'ACTION' }),width: 128,height: 48,}SEQUENCE_FLOW:{EntityClass: Connection}} -
onAction
: This should handle actions triggered from inside of flowchart and update the flowchart state accordingly.Eg:
const onAction = action => {switch (action.type) {case UPDATE_FLOWCHART: {setCanvasState(prevState => ({...prevState,...action.payload,}));break;}default:}} -
gridCellDimensions
: It defines{width, height, gap}
of each grid in flowchart, the position of elements are calculated as a multiple of these.Eg:
{width: 32,height: 32,gap: 2} -
offsets
: It defines{ topOffset, rowGapOffset }
which are used to calculate the position of elements in autolayout mode, by adjusting gap between rows, by the factor ofrowGapOffset
and top offset of first row by the factor oftopOffset
.Eg:
{topOffset: 1.0,rowGapOffset: 1.25,} -
diagramDimensions
: It should contain a single fieldwidth
which is the width of the entire flowchart and is used to calculate the position of elements in autolayout mode.Eg:
{width: 800} -
FlowchartStateContext
: Since flowchart works in a controlled manner, the state of flowchart is maintained by consumer. We have to wrap the Flowchart component inFlowchartStateContext.Provider
passing it the flowchart state which must contain:elements
connections
elementTypeConfigs
Note: The list above outlines the basic requirements for rendering a flowchart, but there are additional fields, props and state values that enable specific features, which are explained in the examples below.
- Autolayout automatically arrange nodes, thus eliminating the need for manual layouting and is intended to be enabled by default for all new flowcharts.
- Most of the features of flowchart are only available in autolayout mode.
- To enable zoom, pass
enableZoom
as true. - By default zoom is enabled if autolayout is enabled
- Pass
enableMinimap
as true to Flowchart to enable Minimap. - This feature provides an overview of the flow, rendering small version of each node and showing the current viewport's position relative to the entire flow.
- The Minimap is interactive, clicking at any place in the smaller view will make the flowchart jump to that position.
- For easier navigation of large flowcharts, we can collapse the subtree of any branching node (node having multiple outgoing connections).
- The user can select 3 options from control panel:
- Initial view: How the nodes are arranged when flowchart first loads
- Preview for initial view
- What happens when clicked on expand.
- To enable this, set
collapsibleViews
in FlowchartState as in the given example.
- We can copy or move a single element or a subtree within a flowchart.
- A copied or moved subtree can only be pasted onto placeholders.
- A single element can be pasted onto placeholders or between connections.
- We can copy a subtree or a single element across different flowcharts of the same
flavour
within the same session. - To copy between different flowcharts, the
flavour
must be included in the canvas state. - We can also skip a node, which sets its
disabled
property totrue
.
- The disconnect button appears when hovering over the connection action (plus icon).
- Set
enableAutolayoutOnlyActions
totrue
in the canvas state. - Available only in
EDIT
mode. - The
disabledSequence
field is set totrue
when a connection is disconnected.
- The browser’s built-in search doesn’t work due to the flowchart being virtualized, so a custom search is required within the flowchart.
- Use
CanvasHeader
inrenderHeader()
and pass it to the Flowchart to enable the search bar. - Additionally, pass the
searchKeys
object to define how elements should match the search query.
highlightIntents
is stored in the canvas state, containing three sets:error
,success
, andwarning
.- Each set holds the IDs of elements or connections to be highlighted according to its type (
error
,success
, orwarning
). - Highlighting is enabled only in
VIEW
mode to avoid interference with other actions (e.g., copy, move). - In
VIEW
mode, setpathTracingEnabled
totrue
to disable any elements not included in thehighlightIntents
sets.
- Add a
getDimensions
function to the element type config to calculate the element's height and width. - The autolayout algorithm will automatically align nodes at the same level, even when they have different dimensions.
- Add
strokeWidth
number props inconnection.settings
to set the width of the connection line. This will also override bothpaintStyle
andhoverWidth
, - Additionally, you can also give
className
inconnection.settings
to apply custom styles to the connection line. - Recommended to use
strokeWidth
in conjunction with appropriateoffsets
to avoid clustering of connections.
Purpose - Group Collapse allows us to collapse non-essential nodes in a flow, making it easier to focus on the important parts.
Key Concept
- Nodes that should always remain visible are given a special status by setting
isGroupHead = true
. - By default, only
groupHead
nodes and branching nodes (nodes with multiple children) are visible.
Behavior
- When a
groupHead
is collapsed, it groups all other nodes in its linear subtree until anothergroupHead
or branching node is encountered. - Grouping is limited to linear subtrees. If a branching node is found, grouping stops, and all direct children of the branching node are treated as
groupHeads
to maintain visibility while hiding non-essential nodes.
Example
- In the provided example, Nodes
1
,4
, and13
are explicitly marked asgroupHeads
. - Nodes
5
,8
,11
, and12
inheritgroupHead
status because they are direct children of branching nodes.
Flowchart props
Name | Type | Default | Description |
---|---|---|---|
activeElements | array | Array of active elements which are to be highlighted in the flowchart | |
autolayout | boolean | To enable or disable autolayout | |
connections | array | Array of connections | |
diagramDimensions | object | An object of shape (width) defining the diagram dimension which is used to calculate positions in autolayout mode | |
elementPropsGetter | function | To define how to get the props for each element | |
elementTypeConfigs | object | Object containing config (renderer, adapter, etc.) for each unique element type | |
elements | array | Array of elements | |
enableCollapsible | boolean | true | To enable or disable collapsible support on branching nodes |
enableMinimap | boolean | false | To enable or disable minimap |
enableZoom | boolean | To enable or disable zoom, it is enabled by default if in autolayout mode | |
extremeOverflowWidth | number | Added to the chart background width | |
flavour | string | Any string which uniquely defines this flowchart | |
gridCellDimensions | object | An object of shape (height, width, gap) defining the dimensions of grid cells | |
highlightedElementId | string | The ID of element which is to be highlighted initially | |
initialScrollPosition | object | The initial position (top, left) to which the flowchart should scroll to on load | |
logErrors | function | To log error which accepts (error, errorInfo, errorKey) | |
offsets | object | To provide an offset (rowGapOffset or topOffset) to each element | |
onAction | function | To handle flowchart actions | |
overrides | object | To provide supported overrides | |
renderHeader | function | To render custom header | |
rowAndColumnGap | object | To provide custom row or column gap between each element in autolayout | |
searchKeys | object | To define how to search for an element |