Skip to main content
Version: 1.0.0

Connecting elements

Relations and generalizations are drawn as connectors — lines routed between the views of the elements they link. The diagram's connector factories do the fiddly part for you: they create the connector view and make sure both endpoints have views to attach to.

Endpoints are created for you

addBinaryRelation, addGeneralization, and addNaryRelation each call findOrCreateView on the classifiers they connect. If a class isn't on the diagram yet, its view is added automatically — so you can drop a relation onto an empty canvas and get everything you need.

Binary relations​

addBinaryRelation returns a BinaryRelationView. It has a source and a target view (the auto-created endpoints) and a path — the polyline that draws the connector. Route the path with moveTo(x, y), which appends a point.

import { class Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('School').PackageBuilder.build(): Package
Builds an instance of Package with the parameters passed to the builder. When no methods are evoked, the created package has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `contents: []`
@throwsan error if the builder has already been used.
build
();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets the stereotype of the class to «kind», which decorates rigid classes that provide an identity principle to their instances, which are functional complexes (e.g., `Person`, `Car`). Also applies the following defaults: - `restrictedTo = [ "functional-complex" ]` - `order = 1`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Person').ClassBuilder.build(): Class
Builds an instance of Class with the parameters passed to the builder. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created class has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,` - `order: 1,` - `isPowertype: false,`
@throwsan error if the builder has already been used.
build
();
const const school: Classschool = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets the stereotype of the class to «kind», which decorates rigid classes that provide an identity principle to their instances, which are functional complexes (e.g., `Person`, `Car`). Also applies the following defaults: - `restrictedTo = [ "functional-complex" ]` - `order = 1`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('School').ClassBuilder.build(): Class
Builds an instance of Class with the parameters passed to the builder. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created class has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,` - `order: 1,` - `isPowertype: false,`
@throwsan error if the builder has already been used.
build
();
const const studiesAt: BinaryRelationstudiesAt = const model: Packagemodel .Package.binaryRelationBuilder(): BinaryRelationBuilder
Creates a builder for a BinaryRelation contained in this package.
binaryRelationBuilder
()
.BinaryRelationBuilder.material(): BinaryRelationBuilder
Sets the stereotype of the relation to «material», which decorates relations between endurants that are founded on relators, such as being married to or being enrolled at. Also applies the following defaults: - `isDerived = true`
@returnsthis builder, for method chaining.
material
()
.NamedElementBuilder<BinaryRelationBuilder>.name(value: string, language?: string): BinaryRelationBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('studies at')
.BinaryRelationBuilder.source(classifier: Classifier<any, any>): BinaryRelationBuilder
Sets the Classifier connected to the source end of the relation.
@returnsthis builder, for method chaining.
source
(const person: Classperson)
.BinaryRelationBuilder.target(classifier: Classifier<any, any>): BinaryRelationBuilder
Sets the Classifier connected to the target end of the relation.
@returnsthis builder, for method chaining.
target
(const school: Classschool)
.BinaryRelationBuilder.build(): BinaryRelation
Builds an instance of BinaryRelation with the parameters passed to the builder. Both the source and the target classifiers are required before `build()` is evoked. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created relation has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,`
@throwsan error if the builder has already been used.
build
();
const const diagram: Diagramdiagram = const project: Projectproject.Project.createDiagram(name?: string): Diagram
Creates a new Diagram and adds it to this project.
@paramname - optional name for the diagram, set in the default language.
createDiagram
('Overview');
const const relView: BinaryRelationViewrelView = const diagram: Diagramdiagram.Diagram.addBinaryRelation(rel: BinaryRelation): BinaryRelationView
Creates a BinaryRelationView for the given relation and adds it to the diagram, creating views for the relation's source and target classifiers when these are not yet depicted. Throws an error if either end of the relation is untyped.
addBinaryRelation
(const studiesAt: BinaryRelationstudiesAt);
// Both endpoint class views were created automatically: var console: Consoleconsole.Console.log(...data: any[]): void
The **`console.log()`** static method outputs a message to the console. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(const diagram: Diagramdiagram.Diagram.containsView(modelElement: ModelElement): boolean
Checks whether the diagram contains a view depicting the given model element.
containsView
(const person: Classperson)); // true
var console: Consoleconsole.Console.log(...data: any[]): void
The **`console.log()`** static method outputs a message to the console. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(const diagram: Diagramdiagram.Diagram.containsView(modelElement: ModelElement): boolean
Checks whether the diagram contains a view depicting the given model element.
containsView
(const school: Classschool)); // true
// Route the connector as a two-point line: const relView: BinaryRelationViewrelView.BinaryConnectorView<Relation>.path: Path
The polyline that renders the connector on the diagram canvas.
path
.Path.moveTo(x: number, y: number): void
Appends a new Point with the given coordinates to the path.
moveTo
(140, 60);
const relView: BinaryRelationViewrelView.BinaryConnectorView<Relation>.path: Path
The polyline that renders the connector on the diagram canvas.
path
.Path.moveTo(x: number, y: number): void
Appends a new Point with the given coordinates to the path.
moveTo
(300, 60);
var console: Consoleconsole.Console.log(...data: any[]): void
The **`console.log()`** static method outputs a message to the console. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(const relView: BinaryRelationViewrelView.BinaryConnectorView<Relation>.source: View<any>
The view at the source end of the connector.
source
.View<any>.element: any
The model element this view depicts.
element
=== const person: Classperson); // true

Generalizations​

addGeneralization takes a Generalization (built in the Generalizations chapter) and returns a GeneralizationView, with the general as source and the specific as target:

import { class Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('People').PackageBuilder.build(): Package
Builds an instance of Package with the parameters passed to the builder. When no methods are evoked, the created package has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `contents: []`
@throwsan error if the builder has already been used.
build
();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets the stereotype of the class to «kind», which decorates rigid classes that provide an identity principle to their instances, which are functional complexes (e.g., `Person`, `Car`). Also applies the following defaults: - `restrictedTo = [ "functional-complex" ]` - `order = 1`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Person').ClassBuilder.build(): Class
Builds an instance of Class with the parameters passed to the builder. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created class has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,` - `order: 1,` - `isPowertype: false,`
@throwsan error if the builder has already been used.
build
();
const const student: Classstudent = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.role(): ClassBuilder
Sets the stereotype of the class to «role», which decorates anti-rigid classes whose instances are contingently classified by virtue of a relational condition (e.g., `Student`, `Employee`).
@returnsthis builder, for method chaining.
role
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Student').ClassBuilder.build(): Class
Builds an instance of Class with the parameters passed to the builder. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created class has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,` - `order: 1,` - `isPowertype: false,`
@throwsan error if the builder has already been used.
build
();
const const isAStudent: GeneralizationisAStudent = const person: Classperson.Classifier<Class, ClassStereotype>.addChild(child: Class): Generalization
Creates a Generalization in which this classifier is the general and the given classifier is the specific.
@paramchild - the classifier to be set as the specific.@returnsthe newly created generalization.
addChild
(const student: Classstudent);
const const diagram: Diagramdiagram = const project: Projectproject.Project.createDiagram(name?: string): Diagram
Creates a new Diagram and adds it to this project.
@paramname - optional name for the diagram, set in the default language.
createDiagram
('Taxonomy');
const const genView: GeneralizationViewgenView = const diagram: Diagramdiagram.Diagram.addGeneralization(gen: Generalization): GeneralizationView
Creates a GeneralizationView for the given generalization and adds it to the diagram, creating views for the general and specific classifiers when these are not yet depicted. The general classifier's view becomes the source of the connector and the specific classifier's view becomes its target.
addGeneralization
(const isAStudent: GeneralizationisAStudent);
const genView: GeneralizationViewgenView.BinaryConnectorView<Generalization>.path: Path
The polyline that renders the connector on the diagram canvas.
path
.Path.moveTo(x: number, y: number): void
Appends a new Point with the given coordinates to the path.
moveTo
(120, 80);
const genView: GeneralizationViewgenView.BinaryConnectorView<Generalization>.path: Path
The polyline that renders the connector on the diagram canvas.
path
.Path.moveTo(x: number, y: number): void
Appends a new Point with the given coordinates to the path.
moveTo
(120, 160);

Generalization sets​

A generalization set is drawn as a labelled marker joining its member generalization connectors. addGeneralizationSet returns a GeneralizationSetView:

import { class Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('People').PackageBuilder.build(): Package
Builds an instance of Package with the parameters passed to the builder. When no methods are evoked, the created package has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `contents: []`
@throwsan error if the builder has already been used.
build
();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets the stereotype of the class to «kind», which decorates rigid classes that provide an identity principle to their instances, which are functional complexes (e.g., `Person`, `Car`). Also applies the following defaults: - `restrictedTo = [ "functional-complex" ]` - `order = 1`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Person').ClassBuilder.build(): Class
Builds an instance of Class with the parameters passed to the builder. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created class has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,` - `order: 1,` - `isPowertype: false,`
@throwsan error if the builder has already been used.
build
();
const const child: Classchild = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.phase(): ClassBuilder
Sets the stereotype of the class to «phase», which decorates anti-rigid classes whose instances are contingently classified by virtue of an intrinsic condition (e.g., `Child`, `LivingPerson`).
@returnsthis builder, for method chaining.
phase
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Child').ClassBuilder.build(): Class
Builds an instance of Class with the parameters passed to the builder. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created class has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,` - `order: 1,` - `isPowertype: false,`
@throwsan error if the builder has already been used.
build
();
const const adult: Classadult = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.phase(): ClassBuilder
Sets the stereotype of the class to «phase», which decorates anti-rigid classes whose instances are contingently classified by virtue of an intrinsic condition (e.g., `Child`, `LivingPerson`).
@returnsthis builder, for method chaining.
phase
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Adult').ClassBuilder.build(): Class
Builds an instance of Class with the parameters passed to the builder. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created class has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,` - `order: 1,` - `isPowertype: false,`
@throwsan error if the builder has already been used.
build
();
const const byAge: GeneralizationSetbyAge = const model: Packagemodel .Package.generalizationSetBuilder(): GeneralizationSetBuilder
Creates a builder for a GeneralizationSet contained in this package.
generalizationSetBuilder
()
.GeneralizationSetBuilder.partition(): GeneralizationSetBuilder
Sets the generalization set as a partition, i.e., as both disjoint and complete.
@returnsthis builder, for method chaining.
partition
()
.NamedElementBuilder<GeneralizationSetBuilder>.name(value: string, language?: string): GeneralizationSetBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('by life phase')
.GeneralizationSetBuilder.generalizations(...generalizations: Generalization[]): GeneralizationSetBuilder
Sets the Generalization instances grouped by the generalization set, replacing any previously set generalizations.
@returnsthis builder, for method chaining.
generalizations
(const person: Classperson.Classifier<Class, ClassStereotype>.addChild(child: Class): Generalization
Creates a Generalization in which this classifier is the general and the given classifier is the specific.
@paramchild - the classifier to be set as the specific.@returnsthe newly created generalization.
addChild
(const child: Classchild), const person: Classperson.Classifier<Class, ClassStereotype>.addChild(child: Class): Generalization
Creates a Generalization in which this classifier is the general and the given classifier is the specific.
@paramchild - the classifier to be set as the specific.@returnsthe newly created generalization.
addChild
(const adult: Classadult))
.GeneralizationSetBuilder.build(): GeneralizationSet
Builds an instance of GeneralizationSet with the parameters passed to the builder. When no methods are evoked, the created generalization set has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isDisjoint: false,` - `isComplete: false,`
@throwsan error if the builder has already been used.
build
();
const const diagram: Diagramdiagram = const project: Projectproject.Project.createDiagram(name?: string): Diagram
Creates a new Diagram and adds it to this project.
@paramname - optional name for the diagram, set in the default language.
createDiagram
('Taxonomy');
const const gsView: GeneralizationSetViewgsView = const diagram: Diagramdiagram.Diagram.addGeneralizationSet(gs: GeneralizationSet): GeneralizationSetView
Creates a GeneralizationSetView for the given generalization set and adds it to the diagram.
addGeneralizationSet
(const byAge: GeneralizationSetbyAge);
var console: Consoleconsole.Console.log(...data: any[]): void
The **`console.log()`** static method outputs a message to the console. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(const gsView: GeneralizationSetViewgsView.View<GeneralizationSet>.element: GeneralizationSet
The model element this view depicts.
element
=== const byAge: GeneralizationSetbyAge); // true

N-ary relations​

An n-ary relation is drawn with a central diamond and one path per member. addNaryRelation returns a NaryRelationView whose diamond you position and whose paths (one per member, in order) you route:

import { class Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Clinic').PackageBuilder.build(): Package
Builds an instance of Package with the parameters passed to the builder. When no methods are evoked, the created package has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `contents: []`
@throwsan error if the builder has already been used.
build
();
const const patient: Classpatient = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.role(): ClassBuilder
Sets the stereotype of the class to «role», which decorates anti-rigid classes whose instances are contingently classified by virtue of a relational condition (e.g., `Student`, `Employee`).
@returnsthis builder, for method chaining.
role
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Patient').ClassBuilder.build(): Class
Builds an instance of Class with the parameters passed to the builder. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created class has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,` - `order: 1,` - `isPowertype: false,`
@throwsan error if the builder has already been used.
build
();
const const physician: Classphysician = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.role(): ClassBuilder
Sets the stereotype of the class to «role», which decorates anti-rigid classes whose instances are contingently classified by virtue of a relational condition (e.g., `Student`, `Employee`).
@returnsthis builder, for method chaining.
role
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Physician').ClassBuilder.build(): Class
Builds an instance of Class with the parameters passed to the builder. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created class has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,` - `order: 1,` - `isPowertype: false,`
@throwsan error if the builder has already been used.
build
();
const const medication: Classmedication = const model: Packagemodel.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets the stereotype of the class to «kind», which decorates rigid classes that provide an identity principle to their instances, which are functional complexes (e.g., `Person`, `Car`). Also applies the following defaults: - `restrictedTo = [ "functional-complex" ]` - `order = 1`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Medication').ClassBuilder.build(): Class
Builds an instance of Class with the parameters passed to the builder. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created class has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,` - `order: 1,` - `isPowertype: false,`
@throwsan error if the builder has already been used.
build
();
const const treatment: NaryRelationtreatment = const model: Packagemodel .Package.naryRelationBuilder(): NaryRelationBuilder
Creates a builder for a NaryRelation contained in this package.
naryRelationBuilder
()
.NaryRelationBuilder.material(): NaryRelationBuilder
Sets the stereotype of the relation to «material», which decorates relations between endurants that are founded on relators, such as being treated in. Also applies the following defaults: - `isDerived = true`
@returnsthis builder, for method chaining.
material
()
.NamedElementBuilder<NaryRelationBuilder>.name(value: string, language?: string): NaryRelationBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('treated with')
.NaryRelationBuilder.members(...members: Classifier<any, any>[]): NaryRelationBuilder
Sets the Classifier instances connected by the ends of the relation, replacing any previously set members. At least three members are required to build the relation.
@returnsthis builder, for method chaining.
members
(const patient: Classpatient, const physician: Classphysician, const medication: Classmedication)
.NaryRelationBuilder.build(): NaryRelation
Builds an instance of NaryRelation with the parameters passed to the builder. At least three members are required before `build()` is evoked. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created relation has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,`
@throwsan error if the builder has already been used.
build
();
const const diagram: Diagramdiagram = const project: Projectproject.Project.createDiagram(name?: string): Diagram
Creates a new Diagram and adds it to this project.
@paramname - optional name for the diagram, set in the default language.
createDiagram
('Treatments');
const const naryView: NaryRelationViewnaryView = const diagram: Diagramdiagram.Diagram.addNaryRelation(rel: NaryRelation): NaryRelationView
Creates a NaryRelationView for the given relation and adds it to the diagram, creating views for the relation's member classes when these are not yet depicted. Throws an error if any property of the relation is untyped or if the relation does not hold between classes.
addNaryRelation
(const treatment: NaryRelationtreatment);
// Put the hub in the middle; the member class views were auto-created. const naryView: NaryRelationViewnaryView.NaryRelationView.diamond: Diamond
The diamond that renders the central hub of the relation.
diamond
.RectangularShape.setX(x: number): void
Sets the horizontal coordinate of the shape's top-left corner.
setX
(200);
const naryView: NaryRelationViewnaryView.NaryRelationView.diamond: Diamond
The diamond that renders the central hub of the relation.
diamond
.RectangularShape.setY(y: number): void
Sets the vertical coordinate of the shape's top-left corner.
setY
(150);
var console: Consoleconsole.Console.log(...data: any[]): void
The **`console.log()`** static method outputs a message to the console. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(const naryView: NaryRelationViewnaryView.NaryRelationView.members: ClassView[]
The views of the classes connected by the relation. Replaces the views of the classes connected by the relation.
members
.Array<ClassView>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.
length
); // 3

Key takeaways​

  • Connector factories auto-create endpoint views via findOrCreateView.
  • addBinaryRelation → BinaryRelationView with source, target, and a path routed by moveTo(x, y).
  • addGeneralization → GeneralizationView (source = general, target = specific); addGeneralizationSet → GeneralizationSetView.
  • addNaryRelation → NaryRelationView with a diamond hub and one path per member.

Next: notes & packages →.