Skip to main content

Class: DataDiagramModel

Asynchronously fetches and stores the entity diagram content: graph elements and links, as well as element, link and property types; maintains selection and the current language to display the data.

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

Extends

Implements

Properties

PropertyModifierTypeDescriptionOverridesInherited from

events

readonly

Events<DataDiagramModelEvents>

Events for the diagram model.

DiagramModel.events

history

readonly

CommandHistory

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

DiagramModel.history

locale

readonly

DataGraphLocaleFormatter

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

Deprecated

Use useTranslation hook instead.

DiagramModel.locale

Accessors

dataProvider

get dataProvider(): DataProvider

Returns the data provider that is associated with the current diagram via creating new or importing an existing layout.

This provider is used to fetch entity graph data on-demand.

By default, it is set to EmptyDataProvider instance without any graph data.

See

Returns

DataProvider

Defined in

editor/dataDiagramModel.ts:186


elements

get elements(): readonly Element[]

All elements (nodes) in the graph.

Returns

readonly Element[]

Implementation of

DataGraphStructure.elements

Inherited from

DiagramModel.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

DataGraphStructure.factory

Inherited from

DiagramModel.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

Inherited from

DiagramModel.language

Defined in

diagram/model.ts:175


get links(): readonly Link[]

All links (edges) between elements in the graph.

Returns

readonly Link[]

Implementation of

DataGraphStructure.links

Inherited from

DiagramModel.links

Defined in

diagram/model.ts:222


operations

get operations(): readonly FetchOperation[]

Returns an immutable snapshot of current fetch operations.

Returns

readonly FetchOperation[]

Defined in

editor/dataDiagramModel.ts:197


selection

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

Current diagram selection (elements and/or links).

Returns

readonly (Element | Link)[]

Inherited from

DiagramModel.selection

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

Inherited from

DiagramModel.addElement

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

Overrides

DiagramModel.addLink

Defined in

editor/dataDiagramModel.ts:553


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

Inherited from

DiagramModel.bringElements

Defined in

diagram/model.ts:334


createElement()

createElement(elementIriOrModel): EntityElement

Creates or gets an existing entity element on the diagram.

If element is specified as an IRI only, then the placeholder data will be used.

If multiple entity elements with the same IRI is on the diagram, the first one in the order will be returned.

The operation puts a command to the command history.

Parameters

ParameterType

elementIriOrModel

ElementIri | ElementModel

Returns

EntityElement

Defined in

editor/dataDiagramModel.ts:532


createElementType()

createElementType(elementTypeIri): ElementType

Creates or gets an existing element type in the graph.

If element type does not exists in the graph yet, it will be created and the data for it will be requested for it from the data provider.

Parameters

ParameterType

elementTypeIri

ElementTypeIri

Returns

ElementType

Defined in

editor/dataDiagramModel.ts:677


createLinkType()

createLinkType(linkTypeIri): LinkType

Creates or gets an existing link type in the graph.

If link type does not exists in the graph yet, it will be created and the data for it will be requested for it from the data provider.

Parameters

ParameterType

linkTypeIri

LinkTypeIri

Returns

LinkType

Defined in

editor/dataDiagramModel.ts:698


createLinks(data): (RelationLink | RelationGroup)[]

Creates or gets an existing links for the specified link model.

Multiple links may exists for the same link model because in some cases there could be multiple source or target elements with the same IRI.

Each existing link for the same link model will be updated with the specified data, link state property urn:reactodia:layoutOnly (TemplateProperties.LayoutOnly) will be discarded if set.

The operation puts a command to the command history.

Parameters

ParameterType

data

LinkModel

Returns

(RelationLink | RelationGroup)[]

Defined in

editor/dataDiagramModel.ts:590


createNewDiagram()

createNewDiagram(params): Promise<void>

Clears up the diagram and associates a new data provider for it.

This method discards all current diagram state (elements, links and other data) and resets the command history.

Parameters

ParameterTypeDescription

params

object

params.dataProvider

DataProvider

Data provider to associate with the diagram.

This provider will be used to fetch entity graph data on-demand for the diagram.

params.signal?

AbortSignal

Cancellation signal.

Returns

Promise<void>

See

importLayout

Defined in

editor/dataDiagramModel.ts:249


createPropertyType()

createPropertyType(propertyIri): PropertyType

Creates or gets an existing property type in the graph.

If property type does not exists in the graph yet, it will be created and the data for it will be requested for it from the data provider.

Parameters

ParameterType

propertyIri

PropertyTypeIri

Returns

PropertyType

Defined in

editor/dataDiagramModel.ts:719


discardLayout()

discardLayout(): void

Discards all diagram content and resets associated data provider to en empty one.

Returns

void

Defined in

editor/dataDiagramModel.ts:380


exportLayout()

exportLayout(): SerializedDiagram

Exports current diagram state to a serializable object.

The exported state includes element and link geometry, template state, references to described entities and relations (via IRIs). Additionally, link type visibility settings are exported as well.

Returns

SerializedDiagram

See

importLayout

Defined in

editor/dataDiagramModel.ts:398


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

DataGraphStructure.findLink

Inherited from

DiagramModel.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

DataGraphStructure.getElement

Inherited from

DiagramModel.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

DataGraphStructure.getElementLinks

Inherited from

DiagramModel.getElementLinks

Defined in

diagram/model.ts:237


getElementType()

getElementType(elementTypeIri): undefined | ElementType

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

Element types are added to the graph as requested by DataDiagramModel.createElementType so the data (e.g. labels) can be fetched from a data provider.

Parameters

ParameterType

elementTypeIri

ElementTypeIri

Returns

undefined | ElementType

See

DataDiagramModel.createElementType

Implementation of

DataGraphStructure.getElementType

Defined in

editor/dataDiagramModel.ts:667


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

DataGraphStructure.getLink

Inherited from

DiagramModel.getLink

Defined in

diagram/model.ts:241


getLinkType()

getLinkType(linkTypeIri): undefined | LinkType

Gets an link type by its LinkType.id in the graph if exists.

Link types are added to the graph as requested by DataDiagramModel.createLinkType so the data (e.g. labels) can be fetched from a data provider.

Parameters

ParameterType

linkTypeIri

LinkTypeIri

Returns

undefined | LinkType

See

DataDiagramModel.createLinkType

Implementation of

DataGraphStructure.getLinkType

Defined in

editor/dataDiagramModel.ts:688


getLinkVisibility()

getLinkVisibility(linkTypeId): LinkTypeVisibility

Gets current visibility mode for the specified link type.

Parameters

ParameterType

linkTypeId

LinkTypeIri

Returns

LinkTypeVisibility

Implementation of

DataGraphStructure.getLinkVisibility

Inherited from

DiagramModel.getLinkVisibility

Defined in

diagram/model.ts:260


getOperationFailReason()

getOperationFailReason<T>(type, target): unknown

Returns a reason (thrown error) why latest fetch operation for specific target failed, if any; otherwise returns undefined.

Type Parameters

Type Parameter

T extends FetchOperationTargetType

Parameters

ParameterType

type

T

target

FetchOperationTypeToTarget[T]

Returns

unknown

Defined in

editor/dataDiagramModel.ts:205


getPropertyType()

getPropertyType(propertyTypeIri): undefined | PropertyType

Gets an property type by its PropertyType.id in the graph if exists.

Property types are added to the graph as requested by DataDiagramModel.createPropertyType so the data (e.g. labels) can be fetched from a data provider.

Parameters

ParameterType

propertyTypeIri

PropertyTypeIri

Returns

undefined | PropertyType

See

DataDiagramModel.createPropertyType

Implementation of

DataGraphStructure.getPropertyType

Defined in

editor/dataDiagramModel.ts:709


group()

group(entities): EntityGroup

Groups multiple entity elements into an entity group element.

Specified entity elements are removed from the diagram and a single entity group element with these entities is created at the center of the bounding box between them.

Relation links from/to specified elements are re-grouped to form relation group links the same way.

The operation puts a command to the command history.

Parameters

ParameterType

entities

readonly EntityElement[]

Returns

EntityGroup

See

Defined in

editor/dataDiagramModel.ts:745


importLayout()

importLayout(params): Promise<void>

Restores diagram content from previously exported state and associates a new data provider for the diagram.

This method discards all current diagram state (elements, links and other data) and resets the command history.

Parameters

ParameterTypeDescription

params

object

params.dataProvider

DataProvider

Data provider to associate with the diagram.

This provider will be used to fetch entity graph data on-demand for the diagram.

params.diagram?

SerializedDiagram

Diagram state to restore (elements and their positions, links with visibility settings, etc).

If specified, current diagram content will be replaced by one from the state, otherwise the diagram will be cleared up only.

params.hideUnusedLinkTypes?

boolean

Whether to fetch known link types on import and automatically hide all unused link types.

Default

false

params.preloadedElements?

ReadonlyMap<ElementIri, ElementModel>

Pre-cached data for the elements which should be used instead of being requested from the data provider on import.

params.signal?

AbortSignal

Cancellation signal.

params.validateLinks?

boolean

Whether links for the between imported elements should be requested from the data provider on import.

Default

false

Returns

Promise<void>

See

Defined in

editor/dataDiagramModel.ts:276


regroupLinks(links): void

Re-creates a set of relations or relation groups to automatically group relations with the same link type connected to entity groups.

The operation puts a command to the command history.

Parameters

ParameterType

links

readonly (RelationLink | RelationGroup)[]

Returns

void

Defined in

editor/dataDiagramModel.ts:911


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

Inherited from

DiagramModel.removeElement

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

Inherited from

DiagramModel.removeLink

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

Inherited from

DiagramModel.reorderElements

Defined in

diagram/model.ts:326


requestElementData()

requestElementData(elementIris): Promise<void>

Requests to fetch the data for the specified elements from a data provider.

Parameters

ParameterType

elementIris

readonly ElementIri[]

Returns

Promise<void>

Defined in

editor/dataDiagramModel.ts:487


requestLinks(options): Promise<void>

Requests to fetch links between all elements on the diagram from a data provider.

Parameters

ParameterType

options

RequestLinksOptions

Returns

Promise<void>

Defined in

editor/dataDiagramModel.ts:494


requestLinksOfType()

requestLinksOfType(linkTypeIds?): Promise<void>

Parameters

ParameterType

linkTypeIds?

readonly LinkTypeIri[]

Returns

Promise<void>

Deprecated

Use DataDiagramModel.requestLinks instead.

Defined in

editor/dataDiagramModel.ts:517


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

Inherited from

DiagramModel.setLanguage

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

Inherited from

DiagramModel.setLinkVisibility

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

Inherited from

DiagramModel.setSelection

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

DataGraphStructure.sourceOf

Inherited from

DiagramModel.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

DataGraphStructure.targetOf

Inherited from

DiagramModel.targetOf

Defined in

diagram/model.ts:256


ungroupAll()

ungroupAll(groups): EntityElement[]

Ungroups one or many entity group elements into all contained entity elements.

Specified entity group elements are removed from the diagram and all contained entity elements are created at the same position as the owner group.

Relation links from/to ungrouped entities are re-grouped to form relation group links the same way.

The operation puts a command to the command history.

Parameters

ParameterType

groups

readonly EntityGroup[]

Returns

EntityElement[]

See

Defined in

editor/dataDiagramModel.ts:809


ungroupSome()

ungroupSome(group, entities): EntityElement[]

Ungroups some entities from an entity group element.

Specified entity group is modified to remove target entities and re-create them at the same position as the group. If only one or less entities are left in the group, the group will be completely ungrouped instead.

Relation links from/to ungrouped entities are re-grouped to form relation group links the same way.

The operation puts a command to the command history.

Parameters

ParameterType

group

EntityGroup

entities

ReadonlySet<ElementIri>

Returns

EntityElement[]

See

Defined in

editor/dataDiagramModel.ts:858