Skip to main content
Version: 4.2

MSAGL

@joint/layout-msagl integrates the Microsoft Automatic Graph Layout (MSAGL) layered layout with JointJS. The package exposes the layout() function together with helper types for configuring the Sugiyama router.

See the learn section for installation steps and examples.

Functions​

layout()​

layout(graphOrCells: dia.Graph | dia.Cell[], options?: Options): LayoutResult;

Rearranges the provided JointJS graph or an array of cells using the MSAGL Sugiyama algorithm and returns a LayoutResult. The bbox field accounts for the tight bounding box of the laid out graph and the fields msGraph and msGeomGraph can be utilized to interact with the underlying MSAGL objects, you can find more information about them in the MSAGL documentation.

Options​

OptionTypeDescription
layerDirectionLayerDirectionEnumControls the direction in which MSAGL stacks layers. Defaults to LayerDirectionEnum.TB.
layerSeparationnumberSets the minimum vertical gap between successive layers. Defaults to 40.
nodeSeparationnumberSets the minimum horizontal gap between nodes that belong to the same layer. Defaults to 20.
polylinePaddingnumberAdds extra clearance between routed polylines and element boundaries. Defaults to 1.
rectilinearSelfEdgeOffsetnumberOffsets rectilinear self-loops vertically so they stay clear of the source element. Defaults to 10.
gridSizenumberGrid size for routing; applied to X and Y. Set 0 to disable snapping. Defaults to 0.
edgeRoutingModeEdgeRoutingModeSwitches between orthogonal (Rectilinear) and bundled spline (SplineBundling) routing. Defaults to EdgeRoutingMode.Rectilinear.
xnumberControls the x coordinate of the top-level graph origin. Defaults to 0.
ynumberControls the y coordinate of the top-level graph origin. Defaults to 0.
clusterPaddingdia.SidesPadding reserved inside subgraph clusters. Pass a number for uniform padding or an object for per-side values. Defaults to 10.
getSize(element: dia.Element) => dia.SizeReturns the element size MSAGL should use during layout. Defaults to element.size().
getLabelSize(cell: dia.Cell) => dia.Size | undefinedProvides label dimensions so edges and subgraphs reserve space. Defaults to cell.get('labelSize'); return undefined to ignore a label.
setPosition(element: dia.Element, position: dia.Point) => voidInvoked with each element's new top-left position. Defaults to element.position(x, y).
setVerticesboolean | (link: dia.Link, vertices: dia.Point[]) => voidControls whether links are updated with the (sampled) vertices. Defaults to true (calls link.vertices(vertices)). Pass false to keep existing routing. If the option is defined as a function it will be used to set the vertices of links at the end of the layout. This is useful if you don't want to use the default but want to set the vertices in an animated fashion via transitions.
setLabelsboolean | (link: dia.Link, labelBBox: dia.BBox, points: dia.Point[]) => voidApplies computed label geometry along the routed edge. Defaults to updating the first label via distance/offset; pass false to skip.
setAnchorboolean | (link: dia.Link, linkEndPoint: dia.Point, bbox: dia.BBox, endType: 'source' | 'target') => voidAdjusts link anchors to match MSAGL entry/exit points. Defaults to assigning the modelCenter anchor; pass false to skip.
setClusterSize(element: dia.Element, size: dia.Size) => voidSets the size of a cluster. Defaults to element.size(size).

Types​

EdgeRoutingMode​

enum EdgeRoutingMode {
SplineBundling = 1,
Rectilinear = 4
}

SplineBundling enables smooth bundled splines, while Rectilinear routes orthogonal polylines (the default).

GetLabelSizeCallback​

type GetLabelSizeCallback = (cell: dia.Cell) => dia.Size | undefined;

GetSizeCallback​

type GetSizeCallback = (element: dia.Element) => dia.Size;

LayerDirectionEnum​

enum LayerDirectionEnum {
TB,
LR,
BT,
RL
}

Use TB, BT, LR, or RL to control the top-level flow direction.

LayoutResult​

interface LayoutResult {
bbox: g.Rect;
msGraph: msagl.Graph;
msGeomGraph: msagl.GeomGraph;
}

Options​

interface Options {
layerDirection?: layout.MSAGL.LayerDirectionEnum;
layerSeparation?: number;
nodeSeparation?: number;
polylinePadding?: number;
rectilinearSelfEdgeOffset?: number;
gridSize?: number;
edgeRoutingMode?: layout.MSAGL.EdgeRoutingMode;
x?: number;
y?: number;
clusterPadding?: dia.Sides;
getSize?: layout.MSAGL.GetSizeCallback;
getLabelSize?: layout.MSAGL.GetLabelSizeCallback;
setPosition?: layout.MSAGL.SetPositionCallback;
setVertices?: boolean | layout.MSAGL.SetVerticesCallback;
setLabels?: boolean | layout.MSAGL.SetLabelsCallback;
setAnchor?: boolean | layout.MSAGL.SetAnchorCallback;
setClusterSize?: layout.MSAGL.SetClusterSizeCallback;
}

SetAnchorCallback​

type SetAnchorCallback = (link: dia.Link, linkEndPoint: dia.Point, bbox: dia.BBox, endType: 'source' | 'target') => void;

SetClusterSizeCallback​

type SetClusterSizeCallback = (element: dia.Element, size: dia.Size) => void;

SetLabelsCallback​

type SetLabelsCallback = (link: dia.Link, labelBBox: dia.BBox, points: dia.Point[]) => void;

SetPositionCallback​

type SetPositionCallback = (element: dia.Element, position: dia.Point) => void;

SetVerticesCallback​

type SetVerticesCallback = (link: dia.Link, vertices: dia.Point[]) => void;