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/cjs/draw.js
CHANGED
|
@@ -48,13 +48,23 @@
|
|
|
48
48
|
* @modified 2022-08-23 Fixed a type issue in the `polyline` function.
|
|
49
49
|
* @modified 2022-08-23 Fixed a type issue in the `setConfiguration` function.
|
|
50
50
|
* @modified 2022-08-23 Fixed a type issue in the `path` function.
|
|
51
|
-
* @
|
|
51
|
+
* @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
|
|
52
|
+
* @modified 2023-09-29 Removed unused method stub for texturedPoly helper function (cleanup).
|
|
53
|
+
* @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.
|
|
54
|
+
* @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
|
|
55
|
+
* @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
|
|
56
|
+
* @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
|
|
57
|
+
* @modified 2023-09-29 Added the `lineDashes` attribute.
|
|
58
|
+
* @modified 2023-09-30 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
|
|
59
|
+
* @modified 2023-10-07 Adding the optional `arrowHeadBasePositionBuffer` param to the arrowHead(...) method.
|
|
60
|
+
* @version 1.13.0
|
|
52
61
|
**/
|
|
53
62
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
63
|
exports.drawutils = void 0;
|
|
55
64
|
var CubicBezierCurve_1 = require("./CubicBezierCurve");
|
|
56
65
|
var Vertex_1 = require("./Vertex");
|
|
57
66
|
var drawutilssvg_1 = require("./drawutilssvg");
|
|
67
|
+
var Vector_1 = require("./Vector");
|
|
58
68
|
// Todo: rename this class to Drawutils?
|
|
59
69
|
/**
|
|
60
70
|
* @classdesc A wrapper class for basic drawing operations.
|
|
@@ -75,10 +85,48 @@ var drawutils = /** @class */ (function () {
|
|
|
75
85
|
**/
|
|
76
86
|
function drawutils(context, fillShapes) {
|
|
77
87
|
this.ctx = context;
|
|
88
|
+
// this.lineDash = [];
|
|
78
89
|
this.offset = new Vertex_1.Vertex(0, 0);
|
|
79
90
|
this.scale = new Vertex_1.Vertex(1, 1);
|
|
80
91
|
this.fillShapes = fillShapes;
|
|
81
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* A private helper method to apply stroke options to the current
|
|
95
|
+
* context.
|
|
96
|
+
* @param {StrokeOptions=} strokeOptions -
|
|
97
|
+
*/
|
|
98
|
+
drawutils.prototype.applyStrokeOpts = function (strokeOptions) {
|
|
99
|
+
var _this = this;
|
|
100
|
+
var _a, _b;
|
|
101
|
+
this.ctx.setLineDash(((_a = strokeOptions === null || strokeOptions === void 0 ? void 0 : strokeOptions.dashArray) !== null && _a !== void 0 ? _a : []).map(function (dashArrayElem) {
|
|
102
|
+
// Note assume scale.x === scale.y
|
|
103
|
+
// Invariant scale makes funny stuff anyway.
|
|
104
|
+
return dashArrayElem * _this.scale.x;
|
|
105
|
+
}));
|
|
106
|
+
this.ctx.lineDashOffset = ((_b = strokeOptions === null || strokeOptions === void 0 ? void 0 : strokeOptions.dashOffset) !== null && _b !== void 0 ? _b : 0) * this.scale.x;
|
|
107
|
+
};
|
|
108
|
+
// +---------------------------------------------------------------------------------
|
|
109
|
+
// | This is the final helper function for drawing and filling stuff. It is not
|
|
110
|
+
// | intended to be used from the outside.
|
|
111
|
+
// |
|
|
112
|
+
// | When in draw mode it draws the current shape.
|
|
113
|
+
// | When in fill mode it fills the current shape.
|
|
114
|
+
// |
|
|
115
|
+
// | This function is usually only called internally.
|
|
116
|
+
// |
|
|
117
|
+
// | @param color A stroke/fill color to use.
|
|
118
|
+
// +-------------------------------
|
|
119
|
+
// TODO: convert this to a STATIC function.
|
|
120
|
+
drawutils.prototype._fillOrDraw = function (color) {
|
|
121
|
+
if (this.fillShapes) {
|
|
122
|
+
this.ctx.fillStyle = color;
|
|
123
|
+
this.ctx.fill();
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
this.ctx.strokeStyle = color;
|
|
127
|
+
this.ctx.stroke();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
82
130
|
/**
|
|
83
131
|
* Called before each draw cycle.
|
|
84
132
|
* @param {UID=} uid - (optional) A UID identifying the currently drawn element(s).
|
|
@@ -109,13 +157,27 @@ var drawutils = /** @class */ (function () {
|
|
|
109
157
|
drawutils.prototype.setConfiguration = function (configuration) {
|
|
110
158
|
this.ctx.globalCompositeOperation = configuration.blendMode || "source-over";
|
|
111
159
|
};
|
|
160
|
+
// /**
|
|
161
|
+
// * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
|
|
162
|
+
// *
|
|
163
|
+
// * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
|
|
164
|
+
// * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
|
165
|
+
// * for how line dashes work.
|
|
166
|
+
// *
|
|
167
|
+
// * @method
|
|
168
|
+
// * @param {Array<number> lineDashes - The line-dash array configuration.
|
|
169
|
+
// * @returns {void}
|
|
170
|
+
// */
|
|
171
|
+
// setLineDash(lineDash: Array<number>) {
|
|
172
|
+
// this.lineDash = lineDash;
|
|
173
|
+
// }
|
|
112
174
|
/**
|
|
113
175
|
* This method shouled be called each time the currently drawn `Drawable` changes.
|
|
114
176
|
* It is used by some libraries for identifying elemente on re-renders.
|
|
115
177
|
*
|
|
116
178
|
* @name setCurrentId
|
|
117
179
|
* @method
|
|
118
|
-
* @param {UID} uid - A UID identifying the currently drawn element(s).
|
|
180
|
+
* @param {UID|null} uid - A UID identifying the currently drawn element(s).
|
|
119
181
|
**/
|
|
120
182
|
drawutils.prototype.setCurrentId = function (uid) {
|
|
121
183
|
// NOOP
|
|
@@ -126,7 +188,7 @@ var drawutils = /** @class */ (function () {
|
|
|
126
188
|
*
|
|
127
189
|
* @name setCurrentClassName
|
|
128
190
|
* @method
|
|
129
|
-
* @param {string} className - A class name for further custom use cases.
|
|
191
|
+
* @param {string|null} className - A class name for further custom use cases.
|
|
130
192
|
**/
|
|
131
193
|
drawutils.prototype.setCurrentClassName = function (className) {
|
|
132
194
|
// NOOP
|
|
@@ -135,17 +197,20 @@ var drawutils = /** @class */ (function () {
|
|
|
135
197
|
* Draw the line between the given two points with the specified (CSS-) color.
|
|
136
198
|
*
|
|
137
199
|
* @method line
|
|
138
|
-
* @param {
|
|
139
|
-
* @param {
|
|
200
|
+
* @param {XYCoords} zA - The start point of the line.
|
|
201
|
+
* @param {XYCoords} zB - The end point of the line.
|
|
140
202
|
* @param {string} color - Any valid CSS color string.
|
|
141
203
|
* @param {number} lineWidth? - [optional] The line's width.
|
|
204
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
205
|
+
*
|
|
142
206
|
* @return {void}
|
|
143
207
|
* @instance
|
|
144
208
|
* @memberof drawutils
|
|
145
209
|
**/
|
|
146
|
-
drawutils.prototype.line = function (zA, zB, color, lineWidth) {
|
|
210
|
+
drawutils.prototype.line = function (zA, zB, color, lineWidth, strokeOptions) {
|
|
147
211
|
this.ctx.save();
|
|
148
212
|
this.ctx.beginPath();
|
|
213
|
+
this.applyStrokeOpts(strokeOptions);
|
|
149
214
|
this.ctx.moveTo(this.offset.x + zA.x * this.scale.x, this.offset.y + zA.y * this.scale.y);
|
|
150
215
|
this.ctx.lineTo(this.offset.x + zB.x * this.scale.x, this.offset.y + zB.y * this.scale.y);
|
|
151
216
|
this.ctx.strokeStyle = color;
|
|
@@ -157,22 +222,76 @@ var drawutils = /** @class */ (function () {
|
|
|
157
222
|
* Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
|
|
158
223
|
*
|
|
159
224
|
* @method arrow
|
|
160
|
-
* @param {
|
|
161
|
-
* @param {
|
|
225
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
226
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
162
227
|
* @param {string} color - Any valid CSS color string.
|
|
163
228
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
229
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
230
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
231
|
+
*
|
|
164
232
|
* @return {void}
|
|
165
233
|
* @instance
|
|
166
234
|
* @memberof drawutils
|
|
167
235
|
**/
|
|
168
|
-
drawutils.prototype.arrow = function (zA, zB, color, lineWidth) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
236
|
+
drawutils.prototype.arrow = function (zA, zB, color, lineWidth, headLength, strokeOptions) {
|
|
237
|
+
if (headLength === void 0) { headLength = 8; }
|
|
238
|
+
var arrowHeadBasePosition = new Vertex_1.Vertex(0, 0);
|
|
239
|
+
this.arrowHead(zA, zB, color, lineWidth, headLength, undefined, arrowHeadBasePosition); // Will NOT use dash configuration
|
|
240
|
+
this.line(zA, arrowHeadBasePosition, color, lineWidth, strokeOptions); // Will use dash configuration
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* 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.
|
|
244
|
+
*
|
|
245
|
+
* @method cubicBezierArrow
|
|
246
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
247
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
248
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
249
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
250
|
+
* @param {string} color - The CSS color to draw the curve with.
|
|
251
|
+
* @param {number} lineWidth - (optional) The line width to use.
|
|
252
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
253
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
254
|
+
*
|
|
255
|
+
* @return {void}
|
|
256
|
+
* @instance
|
|
257
|
+
* @memberof DrawLib
|
|
258
|
+
*/
|
|
259
|
+
drawutils.prototype.cubicBezierArrow = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, headLength, strokeOptions) {
|
|
260
|
+
var arrowHeadBasePosition = new Vertex_1.Vertex(0, 0);
|
|
261
|
+
// Will NOT use dash configuration
|
|
262
|
+
this.arrowHead(endControlPoint, endPoint, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
|
|
263
|
+
var diff = arrowHeadBasePosition.difference(endPoint);
|
|
264
|
+
// Will use dash configuration
|
|
265
|
+
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);
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
|
|
269
|
+
*
|
|
270
|
+
* @method arrow
|
|
271
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
272
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
273
|
+
* @param {string} color - Any valid CSS color string.
|
|
274
|
+
* @param {number=1} lineWidth - (optional) The line width to use; default is 1.
|
|
275
|
+
* @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
|
|
276
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
277
|
+
* @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.
|
|
278
|
+
*
|
|
279
|
+
* @return {void}
|
|
280
|
+
* @instance
|
|
281
|
+
* @memberof DrawLib
|
|
282
|
+
**/
|
|
283
|
+
drawutils.prototype.arrowHead = function (zA, zB, color, lineWidth, headLength, strokeOptions, arrowHeadBasePositionBuffer) {
|
|
284
|
+
// var headLength: number = 8; // length of head in pixels
|
|
285
|
+
if (headLength === void 0) { headLength = 8; }
|
|
172
286
|
this.ctx.save();
|
|
173
287
|
this.ctx.beginPath();
|
|
174
|
-
|
|
175
|
-
|
|
288
|
+
this.applyStrokeOpts(strokeOptions);
|
|
289
|
+
var vertices = Vector_1.Vector.utils.buildArrowHead(zA, zB, headLength, this.scale.x, this.scale.y);
|
|
290
|
+
if (arrowHeadBasePositionBuffer) {
|
|
291
|
+
arrowHeadBasePositionBuffer.x = vertices[0].x / this.scale.x;
|
|
292
|
+
arrowHeadBasePositionBuffer.y = vertices[0].y / this.scale.y;
|
|
293
|
+
}
|
|
294
|
+
this.ctx.moveTo(this.offset.x + vertices[0].x, this.offset.y + vertices[0].y);
|
|
176
295
|
for (var i = 0; i < vertices.length; i++) {
|
|
177
296
|
this.ctx.lineTo(this.offset.x + vertices[i].x, this.offset.y + vertices[i].y);
|
|
178
297
|
}
|
|
@@ -188,8 +307,8 @@ var drawutils = /** @class */ (function () {
|
|
|
188
307
|
*
|
|
189
308
|
* @method image
|
|
190
309
|
* @param {Image} image - The image object to draw.
|
|
191
|
-
* @param {
|
|
192
|
-
* @param {
|
|
310
|
+
* @param {XYCoords} position - The position to draw the the upper left corner at.
|
|
311
|
+
* @param {XYCoords} size - The x/y-size to draw the image with.
|
|
193
312
|
* @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
|
|
194
313
|
* @return {void}
|
|
195
314
|
* @instance
|
|
@@ -219,7 +338,7 @@ var drawutils = /** @class */ (function () {
|
|
|
219
338
|
* @param {Image} textureImage - The image object to draw.
|
|
220
339
|
* @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
|
|
221
340
|
* @param {Polygon} polygon - The polygon to use as clip path.
|
|
222
|
-
* @param {
|
|
341
|
+
* @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
|
|
223
342
|
* @param {number} rotation - The rotation to use for the polygon (and for the texture).
|
|
224
343
|
* @param {XYCoords={x:0,y:0}} rotationCenter - (optional) The rotational center; default is center of bounding box.
|
|
225
344
|
* @return {void}
|
|
@@ -228,10 +347,9 @@ var drawutils = /** @class */ (function () {
|
|
|
228
347
|
**/
|
|
229
348
|
drawutils.prototype.texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation) {
|
|
230
349
|
var basePolygonBounds = polygon.getBounds();
|
|
231
|
-
var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
|
|
232
|
-
|
|
233
|
-
// var
|
|
234
|
-
var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
|
|
350
|
+
// var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
|
|
351
|
+
var targetCenterDifference = new Vertex_1.Vertex(polygonPosition.x, polygonPosition.y).difference(basePolygonBounds.getCenter());
|
|
352
|
+
// var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
|
|
235
353
|
// Get the position offset of the polygon
|
|
236
354
|
var targetTextureSize = new Vertex_1.Vertex(textureSize.width, textureSize.height);
|
|
237
355
|
// var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
|
|
@@ -254,53 +372,83 @@ var drawutils = /** @class */ (function () {
|
|
|
254
372
|
);
|
|
255
373
|
this.ctx.restore();
|
|
256
374
|
};
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
375
|
+
/*
|
|
376
|
+
_texturedPoly(
|
|
377
|
+
textureImage: HTMLImageElement,
|
|
378
|
+
textureSize: Bounds,
|
|
379
|
+
polygon: Polygon,
|
|
380
|
+
polygonPosition: XYCoords,
|
|
381
|
+
rotation: number,
|
|
382
|
+
rotationCenter: XYCoords = { x: 0, y: 0 }
|
|
383
|
+
): void {
|
|
384
|
+
var basePolygonBounds = polygon.getBounds();
|
|
385
|
+
var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
|
|
386
|
+
var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
|
|
387
|
+
// var rotationalOffset = { x: 0, y: 0 };
|
|
388
|
+
var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
|
|
389
|
+
|
|
390
|
+
// Get the position offset of the polygon
|
|
391
|
+
var targetTextureSize = new Vertex(textureSize.width, textureSize.height);
|
|
392
|
+
var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
|
|
393
|
+
|
|
394
|
+
this.ctx.save();
|
|
395
|
+
|
|
396
|
+
// this.ctx.translate(
|
|
397
|
+
// this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
|
|
398
|
+
// this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
|
|
399
|
+
// );
|
|
400
|
+
this.ctx.translate(
|
|
401
|
+
this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
|
|
402
|
+
this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
|
|
403
|
+
);
|
|
404
|
+
this.ctx.rotate(rotation);
|
|
405
|
+
|
|
406
|
+
drawutils.helpers.clipPoly(
|
|
407
|
+
this.ctx,
|
|
408
|
+
{
|
|
409
|
+
x: (-targetCenterDifference.x * 1 - tileCenter.x - rotationalOffset.x) * this.scale.x,
|
|
410
|
+
y: (-targetCenterDifference.y * 1 - tileCenter.y - rotationalOffset.y) * this.scale.y
|
|
411
|
+
},
|
|
412
|
+
this.scale,
|
|
413
|
+
polygon.vertices
|
|
414
|
+
);
|
|
415
|
+
this.ctx.drawImage(
|
|
416
|
+
textureImage,
|
|
417
|
+
0,
|
|
418
|
+
0,
|
|
419
|
+
textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
|
|
279
420
|
textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
|
|
280
|
-
(-polygonPosition.x + targetTextureOffset.x * 1 - rotationalOffset.x * 1) * this.scale.x,
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
421
|
+
(-polygonPosition.x + targetTextureOffset.x * 1 - rotationalOffset.x * 1) * this.scale.x,
|
|
422
|
+
(-polygonPosition.y + targetTextureOffset.y * 1 - rotationalOffset.y * 1) * this.scale.y,
|
|
423
|
+
targetTextureSize.x * this.scale.x,
|
|
424
|
+
targetTextureSize.y * this.scale.y
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
// const scaledTextureSize = new Bounds(
|
|
428
|
+
// new Vertex(
|
|
429
|
+
// -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x,
|
|
430
|
+
// -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y
|
|
431
|
+
// ).scaleXY(this.scale, rotationCenter),
|
|
432
|
+
// new Vertex(
|
|
433
|
+
// -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x + targetTextureSize.x,
|
|
434
|
+
// -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y + targetTextureSize.y
|
|
435
|
+
// ).scaleXY(this.scale, rotationCenter)
|
|
436
|
+
// );
|
|
437
|
+
// this.ctx.drawImage(
|
|
438
|
+
// textureImage,
|
|
439
|
+
// 0,
|
|
440
|
+
// 0,
|
|
441
|
+
// textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
|
|
442
|
+
// textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
|
|
443
|
+
// scaledTextureSize.min.x,
|
|
444
|
+
// scaledTextureSize.min.y,
|
|
445
|
+
// scaledTextureSize.width,
|
|
446
|
+
// scaledTextureSize.height
|
|
447
|
+
// );
|
|
448
|
+
|
|
449
|
+
this.ctx.restore();
|
|
450
|
+
}
|
|
451
|
+
*/
|
|
304
452
|
/**
|
|
305
453
|
* Draw a rectangle.
|
|
306
454
|
*
|
|
@@ -309,10 +457,16 @@ var drawutils = /** @class */ (function () {
|
|
|
309
457
|
* @param {number} height - The height of the rectangle.
|
|
310
458
|
* @param {string} color - The color to use.
|
|
311
459
|
* @param {number=1} lineWidth - (optional) The line with to use (default is 1).
|
|
460
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
461
|
+
*
|
|
462
|
+
* @return {void}
|
|
463
|
+
* @instance
|
|
464
|
+
* @memberof drawutils
|
|
312
465
|
**/
|
|
313
|
-
drawutils.prototype.rect = function (position, width, height, color, lineWidth) {
|
|
466
|
+
drawutils.prototype.rect = function (position, width, height, color, lineWidth, strokeOptions) {
|
|
314
467
|
this.ctx.save();
|
|
315
468
|
this.ctx.beginPath();
|
|
469
|
+
this.applyStrokeOpts(strokeOptions);
|
|
316
470
|
this.ctx.moveTo(this.offset.x + position.x * this.scale.x, this.offset.y + position.y * this.scale.y);
|
|
317
471
|
this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + position.y * this.scale.y);
|
|
318
472
|
this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + (position.y + height) * this.scale.y);
|
|
@@ -323,43 +477,23 @@ var drawutils = /** @class */ (function () {
|
|
|
323
477
|
this._fillOrDraw(color);
|
|
324
478
|
this.ctx.restore();
|
|
325
479
|
};
|
|
326
|
-
// +---------------------------------------------------------------------------------
|
|
327
|
-
// | This is the final helper function for drawing and filling stuff. It is not
|
|
328
|
-
// | intended to be used from the outside.
|
|
329
|
-
// |
|
|
330
|
-
// | When in draw mode it draws the current shape.
|
|
331
|
-
// | When in fill mode it fills the current shape.
|
|
332
|
-
// |
|
|
333
|
-
// | This function is usually only called internally.
|
|
334
|
-
// |
|
|
335
|
-
// | @param color A stroke/fill color to use.
|
|
336
|
-
// +-------------------------------
|
|
337
|
-
// TODO: convert this to a STATIC function.
|
|
338
|
-
drawutils.prototype._fillOrDraw = function (color) {
|
|
339
|
-
if (this.fillShapes) {
|
|
340
|
-
this.ctx.fillStyle = color;
|
|
341
|
-
this.ctx.fill();
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
this.ctx.strokeStyle = color;
|
|
345
|
-
this.ctx.stroke();
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
480
|
/**
|
|
349
481
|
* Draw the given (cubic) bézier curve.
|
|
350
482
|
*
|
|
351
483
|
* @method cubicBezier
|
|
352
|
-
* @param {
|
|
353
|
-
* @param {
|
|
354
|
-
* @param {
|
|
355
|
-
* @param {
|
|
484
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
485
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
486
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
487
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
356
488
|
* @param {string} color - The CSS color to draw the curve with.
|
|
357
489
|
* @param {number} lineWidth - (optional) The line width to use.
|
|
490
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
491
|
+
*
|
|
358
492
|
* @return {void}
|
|
359
493
|
* @instance
|
|
360
494
|
* @memberof drawutils
|
|
361
495
|
*/
|
|
362
|
-
drawutils.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth) {
|
|
496
|
+
drawutils.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
|
|
363
497
|
if (startPoint instanceof CubicBezierCurve_1.CubicBezierCurve) {
|
|
364
498
|
this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
|
|
365
499
|
return;
|
|
@@ -367,6 +501,7 @@ var drawutils = /** @class */ (function () {
|
|
|
367
501
|
// Draw curve
|
|
368
502
|
this.ctx.save();
|
|
369
503
|
this.ctx.beginPath();
|
|
504
|
+
this.applyStrokeOpts(strokeOptions);
|
|
370
505
|
this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
|
|
371
506
|
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);
|
|
372
507
|
//this.ctx.closePath();
|
|
@@ -378,19 +513,22 @@ var drawutils = /** @class */ (function () {
|
|
|
378
513
|
* Draw the given (quadratic) bézier curve.
|
|
379
514
|
*
|
|
380
515
|
* @method quadraticBezier
|
|
381
|
-
* @param {
|
|
382
|
-
* @param {
|
|
383
|
-
* @param {
|
|
516
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
517
|
+
* @param {XYCoords} controlPoint - The control point the cubic Bézier curve.
|
|
518
|
+
* @param {XYCoords} endPoint - The end control point the cubic Bézier curve.
|
|
384
519
|
* @param {string} color - The CSS color to draw the curve with.
|
|
385
520
|
* @param {number|string} lineWidth - (optional) The line width to use.
|
|
521
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
522
|
+
*
|
|
386
523
|
* @return {void}
|
|
387
524
|
* @instance
|
|
388
525
|
* @memberof drawutils
|
|
389
526
|
*/
|
|
390
|
-
drawutils.prototype.quadraticBezier = function (startPoint, controlPoint, endPoint, color, lineWidth) {
|
|
527
|
+
drawutils.prototype.quadraticBezier = function (startPoint, controlPoint, endPoint, color, lineWidth, strokeOptions) {
|
|
391
528
|
// Draw curve
|
|
392
529
|
this.ctx.save();
|
|
393
530
|
this.ctx.beginPath();
|
|
531
|
+
this.applyStrokeOpts(strokeOptions);
|
|
394
532
|
this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
|
|
395
533
|
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);
|
|
396
534
|
this.ctx.lineWidth = lineWidth || 2;
|
|
@@ -405,22 +543,26 @@ var drawutils = /** @class */ (function () {
|
|
|
405
543
|
* <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
|
|
406
544
|
*
|
|
407
545
|
* @method cubicBezierPath
|
|
408
|
-
* @param {
|
|
546
|
+
* @param {XYCoords[]} path - The cubic bezier path as described above.
|
|
409
547
|
* @param {string} color - The CSS colot to draw the path with.
|
|
410
548
|
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
549
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
550
|
+
*
|
|
411
551
|
* @return {void}
|
|
412
552
|
* @instance
|
|
413
553
|
* @memberof drawutils
|
|
414
554
|
*/
|
|
415
|
-
drawutils.prototype.cubicBezierPath = function (path, color, lineWidth) {
|
|
416
|
-
if (!path || path.length == 0)
|
|
555
|
+
drawutils.prototype.cubicBezierPath = function (path, color, lineWidth, strokeOptions) {
|
|
556
|
+
if (!path || path.length == 0) {
|
|
417
557
|
return;
|
|
558
|
+
}
|
|
418
559
|
// Draw curve
|
|
419
560
|
this.ctx.save();
|
|
420
561
|
this.ctx.beginPath();
|
|
421
562
|
var endPoint;
|
|
422
563
|
var startControlPoint;
|
|
423
564
|
var endControlPoint;
|
|
565
|
+
this.applyStrokeOpts(strokeOptions);
|
|
424
566
|
this.ctx.moveTo(this.offset.x + path[0].x * this.scale.x, this.offset.y + path[0].y * this.scale.y);
|
|
425
567
|
for (var i = 1; i < path.length; i += 3) {
|
|
426
568
|
startControlPoint = path[i];
|
|
@@ -439,8 +581,8 @@ var drawutils = /** @class */ (function () {
|
|
|
439
581
|
* The colors for this are fixed and cannot be specified.
|
|
440
582
|
*
|
|
441
583
|
* @method handle
|
|
442
|
-
* @param {
|
|
443
|
-
* @param {
|
|
584
|
+
* @param {XYCoords} startPoint - The start of the handle.
|
|
585
|
+
* @param {XYCoords} endPoint - The end point of the handle.
|
|
444
586
|
* @return {void}
|
|
445
587
|
* @instance
|
|
446
588
|
* @memberof drawutils
|
|
@@ -455,21 +597,21 @@ var drawutils = /** @class */ (function () {
|
|
|
455
597
|
* Draw a handle line (with a light grey).
|
|
456
598
|
*
|
|
457
599
|
* @method handleLine
|
|
458
|
-
* @param {
|
|
459
|
-
* @param {
|
|
600
|
+
* @param {XYCoords} startPoint - The start point to draw the handle at.
|
|
601
|
+
* @param {XYCoords} endPoint - The end point to draw the handle at.
|
|
460
602
|
* @return {void}
|
|
461
603
|
* @instance
|
|
462
604
|
* @memberof drawutils
|
|
463
605
|
*/
|
|
464
606
|
drawutils.prototype.handleLine = function (startPoint, endPoint) {
|
|
465
607
|
// Draw handle lines
|
|
466
|
-
this.line(startPoint, endPoint, "
|
|
608
|
+
this.line(startPoint, endPoint, "rgba(128,128,128, 0.5)", undefined);
|
|
467
609
|
};
|
|
468
610
|
/**
|
|
469
611
|
* Draw a 1x1 dot with the specified (CSS-) color.
|
|
470
612
|
*
|
|
471
613
|
* @method dot
|
|
472
|
-
* @param {
|
|
614
|
+
* @param {XYCoords} p - The position to draw the dot at.
|
|
473
615
|
* @param {string} color - The CSS color to draw the dot with.
|
|
474
616
|
* @return {void}
|
|
475
617
|
* @instance
|
|
@@ -478,6 +620,7 @@ var drawutils = /** @class */ (function () {
|
|
|
478
620
|
drawutils.prototype.dot = function (p, color) {
|
|
479
621
|
this.ctx.save();
|
|
480
622
|
this.ctx.beginPath();
|
|
623
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
481
624
|
this.ctx.moveTo(Math.round(this.offset.x + this.scale.x * p.x), Math.round(this.offset.y + this.scale.y * p.y));
|
|
482
625
|
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));
|
|
483
626
|
this.ctx.closePath();
|
|
@@ -489,7 +632,7 @@ var drawutils = /** @class */ (function () {
|
|
|
489
632
|
* Draw the given point with the specified (CSS-) color and radius 3.
|
|
490
633
|
*
|
|
491
634
|
* @method point
|
|
492
|
-
* @param {
|
|
635
|
+
* @param {XYCoords} p - The position to draw the point at.
|
|
493
636
|
* @param {string} color - The CSS color to draw the point with.
|
|
494
637
|
* @return {void}
|
|
495
638
|
* @instance
|
|
@@ -497,6 +640,7 @@ var drawutils = /** @class */ (function () {
|
|
|
497
640
|
*/
|
|
498
641
|
drawutils.prototype.point = function (p, color) {
|
|
499
642
|
var radius = 3;
|
|
643
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
500
644
|
this.ctx.beginPath();
|
|
501
645
|
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);
|
|
502
646
|
this.ctx.closePath();
|
|
@@ -509,15 +653,18 @@ var drawutils = /** @class */ (function () {
|
|
|
509
653
|
* Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
|
|
510
654
|
*
|
|
511
655
|
* @method circle
|
|
512
|
-
* @param {
|
|
656
|
+
* @param {XYCoords} center - The center of the circle.
|
|
513
657
|
* @param {number} radius - The radius of the circle.
|
|
514
658
|
* @param {string} color - The CSS color to draw the circle with.
|
|
515
659
|
* @param {number} lineWidth - The line width (optional, default=1).
|
|
660
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
661
|
+
*
|
|
516
662
|
* @return {void}
|
|
517
663
|
* @instance
|
|
518
664
|
* @memberof drawutils
|
|
519
665
|
*/
|
|
520
|
-
drawutils.prototype.circle = function (center, radius, color, lineWidth) {
|
|
666
|
+
drawutils.prototype.circle = function (center, radius, color, lineWidth, strokeOptions) {
|
|
667
|
+
this.applyStrokeOpts(strokeOptions);
|
|
521
668
|
this.ctx.beginPath();
|
|
522
669
|
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);
|
|
523
670
|
this.ctx.closePath();
|
|
@@ -525,24 +672,28 @@ var drawutils = /** @class */ (function () {
|
|
|
525
672
|
this._fillOrDraw(color);
|
|
526
673
|
};
|
|
527
674
|
/**
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
675
|
+
* Draw a circular arc (section of a circle) with the given CSS color.
|
|
676
|
+
*
|
|
677
|
+
* @method circleArc
|
|
678
|
+
* @param {XYCoords} center - The center of the circle.
|
|
679
|
+
* @param {number} radius - The radius of the circle.
|
|
680
|
+
* @param {number} startAngle - The angle to start at.
|
|
681
|
+
* @param {number} endAngle - The angle to end at.
|
|
682
|
+
* @param {string=#000000} color - The CSS color to draw the circle with.
|
|
683
|
+
* @param {number=1} lineWidth - The line width to use
|
|
684
|
+
* @param {boolean=false} options.asSegment - If `true` then no beginPath and no draw will be applied (as part of larger path).
|
|
685
|
+
* @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
|
|
686
|
+
* @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
|
|
687
|
+
*
|
|
688
|
+
* @return {void}
|
|
689
|
+
* @instance
|
|
690
|
+
* @memberof drawutils
|
|
691
|
+
*/
|
|
542
692
|
drawutils.prototype.circleArc = function (center, radius, startAngle, endAngle, color, lineWidth, options) {
|
|
543
693
|
if (!options || !options.asSegment) {
|
|
544
694
|
this.ctx.beginPath();
|
|
545
695
|
}
|
|
696
|
+
this.applyStrokeOpts(options);
|
|
546
697
|
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);
|
|
547
698
|
if (!options || !options.asSegment) {
|
|
548
699
|
// this.ctx.closePath();
|
|
@@ -554,20 +705,23 @@ var drawutils = /** @class */ (function () {
|
|
|
554
705
|
* Draw an ellipse with the specified (CSS-) color and thw two radii.
|
|
555
706
|
*
|
|
556
707
|
* @method ellipse
|
|
557
|
-
* @param {
|
|
708
|
+
* @param {XYCoords} center - The center of the ellipse.
|
|
558
709
|
* @param {number} radiusX - The radius of the ellipse.
|
|
559
710
|
* @param {number} radiusY - The radius of the ellipse.
|
|
560
711
|
* @param {string} color - The CSS color to draw the ellipse with.
|
|
561
712
|
* @param {number} lineWidth=1 - An optional line width param (default is 1).
|
|
562
713
|
* @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
|
|
714
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
715
|
+
*
|
|
563
716
|
* @return {void}
|
|
564
717
|
* @instance
|
|
565
718
|
* @memberof drawutils
|
|
566
719
|
*/
|
|
567
|
-
drawutils.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation) {
|
|
720
|
+
drawutils.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation, strokeOptions) {
|
|
568
721
|
if (typeof rotation === "undefined") {
|
|
569
722
|
rotation = 0.0;
|
|
570
723
|
}
|
|
724
|
+
this.applyStrokeOpts(strokeOptions);
|
|
571
725
|
this.ctx.beginPath();
|
|
572
726
|
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);
|
|
573
727
|
this.ctx.closePath();
|
|
@@ -584,11 +738,14 @@ var drawutils = /** @class */ (function () {
|
|
|
584
738
|
* @param {number} size - The size of the square.
|
|
585
739
|
* @param {string} color - The CSS color to draw the square with.
|
|
586
740
|
* @param {number} lineWidth - The line with to use (optional, default is 1).
|
|
741
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
742
|
+
*
|
|
587
743
|
* @return {void}
|
|
588
744
|
* @instance
|
|
589
745
|
* @memberof drawutils
|
|
590
746
|
*/
|
|
591
|
-
drawutils.prototype.square = function (center, size, color, lineWidth) {
|
|
747
|
+
drawutils.prototype.square = function (center, size, color, lineWidth, strokeOptions) {
|
|
748
|
+
this.applyStrokeOpts(strokeOptions);
|
|
592
749
|
this.ctx.beginPath();
|
|
593
750
|
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);
|
|
594
751
|
this.ctx.closePath();
|
|
@@ -599,7 +756,7 @@ var drawutils = /** @class */ (function () {
|
|
|
599
756
|
* Draw a grid of horizontal and vertical lines with the given (CSS-) color.
|
|
600
757
|
*
|
|
601
758
|
* @method grid
|
|
602
|
-
* @param {
|
|
759
|
+
* @param {XYCoords} center - The center of the grid.
|
|
603
760
|
* @param {number} width - The total width of the grid (width/2 each to the left and to the right).
|
|
604
761
|
* @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
|
|
605
762
|
* @param {number} sizeX - The horizontal grid size.
|
|
@@ -610,6 +767,7 @@ var drawutils = /** @class */ (function () {
|
|
|
610
767
|
* @memberof drawutils
|
|
611
768
|
*/
|
|
612
769
|
drawutils.prototype.grid = function (center, width, height, sizeX, sizeY, color) {
|
|
770
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
613
771
|
this.ctx.beginPath();
|
|
614
772
|
var yMin = -Math.ceil((height * 0.5) / sizeY) * sizeY;
|
|
615
773
|
var yMax = height / 2;
|
|
@@ -634,7 +792,7 @@ var drawutils = /** @class */ (function () {
|
|
|
634
792
|
* This works analogue to the grid() function
|
|
635
793
|
*
|
|
636
794
|
* @method raster
|
|
637
|
-
* @param {
|
|
795
|
+
* @param {XYCoords} center - The center of the raster.
|
|
638
796
|
* @param {number} width - The total width of the raster (width/2 each to the left and to the right).
|
|
639
797
|
* @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
|
|
640
798
|
* @param {number} sizeX - The horizontal raster size.
|
|
@@ -646,6 +804,7 @@ var drawutils = /** @class */ (function () {
|
|
|
646
804
|
*/
|
|
647
805
|
drawutils.prototype.raster = function (center, width, height, sizeX, sizeY, color) {
|
|
648
806
|
this.ctx.save();
|
|
807
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
649
808
|
this.ctx.beginPath();
|
|
650
809
|
for (var x = -Math.ceil((width * 0.5) / sizeX) * sizeX; x < width / 2; x += sizeX) {
|
|
651
810
|
for (var y = -Math.ceil((height * 0.5) / sizeY) * sizeY; y < height / 2; y += sizeY) {
|
|
@@ -670,14 +829,15 @@ var drawutils = /** @class */ (function () {
|
|
|
670
829
|
* as even shaped diamonds.
|
|
671
830
|
*
|
|
672
831
|
* @method diamondHandle
|
|
673
|
-
* @param {
|
|
674
|
-
* @param {
|
|
832
|
+
* @param {XYCoords} center - The center of the diamond.
|
|
833
|
+
* @param {number} size - The x/y-size of the diamond.
|
|
675
834
|
* @param {string} color - The CSS color to draw the diamond with.
|
|
676
835
|
* @return {void}
|
|
677
836
|
* @instance
|
|
678
837
|
* @memberof drawutils
|
|
679
838
|
*/
|
|
680
839
|
drawutils.prototype.diamondHandle = function (center, size, color) {
|
|
840
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
681
841
|
this.ctx.beginPath();
|
|
682
842
|
this.ctx.moveTo(this.offset.x + center.x * this.scale.x - size / 2.0, this.offset.y + center.y * this.scale.y);
|
|
683
843
|
this.ctx.lineTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y - size / 2.0);
|
|
@@ -695,14 +855,15 @@ var drawutils = /** @class */ (function () {
|
|
|
695
855
|
* as even shaped squares.
|
|
696
856
|
*
|
|
697
857
|
* @method squareHandle
|
|
698
|
-
* @param {
|
|
699
|
-
* @param {
|
|
858
|
+
* @param {XYCoords} center - The center of the square.
|
|
859
|
+
* @param {number} size - The x/y-size of the square.
|
|
700
860
|
* @param {string} color - The CSS color to draw the square with.
|
|
701
861
|
* @return {void}
|
|
702
862
|
* @instance
|
|
703
863
|
* @memberof drawutils
|
|
704
864
|
*/
|
|
705
865
|
drawutils.prototype.squareHandle = function (center, size, color) {
|
|
866
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
706
867
|
this.ctx.beginPath();
|
|
707
868
|
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);
|
|
708
869
|
this.ctx.closePath();
|
|
@@ -717,7 +878,7 @@ var drawutils = /** @class */ (function () {
|
|
|
717
878
|
* as even shaped circles.
|
|
718
879
|
*
|
|
719
880
|
* @method circleHandle
|
|
720
|
-
* @param {
|
|
881
|
+
* @param {XYCoords} center - The center of the circle.
|
|
721
882
|
* @param {number} radius - The radius of the circle.
|
|
722
883
|
* @param {string} color - The CSS color to draw the circle with.
|
|
723
884
|
* @return {void}
|
|
@@ -726,6 +887,7 @@ var drawutils = /** @class */ (function () {
|
|
|
726
887
|
*/
|
|
727
888
|
drawutils.prototype.circleHandle = function (center, radius, color) {
|
|
728
889
|
radius = radius || 3;
|
|
890
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
729
891
|
this.ctx.beginPath();
|
|
730
892
|
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);
|
|
731
893
|
this.ctx.closePath();
|
|
@@ -748,6 +910,7 @@ var drawutils = /** @class */ (function () {
|
|
|
748
910
|
*/
|
|
749
911
|
drawutils.prototype.crosshair = function (center, radius, color, lineWidth) {
|
|
750
912
|
this.ctx.save();
|
|
913
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
751
914
|
this.ctx.beginPath();
|
|
752
915
|
this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y);
|
|
753
916
|
this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y);
|
|
@@ -775,6 +938,7 @@ var drawutils = /** @class */ (function () {
|
|
|
775
938
|
*/
|
|
776
939
|
drawutils.prototype.cross = function (center, radius, color, lineWidth) {
|
|
777
940
|
this.ctx.save();
|
|
941
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
778
942
|
this.ctx.beginPath();
|
|
779
943
|
this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y - radius);
|
|
780
944
|
this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y + radius);
|
|
@@ -793,30 +957,35 @@ var drawutils = /** @class */ (function () {
|
|
|
793
957
|
* @param {Polygon} polygon - The polygon to draw.
|
|
794
958
|
* @param {string} color - The CSS color to draw the polygon with.
|
|
795
959
|
* @param {string} lineWidth - The line width to use.
|
|
960
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
961
|
+
*
|
|
796
962
|
* @return {void}
|
|
797
963
|
* @instance
|
|
798
964
|
* @memberof drawutils
|
|
799
965
|
*/
|
|
800
|
-
drawutils.prototype.polygon = function (polygon, color, lineWidth) {
|
|
801
|
-
this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth);
|
|
966
|
+
drawutils.prototype.polygon = function (polygon, color, lineWidth, strokeOptions) {
|
|
967
|
+
this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth, strokeOptions);
|
|
802
968
|
};
|
|
803
969
|
/**
|
|
804
970
|
* Draw a polygon line (alternative function to the polygon).
|
|
805
971
|
*
|
|
806
972
|
* @method polyline
|
|
807
|
-
* @param {
|
|
973
|
+
* @param {XYCoords[]} vertices - The polygon vertices to draw.
|
|
808
974
|
* @param {boolan} isOpen - If true the polyline will not be closed at its end.
|
|
809
975
|
* @param {string} color - The CSS color to draw the polygon with.
|
|
810
976
|
* @param {number} lineWidth - The line width (default is 1.0);
|
|
977
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
978
|
+
*
|
|
811
979
|
* @return {void}
|
|
812
980
|
* @instance
|
|
813
981
|
* @memberof drawutils
|
|
814
982
|
*/
|
|
815
|
-
drawutils.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
|
|
983
|
+
drawutils.prototype.polyline = function (vertices, isOpen, color, lineWidth, strokeOptions) {
|
|
816
984
|
if (vertices.length <= 1) {
|
|
817
985
|
return;
|
|
818
986
|
}
|
|
819
987
|
this.ctx.save();
|
|
988
|
+
this.applyStrokeOpts(strokeOptions);
|
|
820
989
|
this.ctx.beginPath();
|
|
821
990
|
this.ctx.lineWidth = (lineWidth || 1.0) * this.scale.x;
|
|
822
991
|
this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
|
|
@@ -928,6 +1097,8 @@ var drawutils = /** @class */ (function () {
|
|
|
928
1097
|
* @param {string=null} color - (optional) The color to draw this path with (default is null).
|
|
929
1098
|
* @param {number=1} lineWidth - (optional) the line width to use (default is 1).
|
|
930
1099
|
* @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.
|
|
1100
|
+
* @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
|
|
1101
|
+
* @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
|
|
931
1102
|
* @instance
|
|
932
1103
|
* @memberof drawutils
|
|
933
1104
|
* @return {R} An instance representing the drawn path.
|
|
@@ -939,6 +1110,7 @@ var drawutils = /** @class */ (function () {
|
|
|
939
1110
|
this.ctx.strokeStyle = color;
|
|
940
1111
|
}
|
|
941
1112
|
this.ctx.lineWidth = lineWidth || 1;
|
|
1113
|
+
this.applyStrokeOpts(options);
|
|
942
1114
|
if (this.fillShapes) {
|
|
943
1115
|
if (color) {
|
|
944
1116
|
this.ctx.fillStyle = color;
|