Skip to content
GalleryOpen Garphield

Layouts and animation

Asynchronous Force layouts reveal moving nodes by default. Connected nodes flock together, then decelerate into the completed layout over about 1.7 seconds. Links then grow into view over 0.6 seconds. Levels moves directly to its completed layout without this animation. Reduced-motion preferences also disable the animation. Cancelling a layout or loading another graph cancels its preview.

For layouts above 5,000 nodes or 20,000 edges, a preparation indicator can appear before the animation begins. It clears while the animation is running.

Dense graphs open already simplified. A graph whose Full drawing reads opens with Group by and Backbone both off. Otherwise, if its node fields nest into groups that explain its links, it opens with Group by on, drawn as nested rings; if not, it opens with the Backbone on. Whichever is set this way is marked Auto until you change it. Group by (rings) draws under Force. Group by is the first well under Layers in the left panel, the Backbone is a switch in the top strip, and both are saved with the view. Merge by, beside Group by, draws one node per value of the node fields you pick; turning it on turns Group by and the Backbone off, and turning either of them on turns the merge off.

Levels arranges a graph in ordered bands. Directed graphs follow edge direction where possible; cycles require some upward edges. Wide levels can use several compact subrows. Automatic mode compares layered placements for crossings, edges through nodes, and spacing after fitting the canvas, retaining a single row when it is clearer.

For networks with large cycles, Levels also compares a placement that keeps related nodes close inside each cyclic group while preserving the direction of connections between groups. Disconnected fragments are handled independently.

Select one or more nodes, then click Levels to use them as roots. Every root starts in the top band. Bands follow shortest graph distance, ignoring edge direction; disconnected components get their own automatic roots. Equal property values stay in the same band, and the entire band remains above the next value even when it uses several subrows. Clicking Levels with no selection returns to automatic layout.

Root IDs are saved in shared views and projects. Loading another dataset clears them. Changing selection does not rearrange the graph until Levels is chosen again. Levels appears directly, without the Force layout animation.

The command API also accepts explicit IDs:

window.garphield.run("layout.levels", { roots: '["a","b"]' });
const result = await window.garphield.run("layout.wait");
if (!result.ok) throw new Error(result.error.message);

Use { levelAttribute: "stage" } to choose a property, { selectionAsRoots: true } to use the current selection, or {} to return to automatic layout. Await layout.wait after each request before reading positions or exporting an image.

When both options are supplied, explicit property values take precedence over root distances. Larger graphs use a bounded layout to keep interaction responsive.

For a tree, or nearly one, such as an organisation chart or a file system, the menu beside Levels switches from Bands to Tree, top-down or Tree, left to right. A tree draws each node under one parent, siblings packed as closely as their subtrees allow and each parent over the middle of its children (Reingold and Tilford’s tidy tree, in van der Ploeg’s version for boxes of any size, so every label gets room beside its node). Links are drawn square, from the parent down to a line above its children (or across to a line beside them) and into each child.

A node with many children that have none of their own lists them as a block rather than one long row: top-down, in rows either side of the parent’s line down; left to right, in columns. The block’s shape is chosen to make the whole drawing as large as the frame allows. Labels sit right of their nodes, as in bands, and a label that would cover another node stays hidden until you zoom in.

The roots work as in bands: selected nodes, or roots; otherwise a directed graph starts from the nodes nothing points to, and an undirected one from the middle of its longest path. A graph that is not a tree is drawn from a spanning tree, found breadth first from the roots and following links in their direction where it can; its other links (a second parent, a link across the tree) are drawn as curves. A tree’s levels are its depths, so it takes no level property.

window.garphield.run("layout.levels", { style: "tree", direction: "right" });

style is layered (bands, the default) or tree; direction, for a tree only, is down (the default) or right. Both are saved in shared views and projects. Laying out again, or picking new roots, keeps the tree.

Coordinate layout is available only when the graph has a usable field pair. Garphield recognizes latitude/longitude names and formats, as well as original X/Y fields. Geographic evidence determines whether the layout uses a basemap; ambiguous X/Y pairs start on the plain canvas with a Use geographic map option.

A unique pair is selected automatically. If several pairs are compatible, choose the fields and click Apply. Nodes without usable coordinates are omitted from that layout along with their incident edges; the controls report how many nodes were placed. Imported coordinates remain available after running Force or Levels and when saving a project.