x4js - v2.2.49
    Preparing search index...

    Class SvgGroup

    Represents an SVG group element (<g>), which can contain other SVG elements. It extends SvgItem and provides methods for appending various SVG shapes and gradients.

    Hierarchy (View Summary)

    Index
    _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 SvgGroup

      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 linear gradient definition to this group.

      Parameters

      • x1: number_or_perc

        The x-coordinate of the starting point of the gradient vector.

      • y1: number_or_perc

        The y-coordinate of the starting point of the gradient vector.

      • x2: number_or_perc

        The x-coordinate of the ending point of the gradient vector.

      • y2: number_or_perc

        The y-coordinate of the ending point of the gradient vector.

      Returns SvgGradient

      The newly created SvgGradient instance.

      const gradient = svgGroup.linear_gradient('0%', '0%', '0%', '100%')
      .addStop(0, 'red')
      .addStop(100, 'green');
      svgGroup.rect(0, 0, 100, 100).fill(gradient.id);
    • 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 SvgGroup

      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.