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.
Files changed (141) hide show
  1. package/README.md +17 -1
  2. package/dist/index.esm.js +2065 -1397
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.esm.min.js +1 -1
  5. package/dist/index.esm.min.js.map +1 -1
  6. package/dist/plotboilerplate.browser.min.js +1 -1
  7. package/dist/plotboilerplate.browser.min.js.map +1 -1
  8. package/dist/plotboilerplate.js +1265 -584
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +2 -1
  11. package/src/cjs/BezierPath.d.ts +27 -49
  12. package/src/cjs/BezierPath.js +69 -237
  13. package/src/cjs/BezierPath.js.map +1 -1
  14. package/src/cjs/Bounds.d.ts +14 -1
  15. package/src/cjs/Bounds.js +21 -1
  16. package/src/cjs/Bounds.js.map +1 -1
  17. package/src/cjs/CubicBezierCurve.d.ts +70 -1
  18. package/src/cjs/CubicBezierCurve.js +130 -12
  19. package/src/cjs/CubicBezierCurve.js.map +1 -1
  20. package/src/cjs/Line.d.ts +2 -1
  21. package/src/cjs/Line.js +1 -0
  22. package/src/cjs/Line.js.map +1 -1
  23. package/src/cjs/PBText.d.ts +2 -1
  24. package/src/cjs/PBText.js +10 -9
  25. package/src/cjs/PBText.js.map +1 -1
  26. package/src/cjs/PlotBoilerplate.d.ts +10 -13
  27. package/src/cjs/PlotBoilerplate.js +136 -47
  28. package/src/cjs/PlotBoilerplate.js.map +1 -1
  29. package/src/cjs/Polygon.d.ts +35 -1
  30. package/src/cjs/Polygon.js +87 -1
  31. package/src/cjs/Polygon.js.map +1 -1
  32. package/src/cjs/Triangle.js +1 -0
  33. package/src/cjs/Triangle.js.map +1 -1
  34. package/src/cjs/VEllipse.js +1 -1
  35. package/src/cjs/VEllipse.js.map +1 -1
  36. package/src/cjs/Vector.d.ts +4 -4
  37. package/src/cjs/Vector.js +2 -2
  38. package/src/cjs/Vector.js.map +1 -1
  39. package/src/cjs/VertTuple.d.ts +2 -1
  40. package/src/cjs/VertTuple.js +4 -3
  41. package/src/cjs/VertTuple.js.map +1 -1
  42. package/src/cjs/Vertex.d.ts +14 -3
  43. package/src/cjs/Vertex.js +18 -3
  44. package/src/cjs/Vertex.js.map +1 -1
  45. package/src/cjs/draw.d.ts +159 -79
  46. package/src/cjs/draw.js +311 -139
  47. package/src/cjs/draw.js.map +1 -1
  48. package/src/cjs/drawgl.d.ts +93 -55
  49. package/src/cjs/drawgl.js +90 -34
  50. package/src/cjs/drawgl.js.map +1 -1
  51. package/src/cjs/drawutilssvg.d.ts +233 -58
  52. package/src/cjs/drawutilssvg.js +384 -95
  53. package/src/cjs/drawutilssvg.js.map +1 -1
  54. package/src/cjs/interfaces/DrawLib.d.ts +161 -82
  55. package/src/cjs/interfaces/DrawLib.js +7 -0
  56. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  57. package/src/cjs/interfaces/core.d.ts +46 -32
  58. package/src/cjs/interfaces/core.js +2 -0
  59. package/src/cjs/interfaces/core.js.map +1 -1
  60. package/src/cjs/utils/creategui.js +16 -10
  61. package/src/cjs/utils/datastructures/Color.d.ts +3 -1
  62. package/src/cjs/utils/datastructures/Color.js +12 -1
  63. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  64. package/src/cjs/utils/detectDarkMode.d.ts +10 -0
  65. package/src/cjs/utils/detectDarkMode.js +32 -0
  66. package/src/cjs/utils/detectDarkMode.js.map +1 -0
  67. package/src/cjs/utils/module.js +4 -2
  68. package/src/esm/BezierPath.d.ts +27 -49
  69. package/src/esm/BezierPath.js +69 -237
  70. package/src/esm/BezierPath.js.map +1 -1
  71. package/src/esm/Bounds.d.ts +14 -1
  72. package/src/esm/Bounds.js +19 -1
  73. package/src/esm/Bounds.js.map +1 -1
  74. package/src/esm/CubicBezierCurve.d.ts +70 -1
  75. package/src/esm/CubicBezierCurve.js +130 -12
  76. package/src/esm/CubicBezierCurve.js.map +1 -1
  77. package/src/esm/Line.d.ts +2 -1
  78. package/src/esm/Line.js +1 -0
  79. package/src/esm/Line.js.map +1 -1
  80. package/src/esm/PBText.d.ts +2 -1
  81. package/src/esm/PBText.js +10 -9
  82. package/src/esm/PBText.js.map +1 -1
  83. package/src/esm/PlotBoilerplate.d.ts +10 -13
  84. package/src/esm/PlotBoilerplate.js +136 -48
  85. package/src/esm/PlotBoilerplate.js.map +1 -1
  86. package/src/esm/Polygon.d.ts +35 -1
  87. package/src/esm/Polygon.js +85 -1
  88. package/src/esm/Polygon.js.map +1 -1
  89. package/src/esm/Triangle.js +1 -0
  90. package/src/esm/Triangle.js.map +1 -1
  91. package/src/esm/VEllipse.js +1 -1
  92. package/src/esm/VEllipse.js.map +1 -1
  93. package/src/esm/Vector.d.ts +4 -4
  94. package/src/esm/Vector.js +2 -2
  95. package/src/esm/Vector.js.map +1 -1
  96. package/src/esm/VertTuple.d.ts +2 -1
  97. package/src/esm/VertTuple.js +4 -3
  98. package/src/esm/VertTuple.js.map +1 -1
  99. package/src/esm/Vertex.d.ts +14 -3
  100. package/src/esm/Vertex.js +18 -3
  101. package/src/esm/Vertex.js.map +1 -1
  102. package/src/esm/draw.d.ts +159 -79
  103. package/src/esm/draw.js +307 -137
  104. package/src/esm/draw.js.map +1 -1
  105. package/src/esm/drawgl.d.ts +93 -55
  106. package/src/esm/drawgl.js +90 -34
  107. package/src/esm/drawgl.js.map +1 -1
  108. package/src/esm/drawutilssvg.d.ts +233 -58
  109. package/src/esm/drawutilssvg.js +379 -95
  110. package/src/esm/drawutilssvg.js.map +1 -1
  111. package/src/esm/interfaces/DrawLib.d.ts +161 -82
  112. package/src/esm/interfaces/DrawLib.js +7 -0
  113. package/src/esm/interfaces/DrawLib.js.map +1 -1
  114. package/src/esm/interfaces/core.d.ts +46 -32
  115. package/src/esm/interfaces/core.js +2 -0
  116. package/src/esm/interfaces/core.js.map +1 -1
  117. package/src/esm/utils/datastructures/Color.d.ts +3 -1
  118. package/src/esm/utils/datastructures/Color.js +12 -1
  119. package/src/esm/utils/datastructures/Color.js.map +1 -1
  120. package/src/esm/utils/detectDarkMode.d.ts +10 -0
  121. package/src/esm/utils/detectDarkMode.js +28 -0
  122. package/src/esm/utils/detectDarkMode.js.map +1 -0
  123. package/src/ts/BezierPath.ts +74 -244
  124. package/src/ts/Bounds.ts +25 -1
  125. package/src/ts/CubicBezierCurve.ts +139 -12
  126. package/src/ts/Line.ts +2 -1
  127. package/src/ts/PBText.ts +10 -9
  128. package/src/ts/PlotBoilerplate.ts +130 -50
  129. package/src/ts/Polygon.ts +91 -1
  130. package/src/ts/Triangle.ts +2 -1
  131. package/src/ts/VEllipse.ts +2 -2
  132. package/src/ts/Vector.ts +4 -4
  133. package/src/ts/VertTuple.ts +4 -3
  134. package/src/ts/Vertex.ts +20 -4
  135. package/src/ts/draw.ts +316 -119
  136. package/src/ts/drawgl.ts +141 -78
  137. package/src/ts/drawutilssvg.ts +562 -133
  138. package/src/ts/interfaces/DrawLib.ts +223 -86
  139. package/src/ts/interfaces/core.ts +47 -32
  140. package/src/ts/utils/datastructures/Color.ts +13 -1
  141. package/src/ts/utils/detectDarkMode.ts +30 -0
@@ -35,12 +35,23 @@
35
35
  * @modified 2022-03-26 Added the `texturedPoly` function to draw textures polygons.
36
36
  * @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
37
37
  * @modified 2022-11-10 Tweaking some type issues.
38
- * @version 1.6.2
38
+ * @modified 2023-02-04 Fixed a typo in the CSS classname for cubic Bézier paths: cubicBezier (was cubierBezier).
39
+ * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
40
+ * @modified 2023-09-29 Added initialization checks for null parameters.
41
+ * @modified 2023-09-29 Added a missing implementation to the `drawurilssvg.do(XYCoords,string)` function. Didn't draw anything.
42
+ * @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.
43
+ * @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
44
+ * @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
45
+ * @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
46
+ * @modified 2023-10-04 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
47
+ *
48
+ * @version 1.6.7
39
49
  **/
40
50
  import { CircleSector } from "./CircleSector";
41
51
  import { CubicBezierCurve } from "./CubicBezierCurve";
42
52
  import { Vertex } from "./Vertex";
43
53
  import { UIDGenerator } from "./UIDGenerator";
54
+ import { Vector } from "./Vector";
44
55
  const RAD_TO_DEG = 180 / Math.PI;
45
56
  /**
46
57
  * @classdesc A helper class for basic SVG drawing operations. This class should
@@ -71,11 +82,14 @@ export class drawutilssvg {
71
82
  this.offset = new Vertex(0, 0).set(offset);
72
83
  this.scale = new Vertex(1, 1).set(scale);
73
84
  this.fillShapes = fillShapes;
74
- this.isSecondary = isSecondary;
85
+ this.isSecondary = Boolean(isSecondary);
75
86
  this.drawlibConfiguration = {};
76
87
  this.cache = new Map();
77
88
  this.setSize(canvasSize);
78
89
  if (isSecondary) {
90
+ if (!gNode || !bufferGNode || !nodeDefs || !bufferNodeDefs) {
91
+ throw "Cannot create secondary svg draw lib with undefinde gNode|bufferGNode|nodeDefs|bufferNodeDefs.";
92
+ }
79
93
  this.gNode = gNode;
80
94
  this.bufferGNode = bufferGNode;
81
95
  this.nodeDefs = nodeDefs;
@@ -101,6 +115,8 @@ export class drawutilssvg {
101
115
  // Which default styles to add? -> All from the DrawConfig.
102
116
  // Compare with DrawConfig interface
103
117
  const keys = {
118
+ // "bezier": "CubicBezierCurve", // TODO: is this correct?
119
+ "bezierPath": "BezierPath",
104
120
  "polygon": "Polygon",
105
121
  "triangle": "Triangle",
106
122
  "ellipse": "Ellipse",
@@ -166,6 +182,9 @@ export class drawutilssvg {
166
182
  * @param {string} nodeName - The expected node name.
167
183
  */
168
184
  findElement(key, nodeName) {
185
+ if (!key) {
186
+ return null;
187
+ }
169
188
  var node = this.cache.get(key);
170
189
  if (node && node.nodeName.toUpperCase() === nodeName.toUpperCase()) {
171
190
  this.cache.delete(key);
@@ -211,6 +230,9 @@ export class drawutilssvg {
211
230
  if (this.drawlibConfiguration.blendMode) {
212
231
  node.style["mix-blend-mode"] = this.drawlibConfiguration.blendMode;
213
232
  }
233
+ // if (this.lineDashEnabled && this.lineDash && this.lineDash.length > 0 && drawutilssvg.nodeSupportsLineDash(nodeName)) {
234
+ // node.setAttribute("stroke-dasharray", this.lineDash.join(" "));
235
+ // }
214
236
  return node;
215
237
  }
216
238
  /**
@@ -233,23 +255,58 @@ export class drawutilssvg {
233
255
  * @param {number=1} lineWidth - (optional) A line width to use for drawing (default is 1).
234
256
  * @return {SVGElement} The node itself (for chaining).
235
257
  */
236
- _bindFillDraw(node, className, color, lineWidth) {
258
+ _bindFillDraw(node, className, color, lineWidth, strokeOptions) {
259
+ this._configureNode(node, className, this.fillShapes, color, lineWidth, strokeOptions);
260
+ return this._bindNode(node, undefined);
261
+ }
262
+ /**
263
+ * Bind this given node to a parent. If no parent is passed then the global
264
+ * node buffer will be used.
265
+ *
266
+ * @method _bindNode
267
+ * @private
268
+ * @instance
269
+ * @memberof drawutilssvg
270
+ * @param {SVGElement} node - The SVG node to bind.
271
+ * @param {SVGElement=} bindingParent - (optional) You may pass node other than the glober buffer node.
272
+ * @returns {SVGElement} The passed node itself.
273
+ */
274
+ _bindNode(node, bindingParent) {
275
+ if (!node.parentNode) {
276
+ // Attach to DOM only if not already attached
277
+ (bindingParent !== null && bindingParent !== void 0 ? bindingParent : this.bufferGNode).appendChild(node);
278
+ }
279
+ return node;
280
+ }
281
+ /**
282
+ * Add custom CSS class names and the globally defined CSS classname to the
283
+ * given node.
284
+ *
285
+ * @method addCSSClasses
286
+ * @private
287
+ * @instance
288
+ * @memberof drawutilssvg
289
+ * @param {SVGElement} node - The SVG node to bind.
290
+ * @param {string} className - The additional custom classname to add.
291
+ * @returns {void}
292
+ */
293
+ _addCSSClasses(node, className) {
237
294
  if (this.curClassName) {
238
295
  node.setAttribute("class", `${className} ${this.curClassName}`);
239
296
  }
240
297
  else {
241
298
  node.setAttribute("class", className);
242
299
  }
243
- node.setAttribute("fill", this.fillShapes ? color : "none");
244
- node.setAttribute("stroke", this.fillShapes ? "none" : color);
300
+ }
301
+ _configureNode(node, className, fillMode, color, lineWidth, strokeOptions) {
302
+ this._addCSSClasses(node, className);
303
+ node.setAttribute("fill", fillMode && color ? color : "none");
304
+ node.setAttribute("stroke", fillMode ? "none" : color || "none");
245
305
  node.setAttribute("stroke-width", `${lineWidth || 1}`);
246
306
  if (this.curId) {
247
307
  node.setAttribute("id", `${this.curId}`); // Maybe React-style 'key' would be better?
248
308
  }
249
- if (!node.parentNode) {
250
- // Attach to DOM only if not already attached
251
- this.bufferGNode.appendChild(node);
252
- }
309
+ this.applyStrokeOpts(node, strokeOptions);
253
310
  return node;
254
311
  }
255
312
  /**
@@ -271,7 +328,7 @@ export class drawutilssvg {
271
328
  * that under the hood the same gl context and gl program will be used.
272
329
  */
273
330
  copyInstance(fillShapes) {
274
- var copy = new drawutilssvg(this.svgNode, this.offset, this.scale, this.canvasSize, fillShapes, null, // no DrawConfig
331
+ var copy = new drawutilssvg(this.svgNode, this.offset, this.scale, this.canvasSize, fillShapes, null, // no DrawConfig – this will work as long as `isSecondary===true`
275
332
  true, // isSecondary
276
333
  this.gNode, this.bufferGNode, this.nodeDefs, this.bufferedNodeDefs);
277
334
  return copy;
@@ -286,13 +343,27 @@ export class drawutilssvg {
286
343
  setConfiguration(configuration) {
287
344
  this.drawlibConfiguration = configuration;
288
345
  }
346
+ // /**
347
+ // * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
348
+ // *
349
+ // * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
350
+ // * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
351
+ // * for how line dashes work.
352
+ // *
353
+ // * @method
354
+ // * @param {Array<number> lineDashes - The line-dash array configuration.
355
+ // * @returns {void}
356
+ // */
357
+ // setLineDash(lineDashes: Array<number>) {
358
+ // this.lineDash = lineDashes;
359
+ // }
289
360
  /**
290
361
  * This method shouled be called each time the currently drawn `Drawable` changes.
291
362
  * It is used by some libraries for identifying elemente on re-renders.
292
363
  *
293
364
  * @name setCurrentId
294
365
  * @method
295
- * @param {UID} uid - A UID identifying the currently drawn element(s).
366
+ * @param {UID|null} uid - A UID identifying the currently drawn element(s).
296
367
  * @instance
297
368
  * @memberof drawutilssvg
298
369
  **/
@@ -305,7 +376,7 @@ export class drawutilssvg {
305
376
  *
306
377
  * @name setCurrentClassName
307
378
  * @method
308
- * @param {string} className - A class name for further custom use cases.
379
+ * @param {string|null} className - A class name for further custom use cases.
309
380
  * @instance
310
381
  * @memberof drawutilssvg
311
382
  **/
@@ -360,6 +431,26 @@ export class drawutilssvg {
360
431
  this.nodeDefs = this.bufferedNodeDefs;
361
432
  this.bufferedNodeDefs = tmpDefsNode;
362
433
  }
434
+ /**
435
+ * A private helper method to apply stroke options to the current
436
+ * context.
437
+ * @param {StrokeOptions=} strokeOptions -
438
+ */
439
+ applyStrokeOpts(node, strokeOptions) {
440
+ if (strokeOptions &&
441
+ strokeOptions.dashArray &&
442
+ strokeOptions.dashArray.length > 0 &&
443
+ drawutilssvg.nodeSupportsLineDash(node.tagName)) {
444
+ node.setAttribute("stroke-dasharray", strokeOptions.dashArray
445
+ .map((dashArayElem) => {
446
+ return dashArayElem * this.scale.x;
447
+ })
448
+ .join(" "));
449
+ if (strokeOptions.dashOffset) {
450
+ node.setAttribute("stroke-dashoffset", `${strokeOptions.dashOffset * this.scale.x}`);
451
+ }
452
+ }
453
+ }
363
454
  _x(x) {
364
455
  return this.offset.x + this.scale.x * x;
365
456
  }
@@ -370,47 +461,101 @@ export class drawutilssvg {
370
461
  * Draw the line between the given two points with the specified (CSS-) color.
371
462
  *
372
463
  * @method line
373
- * @param {Vertex} zA - The start point of the line.
374
- * @param {Vertex} zB - The end point of the line.
464
+ * @param {XYCoords} zA - The start point of the line.
465
+ * @param {XYCoords} zB - The end point of the line.
375
466
  * @param {string} color - Any valid CSS color string.
376
467
  * @param {number=1} lineWidth? - [optional] The line's width.
468
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
469
+ *
377
470
  * @return {void}
378
471
  * @instance
379
472
  * @memberof drawutilssvg
380
473
  **/
381
- line(zA, zB, color, lineWidth) {
382
- const line = this.makeNode("line");
383
- line.setAttribute("x1", `${this._x(zA.x)}`);
384
- line.setAttribute("y1", `${this._y(zA.y)}`);
385
- line.setAttribute("x2", `${this._x(zB.x)}`);
386
- line.setAttribute("y2", `${this._y(zB.y)}`);
387
- return this._bindFillDraw(line, "line", color, lineWidth || 1);
474
+ line(zA, zB, color, lineWidth, strokeOptions) {
475
+ // const line: SVGElement = this.makeNode("line");
476
+ // this.applyStrokeOpts(line, strokeOptions);
477
+ // line.setAttribute("x1", `${this._x(zA.x)}`);
478
+ // line.setAttribute("y1", `${this._y(zA.y)}`);
479
+ // line.setAttribute("x2", `${this._x(zB.x)}`);
480
+ // line.setAttribute("y2", `${this._y(zB.y)}`);
481
+ const line = this.makeLineNode(zA, zB, color, lineWidth, strokeOptions);
482
+ return this._bindFillDraw(line, "line", color, lineWidth || 1, strokeOptions);
388
483
  }
389
484
  /**
390
485
  * Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
391
486
  *
392
487
  * @method arrow
393
- * @param {Vertex} zA - The start point of the arrow-line.
394
- * @param {Vertex} zB - The end point of the arrow-line.
488
+ * @param {XYCoords} zA - The start point of the arrow-line.
489
+ * @param {XYCoords} zB - The end point of the arrow-line.
395
490
  * @param {string} color - Any valid CSS color string.
396
491
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
492
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
493
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
494
+ *
397
495
  * @return {void}
398
496
  * @instance
399
497
  * @memberof drawutilssvg
400
498
  **/
401
- arrow(zA, zB, color, lineWidth) {
402
- const node = this.makeNode("path");
403
- var headlen = 8; // length of head in pixels
404
- var vertices = Vertex.utils.buildArrowHead(zA, zB, headlen, this.scale.x, this.scale.y);
405
- const d = ["M", this._x(zA.x), this._y(zA.y)];
406
- for (var i = 0; i <= vertices.length; i++) {
407
- d.push("L");
408
- // Note: only use offset here (the vertices are already scaled)
409
- d.push(this.offset.x + vertices[i % vertices.length].x);
410
- d.push(this.offset.y + vertices[i % vertices.length].y);
411
- }
412
- node.setAttribute("d", d.join(" "));
413
- return this._bindFillDraw(node, "arrow", color, lineWidth || 1);
499
+ arrow(zA, zB, color, lineWidth, headLength = 8, strokeOptions) {
500
+ const group = this.makeNode("g");
501
+ const arrowHeadBasePosition = { x: 0, y: 0 };
502
+ // Just create the child nodes, don't bind them to the root node.
503
+ const arrowHead = this.makeArrowHeadNode(zA, zB, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
504
+ const line = this.makeLineNode(zA, arrowHeadBasePosition, color, lineWidth, strokeOptions);
505
+ group.appendChild(line);
506
+ group.appendChild(arrowHead);
507
+ this._addCSSClasses(group, "linear-arrow");
508
+ this._bindNode(group, undefined);
509
+ return group;
510
+ }
511
+ /**
512
+ * 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.
513
+ *
514
+ * @method cubicBezierArrow
515
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
516
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
517
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
518
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
519
+ * @param {string} color - The CSS color to draw the curve with.
520
+ * @param {number} lineWidth - (optional) The line width to use.
521
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
522
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
523
+ *
524
+ * @return {void}
525
+ * @instance
526
+ * @memberof DrawLib
527
+ */
528
+ cubicBezierArrow(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, headLength = 8, strokeOptions) {
529
+ const group = this.makeNode("g");
530
+ // Just create the child nodes, don't bind them to the root node.
531
+ const arrowHeadBasePosition = new Vertex(0, 0);
532
+ const arrowHead = this.makeArrowHeadNode(endControlPoint, endPoint, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
533
+ const diff = arrowHeadBasePosition.difference(endPoint);
534
+ const 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);
535
+ group.appendChild(bezier);
536
+ group.appendChild(arrowHead);
537
+ this._addCSSClasses(group, "cubicbezier-arrow");
538
+ this._bindNode(group, undefined);
539
+ return group;
540
+ }
541
+ /**
542
+ * Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
543
+ *
544
+ * @method arrow
545
+ * @param {XYCoords} zA - The start point of the arrow-line.
546
+ * @param {XYCoords} zB - The end point of the arrow-line.
547
+ * @param {string} color - Any valid CSS color string.
548
+ * @param {number=1} lineWidth - (optional) The line width to use; default is 1.
549
+ * @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
550
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
551
+ *
552
+ * @return {void}
553
+ * @instance
554
+ * @memberof DrawLib
555
+ **/
556
+ arrowHead(zA, zB, color, lineWidth, headLength = 8, strokeOptions) {
557
+ const node = this.makeArrowHeadNode(zA, zB, color, lineWidth, headLength, strokeOptions);
558
+ return this._bindFillDraw(node, "arrowhead", color, lineWidth || 1, strokeOptions);
414
559
  }
415
560
  /**
416
561
  * Draw an image at the given position with the given size.<br>
@@ -419,8 +564,8 @@ export class drawutilssvg {
419
564
  *
420
565
  * @method image
421
566
  * @param {Image} image - The image object to draw.
422
- * @param {Vertex} position - The position to draw the the upper left corner at.
423
- * @param {Vertex} size - The x/y-size to draw the image with.
567
+ * @param {XYCoords} position - The position to draw the the upper left corner at.
568
+ * @param {XYCoords} size - The x/y-size to draw the image with.
424
569
  * @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
425
570
  * @return {void}
426
571
  * @instance
@@ -463,16 +608,16 @@ export class drawutilssvg {
463
608
  * @param {Image} textureImage - The image object to draw.
464
609
  * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
465
610
  * @param {Polygon} polygon - The polygon to use as clip path.
466
- * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
611
+ * @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
467
612
  * @param {number} rotation - The rotation to use for the polygon (and for the texture).
468
613
  * @return {void}
469
614
  * @instance
470
615
  * @memberof drawutilssvg
471
616
  **/
472
617
  texturedPoly(textureImage, textureSize, polygon, polygonPosition, rotation) {
473
- const basePolygonBounds = polygon.getBounds();
618
+ // const basePolygonBounds: Bounds = polygon.getBounds();
474
619
  const rotatedScalingOrigin = new Vertex(textureSize.min).clone().rotate(rotation, polygonPosition);
475
- const rotationCenter = polygonPosition.clone().add(rotatedScalingOrigin.difference(textureSize.min).inv());
620
+ // const rotationCenter = polygonPosition.clone().add(rotatedScalingOrigin.difference(textureSize.min).inv());
476
621
  // Create something like this
477
622
  // ...
478
623
  // <defs>
@@ -527,36 +672,21 @@ export class drawutilssvg {
527
672
  * Draw the given (cubic) bézier curve.
528
673
  *
529
674
  * @method cubicBezier
530
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
531
- * @param {Vertex} endPoint - The end point the cubic Bézier curve.
532
- * @param {Vertex} startControlPoint - The start control point the cubic Bézier curve.
533
- * @param {Vertex} endControlPoint - The end control point the cubic Bézier curve.
675
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
676
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
677
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
678
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
534
679
  * @param {string} color - The CSS color to draw the curve with.
535
680
  * @param {number} lineWidth - (optional) The line width to use.
681
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
682
+ *
536
683
  * @return {void}
537
684
  * @instance
538
685
  * @memberof drawutilssvg
539
686
  */
540
- cubicBezier(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth) {
541
- if (startPoint instanceof CubicBezierCurve) {
542
- return this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
543
- }
544
- const node = this.makeNode("path");
545
- // Draw curve
546
- const d = [
547
- "M",
548
- this._x(startPoint.x),
549
- this._y(startPoint.y),
550
- "C",
551
- this._x(startControlPoint.x),
552
- this._y(startControlPoint.y),
553
- this._x(endControlPoint.x),
554
- this._y(endControlPoint.y),
555
- this._x(endPoint.x),
556
- this._y(endPoint.y)
557
- ];
558
- node.setAttribute("d", d.join(" "));
559
- return this._bindFillDraw(node, "cubierBezier", color, lineWidth);
687
+ cubicBezier(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
688
+ const node = this.makeCubicBezierNode(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions);
689
+ return this._bindNode(node, undefined);
560
690
  }
561
691
  /**
562
692
  * Draw the given (cubic) Bézier path.
@@ -566,17 +696,21 @@ export class drawutilssvg {
566
696
  * <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
567
697
  *
568
698
  * @method cubicBezierPath
569
- * @param {Vertex[]} path - The cubic bezier path as described above.
699
+ * @param {XYCoords[]} path - The cubic bezier path as described above.
570
700
  * @param {string} color - The CSS colot to draw the path with.
571
701
  * @param {number=1} lineWidth - (optional) The line width to use.
702
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
703
+ *
572
704
  * @return {void}
573
705
  * @instance
574
706
  * @memberof drawutilssvg
575
707
  */
576
- cubicBezierPath(path, color, lineWidth) {
708
+ cubicBezierPath(path, color, lineWidth, strokeOptions) {
577
709
  const node = this.makeNode("path");
578
- if (!path || path.length == 0)
710
+ this.applyStrokeOpts(node, strokeOptions);
711
+ if (!path || path.length == 0) {
579
712
  return node;
713
+ }
580
714
  // Draw curve
581
715
  const d = ["M", this._x(path[0].x), this._y(path[0].y)];
582
716
  // Draw curve path
@@ -613,20 +747,20 @@ export class drawutilssvg {
613
747
  * Draw a handle line (with a light grey).
614
748
  *
615
749
  * @method handleLine
616
- * @param {Vertex} startPoint - The start point to draw the handle at.
617
- * @param {Vertex} endPoint - The end point to draw the handle at.
750
+ * @param {XYCoords} startPoint - The start point to draw the handle at.
751
+ * @param {XYCoords} endPoint - The end point to draw the handle at.
618
752
  * @return {void}
619
753
  * @instance
620
754
  * @memberof drawutilssvg
621
755
  */
622
756
  handleLine(startPoint, endPoint) {
623
- this.line(startPoint, endPoint, "rgb(192,192,192)");
757
+ this.line(startPoint, endPoint, "rgb(128,128,128,0.5)");
624
758
  }
625
759
  /**
626
760
  * Draw a 1x1 dot with the specified (CSS-) color.
627
761
  *
628
762
  * @method dot
629
- * @param {Vertex} p - The position to draw the dot at.
763
+ * @param {XYCoords} p - The position to draw the dot at.
630
764
  * @param {string} color - The CSS color to draw the dot with.
631
765
  * @return {void}
632
766
  * @instance
@@ -634,13 +768,17 @@ export class drawutilssvg {
634
768
  */
635
769
  dot(p, color) {
636
770
  const node = this.makeNode("line");
771
+ node.setAttribute("x1", `${this._x(p.x)}`);
772
+ node.setAttribute("y1", `${this._y(p.y)}`);
773
+ node.setAttribute("x2", `${this._x(p.x)}`);
774
+ node.setAttribute("y2", `${this._y(p.y)}`);
637
775
  return this._bindFillDraw(node, "dot", color, 1);
638
776
  }
639
777
  /**
640
778
  * Draw the given point with the specified (CSS-) color and radius 3.
641
779
  *
642
780
  * @method point
643
- * @param {Vertex} p - The position to draw the point at.
781
+ * @param {XYCoords} p - The position to draw the point at.
644
782
  * @param {string} color - The CSS color to draw the point with.
645
783
  * @return {void}
646
784
  * @instance
@@ -660,17 +798,20 @@ export class drawutilssvg {
660
798
  * Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
661
799
  *
662
800
  * @method circle
663
- * @param {Vertex} center - The center of the circle.
801
+ * @param {XYCoords} center - The center of the circle.
664
802
  * @param {number} radius - The radius of the circle.
665
803
  * @param {string} color - The CSS color to draw the circle with.
666
804
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
805
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
806
+ *
667
807
  * @return {void}
668
808
  * @instance
669
809
  * @memberof drawutilssvg
670
810
  */
671
- circle(center, radius, color, lineWidth) {
811
+ circle(center, radius, color, lineWidth, strokeOptions) {
672
812
  // Todo: draw ellipse when scalex!=scaley
673
813
  const node = this.makeNode("circle");
814
+ this.applyStrokeOpts(node, strokeOptions);
674
815
  node.setAttribute("cx", `${this._x(center.x)}`);
675
816
  node.setAttribute("cy", `${this._y(center.y)}`);
676
817
  node.setAttribute("r", `${radius * this.scale.x}`); // y?
@@ -680,17 +821,20 @@ export class drawutilssvg {
680
821
  * Draw a circular arc (section of a circle) with the given CSS color.
681
822
  *
682
823
  * @method circleArc
683
- * @param {Vertex} center - The center of the circle.
824
+ * @param {XYCoords} center - The center of the circle.
684
825
  * @param {number} radius - The radius of the circle.
685
826
  * @param {number} startAngle - The angle to start at.
686
827
  * @param {number} endAngle - The angle to end at.
687
828
  * @param {string} color - The CSS color to draw the circle with.
829
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
830
+ *
688
831
  * @return {void}
689
832
  * @instance
690
833
  * @memberof drawutilssvg
691
834
  */
692
- circleArc(center, radius, startAngle, endAngle, color, lineWidth) {
835
+ circleArc(center, radius, startAngle, endAngle, color, lineWidth, strokeOptions) {
693
836
  const node = this.makeNode("path");
837
+ this.applyStrokeOpts(node, strokeOptions);
694
838
  const arcData = CircleSector.circleSectorUtils.describeSVGArc(this._x(center.x), this._y(center.y), radius * this.scale.x, // y?
695
839
  startAngle, endAngle);
696
840
  node.setAttribute("d", arcData.join(" "));
@@ -700,21 +844,24 @@ export class drawutilssvg {
700
844
  * Draw an ellipse with the specified (CSS-) color and thw two radii.
701
845
  *
702
846
  * @method ellipse
703
- * @param {Vertex} center - The center of the ellipse.
847
+ * @param {XYCoords} center - The center of the ellipse.
704
848
  * @param {number} radiusX - The radius of the ellipse.
705
849
  * @param {number} radiusY - The radius of the ellipse.
706
850
  * @param {string} color - The CSS color to draw the ellipse with.
707
851
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
708
852
  * @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
853
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
854
+ *
709
855
  * @return {void}
710
856
  * @instance
711
857
  * @memberof drawutilssvg
712
858
  */
713
- ellipse(center, radiusX, radiusY, color, lineWidth, rotation) {
859
+ ellipse(center, radiusX, radiusY, color, lineWidth, rotation, strokeOptions) {
714
860
  if (typeof rotation === "undefined") {
715
861
  rotation = 0.0;
716
862
  }
717
863
  const node = this.makeNode("ellipse");
864
+ this.applyStrokeOpts(node, strokeOptions);
718
865
  node.setAttribute("cx", `${this._x(center.x)}`);
719
866
  node.setAttribute("cy", `${this._y(center.y)}`);
720
867
  node.setAttribute("rx", `${radiusX * this.scale.x}`);
@@ -730,15 +877,18 @@ export class drawutilssvg {
730
877
  *
731
878
  * @method square
732
879
  * @param {XYCoords} center - The center of the square.
733
- * @param {Vertex} size - The size of the square.
880
+ * @param {number} size - The size of the square.
734
881
  * @param {string} color - The CSS color to draw the square with.
735
882
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
736
- * @return {void}
883
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
884
+ *
885
+ * @return {SVGElement}
737
886
  * @instance
738
887
  * @memberof drawutilssvg
739
888
  */
740
- square(center, size, color, lineWidth) {
889
+ square(center, size, color, lineWidth, strokeOptions) {
741
890
  const node = this.makeNode("rectangle");
891
+ this.applyStrokeOpts(node, strokeOptions);
742
892
  node.setAttribute("x", `${this._x(center.x - size / 2.0)}`);
743
893
  node.setAttribute("y", `${this._y(center.y - size / 2.0)}`);
744
894
  node.setAttribute("width", `${size * this.scale.x}`);
@@ -753,9 +903,15 @@ export class drawutilssvg {
753
903
  * @param {number} height - The height of the rectangle.
754
904
  * @param {string} color - The color to use.
755
905
  * @param {number=1} lineWidth - (optional) The line with to use (default is 1).
906
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
907
+ *
908
+ * @return {SVGElement}
909
+ * @instance
910
+ * @memberof drawutilssvg
756
911
  **/
757
- rect(position, width, height, color, lineWidth) {
912
+ rect(position, width, height, color, lineWidth, strokeOptions) {
758
913
  const node = this.makeNode("rect");
914
+ this.applyStrokeOpts(node, strokeOptions);
759
915
  node.setAttribute("x", `${this._x(position.x)}`);
760
916
  node.setAttribute("y", `${this._y(position.y)}`);
761
917
  node.setAttribute("width", `${width * this.scale.x}`);
@@ -766,7 +922,7 @@ export class drawutilssvg {
766
922
  * Draw a grid of horizontal and vertical lines with the given (CSS-) color.
767
923
  *
768
924
  * @method grid
769
- * @param {Vertex} center - The center of the grid.
925
+ * @param {XYCoords} center - The center of the grid.
770
926
  * @param {number} width - The total width of the grid (width/2 each to the left and to the right).
771
927
  * @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
772
928
  * @param {number} sizeX - The horizontal grid size.
@@ -800,7 +956,7 @@ export class drawutilssvg {
800
956
  * This works analogue to the grid() function
801
957
  *
802
958
  * @method raster
803
- * @param {Vertex} center - The center of the raster.
959
+ * @param {XYCoords} center - The center of the raster.
804
960
  * @param {number} width - The total width of the raster (width/2 each to the left and to the right).
805
961
  * @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
806
962
  * @param {number} sizeX - The horizontal raster size.
@@ -833,8 +989,8 @@ export class drawutilssvg {
833
989
  * as even shaped diamonds.
834
990
  *
835
991
  * @method diamondHandle
836
- * @param {Vertex} center - The center of the diamond.
837
- * @param {Vertex} size - The x/y-size of the diamond.
992
+ * @param {XYCoords} center - The center of the diamond.
993
+ * @param {number} size - The x/y-size of the diamond.
838
994
  * @param {string} color - The CSS color to draw the diamond with.
839
995
  * @return {void}
840
996
  * @instance
@@ -868,8 +1024,8 @@ export class drawutilssvg {
868
1024
  * as even shaped squares.
869
1025
  *
870
1026
  * @method squareHandle
871
- * @param {Vertex} center - The center of the square.
872
- * @param {Vertex} size - The x/y-size of the square.
1027
+ * @param {XYCoords} center - The center of the square.
1028
+ * @param {XYCoords} size - The x/y-size of the square.
873
1029
  * @param {string} color - The CSS color to draw the square with.
874
1030
  * @return {void}
875
1031
  * @instance
@@ -891,7 +1047,7 @@ export class drawutilssvg {
891
1047
  * as even shaped circles.
892
1048
  *
893
1049
  * @method circleHandle
894
- * @param {Vertex} center - The center of the circle.
1050
+ * @param {XYCoords} center - The center of the circle.
895
1051
  * @param {number} radius - The radius of the circle.
896
1052
  * @param {string} color - The CSS color to draw the circle with.
897
1053
  * @return {void}
@@ -990,18 +1146,22 @@ export class drawutilssvg {
990
1146
  * Draw a polygon line (alternative function to the polygon).
991
1147
  *
992
1148
  * @method polyline
993
- * @param {Vertex[]} vertices - The polygon vertices to draw.
1149
+ * @param {XYCoords[]} vertices - The polygon vertices to draw.
994
1150
  * @param {boolan} isOpen - If true the polyline will not be closed at its end.
995
1151
  * @param {string} color - The CSS color to draw the polygon with.
996
1152
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
1153
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
1154
+ *
997
1155
  * @return {void}
998
1156
  * @instance
999
1157
  * @memberof drawutilssvg
1000
1158
  */
1001
- polyline(vertices, isOpen, color, lineWidth) {
1159
+ polyline(vertices, isOpen, color, lineWidth, strokeOptions) {
1002
1160
  const node = this.makeNode("path");
1003
- if (vertices.length == 0)
1161
+ this.applyStrokeOpts(node, strokeOptions);
1162
+ if (vertices.length == 0) {
1004
1163
  return node;
1164
+ }
1005
1165
  // Draw curve
1006
1166
  const d = ["M", this._x(vertices[0].x), this._y(vertices[0].y)];
1007
1167
  var n = vertices.length;
@@ -1104,12 +1264,16 @@ export class drawutilssvg {
1104
1264
  * @param {string=null} color - (optional) The color to draw this path with (default is null).
1105
1265
  * @param {number=1} lineWidth - (optional) the line width to use (default is 1).
1106
1266
  * @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.
1267
+ * @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
1268
+ * @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
1269
+ *
1107
1270
  * @instance
1108
1271
  * @memberof drawutils
1109
1272
  * @return {R} An instance representing the drawn path.
1110
1273
  */
1111
1274
  path(pathData, color, lineWidth, options) {
1112
1275
  const node = this.makeNode("path");
1276
+ this.applyStrokeOpts(node, options);
1113
1277
  // Transform the path: in-place (fast) or copy (slower)
1114
1278
  const d = options && options.inplace ? pathData : drawutilssvg.copyPathData(pathData);
1115
1279
  drawutilssvg.transformPathData(d, this.offset, this.scale);
@@ -1135,7 +1299,7 @@ export class drawutilssvg {
1135
1299
  }
1136
1300
  // Add a covering rect with the given background color
1137
1301
  this.curId = "background";
1138
- this.curClassName = undefined;
1302
+ this.curClassName = null; // undefined;
1139
1303
  const node = this.makeNode("rect");
1140
1304
  // For some strange reason SVG rotation transforms use degrees instead of radians
1141
1305
  // Note that the background does not scale with the zoom level (always covers full element)
@@ -1147,7 +1311,7 @@ export class drawutilssvg {
1147
1311
  this._bindFillDraw(node, this.curId, null, null);
1148
1312
  node.setAttribute("fill", typeof color === "undefined" ? "none" : color);
1149
1313
  // Clear the current ID again
1150
- this.curId = undefined;
1314
+ this.curId = null; // undefined;
1151
1315
  }
1152
1316
  /**
1153
1317
  * A private helper function to clear all SVG nodes from the &gt;g> node.
@@ -1352,6 +1516,126 @@ export class drawutilssvg {
1352
1516
  }
1353
1517
  } // END while
1354
1518
  } // END transformPathData
1519
+ static nodeSupportsLineDash(nodeName) {
1520
+ return ["line", "path", "circle", "ellipse", "rectangle", "rect"].includes(nodeName);
1521
+ }
1522
+ /**
1523
+ * Creates a basic <line> node with start and end coordinates. The created node will not
1524
+ * be bound to any root node.
1525
+ *
1526
+ * @private
1527
+ * @method makeLineNode
1528
+ * @param {XYCoords} zA - The line's start position.
1529
+ * @param {XYCoords} zB - The line's start position.
1530
+ * @param {string} color - The CSS color to draw the point with.
1531
+ * @param {number=1} lineWidth - (optional) The line width to use.
1532
+ * @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
1533
+ * @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
1534
+ * @return {SVGLineElement}
1535
+ * @instance
1536
+ * @memberof drawutilssvg
1537
+ */
1538
+ makeLineNode(zA, zB, color, lineWidth, strokeOptions, classNameOverride) {
1539
+ const line = this.makeNode("line");
1540
+ line.setAttribute("x1", `${this._x(zA.x)}`);
1541
+ line.setAttribute("y1", `${this._y(zA.y)}`);
1542
+ line.setAttribute("x2", `${this._x(zB.x)}`);
1543
+ line.setAttribute("y2", `${this._y(zB.y)}`);
1544
+ this._configureNode(line, classNameOverride !== null && classNameOverride !== void 0 ? classNameOverride : "line", this.fillShapes, color, lineWidth || 1, strokeOptions);
1545
+ return line;
1546
+ }
1547
+ /**
1548
+ * Creates a basic <path> node with given path string data. The created node will not
1549
+ * be bound to any root node.
1550
+ *
1551
+ * @private
1552
+ * @method makePathNode
1553
+ * @param {string} pathString - The path data (must be a valid path data string).
1554
+ * @param {string} color - The CSS color to draw the point with.
1555
+ * @param {number=1} lineWidth - (optional) The line width to use.
1556
+ * @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
1557
+ * @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
1558
+ * @return {SVGPathElement}
1559
+ * @instance
1560
+ * @memberof drawutilssvg
1561
+ */
1562
+ makePathNode(pathString, color, lineWidth, strokeOptions, classNameOverride) {
1563
+ const path = this.makeNode("path");
1564
+ path.setAttribute("d", pathString);
1565
+ this._configureNode(path, classNameOverride !== null && classNameOverride !== void 0 ? classNameOverride : "path", this.fillShapes, color, lineWidth || 1, strokeOptions);
1566
+ return path;
1567
+ }
1568
+ /**
1569
+ * Creates a basic arrow head node (<path> node) at the end of the given line coordinates. The created node will not
1570
+ * be bound to any root node.
1571
+ *
1572
+ * @private
1573
+ * @method makeArrowHeadNode
1574
+ * @param {string} pathString - The path data (must be a valid path data string).
1575
+ * @param {string} color - The CSS color to draw the point with.
1576
+ * @param {number=1} lineWidth - (optional) The line width to use.
1577
+ * @param {number=8} headLength - (optional) The length of the arrow head; if none is specified then the head will be 8 absolute units long.
1578
+ * @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
1579
+ * @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.
1580
+ * @return {SVGPathElement}
1581
+ * @instance
1582
+ * @memberof drawutilssvg
1583
+ */
1584
+ makeArrowHeadNode(zA, zB, color, lineWidth, headLength = 8, strokeOptions, arrowHeadBasePositionBuffer) {
1585
+ var vertices = Vector.utils.buildArrowHead(zA, zB, headLength, this.scale.x, this.scale.y);
1586
+ const d = ["M", this.offset.x + vertices[0].x, this.offset.y + vertices[0].y];
1587
+ if (arrowHeadBasePositionBuffer) {
1588
+ arrowHeadBasePositionBuffer.x = vertices[0].x / this.scale.x;
1589
+ arrowHeadBasePositionBuffer.y = vertices[0].y / this.scale.y;
1590
+ }
1591
+ for (var i = 1; i <= vertices.length; i++) {
1592
+ d.push("L");
1593
+ // Note: only use offset here (the vertices are already scaled)
1594
+ d.push(this.offset.x + vertices[i % vertices.length].x);
1595
+ d.push(this.offset.y + vertices[i % vertices.length].y);
1596
+ }
1597
+ const node = this.makePathNode(d.join(" "), color, lineWidth, strokeOptions, "arrowhead");
1598
+ return node;
1599
+ }
1600
+ /**
1601
+ * Creates a basic cubic Bézier path node (<path> node) with the given cubic Bézier data. The created node will not
1602
+ * be bound to any root node.
1603
+ *
1604
+ * @private
1605
+ * @method makeCubicBezierNode
1606
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
1607
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
1608
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
1609
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
1610
+ * @param {string} color - The CSS color to draw the point with.
1611
+ * @param {number=1} lineWidth - (optional) The line width to use.
1612
+ * @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
1613
+ * @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
1614
+ * @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.
1615
+ * @return {SVGPathElement}
1616
+ * @instance
1617
+ * @memberof drawutilssvg
1618
+ */
1619
+ makeCubicBezierNode(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
1620
+ if (startPoint instanceof CubicBezierCurve) {
1621
+ return this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
1622
+ }
1623
+ // Draw curve
1624
+ const d = [
1625
+ "M",
1626
+ this._x(startPoint.x),
1627
+ this._y(startPoint.y),
1628
+ "C",
1629
+ this._x(startControlPoint.x),
1630
+ this._y(startControlPoint.y),
1631
+ this._x(endControlPoint.x),
1632
+ this._y(endControlPoint.y),
1633
+ this._x(endPoint.x),
1634
+ this._y(endPoint.y)
1635
+ ];
1636
+ const node = this.makePathNode(d.join(" "), color, lineWidth, strokeOptions, "cubicBezier");
1637
+ return node;
1638
+ }
1355
1639
  }
1356
1640
  drawutilssvg.HEAD_XML = [
1357
1641
  '<?xml version="1.0" encoding="UTF-8" standalone="no"?>',