Skip to content

NgDiagramViewportService

The NgDiagramViewportService provides methods and signals for interacting with the diagram viewport.

private viewportService = inject(NgDiagramViewportService);
// Move viewport to (100, 200)
this.viewportService.moveViewport(100, 200);
// Zoom in by a factor of 1.2
this.viewportService.zoom(1.2);
  • NgDiagramBaseService

scale: Signal<number>

Returns a computed signal for the scale that safely handles uninitialized state.


viewport: Signal<Viewport>

Returns a computed signal for the viewport that safely handles uninitialized state.

clientToFlowPosition(clientPosition): Point

Converts a client position to a flow position.

Point

Client position to convert.

Point

Flow position.


clientToFlowViewportPosition(clientPosition): Point

Converts a client position to a position relative to the flow viewport.

Point

Client position.

Point

Position on the flow viewport.


flowToClientPosition(flowPosition): Point

Converts a flow position to a client position.

Point

Flow position to convert.

Point

Client position.


moveViewport(x, y): void

Moves the viewport to the specified coordinates.

number

The x-coordinate to move the viewport to.

number

The y-coordinate to move the viewport to.

void


moveViewportBy(dx, dy): void

Moves the viewport by the specified amounts.

number

The amount to move the viewport in the x-direction.

number

The amount to move the viewport in the y-direction.

void


zoom(factor, center?): void

Zooms the viewport by the specified factor.

number

The factor to zoom by.

Point

The center point to zoom towards.

void