plotboilerplate 1.20.1 → 1.21.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 (141) hide show
  1. package/README.md +17 -1
  2. package/dist/index.esm.js +2065 -1397
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.esm.min.js +1 -1
  5. package/dist/index.esm.min.js.map +1 -1
  6. package/dist/plotboilerplate.browser.min.js +1 -1
  7. package/dist/plotboilerplate.browser.min.js.map +1 -1
  8. package/dist/plotboilerplate.js +1265 -584
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +2 -1
  11. package/src/cjs/BezierPath.d.ts +27 -49
  12. package/src/cjs/BezierPath.js +69 -237
  13. package/src/cjs/BezierPath.js.map +1 -1
  14. package/src/cjs/Bounds.d.ts +14 -1
  15. package/src/cjs/Bounds.js +21 -1
  16. package/src/cjs/Bounds.js.map +1 -1
  17. package/src/cjs/CubicBezierCurve.d.ts +70 -1
  18. package/src/cjs/CubicBezierCurve.js +130 -12
  19. package/src/cjs/CubicBezierCurve.js.map +1 -1
  20. package/src/cjs/Line.d.ts +2 -1
  21. package/src/cjs/Line.js +1 -0
  22. package/src/cjs/Line.js.map +1 -1
  23. package/src/cjs/PBText.d.ts +2 -1
  24. package/src/cjs/PBText.js +10 -9
  25. package/src/cjs/PBText.js.map +1 -1
  26. package/src/cjs/PlotBoilerplate.d.ts +10 -13
  27. package/src/cjs/PlotBoilerplate.js +136 -47
  28. package/src/cjs/PlotBoilerplate.js.map +1 -1
  29. package/src/cjs/Polygon.d.ts +35 -1
  30. package/src/cjs/Polygon.js +87 -1
  31. package/src/cjs/Polygon.js.map +1 -1
  32. package/src/cjs/Triangle.js +1 -0
  33. package/src/cjs/Triangle.js.map +1 -1
  34. package/src/cjs/VEllipse.js +1 -1
  35. package/src/cjs/VEllipse.js.map +1 -1
  36. package/src/cjs/Vector.d.ts +4 -4
  37. package/src/cjs/Vector.js +2 -2
  38. package/src/cjs/Vector.js.map +1 -1
  39. package/src/cjs/VertTuple.d.ts +2 -1
  40. package/src/cjs/VertTuple.js +4 -3
  41. package/src/cjs/VertTuple.js.map +1 -1
  42. package/src/cjs/Vertex.d.ts +14 -3
  43. package/src/cjs/Vertex.js +18 -3
  44. package/src/cjs/Vertex.js.map +1 -1
  45. package/src/cjs/draw.d.ts +159 -79
  46. package/src/cjs/draw.js +311 -139
  47. package/src/cjs/draw.js.map +1 -1
  48. package/src/cjs/drawgl.d.ts +93 -55
  49. package/src/cjs/drawgl.js +90 -34
  50. package/src/cjs/drawgl.js.map +1 -1
  51. package/src/cjs/drawutilssvg.d.ts +233 -58
  52. package/src/cjs/drawutilssvg.js +384 -95
  53. package/src/cjs/drawutilssvg.js.map +1 -1
  54. package/src/cjs/interfaces/DrawLib.d.ts +161 -82
  55. package/src/cjs/interfaces/DrawLib.js +7 -0
  56. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  57. package/src/cjs/interfaces/core.d.ts +46 -32
  58. package/src/cjs/interfaces/core.js +2 -0
  59. package/src/cjs/interfaces/core.js.map +1 -1
  60. package/src/cjs/utils/creategui.js +16 -10
  61. package/src/cjs/utils/datastructures/Color.d.ts +3 -1
  62. package/src/cjs/utils/datastructures/Color.js +12 -1
  63. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  64. package/src/cjs/utils/detectDarkMode.d.ts +10 -0
  65. package/src/cjs/utils/detectDarkMode.js +32 -0
  66. package/src/cjs/utils/detectDarkMode.js.map +1 -0
  67. package/src/cjs/utils/module.js +4 -2
  68. package/src/esm/BezierPath.d.ts +27 -49
  69. package/src/esm/BezierPath.js +69 -237
  70. package/src/esm/BezierPath.js.map +1 -1
  71. package/src/esm/Bounds.d.ts +14 -1
  72. package/src/esm/Bounds.js +19 -1
  73. package/src/esm/Bounds.js.map +1 -1
  74. package/src/esm/CubicBezierCurve.d.ts +70 -1
  75. package/src/esm/CubicBezierCurve.js +130 -12
  76. package/src/esm/CubicBezierCurve.js.map +1 -1
  77. package/src/esm/Line.d.ts +2 -1
  78. package/src/esm/Line.js +1 -0
  79. package/src/esm/Line.js.map +1 -1
  80. package/src/esm/PBText.d.ts +2 -1
  81. package/src/esm/PBText.js +10 -9
  82. package/src/esm/PBText.js.map +1 -1
  83. package/src/esm/PlotBoilerplate.d.ts +10 -13
  84. package/src/esm/PlotBoilerplate.js +136 -48
  85. package/src/esm/PlotBoilerplate.js.map +1 -1
  86. package/src/esm/Polygon.d.ts +35 -1
  87. package/src/esm/Polygon.js +85 -1
  88. package/src/esm/Polygon.js.map +1 -1
  89. package/src/esm/Triangle.js +1 -0
  90. package/src/esm/Triangle.js.map +1 -1
  91. package/src/esm/VEllipse.js +1 -1
  92. package/src/esm/VEllipse.js.map +1 -1
  93. package/src/esm/Vector.d.ts +4 -4
  94. package/src/esm/Vector.js +2 -2
  95. package/src/esm/Vector.js.map +1 -1
  96. package/src/esm/VertTuple.d.ts +2 -1
  97. package/src/esm/VertTuple.js +4 -3
  98. package/src/esm/VertTuple.js.map +1 -1
  99. package/src/esm/Vertex.d.ts +14 -3
  100. package/src/esm/Vertex.js +18 -3
  101. package/src/esm/Vertex.js.map +1 -1
  102. package/src/esm/draw.d.ts +159 -79
  103. package/src/esm/draw.js +307 -137
  104. package/src/esm/draw.js.map +1 -1
  105. package/src/esm/drawgl.d.ts +93 -55
  106. package/src/esm/drawgl.js +90 -34
  107. package/src/esm/drawgl.js.map +1 -1
  108. package/src/esm/drawutilssvg.d.ts +233 -58
  109. package/src/esm/drawutilssvg.js +379 -95
  110. package/src/esm/drawutilssvg.js.map +1 -1
  111. package/src/esm/interfaces/DrawLib.d.ts +161 -82
  112. package/src/esm/interfaces/DrawLib.js +7 -0
  113. package/src/esm/interfaces/DrawLib.js.map +1 -1
  114. package/src/esm/interfaces/core.d.ts +46 -32
  115. package/src/esm/interfaces/core.js +2 -0
  116. package/src/esm/interfaces/core.js.map +1 -1
  117. package/src/esm/utils/datastructures/Color.d.ts +3 -1
  118. package/src/esm/utils/datastructures/Color.js +12 -1
  119. package/src/esm/utils/datastructures/Color.js.map +1 -1
  120. package/src/esm/utils/detectDarkMode.d.ts +10 -0
  121. package/src/esm/utils/detectDarkMode.js +28 -0
  122. package/src/esm/utils/detectDarkMode.js.map +1 -0
  123. package/src/ts/BezierPath.ts +74 -244
  124. package/src/ts/Bounds.ts +25 -1
  125. package/src/ts/CubicBezierCurve.ts +139 -12
  126. package/src/ts/Line.ts +2 -1
  127. package/src/ts/PBText.ts +10 -9
  128. package/src/ts/PlotBoilerplate.ts +130 -50
  129. package/src/ts/Polygon.ts +91 -1
  130. package/src/ts/Triangle.ts +2 -1
  131. package/src/ts/VEllipse.ts +2 -2
  132. package/src/ts/Vector.ts +4 -4
  133. package/src/ts/VertTuple.ts +4 -3
  134. package/src/ts/Vertex.ts +20 -4
  135. package/src/ts/draw.ts +316 -119
  136. package/src/ts/drawgl.ts +141 -78
  137. package/src/ts/drawutilssvg.ts +562 -133
  138. package/src/ts/interfaces/DrawLib.ts +223 -86
  139. package/src/ts/interfaces/core.ts +47 -32
  140. package/src/ts/utils/datastructures/Color.ts +13 -1
  141. package/src/ts/utils/detectDarkMode.ts +30 -0
package/src/ts/draw.ts CHANGED
@@ -47,15 +47,25 @@
47
47
  * @modified 2022-08-23 Fixed a type issue in the `polyline` function.
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
- * @version 1.12.3
50
+ * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
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
51
60
  **/
52
61
 
53
62
  import { CubicBezierCurve } from "./CubicBezierCurve";
54
63
  import { Polygon } from "./Polygon";
55
64
  import { Vertex } from "./Vertex";
56
- import { DrawLib, SVGPathParams, XYCoords, UID, DrawLibConfiguration, FontStyle, FontWeight } from "./interfaces";
65
+ import { DrawLib, SVGPathParams, XYCoords, UID, DrawLibConfiguration, FontStyle, FontWeight, StrokeOptions } from "./interfaces";
57
66
  import { drawutilssvg } from "./drawutilssvg";
58
67
  import { Bounds } from "./Bounds";
68
+ import { Vector } from "./Vector";
59
69
 
60
70
  // Todo: rename this class to Drawutils?
61
71
  /**
@@ -109,11 +119,50 @@ export class drawutils implements DrawLib<void> {
109
119
  **/
110
120
  constructor(context: CanvasRenderingContext2D, fillShapes: boolean) {
111
121
  this.ctx = context;
122
+ // this.lineDash = [];
112
123
  this.offset = new Vertex(0, 0);
113
124
  this.scale = new Vertex(1, 1);
114
125
  this.fillShapes = fillShapes;
115
126
  }
116
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
+
117
166
  /**
118
167
  * Called before each draw cycle.
119
168
  * @param {UID=} uid - (optional) A UID identifying the currently drawn element(s).
@@ -147,15 +196,30 @@ export class drawutils implements DrawLib<void> {
147
196
  this.ctx.globalCompositeOperation = configuration.blendMode || "source-over";
148
197
  }
149
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
+
150
214
  /**
151
215
  * This method shouled be called each time the currently drawn `Drawable` changes.
152
216
  * It is used by some libraries for identifying elemente on re-renders.
153
217
  *
154
218
  * @name setCurrentId
155
219
  * @method
156
- * @param {UID} uid - A UID identifying the currently drawn element(s).
220
+ * @param {UID|null} uid - A UID identifying the currently drawn element(s).
157
221
  **/
158
- setCurrentId(uid: UID | undefined): void {
222
+ setCurrentId(uid: UID | null): void {
159
223
  // NOOP
160
224
  }
161
225
 
@@ -165,9 +229,9 @@ export class drawutils implements DrawLib<void> {
165
229
  *
166
230
  * @name setCurrentClassName
167
231
  * @method
168
- * @param {string} className - A class name for further custom use cases.
232
+ * @param {string|null} className - A class name for further custom use cases.
169
233
  **/
170
- setCurrentClassName(className: string | undefined): void {
234
+ setCurrentClassName(className: string | null): void {
171
235
  // NOOP
172
236
  }
173
237
 
@@ -175,17 +239,20 @@ export class drawutils implements DrawLib<void> {
175
239
  * Draw the line between the given two points with the specified (CSS-) color.
176
240
  *
177
241
  * @method line
178
- * @param {Vertex} zA - The start point of the line.
179
- * @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.
180
244
  * @param {string} color - Any valid CSS color string.
181
245
  * @param {number} lineWidth? - [optional] The line's width.
246
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
247
+ *
182
248
  * @return {void}
183
249
  * @instance
184
250
  * @memberof drawutils
185
251
  **/
186
- line(zA: Vertex, zB: Vertex, color: string, lineWidth?: number) {
252
+ line(zA: XYCoords, zB: XYCoords, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) {
187
253
  this.ctx.save();
188
254
  this.ctx.beginPath();
255
+ this.applyStrokeOpts(strokeOptions);
189
256
  this.ctx.moveTo(this.offset.x + zA.x * this.scale.x, this.offset.y + zA.y * this.scale.y);
190
257
  this.ctx.lineTo(this.offset.x + zB.x * this.scale.x, this.offset.y + zB.y * this.scale.y);
191
258
  this.ctx.strokeStyle = color;
@@ -198,24 +265,103 @@ export class drawutils implements DrawLib<void> {
198
265
  * Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
199
266
  *
200
267
  * @method arrow
201
- * @param {Vertex} zA - The start point of the arrow-line.
202
- * @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.
203
270
  * @param {string} color - Any valid CSS color string.
204
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
+ *
205
275
  * @return {void}
206
276
  * @instance
207
277
  * @memberof drawutils
208
278
  **/
209
- arrow(zA: Vertex, zB: Vertex, color: string, lineWidth?: number) {
210
- var headlen: number = 8; // length of head in pixels
211
- // var vertices = PlotBoilerplate.utils.buildArrowHead( zA, zB, headlen, this.scale.x, this.scale.y );
212
- // 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
213
355
 
214
356
  this.ctx.save();
215
357
  this.ctx.beginPath();
216
- var vertices: Array<Vertex> = Vertex.utils.buildArrowHead(zA, zB, headlen, this.scale.x, this.scale.y);
217
-
218
- 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);
219
365
  for (var i = 0; i < vertices.length; i++) {
220
366
  this.ctx.lineTo(this.offset.x + vertices[i].x, this.offset.y + vertices[i].y);
221
367
  }
@@ -232,14 +378,14 @@ export class drawutils implements DrawLib<void> {
232
378
  *
233
379
  * @method image
234
380
  * @param {Image} image - The image object to draw.
235
- * @param {Vertex} position - The position to draw the the upper left corner at.
236
- * @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.
237
383
  * @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
238
384
  * @return {void}
239
385
  * @instance
240
386
  * @memberof drawutils
241
387
  **/
242
- 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 {
243
389
  if (!image.complete || !image.naturalWidth) {
244
390
  // Avoid drawing un-unloaded or broken images
245
391
  return;
@@ -271,7 +417,7 @@ export class drawutils implements DrawLib<void> {
271
417
  * @param {Image} textureImage - The image object to draw.
272
418
  * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
273
419
  * @param {Polygon} polygon - The polygon to use as clip path.
274
- * @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.
275
421
  * @param {number} rotation - The rotation to use for the polygon (and for the texture).
276
422
  * @param {XYCoords={x:0,y:0}} rotationCenter - (optional) The rotational center; default is center of bounding box.
277
423
  * @return {void}
@@ -282,14 +428,14 @@ export class drawutils implements DrawLib<void> {
282
428
  textureImage: HTMLImageElement,
283
429
  textureSize: Bounds,
284
430
  polygon: Polygon,
285
- polygonPosition: Vertex,
431
+ polygonPosition: XYCoords,
286
432
  rotation: number
287
433
  ): void {
288
434
  var basePolygonBounds = polygon.getBounds();
289
- var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
290
- // var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
291
- // var rotationalOffset = { x: 0, y: 0 };
292
- 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);
293
439
 
294
440
  // Get the position offset of the polygon
295
441
  var targetTextureSize = new Vertex(textureSize.width, textureSize.height);
@@ -326,11 +472,12 @@ export class drawutils implements DrawLib<void> {
326
472
  this.ctx.restore();
327
473
  }
328
474
 
475
+ /*
329
476
  _texturedPoly(
330
477
  textureImage: HTMLImageElement,
331
478
  textureSize: Bounds,
332
479
  polygon: Polygon,
333
- polygonPosition: Vertex,
480
+ polygonPosition: XYCoords,
334
481
  rotation: number,
335
482
  rotationCenter: XYCoords = { x: 0, y: 0 }
336
483
  ): void {
@@ -401,6 +548,7 @@ export class drawutils implements DrawLib<void> {
401
548
 
402
549
  this.ctx.restore();
403
550
  }
551
+ */
404
552
 
405
553
  /**
406
554
  * Draw a rectangle.
@@ -410,10 +558,23 @@ export class drawutils implements DrawLib<void> {
410
558
  * @param {number} height - The height of the rectangle.
411
559
  * @param {string} color - The color to use.
412
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
413
566
  **/
414
- 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 {
415
575
  this.ctx.save();
416
576
  this.ctx.beginPath();
577
+ this.applyStrokeOpts(strokeOptions);
417
578
  this.ctx.moveTo(this.offset.x + position.x * this.scale.x, this.offset.y + position.y * this.scale.y);
418
579
  this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + position.y * this.scale.y);
419
580
  this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + (position.y + height) * this.scale.y);
@@ -425,49 +586,30 @@ export class drawutils implements DrawLib<void> {
425
586
  this.ctx.restore();
426
587
  }
427
588
 
428
- // +---------------------------------------------------------------------------------
429
- // | This is the final helper function for drawing and filling stuff. It is not
430
- // | intended to be used from the outside.
431
- // |
432
- // | When in draw mode it draws the current shape.
433
- // | When in fill mode it fills the current shape.
434
- // |
435
- // | This function is usually only called internally.
436
- // |
437
- // | @param color A stroke/fill color to use.
438
- // +-------------------------------
439
- // TODO: convert this to a STATIC function.
440
- _fillOrDraw(color: string) {
441
- if (this.fillShapes) {
442
- this.ctx.fillStyle = color;
443
- this.ctx.fill();
444
- } else {
445
- this.ctx.strokeStyle = color;
446
- this.ctx.stroke();
447
- }
448
- }
449
-
450
589
  /**
451
590
  * Draw the given (cubic) bézier curve.
452
591
  *
453
592
  * @method cubicBezier
454
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
455
- * @param {Vertex} endPoint - The end point the cubic Bézier curve.
456
- * @param {Vertex} startControlPoint - The start control point the cubic Bézier curve.
457
- * @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.
458
597
  * @param {string} color - The CSS color to draw the curve with.
459
598
  * @param {number} lineWidth - (optional) The line width to use.
599
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
600
+ *
460
601
  * @return {void}
461
602
  * @instance
462
603
  * @memberof drawutils
463
604
  */
464
605
  cubicBezier(
465
- startPoint: Vertex,
466
- endPoint: Vertex,
467
- startControlPoint: Vertex,
468
- endControlPoint: Vertex,
606
+ startPoint: XYCoords,
607
+ endPoint: XYCoords,
608
+ startControlPoint: XYCoords,
609
+ endControlPoint: XYCoords,
469
610
  color: string,
470
- lineWidth?: number
611
+ lineWidth?: number,
612
+ strokeOptions?: StrokeOptions
471
613
  ) {
472
614
  if (startPoint instanceof CubicBezierCurve) {
473
615
  this.cubicBezier(
@@ -483,6 +625,7 @@ export class drawutils implements DrawLib<void> {
483
625
  // Draw curve
484
626
  this.ctx.save();
485
627
  this.ctx.beginPath();
628
+ this.applyStrokeOpts(strokeOptions);
486
629
  this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
487
630
  this.ctx.bezierCurveTo(
488
631
  this.offset.x + startControlPoint.x * this.scale.x,
@@ -502,19 +645,29 @@ export class drawutils implements DrawLib<void> {
502
645
  * Draw the given (quadratic) bézier curve.
503
646
  *
504
647
  * @method quadraticBezier
505
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
506
- * @param {Vertex} controlPoint - The control point the cubic Bézier curve.
507
- * @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.
508
651
  * @param {string} color - The CSS color to draw the curve with.
509
652
  * @param {number|string} lineWidth - (optional) The line width to use.
653
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
654
+ *
510
655
  * @return {void}
511
656
  * @instance
512
657
  * @memberof drawutils
513
658
  */
514
- 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
+ ) {
515
667
  // Draw curve
516
668
  this.ctx.save();
517
669
  this.ctx.beginPath();
670
+ this.applyStrokeOpts(strokeOptions);
518
671
  this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
519
672
  this.ctx.quadraticCurveTo(
520
673
  this.offset.x + controlPoint.x * this.scale.x,
@@ -535,21 +688,26 @@ export class drawutils implements DrawLib<void> {
535
688
  * <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
536
689
  *
537
690
  * @method cubicBezierPath
538
- * @param {Vertex[]} path - The cubic bezier path as described above.
691
+ * @param {XYCoords[]} path - The cubic bezier path as described above.
539
692
  * @param {string} color - The CSS colot to draw the path with.
540
693
  * @param {number=1} lineWidth - (optional) The line width to use.
694
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
695
+ *
541
696
  * @return {void}
542
697
  * @instance
543
698
  * @memberof drawutils
544
699
  */
545
- cubicBezierPath(path: Array<Vertex>, color: string, lineWidth?: number) {
546
- 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
+ }
547
704
  // Draw curve
548
705
  this.ctx.save();
549
706
  this.ctx.beginPath();
550
- var endPoint: Vertex;
551
- var startControlPoint: Vertex;
552
- var endControlPoint: Vertex;
707
+ var endPoint: XYCoords;
708
+ var startControlPoint: XYCoords;
709
+ var endControlPoint: XYCoords;
710
+ this.applyStrokeOpts(strokeOptions);
553
711
  this.ctx.moveTo(this.offset.x + path[0].x * this.scale.x, this.offset.y + path[0].y * this.scale.y);
554
712
  for (var i = 1; i < path.length; i += 3) {
555
713
  startControlPoint = path[i];
@@ -576,13 +734,13 @@ export class drawutils implements DrawLib<void> {
576
734
  * The colors for this are fixed and cannot be specified.
577
735
  *
578
736
  * @method handle
579
- * @param {Vertex} startPoint - The start of the handle.
580
- * @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.
581
739
  * @return {void}
582
740
  * @instance
583
741
  * @memberof drawutils
584
742
  */
585
- handle(startPoint: Vertex, endPoint: Vertex) {
743
+ handle(startPoint: XYCoords, endPoint: XYCoords) {
586
744
  // Draw handles
587
745
  // (No need to save and restore here)
588
746
  this.point(startPoint, "rgb(0,32,192)");
@@ -593,30 +751,31 @@ export class drawutils implements DrawLib<void> {
593
751
  * Draw a handle line (with a light grey).
594
752
  *
595
753
  * @method handleLine
596
- * @param {Vertex} startPoint - The start point to draw the handle at.
597
- * @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.
598
756
  * @return {void}
599
757
  * @instance
600
758
  * @memberof drawutils
601
759
  */
602
- handleLine(startPoint: Vertex, endPoint: Vertex) {
760
+ handleLine(startPoint: XYCoords, endPoint: XYCoords) {
603
761
  // Draw handle lines
604
- this.line(startPoint, endPoint, "rgb(192,192,192)");
762
+ this.line(startPoint, endPoint, "rgba(128,128,128, 0.5)", undefined);
605
763
  }
606
764
 
607
765
  /**
608
766
  * Draw a 1x1 dot with the specified (CSS-) color.
609
767
  *
610
768
  * @method dot
611
- * @param {Vertex} p - The position to draw the dot at.
769
+ * @param {XYCoords} p - The position to draw the dot at.
612
770
  * @param {string} color - The CSS color to draw the dot with.
613
771
  * @return {void}
614
772
  * @instance
615
773
  * @memberof drawutils
616
774
  */
617
- dot(p: Vertex, color: string) {
775
+ dot(p: XYCoords, color: string) {
618
776
  this.ctx.save();
619
777
  this.ctx.beginPath();
778
+ this.ctx.setLineDash([]); // Clear line-dash settings
620
779
  this.ctx.moveTo(Math.round(this.offset.x + this.scale.x * p.x), Math.round(this.offset.y + this.scale.y * p.y));
621
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));
622
781
  this.ctx.closePath();
@@ -629,14 +788,15 @@ export class drawutils implements DrawLib<void> {
629
788
  * Draw the given point with the specified (CSS-) color and radius 3.
630
789
  *
631
790
  * @method point
632
- * @param {Vertex} p - The position to draw the point at.
791
+ * @param {XYCoords} p - The position to draw the point at.
633
792
  * @param {string} color - The CSS color to draw the point with.
634
793
  * @return {void}
635
794
  * @instance
636
795
  * @memberof drawutils
637
796
  */
638
- point(p: Vertex, color: string) {
797
+ point(p: XYCoords, color: string) {
639
798
  var radius: number = 3;
799
+ this.ctx.setLineDash([]); // Clear line-dash settings
640
800
  this.ctx.beginPath();
641
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);
642
802
  this.ctx.closePath();
@@ -650,15 +810,18 @@ export class drawutils implements DrawLib<void> {
650
810
  * Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
651
811
  *
652
812
  * @method circle
653
- * @param {Vertex} center - The center of the circle.
813
+ * @param {XYCoords} center - The center of the circle.
654
814
  * @param {number} radius - The radius of the circle.
655
815
  * @param {string} color - The CSS color to draw the circle with.
656
816
  * @param {number} lineWidth - The line width (optional, default=1).
817
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
818
+ *
657
819
  * @return {void}
658
820
  * @instance
659
821
  * @memberof drawutils
660
822
  */
661
- 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);
662
825
  this.ctx.beginPath();
663
826
  this.ctx.ellipse(
664
827
  this.offset.x + center.x * this.scale.x,
@@ -675,32 +838,36 @@ export class drawutils implements DrawLib<void> {
675
838
  }
676
839
 
677
840
  /**
678
- * Draw a circular arc (section of a circle) with the given CSS color.
679
- *
680
- * @method circleArc
681
- * @param {Vertex} center - The center of the circle.
682
- * @param {number} radius - The radius of the circle.
683
- * @param {number} startAngle - The angle to start at.
684
- * @param {number} endAngle - The angle to end at.
685
- * @param {string=#000000} color - The CSS color to draw the circle with.
686
- * @param {number=1} lineWidth - The line width to use
687
- // * @param {boolean=false} options.asSegment - If `true` then no beginPath and no draw will be applied (as part of larger path).
688
- * @return {void}
689
- * @instance
690
- * @memberof drawutils
691
- */
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
+ */
692
858
  circleArc(
693
- center: Vertex,
859
+ center: XYCoords,
694
860
  radius: number,
695
861
  startAngle: number,
696
862
  endAngle: number,
697
863
  color?: string,
698
864
  lineWidth?: number,
699
- options?: { asSegment?: boolean }
865
+ options?: { asSegment?: boolean } & StrokeOptions
700
866
  ) {
701
867
  if (!options || !options.asSegment) {
702
868
  this.ctx.beginPath();
703
869
  }
870
+ this.applyStrokeOpts(options);
704
871
  this.ctx.ellipse(
705
872
  this.offset.x + center.x * this.scale.x,
706
873
  this.offset.y + center.y * this.scale.y,
@@ -722,20 +889,31 @@ export class drawutils implements DrawLib<void> {
722
889
  * Draw an ellipse with the specified (CSS-) color and thw two radii.
723
890
  *
724
891
  * @method ellipse
725
- * @param {Vertex} center - The center of the ellipse.
892
+ * @param {XYCoords} center - The center of the ellipse.
726
893
  * @param {number} radiusX - The radius of the ellipse.
727
894
  * @param {number} radiusY - The radius of the ellipse.
728
895
  * @param {string} color - The CSS color to draw the ellipse with.
729
896
  * @param {number} lineWidth=1 - An optional line width param (default is 1).
730
897
  * @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
898
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
899
+ *
731
900
  * @return {void}
732
901
  * @instance
733
902
  * @memberof drawutils
734
903
  */
735
- 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
+ ) {
736
913
  if (typeof rotation === "undefined") {
737
914
  rotation = 0.0;
738
915
  }
916
+ this.applyStrokeOpts(strokeOptions);
739
917
  this.ctx.beginPath();
740
918
  this.ctx.ellipse(
741
919
  this.offset.x + center.x * this.scale.x,
@@ -761,11 +939,14 @@ export class drawutils implements DrawLib<void> {
761
939
  * @param {number} size - The size of the square.
762
940
  * @param {string} color - The CSS color to draw the square with.
763
941
  * @param {number} lineWidth - The line with to use (optional, default is 1).
942
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
943
+ *
764
944
  * @return {void}
765
945
  * @instance
766
946
  * @memberof drawutils
767
947
  */
768
- 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);
769
950
  this.ctx.beginPath();
770
951
  this.ctx.rect(
771
952
  this.offset.x + (center.x - size / 2.0) * this.scale.x,
@@ -782,7 +963,7 @@ export class drawutils implements DrawLib<void> {
782
963
  * Draw a grid of horizontal and vertical lines with the given (CSS-) color.
783
964
  *
784
965
  * @method grid
785
- * @param {Vertex} center - The center of the grid.
966
+ * @param {XYCoords} center - The center of the grid.
786
967
  * @param {number} width - The total width of the grid (width/2 each to the left and to the right).
787
968
  * @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
788
969
  * @param {number} sizeX - The horizontal grid size.
@@ -792,7 +973,8 @@ export class drawutils implements DrawLib<void> {
792
973
  * @instance
793
974
  * @memberof drawutils
794
975
  */
795
- 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
796
978
  this.ctx.beginPath();
797
979
  var yMin: number = -Math.ceil((height * 0.5) / sizeY) * sizeY;
798
980
  var yMax: number = height / 2;
@@ -819,7 +1001,7 @@ export class drawutils implements DrawLib<void> {
819
1001
  * This works analogue to the grid() function
820
1002
  *
821
1003
  * @method raster
822
- * @param {Vertex} center - The center of the raster.
1004
+ * @param {XYCoords} center - The center of the raster.
823
1005
  * @param {number} width - The total width of the raster (width/2 each to the left and to the right).
824
1006
  * @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
825
1007
  * @param {number} sizeX - The horizontal raster size.
@@ -829,8 +1011,9 @@ export class drawutils implements DrawLib<void> {
829
1011
  * @instance
830
1012
  * @memberof drawutils
831
1013
  */
832
- 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) {
833
1015
  this.ctx.save();
1016
+ this.ctx.setLineDash([]); // Clear line-dash settings
834
1017
  this.ctx.beginPath();
835
1018
  for (var x = -Math.ceil((width * 0.5) / sizeX) * sizeX; x < width / 2; x += sizeX) {
836
1019
  for (var y = -Math.ceil((height * 0.5) / sizeY) * sizeY; y < height / 2; y += sizeY) {
@@ -856,14 +1039,15 @@ export class drawutils implements DrawLib<void> {
856
1039
  * as even shaped diamonds.
857
1040
  *
858
1041
  * @method diamondHandle
859
- * @param {Vertex} center - The center of the diamond.
860
- * @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.
861
1044
  * @param {string} color - The CSS color to draw the diamond with.
862
1045
  * @return {void}
863
1046
  * @instance
864
1047
  * @memberof drawutils
865
1048
  */
866
- diamondHandle(center: Vertex, size: number, color: string) {
1049
+ diamondHandle(center: XYCoords, size: number, color: string) {
1050
+ this.ctx.setLineDash([]); // Clear line-dash settings
867
1051
  this.ctx.beginPath();
868
1052
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - size / 2.0, this.offset.y + center.y * this.scale.y);
869
1053
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y - size / 2.0);
@@ -882,14 +1066,15 @@ export class drawutils implements DrawLib<void> {
882
1066
  * as even shaped squares.
883
1067
  *
884
1068
  * @method squareHandle
885
- * @param {Vertex} center - The center of the square.
886
- * @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.
887
1071
  * @param {string} color - The CSS color to draw the square with.
888
1072
  * @return {void}
889
1073
  * @instance
890
1074
  * @memberof drawutils
891
1075
  */
892
- squareHandle(center: Vertex, size: number, color: string) {
1076
+ squareHandle(center: XYCoords, size: number, color: string) {
1077
+ this.ctx.setLineDash([]); // Clear line-dash settings
893
1078
  this.ctx.beginPath();
894
1079
  this.ctx.rect(
895
1080
  this.offset.x + center.x * this.scale.x - size / 2.0,
@@ -910,15 +1095,17 @@ export class drawutils implements DrawLib<void> {
910
1095
  * as even shaped circles.
911
1096
  *
912
1097
  * @method circleHandle
913
- * @param {Vertex} center - The center of the circle.
1098
+ * @param {XYCoords} center - The center of the circle.
914
1099
  * @param {number} radius - The radius of the circle.
915
1100
  * @param {string} color - The CSS color to draw the circle with.
916
1101
  * @return {void}
917
1102
  * @instance
918
1103
  * @memberof drawutils
919
1104
  */
920
- circleHandle(center: Vertex, radius: number, color: string) {
1105
+ circleHandle(center: XYCoords, radius: number, color: string) {
921
1106
  radius = radius || 3;
1107
+ this.ctx.setLineDash([]); // Clear line-dash settings
1108
+
922
1109
  this.ctx.beginPath();
923
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);
924
1111
  this.ctx.closePath();
@@ -942,6 +1129,7 @@ export class drawutils implements DrawLib<void> {
942
1129
  */
943
1130
  crosshair(center: XYCoords, radius: number, color: string, lineWidth?: number) {
944
1131
  this.ctx.save();
1132
+ this.ctx.setLineDash([]); // Clear line-dash settings
945
1133
  this.ctx.beginPath();
946
1134
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y);
947
1135
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y);
@@ -970,6 +1158,7 @@ export class drawutils implements DrawLib<void> {
970
1158
  */
971
1159
  cross(center: XYCoords, radius: number, color: string, lineWidth?: number) {
972
1160
  this.ctx.save();
1161
+ this.ctx.setLineDash([]); // Clear line-dash settings
973
1162
  this.ctx.beginPath();
974
1163
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y - radius);
975
1164
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y + radius);
@@ -989,31 +1178,36 @@ export class drawutils implements DrawLib<void> {
989
1178
  * @param {Polygon} polygon - The polygon to draw.
990
1179
  * @param {string} color - The CSS color to draw the polygon with.
991
1180
  * @param {string} lineWidth - The line width to use.
1181
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
1182
+ *
992
1183
  * @return {void}
993
1184
  * @instance
994
1185
  * @memberof drawutils
995
1186
  */
996
- polygon(polygon: Polygon, color: string, lineWidth?: number) {
997
- 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);
998
1189
  }
999
1190
 
1000
1191
  /**
1001
1192
  * Draw a polygon line (alternative function to the polygon).
1002
1193
  *
1003
1194
  * @method polyline
1004
- * @param {Vertex[]} vertices - The polygon vertices to draw.
1195
+ * @param {XYCoords[]} vertices - The polygon vertices to draw.
1005
1196
  * @param {boolan} isOpen - If true the polyline will not be closed at its end.
1006
1197
  * @param {string} color - The CSS color to draw the polygon with.
1007
1198
  * @param {number} lineWidth - The line width (default is 1.0);
1199
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
1200
+ *
1008
1201
  * @return {void}
1009
1202
  * @instance
1010
1203
  * @memberof drawutils
1011
1204
  */
1012
- polyline(vertices: Array<Vertex>, isOpen: boolean, color: string, lineWidth?: number) {
1205
+ polyline(vertices: Array<XYCoords>, isOpen: boolean, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) {
1013
1206
  if (vertices.length <= 1) {
1014
1207
  return;
1015
1208
  }
1016
1209
  this.ctx.save();
1210
+ this.applyStrokeOpts(strokeOptions);
1017
1211
  this.ctx.beginPath();
1018
1212
  this.ctx.lineWidth = (lineWidth || 1.0) * this.scale.x;
1019
1213
  this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
@@ -1143,17 +1337,20 @@ export class drawutils implements DrawLib<void> {
1143
1337
  * @param {string=null} color - (optional) The color to draw this path with (default is null).
1144
1338
  * @param {number=1} lineWidth - (optional) the line width to use (default is 1).
1145
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`.
1146
1342
  * @instance
1147
1343
  * @memberof drawutils
1148
1344
  * @return {R} An instance representing the drawn path.
1149
1345
  */
1150
- path(pathData: SVGPathParams, color?: string, lineWidth?: number, options?: { inplace?: boolean }) {
1346
+ path(pathData: SVGPathParams, color?: string, lineWidth?: number, options?: { inplace?: boolean } & StrokeOptions) {
1151
1347
  const d: SVGPathParams = options && options.inplace ? pathData : drawutilssvg.copyPathData(pathData);
1152
1348
  drawutilssvg.transformPathData(d, this.offset, this.scale);
1153
1349
  if (color) {
1154
1350
  this.ctx.strokeStyle = color;
1155
1351
  }
1156
1352
  this.ctx.lineWidth = lineWidth || 1;
1353
+ this.applyStrokeOpts(options);
1157
1354
  if (this.fillShapes) {
1158
1355
  if (color) {
1159
1356
  this.ctx.fillStyle = color;