Class Diagram

Diagram Class

Diagram is a tree structure Diagram can be a polygon, curve, text, image, or diagram Polygon is a closed path Curve is an open path Diagram is a tree of Diagrams

Constructors

  • Parameters

    • type_: DiagramType
    • args: {
          children?: Diagram[];
          foreignobjdata?: Partial<ForeignObjectData>;
          imgdata?: Partial<ImageData>;
          multilinedata?: Partial<MultilineTextData>;
          path?: Path;
          tags?: string[];
          textdata?: Partial<TextData>;
      } = {}
      • Optionalchildren?: Diagram[]
      • Optionalforeignobjdata?: Partial<ForeignObjectData>
      • Optionalimgdata?: Partial<ImageData>
      • Optionalmultilinedata?: Partial<MultilineTextData>
      • Optionalpath?: Path
      • Optionaltags?: string[]
      • Optionaltextdata?: Partial<TextData>

    Returns Diagram

Properties

children: Diagram[] = []
foreignobjdata: Partial<ForeignObjectData> = {}
imgdata: Partial<ImageData> = {}
multilinedata: Partial<MultilineTextData> = {}
mutable: boolean = false
origin: Vector2 = ...
path: undefined | Path = undefined
style: Partial<DiagramStyle> = {}
tags: string[] = []
textdata: Partial<TextData> = {}
type: DiagramType

Methods

  • Add points to the diagram if the diagram is a polygon or curve, add points to the path if the diagram is a diagram, add points to the last polygon or curve child

    Parameters

    Returns Diagram

  • Apply a function to the diagram and all of its children recursively The function is only applied to the diagrams that contain a specific tag

    Parameters

    • tags: string | string[]

      the tag to filter the diagrams

    • func: ((d: Diagram) => Diagram)

      function to apply func takes in a diagram and returns a diagram

    Returns Diagram

  • Combine another diagram with this diagram

    Parameters

    • Rest...diagrams: Diagram[]

      a diagram or a list of diagrams

    Returns Diagram

  • Parameters

    • tags: string[]

    Returns boolean

  • Check if the diagram contains a tag

    Parameters

    • tag: string

    Returns boolean

  • Flatten the children structure of the diagram so that the diagram only has one level of children * implemented for performance reason

    Returns Diagram

  • Parameters

    • fontweight:
          | number
          | "bold"
          | "normal"
          | "bolder"
          | "lighter"

    Returns Diagram

  • Get the position of the anchor of the diagram

    Parameters

    • anchor: Anchor

      anchor to get, anchors can be 'top-left', 'top-center', 'top-right' 'center-left', 'center-center', 'center-right' 'bottom-left', 'bottom-center', 'bottom-right'

    Returns Vector2

    the position of the anchor

  • Get all the diagrams that contain a specific tag

    Parameters

    • tags: string | string[]

      the tag to filter the diagrams

    Returns Diagram[]

    a list of diagrams

  • Horizontal flip Reflect the diagram over a vertical line x = a

    Parameters

    • Optionala: number

      x value of the line if left undefined, flip over the origin

    Returns Diagram

  • Move the origin of the diagram to a position or anchor

    Parameters

    • pos: Vector2 | Anchor

      position to move the origin to (Vector2), or anchor to move the origin to. anchors can be 'top-left', 'top-center', 'top-right' 'center-left', 'center-center', 'center-right' 'bottom-left', 'bottom-center', 'bottom-right'

      • for texts, use move_origin_text()

    Returns Diagram

  • Move the origin of text diagram to a position

    Parameters

    • anchor: Anchor

      anchor to move the origin to. anchors can be 'top-left', 'top-center', 'top-right' 'center-left', 'center-center', 'center-right' 'bottom-left', 'bottom-center', 'bottom-right'

    Returns Diagram

  • Get the point on the path at t Path can be described parametrically in the form of (x(t), y(t)) Path starts at t=0 and ends at t=1

    Parameters

    • t: number

      parameter

    • Optionalsegment_index: number

      (only works for polygon and curves) If segment_index (n) is defined, get the point at the nth segment If segment_index (n) is defined, t can be outside of [0, 1] and will return the extrapolated point

    Returns Vector2

    the position of the point

  • move the diagram to a position

    Parameters

    • v: Vector2 = ...

      position to move to (if left undefined, move to the origin)

    Returns Diagram

  • Reflect the diagram if given 0 arguments, reflect over the origin if given 1 argument, reflect over a point p1 if given 2 arguments, reflect over a line defined by two points p1 and p2

    Parameters

    Returns Diagram

  • Rotate the diagram by an angle around a pivot

    Parameters

    • angle: number

      angle to rotate

    • pivot: undefined | Vector2 = undefined

      pivot point, if left undefined, rotate around the origin

    Returns Diagram

  • Scale the diagram by a scale around a origin

    Parameters

    • scale: number | Vector2

      scale to scale (x, y)

    • Optionalorigin: Vector2

      origin point, if left undefined, scale around the origin

    Returns Diagram

  • Scale texts contained in the diagram by a scale

    Parameters

    • scale: number

      scaling factor

    Returns Diagram

  • Skew the diagram in the x direction by an angle around a base

    Parameters

    • angle: number

      angle to skew

    • Optionalbase: Vector2

      base point, if left undefined, skew around the origin

    Returns Diagram

  • Skew the diagram in the y direction by an angle around a base

    Parameters

    • angle: number

      angle to skew

    • Optionalbase: Vector2

      base point, if left undefined, skew around the origin

    Returns Diagram

  • Parameters

    • linejoin:
          | "round"
          | "arcs"
          | "bevel"
          | "miter"
          | "miter-clip"

    Returns Diagram

  • Convert the diagram to a curve If the diagram is a polygon, convert it to a curve If the diagram is a Diagram, convert all of the children to curves

    Returns Diagram

  • Convert the diagram to a polygon If the diagram is a curve, convert it to a polygon If the diagram is a Diagram, convert all of the children to polygons

    Returns Diagram

  • Parameters

    • vectoreffect:
          | "none"
          | "non-scaling-stroke"
          | "non-scaling-size"
          | "non-rotation"
          | "fixed-position"

    Returns Diagram

  • Vertical flip Reflect the diagram over a horizontal line y = a

    Parameters

    • Optionala: number

      y value of the line if left undefined, flip over the origin

    Returns Diagram