Skip to content

Graph Layout

Pivotick supports multiple layout strategies for positioning nodes. You can configure the layout through the layout option.

OptionTypeDefaultDescription
type'force' | 'tree''force'The layout algorithm to use. 'force' applies a physics-based force layout. 'tree' arranges nodes in a tree structure.

Tree Layout Options

When type: 'tree' is selected, the following additional options are available:

OptionTypeDefaultDescription
rootIdstringundefinedSpecify the ID of the node to use as the root. If not provided, Pivotick will automatically select a root based on rootIdAlgorithmFinder.
rootIdAlgorithmFinder-MaxReachabilityAlgorithm used to automatically find the root node.
strengthnumber0.1The force strength to maintain tree structure.
horizontalbooleanfalseArrange nodes horizontally rather than vertically.
radialbooleanfalsePlace nodes in a radial layout instead of vertical.
radialGapnumber750Gap between layers in radial layout.
flipEdgeDirectionbooleanfalseFlip the direction of edges in the layout.

Tree Root Finder

In a tree-based layout, one node must be designated as the root. You can specify the root node using the rootId option.

If you're unsure which node should be the root, don't worry! Pivotick will automatically select one using the algorithm defined in rootIdAlgorithmFinder.

Similarly, the flipEdgeDirection option lets you reverse the direction of edges in a directed graph (so A -> B becomes B -> A)—this only affects the layout computation, not the underlying graph data.

DANGER

Add example with the two layouts!

Vertical Tree

js
const options = {
    layout: {
        type: 'tree'
    },
    UI: {
        mode: 'static'
    }
}

Vertical Tree

js
const options = {
    layout: {
        type: 'tree',
        radial: true,
        radialGap: 300,
    },
    UI: {
        mode: 'static'
    }
}