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