Flow Chart Structure
The flow chart in Data-River is the primary visual interface where users design workflows by connecting blocks (nodes) and edges. In Data-River, nodes are generic and flexible, allowing the data they contain to dictate their behavior and appearance. This guide focuses on the structure of the flow chart and how to work with nodes and edges in this context.
Overview
The flow chart is built using the React Flow library, which manages the rendering and state of nodes and edges. The key idea behind the flow chart in Data-River is that nodes are generic—their behavior and appearance are driven by the data they contain, rather than custom node types.
Key Components of the Flow Chart
React Flow Component The core of the flow chart is the
ReactFlow
component from the React Flow library. This component renders the nodes, edges, and manages interactions such as dragging, connecting, and clicking.In Data-River, the node type is always set to
"custom"
. This allows the same node type to be used for various functions, with the node's data controlling its functionality.Nodes and Data-Driven Customization Nodes in the flow chart are generic but highly customizable based on the
data
property. The appearance, inputs, outputs, and controls of a node are determined by the data it contains.In the example above, the node's
data
defines its label, color, icon, and controls, which are rendered dynamically in the flow chart.Node Controls Nodes can have various controls, such as text inputs or text areas, which are defined in the node's
data.controls
array. These controls allow users to interact with the node and change its inputs or outputs.The
NodeControls
component dynamically renders these controls based on the node’s data:Edges and Connections Edges represent the connections between nodes. Just like nodes, the edges in Data-River are generic, with their type always set to
"custom"
. This ensures consistent behavior for all edges.The edges are responsible for directing the flow of data between nodes, and they are updated dynamically as users connect or disconnect nodes in the flow.
Event Handlers Several event handlers manage user interactions with nodes and edges, such as dragging nodes, clicking on them, or connecting nodes together. These event handlers are defined in
useReactFlowEventHandlers()
and are passed to theReactFlow
component.
Working with Nodes and Data
Node Data Structure
The structure of the node's data
property defines the behavior and appearance of each node. Here's an example of an Input
node's data:
The controls
array defines the UI elements that the user can interact with to modify the node's behavior.
Dynamic Node Rendering
The CustomNode
component renders nodes dynamically based on their data. It displays the node's label, icon, and controls, and it manages input/output connections using SourceHandle
and TargetHandle
.
Node Controls and Interaction
The NodeControls
component dynamically generates the controls for each node based on its data.controls
configuration. This allows for flexible user interaction with the nodes without needing to create custom node types for each use case.
Best Practices
Keep Node Data Simple: Since nodes are generic, ensure that the
data
property is concise and easy to manage.Use Controls Efficiently: Leverage the
controls
array to allow users to interact with nodes and adjust their behavior dynamically.Focus on Data-Driven Logic: Avoid creating new node types. Instead, focus on how the node data can be used to drive the rendering and behavior of each node in the flow.
What's Next?
Last updated