@peter.prib/renderengine 0.2.1 → 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/REFERENCE.md +7 -0
- package/dist/renderengine-workspace.umd.js +2455 -2397
- package/dist/renderengine.umd.js +2455 -2397
- package/package.json +1 -1
- package/src/BaseRenderer.js +11 -0
- package/src/CanvasRenderer.js +7 -0
- package/src/SVGRenderer.js +16 -0
- package/src/index.js +2659 -2635
package/package.json
CHANGED
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.
|