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 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 people: Packagepeople = const model: Packagemodel.Package.packageBuilder(): PackageBuilderCreates a builder for a
Package
contained in this package.packageBuilder().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 diagram: Diagramdiagram = const project: Projectproject.Project.createDiagram(name?: string): DiagramCreates a new
Diagram
and adds it to this project.createDiagram('Overview');
const const peopleView: PackageViewpeopleView = const diagram: Diagramdiagram.Diagram.addPackage(pkg: Package): PackageViewCreates a
PackageView
for the given package and adds it to the
diagram.addPackage(const people: Packagepeople);
const peopleView: PackageViewpeopleView.PackageView.rectangle: RectangleThe rectangle that renders the package on the diagram canvas.rectangle.RectangularShape.setX(x: number): voidSets the horizontal coordinate of the shape's top-left corner.setX(40);
const peopleView: PackageViewpeopleView.PackageView.rectangle: RectangleThe rectangle that renders the package on the diagram canvas.rectangle.RectangularShape.setY(y: number): voidSets the vertical coordinate of the shape's top-left corner.setY(40);
const peopleView: PackageViewpeopleView.PackageView.rectangle: RectangleThe rectangle that renders the package on the diagram canvas.rectangle.RectangularShape.width: numberThe 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: RectangleThe rectangle that renders the package on the diagram canvas.rectangle.RectangularShape.height: numberThe 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 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, class NoteViewThe 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(): 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 note: Notenote = const model: Packagemodel
.Package.noteBuilder(): NoteBuilderCreates a builder for a
Note
contained in this package.noteBuilder()
.NoteBuilder.text(value: string, language?: string): NoteBuilderAdds the text of the note in the given language.text('Enrollment periods are set per term.')
.NoteBuilder.build(): NoteBuilds 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`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 noteView: NoteViewnoteView = new new NoteView(note: Note): NoteViewThe 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>): voidAdds 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: TextThe text box that renders the note on the diagram canvas.text.RectangularShape.setX(x: number): voidSets the horizontal coordinate of the shape's top-left corner.setX(260);
const noteView: NoteViewnoteView.NoteView.text: TextThe text box that renders the note on the diagram canvas.text.RectangularShape.setY(y: number): voidSets the vertical coordinate of the shape's top-left corner.setY(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 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): booleanDetermines whether an array includes a certain element, returning true or false as appropriate.includes(const noteView: NoteViewnoteView)); // true
Anchor views (the dashed link)
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 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, class NoteViewThe view of a
Note
in a
Diagram
, rendered as a
Text
box (100 × 50 by default).NoteView, class AnchorViewThe 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(): 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 note: Notenote = const model: Packagemodel.Package.noteBuilder(): NoteBuilderCreates a builder for a
Note
contained in this package.noteBuilder().NoteBuilder.text(value: string, language?: string): NoteBuilderAdds the text of the note in the given language.text('Members are always persons.').NoteBuilder.build(): NoteBuilds 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`build();
const const anchor: Anchoranchor = const note: Notenote.Note.anchorBuilder(): AnchorBuilderCreates a builder for an
Anchor
that attaches this note to a
model element.anchorBuilder().AnchorBuilder.annotates(element: ModelElement): AnchorBuilderSets the
ModelElement
annotated by the note connected by the
anchor.annotates(const person: Classperson).AnchorBuilder.build(): AnchorBuilds 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()`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 personView: ClassViewpersonView = const diagram: Diagramdiagram.Diagram.addClass(clazz: Class): ClassViewCreates 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): NoteViewThe 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>): voidAdds 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>): AnchorViewThe 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>): voidAdds 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[]): 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 anchorView: AnchorViewanchorView.AnchorView.noteView: NoteViewThe view of the note at the source end of the anchor.noteView === const noteView: NoteViewnoteView); // 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 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… factoriesaddView 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 itsrectanglelike a class view.- Notes and anchors have no factory: construct
new NoteView(note)/new AnchorView(anchor, noteView, elementView)and register them withdiagram.addView(...). - A
NoteViewcarries atextshape; anAnchorViewlinks anoteViewto anelementView.
Next: a complete diagram →.