An Editor or View containing everything needed by the drawing/display board: DOM, event listeners, state and API functions.

Param: svgEl

the id of the SVG element to be created or the SVG element itself if it's already made

Param: options

Param: style

see Editor#setStyle

Constructors

  • Parameters

    • svgEl: string | SVGElement
    • options: Partial<EditorOptions> = {}
    • style: Partial<{
          component: Style;
          componentHover: {
              off: Style;
              on: Style;
          };
          componentSelect: {
              off: Style;
              on: Style;
          };
          handle: Style;
          handleHover: Style;
      }> = {}

    Returns Editor

Properties

_cacheElementMapping: Record<string, undefined | Handle | Component>
_handleIdCounter: number
_idCounter: number
cgroup: SVGGElement
componentDrawnHandler?: ((c, id) => void)

Type declaration

    • (c, id): void
    • Parameters

      Returns void

fsmService: Actor<ActorLogic<any, any, any, any>>
height: number
hgroup: SVGGElement
selectModeHandler?: (() => void)

Type declaration

    • (): void
    • Returns void

style: {
    component: Style;
    componentHover: {
        off: Style;
        on: Style;
    };
    componentSelect: {
        off: Style;
        on: Style;
    };
    handle: Style;
    handleHover: Style;
}

Type declaration

svg: SVGSVGElement
viewClickHandler?: ((e, id) => void)

Type declaration

    • (e, id): void
    • Parameters

      • e: Event
      • id: string

      Returns void

width: number

Methods

  • Put editor in draw mode of circles.

    Returns void

  • Put editor in draw mode of ellipses.

    Returns void

  • Export drawn shapes as JSON.

    Parameters

    • Optional escape: boolean

      whether double quotes should be escaped

    Returns string

    • JSON data
  • Import shapes from JSON.

    Parameters

    • data: string
    • Optional idInterceptor: ((id) => string)

      function to change the imported id to avoid name conflicts, eg. in case user decides to import multiple times or import after drawing

        • (id): string
        • Parameters

          • id: string

          Returns string

    Returns any

    Example

    {
    "components": [{
    "id": "circle_1",
    "type": "circle",
    "data": {
    "x": 444,
    "y": 71,
    "width": 241,
    "height": 211
    }
    }]
    }

    Example

    {
    "components": [{
    "id": "rect_1",
    "type": "rect",
    "data": {
    "x": 444,
    "y": 71,
    "width": 241,
    "height": 211
    }
    }]
    }

    Example

    {
    "components": [{
    "id": "ellipse_1",
    "type": "ellipse",
    "data": {
    "x": 444,
    "y": 71,
    "width": 241,
    "height": 211
    }
    }]
    }

    Example

    {
    "components": [{
    "id": "polygon_1",
    "type": "polygon",
    "data": [{
    "x": 603,
    "y": 114
    }, {
    "x": 625,
    "y": 203
    }, {
    "x": 699,
    "y": 124
    }]
    }]
    }
  • Add an image element into the SVG element.

    Parameters

    • path: string
    • Optional width: string | number
    • Optional height: string | number

    Returns Editor

  • Remove event listener(s).

    Parameters

    • eventTypes: string
    • handler: EventListenerOrEventListenerObject

    Returns Editor

  • Add event listener(s).

    Parameters

    • eventTypes: string
    • handler: EventListenerOrEventListenerObject

    Returns Editor

  • Put editor in draw mode of polygons.

    Returns void

  • Put editor in draw mode of rectangles.

    Returns void

  • Remove a component (shape) from the editor or view.

    Parameters

    • componentOrId: string | Component

      a component or a component id

    Returns null | Component

  • Make programmatically selection of a component which basically enables its handles by making them visible. Please note that all components will be unselected when leaving select mode or leaving draw mode.

    Parameters

    • Optional componentOrId: string | Handle | Component

      a component or a component id

    Returns null | Component

  • Put editor in select mode.

    Returns void

  • Completely or partly set current style of components, handles, hovering etc.

    Parameters

    • style: Partial<{
          component: Style;
          componentHover: {
              off: Style;
              on: Style;
          };
          componentSelect: {
              off: Style;
              on: Style;
          };
          handle: Style;
          handleHover: Style;
      }>

    Returns Editor

    Example

    editor.setStyle({
    component: {
    fill: 'rgb(102, 102, 102)',
    stroke: 'rgb(51, 51, 51)',
    },
    componentHover: {
    off: {
    'stroke-width': 1,
    opacity: 0.5,
    },
    on: {
    'stroke-width': 2,
    opacity: 0.6,
    },
    },
    componentSelect: {
    off: {
    'stroke-dasharray': 'none',
    'stroke-linejoin': 'miter',
    },
    on: {
    'stroke-dasharray': '4 3',
    'stroke-linejoin': 'round',
    },
    },
    handle: {
    fill: 'rgb(255, 255, 255)',
    stroke: 'rgb(51, 51, 51)',
    'stroke-width': 1,
    opacity: 0.3,
    },
    handleHover: {
    opacity: 0.6,
    },
    });

Generated using TypeDoc