transform

The transform namespace performs structural graph rewrites — operations that change the shape of the graph by adding, removing, or rerouting nodes and edges in bulk. Unlike style (visual) or filter (visibility), transforms permanently restructure the data.

All five operations are fully undoable. Each emits one history entry regardless of how many internal edges or nodes are affected.

The five operations

Method Purpose Typical use
merge Collapse multiple nodes (or edges) that share key properties into one survivor De-dupe a dataset where the same entity appears with multiple ids
aggregate Group nodes by a property and create one summary node per group "Companies" by industry, "people" by city
extract Pull a property value out into its own node, with edges back to the originals Turn a city field into Location nodes connected to their People
shortcut Replace a 2-hop path through an intermediary with a single direct edge Skip past "joining" nodes in a path query
link Create edges between every pair of nodes matching a predicate Materialise an implicit "same-cohort" relationship

Example: aggregate by category

const result = await api.transform.aggregate({
  groupBy: "category",          // create one summary node per distinct category
  countProperty: "count",       // store member count on each summary
  aggregations: {
    avgScore: { type: "avg", source: "score" },
    totalRev: { type: "sum", source: "revenue" },
  },
});

console.log(result.created.nodes.length); // number of summary nodes added
console.log(result.removed.nodes.length); // 0 — aggregate keeps originals by default

Pass { removeOriginals: true } in AggregateOptions to collapse the source nodes into the summary (true rollup) instead of keeping both layers.

Result shape

Every method returns a TransformResult:

interface TransformResult {
  created: { nodes: NodeData[]; edges: EdgeData[] };
  removed: { nodes: NodeData[]; edges: EdgeData[] };
}

This makes it easy to follow up with a selection or camera focus on what was just created:

const result = await api.transform.extract({ property: "city", category: "Location" });
api.selection.selectNodes(result.created.nodes.map(n => n.id));
await api.camera.flyToNodes(result.created.nodes.map(n => n.id));

Combining with selection

All transforms accept either a target: "all" (operate on every node/edge) or a target: "selection" (only currently selected). Use the latter to build interactive workflows where the user picks the input set in the canvas, then triggers a transform from a menu.

api.selection.selectNodes(["p1", "p2", "p3"]);
await api.transform.merge({
  target: "selection",
  keyProperty: "email",     // collapse those 3 if they share an email
});

Methods