camera

The camera namespace controls the viewpoint: where the camera is positioned, what it is looking at, and how far it is zoomed. Camera operations are pure view-state changes — they are not recorded in the undo/redo history and do not emit events on the shared event bus.

Fitting the view

The most common camera task is fitting the viewport around a set of nodes after data is loaded or a layout is applied.

// Fit the camera to every node in the graph.
await api.camera.flyToAll();

// Fit the camera to a specific subset of nodes.
await api.camera.flyToNodes(["s1", "s2", "s3"], { duration: 600 });

Both methods compute the bounding box of the target nodes and animate cloudScene so those nodes are centered and padded in the viewport (1.5× padding by default). Pass { duration: 0 } to skip animation and jump instantly.

Choosing the right camera operation

Five camera operations cover the common cases, and they are easy to confuse:

Method What it does When to use it
flyToAll() Fits the view to every node's bounding box After loading data or running a layout
flyToNodes(ids) Fits the view to a subset of nodes Focusing on a selection or category
flyToPosition(pos) Flies to an arbitrary world-space coordinate Programmatic navigation to a known point
zoomIn(delta) / zoomOut(delta) Increments or decrements the Z zoom value by delta Nudging the zoom level without reframing
resetRotation() Animates the scene rotation back to (0, 0, 0) Restoring the default orientation after orbit

zoomOut changes the zoom by delta units on each call — repeated calls compound. To back out to a specific level, prefer flyToAll or flyToNodes which compute the correct zoom from the data bounds.

Animation options

All fly-to methods accept a FlyToOptions object:

interface FlyToOptions {
  duration?: number; // ms, default 400. Pass 0 for instant.
  scale?: number;    // bounding-box padding factor, default 1.5
  offset?: number;   // override the Z offset instead of computing from bbox
}

resetRotation accepts AnimateOptions:

interface AnimateOptions {
  duration?: number; // ms, default 400
  smooth?: boolean;  // interpolate (default true) vs snap
}

Auto-rotation

setAutoRotate(enabled, speed?) starts or stops a continuous y-axis rotation loop. The optional speed argument is in radians per frame (default 0.005).

api.camera.setAutoRotate(true, 0.01);  // start fast rotation
api.camera.setAutoRotate(false);        // stop

Screen projection

worldToScreen(point) projects a world-space { x, y, z } position to canvas pixel coordinates, useful for positioning HTML overlays above nodes.

const px = api.camera.worldToScreen({ x: 1, y: 0, z: 0 });
if (px) console.log(`pixel: ${px.x.toFixed(0)}, ${px.y.toFixed(0)}`);

Returns null when the camera is not yet wired.

Methods