plotboilerplate 1.20.2 → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +1985 -1368
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +1170 -541
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/BezierPath.d.ts +27 -49
- package/src/cjs/BezierPath.js +67 -234
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Bounds.d.ts +14 -1
- package/src/cjs/Bounds.js +21 -1
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +70 -1
- package/src/cjs/CubicBezierCurve.js +130 -12
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Line.d.ts +2 -1
- package/src/cjs/Line.js +1 -0
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/PBText.d.ts +2 -1
- package/src/cjs/PBText.js +10 -9
- package/src/cjs/PBText.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +4 -13
- package/src/cjs/PlotBoilerplate.js +61 -15
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +35 -1
- package/src/cjs/Polygon.js +87 -1
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/VEllipse.js +1 -1
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/Vector.d.ts +4 -4
- package/src/cjs/Vector.js +2 -2
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +2 -1
- package/src/cjs/VertTuple.js +4 -3
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +14 -3
- package/src/cjs/Vertex.js +18 -3
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/draw.d.ts +154 -75
- package/src/cjs/draw.js +308 -137
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +87 -50
- package/src/cjs/drawgl.js +86 -31
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +226 -53
- package/src/cjs/drawutilssvg.js +374 -92
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +157 -79
- package/src/cjs/interfaces/DrawLib.js +6 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +13 -2
- package/src/cjs/interfaces/core.js +1 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/creategui.js +16 -10
- package/src/cjs/utils/detectDarkMode.d.ts +10 -0
- package/src/cjs/utils/detectDarkMode.js +32 -0
- package/src/cjs/utils/detectDarkMode.js.map +1 -0
- package/src/esm/BezierPath.d.ts +27 -49
- package/src/esm/BezierPath.js +67 -234
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Bounds.d.ts +14 -1
- package/src/esm/Bounds.js +19 -1
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +70 -1
- package/src/esm/CubicBezierCurve.js +130 -12
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Line.d.ts +2 -1
- package/src/esm/Line.js +1 -0
- package/src/esm/Line.js.map +1 -1
- package/src/esm/PBText.d.ts +2 -1
- package/src/esm/PBText.js +10 -9
- package/src/esm/PBText.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +4 -13
- package/src/esm/PlotBoilerplate.js +62 -16
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +35 -1
- package/src/esm/Polygon.js +85 -1
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/VEllipse.js +1 -1
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/Vector.d.ts +4 -4
- package/src/esm/Vector.js +2 -2
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.d.ts +2 -1
- package/src/esm/VertTuple.js +4 -3
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +14 -3
- package/src/esm/Vertex.js +18 -3
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/draw.d.ts +154 -75
- package/src/esm/draw.js +304 -135
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +87 -50
- package/src/esm/drawgl.js +86 -31
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +226 -53
- package/src/esm/drawutilssvg.js +369 -92
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +157 -79
- package/src/esm/interfaces/DrawLib.js +6 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +13 -2
- package/src/esm/interfaces/core.js +1 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/detectDarkMode.d.ts +10 -0
- package/src/esm/utils/detectDarkMode.js +28 -0
- package/src/esm/utils/detectDarkMode.js.map +1 -0
- package/src/ts/BezierPath.ts +72 -241
- package/src/ts/Bounds.ts +25 -1
- package/src/ts/CubicBezierCurve.ts +139 -12
- package/src/ts/Line.ts +2 -1
- package/src/ts/PBText.ts +10 -9
- package/src/ts/PlotBoilerplate.ts +56 -19
- package/src/ts/Polygon.ts +91 -1
- package/src/ts/VEllipse.ts +2 -2
- package/src/ts/Vector.ts +4 -4
- package/src/ts/VertTuple.ts +4 -3
- package/src/ts/Vertex.ts +20 -4
- package/src/ts/draw.ts +311 -115
- package/src/ts/drawgl.ts +133 -71
- package/src/ts/drawutilssvg.ts +543 -121
- package/src/ts/interfaces/DrawLib.ts +219 -83
- package/src/ts/interfaces/core.ts +14 -2
- package/src/ts/utils/detectDarkMode.ts +30 -0
package/src/esm/drawutilssvg.js
CHANGED
|
@@ -37,12 +37,21 @@
|
|
|
37
37
|
* @modified 2022-11-10 Tweaking some type issues.
|
|
38
38
|
* @modified 2023-02-04 Fixed a typo in the CSS classname for cubic Bézier paths: cubicBezier (was cubierBezier).
|
|
39
39
|
* @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
|
|
40
|
-
* @
|
|
40
|
+
* @modified 2023-09-29 Added initialization checks for null parameters.
|
|
41
|
+
* @modified 2023-09-29 Added a missing implementation to the `drawurilssvg.do(XYCoords,string)` function. Didn't draw anything.
|
|
42
|
+
* @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.
|
|
43
|
+
* @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
|
|
44
|
+
* @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
|
|
45
|
+
* @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
|
|
46
|
+
* @modified 2023-10-04 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
|
|
47
|
+
*
|
|
48
|
+
* @version 1.6.7
|
|
41
49
|
**/
|
|
42
50
|
import { CircleSector } from "./CircleSector";
|
|
43
51
|
import { CubicBezierCurve } from "./CubicBezierCurve";
|
|
44
52
|
import { Vertex } from "./Vertex";
|
|
45
53
|
import { UIDGenerator } from "./UIDGenerator";
|
|
54
|
+
import { Vector } from "./Vector";
|
|
46
55
|
const RAD_TO_DEG = 180 / Math.PI;
|
|
47
56
|
/**
|
|
48
57
|
* @classdesc A helper class for basic SVG drawing operations. This class should
|
|
@@ -78,6 +87,9 @@ export class drawutilssvg {
|
|
|
78
87
|
this.cache = new Map();
|
|
79
88
|
this.setSize(canvasSize);
|
|
80
89
|
if (isSecondary) {
|
|
90
|
+
if (!gNode || !bufferGNode || !nodeDefs || !bufferNodeDefs) {
|
|
91
|
+
throw "Cannot create secondary svg draw lib with undefinde gNode|bufferGNode|nodeDefs|bufferNodeDefs.";
|
|
92
|
+
}
|
|
81
93
|
this.gNode = gNode;
|
|
82
94
|
this.bufferGNode = bufferGNode;
|
|
83
95
|
this.nodeDefs = nodeDefs;
|
|
@@ -218,6 +230,9 @@ export class drawutilssvg {
|
|
|
218
230
|
if (this.drawlibConfiguration.blendMode) {
|
|
219
231
|
node.style["mix-blend-mode"] = this.drawlibConfiguration.blendMode;
|
|
220
232
|
}
|
|
233
|
+
// if (this.lineDashEnabled && this.lineDash && this.lineDash.length > 0 && drawutilssvg.nodeSupportsLineDash(nodeName)) {
|
|
234
|
+
// node.setAttribute("stroke-dasharray", this.lineDash.join(" "));
|
|
235
|
+
// }
|
|
221
236
|
return node;
|
|
222
237
|
}
|
|
223
238
|
/**
|
|
@@ -240,23 +255,58 @@ export class drawutilssvg {
|
|
|
240
255
|
* @param {number=1} lineWidth - (optional) A line width to use for drawing (default is 1).
|
|
241
256
|
* @return {SVGElement} The node itself (for chaining).
|
|
242
257
|
*/
|
|
243
|
-
_bindFillDraw(node, className, color, lineWidth) {
|
|
258
|
+
_bindFillDraw(node, className, color, lineWidth, strokeOptions) {
|
|
259
|
+
this._configureNode(node, className, this.fillShapes, color, lineWidth, strokeOptions);
|
|
260
|
+
return this._bindNode(node, undefined);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Bind this given node to a parent. If no parent is passed then the global
|
|
264
|
+
* node buffer will be used.
|
|
265
|
+
*
|
|
266
|
+
* @method _bindNode
|
|
267
|
+
* @private
|
|
268
|
+
* @instance
|
|
269
|
+
* @memberof drawutilssvg
|
|
270
|
+
* @param {SVGElement} node - The SVG node to bind.
|
|
271
|
+
* @param {SVGElement=} bindingParent - (optional) You may pass node other than the glober buffer node.
|
|
272
|
+
* @returns {SVGElement} The passed node itself.
|
|
273
|
+
*/
|
|
274
|
+
_bindNode(node, bindingParent) {
|
|
275
|
+
if (!node.parentNode) {
|
|
276
|
+
// Attach to DOM only if not already attached
|
|
277
|
+
(bindingParent !== null && bindingParent !== void 0 ? bindingParent : this.bufferGNode).appendChild(node);
|
|
278
|
+
}
|
|
279
|
+
return node;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Add custom CSS class names and the globally defined CSS classname to the
|
|
283
|
+
* given node.
|
|
284
|
+
*
|
|
285
|
+
* @method addCSSClasses
|
|
286
|
+
* @private
|
|
287
|
+
* @instance
|
|
288
|
+
* @memberof drawutilssvg
|
|
289
|
+
* @param {SVGElement} node - The SVG node to bind.
|
|
290
|
+
* @param {string} className - The additional custom classname to add.
|
|
291
|
+
* @returns {void}
|
|
292
|
+
*/
|
|
293
|
+
_addCSSClasses(node, className) {
|
|
244
294
|
if (this.curClassName) {
|
|
245
295
|
node.setAttribute("class", `${className} ${this.curClassName}`);
|
|
246
296
|
}
|
|
247
297
|
else {
|
|
248
298
|
node.setAttribute("class", className);
|
|
249
299
|
}
|
|
250
|
-
|
|
251
|
-
|
|
300
|
+
}
|
|
301
|
+
_configureNode(node, className, fillMode, color, lineWidth, strokeOptions) {
|
|
302
|
+
this._addCSSClasses(node, className);
|
|
303
|
+
node.setAttribute("fill", fillMode && color ? color : "none");
|
|
304
|
+
node.setAttribute("stroke", fillMode ? "none" : color || "none");
|
|
252
305
|
node.setAttribute("stroke-width", `${lineWidth || 1}`);
|
|
253
306
|
if (this.curId) {
|
|
254
307
|
node.setAttribute("id", `${this.curId}`); // Maybe React-style 'key' would be better?
|
|
255
308
|
}
|
|
256
|
-
|
|
257
|
-
// Attach to DOM only if not already attached
|
|
258
|
-
this.bufferGNode.appendChild(node);
|
|
259
|
-
}
|
|
309
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
260
310
|
return node;
|
|
261
311
|
}
|
|
262
312
|
/**
|
|
@@ -278,7 +328,7 @@ export class drawutilssvg {
|
|
|
278
328
|
* that under the hood the same gl context and gl program will be used.
|
|
279
329
|
*/
|
|
280
330
|
copyInstance(fillShapes) {
|
|
281
|
-
var copy = new drawutilssvg(this.svgNode, this.offset, this.scale, this.canvasSize, fillShapes, null, // no DrawConfig
|
|
331
|
+
var copy = new drawutilssvg(this.svgNode, this.offset, this.scale, this.canvasSize, fillShapes, null, // no DrawConfig – this will work as long as `isSecondary===true`
|
|
282
332
|
true, // isSecondary
|
|
283
333
|
this.gNode, this.bufferGNode, this.nodeDefs, this.bufferedNodeDefs);
|
|
284
334
|
return copy;
|
|
@@ -293,6 +343,20 @@ export class drawutilssvg {
|
|
|
293
343
|
setConfiguration(configuration) {
|
|
294
344
|
this.drawlibConfiguration = configuration;
|
|
295
345
|
}
|
|
346
|
+
// /**
|
|
347
|
+
// * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
|
|
348
|
+
// *
|
|
349
|
+
// * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
|
|
350
|
+
// * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
|
351
|
+
// * for how line dashes work.
|
|
352
|
+
// *
|
|
353
|
+
// * @method
|
|
354
|
+
// * @param {Array<number> lineDashes - The line-dash array configuration.
|
|
355
|
+
// * @returns {void}
|
|
356
|
+
// */
|
|
357
|
+
// setLineDash(lineDashes: Array<number>) {
|
|
358
|
+
// this.lineDash = lineDashes;
|
|
359
|
+
// }
|
|
296
360
|
/**
|
|
297
361
|
* This method shouled be called each time the currently drawn `Drawable` changes.
|
|
298
362
|
* It is used by some libraries for identifying elemente on re-renders.
|
|
@@ -367,6 +431,26 @@ export class drawutilssvg {
|
|
|
367
431
|
this.nodeDefs = this.bufferedNodeDefs;
|
|
368
432
|
this.bufferedNodeDefs = tmpDefsNode;
|
|
369
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* A private helper method to apply stroke options to the current
|
|
436
|
+
* context.
|
|
437
|
+
* @param {StrokeOptions=} strokeOptions -
|
|
438
|
+
*/
|
|
439
|
+
applyStrokeOpts(node, strokeOptions) {
|
|
440
|
+
if (strokeOptions &&
|
|
441
|
+
strokeOptions.dashArray &&
|
|
442
|
+
strokeOptions.dashArray.length > 0 &&
|
|
443
|
+
drawutilssvg.nodeSupportsLineDash(node.tagName)) {
|
|
444
|
+
node.setAttribute("stroke-dasharray", strokeOptions.dashArray
|
|
445
|
+
.map((dashArayElem) => {
|
|
446
|
+
return dashArayElem * this.scale.x;
|
|
447
|
+
})
|
|
448
|
+
.join(" "));
|
|
449
|
+
if (strokeOptions.dashOffset) {
|
|
450
|
+
node.setAttribute("stroke-dashoffset", `${strokeOptions.dashOffset * this.scale.x}`);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
370
454
|
_x(x) {
|
|
371
455
|
return this.offset.x + this.scale.x * x;
|
|
372
456
|
}
|
|
@@ -377,47 +461,101 @@ export class drawutilssvg {
|
|
|
377
461
|
* Draw the line between the given two points with the specified (CSS-) color.
|
|
378
462
|
*
|
|
379
463
|
* @method line
|
|
380
|
-
* @param {
|
|
381
|
-
* @param {
|
|
464
|
+
* @param {XYCoords} zA - The start point of the line.
|
|
465
|
+
* @param {XYCoords} zB - The end point of the line.
|
|
382
466
|
* @param {string} color - Any valid CSS color string.
|
|
383
467
|
* @param {number=1} lineWidth? - [optional] The line's width.
|
|
468
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
469
|
+
*
|
|
384
470
|
* @return {void}
|
|
385
471
|
* @instance
|
|
386
472
|
* @memberof drawutilssvg
|
|
387
473
|
**/
|
|
388
|
-
line(zA, zB, color, lineWidth) {
|
|
389
|
-
const line = this.makeNode("line");
|
|
390
|
-
|
|
391
|
-
line.setAttribute("
|
|
392
|
-
line.setAttribute("
|
|
393
|
-
line.setAttribute("
|
|
394
|
-
|
|
474
|
+
line(zA, zB, color, lineWidth, strokeOptions) {
|
|
475
|
+
// const line: SVGElement = this.makeNode("line");
|
|
476
|
+
// this.applyStrokeOpts(line, strokeOptions);
|
|
477
|
+
// line.setAttribute("x1", `${this._x(zA.x)}`);
|
|
478
|
+
// line.setAttribute("y1", `${this._y(zA.y)}`);
|
|
479
|
+
// line.setAttribute("x2", `${this._x(zB.x)}`);
|
|
480
|
+
// line.setAttribute("y2", `${this._y(zB.y)}`);
|
|
481
|
+
const line = this.makeLineNode(zA, zB, color, lineWidth, strokeOptions);
|
|
482
|
+
return this._bindFillDraw(line, "line", color, lineWidth || 1, strokeOptions);
|
|
395
483
|
}
|
|
396
484
|
/**
|
|
397
485
|
* Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
|
|
398
486
|
*
|
|
399
487
|
* @method arrow
|
|
400
|
-
* @param {
|
|
401
|
-
* @param {
|
|
488
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
489
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
402
490
|
* @param {string} color - Any valid CSS color string.
|
|
403
491
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
492
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
493
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
494
|
+
*
|
|
404
495
|
* @return {void}
|
|
405
496
|
* @instance
|
|
406
497
|
* @memberof drawutilssvg
|
|
407
498
|
**/
|
|
408
|
-
arrow(zA, zB, color, lineWidth) {
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
499
|
+
arrow(zA, zB, color, lineWidth, headLength = 8, strokeOptions) {
|
|
500
|
+
const group = this.makeNode("g");
|
|
501
|
+
const arrowHeadBasePosition = { x: 0, y: 0 };
|
|
502
|
+
// Just create the child nodes, don't bind them to the root node.
|
|
503
|
+
const arrowHead = this.makeArrowHeadNode(zA, zB, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
|
|
504
|
+
const line = this.makeLineNode(zA, arrowHeadBasePosition, color, lineWidth, strokeOptions);
|
|
505
|
+
group.appendChild(line);
|
|
506
|
+
group.appendChild(arrowHead);
|
|
507
|
+
this._addCSSClasses(group, "linear-arrow");
|
|
508
|
+
this._bindNode(group, undefined);
|
|
509
|
+
return group;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* 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.
|
|
513
|
+
*
|
|
514
|
+
* @method cubicBezierArrow
|
|
515
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
516
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
517
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
518
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
519
|
+
* @param {string} color - The CSS color to draw the curve with.
|
|
520
|
+
* @param {number} lineWidth - (optional) The line width to use.
|
|
521
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
522
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
523
|
+
*
|
|
524
|
+
* @return {void}
|
|
525
|
+
* @instance
|
|
526
|
+
* @memberof DrawLib
|
|
527
|
+
*/
|
|
528
|
+
cubicBezierArrow(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, headLength = 8, strokeOptions) {
|
|
529
|
+
const group = this.makeNode("g");
|
|
530
|
+
// Just create the child nodes, don't bind them to the root node.
|
|
531
|
+
const arrowHeadBasePosition = new Vertex(0, 0);
|
|
532
|
+
const arrowHead = this.makeArrowHeadNode(endControlPoint, endPoint, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
|
|
533
|
+
const diff = arrowHeadBasePosition.difference(endPoint);
|
|
534
|
+
const bezier = this.makeCubicBezierNode(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);
|
|
535
|
+
group.appendChild(bezier);
|
|
536
|
+
group.appendChild(arrowHead);
|
|
537
|
+
this._addCSSClasses(group, "cubicbezier-arrow");
|
|
538
|
+
this._bindNode(group, undefined);
|
|
539
|
+
return group;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
|
|
543
|
+
*
|
|
544
|
+
* @method arrow
|
|
545
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
546
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
547
|
+
* @param {string} color - Any valid CSS color string.
|
|
548
|
+
* @param {number=1} lineWidth - (optional) The line width to use; default is 1.
|
|
549
|
+
* @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
|
|
550
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
551
|
+
*
|
|
552
|
+
* @return {void}
|
|
553
|
+
* @instance
|
|
554
|
+
* @memberof DrawLib
|
|
555
|
+
**/
|
|
556
|
+
arrowHead(zA, zB, color, lineWidth, headLength = 8, strokeOptions) {
|
|
557
|
+
const node = this.makeArrowHeadNode(zA, zB, color, lineWidth, headLength, strokeOptions);
|
|
558
|
+
return this._bindFillDraw(node, "arrowhead", color, lineWidth || 1, strokeOptions);
|
|
421
559
|
}
|
|
422
560
|
/**
|
|
423
561
|
* Draw an image at the given position with the given size.<br>
|
|
@@ -426,8 +564,8 @@ export class drawutilssvg {
|
|
|
426
564
|
*
|
|
427
565
|
* @method image
|
|
428
566
|
* @param {Image} image - The image object to draw.
|
|
429
|
-
* @param {
|
|
430
|
-
* @param {
|
|
567
|
+
* @param {XYCoords} position - The position to draw the the upper left corner at.
|
|
568
|
+
* @param {XYCoords} size - The x/y-size to draw the image with.
|
|
431
569
|
* @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
|
|
432
570
|
* @return {void}
|
|
433
571
|
* @instance
|
|
@@ -470,16 +608,16 @@ export class drawutilssvg {
|
|
|
470
608
|
* @param {Image} textureImage - The image object to draw.
|
|
471
609
|
* @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
|
|
472
610
|
* @param {Polygon} polygon - The polygon to use as clip path.
|
|
473
|
-
* @param {
|
|
611
|
+
* @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
|
|
474
612
|
* @param {number} rotation - The rotation to use for the polygon (and for the texture).
|
|
475
613
|
* @return {void}
|
|
476
614
|
* @instance
|
|
477
615
|
* @memberof drawutilssvg
|
|
478
616
|
**/
|
|
479
617
|
texturedPoly(textureImage, textureSize, polygon, polygonPosition, rotation) {
|
|
480
|
-
const basePolygonBounds = polygon.getBounds();
|
|
618
|
+
// const basePolygonBounds: Bounds = polygon.getBounds();
|
|
481
619
|
const rotatedScalingOrigin = new Vertex(textureSize.min).clone().rotate(rotation, polygonPosition);
|
|
482
|
-
const rotationCenter = polygonPosition.clone().add(rotatedScalingOrigin.difference(textureSize.min).inv());
|
|
620
|
+
// const rotationCenter = polygonPosition.clone().add(rotatedScalingOrigin.difference(textureSize.min).inv());
|
|
483
621
|
// Create something like this
|
|
484
622
|
// ...
|
|
485
623
|
// <defs>
|
|
@@ -534,36 +672,21 @@ export class drawutilssvg {
|
|
|
534
672
|
* Draw the given (cubic) bézier curve.
|
|
535
673
|
*
|
|
536
674
|
* @method cubicBezier
|
|
537
|
-
* @param {
|
|
538
|
-
* @param {
|
|
539
|
-
* @param {
|
|
540
|
-
* @param {
|
|
675
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
676
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
677
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
678
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
541
679
|
* @param {string} color - The CSS color to draw the curve with.
|
|
542
680
|
* @param {number} lineWidth - (optional) The line width to use.
|
|
681
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
682
|
+
*
|
|
543
683
|
* @return {void}
|
|
544
684
|
* @instance
|
|
545
685
|
* @memberof drawutilssvg
|
|
546
686
|
*/
|
|
547
|
-
cubicBezier(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth) {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
}
|
|
551
|
-
const node = this.makeNode("path");
|
|
552
|
-
// Draw curve
|
|
553
|
-
const d = [
|
|
554
|
-
"M",
|
|
555
|
-
this._x(startPoint.x),
|
|
556
|
-
this._y(startPoint.y),
|
|
557
|
-
"C",
|
|
558
|
-
this._x(startControlPoint.x),
|
|
559
|
-
this._y(startControlPoint.y),
|
|
560
|
-
this._x(endControlPoint.x),
|
|
561
|
-
this._y(endControlPoint.y),
|
|
562
|
-
this._x(endPoint.x),
|
|
563
|
-
this._y(endPoint.y)
|
|
564
|
-
];
|
|
565
|
-
node.setAttribute("d", d.join(" "));
|
|
566
|
-
return this._bindFillDraw(node, "cubicBezier", color, lineWidth);
|
|
687
|
+
cubicBezier(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
|
|
688
|
+
const node = this.makeCubicBezierNode(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions);
|
|
689
|
+
return this._bindNode(node, undefined);
|
|
567
690
|
}
|
|
568
691
|
/**
|
|
569
692
|
* Draw the given (cubic) Bézier path.
|
|
@@ -573,17 +696,21 @@ export class drawutilssvg {
|
|
|
573
696
|
* <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
|
|
574
697
|
*
|
|
575
698
|
* @method cubicBezierPath
|
|
576
|
-
* @param {
|
|
699
|
+
* @param {XYCoords[]} path - The cubic bezier path as described above.
|
|
577
700
|
* @param {string} color - The CSS colot to draw the path with.
|
|
578
701
|
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
702
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
703
|
+
*
|
|
579
704
|
* @return {void}
|
|
580
705
|
* @instance
|
|
581
706
|
* @memberof drawutilssvg
|
|
582
707
|
*/
|
|
583
|
-
cubicBezierPath(path, color, lineWidth) {
|
|
708
|
+
cubicBezierPath(path, color, lineWidth, strokeOptions) {
|
|
584
709
|
const node = this.makeNode("path");
|
|
585
|
-
|
|
710
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
711
|
+
if (!path || path.length == 0) {
|
|
586
712
|
return node;
|
|
713
|
+
}
|
|
587
714
|
// Draw curve
|
|
588
715
|
const d = ["M", this._x(path[0].x), this._y(path[0].y)];
|
|
589
716
|
// Draw curve path
|
|
@@ -620,20 +747,20 @@ export class drawutilssvg {
|
|
|
620
747
|
* Draw a handle line (with a light grey).
|
|
621
748
|
*
|
|
622
749
|
* @method handleLine
|
|
623
|
-
* @param {
|
|
624
|
-
* @param {
|
|
750
|
+
* @param {XYCoords} startPoint - The start point to draw the handle at.
|
|
751
|
+
* @param {XYCoords} endPoint - The end point to draw the handle at.
|
|
625
752
|
* @return {void}
|
|
626
753
|
* @instance
|
|
627
754
|
* @memberof drawutilssvg
|
|
628
755
|
*/
|
|
629
756
|
handleLine(startPoint, endPoint) {
|
|
630
|
-
this.line(startPoint, endPoint, "rgb(
|
|
757
|
+
this.line(startPoint, endPoint, "rgb(128,128,128,0.5)");
|
|
631
758
|
}
|
|
632
759
|
/**
|
|
633
760
|
* Draw a 1x1 dot with the specified (CSS-) color.
|
|
634
761
|
*
|
|
635
762
|
* @method dot
|
|
636
|
-
* @param {
|
|
763
|
+
* @param {XYCoords} p - The position to draw the dot at.
|
|
637
764
|
* @param {string} color - The CSS color to draw the dot with.
|
|
638
765
|
* @return {void}
|
|
639
766
|
* @instance
|
|
@@ -641,13 +768,17 @@ export class drawutilssvg {
|
|
|
641
768
|
*/
|
|
642
769
|
dot(p, color) {
|
|
643
770
|
const node = this.makeNode("line");
|
|
771
|
+
node.setAttribute("x1", `${this._x(p.x)}`);
|
|
772
|
+
node.setAttribute("y1", `${this._y(p.y)}`);
|
|
773
|
+
node.setAttribute("x2", `${this._x(p.x)}`);
|
|
774
|
+
node.setAttribute("y2", `${this._y(p.y)}`);
|
|
644
775
|
return this._bindFillDraw(node, "dot", color, 1);
|
|
645
776
|
}
|
|
646
777
|
/**
|
|
647
778
|
* Draw the given point with the specified (CSS-) color and radius 3.
|
|
648
779
|
*
|
|
649
780
|
* @method point
|
|
650
|
-
* @param {
|
|
781
|
+
* @param {XYCoords} p - The position to draw the point at.
|
|
651
782
|
* @param {string} color - The CSS color to draw the point with.
|
|
652
783
|
* @return {void}
|
|
653
784
|
* @instance
|
|
@@ -667,17 +798,20 @@ export class drawutilssvg {
|
|
|
667
798
|
* Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
|
|
668
799
|
*
|
|
669
800
|
* @method circle
|
|
670
|
-
* @param {
|
|
801
|
+
* @param {XYCoords} center - The center of the circle.
|
|
671
802
|
* @param {number} radius - The radius of the circle.
|
|
672
803
|
* @param {string} color - The CSS color to draw the circle with.
|
|
673
804
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
805
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
806
|
+
*
|
|
674
807
|
* @return {void}
|
|
675
808
|
* @instance
|
|
676
809
|
* @memberof drawutilssvg
|
|
677
810
|
*/
|
|
678
|
-
circle(center, radius, color, lineWidth) {
|
|
811
|
+
circle(center, radius, color, lineWidth, strokeOptions) {
|
|
679
812
|
// Todo: draw ellipse when scalex!=scaley
|
|
680
813
|
const node = this.makeNode("circle");
|
|
814
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
681
815
|
node.setAttribute("cx", `${this._x(center.x)}`);
|
|
682
816
|
node.setAttribute("cy", `${this._y(center.y)}`);
|
|
683
817
|
node.setAttribute("r", `${radius * this.scale.x}`); // y?
|
|
@@ -687,17 +821,20 @@ export class drawutilssvg {
|
|
|
687
821
|
* Draw a circular arc (section of a circle) with the given CSS color.
|
|
688
822
|
*
|
|
689
823
|
* @method circleArc
|
|
690
|
-
* @param {
|
|
824
|
+
* @param {XYCoords} center - The center of the circle.
|
|
691
825
|
* @param {number} radius - The radius of the circle.
|
|
692
826
|
* @param {number} startAngle - The angle to start at.
|
|
693
827
|
* @param {number} endAngle - The angle to end at.
|
|
694
828
|
* @param {string} color - The CSS color to draw the circle with.
|
|
829
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
830
|
+
*
|
|
695
831
|
* @return {void}
|
|
696
832
|
* @instance
|
|
697
833
|
* @memberof drawutilssvg
|
|
698
834
|
*/
|
|
699
|
-
circleArc(center, radius, startAngle, endAngle, color, lineWidth) {
|
|
835
|
+
circleArc(center, radius, startAngle, endAngle, color, lineWidth, strokeOptions) {
|
|
700
836
|
const node = this.makeNode("path");
|
|
837
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
701
838
|
const arcData = CircleSector.circleSectorUtils.describeSVGArc(this._x(center.x), this._y(center.y), radius * this.scale.x, // y?
|
|
702
839
|
startAngle, endAngle);
|
|
703
840
|
node.setAttribute("d", arcData.join(" "));
|
|
@@ -707,21 +844,24 @@ export class drawutilssvg {
|
|
|
707
844
|
* Draw an ellipse with the specified (CSS-) color and thw two radii.
|
|
708
845
|
*
|
|
709
846
|
* @method ellipse
|
|
710
|
-
* @param {
|
|
847
|
+
* @param {XYCoords} center - The center of the ellipse.
|
|
711
848
|
* @param {number} radiusX - The radius of the ellipse.
|
|
712
849
|
* @param {number} radiusY - The radius of the ellipse.
|
|
713
850
|
* @param {string} color - The CSS color to draw the ellipse with.
|
|
714
851
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
715
852
|
* @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
|
|
853
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
854
|
+
*
|
|
716
855
|
* @return {void}
|
|
717
856
|
* @instance
|
|
718
857
|
* @memberof drawutilssvg
|
|
719
858
|
*/
|
|
720
|
-
ellipse(center, radiusX, radiusY, color, lineWidth, rotation) {
|
|
859
|
+
ellipse(center, radiusX, radiusY, color, lineWidth, rotation, strokeOptions) {
|
|
721
860
|
if (typeof rotation === "undefined") {
|
|
722
861
|
rotation = 0.0;
|
|
723
862
|
}
|
|
724
863
|
const node = this.makeNode("ellipse");
|
|
864
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
725
865
|
node.setAttribute("cx", `${this._x(center.x)}`);
|
|
726
866
|
node.setAttribute("cy", `${this._y(center.y)}`);
|
|
727
867
|
node.setAttribute("rx", `${radiusX * this.scale.x}`);
|
|
@@ -737,15 +877,18 @@ export class drawutilssvg {
|
|
|
737
877
|
*
|
|
738
878
|
* @method square
|
|
739
879
|
* @param {XYCoords} center - The center of the square.
|
|
740
|
-
* @param {
|
|
880
|
+
* @param {number} size - The size of the square.
|
|
741
881
|
* @param {string} color - The CSS color to draw the square with.
|
|
742
882
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
743
|
-
* @
|
|
883
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
884
|
+
*
|
|
885
|
+
* @return {SVGElement}
|
|
744
886
|
* @instance
|
|
745
887
|
* @memberof drawutilssvg
|
|
746
888
|
*/
|
|
747
|
-
square(center, size, color, lineWidth) {
|
|
889
|
+
square(center, size, color, lineWidth, strokeOptions) {
|
|
748
890
|
const node = this.makeNode("rectangle");
|
|
891
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
749
892
|
node.setAttribute("x", `${this._x(center.x - size / 2.0)}`);
|
|
750
893
|
node.setAttribute("y", `${this._y(center.y - size / 2.0)}`);
|
|
751
894
|
node.setAttribute("width", `${size * this.scale.x}`);
|
|
@@ -760,9 +903,15 @@ export class drawutilssvg {
|
|
|
760
903
|
* @param {number} height - The height of the rectangle.
|
|
761
904
|
* @param {string} color - The color to use.
|
|
762
905
|
* @param {number=1} lineWidth - (optional) The line with to use (default is 1).
|
|
906
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
907
|
+
*
|
|
908
|
+
* @return {SVGElement}
|
|
909
|
+
* @instance
|
|
910
|
+
* @memberof drawutilssvg
|
|
763
911
|
**/
|
|
764
|
-
rect(position, width, height, color, lineWidth) {
|
|
912
|
+
rect(position, width, height, color, lineWidth, strokeOptions) {
|
|
765
913
|
const node = this.makeNode("rect");
|
|
914
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
766
915
|
node.setAttribute("x", `${this._x(position.x)}`);
|
|
767
916
|
node.setAttribute("y", `${this._y(position.y)}`);
|
|
768
917
|
node.setAttribute("width", `${width * this.scale.x}`);
|
|
@@ -773,7 +922,7 @@ export class drawutilssvg {
|
|
|
773
922
|
* Draw a grid of horizontal and vertical lines with the given (CSS-) color.
|
|
774
923
|
*
|
|
775
924
|
* @method grid
|
|
776
|
-
* @param {
|
|
925
|
+
* @param {XYCoords} center - The center of the grid.
|
|
777
926
|
* @param {number} width - The total width of the grid (width/2 each to the left and to the right).
|
|
778
927
|
* @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
|
|
779
928
|
* @param {number} sizeX - The horizontal grid size.
|
|
@@ -807,7 +956,7 @@ export class drawutilssvg {
|
|
|
807
956
|
* This works analogue to the grid() function
|
|
808
957
|
*
|
|
809
958
|
* @method raster
|
|
810
|
-
* @param {
|
|
959
|
+
* @param {XYCoords} center - The center of the raster.
|
|
811
960
|
* @param {number} width - The total width of the raster (width/2 each to the left and to the right).
|
|
812
961
|
* @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
|
|
813
962
|
* @param {number} sizeX - The horizontal raster size.
|
|
@@ -840,8 +989,8 @@ export class drawutilssvg {
|
|
|
840
989
|
* as even shaped diamonds.
|
|
841
990
|
*
|
|
842
991
|
* @method diamondHandle
|
|
843
|
-
* @param {
|
|
844
|
-
* @param {
|
|
992
|
+
* @param {XYCoords} center - The center of the diamond.
|
|
993
|
+
* @param {number} size - The x/y-size of the diamond.
|
|
845
994
|
* @param {string} color - The CSS color to draw the diamond with.
|
|
846
995
|
* @return {void}
|
|
847
996
|
* @instance
|
|
@@ -875,8 +1024,8 @@ export class drawutilssvg {
|
|
|
875
1024
|
* as even shaped squares.
|
|
876
1025
|
*
|
|
877
1026
|
* @method squareHandle
|
|
878
|
-
* @param {
|
|
879
|
-
* @param {
|
|
1027
|
+
* @param {XYCoords} center - The center of the square.
|
|
1028
|
+
* @param {XYCoords} size - The x/y-size of the square.
|
|
880
1029
|
* @param {string} color - The CSS color to draw the square with.
|
|
881
1030
|
* @return {void}
|
|
882
1031
|
* @instance
|
|
@@ -898,7 +1047,7 @@ export class drawutilssvg {
|
|
|
898
1047
|
* as even shaped circles.
|
|
899
1048
|
*
|
|
900
1049
|
* @method circleHandle
|
|
901
|
-
* @param {
|
|
1050
|
+
* @param {XYCoords} center - The center of the circle.
|
|
902
1051
|
* @param {number} radius - The radius of the circle.
|
|
903
1052
|
* @param {string} color - The CSS color to draw the circle with.
|
|
904
1053
|
* @return {void}
|
|
@@ -997,18 +1146,22 @@ export class drawutilssvg {
|
|
|
997
1146
|
* Draw a polygon line (alternative function to the polygon).
|
|
998
1147
|
*
|
|
999
1148
|
* @method polyline
|
|
1000
|
-
* @param {
|
|
1149
|
+
* @param {XYCoords[]} vertices - The polygon vertices to draw.
|
|
1001
1150
|
* @param {boolan} isOpen - If true the polyline will not be closed at its end.
|
|
1002
1151
|
* @param {string} color - The CSS color to draw the polygon with.
|
|
1003
1152
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
1153
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
1154
|
+
*
|
|
1004
1155
|
* @return {void}
|
|
1005
1156
|
* @instance
|
|
1006
1157
|
* @memberof drawutilssvg
|
|
1007
1158
|
*/
|
|
1008
|
-
polyline(vertices, isOpen, color, lineWidth) {
|
|
1159
|
+
polyline(vertices, isOpen, color, lineWidth, strokeOptions) {
|
|
1009
1160
|
const node = this.makeNode("path");
|
|
1010
|
-
|
|
1161
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
1162
|
+
if (vertices.length == 0) {
|
|
1011
1163
|
return node;
|
|
1164
|
+
}
|
|
1012
1165
|
// Draw curve
|
|
1013
1166
|
const d = ["M", this._x(vertices[0].x), this._y(vertices[0].y)];
|
|
1014
1167
|
var n = vertices.length;
|
|
@@ -1111,12 +1264,16 @@ export class drawutilssvg {
|
|
|
1111
1264
|
* @param {string=null} color - (optional) The color to draw this path with (default is null).
|
|
1112
1265
|
* @param {number=1} lineWidth - (optional) the line width to use (default is 1).
|
|
1113
1266
|
* @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.
|
|
1267
|
+
* @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
|
|
1268
|
+
* @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
|
|
1269
|
+
*
|
|
1114
1270
|
* @instance
|
|
1115
1271
|
* @memberof drawutils
|
|
1116
1272
|
* @return {R} An instance representing the drawn path.
|
|
1117
1273
|
*/
|
|
1118
1274
|
path(pathData, color, lineWidth, options) {
|
|
1119
1275
|
const node = this.makeNode("path");
|
|
1276
|
+
this.applyStrokeOpts(node, options);
|
|
1120
1277
|
// Transform the path: in-place (fast) or copy (slower)
|
|
1121
1278
|
const d = options && options.inplace ? pathData : drawutilssvg.copyPathData(pathData);
|
|
1122
1279
|
drawutilssvg.transformPathData(d, this.offset, this.scale);
|
|
@@ -1142,7 +1299,7 @@ export class drawutilssvg {
|
|
|
1142
1299
|
}
|
|
1143
1300
|
// Add a covering rect with the given background color
|
|
1144
1301
|
this.curId = "background";
|
|
1145
|
-
this.curClassName = undefined;
|
|
1302
|
+
this.curClassName = null; // undefined;
|
|
1146
1303
|
const node = this.makeNode("rect");
|
|
1147
1304
|
// For some strange reason SVG rotation transforms use degrees instead of radians
|
|
1148
1305
|
// Note that the background does not scale with the zoom level (always covers full element)
|
|
@@ -1154,7 +1311,7 @@ export class drawutilssvg {
|
|
|
1154
1311
|
this._bindFillDraw(node, this.curId, null, null);
|
|
1155
1312
|
node.setAttribute("fill", typeof color === "undefined" ? "none" : color);
|
|
1156
1313
|
// Clear the current ID again
|
|
1157
|
-
this.curId = undefined;
|
|
1314
|
+
this.curId = null; // undefined;
|
|
1158
1315
|
}
|
|
1159
1316
|
/**
|
|
1160
1317
|
* A private helper function to clear all SVG nodes from the >g> node.
|
|
@@ -1359,6 +1516,126 @@ export class drawutilssvg {
|
|
|
1359
1516
|
}
|
|
1360
1517
|
} // END while
|
|
1361
1518
|
} // END transformPathData
|
|
1519
|
+
static nodeSupportsLineDash(nodeName) {
|
|
1520
|
+
return ["line", "path", "circle", "ellipse", "rectangle", "rect"].includes(nodeName);
|
|
1521
|
+
}
|
|
1522
|
+
/**
|
|
1523
|
+
* Creates a basic <line> node with start and end coordinates. The created node will not
|
|
1524
|
+
* be bound to any root node.
|
|
1525
|
+
*
|
|
1526
|
+
* @private
|
|
1527
|
+
* @method makeLineNode
|
|
1528
|
+
* @param {XYCoords} zA - The line's start position.
|
|
1529
|
+
* @param {XYCoords} zB - The line's start position.
|
|
1530
|
+
* @param {string} color - The CSS color to draw the point with.
|
|
1531
|
+
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
1532
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
|
|
1533
|
+
* @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
|
|
1534
|
+
* @return {SVGLineElement}
|
|
1535
|
+
* @instance
|
|
1536
|
+
* @memberof drawutilssvg
|
|
1537
|
+
*/
|
|
1538
|
+
makeLineNode(zA, zB, color, lineWidth, strokeOptions, classNameOverride) {
|
|
1539
|
+
const line = this.makeNode("line");
|
|
1540
|
+
line.setAttribute("x1", `${this._x(zA.x)}`);
|
|
1541
|
+
line.setAttribute("y1", `${this._y(zA.y)}`);
|
|
1542
|
+
line.setAttribute("x2", `${this._x(zB.x)}`);
|
|
1543
|
+
line.setAttribute("y2", `${this._y(zB.y)}`);
|
|
1544
|
+
this._configureNode(line, classNameOverride !== null && classNameOverride !== void 0 ? classNameOverride : "line", this.fillShapes, color, lineWidth || 1, strokeOptions);
|
|
1545
|
+
return line;
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Creates a basic <path> node with given path string data. The created node will not
|
|
1549
|
+
* be bound to any root node.
|
|
1550
|
+
*
|
|
1551
|
+
* @private
|
|
1552
|
+
* @method makePathNode
|
|
1553
|
+
* @param {string} pathString - The path data (must be a valid path data string).
|
|
1554
|
+
* @param {string} color - The CSS color to draw the point with.
|
|
1555
|
+
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
1556
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
|
|
1557
|
+
* @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
|
|
1558
|
+
* @return {SVGPathElement}
|
|
1559
|
+
* @instance
|
|
1560
|
+
* @memberof drawutilssvg
|
|
1561
|
+
*/
|
|
1562
|
+
makePathNode(pathString, color, lineWidth, strokeOptions, classNameOverride) {
|
|
1563
|
+
const path = this.makeNode("path");
|
|
1564
|
+
path.setAttribute("d", pathString);
|
|
1565
|
+
this._configureNode(path, classNameOverride !== null && classNameOverride !== void 0 ? classNameOverride : "path", this.fillShapes, color, lineWidth || 1, strokeOptions);
|
|
1566
|
+
return path;
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* Creates a basic arrow head node (<path> node) at the end of the given line coordinates. The created node will not
|
|
1570
|
+
* be bound to any root node.
|
|
1571
|
+
*
|
|
1572
|
+
* @private
|
|
1573
|
+
* @method makeArrowHeadNode
|
|
1574
|
+
* @param {string} pathString - The path data (must be a valid path data string).
|
|
1575
|
+
* @param {string} color - The CSS color to draw the point with.
|
|
1576
|
+
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
1577
|
+
* @param {number=8} headLength - (optional) The length of the arrow head; if none is specified then the head will be 8 absolute units long.
|
|
1578
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
|
|
1579
|
+
* @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.
|
|
1580
|
+
* @return {SVGPathElement}
|
|
1581
|
+
* @instance
|
|
1582
|
+
* @memberof drawutilssvg
|
|
1583
|
+
*/
|
|
1584
|
+
makeArrowHeadNode(zA, zB, color, lineWidth, headLength = 8, strokeOptions, arrowHeadBasePositionBuffer) {
|
|
1585
|
+
var vertices = Vector.utils.buildArrowHead(zA, zB, headLength, this.scale.x, this.scale.y);
|
|
1586
|
+
const d = ["M", this.offset.x + vertices[0].x, this.offset.y + vertices[0].y];
|
|
1587
|
+
if (arrowHeadBasePositionBuffer) {
|
|
1588
|
+
arrowHeadBasePositionBuffer.x = vertices[0].x / this.scale.x;
|
|
1589
|
+
arrowHeadBasePositionBuffer.y = vertices[0].y / this.scale.y;
|
|
1590
|
+
}
|
|
1591
|
+
for (var i = 1; i <= vertices.length; i++) {
|
|
1592
|
+
d.push("L");
|
|
1593
|
+
// Note: only use offset here (the vertices are already scaled)
|
|
1594
|
+
d.push(this.offset.x + vertices[i % vertices.length].x);
|
|
1595
|
+
d.push(this.offset.y + vertices[i % vertices.length].y);
|
|
1596
|
+
}
|
|
1597
|
+
const node = this.makePathNode(d.join(" "), color, lineWidth, strokeOptions, "arrowhead");
|
|
1598
|
+
return node;
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Creates a basic cubic Bézier path node (<path> node) with the given cubic Bézier data. The created node will not
|
|
1602
|
+
* be bound to any root node.
|
|
1603
|
+
*
|
|
1604
|
+
* @private
|
|
1605
|
+
* @method makeCubicBezierNode
|
|
1606
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
1607
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
1608
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
1609
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
1610
|
+
* @param {string} color - The CSS color to draw the point with.
|
|
1611
|
+
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
1612
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
|
|
1613
|
+
* @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
|
|
1614
|
+
* @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.
|
|
1615
|
+
* @return {SVGPathElement}
|
|
1616
|
+
* @instance
|
|
1617
|
+
* @memberof drawutilssvg
|
|
1618
|
+
*/
|
|
1619
|
+
makeCubicBezierNode(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
|
|
1620
|
+
if (startPoint instanceof CubicBezierCurve) {
|
|
1621
|
+
return this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
|
|
1622
|
+
}
|
|
1623
|
+
// Draw curve
|
|
1624
|
+
const d = [
|
|
1625
|
+
"M",
|
|
1626
|
+
this._x(startPoint.x),
|
|
1627
|
+
this._y(startPoint.y),
|
|
1628
|
+
"C",
|
|
1629
|
+
this._x(startControlPoint.x),
|
|
1630
|
+
this._y(startControlPoint.y),
|
|
1631
|
+
this._x(endControlPoint.x),
|
|
1632
|
+
this._y(endControlPoint.y),
|
|
1633
|
+
this._x(endPoint.x),
|
|
1634
|
+
this._y(endPoint.y)
|
|
1635
|
+
];
|
|
1636
|
+
const node = this.makePathNode(d.join(" "), color, lineWidth, strokeOptions, "cubicBezier");
|
|
1637
|
+
return node;
|
|
1638
|
+
}
|
|
1362
1639
|
}
|
|
1363
1640
|
drawutilssvg.HEAD_XML = [
|
|
1364
1641
|
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>',
|