SVG Graph Network API Documentation - v0.2.0
    Preparing search index...

    Class Node<T>

    Node class representing a graph node with position, velocity, and force vectors Enhanced with full TypeScript support and generic node data

    Type Parameters

    Index

    Constructors

    • Create a new Node instance

      Type Parameters

      Parameters

      • data: T

        Node data containing id, name, and other properties

      • containerWidth: number = 800

        Container width for random positioning (default: 800)

      • containerHeight: number = 600

        Container height for random positioning (default: 600)

      Returns Node<T>

    Properties

    position: Vector

    Position vector of the node

    velocity: Vector

    Velocity vector for physics simulation

    force: Vector

    Force vector accumulator for physics simulation

    size: number

    Visual size of the node in pixels

    isFixed: boolean

    Whether the node is fixed in position

    dynamicWidth: null | number = null

    Dynamic width for rectangular nodes (calculated by renderer)

    dynamicHeight: null | number = null

    Dynamic height for rectangular nodes (calculated by renderer)

    data: T

    Node data containing id, name, and other properties

    Methods

    • Reset the node's position to a random location within the specified bounds This also resets velocity to zero but preserves the fixed state for position

      Parameters

      • containerWidth: number

        New container width

      • containerHeight: number

        New container height

      Returns void

    • Fix the node at its current position and reset velocity Fixed nodes will not be affected by physics forces

      Returns void

    • Unfix the node, allowing it to move freely with physics

      Returns void

    • Get the display name of the node

      Returns string

      The node's display name

    • Get the unique identifier of the node

      Returns string

      The node's unique ID

    • Get the type of the node for styling and grouping

      Returns undefined | string

      The node's type or undefined if not specified

    • Get the shape of the node for rendering

      Returns "circle" | "rectangle" | "square" | "triangle"

      The node's shape or 'circle' as default

    • Check if this node has the same type as another node

      Parameters

      • other: Node

        Other node to compare with

      Returns boolean

      True if both nodes have the same type

    • Calculate the distance to another node

      Parameters

      • other: Node

        Other node

      Returns number

      Distance between nodes

    • Calculate the direction vector to another node

      Parameters

      • other: Node

        Other node

      Returns Vector

      Normalized direction vector pointing towards the other node

    • Apply a force to this node (accumulates with existing force)

      Parameters

      • force: Vector

        Force vector to apply

      Returns void

    • Reset the accumulated force to zero

      Returns void

    • Update the node's position based on current velocity and force This is typically called by the physics engine

      Parameters

      • deltaTime: number = 1

        Time step for integration (default: 1)

      • damping: number = 0.95

        Velocity damping factor (default: 0.95)

      Returns void

    • Get the effective radius for collision detection Takes into account different shapes and dynamic sizing

      Returns number

      Effective radius for physics calculations

    • Clone this node with the same data but reset physics state

      Parameters

      • OptionalcontainerWidth: number

        Container width for new position

      • OptionalcontainerHeight: number

        Container height for new position

      Returns Node<T>

      New node instance with cloned data

    • Convert node to a serializable object

      Returns {
          data: T;
          position: { x: number; y: number };
          velocity: { x: number; y: number };
          isFixed: boolean;
          size: number;
      }

      Object representation including data and current state

    • Create a string representation of the node

      Returns string

      String representation

    • Create a node from a serialized object

      Type Parameters

      Parameters

      • obj: {
            data: T;
            position?: { x: number; y: number };
            velocity?: { x: number; y: number };
            isFixed?: boolean;
            size?: number;
        }

        Serialized node object

      • OptionalcontainerWidth: number

        Container width (if position should be reset)

      • OptionalcontainerHeight: number

        Container height (if position should be reset)

      Returns Node<T>

      New node instance