plotboilerplate 1.12.9 → 1.15.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 (113) hide show
  1. package/README.md +5 -1
  2. package/changelog.md +34 -0
  3. package/dist/index.esm.js +435 -92
  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 +449 -91
  10. package/dist/plotboilerplate.min.js +1 -1
  11. package/package.json +1 -1
  12. package/src/cjs/BezierPath.d.ts +12 -1
  13. package/src/cjs/BezierPath.js +34 -5
  14. package/src/cjs/BezierPath.js.map +1 -1
  15. package/src/cjs/PBText.d.ts +116 -0
  16. package/src/cjs/PBText.js +66 -0
  17. package/src/cjs/PBText.js.map +1 -0
  18. package/src/cjs/PlotBoilerplate.d.ts +2 -1
  19. package/src/cjs/PlotBoilerplate.js +43 -15
  20. package/src/cjs/PlotBoilerplate.js.map +1 -1
  21. package/src/cjs/Polygon.d.ts +22 -1
  22. package/src/cjs/Polygon.js +102 -39
  23. package/src/cjs/Polygon.js.map +1 -1
  24. package/src/cjs/Vertex.d.ts +42 -4
  25. package/src/cjs/Vertex.js +62 -7
  26. package/src/cjs/Vertex.js.map +1 -1
  27. package/src/cjs/draw.d.ts +30 -2
  28. package/src/cjs/draw.js +51 -6
  29. package/src/cjs/draw.js.map +1 -1
  30. package/src/cjs/drawgl.d.ts +29 -2
  31. package/src/cjs/drawgl.js +21 -4
  32. package/src/cjs/drawgl.js.map +1 -1
  33. package/src/cjs/drawutilssvg.d.ts +25 -7
  34. package/src/cjs/drawutilssvg.js +62 -14
  35. package/src/cjs/drawutilssvg.js.map +1 -1
  36. package/src/cjs/entry.js +1 -0
  37. package/src/cjs/index.d.ts +1 -0
  38. package/src/cjs/index.js +1 -0
  39. package/src/cjs/index.js.map +1 -1
  40. package/src/cjs/interfaces/DrawLib.d.ts +27 -6
  41. package/src/cjs/interfaces/DrawLib.js +3 -0
  42. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  43. package/src/cjs/interfaces/core.d.ts +9 -1
  44. package/src/cjs/interfaces/core.js +1 -0
  45. package/src/cjs/interfaces/core.js.map +1 -1
  46. package/src/cjs/utils/datastructures/Color.d.ts +28 -15
  47. package/src/cjs/utils/datastructures/Color.js +276 -88
  48. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  49. package/src/cjs/utils/findInVertexArray.d.ts +19 -0
  50. package/src/cjs/utils/findInVertexArray.js +29 -0
  51. package/src/cjs/utils/findInVertexArray.js.map +1 -0
  52. package/src/esm/BezierPath.d.ts +12 -1
  53. package/src/esm/BezierPath.js +34 -5
  54. package/src/esm/BezierPath.js.map +1 -1
  55. package/src/esm/PBText.d.ts +116 -0
  56. package/src/esm/PBText.js +61 -0
  57. package/src/esm/PBText.js.map +1 -0
  58. package/src/esm/PlotBoilerplate.d.ts +2 -1
  59. package/src/esm/PlotBoilerplate.js +43 -15
  60. package/src/esm/PlotBoilerplate.js.map +1 -1
  61. package/src/esm/Polygon.d.ts +22 -1
  62. package/src/esm/Polygon.js +102 -39
  63. package/src/esm/Polygon.js.map +1 -1
  64. package/src/esm/Vertex.d.ts +42 -4
  65. package/src/esm/Vertex.js +62 -7
  66. package/src/esm/Vertex.js.map +1 -1
  67. package/src/esm/draw.d.ts +30 -2
  68. package/src/esm/draw.js +51 -6
  69. package/src/esm/draw.js.map +1 -1
  70. package/src/esm/drawgl.d.ts +29 -2
  71. package/src/esm/drawgl.js +21 -4
  72. package/src/esm/drawgl.js.map +1 -1
  73. package/src/esm/drawutilssvg.d.ts +25 -7
  74. package/src/esm/drawutilssvg.js +62 -14
  75. package/src/esm/drawutilssvg.js.map +1 -1
  76. package/src/esm/entry.js +1 -0
  77. package/src/esm/index.d.ts +1 -0
  78. package/src/esm/index.js +1 -0
  79. package/src/esm/index.js.map +1 -1
  80. package/src/esm/interfaces/DrawLib.d.ts +27 -6
  81. package/src/esm/interfaces/DrawLib.js +3 -0
  82. package/src/esm/interfaces/DrawLib.js.map +1 -1
  83. package/src/esm/interfaces/core.d.ts +9 -1
  84. package/src/esm/interfaces/core.js +1 -0
  85. package/src/esm/interfaces/core.js.map +1 -1
  86. package/src/esm/utils/datastructures/Color.d.ts +28 -15
  87. package/src/esm/utils/datastructures/Color.js +277 -89
  88. package/src/esm/utils/datastructures/Color.js.map +1 -1
  89. package/src/esm/utils/findInVertexArray.d.ts +19 -0
  90. package/src/esm/utils/findInVertexArray.js +25 -0
  91. package/src/esm/utils/findInVertexArray.js.map +1 -0
  92. package/src/ts/BezierPath.ts +37 -5
  93. package/src/ts/PBText.ts +147 -0
  94. package/src/ts/PlotBoilerplate.ts +47 -19
  95. package/src/ts/Polygon.ts +493 -451
  96. package/src/ts/Vertex.ts +66 -7
  97. package/src/ts/draw.ts +71 -8
  98. package/src/ts/drawgl.ts +48 -8
  99. package/src/ts/drawutilssvg.ts +94 -17
  100. package/src/ts/index.ts +1 -0
  101. package/src/ts/interfaces/DrawLib.ts +30 -4
  102. package/src/ts/interfaces/core.ts +9 -0
  103. package/src/ts/utils/datastructures/Color.ts +695 -508
  104. package/src/ts/utils/findInVertexArray.ts +28 -0
  105. package/dist/plotboilerplate.browser.min.js.LICENSE.txt +0 -8
  106. package/src/ts/utils/algorithms/clearPolygonDuplicateVertices.ts~ +0 -5
  107. package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts~ +0 -45
  108. package/src/ts/utils/algorithms/sh-tmp.ts~ +0 -59
  109. package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts~ +0 -113
  110. package/src/ts/utils/algorithms/sutherlandHodgman.ts~ +0 -88
  111. package/src/ts/utils/datastructures/Color.ts~ +0 -331
  112. package/src/ts/utils/datastructures/Girih.ts~ +0 -151
  113. package/src/ts/utils/datastructures/GirihTile.ts~ +0 -419
@@ -882,6 +882,35 @@ var BezierPath = /** @class */ (function () {
882
882
  this.updateArcLengths();
883
883
  return this;
884
884
  };
885
+ /**
886
+ * Scale the whole bezier path by the given uniform factor.
887
+ *
888
+ * @method scale
889
+ * @param {Vertex} anchor - The scale origin to scale from.
890
+ * @param {number} scaleFactor - The scalar to be multiplied with.
891
+ * @instance
892
+ * @memberof BezierPath
893
+ * @return {BezierPath} this for chaining.
894
+ **/
895
+ BezierPath.prototype.scale = function (anchor, scaleFactor) {
896
+ // var scaleFactors : XYCoords = { x : scaleFactor, y : scaleFactor };
897
+ // for (var i = 0; i < this.bezierCurves.length; i++) {
898
+ // var curve = this.bezierCurves[i];
899
+ // curve.getStartPoint().scale(scaleFactor, anchor);
900
+ // curve.getStartControlPoint().scale(scaleFactor, anchor);
901
+ // curve.getEndControlPoint().scale(scaleFactor, anchor);
902
+ // // Do NOT scale the end point here!
903
+ // // Don't forget that the curves are connected and on curve's end point
904
+ // // the the successor's start point (same instance)!
905
+ // }
906
+ // // Finally move the last end point (was not scaled yet)
907
+ // if (this.bezierCurves.length > 0 && !this.adjustCircular) {
908
+ // this.bezierCurves[this.bezierCurves.length - 1].getEndPoint().scale(scaleFactor, anchor);
909
+ // }
910
+ // this.updateArcLengths();
911
+ // return this;
912
+ return this.scaleXY({ x: scaleFactor, y: scaleFactor }, anchor);
913
+ };
885
914
  /**
886
915
  * Scale the whole bezier path by the given (x,y)-factors.
887
916
  *
@@ -892,19 +921,19 @@ var BezierPath = /** @class */ (function () {
892
921
  * @memberof BezierPath
893
922
  * @return {BezierPath} this for chaining.
894
923
  **/
895
- BezierPath.prototype.scale = function (anchor, scaling) {
924
+ BezierPath.prototype.scaleXY = function (scaleFactors, anchor) {
896
925
  for (var i = 0; i < this.bezierCurves.length; i++) {
897
926
  var curve = this.bezierCurves[i];
898
- curve.getStartPoint().scale(scaling, anchor);
899
- curve.getStartControlPoint().scale(scaling, anchor);
900
- curve.getEndControlPoint().scale(scaling, anchor);
927
+ curve.getStartPoint().scaleXY(scaleFactors, anchor);
928
+ curve.getStartControlPoint().scaleXY(scaleFactors, anchor);
929
+ curve.getEndControlPoint().scaleXY(scaleFactors, anchor);
901
930
  // Do NOT scale the end point here!
902
931
  // Don't forget that the curves are connected and on curve's end point
903
932
  // the the successor's start point (same instance)!
904
933
  }
905
934
  // Finally move the last end point (was not scaled yet)
906
935
  if (this.bezierCurves.length > 0 && !this.adjustCircular) {
907
- this.bezierCurves[this.bezierCurves.length - 1].getEndPoint().scale(scaling, anchor);
936
+ this.bezierCurves[this.bezierCurves.length - 1].getEndPoint().scaleXY(scaleFactors, anchor);
908
937
  }
909
938
  this.updateArcLengths();
910
939
  return this;
@@ -3900,6 +3929,78 @@ exports.PBImage = PBImage;
3900
3929
 
3901
3930
  /***/ }),
3902
3931
 
3932
+ /***/ 196:
3933
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
3934
+
3935
+
3936
+ /**
3937
+ * @author Ikaros Kappler
3938
+ * @date 2021-11-16
3939
+ * @version 1.0.0
3940
+ **/
3941
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3942
+ exports.PBText = void 0;
3943
+ var UIDGenerator_1 = __webpack_require__(197);
3944
+ var Vertex_1 = __webpack_require__(421);
3945
+ /**
3946
+ * @classdesc A simple text element: position, fontSize, fontFamily, color, textAlign, lineHeight and rotation.
3947
+ *
3948
+ * @requires FontOptions
3949
+ * @requires FontSize
3950
+ * @requires FontStyle
3951
+ * @requires FontWeight
3952
+ * @requires Vertex
3953
+ * @requires SVGSerializale
3954
+ * @requires UID
3955
+ * @requires UIDGenerator
3956
+ **/
3957
+ var PBText = /** @class */ (function () {
3958
+ /**
3959
+ * Create a new circle with given center point and radius.
3960
+ *
3961
+ * @constructor
3962
+ * @name Circle
3963
+ * @param {Vertex} center - The center point of the circle.
3964
+ * @param {number} radius - The radius of the circle.
3965
+ */
3966
+ function PBText(text, anchor, options) {
3967
+ /**
3968
+ * Required to generate proper CSS classes and other class related IDs.
3969
+ **/
3970
+ this.className = "PBText";
3971
+ this.uid = UIDGenerator_1.UIDGenerator.next();
3972
+ this.text = text;
3973
+ this.anchor = anchor !== null && anchor !== void 0 ? anchor : new Vertex_1.Vertex();
3974
+ this.color = options.color;
3975
+ this.fontFamily = options.fontFamily;
3976
+ this.fontSize = options.fontSize;
3977
+ this.fontStyle = options.fontStyle;
3978
+ this.fontWeight = options.fontWeight;
3979
+ this.lineHeight = options.lineHeight;
3980
+ this.textAlign = options.textAlign;
3981
+ this.rotation = options.rotation;
3982
+ }
3983
+ /**
3984
+ * Create an SVG representation of this circle.
3985
+ *
3986
+ * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
3987
+ * @method toSVGString
3988
+ * @param {object=} options - An optional set of options, like 'className'.
3989
+ * @return {string} A string representing the SVG code for this vertex.
3990
+ * @instance
3991
+ * @memberof Circle
3992
+ */
3993
+ PBText.prototype.toSVGString = function (options) {
3994
+ console.warn("[PBText.toSVGString()] This function is not implemented as it defines a deprecated method. Use the 'drawutilssvg.text()' method instead.");
3995
+ return "";
3996
+ };
3997
+ return PBText;
3998
+ }()); // END class
3999
+ exports.PBText = PBText;
4000
+ //# sourceMappingURL=PBText.js.map
4001
+
4002
+ /***/ }),
4003
+
3903
4004
  /***/ 919:
3904
4005
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
3905
4006
 
@@ -3980,7 +4081,8 @@ var __webpack_unused_export__;
3980
4081
  * @modified 2021-03-03 Added the `VEllipseSector` drawable.
3981
4082
  * @modified 2021-03-29 Clearing `currentClassName` and `currentId` after drawing each drawable.
3982
4083
  * @modified 2021-04-25 Extending `remove` to accept arrays of drawables.
3983
- * @version 1.14.0
4084
+ * @modified 2021-11-16 Adding the `PBText` drawable.
4085
+ * @version 1.15.0
3984
4086
  *
3985
4087
  * @file PlotBoilerplate
3986
4088
  * @fileoverview The main class.
@@ -4008,6 +4110,7 @@ var VEllipseSector_1 = __webpack_require__(965);
4008
4110
  var Vector_1 = __webpack_require__(73);
4009
4111
  var Vertex_1 = __webpack_require__(421);
4010
4112
  var VertexAttr_1 = __webpack_require__(861);
4113
+ var PBText_1 = __webpack_require__(196);
4011
4114
  /**
4012
4115
  * @classdesc The main class of the PlotBoilerplate.
4013
4116
  *
@@ -4246,6 +4349,12 @@ var PlotBoilerplate = /** @class */ (function () {
4246
4349
  image: {
4247
4350
  color: "#a8a8a8",
4248
4351
  lineWidth: 1
4352
+ },
4353
+ text: {
4354
+ color: "rgba(192,0,128,0.5)",
4355
+ lineWidth: 1,
4356
+ fill: true,
4357
+ anchor: true
4249
4358
  }
4250
4359
  }; // END drawConfig
4251
4360
  // +---------------------------------------------------------------------------------
@@ -4367,7 +4476,7 @@ var PlotBoilerplate = /** @class */ (function () {
4367
4476
  var blob = new Blob([svgCode], { type: "image/svg;charset=utf-8" });
4368
4477
  // See documentation for FileSaver.js for usage.
4369
4478
  // https://github.com/eligrey/FileSaver.js
4370
- if (typeof globalThis["saveAs"] != "function")
4479
+ if (typeof globalThis["saveAs"] !== "function")
4371
4480
  throw "Cannot save file; did you load the ./utils/savefile helper function and the eligrey/SaveFile library?";
4372
4481
  var _saveAs = globalThis["saveAs"];
4373
4482
  _saveAs(blob, "plotboilerplate.svg");
@@ -4473,7 +4582,6 @@ var PlotBoilerplate = /** @class */ (function () {
4473
4582
  PlotBoilerplate.prototype.add = function (drawable, redraw) {
4474
4583
  if (Array.isArray(drawable)) {
4475
4584
  var arr = drawable;
4476
- // for( var i in arr )
4477
4585
  for (var i = 0; i < arr.length; i++) {
4478
4586
  this.add(arr[i], false);
4479
4587
  }
@@ -4519,9 +4627,9 @@ var PlotBoilerplate = /** @class */ (function () {
4519
4627
  }
4520
4628
  else if (drawable instanceof Polygon_1.Polygon) {
4521
4629
  this.drawables.push(drawable);
4522
- // for( var i in drawable.vertices )
4523
- for (var i = 0; i < drawable.vertices.length; i++)
4630
+ for (var i = 0; i < drawable.vertices.length; i++) {
4524
4631
  this.vertices.push(drawable.vertices[i]);
4632
+ }
4525
4633
  }
4526
4634
  else if (drawable instanceof Triangle_1.Triangle) {
4527
4635
  this.drawables.push(drawable);
@@ -4533,8 +4641,9 @@ var PlotBoilerplate = /** @class */ (function () {
4533
4641
  this.drawables.push(drawable);
4534
4642
  var bezierPath = drawable;
4535
4643
  for (var i = 0; i < bezierPath.bezierCurves.length; i++) {
4536
- if (!drawable.adjustCircular && i == 0)
4644
+ if (!drawable.adjustCircular && i == 0) {
4537
4645
  this.vertices.push(bezierPath.bezierCurves[i].startPoint);
4646
+ }
4538
4647
  this.vertices.push(bezierPath.bezierCurves[i].endPoint);
4539
4648
  this.vertices.push(bezierPath.bezierCurves[i].startControlPoint);
4540
4649
  this.vertices.push(bezierPath.bezierCurves[i].endControlPoint);
@@ -4553,6 +4662,11 @@ var PlotBoilerplate = /** @class */ (function () {
4553
4662
  });
4554
4663
  drawable.lowerRight.attr.selectable = false;
4555
4664
  }
4665
+ else if (drawable instanceof PBText_1.PBText) {
4666
+ this.vertices.push(drawable.anchor);
4667
+ this.drawables.push(drawable);
4668
+ drawable.anchor.attr.selectable = false;
4669
+ }
4556
4670
  else {
4557
4671
  throw "Cannot add drawable of unrecognized type: " + typeof drawable + ".";
4558
4672
  }
@@ -4651,6 +4765,9 @@ var PlotBoilerplate = /** @class */ (function () {
4651
4765
  this.removeVertex(drawable.upperLeft, false);
4652
4766
  this.removeVertex(drawable.lowerRight, false);
4653
4767
  }
4768
+ else if (drawable instanceof PBText_1.PBText) {
4769
+ this.removeVertex(drawable.anchor, false);
4770
+ }
4654
4771
  } // END removeWithVertices
4655
4772
  if (redraw) {
4656
4773
  this.redraw();
@@ -4672,8 +4789,9 @@ var PlotBoilerplate = /** @class */ (function () {
4672
4789
  for (var i = 0; i < this.vertices.length; i++) {
4673
4790
  if (this.vertices[i] === vert) {
4674
4791
  this.vertices.splice(i, 1);
4675
- if (redraw)
4792
+ if (redraw) {
4676
4793
  this.redraw();
4794
+ }
4677
4795
  return;
4678
4796
  }
4679
4797
  }
@@ -4708,8 +4826,9 @@ var PlotBoilerplate = /** @class */ (function () {
4708
4826
  **/
4709
4827
  PlotBoilerplate.prototype.getVertexNear = function (pixelPosition, pixelTolerance) {
4710
4828
  var p = this.locatePointNear(this.transformMousePosition(pixelPosition.x, pixelPosition.y), pixelTolerance / Math.min(this.config.cssScaleX, this.config.cssScaleY));
4711
- if (p && p.typeName == "vertex")
4829
+ if (p && p.typeName == "vertex") {
4712
4830
  return this.vertices[p.vindex];
4831
+ }
4713
4832
  return undefined;
4714
4833
  };
4715
4834
  /**
@@ -4976,6 +5095,16 @@ var PlotBoilerplate = /** @class */ (function () {
4976
5095
  d.lowerRight.attr.renderTime = renderTime;
4977
5096
  }
4978
5097
  }
5098
+ else if (d instanceof PBText_1.PBText) {
5099
+ fill.setCurrentId(d.uid);
5100
+ fill.text(d.text, d.anchor.x, d.anchor.y, d);
5101
+ if (this.drawConfig.text.anchor) {
5102
+ draw.setCurrentId(d.uid + "_a0");
5103
+ draw.setCurrentClassName(d.className + "-anchor");
5104
+ (this.drawConfig.text.fill ? fill : draw).point(d.anchor, this.drawConfig.text.color);
5105
+ }
5106
+ d.anchor.attr.renderTime = renderTime;
5107
+ }
4979
5108
  else {
4980
5109
  console.error("Cannot draw object. Unknown class.");
4981
5110
  }
@@ -5255,7 +5384,6 @@ var PlotBoilerplate = /** @class */ (function () {
5255
5384
  // Apply the zoom (the tolerant area should not shrink or grow when zooming)
5256
5385
  tolerance /= _self.draw.scale.x;
5257
5386
  // Search in vertices
5258
- // for( var vindex in _self.vertices ) {
5259
5387
  for (var vindex = 0; vindex < _self.vertices.length; vindex++) {
5260
5388
  var vert = _self.vertices[vindex];
5261
5389
  if ((vert.attr.draggable || vert.attr.selectable) && vert.distance(point) < tolerance) {
@@ -5275,10 +5403,7 @@ var PlotBoilerplate = /** @class */ (function () {
5275
5403
  * @return {void}
5276
5404
  **/
5277
5405
  PlotBoilerplate.prototype.handleClick = function (e) {
5278
- // x:number,y:number) {
5279
5406
  var _self = this;
5280
- // const x:number = e.params.pos.x;
5281
- //const y:number = e.params.pos.y;
5282
5407
  var p = this.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX, _self.config.cssScaleY));
5283
5408
  if (p) {
5284
5409
  _self.vertices[p.vindex].listeners.fireClickEvent(e);
@@ -5295,7 +5420,7 @@ var PlotBoilerplate = /** @class */ (function () {
5295
5420
  }
5296
5421
  _self.redraw();
5297
5422
  }
5298
- else if (this.keyHandler.isDown("y") /* && p.type=='bpath' && (p.pid==BezierPath.START_POINT || p.pid==BezierPath.END_POINT) */) {
5423
+ else if (this.keyHandler.isDown("y")) {
5299
5424
  _self.vertices[p.vindex].attr.bezierAutoAdjust = !_self.vertices[p.vindex].attr.bezierAutoAdjust;
5300
5425
  _self.redraw();
5301
5426
  }
@@ -5593,6 +5718,7 @@ var PlotBoilerplate = /** @class */ (function () {
5593
5718
  _self.draggedElements = [];
5594
5719
  };
5595
5720
  var afProps = {
5721
+ // touchStart: (evt: TouchEvent) => {
5596
5722
  touchStart: function (evt) {
5597
5723
  if (evt.touches.length == 1) {
5598
5724
  touchMovePos = new Vertex_1.Vertex(relPos_1({ x: evt.touches[0].clientX, y: evt.touches[0].clientY }));
@@ -5695,10 +5821,13 @@ var PlotBoilerplate = /** @class */ (function () {
5695
5821
  _self.redraw();
5696
5822
  }
5697
5823
  }; // END afProps
5698
- if (window["createAlloyFinger"])
5824
+ if (window["createAlloyFinger"]) {
5699
5825
  window["createAlloyFinger"](this.eventCatcher ? this.eventCatcher : this.canvas, afProps);
5700
- else
5826
+ }
5827
+ else {
5828
+ /* tslint:disable-next-line */
5701
5829
  new alloyfinger_typescript_1.default(this.eventCatcher ? this.eventCatcher : this.canvas, afProps);
5830
+ }
5702
5831
  }
5703
5832
  catch (e) {
5704
5833
  console.error("Failed to initialize AlloyFinger!");
@@ -5999,7 +6128,9 @@ __webpack_unused_export__ = PlotBoilerplate;
5999
6128
  * @modified 2021-01-29 Added the `isClockwise` function.
6000
6129
  * @modified 2021-01-29 Added the `area` function.
6001
6130
  * @modified 2021-01-29 Changed the param type for `containsVert` from Vertex to XYCoords.
6002
- * @version 1.7.0
6131
+ * @modified 2021-12-14 Added the `perimeter()` function.
6132
+ * @modified 2021-12-16 Added the `getEvenDistributionPolygon()` function.
6133
+ * @version 1.8.0
6003
6134
  *
6004
6135
  * @file Polygon
6005
6136
  * @public
@@ -6036,12 +6167,11 @@ var Polygon = /** @class */ (function () {
6036
6167
  **/
6037
6168
  this.className = "Polygon";
6038
6169
  this.uid = UIDGenerator_1.UIDGenerator.next();
6039
- if (typeof vertices == 'undefined')
6170
+ if (typeof vertices == "undefined")
6040
6171
  vertices = [];
6041
6172
  this.vertices = vertices;
6042
6173
  this.isOpen = isOpen;
6043
6174
  }
6044
- ;
6045
6175
  /**
6046
6176
  * Add a vertex to the end of the `vertices` array.
6047
6177
  *
@@ -6053,7 +6183,6 @@ var Polygon = /** @class */ (function () {
6053
6183
  Polygon.prototype.addVertex = function (vert) {
6054
6184
  this.vertices.push(vert);
6055
6185
  };
6056
- ;
6057
6186
  /**
6058
6187
  * Get the polygon vertex at the given position (index).
6059
6188
  *
@@ -6076,7 +6205,6 @@ var Polygon = /** @class */ (function () {
6076
6205
  else
6077
6206
  return this.vertices[index % this.vertices.length];
6078
6207
  };
6079
- ;
6080
6208
  /**
6081
6209
  * Move the polygon's vertices by the given amount.
6082
6210
  *
@@ -6092,7 +6220,6 @@ var Polygon = /** @class */ (function () {
6092
6220
  }
6093
6221
  return this;
6094
6222
  };
6095
- ;
6096
6223
  /**
6097
6224
  * Check if the given vertex is inside this polygon.<br>
6098
6225
  * <br>
@@ -6112,14 +6239,12 @@ var Polygon = /** @class */ (function () {
6112
6239
  for (var i = 0, j = this.vertices.length - 1; i < this.vertices.length; j = i++) {
6113
6240
  var xi = this.vertices[i].x, yi = this.vertices[i].y;
6114
6241
  var xj = this.vertices[j].x, yj = this.vertices[j].y;
6115
- var intersect = ((yi > vert.y) != (yj > vert.y))
6116
- && (vert.x < (xj - xi) * (vert.y - yi) / (yj - yi) + xi);
6242
+ var intersect = yi > vert.y != yj > vert.y && vert.x < ((xj - xi) * (vert.y - yi)) / (yj - yi) + xi;
6117
6243
  if (intersect)
6118
6244
  inside = !inside;
6119
6245
  }
6120
6246
  return inside;
6121
6247
  };
6122
- ;
6123
6248
  /**
6124
6249
  * Calculate the area of the given polygon (unsigned).
6125
6250
  *
@@ -6133,7 +6258,6 @@ var Polygon = /** @class */ (function () {
6133
6258
  Polygon.prototype.area = function () {
6134
6259
  return Polygon.utils.area(this.vertices);
6135
6260
  };
6136
- ;
6137
6261
  /**
6138
6262
  * Calulate the signed polyon area by interpreting the polygon as a matrix
6139
6263
  * and calculating its determinant.
@@ -6146,7 +6270,6 @@ var Polygon = /** @class */ (function () {
6146
6270
  Polygon.prototype.signedArea = function () {
6147
6271
  return Polygon.utils.signedArea(this.vertices);
6148
6272
  };
6149
- ;
6150
6273
  /**
6151
6274
  * Get the winding order of this polgon: clockwise or counterclockwise.
6152
6275
  *
@@ -6158,7 +6281,28 @@ var Polygon = /** @class */ (function () {
6158
6281
  Polygon.prototype.isClockwise = function () {
6159
6282
  return Polygon.utils.signedArea(this.vertices) < 0;
6160
6283
  };
6161
- ;
6284
+ /**
6285
+ * Get the perimeter of this polygon.
6286
+ * The perimeter is the absolute length of the outline.
6287
+ *
6288
+ * If this polygon is open then the last segment (connecting the first and the
6289
+ * last vertex) will be skipped.
6290
+ *
6291
+ * @method perimeter
6292
+ * @instance
6293
+ * @memberof Polygon
6294
+ * @return {number}
6295
+ */
6296
+ Polygon.prototype.perimeter = function () {
6297
+ var length = 0;
6298
+ for (var i = 1; i < this.vertices.length; i++) {
6299
+ length += this.vertices[i - 1].distance(this.vertices[i]);
6300
+ }
6301
+ if (!this.isOpen && this.vertices.length > 1) {
6302
+ length += this.vertices[0].distance(this.vertices[this.vertices.length - 1]);
6303
+ }
6304
+ return length;
6305
+ };
6162
6306
  /**
6163
6307
  * Scale the polygon relative to the given center.
6164
6308
  *
@@ -6171,14 +6315,13 @@ var Polygon = /** @class */ (function () {
6171
6315
  **/
6172
6316
  Polygon.prototype.scale = function (factor, center) {
6173
6317
  for (var i in this.vertices) {
6174
- if (typeof this.vertices[i].scale == 'function')
6318
+ if (typeof this.vertices[i].scale == "function")
6175
6319
  this.vertices[i].scale(factor, center);
6176
6320
  else
6177
- console.log('There seems to be a null vertex!', this.vertices[i]);
6321
+ console.log("There seems to be a null vertex!", this.vertices[i]);
6178
6322
  }
6179
6323
  return this;
6180
6324
  };
6181
- ;
6182
6325
  /**
6183
6326
  * Rotate the polygon around the given center.
6184
6327
  *
@@ -6195,7 +6338,52 @@ var Polygon = /** @class */ (function () {
6195
6338
  }
6196
6339
  return this;
6197
6340
  };
6198
- ;
6341
+ /**
6342
+ * Convert this polygon into a new polygon with n evenly distributed vertices.
6343
+ *
6344
+ * @param {number} pointCount - Must not be negative.
6345
+ */
6346
+ Polygon.prototype.getEvenDistributionPolygon = function (pointCount) {
6347
+ if (pointCount <= 0) {
6348
+ throw new Error("pointCount must be larger than zero; is " + pointCount + ".");
6349
+ }
6350
+ var result = new Polygon([], this.isOpen);
6351
+ if (this.vertices.length === 0) {
6352
+ return result;
6353
+ }
6354
+ // Fetch and add the start point from the source polygon
6355
+ var polygonPoint = new Vertex_1.Vertex(this.vertices[0]);
6356
+ result.vertices.push(polygonPoint);
6357
+ if (this.vertices.length === 1) {
6358
+ return result;
6359
+ }
6360
+ var perimeter = this.perimeter();
6361
+ var stepSize = perimeter / pointCount;
6362
+ var n = this.vertices.length;
6363
+ var polygonIndex = 1;
6364
+ var nextPolygonPoint = new Vertex_1.Vertex(this.vertices[1]);
6365
+ var segmentLength = polygonPoint.distance(nextPolygonPoint);
6366
+ var loopMax = this.isOpen ? n : n + 1;
6367
+ var curSegmentU = stepSize;
6368
+ var i = 1;
6369
+ while (i < pointCount && polygonIndex < loopMax) {
6370
+ // Check if next eq point is inside this segment
6371
+ if (curSegmentU < segmentLength) {
6372
+ var newPoint = polygonPoint.clone().lerpAbs(nextPolygonPoint, curSegmentU);
6373
+ result.vertices.push(newPoint);
6374
+ curSegmentU += stepSize;
6375
+ i++;
6376
+ }
6377
+ else {
6378
+ polygonIndex++;
6379
+ polygonPoint = nextPolygonPoint;
6380
+ nextPolygonPoint = new Vertex_1.Vertex(this.vertices[polygonIndex % n]);
6381
+ curSegmentU = curSegmentU - segmentLength;
6382
+ segmentLength = polygonPoint.distance(nextPolygonPoint);
6383
+ }
6384
+ }
6385
+ return result;
6386
+ };
6199
6387
  /**
6200
6388
  * Get the bounding box (bounds) of this polygon.
6201
6389
  *
@@ -6207,7 +6395,6 @@ var Polygon = /** @class */ (function () {
6207
6395
  Polygon.prototype.getBounds = function () {
6208
6396
  return Bounds_1.Bounds.computeFromVertices(this.vertices);
6209
6397
  };
6210
- ;
6211
6398
  /**
6212
6399
  * Convert this polygon to a sequence of quadratic Bézier curves.<br>
6213
6400
  * <br>
@@ -6239,7 +6426,6 @@ var Polygon = /** @class */ (function () {
6239
6426
  }
6240
6427
  return qbezier;
6241
6428
  };
6242
- ;
6243
6429
  /**
6244
6430
  * Convert this polygon to a quadratic bezier curve, represented as an SVG data string.
6245
6431
  *
@@ -6252,13 +6438,12 @@ var Polygon = /** @class */ (function () {
6252
6438
  var qdata = this.toQuadraticBezierData();
6253
6439
  if (qdata.length == 0)
6254
6440
  return "";
6255
- var buffer = ['M ' + qdata[0].x + ' ' + qdata[0].y];
6441
+ var buffer = ["M " + qdata[0].x + " " + qdata[0].y];
6256
6442
  for (var i = 1; i < qdata.length; i += 2) {
6257
- buffer.push('Q ' + qdata[i].x + ' ' + qdata[i].y + ', ' + qdata[i + 1].x + ' ' + qdata[i + 1].y);
6443
+ buffer.push("Q " + qdata[i].x + " " + qdata[i].y + ", " + qdata[i + 1].x + " " + qdata[i + 1].y);
6258
6444
  }
6259
- return buffer.join(' ');
6445
+ return buffer.join(" ");
6260
6446
  };
6261
- ;
6262
6447
  /**
6263
6448
  * Convert this polygon to a sequence of cubic Bézier curves.<br>
6264
6449
  * <br>
@@ -6275,7 +6460,7 @@ var Polygon = /** @class */ (function () {
6275
6460
  * @memberof Polygon
6276
6461
  **/
6277
6462
  Polygon.prototype.toCubicBezierData = function (threshold) {
6278
- if (typeof threshold == 'undefined')
6463
+ if (typeof threshold == "undefined")
6279
6464
  threshold = 1.0;
6280
6465
  if (this.vertices.length < 3)
6281
6466
  return [];
@@ -6299,7 +6484,6 @@ var Polygon = /** @class */ (function () {
6299
6484
  }
6300
6485
  return cbezier;
6301
6486
  };
6302
- ;
6303
6487
  /**
6304
6488
  * Convert this polygon to a cubic bezier curve, represented as an SVG data string.
6305
6489
  *
@@ -6312,13 +6496,23 @@ var Polygon = /** @class */ (function () {
6312
6496
  var qdata = this.toCubicBezierData(threshold);
6313
6497
  if (qdata.length == 0)
6314
6498
  return "";
6315
- var buffer = ['M ' + qdata[0].x + ' ' + qdata[0].y];
6499
+ var buffer = ["M " + qdata[0].x + " " + qdata[0].y];
6316
6500
  for (var i = 1; i < qdata.length; i += 3) {
6317
- buffer.push('C ' + qdata[i].x + ' ' + qdata[i].y + ', ' + qdata[i + 1].x + ' ' + qdata[i + 1].y + ', ' + qdata[i + 2].x + ' ' + qdata[i + 2].y);
6318
- }
6319
- return buffer.join(' ');
6501
+ buffer.push("C " +
6502
+ qdata[i].x +
6503
+ " " +
6504
+ qdata[i].y +
6505
+ ", " +
6506
+ qdata[i + 1].x +
6507
+ " " +
6508
+ qdata[i + 1].y +
6509
+ ", " +
6510
+ qdata[i + 2].x +
6511
+ " " +
6512
+ qdata[i + 2].y);
6513
+ }
6514
+ return buffer.join(" ");
6320
6515
  };
6321
- ;
6322
6516
  /**
6323
6517
  * Convert this polygon to a cubic bezier path instance.
6324
6518
  *
@@ -6337,7 +6531,6 @@ var Polygon = /** @class */ (function () {
6337
6531
  }
6338
6532
  return BezierPath_1.BezierPath.fromArray(pathdata);
6339
6533
  };
6340
- ;
6341
6534
  /**
6342
6535
  * Create an SVG representation of this polygon.
6343
6536
  *
@@ -6351,29 +6544,28 @@ var Polygon = /** @class */ (function () {
6351
6544
  Polygon.prototype.toSVGString = function (options) {
6352
6545
  options = options || {};
6353
6546
  var buffer = [];
6354
- buffer.push('<path');
6547
+ buffer.push("<path");
6355
6548
  if (options.className)
6356
6549
  buffer.push(' class="' + options.className + '"');
6357
6550
  buffer.push(' d="');
6358
6551
  if (this.vertices.length > 0) {
6359
- buffer.push('M ');
6552
+ buffer.push("M ");
6360
6553
  buffer.push(this.vertices[0].x.toString());
6361
- buffer.push(' ');
6554
+ buffer.push(" ");
6362
6555
  buffer.push(this.vertices[0].y.toString());
6363
6556
  for (var i = 1; i < this.vertices.length; i++) {
6364
- buffer.push(' L ');
6557
+ buffer.push(" L ");
6365
6558
  buffer.push(this.vertices[i].x.toString());
6366
- buffer.push(' ');
6559
+ buffer.push(" ");
6367
6560
  buffer.push(this.vertices[i].y.toString());
6368
6561
  }
6369
6562
  if (!this.isOpen) {
6370
- buffer.push(' Z');
6563
+ buffer.push(" Z");
6371
6564
  }
6372
6565
  }
6373
6566
  buffer.push('" />');
6374
- return buffer.join('');
6567
+ return buffer.join("");
6375
6568
  };
6376
- ;
6377
6569
  Polygon.utils = {
6378
6570
  /**
6379
6571
  * Calculate the area of the given polygon (unsigned).
@@ -6392,8 +6584,8 @@ var Polygon = /** @class */ (function () {
6392
6584
  var addY = vertices[(i + 1) % l].y;
6393
6585
  var subX = vertices[(i + 1) % l].x;
6394
6586
  var subY = vertices[i].y;
6395
- total += (addX * addY * 0.5);
6396
- total -= (subX * subY * 0.5);
6587
+ total += addX * addY * 0.5;
6588
+ total -= subX * subY * 0.5;
6397
6589
  }
6398
6590
  return Math.abs(total);
6399
6591
  },
@@ -8159,7 +8351,10 @@ exports.VertTuple = VertTuple;
8159
8351
  * @modified 2020-05-26 Added functions addX(number) and addY(number).
8160
8352
  * @modified 2020-10-30 Changed the warnings in `sub(...)` and `add(...)` into real errors.
8161
8353
  * @modified 2021-03-01 Changed the second param `center` in the `rotate` function from Vertex to XYCoords.
8162
- * @version 2.4.2
8354
+ * @modified 2021-12-01 Changed the type of param of `scale` to XYCoords.
8355
+ * @modified 2021-12-01 Added function `scaleXY` for non uniform scaling.
8356
+ * @modified 2021-12-17 Added the functions `lerp` and `lerpAbs` for linear interpolations.
8357
+ * @version 2.6.0
8163
8358
  *
8164
8359
  * @file Vertex
8165
8360
  * @public
@@ -8505,20 +8700,72 @@ var Vertex = /** @class */ (function () {
8505
8700
  };
8506
8701
  /**
8507
8702
  * This is a vector-like behavior and 'scales' this vertex
8508
- * towards/from a given center.
8703
+ * towards/from a given center by one uniform scale factor.
8509
8704
  *
8510
8705
  * @method scale
8511
8706
  * @param {number} factor - The factor to 'scale' this vertex; 1.0 means no change.
8512
- * @param {Vertex=} center - The origin of scaling; default is (0,0).
8707
+ * @param {XYCoords=} center - The origin of scaling; default is (0,0).
8513
8708
  * @return {Vertex} this
8514
8709
  * @instance
8515
8710
  * @memberof Vertex
8516
8711
  **/
8517
8712
  Vertex.prototype.scale = function (factor, center) {
8518
- if (!center || typeof center === "undefined")
8519
- center = new Vertex(0, 0);
8520
- this.x = center.x + (this.x - center.x) * factor;
8521
- this.y = center.y + (this.y - center.y) * factor;
8713
+ return this.scaleXY({ x: factor, y: factor }, center);
8714
+ };
8715
+ /**
8716
+ * Perform a linear interpolation towards the given target vertex.
8717
+ * The amount value `t` is relative, `t=0.0` means no change, `t=1.0`
8718
+ * means this point will be moved to the exact target position.
8719
+ *
8720
+ * `t=0.5` will move this point to the middle of the connecting
8721
+ * linear segment.
8722
+ *
8723
+ * @param {XYCoords} target - The target position to lerp this vertex to.
8724
+ * @param {number} t - The relative amount, usually in [0..1], but other values will work, too.
8725
+ * @returns
8726
+ */
8727
+ Vertex.prototype.lerp = function (target, t) {
8728
+ var diff = this.difference(target);
8729
+ // return new Vertex(this.x + diff.x * t, this.y + diff.y * t);
8730
+ this.x += diff.x * t;
8731
+ this.y += diff.y * t;
8732
+ return this;
8733
+ };
8734
+ /**
8735
+ * Perform a linear interpolation towards the given target vertex (absolute variant).
8736
+ * The amount value `t` is absolute, which means the lerp amount is a direct distance
8737
+ * value. This point will have move the amount of the passed distance `u`.
8738
+ *
8739
+ * @param {XYCoords} target - The target position to lerp this vertex to.
8740
+ * @param {number} t - The absolute move amount to use to lerping.
8741
+ * @returns
8742
+ */
8743
+ Vertex.prototype.lerpAbs = function (target, u) {
8744
+ var dist = this.distance(target);
8745
+ var diff = this.difference(target);
8746
+ var step = { x: diff.x / dist, y: diff.y / dist };
8747
+ // return new Vertex(this.x + step.x * u, this.y + step.y * u);
8748
+ this.x += step.x * u;
8749
+ this.y += step.y * u;
8750
+ return this;
8751
+ };
8752
+ /**
8753
+ * This is a vector-like behavior and 'scales' this vertex
8754
+ * towards/from a given center by two independent x- and y- scale factors.
8755
+ *
8756
+ * @method scale
8757
+ * @param {number} factor - The factor to 'scale' this vertex; 1.0 means no change.
8758
+ * @param {XYCoords=} center - The origin of scaling; default is (0,0).
8759
+ * @return {Vertex} this
8760
+ * @instance
8761
+ * @memberof Vertex
8762
+ **/
8763
+ Vertex.prototype.scaleXY = function (factors, center) {
8764
+ if (!center || typeof center === "undefined") {
8765
+ center = { x: 0, y: 0 };
8766
+ }
8767
+ this.x = center.x + (this.x - center.x) * factors.x;
8768
+ this.y = center.y + (this.y - center.y) * factors.y;
8522
8769
  return this;
8523
8770
  };
8524
8771
  /**
@@ -9070,7 +9317,9 @@ exports.VertexListeners = VertexListeners;
9070
9317
  * @modified 2021-02-22 Added the `path` drawing function to draw SVG path data.
9071
9318
  * @modified 2021-03-31 Added the `endDrawCycle` function from `DrawLib`.
9072
9319
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
9073
- * @version 1.9.0
9320
+ * @modified 2021-11-12 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
9321
+ * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
9322
+ * @version 1.10.0
9074
9323
  **/
9075
9324
  Object.defineProperty(exports, "__esModule", ({ value: true }));
9076
9325
  exports.drawutils = void 0;
@@ -9730,20 +9979,62 @@ var drawutils = /** @class */ (function () {
9730
9979
  this.ctx.setLineDash([]);
9731
9980
  this.ctx.restore();
9732
9981
  };
9982
+ /**
9983
+ * Draw a text at the given relative position.
9984
+ *
9985
+ * @method text
9986
+ * @param {string} text - The text to draw.
9987
+ * @param {number} x - The x-position to draw the text at.
9988
+ * @param {number} y - The y-position to draw the text at.
9989
+ * @param {string=} options.color - The Color to use.
9990
+ * @param {string=} options.fontFamily - The font family to use.
9991
+ * @param {number=} options.fontSize - The font size (in pixels) to use.
9992
+ * @param {FontStyle=} options.fontStyle - The font style to use.
9993
+ * @param {FontWeight=} options.fontWeight - The font weight to use.
9994
+ * @param {number=} options.lineHeight - The line height (in pixels) to use.
9995
+ * @param {number=} options.rotation - The (optional) rotation in radians.
9996
+ * @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"`.
9997
+ * @return {void}
9998
+ * @instance
9999
+ * @memberof drawutils
10000
+ */
9733
10001
  drawutils.prototype.text = function (text, x, y, options) {
10002
+ // See https://stackoverflow.com/a/23523697
10003
+ var _a, _b, _c;
9734
10004
  options = options || {};
9735
10005
  this.ctx.save();
9736
- x = this.offset.x + x * this.scale.x;
9737
- y = this.offset.y + y * this.scale.y;
10006
+ var relX = this.offset.x + x * this.scale.x;
10007
+ var relY = this.offset.y + y * this.scale.y;
9738
10008
  var color = options.color || "black";
10009
+ if (options.fontSize || options.fontFamily) {
10010
+ // Scaling of text only works in uniform mode
10011
+ this.ctx.font =
10012
+ (options.fontWeight ? options.fontWeight + " " : "") +
10013
+ (options.fontStyle ? options.fontStyle + " " : "") +
10014
+ (options.fontSize ? options.fontSize * this.scale.x + "px " : " ") +
10015
+ (options.fontFamily
10016
+ ? options.fontFamily.indexOf(" ") === -1
10017
+ ? options.fontFamily
10018
+ : "\"" + options.fontFamily + "\""
10019
+ : "Arial");
10020
+ }
10021
+ if (options.textAlign) {
10022
+ this.ctx.textAlign = options.textAlign;
10023
+ }
10024
+ var rotation = (_a = options.rotation) !== null && _a !== void 0 ? _a : 0.0;
10025
+ var lineHeight = ((_c = (_b = options.lineHeight) !== null && _b !== void 0 ? _b : options.fontSize) !== null && _c !== void 0 ? _c : 0) * this.scale.x;
10026
+ this.ctx.translate(relX, relY);
10027
+ this.ctx.rotate(rotation);
9739
10028
  if (this.fillShapes) {
9740
10029
  this.ctx.fillStyle = color;
9741
- this.ctx.fillText(text, x, y);
10030
+ this.ctx.fillText(text, 0, lineHeight / 2);
9742
10031
  }
9743
10032
  else {
9744
10033
  this.ctx.strokeStyle = color;
9745
- this.ctx.strokeText(text, x, y);
10034
+ this.ctx.strokeText(text, 0, lineHeight / 2);
9746
10035
  }
10036
+ // this.ctx.translate(-relX, -relY);
10037
+ // this.ctx.rotate(-rotation); // is this necessary before 'restore()'?
9747
10038
  this.ctx.restore();
9748
10039
  };
9749
10040
  /**
@@ -9763,8 +10054,9 @@ var drawutils = /** @class */ (function () {
9763
10054
  */
9764
10055
  drawutils.prototype.label = function (text, x, y, rotation, color) {
9765
10056
  this.ctx.save();
10057
+ this.ctx.font = "lighter 9pt Arial";
9766
10058
  this.ctx.translate(x, y);
9767
- if (typeof rotation != "undefined")
10059
+ if (typeof rotation !== "undefined")
9768
10060
  this.ctx.rotate(rotation);
9769
10061
  this.ctx.fillStyle = color || "black";
9770
10062
  if (this.fillShapes) {
@@ -10385,6 +10677,25 @@ var drawutilsgl = /** @class */ (function () {
10385
10677
  drawutilsgl.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
10386
10678
  // NOT YET IMPLEMENTED
10387
10679
  };
10680
+ /**
10681
+ * Draw a text at the given relative position.
10682
+ *
10683
+ * @method text
10684
+ * @param {string} text - The text to draw.
10685
+ * @param {number} x - The x-position to draw the text at.
10686
+ * @param {number} y - The y-position to draw the text at.
10687
+ * @param {string=} options.color - The Color to use.
10688
+ * @param {string=} options.fontFamily - The font family to use.
10689
+ * @param {number=} options.fontSize - The font size (in pixels) to use.
10690
+ * @param {FontStyle=} options.fontStyle - The font style to use.
10691
+ * @param {FontWeight=} options.fontWeight - The font weight to use.
10692
+ * @param {number=} options.lineHeight - The line height (in pixels) to use.
10693
+ * @param {number=} options.rotation - The (optional) rotation in radians.
10694
+ * @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"`.
10695
+ * @return {void}
10696
+ * @instance
10697
+ * @memberof drawutils
10698
+ */
10388
10699
  drawutilsgl.prototype.text = function (text, x, y, options) {
10389
10700
  // NOT YET IMPLEMENTED
10390
10701
  };
@@ -10396,14 +10707,12 @@ var drawutilsgl = /** @class */ (function () {
10396
10707
  * @param {number} x - The x-position to draw the text at.
10397
10708
  * @param {number} y - The y-position to draw the text at.
10398
10709
  * @param {number=} rotation - The (aoptional) rotation in radians.
10710
+ * @param {string="black"} color - The color to use (default is black).
10399
10711
  * @return {void}
10400
10712
  * @instance
10401
10713
  * @memberof drawutils
10402
10714
  */
10403
- // +---------------------------------------------------------------------------------
10404
- // | Draw a non-scaling text label at the given position.
10405
- // +-------------------------------
10406
- drawutilsgl.prototype.label = function (text, x, y, rotation) {
10715
+ drawutilsgl.prototype.label = function (text, x, y, rotation, color) {
10407
10716
  // NOT YET IMPLEMENTED
10408
10717
  };
10409
10718
  /**
@@ -10538,13 +10847,17 @@ var GLU = /** @class */ (function () {
10538
10847
  * @modified 2021-03-31 Added 'ellipseSector' the the class names.
10539
10848
  * @modified 2021-03-31 Implemented buffering using a buffer <g> node and the beginDrawCycle and endDrawCycle methods.
10540
10849
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
10541
- * @version 1.3.0
10850
+ * @modified 2021-11-15 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
10851
+ * @modified 2021-11-19 Fixing the `label(text,x,y)` position.
10852
+ * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
10853
+ * @version 1.4.0
10542
10854
  **/
10543
10855
  Object.defineProperty(exports, "__esModule", ({ value: true }));
10544
10856
  exports.drawutilssvg = void 0;
10545
10857
  var CircleSector_1 = __webpack_require__(946);
10546
10858
  var CubicBezierCurve_1 = __webpack_require__(510);
10547
10859
  var Vertex_1 = __webpack_require__(421);
10860
+ var RAD_TO_DEG = 180 / Math.PI;
10548
10861
  /**
10549
10862
  * @classdesc A helper class for basic SVG drawing operations. This class should
10550
10863
  * be compatible to the default 'draw' class.
@@ -10604,7 +10917,8 @@ var drawutilssvg = /** @class */ (function () {
10604
10917
  "vertex": "Vertex",
10605
10918
  "line": "Line",
10606
10919
  "vector": "Vector",
10607
- "image": "Image"
10920
+ "image": "Image",
10921
+ "text": "Text"
10608
10922
  };
10609
10923
  // Question: why isn't this working if the svgNode is created dynamically? (nodeStyle.sheet is null)
10610
10924
  var rules = [];
@@ -11385,27 +11699,65 @@ var drawutilssvg = /** @class */ (function () {
11385
11699
  if (!isOpen)
11386
11700
  d.push("Z");
11387
11701
  node.setAttribute("d", d.join(" "));
11388
- return this._bindFillDraw(node, "polyline", color, lineWidth || 1);
11702
+ return this._bindFillDraw(node, "polygon", color, lineWidth || 1);
11389
11703
  };
11390
11704
  /**
11391
- * Draw a text label at the given relative position.
11705
+ * Draw a text at the given relative position.
11392
11706
  *
11393
- * @method label
11707
+ * @method text
11394
11708
  * @param {string} text - The text to draw.
11395
11709
  * @param {number} x - The x-position to draw the text at.
11396
11710
  * @param {number} y - The y-position to draw the text at.
11397
- * @param {number=} rotation - The (optional) rotation in radians.
11711
+ * @param {string=} options.color - The Color to use.
11712
+ * @param {string=} options.fontFamily - The font family to use.
11713
+ * @param {number=} options.fontSize - The font size (in pixels) to use.
11714
+ * @param {FontStyle=} options.fontStyle - The font style to use.
11715
+ * @param {FontWeight=} options.fontWeight - The font weight to use.
11716
+ * @param {number=} options.lineHeight - The line height (in pixels) to use.
11717
+ * @param {number=} options.rotation - The (optional) rotation in radians.
11718
+ * @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"`.
11398
11719
  * @return {void}
11399
11720
  * @instance
11400
- * @memberof drawutilssvg
11721
+ * @memberof drawutils
11401
11722
  */
11402
11723
  drawutilssvg.prototype.text = function (text, x, y, options) {
11724
+ var _a, _b;
11403
11725
  options = options || {};
11404
11726
  var color = options.color || "black";
11405
- var node = this.makeNode("text");
11406
- node.setAttribute("x", "" + this._x(x));
11407
- node.setAttribute("y", "" + this._y(y));
11408
- node.innerHTML = text;
11727
+ var lineHeight = ((_b = (_a = options.lineHeight) !== null && _a !== void 0 ? _a : options.fontSize) !== null && _b !== void 0 ? _b : 0) * this.scale.x;
11728
+ // https://www.w3.org/TR/SVG/text.html#TextAnchorProperty
11729
+ // start | middle | end
11730
+ var textAlign = options.textAlign === "left" || options.textAlign === "start"
11731
+ ? "start"
11732
+ : options.textAlign === "center"
11733
+ ? "middle"
11734
+ : options.textAlign === "right" || options.textAlign === "end"
11735
+ ? "end"
11736
+ : "start";
11737
+ var transformOrigin = this._x(x) + "px " + this._y(y) + "px";
11738
+ var translate = "translate(" + this._x(x) + " " + (this._y(y) + lineHeight / 2) + ")";
11739
+ // Safari has a transform-origin/rotation bug.
11740
+ // It's essential to use rotate(r,x,y) here. "rotate(r)"" with transform-origin(x,y) won't do the job.
11741
+ // And rotate and translate cannot be used is combination on a text object.
11742
+ // So wrap the text inside a <g>, translate the <g>, and rotate the text inside.
11743
+ var rotate = options.rotation ? "rotate(" + options.rotation * RAD_TO_DEG + " 0 0)" : "";
11744
+ var node = this.makeNode("g");
11745
+ var curId = this.curId;
11746
+ this.curId = curId + "_text";
11747
+ var textNode = this.makeNode("text");
11748
+ node.appendChild(textNode);
11749
+ textNode.setAttribute("font-family", options.fontFamily); // May be undefined
11750
+ textNode.setAttribute("font-size", options.fontSize ? "" + options.fontSize * this.scale.x : null);
11751
+ textNode.setAttribute("font-style", options.fontStyle ? "" + options.fontStyle : null);
11752
+ textNode.setAttribute("font-weight", options.fontWeight ? "" + options.fontWeight : null);
11753
+ textNode.setAttribute("text-anchor", textAlign);
11754
+ textNode.setAttribute("transform-origin", "0 0");
11755
+ textNode.setAttribute("transform", rotate);
11756
+ node.setAttribute("transform-origin", transformOrigin);
11757
+ node.setAttribute("transform", translate);
11758
+ textNode.innerHTML = text;
11759
+ // Restore old ID
11760
+ this.curId = curId;
11409
11761
  return this._bindFillDraw(node, "text", color, 1);
11410
11762
  };
11411
11763
  /**
@@ -11416,16 +11768,21 @@ var drawutilssvg = /** @class */ (function () {
11416
11768
  * @param {number} x - The x-position to draw the text at.
11417
11769
  * @param {number} y - The y-position to draw the text at.
11418
11770
  * @param {number=} rotation - The (optional) rotation in radians.
11771
+ * @param {string="black"} color - The color to use (default is black).
11419
11772
  * @return {void}
11420
11773
  * @instance
11421
11774
  * @memberof drawutilssvg
11422
11775
  */
11423
- drawutilssvg.prototype.label = function (text, x, y, rotation) {
11776
+ drawutilssvg.prototype.label = function (text, x, y, rotation, color) {
11424
11777
  var node = this.makeNode("text");
11425
11778
  // For some strange reason SVG rotation transforms use degrees instead of radians
11426
- node.setAttribute("transform", "translate(" + this.offset.x + "," + this.offset.y + "), rotate(" + (rotation / Math.PI) * 180 + ")");
11779
+ node.setAttribute("transform", "translate(" + x + "," + y + "), rotate(" + ((rotation || 0) / Math.PI) * 180 + ")");
11780
+ node.setAttribute("font-family", "Arial");
11781
+ node.setAttribute("font-size", "9pt");
11782
+ node.setAttribute("font-style", "normal");
11783
+ node.setAttribute("font-weight", "lighter");
11427
11784
  node.innerHTML = text;
11428
- return this._bindFillDraw(node, "label", "black", null);
11785
+ return this._bindFillDraw(node, "label", color || "black", null);
11429
11786
  };
11430
11787
  /**
11431
11788
  * Draw an SVG-like path given by the specified path data.
@@ -11876,6 +12233,7 @@ globalThis.VEllipse = __webpack_require__(112).VEllipse;
11876
12233
  globalThis.Circle = __webpack_require__(913).Circle;
11877
12234
  globalThis.CircleSector = __webpack_require__(946).CircleSector;
11878
12235
  globalThis.PBImage = __webpack_require__(699).PBImage;
12236
+ globalThis.PBText = __webpack_require__(196).PBText;
11879
12237
  globalThis.MouseHandler = __webpack_require__(293).MouseHandler;
11880
12238
  globalThis.KeyHandler = __webpack_require__(909).KeyHandler;
11881
12239
  globalThis.drawutils = __webpack_require__(149).drawutils;