PathLogs UI
Русский

Widgets

FlowCanvas

A pan/zoom canvas with nodes and edges — a small react-flow.

A pan/zoom canvas with nodes and edges — a small react-flow. The canvas pans by dragging, zooms with the wheel, and nodes move and snap to the grid.

Installation

terminal
npx @toimetdev/pathlogs-ui add flow-canvas

Example

Источник
Преобразование
Фильтр
Приёмник
100%

Drag the background and the canvas pans. The wheel zooms. Nodes drag and land on the grid. The ⤢ button fits everything into view.

Props

nodes*N[]

The nodes: id, x, y, width?, height?.

renderNode*(node, meta) => ReactNode

A node's contents.

edgesFlowEdge[]

defaults to: []

Links, with optional port sides.

onNodesChange(nodes) => void

The new positions after a drag. Without it nodes do not move.

gridnumber

defaults to: 20

The grid step for snapping and the background. 0 disables the grid.

onSelect(node | null) => void

Selecting a node, or clearing it by clicking the background.

Zooming to the cursor

The maths, separately

tsx
import {
  worldToScreen, screenToWorld,  // mutually inverse transforms
  zoomAt,                        // zoom that preserves the point under the cursor
  fitView,                       // a camera that fits everything on screen
  snapToGrid, portPoint, edgePath,
} from "@/components/ui/flow-canvas/viewport";