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/ts/draw.ts CHANGED
@@ -48,15 +48,24 @@
48
48
  * @modified 2022-08-23 Fixed a type issue in the `setConfiguration` function.
49
49
  * @modified 2022-08-23 Fixed a type issue in the `path` function.
50
50
  * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
51
- * @version 1.12.4
51
+ * @modified 2023-09-29 Removed unused method stub for texturedPoly helper function (cleanup).
52
+ * @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.
53
+ * @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
54
+ * @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
55
+ * @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
56
+ * @modified 2023-09-29 Added the `lineDashes` attribute.
57
+ * @modified 2023-09-30 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
58
+ * @modified 2023-10-07 Adding the optional `arrowHeadBasePositionBuffer` param to the arrowHead(...) method.
59
+ * @version 1.13.0
52
60
  **/
53
61
 
54
62
  import { CubicBezierCurve } from "./CubicBezierCurve";
55
63
  import { Polygon } from "./Polygon";
56
64
  import { Vertex } from "./Vertex";
57
- import { DrawLib, SVGPathParams, XYCoords, UID, DrawLibConfiguration, FontStyle, FontWeight } from "./interfaces";
65
+ import { DrawLib, SVGPathParams, XYCoords, UID, DrawLibConfiguration, FontStyle, FontWeight, StrokeOptions } from "./interfaces";
58
66
  import { drawutilssvg } from "./drawutilssvg";
59
67
  import { Bounds } from "./Bounds";
68
+ import { Vector } from "./Vector";
60
69
 
61
70
  // Todo: rename this class to Drawutils?
62
71
  /**
@@ -110,11 +119,50 @@ export class drawutils implements DrawLib<void> {
110
119
  **/
111
120
  constructor(context: CanvasRenderingContext2D, fillShapes: boolean) {
112
121
  this.ctx = context;
122
+ // this.lineDash = [];
113
123
  this.offset = new Vertex(0, 0);
114
124
  this.scale = new Vertex(1, 1);
115
125
  this.fillShapes = fillShapes;
116
126
  }
117
127
 
128
+ /**
129
+ * A private helper method to apply stroke options to the current
130
+ * context.
131
+ * @param {StrokeOptions=} strokeOptions -
132
+ */
133
+ private applyStrokeOpts(strokeOptions?: StrokeOptions) {
134
+ this.ctx.setLineDash(
135
+ (strokeOptions?.dashArray ?? []).map((dashArrayElem: number) => {
136
+ // Note assume scale.x === scale.y
137
+ // Invariant scale makes funny stuff anyway.
138
+ return dashArrayElem * this.scale.x;
139
+ })
140
+ );
141
+ this.ctx.lineDashOffset = (strokeOptions?.dashOffset ?? 0) * this.scale.x;
142
+ }
143
+
144
+ // +---------------------------------------------------------------------------------
145
+ // | This is the final helper function for drawing and filling stuff. It is not
146
+ // | intended to be used from the outside.
147
+ // |
148
+ // | When in draw mode it draws the current shape.
149
+ // | When in fill mode it fills the current shape.
150
+ // |
151
+ // | This function is usually only called internally.
152
+ // |
153
+ // | @param color A stroke/fill color to use.
154
+ // +-------------------------------
155
+ // TODO: convert this to a STATIC function.
156
+ _fillOrDraw(color: string) {
157
+ if (this.fillShapes) {
158
+ this.ctx.fillStyle = color;
159
+ this.ctx.fill();
160
+ } else {
161
+ this.ctx.strokeStyle = color;
162
+ this.ctx.stroke();
163
+ }
164
+ }
165
+
118
166
  /**
119
167
  * Called before each draw cycle.
120
168
  * @param {UID=} uid - (optional) A UID identifying the currently drawn element(s).
@@ -148,6 +196,21 @@ export class drawutils implements DrawLib<void> {
148
196
  this.ctx.globalCompositeOperation = configuration.blendMode || "source-over";
149
197
  }
150
198
 
199
+ // /**
200
+ // * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
201
+ // *
202
+ // * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
203
+ // * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
204
+ // * for how line dashes work.
205
+ // *
206
+ // * @method
207
+ // * @param {Array<number> lineDashes - The line-dash array configuration.
208
+ // * @returns {void}
209
+ // */
210
+ // setLineDash(lineDash: Array<number>) {
211
+ // this.lineDash = lineDash;
212
+ // }
213
+
151
214
  /**
152
215
  * This method shouled be called each time the currently drawn `Drawable` changes.
153
216
  * It is used by some libraries for identifying elemente on re-renders.
@@ -176,17 +239,20 @@ export class drawutils implements DrawLib<void> {
176
239
  * Draw the line between the given two points with the specified (CSS-) color.
177
240
  *
178
241
  * @method line
179
- * @param {Vertex} zA - The start point of the line.
180
- * @param {Vertex} zB - The end point of the line.
242
+ * @param {XYCoords} zA - The start point of the line.
243
+ * @param {XYCoords} zB - The end point of the line.
181
244
  * @param {string} color - Any valid CSS color string.
182
245
  * @param {number} lineWidth? - [optional] The line's width.
246
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
247
+ *
183
248
  * @return {void}
184
249
  * @instance
185
250
  * @memberof drawutils
186
251
  **/
187
- line(zA: Vertex, zB: Vertex, color: string, lineWidth?: number) {
252
+ line(zA: XYCoords, zB: XYCoords, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) {
188
253
  this.ctx.save();
189
254
  this.ctx.beginPath();
255
+ this.applyStrokeOpts(strokeOptions);
190
256
  this.ctx.moveTo(this.offset.x + zA.x * this.scale.x, this.offset.y + zA.y * this.scale.y);
191
257
  this.ctx.lineTo(this.offset.x + zB.x * this.scale.x, this.offset.y + zB.y * this.scale.y);
192
258
  this.ctx.strokeStyle = color;
@@ -199,24 +265,103 @@ export class drawutils implements DrawLib<void> {
199
265
  * Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
200
266
  *
201
267
  * @method arrow
202
- * @param {Vertex} zA - The start point of the arrow-line.
203
- * @param {Vertex} zB - The end point of the arrow-line.
268
+ * @param {XYCoords} zA - The start point of the arrow-line.
269
+ * @param {XYCoords} zB - The end point of the arrow-line.
204
270
  * @param {string} color - Any valid CSS color string.
205
271
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
272
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
273
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
274
+ *
206
275
  * @return {void}
207
276
  * @instance
208
277
  * @memberof drawutils
209
278
  **/
210
- arrow(zA: Vertex, zB: Vertex, color: string, lineWidth?: number) {
211
- var headlen: number = 8; // length of head in pixels
212
- // var vertices = PlotBoilerplate.utils.buildArrowHead( zA, zB, headlen, this.scale.x, this.scale.y );
213
- // var vertices : Array<Vertex> = Vertex.utils.buildArrowHead( zA, zB, headlen, this.scale.x, this.scale.y );
279
+ arrow(zA: XYCoords, zB: XYCoords, color: string, lineWidth?: number, headLength: number = 8, strokeOptions?: StrokeOptions) {
280
+ const arrowHeadBasePosition = new Vertex(0, 0);
281
+ this.arrowHead(zA, zB, color, lineWidth, headLength, undefined, arrowHeadBasePosition); // Will NOT use dash configuration
282
+ this.line(zA, arrowHeadBasePosition, color, lineWidth, strokeOptions); // Will use dash configuration
283
+ }
284
+
285
+ /**
286
+ * 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.
287
+ *
288
+ * @method cubicBezierArrow
289
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
290
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
291
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
292
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
293
+ * @param {string} color - The CSS color to draw the curve with.
294
+ * @param {number} lineWidth - (optional) The line width to use.
295
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
296
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
297
+ *
298
+ * @return {void}
299
+ * @instance
300
+ * @memberof DrawLib
301
+ */
302
+ cubicBezierArrow(
303
+ startPoint: XYCoords,
304
+ endPoint: XYCoords,
305
+ startControlPoint: XYCoords,
306
+ endControlPoint: XYCoords,
307
+ color: string,
308
+ lineWidth?: number,
309
+ headLength?: number,
310
+ strokeOptions?: StrokeOptions
311
+ ) {
312
+ const arrowHeadBasePosition = new Vertex(0, 0);
313
+
314
+ // Will NOT use dash configuration
315
+ this.arrowHead(endControlPoint, endPoint, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
316
+ const diff = arrowHeadBasePosition.difference(endPoint);
317
+ // Will use dash configuration
318
+ this.cubicBezier(
319
+ startPoint,
320
+ { x: endPoint.x - diff.x, y: endPoint.y - diff.y },
321
+ startControlPoint,
322
+ { x: endControlPoint.x - diff.x, y: endControlPoint.y - diff.y },
323
+ color,
324
+ lineWidth,
325
+ strokeOptions
326
+ );
327
+ }
328
+
329
+ /**
330
+ * Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
331
+ *
332
+ * @method arrow
333
+ * @param {XYCoords} zA - The start point of the arrow-line.
334
+ * @param {XYCoords} zB - The end point of the arrow-line.
335
+ * @param {string} color - Any valid CSS color string.
336
+ * @param {number=1} lineWidth - (optional) The line width to use; default is 1.
337
+ * @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
338
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
339
+ * @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.
340
+ *
341
+ * @return {void}
342
+ * @instance
343
+ * @memberof DrawLib
344
+ **/
345
+ arrowHead(
346
+ zA: XYCoords,
347
+ zB: XYCoords,
348
+ color: string,
349
+ lineWidth?: number,
350
+ headLength: number = 8,
351
+ strokeOptions?: StrokeOptions,
352
+ arrowHeadBasePositionBuffer?: XYCoords
353
+ ) {
354
+ // var headLength: number = 8; // length of head in pixels
214
355
 
215
356
  this.ctx.save();
216
357
  this.ctx.beginPath();
217
- var vertices: Array<Vertex> = Vertex.utils.buildArrowHead(zA, zB, headlen, this.scale.x, this.scale.y);
218
-
219
- this.ctx.moveTo(this.offset.x + zA.x * this.scale.x, this.offset.y + zA.y * this.scale.y);
358
+ this.applyStrokeOpts(strokeOptions);
359
+ var vertices: Array<Vertex> = Vector.utils.buildArrowHead(zA, zB, headLength, this.scale.x, this.scale.y);
360
+ if (arrowHeadBasePositionBuffer) {
361
+ arrowHeadBasePositionBuffer.x = vertices[0].x / this.scale.x;
362
+ arrowHeadBasePositionBuffer.y = vertices[0].y / this.scale.y;
363
+ }
364
+ this.ctx.moveTo(this.offset.x + vertices[0].x, this.offset.y + vertices[0].y);
220
365
  for (var i = 0; i < vertices.length; i++) {
221
366
  this.ctx.lineTo(this.offset.x + vertices[i].x, this.offset.y + vertices[i].y);
222
367
  }
@@ -233,14 +378,14 @@ export class drawutils implements DrawLib<void> {
233
378
  *
234
379
  * @method image
235
380
  * @param {Image} image - The image object to draw.
236
- * @param {Vertex} position - The position to draw the the upper left corner at.
237
- * @param {Vertex} size - The x/y-size to draw the image with.
381
+ * @param {XYCoords} position - The position to draw the the upper left corner at.
382
+ * @param {XYCoords} size - The x/y-size to draw the image with.
238
383
  * @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
239
384
  * @return {void}
240
385
  * @instance
241
386
  * @memberof drawutils
242
387
  **/
243
- image(image: HTMLImageElement, position: Vertex, size: Vertex, alpha: number = 1.0): void {
388
+ image(image: HTMLImageElement, position: XYCoords, size: XYCoords, alpha: number = 1.0): void {
244
389
  if (!image.complete || !image.naturalWidth) {
245
390
  // Avoid drawing un-unloaded or broken images
246
391
  return;
@@ -272,7 +417,7 @@ export class drawutils implements DrawLib<void> {
272
417
  * @param {Image} textureImage - The image object to draw.
273
418
  * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
274
419
  * @param {Polygon} polygon - The polygon to use as clip path.
275
- * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
420
+ * @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
276
421
  * @param {number} rotation - The rotation to use for the polygon (and for the texture).
277
422
  * @param {XYCoords={x:0,y:0}} rotationCenter - (optional) The rotational center; default is center of bounding box.
278
423
  * @return {void}
@@ -283,14 +428,14 @@ export class drawutils implements DrawLib<void> {
283
428
  textureImage: HTMLImageElement,
284
429
  textureSize: Bounds,
285
430
  polygon: Polygon,
286
- polygonPosition: Vertex,
431
+ polygonPosition: XYCoords,
287
432
  rotation: number
288
433
  ): void {
289
434
  var basePolygonBounds = polygon.getBounds();
290
- var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
291
- // var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
292
- // var rotationalOffset = { x: 0, y: 0 };
293
- var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
435
+ // var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
436
+ var targetCenterDifference = new Vertex(polygonPosition.x, polygonPosition.y).difference(basePolygonBounds.getCenter());
437
+
438
+ // var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
294
439
 
295
440
  // Get the position offset of the polygon
296
441
  var targetTextureSize = new Vertex(textureSize.width, textureSize.height);
@@ -327,11 +472,12 @@ export class drawutils implements DrawLib<void> {
327
472
  this.ctx.restore();
328
473
  }
329
474
 
475
+ /*
330
476
  _texturedPoly(
331
477
  textureImage: HTMLImageElement,
332
478
  textureSize: Bounds,
333
479
  polygon: Polygon,
334
- polygonPosition: Vertex,
480
+ polygonPosition: XYCoords,
335
481
  rotation: number,
336
482
  rotationCenter: XYCoords = { x: 0, y: 0 }
337
483
  ): void {
@@ -402,6 +548,7 @@ export class drawutils implements DrawLib<void> {
402
548
 
403
549
  this.ctx.restore();
404
550
  }
551
+ */
405
552
 
406
553
  /**
407
554
  * Draw a rectangle.
@@ -411,10 +558,23 @@ export class drawutils implements DrawLib<void> {
411
558
  * @param {number} height - The height of the rectangle.
412
559
  * @param {string} color - The color to use.
413
560
  * @param {number=1} lineWidth - (optional) The line with to use (default is 1).
561
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
562
+ *
563
+ * @return {void}
564
+ * @instance
565
+ * @memberof drawutils
414
566
  **/
415
- rect(position: XYCoords, width: number, height: number, color: string, lineWidth?: number): void {
567
+ rect(
568
+ position: XYCoords,
569
+ width: number,
570
+ height: number,
571
+ color: string,
572
+ lineWidth?: number,
573
+ strokeOptions?: StrokeOptions
574
+ ): void {
416
575
  this.ctx.save();
417
576
  this.ctx.beginPath();
577
+ this.applyStrokeOpts(strokeOptions);
418
578
  this.ctx.moveTo(this.offset.x + position.x * this.scale.x, this.offset.y + position.y * this.scale.y);
419
579
  this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + position.y * this.scale.y);
420
580
  this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + (position.y + height) * this.scale.y);
@@ -426,49 +586,30 @@ export class drawutils implements DrawLib<void> {
426
586
  this.ctx.restore();
427
587
  }
428
588
 
429
- // +---------------------------------------------------------------------------------
430
- // | This is the final helper function for drawing and filling stuff. It is not
431
- // | intended to be used from the outside.
432
- // |
433
- // | When in draw mode it draws the current shape.
434
- // | When in fill mode it fills the current shape.
435
- // |
436
- // | This function is usually only called internally.
437
- // |
438
- // | @param color A stroke/fill color to use.
439
- // +-------------------------------
440
- // TODO: convert this to a STATIC function.
441
- _fillOrDraw(color: string) {
442
- if (this.fillShapes) {
443
- this.ctx.fillStyle = color;
444
- this.ctx.fill();
445
- } else {
446
- this.ctx.strokeStyle = color;
447
- this.ctx.stroke();
448
- }
449
- }
450
-
451
589
  /**
452
590
  * Draw the given (cubic) bézier curve.
453
591
  *
454
592
  * @method cubicBezier
455
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
456
- * @param {Vertex} endPoint - The end point the cubic Bézier curve.
457
- * @param {Vertex} startControlPoint - The start control point the cubic Bézier curve.
458
- * @param {Vertex} endControlPoint - The end control point the cubic Bézier curve.
593
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
594
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
595
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
596
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
459
597
  * @param {string} color - The CSS color to draw the curve with.
460
598
  * @param {number} lineWidth - (optional) The line width to use.
599
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
600
+ *
461
601
  * @return {void}
462
602
  * @instance
463
603
  * @memberof drawutils
464
604
  */
465
605
  cubicBezier(
466
- startPoint: Vertex,
467
- endPoint: Vertex,
468
- startControlPoint: Vertex,
469
- endControlPoint: Vertex,
606
+ startPoint: XYCoords,
607
+ endPoint: XYCoords,
608
+ startControlPoint: XYCoords,
609
+ endControlPoint: XYCoords,
470
610
  color: string,
471
- lineWidth?: number
611
+ lineWidth?: number,
612
+ strokeOptions?: StrokeOptions
472
613
  ) {
473
614
  if (startPoint instanceof CubicBezierCurve) {
474
615
  this.cubicBezier(
@@ -484,6 +625,7 @@ export class drawutils implements DrawLib<void> {
484
625
  // Draw curve
485
626
  this.ctx.save();
486
627
  this.ctx.beginPath();
628
+ this.applyStrokeOpts(strokeOptions);
487
629
  this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
488
630
  this.ctx.bezierCurveTo(
489
631
  this.offset.x + startControlPoint.x * this.scale.x,
@@ -503,19 +645,29 @@ export class drawutils implements DrawLib<void> {
503
645
  * Draw the given (quadratic) bézier curve.
504
646
  *
505
647
  * @method quadraticBezier
506
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
507
- * @param {Vertex} controlPoint - The control point the cubic Bézier curve.
508
- * @param {Vertex} endPoint - The end control point the cubic Bézier curve.
648
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
649
+ * @param {XYCoords} controlPoint - The control point the cubic Bézier curve.
650
+ * @param {XYCoords} endPoint - The end control point the cubic Bézier curve.
509
651
  * @param {string} color - The CSS color to draw the curve with.
510
652
  * @param {number|string} lineWidth - (optional) The line width to use.
653
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
654
+ *
511
655
  * @return {void}
512
656
  * @instance
513
657
  * @memberof drawutils
514
658
  */
515
- quadraticBezier(startPoint: Vertex, controlPoint: Vertex, endPoint: Vertex, color: string, lineWidth?: number) {
659
+ quadraticBezier(
660
+ startPoint: XYCoords,
661
+ controlPoint: XYCoords,
662
+ endPoint: XYCoords,
663
+ color: string,
664
+ lineWidth?: number,
665
+ strokeOptions?: StrokeOptions
666
+ ) {
516
667
  // Draw curve
517
668
  this.ctx.save();
518
669
  this.ctx.beginPath();
670
+ this.applyStrokeOpts(strokeOptions);
519
671
  this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
520
672
  this.ctx.quadraticCurveTo(
521
673
  this.offset.x + controlPoint.x * this.scale.x,
@@ -536,21 +688,26 @@ export class drawutils implements DrawLib<void> {
536
688
  * <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
537
689
  *
538
690
  * @method cubicBezierPath
539
- * @param {Vertex[]} path - The cubic bezier path as described above.
691
+ * @param {XYCoords[]} path - The cubic bezier path as described above.
540
692
  * @param {string} color - The CSS colot to draw the path with.
541
693
  * @param {number=1} lineWidth - (optional) The line width to use.
694
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
695
+ *
542
696
  * @return {void}
543
697
  * @instance
544
698
  * @memberof drawutils
545
699
  */
546
- cubicBezierPath(path: Array<Vertex>, color: string, lineWidth?: number) {
547
- if (!path || path.length == 0) return;
700
+ cubicBezierPath(path: Array<XYCoords>, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) {
701
+ if (!path || path.length == 0) {
702
+ return;
703
+ }
548
704
  // Draw curve
549
705
  this.ctx.save();
550
706
  this.ctx.beginPath();
551
- var endPoint: Vertex;
552
- var startControlPoint: Vertex;
553
- var endControlPoint: Vertex;
707
+ var endPoint: XYCoords;
708
+ var startControlPoint: XYCoords;
709
+ var endControlPoint: XYCoords;
710
+ this.applyStrokeOpts(strokeOptions);
554
711
  this.ctx.moveTo(this.offset.x + path[0].x * this.scale.x, this.offset.y + path[0].y * this.scale.y);
555
712
  for (var i = 1; i < path.length; i += 3) {
556
713
  startControlPoint = path[i];
@@ -577,13 +734,13 @@ export class drawutils implements DrawLib<void> {
577
734
  * The colors for this are fixed and cannot be specified.
578
735
  *
579
736
  * @method handle
580
- * @param {Vertex} startPoint - The start of the handle.
581
- * @param {Vertex} endPoint - The end point of the handle.
737
+ * @param {XYCoords} startPoint - The start of the handle.
738
+ * @param {XYCoords} endPoint - The end point of the handle.
582
739
  * @return {void}
583
740
  * @instance
584
741
  * @memberof drawutils
585
742
  */
586
- handle(startPoint: Vertex, endPoint: Vertex) {
743
+ handle(startPoint: XYCoords, endPoint: XYCoords) {
587
744
  // Draw handles
588
745
  // (No need to save and restore here)
589
746
  this.point(startPoint, "rgb(0,32,192)");
@@ -594,30 +751,31 @@ export class drawutils implements DrawLib<void> {
594
751
  * Draw a handle line (with a light grey).
595
752
  *
596
753
  * @method handleLine
597
- * @param {Vertex} startPoint - The start point to draw the handle at.
598
- * @param {Vertex} endPoint - The end point to draw the handle at.
754
+ * @param {XYCoords} startPoint - The start point to draw the handle at.
755
+ * @param {XYCoords} endPoint - The end point to draw the handle at.
599
756
  * @return {void}
600
757
  * @instance
601
758
  * @memberof drawutils
602
759
  */
603
- handleLine(startPoint: Vertex, endPoint: Vertex) {
760
+ handleLine(startPoint: XYCoords, endPoint: XYCoords) {
604
761
  // Draw handle lines
605
- this.line(startPoint, endPoint, "rgb(192,192,192)");
762
+ this.line(startPoint, endPoint, "rgba(128,128,128, 0.5)", undefined);
606
763
  }
607
764
 
608
765
  /**
609
766
  * Draw a 1x1 dot with the specified (CSS-) color.
610
767
  *
611
768
  * @method dot
612
- * @param {Vertex} p - The position to draw the dot at.
769
+ * @param {XYCoords} p - The position to draw the dot at.
613
770
  * @param {string} color - The CSS color to draw the dot with.
614
771
  * @return {void}
615
772
  * @instance
616
773
  * @memberof drawutils
617
774
  */
618
- dot(p: Vertex, color: string) {
775
+ dot(p: XYCoords, color: string) {
619
776
  this.ctx.save();
620
777
  this.ctx.beginPath();
778
+ this.ctx.setLineDash([]); // Clear line-dash settings
621
779
  this.ctx.moveTo(Math.round(this.offset.x + this.scale.x * p.x), Math.round(this.offset.y + this.scale.y * p.y));
622
780
  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));
623
781
  this.ctx.closePath();
@@ -630,14 +788,15 @@ export class drawutils implements DrawLib<void> {
630
788
  * Draw the given point with the specified (CSS-) color and radius 3.
631
789
  *
632
790
  * @method point
633
- * @param {Vertex} p - The position to draw the point at.
791
+ * @param {XYCoords} p - The position to draw the point at.
634
792
  * @param {string} color - The CSS color to draw the point with.
635
793
  * @return {void}
636
794
  * @instance
637
795
  * @memberof drawutils
638
796
  */
639
- point(p: Vertex, color: string) {
797
+ point(p: XYCoords, color: string) {
640
798
  var radius: number = 3;
799
+ this.ctx.setLineDash([]); // Clear line-dash settings
641
800
  this.ctx.beginPath();
642
801
  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);
643
802
  this.ctx.closePath();
@@ -651,15 +810,18 @@ export class drawutils implements DrawLib<void> {
651
810
  * Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
652
811
  *
653
812
  * @method circle
654
- * @param {Vertex} center - The center of the circle.
813
+ * @param {XYCoords} center - The center of the circle.
655
814
  * @param {number} radius - The radius of the circle.
656
815
  * @param {string} color - The CSS color to draw the circle with.
657
816
  * @param {number} lineWidth - The line width (optional, default=1).
817
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
818
+ *
658
819
  * @return {void}
659
820
  * @instance
660
821
  * @memberof drawutils
661
822
  */
662
- circle(center: Vertex, radius: number, color: string, lineWidth?: number) {
823
+ circle(center: XYCoords, radius: number, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) {
824
+ this.applyStrokeOpts(strokeOptions);
663
825
  this.ctx.beginPath();
664
826
  this.ctx.ellipse(
665
827
  this.offset.x + center.x * this.scale.x,
@@ -676,32 +838,36 @@ export class drawutils implements DrawLib<void> {
676
838
  }
677
839
 
678
840
  /**
679
- * Draw a circular arc (section of a circle) with the given CSS color.
680
- *
681
- * @method circleArc
682
- * @param {Vertex} center - The center of the circle.
683
- * @param {number} radius - The radius of the circle.
684
- * @param {number} startAngle - The angle to start at.
685
- * @param {number} endAngle - The angle to end at.
686
- * @param {string=#000000} color - The CSS color to draw the circle with.
687
- * @param {number=1} lineWidth - The line width to use
688
- // * @param {boolean=false} options.asSegment - If `true` then no beginPath and no draw will be applied (as part of larger path).
689
- * @return {void}
690
- * @instance
691
- * @memberof drawutils
692
- */
841
+ * Draw a circular arc (section of a circle) with the given CSS color.
842
+ *
843
+ * @method circleArc
844
+ * @param {XYCoords} center - The center of the circle.
845
+ * @param {number} radius - The radius of the circle.
846
+ * @param {number} startAngle - The angle to start at.
847
+ * @param {number} endAngle - The angle to end at.
848
+ * @param {string=#000000} color - The CSS color to draw the circle with.
849
+ * @param {number=1} lineWidth - The line width to use
850
+ * @param {boolean=false} options.asSegment - If `true` then no beginPath and no draw will be applied (as part of larger path).
851
+ * @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
852
+ * @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
853
+ *
854
+ * @return {void}
855
+ * @instance
856
+ * @memberof drawutils
857
+ */
693
858
  circleArc(
694
- center: Vertex,
859
+ center: XYCoords,
695
860
  radius: number,
696
861
  startAngle: number,
697
862
  endAngle: number,
698
863
  color?: string,
699
864
  lineWidth?: number,
700
- options?: { asSegment?: boolean }
865
+ options?: { asSegment?: boolean } & StrokeOptions
701
866
  ) {
702
867
  if (!options || !options.asSegment) {
703
868
  this.ctx.beginPath();
704
869
  }
870
+ this.applyStrokeOpts(options);
705
871
  this.ctx.ellipse(
706
872
  this.offset.x + center.x * this.scale.x,
707
873
  this.offset.y + center.y * this.scale.y,
@@ -723,20 +889,31 @@ export class drawutils implements DrawLib<void> {
723
889
  * Draw an ellipse with the specified (CSS-) color and thw two radii.
724
890
  *
725
891
  * @method ellipse
726
- * @param {Vertex} center - The center of the ellipse.
892
+ * @param {XYCoords} center - The center of the ellipse.
727
893
  * @param {number} radiusX - The radius of the ellipse.
728
894
  * @param {number} radiusY - The radius of the ellipse.
729
895
  * @param {string} color - The CSS color to draw the ellipse with.
730
896
  * @param {number} lineWidth=1 - An optional line width param (default is 1).
731
897
  * @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
898
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
899
+ *
732
900
  * @return {void}
733
901
  * @instance
734
902
  * @memberof drawutils
735
903
  */
736
- ellipse(center: Vertex, radiusX: number, radiusY: number, color: string, lineWidth?: number, rotation?: number) {
904
+ ellipse(
905
+ center: XYCoords,
906
+ radiusX: number,
907
+ radiusY: number,
908
+ color: string,
909
+ lineWidth?: number,
910
+ rotation?: number,
911
+ strokeOptions?: StrokeOptions
912
+ ) {
737
913
  if (typeof rotation === "undefined") {
738
914
  rotation = 0.0;
739
915
  }
916
+ this.applyStrokeOpts(strokeOptions);
740
917
  this.ctx.beginPath();
741
918
  this.ctx.ellipse(
742
919
  this.offset.x + center.x * this.scale.x,
@@ -762,11 +939,14 @@ export class drawutils implements DrawLib<void> {
762
939
  * @param {number} size - The size of the square.
763
940
  * @param {string} color - The CSS color to draw the square with.
764
941
  * @param {number} lineWidth - The line with to use (optional, default is 1).
942
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
943
+ *
765
944
  * @return {void}
766
945
  * @instance
767
946
  * @memberof drawutils
768
947
  */
769
- square(center: XYCoords, size: number, color: string, lineWidth?: number) {
948
+ square(center: XYCoords, size: number, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) {
949
+ this.applyStrokeOpts(strokeOptions);
770
950
  this.ctx.beginPath();
771
951
  this.ctx.rect(
772
952
  this.offset.x + (center.x - size / 2.0) * this.scale.x,
@@ -783,7 +963,7 @@ export class drawutils implements DrawLib<void> {
783
963
  * Draw a grid of horizontal and vertical lines with the given (CSS-) color.
784
964
  *
785
965
  * @method grid
786
- * @param {Vertex} center - The center of the grid.
966
+ * @param {XYCoords} center - The center of the grid.
787
967
  * @param {number} width - The total width of the grid (width/2 each to the left and to the right).
788
968
  * @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
789
969
  * @param {number} sizeX - The horizontal grid size.
@@ -793,7 +973,8 @@ export class drawutils implements DrawLib<void> {
793
973
  * @instance
794
974
  * @memberof drawutils
795
975
  */
796
- grid(center: Vertex, width: number, height: number, sizeX: number, sizeY: number, color: string) {
976
+ grid(center: XYCoords, width: number, height: number, sizeX: number, sizeY: number, color: string) {
977
+ this.ctx.setLineDash([]); // Clear line-dash settings
797
978
  this.ctx.beginPath();
798
979
  var yMin: number = -Math.ceil((height * 0.5) / sizeY) * sizeY;
799
980
  var yMax: number = height / 2;
@@ -820,7 +1001,7 @@ export class drawutils implements DrawLib<void> {
820
1001
  * This works analogue to the grid() function
821
1002
  *
822
1003
  * @method raster
823
- * @param {Vertex} center - The center of the raster.
1004
+ * @param {XYCoords} center - The center of the raster.
824
1005
  * @param {number} width - The total width of the raster (width/2 each to the left and to the right).
825
1006
  * @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
826
1007
  * @param {number} sizeX - The horizontal raster size.
@@ -830,8 +1011,9 @@ export class drawutils implements DrawLib<void> {
830
1011
  * @instance
831
1012
  * @memberof drawutils
832
1013
  */
833
- raster(center: Vertex, width: number, height: number, sizeX: number, sizeY: number, color: string) {
1014
+ raster(center: XYCoords, width: number, height: number, sizeX: number, sizeY: number, color: string) {
834
1015
  this.ctx.save();
1016
+ this.ctx.setLineDash([]); // Clear line-dash settings
835
1017
  this.ctx.beginPath();
836
1018
  for (var x = -Math.ceil((width * 0.5) / sizeX) * sizeX; x < width / 2; x += sizeX) {
837
1019
  for (var y = -Math.ceil((height * 0.5) / sizeY) * sizeY; y < height / 2; y += sizeY) {
@@ -857,14 +1039,15 @@ export class drawutils implements DrawLib<void> {
857
1039
  * as even shaped diamonds.
858
1040
  *
859
1041
  * @method diamondHandle
860
- * @param {Vertex} center - The center of the diamond.
861
- * @param {Vertex} size - The x/y-size of the diamond.
1042
+ * @param {XYCoords} center - The center of the diamond.
1043
+ * @param {number} size - The x/y-size of the diamond.
862
1044
  * @param {string} color - The CSS color to draw the diamond with.
863
1045
  * @return {void}
864
1046
  * @instance
865
1047
  * @memberof drawutils
866
1048
  */
867
- diamondHandle(center: Vertex, size: number, color: string) {
1049
+ diamondHandle(center: XYCoords, size: number, color: string) {
1050
+ this.ctx.setLineDash([]); // Clear line-dash settings
868
1051
  this.ctx.beginPath();
869
1052
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - size / 2.0, this.offset.y + center.y * this.scale.y);
870
1053
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y - size / 2.0);
@@ -883,14 +1066,15 @@ export class drawutils implements DrawLib<void> {
883
1066
  * as even shaped squares.
884
1067
  *
885
1068
  * @method squareHandle
886
- * @param {Vertex} center - The center of the square.
887
- * @param {Vertex} size - The x/y-size of the square.
1069
+ * @param {XYCoords} center - The center of the square.
1070
+ * @param {number} size - The x/y-size of the square.
888
1071
  * @param {string} color - The CSS color to draw the square with.
889
1072
  * @return {void}
890
1073
  * @instance
891
1074
  * @memberof drawutils
892
1075
  */
893
- squareHandle(center: Vertex, size: number, color: string) {
1076
+ squareHandle(center: XYCoords, size: number, color: string) {
1077
+ this.ctx.setLineDash([]); // Clear line-dash settings
894
1078
  this.ctx.beginPath();
895
1079
  this.ctx.rect(
896
1080
  this.offset.x + center.x * this.scale.x - size / 2.0,
@@ -911,15 +1095,17 @@ export class drawutils implements DrawLib<void> {
911
1095
  * as even shaped circles.
912
1096
  *
913
1097
  * @method circleHandle
914
- * @param {Vertex} center - The center of the circle.
1098
+ * @param {XYCoords} center - The center of the circle.
915
1099
  * @param {number} radius - The radius of the circle.
916
1100
  * @param {string} color - The CSS color to draw the circle with.
917
1101
  * @return {void}
918
1102
  * @instance
919
1103
  * @memberof drawutils
920
1104
  */
921
- circleHandle(center: Vertex, radius: number, color: string) {
1105
+ circleHandle(center: XYCoords, radius: number, color: string) {
922
1106
  radius = radius || 3;
1107
+ this.ctx.setLineDash([]); // Clear line-dash settings
1108
+
923
1109
  this.ctx.beginPath();
924
1110
  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);
925
1111
  this.ctx.closePath();
@@ -943,6 +1129,7 @@ export class drawutils implements DrawLib<void> {
943
1129
  */
944
1130
  crosshair(center: XYCoords, radius: number, color: string, lineWidth?: number) {
945
1131
  this.ctx.save();
1132
+ this.ctx.setLineDash([]); // Clear line-dash settings
946
1133
  this.ctx.beginPath();
947
1134
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y);
948
1135
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y);
@@ -971,6 +1158,7 @@ export class drawutils implements DrawLib<void> {
971
1158
  */
972
1159
  cross(center: XYCoords, radius: number, color: string, lineWidth?: number) {
973
1160
  this.ctx.save();
1161
+ this.ctx.setLineDash([]); // Clear line-dash settings
974
1162
  this.ctx.beginPath();
975
1163
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y - radius);
976
1164
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y + radius);
@@ -990,31 +1178,36 @@ export class drawutils implements DrawLib<void> {
990
1178
  * @param {Polygon} polygon - The polygon to draw.
991
1179
  * @param {string} color - The CSS color to draw the polygon with.
992
1180
  * @param {string} lineWidth - The line width to use.
1181
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
1182
+ *
993
1183
  * @return {void}
994
1184
  * @instance
995
1185
  * @memberof drawutils
996
1186
  */
997
- polygon(polygon: Polygon, color: string, lineWidth?: number) {
998
- this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth);
1187
+ polygon(polygon: Polygon, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) {
1188
+ this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth, strokeOptions);
999
1189
  }
1000
1190
 
1001
1191
  /**
1002
1192
  * Draw a polygon line (alternative function to the polygon).
1003
1193
  *
1004
1194
  * @method polyline
1005
- * @param {Vertex[]} vertices - The polygon vertices to draw.
1195
+ * @param {XYCoords[]} vertices - The polygon vertices to draw.
1006
1196
  * @param {boolan} isOpen - If true the polyline will not be closed at its end.
1007
1197
  * @param {string} color - The CSS color to draw the polygon with.
1008
1198
  * @param {number} lineWidth - The line width (default is 1.0);
1199
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
1200
+ *
1009
1201
  * @return {void}
1010
1202
  * @instance
1011
1203
  * @memberof drawutils
1012
1204
  */
1013
- polyline(vertices: Array<Vertex>, isOpen: boolean, color: string, lineWidth?: number) {
1205
+ polyline(vertices: Array<XYCoords>, isOpen: boolean, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) {
1014
1206
  if (vertices.length <= 1) {
1015
1207
  return;
1016
1208
  }
1017
1209
  this.ctx.save();
1210
+ this.applyStrokeOpts(strokeOptions);
1018
1211
  this.ctx.beginPath();
1019
1212
  this.ctx.lineWidth = (lineWidth || 1.0) * this.scale.x;
1020
1213
  this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
@@ -1144,17 +1337,20 @@ export class drawutils implements DrawLib<void> {
1144
1337
  * @param {string=null} color - (optional) The color to draw this path with (default is null).
1145
1338
  * @param {number=1} lineWidth - (optional) the line width to use (default is 1).
1146
1339
  * @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.
1340
+ * @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
1341
+ * @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
1147
1342
  * @instance
1148
1343
  * @memberof drawutils
1149
1344
  * @return {R} An instance representing the drawn path.
1150
1345
  */
1151
- path(pathData: SVGPathParams, color?: string, lineWidth?: number, options?: { inplace?: boolean }) {
1346
+ path(pathData: SVGPathParams, color?: string, lineWidth?: number, options?: { inplace?: boolean } & StrokeOptions) {
1152
1347
  const d: SVGPathParams = options && options.inplace ? pathData : drawutilssvg.copyPathData(pathData);
1153
1348
  drawutilssvg.transformPathData(d, this.offset, this.scale);
1154
1349
  if (color) {
1155
1350
  this.ctx.strokeStyle = color;
1156
1351
  }
1157
1352
  this.ctx.lineWidth = lineWidth || 1;
1353
+ this.applyStrokeOpts(options);
1158
1354
  if (this.fillShapes) {
1159
1355
  if (color) {
1160
1356
  this.ctx.fillStyle = color;