Represents a 2D shape.

Hierarchy (view full)

Constructors

  • Creates an instance of Shape.

    Parameters

    • tag: string

      The name of the shape.

    • attrs: {} = {}

      The attributes required for drawing the shape.

      • kwargs: {} = {}

        The styling information to be used before drawing the shape.

        • children: Shape[] = []

          Other shapes that are drawn relative to the current instance of Shape.

        Returns Shape

      Properties

      attrs: any
      children: Shape[]
      kwargs: any
      tag: string
      transform: Transformation[]

      Methods

      • Adds a child shape to the current Shape instance.

        Parameters

        • shape: Shape

          A child shape.

        Returns Shape

        The current instance of Shape for chaining.

      • Returns a clone of the current Shape instance with new styling information if available.

        Parameters

        • newKwargs: {} = {}

          Key value pairs to provide styling information for a shape. eg { fill: 'red', stroke: 'blue' }.

          Returns Shape

          A new instance of Shape.

        • Repeats the current shape n times by applying transform iteratively.

          Parameters

          • n: number

            A positive integer representing the number of times a shape is to be repeated.

          • transform: Transformation | ((index: number) => TransformationWithStyle) | ((index: number) => Transformation)

            An instance of Transformation that is applied every time the shape is repeated.

          Returns Shape

          The current instance of Shape for chaining.

        • Applies a Rotate transformation to the current Shape instance.

          Parameters

          • angle: number = 0

            Amount to rotate clockwise in degrees. Defaults to 0.

          Returns Shape

          The current instance of Shape for chaining.

        • Applies a Scale transformation to the current Shape instance.

          Parameters

          • x: number = 1

            Amount to scale along the positive x-axis. Defaults to 1.

          • y: number = 1

            Amount to scale along the positive y-axis. Defaults to 1.

          Returns Shape

          The current instance of Shape for chaining.

        • Displays a shape. Steps performed for display are as follows.

          • Apply the transforms that exist on a shape.
          • Apply the styling that exists on a shape.
          • Draw the shape.
          • Draw children shapes.

          Parameters

          • Optionalr: Drawable

            An instance of Drawable.

          Returns void

        • Returns a string representation of Shape.

          Returns string

          • A string with the name of the shape and its' attributes.
        • Applies a Translate transformation to the current Shape instance.

          Parameters

          • x: number = 0

            Amount to translate along the positive x-axis. Defaults to 0.

          • y: number = 0

            Amount to translate along the positive y-axis. Defaults to 0.

          Returns Shape

          The current instance of Shape for chaining.