A renderable diagram, created with DiagramBuilder.prototype.build. You should pass a factory method to useDiagram to create a Diagram from within a React component, for performance reasons.

Methods

  • Add an effect to an input. The effect will be called any time the input changes.

    Parameters

    • name: string

      The name of the input

    • fn: ((val: number, name: string) => void)

      The effect function

        • (val, name): void
        • Parameters

          • val: number
          • name: string

          Returns void

    Returns void

  • Get the canvas of the diagram.

    Returns {
        height: number;
        size: [number, number];
        width: number;
        xRange: Range;
        yRange: Range;
    }

    • height: number
    • size: [number, number]
    • width: number
    • xRange: Range
    • yRange: Range
  • Get the value of an input by name.

    Parameters

    • name: string

      The name of the input

    Returns number

  • Returns an HTMLElement presenting an interactive diagram. This element should be appended added to an existing document node to be visible. The element is styled by default with "width: 100%; height: 100%l touch-action: none".

    Returns HTMLDivElement

  • Take one optimization step. This will update the internal state of the diagram.

    Returns Promise<boolean>

    true if the optimization should continue, false if it should stop (i.e. when optimization converges or fails)

  • Remove an effect from an input.

    Parameters

    • name: string

      The name of the input

    • fn: ((val: number, name: string) => void)

      The effect function

        • (val, name): void
        • Parameters

          • val: number
          • name: string

          Returns void

    Returns void

  • Render an SVG of the current diagram state and a map of shape names to SVG elements.

    Returns Promise<{
        nameElemMap: Map<string, SVGElement>;
        svg: SVGSVGElement;
    }>

  • Set the value of an input by name.

    Parameters

    • name: string

      The name of the input

    • val: number

      The new value

    Returns void

  • Parameters

    • fn: (() => void)
        • (): void
        • Returns void

    Returns (() => void)

      • (): void
      • Returns void

  • Set the value of an input by index.

    Parameters

    • name: string
    • optimized: boolean

      Whether the input should be optimized

    Returns void