Skip to main content

Class: DiagramModel

Stores the diagram content: graph (elements, links); maintains selection and the current language to display the data.

Additionally, the diagram model provides the means to undo/redo commands via history.

Extended by

Implements

Properties

PropertyModifierTypeDescription

events

readonly

Events<DiagramModelEvents>

Events for the diagram model.

history

readonly

CommandHistory

Provides the mechanism to undo/redo commands on the diagram.

locale

readonly

LocaleFormatter

Provides the methods to format the content according to the current language.

Deprecated

Use useTranslation hook instead.

Accessors

elements

get elements(): readonly Element[]

All elements (nodes) in the graph.

Returns

readonly Element[]

Implementation of

GraphStructure.elements

Defined in

diagram/model.ts:218


factory

get factory(): DataFactory

Provides an RDF term factory to create RDF terms for identifiers and property values.

Returns

DataFactory

Implementation of

GraphStructure.factory

Defined in

diagram/model.ts:214


language

get language(): string

Current language for the diagram content.

Language code is specified as lowercase BCP47 string (examples: en, en-gb, etc).

Initial language is en.

Returns

string

Defined in

diagram/model.ts:175


get links(): readonly Link[]

All links (edges) between elements in the graph.

Returns

readonly Link[]

Implementation of

GraphStructure.links

Defined in

diagram/model.ts:222


selection

get selection(): readonly (Element | Link)[]

Current diagram selection (elements and/or links).

Returns

readonly (Element | Link)[]

Defined in

diagram/model.ts:195

Methods

addElement()

addElement(element): void

Adds the element to the diagram.

Throws an error if element with the same Element.id already exists in the graph.

The operation puts a command to the command history.

Parameters

ParameterType

element

Element

Returns

void

Defined in

diagram/model.ts:353


addLink(link): void

Adds the link to the diagram.

Throws an error if link with the same Link.id already exists in the graph or any of source or target is not in the graph.

The operation puts a command to the command history.

Parameters

ParameterType

link

Link

Returns

void

Defined in

diagram/model.ts:383


bringElements()

bringElements(targets, to): void

Puts specified elements before or after all other in the display order.

Parameters

ParameterType

targets

readonly Element[]

to

"front" | "back"

Returns

void

Defined in

diagram/model.ts:334


findLink(linkTypeId, sourceId, targetId): undefined | Link

Searches for any link of the specified type between elements with specified IDs in the graph if exists.

If multiple links is found, any of them could be returned.

Parameters

ParameterType

linkTypeId

LinkTypeIri

sourceId

string

targetId

string

Returns

undefined | Link

Implementation of

GraphStructure.findLink

Defined in

diagram/model.ts:245


getElement()

getElement(elementId): undefined | Element

Gets an element by its Element.id in the graph if exists.

Parameters

ParameterType

elementId

string

Returns

undefined | Element

Implementation of

GraphStructure.getElement

Defined in

diagram/model.ts:233


getElementLinks(element): readonly Link[]

Gets all links connected to the specified element in the graph.

If element is not in the graph, no links would be returned.

Parameters

ParameterType

element

Element

Returns

readonly Link[]

Implementation of

GraphStructure.getElementLinks

Defined in

diagram/model.ts:237


getLink(linkId): undefined | Link

Gets a link by its Link.id in the graph if exists.

Parameters

ParameterType

linkId

string

Returns

undefined | Link

Implementation of

GraphStructure.getLink

Defined in

diagram/model.ts:241


getLinkVisibility()

getLinkVisibility(linkTypeId): LinkTypeVisibility

Gets current visibility mode for the specified link type.

Parameters

ParameterType

linkTypeId

LinkTypeIri

Returns

LinkTypeVisibility

Implementation of

GraphStructure.getLinkVisibility

Defined in

diagram/model.ts:260


removeElement()

removeElement(elementId): void

Removes the element with specified ID from the diagram if exists.

When element is removed, all connected links will be removed as well.

The operation puts a command to the command history.

Parameters

ParameterType

elementId

string

Returns

void

Defined in

diagram/model.ts:366


removeLink(linkId): void

Removes the link with specified ID from the diagram if exists.

The operation puts a command to the command history.

Parameters

ParameterType

linkId

string

Returns

void

Defined in

diagram/model.ts:392


reorderElements()

reorderElements(compare): void

Changes display order of elements on the diagram.

Parameters

ParameterTypeDescription

compare

(a, b) => number

Sort comparator to establish a particular ordering

Returns

void

Defined in

diagram/model.ts:326


setLanguage()

setLanguage(value): void

Sets current language for the diagram content.

Language code is specified as lowercase BCP47 string (examples: en, en-gb, etc).

Parameters

ParameterType

value

string

Returns

void

Defined in

diagram/model.ts:182


setLinkVisibility()

setLinkVisibility(linkTypeId, value): void

Sets current visibility mode for the specified link type.

Parameters

ParameterType

linkTypeId

LinkTypeIri

value

LinkTypeVisibility

Returns

void

Defined in

diagram/model.ts:267


setSelection()

setSelection(value): void

Sets current diagram selection (elements and/or links).

When called, selected cells will be brought to the front before all other diagram cells.

Parameters

ParameterType

value

readonly (Element | Link)[]

Returns

void

Defined in

diagram/model.ts:202


sourceOf()

sourceOf(link): undefined | Element

Gets a source element for the specified link in the graph.

If link is not in the graph, undefined would be returned instead.

Parameters

ParameterType

link

Link

Returns

undefined | Element

Implementation of

GraphStructure.sourceOf

Defined in

diagram/model.ts:252


targetOf()

targetOf(link): undefined | Element

Gets a target element for the specified link in the graph.

If link is not in the graph, undefined would be returned instead.

Parameters

ParameterType

link

Link

Returns

undefined | Element

Implementation of

GraphStructure.targetOf

Defined in

diagram/model.ts:256