plotboilerplate 1.12.10 → 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 (73) hide show
  1. package/README.md +4 -1
  2. package/changelog.md +13 -0
  3. package/dist/index.esm.js +220 -26
  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 +234 -25
  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 +27 -1
  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 +9 -1
  35. package/src/cjs/interfaces/core.js +1 -0
  36. package/src/cjs/interfaces/core.js.map +1 -1
  37. package/src/esm/PBText.d.ts +116 -0
  38. package/src/esm/PBText.js +61 -0
  39. package/src/esm/PBText.js.map +1 -0
  40. package/src/esm/PlotBoilerplate.d.ts +2 -1
  41. package/src/esm/PlotBoilerplate.js +27 -1
  42. package/src/esm/PlotBoilerplate.js.map +1 -1
  43. package/src/esm/draw.d.ts +30 -2
  44. package/src/esm/draw.js +51 -6
  45. package/src/esm/draw.js.map +1 -1
  46. package/src/esm/drawgl.d.ts +29 -2
  47. package/src/esm/drawgl.js +21 -4
  48. package/src/esm/drawgl.js.map +1 -1
  49. package/src/esm/drawutilssvg.d.ts +25 -7
  50. package/src/esm/drawutilssvg.js +62 -14
  51. package/src/esm/drawutilssvg.js.map +1 -1
  52. package/src/esm/entry.js +1 -0
  53. package/src/esm/index.d.ts +1 -0
  54. package/src/esm/index.js +1 -0
  55. package/src/esm/index.js.map +1 -1
  56. package/src/esm/interfaces/DrawLib.d.ts +27 -6
  57. package/src/esm/interfaces/DrawLib.js +3 -0
  58. package/src/esm/interfaces/DrawLib.js.map +1 -1
  59. package/src/esm/interfaces/core.d.ts +9 -1
  60. package/src/esm/interfaces/core.js +1 -0
  61. package/src/esm/interfaces/core.js.map +1 -1
  62. package/src/ts/PBText.ts +147 -0
  63. package/src/ts/PlotBoilerplate.ts +24 -1
  64. package/src/ts/draw.ts +71 -8
  65. package/src/ts/drawgl.ts +48 -8
  66. package/src/ts/drawutilssvg.ts +94 -17
  67. package/src/ts/index.ts +1 -0
  68. package/src/ts/interfaces/DrawLib.ts +30 -4
  69. package/src/ts/interfaces/core.ts +9 -0
  70. package/src/ts/utils/algorithms/clearPolygonDuplicateVertices.ts~ +0 -5
  71. package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts~ +0 -45
  72. package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts~ +0 -113
  73. package/src/ts/utils/algorithms/sutherlandHodgman.ts~ +0 -88
package/README.md CHANGED
@@ -44,12 +44,15 @@ often use for the visualization of 2D geometries. Basic features are
44
44
  - images
45
45
  ([docs](https://plotboilerplate.io/docs_typedoc/classes/pbimage.html "PBImage class"),
46
46
  [example](https://plotboilerplate.io/repo/demos/basic-PBImage "PBImage example"))
47
+ - text
48
+ ([docs](https://plotboilerplate.io/docs_typedoc/classes/pbtext.html "PBText class"),
49
+ [example](https://plotboilerplate.io/repo/demos/basic-PBText "PBText example"))
47
50
  - configuration of the canvas behavior (fullsize, interaction, raster)
48
51
  - mouse interaction (zoom, pan, drag elements)
49
52
  - keyboard interaction
50
53
  - touch interaction for dragging vertices (mobile devices: zoom, pan, drag elements)
51
54
 
52
- The compressed library has 123kb.
55
+ The compressed library has 128kb.
53
56
 
54
57
  ## Install the package via npm
55
58
 
package/changelog.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ - 2021-11-24
4
+ - Speeding up the demo page with async script execution.
5
+ - Finalizing the demo page for the new `PBText` element (note: it has this name because `Text` already exists).
6
+ - 2021-11-19
7
+ - Fixing the `drawutilssvg.label(text,x,y)` position.
8
+ - Added the `color` param to the `label(...)` function.
9
+ - 2021-11-16
10
+ - Added `text` options to the `DrawConfig` interface.
11
+ - Added the `PBText` class.
12
+ - 2021-11-15
13
+ - Adding more parameters tot the `drawutilssvg.text()` function: fontSize, textAlign, fontFamily, lineHeight.
14
+ - 2021-11-12
15
+ - Adding more parameters tot the `draw.text()` function: fontSize, textAlign, fontFamily, lineHeight.
3
16
  - 2021-11.07
4
17
  - Changed the behavior of `darken` and `lighten`: the passed value is handled relative now which makes values much easier predictable and makes the change feel more 'natural'.
5
18
  - Added tests for the Color class. There were some strange things happening the the `ligthen` and `darken` function.
package/dist/index.esm.js CHANGED
@@ -4165,8 +4165,12 @@ CircleSector.circleSectorUtils = {
4165
4165
  * @modified 2021-03-31 Added 'ellipseSector' the the class names.
4166
4166
  * @modified 2021-03-31 Implemented buffering using a buffer <g> node and the beginDrawCycle and endDrawCycle methods.
4167
4167
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
4168
- * @version 1.3.0
4168
+ * @modified 2021-11-15 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
4169
+ * @modified 2021-11-19 Fixing the `label(text,x,y)` position.
4170
+ * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
4171
+ * @version 1.4.0
4169
4172
  **/
4173
+ const RAD_TO_DEG = 180 / Math.PI;
4170
4174
  /**
4171
4175
  * @classdesc A helper class for basic SVG drawing operations. This class should
4172
4176
  * be compatible to the default 'draw' class.
@@ -4226,7 +4230,8 @@ class drawutilssvg {
4226
4230
  "vertex": "Vertex",
4227
4231
  "line": "Line",
4228
4232
  "vector": "Vector",
4229
- "image": "Image"
4233
+ "image": "Image",
4234
+ "text": "Text"
4230
4235
  };
4231
4236
  // Question: why isn't this working if the svgNode is created dynamically? (nodeStyle.sheet is null)
4232
4237
  const rules = [];
@@ -5006,27 +5011,65 @@ class drawutilssvg {
5006
5011
  if (!isOpen)
5007
5012
  d.push("Z");
5008
5013
  node.setAttribute("d", d.join(" "));
5009
- return this._bindFillDraw(node, "polyline", color, lineWidth || 1);
5014
+ return this._bindFillDraw(node, "polygon", color, lineWidth || 1);
5010
5015
  }
5011
5016
  /**
5012
- * Draw a text label at the given relative position.
5017
+ * Draw a text at the given relative position.
5013
5018
  *
5014
- * @method label
5019
+ * @method text
5015
5020
  * @param {string} text - The text to draw.
5016
5021
  * @param {number} x - The x-position to draw the text at.
5017
5022
  * @param {number} y - The y-position to draw the text at.
5018
- * @param {number=} rotation - The (optional) rotation in radians.
5023
+ * @param {string=} options.color - The Color to use.
5024
+ * @param {string=} options.fontFamily - The font family to use.
5025
+ * @param {number=} options.fontSize - The font size (in pixels) to use.
5026
+ * @param {FontStyle=} options.fontStyle - The font style to use.
5027
+ * @param {FontWeight=} options.fontWeight - The font weight to use.
5028
+ * @param {number=} options.lineHeight - The line height (in pixels) to use.
5029
+ * @param {number=} options.rotation - The (optional) rotation in radians.
5030
+ * @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"`.
5019
5031
  * @return {void}
5020
5032
  * @instance
5021
- * @memberof drawutilssvg
5033
+ * @memberof drawutils
5022
5034
  */
5023
5035
  text(text, x, y, options) {
5036
+ var _a, _b;
5024
5037
  options = options || {};
5025
5038
  const color = options.color || "black";
5026
- const node = this.makeNode("text");
5027
- node.setAttribute("x", `${this._x(x)}`);
5028
- node.setAttribute("y", `${this._y(y)}`);
5029
- node.innerHTML = text;
5039
+ const lineHeight = ((_b = (_a = options.lineHeight) !== null && _a !== void 0 ? _a : options.fontSize) !== null && _b !== void 0 ? _b : 0) * this.scale.x;
5040
+ // https://www.w3.org/TR/SVG/text.html#TextAnchorProperty
5041
+ // start | middle | end
5042
+ const textAlign = options.textAlign === "left" || options.textAlign === "start"
5043
+ ? "start"
5044
+ : options.textAlign === "center"
5045
+ ? "middle"
5046
+ : options.textAlign === "right" || options.textAlign === "end"
5047
+ ? "end"
5048
+ : "start";
5049
+ const transformOrigin = `${this._x(x)}px ${this._y(y)}px`;
5050
+ const translate = `translate(${this._x(x)} ${this._y(y) + lineHeight / 2})`;
5051
+ // Safari has a transform-origin/rotation bug.
5052
+ // It's essential to use rotate(r,x,y) here. "rotate(r)"" with transform-origin(x,y) won't do the job.
5053
+ // And rotate and translate cannot be used is combination on a text object.
5054
+ // So wrap the text inside a <g>, translate the <g>, and rotate the text inside.
5055
+ const rotate = options.rotation ? `rotate(${options.rotation * RAD_TO_DEG} 0 0)` : ``;
5056
+ const node = this.makeNode("g");
5057
+ const curId = this.curId;
5058
+ this.curId = curId + "_text";
5059
+ const textNode = this.makeNode("text");
5060
+ node.appendChild(textNode);
5061
+ textNode.setAttribute("font-family", options.fontFamily); // May be undefined
5062
+ textNode.setAttribute("font-size", options.fontSize ? `${options.fontSize * this.scale.x}` : null);
5063
+ textNode.setAttribute("font-style", options.fontStyle ? `${options.fontStyle}` : null);
5064
+ textNode.setAttribute("font-weight", options.fontWeight ? `${options.fontWeight}` : null);
5065
+ textNode.setAttribute("text-anchor", textAlign);
5066
+ textNode.setAttribute("transform-origin", "0 0");
5067
+ textNode.setAttribute("transform", rotate);
5068
+ node.setAttribute("transform-origin", transformOrigin);
5069
+ node.setAttribute("transform", translate);
5070
+ textNode.innerHTML = text;
5071
+ // Restore old ID
5072
+ this.curId = curId;
5030
5073
  return this._bindFillDraw(node, "text", color, 1);
5031
5074
  }
5032
5075
  /**
@@ -5037,16 +5080,21 @@ class drawutilssvg {
5037
5080
  * @param {number} x - The x-position to draw the text at.
5038
5081
  * @param {number} y - The y-position to draw the text at.
5039
5082
  * @param {number=} rotation - The (optional) rotation in radians.
5083
+ * @param {string="black"} color - The color to use (default is black).
5040
5084
  * @return {void}
5041
5085
  * @instance
5042
5086
  * @memberof drawutilssvg
5043
5087
  */
5044
- label(text, x, y, rotation) {
5088
+ label(text, x, y, rotation, color) {
5045
5089
  const node = this.makeNode("text");
5046
5090
  // For some strange reason SVG rotation transforms use degrees instead of radians
5047
- node.setAttribute("transform", `translate(${this.offset.x},${this.offset.y}), rotate(${(rotation / Math.PI) * 180})`);
5091
+ node.setAttribute("transform", `translate(${x},${y}), rotate(${((rotation || 0) / Math.PI) * 180})`);
5092
+ node.setAttribute("font-family", "Arial");
5093
+ node.setAttribute("font-size", "9pt");
5094
+ node.setAttribute("font-style", "normal");
5095
+ node.setAttribute("font-weight", "lighter");
5048
5096
  node.innerHTML = text;
5049
- return this._bindFillDraw(node, "label", "black", null);
5097
+ return this._bindFillDraw(node, "label", color || "black", null);
5050
5098
  }
5051
5099
  /**
5052
5100
  * Draw an SVG-like path given by the specified path data.
@@ -5355,7 +5403,9 @@ drawutilssvg.HEAD_XML = [
5355
5403
  * @modified 2021-02-22 Added the `path` drawing function to draw SVG path data.
5356
5404
  * @modified 2021-03-31 Added the `endDrawCycle` function from `DrawLib`.
5357
5405
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
5358
- * @version 1.9.0
5406
+ * @modified 2021-11-12 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
5407
+ * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
5408
+ * @version 1.10.0
5359
5409
  **/
5360
5410
  // Todo: rename this class to Drawutils?
5361
5411
  /**
@@ -6010,20 +6060,62 @@ class drawutils {
6010
6060
  this.ctx.setLineDash([]);
6011
6061
  this.ctx.restore();
6012
6062
  }
6063
+ /**
6064
+ * Draw a text at the given relative position.
6065
+ *
6066
+ * @method text
6067
+ * @param {string} text - The text to draw.
6068
+ * @param {number} x - The x-position to draw the text at.
6069
+ * @param {number} y - The y-position to draw the text at.
6070
+ * @param {string=} options.color - The Color to use.
6071
+ * @param {string=} options.fontFamily - The font family to use.
6072
+ * @param {number=} options.fontSize - The font size (in pixels) to use.
6073
+ * @param {FontStyle=} options.fontStyle - The font style to use.
6074
+ * @param {FontWeight=} options.fontWeight - The font weight to use.
6075
+ * @param {number=} options.lineHeight - The line height (in pixels) to use.
6076
+ * @param {number=} options.rotation - The (optional) rotation in radians.
6077
+ * @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"`.
6078
+ * @return {void}
6079
+ * @instance
6080
+ * @memberof drawutils
6081
+ */
6013
6082
  text(text, x, y, options) {
6083
+ // See https://stackoverflow.com/a/23523697
6084
+ var _a, _b, _c;
6014
6085
  options = options || {};
6015
6086
  this.ctx.save();
6016
- x = this.offset.x + x * this.scale.x;
6017
- y = this.offset.y + y * this.scale.y;
6087
+ let relX = this.offset.x + x * this.scale.x;
6088
+ let relY = this.offset.y + y * this.scale.y;
6018
6089
  const color = options.color || "black";
6090
+ if (options.fontSize || options.fontFamily) {
6091
+ // Scaling of text only works in uniform mode
6092
+ this.ctx.font =
6093
+ (options.fontWeight ? options.fontWeight + " " : "") +
6094
+ (options.fontStyle ? options.fontStyle + " " : "") +
6095
+ (options.fontSize ? options.fontSize * this.scale.x + "px " : " ") +
6096
+ (options.fontFamily
6097
+ ? options.fontFamily.indexOf(" ") === -1
6098
+ ? options.fontFamily
6099
+ : `"${options.fontFamily}"`
6100
+ : "Arial");
6101
+ }
6102
+ if (options.textAlign) {
6103
+ this.ctx.textAlign = options.textAlign;
6104
+ }
6105
+ const rotation = (_a = options.rotation) !== null && _a !== void 0 ? _a : 0.0;
6106
+ const lineHeight = ((_c = (_b = options.lineHeight) !== null && _b !== void 0 ? _b : options.fontSize) !== null && _c !== void 0 ? _c : 0) * this.scale.x;
6107
+ this.ctx.translate(relX, relY);
6108
+ this.ctx.rotate(rotation);
6019
6109
  if (this.fillShapes) {
6020
6110
  this.ctx.fillStyle = color;
6021
- this.ctx.fillText(text, x, y);
6111
+ this.ctx.fillText(text, 0, lineHeight / 2);
6022
6112
  }
6023
6113
  else {
6024
6114
  this.ctx.strokeStyle = color;
6025
- this.ctx.strokeText(text, x, y);
6115
+ this.ctx.strokeText(text, 0, lineHeight / 2);
6026
6116
  }
6117
+ // this.ctx.translate(-relX, -relY);
6118
+ // this.ctx.rotate(-rotation); // is this necessary before 'restore()'?
6027
6119
  this.ctx.restore();
6028
6120
  }
6029
6121
  /**
@@ -6043,8 +6135,9 @@ class drawutils {
6043
6135
  */
6044
6136
  label(text, x, y, rotation, color) {
6045
6137
  this.ctx.save();
6138
+ this.ctx.font = "lighter 9pt Arial";
6046
6139
  this.ctx.translate(x, y);
6047
- if (typeof rotation != "undefined")
6140
+ if (typeof rotation !== "undefined")
6048
6141
  this.ctx.rotate(rotation);
6049
6142
  this.ctx.fillStyle = color || "black";
6050
6143
  if (this.fillShapes) {
@@ -6653,6 +6746,25 @@ class drawutilsgl {
6653
6746
  polyline(vertices, isOpen, color, lineWidth) {
6654
6747
  // NOT YET IMPLEMENTED
6655
6748
  }
6749
+ /**
6750
+ * Draw a text at the given relative position.
6751
+ *
6752
+ * @method text
6753
+ * @param {string} text - The text to draw.
6754
+ * @param {number} x - The x-position to draw the text at.
6755
+ * @param {number} y - The y-position to draw the text at.
6756
+ * @param {string=} options.color - The Color to use.
6757
+ * @param {string=} options.fontFamily - The font family to use.
6758
+ * @param {number=} options.fontSize - The font size (in pixels) to use.
6759
+ * @param {FontStyle=} options.fontStyle - The font style to use.
6760
+ * @param {FontWeight=} options.fontWeight - The font weight to use.
6761
+ * @param {number=} options.lineHeight - The line height (in pixels) to use.
6762
+ * @param {number=} options.rotation - The (optional) rotation in radians.
6763
+ * @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"`.
6764
+ * @return {void}
6765
+ * @instance
6766
+ * @memberof drawutils
6767
+ */
6656
6768
  text(text, x, y, options) {
6657
6769
  // NOT YET IMPLEMENTED
6658
6770
  }
@@ -6664,14 +6776,12 @@ class drawutilsgl {
6664
6776
  * @param {number} x - The x-position to draw the text at.
6665
6777
  * @param {number} y - The y-position to draw the text at.
6666
6778
  * @param {number=} rotation - The (aoptional) rotation in radians.
6779
+ * @param {string="black"} color - The color to use (default is black).
6667
6780
  * @return {void}
6668
6781
  * @instance
6669
6782
  * @memberof drawutils
6670
6783
  */
6671
- // +---------------------------------------------------------------------------------
6672
- // | Draw a non-scaling text label at the given position.
6673
- // +-------------------------------
6674
- label(text, x, y, rotation) {
6784
+ label(text, x, y, rotation, color) {
6675
6785
  // NOT YET IMPLEMENTED
6676
6786
  }
6677
6787
  /**
@@ -8265,6 +8375,65 @@ class PBImage {
8265
8375
  ;
8266
8376
  }
8267
8377
 
8378
+ /**
8379
+ * @author Ikaros Kappler
8380
+ * @date 2021-11-16
8381
+ * @version 1.0.0
8382
+ **/
8383
+ /**
8384
+ * @classdesc A simple text element: position, fontSize, fontFamily, color, textAlign, lineHeight and rotation.
8385
+ *
8386
+ * @requires FontOptions
8387
+ * @requires FontSize
8388
+ * @requires FontStyle
8389
+ * @requires FontWeight
8390
+ * @requires Vertex
8391
+ * @requires SVGSerializale
8392
+ * @requires UID
8393
+ * @requires UIDGenerator
8394
+ **/
8395
+ class PBText {
8396
+ /**
8397
+ * Create a new circle with given center point and radius.
8398
+ *
8399
+ * @constructor
8400
+ * @name Circle
8401
+ * @param {Vertex} center - The center point of the circle.
8402
+ * @param {number} radius - The radius of the circle.
8403
+ */
8404
+ constructor(text, anchor, options) {
8405
+ /**
8406
+ * Required to generate proper CSS classes and other class related IDs.
8407
+ **/
8408
+ this.className = "PBText";
8409
+ this.uid = UIDGenerator.next();
8410
+ this.text = text;
8411
+ this.anchor = anchor !== null && anchor !== void 0 ? anchor : new Vertex();
8412
+ this.color = options.color;
8413
+ this.fontFamily = options.fontFamily;
8414
+ this.fontSize = options.fontSize;
8415
+ this.fontStyle = options.fontStyle;
8416
+ this.fontWeight = options.fontWeight;
8417
+ this.lineHeight = options.lineHeight;
8418
+ this.textAlign = options.textAlign;
8419
+ this.rotation = options.rotation;
8420
+ }
8421
+ /**
8422
+ * Create an SVG representation of this circle.
8423
+ *
8424
+ * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
8425
+ * @method toSVGString
8426
+ * @param {object=} options - An optional set of options, like 'className'.
8427
+ * @return {string} A string representing the SVG code for this vertex.
8428
+ * @instance
8429
+ * @memberof Circle
8430
+ */
8431
+ toSVGString(options) {
8432
+ console.warn("[PBText.toSVGString()] This function is not implemented as it defines a deprecated method. Use the 'drawutilssvg.text()' method instead.");
8433
+ return "";
8434
+ }
8435
+ } // END class
8436
+
8268
8437
  /* Port from AlloyFinger v0.1.15
8269
8438
  * Original by dntzhang
8270
8439
  * Typescript port by Ikaros Kappler
@@ -9394,7 +9563,8 @@ VEllipseSector.ellipseSectorUtils = {
9394
9563
  * @modified 2021-03-03 Added the `VEllipseSector` drawable.
9395
9564
  * @modified 2021-03-29 Clearing `currentClassName` and `currentId` after drawing each drawable.
9396
9565
  * @modified 2021-04-25 Extending `remove` to accept arrays of drawables.
9397
- * @version 1.14.0
9566
+ * @modified 2021-11-16 Adding the `PBText` drawable.
9567
+ * @version 1.15.0
9398
9568
  *
9399
9569
  * @file PlotBoilerplate
9400
9570
  * @fileoverview The main class.
@@ -9639,6 +9809,12 @@ class PlotBoilerplate {
9639
9809
  image: {
9640
9810
  color: "#a8a8a8",
9641
9811
  lineWidth: 1
9812
+ },
9813
+ text: {
9814
+ color: "rgba(192,0,128,0.5)",
9815
+ lineWidth: 1,
9816
+ fill: true,
9817
+ anchor: true
9642
9818
  }
9643
9819
  }; // END drawConfig
9644
9820
  // +---------------------------------------------------------------------------------
@@ -9946,6 +10122,11 @@ class PlotBoilerplate {
9946
10122
  });
9947
10123
  drawable.lowerRight.attr.selectable = false;
9948
10124
  }
10125
+ else if (drawable instanceof PBText) {
10126
+ this.vertices.push(drawable.anchor);
10127
+ this.drawables.push(drawable);
10128
+ drawable.anchor.attr.selectable = false;
10129
+ }
9949
10130
  else {
9950
10131
  throw "Cannot add drawable of unrecognized type: " + typeof drawable + ".";
9951
10132
  }
@@ -10044,6 +10225,9 @@ class PlotBoilerplate {
10044
10225
  this.removeVertex(drawable.upperLeft, false);
10045
10226
  this.removeVertex(drawable.lowerRight, false);
10046
10227
  }
10228
+ else if (drawable instanceof PBText) {
10229
+ this.removeVertex(drawable.anchor, false);
10230
+ }
10047
10231
  } // END removeWithVertices
10048
10232
  if (redraw) {
10049
10233
  this.redraw();
@@ -10369,6 +10553,16 @@ class PlotBoilerplate {
10369
10553
  d.lowerRight.attr.renderTime = renderTime;
10370
10554
  }
10371
10555
  }
10556
+ else if (d instanceof PBText) {
10557
+ fill.setCurrentId(d.uid);
10558
+ fill.text(d.text, d.anchor.x, d.anchor.y, d);
10559
+ if (this.drawConfig.text.anchor) {
10560
+ draw.setCurrentId(`${d.uid}_a0`);
10561
+ draw.setCurrentClassName(`${d.className}-anchor`);
10562
+ (this.drawConfig.text.fill ? fill : draw).point(d.anchor, this.drawConfig.text.color);
10563
+ }
10564
+ d.anchor.attr.renderTime = renderTime;
10565
+ }
10372
10566
  else {
10373
10567
  console.error("Cannot draw object. Unknown class.");
10374
10568
  }
@@ -11453,5 +11647,5 @@ class SVGBuilder {
11453
11647
  ;
11454
11648
  }
11455
11649
 
11456
- export { BezierPath, Bounds, Circle, CircleSector, CubicBezierCurve, Grid, KeyHandler, Line, MouseHandler, PBImage, PlotBoilerplate, Polygon, SVGBuilder, Triangle, UIDGenerator, VEllipse, VEllipseSector, Vector, VertTuple, Vertex, VertexAttr, VertexListeners, XMouseEvent, XWheelEvent, drawutils, drawutilsgl, drawutilssvg, geomutils };
11650
+ export { BezierPath, Bounds, Circle, CircleSector, CubicBezierCurve, Grid, KeyHandler, Line, MouseHandler, PBImage, PBText, PlotBoilerplate, Polygon, SVGBuilder, Triangle, UIDGenerator, VEllipse, VEllipseSector, Vector, VertTuple, Vertex, VertexAttr, VertexListeners, XMouseEvent, XWheelEvent, drawutils, drawutilsgl, drawutilssvg, geomutils };
11457
11651
  //# sourceMappingURL=index.esm.js.map