Skip to main content

Class: DataDiagramModel

Defined in: editor/dataDiagramModel.ts:149

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

Accessors

dataProvider

Get Signature

get dataProvider(): DataProvider

Defined in: editor/dataDiagramModel.ts:189

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


elements

Get Signature

get elements(): readonly Element[]

Defined in: diagram/model.ts:208

All elements (nodes) in the graph.

Returns

readonly Element[]

Implementation of

DataGraphStructure.elements

Inherited from

DiagramModel.elements


factory

Get Signature

get factory(): DataFactory

Defined in: diagram/model.ts:204

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

Returns

DataFactory

Implementation of

DataGraphStructure.factory

Inherited from

DiagramModel.factory


language

Get Signature

get language(): string

Defined in: diagram/model.ts:163

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


Get Signature

get links(): readonly Link[]

Defined in: diagram/model.ts:212

All links (edges) between elements in the graph.

Returns

readonly Link[]

Implementation of

DataGraphStructure.links

Inherited from

DiagramModel.links


locale

Get Signature

get locale(): DataLocaleProvider

Defined in: editor/dataDiagramModel.ts:200

Provides the methods to format the graph data according to the current language.

Returns

DataLocaleProvider


operations

Get Signature

get operations(): readonly FetchOperation[]

Defined in: editor/dataDiagramModel.ts:207

Returns an immutable snapshot of current fetch operations.

Returns

readonly FetchOperation[]


selection

Get Signature

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

Defined in: diagram/model.ts:183

Current diagram selection (elements and/or links).

Returns

readonly (Element | Link)[]

Inherited from

DiagramModel.selection

Methods

addElement()

addElement(element): void

Defined in: diagram/model.ts:343

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


addLink(link): void

Defined in: editor/dataDiagramModel.ts:597

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


bringElements()

bringElements(targets, to): void

Defined in: diagram/model.ts:324

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


createElement()

createElement(elementIriOrModel): EntityElement

Defined in: editor/dataDiagramModel.ts:576

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


createElementType()

createElementType(elementTypeIri): ElementType

Defined in: editor/dataDiagramModel.ts:721

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


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

Defined in: editor/dataDiagramModel.ts:634

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)[]


createLinkType()

createLinkType(linkTypeIri): LinkType

Defined in: editor/dataDiagramModel.ts:742

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


createNewDiagram()

createNewDiagram(params): Promise<void>

Defined in: editor/dataDiagramModel.ts:259

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

{ dataProvider: DataProvider; locale?: DataLocaleProvider; signal?: AbortSignal; }

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.locale?

DataLocaleProvider

Formatter for the graph data on the diagram.

If not specified, the DefaultDataLocaleProvider is used.

See

DataDiagramModel.locale

params.signal?

AbortSignal

Cancellation signal.

Returns

Promise<void>

See

importLayout


createPropertyType()

createPropertyType(propertyIri): PropertyType

Defined in: editor/dataDiagramModel.ts:763

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


discardLayout()

discardLayout(): void

Defined in: editor/dataDiagramModel.ts:413

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

Returns

void


exportLayout()

exportLayout(): SerializedDiagram

Defined in: editor/dataDiagramModel.ts:442

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


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

Defined in: diagram/model.ts:235

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


getElement()

getElement(elementId): undefined | Element

Defined in: diagram/model.ts:223

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


getElementLinks(element): readonly Link[]

Defined in: diagram/model.ts:227

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


getElementType()

getElementType(elementTypeIri): undefined | ElementType

Defined in: editor/dataDiagramModel.ts:711

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


getLink(linkId): undefined | Link

Defined in: diagram/model.ts:231

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


getLinkType()

getLinkType(linkTypeIri): undefined | LinkType

Defined in: editor/dataDiagramModel.ts:732

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


getLinkVisibility()

getLinkVisibility(linkTypeId): LinkTypeVisibility

Defined in: diagram/model.ts:250

Gets current visibility mode for the specified link type.

Parameters

ParameterType

linkTypeId

LinkTypeIri

Returns

LinkTypeVisibility

Implementation of

DataGraphStructure.getLinkVisibility

Inherited from

DiagramModel.getLinkVisibility


getOperationFailReason()

getOperationFailReason<T>(type, target): unknown

Defined in: editor/dataDiagramModel.ts:215

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


getPropertyType()

getPropertyType(propertyTypeIri): undefined | PropertyType

Defined in: editor/dataDiagramModel.ts:753

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


group()

group(entities): EntityGroup

Defined in: editor/dataDiagramModel.ts:789

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


importLayout()

importLayout(params): Promise<void>

Defined in: editor/dataDiagramModel.ts:294

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

{ dataProvider: DataProvider; diagram?: SerializedDiagram; hideUnusedLinkTypes?: boolean; locale?: DataLocaleProvider; preloadedElements?: ReadonlyMap<ElementIri, ElementModel>; signal?: AbortSignal; validateLinks?: boolean; }

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.locale?

DataLocaleProvider

Formatter for the graph data on the diagram.

If not specified, the DefaultDataLocaleProvider is used.

See

DataDiagramModel.locale

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


regroupLinks(links): void

Defined in: editor/dataDiagramModel.ts:955

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


removeElement()

removeElement(elementId): void

Defined in: diagram/model.ts:356

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


removeLink(linkId): void

Defined in: diagram/model.ts:382

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


reorderElements()

reorderElements(compare): void

Defined in: diagram/model.ts:316

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


requestElementData()

requestElementData(elementIris): Promise<void>

Defined in: editor/dataDiagramModel.ts:531

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

Parameters

ParameterType

elementIris

readonly ElementIri[]

Returns

Promise<void>


requestLinks(options): Promise<void>

Defined in: editor/dataDiagramModel.ts:538

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

Parameters

ParameterType

options

RequestLinksOptions

Returns

Promise<void>


requestLinksOfType()

requestLinksOfType(linkTypeIds?): Promise<void>

Defined in: editor/dataDiagramModel.ts:561

Parameters

ParameterType

linkTypeIds?

readonly LinkTypeIri[]

Returns

Promise<void>

Deprecated

Use DataDiagramModel.requestLinks instead.


setLanguage()

setLanguage(value): void

Defined in: diagram/model.ts:170

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


setLinkVisibility()

setLinkVisibility(linkTypeId, value): void

Defined in: diagram/model.ts:257

Sets current visibility mode for the specified link type.

Parameters

ParameterType

linkTypeId

LinkTypeIri

value

LinkTypeVisibility

Returns

void

Inherited from

DiagramModel.setLinkVisibility


setSelection()

setSelection(value): void

Defined in: diagram/model.ts:190

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


sourceOf()

sourceOf(link): undefined | Element

Defined in: diagram/model.ts:242

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


targetOf()

targetOf(link): undefined | Element

Defined in: diagram/model.ts:246

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


ungroupAll()

ungroupAll(groups): EntityElement[]

Defined in: editor/dataDiagramModel.ts:853

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


ungroupSome()

ungroupSome(group, entities): EntityElement[]

Defined in: editor/dataDiagramModel.ts:902

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