plotboilerplate 1.20.2 → 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.
- package/dist/index.esm.js +1985 -1368
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +1170 -541
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/BezierPath.d.ts +27 -49
- package/src/cjs/BezierPath.js +67 -234
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Bounds.d.ts +14 -1
- package/src/cjs/Bounds.js +21 -1
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +70 -1
- package/src/cjs/CubicBezierCurve.js +130 -12
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Line.d.ts +2 -1
- package/src/cjs/Line.js +1 -0
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/PBText.d.ts +2 -1
- package/src/cjs/PBText.js +10 -9
- package/src/cjs/PBText.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +4 -13
- package/src/cjs/PlotBoilerplate.js +61 -15
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +35 -1
- package/src/cjs/Polygon.js +87 -1
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/VEllipse.js +1 -1
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/Vector.d.ts +4 -4
- package/src/cjs/Vector.js +2 -2
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +2 -1
- package/src/cjs/VertTuple.js +4 -3
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +14 -3
- package/src/cjs/Vertex.js +18 -3
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/draw.d.ts +154 -75
- package/src/cjs/draw.js +308 -137
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +87 -50
- package/src/cjs/drawgl.js +86 -31
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +226 -53
- package/src/cjs/drawutilssvg.js +374 -92
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +157 -79
- package/src/cjs/interfaces/DrawLib.js +6 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +13 -2
- package/src/cjs/interfaces/core.js +1 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/creategui.js +16 -10
- package/src/cjs/utils/detectDarkMode.d.ts +10 -0
- package/src/cjs/utils/detectDarkMode.js +32 -0
- package/src/cjs/utils/detectDarkMode.js.map +1 -0
- package/src/esm/BezierPath.d.ts +27 -49
- package/src/esm/BezierPath.js +67 -234
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Bounds.d.ts +14 -1
- package/src/esm/Bounds.js +19 -1
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +70 -1
- package/src/esm/CubicBezierCurve.js +130 -12
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Line.d.ts +2 -1
- package/src/esm/Line.js +1 -0
- package/src/esm/Line.js.map +1 -1
- package/src/esm/PBText.d.ts +2 -1
- package/src/esm/PBText.js +10 -9
- package/src/esm/PBText.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +4 -13
- package/src/esm/PlotBoilerplate.js +62 -16
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +35 -1
- package/src/esm/Polygon.js +85 -1
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/VEllipse.js +1 -1
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/Vector.d.ts +4 -4
- package/src/esm/Vector.js +2 -2
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.d.ts +2 -1
- package/src/esm/VertTuple.js +4 -3
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +14 -3
- package/src/esm/Vertex.js +18 -3
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/draw.d.ts +154 -75
- package/src/esm/draw.js +304 -135
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +87 -50
- package/src/esm/drawgl.js +86 -31
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +226 -53
- package/src/esm/drawutilssvg.js +369 -92
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +157 -79
- package/src/esm/interfaces/DrawLib.js +6 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +13 -2
- package/src/esm/interfaces/core.js +1 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/detectDarkMode.d.ts +10 -0
- package/src/esm/utils/detectDarkMode.js +28 -0
- package/src/esm/utils/detectDarkMode.js.map +1 -0
- package/src/ts/BezierPath.ts +72 -241
- package/src/ts/Bounds.ts +25 -1
- package/src/ts/CubicBezierCurve.ts +139 -12
- package/src/ts/Line.ts +2 -1
- package/src/ts/PBText.ts +10 -9
- package/src/ts/PlotBoilerplate.ts +56 -19
- package/src/ts/Polygon.ts +91 -1
- package/src/ts/VEllipse.ts +2 -2
- package/src/ts/Vector.ts +4 -4
- package/src/ts/VertTuple.ts +4 -3
- package/src/ts/Vertex.ts +20 -4
- package/src/ts/draw.ts +311 -115
- package/src/ts/drawgl.ts +133 -71
- package/src/ts/drawutilssvg.ts +543 -121
- package/src/ts/interfaces/DrawLib.ts +219 -83
- package/src/ts/interfaces/core.ts +14 -2
- package/src/ts/utils/detectDarkMode.ts +30 -0
package/src/esm/draw.js
CHANGED
|
@@ -48,11 +48,20 @@
|
|
|
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
|
-
* @
|
|
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
|
import { CubicBezierCurve } from "./CubicBezierCurve";
|
|
54
62
|
import { Vertex } from "./Vertex";
|
|
55
63
|
import { drawutilssvg } from "./drawutilssvg";
|
|
64
|
+
import { Vector } from "./Vector";
|
|
56
65
|
// Todo: rename this class to Drawutils?
|
|
57
66
|
/**
|
|
58
67
|
* @classdesc A wrapper class for basic drawing operations.
|
|
@@ -73,10 +82,47 @@ export class drawutils {
|
|
|
73
82
|
**/
|
|
74
83
|
constructor(context, fillShapes) {
|
|
75
84
|
this.ctx = context;
|
|
85
|
+
// this.lineDash = [];
|
|
76
86
|
this.offset = new Vertex(0, 0);
|
|
77
87
|
this.scale = new Vertex(1, 1);
|
|
78
88
|
this.fillShapes = fillShapes;
|
|
79
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* A private helper method to apply stroke options to the current
|
|
92
|
+
* context.
|
|
93
|
+
* @param {StrokeOptions=} strokeOptions -
|
|
94
|
+
*/
|
|
95
|
+
applyStrokeOpts(strokeOptions) {
|
|
96
|
+
var _a, _b;
|
|
97
|
+
this.ctx.setLineDash(((_a = strokeOptions === null || strokeOptions === void 0 ? void 0 : strokeOptions.dashArray) !== null && _a !== void 0 ? _a : []).map((dashArrayElem) => {
|
|
98
|
+
// Note assume scale.x === scale.y
|
|
99
|
+
// Invariant scale makes funny stuff anyway.
|
|
100
|
+
return dashArrayElem * this.scale.x;
|
|
101
|
+
}));
|
|
102
|
+
this.ctx.lineDashOffset = ((_b = strokeOptions === null || strokeOptions === void 0 ? void 0 : strokeOptions.dashOffset) !== null && _b !== void 0 ? _b : 0) * this.scale.x;
|
|
103
|
+
}
|
|
104
|
+
// +---------------------------------------------------------------------------------
|
|
105
|
+
// | This is the final helper function for drawing and filling stuff. It is not
|
|
106
|
+
// | intended to be used from the outside.
|
|
107
|
+
// |
|
|
108
|
+
// | When in draw mode it draws the current shape.
|
|
109
|
+
// | When in fill mode it fills the current shape.
|
|
110
|
+
// |
|
|
111
|
+
// | This function is usually only called internally.
|
|
112
|
+
// |
|
|
113
|
+
// | @param color A stroke/fill color to use.
|
|
114
|
+
// +-------------------------------
|
|
115
|
+
// TODO: convert this to a STATIC function.
|
|
116
|
+
_fillOrDraw(color) {
|
|
117
|
+
if (this.fillShapes) {
|
|
118
|
+
this.ctx.fillStyle = color;
|
|
119
|
+
this.ctx.fill();
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
this.ctx.strokeStyle = color;
|
|
123
|
+
this.ctx.stroke();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
80
126
|
/**
|
|
81
127
|
* Called before each draw cycle.
|
|
82
128
|
* @param {UID=} uid - (optional) A UID identifying the currently drawn element(s).
|
|
@@ -107,6 +153,20 @@ export class drawutils {
|
|
|
107
153
|
setConfiguration(configuration) {
|
|
108
154
|
this.ctx.globalCompositeOperation = configuration.blendMode || "source-over";
|
|
109
155
|
}
|
|
156
|
+
// /**
|
|
157
|
+
// * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
|
|
158
|
+
// *
|
|
159
|
+
// * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
|
|
160
|
+
// * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
|
161
|
+
// * for how line dashes work.
|
|
162
|
+
// *
|
|
163
|
+
// * @method
|
|
164
|
+
// * @param {Array<number> lineDashes - The line-dash array configuration.
|
|
165
|
+
// * @returns {void}
|
|
166
|
+
// */
|
|
167
|
+
// setLineDash(lineDash: Array<number>) {
|
|
168
|
+
// this.lineDash = lineDash;
|
|
169
|
+
// }
|
|
110
170
|
/**
|
|
111
171
|
* This method shouled be called each time the currently drawn `Drawable` changes.
|
|
112
172
|
* It is used by some libraries for identifying elemente on re-renders.
|
|
@@ -133,17 +193,20 @@ export class drawutils {
|
|
|
133
193
|
* Draw the line between the given two points with the specified (CSS-) color.
|
|
134
194
|
*
|
|
135
195
|
* @method line
|
|
136
|
-
* @param {
|
|
137
|
-
* @param {
|
|
196
|
+
* @param {XYCoords} zA - The start point of the line.
|
|
197
|
+
* @param {XYCoords} zB - The end point of the line.
|
|
138
198
|
* @param {string} color - Any valid CSS color string.
|
|
139
199
|
* @param {number} lineWidth? - [optional] The line's width.
|
|
200
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
201
|
+
*
|
|
140
202
|
* @return {void}
|
|
141
203
|
* @instance
|
|
142
204
|
* @memberof drawutils
|
|
143
205
|
**/
|
|
144
|
-
line(zA, zB, color, lineWidth) {
|
|
206
|
+
line(zA, zB, color, lineWidth, strokeOptions) {
|
|
145
207
|
this.ctx.save();
|
|
146
208
|
this.ctx.beginPath();
|
|
209
|
+
this.applyStrokeOpts(strokeOptions);
|
|
147
210
|
this.ctx.moveTo(this.offset.x + zA.x * this.scale.x, this.offset.y + zA.y * this.scale.y);
|
|
148
211
|
this.ctx.lineTo(this.offset.x + zB.x * this.scale.x, this.offset.y + zB.y * this.scale.y);
|
|
149
212
|
this.ctx.strokeStyle = color;
|
|
@@ -155,22 +218,74 @@ export class drawutils {
|
|
|
155
218
|
* Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
|
|
156
219
|
*
|
|
157
220
|
* @method arrow
|
|
158
|
-
* @param {
|
|
159
|
-
* @param {
|
|
221
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
222
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
160
223
|
* @param {string} color - Any valid CSS color string.
|
|
161
224
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
225
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
226
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
227
|
+
*
|
|
162
228
|
* @return {void}
|
|
163
229
|
* @instance
|
|
164
230
|
* @memberof drawutils
|
|
165
231
|
**/
|
|
166
|
-
arrow(zA, zB, color, lineWidth) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
232
|
+
arrow(zA, zB, color, lineWidth, headLength = 8, strokeOptions) {
|
|
233
|
+
const arrowHeadBasePosition = new Vertex(0, 0);
|
|
234
|
+
this.arrowHead(zA, zB, color, lineWidth, headLength, undefined, arrowHeadBasePosition); // Will NOT use dash configuration
|
|
235
|
+
this.line(zA, arrowHeadBasePosition, color, lineWidth, strokeOptions); // Will use dash configuration
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* 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.
|
|
239
|
+
*
|
|
240
|
+
* @method cubicBezierArrow
|
|
241
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
242
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
243
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
244
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
245
|
+
* @param {string} color - The CSS color to draw the curve with.
|
|
246
|
+
* @param {number} lineWidth - (optional) The line width to use.
|
|
247
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
248
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
249
|
+
*
|
|
250
|
+
* @return {void}
|
|
251
|
+
* @instance
|
|
252
|
+
* @memberof DrawLib
|
|
253
|
+
*/
|
|
254
|
+
cubicBezierArrow(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, headLength, strokeOptions) {
|
|
255
|
+
const arrowHeadBasePosition = new Vertex(0, 0);
|
|
256
|
+
// Will NOT use dash configuration
|
|
257
|
+
this.arrowHead(endControlPoint, endPoint, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
|
|
258
|
+
const diff = arrowHeadBasePosition.difference(endPoint);
|
|
259
|
+
// Will use dash configuration
|
|
260
|
+
this.cubicBezier(startPoint, { x: endPoint.x - diff.x, y: endPoint.y - diff.y }, startControlPoint, { x: endControlPoint.x - diff.x, y: endControlPoint.y - diff.y }, color, lineWidth, strokeOptions);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
|
|
264
|
+
*
|
|
265
|
+
* @method arrow
|
|
266
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
267
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
268
|
+
* @param {string} color - Any valid CSS color string.
|
|
269
|
+
* @param {number=1} lineWidth - (optional) The line width to use; default is 1.
|
|
270
|
+
* @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
|
|
271
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
272
|
+
* @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.
|
|
273
|
+
*
|
|
274
|
+
* @return {void}
|
|
275
|
+
* @instance
|
|
276
|
+
* @memberof DrawLib
|
|
277
|
+
**/
|
|
278
|
+
arrowHead(zA, zB, color, lineWidth, headLength = 8, strokeOptions, arrowHeadBasePositionBuffer) {
|
|
279
|
+
// var headLength: number = 8; // length of head in pixels
|
|
170
280
|
this.ctx.save();
|
|
171
281
|
this.ctx.beginPath();
|
|
172
|
-
|
|
173
|
-
|
|
282
|
+
this.applyStrokeOpts(strokeOptions);
|
|
283
|
+
var vertices = Vector.utils.buildArrowHead(zA, zB, headLength, this.scale.x, this.scale.y);
|
|
284
|
+
if (arrowHeadBasePositionBuffer) {
|
|
285
|
+
arrowHeadBasePositionBuffer.x = vertices[0].x / this.scale.x;
|
|
286
|
+
arrowHeadBasePositionBuffer.y = vertices[0].y / this.scale.y;
|
|
287
|
+
}
|
|
288
|
+
this.ctx.moveTo(this.offset.x + vertices[0].x, this.offset.y + vertices[0].y);
|
|
174
289
|
for (var i = 0; i < vertices.length; i++) {
|
|
175
290
|
this.ctx.lineTo(this.offset.x + vertices[i].x, this.offset.y + vertices[i].y);
|
|
176
291
|
}
|
|
@@ -186,8 +301,8 @@ export class drawutils {
|
|
|
186
301
|
*
|
|
187
302
|
* @method image
|
|
188
303
|
* @param {Image} image - The image object to draw.
|
|
189
|
-
* @param {
|
|
190
|
-
* @param {
|
|
304
|
+
* @param {XYCoords} position - The position to draw the the upper left corner at.
|
|
305
|
+
* @param {XYCoords} size - The x/y-size to draw the image with.
|
|
191
306
|
* @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
|
|
192
307
|
* @return {void}
|
|
193
308
|
* @instance
|
|
@@ -216,7 +331,7 @@ export class drawutils {
|
|
|
216
331
|
* @param {Image} textureImage - The image object to draw.
|
|
217
332
|
* @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
|
|
218
333
|
* @param {Polygon} polygon - The polygon to use as clip path.
|
|
219
|
-
* @param {
|
|
334
|
+
* @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
|
|
220
335
|
* @param {number} rotation - The rotation to use for the polygon (and for the texture).
|
|
221
336
|
* @param {XYCoords={x:0,y:0}} rotationCenter - (optional) The rotational center; default is center of bounding box.
|
|
222
337
|
* @return {void}
|
|
@@ -225,10 +340,9 @@ export class drawutils {
|
|
|
225
340
|
**/
|
|
226
341
|
texturedPoly(textureImage, textureSize, polygon, polygonPosition, rotation) {
|
|
227
342
|
var basePolygonBounds = polygon.getBounds();
|
|
228
|
-
var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
|
|
229
|
-
|
|
230
|
-
// var
|
|
231
|
-
var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
|
|
343
|
+
// var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
|
|
344
|
+
var targetCenterDifference = new Vertex(polygonPosition.x, polygonPosition.y).difference(basePolygonBounds.getCenter());
|
|
345
|
+
// var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
|
|
232
346
|
// Get the position offset of the polygon
|
|
233
347
|
var targetTextureSize = new Vertex(textureSize.width, textureSize.height);
|
|
234
348
|
// var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
|
|
@@ -251,52 +365,83 @@ export class drawutils {
|
|
|
251
365
|
);
|
|
252
366
|
this.ctx.restore();
|
|
253
367
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
368
|
+
/*
|
|
369
|
+
_texturedPoly(
|
|
370
|
+
textureImage: HTMLImageElement,
|
|
371
|
+
textureSize: Bounds,
|
|
372
|
+
polygon: Polygon,
|
|
373
|
+
polygonPosition: XYCoords,
|
|
374
|
+
rotation: number,
|
|
375
|
+
rotationCenter: XYCoords = { x: 0, y: 0 }
|
|
376
|
+
): void {
|
|
377
|
+
var basePolygonBounds = polygon.getBounds();
|
|
378
|
+
var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
|
|
379
|
+
var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
|
|
380
|
+
// var rotationalOffset = { x: 0, y: 0 };
|
|
381
|
+
var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
|
|
382
|
+
|
|
383
|
+
// Get the position offset of the polygon
|
|
384
|
+
var targetTextureSize = new Vertex(textureSize.width, textureSize.height);
|
|
385
|
+
var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
|
|
386
|
+
|
|
387
|
+
this.ctx.save();
|
|
388
|
+
|
|
389
|
+
// this.ctx.translate(
|
|
390
|
+
// this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
|
|
391
|
+
// this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
|
|
392
|
+
// );
|
|
393
|
+
this.ctx.translate(
|
|
394
|
+
this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
|
|
395
|
+
this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
|
|
396
|
+
);
|
|
397
|
+
this.ctx.rotate(rotation);
|
|
398
|
+
|
|
399
|
+
drawutils.helpers.clipPoly(
|
|
400
|
+
this.ctx,
|
|
401
|
+
{
|
|
402
|
+
x: (-targetCenterDifference.x * 1 - tileCenter.x - rotationalOffset.x) * this.scale.x,
|
|
403
|
+
y: (-targetCenterDifference.y * 1 - tileCenter.y - rotationalOffset.y) * this.scale.y
|
|
404
|
+
},
|
|
405
|
+
this.scale,
|
|
406
|
+
polygon.vertices
|
|
407
|
+
);
|
|
408
|
+
this.ctx.drawImage(
|
|
409
|
+
textureImage,
|
|
410
|
+
0,
|
|
411
|
+
0,
|
|
412
|
+
textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
|
|
275
413
|
textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
|
|
276
|
-
(-polygonPosition.x + targetTextureOffset.x * 1 - rotationalOffset.x * 1) * this.scale.x,
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
414
|
+
(-polygonPosition.x + targetTextureOffset.x * 1 - rotationalOffset.x * 1) * this.scale.x,
|
|
415
|
+
(-polygonPosition.y + targetTextureOffset.y * 1 - rotationalOffset.y * 1) * this.scale.y,
|
|
416
|
+
targetTextureSize.x * this.scale.x,
|
|
417
|
+
targetTextureSize.y * this.scale.y
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
// const scaledTextureSize = new Bounds(
|
|
421
|
+
// new Vertex(
|
|
422
|
+
// -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x,
|
|
423
|
+
// -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y
|
|
424
|
+
// ).scaleXY(this.scale, rotationCenter),
|
|
425
|
+
// new Vertex(
|
|
426
|
+
// -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x + targetTextureSize.x,
|
|
427
|
+
// -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y + targetTextureSize.y
|
|
428
|
+
// ).scaleXY(this.scale, rotationCenter)
|
|
429
|
+
// );
|
|
430
|
+
// this.ctx.drawImage(
|
|
431
|
+
// textureImage,
|
|
432
|
+
// 0,
|
|
433
|
+
// 0,
|
|
434
|
+
// textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
|
|
435
|
+
// textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
|
|
436
|
+
// scaledTextureSize.min.x,
|
|
437
|
+
// scaledTextureSize.min.y,
|
|
438
|
+
// scaledTextureSize.width,
|
|
439
|
+
// scaledTextureSize.height
|
|
440
|
+
// );
|
|
441
|
+
|
|
442
|
+
this.ctx.restore();
|
|
299
443
|
}
|
|
444
|
+
*/
|
|
300
445
|
/**
|
|
301
446
|
* Draw a rectangle.
|
|
302
447
|
*
|
|
@@ -305,10 +450,16 @@ export class drawutils {
|
|
|
305
450
|
* @param {number} height - The height of the rectangle.
|
|
306
451
|
* @param {string} color - The color to use.
|
|
307
452
|
* @param {number=1} lineWidth - (optional) The line with to use (default is 1).
|
|
453
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
454
|
+
*
|
|
455
|
+
* @return {void}
|
|
456
|
+
* @instance
|
|
457
|
+
* @memberof drawutils
|
|
308
458
|
**/
|
|
309
|
-
rect(position, width, height, color, lineWidth) {
|
|
459
|
+
rect(position, width, height, color, lineWidth, strokeOptions) {
|
|
310
460
|
this.ctx.save();
|
|
311
461
|
this.ctx.beginPath();
|
|
462
|
+
this.applyStrokeOpts(strokeOptions);
|
|
312
463
|
this.ctx.moveTo(this.offset.x + position.x * this.scale.x, this.offset.y + position.y * this.scale.y);
|
|
313
464
|
this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + position.y * this.scale.y);
|
|
314
465
|
this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + (position.y + height) * this.scale.y);
|
|
@@ -319,43 +470,23 @@ export class drawutils {
|
|
|
319
470
|
this._fillOrDraw(color);
|
|
320
471
|
this.ctx.restore();
|
|
321
472
|
}
|
|
322
|
-
// +---------------------------------------------------------------------------------
|
|
323
|
-
// | This is the final helper function for drawing and filling stuff. It is not
|
|
324
|
-
// | intended to be used from the outside.
|
|
325
|
-
// |
|
|
326
|
-
// | When in draw mode it draws the current shape.
|
|
327
|
-
// | When in fill mode it fills the current shape.
|
|
328
|
-
// |
|
|
329
|
-
// | This function is usually only called internally.
|
|
330
|
-
// |
|
|
331
|
-
// | @param color A stroke/fill color to use.
|
|
332
|
-
// +-------------------------------
|
|
333
|
-
// TODO: convert this to a STATIC function.
|
|
334
|
-
_fillOrDraw(color) {
|
|
335
|
-
if (this.fillShapes) {
|
|
336
|
-
this.ctx.fillStyle = color;
|
|
337
|
-
this.ctx.fill();
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
this.ctx.strokeStyle = color;
|
|
341
|
-
this.ctx.stroke();
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
473
|
/**
|
|
345
474
|
* Draw the given (cubic) bézier curve.
|
|
346
475
|
*
|
|
347
476
|
* @method cubicBezier
|
|
348
|
-
* @param {
|
|
349
|
-
* @param {
|
|
350
|
-
* @param {
|
|
351
|
-
* @param {
|
|
477
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
478
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
479
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
480
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
352
481
|
* @param {string} color - The CSS color to draw the curve with.
|
|
353
482
|
* @param {number} lineWidth - (optional) The line width to use.
|
|
483
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
484
|
+
*
|
|
354
485
|
* @return {void}
|
|
355
486
|
* @instance
|
|
356
487
|
* @memberof drawutils
|
|
357
488
|
*/
|
|
358
|
-
cubicBezier(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth) {
|
|
489
|
+
cubicBezier(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
|
|
359
490
|
if (startPoint instanceof CubicBezierCurve) {
|
|
360
491
|
this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
|
|
361
492
|
return;
|
|
@@ -363,6 +494,7 @@ export class drawutils {
|
|
|
363
494
|
// Draw curve
|
|
364
495
|
this.ctx.save();
|
|
365
496
|
this.ctx.beginPath();
|
|
497
|
+
this.applyStrokeOpts(strokeOptions);
|
|
366
498
|
this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
|
|
367
499
|
this.ctx.bezierCurveTo(this.offset.x + startControlPoint.x * this.scale.x, this.offset.y + startControlPoint.y * this.scale.y, this.offset.x + endControlPoint.x * this.scale.x, this.offset.y + endControlPoint.y * this.scale.y, this.offset.x + endPoint.x * this.scale.x, this.offset.y + endPoint.y * this.scale.y);
|
|
368
500
|
//this.ctx.closePath();
|
|
@@ -374,19 +506,22 @@ export class drawutils {
|
|
|
374
506
|
* Draw the given (quadratic) bézier curve.
|
|
375
507
|
*
|
|
376
508
|
* @method quadraticBezier
|
|
377
|
-
* @param {
|
|
378
|
-
* @param {
|
|
379
|
-
* @param {
|
|
509
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
510
|
+
* @param {XYCoords} controlPoint - The control point the cubic Bézier curve.
|
|
511
|
+
* @param {XYCoords} endPoint - The end control point the cubic Bézier curve.
|
|
380
512
|
* @param {string} color - The CSS color to draw the curve with.
|
|
381
513
|
* @param {number|string} lineWidth - (optional) The line width to use.
|
|
514
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
515
|
+
*
|
|
382
516
|
* @return {void}
|
|
383
517
|
* @instance
|
|
384
518
|
* @memberof drawutils
|
|
385
519
|
*/
|
|
386
|
-
quadraticBezier(startPoint, controlPoint, endPoint, color, lineWidth) {
|
|
520
|
+
quadraticBezier(startPoint, controlPoint, endPoint, color, lineWidth, strokeOptions) {
|
|
387
521
|
// Draw curve
|
|
388
522
|
this.ctx.save();
|
|
389
523
|
this.ctx.beginPath();
|
|
524
|
+
this.applyStrokeOpts(strokeOptions);
|
|
390
525
|
this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
|
|
391
526
|
this.ctx.quadraticCurveTo(this.offset.x + controlPoint.x * this.scale.x, this.offset.y + controlPoint.y * this.scale.y, this.offset.x + endPoint.x * this.scale.x, this.offset.y + endPoint.y * this.scale.y);
|
|
392
527
|
this.ctx.lineWidth = lineWidth || 2;
|
|
@@ -401,22 +536,26 @@ export class drawutils {
|
|
|
401
536
|
* <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
|
|
402
537
|
*
|
|
403
538
|
* @method cubicBezierPath
|
|
404
|
-
* @param {
|
|
539
|
+
* @param {XYCoords[]} path - The cubic bezier path as described above.
|
|
405
540
|
* @param {string} color - The CSS colot to draw the path with.
|
|
406
541
|
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
542
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
543
|
+
*
|
|
407
544
|
* @return {void}
|
|
408
545
|
* @instance
|
|
409
546
|
* @memberof drawutils
|
|
410
547
|
*/
|
|
411
|
-
cubicBezierPath(path, color, lineWidth) {
|
|
412
|
-
if (!path || path.length == 0)
|
|
548
|
+
cubicBezierPath(path, color, lineWidth, strokeOptions) {
|
|
549
|
+
if (!path || path.length == 0) {
|
|
413
550
|
return;
|
|
551
|
+
}
|
|
414
552
|
// Draw curve
|
|
415
553
|
this.ctx.save();
|
|
416
554
|
this.ctx.beginPath();
|
|
417
555
|
var endPoint;
|
|
418
556
|
var startControlPoint;
|
|
419
557
|
var endControlPoint;
|
|
558
|
+
this.applyStrokeOpts(strokeOptions);
|
|
420
559
|
this.ctx.moveTo(this.offset.x + path[0].x * this.scale.x, this.offset.y + path[0].y * this.scale.y);
|
|
421
560
|
for (var i = 1; i < path.length; i += 3) {
|
|
422
561
|
startControlPoint = path[i];
|
|
@@ -435,8 +574,8 @@ export class drawutils {
|
|
|
435
574
|
* The colors for this are fixed and cannot be specified.
|
|
436
575
|
*
|
|
437
576
|
* @method handle
|
|
438
|
-
* @param {
|
|
439
|
-
* @param {
|
|
577
|
+
* @param {XYCoords} startPoint - The start of the handle.
|
|
578
|
+
* @param {XYCoords} endPoint - The end point of the handle.
|
|
440
579
|
* @return {void}
|
|
441
580
|
* @instance
|
|
442
581
|
* @memberof drawutils
|
|
@@ -451,21 +590,21 @@ export class drawutils {
|
|
|
451
590
|
* Draw a handle line (with a light grey).
|
|
452
591
|
*
|
|
453
592
|
* @method handleLine
|
|
454
|
-
* @param {
|
|
455
|
-
* @param {
|
|
593
|
+
* @param {XYCoords} startPoint - The start point to draw the handle at.
|
|
594
|
+
* @param {XYCoords} endPoint - The end point to draw the handle at.
|
|
456
595
|
* @return {void}
|
|
457
596
|
* @instance
|
|
458
597
|
* @memberof drawutils
|
|
459
598
|
*/
|
|
460
599
|
handleLine(startPoint, endPoint) {
|
|
461
600
|
// Draw handle lines
|
|
462
|
-
this.line(startPoint, endPoint, "
|
|
601
|
+
this.line(startPoint, endPoint, "rgba(128,128,128, 0.5)", undefined);
|
|
463
602
|
}
|
|
464
603
|
/**
|
|
465
604
|
* Draw a 1x1 dot with the specified (CSS-) color.
|
|
466
605
|
*
|
|
467
606
|
* @method dot
|
|
468
|
-
* @param {
|
|
607
|
+
* @param {XYCoords} p - The position to draw the dot at.
|
|
469
608
|
* @param {string} color - The CSS color to draw the dot with.
|
|
470
609
|
* @return {void}
|
|
471
610
|
* @instance
|
|
@@ -474,6 +613,7 @@ export class drawutils {
|
|
|
474
613
|
dot(p, color) {
|
|
475
614
|
this.ctx.save();
|
|
476
615
|
this.ctx.beginPath();
|
|
616
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
477
617
|
this.ctx.moveTo(Math.round(this.offset.x + this.scale.x * p.x), Math.round(this.offset.y + this.scale.y * p.y));
|
|
478
618
|
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));
|
|
479
619
|
this.ctx.closePath();
|
|
@@ -485,7 +625,7 @@ export class drawutils {
|
|
|
485
625
|
* Draw the given point with the specified (CSS-) color and radius 3.
|
|
486
626
|
*
|
|
487
627
|
* @method point
|
|
488
|
-
* @param {
|
|
628
|
+
* @param {XYCoords} p - The position to draw the point at.
|
|
489
629
|
* @param {string} color - The CSS color to draw the point with.
|
|
490
630
|
* @return {void}
|
|
491
631
|
* @instance
|
|
@@ -493,6 +633,7 @@ export class drawutils {
|
|
|
493
633
|
*/
|
|
494
634
|
point(p, color) {
|
|
495
635
|
var radius = 3;
|
|
636
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
496
637
|
this.ctx.beginPath();
|
|
497
638
|
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);
|
|
498
639
|
this.ctx.closePath();
|
|
@@ -505,15 +646,18 @@ export class drawutils {
|
|
|
505
646
|
* Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
|
|
506
647
|
*
|
|
507
648
|
* @method circle
|
|
508
|
-
* @param {
|
|
649
|
+
* @param {XYCoords} center - The center of the circle.
|
|
509
650
|
* @param {number} radius - The radius of the circle.
|
|
510
651
|
* @param {string} color - The CSS color to draw the circle with.
|
|
511
652
|
* @param {number} lineWidth - The line width (optional, default=1).
|
|
653
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
654
|
+
*
|
|
512
655
|
* @return {void}
|
|
513
656
|
* @instance
|
|
514
657
|
* @memberof drawutils
|
|
515
658
|
*/
|
|
516
|
-
circle(center, radius, color, lineWidth) {
|
|
659
|
+
circle(center, radius, color, lineWidth, strokeOptions) {
|
|
660
|
+
this.applyStrokeOpts(strokeOptions);
|
|
517
661
|
this.ctx.beginPath();
|
|
518
662
|
this.ctx.ellipse(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y, radius * this.scale.x, radius * this.scale.y, 0.0, 0.0, Math.PI * 2);
|
|
519
663
|
this.ctx.closePath();
|
|
@@ -521,24 +665,28 @@ export class drawutils {
|
|
|
521
665
|
this._fillOrDraw(color);
|
|
522
666
|
}
|
|
523
667
|
/**
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
668
|
+
* Draw a circular arc (section of a circle) with the given CSS color.
|
|
669
|
+
*
|
|
670
|
+
* @method circleArc
|
|
671
|
+
* @param {XYCoords} center - The center of the circle.
|
|
672
|
+
* @param {number} radius - The radius of the circle.
|
|
673
|
+
* @param {number} startAngle - The angle to start at.
|
|
674
|
+
* @param {number} endAngle - The angle to end at.
|
|
675
|
+
* @param {string=#000000} color - The CSS color to draw the circle with.
|
|
676
|
+
* @param {number=1} lineWidth - The line width to use
|
|
677
|
+
* @param {boolean=false} options.asSegment - If `true` then no beginPath and no draw will be applied (as part of larger path).
|
|
678
|
+
* @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
|
|
679
|
+
* @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
|
|
680
|
+
*
|
|
681
|
+
* @return {void}
|
|
682
|
+
* @instance
|
|
683
|
+
* @memberof drawutils
|
|
684
|
+
*/
|
|
538
685
|
circleArc(center, radius, startAngle, endAngle, color, lineWidth, options) {
|
|
539
686
|
if (!options || !options.asSegment) {
|
|
540
687
|
this.ctx.beginPath();
|
|
541
688
|
}
|
|
689
|
+
this.applyStrokeOpts(options);
|
|
542
690
|
this.ctx.ellipse(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y, radius * this.scale.x, radius * this.scale.y, 0.0, startAngle, endAngle, false);
|
|
543
691
|
if (!options || !options.asSegment) {
|
|
544
692
|
// this.ctx.closePath();
|
|
@@ -550,20 +698,23 @@ export class drawutils {
|
|
|
550
698
|
* Draw an ellipse with the specified (CSS-) color and thw two radii.
|
|
551
699
|
*
|
|
552
700
|
* @method ellipse
|
|
553
|
-
* @param {
|
|
701
|
+
* @param {XYCoords} center - The center of the ellipse.
|
|
554
702
|
* @param {number} radiusX - The radius of the ellipse.
|
|
555
703
|
* @param {number} radiusY - The radius of the ellipse.
|
|
556
704
|
* @param {string} color - The CSS color to draw the ellipse with.
|
|
557
705
|
* @param {number} lineWidth=1 - An optional line width param (default is 1).
|
|
558
706
|
* @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
|
|
707
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
708
|
+
*
|
|
559
709
|
* @return {void}
|
|
560
710
|
* @instance
|
|
561
711
|
* @memberof drawutils
|
|
562
712
|
*/
|
|
563
|
-
ellipse(center, radiusX, radiusY, color, lineWidth, rotation) {
|
|
713
|
+
ellipse(center, radiusX, radiusY, color, lineWidth, rotation, strokeOptions) {
|
|
564
714
|
if (typeof rotation === "undefined") {
|
|
565
715
|
rotation = 0.0;
|
|
566
716
|
}
|
|
717
|
+
this.applyStrokeOpts(strokeOptions);
|
|
567
718
|
this.ctx.beginPath();
|
|
568
719
|
this.ctx.ellipse(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y, radiusX * this.scale.x, radiusY * this.scale.y, rotation, 0.0, Math.PI * 2);
|
|
569
720
|
this.ctx.closePath();
|
|
@@ -580,11 +731,14 @@ export class drawutils {
|
|
|
580
731
|
* @param {number} size - The size of the square.
|
|
581
732
|
* @param {string} color - The CSS color to draw the square with.
|
|
582
733
|
* @param {number} lineWidth - The line with to use (optional, default is 1).
|
|
734
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
735
|
+
*
|
|
583
736
|
* @return {void}
|
|
584
737
|
* @instance
|
|
585
738
|
* @memberof drawutils
|
|
586
739
|
*/
|
|
587
|
-
square(center, size, color, lineWidth) {
|
|
740
|
+
square(center, size, color, lineWidth, strokeOptions) {
|
|
741
|
+
this.applyStrokeOpts(strokeOptions);
|
|
588
742
|
this.ctx.beginPath();
|
|
589
743
|
this.ctx.rect(this.offset.x + (center.x - size / 2.0) * this.scale.x, this.offset.y + (center.y - size / 2.0) * this.scale.y, size * this.scale.x, size * this.scale.y);
|
|
590
744
|
this.ctx.closePath();
|
|
@@ -595,7 +749,7 @@ export class drawutils {
|
|
|
595
749
|
* Draw a grid of horizontal and vertical lines with the given (CSS-) color.
|
|
596
750
|
*
|
|
597
751
|
* @method grid
|
|
598
|
-
* @param {
|
|
752
|
+
* @param {XYCoords} center - The center of the grid.
|
|
599
753
|
* @param {number} width - The total width of the grid (width/2 each to the left and to the right).
|
|
600
754
|
* @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
|
|
601
755
|
* @param {number} sizeX - The horizontal grid size.
|
|
@@ -606,6 +760,7 @@ export class drawutils {
|
|
|
606
760
|
* @memberof drawutils
|
|
607
761
|
*/
|
|
608
762
|
grid(center, width, height, sizeX, sizeY, color) {
|
|
763
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
609
764
|
this.ctx.beginPath();
|
|
610
765
|
var yMin = -Math.ceil((height * 0.5) / sizeY) * sizeY;
|
|
611
766
|
var yMax = height / 2;
|
|
@@ -630,7 +785,7 @@ export class drawutils {
|
|
|
630
785
|
* This works analogue to the grid() function
|
|
631
786
|
*
|
|
632
787
|
* @method raster
|
|
633
|
-
* @param {
|
|
788
|
+
* @param {XYCoords} center - The center of the raster.
|
|
634
789
|
* @param {number} width - The total width of the raster (width/2 each to the left and to the right).
|
|
635
790
|
* @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
|
|
636
791
|
* @param {number} sizeX - The horizontal raster size.
|
|
@@ -642,6 +797,7 @@ export class drawutils {
|
|
|
642
797
|
*/
|
|
643
798
|
raster(center, width, height, sizeX, sizeY, color) {
|
|
644
799
|
this.ctx.save();
|
|
800
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
645
801
|
this.ctx.beginPath();
|
|
646
802
|
for (var x = -Math.ceil((width * 0.5) / sizeX) * sizeX; x < width / 2; x += sizeX) {
|
|
647
803
|
for (var y = -Math.ceil((height * 0.5) / sizeY) * sizeY; y < height / 2; y += sizeY) {
|
|
@@ -666,14 +822,15 @@ export class drawutils {
|
|
|
666
822
|
* as even shaped diamonds.
|
|
667
823
|
*
|
|
668
824
|
* @method diamondHandle
|
|
669
|
-
* @param {
|
|
670
|
-
* @param {
|
|
825
|
+
* @param {XYCoords} center - The center of the diamond.
|
|
826
|
+
* @param {number} size - The x/y-size of the diamond.
|
|
671
827
|
* @param {string} color - The CSS color to draw the diamond with.
|
|
672
828
|
* @return {void}
|
|
673
829
|
* @instance
|
|
674
830
|
* @memberof drawutils
|
|
675
831
|
*/
|
|
676
832
|
diamondHandle(center, size, color) {
|
|
833
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
677
834
|
this.ctx.beginPath();
|
|
678
835
|
this.ctx.moveTo(this.offset.x + center.x * this.scale.x - size / 2.0, this.offset.y + center.y * this.scale.y);
|
|
679
836
|
this.ctx.lineTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y - size / 2.0);
|
|
@@ -691,14 +848,15 @@ export class drawutils {
|
|
|
691
848
|
* as even shaped squares.
|
|
692
849
|
*
|
|
693
850
|
* @method squareHandle
|
|
694
|
-
* @param {
|
|
695
|
-
* @param {
|
|
851
|
+
* @param {XYCoords} center - The center of the square.
|
|
852
|
+
* @param {number} size - The x/y-size of the square.
|
|
696
853
|
* @param {string} color - The CSS color to draw the square with.
|
|
697
854
|
* @return {void}
|
|
698
855
|
* @instance
|
|
699
856
|
* @memberof drawutils
|
|
700
857
|
*/
|
|
701
858
|
squareHandle(center, size, color) {
|
|
859
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
702
860
|
this.ctx.beginPath();
|
|
703
861
|
this.ctx.rect(this.offset.x + center.x * this.scale.x - size / 2.0, this.offset.y + center.y * this.scale.y - size / 2.0, size, size);
|
|
704
862
|
this.ctx.closePath();
|
|
@@ -713,7 +871,7 @@ export class drawutils {
|
|
|
713
871
|
* as even shaped circles.
|
|
714
872
|
*
|
|
715
873
|
* @method circleHandle
|
|
716
|
-
* @param {
|
|
874
|
+
* @param {XYCoords} center - The center of the circle.
|
|
717
875
|
* @param {number} radius - The radius of the circle.
|
|
718
876
|
* @param {string} color - The CSS color to draw the circle with.
|
|
719
877
|
* @return {void}
|
|
@@ -722,6 +880,7 @@ export class drawutils {
|
|
|
722
880
|
*/
|
|
723
881
|
circleHandle(center, radius, color) {
|
|
724
882
|
radius = radius || 3;
|
|
883
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
725
884
|
this.ctx.beginPath();
|
|
726
885
|
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);
|
|
727
886
|
this.ctx.closePath();
|
|
@@ -744,6 +903,7 @@ export class drawutils {
|
|
|
744
903
|
*/
|
|
745
904
|
crosshair(center, radius, color, lineWidth) {
|
|
746
905
|
this.ctx.save();
|
|
906
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
747
907
|
this.ctx.beginPath();
|
|
748
908
|
this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y);
|
|
749
909
|
this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y);
|
|
@@ -771,6 +931,7 @@ export class drawutils {
|
|
|
771
931
|
*/
|
|
772
932
|
cross(center, radius, color, lineWidth) {
|
|
773
933
|
this.ctx.save();
|
|
934
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
774
935
|
this.ctx.beginPath();
|
|
775
936
|
this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y - radius);
|
|
776
937
|
this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y + radius);
|
|
@@ -789,30 +950,35 @@ export class drawutils {
|
|
|
789
950
|
* @param {Polygon} polygon - The polygon to draw.
|
|
790
951
|
* @param {string} color - The CSS color to draw the polygon with.
|
|
791
952
|
* @param {string} lineWidth - The line width to use.
|
|
953
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
954
|
+
*
|
|
792
955
|
* @return {void}
|
|
793
956
|
* @instance
|
|
794
957
|
* @memberof drawutils
|
|
795
958
|
*/
|
|
796
|
-
polygon(polygon, color, lineWidth) {
|
|
797
|
-
this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth);
|
|
959
|
+
polygon(polygon, color, lineWidth, strokeOptions) {
|
|
960
|
+
this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth, strokeOptions);
|
|
798
961
|
}
|
|
799
962
|
/**
|
|
800
963
|
* Draw a polygon line (alternative function to the polygon).
|
|
801
964
|
*
|
|
802
965
|
* @method polyline
|
|
803
|
-
* @param {
|
|
966
|
+
* @param {XYCoords[]} vertices - The polygon vertices to draw.
|
|
804
967
|
* @param {boolan} isOpen - If true the polyline will not be closed at its end.
|
|
805
968
|
* @param {string} color - The CSS color to draw the polygon with.
|
|
806
969
|
* @param {number} lineWidth - The line width (default is 1.0);
|
|
970
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
971
|
+
*
|
|
807
972
|
* @return {void}
|
|
808
973
|
* @instance
|
|
809
974
|
* @memberof drawutils
|
|
810
975
|
*/
|
|
811
|
-
polyline(vertices, isOpen, color, lineWidth) {
|
|
976
|
+
polyline(vertices, isOpen, color, lineWidth, strokeOptions) {
|
|
812
977
|
if (vertices.length <= 1) {
|
|
813
978
|
return;
|
|
814
979
|
}
|
|
815
980
|
this.ctx.save();
|
|
981
|
+
this.applyStrokeOpts(strokeOptions);
|
|
816
982
|
this.ctx.beginPath();
|
|
817
983
|
this.ctx.lineWidth = (lineWidth || 1.0) * this.scale.x;
|
|
818
984
|
this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
|
|
@@ -924,6 +1090,8 @@ export class drawutils {
|
|
|
924
1090
|
* @param {string=null} color - (optional) The color to draw this path with (default is null).
|
|
925
1091
|
* @param {number=1} lineWidth - (optional) the line width to use (default is 1).
|
|
926
1092
|
* @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.
|
|
1093
|
+
* @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
|
|
1094
|
+
* @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
|
|
927
1095
|
* @instance
|
|
928
1096
|
* @memberof drawutils
|
|
929
1097
|
* @return {R} An instance representing the drawn path.
|
|
@@ -935,6 +1103,7 @@ export class drawutils {
|
|
|
935
1103
|
this.ctx.strokeStyle = color;
|
|
936
1104
|
}
|
|
937
1105
|
this.ctx.lineWidth = lineWidth || 1;
|
|
1106
|
+
this.applyStrokeOpts(options);
|
|
938
1107
|
if (this.fillShapes) {
|
|
939
1108
|
if (color) {
|
|
940
1109
|
this.ctx.fillStyle = color;
|