NgDiagramViewportService
The NgDiagramViewportService
provides methods and signals for interacting with the diagram viewport.
Example usage
Section titled “Example usage”private viewportService = inject(NgDiagramViewportService);
// Move viewport to (100, 200)this.viewportService.moveViewport(100, 200);
// Zoom in by a factor of 1.2this.viewportService.zoom(1.2);
Extends
Section titled “Extends”NgDiagramBaseService
Properties
Section titled “Properties”scale:
Signal
<number
>
Returns a computed signal for the scale that safely handles uninitialized state.
viewport
Section titled “viewport”viewport:
Signal
<Viewport
>
Returns a computed signal for the viewport that safely handles uninitialized state.
Methods
Section titled “Methods”clientToFlowPosition()
Section titled “clientToFlowPosition()”clientToFlowPosition(
clientPosition
):Point
Converts a client position to a flow position.
Parameters
Section titled “Parameters”clientPosition
Section titled “clientPosition”Client position to convert.
Returns
Section titled “Returns”Flow position.
clientToFlowViewportPosition()
Section titled “clientToFlowViewportPosition()”clientToFlowViewportPosition(
clientPosition
):Point
Converts a client position to a position relative to the flow viewport.
Parameters
Section titled “Parameters”clientPosition
Section titled “clientPosition”Client position.
Returns
Section titled “Returns”Position on the flow viewport.
flowToClientPosition()
Section titled “flowToClientPosition()”flowToClientPosition(
flowPosition
):Point
Converts a flow position to a client position.
Parameters
Section titled “Parameters”flowPosition
Section titled “flowPosition”Flow position to convert.
Returns
Section titled “Returns”Client position.
moveViewport()
Section titled “moveViewport()”moveViewport(
x
,y
):void
Moves the viewport to the specified coordinates.
Parameters
Section titled “Parameters”number
The x-coordinate to move the viewport to.
number
The y-coordinate to move the viewport to.
Returns
Section titled “Returns”void
moveViewportBy()
Section titled “moveViewportBy()”moveViewportBy(
dx
,dy
):void
Moves the viewport by the specified amounts.
Parameters
Section titled “Parameters”number
The amount to move the viewport in the x-direction.
number
The amount to move the viewport in the y-direction.
Returns
Section titled “Returns”void
zoom()
Section titled “zoom()”zoom(
factor
,center?
):void
Zooms the viewport by the specified factor.
Parameters
Section titled “Parameters”factor
Section titled “factor”number
The factor to zoom by.
center?
Section titled “center?”The center point to zoom towards.
Returns
Section titled “Returns”void