plotboilerplate 1.20.2 → 1.22.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 (169) hide show
  1. package/dist/index.esm.js +2012 -1366
  2. package/dist/index.esm.js.map +1 -1
  3. package/dist/index.esm.min.js +1 -1
  4. package/dist/index.esm.min.js.map +1 -1
  5. package/dist/plotboilerplate.browser.min.js +1 -1
  6. package/dist/plotboilerplate.browser.min.js.map +1 -1
  7. package/dist/plotboilerplate.js +1199 -541
  8. package/dist/plotboilerplate.min.js +1 -1
  9. package/package.json +3 -2
  10. package/src/cjs/BezierPath.d.ts +27 -49
  11. package/src/cjs/BezierPath.js +67 -234
  12. package/src/cjs/BezierPath.js.map +1 -1
  13. package/src/cjs/Bounds.d.ts +14 -1
  14. package/src/cjs/Bounds.js +21 -1
  15. package/src/cjs/Bounds.js.map +1 -1
  16. package/src/cjs/CubicBezierCurve.d.ts +70 -1
  17. package/src/cjs/CubicBezierCurve.js +130 -12
  18. package/src/cjs/CubicBezierCurve.js.map +1 -1
  19. package/src/cjs/Line.d.ts +2 -1
  20. package/src/cjs/Line.js +1 -0
  21. package/src/cjs/Line.js.map +1 -1
  22. package/src/cjs/PBText.d.ts +2 -1
  23. package/src/cjs/PBText.js +10 -9
  24. package/src/cjs/PBText.js.map +1 -1
  25. package/src/cjs/PlotBoilerplate.d.ts +4 -13
  26. package/src/cjs/PlotBoilerplate.js +61 -15
  27. package/src/cjs/PlotBoilerplate.js.map +1 -1
  28. package/src/cjs/Polygon.d.ts +47 -1
  29. package/src/cjs/Polygon.js +116 -1
  30. package/src/cjs/Polygon.js.map +1 -1
  31. package/src/cjs/VEllipse.js +1 -1
  32. package/src/cjs/VEllipse.js.map +1 -1
  33. package/src/cjs/Vector.d.ts +4 -4
  34. package/src/cjs/Vector.js +2 -2
  35. package/src/cjs/Vector.js.map +1 -1
  36. package/src/cjs/VertTuple.d.ts +2 -1
  37. package/src/cjs/VertTuple.js +4 -3
  38. package/src/cjs/VertTuple.js.map +1 -1
  39. package/src/cjs/Vertex.d.ts +14 -3
  40. package/src/cjs/Vertex.js +18 -3
  41. package/src/cjs/Vertex.js.map +1 -1
  42. package/src/cjs/draw.d.ts +154 -75
  43. package/src/cjs/draw.js +308 -137
  44. package/src/cjs/draw.js.map +1 -1
  45. package/src/cjs/drawgl.d.ts +87 -50
  46. package/src/cjs/drawgl.js +86 -31
  47. package/src/cjs/drawgl.js.map +1 -1
  48. package/src/cjs/drawutilssvg.d.ts +226 -53
  49. package/src/cjs/drawutilssvg.js +374 -92
  50. package/src/cjs/drawutilssvg.js.map +1 -1
  51. package/src/cjs/interfaces/DrawLib.d.ts +157 -79
  52. package/src/cjs/interfaces/DrawLib.js +6 -0
  53. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  54. package/src/cjs/interfaces/core.d.ts +13 -2
  55. package/src/cjs/interfaces/core.js +1 -0
  56. package/src/cjs/interfaces/core.js.map +1 -1
  57. package/src/cjs/utils/Params.d.ts +15 -0
  58. package/src/cjs/utils/Params.js +49 -0
  59. package/src/cjs/utils/Params.js.map +1 -0
  60. package/src/cjs/utils/algorithms/ContourLineDetection.d.ts +150 -0
  61. package/src/cjs/utils/algorithms/ContourLineDetection.js +367 -0
  62. package/src/cjs/utils/algorithms/ContourLineDetection.js.map +1 -0
  63. package/src/cjs/utils/algorithms/clearDuplicateVertices.d.ts +21 -0
  64. package/src/cjs/utils/algorithms/clearDuplicateVertices.js +48 -0
  65. package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -0
  66. package/src/cjs/utils/creategui.js +16 -10
  67. package/src/cjs/utils/datastructures/DataGrid2d.d.ts +47 -0
  68. package/src/cjs/utils/datastructures/DataGrid2d.js +20 -0
  69. package/src/cjs/utils/datastructures/DataGrid2d.js.map +1 -0
  70. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.d.ts +65 -0
  71. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js +84 -0
  72. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js.map +1 -0
  73. package/src/cjs/utils/datastructures/GenericPath.d.ts +14 -3
  74. package/src/cjs/utils/datastructures/GenericPath.js +20 -3
  75. package/src/cjs/utils/datastructures/GenericPath.js.map +1 -1
  76. package/src/cjs/utils/detectDarkMode.d.ts +10 -0
  77. package/src/cjs/utils/detectDarkMode.js +32 -0
  78. package/src/cjs/utils/detectDarkMode.js.map +1 -0
  79. package/src/esm/BezierPath.d.ts +27 -49
  80. package/src/esm/BezierPath.js +67 -234
  81. package/src/esm/BezierPath.js.map +1 -1
  82. package/src/esm/Bounds.d.ts +14 -1
  83. package/src/esm/Bounds.js +19 -1
  84. package/src/esm/Bounds.js.map +1 -1
  85. package/src/esm/CubicBezierCurve.d.ts +70 -1
  86. package/src/esm/CubicBezierCurve.js +130 -12
  87. package/src/esm/CubicBezierCurve.js.map +1 -1
  88. package/src/esm/Line.d.ts +2 -1
  89. package/src/esm/Line.js +1 -0
  90. package/src/esm/Line.js.map +1 -1
  91. package/src/esm/PBText.d.ts +2 -1
  92. package/src/esm/PBText.js +10 -9
  93. package/src/esm/PBText.js.map +1 -1
  94. package/src/esm/PlotBoilerplate.d.ts +4 -13
  95. package/src/esm/PlotBoilerplate.js +62 -16
  96. package/src/esm/PlotBoilerplate.js.map +1 -1
  97. package/src/esm/Polygon.d.ts +47 -1
  98. package/src/esm/Polygon.js +114 -1
  99. package/src/esm/Polygon.js.map +1 -1
  100. package/src/esm/VEllipse.js +1 -1
  101. package/src/esm/VEllipse.js.map +1 -1
  102. package/src/esm/Vector.d.ts +4 -4
  103. package/src/esm/Vector.js +2 -2
  104. package/src/esm/Vector.js.map +1 -1
  105. package/src/esm/VertTuple.d.ts +2 -1
  106. package/src/esm/VertTuple.js +4 -3
  107. package/src/esm/VertTuple.js.map +1 -1
  108. package/src/esm/Vertex.d.ts +14 -3
  109. package/src/esm/Vertex.js +18 -3
  110. package/src/esm/Vertex.js.map +1 -1
  111. package/src/esm/draw.d.ts +154 -75
  112. package/src/esm/draw.js +304 -135
  113. package/src/esm/draw.js.map +1 -1
  114. package/src/esm/drawgl.d.ts +87 -50
  115. package/src/esm/drawgl.js +86 -31
  116. package/src/esm/drawgl.js.map +1 -1
  117. package/src/esm/drawutilssvg.d.ts +226 -53
  118. package/src/esm/drawutilssvg.js +369 -92
  119. package/src/esm/drawutilssvg.js.map +1 -1
  120. package/src/esm/interfaces/DrawLib.d.ts +157 -79
  121. package/src/esm/interfaces/DrawLib.js +6 -0
  122. package/src/esm/interfaces/DrawLib.js.map +1 -1
  123. package/src/esm/interfaces/core.d.ts +13 -2
  124. package/src/esm/interfaces/core.js +1 -0
  125. package/src/esm/interfaces/core.js.map +1 -1
  126. package/src/esm/utils/Params.d.ts +15 -0
  127. package/src/esm/utils/Params.js +44 -0
  128. package/src/esm/utils/Params.js.map +1 -0
  129. package/src/esm/utils/algorithms/ContourLineDetection.d.ts +150 -0
  130. package/src/esm/utils/algorithms/ContourLineDetection.js +362 -0
  131. package/src/esm/utils/algorithms/ContourLineDetection.js.map +1 -0
  132. package/src/esm/utils/algorithms/clearDuplicateVertices.d.ts +21 -0
  133. package/src/esm/utils/algorithms/clearDuplicateVertices.js +44 -0
  134. package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -0
  135. package/src/esm/utils/datastructures/DataGrid2d.d.ts +47 -0
  136. package/src/esm/utils/datastructures/DataGrid2d.js +19 -0
  137. package/src/esm/utils/datastructures/DataGrid2d.js.map +1 -0
  138. package/src/esm/utils/datastructures/DataGrid2dListAdapter.d.ts +65 -0
  139. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js +79 -0
  140. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js.map +1 -0
  141. package/src/esm/utils/datastructures/GenericPath.d.ts +14 -3
  142. package/src/esm/utils/datastructures/GenericPath.js +20 -3
  143. package/src/esm/utils/datastructures/GenericPath.js.map +1 -1
  144. package/src/esm/utils/detectDarkMode.d.ts +10 -0
  145. package/src/esm/utils/detectDarkMode.js +28 -0
  146. package/src/esm/utils/detectDarkMode.js.map +1 -0
  147. package/src/ts/BezierPath.ts +72 -241
  148. package/src/ts/Bounds.ts +25 -1
  149. package/src/ts/CubicBezierCurve.ts +139 -12
  150. package/src/ts/Line.ts +2 -1
  151. package/src/ts/PBText.ts +10 -9
  152. package/src/ts/PlotBoilerplate.ts +56 -19
  153. package/src/ts/Polygon.ts +121 -1
  154. package/src/ts/VEllipse.ts +2 -2
  155. package/src/ts/Vector.ts +4 -4
  156. package/src/ts/VertTuple.ts +4 -3
  157. package/src/ts/Vertex.ts +20 -4
  158. package/src/ts/draw.ts +311 -115
  159. package/src/ts/drawgl.ts +133 -71
  160. package/src/ts/drawutilssvg.ts +543 -121
  161. package/src/ts/interfaces/DrawLib.ts +219 -83
  162. package/src/ts/interfaces/core.ts +14 -2
  163. package/src/ts/utils/Params.ts +47 -0
  164. package/src/ts/utils/algorithms/ContourLineDetection.ts +485 -0
  165. package/src/ts/utils/algorithms/clearDuplicateVertices.ts +49 -0
  166. package/src/ts/utils/datastructures/DataGrid2d.ts +54 -0
  167. package/src/ts/utils/datastructures/DataGrid2dListAdapter.ts +121 -0
  168. package/src/ts/utils/datastructures/GenericPath.ts +21 -3
  169. package/src/ts/utils/detectDarkMode.ts +30 -0
package/src/cjs/draw.js CHANGED
@@ -49,13 +49,22 @@
49
49
  * @modified 2022-08-23 Fixed a type issue in the `setConfiguration` function.
50
50
  * @modified 2022-08-23 Fixed a type issue in the `path` function.
51
51
  * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
52
- * @version 1.12.4
52
+ * @modified 2023-09-29 Removed unused method stub for texturedPoly helper function (cleanup).
53
+ * @modified 2023-09-29 Downgrading all `Vertex` param type to the more generic `XYCoords` type in these render functions: line, arrow, texturedPoly, cubicBezier, cubicBezierPath, handle, handleLine, dot, point, circle, circleArc, ellipse, grid, raster.
54
+ * @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
55
+ * @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
56
+ * @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
57
+ * @modified 2023-09-29 Added the `lineDashes` attribute.
58
+ * @modified 2023-09-30 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
59
+ * @modified 2023-10-07 Adding the optional `arrowHeadBasePositionBuffer` param to the arrowHead(...) method.
60
+ * @version 1.13.0
53
61
  **/
54
62
  Object.defineProperty(exports, "__esModule", { value: true });
55
63
  exports.drawutils = void 0;
56
64
  var CubicBezierCurve_1 = require("./CubicBezierCurve");
57
65
  var Vertex_1 = require("./Vertex");
58
66
  var drawutilssvg_1 = require("./drawutilssvg");
67
+ var Vector_1 = require("./Vector");
59
68
  // Todo: rename this class to Drawutils?
60
69
  /**
61
70
  * @classdesc A wrapper class for basic drawing operations.
@@ -76,10 +85,48 @@ var drawutils = /** @class */ (function () {
76
85
  **/
77
86
  function drawutils(context, fillShapes) {
78
87
  this.ctx = context;
88
+ // this.lineDash = [];
79
89
  this.offset = new Vertex_1.Vertex(0, 0);
80
90
  this.scale = new Vertex_1.Vertex(1, 1);
81
91
  this.fillShapes = fillShapes;
82
92
  }
93
+ /**
94
+ * A private helper method to apply stroke options to the current
95
+ * context.
96
+ * @param {StrokeOptions=} strokeOptions -
97
+ */
98
+ drawutils.prototype.applyStrokeOpts = function (strokeOptions) {
99
+ var _this = this;
100
+ var _a, _b;
101
+ this.ctx.setLineDash(((_a = strokeOptions === null || strokeOptions === void 0 ? void 0 : strokeOptions.dashArray) !== null && _a !== void 0 ? _a : []).map(function (dashArrayElem) {
102
+ // Note assume scale.x === scale.y
103
+ // Invariant scale makes funny stuff anyway.
104
+ return dashArrayElem * _this.scale.x;
105
+ }));
106
+ this.ctx.lineDashOffset = ((_b = strokeOptions === null || strokeOptions === void 0 ? void 0 : strokeOptions.dashOffset) !== null && _b !== void 0 ? _b : 0) * this.scale.x;
107
+ };
108
+ // +---------------------------------------------------------------------------------
109
+ // | This is the final helper function for drawing and filling stuff. It is not
110
+ // | intended to be used from the outside.
111
+ // |
112
+ // | When in draw mode it draws the current shape.
113
+ // | When in fill mode it fills the current shape.
114
+ // |
115
+ // | This function is usually only called internally.
116
+ // |
117
+ // | @param color A stroke/fill color to use.
118
+ // +-------------------------------
119
+ // TODO: convert this to a STATIC function.
120
+ drawutils.prototype._fillOrDraw = function (color) {
121
+ if (this.fillShapes) {
122
+ this.ctx.fillStyle = color;
123
+ this.ctx.fill();
124
+ }
125
+ else {
126
+ this.ctx.strokeStyle = color;
127
+ this.ctx.stroke();
128
+ }
129
+ };
83
130
  /**
84
131
  * Called before each draw cycle.
85
132
  * @param {UID=} uid - (optional) A UID identifying the currently drawn element(s).
@@ -110,6 +157,20 @@ var drawutils = /** @class */ (function () {
110
157
  drawutils.prototype.setConfiguration = function (configuration) {
111
158
  this.ctx.globalCompositeOperation = configuration.blendMode || "source-over";
112
159
  };
160
+ // /**
161
+ // * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
162
+ // *
163
+ // * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
164
+ // * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
165
+ // * for how line dashes work.
166
+ // *
167
+ // * @method
168
+ // * @param {Array<number> lineDashes - The line-dash array configuration.
169
+ // * @returns {void}
170
+ // */
171
+ // setLineDash(lineDash: Array<number>) {
172
+ // this.lineDash = lineDash;
173
+ // }
113
174
  /**
114
175
  * This method shouled be called each time the currently drawn `Drawable` changes.
115
176
  * It is used by some libraries for identifying elemente on re-renders.
@@ -136,17 +197,20 @@ var drawutils = /** @class */ (function () {
136
197
  * Draw the line between the given two points with the specified (CSS-) color.
137
198
  *
138
199
  * @method line
139
- * @param {Vertex} zA - The start point of the line.
140
- * @param {Vertex} zB - The end point of the line.
200
+ * @param {XYCoords} zA - The start point of the line.
201
+ * @param {XYCoords} zB - The end point of the line.
141
202
  * @param {string} color - Any valid CSS color string.
142
203
  * @param {number} lineWidth? - [optional] The line's width.
204
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
205
+ *
143
206
  * @return {void}
144
207
  * @instance
145
208
  * @memberof drawutils
146
209
  **/
147
- drawutils.prototype.line = function (zA, zB, color, lineWidth) {
210
+ drawutils.prototype.line = function (zA, zB, color, lineWidth, strokeOptions) {
148
211
  this.ctx.save();
149
212
  this.ctx.beginPath();
213
+ this.applyStrokeOpts(strokeOptions);
150
214
  this.ctx.moveTo(this.offset.x + zA.x * this.scale.x, this.offset.y + zA.y * this.scale.y);
151
215
  this.ctx.lineTo(this.offset.x + zB.x * this.scale.x, this.offset.y + zB.y * this.scale.y);
152
216
  this.ctx.strokeStyle = color;
@@ -158,22 +222,76 @@ var drawutils = /** @class */ (function () {
158
222
  * Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
159
223
  *
160
224
  * @method arrow
161
- * @param {Vertex} zA - The start point of the arrow-line.
162
- * @param {Vertex} zB - The end point of the arrow-line.
225
+ * @param {XYCoords} zA - The start point of the arrow-line.
226
+ * @param {XYCoords} zB - The end point of the arrow-line.
163
227
  * @param {string} color - Any valid CSS color string.
164
228
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
229
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
230
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
231
+ *
165
232
  * @return {void}
166
233
  * @instance
167
234
  * @memberof drawutils
168
235
  **/
169
- drawutils.prototype.arrow = function (zA, zB, color, lineWidth) {
170
- var headlen = 8; // length of head in pixels
171
- // var vertices = PlotBoilerplate.utils.buildArrowHead( zA, zB, headlen, this.scale.x, this.scale.y );
172
- // var vertices : Array<Vertex> = Vertex.utils.buildArrowHead( zA, zB, headlen, this.scale.x, this.scale.y );
236
+ drawutils.prototype.arrow = function (zA, zB, color, lineWidth, headLength, strokeOptions) {
237
+ if (headLength === void 0) { headLength = 8; }
238
+ var arrowHeadBasePosition = new Vertex_1.Vertex(0, 0);
239
+ this.arrowHead(zA, zB, color, lineWidth, headLength, undefined, arrowHeadBasePosition); // Will NOT use dash configuration
240
+ this.line(zA, arrowHeadBasePosition, color, lineWidth, strokeOptions); // Will use dash configuration
241
+ };
242
+ /**
243
+ * Draw a cubic Bézier curve and and an arrow at the end (endControlPoint) of the given line width the specified (CSS-) color and arrow size.
244
+ *
245
+ * @method cubicBezierArrow
246
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
247
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
248
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
249
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
250
+ * @param {string} color - The CSS color to draw the curve with.
251
+ * @param {number} lineWidth - (optional) The line width to use.
252
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
253
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
254
+ *
255
+ * @return {void}
256
+ * @instance
257
+ * @memberof DrawLib
258
+ */
259
+ drawutils.prototype.cubicBezierArrow = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, headLength, strokeOptions) {
260
+ var arrowHeadBasePosition = new Vertex_1.Vertex(0, 0);
261
+ // Will NOT use dash configuration
262
+ this.arrowHead(endControlPoint, endPoint, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
263
+ var diff = arrowHeadBasePosition.difference(endPoint);
264
+ // Will use dash configuration
265
+ this.cubicBezier(startPoint, { x: endPoint.x - diff.x, y: endPoint.y - diff.y }, startControlPoint, { x: endControlPoint.x - diff.x, y: endControlPoint.y - diff.y }, color, lineWidth, strokeOptions);
266
+ };
267
+ /**
268
+ * Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
269
+ *
270
+ * @method arrow
271
+ * @param {XYCoords} zA - The start point of the arrow-line.
272
+ * @param {XYCoords} zB - The end point of the arrow-line.
273
+ * @param {string} color - Any valid CSS color string.
274
+ * @param {number=1} lineWidth - (optional) The line width to use; default is 1.
275
+ * @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
276
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
277
+ * @param {XYCoords=} arrowHeadBasePositionBuffer - (optional) If not null, then this position will contain the arrow head's start point (after execution). Some sort of OUT variable.
278
+ *
279
+ * @return {void}
280
+ * @instance
281
+ * @memberof DrawLib
282
+ **/
283
+ drawutils.prototype.arrowHead = function (zA, zB, color, lineWidth, headLength, strokeOptions, arrowHeadBasePositionBuffer) {
284
+ // var headLength: number = 8; // length of head in pixels
285
+ if (headLength === void 0) { headLength = 8; }
173
286
  this.ctx.save();
174
287
  this.ctx.beginPath();
175
- var vertices = Vertex_1.Vertex.utils.buildArrowHead(zA, zB, headlen, this.scale.x, this.scale.y);
176
- this.ctx.moveTo(this.offset.x + zA.x * this.scale.x, this.offset.y + zA.y * this.scale.y);
288
+ this.applyStrokeOpts(strokeOptions);
289
+ var vertices = Vector_1.Vector.utils.buildArrowHead(zA, zB, headLength, this.scale.x, this.scale.y);
290
+ if (arrowHeadBasePositionBuffer) {
291
+ arrowHeadBasePositionBuffer.x = vertices[0].x / this.scale.x;
292
+ arrowHeadBasePositionBuffer.y = vertices[0].y / this.scale.y;
293
+ }
294
+ this.ctx.moveTo(this.offset.x + vertices[0].x, this.offset.y + vertices[0].y);
177
295
  for (var i = 0; i < vertices.length; i++) {
178
296
  this.ctx.lineTo(this.offset.x + vertices[i].x, this.offset.y + vertices[i].y);
179
297
  }
@@ -189,8 +307,8 @@ var drawutils = /** @class */ (function () {
189
307
  *
190
308
  * @method image
191
309
  * @param {Image} image - The image object to draw.
192
- * @param {Vertex} position - The position to draw the the upper left corner at.
193
- * @param {Vertex} size - The x/y-size to draw the image with.
310
+ * @param {XYCoords} position - The position to draw the the upper left corner at.
311
+ * @param {XYCoords} size - The x/y-size to draw the image with.
194
312
  * @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
195
313
  * @return {void}
196
314
  * @instance
@@ -220,7 +338,7 @@ var drawutils = /** @class */ (function () {
220
338
  * @param {Image} textureImage - The image object to draw.
221
339
  * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
222
340
  * @param {Polygon} polygon - The polygon to use as clip path.
223
- * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
341
+ * @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
224
342
  * @param {number} rotation - The rotation to use for the polygon (and for the texture).
225
343
  * @param {XYCoords={x:0,y:0}} rotationCenter - (optional) The rotational center; default is center of bounding box.
226
344
  * @return {void}
@@ -229,10 +347,9 @@ var drawutils = /** @class */ (function () {
229
347
  **/
230
348
  drawutils.prototype.texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation) {
231
349
  var basePolygonBounds = polygon.getBounds();
232
- var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
233
- // var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
234
- // var rotationalOffset = { x: 0, y: 0 };
235
- var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
350
+ // var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
351
+ var targetCenterDifference = new Vertex_1.Vertex(polygonPosition.x, polygonPosition.y).difference(basePolygonBounds.getCenter());
352
+ // var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
236
353
  // Get the position offset of the polygon
237
354
  var targetTextureSize = new Vertex_1.Vertex(textureSize.width, textureSize.height);
238
355
  // var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
@@ -255,53 +372,83 @@ var drawutils = /** @class */ (function () {
255
372
  );
256
373
  this.ctx.restore();
257
374
  };
258
- drawutils.prototype._texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation, rotationCenter) {
259
- if (rotationCenter === void 0) { rotationCenter = { x: 0, y: 0 }; }
260
- var basePolygonBounds = polygon.getBounds();
261
- var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
262
- var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
263
- // var rotationalOffset = { x: 0, y: 0 };
264
- var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
265
- // Get the position offset of the polygon
266
- var targetTextureSize = new Vertex_1.Vertex(textureSize.width, textureSize.height);
267
- var targetTextureOffset = new Vertex_1.Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
268
- this.ctx.save();
269
- // this.ctx.translate(
270
- // this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
271
- // this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
272
- // );
273
- this.ctx.translate(this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x, this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y);
274
- this.ctx.rotate(rotation);
275
- drawutils.helpers.clipPoly(this.ctx, {
276
- x: (-targetCenterDifference.x * 1 - tileCenter.x - rotationalOffset.x) * this.scale.x,
277
- y: (-targetCenterDifference.y * 1 - tileCenter.y - rotationalOffset.y) * this.scale.y
278
- }, this.scale, polygon.vertices);
279
- this.ctx.drawImage(textureImage, 0, 0, textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
375
+ /*
376
+ _texturedPoly(
377
+ textureImage: HTMLImageElement,
378
+ textureSize: Bounds,
379
+ polygon: Polygon,
380
+ polygonPosition: XYCoords,
381
+ rotation: number,
382
+ rotationCenter: XYCoords = { x: 0, y: 0 }
383
+ ): void {
384
+ var basePolygonBounds = polygon.getBounds();
385
+ var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
386
+ var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
387
+ // var rotationalOffset = { x: 0, y: 0 };
388
+ var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
389
+
390
+ // Get the position offset of the polygon
391
+ var targetTextureSize = new Vertex(textureSize.width, textureSize.height);
392
+ var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
393
+
394
+ this.ctx.save();
395
+
396
+ // this.ctx.translate(
397
+ // this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
398
+ // this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
399
+ // );
400
+ this.ctx.translate(
401
+ this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
402
+ this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
403
+ );
404
+ this.ctx.rotate(rotation);
405
+
406
+ drawutils.helpers.clipPoly(
407
+ this.ctx,
408
+ {
409
+ x: (-targetCenterDifference.x * 1 - tileCenter.x - rotationalOffset.x) * this.scale.x,
410
+ y: (-targetCenterDifference.y * 1 - tileCenter.y - rotationalOffset.y) * this.scale.y
411
+ },
412
+ this.scale,
413
+ polygon.vertices
414
+ );
415
+ this.ctx.drawImage(
416
+ textureImage,
417
+ 0,
418
+ 0,
419
+ textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
280
420
  textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
281
- (-polygonPosition.x + targetTextureOffset.x * 1 - rotationalOffset.x * 1) * this.scale.x, (-polygonPosition.y + targetTextureOffset.y * 1 - rotationalOffset.y * 1) * this.scale.y, targetTextureSize.x * this.scale.x, targetTextureSize.y * this.scale.y);
282
- // const scaledTextureSize = new Bounds(
283
- // new Vertex(
284
- // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x,
285
- // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y
286
- // ).scaleXY(this.scale, rotationCenter),
287
- // new Vertex(
288
- // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x + targetTextureSize.x,
289
- // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y + targetTextureSize.y
290
- // ).scaleXY(this.scale, rotationCenter)
291
- // );
292
- // this.ctx.drawImage(
293
- // textureImage,
294
- // 0,
295
- // 0,
296
- // textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
297
- // textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
298
- // scaledTextureSize.min.x,
299
- // scaledTextureSize.min.y,
300
- // scaledTextureSize.width,
301
- // scaledTextureSize.height
302
- // );
303
- this.ctx.restore();
304
- };
421
+ (-polygonPosition.x + targetTextureOffset.x * 1 - rotationalOffset.x * 1) * this.scale.x,
422
+ (-polygonPosition.y + targetTextureOffset.y * 1 - rotationalOffset.y * 1) * this.scale.y,
423
+ targetTextureSize.x * this.scale.x,
424
+ targetTextureSize.y * this.scale.y
425
+ );
426
+
427
+ // const scaledTextureSize = new Bounds(
428
+ // new Vertex(
429
+ // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x,
430
+ // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y
431
+ // ).scaleXY(this.scale, rotationCenter),
432
+ // new Vertex(
433
+ // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x + targetTextureSize.x,
434
+ // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y + targetTextureSize.y
435
+ // ).scaleXY(this.scale, rotationCenter)
436
+ // );
437
+ // this.ctx.drawImage(
438
+ // textureImage,
439
+ // 0,
440
+ // 0,
441
+ // textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
442
+ // textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
443
+ // scaledTextureSize.min.x,
444
+ // scaledTextureSize.min.y,
445
+ // scaledTextureSize.width,
446
+ // scaledTextureSize.height
447
+ // );
448
+
449
+ this.ctx.restore();
450
+ }
451
+ */
305
452
  /**
306
453
  * Draw a rectangle.
307
454
  *
@@ -310,10 +457,16 @@ var drawutils = /** @class */ (function () {
310
457
  * @param {number} height - The height of the rectangle.
311
458
  * @param {string} color - The color to use.
312
459
  * @param {number=1} lineWidth - (optional) The line with to use (default is 1).
460
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
461
+ *
462
+ * @return {void}
463
+ * @instance
464
+ * @memberof drawutils
313
465
  **/
314
- drawutils.prototype.rect = function (position, width, height, color, lineWidth) {
466
+ drawutils.prototype.rect = function (position, width, height, color, lineWidth, strokeOptions) {
315
467
  this.ctx.save();
316
468
  this.ctx.beginPath();
469
+ this.applyStrokeOpts(strokeOptions);
317
470
  this.ctx.moveTo(this.offset.x + position.x * this.scale.x, this.offset.y + position.y * this.scale.y);
318
471
  this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + position.y * this.scale.y);
319
472
  this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + (position.y + height) * this.scale.y);
@@ -324,43 +477,23 @@ var drawutils = /** @class */ (function () {
324
477
  this._fillOrDraw(color);
325
478
  this.ctx.restore();
326
479
  };
327
- // +---------------------------------------------------------------------------------
328
- // | This is the final helper function for drawing and filling stuff. It is not
329
- // | intended to be used from the outside.
330
- // |
331
- // | When in draw mode it draws the current shape.
332
- // | When in fill mode it fills the current shape.
333
- // |
334
- // | This function is usually only called internally.
335
- // |
336
- // | @param color A stroke/fill color to use.
337
- // +-------------------------------
338
- // TODO: convert this to a STATIC function.
339
- drawutils.prototype._fillOrDraw = function (color) {
340
- if (this.fillShapes) {
341
- this.ctx.fillStyle = color;
342
- this.ctx.fill();
343
- }
344
- else {
345
- this.ctx.strokeStyle = color;
346
- this.ctx.stroke();
347
- }
348
- };
349
480
  /**
350
481
  * Draw the given (cubic) bézier curve.
351
482
  *
352
483
  * @method cubicBezier
353
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
354
- * @param {Vertex} endPoint - The end point the cubic Bézier curve.
355
- * @param {Vertex} startControlPoint - The start control point the cubic Bézier curve.
356
- * @param {Vertex} endControlPoint - The end control point the cubic Bézier curve.
484
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
485
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
486
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
487
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
357
488
  * @param {string} color - The CSS color to draw the curve with.
358
489
  * @param {number} lineWidth - (optional) The line width to use.
490
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
491
+ *
359
492
  * @return {void}
360
493
  * @instance
361
494
  * @memberof drawutils
362
495
  */
363
- drawutils.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth) {
496
+ drawutils.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
364
497
  if (startPoint instanceof CubicBezierCurve_1.CubicBezierCurve) {
365
498
  this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
366
499
  return;
@@ -368,6 +501,7 @@ var drawutils = /** @class */ (function () {
368
501
  // Draw curve
369
502
  this.ctx.save();
370
503
  this.ctx.beginPath();
504
+ this.applyStrokeOpts(strokeOptions);
371
505
  this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
372
506
  this.ctx.bezierCurveTo(this.offset.x + startControlPoint.x * this.scale.x, this.offset.y + startControlPoint.y * this.scale.y, this.offset.x + endControlPoint.x * this.scale.x, this.offset.y + endControlPoint.y * this.scale.y, this.offset.x + endPoint.x * this.scale.x, this.offset.y + endPoint.y * this.scale.y);
373
507
  //this.ctx.closePath();
@@ -379,19 +513,22 @@ var drawutils = /** @class */ (function () {
379
513
  * Draw the given (quadratic) bézier curve.
380
514
  *
381
515
  * @method quadraticBezier
382
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
383
- * @param {Vertex} controlPoint - The control point the cubic Bézier curve.
384
- * @param {Vertex} endPoint - The end control point the cubic Bézier curve.
516
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
517
+ * @param {XYCoords} controlPoint - The control point the cubic Bézier curve.
518
+ * @param {XYCoords} endPoint - The end control point the cubic Bézier curve.
385
519
  * @param {string} color - The CSS color to draw the curve with.
386
520
  * @param {number|string} lineWidth - (optional) The line width to use.
521
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
522
+ *
387
523
  * @return {void}
388
524
  * @instance
389
525
  * @memberof drawutils
390
526
  */
391
- drawutils.prototype.quadraticBezier = function (startPoint, controlPoint, endPoint, color, lineWidth) {
527
+ drawutils.prototype.quadraticBezier = function (startPoint, controlPoint, endPoint, color, lineWidth, strokeOptions) {
392
528
  // Draw curve
393
529
  this.ctx.save();
394
530
  this.ctx.beginPath();
531
+ this.applyStrokeOpts(strokeOptions);
395
532
  this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
396
533
  this.ctx.quadraticCurveTo(this.offset.x + controlPoint.x * this.scale.x, this.offset.y + controlPoint.y * this.scale.y, this.offset.x + endPoint.x * this.scale.x, this.offset.y + endPoint.y * this.scale.y);
397
534
  this.ctx.lineWidth = lineWidth || 2;
@@ -406,22 +543,26 @@ var drawutils = /** @class */ (function () {
406
543
  * <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
407
544
  *
408
545
  * @method cubicBezierPath
409
- * @param {Vertex[]} path - The cubic bezier path as described above.
546
+ * @param {XYCoords[]} path - The cubic bezier path as described above.
410
547
  * @param {string} color - The CSS colot to draw the path with.
411
548
  * @param {number=1} lineWidth - (optional) The line width to use.
549
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
550
+ *
412
551
  * @return {void}
413
552
  * @instance
414
553
  * @memberof drawutils
415
554
  */
416
- drawutils.prototype.cubicBezierPath = function (path, color, lineWidth) {
417
- if (!path || path.length == 0)
555
+ drawutils.prototype.cubicBezierPath = function (path, color, lineWidth, strokeOptions) {
556
+ if (!path || path.length == 0) {
418
557
  return;
558
+ }
419
559
  // Draw curve
420
560
  this.ctx.save();
421
561
  this.ctx.beginPath();
422
562
  var endPoint;
423
563
  var startControlPoint;
424
564
  var endControlPoint;
565
+ this.applyStrokeOpts(strokeOptions);
425
566
  this.ctx.moveTo(this.offset.x + path[0].x * this.scale.x, this.offset.y + path[0].y * this.scale.y);
426
567
  for (var i = 1; i < path.length; i += 3) {
427
568
  startControlPoint = path[i];
@@ -440,8 +581,8 @@ var drawutils = /** @class */ (function () {
440
581
  * The colors for this are fixed and cannot be specified.
441
582
  *
442
583
  * @method handle
443
- * @param {Vertex} startPoint - The start of the handle.
444
- * @param {Vertex} endPoint - The end point of the handle.
584
+ * @param {XYCoords} startPoint - The start of the handle.
585
+ * @param {XYCoords} endPoint - The end point of the handle.
445
586
  * @return {void}
446
587
  * @instance
447
588
  * @memberof drawutils
@@ -456,21 +597,21 @@ var drawutils = /** @class */ (function () {
456
597
  * Draw a handle line (with a light grey).
457
598
  *
458
599
  * @method handleLine
459
- * @param {Vertex} startPoint - The start point to draw the handle at.
460
- * @param {Vertex} endPoint - The end point to draw the handle at.
600
+ * @param {XYCoords} startPoint - The start point to draw the handle at.
601
+ * @param {XYCoords} endPoint - The end point to draw the handle at.
461
602
  * @return {void}
462
603
  * @instance
463
604
  * @memberof drawutils
464
605
  */
465
606
  drawutils.prototype.handleLine = function (startPoint, endPoint) {
466
607
  // Draw handle lines
467
- this.line(startPoint, endPoint, "rgb(192,192,192)");
608
+ this.line(startPoint, endPoint, "rgba(128,128,128, 0.5)", undefined);
468
609
  };
469
610
  /**
470
611
  * Draw a 1x1 dot with the specified (CSS-) color.
471
612
  *
472
613
  * @method dot
473
- * @param {Vertex} p - The position to draw the dot at.
614
+ * @param {XYCoords} p - The position to draw the dot at.
474
615
  * @param {string} color - The CSS color to draw the dot with.
475
616
  * @return {void}
476
617
  * @instance
@@ -479,6 +620,7 @@ var drawutils = /** @class */ (function () {
479
620
  drawutils.prototype.dot = function (p, color) {
480
621
  this.ctx.save();
481
622
  this.ctx.beginPath();
623
+ this.ctx.setLineDash([]); // Clear line-dash settings
482
624
  this.ctx.moveTo(Math.round(this.offset.x + this.scale.x * p.x), Math.round(this.offset.y + this.scale.y * p.y));
483
625
  this.ctx.lineTo(Math.round(this.offset.x + this.scale.x * p.x + 1), Math.round(this.offset.y + this.scale.y * p.y + 1));
484
626
  this.ctx.closePath();
@@ -490,7 +632,7 @@ var drawutils = /** @class */ (function () {
490
632
  * Draw the given point with the specified (CSS-) color and radius 3.
491
633
  *
492
634
  * @method point
493
- * @param {Vertex} p - The position to draw the point at.
635
+ * @param {XYCoords} p - The position to draw the point at.
494
636
  * @param {string} color - The CSS color to draw the point with.
495
637
  * @return {void}
496
638
  * @instance
@@ -498,6 +640,7 @@ var drawutils = /** @class */ (function () {
498
640
  */
499
641
  drawutils.prototype.point = function (p, color) {
500
642
  var radius = 3;
643
+ this.ctx.setLineDash([]); // Clear line-dash settings
501
644
  this.ctx.beginPath();
502
645
  this.ctx.arc(this.offset.x + p.x * this.scale.x, this.offset.y + p.y * this.scale.y, radius, 0, 2 * Math.PI, false);
503
646
  this.ctx.closePath();
@@ -510,15 +653,18 @@ var drawutils = /** @class */ (function () {
510
653
  * Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
511
654
  *
512
655
  * @method circle
513
- * @param {Vertex} center - The center of the circle.
656
+ * @param {XYCoords} center - The center of the circle.
514
657
  * @param {number} radius - The radius of the circle.
515
658
  * @param {string} color - The CSS color to draw the circle with.
516
659
  * @param {number} lineWidth - The line width (optional, default=1).
660
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
661
+ *
517
662
  * @return {void}
518
663
  * @instance
519
664
  * @memberof drawutils
520
665
  */
521
- drawutils.prototype.circle = function (center, radius, color, lineWidth) {
666
+ drawutils.prototype.circle = function (center, radius, color, lineWidth, strokeOptions) {
667
+ this.applyStrokeOpts(strokeOptions);
522
668
  this.ctx.beginPath();
523
669
  this.ctx.ellipse(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y, radius * this.scale.x, radius * this.scale.y, 0.0, 0.0, Math.PI * 2);
524
670
  this.ctx.closePath();
@@ -526,24 +672,28 @@ var drawutils = /** @class */ (function () {
526
672
  this._fillOrDraw(color);
527
673
  };
528
674
  /**
529
- * Draw a circular arc (section of a circle) with the given CSS color.
530
- *
531
- * @method circleArc
532
- * @param {Vertex} center - The center of the circle.
533
- * @param {number} radius - The radius of the circle.
534
- * @param {number} startAngle - The angle to start at.
535
- * @param {number} endAngle - The angle to end at.
536
- * @param {string=#000000} color - The CSS color to draw the circle with.
537
- * @param {number=1} lineWidth - The line width to use
538
- // * @param {boolean=false} options.asSegment - If `true` then no beginPath and no draw will be applied (as part of larger path).
539
- * @return {void}
540
- * @instance
541
- * @memberof drawutils
542
- */
675
+ * Draw a circular arc (section of a circle) with the given CSS color.
676
+ *
677
+ * @method circleArc
678
+ * @param {XYCoords} center - The center of the circle.
679
+ * @param {number} radius - The radius of the circle.
680
+ * @param {number} startAngle - The angle to start at.
681
+ * @param {number} endAngle - The angle to end at.
682
+ * @param {string=#000000} color - The CSS color to draw the circle with.
683
+ * @param {number=1} lineWidth - The line width to use
684
+ * @param {boolean=false} options.asSegment - If `true` then no beginPath and no draw will be applied (as part of larger path).
685
+ * @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
686
+ * @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
687
+ *
688
+ * @return {void}
689
+ * @instance
690
+ * @memberof drawutils
691
+ */
543
692
  drawutils.prototype.circleArc = function (center, radius, startAngle, endAngle, color, lineWidth, options) {
544
693
  if (!options || !options.asSegment) {
545
694
  this.ctx.beginPath();
546
695
  }
696
+ this.applyStrokeOpts(options);
547
697
  this.ctx.ellipse(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y, radius * this.scale.x, radius * this.scale.y, 0.0, startAngle, endAngle, false);
548
698
  if (!options || !options.asSegment) {
549
699
  // this.ctx.closePath();
@@ -555,20 +705,23 @@ var drawutils = /** @class */ (function () {
555
705
  * Draw an ellipse with the specified (CSS-) color and thw two radii.
556
706
  *
557
707
  * @method ellipse
558
- * @param {Vertex} center - The center of the ellipse.
708
+ * @param {XYCoords} center - The center of the ellipse.
559
709
  * @param {number} radiusX - The radius of the ellipse.
560
710
  * @param {number} radiusY - The radius of the ellipse.
561
711
  * @param {string} color - The CSS color to draw the ellipse with.
562
712
  * @param {number} lineWidth=1 - An optional line width param (default is 1).
563
713
  * @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
714
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
715
+ *
564
716
  * @return {void}
565
717
  * @instance
566
718
  * @memberof drawutils
567
719
  */
568
- drawutils.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation) {
720
+ drawutils.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation, strokeOptions) {
569
721
  if (typeof rotation === "undefined") {
570
722
  rotation = 0.0;
571
723
  }
724
+ this.applyStrokeOpts(strokeOptions);
572
725
  this.ctx.beginPath();
573
726
  this.ctx.ellipse(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y, radiusX * this.scale.x, radiusY * this.scale.y, rotation, 0.0, Math.PI * 2);
574
727
  this.ctx.closePath();
@@ -585,11 +738,14 @@ var drawutils = /** @class */ (function () {
585
738
  * @param {number} size - The size of the square.
586
739
  * @param {string} color - The CSS color to draw the square with.
587
740
  * @param {number} lineWidth - The line with to use (optional, default is 1).
741
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
742
+ *
588
743
  * @return {void}
589
744
  * @instance
590
745
  * @memberof drawutils
591
746
  */
592
- drawutils.prototype.square = function (center, size, color, lineWidth) {
747
+ drawutils.prototype.square = function (center, size, color, lineWidth, strokeOptions) {
748
+ this.applyStrokeOpts(strokeOptions);
593
749
  this.ctx.beginPath();
594
750
  this.ctx.rect(this.offset.x + (center.x - size / 2.0) * this.scale.x, this.offset.y + (center.y - size / 2.0) * this.scale.y, size * this.scale.x, size * this.scale.y);
595
751
  this.ctx.closePath();
@@ -600,7 +756,7 @@ var drawutils = /** @class */ (function () {
600
756
  * Draw a grid of horizontal and vertical lines with the given (CSS-) color.
601
757
  *
602
758
  * @method grid
603
- * @param {Vertex} center - The center of the grid.
759
+ * @param {XYCoords} center - The center of the grid.
604
760
  * @param {number} width - The total width of the grid (width/2 each to the left and to the right).
605
761
  * @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
606
762
  * @param {number} sizeX - The horizontal grid size.
@@ -611,6 +767,7 @@ var drawutils = /** @class */ (function () {
611
767
  * @memberof drawutils
612
768
  */
613
769
  drawutils.prototype.grid = function (center, width, height, sizeX, sizeY, color) {
770
+ this.ctx.setLineDash([]); // Clear line-dash settings
614
771
  this.ctx.beginPath();
615
772
  var yMin = -Math.ceil((height * 0.5) / sizeY) * sizeY;
616
773
  var yMax = height / 2;
@@ -635,7 +792,7 @@ var drawutils = /** @class */ (function () {
635
792
  * This works analogue to the grid() function
636
793
  *
637
794
  * @method raster
638
- * @param {Vertex} center - The center of the raster.
795
+ * @param {XYCoords} center - The center of the raster.
639
796
  * @param {number} width - The total width of the raster (width/2 each to the left and to the right).
640
797
  * @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
641
798
  * @param {number} sizeX - The horizontal raster size.
@@ -647,6 +804,7 @@ var drawutils = /** @class */ (function () {
647
804
  */
648
805
  drawutils.prototype.raster = function (center, width, height, sizeX, sizeY, color) {
649
806
  this.ctx.save();
807
+ this.ctx.setLineDash([]); // Clear line-dash settings
650
808
  this.ctx.beginPath();
651
809
  for (var x = -Math.ceil((width * 0.5) / sizeX) * sizeX; x < width / 2; x += sizeX) {
652
810
  for (var y = -Math.ceil((height * 0.5) / sizeY) * sizeY; y < height / 2; y += sizeY) {
@@ -671,14 +829,15 @@ var drawutils = /** @class */ (function () {
671
829
  * as even shaped diamonds.
672
830
  *
673
831
  * @method diamondHandle
674
- * @param {Vertex} center - The center of the diamond.
675
- * @param {Vertex} size - The x/y-size of the diamond.
832
+ * @param {XYCoords} center - The center of the diamond.
833
+ * @param {number} size - The x/y-size of the diamond.
676
834
  * @param {string} color - The CSS color to draw the diamond with.
677
835
  * @return {void}
678
836
  * @instance
679
837
  * @memberof drawutils
680
838
  */
681
839
  drawutils.prototype.diamondHandle = function (center, size, color) {
840
+ this.ctx.setLineDash([]); // Clear line-dash settings
682
841
  this.ctx.beginPath();
683
842
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - size / 2.0, this.offset.y + center.y * this.scale.y);
684
843
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y - size / 2.0);
@@ -696,14 +855,15 @@ var drawutils = /** @class */ (function () {
696
855
  * as even shaped squares.
697
856
  *
698
857
  * @method squareHandle
699
- * @param {Vertex} center - The center of the square.
700
- * @param {Vertex} size - The x/y-size of the square.
858
+ * @param {XYCoords} center - The center of the square.
859
+ * @param {number} size - The x/y-size of the square.
701
860
  * @param {string} color - The CSS color to draw the square with.
702
861
  * @return {void}
703
862
  * @instance
704
863
  * @memberof drawutils
705
864
  */
706
865
  drawutils.prototype.squareHandle = function (center, size, color) {
866
+ this.ctx.setLineDash([]); // Clear line-dash settings
707
867
  this.ctx.beginPath();
708
868
  this.ctx.rect(this.offset.x + center.x * this.scale.x - size / 2.0, this.offset.y + center.y * this.scale.y - size / 2.0, size, size);
709
869
  this.ctx.closePath();
@@ -718,7 +878,7 @@ var drawutils = /** @class */ (function () {
718
878
  * as even shaped circles.
719
879
  *
720
880
  * @method circleHandle
721
- * @param {Vertex} center - The center of the circle.
881
+ * @param {XYCoords} center - The center of the circle.
722
882
  * @param {number} radius - The radius of the circle.
723
883
  * @param {string} color - The CSS color to draw the circle with.
724
884
  * @return {void}
@@ -727,6 +887,7 @@ var drawutils = /** @class */ (function () {
727
887
  */
728
888
  drawutils.prototype.circleHandle = function (center, radius, color) {
729
889
  radius = radius || 3;
890
+ this.ctx.setLineDash([]); // Clear line-dash settings
730
891
  this.ctx.beginPath();
731
892
  this.ctx.arc(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y, radius, 0, 2 * Math.PI, false);
732
893
  this.ctx.closePath();
@@ -749,6 +910,7 @@ var drawutils = /** @class */ (function () {
749
910
  */
750
911
  drawutils.prototype.crosshair = function (center, radius, color, lineWidth) {
751
912
  this.ctx.save();
913
+ this.ctx.setLineDash([]); // Clear line-dash settings
752
914
  this.ctx.beginPath();
753
915
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y);
754
916
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y);
@@ -776,6 +938,7 @@ var drawutils = /** @class */ (function () {
776
938
  */
777
939
  drawutils.prototype.cross = function (center, radius, color, lineWidth) {
778
940
  this.ctx.save();
941
+ this.ctx.setLineDash([]); // Clear line-dash settings
779
942
  this.ctx.beginPath();
780
943
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y - radius);
781
944
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y + radius);
@@ -794,30 +957,35 @@ var drawutils = /** @class */ (function () {
794
957
  * @param {Polygon} polygon - The polygon to draw.
795
958
  * @param {string} color - The CSS color to draw the polygon with.
796
959
  * @param {string} lineWidth - The line width to use.
960
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
961
+ *
797
962
  * @return {void}
798
963
  * @instance
799
964
  * @memberof drawutils
800
965
  */
801
- drawutils.prototype.polygon = function (polygon, color, lineWidth) {
802
- this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth);
966
+ drawutils.prototype.polygon = function (polygon, color, lineWidth, strokeOptions) {
967
+ this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth, strokeOptions);
803
968
  };
804
969
  /**
805
970
  * Draw a polygon line (alternative function to the polygon).
806
971
  *
807
972
  * @method polyline
808
- * @param {Vertex[]} vertices - The polygon vertices to draw.
973
+ * @param {XYCoords[]} vertices - The polygon vertices to draw.
809
974
  * @param {boolan} isOpen - If true the polyline will not be closed at its end.
810
975
  * @param {string} color - The CSS color to draw the polygon with.
811
976
  * @param {number} lineWidth - The line width (default is 1.0);
977
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
978
+ *
812
979
  * @return {void}
813
980
  * @instance
814
981
  * @memberof drawutils
815
982
  */
816
- drawutils.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
983
+ drawutils.prototype.polyline = function (vertices, isOpen, color, lineWidth, strokeOptions) {
817
984
  if (vertices.length <= 1) {
818
985
  return;
819
986
  }
820
987
  this.ctx.save();
988
+ this.applyStrokeOpts(strokeOptions);
821
989
  this.ctx.beginPath();
822
990
  this.ctx.lineWidth = (lineWidth || 1.0) * this.scale.x;
823
991
  this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
@@ -929,6 +1097,8 @@ var drawutils = /** @class */ (function () {
929
1097
  * @param {string=null} color - (optional) The color to draw this path with (default is null).
930
1098
  * @param {number=1} lineWidth - (optional) the line width to use (default is 1).
931
1099
  * @param {boolean=false} options.inplace - (optional) If set to true then path transforamtions (scale and translate) will be done in-place in the array. This can boost the performance.
1100
+ * @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
1101
+ * @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
932
1102
  * @instance
933
1103
  * @memberof drawutils
934
1104
  * @return {R} An instance representing the drawn path.
@@ -940,6 +1110,7 @@ var drawutils = /** @class */ (function () {
940
1110
  this.ctx.strokeStyle = color;
941
1111
  }
942
1112
  this.ctx.lineWidth = lineWidth || 1;
1113
+ this.applyStrokeOpts(options);
943
1114
  if (this.fillShapes) {
944
1115
  if (color) {
945
1116
  this.ctx.fillStyle = color;