Class DiagramEditor

DiagramEditor is the main diagram editing web component of the MJS Diagram library.

You add an instance of DiagramEditor to your page to enable diagram editing.

You can add it in your HTML markup as a custom element with something like this:

<mjs-diagram-editor id="mjsDiaEditor"></mjs-diagram-editor>

Or you can add it in code.

One important thing to set when the component loads is the StencilEditorSet you want to use.

Here we add a Flowchart stencil set:

let editor = document.getElementById('mjsDiaEditor');
editor.stencilEditorSet = flowchartStencilEditorSet;

You may want to add a previously saved state via the restoreState.

Finally, you most probably want to handle the saveclick event to store the editing results:

editor.addEventListener('saveclick', (ev) => {
// process state (represents the created diagram)
console.log(ev.detail.state);
});

See

Check out MJS Diagram docs and demos for more details.

Hierarchy

  • HTMLElement
    • DiagramEditor

Constructors

  • Creates the new instance of the editor.

    Returns DiagramEditor

Properties

_manipulationStartX: number = 0
_manipulationStartY: number = 0
languageManager: Language = ...

Enables multi-language support.

settings: EditorSettings = ...

Editor settings.

Control available colors, font families, etc. through this property.

zoomSteps: number[] = ...

Steps zoom in/out buttons go through.

Accessors

  • get isRedoPossible(): boolean
  • Returns true if redo operation can be performed (redo stack is not empty).

    Returns boolean

  • get isUndoPossible(): boolean
  • Returns true if undo operation can be performed (undo stack is not empty).

    Returns boolean

  • get language(): string
  • Returns string

  • set language(value): void
  • Parameters

    • value: string

    Returns void

  • get stencilEditorSet(): StencilEditorSet
  • Returns the current stencil editor set.

    Returns StencilEditorSet

  • set stencilEditorSet(value): void
  • Sets the current stencil editor set.

    Remarks

    Note that all the current edits are lost when new stencil set is set.

    Parameters

    Returns void

  • get zoomLevel(): number
  • Returns the current zoom level.

    Returns number

  • set zoomLevel(value): void
  • Sets the current zoom level.

    Parameters

    • value: number

    Returns void

Methods

  • Type Parameters

    Parameters

    • type: T
    • listener: ((this, ev) => void)
    • Optional options: boolean | AddEventListenerOptions

    Returns void

  • Type Parameters

    • K extends keyof HTMLElementEventMap

    Parameters

    • type: K
    • listener: ((this, ev) => void)
        • (this, ev): void
        • Parameters

          • this: HTMLElement
          • ev: HTMLElementEventMap[K]

          Returns void

    • Optional options: boolean | AddEventListenerOptions

    Returns void

  • Creates a new stencil of the specified type

    Parameters

    • stencilType: undefined | string | typeof StencilBase

      stencil type as either type or its string representation

    Returns void

  • Removes the supplied stencil editor from selection. If no stencil editor is supplied, all selected stencils are unselected.

    Parameters

    Returns void

  • Generates a new internal identifier used to identify stencils and connectors when serialized to the state JSON.

    Returns number

    new internally unique identifier.

  • Returns the diagram configration state object. Use it to store the state in databases, files, etc.

    Returns DiagramState

    diagram configuration as a serializable object.

  • Hides toolbar buttons for provided commands.

    Available buttons/commands:

    select, delete, save, undo, redo, add, connect, document-setup, zoomout, zoomin, zoomreset, properties.

    This method can be used to both remove buttons to preserve space and simplify user experience by removing unnecessary functions and to remove access to certain functions. For example, you may constantly auto-save the diagram in your code so the save button isn't necessary and misleading.

    Example

    The code below hides zoomreset and redo buttons.

    editor.hideToolbarButtons('zoomreset', 'redo');
    

    Since

    1.1.0

    Parameters

    • Rest ...commands: string[]

      list of commands

    Returns void

  • Redo previously undone action.

    Returns void

  • Type Parameters

    Parameters

    • type: T
    • listener: ((this, ev) => void)
    • Optional options: boolean | EventListenerOptions

    Returns void

  • Type Parameters

    • K extends keyof HTMLElementEventMap

    Parameters

    • type: K
    • listener: ((this, ev) => void)
        • (this, ev): void
        • Parameters

          • this: HTMLElement
          • ev: HTMLElementEventMap[K]

          Returns void

    • Optional options: boolean | EventListenerOptions

    Returns void

  • Use this method to reneder the current diagram as a static raster image.

    Parameters

    • Optional width: number

      target width

    • Optional height: number

      target height

    • imageType: string = 'image/png'

      image type (image/png, image/jpeg, etc.)

    • Optional quality: number

      render quality for lossy codecs (1=100% for jpeg).

    Returns Promise<undefined | string>

    rendered image as a data URL.

  • Restores (loads) previous saved (or manually created) diagram.

    Parameters

    Returns void

  • Selects a stencil. If there already is a selected stencil then the supplied stencil is added to the selection.

    Parameters

    Returns void

  • Sets the currently active stencil editor. If multiple stencils are selected then there's no "current" stencil. Passing nothing/undefined unsets the current stencil.

    Parameters

    Returns void

  • Undo last action.

    Returns void

  • Zooms in or out to the supplied zoom level (1 = 100%).

    Parameters

    • factor: number

      zoom level.

    Returns void

Generated using TypeDoc