@samatawy/diagrams
    Preparing search index...

    Class FitViewport

    FitViewport is a utility class that provides methods to adjust the viewport of a DiagramView to fit its content (nodes) within the visible area. It calculates the appropriate zoom level and pan offset based on the dimensions of the nodes and the canvas, allowing for different alignment options (center, left, right, top, bottom). The class also includes methods to clamp the zoom level within specified minimum and maximum values.

    Index

    Constructors

    • Creates an instance of FitViewport and attaches it to a DiagramView. This allows the FitViewport to manipulate the viewport of the DiagramView when fitting content.

      Parameters

      • diagram: DiagramView

        the DiagramView instance to attach to

      • Optionaloptions: { minZoom?: number; maxZoom?: number }

        optional configuration for minimum and maximum zoom levels

      Returns FitViewport

    Methods

    • Adjusts the viewport to fit the width of the nodes within the visible area of the canvas.

      Parameters

      • Optionaloptions: { padding?: number; alignment?: FitAlign }

        Optional configuration for padding and alignment.

      Returns void

    • Adjusts the viewport to fit all nodes within the visible area of the canvas.

      Parameters

      • Optionaloptions: { padding?: number; alignment?: FitAlign }

        Optional configuration for padding and alignment.

      Returns void

    • Applies the calculated viewport settings (zoom and pan) to the diagram based on the provided bounds. This method applies a transform to the diagram's canvas and coordinate system.

      Parameters

      • bounds: IRect

        The bounding rectangle of the content to fit.

      • zoom: number

        The zoom level to apply.

      • padding: number

        The padding to apply around the content.

      • Optionalalignment: FitAlign

        The alignment options for fitting the content.

      Returns void

    • Clamps the zoom value to the allowed range defined by minZoom and maxZoom.

      Parameters

      • value: number

        The zoom value to clamp.

      Returns number

      The clamped zoom value.