Skip to main content
Version: Next

Notes & packages

Most elements have a one-call factory (addClass, addBinaryRelation, …). Two do not: notes and anchors have no add… shortcut, so you build their views by hand. Packages do have a factory. This page covers all three.

Package views​

addPackage mirrors addClass — it returns a PackageView whose box is a rectangle you position like any other:

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 people: Packagepeople = const model: Packagemodel.Package.packageBuilder(): PackageBuilder
Creates a builder for a Package contained in this package.
packageBuilder
().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 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 peopleView: PackageViewpeopleView = const diagram: Diagramdiagram.Diagram.addPackage(pkg: Package): PackageView
Creates a PackageView for the given package and adds it to the diagram.
addPackage
(const people: Packagepeople);
const peopleView: PackageViewpeopleView.PackageView.rectangle: Rectangle
The rectangle that renders the package on the diagram canvas.
rectangle
.RectangularShape.setX(x: number): void
Sets the horizontal coordinate of the shape's top-left corner.
setX
(40);
const peopleView: PackageViewpeopleView.PackageView.rectangle: Rectangle
The rectangle that renders the package on the diagram canvas.
rectangle
.RectangularShape.setY(y: number): void
Sets the vertical coordinate of the shape's top-left corner.
setY
(40);
const peopleView: PackageViewpeopleView.PackageView.rectangle: Rectangle
The rectangle that renders the package on the diagram canvas.
rectangle
.RectangularShape.width: number
The width of the shape's bounding rectangle. Sets the width of the shape's bounding rectangle. Throws an error if the value is negative.
width
= 200;
const peopleView: PackageViewpeopleView.PackageView.rectangle: Rectangle
The rectangle that renders the package on the diagram canvas.
rectangle
.RectangularShape.height: number
The height of the shape's bounding rectangle. Sets the height of the shape's bounding rectangle. Throws an error if the value is negative.
height
= 160;

Note views (built by hand)​

There is no addNote. Construct a NoteView around the note, add it with the low-level addView, then position its text box:

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
, class NoteView
The view of a Note in a Diagram , rendered as a Text box (100 × 50 by default).
NoteView
} 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 note: Notenote = const model: Packagemodel .Package.noteBuilder(): NoteBuilder
Creates a builder for a Note contained in this package.
noteBuilder
()
.NoteBuilder.text(value: string, language?: string): NoteBuilder
Adds the text of the note in the given language.
@paramvalue - the note text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
text
('Enrollment periods are set per term.')
.NoteBuilder.build(): Note
Builds an instance of Note with the parameters passed to the builder. When no methods are evoked, the created note has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `text: empty`
@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 noteView: NoteViewnoteView = new new NoteView(note: Note): NoteView
The view of a Note in a Diagram , rendered as a Text box (100 × 50 by default).
NoteView
(const note: Notenote);
const diagram: Diagramdiagram.Diagram.addView(element: View<any>): void
Adds a view to the diagram and registers it in the containing project. Does nothing when the view is `null` or `undefined`.
addView
(const noteView: NoteViewnoteView);
const noteView: NoteViewnoteView.NoteView.text: Text
The text box that renders the note on the diagram canvas.
text
.RectangularShape.setX(x: number): void
Sets the horizontal coordinate of the shape's top-left corner.
setX
(260);
const noteView: NoteViewnoteView.NoteView.text: Text
The text box that renders the note on the diagram canvas.
text
.RectangularShape.setY(y: number): void
Sets the vertical coordinate of the shape's top-left corner.
setY
(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 diagram: Diagramdiagram.Diagram.views: View<any>[]
The views contained in the diagram. Replaces the views contained in the diagram.
views
.Array<View<any>>.includes(searchElement: View<any>, fromIndex?: number): boolean
Determines whether an array includes a certain element, returning true or false as appropriate.
@paramsearchElement The element to search for.@paramfromIndex The position in this array at which to begin searching for searchElement.
includes
(const noteView: NoteViewnoteView)); // true

An anchor is drawn as a dashed line from a note view to the view of the element it annotates. An AnchorView needs all three — the anchor, the NoteView, and the target element's view:

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
, class NoteView
The view of a Note in a Diagram , rendered as a Text box (100 × 50 by default).
NoteView
, class AnchorView
The view of an Anchor in a Diagram , rendered as a Path connecting a NoteView to the view of the element the note is attached to.
AnchorView
} 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 note: Notenote = const model: Packagemodel.Package.noteBuilder(): NoteBuilder
Creates a builder for a Note contained in this package.
noteBuilder
().NoteBuilder.text(value: string, language?: string): NoteBuilder
Adds the text of the note in the given language.
@paramvalue - the note text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
text
('Members are always persons.').NoteBuilder.build(): Note
Builds an instance of Note with the parameters passed to the builder. When no methods are evoked, the created note has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `text: empty`
@throwsan error if the builder has already been used.
build
();
const const anchor: Anchoranchor = const note: Notenote.Note.anchorBuilder(): AnchorBuilder
Creates a builder for an Anchor that attaches this note to a model element.
anchorBuilder
().AnchorBuilder.annotates(element: ModelElement): AnchorBuilder
Sets the ModelElement annotated by the note connected by the anchor.
@returnsthis builder, for method chaining.
annotates
(const person: Classperson).AnchorBuilder.build(): Anchor
Builds an instance of Anchor with the parameters passed to the builder. Both the note and the annotated element are required before `build()` is evoked. When no other methods are evoked, the created anchor has the following defaults: - `id: "randomly-generated-id",` - `created: new Date()`
@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 personView: ClassViewpersonView = const diagram: Diagramdiagram.Diagram.addClass(clazz: Class): ClassView
Creates a ClassView for the given class and adds it to the diagram.
addClass
(const person: Classperson);
const const noteView: NoteViewnoteView = new new NoteView(note: Note): NoteView
The view of a Note in a Diagram , rendered as a Text box (100 × 50 by default).
NoteView
(const note: Notenote);
const diagram: Diagramdiagram.Diagram.addView(element: View<any>): void
Adds a view to the diagram and registers it in the containing project. Does nothing when the view is `null` or `undefined`.
addView
(const noteView: NoteViewnoteView);
// Link the note view to the class view. const const anchorView: AnchorViewanchorView = new new AnchorView(element: Anchor, noteView: NoteView, elementView: View<any>): AnchorView
The view of an Anchor in a Diagram , rendered as a Path connecting a NoteView to the view of the element the note is attached to.
AnchorView
(const anchor: Anchoranchor, const noteView: NoteViewnoteView, const personView: ClassViewpersonView);
const diagram: Diagramdiagram.Diagram.addView(element: View<any>): void
Adds a view to the diagram and registers it in the containing project. Does nothing when the view is `null` or `undefined`.
addView
(const anchorView: AnchorViewanchorView);
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 anchorView: AnchorViewanchorView.AnchorView.noteView: NoteView
The view of the note at the source end of the anchor.
noteView
=== const noteView: NoteViewnoteView); // 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 anchorView: AnchorViewanchorView.AnchorView.elementView: View<any>
The view of the element to which the note is attached.
elementView
=== const personView: ClassViewpersonView); // true
addView vs the add… factories

addView is the primitive: it registers a view you constructed yourself. The add… factories are conveniences layered on top that build the view (with default shapes) and call addView. Notes and anchors simply don't have such a convenience — so you reach for addView directly.

Key takeaways​

  • addPackage(pkg) → PackageView, positioned via its rectangle like a class view.
  • Notes and anchors have no factory: construct new NoteView(note) / new AnchorView(anchor, noteView, elementView) and register them with diagram.addView(...).
  • A NoteView carries a text shape; an AnchorView links a noteView to an elementView.

Next: a complete diagram →.