plotboilerplate 1.20.1 → 1.21.0
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 +17 -1
- package/dist/index.esm.js +2065 -1397
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +1265 -584
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +2 -1
- package/src/cjs/BezierPath.d.ts +27 -49
- package/src/cjs/BezierPath.js +69 -237
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Bounds.d.ts +14 -1
- package/src/cjs/Bounds.js +21 -1
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +70 -1
- package/src/cjs/CubicBezierCurve.js +130 -12
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Line.d.ts +2 -1
- package/src/cjs/Line.js +1 -0
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/PBText.d.ts +2 -1
- package/src/cjs/PBText.js +10 -9
- package/src/cjs/PBText.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +10 -13
- package/src/cjs/PlotBoilerplate.js +136 -47
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +35 -1
- package/src/cjs/Polygon.js +87 -1
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.js +1 -0
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/VEllipse.js +1 -1
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/Vector.d.ts +4 -4
- package/src/cjs/Vector.js +2 -2
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +2 -1
- package/src/cjs/VertTuple.js +4 -3
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +14 -3
- package/src/cjs/Vertex.js +18 -3
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/draw.d.ts +159 -79
- package/src/cjs/draw.js +311 -139
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +93 -55
- package/src/cjs/drawgl.js +90 -34
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +233 -58
- package/src/cjs/drawutilssvg.js +384 -95
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +161 -82
- package/src/cjs/interfaces/DrawLib.js +7 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +46 -32
- package/src/cjs/interfaces/core.js +2 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/creategui.js +16 -10
- package/src/cjs/utils/datastructures/Color.d.ts +3 -1
- package/src/cjs/utils/datastructures/Color.js +12 -1
- package/src/cjs/utils/datastructures/Color.js.map +1 -1
- package/src/cjs/utils/detectDarkMode.d.ts +10 -0
- package/src/cjs/utils/detectDarkMode.js +32 -0
- package/src/cjs/utils/detectDarkMode.js.map +1 -0
- package/src/cjs/utils/module.js +4 -2
- package/src/esm/BezierPath.d.ts +27 -49
- package/src/esm/BezierPath.js +69 -237
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Bounds.d.ts +14 -1
- package/src/esm/Bounds.js +19 -1
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +70 -1
- package/src/esm/CubicBezierCurve.js +130 -12
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Line.d.ts +2 -1
- package/src/esm/Line.js +1 -0
- package/src/esm/Line.js.map +1 -1
- package/src/esm/PBText.d.ts +2 -1
- package/src/esm/PBText.js +10 -9
- package/src/esm/PBText.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +10 -13
- package/src/esm/PlotBoilerplate.js +136 -48
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +35 -1
- package/src/esm/Polygon.js +85 -1
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.js +1 -0
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/VEllipse.js +1 -1
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/Vector.d.ts +4 -4
- package/src/esm/Vector.js +2 -2
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.d.ts +2 -1
- package/src/esm/VertTuple.js +4 -3
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +14 -3
- package/src/esm/Vertex.js +18 -3
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/draw.d.ts +159 -79
- package/src/esm/draw.js +307 -137
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +93 -55
- package/src/esm/drawgl.js +90 -34
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +233 -58
- package/src/esm/drawutilssvg.js +379 -95
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +161 -82
- package/src/esm/interfaces/DrawLib.js +7 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +46 -32
- package/src/esm/interfaces/core.js +2 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/datastructures/Color.d.ts +3 -1
- package/src/esm/utils/datastructures/Color.js +12 -1
- package/src/esm/utils/datastructures/Color.js.map +1 -1
- package/src/esm/utils/detectDarkMode.d.ts +10 -0
- package/src/esm/utils/detectDarkMode.js +28 -0
- package/src/esm/utils/detectDarkMode.js.map +1 -0
- package/src/ts/BezierPath.ts +74 -244
- package/src/ts/Bounds.ts +25 -1
- package/src/ts/CubicBezierCurve.ts +139 -12
- package/src/ts/Line.ts +2 -1
- package/src/ts/PBText.ts +10 -9
- package/src/ts/PlotBoilerplate.ts +130 -50
- package/src/ts/Polygon.ts +91 -1
- package/src/ts/Triangle.ts +2 -1
- package/src/ts/VEllipse.ts +2 -2
- package/src/ts/Vector.ts +4 -4
- package/src/ts/VertTuple.ts +4 -3
- package/src/ts/Vertex.ts +20 -4
- package/src/ts/draw.ts +316 -119
- package/src/ts/drawgl.ts +141 -78
- package/src/ts/drawutilssvg.ts +562 -133
- package/src/ts/interfaces/DrawLib.ts +223 -86
- package/src/ts/interfaces/core.ts +47 -32
- package/src/ts/utils/datastructures/Color.ts +13 -1
- package/src/ts/utils/detectDarkMode.ts +30 -0
package/src/cjs/drawutilssvg.js
CHANGED
|
@@ -36,7 +36,17 @@
|
|
|
36
36
|
* @modified 2022-03-26 Added the `texturedPoly` function to draw textures polygons.
|
|
37
37
|
* @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
|
|
38
38
|
* @modified 2022-11-10 Tweaking some type issues.
|
|
39
|
-
* @
|
|
39
|
+
* @modified 2023-02-04 Fixed a typo in the CSS classname for cubic Bézier paths: cubicBezier (was cubierBezier).
|
|
40
|
+
* @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
|
|
41
|
+
* @modified 2023-09-29 Added initialization checks for null parameters.
|
|
42
|
+
* @modified 2023-09-29 Added a missing implementation to the `drawurilssvg.do(XYCoords,string)` function. Didn't draw anything.
|
|
43
|
+
* @modified 2023-09-29 Downgrading all `Vertex` param type to the more generic `XYCoords` type in these render functions: line, arrow, texturedPoly, cubicBezier, cubicBezierPath, handle, handleLine, dot, point, circle, circleArc, ellipse, grid, raster.
|
|
44
|
+
* @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
|
|
45
|
+
* @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
|
|
46
|
+
* @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
|
|
47
|
+
* @modified 2023-10-04 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
|
|
48
|
+
*
|
|
49
|
+
* @version 1.6.7
|
|
40
50
|
**/
|
|
41
51
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
52
|
exports.drawutilssvg = void 0;
|
|
@@ -44,6 +54,7 @@ var CircleSector_1 = require("./CircleSector");
|
|
|
44
54
|
var CubicBezierCurve_1 = require("./CubicBezierCurve");
|
|
45
55
|
var Vertex_1 = require("./Vertex");
|
|
46
56
|
var UIDGenerator_1 = require("./UIDGenerator");
|
|
57
|
+
var Vector_1 = require("./Vector");
|
|
47
58
|
var RAD_TO_DEG = 180 / Math.PI;
|
|
48
59
|
/**
|
|
49
60
|
* @classdesc A helper class for basic SVG drawing operations. This class should
|
|
@@ -74,11 +85,14 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
74
85
|
this.offset = new Vertex_1.Vertex(0, 0).set(offset);
|
|
75
86
|
this.scale = new Vertex_1.Vertex(1, 1).set(scale);
|
|
76
87
|
this.fillShapes = fillShapes;
|
|
77
|
-
this.isSecondary = isSecondary;
|
|
88
|
+
this.isSecondary = Boolean(isSecondary);
|
|
78
89
|
this.drawlibConfiguration = {};
|
|
79
90
|
this.cache = new Map();
|
|
80
91
|
this.setSize(canvasSize);
|
|
81
92
|
if (isSecondary) {
|
|
93
|
+
if (!gNode || !bufferGNode || !nodeDefs || !bufferNodeDefs) {
|
|
94
|
+
throw "Cannot create secondary svg draw lib with undefinde gNode|bufferGNode|nodeDefs|bufferNodeDefs.";
|
|
95
|
+
}
|
|
82
96
|
this.gNode = gNode;
|
|
83
97
|
this.bufferGNode = bufferGNode;
|
|
84
98
|
this.nodeDefs = nodeDefs;
|
|
@@ -104,6 +118,8 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
104
118
|
// Which default styles to add? -> All from the DrawConfig.
|
|
105
119
|
// Compare with DrawConfig interface
|
|
106
120
|
var keys = {
|
|
121
|
+
// "bezier": "CubicBezierCurve", // TODO: is this correct?
|
|
122
|
+
"bezierPath": "BezierPath",
|
|
107
123
|
"polygon": "Polygon",
|
|
108
124
|
"triangle": "Triangle",
|
|
109
125
|
"ellipse": "Ellipse",
|
|
@@ -169,6 +185,9 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
169
185
|
* @param {string} nodeName - The expected node name.
|
|
170
186
|
*/
|
|
171
187
|
drawutilssvg.prototype.findElement = function (key, nodeName) {
|
|
188
|
+
if (!key) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
172
191
|
var node = this.cache.get(key);
|
|
173
192
|
if (node && node.nodeName.toUpperCase() === nodeName.toUpperCase()) {
|
|
174
193
|
this.cache.delete(key);
|
|
@@ -214,6 +233,9 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
214
233
|
if (this.drawlibConfiguration.blendMode) {
|
|
215
234
|
node.style["mix-blend-mode"] = this.drawlibConfiguration.blendMode;
|
|
216
235
|
}
|
|
236
|
+
// if (this.lineDashEnabled && this.lineDash && this.lineDash.length > 0 && drawutilssvg.nodeSupportsLineDash(nodeName)) {
|
|
237
|
+
// node.setAttribute("stroke-dasharray", this.lineDash.join(" "));
|
|
238
|
+
// }
|
|
217
239
|
return node;
|
|
218
240
|
};
|
|
219
241
|
/**
|
|
@@ -236,23 +258,58 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
236
258
|
* @param {number=1} lineWidth - (optional) A line width to use for drawing (default is 1).
|
|
237
259
|
* @return {SVGElement} The node itself (for chaining).
|
|
238
260
|
*/
|
|
239
|
-
drawutilssvg.prototype._bindFillDraw = function (node, className, color, lineWidth) {
|
|
261
|
+
drawutilssvg.prototype._bindFillDraw = function (node, className, color, lineWidth, strokeOptions) {
|
|
262
|
+
this._configureNode(node, className, this.fillShapes, color, lineWidth, strokeOptions);
|
|
263
|
+
return this._bindNode(node, undefined);
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* Bind this given node to a parent. If no parent is passed then the global
|
|
267
|
+
* node buffer will be used.
|
|
268
|
+
*
|
|
269
|
+
* @method _bindNode
|
|
270
|
+
* @private
|
|
271
|
+
* @instance
|
|
272
|
+
* @memberof drawutilssvg
|
|
273
|
+
* @param {SVGElement} node - The SVG node to bind.
|
|
274
|
+
* @param {SVGElement=} bindingParent - (optional) You may pass node other than the glober buffer node.
|
|
275
|
+
* @returns {SVGElement} The passed node itself.
|
|
276
|
+
*/
|
|
277
|
+
drawutilssvg.prototype._bindNode = function (node, bindingParent) {
|
|
278
|
+
if (!node.parentNode) {
|
|
279
|
+
// Attach to DOM only if not already attached
|
|
280
|
+
(bindingParent !== null && bindingParent !== void 0 ? bindingParent : this.bufferGNode).appendChild(node);
|
|
281
|
+
}
|
|
282
|
+
return node;
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* Add custom CSS class names and the globally defined CSS classname to the
|
|
286
|
+
* given node.
|
|
287
|
+
*
|
|
288
|
+
* @method addCSSClasses
|
|
289
|
+
* @private
|
|
290
|
+
* @instance
|
|
291
|
+
* @memberof drawutilssvg
|
|
292
|
+
* @param {SVGElement} node - The SVG node to bind.
|
|
293
|
+
* @param {string} className - The additional custom classname to add.
|
|
294
|
+
* @returns {void}
|
|
295
|
+
*/
|
|
296
|
+
drawutilssvg.prototype._addCSSClasses = function (node, className) {
|
|
240
297
|
if (this.curClassName) {
|
|
241
298
|
node.setAttribute("class", className + " " + this.curClassName);
|
|
242
299
|
}
|
|
243
300
|
else {
|
|
244
301
|
node.setAttribute("class", className);
|
|
245
302
|
}
|
|
246
|
-
|
|
247
|
-
|
|
303
|
+
};
|
|
304
|
+
drawutilssvg.prototype._configureNode = function (node, className, fillMode, color, lineWidth, strokeOptions) {
|
|
305
|
+
this._addCSSClasses(node, className);
|
|
306
|
+
node.setAttribute("fill", fillMode && color ? color : "none");
|
|
307
|
+
node.setAttribute("stroke", fillMode ? "none" : color || "none");
|
|
248
308
|
node.setAttribute("stroke-width", "" + (lineWidth || 1));
|
|
249
309
|
if (this.curId) {
|
|
250
310
|
node.setAttribute("id", "" + this.curId); // Maybe React-style 'key' would be better?
|
|
251
311
|
}
|
|
252
|
-
|
|
253
|
-
// Attach to DOM only if not already attached
|
|
254
|
-
this.bufferGNode.appendChild(node);
|
|
255
|
-
}
|
|
312
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
256
313
|
return node;
|
|
257
314
|
};
|
|
258
315
|
/**
|
|
@@ -274,7 +331,7 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
274
331
|
* that under the hood the same gl context and gl program will be used.
|
|
275
332
|
*/
|
|
276
333
|
drawutilssvg.prototype.copyInstance = function (fillShapes) {
|
|
277
|
-
var copy = new drawutilssvg(this.svgNode, this.offset, this.scale, this.canvasSize, fillShapes, null, // no DrawConfig
|
|
334
|
+
var copy = new drawutilssvg(this.svgNode, this.offset, this.scale, this.canvasSize, fillShapes, null, // no DrawConfig – this will work as long as `isSecondary===true`
|
|
278
335
|
true, // isSecondary
|
|
279
336
|
this.gNode, this.bufferGNode, this.nodeDefs, this.bufferedNodeDefs);
|
|
280
337
|
return copy;
|
|
@@ -289,13 +346,27 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
289
346
|
drawutilssvg.prototype.setConfiguration = function (configuration) {
|
|
290
347
|
this.drawlibConfiguration = configuration;
|
|
291
348
|
};
|
|
349
|
+
// /**
|
|
350
|
+
// * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
|
|
351
|
+
// *
|
|
352
|
+
// * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
|
|
353
|
+
// * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
|
354
|
+
// * for how line dashes work.
|
|
355
|
+
// *
|
|
356
|
+
// * @method
|
|
357
|
+
// * @param {Array<number> lineDashes - The line-dash array configuration.
|
|
358
|
+
// * @returns {void}
|
|
359
|
+
// */
|
|
360
|
+
// setLineDash(lineDashes: Array<number>) {
|
|
361
|
+
// this.lineDash = lineDashes;
|
|
362
|
+
// }
|
|
292
363
|
/**
|
|
293
364
|
* This method shouled be called each time the currently drawn `Drawable` changes.
|
|
294
365
|
* It is used by some libraries for identifying elemente on re-renders.
|
|
295
366
|
*
|
|
296
367
|
* @name setCurrentId
|
|
297
368
|
* @method
|
|
298
|
-
* @param {UID} uid - A UID identifying the currently drawn element(s).
|
|
369
|
+
* @param {UID|null} uid - A UID identifying the currently drawn element(s).
|
|
299
370
|
* @instance
|
|
300
371
|
* @memberof drawutilssvg
|
|
301
372
|
**/
|
|
@@ -308,7 +379,7 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
308
379
|
*
|
|
309
380
|
* @name setCurrentClassName
|
|
310
381
|
* @method
|
|
311
|
-
* @param {string} className - A class name for further custom use cases.
|
|
382
|
+
* @param {string|null} className - A class name for further custom use cases.
|
|
312
383
|
* @instance
|
|
313
384
|
* @memberof drawutilssvg
|
|
314
385
|
**/
|
|
@@ -363,6 +434,27 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
363
434
|
this.nodeDefs = this.bufferedNodeDefs;
|
|
364
435
|
this.bufferedNodeDefs = tmpDefsNode;
|
|
365
436
|
};
|
|
437
|
+
/**
|
|
438
|
+
* A private helper method to apply stroke options to the current
|
|
439
|
+
* context.
|
|
440
|
+
* @param {StrokeOptions=} strokeOptions -
|
|
441
|
+
*/
|
|
442
|
+
drawutilssvg.prototype.applyStrokeOpts = function (node, strokeOptions) {
|
|
443
|
+
var _this = this;
|
|
444
|
+
if (strokeOptions &&
|
|
445
|
+
strokeOptions.dashArray &&
|
|
446
|
+
strokeOptions.dashArray.length > 0 &&
|
|
447
|
+
drawutilssvg.nodeSupportsLineDash(node.tagName)) {
|
|
448
|
+
node.setAttribute("stroke-dasharray", strokeOptions.dashArray
|
|
449
|
+
.map(function (dashArayElem) {
|
|
450
|
+
return dashArayElem * _this.scale.x;
|
|
451
|
+
})
|
|
452
|
+
.join(" "));
|
|
453
|
+
if (strokeOptions.dashOffset) {
|
|
454
|
+
node.setAttribute("stroke-dashoffset", "" + strokeOptions.dashOffset * this.scale.x);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
};
|
|
366
458
|
drawutilssvg.prototype._x = function (x) {
|
|
367
459
|
return this.offset.x + this.scale.x * x;
|
|
368
460
|
};
|
|
@@ -373,47 +465,104 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
373
465
|
* Draw the line between the given two points with the specified (CSS-) color.
|
|
374
466
|
*
|
|
375
467
|
* @method line
|
|
376
|
-
* @param {
|
|
377
|
-
* @param {
|
|
468
|
+
* @param {XYCoords} zA - The start point of the line.
|
|
469
|
+
* @param {XYCoords} zB - The end point of the line.
|
|
378
470
|
* @param {string} color - Any valid CSS color string.
|
|
379
471
|
* @param {number=1} lineWidth? - [optional] The line's width.
|
|
472
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
473
|
+
*
|
|
380
474
|
* @return {void}
|
|
381
475
|
* @instance
|
|
382
476
|
* @memberof drawutilssvg
|
|
383
477
|
**/
|
|
384
|
-
drawutilssvg.prototype.line = function (zA, zB, color, lineWidth) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
line.setAttribute("
|
|
388
|
-
line.setAttribute("
|
|
389
|
-
line.setAttribute("
|
|
390
|
-
|
|
478
|
+
drawutilssvg.prototype.line = function (zA, zB, color, lineWidth, strokeOptions) {
|
|
479
|
+
// const line: SVGElement = this.makeNode("line");
|
|
480
|
+
// this.applyStrokeOpts(line, strokeOptions);
|
|
481
|
+
// line.setAttribute("x1", `${this._x(zA.x)}`);
|
|
482
|
+
// line.setAttribute("y1", `${this._y(zA.y)}`);
|
|
483
|
+
// line.setAttribute("x2", `${this._x(zB.x)}`);
|
|
484
|
+
// line.setAttribute("y2", `${this._y(zB.y)}`);
|
|
485
|
+
var line = this.makeLineNode(zA, zB, color, lineWidth, strokeOptions);
|
|
486
|
+
return this._bindFillDraw(line, "line", color, lineWidth || 1, strokeOptions);
|
|
391
487
|
};
|
|
392
488
|
/**
|
|
393
489
|
* Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
|
|
394
490
|
*
|
|
395
491
|
* @method arrow
|
|
396
|
-
* @param {
|
|
397
|
-
* @param {
|
|
492
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
493
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
398
494
|
* @param {string} color - Any valid CSS color string.
|
|
399
495
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
496
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
497
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
498
|
+
*
|
|
400
499
|
* @return {void}
|
|
401
500
|
* @instance
|
|
402
501
|
* @memberof drawutilssvg
|
|
403
502
|
**/
|
|
404
|
-
drawutilssvg.prototype.arrow = function (zA, zB, color, lineWidth) {
|
|
405
|
-
|
|
406
|
-
var
|
|
407
|
-
var
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
503
|
+
drawutilssvg.prototype.arrow = function (zA, zB, color, lineWidth, headLength, strokeOptions) {
|
|
504
|
+
if (headLength === void 0) { headLength = 8; }
|
|
505
|
+
var group = this.makeNode("g");
|
|
506
|
+
var arrowHeadBasePosition = { x: 0, y: 0 };
|
|
507
|
+
// Just create the child nodes, don't bind them to the root node.
|
|
508
|
+
var arrowHead = this.makeArrowHeadNode(zA, zB, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
|
|
509
|
+
var line = this.makeLineNode(zA, arrowHeadBasePosition, color, lineWidth, strokeOptions);
|
|
510
|
+
group.appendChild(line);
|
|
511
|
+
group.appendChild(arrowHead);
|
|
512
|
+
this._addCSSClasses(group, "linear-arrow");
|
|
513
|
+
this._bindNode(group, undefined);
|
|
514
|
+
return group;
|
|
515
|
+
};
|
|
516
|
+
/**
|
|
517
|
+
* Draw a cubic Bézier curve and and an arrow at the end (endControlPoint) of the given line width the specified (CSS-) color and arrow size.
|
|
518
|
+
*
|
|
519
|
+
* @method cubicBezierArrow
|
|
520
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
521
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
522
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
523
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
524
|
+
* @param {string} color - The CSS color to draw the curve with.
|
|
525
|
+
* @param {number} lineWidth - (optional) The line width to use.
|
|
526
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
527
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
528
|
+
*
|
|
529
|
+
* @return {void}
|
|
530
|
+
* @instance
|
|
531
|
+
* @memberof DrawLib
|
|
532
|
+
*/
|
|
533
|
+
drawutilssvg.prototype.cubicBezierArrow = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, headLength, strokeOptions) {
|
|
534
|
+
if (headLength === void 0) { headLength = 8; }
|
|
535
|
+
var group = this.makeNode("g");
|
|
536
|
+
// Just create the child nodes, don't bind them to the root node.
|
|
537
|
+
var arrowHeadBasePosition = new Vertex_1.Vertex(0, 0);
|
|
538
|
+
var arrowHead = this.makeArrowHeadNode(endControlPoint, endPoint, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
|
|
539
|
+
var diff = arrowHeadBasePosition.difference(endPoint);
|
|
540
|
+
var bezier = this.makeCubicBezierNode(startPoint, { x: endPoint.x - diff.x, y: endPoint.y - diff.y }, startControlPoint, { x: endControlPoint.x - diff.x, y: endControlPoint.y - diff.y }, color, lineWidth, strokeOptions);
|
|
541
|
+
group.appendChild(bezier);
|
|
542
|
+
group.appendChild(arrowHead);
|
|
543
|
+
this._addCSSClasses(group, "cubicbezier-arrow");
|
|
544
|
+
this._bindNode(group, undefined);
|
|
545
|
+
return group;
|
|
546
|
+
};
|
|
547
|
+
/**
|
|
548
|
+
* Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
|
|
549
|
+
*
|
|
550
|
+
* @method arrow
|
|
551
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
552
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
553
|
+
* @param {string} color - Any valid CSS color string.
|
|
554
|
+
* @param {number=1} lineWidth - (optional) The line width to use; default is 1.
|
|
555
|
+
* @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
|
|
556
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
557
|
+
*
|
|
558
|
+
* @return {void}
|
|
559
|
+
* @instance
|
|
560
|
+
* @memberof DrawLib
|
|
561
|
+
**/
|
|
562
|
+
drawutilssvg.prototype.arrowHead = function (zA, zB, color, lineWidth, headLength, strokeOptions) {
|
|
563
|
+
if (headLength === void 0) { headLength = 8; }
|
|
564
|
+
var node = this.makeArrowHeadNode(zA, zB, color, lineWidth, headLength, strokeOptions);
|
|
565
|
+
return this._bindFillDraw(node, "arrowhead", color, lineWidth || 1, strokeOptions);
|
|
417
566
|
};
|
|
418
567
|
/**
|
|
419
568
|
* Draw an image at the given position with the given size.<br>
|
|
@@ -422,8 +571,8 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
422
571
|
*
|
|
423
572
|
* @method image
|
|
424
573
|
* @param {Image} image - The image object to draw.
|
|
425
|
-
* @param {
|
|
426
|
-
* @param {
|
|
574
|
+
* @param {XYCoords} position - The position to draw the the upper left corner at.
|
|
575
|
+
* @param {XYCoords} size - The x/y-size to draw the image with.
|
|
427
576
|
* @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
|
|
428
577
|
* @return {void}
|
|
429
578
|
* @instance
|
|
@@ -468,16 +617,16 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
468
617
|
* @param {Image} textureImage - The image object to draw.
|
|
469
618
|
* @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
|
|
470
619
|
* @param {Polygon} polygon - The polygon to use as clip path.
|
|
471
|
-
* @param {
|
|
620
|
+
* @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
|
|
472
621
|
* @param {number} rotation - The rotation to use for the polygon (and for the texture).
|
|
473
622
|
* @return {void}
|
|
474
623
|
* @instance
|
|
475
624
|
* @memberof drawutilssvg
|
|
476
625
|
**/
|
|
477
626
|
drawutilssvg.prototype.texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation) {
|
|
478
|
-
|
|
627
|
+
// const basePolygonBounds: Bounds = polygon.getBounds();
|
|
479
628
|
var rotatedScalingOrigin = new Vertex_1.Vertex(textureSize.min).clone().rotate(rotation, polygonPosition);
|
|
480
|
-
|
|
629
|
+
// const rotationCenter = polygonPosition.clone().add(rotatedScalingOrigin.difference(textureSize.min).inv());
|
|
481
630
|
// Create something like this
|
|
482
631
|
// ...
|
|
483
632
|
// <defs>
|
|
@@ -532,36 +681,21 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
532
681
|
* Draw the given (cubic) bézier curve.
|
|
533
682
|
*
|
|
534
683
|
* @method cubicBezier
|
|
535
|
-
* @param {
|
|
536
|
-
* @param {
|
|
537
|
-
* @param {
|
|
538
|
-
* @param {
|
|
684
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
685
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
686
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
687
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
539
688
|
* @param {string} color - The CSS color to draw the curve with.
|
|
540
689
|
* @param {number} lineWidth - (optional) The line width to use.
|
|
690
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
691
|
+
*
|
|
541
692
|
* @return {void}
|
|
542
693
|
* @instance
|
|
543
694
|
* @memberof drawutilssvg
|
|
544
695
|
*/
|
|
545
|
-
drawutilssvg.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
}
|
|
549
|
-
var node = this.makeNode("path");
|
|
550
|
-
// Draw curve
|
|
551
|
-
var d = [
|
|
552
|
-
"M",
|
|
553
|
-
this._x(startPoint.x),
|
|
554
|
-
this._y(startPoint.y),
|
|
555
|
-
"C",
|
|
556
|
-
this._x(startControlPoint.x),
|
|
557
|
-
this._y(startControlPoint.y),
|
|
558
|
-
this._x(endControlPoint.x),
|
|
559
|
-
this._y(endControlPoint.y),
|
|
560
|
-
this._x(endPoint.x),
|
|
561
|
-
this._y(endPoint.y)
|
|
562
|
-
];
|
|
563
|
-
node.setAttribute("d", d.join(" "));
|
|
564
|
-
return this._bindFillDraw(node, "cubierBezier", color, lineWidth);
|
|
696
|
+
drawutilssvg.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
|
|
697
|
+
var node = this.makeCubicBezierNode(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions);
|
|
698
|
+
return this._bindNode(node, undefined);
|
|
565
699
|
};
|
|
566
700
|
/**
|
|
567
701
|
* Draw the given (cubic) Bézier path.
|
|
@@ -571,17 +705,21 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
571
705
|
* <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
|
|
572
706
|
*
|
|
573
707
|
* @method cubicBezierPath
|
|
574
|
-
* @param {
|
|
708
|
+
* @param {XYCoords[]} path - The cubic bezier path as described above.
|
|
575
709
|
* @param {string} color - The CSS colot to draw the path with.
|
|
576
710
|
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
711
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
712
|
+
*
|
|
577
713
|
* @return {void}
|
|
578
714
|
* @instance
|
|
579
715
|
* @memberof drawutilssvg
|
|
580
716
|
*/
|
|
581
|
-
drawutilssvg.prototype.cubicBezierPath = function (path, color, lineWidth) {
|
|
717
|
+
drawutilssvg.prototype.cubicBezierPath = function (path, color, lineWidth, strokeOptions) {
|
|
582
718
|
var node = this.makeNode("path");
|
|
583
|
-
|
|
719
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
720
|
+
if (!path || path.length == 0) {
|
|
584
721
|
return node;
|
|
722
|
+
}
|
|
585
723
|
// Draw curve
|
|
586
724
|
var d = ["M", this._x(path[0].x), this._y(path[0].y)];
|
|
587
725
|
// Draw curve path
|
|
@@ -618,20 +756,20 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
618
756
|
* Draw a handle line (with a light grey).
|
|
619
757
|
*
|
|
620
758
|
* @method handleLine
|
|
621
|
-
* @param {
|
|
622
|
-
* @param {
|
|
759
|
+
* @param {XYCoords} startPoint - The start point to draw the handle at.
|
|
760
|
+
* @param {XYCoords} endPoint - The end point to draw the handle at.
|
|
623
761
|
* @return {void}
|
|
624
762
|
* @instance
|
|
625
763
|
* @memberof drawutilssvg
|
|
626
764
|
*/
|
|
627
765
|
drawutilssvg.prototype.handleLine = function (startPoint, endPoint) {
|
|
628
|
-
this.line(startPoint, endPoint, "rgb(
|
|
766
|
+
this.line(startPoint, endPoint, "rgb(128,128,128,0.5)");
|
|
629
767
|
};
|
|
630
768
|
/**
|
|
631
769
|
* Draw a 1x1 dot with the specified (CSS-) color.
|
|
632
770
|
*
|
|
633
771
|
* @method dot
|
|
634
|
-
* @param {
|
|
772
|
+
* @param {XYCoords} p - The position to draw the dot at.
|
|
635
773
|
* @param {string} color - The CSS color to draw the dot with.
|
|
636
774
|
* @return {void}
|
|
637
775
|
* @instance
|
|
@@ -639,13 +777,17 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
639
777
|
*/
|
|
640
778
|
drawutilssvg.prototype.dot = function (p, color) {
|
|
641
779
|
var node = this.makeNode("line");
|
|
780
|
+
node.setAttribute("x1", "" + this._x(p.x));
|
|
781
|
+
node.setAttribute("y1", "" + this._y(p.y));
|
|
782
|
+
node.setAttribute("x2", "" + this._x(p.x));
|
|
783
|
+
node.setAttribute("y2", "" + this._y(p.y));
|
|
642
784
|
return this._bindFillDraw(node, "dot", color, 1);
|
|
643
785
|
};
|
|
644
786
|
/**
|
|
645
787
|
* Draw the given point with the specified (CSS-) color and radius 3.
|
|
646
788
|
*
|
|
647
789
|
* @method point
|
|
648
|
-
* @param {
|
|
790
|
+
* @param {XYCoords} p - The position to draw the point at.
|
|
649
791
|
* @param {string} color - The CSS color to draw the point with.
|
|
650
792
|
* @return {void}
|
|
651
793
|
* @instance
|
|
@@ -665,17 +807,20 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
665
807
|
* Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
|
|
666
808
|
*
|
|
667
809
|
* @method circle
|
|
668
|
-
* @param {
|
|
810
|
+
* @param {XYCoords} center - The center of the circle.
|
|
669
811
|
* @param {number} radius - The radius of the circle.
|
|
670
812
|
* @param {string} color - The CSS color to draw the circle with.
|
|
671
813
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
814
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
815
|
+
*
|
|
672
816
|
* @return {void}
|
|
673
817
|
* @instance
|
|
674
818
|
* @memberof drawutilssvg
|
|
675
819
|
*/
|
|
676
|
-
drawutilssvg.prototype.circle = function (center, radius, color, lineWidth) {
|
|
820
|
+
drawutilssvg.prototype.circle = function (center, radius, color, lineWidth, strokeOptions) {
|
|
677
821
|
// Todo: draw ellipse when scalex!=scaley
|
|
678
822
|
var node = this.makeNode("circle");
|
|
823
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
679
824
|
node.setAttribute("cx", "" + this._x(center.x));
|
|
680
825
|
node.setAttribute("cy", "" + this._y(center.y));
|
|
681
826
|
node.setAttribute("r", "" + radius * this.scale.x); // y?
|
|
@@ -685,17 +830,20 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
685
830
|
* Draw a circular arc (section of a circle) with the given CSS color.
|
|
686
831
|
*
|
|
687
832
|
* @method circleArc
|
|
688
|
-
* @param {
|
|
833
|
+
* @param {XYCoords} center - The center of the circle.
|
|
689
834
|
* @param {number} radius - The radius of the circle.
|
|
690
835
|
* @param {number} startAngle - The angle to start at.
|
|
691
836
|
* @param {number} endAngle - The angle to end at.
|
|
692
837
|
* @param {string} color - The CSS color to draw the circle with.
|
|
838
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
839
|
+
*
|
|
693
840
|
* @return {void}
|
|
694
841
|
* @instance
|
|
695
842
|
* @memberof drawutilssvg
|
|
696
843
|
*/
|
|
697
|
-
drawutilssvg.prototype.circleArc = function (center, radius, startAngle, endAngle, color, lineWidth) {
|
|
844
|
+
drawutilssvg.prototype.circleArc = function (center, radius, startAngle, endAngle, color, lineWidth, strokeOptions) {
|
|
698
845
|
var node = this.makeNode("path");
|
|
846
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
699
847
|
var arcData = CircleSector_1.CircleSector.circleSectorUtils.describeSVGArc(this._x(center.x), this._y(center.y), radius * this.scale.x, // y?
|
|
700
848
|
startAngle, endAngle);
|
|
701
849
|
node.setAttribute("d", arcData.join(" "));
|
|
@@ -705,21 +853,24 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
705
853
|
* Draw an ellipse with the specified (CSS-) color and thw two radii.
|
|
706
854
|
*
|
|
707
855
|
* @method ellipse
|
|
708
|
-
* @param {
|
|
856
|
+
* @param {XYCoords} center - The center of the ellipse.
|
|
709
857
|
* @param {number} radiusX - The radius of the ellipse.
|
|
710
858
|
* @param {number} radiusY - The radius of the ellipse.
|
|
711
859
|
* @param {string} color - The CSS color to draw the ellipse with.
|
|
712
860
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
713
861
|
* @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
|
|
862
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
863
|
+
*
|
|
714
864
|
* @return {void}
|
|
715
865
|
* @instance
|
|
716
866
|
* @memberof drawutilssvg
|
|
717
867
|
*/
|
|
718
|
-
drawutilssvg.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation) {
|
|
868
|
+
drawutilssvg.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation, strokeOptions) {
|
|
719
869
|
if (typeof rotation === "undefined") {
|
|
720
870
|
rotation = 0.0;
|
|
721
871
|
}
|
|
722
872
|
var node = this.makeNode("ellipse");
|
|
873
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
723
874
|
node.setAttribute("cx", "" + this._x(center.x));
|
|
724
875
|
node.setAttribute("cy", "" + this._y(center.y));
|
|
725
876
|
node.setAttribute("rx", "" + radiusX * this.scale.x);
|
|
@@ -735,15 +886,18 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
735
886
|
*
|
|
736
887
|
* @method square
|
|
737
888
|
* @param {XYCoords} center - The center of the square.
|
|
738
|
-
* @param {
|
|
889
|
+
* @param {number} size - The size of the square.
|
|
739
890
|
* @param {string} color - The CSS color to draw the square with.
|
|
740
891
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
741
|
-
* @
|
|
892
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
893
|
+
*
|
|
894
|
+
* @return {SVGElement}
|
|
742
895
|
* @instance
|
|
743
896
|
* @memberof drawutilssvg
|
|
744
897
|
*/
|
|
745
|
-
drawutilssvg.prototype.square = function (center, size, color, lineWidth) {
|
|
898
|
+
drawutilssvg.prototype.square = function (center, size, color, lineWidth, strokeOptions) {
|
|
746
899
|
var node = this.makeNode("rectangle");
|
|
900
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
747
901
|
node.setAttribute("x", "" + this._x(center.x - size / 2.0));
|
|
748
902
|
node.setAttribute("y", "" + this._y(center.y - size / 2.0));
|
|
749
903
|
node.setAttribute("width", "" + size * this.scale.x);
|
|
@@ -758,9 +912,15 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
758
912
|
* @param {number} height - The height of the rectangle.
|
|
759
913
|
* @param {string} color - The color to use.
|
|
760
914
|
* @param {number=1} lineWidth - (optional) The line with to use (default is 1).
|
|
915
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
916
|
+
*
|
|
917
|
+
* @return {SVGElement}
|
|
918
|
+
* @instance
|
|
919
|
+
* @memberof drawutilssvg
|
|
761
920
|
**/
|
|
762
|
-
drawutilssvg.prototype.rect = function (position, width, height, color, lineWidth) {
|
|
921
|
+
drawutilssvg.prototype.rect = function (position, width, height, color, lineWidth, strokeOptions) {
|
|
763
922
|
var node = this.makeNode("rect");
|
|
923
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
764
924
|
node.setAttribute("x", "" + this._x(position.x));
|
|
765
925
|
node.setAttribute("y", "" + this._y(position.y));
|
|
766
926
|
node.setAttribute("width", "" + width * this.scale.x);
|
|
@@ -771,7 +931,7 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
771
931
|
* Draw a grid of horizontal and vertical lines with the given (CSS-) color.
|
|
772
932
|
*
|
|
773
933
|
* @method grid
|
|
774
|
-
* @param {
|
|
934
|
+
* @param {XYCoords} center - The center of the grid.
|
|
775
935
|
* @param {number} width - The total width of the grid (width/2 each to the left and to the right).
|
|
776
936
|
* @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
|
|
777
937
|
* @param {number} sizeX - The horizontal grid size.
|
|
@@ -805,7 +965,7 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
805
965
|
* This works analogue to the grid() function
|
|
806
966
|
*
|
|
807
967
|
* @method raster
|
|
808
|
-
* @param {
|
|
968
|
+
* @param {XYCoords} center - The center of the raster.
|
|
809
969
|
* @param {number} width - The total width of the raster (width/2 each to the left and to the right).
|
|
810
970
|
* @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
|
|
811
971
|
* @param {number} sizeX - The horizontal raster size.
|
|
@@ -838,8 +998,8 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
838
998
|
* as even shaped diamonds.
|
|
839
999
|
*
|
|
840
1000
|
* @method diamondHandle
|
|
841
|
-
* @param {
|
|
842
|
-
* @param {
|
|
1001
|
+
* @param {XYCoords} center - The center of the diamond.
|
|
1002
|
+
* @param {number} size - The x/y-size of the diamond.
|
|
843
1003
|
* @param {string} color - The CSS color to draw the diamond with.
|
|
844
1004
|
* @return {void}
|
|
845
1005
|
* @instance
|
|
@@ -873,8 +1033,8 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
873
1033
|
* as even shaped squares.
|
|
874
1034
|
*
|
|
875
1035
|
* @method squareHandle
|
|
876
|
-
* @param {
|
|
877
|
-
* @param {
|
|
1036
|
+
* @param {XYCoords} center - The center of the square.
|
|
1037
|
+
* @param {XYCoords} size - The x/y-size of the square.
|
|
878
1038
|
* @param {string} color - The CSS color to draw the square with.
|
|
879
1039
|
* @return {void}
|
|
880
1040
|
* @instance
|
|
@@ -896,7 +1056,7 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
896
1056
|
* as even shaped circles.
|
|
897
1057
|
*
|
|
898
1058
|
* @method circleHandle
|
|
899
|
-
* @param {
|
|
1059
|
+
* @param {XYCoords} center - The center of the circle.
|
|
900
1060
|
* @param {number} radius - The radius of the circle.
|
|
901
1061
|
* @param {string} color - The CSS color to draw the circle with.
|
|
902
1062
|
* @return {void}
|
|
@@ -995,18 +1155,22 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
995
1155
|
* Draw a polygon line (alternative function to the polygon).
|
|
996
1156
|
*
|
|
997
1157
|
* @method polyline
|
|
998
|
-
* @param {
|
|
1158
|
+
* @param {XYCoords[]} vertices - The polygon vertices to draw.
|
|
999
1159
|
* @param {boolan} isOpen - If true the polyline will not be closed at its end.
|
|
1000
1160
|
* @param {string} color - The CSS color to draw the polygon with.
|
|
1001
1161
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
1162
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
1163
|
+
*
|
|
1002
1164
|
* @return {void}
|
|
1003
1165
|
* @instance
|
|
1004
1166
|
* @memberof drawutilssvg
|
|
1005
1167
|
*/
|
|
1006
|
-
drawutilssvg.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
|
|
1168
|
+
drawutilssvg.prototype.polyline = function (vertices, isOpen, color, lineWidth, strokeOptions) {
|
|
1007
1169
|
var node = this.makeNode("path");
|
|
1008
|
-
|
|
1170
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
1171
|
+
if (vertices.length == 0) {
|
|
1009
1172
|
return node;
|
|
1173
|
+
}
|
|
1010
1174
|
// Draw curve
|
|
1011
1175
|
var d = ["M", this._x(vertices[0].x), this._y(vertices[0].y)];
|
|
1012
1176
|
var n = vertices.length;
|
|
@@ -1109,12 +1273,16 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
1109
1273
|
* @param {string=null} color - (optional) The color to draw this path with (default is null).
|
|
1110
1274
|
* @param {number=1} lineWidth - (optional) the line width to use (default is 1).
|
|
1111
1275
|
* @param {boolean=false} options.inplace - (optional) If set to true then path transforamtions (scale and translate) will be done in-place in the array. This can boost the performance.
|
|
1276
|
+
* @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
|
|
1277
|
+
* @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
|
|
1278
|
+
*
|
|
1112
1279
|
* @instance
|
|
1113
1280
|
* @memberof drawutils
|
|
1114
1281
|
* @return {R} An instance representing the drawn path.
|
|
1115
1282
|
*/
|
|
1116
1283
|
drawutilssvg.prototype.path = function (pathData, color, lineWidth, options) {
|
|
1117
1284
|
var node = this.makeNode("path");
|
|
1285
|
+
this.applyStrokeOpts(node, options);
|
|
1118
1286
|
// Transform the path: in-place (fast) or copy (slower)
|
|
1119
1287
|
var d = options && options.inplace ? pathData : drawutilssvg.copyPathData(pathData);
|
|
1120
1288
|
drawutilssvg.transformPathData(d, this.offset, this.scale);
|
|
@@ -1140,7 +1308,7 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
1140
1308
|
}
|
|
1141
1309
|
// Add a covering rect with the given background color
|
|
1142
1310
|
this.curId = "background";
|
|
1143
|
-
this.curClassName = undefined;
|
|
1311
|
+
this.curClassName = null; // undefined;
|
|
1144
1312
|
var node = this.makeNode("rect");
|
|
1145
1313
|
// For some strange reason SVG rotation transforms use degrees instead of radians
|
|
1146
1314
|
// Note that the background does not scale with the zoom level (always covers full element)
|
|
@@ -1152,7 +1320,7 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
1152
1320
|
this._bindFillDraw(node, this.curId, null, null);
|
|
1153
1321
|
node.setAttribute("fill", typeof color === "undefined" ? "none" : color);
|
|
1154
1322
|
// Clear the current ID again
|
|
1155
|
-
this.curId = undefined;
|
|
1323
|
+
this.curId = null; // undefined;
|
|
1156
1324
|
};
|
|
1157
1325
|
/**
|
|
1158
1326
|
* A private helper function to clear all SVG nodes from the >g> node.
|
|
@@ -1357,6 +1525,127 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
1357
1525
|
}
|
|
1358
1526
|
} // END while
|
|
1359
1527
|
}; // END transformPathData
|
|
1528
|
+
drawutilssvg.nodeSupportsLineDash = function (nodeName) {
|
|
1529
|
+
return ["line", "path", "circle", "ellipse", "rectangle", "rect"].includes(nodeName);
|
|
1530
|
+
};
|
|
1531
|
+
/**
|
|
1532
|
+
* Creates a basic <line> node with start and end coordinates. The created node will not
|
|
1533
|
+
* be bound to any root node.
|
|
1534
|
+
*
|
|
1535
|
+
* @private
|
|
1536
|
+
* @method makeLineNode
|
|
1537
|
+
* @param {XYCoords} zA - The line's start position.
|
|
1538
|
+
* @param {XYCoords} zB - The line's start position.
|
|
1539
|
+
* @param {string} color - The CSS color to draw the point with.
|
|
1540
|
+
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
1541
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
|
|
1542
|
+
* @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
|
|
1543
|
+
* @return {SVGLineElement}
|
|
1544
|
+
* @instance
|
|
1545
|
+
* @memberof drawutilssvg
|
|
1546
|
+
*/
|
|
1547
|
+
drawutilssvg.prototype.makeLineNode = function (zA, zB, color, lineWidth, strokeOptions, classNameOverride) {
|
|
1548
|
+
var line = this.makeNode("line");
|
|
1549
|
+
line.setAttribute("x1", "" + this._x(zA.x));
|
|
1550
|
+
line.setAttribute("y1", "" + this._y(zA.y));
|
|
1551
|
+
line.setAttribute("x2", "" + this._x(zB.x));
|
|
1552
|
+
line.setAttribute("y2", "" + this._y(zB.y));
|
|
1553
|
+
this._configureNode(line, classNameOverride !== null && classNameOverride !== void 0 ? classNameOverride : "line", this.fillShapes, color, lineWidth || 1, strokeOptions);
|
|
1554
|
+
return line;
|
|
1555
|
+
};
|
|
1556
|
+
/**
|
|
1557
|
+
* Creates a basic <path> node with given path string data. The created node will not
|
|
1558
|
+
* be bound to any root node.
|
|
1559
|
+
*
|
|
1560
|
+
* @private
|
|
1561
|
+
* @method makePathNode
|
|
1562
|
+
* @param {string} pathString - The path data (must be a valid path data string).
|
|
1563
|
+
* @param {string} color - The CSS color to draw the point with.
|
|
1564
|
+
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
1565
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
|
|
1566
|
+
* @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
|
|
1567
|
+
* @return {SVGPathElement}
|
|
1568
|
+
* @instance
|
|
1569
|
+
* @memberof drawutilssvg
|
|
1570
|
+
*/
|
|
1571
|
+
drawutilssvg.prototype.makePathNode = function (pathString, color, lineWidth, strokeOptions, classNameOverride) {
|
|
1572
|
+
var path = this.makeNode("path");
|
|
1573
|
+
path.setAttribute("d", pathString);
|
|
1574
|
+
this._configureNode(path, classNameOverride !== null && classNameOverride !== void 0 ? classNameOverride : "path", this.fillShapes, color, lineWidth || 1, strokeOptions);
|
|
1575
|
+
return path;
|
|
1576
|
+
};
|
|
1577
|
+
/**
|
|
1578
|
+
* Creates a basic arrow head node (<path> node) at the end of the given line coordinates. The created node will not
|
|
1579
|
+
* be bound to any root node.
|
|
1580
|
+
*
|
|
1581
|
+
* @private
|
|
1582
|
+
* @method makeArrowHeadNode
|
|
1583
|
+
* @param {string} pathString - The path data (must be a valid path data string).
|
|
1584
|
+
* @param {string} color - The CSS color to draw the point with.
|
|
1585
|
+
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
1586
|
+
* @param {number=8} headLength - (optional) The length of the arrow head; if none is specified then the head will be 8 absolute units long.
|
|
1587
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
|
|
1588
|
+
* @param {XYCoords=} arrowHeadBasePositionBuffer - (optional) If not null, then this position will contain the arrow head's start point (after execution). Some sort of OUT variable.
|
|
1589
|
+
* @return {SVGPathElement}
|
|
1590
|
+
* @instance
|
|
1591
|
+
* @memberof drawutilssvg
|
|
1592
|
+
*/
|
|
1593
|
+
drawutilssvg.prototype.makeArrowHeadNode = function (zA, zB, color, lineWidth, headLength, strokeOptions, arrowHeadBasePositionBuffer) {
|
|
1594
|
+
if (headLength === void 0) { headLength = 8; }
|
|
1595
|
+
var vertices = Vector_1.Vector.utils.buildArrowHead(zA, zB, headLength, this.scale.x, this.scale.y);
|
|
1596
|
+
var d = ["M", this.offset.x + vertices[0].x, this.offset.y + vertices[0].y];
|
|
1597
|
+
if (arrowHeadBasePositionBuffer) {
|
|
1598
|
+
arrowHeadBasePositionBuffer.x = vertices[0].x / this.scale.x;
|
|
1599
|
+
arrowHeadBasePositionBuffer.y = vertices[0].y / this.scale.y;
|
|
1600
|
+
}
|
|
1601
|
+
for (var i = 1; i <= vertices.length; i++) {
|
|
1602
|
+
d.push("L");
|
|
1603
|
+
// Note: only use offset here (the vertices are already scaled)
|
|
1604
|
+
d.push(this.offset.x + vertices[i % vertices.length].x);
|
|
1605
|
+
d.push(this.offset.y + vertices[i % vertices.length].y);
|
|
1606
|
+
}
|
|
1607
|
+
var node = this.makePathNode(d.join(" "), color, lineWidth, strokeOptions, "arrowhead");
|
|
1608
|
+
return node;
|
|
1609
|
+
};
|
|
1610
|
+
/**
|
|
1611
|
+
* Creates a basic cubic Bézier path node (<path> node) with the given cubic Bézier data. The created node will not
|
|
1612
|
+
* be bound to any root node.
|
|
1613
|
+
*
|
|
1614
|
+
* @private
|
|
1615
|
+
* @method makeCubicBezierNode
|
|
1616
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
1617
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
1618
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
1619
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
1620
|
+
* @param {string} color - The CSS color to draw the point with.
|
|
1621
|
+
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
1622
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
|
|
1623
|
+
* @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
|
|
1624
|
+
* @param {XYCoords=} arrowHeadBasePositionBuffer - (optional) If not null, then this position will contain the arrow head's start point (after execution). Some sort of OUT variable.
|
|
1625
|
+
* @return {SVGPathElement}
|
|
1626
|
+
* @instance
|
|
1627
|
+
* @memberof drawutilssvg
|
|
1628
|
+
*/
|
|
1629
|
+
drawutilssvg.prototype.makeCubicBezierNode = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
|
|
1630
|
+
if (startPoint instanceof CubicBezierCurve_1.CubicBezierCurve) {
|
|
1631
|
+
return this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
|
|
1632
|
+
}
|
|
1633
|
+
// Draw curve
|
|
1634
|
+
var d = [
|
|
1635
|
+
"M",
|
|
1636
|
+
this._x(startPoint.x),
|
|
1637
|
+
this._y(startPoint.y),
|
|
1638
|
+
"C",
|
|
1639
|
+
this._x(startControlPoint.x),
|
|
1640
|
+
this._y(startControlPoint.y),
|
|
1641
|
+
this._x(endControlPoint.x),
|
|
1642
|
+
this._y(endControlPoint.y),
|
|
1643
|
+
this._x(endPoint.x),
|
|
1644
|
+
this._y(endPoint.y)
|
|
1645
|
+
];
|
|
1646
|
+
var node = this.makePathNode(d.join(" "), color, lineWidth, strokeOptions, "cubicBezier");
|
|
1647
|
+
return node;
|
|
1648
|
+
};
|
|
1360
1649
|
drawutilssvg.HEAD_XML = [
|
|
1361
1650
|
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>',
|
|
1362
1651
|
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" ',
|