Import it from @grafloria/engine.
tsclass LayoutApplicator
Methods
constructor(options: LayoutApplicatorOptions = {})async applyOptimalLayout( diagram: DiagramModel, ast?: DiagramNode ): Promise<LayoutApplicationResult>— Detect and apply optimal layoutasync applyLayoutPreset(diagram: DiagramModel, presetId: string): Promise<void>— Apply a specific layout preset.
THIS METHOD DID NOTHING. THE ENTIRE PRESET LIBRARY WAS DEAD.
It used to build:
const config: LayoutConfiguration = { algorithm: preset.adapter === 'dagre' ? 'dagre' : 'elk', ...preset.options, // rankdir, nodesep, 'elk.direction', … }; await diagram.reLayout(config);
and every part of that was inert:
• LayoutConfiguration has no algorithm field at all. It has type, and
the only legal values are 'grid' | 'force-directed' | 'hierarchical' |
'hybrid' — 'dagre' and 'elk' are not among them.
• reLayout() then OVERWRITES type with this.currentAlgorithm.getType(),
the LayoutManager's single-node placement strategy. So the preset's chosen
adapter was discarded before it was even mistyped.
• reLayout() reads adapter options from config.options (nested). The
preset's options were spread at the TOP level, so rankdir, nodesep,
ranker, elk.direction — every knob the 17 presets exist to set — were
never read by anything.
Net effect: "Org Chart (Compact)", "Workflow (Horizontal)" and "Force-Directed (Tight)" all produced the SAME picture, whatever the LayoutManager's current placement algorithm happened to be. The presets, the detector that chooses between them, and the confidence threshold that gates the choice were an elaborate no-op. This is the "config declared but never consumed" shape, and it survived six waves because nothing tested it.
getLayoutRegistry(): LayoutRegistry— The registry presets are applied through. Injectable, so a host that has replaced a built-in layout (or registered its own) gets its version here too rather than a second, private copy of the built-ins.setLayoutRegistry(registry: LayoutRegistry): voidasync applyCustomLayout( diagram: DiagramModel, config: LayoutConfiguration ): Promise<LayoutApplicationResult>— Apply layout with custom configurationsuggestLayout(diagram: DiagramModel, ast?: DiagramNode): LayoutSuggestion— Get layout suggestion without applyinglistPresets(): Array<{ id: string; name: string; category: string }>— List all available presetssetMinConfidence(threshold: number): void— Set minimum confidence thresholdaddCustomLayout(id: string, config: LayoutConfiguration): void— Add custom layout presetremoveCustomLayout(id: string): boolean— Remove custom layout preset
Was this page helpful?