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
@@ -18,6 +18,13 @@
18
18
  * @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
19
19
  * @modified 2022-02-03 Added the `cross(...)` function.
20
20
  * @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
21
+ * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
22
+ * @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.
23
+ * @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
24
+ * @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
25
+ * @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
26
+ * @modified 2023-09-29 Added the `lineDashes` attribute.
27
+ * @modified 2023-09-30 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
21
28
  **/
22
29
  import { Bounds } from "../Bounds";
23
30
  import { Polygon } from "../Polygon";
@@ -38,6 +45,19 @@ export interface FontOptions {
38
45
  textAlign?: CanvasRenderingContext2D["textAlign"];
39
46
  rotation?: number;
40
47
  }
48
+ /**
49
+ * Defines a line-dash configuration.
50
+ *
51
+ * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
52
+ * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
53
+ * for how line dashes work.
54
+ *
55
+ * Setting line-dash to empty array `[]` resets the dashing.
56
+ */
57
+ export interface StrokeOptions {
58
+ dashOffset?: number;
59
+ dashArray?: Array<number>;
60
+ }
41
61
  /**
42
62
  * An interface all drawing libraries must implement to be used with PlotBoilerplate.
43
63
  *
@@ -66,16 +86,16 @@ export interface DrawLib<R> {
66
86
  * @method
67
87
  * @param {UID|null} uid - A UID identifying the currently drawn element(s), or null to clear.
68
88
  **/
69
- setCurrentId: (uid: UID | undefined) => void;
89
+ setCurrentId: (uid: UID | null) => void;
70
90
  /**
71
91
  * This method shouled be called each time the currently drawn `Drawable` changes.
72
92
  * Determine the class name for further usage here.
73
93
  *
74
94
  * @name setCurrentClassName
75
95
  * @method
76
- * @param {string} className - A class name for further custom use cases.
96
+ * @param {string|null} className - A class name for further custom use cases.
77
97
  **/
78
- setCurrentClassName: (className: string | undefined) => void;
98
+ setCurrentClassName: (className: string | null) => void;
79
99
  /**
80
100
  * Called before each draw cycle.
81
101
  *
@@ -102,28 +122,65 @@ export interface DrawLib<R> {
102
122
  * Draw the line between the given two points with the specified (CSS-) color.
103
123
  *
104
124
  * @method line
105
- * @param {Vertex} zA - The start point of the line.
106
- * @param {Vertex} zB - The end point of the line.
125
+ * @param {XYCoords} zA - The start point of the line.
126
+ * @param {XYCoords} zB - The end point of the line.
107
127
  * @param {string} color - Any valid CSS color string.
108
- * @param {number=1} lineWidth? - [optional] The line's width.
109
- * @return {void}
128
+ * @param {number=1} lineWidth? - (optional) The line's width.
129
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
130
+ * @return {R}
110
131
  * @instance
111
132
  * @memberof DrawLib
112
133
  **/
113
- line: (zA: Vertex, zB: Vertex, color: string, lineWidth?: number) => R;
134
+ line: (zA: XYCoords, zB: XYCoords, color: string, lineWidth?: number, strokeOptopns?: StrokeOptions) => R;
114
135
  /**
115
- * Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
136
+ * Draw a line and an arrow at the end (zB) of the given line width the specified (CSS-) color and size.
116
137
  *
117
138
  * @method arrow
118
- * @param {Vertex} zA - The start point of the arrow-line.
119
- * @param {Vertex} zB - The end point of the arrow-line.
139
+ * @param {XYCoords} zA - The start point of the arrow-line.
140
+ * @param {XYCoords} zB - The end point of the arrow-line.
120
141
  * @param {string} color - Any valid CSS color string.
121
- * @param {number=} lineWidth - (optional) The line width to use; default is 1.
122
- * @return {void}
142
+ * @param {number=1} lineWidth - (optional) The line width to use; default is 1.
143
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
144
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
145
+ * @return {R}
146
+ * @instance
147
+ * @memberof DrawLib
148
+ **/
149
+ arrow: (zA: XYCoords, zB: XYCoords, color: string, lineWidth?: number, headLength?: number, strokeOptopns?: StrokeOptions) => R;
150
+ /**
151
+ * 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.
152
+ *
153
+ * @method cubicBezierArrow
154
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
155
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
156
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
157
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
158
+ * @param {string} color - The CSS color to draw the curve with.
159
+ * @param {number} lineWidth - (optional) The line width to use.
160
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
161
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
162
+ *
163
+ * @return {R}
164
+ * @instance
165
+ * @memberof DrawLib
166
+ */
167
+ cubicBezierArrow: (startPoint: XYCoords, endPoint: XYCoords, startControlPoint: XYCoords, endControlPoint: XYCoords, color: string, lineWidth?: number, headLength?: number, strokeOptopns?: StrokeOptions) => R;
168
+ /**
169
+ * Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
170
+ *
171
+ * @method arrow
172
+ * @param {XYCoords} zA - The start point of the arrow-line.
173
+ * @param {XYCoords} zB - The end point of the arrow-line.
174
+ * @param {string} color - Any valid CSS color string.
175
+ * @param {number=1} lineWidth - (optional) The line width to use; default is 1.
176
+ * @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
177
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
178
+ *
179
+ * @return {R}
123
180
  * @instance
124
181
  * @memberof DrawLib
125
182
  **/
126
- arrow: (zA: Vertex, zB: Vertex, color: string, lineWidth?: number) => R;
183
+ arrowHead: (zA: XYCoords, zB: XYCoords, color: string, lineWidth?: number, headLength?: number, strokeOptopns?: StrokeOptions) => R;
127
184
  /**
128
185
  * Draw an image at the given position with the given size.<br>
129
186
  * <br>
@@ -131,14 +188,14 @@ export interface DrawLib<R> {
131
188
  *
132
189
  * @method image
133
190
  * @param {Image} image - The image object to draw.
134
- * @param {Vertex} position - The position to draw the the upper left corner at.
135
- * @param {Vertex} size - The x/y-size to draw the image with.
191
+ * @param {XYCoords} position - The position to draw the the upper left corner at.
192
+ * @param {XYCoords} size - The x/y-size to draw the image with.
136
193
  * @param {number=1.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
137
- * @return {void}
194
+ * @return {R}
138
195
  * @instance
139
196
  * @memberof DrawLib
140
197
  **/
141
- image: (image: HTMLImageElement, position: Vertex, size: Vertex, alpha?: number) => R;
198
+ image: (image: HTMLImageElement, position: XYCoords, size: XYCoords, alpha?: number) => R;
142
199
  /**
143
200
  * Draw an image at the given position with the given size.<br>
144
201
  * <br>
@@ -148,28 +205,30 @@ export interface DrawLib<R> {
148
205
  * @param {Image} textureImage - The image object to draw.
149
206
  * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
150
207
  * @param {Polygon} polygon - The polygon to use as clip path.
151
- * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
208
+ * @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
152
209
  * @param {number} rotation - The rotation to use for the polygon (and for the texture).
153
210
  * @return {void}
154
211
  * @instance
155
212
  * @memberof DrawLib
156
213
  **/
157
- texturedPoly: (textureImage: HTMLImageElement, textureSize: Bounds, polygon: Polygon, polygonPosition: Vertex, rotation: number) => R;
214
+ texturedPoly: (textureImage: HTMLImageElement, textureSize: Bounds, polygon: Polygon, polygonPosition: XYCoords, rotation: number) => R;
158
215
  /**
159
216
  * Draw the given (cubic) bézier curve.
160
217
  *
161
218
  * @method cubicBezier
162
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
163
- * @param {Vertex} endPoint - The end point the cubic Bézier curve.
164
- * @param {Vertex} startControlPoint - The start control point the cubic Bézier curve.
165
- * @param {Vertex} endControlPoint - The end control point the cubic Bézier curve.
219
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
220
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
221
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
222
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
166
223
  * @param {string} color - The CSS color to draw the curve with.
167
224
  * @param {number} lineWidth - (optional) The line width to use.
168
- * @return {void}
225
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
226
+ *
227
+ * @return {R}
169
228
  * @instance
170
229
  * @memberof DrawLib
171
230
  */
172
- cubicBezier: (startPoint: Vertex, endPoint: Vertex, startControlPoint: Vertex, endControlPoint: Vertex, color: string, lineWidth?: number) => R;
231
+ cubicBezier: (startPoint: XYCoords, endPoint: XYCoords, startControlPoint: XYCoords, endControlPoint: XYCoords, color: string, lineWidth?: number, strokeOptopns?: StrokeOptions) => R;
173
232
  /**
174
233
  * Draw the given (cubic) Bézier path.
175
234
  *
@@ -178,105 +237,113 @@ export interface DrawLib<R> {
178
237
  * <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
179
238
  *
180
239
  * @method cubicBezierPath
181
- * @param {Vertex[]} path - The cubic bezier path as described above.
240
+ * @param {XYCoords[]} path - The cubic bezier path as described above.
182
241
  * @param {string} color - The CSS colot to draw the path with.
183
242
  * @param {number=1} lineWidth - (optional) The line width to use.
184
- * @return {void}
243
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
244
+ *
245
+ * @return {R}
185
246
  * @instance
186
247
  * @memberof DrawLib
187
248
  */
188
- cubicBezierPath: (path: Array<Vertex>, color: string, lineWidth?: number) => R;
249
+ cubicBezierPath: (path: Array<XYCoords>, color: string, lineWidth?: number, strokeOptopns?: StrokeOptions) => R;
189
250
  /**
190
251
  * Draw the given handle and handle point (used to draw interactive Bézier curves).
191
252
  *
192
253
  * The colors for this are fixed and cannot be specified.
193
254
  *
194
255
  * @method handle
195
- * @param {Vertex} startPoint - The start of the handle.
196
- * @param {Vertex} endPoint - The end point of the handle.
197
- * @return {void}
256
+ * @param {XYCoords} startPoint - The start of the handle.
257
+ * @param {XYCoords} endPoint - The end point of the handle.
258
+ * @return {R}
198
259
  * @instance
199
260
  * @memberof DrawLib
200
261
  */
201
- handle: (startPoint: Vertex, endPoint: Vertex) => R;
262
+ handle: (startPoint: XYCoords, endPoint: XYCoords) => R;
202
263
  /**
203
264
  * Draw a handle line (with a light grey).
204
265
  *
205
266
  * @method handleLine
206
- * @param {Vertex} startPoint - The start point to draw the handle at.
207
- * @param {Vertex} endPoint - The end point to draw the handle at.
208
- * @return {void}
267
+ * @param {XYCoords} startPoint - The start point to draw the handle at.
268
+ * @param {XYCoords} endPoint - The end point to draw the handle at.
269
+ * @return {R}
209
270
  * @instance
210
271
  * @memberof DrawLib
211
272
  */
212
- handleLine: (startPoint: Vertex, endPoint: Vertex) => R;
273
+ handleLine: (startPoint: XYCoords, endPoint: XYCoords) => R;
213
274
  /**
214
275
  * Draw a 1x1 dot with the specified (CSS-) color.
215
276
  *
216
277
  * @method dot
217
- * @param {Vertex} p - The position to draw the dot at.
278
+ * @param {XYCoords} p - The position to draw the dot at.
218
279
  * @param {string} color - The CSS color to draw the dot with.
219
- * @return {void}
280
+ * @return {R}
220
281
  * @instance
221
282
  * @memberof DrawLib
222
283
  */
223
- dot: (p: Vertex, color: string) => R;
284
+ dot: (p: XYCoords, color: string) => R;
224
285
  /**
225
286
  * Draw the given point with the specified (CSS-) color and radius 3.
226
287
  *
227
288
  * @method point
228
- * @param {Vertex} p - The position to draw the point at.
229
- * @param {string} color - The CSS color to draw the point with.
230
- * @return {void}
289
+ * @param {XYCoords} p - The position to draw the point at.
290
+ * @param {XYCoords} color - The CSS color to draw the point with.
291
+ * @return {R}
231
292
  * @instance
232
293
  * @memberof DrawLib
233
294
  */
234
- point: (p: Vertex, color: string) => R;
295
+ point: (p: XYCoords, color: string) => R;
235
296
  /**
236
297
  * Draw a circle with the specified (CSS-) color and radius.<br>
237
298
  * <br>
238
299
  * Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
239
300
  *
240
301
  * @method circle
241
- * @param {Vertex} center - The center of the circle.
302
+ * @param {XYCoords} center - The center of the circle.
242
303
  * @param {number} radius - The radius of the circle.
243
304
  * @param {string} color - The CSS color to draw the circle with.
244
305
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
245
- * @return {void}
306
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
307
+ *
308
+ * @return {R}
246
309
  * @instance
247
310
  * @memberof DrawLib
248
311
  */
249
- circle: (center: Vertex, radius: number, color: string, lineWidth?: number) => R;
312
+ circle: (center: XYCoords, radius: number, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) => R;
250
313
  /**
251
314
  * Draw a circular arc (section of a circle) with the given CSS color.
252
315
  *
253
316
  * @method circleArc
254
- * @param {Vertex} center - The center of the circle.
317
+ * @param {XYCoords} center - The center of the circle.
255
318
  * @param {number} radius - The radius of the circle.
256
319
  * @param {number} startAngle - The angle to start at.
257
320
  * @param {number} endAngle - The angle to end at.
258
321
  * @param {string} color - The CSS color to draw the circle with.
259
322
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
260
- * @return {void}
323
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
324
+ *
325
+ * @return {R}
261
326
  * @instance
262
327
  * @memberof DrawLib
263
328
  */
264
- circleArc: (center: Vertex, radius: number, startAngle: number, endAngle: number, color: string, lineWidth?: number) => R;
329
+ circleArc: (center: XYCoords, radius: number, startAngle: number, endAngle: number, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) => R;
265
330
  /**
266
331
  * Draw an ellipse with the specified (CSS-) color and thw two radii.
267
332
  *
268
333
  * @method ellipse
269
- * @param {Vertex} center - The center of the ellipse.
334
+ * @param {XYCoords} center - The center of the ellipse.
270
335
  * @param {number} radiusX - The radius of the ellipse.
271
336
  * @param {number} radiusY - The radius of the ellipse.
272
337
  * @param {string} color - The CSS color to draw the ellipse with.
273
338
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
274
339
  * @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
275
- * @return {void}
340
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
341
+ *
342
+ * @return {R}
276
343
  * @instance
277
344
  * @memberof DrawLib
278
345
  */
279
- ellipse: (center: Vertex, radiusX: number, radiusY: number, color: string, lineWidth?: number, rotation?: number) => R;
346
+ ellipse: (center: XYCoords, radiusX: number, radiusY: number, color: string, lineWidth?: number, rotation?: number, strokeOptions?: StrokeOptions) => R;
280
347
  /**
281
348
  * Draw square at the given center, size and with the specified (CSS-) color.<br>
282
349
  * <br>
@@ -287,11 +354,13 @@ export interface DrawLib<R> {
287
354
  * @param {number} size - The size of the square.
288
355
  * @param {string} color - The CSS color to draw the square with.
289
356
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
290
- * @return {void}
357
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
358
+ *
359
+ * @return {R}
291
360
  * @instance
292
361
  * @memberof DrawLib
293
362
  */
294
- square: (center: XYCoords, size: number, color: string, lineWidth?: number) => R;
363
+ square: (center: XYCoords, size: number, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) => R;
295
364
  /**
296
365
  * Draw a rectangle at the given left upper corner, with, height; and with the specified line width and (CSS-) color.<br>
297
366
  *
@@ -301,43 +370,45 @@ export interface DrawLib<R> {
301
370
  * @param {number} height - The height of the rectangle.
302
371
  * @param {string} color - The CSS color to draw the rectangle with.
303
372
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
304
- * @return {void}
373
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
374
+ *
375
+ * @return {R}
305
376
  * @instance
306
377
  * @memberof DrawLib
307
378
  */
308
- rect: (upperLeft: XYCoords, width: number, height: number, color: string, lineWidth?: number) => R;
379
+ rect: (upperLeft: XYCoords, width: number, height: number, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) => R;
309
380
  /**
310
381
  * Draw a grid of horizontal and vertical lines with the given (CSS-) color.
311
382
  *
312
383
  * @method grid
313
- * @param {Vertex} center - The center of the grid.
384
+ * @param {XYCoords} center - The center of the grid.
314
385
  * @param {number} width - The total width of the grid (width/2 each to the left and to the right).
315
386
  * @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
316
387
  * @param {number} sizeX - The horizontal grid size.
317
388
  * @param {number} sizeY - The vertical grid size.
318
389
  * @param {string} color - The CSS color to draw the grid with.
319
- * @return {void}
390
+ * @return {R}
320
391
  * @instance
321
392
  * @memberof DrawLib
322
393
  */
323
- grid: (center: Vertex, width: number, height: number, sizeX: number, sizeY: number, color: string) => R;
394
+ grid: (center: XYCoords, width: number, height: number, sizeX: number, sizeY: number, color: string) => R;
324
395
  /**
325
396
  * Draw a raster of crosshairs in the given grid.<br>
326
397
  *
327
398
  * This works analogue to the grid() function
328
399
  *
329
400
  * @method raster
330
- * @param {Vertex} center - The center of the raster.
401
+ * @param {XYCoords} center - The center of the raster.
331
402
  * @param {number} width - The total width of the raster (width/2 each to the left and to the right).
332
403
  * @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
333
404
  * @param {number} sizeX - The horizontal raster size.
334
405
  * @param {number} sizeY - The vertical raster size.
335
406
  * @param {string} color - The CSS color to draw the raster with.
336
- * @return {void}
407
+ * @return {R}
337
408
  * @instance
338
409
  * @memberof DrawLib
339
410
  */
340
- raster: (center: Vertex, width: number, height: number, sizeX: number, sizeY: number, color: string) => R;
411
+ raster: (center: XYCoords, width: number, height: number, sizeX: number, sizeY: number, color: string) => R;
341
412
  /**
342
413
  * Draw a diamond handle (square rotated by 45°) with the given CSS color.
343
414
  *
@@ -346,14 +417,14 @@ export interface DrawLib<R> {
346
417
  * as even shaped diamonds.
347
418
  *
348
419
  * @method diamondHandle
349
- * @param {Vertex} center - The center of the diamond.
350
- * @param {Vertex} size - The x/y-size of the diamond.
420
+ * @param {XYCoords} center - The center of the diamond.
421
+ * @param {number} size - The x/y-size of the diamond.
351
422
  * @param {string} color - The CSS color to draw the diamond with.
352
- * @return {void}
423
+ * @return {R}
353
424
  * @instance
354
425
  * @memberof DrawLib
355
426
  */
356
- diamondHandle: (center: Vertex, size: number, color: string) => R;
427
+ diamondHandle: (center: XYCoords, size: number, color: string) => R;
357
428
  /**
358
429
  * Draw a square handle with the given CSS color.<br>
359
430
  * <br>
@@ -362,14 +433,14 @@ export interface DrawLib<R> {
362
433
  * as even shaped squares.
363
434
  *
364
435
  * @method squareHandle
365
- * @param {Vertex} center - The center of the square.
366
- * @param {Vertex} size - The x/y-size of the square.
436
+ * @param {XYCoords} center - The center of the square.
437
+ * @param {number} size - The x/y-size of the square.
367
438
  * @param {string} color - The CSS color to draw the square with.
368
- * @return {void}
439
+ * @return {R}
369
440
  * @instance
370
441
  * @memberof DrawLib
371
442
  */
372
- squareHandle: (center: Vertex, size: number, color: string) => R;
443
+ squareHandle: (center: XYCoords, size: number, color: string) => R;
373
444
  /**
374
445
  * Draw a circle handle with the given CSS color.<br>
375
446
  * <br>
@@ -378,14 +449,14 @@ export interface DrawLib<R> {
378
449
  * as even shaped circles.
379
450
  *
380
451
  * @method circleHandle
381
- * @param {Vertex} center - The center of the circle.
452
+ * @param {XYCoords} center - The center of the circle.
382
453
  * @param {number} radius - The radius of the circle.
383
454
  * @param {string} color - The CSS color to draw the circle with.
384
- * @return {void}
455
+ * @return {R}
385
456
  * @instance
386
457
  * @memberof DrawLib
387
458
  */
388
- circleHandle: (center: Vertex, size: number, color: string) => R;
459
+ circleHandle: (center: XYCoords, size: number, color: string) => R;
389
460
  /**
390
461
  * Draw a crosshair with given radius and color at the given position.<br>
391
462
  * <br>
@@ -396,7 +467,7 @@ export interface DrawLib<R> {
396
467
  * @param {number} radius - The radius of the crosshair.
397
468
  * @param {string} color - The CSS color to draw the crosshair with.
398
469
  * @param {number=0.5} lineWidth - (optional, default=0.5) The line width to use.
399
- * @return {void}
470
+ * @return {R}
400
471
  * @instance
401
472
  * @memberof DrawLib
402
473
  */
@@ -411,7 +482,7 @@ export interface DrawLib<R> {
411
482
  * @param {number} radius - The radius of the crosshair.
412
483
  * @param {string} color - The CSS color to draw the crosshair with.
413
484
  * @param {number=1} lineWidth - (optional, default=1.0) The line width to use.
414
- * @return {void}
485
+ * @return {R}
415
486
  * @instance
416
487
  * @memberof DrawLib
417
488
  */
@@ -422,24 +493,29 @@ export interface DrawLib<R> {
422
493
  * @method polygon
423
494
  * @param {Polygon} polygon - The polygon to draw.
424
495
  * @param {string} color - The CSS color to draw the polygon with.
425
- * @return {void}
496
+ * @param {number=} lineWidth - The line width to draw this polygon with.
497
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
498
+ *
499
+ * @return {R}
426
500
  * @instance
427
501
  * @memberof DrawLib
428
502
  */
429
- polygon: (polygon: Polygon, color: string, lineWidth?: number) => R;
503
+ polygon: (polygon: Polygon, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) => R;
430
504
  /**
431
505
  * Draw a polygon line (alternative function to the polygon).
432
506
  *
433
507
  * @method polyline
434
- * @param {Vertex[]} vertices - The polygon vertices to draw.
508
+ * @param {XYCoords[]} vertices - The polygon vertices to draw.
435
509
  * @param {boolan} isOpen - If true the polyline will not be closed at its end.
436
510
  * @param {string} color - The CSS color to draw the polygon with.
437
511
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
438
- * @return {void}
512
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
513
+ *
514
+ * @return {R}
439
515
  * @instance
440
516
  * @memberof DrawLib
441
517
  */
442
- polyline: (vertices: Array<Vertex>, isOpen: boolean, color: string, lineWidth?: number) => R;
518
+ polyline: (vertices: Array<XYCoords>, isOpen: boolean, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) => R;
443
519
  /**
444
520
  * Draw a text at the given relative position.
445
521
  *
@@ -482,13 +558,16 @@ export interface DrawLib<R> {
482
558
  * @param {string=null} color - (optional) The color to draw this path with (default is null).
483
559
  * @param {number=1} lineWidth - (optional) the line width to use (default is 1).
484
560
  * @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.
561
+ * @param {number=} options.dashOffset - See `StrokeOptions`.
562
+ * @param {number[]=} options.dashArray - See `StrokeOptions`.
563
+ *
485
564
  * @instance
486
565
  * @memberof DrawLib
487
566
  * @return {R} An instance representing the drawn path.
488
567
  */
489
568
  path: (pathData: SVGPathParams, color?: string, lineWidth?: number, options?: {
490
569
  inplace?: boolean;
491
- }) => R;
570
+ } & StrokeOptions) => R;
492
571
  /**
493
572
  * Due to gl compatibility there is a generic 'clear' function required
494
573
  * to avoid accessing the context object itself directly.
@@ -19,6 +19,13 @@
19
19
  * @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
20
20
  * @modified 2022-02-03 Added the `cross(...)` function.
21
21
  * @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
22
+ * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
23
+ * @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.
24
+ * @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
25
+ * @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
26
+ * @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
27
+ * @modified 2023-09-29 Added the `lineDashes` attribute.
28
+ * @modified 2023-09-30 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
22
29
  **/
23
30
  Object.defineProperty(exports, "__esModule", { value: true });
24
31
  //# sourceMappingURL=DrawLib.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DrawLib.js","sourceRoot":"","sources":["../../ts/interfaces/DrawLib.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;IAoBI"}
1
+ {"version":3,"file":"DrawLib.js","sourceRoot":"","sources":["../../ts/interfaces/DrawLib.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2BI"}
@@ -17,6 +17,8 @@
17
17
  * @modified 2022-08-01 Added `title` param to the `PBParams` interface.
18
18
  * @modified 2022-10-25 Added `origin` param to the `DrawConfig` interface.
19
19
  * @modified 2022-11-23 Added `drawRaster` to the `Config` interface.
20
+ * @modified 2023-02-10 All non-function attributes of the `Config` interface are now mandatory.
21
+ * @modified 2023-09-29 Added the `randomPoint(...)` function declaration to the IBounds interface.
20
22
  **/
21
23
  import { Vertex } from "../Vertex";
22
24
  import { Vector } from "../Vector";
@@ -62,6 +64,16 @@ export interface IBounds {
62
64
  min: XYCoords;
63
65
  max: XYCoords;
64
66
  getCenter(): Vertex;
67
+ /**
68
+ * Generate a random point inside this bounds object. Safe areas at the border to avoid
69
+ * included.
70
+ *
71
+ * @method randomPoint
72
+ * @param {horizontalSafeArea} - (optional) The horizonal (left and right) safe area. No vertex will be created here. Can be used as percent in (0.0 ... 0.1) interval.
73
+ * @param {verticalSafeArea} - (optional) The vertical (top and bottom) safe area. No vertex will be created here. Can be used as percent in (0.0 ... 0.1) interval
74
+ * @returns {Vertex} A pseudo random point inside these bounds.
75
+ */
76
+ randomPoint: (horizontalSafeArea?: number, verticalSafeArea?: number) => Vertex;
65
77
  }
66
78
  /**
67
79
  * The types that can be drawn and thus added to the draw queue.
@@ -81,44 +93,46 @@ export interface CanvasWrapper {
81
93
  /**
82
94
  * The config that's used by PB.
83
95
  */
84
- export interface Config {
85
- canvas: HTMLCanvasElement | string;
86
- fullSize?: boolean;
87
- fitToParent?: boolean;
88
- scaleX?: number;
89
- scaleY?: number;
90
- offsetX?: number;
91
- offsetY?: number;
92
- rasterGrid?: boolean;
93
- drawRaster?: boolean;
94
- rasterScaleX?: number;
95
- rasterScaleY?: number;
96
- rasterAdjustFactor?: number;
97
- drawOrigin?: boolean;
98
- autoAdjustOffset?: boolean;
99
- offsetAdjustXPercent?: number;
100
- offsetAdjustYPercent?: number;
101
- defaultCanvasWidth?: number;
102
- defaultCanvasHeight?: number;
103
- canvasWidthFactor?: number;
104
- canvasHeightFactor?: number;
105
- cssScaleX?: number;
106
- cssScaleY?: number;
107
- cssUniformScale?: boolean;
108
- backgroundColor?: string;
109
- redrawOnResize?: boolean;
96
+ export interface Config extends Record<string, boolean | number | string | Function | HTMLCanvasElement | SVGElement | undefined> {
97
+ canvas: HTMLCanvasElement | SVGElement | string;
98
+ fullSize: boolean;
99
+ fitToParent: boolean;
100
+ scaleX: number;
101
+ scaleY: number;
102
+ offsetX: number;
103
+ offsetY: number;
104
+ rasterGrid: boolean;
105
+ drawRaster: boolean;
106
+ rasterScaleX: number;
107
+ rasterScaleY: number;
108
+ rasterAdjustFactor: number;
109
+ drawOrigin: boolean;
110
+ autoAdjustOffset: boolean;
111
+ offsetAdjustXPercent: number;
112
+ offsetAdjustYPercent: number;
113
+ defaultCanvasWidth: number;
114
+ defaultCanvasHeight: number;
115
+ canvasWidthFactor: number;
116
+ canvasHeightFactor: number;
117
+ cssScaleX: number;
118
+ cssScaleY: number;
119
+ cssUniformScale: boolean;
120
+ backgroundColor: string;
121
+ redrawOnResize: boolean;
110
122
  preClear?: () => void;
111
123
  preDraw?: (draw: DrawLib<any>, fill: DrawLib<any>) => void;
112
124
  postDraw?: (draw: DrawLib<any>, fill: DrawLib<any>) => void;
113
- enableMouse?: boolean;
114
- enableTouch?: boolean;
115
- enableKeys?: boolean;
116
- enableMouseWheel?: boolean;
125
+ enableMouse: boolean;
126
+ enableTouch: boolean;
127
+ enableKeys: boolean;
128
+ enableMouseWheel: boolean;
129
+ enableZoom: boolean;
130
+ enablePan: boolean;
117
131
  enableGL?: boolean;
118
- enableSVGExport?: boolean;
132
+ enableSVGExport: boolean;
119
133
  saveFile?: () => void;
120
134
  setToRetina?: () => void;
121
- autoDetectRetina?: boolean;
135
+ autoDetectRetina: boolean;
122
136
  }
123
137
  /**
124
138
  * For initialization the constructor needs a mix of config and draw-settings.
@@ -18,6 +18,8 @@
18
18
  * @modified 2022-08-01 Added `title` param to the `PBParams` interface.
19
19
  * @modified 2022-10-25 Added `origin` param to the `DrawConfig` interface.
20
20
  * @modified 2022-11-23 Added `drawRaster` to the `Config` interface.
21
+ * @modified 2023-02-10 All non-function attributes of the `Config` interface are now mandatory.
22
+ * @modified 2023-09-29 Added the `randomPoint(...)` function declaration to the IBounds interface.
21
23
  **/
22
24
  Object.defineProperty(exports, "__esModule", { value: true });
23
25
  //# sourceMappingURL=core.js.map