Skip to content

@graphty/graphty-element / session / recommendLayout

Function: recommendLayout() ​

recommendLayout(statistics, options?): LayoutRecommendation | undefined

Defined in: graphty-element/src/session/layout.ts:175

Which arrangement suits this graph.

It never names an arrangement the element cannot serve: every candidate is resolved against the layout catalogue and skipped if it is missing, if it needs an input the caller has not supplied, or if the catalogue rates it below this graph's size.

Parameters ​

statistics ​

GraphStatistics

The graph's shape, from session.data.statistics().

options? ​

LayoutRecommendationOptions = {}

How many nodes carry a coordinate, and the large-graph threshold to use.

Returns ​

LayoutRecommendation | undefined

The recommendation, or undefined when the catalogue serves no arrangement that needs no further input -- which the shipped catalogue always does, so a consumer sees this only after the catalogue has been cut down.

Example ​

ts
const advice = recommendLayout(session.data.statistics(), {
    placedNodes: session.positions.placedCount,
});

if (advice !== undefined) {
    await element.setLayout(advice.layout.id);
}