x4js - v2.2.49
    Preparing search index...

    Class SvgBuilder

    A specialized SvgGroup that provides methods for adding SVG definitions like clip paths and patterns. It extends SvgGroup to inherit common SVG element functionalities and acts as a container for definitions.

    Hierarchy (View Summary)

    Index
    _dom: SVGElement
    • Adds an SVG clip path definition to the builder.

      Parameters

      • x: number

        The x-coordinate of the top-left corner of the clipping rectangle.

      • y: number

        The y-coordinate of the top-left corner of the clipping rectangle.

      • w: number

        The width of the clipping rectangle.

      • h: number

        The height of the clipping rectangle.

      Returns { clip: SvgGroup; id: string }

      An object containing the generated id for the clip path and the SvgGroup instance representing the clip path.

      • clip: SvgGroup
      • id: string

        Adds an SVG clip path definition to the builder.

        The x-coordinate of the top-left corner of the clipping rectangle.

        The y-coordinate of the top-left corner of the clipping rectangle.

        The width of the clipping rectangle.

        The height of the clipping rectangle.

        An object containing the generated id for the clip path and the SvgGroup instance representing the clip path.

    • Adds an SVG pattern definition to the builder.

      Parameters

      • x: number

        The x-coordinate of the pattern tile's top-left corner.

      • y: number

        The y-coordinate of the pattern tile's top-left corner.

      • w: number

        The width of the pattern tile.

      • h: number

        The height of the pattern tile.

      Returns { id: string; pat: SvgGroup }

      An object containing the generated id for the pattern and the SvgGroup instance representing the pattern.

      • id: string

        Adds an SVG pattern definition to the builder.

        The x-coordinate of the pattern tile's top-left corner.

        The y-coordinate of the pattern tile's top-left corner.

        The width of the pattern tile.

        The height of the pattern tile.

        An object containing the generated id for the pattern and the SvgGroup instance representing the pattern.

      • pat: SvgGroup
    • 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 SvgBuilder

      the current instance to allow chaining).

    • Appends an SvgItem to this group.

      Type Parameters

      • K extends SvgItem

        The type of the SvgItem being appended.

      Parameters

      • item: K

        The SvgItem instance to append.

      Returns K

      The appended SvgItem instance.

    • Creates and appends an SVG circle element to this group. (Internally uses an ellipse with equal x and y radii).

      Parameters

      • x: number

        The x-coordinate of the center of the circle.

      • y: number

        The y-coordinate of the center of the circle.

      • r1: number

        The radius of the circle.

      Returns SvgShape

      The newly created SvgShape instance representing the circle.

    • Creates and appends an SVG ellipse element to this group.

      Parameters

      • x: number

        The x-coordinate of the center of the ellipse.

      • y: number

        The y-coordinate of the center of the ellipse.

      • r1: number

        The x-radius of the ellipse.

      • Optionalr2: number

        The y-radius of the ellipse.

      Returns SvgShape

      The newly created SvgShape instance representing the ellipse.

    • Creates and appends an SVG group element (<g>) to this group.

      Parameters

      • Optionalid: string

        Optional. An ID for the new group.

      Returns SvgGroup

      The newly created SvgGroup instance.

    • Creates and appends an SvgIcon element to this group.

      Parameters

      • svg: string

        The SVG string content for the icon.

      • x: number

        The x-coordinate for the icon's position.

      • y: number

        The y-coordinate for the icon's position.

      • w: number

        The width of the icon.

      • h: number

        The height of the icon.

      Returns SvgIcon

      The newly created SvgIcon instance.

    • Creates and appends an SVG rectangle element to this group. Handles negative height by adjusting y and h accordingly.

      Parameters

      • x: number

        The x-coordinate of the top-left corner of the rectangle.

      • y: number

        The y-coordinate of the top-left corner of the rectangle.

      • w: number

        The width of the rectangle.

      • h: number

        The height of the rectangle.

      Returns SvgShape

      The newly created SvgShape instance representing the rectangle.

    • 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 SvgBuilder

      The current instance to allow method chaining.

    • Creates and appends an SvgText element to this group.

      Parameters

      • x: number

        The x-coordinate for the text.

      • y: number

        The y-coordinate for the text.

      • txt: string

        The text content.

      Returns SvgText

      The newly created SvgText instance.