Foblex Flow
Introduction
Overview
Nodes
Custom Nodes
Drag Handle
Node Selection
Resize Handle
Rotate Handle
Grouping
Drag to Group
Connectors
Node as Connector
Connector Inside Node
Connector Outlet
Limiting Connections
Connection Rules
Connectable Side
Updated
Connections
Drag to Connect
Drag to Reassign
Create Node on Connection Drop
Remove Connection on Drop
Assign Node to Connection on Drop
Auto Snap
Connection Types (Straight, Segment, Bezier, Adaptive Curve)
Custom Connection Type
Connection Behaviours
Connection Markers
Connection Content
Updated
Connection Waypoints
New
Connection Gradients
Updated
Connection Connectable Side
New
Extensions
Auto Pan
New
Add Node from Palette
Selection Area
Help in Positioning (Legacy)
Deprecated
Magnetic Lines
New
Magnetic Rects
New
Grid System
Minimap
Zoom
Background
Plugins
Dagre Layout
New
Dagre Auto Layout
New
ELK.js Layout
New
ELK.js Auto Layout
New
Advanced
Large Scene Performance
Connection Redraw Performance
Updated
Cut/Copy/Paste
Undo/Redo
Undo/Redo V2
Drag Start/End Events
Custom Event Triggers
Reference Apps
AI Low-Code Platform
Updated
Schema Designer
Updated
Call Center Flow
Updated
UML Diagram
Updated
Tournament Bracket
Updated
Foblex Flow

Dagre Auto Layout

This page shows how to use @foblex/flow-dagre-layout together with Foblex Flow auto mode. The example still rebuilds the graph from component state, but it no longer calls calculate(...) manually. Instead, Flow renders the graph first, measures the nodes, and then asks Dagre to recalculate positions automatically.

The important split is:

  • @foblex/flow-dagre-layout calculates node positions
  • @foblex/flow detects graph changes, asks the engine to relayout, and redraws the scene
  • your app still owns graph state through writeback

How This Differs From The Manual Example

The manual example explicitly calls calculate(...) and usually passes a size for every node before rendering.

This auto example works differently:

  1. The component rebuilds the source graph from toolbar state.
  2. That graph is rendered in f-flow.
  3. Flow calls getState({ measuredSize: true }) internally and reads the actual rendered node size from the DOM.
  4. Flow then runs Dagre automatically and sends the new positions back through writeback.

That is why this example does not pass node sizes into generateGraph(...). Real measured sizes come from rendered nodes, and defaultNodeSize is only a fallback for cases where a measurement is not available yet.

Example

[example.html] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/libs/f-examples/plugins/dagre-layout-auto/example.html [example.ts] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/libs/f-examples/plugins/dagre-layout-auto/example.ts [example.scss] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/libs/f-examples/plugins/dagre-layout-auto/example.scss [apply-layout.ts] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/libs/f-examples/plugins/utils/apply-layout.ts [generate-graph.ts] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/libs/f-examples/plugins/utils/generate-graph.ts [layout-connection-sides.ts] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/libs/f-examples/plugins/utils/layout-connection-sides.ts [layout-controls.ts] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/libs/f-examples/plugins/utils/layout-controls.ts

Install

If you prefer manual installation:

You do not need to install dagre separately because the adapter ships it as a runtime dependency.

How Auto Mode Works

  1. Provide the layout engine with mode: EFLayoutMode.AUTO.
  2. Rebuild and render your nodes and connections in f-flow.
  3. When the rendered graph changes, Flow collects measured node sizes and calls calculate(...) automatically.
  4. Use setInteractiveOptions(...) to keep the engine in sync with toolbar state.
  5. Use setWriteback(...) to sync calculated positions back into your application state.

What This Example Shows

  • Rebuilding the source graph reactively from toolbar state, just like the manual example
  • Letting auto mode calculate positions after render instead of calling calculate(...) manually
  • Measuring real rendered node sizes from Flow instead of passing size in the demo graph
  • Keeping application state in sync through writeback
  • Reusing the same graph factory as the manual example with less layout code in the component

When To Choose Auto Mode

Use auto mode when you want Flow to orchestrate the layout cycle for you:

  • render the graph
  • measure nodes
  • call the layout engine
  • apply new positions
  • redraw connections

Manual mode is still the better choice when you need full control over exactly when layout runs or when layout should happen outside the rendered Flow lifecycle.

Related docs and examples

Edit this page on GitHub