Skip to main content

Class: DataDiagramModel

Defined in: src/editor/dataDiagramModel.ts:153

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​

cellsVersion​

Get Signature​

get cellsVersion(): number

Defined in: src/diagram/model.ts:220

Graph content (elements and links) version number which changes on every cell change (when element or link added/removed/reordered, see DiagramModelEvents.changeCells).

Returns​

number

Implementation of​

DataGraphStructure.cellsVersion

Inherited from​

DiagramModel.cellsVersion


dataProvider​

Get Signature​

get dataProvider(): DataProvider

Defined in: src/editor/dataDiagramModel.ts:193

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: src/diagram/model.ts:224

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: src/diagram/model.ts:216

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: src/diagram/model.ts:175

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: src/diagram/model.ts:228

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: src/editor/dataDiagramModel.ts:204

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

Returns​

DataLocaleProvider


operations​

Get Signature​

get operations(): readonly FetchOperation[]

Defined in: src/editor/dataDiagramModel.ts:211

Returns an immutable snapshot of current fetch operations.

Returns​

readonly FetchOperation[]


selection​

Get Signature​

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

Defined in: src/diagram/model.ts:195

Current diagram selection (elements and/or links).

Returns​

readonly (Element | Link)[]

Inherited from​

DiagramModel.selection

Methods​

addElement()​

addElement(element): void

Defined in: src/diagram/model.ts:359

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: src/diagram/model.ts:389

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

Inherited from​

DiagramModel.addLink


bringElements()​

bringElements(targets, to): void

Defined in: src/diagram/model.ts:340

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: src/editor/dataDiagramModel.ts:659

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: src/editor/dataDiagramModel.ts:801

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: src/editor/dataDiagramModel.ts:707

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: src/editor/dataDiagramModel.ts:822

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: src/editor/dataDiagramModel.ts:263

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: src/editor/dataDiagramModel.ts:843

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: src/editor/dataDiagramModel.ts:453

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

Returns​

void


exportLayout()​

exportLayout(): SerializedDiagram

Defined in: src/editor/dataDiagramModel.ts:482

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: src/diagram/model.ts:251

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: src/diagram/model.ts:239

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: src/diagram/model.ts:243

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: src/editor/dataDiagramModel.ts:791

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: src/diagram/model.ts:247

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: src/editor/dataDiagramModel.ts:812

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: src/diagram/model.ts:266

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: src/editor/dataDiagramModel.ts:219

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: src/editor/dataDiagramModel.ts:833

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: src/editor/dataDiagramModel.ts:869

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: src/editor/dataDiagramModel.ts:298

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; elementCellTypes?: readonly SerializableElementCell<JsonableElement>[]; hideUnusedLinkTypes?: boolean; linkCellTypes?: readonly SerializableLinkCell<JsonableLink>[]; locale?: DataLocaleProvider; preloadedElements?: ReadonlyMap<ElementIri, ElementModel>; preloadedLinks?: ReadonlyHashMap<LinkKey, LinkModel>; 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.elementCellTypes?

readonly SerializableElementCell<JsonableElement>[]

Element cell types to deserialize from the imported diagram state.

Any element cell type not from this list will be silently ignored.

Unstable: this feature is likely to be changed in the future.

Default

[EntityElement, EntityGroup, AnnotationElement]

params.hideUnusedLinkTypes?

boolean

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

Default

false

params.linkCellTypes?

readonly SerializableLinkCell<JsonableLink>[]

Link cell types to deserialize from the imported diagram state.

Any link cell type not from this list will be silently ignored.

Unstable: this feature is likely to be changed in the future.

Default

[RelationLink, RelationGroup, AnnotationLink]

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 entities which should be used instead of being requested from the data provider on import.

params.preloadedLinks?

ReadonlyHashMap<LinkKey, LinkModel>

Pre-cached data for the relations 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: src/editor/dataDiagramModel.ts:1037

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: src/diagram/model.ts:372

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: src/diagram/model.ts:398

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: src/diagram/model.ts:332

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


requestData()​

requestData(): Promise<void>

Defined in: src/editor/dataDiagramModel.ts:594

Requests to load all entities with placeholder data and all relations connected to them.

Returns​

Promise<void>

See​


requestElementData()​

requestElementData(elementIris): Promise<void>

Defined in: src/editor/dataDiagramModel.ts:614

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: src/editor/dataDiagramModel.ts:621

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: src/editor/dataDiagramModel.ts:644

Parameters​

ParameterType

linkTypeIds?

readonly LinkTypeIri[]

Returns​

Promise<void>

Deprecated​

Use DataDiagramModel.requestLinks instead.


setLanguage()​

setLanguage(value): void

Defined in: src/diagram/model.ts:182

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: src/diagram/model.ts:273

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: src/diagram/model.ts:202

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: src/diagram/model.ts:258

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: src/diagram/model.ts:262

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: src/editor/dataDiagramModel.ts:933

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: src/editor/dataDiagramModel.ts:983

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​