Represents an entity-relationship data model.

This model is:

For detailed usage, refer to @xeokit/sdk/data.

Hierarchy (View Summary)

Properties

author?: string

The model author, if available.

built: boolean

Indicates if this DataModel has been built.

createdAt?: string

The date the model was created, if available.

creatingApplication?: string

The application that created the model, if available.

data: Data

The Data that contains this DataModel.

destroyed: boolean

True once this Component has been destroyed.

Don't use this Component if this is true.

dirty: boolean
id: string

Unique ID of this DataModel.

DataModels are stored against this ID in Data.models.

name?: string

The model name, if available.

objects: { [key: string]: DataObject }

The DataObjects in this DataModel, mapped to DataObject.id.

DataObjects have globally-unique IDs and will also be stored in Data.objects.

objectsByType: { [key: string]: { [key: string]: DataObject } }

The DataObjects in this DataModel, mapped to DataObject.type, sub-mapped to DataObject.id.

projectId?: string | number

The project ID, if available.

propertySets: { [key: string]: PropertySet }

ThePropertySets in this DataModel, mapped toPropertySet.id.

PropertySets have globally-unique IDs and will also be stored in Data.propertySets.

relationships: Relationship[]

The Relationships in this DataModel.

  • The Relationships can be between DataObjects in different DataModels, but always within the same Data.
revisionId?: string | number

The revision ID, if available.

rootObjects: { [key: string]: DataObject }

The root DataObjects in this DataModel, mapped to DataObject.id.

  • This is the set of DataObjects in this DataModel that are not the related participant in any Relationships, where they have no incoming Relationships and their DataObject.relating property is empty.
schema?: string

The model schema version, if available.

typeCounts: { [key: string]: number }

The count of each type of DataObject in this DataModel, mapped to DataObject.type.

Methods

  • Finalizes this DataModel, making it ready for use.

    dataModel.onBuilt.subscribe(() => {
    // The DataModel is built and ready for use
    });

    data.onModelCreated.subscribe((dataModel) => {
    // Another way to listen for DataModel readiness
    });

    const result = dataModel.build();

    if (result instanceof SDKError) {
    console.error(result.message);
    } else {
    // Success
    }

    See @xeokit/sdk/data for more details.

    Returns Promise<DataModel>

    SDKError if:

    • The DataModel has already been built.
    • The DataModel has been destroyed.
  • Creates a new DataObject and registers it within the DataModel and Data.

    • The new DataObject is stored in DataModel.objects and Data.objects.
    • Triggers an event via Data.onObjectCreated.
    • DataObject IDs are globally unique. If a DataObject with the given ID already exists in the same Data, it will be reused and shared across DataModels rather than creating a duplicate.
    • This behavior enables xeokit to support federated data models.
    const myDataObject = dataModel.createObject({
    id: "myDataObject",
    type: BasicEntity, // @xeokit/basictypes!basicTypes
    name: "My Object",
    propertySetIds: ["myPropertySet"]
    });

    const myDataObject2 = dataModel.createObject({
    id: "myDataObject2",
    name: "My Other Object",
    type: BasicEntity,
    propertySetIds: ["myPropertySet"]
    });

    if (myDataObject instanceof SDKError) {
    console.error(myDataObject.message);
    } else if (myDataObject2 instanceof SDKError) {
    console.error(myDataObject2.message);
    } else {
    // Success
    const gotMyDataObject = dataModel.objects["myDataObject"];
    const gotMyDataObjectAgain = data.objects["myDataObject"];
    }

    See @xeokit/sdk/data for more details.

    Parameters

    • dataObjectParams: DataObjectParams

      Configuration parameters for the new DataObject.

    Returns SDKError | DataObject

    DataObject on success.

  • Creates a new PropertySet and registers it within the DataModel and Data.

    • The new PropertySet is stored in DataModel.propertySets and Data.propertySets.
    • PropertySet IDs are globally unique. If a PropertySet with the given ID already exists in the same Data, it will be reused and shared across DataModels instead of creating a duplicate.
    • A PropertySet ID must be unique within a single DataModel but can be shared between multiple DataModels.
    const propertySet = dataModel.createPropertySet({
    id: "myPropertySet",
    name: "My properties",
    properties: [
    {
    name: "Weight",
    value: 5,
    type: "",
    valueType: "",
    description: "Weight of a thing"
    },
    {
    name: "Height",
    value: 12,
    type: "",
    valueType: "",
    description: "Height of a thing"
    }
    ]
    });

    if (propertySet instanceof SDKError) {
    console.error(propertySet.message);
    } else {
    // PropertySet successfully created
    }

    See @xeokit/sdk/data for more details.

    Parameters

    Returns SDKError | PropertySet

    PropertySet on success.

  • Creates a new Relationship between two existing DataObjects.

    • A Relationship consists of a relating DataObject and a related DataObject.
    • The relating and related DataObjects can belong to different DataModels, provided both DataModels exist within the same Data. This enables xeokit to support federated models.
    • The created Relationship is stored in:
    const myRelationship = dataModel.createRelationship({
    type: BasicAggregation, // @xeokit/basictypes!basicTypes
    relatingObjectId: "myDataObject",
    relatedObjectId: "myDataObject2"
    });

    if (myRelationship instanceof SDKError) {
    console.error(myRelationship.message);
    } else {
    // Success
    const myDataObject = dataModel.objects["myDataObject"];
    const myDataObject2 = dataModel.objects["myDataObject2"];

    const gotMyRelationship = myDataObject.related[BasicAggregation][0];
    const gotMyRelationshipAgain = myDataObject2.relating[BasicAggregation][0];
    }

    See @xeokit/sdk/data for more details.

    Parameters

    Returns SDKError | Relationship

    Relationship on success.

  • Protected

    Logs an error for this component to the JavaScript console.

    The console message will have this format: [ERROR] [<component type> =<component id>: <message>

    Parameters

    • message: string

      The error message to log

    Returns void

  • Protected

    Logs a message for this component.

    The message will have this format: [LOG] [<component type> <component id>: <message>

    Parameters

    • message: string

      The message to log

    Returns void

  • Protected

    Logs a warning for this component to the JavaScript console.

    The console message will have this format: [WARN] [<component type> =<component id>: <message>

    Parameters

    • message: string

      The warning message to log

    Returns void

Events

onBuilt: EventEmitter<DataModel, null>

Emits an event when the DataModel has been built.

  • The DataModel is built using DataModel.build.
  • DataModel.built indicates if the DataModel is currently built.
  • Don't create anything more in this DataModel once it's built.
onDestroyed: EventEmitter<Component, null>

Emits an event when the Component has been destroyed.