@peter.prib/renderengine 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +215 -213
  2. package/REFERENCE.md +99 -7
  3. package/dist/renderengine-workspace.umd.js +13168 -11966
  4. package/dist/renderengine.umd.js +7439 -6472
  5. package/examples/data-model.html +324 -0
  6. package/package.json +70 -68
  7. package/src/charting/CheckboxTreeSelector.js +373 -304
  8. package/src/charting/DiagramEditor.js +3372 -3330
  9. package/src/charting/DiagramTypeRegistry.js +365 -326
  10. package/src/charting/Palette.js +119 -119
  11. package/src/charting/TemplateCatalog.js +61 -59
  12. package/src/charting/archimate/ArchimateCanvasEditor.js +825 -815
  13. package/src/charting/archimate/ArchimateElementTemplate.js +208 -195
  14. package/src/charting/datamodel/DataModel.js +299 -0
  15. package/src/charting/datamodel/DataModelContext.js +108 -0
  16. package/src/charting/datamodel/DataModelPerspective.js +84 -0
  17. package/src/charting/datamodel/LevelMapping.js +38 -0
  18. package/src/charting/datamodel/LevelSchema.js +41 -0
  19. package/src/charting/datamodel/index.js +5 -0
  20. package/src/charting/diagrams/DataModelDiagram.js +160 -86
  21. package/src/charting/diagrams/DataModelRelationshipStrategy.js +86 -38
  22. package/src/charting/diagrams/nesting.js +31 -0
  23. package/src/charting/modelTree/ModelTree.js +202 -164
  24. package/src/charting/modelTree/ModelTreePanel.js +36 -3
  25. package/src/charting/modelTree/TreeViewMode.js +131 -110
  26. package/src/charting/modelTree/modes/FlatTreeMode.js +32 -46
  27. package/src/charting/modelTree/modes/LayerGroupedTreeMode.js +47 -62
  28. package/src/charting/modelTree/modes/TypeGroupedTreeMode.js +46 -60
  29. package/src/datamodel.js +132 -122
  30. package/src/diagramCatalog.js +35 -30
  31. package/src/index.js +6 -1
  32. package/src/workspace/index.js +1 -0
  33. package/src/workspace/parts/ArchimateCanvasPart.js +5 -2
  34. package/src/workspace/parts/ChartPart.js +6 -1
  35. package/src/workspace/parts/DataModelPart.js +234 -0
@@ -1,195 +1,208 @@
1
- import { TextStyle, TEXT_STYLE_KEYS } from '../TextStyle.js';
2
- import { GlyphTemplate } from '../templates/GlyphTemplate.js';
3
- import { Glyph } from '../glyphs/Glyph.js';
4
- import { glyphFor } from '../glyphs/index.js';
5
- import { ArchimateDiagram } from '../diagrams/ArchimateDiagram.js';
6
- import { LabelHelper } from '../diagrams/LabelHelper.js';
7
-
8
- /** Paint a view can set on one occurrence: template property → appearance key (same names). */
9
- const APPEARANCE = ['fillColor', 'fillOpacity', 'strokeColor', 'strokeWidth', 'textColor', ...TEXT_STYLE_KEYS];
10
-
11
- /**
12
- * ArchimateElementTemplate — one element (or note, or image) on an ArchiMate
13
- * view, as an editor template. It keeps no copy of its own: position, size,
14
- * stacking and paint are read from and written to its ElementInstance, and
15
- * what it looks like comes from the model element through the same
16
- * enrichment the graph engine uses (ArchimateDiagram.buildNode: layer colour,
17
- * corner style, notation shape, type badge, label position). So every editor
18
- * command that moves, resizes, restacks or repaints a template edits the view
19
- * itself, and its undo does too.
20
- *
21
- * The shape is the node's glyph: a box (sharp, rounded or chamfered by
22
- * aspect) with the type's glyph as a corner badge, or the full notation shape
23
- * when distinct shapes are on; notes and images draw their own glyph.
24
- */
25
- export class ArchimateElementTemplate extends GlyphTemplate {
26
- /** ArchiMate notation is not rotated. */
27
- static rotatable = false;
28
-
29
- /** The format painter copies its appearance (what the view's instance holds). */
30
- static formatKeys = Object.freeze([...APPEARANCE]);
31
-
32
- /**
33
- * @param {ElementInstance} instance - What this template shows, and where
34
- * @param {ArchimateModel} model
35
- * @param {Object} [options]
36
- * @param {Object} [options.nodeOptions] - ArchimateDiagram.buildNode options
37
- * (archimateVersion, useDistinctShapes, layerColors, elementWidth, ...)
38
- */
39
- constructor(instance, model, { nodeOptions = {} } = {}) {
40
- super(instance.id, undefined, {});
41
- this.instance = instance;
42
- this.model = model;
43
- this.nodeOptions = nodeOptions;
44
- }
45
-
46
- /** State lives on the instance and the model element, not here. @protected */
47
- _initState() {}
48
-
49
- /** The element as the ArchiMate notation draws it on this view. */
50
- get node() {
51
- const projected = this.instance.project(this.model) ?? { id: this.instance.id, name: this.instance.elementId };
52
- return ArchimateDiagram.buildNode(projected, this.nodeOptions);
53
- }
54
-
55
- get name() { return this.instance.getDisplayName(this.model); }
56
- /** Renaming one occurrence labels it on this view; the element's own name is left alone. */
57
- set name(value) {
58
- const own = this.instance.resolve(this.model)?.name;
59
- this.instance.labelOverride = value && value !== own ? value : null;
60
- }
61
-
62
- get x() { return this.instance.x; }
63
- set x(value) { this.instance.x = value; }
64
- get y() { return this.instance.y; }
65
- set y(value) { this.instance.y = value; }
66
- get zIndex() { return this.instance.zIndex; }
67
- set zIndex(value) { this.instance.zIndex = value ?? 0; }
68
- get visible() { return this.instance.visible; }
69
- set visible(value) { this.instance.visible = value !== false; }
70
-
71
- get width() { return this.node.width; }
72
- set width(value) { this._setSize('width', value); }
73
- get height() { return this.node.height; }
74
- set height(value) { this._setSize('height', value); }
75
-
76
- get fillColor() { return this.node.color; }
77
- set fillColor(value) { this._setAppearance('fillColor', value); }
78
- get fillOpacity() { return this.instance.appearance.fillOpacity ?? 1; }
79
- set fillOpacity(value) { this._setAppearance('fillOpacity', value); }
80
- get strokeColor() { return this.node.strokeColor; }
81
- set strokeColor(value) { this._setAppearance('strokeColor', value); }
82
- get strokeWidth() { return this.node.strokeWidth; }
83
- set strokeWidth(value) { this._setAppearance('strokeWidth', value); }
84
- get textColor() { return this.instance.appearance.textColor ?? '#222'; }
85
- set textColor(value) { this._setAppearance('textColor', value); }
86
- get fontFamily() { return this.instance.appearance.fontFamily; }
87
- set fontFamily(value) { this._setAppearance('fontFamily', value); }
88
- get fontSize() { return this.instance.appearance.fontSize; }
89
- set fontSize(value) { this._setAppearance('fontSize', value); }
90
- get fontWeight() { return this.instance.appearance.fontWeight; }
91
- set fontWeight(value) { this._setAppearance('fontWeight', value); }
92
- get fontStyle() { return this.instance.appearance.fontStyle; }
93
- set fontStyle(value) { this._setAppearance('fontStyle', value); }
94
- get textDecoration() { return this.instance.appearance.textDecoration; }
95
- set textDecoration(value) { this._setAppearance('textDecoration', value); }
96
- get textAlign() { return this.instance.appearance.textAlign; }
97
- set textAlign(value) { this._setAppearance('textAlign', value); }
98
- get textPosition() { return this.instance.appearance.textPosition; }
99
- set textPosition(value) { this._setAppearance('textPosition', value); }
100
-
101
- /**
102
- * What this occurrence sets itself for a property (undefined when it shows
103
- * the element's own), for commands that must undo to "unset".
104
- */
105
- ownProperty(key) {
106
- if (APPEARANCE.includes(key)) return this.instance.appearance[key];
107
- if (key === 'width' || key === 'height') return this.instance.size[key];
108
- if (key === 'name') return this.instance.labelOverride ?? undefined;
109
- return this[key];
110
- }
111
-
112
- /** undefined puts the occurrence back on the element's own value. @private */
113
- _setSize(key, value) {
114
- if (value === undefined) delete this.instance.size[key];
115
- else this.instance.size = { ...this.instance.size, [key]: value };
116
- }
117
-
118
- /** @private */
119
- _setAppearance(key, value) {
120
- if (!APPEARANCE.includes(key)) throw new TypeError(`Not an appearance property: ${key}`);
121
- if (value === undefined) delete this.instance.appearance[key];
122
- else this.instance.appearance = { ...this.instance.appearance, [key]: value };
123
- }
124
-
125
- glyph() {
126
- return glyphFor(this.node.shape);
127
- }
128
-
129
- glyphContext() {
130
- const node = this.node;
131
- return Glyph.context({
132
- R: Math.max(node.width, node.height) / 2,
133
- size: { w: node.width, h: node.height },
134
- color: node.color,
135
- cornerStyle: node.cornerStyle,
136
- strokeColor: node.strokeColor,
137
- strokeWidth: node.strokeWidth,
138
- icon: node.icon,
139
- iconUrl: node.iconUrl,
140
- ownFill: this.instance.appearance.fillColor ?? null,
141
- });
142
- }
143
-
144
- /**
145
- * The type badge in the top-right corner: its glyph, or an icon (text or
146
- * image). As in the graph engine, a notation shape gets no glyph badge
147
- * (buildNode leaves iconShape unset) but keeps an icon the element sets.
148
- */
149
- decorations(ctx) {
150
- const node = this.node;
151
- const { w, h } = ctx;
152
- if (node.iconShape) {
153
- const badge = Math.max(10, Math.round(Math.min(w, h) * 0.3));
154
- const inset = badge / 2 + 3;
155
- const parts = glyphFor(node.iconShape).parts(Glyph.context({
156
- R: badge / 2, size: { w: badge, h: badge * 0.78 }, color: 'none', strokeColor: node.strokeColor || '#000000', strokeWidth: 1,
157
- }));
158
- return [Glyph.group([parts], { transform: `translate(${w / 2 - inset},${-h / 2 + inset})`, 'pointer-events': 'none' })];
159
- }
160
- if (node.icon || node.iconUrl) {
161
- const size = Math.max(12, Math.round(Math.min(w, h) * 0.3));
162
- const bx = w / 2 - (size / 2 + 2), by = -h / 2 + (size / 2 + 2);
163
- return [node.iconUrl
164
- ? Glyph.image(node.iconUrl, bx - size / 2, by - size / 2, size, size, { 'pointer-events': 'none' })
165
- : Glyph.text(node.icon, bx, by, { fill: node.strokeColor || '#fff', textAnchor: 'middle', verticalAlign: 'middle', fontSize: `${size}px`, 'pointer-events': 'none' })];
166
- }
167
- return [];
168
- }
169
-
170
- /** The name inside the box (wrapped, top-left) or below a notation shape; images have none. */
171
- _renderLabel(g, doc) {
172
- const node = this.node;
173
- if (node.shape === 'image') return;
174
- const text = (x, y, content, attrs) => {
175
- const t = doc.createElementNS('http://www.w3.org/2000/svg', 'text');
176
- for (const [k, v] of Object.entries({ x, y, 'pointer-events': 'none', 'font-family': 'sans-serif', ...attrs })) t.setAttribute(k, String(v));
177
- t.textContent = content;
178
- g.appendChild(t);
179
- };
180
- const { width: w, height: h } = node;
181
- const inside = (node.labelPosition || (node.shape === 'note' ? 'inside' : 'below')) === 'inside';
182
- if (inside) {
183
- const font = TextStyle.svgAttributes(this.textStyle, { defaultPixels: 10 });
184
- const PAD = 6, FONT_SIZE = font['font-size'], LINE_HEIGHT = Math.round(FONT_SIZE * 1.2);
185
- const lines = LabelHelper.wrapLabelLines(this.name, w - PAD * 2, FONT_SIZE, h - PAD * 2, LINE_HEIGHT);
186
- // Top left unless the occurrence says otherwise, as in Archi.
187
- const at = TextStyle.block(this.textStyle, { left: this.x - w / 2, right: this.x + w / 2, top: this.y - h / 2, bottom: this.y + h / 2 },
188
- lines.length, { pixels: FONT_SIZE, lineHeight: LINE_HEIGHT, pad: PAD });
189
- lines.forEach((line, i) => text(at.x, at.baseline + i * LINE_HEIGHT, line,
190
- { ...font, fill: this.textColor, 'font-size': `${FONT_SIZE}px`, 'text-anchor': at.textAnchor }));
191
- } else {
192
- text(this.x, this.y + h / 2 + 9, this.name, { fill: '#333', 'font-size': '9px', 'text-anchor': 'middle' });
193
- }
194
- }
195
- }
1
+ import { TextStyle, TEXT_STYLE_KEYS } from '../TextStyle.js';
2
+ import { GlyphTemplate } from '../templates/GlyphTemplate.js';
3
+ import { Glyph } from '../glyphs/Glyph.js';
4
+ import { glyphFor } from '../glyphs/index.js';
5
+ import { ArchimateDiagram } from '../diagrams/ArchimateDiagram.js';
6
+ import { LabelHelper } from '../diagrams/LabelHelper.js';
7
+
8
+ /** Paint a view can set on one occurrence: template property → appearance key (same names). */
9
+ const APPEARANCE = ['fillColor', 'fillOpacity', 'strokeColor', 'strokeWidth', 'textColor', ...TEXT_STYLE_KEYS];
10
+
11
+ /**
12
+ * ArchimateElementTemplate — one element (or note, or image) on an ArchiMate
13
+ * view, as an editor template. It keeps no copy of its own: position, size,
14
+ * stacking and paint are read from and written to its ElementInstance, and
15
+ * what it looks like comes from the model element through the same
16
+ * enrichment the graph engine uses (ArchimateDiagram.buildNode: layer colour,
17
+ * corner style, notation shape, type badge, label position). So every editor
18
+ * command that moves, resizes, restacks or repaints a template edits the view
19
+ * itself, and its undo does too.
20
+ *
21
+ * The shape is the node's glyph: a box (sharp, rounded or chamfered by
22
+ * aspect) with the type's glyph as a corner badge, or the full notation shape
23
+ * when distinct shapes are on; notes and images draw their own glyph.
24
+ */
25
+ export class ArchimateElementTemplate extends GlyphTemplate {
26
+ /** ArchiMate notation is not rotated. */
27
+ static rotatable = false;
28
+
29
+ /** The format painter copies its appearance (what the view's instance holds). */
30
+ static formatKeys = Object.freeze([...APPEARANCE]);
31
+
32
+ /**
33
+ * @param {ElementInstance} instance - What this template shows, and where
34
+ * @param {ArchimateModel} model
35
+ * @param {Object} [options]
36
+ * @param {Object} [options.nodeOptions] - ArchimateDiagram.buildNode options
37
+ * (archimateVersion, useDistinctShapes, layerColors, elementWidth, ...)
38
+ */
39
+ constructor(instance, model, { nodeOptions = {} } = {}) {
40
+ super(instance.id, undefined, {});
41
+ this.instance = instance;
42
+ this.model = model;
43
+ this.nodeOptions = nodeOptions;
44
+ }
45
+
46
+ /** State lives on the instance and the model element, not here. @protected */
47
+ _initState() {}
48
+
49
+ /** The element as the ArchiMate notation draws it on this view. */
50
+ get node() {
51
+ const projected = this.instance.project(this.model) ?? { id: this.instance.id, name: this.instance.elementId };
52
+ return ArchimateDiagram.buildNode(projected, this.nodeOptions);
53
+ }
54
+
55
+ get name() { return this.instance.getDisplayName(this.model); }
56
+ /** Renaming one occurrence labels it on this view; the element's own name is left alone. */
57
+ set name(value) {
58
+ const own = this.instance.resolve(this.model)?.name;
59
+ this.instance.labelOverride = value && value !== own ? value : null;
60
+ }
61
+
62
+ get x() { return this.instance.x; }
63
+ set x(value) { this.instance.x = value; }
64
+ get y() { return this.instance.y; }
65
+ set y(value) { this.instance.y = value; }
66
+ get zIndex() { return this.instance.zIndex; }
67
+ set zIndex(value) { this.instance.zIndex = value ?? 0; }
68
+ get visible() { return this.instance.visible; }
69
+ set visible(value) { this.instance.visible = value !== false; }
70
+
71
+ get width() { return this.node.width; }
72
+ set width(value) { this._setSize('width', value); }
73
+ get height() { return this.node.height; }
74
+ set height(value) { this._setSize('height', value); }
75
+
76
+ get fillColor() { return this.node.color; }
77
+ set fillColor(value) { this._setAppearance('fillColor', value); }
78
+ get fillOpacity() { return this.instance.appearance.fillOpacity ?? 1; }
79
+ set fillOpacity(value) { this._setAppearance('fillOpacity', value); }
80
+ get strokeColor() { return this.node.strokeColor; }
81
+ set strokeColor(value) { this._setAppearance('strokeColor', value); }
82
+ get strokeWidth() { return this.node.strokeWidth; }
83
+ set strokeWidth(value) { this._setAppearance('strokeWidth', value); }
84
+ get textColor() { return this.instance.appearance.textColor ?? '#222'; }
85
+ set textColor(value) { this._setAppearance('textColor', value); }
86
+ get fontFamily() { return this.instance.appearance.fontFamily; }
87
+ set fontFamily(value) { this._setAppearance('fontFamily', value); }
88
+ get fontSize() { return this.instance.appearance.fontSize; }
89
+ set fontSize(value) { this._setAppearance('fontSize', value); }
90
+ get fontWeight() { return this.instance.appearance.fontWeight; }
91
+ set fontWeight(value) { this._setAppearance('fontWeight', value); }
92
+ get fontStyle() { return this.instance.appearance.fontStyle; }
93
+ set fontStyle(value) { this._setAppearance('fontStyle', value); }
94
+ get textDecoration() { return this.instance.appearance.textDecoration; }
95
+ set textDecoration(value) { this._setAppearance('textDecoration', value); }
96
+ get textAlign() { return this.instance.appearance.textAlign; }
97
+ set textAlign(value) { this._setAppearance('textAlign', value); }
98
+ get textPosition() { return this.instance.appearance.textPosition; }
99
+ set textPosition(value) { this._setAppearance('textPosition', value); }
100
+
101
+ /**
102
+ * What this occurrence sets itself for a property (undefined when it shows
103
+ * the element's own), for commands that must undo to "unset".
104
+ */
105
+ ownProperty(key) {
106
+ if (APPEARANCE.includes(key)) return this.instance.appearance[key];
107
+ if (key === 'width' || key === 'height') return this.instance.size[key];
108
+ if (key === 'name') return this.instance.labelOverride ?? undefined;
109
+ return this[key];
110
+ }
111
+
112
+ /** undefined puts the occurrence back on the element's own value. @private */
113
+ _setSize(key, value) {
114
+ if (value === undefined) delete this.instance.size[key];
115
+ else this.instance.size = { ...this.instance.size, [key]: value };
116
+ }
117
+
118
+ /** @private */
119
+ _setAppearance(key, value) {
120
+ if (!APPEARANCE.includes(key)) throw new TypeError(`Not an appearance property: ${key}`);
121
+ if (value === undefined) delete this.instance.appearance[key];
122
+ else this.instance.appearance = { ...this.instance.appearance, [key]: value };
123
+ }
124
+
125
+ glyph() {
126
+ return glyphFor(this.node.shape);
127
+ }
128
+
129
+ glyphContext() {
130
+ const node = this.node;
131
+ return Glyph.context({
132
+ R: Math.max(node.width, node.height) / 2,
133
+ size: { w: node.width, h: node.height },
134
+ color: node.color,
135
+ cornerStyle: node.cornerStyle,
136
+ strokeColor: node.strokeColor,
137
+ strokeWidth: node.strokeWidth,
138
+ icon: node.icon,
139
+ iconUrl: node.iconUrl,
140
+ ownFill: this.instance.appearance.fillColor ?? null,
141
+ });
142
+ }
143
+
144
+ /**
145
+ * The badge's size: the same whatever the box's size (as Archi draws it), so
146
+ * resizing a box, or a parent growing to hold what is dropped in it, leaves
147
+ * it as it was; only a box too small for it gets a smaller one.
148
+ */
149
+ static badgeSize(w, h) {
150
+ return Math.max(8, Math.min(ArchimateElementTemplate.BADGE_SIZE, Math.round(Math.min(w, h) * 0.4)));
151
+ }
152
+
153
+ /**
154
+ * The type badge in the top-right corner: its glyph, or an icon (text or
155
+ * image), a fixed size (badgeSize). As in the graph engine, a notation shape
156
+ * gets no glyph badge (buildNode leaves iconShape unset) but keeps an icon the element sets.
157
+ */
158
+ decorations(ctx) {
159
+ const node = this.node;
160
+ const { w, h } = ctx;
161
+ const fixed = ArchimateElementTemplate.badgeSize(w, h);
162
+ if (node.iconShape) {
163
+ const badge = fixed;
164
+ const inset = badge / 2 + 3;
165
+ const parts = glyphFor(node.iconShape).parts(Glyph.context({
166
+ R: badge / 2, size: { w: badge, h: badge * 0.78 }, color: 'none', strokeColor: node.strokeColor || '#000000', strokeWidth: 1,
167
+ }));
168
+ return [Glyph.group([parts], { transform: `translate(${w / 2 - inset},${-h / 2 + inset})`, 'pointer-events': 'none' })];
169
+ }
170
+ if (node.icon || node.iconUrl) {
171
+ const size = fixed;
172
+ const bx = w / 2 - (size / 2 + 2), by = -h / 2 + (size / 2 + 2);
173
+ return [node.iconUrl
174
+ ? Glyph.image(node.iconUrl, bx - size / 2, by - size / 2, size, size, { 'pointer-events': 'none' })
175
+ : Glyph.text(node.icon, bx, by, { fill: node.strokeColor || '#fff', textAnchor: 'middle', verticalAlign: 'middle', fontSize: `${size}px`, 'pointer-events': 'none' })];
176
+ }
177
+ return [];
178
+ }
179
+
180
+ /** The name inside the box (wrapped, top-left) or below a notation shape; images have none. */
181
+ _renderLabel(g, doc) {
182
+ const node = this.node;
183
+ if (node.shape === 'image') return;
184
+ const text = (x, y, content, attrs) => {
185
+ const t = doc.createElementNS('http://www.w3.org/2000/svg', 'text');
186
+ for (const [k, v] of Object.entries({ x, y, 'pointer-events': 'none', 'font-family': 'sans-serif', ...attrs })) t.setAttribute(k, String(v));
187
+ t.textContent = content;
188
+ g.appendChild(t);
189
+ };
190
+ const { width: w, height: h } = node;
191
+ const inside = (node.labelPosition || (node.shape === 'note' ? 'inside' : 'below')) === 'inside';
192
+ if (inside) {
193
+ const font = TextStyle.svgAttributes(this.textStyle, { defaultPixels: 10 });
194
+ const PAD = 6, FONT_SIZE = font['font-size'], LINE_HEIGHT = Math.round(FONT_SIZE * 1.2);
195
+ const lines = LabelHelper.wrapLabelLines(this.name, w - PAD * 2, FONT_SIZE, h - PAD * 2, LINE_HEIGHT);
196
+ // Top left unless the occurrence says otherwise, as in Archi.
197
+ const at = TextStyle.block(this.textStyle, { left: this.x - w / 2, right: this.x + w / 2, top: this.y - h / 2, bottom: this.y + h / 2 },
198
+ lines.length, { pixels: FONT_SIZE, lineHeight: LINE_HEIGHT, pad: PAD });
199
+ lines.forEach((line, i) => text(at.x, at.baseline + i * LINE_HEIGHT, line,
200
+ { ...font, fill: this.textColor, 'font-size': `${FONT_SIZE}px`, 'text-anchor': at.textAnchor }));
201
+ } else {
202
+ text(this.x, this.y + h / 2 + 9, this.name, { fill: '#333', 'font-size': '9px', 'text-anchor': 'middle' });
203
+ }
204
+ }
205
+ }
206
+
207
+ /** The corner badge's size in pixels (badgeSize). */
208
+ ArchimateElementTemplate.BADGE_SIZE = 16;