plotboilerplate 1.12.7 → 1.13.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 (83) hide show
  1. package/README.md +4 -1
  2. package/changelog.md +25 -0
  3. package/dist/index.esm.js +259 -44
  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 +273 -43
  10. package/dist/plotboilerplate.min.js +1 -1
  11. package/package.json +1 -1
  12. package/src/cjs/PBText.d.ts +116 -0
  13. package/src/cjs/PBText.js +66 -0
  14. package/src/cjs/PBText.js.map +1 -0
  15. package/src/cjs/PlotBoilerplate.d.ts +2 -1
  16. package/src/cjs/PlotBoilerplate.js +66 -19
  17. package/src/cjs/PlotBoilerplate.js.map +1 -1
  18. package/src/cjs/draw.d.ts +30 -2
  19. package/src/cjs/draw.js +51 -6
  20. package/src/cjs/draw.js.map +1 -1
  21. package/src/cjs/drawgl.d.ts +29 -2
  22. package/src/cjs/drawgl.js +21 -4
  23. package/src/cjs/drawgl.js.map +1 -1
  24. package/src/cjs/drawutilssvg.d.ts +25 -7
  25. package/src/cjs/drawutilssvg.js +62 -14
  26. package/src/cjs/drawutilssvg.js.map +1 -1
  27. package/src/cjs/entry.js +1 -0
  28. package/src/cjs/index.d.ts +1 -0
  29. package/src/cjs/index.js +1 -0
  30. package/src/cjs/index.js.map +1 -1
  31. package/src/cjs/interfaces/DrawLib.d.ts +27 -6
  32. package/src/cjs/interfaces/DrawLib.js +3 -0
  33. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  34. package/src/cjs/interfaces/core.d.ts +12 -1
  35. package/src/cjs/interfaces/core.js +1 -0
  36. package/src/cjs/interfaces/core.js.map +1 -1
  37. package/src/cjs/utils/datastructures/Color.d.ts +28 -15
  38. package/src/cjs/utils/datastructures/Color.js +276 -88
  39. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  40. package/src/esm/PBText.d.ts +116 -0
  41. package/src/esm/PBText.js +61 -0
  42. package/src/esm/PBText.js.map +1 -0
  43. package/src/esm/PlotBoilerplate.d.ts +2 -1
  44. package/src/esm/PlotBoilerplate.js +66 -19
  45. package/src/esm/PlotBoilerplate.js.map +1 -1
  46. package/src/esm/draw.d.ts +30 -2
  47. package/src/esm/draw.js +51 -6
  48. package/src/esm/draw.js.map +1 -1
  49. package/src/esm/drawgl.d.ts +29 -2
  50. package/src/esm/drawgl.js +21 -4
  51. package/src/esm/drawgl.js.map +1 -1
  52. package/src/esm/drawutilssvg.d.ts +25 -7
  53. package/src/esm/drawutilssvg.js +62 -14
  54. package/src/esm/drawutilssvg.js.map +1 -1
  55. package/src/esm/entry.js +1 -0
  56. package/src/esm/index.d.ts +1 -0
  57. package/src/esm/index.js +1 -0
  58. package/src/esm/index.js.map +1 -1
  59. package/src/esm/interfaces/DrawLib.d.ts +27 -6
  60. package/src/esm/interfaces/DrawLib.js +3 -0
  61. package/src/esm/interfaces/DrawLib.js.map +1 -1
  62. package/src/esm/interfaces/core.d.ts +12 -1
  63. package/src/esm/interfaces/core.js +1 -0
  64. package/src/esm/interfaces/core.js.map +1 -1
  65. package/src/esm/utils/datastructures/Color.d.ts +28 -15
  66. package/src/esm/utils/datastructures/Color.js +277 -89
  67. package/src/esm/utils/datastructures/Color.js.map +1 -1
  68. package/src/ts/PBText.ts +147 -0
  69. package/src/ts/PlotBoilerplate.ts +74 -23
  70. package/src/ts/draw.ts +71 -8
  71. package/src/ts/drawgl.ts +48 -8
  72. package/src/ts/drawutilssvg.ts +94 -17
  73. package/src/ts/index.ts +1 -0
  74. package/src/ts/interfaces/DrawLib.ts +30 -4
  75. package/src/ts/interfaces/core.ts +12 -0
  76. package/src/ts/utils/datastructures/Color.ts +695 -508
  77. package/src/ts/utils/algorithms/clearPolygonDuplicateVertices.ts~ +0 -5
  78. package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts~ +0 -45
  79. package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts~ +0 -113
  80. package/src/ts/utils/algorithms/sutherlandHodgman.ts~ +0 -88
  81. package/src/ts/utils/datastructures/Color.ts~ +0 -331
  82. package/src/ts/utils/datastructures/Girih.ts~ +0 -151
  83. package/src/ts/utils/datastructures/GirihTile.ts~ +0 -419
@@ -3900,6 +3900,78 @@ exports.PBImage = PBImage;
3900
3900
 
3901
3901
  /***/ }),
3902
3902
 
3903
+ /***/ 196:
3904
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
3905
+
3906
+
3907
+ /**
3908
+ * @author Ikaros Kappler
3909
+ * @date 2021-11-16
3910
+ * @version 1.0.0
3911
+ **/
3912
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3913
+ exports.PBText = void 0;
3914
+ var UIDGenerator_1 = __webpack_require__(197);
3915
+ var Vertex_1 = __webpack_require__(421);
3916
+ /**
3917
+ * @classdesc A simple text element: position, fontSize, fontFamily, color, textAlign, lineHeight and rotation.
3918
+ *
3919
+ * @requires FontOptions
3920
+ * @requires FontSize
3921
+ * @requires FontStyle
3922
+ * @requires FontWeight
3923
+ * @requires Vertex
3924
+ * @requires SVGSerializale
3925
+ * @requires UID
3926
+ * @requires UIDGenerator
3927
+ **/
3928
+ var PBText = /** @class */ (function () {
3929
+ /**
3930
+ * Create a new circle with given center point and radius.
3931
+ *
3932
+ * @constructor
3933
+ * @name Circle
3934
+ * @param {Vertex} center - The center point of the circle.
3935
+ * @param {number} radius - The radius of the circle.
3936
+ */
3937
+ function PBText(text, anchor, options) {
3938
+ /**
3939
+ * Required to generate proper CSS classes and other class related IDs.
3940
+ **/
3941
+ this.className = "PBText";
3942
+ this.uid = UIDGenerator_1.UIDGenerator.next();
3943
+ this.text = text;
3944
+ this.anchor = anchor !== null && anchor !== void 0 ? anchor : new Vertex_1.Vertex();
3945
+ this.color = options.color;
3946
+ this.fontFamily = options.fontFamily;
3947
+ this.fontSize = options.fontSize;
3948
+ this.fontStyle = options.fontStyle;
3949
+ this.fontWeight = options.fontWeight;
3950
+ this.lineHeight = options.lineHeight;
3951
+ this.textAlign = options.textAlign;
3952
+ this.rotation = options.rotation;
3953
+ }
3954
+ /**
3955
+ * Create an SVG representation of this circle.
3956
+ *
3957
+ * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
3958
+ * @method toSVGString
3959
+ * @param {object=} options - An optional set of options, like 'className'.
3960
+ * @return {string} A string representing the SVG code for this vertex.
3961
+ * @instance
3962
+ * @memberof Circle
3963
+ */
3964
+ PBText.prototype.toSVGString = function (options) {
3965
+ console.warn("[PBText.toSVGString()] This function is not implemented as it defines a deprecated method. Use the 'drawutilssvg.text()' method instead.");
3966
+ return "";
3967
+ };
3968
+ return PBText;
3969
+ }()); // END class
3970
+ exports.PBText = PBText;
3971
+ //# sourceMappingURL=PBText.js.map
3972
+
3973
+ /***/ }),
3974
+
3903
3975
  /***/ 919:
3904
3976
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
3905
3977
 
@@ -3980,7 +4052,8 @@ var __webpack_unused_export__;
3980
4052
  * @modified 2021-03-03 Added the `VEllipseSector` drawable.
3981
4053
  * @modified 2021-03-29 Clearing `currentClassName` and `currentId` after drawing each drawable.
3982
4054
  * @modified 2021-04-25 Extending `remove` to accept arrays of drawables.
3983
- * @version 1.14.0
4055
+ * @modified 2021-11-16 Adding the `PBText` drawable.
4056
+ * @version 1.15.0
3984
4057
  *
3985
4058
  * @file PlotBoilerplate
3986
4059
  * @fileoverview The main class.
@@ -4008,6 +4081,7 @@ var VEllipseSector_1 = __webpack_require__(965);
4008
4081
  var Vector_1 = __webpack_require__(73);
4009
4082
  var Vertex_1 = __webpack_require__(421);
4010
4083
  var VertexAttr_1 = __webpack_require__(861);
4084
+ var PBText_1 = __webpack_require__(196);
4011
4085
  /**
4012
4086
  * @classdesc The main class of the PlotBoilerplate.
4013
4087
  *
@@ -4191,6 +4265,16 @@ var PlotBoilerplate = /** @class */ (function () {
4191
4265
  handleLine: {
4192
4266
  color: "rgba(180,180,180,0.5)",
4193
4267
  lineWidth: 1
4268
+ },
4269
+ pathVertex: {
4270
+ color: "#B400FF",
4271
+ lineWidth: 1,
4272
+ fill: true
4273
+ },
4274
+ controlVertex: {
4275
+ color: "#B8D438",
4276
+ lineWidth: 1,
4277
+ fill: true
4194
4278
  }
4195
4279
  },
4196
4280
  polygon: {
@@ -4236,6 +4320,12 @@ var PlotBoilerplate = /** @class */ (function () {
4236
4320
  image: {
4237
4321
  color: "#a8a8a8",
4238
4322
  lineWidth: 1
4323
+ },
4324
+ text: {
4325
+ color: "rgba(192,0,128,0.5)",
4326
+ lineWidth: 1,
4327
+ fill: true,
4328
+ anchor: true
4239
4329
  }
4240
4330
  }; // END drawConfig
4241
4331
  // +---------------------------------------------------------------------------------
@@ -4543,6 +4633,11 @@ var PlotBoilerplate = /** @class */ (function () {
4543
4633
  });
4544
4634
  drawable.lowerRight.attr.selectable = false;
4545
4635
  }
4636
+ else if (drawable instanceof PBText_1.PBText) {
4637
+ this.vertices.push(drawable.anchor);
4638
+ this.drawables.push(drawable);
4639
+ drawable.anchor.attr.selectable = false;
4640
+ }
4546
4641
  else {
4547
4642
  throw "Cannot add drawable of unrecognized type: " + typeof drawable + ".";
4548
4643
  }
@@ -4641,6 +4736,9 @@ var PlotBoilerplate = /** @class */ (function () {
4641
4736
  this.removeVertex(drawable.upperLeft, false);
4642
4737
  this.removeVertex(drawable.lowerRight, false);
4643
4738
  }
4739
+ else if (drawable instanceof PBText_1.PBText) {
4740
+ this.removeVertex(drawable.anchor, false);
4741
+ }
4644
4742
  } // END removeWithVertices
4645
4743
  if (redraw) {
4646
4744
  this.redraw();
@@ -4814,32 +4912,43 @@ var PlotBoilerplate = /** @class */ (function () {
4814
4912
  for (var c in d.bezierCurves) {
4815
4913
  draw.cubicBezier(d.bezierCurves[c].startPoint, d.bezierCurves[c].endPoint, d.bezierCurves[c].startControlPoint, d.bezierCurves[c].endControlPoint, this.drawConfig.bezier.color, this.drawConfig.bezier.lineWidth);
4816
4914
  if (this.drawConfig.drawBezierHandlePoints && this.drawConfig.drawHandlePoints) {
4817
- if (!d.bezierCurves[c].startPoint.attr.bezierAutoAdjust) {
4818
- if (d.bezierCurves[c].startPoint.attr.visible) {
4819
- draw.setCurrentId(d.uid + "_h0");
4820
- draw.setCurrentClassName(d.className + "-start-handle");
4821
- draw.diamondHandle(d.bezierCurves[c].startPoint, 7, this._handleColor(d.bezierCurves[c].startPoint, this.drawConfig.vertex.color));
4915
+ if (d.bezierCurves[c].startPoint.attr.visible) {
4916
+ var df = this.drawConfig.bezier.pathVertex.fill ? fill : draw;
4917
+ df.setCurrentId(d.uid + "_h0");
4918
+ df.setCurrentClassName(d.className + "-start-handle");
4919
+ if (d.bezierCurves[c].startPoint.attr.bezierAutoAdjust) {
4920
+ df.squareHandle(d.bezierCurves[c].startPoint, 5, this._handleColor(d.bezierCurves[c].startPoint, this.drawConfig.bezier.pathVertex.color));
4921
+ }
4922
+ else {
4923
+ df.diamondHandle(d.bezierCurves[c].startPoint, 7, this._handleColor(d.bezierCurves[c].startPoint, this.drawConfig.bezier.pathVertex.color));
4822
4924
  }
4823
- d.bezierCurves[c].startPoint.attr.renderTime = renderTime;
4824
4925
  }
4825
- if (!d.bezierCurves[c].endPoint.attr.bezierAutoAdjust) {
4826
- if (d.bezierCurves[c].endPoint.attr.visible) {
4827
- draw.setCurrentId(d.uid + "_h1");
4828
- draw.setCurrentClassName(d.className + "-end-handle");
4829
- draw.diamondHandle(d.bezierCurves[c].endPoint, 7, this._handleColor(d.bezierCurves[c].endPoint, this.drawConfig.vertex.color));
4926
+ d.bezierCurves[c].startPoint.attr.renderTime = renderTime;
4927
+ if (d.bezierCurves[c].endPoint.attr.visible) {
4928
+ var df = this.drawConfig.bezier.pathVertex.fill ? fill : draw;
4929
+ df.setCurrentId(d.uid + "_h0");
4930
+ df.setCurrentClassName(d.className + "-start-handle");
4931
+ if (d.bezierCurves[c].endPoint.attr.bezierAutoAdjust) {
4932
+ df.squareHandle(d.bezierCurves[c].endPoint, 5, this._handleColor(d.bezierCurves[c].endPoint, this.drawConfig.bezier.pathVertex.color));
4933
+ }
4934
+ else {
4935
+ df.diamondHandle(d.bezierCurves[c].endPoint, 7, this._handleColor(d.bezierCurves[c].endPoint, this.drawConfig.bezier.pathVertex.color));
4830
4936
  }
4831
- d.bezierCurves[c].endPoint.attr.renderTime = renderTime;
4832
4937
  }
4833
4938
  if (d.bezierCurves[c].startControlPoint.attr.visible) {
4834
- draw.setCurrentId(d.uid + "_h2");
4835
- draw.setCurrentClassName(d.className + "-start-control-handle");
4836
- draw.circleHandle(d.bezierCurves[c].startControlPoint, 3, this._handleColor(d.bezierCurves[c].startControlPoint, "#008888"));
4939
+ var df = this.drawConfig.bezier.controlVertex.fill ? fill : draw;
4940
+ df.setCurrentId(d.uid + "_h2");
4941
+ df.setCurrentClassName(d.className + "-start-control-handle");
4942
+ df.circleHandle(d.bezierCurves[c].startControlPoint, 3, this._handleColor(d.bezierCurves[c].startControlPoint, this.drawConfig.bezier.controlVertex.color));
4837
4943
  }
4838
4944
  if (d.bezierCurves[c].endControlPoint.attr.visible) {
4839
- draw.setCurrentId(d.uid + "_h3");
4840
- draw.setCurrentClassName(d.className + "-end-control-handle");
4841
- draw.circleHandle(d.bezierCurves[c].endControlPoint, 3, this._handleColor(d.bezierCurves[c].endControlPoint, "#008888"));
4945
+ var df = this.drawConfig.bezier.controlVertex.fill ? fill : draw;
4946
+ df.setCurrentId(d.uid + "_h3");
4947
+ df.setCurrentClassName(d.className + "-end-control-handle");
4948
+ df.circleHandle(d.bezierCurves[c].endControlPoint, 3, this._handleColor(d.bezierCurves[c].endControlPoint, this.drawConfig.bezier.controlVertex.color));
4842
4949
  }
4950
+ d.bezierCurves[c].startPoint.attr.renderTime = renderTime;
4951
+ d.bezierCurves[c].endPoint.attr.renderTime = renderTime;
4843
4952
  d.bezierCurves[c].startControlPoint.attr.renderTime = renderTime;
4844
4953
  d.bezierCurves[c].endControlPoint.attr.renderTime = renderTime;
4845
4954
  }
@@ -4955,6 +5064,16 @@ var PlotBoilerplate = /** @class */ (function () {
4955
5064
  d.lowerRight.attr.renderTime = renderTime;
4956
5065
  }
4957
5066
  }
5067
+ else if (d instanceof PBText_1.PBText) {
5068
+ fill.setCurrentId(d.uid);
5069
+ fill.text(d.text, d.anchor.x, d.anchor.y, d);
5070
+ if (this.drawConfig.text.anchor) {
5071
+ draw.setCurrentId(d.uid + "_a0");
5072
+ draw.setCurrentClassName(d.className + "-anchor");
5073
+ (this.drawConfig.text.fill ? fill : draw).point(d.anchor, this.drawConfig.text.color);
5074
+ }
5075
+ d.anchor.attr.renderTime = renderTime;
5076
+ }
4958
5077
  else {
4959
5078
  console.error("Cannot draw object. Unknown class.");
4960
5079
  }
@@ -9049,7 +9168,9 @@ exports.VertexListeners = VertexListeners;
9049
9168
  * @modified 2021-02-22 Added the `path` drawing function to draw SVG path data.
9050
9169
  * @modified 2021-03-31 Added the `endDrawCycle` function from `DrawLib`.
9051
9170
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
9052
- * @version 1.9.0
9171
+ * @modified 2021-11-12 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
9172
+ * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
9173
+ * @version 1.10.0
9053
9174
  **/
9054
9175
  Object.defineProperty(exports, "__esModule", ({ value: true }));
9055
9176
  exports.drawutils = void 0;
@@ -9709,20 +9830,62 @@ var drawutils = /** @class */ (function () {
9709
9830
  this.ctx.setLineDash([]);
9710
9831
  this.ctx.restore();
9711
9832
  };
9833
+ /**
9834
+ * Draw a text at the given relative position.
9835
+ *
9836
+ * @method text
9837
+ * @param {string} text - The text to draw.
9838
+ * @param {number} x - The x-position to draw the text at.
9839
+ * @param {number} y - The y-position to draw the text at.
9840
+ * @param {string=} options.color - The Color to use.
9841
+ * @param {string=} options.fontFamily - The font family to use.
9842
+ * @param {number=} options.fontSize - The font size (in pixels) to use.
9843
+ * @param {FontStyle=} options.fontStyle - The font style to use.
9844
+ * @param {FontWeight=} options.fontWeight - The font weight to use.
9845
+ * @param {number=} options.lineHeight - The line height (in pixels) to use.
9846
+ * @param {number=} options.rotation - The (optional) rotation in radians.
9847
+ * @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"`.
9848
+ * @return {void}
9849
+ * @instance
9850
+ * @memberof drawutils
9851
+ */
9712
9852
  drawutils.prototype.text = function (text, x, y, options) {
9853
+ // See https://stackoverflow.com/a/23523697
9854
+ var _a, _b, _c;
9713
9855
  options = options || {};
9714
9856
  this.ctx.save();
9715
- x = this.offset.x + x * this.scale.x;
9716
- y = this.offset.y + y * this.scale.y;
9857
+ var relX = this.offset.x + x * this.scale.x;
9858
+ var relY = this.offset.y + y * this.scale.y;
9717
9859
  var color = options.color || "black";
9860
+ if (options.fontSize || options.fontFamily) {
9861
+ // Scaling of text only works in uniform mode
9862
+ this.ctx.font =
9863
+ (options.fontWeight ? options.fontWeight + " " : "") +
9864
+ (options.fontStyle ? options.fontStyle + " " : "") +
9865
+ (options.fontSize ? options.fontSize * this.scale.x + "px " : " ") +
9866
+ (options.fontFamily
9867
+ ? options.fontFamily.indexOf(" ") === -1
9868
+ ? options.fontFamily
9869
+ : "\"" + options.fontFamily + "\""
9870
+ : "Arial");
9871
+ }
9872
+ if (options.textAlign) {
9873
+ this.ctx.textAlign = options.textAlign;
9874
+ }
9875
+ var rotation = (_a = options.rotation) !== null && _a !== void 0 ? _a : 0.0;
9876
+ var lineHeight = ((_c = (_b = options.lineHeight) !== null && _b !== void 0 ? _b : options.fontSize) !== null && _c !== void 0 ? _c : 0) * this.scale.x;
9877
+ this.ctx.translate(relX, relY);
9878
+ this.ctx.rotate(rotation);
9718
9879
  if (this.fillShapes) {
9719
9880
  this.ctx.fillStyle = color;
9720
- this.ctx.fillText(text, x, y);
9881
+ this.ctx.fillText(text, 0, lineHeight / 2);
9721
9882
  }
9722
9883
  else {
9723
9884
  this.ctx.strokeStyle = color;
9724
- this.ctx.strokeText(text, x, y);
9885
+ this.ctx.strokeText(text, 0, lineHeight / 2);
9725
9886
  }
9887
+ // this.ctx.translate(-relX, -relY);
9888
+ // this.ctx.rotate(-rotation); // is this necessary before 'restore()'?
9726
9889
  this.ctx.restore();
9727
9890
  };
9728
9891
  /**
@@ -9742,8 +9905,9 @@ var drawutils = /** @class */ (function () {
9742
9905
  */
9743
9906
  drawutils.prototype.label = function (text, x, y, rotation, color) {
9744
9907
  this.ctx.save();
9908
+ this.ctx.font = "lighter 9pt Arial";
9745
9909
  this.ctx.translate(x, y);
9746
- if (typeof rotation != "undefined")
9910
+ if (typeof rotation !== "undefined")
9747
9911
  this.ctx.rotate(rotation);
9748
9912
  this.ctx.fillStyle = color || "black";
9749
9913
  if (this.fillShapes) {
@@ -10364,6 +10528,25 @@ var drawutilsgl = /** @class */ (function () {
10364
10528
  drawutilsgl.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
10365
10529
  // NOT YET IMPLEMENTED
10366
10530
  };
10531
+ /**
10532
+ * Draw a text at the given relative position.
10533
+ *
10534
+ * @method text
10535
+ * @param {string} text - The text to draw.
10536
+ * @param {number} x - The x-position to draw the text at.
10537
+ * @param {number} y - The y-position to draw the text at.
10538
+ * @param {string=} options.color - The Color to use.
10539
+ * @param {string=} options.fontFamily - The font family to use.
10540
+ * @param {number=} options.fontSize - The font size (in pixels) to use.
10541
+ * @param {FontStyle=} options.fontStyle - The font style to use.
10542
+ * @param {FontWeight=} options.fontWeight - The font weight to use.
10543
+ * @param {number=} options.lineHeight - The line height (in pixels) to use.
10544
+ * @param {number=} options.rotation - The (optional) rotation in radians.
10545
+ * @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"`.
10546
+ * @return {void}
10547
+ * @instance
10548
+ * @memberof drawutils
10549
+ */
10367
10550
  drawutilsgl.prototype.text = function (text, x, y, options) {
10368
10551
  // NOT YET IMPLEMENTED
10369
10552
  };
@@ -10375,14 +10558,12 @@ var drawutilsgl = /** @class */ (function () {
10375
10558
  * @param {number} x - The x-position to draw the text at.
10376
10559
  * @param {number} y - The y-position to draw the text at.
10377
10560
  * @param {number=} rotation - The (aoptional) rotation in radians.
10561
+ * @param {string="black"} color - The color to use (default is black).
10378
10562
  * @return {void}
10379
10563
  * @instance
10380
10564
  * @memberof drawutils
10381
10565
  */
10382
- // +---------------------------------------------------------------------------------
10383
- // | Draw a non-scaling text label at the given position.
10384
- // +-------------------------------
10385
- drawutilsgl.prototype.label = function (text, x, y, rotation) {
10566
+ drawutilsgl.prototype.label = function (text, x, y, rotation, color) {
10386
10567
  // NOT YET IMPLEMENTED
10387
10568
  };
10388
10569
  /**
@@ -10517,13 +10698,17 @@ var GLU = /** @class */ (function () {
10517
10698
  * @modified 2021-03-31 Added 'ellipseSector' the the class names.
10518
10699
  * @modified 2021-03-31 Implemented buffering using a buffer <g> node and the beginDrawCycle and endDrawCycle methods.
10519
10700
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
10520
- * @version 1.3.0
10701
+ * @modified 2021-11-15 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
10702
+ * @modified 2021-11-19 Fixing the `label(text,x,y)` position.
10703
+ * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
10704
+ * @version 1.4.0
10521
10705
  **/
10522
10706
  Object.defineProperty(exports, "__esModule", ({ value: true }));
10523
10707
  exports.drawutilssvg = void 0;
10524
10708
  var CircleSector_1 = __webpack_require__(946);
10525
10709
  var CubicBezierCurve_1 = __webpack_require__(510);
10526
10710
  var Vertex_1 = __webpack_require__(421);
10711
+ var RAD_TO_DEG = 180 / Math.PI;
10527
10712
  /**
10528
10713
  * @classdesc A helper class for basic SVG drawing operations. This class should
10529
10714
  * be compatible to the default 'draw' class.
@@ -10583,7 +10768,8 @@ var drawutilssvg = /** @class */ (function () {
10583
10768
  "vertex": "Vertex",
10584
10769
  "line": "Line",
10585
10770
  "vector": "Vector",
10586
- "image": "Image"
10771
+ "image": "Image",
10772
+ "text": "Text"
10587
10773
  };
10588
10774
  // Question: why isn't this working if the svgNode is created dynamically? (nodeStyle.sheet is null)
10589
10775
  var rules = [];
@@ -11364,27 +11550,65 @@ var drawutilssvg = /** @class */ (function () {
11364
11550
  if (!isOpen)
11365
11551
  d.push("Z");
11366
11552
  node.setAttribute("d", d.join(" "));
11367
- return this._bindFillDraw(node, "polyline", color, lineWidth || 1);
11553
+ return this._bindFillDraw(node, "polygon", color, lineWidth || 1);
11368
11554
  };
11369
11555
  /**
11370
- * Draw a text label at the given relative position.
11556
+ * Draw a text at the given relative position.
11371
11557
  *
11372
- * @method label
11558
+ * @method text
11373
11559
  * @param {string} text - The text to draw.
11374
11560
  * @param {number} x - The x-position to draw the text at.
11375
11561
  * @param {number} y - The y-position to draw the text at.
11376
- * @param {number=} rotation - The (optional) rotation in radians.
11562
+ * @param {string=} options.color - The Color to use.
11563
+ * @param {string=} options.fontFamily - The font family to use.
11564
+ * @param {number=} options.fontSize - The font size (in pixels) to use.
11565
+ * @param {FontStyle=} options.fontStyle - The font style to use.
11566
+ * @param {FontWeight=} options.fontWeight - The font weight to use.
11567
+ * @param {number=} options.lineHeight - The line height (in pixels) to use.
11568
+ * @param {number=} options.rotation - The (optional) rotation in radians.
11569
+ * @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"`.
11377
11570
  * @return {void}
11378
11571
  * @instance
11379
- * @memberof drawutilssvg
11572
+ * @memberof drawutils
11380
11573
  */
11381
11574
  drawutilssvg.prototype.text = function (text, x, y, options) {
11575
+ var _a, _b;
11382
11576
  options = options || {};
11383
11577
  var color = options.color || "black";
11384
- var node = this.makeNode("text");
11385
- node.setAttribute("x", "" + this._x(x));
11386
- node.setAttribute("y", "" + this._y(y));
11387
- node.innerHTML = text;
11578
+ var lineHeight = ((_b = (_a = options.lineHeight) !== null && _a !== void 0 ? _a : options.fontSize) !== null && _b !== void 0 ? _b : 0) * this.scale.x;
11579
+ // https://www.w3.org/TR/SVG/text.html#TextAnchorProperty
11580
+ // start | middle | end
11581
+ var textAlign = options.textAlign === "left" || options.textAlign === "start"
11582
+ ? "start"
11583
+ : options.textAlign === "center"
11584
+ ? "middle"
11585
+ : options.textAlign === "right" || options.textAlign === "end"
11586
+ ? "end"
11587
+ : "start";
11588
+ var transformOrigin = this._x(x) + "px " + this._y(y) + "px";
11589
+ var translate = "translate(" + this._x(x) + " " + (this._y(y) + lineHeight / 2) + ")";
11590
+ // Safari has a transform-origin/rotation bug.
11591
+ // It's essential to use rotate(r,x,y) here. "rotate(r)"" with transform-origin(x,y) won't do the job.
11592
+ // And rotate and translate cannot be used is combination on a text object.
11593
+ // So wrap the text inside a <g>, translate the <g>, and rotate the text inside.
11594
+ var rotate = options.rotation ? "rotate(" + options.rotation * RAD_TO_DEG + " 0 0)" : "";
11595
+ var node = this.makeNode("g");
11596
+ var curId = this.curId;
11597
+ this.curId = curId + "_text";
11598
+ var textNode = this.makeNode("text");
11599
+ node.appendChild(textNode);
11600
+ textNode.setAttribute("font-family", options.fontFamily); // May be undefined
11601
+ textNode.setAttribute("font-size", options.fontSize ? "" + options.fontSize * this.scale.x : null);
11602
+ textNode.setAttribute("font-style", options.fontStyle ? "" + options.fontStyle : null);
11603
+ textNode.setAttribute("font-weight", options.fontWeight ? "" + options.fontWeight : null);
11604
+ textNode.setAttribute("text-anchor", textAlign);
11605
+ textNode.setAttribute("transform-origin", "0 0");
11606
+ textNode.setAttribute("transform", rotate);
11607
+ node.setAttribute("transform-origin", transformOrigin);
11608
+ node.setAttribute("transform", translate);
11609
+ textNode.innerHTML = text;
11610
+ // Restore old ID
11611
+ this.curId = curId;
11388
11612
  return this._bindFillDraw(node, "text", color, 1);
11389
11613
  };
11390
11614
  /**
@@ -11395,16 +11619,21 @@ var drawutilssvg = /** @class */ (function () {
11395
11619
  * @param {number} x - The x-position to draw the text at.
11396
11620
  * @param {number} y - The y-position to draw the text at.
11397
11621
  * @param {number=} rotation - The (optional) rotation in radians.
11622
+ * @param {string="black"} color - The color to use (default is black).
11398
11623
  * @return {void}
11399
11624
  * @instance
11400
11625
  * @memberof drawutilssvg
11401
11626
  */
11402
- drawutilssvg.prototype.label = function (text, x, y, rotation) {
11627
+ drawutilssvg.prototype.label = function (text, x, y, rotation, color) {
11403
11628
  var node = this.makeNode("text");
11404
11629
  // For some strange reason SVG rotation transforms use degrees instead of radians
11405
- node.setAttribute("transform", "translate(" + this.offset.x + "," + this.offset.y + "), rotate(" + (rotation / Math.PI) * 180 + ")");
11630
+ node.setAttribute("transform", "translate(" + x + "," + y + "), rotate(" + ((rotation || 0) / Math.PI) * 180 + ")");
11631
+ node.setAttribute("font-family", "Arial");
11632
+ node.setAttribute("font-size", "9pt");
11633
+ node.setAttribute("font-style", "normal");
11634
+ node.setAttribute("font-weight", "lighter");
11406
11635
  node.innerHTML = text;
11407
- return this._bindFillDraw(node, "label", "black", null);
11636
+ return this._bindFillDraw(node, "label", color || "black", null);
11408
11637
  };
11409
11638
  /**
11410
11639
  * Draw an SVG-like path given by the specified path data.
@@ -11855,6 +12084,7 @@ globalThis.VEllipse = __webpack_require__(112).VEllipse;
11855
12084
  globalThis.Circle = __webpack_require__(913).Circle;
11856
12085
  globalThis.CircleSector = __webpack_require__(946).CircleSector;
11857
12086
  globalThis.PBImage = __webpack_require__(699).PBImage;
12087
+ globalThis.PBText = __webpack_require__(196).PBText;
11858
12088
  globalThis.MouseHandler = __webpack_require__(293).MouseHandler;
11859
12089
  globalThis.KeyHandler = __webpack_require__(909).KeyHandler;
11860
12090
  globalThis.drawutils = __webpack_require__(149).drawutils;