layout

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package layout generates BPMN diagram interchange (BPMN-DI) for models that carry none, and regenerates it for models whose layout a user has tangled. It is the server-side auto-layout the Modeler's "Auto-layout" button calls and the fallback that lets a semantic-only deployed model still render (ADR-0124), implemented as the layered pipeline — rank, order, place, route — whose invariants ADR-0127 pins down.

The package is deliberately free of any engine or server dependency: it reads BPMN XML with its own minimal structs and writes BPMN-DI back, nothing more. It runs when a human fetches or re-arranges a model, never on the processor's hot path.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoDiagram means the incoming document carries no diagram interchange to
	// take — an empty <BPMNDiagram> included, since a plane with no shapes on it
	// would replace the stored picture with a blank canvas.
	ErrNoDiagram = errors.New("the model carries no diagram interchange")
	// ErrDifferentModel means the two documents do not describe the same process:
	// their semantic halves differ in some element, attribute or text. The diagram
	// is not transplanted, because a layout only means anything against the shapes
	// it was drawn for.
	ErrDifferentModel = errors.New("the model's semantic content differs from the stored one")
)

Errors Transplant returns. They are distinguished because the HTTP surface maps them to different statuses: a model whose meaning differs is the caller's mistake to fix (409), a body carrying no diagram is a malformed request (400).

Functions

func Ensure

func Ensure(src []byte) []byte

Ensure returns src unchanged if it already carries BPMN diagram interchange (a <BPMNDiagram>); otherwise it generates a simple left-to-right layered layout and injects one so bpmn-js can render the model. It is best-effort: on any parse or structural problem it returns src unchanged.

This runs when the UI fetches a model's XML — a rendering concern, never the engine hot path — so models deployed as pure semantic XML (no layout) still show up in the editor and the live overlay.

func EnsureReport added in v0.4.0

func EnsureReport(src []byte) ([]byte, bool)

EnsureReport is Ensure, additionally reporting whether it generated the layout — which a caller storing the result wants to know, so it can say where the diagram came from. False means the model already had one, or none could be generated; in both cases src comes back unchanged.

func Regenerate

func Regenerate(src []byte) []byte

Regenerate discards whatever diagram interchange the model already carries and generates a fresh left-to-right layout in its place. It backs the Modeler's "Auto-layout" button: a diagram a user has tangled by hand is re-flowed by the same generator that lays out a layout-less deployed model. Only shape and edge coordinates change — the semantic model (processes, flows, ids) is untouched.

Best-effort, like Ensure: if a new layout can't be generated (the XML won't parse, or the model has no layout-relevant nodes) src is returned unchanged rather than stripped of the layout it had.

func SameModel added in v0.5.0

func SameModel(a, b []byte) (bool, error)

SameModel reports whether two BPMN documents describe the same process — equal everywhere the engine looks, whatever their diagrams say. It is the question Transplant asks before it moves anything, exposed on its own so a caller can tell "you changed the model" from "the model won't parse" before offering to save a layout.

func Transplant added in v0.5.0

func Transplant(stored, incoming []byte) ([]byte, error)

Transplant returns the stored document with the incoming document's diagram interchange in place of its own. Only the picture moves: every byte of stored outside its <BPMNDiagram> blocks comes back unchanged, so the model the compiler already turned into a CompiledProcess is bit-for-bit the model it still holds — script bodies, documentation text, formatting and all.

It refuses with ErrDifferentModel unless the two documents' semantic halves are equal as XML (see semanticDigest), and with ErrNoDiagram if the incoming document has no shapes to give.

The incoming diagram is made self-contained on the way over: the namespace prefixes it uses are re-declared on the <BPMNDiagram> element itself, from the declarations its own document bound them to. Without that, a diagram written with prefixes the stored document's root does not declare would splice in as well-formed nonsense.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL