@peter.prib/renderengine 0.2.0 → 0.2.2
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.
- package/README.md +9 -0
- package/REFERENCE.md +7 -0
- package/dist/renderengine-workspace.umd.js +2455 -2403
- package/dist/renderengine.umd.js +2455 -2403
- package/examples/diagram-editor.html +9 -4
- package/package.json +3 -2
- package/src/BaseRenderer.js +11 -0
- package/src/CanvasRenderer.js +7 -0
- package/src/SVGRenderer.js +16 -0
- package/src/charting/templates/Template.js +0 -6
- package/src/index.js +2659 -2635
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
<script src="../dist/renderengine.umd.js"></script>
|
|
18
18
|
<script src="../dist/renderengine-workspace.umd.js"></script>
|
|
19
19
|
<script>
|
|
20
|
-
const { RectangleTemplate, StadiumTemplate, DiamondTemplate } = window.RenderEngine;
|
|
20
|
+
const { RectangleTemplate, StadiumTemplate, DiamondTemplate, ParallelogramTemplate, Edge } = window.RenderEngine;
|
|
21
21
|
const { el, registerBuiltinParts, DiagramEditorPart } = window.RenderEngineWorkspace;
|
|
22
22
|
|
|
23
23
|
const ws = document.body.appendChild(el({
|
|
@@ -35,16 +35,21 @@
|
|
|
35
35
|
ws.registerPerspective('Diagrams', { type: 'part', partId: 'models' });
|
|
36
36
|
ws.activatePerspective('Diagrams');
|
|
37
37
|
|
|
38
|
-
// A small flowchart to start from.
|
|
38
|
+
// A small flowchart to start from: its shapes, and the lines between them.
|
|
39
39
|
const editorPart = ws.getPart('editor');
|
|
40
|
-
const { templates } = editorPart.model.currentView;
|
|
40
|
+
const { templates, edges } = editorPart.model.currentView;
|
|
41
41
|
for (const t of [
|
|
42
42
|
new StadiumTemplate('start', 'Order received', { x: 160, y: 80, fillColor: '#dcfce7' }),
|
|
43
43
|
new RectangleTemplate('check', 'Check stock', { x: 160, y: 200, fillColor: '#dbeafe' }),
|
|
44
44
|
new DiamondTemplate('decide', 'In stock?', { x: 160, y: 330, fillColor: '#fef9c3' }),
|
|
45
45
|
new RectangleTemplate('ship', 'Ship order', { x: 400, y: 330, fillColor: '#dbeafe' }),
|
|
46
|
-
new
|
|
46
|
+
new ParallelogramTemplate('reorder', 'Reorder stock', { x: 160, y: 470, fillColor: '#ede9fe' }),
|
|
47
|
+
new StadiumTemplate('end', 'Done', { x: 400, y: 470, fillColor: '#dcfce7' }),
|
|
47
48
|
]) templates.set(t.id, t);
|
|
49
|
+
for (const [id, from, to, label = ''] of [
|
|
50
|
+
['e1', 'start', 'check'], ['e2', 'check', 'decide'], ['e3', 'decide', 'ship', 'yes'],
|
|
51
|
+
['e4', 'decide', 'reorder', 'no'], ['e5', 'ship', 'end'], ['e6', 'reorder', 'ship'],
|
|
52
|
+
]) edges.set(id, new Edge(id, from, to, { endMarker: 'arrow', label }));
|
|
48
53
|
editorPart.editor.render();
|
|
49
54
|
</script>
|
|
50
55
|
</body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peter.prib/renderengine",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "ArchiMate modeller, diagram editor and chart library for the browser, with no runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"diagram": "node scripts/open.mjs examples/diagram-editor.html",
|
|
29
29
|
"test": "node --test --test-timeout=10000 ./test/*.js ./test/charting/*.js ./test/charting/charts/*.js ./test/charting/diagrams/*.js ./test/charting/shapes/*.js",
|
|
30
30
|
"build": "rollup -c",
|
|
31
|
-
"prepublishOnly": "npm test && npm run build"
|
|
31
|
+
"prepublishOnly": "npm test && npm run build",
|
|
32
|
+
"screenshots": "node scripts/screenshots/screenshots.mjs"
|
|
32
33
|
},
|
|
33
34
|
"keywords": [
|
|
34
35
|
"archimate",
|
package/src/BaseRenderer.js
CHANGED
|
@@ -13,6 +13,17 @@ export class BaseRenderer {
|
|
|
13
13
|
this.width = width;
|
|
14
14
|
this.height = height;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Take a new drawing size — the container's, once it has one. A renderer
|
|
18
|
+
* is sized from its container when it is created, and a container that is
|
|
19
|
+
* hidden then (a pane in a tab not yet shown) measures 0×0; without this
|
|
20
|
+
* the drawing stays 0×0 when the pane is shown. Subclasses resize their
|
|
21
|
+
* surface and call this.
|
|
22
|
+
*/
|
|
23
|
+
resize(width, height) {
|
|
24
|
+
this.width = width;
|
|
25
|
+
this.height = height;
|
|
26
|
+
}
|
|
16
27
|
clear() { throw new Error("Method 'clear()' must be implemented."); }
|
|
17
28
|
rect(x, y, width, height, fill, stroke) { throw new Error("Method 'rect()' must be implemented."); }
|
|
18
29
|
circle(cx, cy, r, fill, stroke) { throw new Error("Method 'circle()' must be implemented."); }
|
package/src/CanvasRenderer.js
CHANGED
|
@@ -22,6 +22,13 @@ export class CanvasRenderer extends BaseRenderer {
|
|
|
22
22
|
this.ctx = this.canvas.getContext('2d');
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/** Resize the canvas. Setting a canvas's size clears it, so redraw after. */
|
|
26
|
+
resize(width, height) {
|
|
27
|
+
super.resize(width, height);
|
|
28
|
+
this.canvas.width = width;
|
|
29
|
+
this.canvas.height = height;
|
|
30
|
+
}
|
|
31
|
+
|
|
25
32
|
clear() {
|
|
26
33
|
this.ctx.clearRect(0, 0, this.width, this.height);
|
|
27
34
|
this._shapes = [];
|
package/src/SVGRenderer.js
CHANGED
|
@@ -167,6 +167,22 @@ export class SVGRenderer extends BaseRenderer {
|
|
|
167
167
|
this.container.appendChild(this.svg);
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Resize the <svg>. Its viewBox follows only while it is still the size it
|
|
172
|
+
* was created with: a diagram sets its own viewBox to its content, and that
|
|
173
|
+
* must survive, so the diagram then scales to the new box instead of
|
|
174
|
+
* being cropped to it.
|
|
175
|
+
*/
|
|
176
|
+
resize(width, height) {
|
|
177
|
+
const defaultViewBox = `0 0 ${this.width} ${this.height}`;
|
|
178
|
+
super.resize(width, height);
|
|
179
|
+
this.svg.setAttribute('width', width);
|
|
180
|
+
this.svg.setAttribute('height', height);
|
|
181
|
+
if (this.svg.getAttribute('viewBox') === defaultViewBox) {
|
|
182
|
+
this.svg.setAttribute('viewBox', `0 0 ${width} ${height}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
170
186
|
clear() {
|
|
171
187
|
this._elMap.clear();
|
|
172
188
|
// Keep <defs> and <style> elements; remove everything else.
|
|
@@ -170,20 +170,14 @@ export class Template {
|
|
|
170
170
|
};
|
|
171
171
|
const style = this.textStyle;
|
|
172
172
|
const font = TextStyle.svgAttributes(style, { defaultPixels: 12 });
|
|
173
|
-
const zLine = `Z:${this.zIndex || 0}`;
|
|
174
173
|
if (TextStyle.placesText(style)) {
|
|
175
174
|
// Placed in the shape's box by its alignment and position (centred, middle where unset).
|
|
176
175
|
const at = TextStyle.block(style, this, 1, { pixels: font['font-size'], defaults: { textAlign: 'center', textPosition: 'middle' } });
|
|
177
176
|
const placed = { 'text-anchor': at.textAnchor, 'dominant-baseline': 'auto' };
|
|
178
177
|
if (this.name) text({ x: at.x, y: at.baseline, ...font, ...placed, fill: this.textColor }, this.name);
|
|
179
|
-
// Under the name, or over it when the name is at the bottom (so it stays in the shape).
|
|
180
|
-
const zY = style.textPosition === 'bottom' ? at.baseline - font['font-size'] - 2 : at.baseline + 12;
|
|
181
|
-
text({ x: at.x, y: zY, 'font-size': 10, fill: '#666', ...placed }, zLine);
|
|
182
178
|
return;
|
|
183
179
|
}
|
|
184
180
|
if (this.name) text({ x, y, ...font, fill: this.textColor }, this.name);
|
|
185
|
-
// Below the name, however large it is set.
|
|
186
|
-
text({ x, y: y + Math.max(16, font['font-size'] / 2 + 10), 'font-size': 10, fill: '#666' }, zLine);
|
|
187
181
|
}
|
|
188
182
|
|
|
189
183
|
serialize() {
|