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
package/dist/index.esm.js CHANGED
@@ -843,31 +843,6 @@ class Vertex {
843
843
  toString() {
844
844
  return "(" + this.x + "," + this.y + ")";
845
845
  }
846
- /**
847
- * Convert this vertex to SVG code.
848
- *
849
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
850
- * @method toSVGString
851
- * @param {object=} options - An optional set of options, like 'className'.
852
- * @return {string} A string representing the SVG code for this vertex.
853
- * @instance
854
- * @memberof Vertex
855
- * @deprecated
856
- **/
857
- toSVGString(options) {
858
- // options = options || {};
859
- // var buffer = [];
860
- // buffer.push("<circle");
861
- // if (options.className) buffer.push(' class="' + options.className + '"');
862
- // buffer.push(' cx="' + this.x + '"');
863
- // buffer.push(' cy="' + this.y + '"');
864
- // buffer.push(' r="2"');
865
- // buffer.push(" />");
866
- // return buffer.join("");
867
- console.warn("[Deprecation] Warning: the Vertex.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
868
- return "";
869
- }
870
- // END Vertex
871
846
  /**
872
847
  * This function should invalidate any installed listeners and invalidate this object.
873
848
  * After calling this function the object might not hold valid data any more and
@@ -972,7 +947,8 @@ Vertex.utils = {
972
947
  * @modified 2021-12-16 Added the `getEvenDistributionPolygon()` function.
973
948
  * @modified 2022-02-02 Added the `destroy` method.
974
949
  * @modified 2022-02-02 Cleared the `Polygon.toSVGString` function (deprecated). Use `drawutilssvg` instead.
975
- * @version 1.9.0
950
+ * @modified 2022-03-08 Added the `Polygon.clone()` function.
951
+ * @version 1.10.0
976
952
  *
977
953
  * @file Polygon
978
954
  * @public
@@ -1050,9 +1026,9 @@ class Polygon {
1050
1026
  * @memberof Polygon
1051
1027
  * @return {Polygon} this for chaining
1052
1028
  **/
1053
- move(vert) {
1029
+ move(amount) {
1054
1030
  for (var i in this.vertices) {
1055
- this.vertices[i].add(vert);
1031
+ this.vertices[i].add(amount);
1056
1032
  }
1057
1033
  return this;
1058
1034
  }
@@ -1231,6 +1207,14 @@ class Polygon {
1231
1207
  getBounds() {
1232
1208
  return Bounds.computeFromVertices(this.vertices);
1233
1209
  }
1210
+ /**
1211
+ * Create a deep copy of this polygon.
1212
+ *
1213
+ * @return {Polygon} The cloned polygon.
1214
+ */
1215
+ clone() {
1216
+ return new Polygon(this.vertices.map(vert => vert.clone()), this.isOpen);
1217
+ }
1234
1218
  /**
1235
1219
  * Convert this polygon to a sequence of quadratic Bézier curves.<br>
1236
1220
  * <br>
@@ -1367,42 +1351,6 @@ class Polygon {
1367
1351
  }
1368
1352
  return BezierPath.fromArray(pathdata);
1369
1353
  }
1370
- /**
1371
- * Create an SVG representation of this polygon.
1372
- *
1373
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
1374
- * @method toSVGString
1375
- * @param {object=} options - An optional set of options, like 'className'.
1376
- * @return {string} The SVG string.
1377
- * @instance
1378
- * @memberof Polygon
1379
- **/
1380
- toSVGString(options) {
1381
- // options = options || {};
1382
- // var buffer: Array<string> = [];
1383
- // buffer.push("<path");
1384
- // if (options.className) buffer.push(' class="' + options.className + '"');
1385
- // buffer.push(' d="');
1386
- // if (this.vertices.length > 0) {
1387
- // buffer.push("M ");
1388
- // buffer.push(this.vertices[0].x.toString());
1389
- // buffer.push(" ");
1390
- // buffer.push(this.vertices[0].y.toString());
1391
- // for (var i = 1; i < this.vertices.length; i++) {
1392
- // buffer.push(" L ");
1393
- // buffer.push(this.vertices[i].x.toString());
1394
- // buffer.push(" ");
1395
- // buffer.push(this.vertices[i].y.toString());
1396
- // }
1397
- // if (!this.isOpen) {
1398
- // buffer.push(" Z");
1399
- // }
1400
- // }
1401
- // buffer.push('" />');
1402
- // return buffer.join("");
1403
- console.warn("[Deprecation] Warning: the Polygon.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
1404
- return "";
1405
- }
1406
1354
  /**
1407
1355
  * This function should invalidate any installed listeners and invalidate this object.
1408
1356
  * After calling this function the object might not hold valid data any more and
@@ -1463,7 +1411,8 @@ Polygon.utils = {
1463
1411
  * @modified 2020-11-19 Set min, max, width and height to private.
1464
1412
  * @modified 2021-02-02 Added the `toPolygon` method.
1465
1413
  * @modified 2021-06-21 (mid-summer) Added `getCenter` method.
1466
- * @version 1.3.0
1414
+ * @modified 2022-02-01 Added the `toString` function.
1415
+ * @version 1.4.0
1467
1416
  **/
1468
1417
  /**
1469
1418
  * @classdesc A bounds class with min and max values. Implementing IBounds.
@@ -1498,9 +1447,31 @@ class Bounds {
1498
1447
  toPolygon() {
1499
1448
  return new Polygon([new Vertex(this.min), new Vertex(this.max.x, this.min.y), new Vertex(this.max), new Vertex(this.min.x, this.max.y)], false);
1500
1449
  }
1450
+ /**
1451
+ * Get the center of this boinding box.
1452
+ *
1453
+ * @method getCenter
1454
+ * @instance
1455
+ * @memberof Bounds
1456
+ * @returns {Vertex} The center of these bounds.
1457
+ */
1501
1458
  getCenter() {
1502
1459
  return new Vertex(this.min.x + (this.max.x - this.min.x) / 2.0, this.min.y + (this.max.y - this.min.y) / 2);
1503
1460
  }
1461
+ /**
1462
+ * Convert these bounds to a human readable form.
1463
+ *
1464
+ * Note: the returned format might change in the future, so please do not
1465
+ * rely on the returned string format.
1466
+ *
1467
+ * @method toString
1468
+ * @instance
1469
+ * @memberof Bounds
1470
+ * @returns {string} Get these bounds in a human readable form.
1471
+ */
1472
+ toString() {
1473
+ return `{ min: ${this.min.toString()}, max : ${this.max.toString()}, width: ${this.width}, height : ${this.height} }`;
1474
+ }
1504
1475
  /**
1505
1476
  * Compute the minimal bounding box for a given set of vertices.
1506
1477
  *
@@ -1938,42 +1909,6 @@ class Vector extends VertTuple {
1938
1909
  // if we cast these lines infinitely in both directions, they intersect here:
1939
1910
  return new Vertex(this.a.x + a * (this.b.x - this.a.x), this.a.y + a * (this.b.y - this.a.y));
1940
1911
  }
1941
- /**
1942
- * Create an SVG representation of this line.
1943
- *
1944
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
1945
- * @method toSVGString
1946
- * @override
1947
- * @param {object=} options - A set of options, like 'className'.
1948
- * @return {string} The SVG string representation.
1949
- * @instance
1950
- * @memberof Vector
1951
- **/
1952
- toSVGString(options) {
1953
- // options = options || {};
1954
- // var buffer = [];
1955
- // var vertices = Vector.utils.buildArrowHead(this.a, this.b, 8, 1.0, 1.0);
1956
- // buffer.push("<g");
1957
- // if (options.className) buffer.push(' class="' + options.className + '"');
1958
- // buffer.push(">");
1959
- // buffer.push(" <line");
1960
- // buffer.push(' x1="' + this.a.x + '"');
1961
- // buffer.push(' y1="' + this.a.y + '"');
1962
- // buffer.push(' x2="' + vertices[0].x + '"');
1963
- // buffer.push(' y2="' + vertices[0].y + '"');
1964
- // buffer.push(" />");
1965
- // // Add arrow head
1966
- // buffer.push(' <polygon points="');
1967
- // for (var i = 0; i < vertices.length; i++) {
1968
- // if (i > 0) buffer.push(" ");
1969
- // buffer.push("" + vertices[i].x + "," + vertices[i].y);
1970
- // }
1971
- // buffer.push('"/>');
1972
- // buffer.push("</g>");
1973
- // return buffer.join("");
1974
- console.warn("[Deprecation] Warning: the Vector.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
1975
- return "";
1976
- }
1977
1912
  }
1978
1913
  Vector.utils = {
1979
1914
  /**
@@ -2574,42 +2509,6 @@ class CubicBezierCurve {
2574
2509
  */
2575
2510
  return obj instanceof CubicBezierCurve;
2576
2511
  }
2577
- /**
2578
- * Create an SVG path data representation of this bézier curve.
2579
- *
2580
- * Path data string format is:<br>
2581
- * <pre>'M x0 y1 C dx0 dy1 dx1 dy1 x1 x2'</pre><br>
2582
- * or in other words<br>
2583
- * <pre>'M startoint.x startPoint.y C startControlPoint.x startControlPoint.y endControlPoint.x endControlPoint.y endPoint.x endPoint.y'</pre>
2584
- *
2585
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
2586
- * @method toSVGPathData
2587
- * @instance
2588
- * @memberof CubicBezierCurve
2589
- * @return {string} The SVG path data string.
2590
- **/
2591
- toSVGPathData() {
2592
- // var buffer: Array<string> = [];
2593
- // buffer.push("M ");
2594
- // buffer.push(this.startPoint.x.toString());
2595
- // buffer.push(" ");
2596
- // buffer.push(this.startPoint.y.toString());
2597
- // buffer.push(" C ");
2598
- // buffer.push(this.startControlPoint.x.toString());
2599
- // buffer.push(" ");
2600
- // buffer.push(this.startControlPoint.y.toString());
2601
- // buffer.push(" ");
2602
- // buffer.push(this.endControlPoint.x.toString());
2603
- // buffer.push(" ");
2604
- // buffer.push(this.endControlPoint.y.toString());
2605
- // buffer.push(" ");
2606
- // buffer.push(this.endPoint.x.toString());
2607
- // buffer.push(" ");
2608
- // buffer.push(this.endPoint.y.toString());
2609
- // return buffer.join("");
2610
- console.warn("[Deprecation] Warning: the CubicBezierCurve.toSVGPathData method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
2611
- return "";
2612
- }
2613
2512
  /**
2614
2513
  * Convert this curve to a JSON string.
2615
2514
  *
@@ -3724,32 +3623,6 @@ class BezierPath {
3724
3623
  }
3725
3624
  return true;
3726
3625
  }
3727
- /**
3728
- * Create a <pre>&lt;path&gt;</pre> SVG representation of this bézier curve.
3729
- *
3730
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
3731
- * @method toSVGString
3732
- * @param {object=} [options={}] - Like options.className
3733
- * @param {string=} [options.className] - The classname to use for the SVG item.
3734
- * @instance
3735
- * @memberof BezierPath
3736
- * @return {string} The SVG string.
3737
- **/
3738
- toSVGString(options) {
3739
- // options = options || {};
3740
- // var buffer: Array<string> = [];
3741
- // buffer.push("<path");
3742
- // if (options.className) buffer.push(' class="' + options.className + '"');
3743
- // buffer.push(' d="');
3744
- // for (var c = 0; c < this.bezierCurves.length; c++) {
3745
- // if (c > 0) buffer.push(" ");
3746
- // buffer.push(this.bezierCurves[c].toSVGPathData());
3747
- // }
3748
- // buffer.push('" />');
3749
- // return buffer.join("");
3750
- console.warn("[Deprecation] Warning: the BezierPath.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
3751
- return "";
3752
- }
3753
3626
  /**
3754
3627
  * This function should invalidate any installed listeners and invalidate this object.
3755
3628
  * After calling this function the object might not hold valid data any more and
@@ -4045,32 +3918,6 @@ class Line extends VertTuple {
4045
3918
  // if we cast these lines infinitely in both directions, they intersect here:
4046
3919
  return new Vertex(x, y);
4047
3920
  }
4048
- /**
4049
- * Create an SVG representation of this line.
4050
- *
4051
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
4052
- * @method toSVGString
4053
- * @param {options} p - A set of options, like the 'classname' to use
4054
- * for the line object.
4055
- * @return {string} The SVG string representing this line.
4056
- * @instance
4057
- * @memberof Line
4058
- **/
4059
- toSVGString(options) {
4060
- // options = options || {};
4061
- // var buffer = [];
4062
- // buffer.push( '<line' );
4063
- // if( options.className )
4064
- // buffer.push( ' class="' + options.className + '"' );
4065
- // buffer.push( ' x1="' + this.a.x + '"' );
4066
- // buffer.push( ' y1="' + this.a.y + '"' );
4067
- // buffer.push( ' x2="' + this.b.x + '"' );
4068
- // buffer.push( ' y2="' + this.b.y + '"' );
4069
- // buffer.push( ' />' );
4070
- // return buffer.join('');
4071
- console.warn("[Deprecation] Warning: the Line.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
4072
- return "";
4073
- }
4074
3921
  }
4075
3922
 
4076
3923
  /**
@@ -4226,29 +4073,6 @@ class Circle {
4226
4073
  var y4 = p2.y + (h * (p1.x - p0.x)) / d;
4227
4074
  return new Line(new Vertex(x3, y3), new Vertex(x4, y4));
4228
4075
  }
4229
- /**
4230
- * Create an SVG representation of this circle.
4231
- *
4232
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
4233
- * @method toSVGString
4234
- * @param {object=} options - An optional set of options, like 'className'.
4235
- * @return {string} A string representing the SVG code for this vertex.
4236
- * @instance
4237
- * @memberof Circle
4238
- */
4239
- toSVGString(options) {
4240
- // options = options || {};
4241
- // var buffer: Array<string> = [];
4242
- // buffer.push("<circle");
4243
- // if (options.className) buffer.push(' class="' + options.className + '"');
4244
- // buffer.push(' cx="' + this.center.x + '"');
4245
- // buffer.push(' cy="' + this.center.y + '"');
4246
- // buffer.push(' r="' + this.radius + '"');
4247
- // buffer.push(" />");
4248
- // return buffer.join("");
4249
- console.warn("[Deprecation] Warning: the Circle.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
4250
- return "";
4251
- }
4252
4076
  /**
4253
4077
  * This function should invalidate any installed listeners and invalidate this object.
4254
4078
  * After calling this function the object might not hold valid data any more and
@@ -4303,33 +4127,6 @@ class CircleSector {
4303
4127
  this.startAngle = startAngle;
4304
4128
  this.endAngle = endAngle;
4305
4129
  }
4306
- /**
4307
- * Create an SVG representation of this circle.
4308
- *
4309
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
4310
- * @method toSVGString
4311
- * @param {object=} options - An optional set of options, like 'className'.
4312
- * @return {string} A string representing the SVG code for this vertex.
4313
- * @instance
4314
- * @memberof Circle
4315
- */
4316
- toSVGString(options) {
4317
- // options = options || {};
4318
- // var buffer: Array<string> = [];
4319
- // buffer.push("<path ");
4320
- // if (options.className) buffer.push(' class="' + options.className + '"');
4321
- // const data: SVGPathParams = CircleSector.circleSectorUtils.describeSVGArc(
4322
- // this.circle.center.x,
4323
- // this.circle.center.y,
4324
- // this.circle.radius,
4325
- // this.startAngle,
4326
- // this.endAngle
4327
- // );
4328
- // buffer.push(' d="' + data.join(" ") + '" />');
4329
- // return buffer.join("");
4330
- console.warn("[Deprecation] Warning: the CircleSector.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
4331
- return "";
4332
- }
4333
4130
  /**
4334
4131
  * This function should invalidate any installed listeners and invalidate this object.
4335
4132
  * After calling this function the object might not hold valid data any more and
@@ -4427,7 +4224,11 @@ CircleSector.circleSectorUtils = {
4427
4224
  * @modified 2021-11-15 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
4428
4225
  * @modified 2021-11-19 Fixing the `label(text,x,y)` position.
4429
4226
  * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
4430
- * @version 1.4.0
4227
+ * @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
4228
+ * @modified 2022-02-03 Added the `cross(...)` function.
4229
+ * @modified 2022-03-26 Added the private `nodeDefs` and `bufferedNodeDefs` attributes.
4230
+ * @modified 2022-03-26 Added the `texturedPoly` function to draw textures polygons.
4231
+ * @version 1.6.0
4431
4232
  **/
4432
4233
  const RAD_TO_DEG = 180 / Math.PI;
4433
4234
  /**
@@ -4454,7 +4255,7 @@ class drawutilssvg {
4454
4255
  * @param {boolean=} isSecondary - (optional) Indicates if this is the primary or secondary instance. Only primary instances manage child nodes.
4455
4256
  * @param {SVGGElement=} gNode - (optional) Primary and seconday instances share the same &lt;g> node.
4456
4257
  **/
4457
- constructor(svgNode, offset, scale, canvasSize, fillShapes, drawConfig, isSecondary, gNode, bufferGNode) {
4258
+ constructor(svgNode, offset, scale, canvasSize, fillShapes, drawConfig, isSecondary, gNode, bufferGNode, nodeDefs, bufferNodeDefs) {
4458
4259
  this.svgNode = svgNode;
4459
4260
  this.offset = new Vertex(0, 0).set(offset);
4460
4261
  this.scale = new Vertex(1, 1).set(scale);
@@ -4466,14 +4267,23 @@ class drawutilssvg {
4466
4267
  if (isSecondary) {
4467
4268
  this.gNode = gNode;
4468
4269
  this.bufferGNode = bufferGNode;
4270
+ this.nodeDefs = nodeDefs;
4271
+ this.bufferedNodeDefs = bufferNodeDefs;
4469
4272
  }
4470
4273
  else {
4471
4274
  this.addStyleDefs(drawConfig);
4275
+ this.addDefsNode();
4472
4276
  this.gNode = this.createSVGNode("g");
4473
4277
  this.bufferGNode = this.createSVGNode("g");
4474
4278
  this.svgNode.appendChild(this.gNode);
4475
4279
  }
4476
4280
  }
4281
+ /**
4282
+ * Adds a default style defintion based on the passed DrawConfig.
4283
+ * Twaek the draw config to change default colors or line thicknesses.
4284
+ *
4285
+ * @param {DrawConfig} drawConfig
4286
+ */
4477
4287
  addStyleDefs(drawConfig) {
4478
4288
  this.nodeStyle = this.createSVGNode("style");
4479
4289
  this.svgNode.appendChild(this.nodeStyle);
@@ -4506,6 +4316,15 @@ class drawutilssvg {
4506
4316
  }
4507
4317
  this.nodeStyle.innerHTML = rules.join("\n");
4508
4318
  }
4319
+ /**
4320
+ * Adds the internal <defs> node.
4321
+ */
4322
+ addDefsNode() {
4323
+ this.nodeDefs = this.createSVGNode("defs");
4324
+ // this.svgNode.appendChild(this.nodeDefs);
4325
+ this.bufferedNodeDefs = this.createSVGNode("defs");
4326
+ this.svgNode.appendChild(this.nodeDefs);
4327
+ }
4509
4328
  /**
4510
4329
  * This is a simple way to include custom CSS class mappings to the style defs of the generated SVG.
4511
4330
  *
@@ -4643,7 +4462,7 @@ class drawutilssvg {
4643
4462
  copyInstance(fillShapes) {
4644
4463
  var copy = new drawutilssvg(this.svgNode, this.offset, this.scale, this.canvasSize, fillShapes, null, // no DrawConfig
4645
4464
  true, // isSecondary
4646
- this.gNode, this.bufferGNode);
4465
+ this.gNode, this.bufferGNode, this.nodeDefs, this.bufferedNodeDefs);
4647
4466
  return copy;
4648
4467
  }
4649
4468
  /**
@@ -4720,11 +4539,15 @@ class drawutilssvg {
4720
4539
  // layout updates.
4721
4540
  // Replace the old <g>-node with the buffer node.
4722
4541
  // https://stackoverflow.com/questions/27442464/how-to-update-a-svg-image-without-seeing-a-blinking
4542
+ this.svgNode.replaceChild(this.bufferedNodeDefs, this.nodeDefs);
4723
4543
  this.svgNode.replaceChild(this.bufferGNode, this.gNode);
4724
4544
  }
4725
- let tmp = this.gNode;
4545
+ const tmpGNode = this.gNode;
4726
4546
  this.gNode = this.bufferGNode;
4727
- this.bufferGNode = tmp;
4547
+ this.bufferGNode = tmpGNode;
4548
+ const tmpDefsNode = this.nodeDefs;
4549
+ this.nodeDefs = this.bufferedNodeDefs;
4550
+ this.bufferedNodeDefs = tmpDefsNode;
4728
4551
  }
4729
4552
  _x(x) {
4730
4553
  return this.offset.x + this.scale.x * x;
@@ -4816,6 +4639,74 @@ class drawutilssvg {
4816
4639
  node.setAttribute("href", image.src);
4817
4640
  return this._bindFillDraw(node, "image", null, null);
4818
4641
  }
4642
+ /**
4643
+ * Draw an image at the given position with the given size.<br>
4644
+ * <br>
4645
+ * 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.
4646
+ *
4647
+ * @method texturedPoly
4648
+ * @param {Image} textureImage - The image object to draw.
4649
+ * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
4650
+ * @param {Polygon} polygon - The polygon to use as clip path.
4651
+ * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
4652
+ * @param {number} rotation - The rotation to use for the polygon (and for the texture).
4653
+ * @return {void}
4654
+ * @instance
4655
+ * @memberof drawutilssvg
4656
+ **/
4657
+ texturedPoly(textureImage, textureSize, polygon, polygonPosition, rotation) {
4658
+ polygon.getBounds();
4659
+ const rotatedScalingOrigin = new Vertex(textureSize.min).clone().rotate(rotation, polygonPosition);
4660
+ polygonPosition.clone().add(rotatedScalingOrigin.difference(textureSize.min).inv());
4661
+ // Create something like this
4662
+ // ...
4663
+ // <defs>
4664
+ // <clipPath id="shape">
4665
+ // <path fill="none" d="..."/>
4666
+ // </clipPath>
4667
+ // </defs>
4668
+ // ...
4669
+ // <g clip-path="url(#shape)">
4670
+ // <g transform="scale(...)">
4671
+ // <image width="643" height="643" transform="rotate(...)" xlink:href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/beagle400.jpg" >
4672
+ // </g>
4673
+ // </g>
4674
+ // </image>
4675
+ // ...
4676
+ const clipPathNode = this.makeNode("clipPath");
4677
+ const clipPathId = `clippath_${UIDGenerator.next()}`; // TODO: use a better UUID generator here?
4678
+ clipPathNode.setAttribute("id", clipPathId);
4679
+ const gNode = this.makeNode("g");
4680
+ const imageNode = this.makeNode("image");
4681
+ imageNode.setAttribute("x", `${this._x(rotatedScalingOrigin.x)}`);
4682
+ imageNode.setAttribute("y", `${this._y(rotatedScalingOrigin.y)}`);
4683
+ imageNode.setAttribute("width", `${textureSize.width}`);
4684
+ imageNode.setAttribute("height", `${textureSize.height}`);
4685
+ imageNode.setAttribute("href", textureImage.src);
4686
+ // imageNode.setAttribute("opacity", "0.5");
4687
+ // SVG rotations in degrees
4688
+ imageNode.setAttribute("transform", `rotate(${rotation * RAD_TO_DEG}, ${this._x(rotatedScalingOrigin.x)}, ${this._y(rotatedScalingOrigin.y)})`);
4689
+ const pathNode = this.makeNode("path");
4690
+ const pathData = [];
4691
+ if (polygon.vertices.length > 0) {
4692
+ pathData.push("M", `${this._x(polygon.vertices[0].x)}`, `${this._y(polygon.vertices[0].y)}`);
4693
+ for (var i = 1; i < polygon.vertices.length; i++) {
4694
+ pathData.push("L", `${this._x(polygon.vertices[i].x)}`, `${this._y(polygon.vertices[i].y)}`);
4695
+ }
4696
+ }
4697
+ pathNode.setAttribute("d", pathData.join(" "));
4698
+ clipPathNode.appendChild(pathNode);
4699
+ this.bufferedNodeDefs.appendChild(clipPathNode);
4700
+ gNode.appendChild(imageNode);
4701
+ gNode.setAttribute("transform-origin", `${this._x(rotatedScalingOrigin.x)} ${this._y(rotatedScalingOrigin.y)}`);
4702
+ gNode.setAttribute("transform", `scale(${this.scale.x}, ${this.scale.y})`);
4703
+ const clipNode = this.makeNode("g");
4704
+ clipNode.appendChild(gNode);
4705
+ clipNode.setAttribute("clip-path", `url(#${clipPathId})`);
4706
+ // TODO: check if the image class is correct here or if we should use a 'clippedImage' class here
4707
+ this._bindFillDraw(clipNode, "image", null, null); // No color, no lineWidth
4708
+ return clipNode;
4709
+ }
4819
4710
  /**
4820
4711
  * Draw the given (cubic) bézier curve.
4821
4712
  *
@@ -5208,11 +5099,12 @@ class drawutilssvg {
5208
5099
  * @param {XYCoords} center - The center of the crosshair.
5209
5100
  * @param {number} radius - The radius of the crosshair.
5210
5101
  * @param {string} color - The CSS color to draw the crosshair with.
5102
+ * @param {number=0.5} lineWidth - (optional, default=0.5) The line width to use.
5211
5103
  * @return {void}
5212
5104
  * @instance
5213
5105
  * @memberof drawutilssvg
5214
5106
  */
5215
- crosshair(center, radius, color) {
5107
+ crosshair(center, radius, color, lineWidth) {
5216
5108
  const node = this.makeNode("path");
5217
5109
  const d = [
5218
5110
  "M",
@@ -5229,7 +5121,40 @@ class drawutilssvg {
5229
5121
  this._y(center.y) + radius
5230
5122
  ];
5231
5123
  node.setAttribute("d", d.join(" "));
5232
- return this._bindFillDraw(node, "crosshair", color, 0.5);
5124
+ return this._bindFillDraw(node, "crosshair", color, lineWidth || 0.5);
5125
+ }
5126
+ /**
5127
+ * Draw a cross with diagonal axes with given radius, color and lineWidth at the given position.<br>
5128
+ * <br>
5129
+ * Note that the x's radius will not be affected by scaling.
5130
+ *
5131
+ * @method crosshair
5132
+ * @param {XYCoords} center - The center of the crosshair.
5133
+ * @param {number} radius - The radius of the crosshair.
5134
+ * @param {string} color - The CSS color to draw the crosshair with.
5135
+ * @param {number=1} lineWidth - (optional, default=1.0) The line width to use.
5136
+ * @return {void}
5137
+ * @instance
5138
+ * @memberof drawutils
5139
+ */
5140
+ cross(center, radius, color, lineWidth) {
5141
+ const node = this.makeNode("path");
5142
+ const d = [
5143
+ "M",
5144
+ this._x(center.x) - radius,
5145
+ this._y(center.y) - radius,
5146
+ "L",
5147
+ this._x(center.x) + radius,
5148
+ this._y(center.y) + radius,
5149
+ "M",
5150
+ this._x(center.x) - radius,
5151
+ this._y(center.y) + radius,
5152
+ "L",
5153
+ this._x(center.x) + radius,
5154
+ this._y(center.y) - radius
5155
+ ];
5156
+ node.setAttribute("d", d.join(" "));
5157
+ return this._bindFillDraw(node, "cross", color, lineWidth || 1.0);
5233
5158
  }
5234
5159
  /**
5235
5160
  * Draw a polygon.
@@ -5392,14 +5317,6 @@ class drawutilssvg {
5392
5317
  if (this.isSecondary) {
5393
5318
  return;
5394
5319
  }
5395
- // // Clearing an SVG is equivalent to removing all its child elements.
5396
- // for (var i = 0; i < this.gNode.childNodes.length; i++) {
5397
- // // Hide all nodes here. Don't throw them away.
5398
- // // We can probably re-use them in the next draw cycle.
5399
- // var child: SVGElement = this.gNode.childNodes[i] as SVGElement;
5400
- // this.cache.set(child.getAttribute("id"), child);
5401
- // }
5402
- // this.removeAllChildNodes();
5403
5320
  // Add a covering rect with the given background color
5404
5321
  this.curId = "background";
5405
5322
  this.curClassName = undefined;
@@ -5425,6 +5342,9 @@ class drawutilssvg {
5425
5342
  while (this.bufferGNode.lastChild) {
5426
5343
  this.bufferGNode.removeChild(this.bufferGNode.lastChild);
5427
5344
  }
5345
+ while (this.bufferedNodeDefs.lastChild) {
5346
+ this.bufferedNodeDefs.removeChild(this.bufferedNodeDefs.lastChild);
5347
+ }
5428
5348
  }
5429
5349
  /**
5430
5350
  * Create a new and empty `SVGElement` &lt;svg&gt; in the svg-namespace.
@@ -5664,7 +5584,10 @@ drawutilssvg.HEAD_XML = [
5664
5584
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
5665
5585
  * @modified 2021-11-12 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
5666
5586
  * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
5667
- * @version 1.10.0
5587
+ * @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
5588
+ * @modified 2022-02-03 Added the `cross(...)` function.
5589
+ * @modified 2022-03-27 Added the `texturedPoly` function.
5590
+ * @version 1.12.0
5668
5591
  **/
5669
5592
  // Todo: rename this class to Drawutils?
5670
5593
  /**
@@ -5818,6 +5741,96 @@ class drawutils {
5818
5741
  this.offset.x + position.x * this.scale.x, this.offset.y + position.y * this.scale.y, size.x * this.scale.x, size.y * this.scale.y);
5819
5742
  this.ctx.restore();
5820
5743
  }
5744
+ /**
5745
+ * Draw an image at the given position with the given size.<br>
5746
+ * <br>
5747
+ * 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.
5748
+ *
5749
+ * @method texturedPoly
5750
+ * @param {Image} textureImage - The image object to draw.
5751
+ * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
5752
+ * @param {Polygon} polygon - The polygon to use as clip path.
5753
+ * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
5754
+ * @param {number} rotation - The rotation to use for the polygon (and for the texture).
5755
+ * @param {XYCoords={x:0,y:0}} rotationCenter - (optional) The rotational center; default is center of bounding box.
5756
+ * @return {void}
5757
+ * @instance
5758
+ * @memberof drawutils
5759
+ **/
5760
+ texturedPoly(textureImage, textureSize, polygon, polygonPosition, rotation) {
5761
+ var basePolygonBounds = polygon.getBounds();
5762
+ var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
5763
+ // var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
5764
+ // var rotationalOffset = { x: 0, y: 0 };
5765
+ basePolygonBounds.getCenter().sub(targetCenterDifference);
5766
+ // Get the position offset of the polygon
5767
+ var targetTextureSize = new Vertex(textureSize.width, textureSize.height);
5768
+ // var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
5769
+ var targetTextureOffset = new Vertex(textureSize.min.x, textureSize.min.y).sub(polygonPosition);
5770
+ this.ctx.save();
5771
+ // this.ctx.translate(this.offset.x + rotationCenter.x * this.scale.x, this.offset.y + rotationCenter.y * this.scale.y);
5772
+ this.ctx.translate(this.offset.x + polygonPosition.x * this.scale.x, this.offset.y + polygonPosition.y * this.scale.y);
5773
+ drawutils.helpers.clipPoly(this.ctx, {
5774
+ x: -polygonPosition.x * this.scale.x,
5775
+ y: -polygonPosition.y * this.scale.y
5776
+ }, this.scale, polygon.vertices);
5777
+ this.ctx.scale(this.scale.x, this.scale.y);
5778
+ this.ctx.rotate(rotation);
5779
+ this.ctx.drawImage(textureImage, 0, 0, textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
5780
+ textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
5781
+ targetTextureOffset.x, // * this.scale.x,
5782
+ targetTextureOffset.y, // * this.scale.y,
5783
+ targetTextureSize.x, // * this.scale.x,
5784
+ targetTextureSize.y // * this.scale.y
5785
+ );
5786
+ this.ctx.restore();
5787
+ }
5788
+ _texturedPoly(textureImage, textureSize, polygon, polygonPosition, rotation, rotationCenter = { x: 0, y: 0 }) {
5789
+ var basePolygonBounds = polygon.getBounds();
5790
+ var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
5791
+ var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
5792
+ // var rotationalOffset = { x: 0, y: 0 };
5793
+ var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
5794
+ // Get the position offset of the polygon
5795
+ var targetTextureSize = new Vertex(textureSize.width, textureSize.height);
5796
+ var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
5797
+ this.ctx.save();
5798
+ // this.ctx.translate(
5799
+ // this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
5800
+ // this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
5801
+ // );
5802
+ this.ctx.translate(this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x, this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y);
5803
+ this.ctx.rotate(rotation);
5804
+ drawutils.helpers.clipPoly(this.ctx, {
5805
+ x: (-targetCenterDifference.x * 1 - tileCenter.x - rotationalOffset.x) * this.scale.x,
5806
+ y: (-targetCenterDifference.y * 1 - tileCenter.y - rotationalOffset.y) * this.scale.y
5807
+ }, this.scale, polygon.vertices);
5808
+ this.ctx.drawImage(textureImage, 0, 0, textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
5809
+ textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
5810
+ (-polygonPosition.x + targetTextureOffset.x * 1 - rotationalOffset.x * 1) * this.scale.x, (-polygonPosition.y + targetTextureOffset.y * 1 - rotationalOffset.y * 1) * this.scale.y, targetTextureSize.x * this.scale.x, targetTextureSize.y * this.scale.y);
5811
+ // const scaledTextureSize = new Bounds(
5812
+ // new Vertex(
5813
+ // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x,
5814
+ // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y
5815
+ // ).scaleXY(this.scale, rotationCenter),
5816
+ // new Vertex(
5817
+ // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x + targetTextureSize.x,
5818
+ // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y + targetTextureSize.y
5819
+ // ).scaleXY(this.scale, rotationCenter)
5820
+ // );
5821
+ // this.ctx.drawImage(
5822
+ // textureImage,
5823
+ // 0,
5824
+ // 0,
5825
+ // textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
5826
+ // textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
5827
+ // scaledTextureSize.min.x,
5828
+ // scaledTextureSize.min.y,
5829
+ // scaledTextureSize.width,
5830
+ // scaledTextureSize.height
5831
+ // );
5832
+ this.ctx.restore();
5833
+ }
5821
5834
  /**
5822
5835
  * Draw a rectangle.
5823
5836
  *
@@ -6258,11 +6271,12 @@ class drawutils {
6258
6271
  * @param {XYCoords} center - The center of the crosshair.
6259
6272
  * @param {number} radius - The radius of the crosshair.
6260
6273
  * @param {string} color - The CSS color to draw the crosshair with.
6274
+ * @param {number=0.5} lineWidth - (optional, default=0.5) The line width to use.
6261
6275
  * @return {void}
6262
6276
  * @instance
6263
6277
  * @memberof drawutils
6264
6278
  */
6265
- crosshair(center, radius, color) {
6279
+ crosshair(center, radius, color, lineWidth) {
6266
6280
  this.ctx.save();
6267
6281
  this.ctx.beginPath();
6268
6282
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y);
@@ -6270,7 +6284,34 @@ class drawutils {
6270
6284
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y - radius);
6271
6285
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y + radius);
6272
6286
  this.ctx.strokeStyle = color;
6273
- this.ctx.lineWidth = 0.5;
6287
+ this.ctx.lineWidth = lineWidth || 0.5;
6288
+ this.ctx.stroke();
6289
+ this.ctx.closePath();
6290
+ this.ctx.restore();
6291
+ }
6292
+ /**
6293
+ * Draw a cross with diagonal axes with given radius, color and lineWidth at the given position.<br>
6294
+ * <br>
6295
+ * Note that the x's radius will not be affected by scaling.
6296
+ *
6297
+ * @method crosshair
6298
+ * @param {XYCoords} center - The center of the crosshair.
6299
+ * @param {number} radius - The radius of the crosshair.
6300
+ * @param {string} color - The CSS color to draw the crosshair with.
6301
+ * @param {number=1} lineWidth - (optional, default=1.0) The line width to use.
6302
+ * @return {void}
6303
+ * @instance
6304
+ * @memberof drawutils
6305
+ */
6306
+ cross(center, radius, color, lineWidth) {
6307
+ this.ctx.save();
6308
+ this.ctx.beginPath();
6309
+ this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y - radius);
6310
+ this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y + radius);
6311
+ this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y + radius);
6312
+ this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y - radius);
6313
+ this.ctx.strokeStyle = color;
6314
+ this.ctx.lineWidth = lineWidth || 1.0;
6274
6315
  this.ctx.stroke();
6275
6316
  this.ctx.closePath();
6276
6317
  this.ctx.restore();
@@ -6448,6 +6489,21 @@ class drawutils {
6448
6489
  this.ctx.fillRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
6449
6490
  }
6450
6491
  }
6492
+ drawutils.helpers = {
6493
+ // A helper function to define the clipping path.
6494
+ // This could be a candidate for the draw library.
6495
+ clipPoly: (ctx, offset, scale, vertices) => {
6496
+ ctx.beginPath();
6497
+ // Set clip mask
6498
+ ctx.moveTo(offset.x + vertices[0].x * scale.x, offset.y + vertices[0].y * scale.y);
6499
+ for (var i = 1; i < vertices.length; i++) {
6500
+ const vert = vertices[i];
6501
+ ctx.lineTo(offset.x + vert.x * scale.x, offset.y + vert.y * scale.y);
6502
+ }
6503
+ ctx.closePath();
6504
+ ctx.clip();
6505
+ }
6506
+ };
6451
6507
 
6452
6508
  /**
6453
6509
  * @author Ikaros Kappler
@@ -6457,7 +6513,10 @@ class drawutils {
6457
6513
  * @modified 2020-10-15 Re-added the text() function.
6458
6514
  * @modified 2021-01-24 Added the `setCurrentId` function.
6459
6515
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
6460
- * @version 0.0.5
6516
+ * @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
6517
+ * @modified 2022-02-03 Added the `cross(...)` function.
6518
+ * @modified 2022-03-27 Added the `texturedPoly` function.
6519
+ * @version 0.0.7
6461
6520
  **/
6462
6521
  /**
6463
6522
  * @classdesc A wrapper class for basic drawing operations. This is the WebGL
@@ -6654,6 +6713,24 @@ class drawutilsgl {
6654
6713
  image(image, position, size) {
6655
6714
  // NOT YET IMPLEMENTED
6656
6715
  }
6716
+ /**
6717
+ * Draw an image at the given position with the given size.<br>
6718
+ * <br>
6719
+ * 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.
6720
+ *
6721
+ * @method texturedPoly
6722
+ * @param {Image} textureImage - The image object to draw.
6723
+ * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
6724
+ * @param {Polygon} polygon - The polygon to use as clip path.
6725
+ * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
6726
+ * @param {number} rotation - The rotation to use for the polygon (and for the texture).
6727
+ * @return {void}
6728
+ * @instance
6729
+ * @memberof drawutilsgl
6730
+ **/
6731
+ texturedPoly(textureImage, textureSize, polygon, polygonPosition, rotation) {
6732
+ // NOT YET IMPLEMENTED
6733
+ }
6657
6734
  // +---------------------------------------------------------------------------------
6658
6735
  // | This is the final helper function for drawing and filling stuff. It is not
6659
6736
  // | intended to be used from the outside.
@@ -6935,11 +7012,29 @@ class drawutilsgl {
6935
7012
  * @param {XYCoords} center - The center of the crosshair.
6936
7013
  * @param {number} radius - The radius of the crosshair.
6937
7014
  * @param {string} color - The CSS color to draw the crosshair with.
7015
+ * @param {number=0.5} lineWidth - (optional, default=0.5) The line width to use.
6938
7016
  * @return {void}
6939
7017
  * @instance
6940
7018
  * @memberof drawutils
6941
7019
  */
6942
- crosshair(center, radius, color) {
7020
+ crosshair(center, radius, color, lineWidth) {
7021
+ // NOT YET IMPLEMENTED
7022
+ }
7023
+ /**
7024
+ * Draw a cross with diagonal axes with given radius, color and lineWidth at the given position.<br>
7025
+ * <br>
7026
+ * Note that the x's radius will not be affected by scaling.
7027
+ *
7028
+ * @method crosshair
7029
+ * @param {XYCoords} center - The center of the crosshair.
7030
+ * @param {number} radius - The radius of the crosshair.
7031
+ * @param {string} color - The CSS color to draw the crosshair with.
7032
+ * @param {number=1} lineWidth - (optional, default=1.0) The line width to use.
7033
+ * @return {void}
7034
+ * @instance
7035
+ * @memberof drawutils
7036
+ */
7037
+ cross(center, radius, color, lineWidth) {
6943
7038
  // NOT YET IMPLEMENTED
6944
7039
  }
6945
7040
  /**
@@ -7503,43 +7598,6 @@ class Triangle {
7503
7598
  toString() {
7504
7599
  return "{ a : " + this.a.toString() + ", b : " + this.b.toString() + ", c : " + this.c.toString() + "}";
7505
7600
  }
7506
- /**
7507
- * Create an SVG representation of this triangle.
7508
- *
7509
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
7510
- * @method toSVGString
7511
- * @param {object=} options - An optional set of options, like 'className'.
7512
- * @return {string} The SVG string.
7513
- * @instance
7514
- * @memberof Triangle
7515
- **/
7516
- toSVGString(options) {
7517
- // options = options || {};
7518
- // var buffer = [];
7519
- // buffer.push("<path");
7520
- // if (options.className) buffer.push(' class="' + options.className + '"');
7521
- // buffer.push(' d="');
7522
- // var vertices = [this.a, this.b, this.c];
7523
- // if (vertices.length > 0) {
7524
- // buffer.push("M ");
7525
- // buffer.push(vertices[0].x);
7526
- // buffer.push(" ");
7527
- // buffer.push(vertices[0].y);
7528
- // for (var i = 1; i < vertices.length; i++) {
7529
- // buffer.push(" L ");
7530
- // buffer.push(vertices[i].x);
7531
- // buffer.push(" ");
7532
- // buffer.push(vertices[i].y);
7533
- // }
7534
- // //if( !this.isOpen ) {
7535
- // buffer.push(" Z");
7536
- // //}
7537
- // }
7538
- // buffer.push('" />');
7539
- // return buffer.join("");
7540
- console.warn("[Deprecation] Warning: the Triangle.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
7541
- return "";
7542
- }
7543
7601
  /**
7544
7602
  * This function should invalidate any installed listeners and invalidate this object.
7545
7603
  * After calling this function the object might not hold valid data any more and
@@ -8609,20 +8667,6 @@ class PBImage {
8609
8667
  this.upperLeft = upperLeft;
8610
8668
  this.lowerRight = lowerRight;
8611
8669
  }
8612
- /**
8613
- * Convert this vertex to SVG code.
8614
- *
8615
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
8616
- * @method toSVGString
8617
- * @param {object=} options - An optional set of options, like 'className'.
8618
- * @return {string} A string representing the SVG code for this vertex.
8619
- * @instance
8620
- * @memberof PBImage
8621
- **/
8622
- toSVGString(options) {
8623
- console.warn("PBImage is not yet SVG serializable. Returning empty SVG string.");
8624
- return "";
8625
- }
8626
8670
  /**
8627
8671
  * This function should invalidate any installed listeners and invalidate this object.
8628
8672
  * After calling this function the object might not hold valid data any more and
@@ -8679,20 +8723,6 @@ class PBText {
8679
8723
  this.textAlign = options.textAlign;
8680
8724
  this.rotation = options.rotation;
8681
8725
  }
8682
- /**
8683
- * Create an SVG representation of this circle.
8684
- *
8685
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
8686
- * @method toSVGString
8687
- * @param {object=} options - An optional set of options, like 'className'.
8688
- * @return {string} A string representing the SVG code for this vertex.
8689
- * @instance
8690
- * @memberof Circle
8691
- */
8692
- toSVGString(options) {
8693
- console.warn("[PBText.toSVGString()] This function is not implemented as it defines a deprecated method. Use the 'drawutilssvg.text()' method instead.");
8694
- return "";
8695
- }
8696
8726
  /**
8697
8727
  * This function should invalidate any installed listeners and invalidate this object.
8698
8728
  * After calling this function the object might not hold valid data any more and
@@ -9425,27 +9455,6 @@ class VEllipse {
9425
9455
  }
9426
9456
  return curves;
9427
9457
  }
9428
- /**
9429
- * Create an SVG representation of this ellipse.
9430
- *
9431
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
9432
- * @param {object} options { className?:string }
9433
- * @return string The SVG string
9434
- */
9435
- toSVGString(options) {
9436
- // options = options || {};
9437
- // var buffer: Array<string> = [];
9438
- // buffer.push("<ellipse");
9439
- // if (options.className) buffer.push(' class="' + options.className + '"');
9440
- // buffer.push(' cx="' + this.center.x + '"');
9441
- // buffer.push(' cy="' + this.center.y + '"');
9442
- // buffer.push(' rx="' + this.axis.x + '"');
9443
- // buffer.push(' ry="' + this.axis.y + '"');
9444
- // buffer.push(" />");
9445
- // return buffer.join("");
9446
- console.warn("[Deprecation] Warning: the VEllipse.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
9447
- return "";
9448
- }
9449
9458
  /**
9450
9459
  * This function should invalidate any installed listeners and invalidate this object.
9451
9460
  * After calling this function the object might not hold valid data any more and
@@ -11847,100 +11856,5 @@ PlotBoilerplate.utils = {
11847
11856
  }
11848
11857
  }; // END utils
11849
11858
 
11850
- /**
11851
- * Todos:
11852
- * + use a Drawable interface
11853
- * + use a SVGSerializable interface
11854
- *
11855
- * @require Vertex
11856
- *
11857
- * @deprecated THIS CLASS IS DEPRECATED. Please use the new `drawutilssvg` instead.
11858
- *
11859
- * @author Ikaros Kappler
11860
- * @date 2018-12-04
11861
- * @modified 2019-11-07 Added the 'Triangle' style class.
11862
- * @modified 2019-11-13 Added the <?xml ...?> tag.
11863
- * @modified 2020-03-25 Ported this class from vanilla-JS to Typescript.
11864
- * @modified 2020-12-17 Added Circle and CircleSection style classes.
11865
- * @modified 2021-01-26 DEPRECATION
11866
- * @version 1.0.5
11867
- **/
11868
- /**
11869
- * @classdesc A default SVG builder.
11870
- *
11871
- * @requires SVGSerializable
11872
- * @requires Vertex
11873
- */
11874
- class SVGBuilder {
11875
- /**
11876
- * @constructor
11877
- **/
11878
- constructor() {
11879
- console.warn("THIS CLASS IS DEPRECATED. Please use the new 'drawutilssvg' instead.");
11880
- }
11881
- ;
11882
- /**
11883
- * Builds the SVG code from the given list of drawables.
11884
- *
11885
- * @param {object[]} drawables - The drawable elements (should implement Drawable) to be converted (each must have a toSVGString-function).
11886
- * @param {object} options - { canvasSize, zoom, offset }
11887
- * @return {string}
11888
- **/
11889
- build(drawables, options) {
11890
- var nl = '\n';
11891
- var indent = ' ';
11892
- var buffer = [];
11893
- buffer.push('<?xml version="1.0" encoding="UTF-8"?>' + nl);
11894
- buffer.push('<svg width="' + options.canvasSize.width + '" height="' + options.canvasSize.height + '"');
11895
- buffer.push(' viewBox="');
11896
- buffer.push('0');
11897
- buffer.push(' ');
11898
- buffer.push('0');
11899
- buffer.push(' ');
11900
- buffer.push(options.canvasSize.width.toString());
11901
- buffer.push(' ');
11902
- buffer.push(options.canvasSize.height.toString());
11903
- buffer.push('"');
11904
- buffer.push(' xmlns="http://www.w3.org/2000/svg">' + nl);
11905
- buffer.push(indent + '<defs>' + nl);
11906
- buffer.push(indent + '<style>' + nl);
11907
- buffer.push(indent + indent + ' .Vertex { fill : blue; stroke : none; } ' + nl);
11908
- buffer.push(indent + indent + ' .Triangle { fill : none; stroke : turquoise; stroke-width : 1px; } ' + nl);
11909
- buffer.push(indent + indent + ' .Polygon { fill : none; stroke : green; stroke-width : 2px; } ' + nl);
11910
- buffer.push(indent + indent + ' .BezierPath { fill : none; stroke : blue; stroke-width : 2px; } ' + nl);
11911
- buffer.push(indent + indent + ' .VEllipse { fill : none; stroke : black; stroke-width : 1px; } ' + nl);
11912
- buffer.push(indent + indent + ' .Line { fill : none; stroke : purple; stroke-width : 1px; } ' + nl);
11913
- buffer.push(indent + indent + ' .Circle { fill : none; stroke : purple; stroke-width : 1px; } ' + nl);
11914
- buffer.push(indent + indent + ' .CircleSector { fill : none; stroke : purple; stroke-width : 1px; } ' + nl);
11915
- buffer.push(indent + '</style>' + nl);
11916
- buffer.push(indent + '</defs>' + nl);
11917
- buffer.push(indent + '<g class="main-g"');
11918
- if (options.zoom || options.offset) {
11919
- buffer.push(' transform="');
11920
- if (options.zoom)
11921
- buffer.push('scale(' + options.zoom.x + ',' + options.zoom.y + ')');
11922
- if (options.offset)
11923
- buffer.push(' translate(' + options.offset.x + ',' + options.offset.y + ')');
11924
- buffer.push('"');
11925
- }
11926
- buffer.push('>' + nl);
11927
- for (var i in drawables) {
11928
- var d = drawables[i];
11929
- if (typeof d.toSVGString == 'function') {
11930
- buffer.push(indent + indent);
11931
- buffer.push(d.toSVGString({ 'className': d.className }));
11932
- buffer.push(nl);
11933
- }
11934
- else {
11935
- console.warn('Unrecognized drawable type has no toSVGString()-function. Ignoring: ' + d.className);
11936
- }
11937
- }
11938
- buffer.push(indent + '</g>' + nl);
11939
- buffer.push('</svg>' + nl);
11940
- return buffer.join('');
11941
- }
11942
- ;
11943
- }
11944
-
11945
- export { BezierPath, Bounds, Circle, CircleSector, CubicBezierCurve, Grid, KeyHandler, Line, MouseHandler, PBImage, PBText, PlotBoilerplate, Polygon, SVGBuilder, Triangle, UIDGenerator, VEllipse, VEllipseSector, Vector, VertTuple, Vertex, VertexAttr, VertexListeners, XMouseEvent, XWheelEvent, drawutils, drawutilsgl, drawutilssvg, geomutils };
11859
+ export { BezierPath, Bounds, Circle, CircleSector, CubicBezierCurve, Grid, KeyHandler, Line, MouseHandler, PBImage, PBText, PlotBoilerplate, Polygon, Triangle, UIDGenerator, VEllipse, VEllipseSector, Vector, VertTuple, Vertex, VertexAttr, VertexListeners, XMouseEvent, XWheelEvent, drawutils, drawutilsgl, drawutilssvg, geomutils };
11946
11860
  //# sourceMappingURL=index.esm.js.map