plotboilerplate 1.16.0 → 1.17.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 (173) hide show
  1. package/README.md +1 -0
  2. package/changelog.md +26 -1
  3. package/dist/index.esm.js +355 -441
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.esm.min.js +1 -1
  6. package/dist/index.esm.min.js.map +1 -1
  7. package/dist/plotboilerplate.browser.min.js +1 -1
  8. package/dist/plotboilerplate.browser.min.js.map +1 -1
  9. package/dist/plotboilerplate.js +357 -345
  10. package/dist/plotboilerplate.min.js +1 -1
  11. package/package.json +1 -1
  12. package/src/cjs/BezierPath.d.ts +0 -14
  13. package/src/cjs/BezierPath.js +0 -26
  14. package/src/cjs/BezierPath.js.map +1 -1
  15. package/src/cjs/Bounds.d.ts +22 -1
  16. package/src/cjs/Bounds.js +24 -1
  17. package/src/cjs/Bounds.js.map +1 -1
  18. package/src/cjs/Circle.d.ts +0 -13
  19. package/src/cjs/Circle.js +0 -23
  20. package/src/cjs/Circle.js.map +1 -1
  21. package/src/cjs/CircleSector.d.ts +0 -13
  22. package/src/cjs/CircleSector.js +0 -27
  23. package/src/cjs/CircleSector.js.map +1 -1
  24. package/src/cjs/CubicBezierCurve.d.ts +0 -15
  25. package/src/cjs/CubicBezierCurve.js +0 -36
  26. package/src/cjs/CubicBezierCurve.js.map +1 -1
  27. package/src/cjs/Line.d.ts +0 -14
  28. package/src/cjs/Line.js +0 -26
  29. package/src/cjs/Line.js.map +1 -1
  30. package/src/cjs/PBImage.d.ts +0 -13
  31. package/src/cjs/PBImage.js +0 -14
  32. package/src/cjs/PBImage.js.map +1 -1
  33. package/src/cjs/PBText.d.ts +0 -13
  34. package/src/cjs/PBText.js +0 -14
  35. package/src/cjs/PBText.js.map +1 -1
  36. package/src/cjs/Polygon.d.ts +9 -15
  37. package/src/cjs/Polygon.js +12 -39
  38. package/src/cjs/Polygon.js.map +1 -1
  39. package/src/cjs/Triangle.d.ts +0 -13
  40. package/src/cjs/Triangle.js +0 -37
  41. package/src/cjs/Triangle.js.map +1 -1
  42. package/src/cjs/VEllipse.d.ts +0 -10
  43. package/src/cjs/VEllipse.js +0 -21
  44. package/src/cjs/VEllipse.js.map +1 -1
  45. package/src/cjs/Vector.d.ts +0 -14
  46. package/src/cjs/Vector.js +0 -36
  47. package/src/cjs/Vector.js.map +1 -1
  48. package/src/cjs/Vertex.d.ts +0 -14
  49. package/src/cjs/Vertex.js +0 -25
  50. package/src/cjs/Vertex.js.map +1 -1
  51. package/src/cjs/draw.d.ts +41 -2
  52. package/src/cjs/draw.js +140 -3
  53. package/src/cjs/draw.js.map +1 -1
  54. package/src/cjs/drawgl.d.ts +38 -2
  55. package/src/cjs/drawgl.js +41 -2
  56. package/src/cjs/drawgl.js.map +1 -1
  57. package/src/cjs/drawutilssvg.d.ts +66 -3
  58. package/src/cjs/drawutilssvg.js +140 -15
  59. package/src/cjs/drawutilssvg.js.map +1 -1
  60. package/src/cjs/index.d.ts +0 -1
  61. package/src/cjs/index.js +0 -1
  62. package/src/cjs/index.js.map +1 -1
  63. package/src/cjs/interfaces/DrawLib.d.ts +61 -26
  64. package/src/cjs/interfaces/DrawLib.js +2 -0
  65. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  66. package/src/cjs/interfaces/core.d.ts +0 -12
  67. package/src/cjs/module.d.ts +1 -3
  68. package/src/cjs/module.js +2 -5
  69. package/src/cjs/module.js.map +1 -1
  70. package/src/cjs/utils/creategui.js +16 -2
  71. package/src/cjs/utils/datastructures/Girih.d.ts +5 -0
  72. package/src/cjs/utils/datastructures/Girih.js +18 -14
  73. package/src/cjs/utils/datastructures/Girih.js.map +1 -1
  74. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js +42 -25
  75. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  76. package/src/cjs/utils/datastructures/GirihTile.js +2 -13
  77. package/src/cjs/utils/datastructures/GirihTile.js.map +1 -1
  78. package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +2 -1
  79. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +9 -18
  80. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  81. package/src/esm/BezierPath.d.ts +0 -14
  82. package/src/esm/BezierPath.js +0 -26
  83. package/src/esm/BezierPath.js.map +1 -1
  84. package/src/esm/Bounds.d.ts +22 -1
  85. package/src/esm/Bounds.js +24 -1
  86. package/src/esm/Bounds.js.map +1 -1
  87. package/src/esm/Circle.d.ts +0 -13
  88. package/src/esm/Circle.js +0 -23
  89. package/src/esm/Circle.js.map +1 -1
  90. package/src/esm/CircleSector.d.ts +0 -13
  91. package/src/esm/CircleSector.js +0 -27
  92. package/src/esm/CircleSector.js.map +1 -1
  93. package/src/esm/CubicBezierCurve.d.ts +0 -15
  94. package/src/esm/CubicBezierCurve.js +0 -36
  95. package/src/esm/CubicBezierCurve.js.map +1 -1
  96. package/src/esm/Line.d.ts +0 -14
  97. package/src/esm/Line.js +0 -26
  98. package/src/esm/Line.js.map +1 -1
  99. package/src/esm/PBImage.d.ts +0 -13
  100. package/src/esm/PBImage.js +0 -14
  101. package/src/esm/PBImage.js.map +1 -1
  102. package/src/esm/PBText.d.ts +0 -13
  103. package/src/esm/PBText.js +0 -14
  104. package/src/esm/PBText.js.map +1 -1
  105. package/src/esm/Polygon.d.ts +9 -15
  106. package/src/esm/Polygon.js +12 -39
  107. package/src/esm/Polygon.js.map +1 -1
  108. package/src/esm/Triangle.d.ts +0 -13
  109. package/src/esm/Triangle.js +0 -37
  110. package/src/esm/Triangle.js.map +1 -1
  111. package/src/esm/VEllipse.d.ts +0 -10
  112. package/src/esm/VEllipse.js +0 -21
  113. package/src/esm/VEllipse.js.map +1 -1
  114. package/src/esm/Vector.d.ts +0 -14
  115. package/src/esm/Vector.js +0 -36
  116. package/src/esm/Vector.js.map +1 -1
  117. package/src/esm/Vertex.d.ts +0 -14
  118. package/src/esm/Vertex.js +0 -25
  119. package/src/esm/Vertex.js.map +1 -1
  120. package/src/esm/draw.d.ts +41 -2
  121. package/src/esm/draw.js +139 -3
  122. package/src/esm/draw.js.map +1 -1
  123. package/src/esm/drawgl.d.ts +38 -2
  124. package/src/esm/drawgl.js +41 -2
  125. package/src/esm/drawgl.js.map +1 -1
  126. package/src/esm/drawutilssvg.d.ts +66 -3
  127. package/src/esm/drawutilssvg.js +140 -15
  128. package/src/esm/drawutilssvg.js.map +1 -1
  129. package/src/esm/index.d.ts +0 -1
  130. package/src/esm/index.js +0 -1
  131. package/src/esm/index.js.map +1 -1
  132. package/src/esm/interfaces/DrawLib.d.ts +61 -26
  133. package/src/esm/interfaces/DrawLib.js +2 -0
  134. package/src/esm/interfaces/DrawLib.js.map +1 -1
  135. package/src/esm/interfaces/core.d.ts +0 -12
  136. package/src/esm/module.d.ts +1 -3
  137. package/src/esm/module.js +5 -4
  138. package/src/esm/module.js.map +1 -1
  139. package/src/esm/utils/datastructures/Girih.d.ts +5 -0
  140. package/src/esm/utils/datastructures/Girih.js +18 -14
  141. package/src/esm/utils/datastructures/Girih.js.map +1 -1
  142. package/src/esm/utils/datastructures/GirihPenroseRhombus.js +42 -25
  143. package/src/esm/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  144. package/src/esm/utils/datastructures/GirihTile.js +2 -13
  145. package/src/esm/utils/datastructures/GirihTile.js.map +1 -1
  146. package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +2 -1
  147. package/src/esm/utils/helpers/BezierPathInteractionHelper.js +9 -18
  148. package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  149. package/src/ts/BezierPath.ts +0 -29
  150. package/src/ts/Bounds.ts +25 -1
  151. package/src/ts/Circle.ts +0 -26
  152. package/src/ts/CircleSector.ts +0 -30
  153. package/src/ts/CubicBezierCurve.ts +0 -39
  154. package/src/ts/Line.ts +0 -29
  155. package/src/ts/PBImage.ts +0 -15
  156. package/src/ts/PBText.ts +0 -17
  157. package/src/ts/Polygon.ts +16 -42
  158. package/src/ts/Triangle.ts +0 -40
  159. package/src/ts/VEllipse.ts +0 -24
  160. package/src/ts/Vector.ts +0 -40
  161. package/src/ts/Vertex.ts +0 -28
  162. package/src/ts/draw.ts +192 -3
  163. package/src/ts/drawgl.ts +44 -2
  164. package/src/ts/drawutilssvg.ts +181 -15
  165. package/src/ts/index.ts +0 -1
  166. package/src/ts/interfaces/DrawLib.ts +69 -26
  167. package/src/ts/interfaces/core.ts +0 -11
  168. package/src/ts/module.ts +2 -4
  169. package/src/ts/utils/datastructures/Girih.ts +204 -209
  170. package/src/ts/utils/datastructures/GirihPenroseRhombus.ts +170 -152
  171. package/src/ts/utils/datastructures/GirihTile.ts +394 -419
  172. package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +9 -18
  173. package/src/ts/SVGBuilder.ts +0 -109
@@ -29,7 +29,11 @@
29
29
  * @modified 2021-11-15 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
30
30
  * @modified 2021-11-19 Fixing the `label(text,x,y)` position.
31
31
  * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
32
- * @version 1.4.0
32
+ * @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
33
+ * @modified 2022-02-03 Added the `cross(...)` function.
34
+ * @modified 2022-03-26 Added the private `nodeDefs` and `bufferedNodeDefs` attributes.
35
+ * @modified 2022-03-26 Added the `texturedPoly` function to draw textures polygons.
36
+ * @version 1.6.0
33
37
  **/
34
38
 
35
39
  import { CircleSector } from "./CircleSector";
@@ -48,6 +52,8 @@ import {
48
52
  FontStyle,
49
53
  FontWeight
50
54
  } from "./interfaces";
55
+ import { Bounds } from "./Bounds";
56
+ import { UIDGenerator } from "./UIDGenerator";
51
57
 
52
58
  const RAD_TO_DEG = 180 / Math.PI;
53
59
 
@@ -98,6 +104,24 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
98
104
  */
99
105
  private nodeStyle: SVGStyleElement;
100
106
 
107
+ /**
108
+ * A style node of type `<defs>`.
109
+ * @member {SVGGelement}
110
+ * @memberof drawutilssvg
111
+ * @instance
112
+ * @private
113
+ */
114
+ private nodeDefs: SVGDefsElement;
115
+
116
+ /**
117
+ * The buffered nodeDefs.
118
+ * @member {SVGGelement}
119
+ * @memberof drawutilssvg
120
+ * @instance
121
+ * @private
122
+ */
123
+ private bufferedNodeDefs: SVGDefsElement;
124
+
101
125
  /**
102
126
  * @member {Vertex}
103
127
  * @memberof drawutilssvg
@@ -181,7 +205,9 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
181
205
  drawConfig: DrawConfig,
182
206
  isSecondary?: boolean,
183
207
  gNode?: SVGGElement,
184
- bufferGNode?: SVGGElement
208
+ bufferGNode?: SVGGElement,
209
+ nodeDefs?: SVGDefsElement,
210
+ bufferNodeDefs?: SVGDefsElement
185
211
  ) {
186
212
  this.svgNode = svgNode;
187
213
  this.offset = new Vertex(0, 0).set(offset);
@@ -195,14 +221,23 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
195
221
  if (isSecondary) {
196
222
  this.gNode = gNode;
197
223
  this.bufferGNode = bufferGNode;
224
+ this.nodeDefs = nodeDefs;
225
+ this.bufferedNodeDefs = bufferNodeDefs;
198
226
  } else {
199
227
  this.addStyleDefs(drawConfig);
228
+ this.addDefsNode();
200
229
  this.gNode = this.createSVGNode("g") as SVGGElement;
201
230
  this.bufferGNode = this.createSVGNode("g") as SVGGElement;
202
231
  this.svgNode.appendChild(this.gNode);
203
232
  }
204
233
  }
205
234
 
235
+ /**
236
+ * Adds a default style defintion based on the passed DrawConfig.
237
+ * Twaek the draw config to change default colors or line thicknesses.
238
+ *
239
+ * @param {DrawConfig} drawConfig
240
+ */
206
241
  private addStyleDefs(drawConfig: DrawConfig) {
207
242
  this.nodeStyle = this.createSVGNode("style") as SVGStyleElement;
208
243
  this.svgNode.appendChild(this.nodeStyle);
@@ -236,6 +271,16 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
236
271
  this.nodeStyle.innerHTML = rules.join("\n");
237
272
  }
238
273
 
274
+ /**
275
+ * Adds the internal <defs> node.
276
+ */
277
+ private addDefsNode() {
278
+ this.nodeDefs = this.createSVGNode("defs") as SVGDefsElement;
279
+ // this.svgNode.appendChild(this.nodeDefs);
280
+ this.bufferedNodeDefs = this.createSVGNode("defs") as SVGDefsElement;
281
+ this.svgNode.appendChild(this.nodeDefs);
282
+ }
283
+
239
284
  /**
240
285
  * This is a simple way to include custom CSS class mappings to the style defs of the generated SVG.
241
286
  *
@@ -386,7 +431,9 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
386
431
  null, // no DrawConfig
387
432
  true, // isSecondary
388
433
  this.gNode,
389
- this.bufferGNode
434
+ this.bufferGNode,
435
+ this.nodeDefs,
436
+ this.bufferedNodeDefs
390
437
  );
391
438
  return copy;
392
439
  }
@@ -470,11 +517,16 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
470
517
  // layout updates.
471
518
  // Replace the old <g>-node with the buffer node.
472
519
  // https://stackoverflow.com/questions/27442464/how-to-update-a-svg-image-without-seeing-a-blinking
520
+ this.svgNode.replaceChild(this.bufferedNodeDefs, this.nodeDefs);
473
521
  this.svgNode.replaceChild(this.bufferGNode, this.gNode);
474
522
  }
475
- let tmp: SVGGElement = this.gNode;
523
+ const tmpGNode: SVGGElement = this.gNode;
476
524
  this.gNode = this.bufferGNode;
477
- this.bufferGNode = tmp;
525
+ this.bufferGNode = tmpGNode;
526
+
527
+ const tmpDefsNode: SVGDefsElement = this.nodeDefs;
528
+ this.nodeDefs = this.bufferedNodeDefs;
529
+ this.bufferedNodeDefs = tmpDefsNode;
478
530
  }
479
531
 
480
532
  private _x(x: number): number {
@@ -574,6 +626,90 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
574
626
  return this._bindFillDraw(node, "image", null, null);
575
627
  }
576
628
 
629
+ /**
630
+ * Draw an image at the given position with the given size.<br>
631
+ * <br>
632
+ * Note: SVG images may have resizing issues at the moment.Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
633
+ *
634
+ * @method texturedPoly
635
+ * @param {Image} textureImage - The image object to draw.
636
+ * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
637
+ * @param {Polygon} polygon - The polygon to use as clip path.
638
+ * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
639
+ * @param {number} rotation - The rotation to use for the polygon (and for the texture).
640
+ * @return {void}
641
+ * @instance
642
+ * @memberof drawutilssvg
643
+ **/
644
+ texturedPoly(
645
+ textureImage: HTMLImageElement,
646
+ textureSize: Bounds,
647
+ polygon: Polygon,
648
+ polygonPosition: Vertex,
649
+ rotation: number
650
+ ): SVGElement {
651
+ const basePolygonBounds: Bounds = polygon.getBounds();
652
+ const rotatedScalingOrigin = new Vertex(textureSize.min).clone().rotate(rotation, polygonPosition);
653
+ const rotationCenter = polygonPosition.clone().add(rotatedScalingOrigin.difference(textureSize.min).inv());
654
+ // Create something like this
655
+ // ...
656
+ // <defs>
657
+ // <clipPath id="shape">
658
+ // <path fill="none" d="..."/>
659
+ // </clipPath>
660
+ // </defs>
661
+ // ...
662
+ // <g clip-path="url(#shape)">
663
+ // <g transform="scale(...)">
664
+ // <image width="643" height="643" transform="rotate(...)" xlink:href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/beagle400.jpg" >
665
+ // </g>
666
+ // </g>
667
+ // </image>
668
+ // ...
669
+ const clipPathNode: SVGClipPathElement = this.makeNode("clipPath") as SVGClipPathElement;
670
+ const clipPathId: string = `clippath_${UIDGenerator.next()}`; // TODO: use a better UUID generator here?
671
+ clipPathNode.setAttribute("id", clipPathId);
672
+
673
+ const gNode = this.makeNode("g") as SVGGElement;
674
+ const imageNode: SVGImageElement = this.makeNode("image") as SVGImageElement;
675
+ imageNode.setAttribute("x", `${this._x(rotatedScalingOrigin.x)}`);
676
+ imageNode.setAttribute("y", `${this._y(rotatedScalingOrigin.y)}`);
677
+ imageNode.setAttribute("width", `${textureSize.width}`);
678
+ imageNode.setAttribute("height", `${textureSize.height}`);
679
+ imageNode.setAttribute("href", textureImage.src);
680
+ // imageNode.setAttribute("opacity", "0.5");
681
+ // SVG rotations in degrees
682
+ imageNode.setAttribute(
683
+ "transform",
684
+ `rotate(${rotation * RAD_TO_DEG}, ${this._x(rotatedScalingOrigin.x)}, ${this._y(rotatedScalingOrigin.y)})`
685
+ );
686
+ const pathNode: SVGPathElement = this.makeNode("path") as SVGPathElement;
687
+ const pathData: string[] = [];
688
+ if (polygon.vertices.length > 0) {
689
+ const self = this;
690
+ pathData.push("M", `${this._x(polygon.vertices[0].x)}`, `${this._y(polygon.vertices[0].y)}`);
691
+ for (var i = 1; i < polygon.vertices.length; i++) {
692
+ pathData.push("L", `${this._x(polygon.vertices[i].x)}`, `${this._y(polygon.vertices[i].y)}`);
693
+ }
694
+ }
695
+
696
+ pathNode.setAttribute("d", pathData.join(" "));
697
+ clipPathNode.appendChild(pathNode);
698
+ this.bufferedNodeDefs.appendChild(clipPathNode);
699
+
700
+ gNode.appendChild(imageNode);
701
+ gNode.setAttribute("transform-origin", `${this._x(rotatedScalingOrigin.x)} ${this._y(rotatedScalingOrigin.y)}`);
702
+ gNode.setAttribute("transform", `scale(${this.scale.x}, ${this.scale.y})`);
703
+
704
+ const clipNode: SVGGElement = this.makeNode("g") as SVGGElement;
705
+ clipNode.appendChild(gNode);
706
+ clipNode.setAttribute("clip-path", `url(#${clipPathId})`);
707
+
708
+ // TODO: check if the image class is correct here or if we should use a 'clippedImage' class here
709
+ this._bindFillDraw(clipNode, "image", null, null); // No color, no lineWidth
710
+ return clipNode;
711
+ }
712
+
577
713
  /**
578
714
  * Draw the given (cubic) bézier curve.
579
715
  *
@@ -1020,11 +1156,12 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
1020
1156
  * @param {XYCoords} center - The center of the crosshair.
1021
1157
  * @param {number} radius - The radius of the crosshair.
1022
1158
  * @param {string} color - The CSS color to draw the crosshair with.
1159
+ * @param {number=0.5} lineWidth - (optional, default=0.5) The line width to use.
1023
1160
  * @return {void}
1024
1161
  * @instance
1025
1162
  * @memberof drawutilssvg
1026
1163
  */
1027
- crosshair(center: XYCoords, radius: number, color: string) {
1164
+ crosshair(center: XYCoords, radius: number, color: string, lineWidth?: number) {
1028
1165
  const node: SVGElement = this.makeNode("path");
1029
1166
  const d: SVGPathParams = [
1030
1167
  "M",
@@ -1041,7 +1178,41 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
1041
1178
  this._y(center.y) + radius
1042
1179
  ];
1043
1180
  node.setAttribute("d", d.join(" "));
1044
- return this._bindFillDraw(node, "crosshair", color, 0.5);
1181
+ return this._bindFillDraw(node, "crosshair", color, lineWidth || 0.5);
1182
+ }
1183
+
1184
+ /**
1185
+ * Draw a cross with diagonal axes with given radius, color and lineWidth at the given position.<br>
1186
+ * <br>
1187
+ * Note that the x's radius will not be affected by scaling.
1188
+ *
1189
+ * @method crosshair
1190
+ * @param {XYCoords} center - The center of the crosshair.
1191
+ * @param {number} radius - The radius of the crosshair.
1192
+ * @param {string} color - The CSS color to draw the crosshair with.
1193
+ * @param {number=1} lineWidth - (optional, default=1.0) The line width to use.
1194
+ * @return {void}
1195
+ * @instance
1196
+ * @memberof drawutils
1197
+ */
1198
+ cross(center: XYCoords, radius: number, color: string, lineWidth?: number) {
1199
+ const node: SVGElement = this.makeNode("path");
1200
+ const d: SVGPathParams = [
1201
+ "M",
1202
+ this._x(center.x) - radius,
1203
+ this._y(center.y) - radius,
1204
+ "L",
1205
+ this._x(center.x) + radius,
1206
+ this._y(center.y) + radius,
1207
+ "M",
1208
+ this._x(center.x) - radius,
1209
+ this._y(center.y) + radius,
1210
+ "L",
1211
+ this._x(center.x) + radius,
1212
+ this._y(center.y) - radius
1213
+ ];
1214
+ node.setAttribute("d", d.join(" "));
1215
+ return this._bindFillDraw(node, "cross", color, lineWidth || 1.0);
1045
1216
  }
1046
1217
 
1047
1218
  /**
@@ -1226,14 +1397,6 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
1226
1397
  if (this.isSecondary) {
1227
1398
  return;
1228
1399
  }
1229
- // // Clearing an SVG is equivalent to removing all its child elements.
1230
- // for (var i = 0; i < this.gNode.childNodes.length; i++) {
1231
- // // Hide all nodes here. Don't throw them away.
1232
- // // We can probably re-use them in the next draw cycle.
1233
- // var child: SVGElement = this.gNode.childNodes[i] as SVGElement;
1234
- // this.cache.set(child.getAttribute("id"), child);
1235
- // }
1236
- // this.removeAllChildNodes();
1237
1400
 
1238
1401
  // Add a covering rect with the given background color
1239
1402
  this.curId = "background";
@@ -1262,6 +1425,9 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
1262
1425
  while (this.bufferGNode.lastChild) {
1263
1426
  this.bufferGNode.removeChild(this.bufferGNode.lastChild);
1264
1427
  }
1428
+ while (this.bufferedNodeDefs.lastChild) {
1429
+ this.bufferedNodeDefs.removeChild(this.bufferedNodeDefs.lastChild);
1430
+ }
1265
1431
  }
1266
1432
 
1267
1433
  /**
package/src/ts/index.ts CHANGED
@@ -16,7 +16,6 @@ export * from "./PBImage";
16
16
  export * from "./PBText";
17
17
  export * from "./PlotBoilerplate";
18
18
  export * from "./Polygon";
19
- export * from "./SVGBuilder";
20
19
  export * from "./Triangle";
21
20
  export * from "./UIDGenerator";
22
21
  export * from "./Vector";
@@ -15,8 +15,11 @@
15
15
  * @modified 2021-11-12 Added `text()` params fontSize, fontFamily, rotation, textAlign.
16
16
  * @modified 2021-11-16 Added `text()` params fontWeight and fontStyle.
17
17
  * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
18
+ * @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
19
+ * @modified 2022-02-03 Added the `cross(...)` function.
18
20
  **/
19
21
 
22
+ import { Bounds } from "../Bounds";
20
23
  import { Polygon } from "../Polygon";
21
24
  import { Vertex } from "../Vertex";
22
25
  import { SVGPathParams, UID, XYCoords } from "./core";
@@ -121,7 +124,7 @@ export interface DrawLib<R> {
121
124
  * @param {number=1} lineWidth? - [optional] The line's width.
122
125
  * @return {void}
123
126
  * @instance
124
- * @memberof drawutils
127
+ * @memberof DrawLib
125
128
  **/
126
129
  line: (zA: Vertex, zB: Vertex, color: string, lineWidth?: number) => R;
127
130
 
@@ -135,7 +138,7 @@ export interface DrawLib<R> {
135
138
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
136
139
  * @return {void}
137
140
  * @instance
138
- * @memberof drawutils
141
+ * @memberof DrawLib
139
142
  **/
140
143
  arrow: (zA: Vertex, zB: Vertex, color: string, lineWidth?: number) => R;
141
144
 
@@ -150,10 +153,33 @@ export interface DrawLib<R> {
150
153
  * @param {Vertex} size - The x/y-size to draw the image with.
151
154
  * @return {void}
152
155
  * @instance
153
- * @memberof drawutils
156
+ * @memberof DrawLib
154
157
  **/
155
158
  image: (image: HTMLImageElement, position: Vertex, size: Vertex) => R;
156
159
 
160
+ /**
161
+ * Draw an image at the given position with the given size.<br>
162
+ * <br>
163
+ * Note: SVG images may have resizing issues at the moment.Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
164
+ *
165
+ * @method texturedPoly
166
+ * @param {Image} textureImage - The image object to draw.
167
+ * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
168
+ * @param {Polygon} polygon - The polygon to use as clip path.
169
+ * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
170
+ * @param {number} rotation - The rotation to use for the polygon (and for the texture).
171
+ * @return {void}
172
+ * @instance
173
+ * @memberof DrawLib
174
+ **/
175
+ texturedPoly: (
176
+ textureImage: HTMLImageElement,
177
+ textureSize: Bounds,
178
+ polygon: Polygon,
179
+ polygonPosition: Vertex,
180
+ rotation: number
181
+ ) => R;
182
+
157
183
  /**
158
184
  * Draw the given (cubic) bézier curve.
159
185
  *
@@ -166,7 +192,7 @@ export interface DrawLib<R> {
166
192
  * @param {number} lineWidth - (optional) The line width to use.
167
193
  * @return {void}
168
194
  * @instance
169
- * @memberof drawutils
195
+ * @memberof DrawLib
170
196
  */
171
197
  cubicBezier: (
172
198
  startPoint: Vertex,
@@ -190,7 +216,7 @@ export interface DrawLib<R> {
190
216
  * @param {number=1} lineWidth - (optional) The line width to use.
191
217
  * @return {void}
192
218
  * @instance
193
- * @memberof drawutils
219
+ * @memberof DrawLib
194
220
  */
195
221
  cubicBezierPath: (path: Array<Vertex>, color: string, lineWidth?: number) => R;
196
222
 
@@ -204,7 +230,7 @@ export interface DrawLib<R> {
204
230
  * @param {Vertex} endPoint - The end point of the handle.
205
231
  * @return {void}
206
232
  * @instance
207
- * @memberof drawutils
233
+ * @memberof DrawLib
208
234
  */
209
235
  handle: (startPoint: Vertex, endPoint: Vertex) => R;
210
236
 
@@ -216,7 +242,7 @@ export interface DrawLib<R> {
216
242
  * @param {Vertex} endPoint - The end point to draw the handle at.
217
243
  * @return {void}
218
244
  * @instance
219
- * @memberof drawutils
245
+ * @memberof DrawLib
220
246
  */
221
247
  handleLine: (startPoint: Vertex, endPoint: Vertex) => R;
222
248
 
@@ -228,7 +254,7 @@ export interface DrawLib<R> {
228
254
  * @param {string} color - The CSS color to draw the dot with.
229
255
  * @return {void}
230
256
  * @instance
231
- * @memberof drawutils
257
+ * @memberof DrawLib
232
258
  */
233
259
  dot: (p: Vertex, color: string) => R;
234
260
 
@@ -240,7 +266,7 @@ export interface DrawLib<R> {
240
266
  * @param {string} color - The CSS color to draw the point with.
241
267
  * @return {void}
242
268
  * @instance
243
- * @memberof drawutils
269
+ * @memberof DrawLib
244
270
  */
245
271
  point: (p: Vertex, color: string) => R;
246
272
 
@@ -256,7 +282,7 @@ export interface DrawLib<R> {
256
282
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
257
283
  * @return {void}
258
284
  * @instance
259
- * @memberof drawutils
285
+ * @memberof DrawLib
260
286
  */
261
287
  circle: (center: Vertex, radius: number, color: string, lineWidth?: number) => R;
262
288
 
@@ -272,7 +298,7 @@ export interface DrawLib<R> {
272
298
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
273
299
  * @return {void}
274
300
  * @instance
275
- * @memberof drawutils
301
+ * @memberof DrawLib
276
302
  */
277
303
  circleArc: (center: Vertex, radius: number, startAngle: number, endAngle: number, color: string, lineWidth?: number) => R;
278
304
 
@@ -288,7 +314,7 @@ export interface DrawLib<R> {
288
314
  * @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
289
315
  * @return {void}
290
316
  * @instance
291
- * @memberof drawutils
317
+ * @memberof DrawLib
292
318
  */
293
319
  ellipse: (center: Vertex, radiusX: number, radiusY: number, color: string, lineWidth?: number, rotation?: number) => R;
294
320
 
@@ -304,7 +330,7 @@ export interface DrawLib<R> {
304
330
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
305
331
  * @return {void}
306
332
  * @instance
307
- * @memberof drawutils
333
+ * @memberof DrawLib
308
334
  */
309
335
  square: (center: XYCoords, size: number, color: string, lineWidth?: number) => R;
310
336
 
@@ -319,7 +345,7 @@ export interface DrawLib<R> {
319
345
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
320
346
  * @return {void}
321
347
  * @instance
322
- * @memberof drawutils
348
+ * @memberof DrawLib
323
349
  */
324
350
  rect: (upperLeft: XYCoords, width: number, height: number, color: string, lineWidth?: number) => R;
325
351
 
@@ -335,7 +361,7 @@ export interface DrawLib<R> {
335
361
  * @param {string} color - The CSS color to draw the grid with.
336
362
  * @return {void}
337
363
  * @instance
338
- * @memberof drawutils
364
+ * @memberof DrawLib
339
365
  */
340
366
  grid: (center: Vertex, width: number, height: number, sizeX: number, sizeY: number, color: string) => R;
341
367
 
@@ -353,7 +379,7 @@ export interface DrawLib<R> {
353
379
  * @param {string} color - The CSS color to draw the raster with.
354
380
  * @return {void}
355
381
  * @instance
356
- * @memberof drawutils
382
+ * @memberof DrawLib
357
383
  */
358
384
  raster: (center: Vertex, width: number, height: number, sizeX: number, sizeY: number, color: string) => R;
359
385
 
@@ -370,7 +396,7 @@ export interface DrawLib<R> {
370
396
  * @param {string} color - The CSS color to draw the diamond with.
371
397
  * @return {void}
372
398
  * @instance
373
- * @memberof drawutils
399
+ * @memberof DrawLib
374
400
  */
375
401
  diamondHandle: (center: Vertex, size: number, color: string) => R;
376
402
 
@@ -387,7 +413,7 @@ export interface DrawLib<R> {
387
413
  * @param {string} color - The CSS color to draw the square with.
388
414
  * @return {void}
389
415
  * @instance
390
- * @memberof drawutils
416
+ * @memberof DrawLib
391
417
  */
392
418
  squareHandle: (center: Vertex, size: number, color: string) => R;
393
419
 
@@ -404,7 +430,7 @@ export interface DrawLib<R> {
404
430
  * @param {string} color - The CSS color to draw the circle with.
405
431
  * @return {void}
406
432
  * @instance
407
- * @memberof drawutils
433
+ * @memberof DrawLib
408
434
  */
409
435
  circleHandle: (center: Vertex, size: number, color: string) => R;
410
436
 
@@ -417,11 +443,28 @@ export interface DrawLib<R> {
417
443
  * @param {XYCoords} center - The center of the crosshair.
418
444
  * @param {number} radius - The radius of the crosshair.
419
445
  * @param {string} color - The CSS color to draw the crosshair with.
446
+ * @param {number=0.5} lineWidth - (optional, default=0.5) The line width to use.
447
+ * @return {void}
448
+ * @instance
449
+ * @memberof DrawLib
450
+ */
451
+ crosshair: (center: XYCoords, radius: number, color: string, lineWidth?: number) => R;
452
+
453
+ /**
454
+ * Draw a cross with diagonal axes with given radius, color and lineWidth at the given position.<br>
455
+ * <br>
456
+ * Note that the x's radius will not be affected by scaling.
457
+ *
458
+ * @method crosshair
459
+ * @param {XYCoords} center - The center of the crosshair.
460
+ * @param {number} radius - The radius of the crosshair.
461
+ * @param {string} color - The CSS color to draw the crosshair with.
462
+ * @param {number=1} lineWidth - (optional, default=1.0) The line width to use.
420
463
  * @return {void}
421
464
  * @instance
422
- * @memberof drawutils
465
+ * @memberof DrawLib
423
466
  */
424
- crosshair: (center: XYCoords, radius: number, color: string) => R;
467
+ cross: (center: XYCoords, radius: number, color: string, lineWidth?: number) => R;
425
468
 
426
469
  /**
427
470
  * Draw a polygon.
@@ -431,7 +474,7 @@ export interface DrawLib<R> {
431
474
  * @param {string} color - The CSS color to draw the polygon with.
432
475
  * @return {void}
433
476
  * @instance
434
- * @memberof drawutils
477
+ * @memberof DrawLib
435
478
  */
436
479
  polygon: (polygon: Polygon, color: string, lineWidth?: number) => R;
437
480
 
@@ -445,7 +488,7 @@ export interface DrawLib<R> {
445
488
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
446
489
  * @return {void}
447
490
  * @instance
448
- * @memberof drawutils
491
+ * @memberof DrawLib
449
492
  */
450
493
  polyline: (vertices: Array<Vertex>, isOpen: boolean, color: string, lineWidth?: number) => R;
451
494
 
@@ -466,7 +509,7 @@ export interface DrawLib<R> {
466
509
  * @param {string=} options.textAlign - The text align to use. According to the specifiactions (https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign) valid values are `"left" || "right" || "center" || "start" || "end"`.
467
510
  * @return {void}
468
511
  * @instance
469
- * @memberof drawutils
512
+ * @memberof DrawLib
470
513
  */
471
514
  text: (text: string, x: number, y: number, options?: FontOptions) => R;
472
515
 
@@ -481,7 +524,7 @@ export interface DrawLib<R> {
481
524
  * @param {string="black"} color - The color to use (default is black).
482
525
  * @return {void}
483
526
  * @instance
484
- * @memberof drawutils
527
+ * @memberof DrawLib
485
528
  */
486
529
  label: (text: string, x: number, y: number, rotation?: number, color?: string) => R;
487
530
 
@@ -494,7 +537,7 @@ export interface DrawLib<R> {
494
537
  * @param {number=1} lineWidth - (optional) the line width to use (default is 1).
495
538
  * @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.
496
539
  * @instance
497
- * @memberof drawutils
540
+ * @memberof DrawLib
498
541
  * @return {R} An instance representing the drawn path.
499
542
  */
500
543
  path: (pathData: SVGPathParams, color?: string, lineWidth?: number, options?: { inplace?: boolean }) => R;
@@ -211,17 +211,6 @@ export interface SVGSerializable {
211
211
  * Required to generate proper CSS classes and other class related IDs.
212
212
  **/
213
213
  readonly className: string;
214
-
215
- /**
216
- * Convert this vertex to SVG code.
217
- *
218
- * @method toSVGString
219
- * @param {object=} options - An optional set of options, like 'className'.
220
- * @return {string} A string representing the SVG code for this vertex.
221
- * @instance
222
- * @memberof Vertex
223
- **/
224
- toSVGString: (options: { className?: string }) => string;
225
214
  }
226
215
 
227
216
  /**
package/src/ts/module.ts CHANGED
@@ -11,7 +11,7 @@ import { Circle } from "./Circle";
11
11
  import { CircleSector } from "./CircleSector";
12
12
  import { CubicBezierCurve } from "./CubicBezierCurve";
13
13
  import { drawutils } from "./draw";
14
- import { drawutilsgl } from "./drawgl";
14
+ // import { drawutilsgl } from "./drawgl";
15
15
  import { geomutils } from "./geomutils";
16
16
  import { Grid } from "./Grid";
17
17
  import { KeyHandler } from "./KeyHandler";
@@ -20,7 +20,6 @@ import { MouseHandler } from "./MouseHandler";
20
20
  import { PBImage } from "./PBImage";
21
21
  import { PlotBoilerplate } from "./PlotBoilerplate";
22
22
  import { Polygon } from "./Polygon";
23
- import { SVGBuilder } from "./SVGBuilder";
24
23
  import { Triangle } from "./Triangle";
25
24
  import { UIDGenerator } from "./UIDGenerator";
26
25
  import { Vector } from "./Vector";
@@ -39,7 +38,7 @@ export {
39
38
  CircleSector,
40
39
  CubicBezierCurve,
41
40
  drawutils,
42
- drawutilsgl,
41
+ // drawutilsgl,
43
42
  geomutils,
44
43
  Grid,
45
44
  // ...interf,
@@ -49,7 +48,6 @@ export {
49
48
  PBImage,
50
49
  PlotBoilerplate,
51
50
  Polygon,
52
- SVGBuilder,
53
51
  Triangle,
54
52
  UIDGenerator,
55
53
  Vector,