Skip to content
Back to skills

Camera

ASecurity

Camera control, modes, centering, and viewport manipulation.

  • 4 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 27, 2026
data-ainode

Works with

  • cli

Security analysis

A100/100

Scanned May 27, 2026

npx -y skills add reaviz/skills --skill camera --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Camera?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Camera
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/reaviz-camera/badge)](https://www.skillsdirectory.com/skills/reaviz-camera)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Camera

Camera control, modes, centering, and viewport manipulation.

## Import

```tsx
import { GraphCanvas, useCameraControls, useCenterGraph } from 'reagraph';
```

## CameraMode

Set via `cameraMode` on `GraphCanvas`:

| Mode | Description |
|------|-------------|
| `'pan'` | Pan and zoom (default, best for 2D) |
| `'rotate'` | Rotate and zoom |
| `'orbit'` | Full orbit control (best for 3D) |
| `'orthographic'` | Orthographic projection with pan/zoom |

## GraphCanvas Camera Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `cameraMode` | `CameraMode` | `'pan'` | Camera interaction mode |
| `maxDistance` | `number` | `50000` | Max camera distance (perspective) |
| `minDistance` | `number` | `1000` | Min camera distance (perspective) |
| `minZoom` | `number` | `1` | Min zoom level (orthographic) |
| `maxZoom` | `number` | `100` | Max zoom level (orthographic) |

## useCameraControls Hook

Access camera controls imperatively from inside the Three.js context:

```tsx
const {
  controls,
  resetControls,
  zoomIn,
  zoomOut,
  dollyIn,
  dollyOut,
  panLeft,
  panRight,
  panUp,
  panDown,
  freeze,
  unFreeze,
} = useCameraControls();
```

| Method | Description |
|--------|-------------|
| `resetControls(animated?)` | Reset camera to initial state |
| `zoomIn()` / `zoomOut()` | Zoom camera |
| `dollyIn(distance?)` / `dollyOut(distance?)` | Move camera closer/further (default: 1000) |
| `panLeft(delta?)` / `panRight(delta?)` | Pan horizontally (default: 100) |
| `panUp(delta?)` / `panDown(delta?)` | Pan vertically (default: 100) |
| `freeze()` / `unFreeze()` | Freeze/unfreeze camera controls |

## useCenterGraph Hook

Center or fit nodes into the viewport:

```tsx
const {
  centerNodes,
  centerNodesById,
  fitNodesInViewById,
  isCentered,
} = useCenterGraph({ animated: true, layoutType });
```

| Method | Description |
|--------|-------------|
| `centerNodes(nodes, opts?)` | Center on node objects |
| `centerNodesById(ids, opts?)` | Center on node IDs |
| `fitNodesInViewById(ids, opts?)` | Fit nodes into viewport |

### Options

```ts
interface CenterNodesParams {
  animated?: boolean;
  centerOnlyIfNodesNotInView?: boolean;
}

interface FitNodesParams {
  animated?: boolean;
  fitOnlyIfNodesNotInView?: boolean;
}
```

## Using Ref (Outside Three.js Context)

For camera control outside the canvas, use the `GraphCanvasRef`:

```tsx
const ref = useRef<GraphCanvasRef>(null);

<GraphCanvas ref={ref} nodes={nodes} edges={edges} />

<button onClick={() => ref.current?.centerGraph()}>Center</button>
<button onClick={() => ref.current?.zoomIn()}>Zoom In</button>
<button onClick={() => ref.current?.fitNodesInView(['1', '2'])}>Fit Nodes</button>
```

## 2D Mode

```tsx
<GraphCanvas
  nodes={nodes}
  edges={edges}
  cameraMode="pan"
  layoutType="forceDirected2d"
/>
```

## 3D Mode

```tsx
<GraphCanvas
  nodes={nodes}
  edges={edges}
  cameraMode="orbit"
  layoutType="forceDirected3d"
/>
```

## Orthographic Mode

```tsx
<GraphCanvas
  nodes={nodes}
  edges={edges}
  cameraMode="orthographic"
  minZoom={0.5}
  maxZoom={50}
/>
```

## Notes

- `useCameraControls` and `useCenterGraph` must be used inside the Three.js context (child of `GraphCanvas`)
- For external control, use the `GraphCanvasRef` methods instead
- `cameraMode="orbit"` is recommended for 3D layouts
- `cameraMode="pan"` is recommended for 2D layouts

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.