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.
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 ProjectAn 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.Project } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn 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.Project();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('School').PackageBuilder.build(): PackageBuilds 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: []`build();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets 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`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Person').ClassBuilder.build(): ClassBuilds 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,`build();
const const school: Classschool = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets 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`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('School').ClassBuilder.build(): ClassBuilds 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,`build();
const const studiesAt: BinaryRelationstudiesAt = const model: Packagemodel
.Package.binaryRelationBuilder(): BinaryRelationBuilderCreates a builder for a
BinaryRelation
contained in this
package.binaryRelationBuilder()
.BinaryRelationBuilder.material(): BinaryRelationBuilderSets 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`material()
.NamedElementBuilder<BinaryRelationBuilder>.name(value: string, language?: string): BinaryRelationBuilderAdds a name to the element in the given language.name('studies at')
.BinaryRelationBuilder.source(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the source end of the relation.source(const person: Classperson)
.BinaryRelationBuilder.target(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the target end of the relation.target(const school: Classschool)
.BinaryRelationBuilder.build(): BinaryRelationBuilds 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,`build();
const const diagram: Diagramdiagram = const project: Projectproject.Project.createDiagram(name?: string): DiagramCreates a new
Diagram
and adds it to this project.createDiagram('Overview');
const const relView: BinaryRelationViewrelView = const diagram: Diagramdiagram.Diagram.addBinaryRelation(rel: BinaryRelation): BinaryRelationViewCreates 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[]): voidThe **`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): booleanChecks whether the diagram contains a view depicting the given model
element.containsView(const person: Classperson)); // true
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`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): booleanChecks 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: PathThe polyline that renders the connector on the diagram canvas.path.Path.moveTo(x: number, y: number): voidAppends a new
Point
with the given coordinates to the path.moveTo(140, 60);
const relView: BinaryRelationViewrelView.BinaryConnectorView<Relation>.path: PathThe polyline that renders the connector on the diagram canvas.path.Path.moveTo(x: number, y: number): voidAppends a new
Point
with the given coordinates to the path.moveTo(300, 60);
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`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: anyThe 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 ProjectAn 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.Project } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn 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.Project();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('People').PackageBuilder.build(): PackageBuilds 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: []`build();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets 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`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Person').ClassBuilder.build(): ClassBuilds 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,`build();
const const student: Classstudent = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.role(): ClassBuilderSets 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`).role().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Student').ClassBuilder.build(): ClassBuilds 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,`build();
const const isAStudent: GeneralizationisAStudent = const person: Classperson.Classifier<Class, ClassStereotype>.addChild(child: Class): GeneralizationCreates a
Generalization
in which this classifier is the
general and the given classifier is the specific.addChild(const student: Classstudent);
const const diagram: Diagramdiagram = const project: Projectproject.Project.createDiagram(name?: string): DiagramCreates a new
Diagram
and adds it to this project.createDiagram('Taxonomy');
const const genView: GeneralizationViewgenView = const diagram: Diagramdiagram.Diagram.addGeneralization(gen: Generalization): GeneralizationViewCreates 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: PathThe polyline that renders the connector on the diagram canvas.path.Path.moveTo(x: number, y: number): voidAppends a new
Point
with the given coordinates to the path.moveTo(120, 80);
const genView: GeneralizationViewgenView.BinaryConnectorView<Generalization>.path: PathThe polyline that renders the connector on the diagram canvas.path.Path.moveTo(x: number, y: number): voidAppends 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 ProjectAn 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.Project } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn 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.Project();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('People').PackageBuilder.build(): PackageBuilds 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: []`build();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets 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`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Person').ClassBuilder.build(): ClassBuilds 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,`build();
const const child: Classchild = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.phase(): ClassBuilderSets 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`).phase().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Child').ClassBuilder.build(): ClassBuilds 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,`build();
const const adult: Classadult = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.phase(): ClassBuilderSets 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`).phase().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Adult').ClassBuilder.build(): ClassBuilds 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,`build();
const const byAge: GeneralizationSetbyAge = const model: Packagemodel
.Package.generalizationSetBuilder(): GeneralizationSetBuilderCreates a builder for a
GeneralizationSet
contained in this
package.generalizationSetBuilder()
.GeneralizationSetBuilder.partition(): GeneralizationSetBuilderSets the generalization set as a partition, i.e., as both disjoint and
complete.partition()
.NamedElementBuilder<GeneralizationSetBuilder>.name(value: string, language?: string): GeneralizationSetBuilderAdds a name to the element in the given language.name('by life phase')
.GeneralizationSetBuilder.generalizations(...generalizations: Generalization[]): GeneralizationSetBuilderSets the
Generalization
instances grouped by the generalization
set, replacing any previously set generalizations.generalizations(const person: Classperson.Classifier<Class, ClassStereotype>.addChild(child: Class): GeneralizationCreates a
Generalization
in which this classifier is the
general and the given classifier is the specific.addChild(const child: Classchild), const person: Classperson.Classifier<Class, ClassStereotype>.addChild(child: Class): GeneralizationCreates a
Generalization
in which this classifier is the
general and the given classifier is the specific.addChild(const adult: Classadult))
.GeneralizationSetBuilder.build(): GeneralizationSetBuilds 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,`build();
const const diagram: Diagramdiagram = const project: Projectproject.Project.createDiagram(name?: string): DiagramCreates a new
Diagram
and adds it to this project.createDiagram('Taxonomy');
const const gsView: GeneralizationSetViewgsView = const diagram: Diagramdiagram.Diagram.addGeneralizationSet(gs: GeneralizationSet): GeneralizationSetViewCreates a
GeneralizationSetView
for the given generalization set
and adds it to the diagram.addGeneralizationSet(const byAge: GeneralizationSetbyAge);
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`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: GeneralizationSetThe 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 ProjectAn 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.Project } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn 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.Project();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('Clinic').PackageBuilder.build(): PackageBuilds 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: []`build();
const const patient: Classpatient = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.role(): ClassBuilderSets 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`).role().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Patient').ClassBuilder.build(): ClassBuilds 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,`build();
const const physician: Classphysician = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.role(): ClassBuilderSets 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`).role().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Physician').ClassBuilder.build(): ClassBuilds 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,`build();
const const medication: Classmedication = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets 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`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Medication').ClassBuilder.build(): ClassBuilds 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,`build();
const const treatment: NaryRelationtreatment = const model: Packagemodel
.Package.naryRelationBuilder(): NaryRelationBuilderCreates a builder for a
NaryRelation
contained in this package.naryRelationBuilder()
.NaryRelationBuilder.material(): NaryRelationBuilderSets 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`material()
.NamedElementBuilder<NaryRelationBuilder>.name(value: string, language?: string): NaryRelationBuilderAdds a name to the element in the given language.name('treated with')
.NaryRelationBuilder.members(...members: Classifier<any, any>[]): NaryRelationBuilderSets 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.members(const patient: Classpatient, const physician: Classphysician, const medication: Classmedication)
.NaryRelationBuilder.build(): NaryRelationBuilds 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,`build();
const const diagram: Diagramdiagram = const project: Projectproject.Project.createDiagram(name?: string): DiagramCreates a new
Diagram
and adds it to this project.createDiagram('Treatments');
const const naryView: NaryRelationViewnaryView = const diagram: Diagramdiagram.Diagram.addNaryRelation(rel: NaryRelation): NaryRelationViewCreates 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: DiamondThe diamond that renders the central hub of the relation.diamond.RectangularShape.setX(x: number): voidSets the horizontal coordinate of the shape's top-left corner.setX(200);
const naryView: NaryRelationViewnaryView.NaryRelationView.diamond: DiamondThe diamond that renders the central hub of the relation.diamond.RectangularShape.setY(y: number): voidSets the vertical coordinate of the shape's top-left corner.setY(150);
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`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: numberGets 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→BinaryRelationViewwithsource,target, and apathrouted bymoveTo(x, y).addGeneralization→GeneralizationView(source = general, target = specific);addGeneralizationSet→GeneralizationSetView.addNaryRelation→NaryRelationViewwith adiamondhub and onepathper member.
Next: notes & packages →.