@samatawy/diagrams
    Preparing search index...

    Class NodeBasics

    Provides basic operations for manipulating nodes, such as moving, resizing, rotating, and checking for overlaps or containment. These utilities are designed to work with nodes in a diagram editor, allowing for transformations and hit testing based on the node's geometry and the diagram's coordinate system. The methods take into account the node's points, angle, and bounding rectangle to perform accurate calculations for movement, resizing, and selection. This class can be used as a foundation for implementing more complex node behaviors in a diagram editing application.

    Index

    Constructors

    Methods

    • Moves a node by the specified deltas.

      Parameters

      • node: INode

        The node to move.

      • byX: number

        The horizontal delta.

      • byY: number

        The vertical delta.

      • Optionalflags: "ignore_scale" | null

        Optional flags for movement behavior.

      Returns void

    • Resizes a node based on the specified handle and movement deltas.

      Parameters

      • node: INode

        The node to resize.

      • handle: NodeHandle

        The handle being used for resizing.

      • byX: number

        The horizontal movement delta.

      • byY: number

        The vertical movement delta.

      • OptionalpreserveAspect: boolean

        Whether to preserve the aspect ratio during resizing.

      Returns void

    • Rotates a node to the specified angle.

      Parameters

      • node: INode

        The node to rotate.

      • degrees: number

        The angle to rotate the node to.

      • kind: "degrees" | "radians" = 'degrees'

        The unit of the angle, either 'degrees' or 'radians'.

      Returns void

    • Checks if a node overlaps with a target rectangle or another node's bounding rectangle.

      Parameters

      • node: INode

        The node to check.

      • target: IRect | INode

        The target rectangle or node to check against.

      Returns boolean

      True if the node overlaps with the target, false otherwise.

    • Checks if a node is fully inside a target rectangle or another node's bounding rectangle.

      Parameters

      • node: INode

        The node to check.

      • target: IRect | INode

        The target rectangle or node to check against.

      Returns boolean

      True if the node is fully inside the target, false otherwise.

    • Returns the longest segment from an ordered point list.

      Parameters

      • points: IPoint[]

        Ordered polyline points.

      Returns { from: IPoint; to: IPoint } | undefined

      The longest segment endpoints, or undefined when fewer than two points are provided.

    • Determines whether a line orientation is considered inverted.

      Parameters

      Returns boolean

      True when the line should be flipped by normalizeLine.

    • Finds the nearest allowed connection handle for a point. The result belongs to the 'node' argumewnt and can connect to the 'target' argument in the specified direction. The returned handle is guaranteed to be valid for connection purposes, or MOVE if the point is inside the node and MOVE is allowed.

      Parameters

      • node: INode

        Target node.

      • direction: "from" | "to"

        Connection direction, either 'from' or 'to'.

      • target: INode | undefined

        Optional target node for connection validation.

      • point: IPoint

        Lookup point in world coordinates.

      • is_inside: boolean

        Whether inside hits should resolve to MOVE fallback when supported.

      • Optionaltolerance: number

        Interior distance threshold.

      Returns IHandlePoint | undefined

      Nearest connection handle and snapped point, or undefined when no candidate is found.

    • Resolves the exact connection handle hit at a point within a tolerance.

      Parameters

      • node: INode

        Target node.

      • point: IPoint

        Lookup point in world coordinates.

      • direction: "from" | "to" | "any" = 'any'
      • target: Partial<INode>
      • tolerance: number = DiagramConstants.HANDLE_HIT_EPSILON

        Maximum distance for a handle hit.

      Returns IHandlePoint | undefined

      Matching handle and snapped point, or undefined when no candidate matches.