@samatawy/diagrams
    Preparing search index...

    Class RenderBasics

    Provides basic rendering utilities for diagram nodes, including preparation of the canvas context for drawing nodes and their text. It handles setting up styles, shadows, and transformations based on node properties such as angle and transparency. The class also includes logic for rendering multi-line text within nodes, taking into account text alignment and baseline settings.

    Index

    Constructors

    Methods

    • Prepares the canvas context for rendering a node, including setting styles, shadows, and transformations.

      Parameters

      • node: INode

        The node to prepare for rendering.

      • context: CanvasRenderingContext2D

        The canvas rendering context.

      • show: "all" | "quick" = 'all'

      Returns void

    • Skips shadow for subsequent draw calls on the context. Call this after fill and before stroke when shadow should not apply to the stroke.

      Parameters

      • context: CanvasRenderingContext2D

      Returns void

    • Prepares the canvas context for rendering node handles, including setting styles and transformations based on node properties.

      Parameters

      • node: INode

        The node for which to prepare handles.

      • context: CanvasRenderingContext2D

        The canvas rendering context.

      Returns void

    • Parameters

      • node: INode
      • point: IPoint
      • path: Path2D
      • canvas: CanvasRenderingContext2D

      Returns void

    • Renders the node's image onto the canvas, clipped to the given shape path. Respects image_mode, image_padding, and image_align from the node.

      • 'fit' — stretches the image to fill the padded rect (ignores aspect ratio).
      • 'contain' — scales the image to fit inside the padded rect, preserving aspect ratio, positioned according to image_align (default 'center').
      • 'pattern' — no-op; pattern fill is applied in prepare() via createPattern.
      • 'none' — no-op.

      Must be called inside a context.save() / context.restore() block, after prepare(). Pass the shape's path for non-rectangular shapes so the image is clipped correctly.

      Parameters

      • node: INode

        The node being rendered.

      • context: CanvasRenderingContext2D

        The canvas rendering context.

      • rect: IRect

        The node's bounding rect in canvas coordinates.

      • Optionalpath: Path2D

        Optional clip path (the filled shape). When omitted the image is drawn unclipped.

      Returns void

    • Renders the text for a node, taking into account text alignment, overflow, and clipping options. Text options can define 2 points: from and to - if provided, the text is rendered on the slope between them.

      N.B. After rendering the text path is cached for hit-testing.

      Parameters

      • node: INode

        The node for which to render text.

      • context: CanvasRenderingContext2D

        The canvas rendering context.

      • options: TextOptions

        Options for text rendering, including overflow and clipping path.

      Returns void

    • Renders the arrows for a connection node.

      Parameters

      • node: INode & IConnection

        The connection node to render arrows for.

      • context: CanvasRenderingContext2D

        The canvas rendering context.

      • Optionalpoints: IPoint[]

      Returns void