Skip to content
D
Documentation

LayoutApplicator

reference
1 min readUpdated

Import it from @grafloria/engine.

ts
class LayoutApplicator

Methods

  • constructor(options: LayoutApplicatorOptions = {})
  • async applyOptimalLayout( diagram: DiagramModel, ast?: DiagramNode ): Promise<LayoutApplicationResult> — Detect and apply optimal layout
  • async 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): void
  • async applyCustomLayout( diagram: DiagramModel, config: LayoutConfiguration ): Promise<LayoutApplicationResult> — Apply layout with custom configuration
  • suggestLayout(diagram: DiagramModel, ast?: DiagramNode): LayoutSuggestion — Get layout suggestion without applying
  • listPresets(): Array<{ id: string; name: string; category: string }> — List all available presets
  • setMinConfidence(threshold: number): void — Set minimum confidence threshold
  • addCustomLayout(id: string, config: LayoutConfiguration): void — Add custom layout preset
  • removeCustomLayout(id: string): boolean — Remove custom layout preset

Was this page helpful?

LayoutApplicator — Grafloria