x4js - v2.2.49
    Preparing search index...

    Class SvgText

    Represents an SVG text element, providing methods for positioning and styling text. It extends SvgItem to inherit common SVG element functionalities.

    Hierarchy (View Summary)

    Index
    • Creates an instance of SvgText.

      Parameters

      • x: number

        The x-coordinate for the text's starting position.

      • y: number

        The y-coordinate for the text's starting position.

      • txt: string

        The text content.

      Returns SvgText

    _dom: SVGElement
    • Set the shape rendering attribute to control anti-aliasing for shapes.

      When enabled, the attribute is set to "auto" to allow smoothing/anti-aliasing. When disabled, the attribute is set to "crispEdges" to favor pixel-aligned, non-anti-aliased rendering.

      Parameters

      • set: boolean

        True to enable anti-aliasing ("auto"), false to disable ("crispEdges").

      Returns SvgText

      the current instance to allow chaining).

    • Sets the font family for the text.

      Parameters

      • font: string

        The font family name (e.g., "Arial", "sans-serif").

      Returns this

      The current SvgText instance for chaining.

    • Sets the font size for the text.

      Parameters

      • size: string | number

        The font size, either as a number (e.g., 12) or a string (e.g., "1.2em").

      Returns this

      The current SvgText instance for chaining.

    • Sets the font weight for the text.

      Parameters

      • weight: "bold" | "normal" | "light"

        The font weight ("light", "normal", or "bold").

      Returns this

      The current SvgText instance for chaining.

    • define a new attribute

      Parameters

      • name: string

        attibute name

      • value: string

        attribute value

      Returns this

      this

    • change one style value

      Type Parameters

      • K extends keyof CSSStyleDeclaration

      Parameters

      • name: K
      • value: string | number

      Returns this

    • change the stroke color

      Parameters

      • color: string
      • Optionalwidth: number

      Returns this

    • change the stroke opacity attribute on the element.

      Parameters

      • opacity: number

        Opacity value where 0 is fully transparent and 1 is fully opaque.

      Returns SvgText

      The current instance to allow method chaining.

    • Sets the horizontal text alignment.

      Parameters

      • align: "center" | "left" | "right"

        The horizontal alignment ("left", "center", or "right").

      Returns this

      The current SvgText instance for chaining.

    • change the vertical alignment

      Parameters

      • align: "center" | "top" | "bottom" | "baseline"

      Returns this