This page shows how to use @foblex/flow-elk-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 ELK.js to recalculate positions automatically.
The important split is:
@foblex/flow-elk-layout calculates node positions with ELK.js@foblex/flow detects graph changes, runs auto relayout, and redraws the scenewritebackThe manual example explicitly calls calculate(...) and usually passes a size for every node before rendering.
This auto example works differently:
f-flow.getState({ measuredSize: true }) internally and reads the actual rendered node size from the DOM.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.html] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/libs/f-examples/plugins/elk-layout-auto/example.html [example.ts] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/libs/f-examples/plugins/elk-layout-auto/example.ts [example.scss] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/libs/f-examples/plugins/elk-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
If you prefer manual installation:
You do not need to install elkjs separately because the adapter ships it as a runtime dependency.
mode: EFLayoutMode.AUTO.f-flow.calculate(...) automatically.setInteractiveOptions(...) to keep the engine in sync with toolbar state.setWriteback(...) to sync calculated positions back into your application state.calculate(...) manuallysize in the demo graphwritebackUse auto mode when you want Flow to orchestrate the layout cycle for you:
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.