plotboilerplate 1.12.8 → 1.14.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 (98) hide show
  1. package/README.md +4 -1
  2. package/changelog.md +26 -0
  3. package/dist/index.esm.js +292 -51
  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 +306 -50
  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 +41 -14
  20. package/src/cjs/PlotBoilerplate.js.map +1 -1
  21. package/src/cjs/Vertex.d.ts +18 -4
  22. package/src/cjs/Vertex.js +24 -7
  23. package/src/cjs/Vertex.js.map +1 -1
  24. package/src/cjs/draw.d.ts +30 -2
  25. package/src/cjs/draw.js +51 -6
  26. package/src/cjs/draw.js.map +1 -1
  27. package/src/cjs/drawgl.d.ts +29 -2
  28. package/src/cjs/drawgl.js +21 -4
  29. package/src/cjs/drawgl.js.map +1 -1
  30. package/src/cjs/drawutilssvg.d.ts +25 -7
  31. package/src/cjs/drawutilssvg.js +62 -14
  32. package/src/cjs/drawutilssvg.js.map +1 -1
  33. package/src/cjs/entry.js +1 -0
  34. package/src/cjs/index.d.ts +1 -0
  35. package/src/cjs/index.js +1 -0
  36. package/src/cjs/index.js.map +1 -1
  37. package/src/cjs/interfaces/DrawLib.d.ts +27 -6
  38. package/src/cjs/interfaces/DrawLib.js +3 -0
  39. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  40. package/src/cjs/interfaces/core.d.ts +9 -1
  41. package/src/cjs/interfaces/core.js +1 -0
  42. package/src/cjs/interfaces/core.js.map +1 -1
  43. package/src/cjs/utils/datastructures/Color.d.ts +28 -15
  44. package/src/cjs/utils/datastructures/Color.js +276 -88
  45. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  46. package/src/esm/BezierPath.d.ts +12 -1
  47. package/src/esm/BezierPath.js +34 -5
  48. package/src/esm/BezierPath.js.map +1 -1
  49. package/src/esm/PBText.d.ts +116 -0
  50. package/src/esm/PBText.js +61 -0
  51. package/src/esm/PBText.js.map +1 -0
  52. package/src/esm/PlotBoilerplate.d.ts +2 -1
  53. package/src/esm/PlotBoilerplate.js +41 -14
  54. package/src/esm/PlotBoilerplate.js.map +1 -1
  55. package/src/esm/Vertex.d.ts +18 -4
  56. package/src/esm/Vertex.js +24 -7
  57. package/src/esm/Vertex.js.map +1 -1
  58. package/src/esm/draw.d.ts +30 -2
  59. package/src/esm/draw.js +51 -6
  60. package/src/esm/draw.js.map +1 -1
  61. package/src/esm/drawgl.d.ts +29 -2
  62. package/src/esm/drawgl.js +21 -4
  63. package/src/esm/drawgl.js.map +1 -1
  64. package/src/esm/drawutilssvg.d.ts +25 -7
  65. package/src/esm/drawutilssvg.js +62 -14
  66. package/src/esm/drawutilssvg.js.map +1 -1
  67. package/src/esm/entry.js +1 -0
  68. package/src/esm/index.d.ts +1 -0
  69. package/src/esm/index.js +1 -0
  70. package/src/esm/index.js.map +1 -1
  71. package/src/esm/interfaces/DrawLib.d.ts +27 -6
  72. package/src/esm/interfaces/DrawLib.js +3 -0
  73. package/src/esm/interfaces/DrawLib.js.map +1 -1
  74. package/src/esm/interfaces/core.d.ts +9 -1
  75. package/src/esm/interfaces/core.js +1 -0
  76. package/src/esm/interfaces/core.js.map +1 -1
  77. package/src/esm/utils/datastructures/Color.d.ts +28 -15
  78. package/src/esm/utils/datastructures/Color.js +277 -89
  79. package/src/esm/utils/datastructures/Color.js.map +1 -1
  80. package/src/ts/BezierPath.ts +37 -5
  81. package/src/ts/PBText.ts +147 -0
  82. package/src/ts/PlotBoilerplate.ts +44 -18
  83. package/src/ts/Vertex.ts +26 -7
  84. package/src/ts/draw.ts +71 -8
  85. package/src/ts/drawgl.ts +48 -8
  86. package/src/ts/drawutilssvg.ts +94 -17
  87. package/src/ts/index.ts +1 -0
  88. package/src/ts/interfaces/DrawLib.ts +30 -4
  89. package/src/ts/interfaces/core.ts +9 -0
  90. package/src/ts/utils/datastructures/Color.ts +695 -508
  91. package/dist/plotboilerplate.browser.min.js.LICENSE.txt +0 -8
  92. package/src/ts/utils/algorithms/clearPolygonDuplicateVertices.ts~ +0 -5
  93. package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts~ +0 -45
  94. package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts~ +0 -113
  95. package/src/ts/utils/algorithms/sutherlandHodgman.ts~ +0 -88
  96. package/src/ts/utils/datastructures/Color.ts~ +0 -331
  97. package/src/ts/utils/datastructures/Girih.ts~ +0 -151
  98. 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
  }
@@ -4976,6 +5094,16 @@ var PlotBoilerplate = /** @class */ (function () {
4976
5094
  d.lowerRight.attr.renderTime = renderTime;
4977
5095
  }
4978
5096
  }
5097
+ else if (d instanceof PBText_1.PBText) {
5098
+ fill.setCurrentId(d.uid);
5099
+ fill.text(d.text, d.anchor.x, d.anchor.y, d);
5100
+ if (this.drawConfig.text.anchor) {
5101
+ draw.setCurrentId(d.uid + "_a0");
5102
+ draw.setCurrentClassName(d.className + "-anchor");
5103
+ (this.drawConfig.text.fill ? fill : draw).point(d.anchor, this.drawConfig.text.color);
5104
+ }
5105
+ d.anchor.attr.renderTime = renderTime;
5106
+ }
4979
5107
  else {
4980
5108
  console.error("Cannot draw object. Unknown class.");
4981
5109
  }
@@ -5255,7 +5383,6 @@ var PlotBoilerplate = /** @class */ (function () {
5255
5383
  // Apply the zoom (the tolerant area should not shrink or grow when zooming)
5256
5384
  tolerance /= _self.draw.scale.x;
5257
5385
  // Search in vertices
5258
- // for( var vindex in _self.vertices ) {
5259
5386
  for (var vindex = 0; vindex < _self.vertices.length; vindex++) {
5260
5387
  var vert = _self.vertices[vindex];
5261
5388
  if ((vert.attr.draggable || vert.attr.selectable) && vert.distance(point) < tolerance) {
@@ -5275,10 +5402,7 @@ var PlotBoilerplate = /** @class */ (function () {
5275
5402
  * @return {void}
5276
5403
  **/
5277
5404
  PlotBoilerplate.prototype.handleClick = function (e) {
5278
- // x:number,y:number) {
5279
5405
  var _self = this;
5280
- // const x:number = e.params.pos.x;
5281
- //const y:number = e.params.pos.y;
5282
5406
  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
5407
  if (p) {
5284
5408
  _self.vertices[p.vindex].listeners.fireClickEvent(e);
@@ -5295,7 +5419,7 @@ var PlotBoilerplate = /** @class */ (function () {
5295
5419
  }
5296
5420
  _self.redraw();
5297
5421
  }
5298
- else if (this.keyHandler.isDown("y") /* && p.type=='bpath' && (p.pid==BezierPath.START_POINT || p.pid==BezierPath.END_POINT) */) {
5422
+ else if (this.keyHandler.isDown("y")) {
5299
5423
  _self.vertices[p.vindex].attr.bezierAutoAdjust = !_self.vertices[p.vindex].attr.bezierAutoAdjust;
5300
5424
  _self.redraw();
5301
5425
  }
@@ -5593,6 +5717,7 @@ var PlotBoilerplate = /** @class */ (function () {
5593
5717
  _self.draggedElements = [];
5594
5718
  };
5595
5719
  var afProps = {
5720
+ // touchStart: (evt: TouchEvent) => {
5596
5721
  touchStart: function (evt) {
5597
5722
  if (evt.touches.length == 1) {
5598
5723
  touchMovePos = new Vertex_1.Vertex(relPos_1({ x: evt.touches[0].clientX, y: evt.touches[0].clientY }));
@@ -5695,10 +5820,13 @@ var PlotBoilerplate = /** @class */ (function () {
5695
5820
  _self.redraw();
5696
5821
  }
5697
5822
  }; // END afProps
5698
- if (window["createAlloyFinger"])
5823
+ if (window["createAlloyFinger"]) {
5699
5824
  window["createAlloyFinger"](this.eventCatcher ? this.eventCatcher : this.canvas, afProps);
5700
- else
5825
+ }
5826
+ else {
5827
+ /* tslint:disable-next-line */
5701
5828
  new alloyfinger_typescript_1.default(this.eventCatcher ? this.eventCatcher : this.canvas, afProps);
5829
+ }
5702
5830
  }
5703
5831
  catch (e) {
5704
5832
  console.error("Failed to initialize AlloyFinger!");
@@ -8159,7 +8287,9 @@ exports.VertTuple = VertTuple;
8159
8287
  * @modified 2020-05-26 Added functions addX(number) and addY(number).
8160
8288
  * @modified 2020-10-30 Changed the warnings in `sub(...)` and `add(...)` into real errors.
8161
8289
  * @modified 2021-03-01 Changed the second param `center` in the `rotate` function from Vertex to XYCoords.
8162
- * @version 2.4.2
8290
+ * @modified 2021-12-01 Changed the type of param of `scale` to XYCoords.
8291
+ * @modified 2021-12-01 Added function `scaleXY` for non uniform scaling.
8292
+ * @version 2.5.0
8163
8293
  *
8164
8294
  * @file Vertex
8165
8295
  * @public
@@ -8505,20 +8635,35 @@ var Vertex = /** @class */ (function () {
8505
8635
  };
8506
8636
  /**
8507
8637
  * This is a vector-like behavior and 'scales' this vertex
8508
- * towards/from a given center.
8638
+ * towards/from a given center by one uniform scale factor.
8509
8639
  *
8510
8640
  * @method scale
8511
8641
  * @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).
8642
+ * @param {XYCoords=} center - The origin of scaling; default is (0,0).
8513
8643
  * @return {Vertex} this
8514
8644
  * @instance
8515
8645
  * @memberof Vertex
8516
8646
  **/
8517
8647
  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;
8648
+ return this.scaleXY({ x: factor, y: factor }, center);
8649
+ };
8650
+ /**
8651
+ * This is a vector-like behavior and 'scales' this vertex
8652
+ * towards/from a given center by two independent x- and y- scale factors.
8653
+ *
8654
+ * @method scale
8655
+ * @param {number} factor - The factor to 'scale' this vertex; 1.0 means no change.
8656
+ * @param {XYCoords=} center - The origin of scaling; default is (0,0).
8657
+ * @return {Vertex} this
8658
+ * @instance
8659
+ * @memberof Vertex
8660
+ **/
8661
+ Vertex.prototype.scaleXY = function (factors, center) {
8662
+ if (!center || typeof center === "undefined") {
8663
+ center = { x: 0, y: 0 };
8664
+ }
8665
+ this.x = center.x + (this.x - center.x) * factors.x;
8666
+ this.y = center.y + (this.y - center.y) * factors.y;
8522
8667
  return this;
8523
8668
  };
8524
8669
  /**
@@ -9070,7 +9215,9 @@ exports.VertexListeners = VertexListeners;
9070
9215
  * @modified 2021-02-22 Added the `path` drawing function to draw SVG path data.
9071
9216
  * @modified 2021-03-31 Added the `endDrawCycle` function from `DrawLib`.
9072
9217
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
9073
- * @version 1.9.0
9218
+ * @modified 2021-11-12 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
9219
+ * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
9220
+ * @version 1.10.0
9074
9221
  **/
9075
9222
  Object.defineProperty(exports, "__esModule", ({ value: true }));
9076
9223
  exports.drawutils = void 0;
@@ -9730,20 +9877,62 @@ var drawutils = /** @class */ (function () {
9730
9877
  this.ctx.setLineDash([]);
9731
9878
  this.ctx.restore();
9732
9879
  };
9880
+ /**
9881
+ * Draw a text at the given relative position.
9882
+ *
9883
+ * @method text
9884
+ * @param {string} text - The text to draw.
9885
+ * @param {number} x - The x-position to draw the text at.
9886
+ * @param {number} y - The y-position to draw the text at.
9887
+ * @param {string=} options.color - The Color to use.
9888
+ * @param {string=} options.fontFamily - The font family to use.
9889
+ * @param {number=} options.fontSize - The font size (in pixels) to use.
9890
+ * @param {FontStyle=} options.fontStyle - The font style to use.
9891
+ * @param {FontWeight=} options.fontWeight - The font weight to use.
9892
+ * @param {number=} options.lineHeight - The line height (in pixels) to use.
9893
+ * @param {number=} options.rotation - The (optional) rotation in radians.
9894
+ * @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"`.
9895
+ * @return {void}
9896
+ * @instance
9897
+ * @memberof drawutils
9898
+ */
9733
9899
  drawutils.prototype.text = function (text, x, y, options) {
9900
+ // See https://stackoverflow.com/a/23523697
9901
+ var _a, _b, _c;
9734
9902
  options = options || {};
9735
9903
  this.ctx.save();
9736
- x = this.offset.x + x * this.scale.x;
9737
- y = this.offset.y + y * this.scale.y;
9904
+ var relX = this.offset.x + x * this.scale.x;
9905
+ var relY = this.offset.y + y * this.scale.y;
9738
9906
  var color = options.color || "black";
9907
+ if (options.fontSize || options.fontFamily) {
9908
+ // Scaling of text only works in uniform mode
9909
+ this.ctx.font =
9910
+ (options.fontWeight ? options.fontWeight + " " : "") +
9911
+ (options.fontStyle ? options.fontStyle + " " : "") +
9912
+ (options.fontSize ? options.fontSize * this.scale.x + "px " : " ") +
9913
+ (options.fontFamily
9914
+ ? options.fontFamily.indexOf(" ") === -1
9915
+ ? options.fontFamily
9916
+ : "\"" + options.fontFamily + "\""
9917
+ : "Arial");
9918
+ }
9919
+ if (options.textAlign) {
9920
+ this.ctx.textAlign = options.textAlign;
9921
+ }
9922
+ var rotation = (_a = options.rotation) !== null && _a !== void 0 ? _a : 0.0;
9923
+ var lineHeight = ((_c = (_b = options.lineHeight) !== null && _b !== void 0 ? _b : options.fontSize) !== null && _c !== void 0 ? _c : 0) * this.scale.x;
9924
+ this.ctx.translate(relX, relY);
9925
+ this.ctx.rotate(rotation);
9739
9926
  if (this.fillShapes) {
9740
9927
  this.ctx.fillStyle = color;
9741
- this.ctx.fillText(text, x, y);
9928
+ this.ctx.fillText(text, 0, lineHeight / 2);
9742
9929
  }
9743
9930
  else {
9744
9931
  this.ctx.strokeStyle = color;
9745
- this.ctx.strokeText(text, x, y);
9932
+ this.ctx.strokeText(text, 0, lineHeight / 2);
9746
9933
  }
9934
+ // this.ctx.translate(-relX, -relY);
9935
+ // this.ctx.rotate(-rotation); // is this necessary before 'restore()'?
9747
9936
  this.ctx.restore();
9748
9937
  };
9749
9938
  /**
@@ -9763,8 +9952,9 @@ var drawutils = /** @class */ (function () {
9763
9952
  */
9764
9953
  drawutils.prototype.label = function (text, x, y, rotation, color) {
9765
9954
  this.ctx.save();
9955
+ this.ctx.font = "lighter 9pt Arial";
9766
9956
  this.ctx.translate(x, y);
9767
- if (typeof rotation != "undefined")
9957
+ if (typeof rotation !== "undefined")
9768
9958
  this.ctx.rotate(rotation);
9769
9959
  this.ctx.fillStyle = color || "black";
9770
9960
  if (this.fillShapes) {
@@ -10385,6 +10575,25 @@ var drawutilsgl = /** @class */ (function () {
10385
10575
  drawutilsgl.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
10386
10576
  // NOT YET IMPLEMENTED
10387
10577
  };
10578
+ /**
10579
+ * Draw a text at the given relative position.
10580
+ *
10581
+ * @method text
10582
+ * @param {string} text - The text to draw.
10583
+ * @param {number} x - The x-position to draw the text at.
10584
+ * @param {number} y - The y-position to draw the text at.
10585
+ * @param {string=} options.color - The Color to use.
10586
+ * @param {string=} options.fontFamily - The font family to use.
10587
+ * @param {number=} options.fontSize - The font size (in pixels) to use.
10588
+ * @param {FontStyle=} options.fontStyle - The font style to use.
10589
+ * @param {FontWeight=} options.fontWeight - The font weight to use.
10590
+ * @param {number=} options.lineHeight - The line height (in pixels) to use.
10591
+ * @param {number=} options.rotation - The (optional) rotation in radians.
10592
+ * @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"`.
10593
+ * @return {void}
10594
+ * @instance
10595
+ * @memberof drawutils
10596
+ */
10388
10597
  drawutilsgl.prototype.text = function (text, x, y, options) {
10389
10598
  // NOT YET IMPLEMENTED
10390
10599
  };
@@ -10396,14 +10605,12 @@ var drawutilsgl = /** @class */ (function () {
10396
10605
  * @param {number} x - The x-position to draw the text at.
10397
10606
  * @param {number} y - The y-position to draw the text at.
10398
10607
  * @param {number=} rotation - The (aoptional) rotation in radians.
10608
+ * @param {string="black"} color - The color to use (default is black).
10399
10609
  * @return {void}
10400
10610
  * @instance
10401
10611
  * @memberof drawutils
10402
10612
  */
10403
- // +---------------------------------------------------------------------------------
10404
- // | Draw a non-scaling text label at the given position.
10405
- // +-------------------------------
10406
- drawutilsgl.prototype.label = function (text, x, y, rotation) {
10613
+ drawutilsgl.prototype.label = function (text, x, y, rotation, color) {
10407
10614
  // NOT YET IMPLEMENTED
10408
10615
  };
10409
10616
  /**
@@ -10538,13 +10745,17 @@ var GLU = /** @class */ (function () {
10538
10745
  * @modified 2021-03-31 Added 'ellipseSector' the the class names.
10539
10746
  * @modified 2021-03-31 Implemented buffering using a buffer <g> node and the beginDrawCycle and endDrawCycle methods.
10540
10747
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
10541
- * @version 1.3.0
10748
+ * @modified 2021-11-15 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
10749
+ * @modified 2021-11-19 Fixing the `label(text,x,y)` position.
10750
+ * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
10751
+ * @version 1.4.0
10542
10752
  **/
10543
10753
  Object.defineProperty(exports, "__esModule", ({ value: true }));
10544
10754
  exports.drawutilssvg = void 0;
10545
10755
  var CircleSector_1 = __webpack_require__(946);
10546
10756
  var CubicBezierCurve_1 = __webpack_require__(510);
10547
10757
  var Vertex_1 = __webpack_require__(421);
10758
+ var RAD_TO_DEG = 180 / Math.PI;
10548
10759
  /**
10549
10760
  * @classdesc A helper class for basic SVG drawing operations. This class should
10550
10761
  * be compatible to the default 'draw' class.
@@ -10604,7 +10815,8 @@ var drawutilssvg = /** @class */ (function () {
10604
10815
  "vertex": "Vertex",
10605
10816
  "line": "Line",
10606
10817
  "vector": "Vector",
10607
- "image": "Image"
10818
+ "image": "Image",
10819
+ "text": "Text"
10608
10820
  };
10609
10821
  // Question: why isn't this working if the svgNode is created dynamically? (nodeStyle.sheet is null)
10610
10822
  var rules = [];
@@ -11385,27 +11597,65 @@ var drawutilssvg = /** @class */ (function () {
11385
11597
  if (!isOpen)
11386
11598
  d.push("Z");
11387
11599
  node.setAttribute("d", d.join(" "));
11388
- return this._bindFillDraw(node, "polyline", color, lineWidth || 1);
11600
+ return this._bindFillDraw(node, "polygon", color, lineWidth || 1);
11389
11601
  };
11390
11602
  /**
11391
- * Draw a text label at the given relative position.
11603
+ * Draw a text at the given relative position.
11392
11604
  *
11393
- * @method label
11605
+ * @method text
11394
11606
  * @param {string} text - The text to draw.
11395
11607
  * @param {number} x - The x-position to draw the text at.
11396
11608
  * @param {number} y - The y-position to draw the text at.
11397
- * @param {number=} rotation - The (optional) rotation in radians.
11609
+ * @param {string=} options.color - The Color to use.
11610
+ * @param {string=} options.fontFamily - The font family to use.
11611
+ * @param {number=} options.fontSize - The font size (in pixels) to use.
11612
+ * @param {FontStyle=} options.fontStyle - The font style to use.
11613
+ * @param {FontWeight=} options.fontWeight - The font weight to use.
11614
+ * @param {number=} options.lineHeight - The line height (in pixels) to use.
11615
+ * @param {number=} options.rotation - The (optional) rotation in radians.
11616
+ * @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
11617
  * @return {void}
11399
11618
  * @instance
11400
- * @memberof drawutilssvg
11619
+ * @memberof drawutils
11401
11620
  */
11402
11621
  drawutilssvg.prototype.text = function (text, x, y, options) {
11622
+ var _a, _b;
11403
11623
  options = options || {};
11404
11624
  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;
11625
+ var lineHeight = ((_b = (_a = options.lineHeight) !== null && _a !== void 0 ? _a : options.fontSize) !== null && _b !== void 0 ? _b : 0) * this.scale.x;
11626
+ // https://www.w3.org/TR/SVG/text.html#TextAnchorProperty
11627
+ // start | middle | end
11628
+ var textAlign = options.textAlign === "left" || options.textAlign === "start"
11629
+ ? "start"
11630
+ : options.textAlign === "center"
11631
+ ? "middle"
11632
+ : options.textAlign === "right" || options.textAlign === "end"
11633
+ ? "end"
11634
+ : "start";
11635
+ var transformOrigin = this._x(x) + "px " + this._y(y) + "px";
11636
+ var translate = "translate(" + this._x(x) + " " + (this._y(y) + lineHeight / 2) + ")";
11637
+ // Safari has a transform-origin/rotation bug.
11638
+ // It's essential to use rotate(r,x,y) here. "rotate(r)"" with transform-origin(x,y) won't do the job.
11639
+ // And rotate and translate cannot be used is combination on a text object.
11640
+ // So wrap the text inside a <g>, translate the <g>, and rotate the text inside.
11641
+ var rotate = options.rotation ? "rotate(" + options.rotation * RAD_TO_DEG + " 0 0)" : "";
11642
+ var node = this.makeNode("g");
11643
+ var curId = this.curId;
11644
+ this.curId = curId + "_text";
11645
+ var textNode = this.makeNode("text");
11646
+ node.appendChild(textNode);
11647
+ textNode.setAttribute("font-family", options.fontFamily); // May be undefined
11648
+ textNode.setAttribute("font-size", options.fontSize ? "" + options.fontSize * this.scale.x : null);
11649
+ textNode.setAttribute("font-style", options.fontStyle ? "" + options.fontStyle : null);
11650
+ textNode.setAttribute("font-weight", options.fontWeight ? "" + options.fontWeight : null);
11651
+ textNode.setAttribute("text-anchor", textAlign);
11652
+ textNode.setAttribute("transform-origin", "0 0");
11653
+ textNode.setAttribute("transform", rotate);
11654
+ node.setAttribute("transform-origin", transformOrigin);
11655
+ node.setAttribute("transform", translate);
11656
+ textNode.innerHTML = text;
11657
+ // Restore old ID
11658
+ this.curId = curId;
11409
11659
  return this._bindFillDraw(node, "text", color, 1);
11410
11660
  };
11411
11661
  /**
@@ -11416,16 +11666,21 @@ var drawutilssvg = /** @class */ (function () {
11416
11666
  * @param {number} x - The x-position to draw the text at.
11417
11667
  * @param {number} y - The y-position to draw the text at.
11418
11668
  * @param {number=} rotation - The (optional) rotation in radians.
11669
+ * @param {string="black"} color - The color to use (default is black).
11419
11670
  * @return {void}
11420
11671
  * @instance
11421
11672
  * @memberof drawutilssvg
11422
11673
  */
11423
- drawutilssvg.prototype.label = function (text, x, y, rotation) {
11674
+ drawutilssvg.prototype.label = function (text, x, y, rotation, color) {
11424
11675
  var node = this.makeNode("text");
11425
11676
  // 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 + ")");
11677
+ node.setAttribute("transform", "translate(" + x + "," + y + "), rotate(" + ((rotation || 0) / Math.PI) * 180 + ")");
11678
+ node.setAttribute("font-family", "Arial");
11679
+ node.setAttribute("font-size", "9pt");
11680
+ node.setAttribute("font-style", "normal");
11681
+ node.setAttribute("font-weight", "lighter");
11427
11682
  node.innerHTML = text;
11428
- return this._bindFillDraw(node, "label", "black", null);
11683
+ return this._bindFillDraw(node, "label", color || "black", null);
11429
11684
  };
11430
11685
  /**
11431
11686
  * Draw an SVG-like path given by the specified path data.
@@ -11876,6 +12131,7 @@ globalThis.VEllipse = __webpack_require__(112).VEllipse;
11876
12131
  globalThis.Circle = __webpack_require__(913).Circle;
11877
12132
  globalThis.CircleSector = __webpack_require__(946).CircleSector;
11878
12133
  globalThis.PBImage = __webpack_require__(699).PBImage;
12134
+ globalThis.PBText = __webpack_require__(196).PBText;
11879
12135
  globalThis.MouseHandler = __webpack_require__(293).MouseHandler;
11880
12136
  globalThis.KeyHandler = __webpack_require__(909).KeyHandler;
11881
12137
  globalThis.drawutils = __webpack_require__(149).drawutils;