plotboilerplate 1.20.0 → 1.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +17 -0
  2. package/dist/index.esm.js +101 -50
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.esm.min.js +1 -1
  5. package/dist/index.esm.min.js.map +1 -1
  6. package/dist/plotboilerplate.browser.min.js +1 -1
  7. package/dist/plotboilerplate.browser.min.js.map +1 -1
  8. package/dist/plotboilerplate.js +102 -50
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +2 -1
  11. package/src/cjs/BezierPath.js +2 -3
  12. package/src/cjs/BezierPath.js.map +1 -1
  13. package/src/cjs/PlotBoilerplate.d.ts +7 -1
  14. package/src/cjs/PlotBoilerplate.js +76 -33
  15. package/src/cjs/PlotBoilerplate.js.map +1 -1
  16. package/src/cjs/Triangle.js +1 -0
  17. package/src/cjs/Triangle.js.map +1 -1
  18. package/src/cjs/draw.d.ts +6 -5
  19. package/src/cjs/draw.js +4 -3
  20. package/src/cjs/draw.js.map +1 -1
  21. package/src/cjs/drawgl.d.ts +7 -6
  22. package/src/cjs/drawgl.js +5 -4
  23. package/src/cjs/drawgl.js.map +1 -1
  24. package/src/cjs/drawutilssvg.d.ts +8 -6
  25. package/src/cjs/drawutilssvg.js +14 -7
  26. package/src/cjs/drawutilssvg.js.map +1 -1
  27. package/src/cjs/interfaces/DrawLib.d.ts +4 -3
  28. package/src/cjs/interfaces/DrawLib.js +1 -0
  29. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  30. package/src/cjs/interfaces/core.d.ts +33 -30
  31. package/src/cjs/interfaces/core.js +1 -0
  32. package/src/cjs/interfaces/core.js.map +1 -1
  33. package/src/cjs/utils/datastructures/Color.d.ts +3 -1
  34. package/src/cjs/utils/datastructures/Color.js +12 -1
  35. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  36. package/src/cjs/utils/module.js +4 -2
  37. package/src/cjs/utils/parsers/svg/parseSVGPathData.d.ts +2 -1
  38. package/src/cjs/utils/parsers/svg/parseSVGPathData.js +228 -205
  39. package/src/cjs/utils/parsers/svg/parseSVGPathData.js.map +1 -1
  40. package/src/cjs/utils/parsers/svg/splitSVGPathData.js +6 -2
  41. package/src/cjs/utils/parsers/svg/splitSVGPathData.js.map +1 -1
  42. package/src/cjs/utils/parsers/svg/types.d.ts +29 -9
  43. package/src/cjs/utils/parsers/svg/types.js +4 -3
  44. package/src/cjs/utils/parsers/svg/types.js.map +1 -1
  45. package/src/esm/BezierPath.js +2 -3
  46. package/src/esm/BezierPath.js.map +1 -1
  47. package/src/esm/PlotBoilerplate.d.ts +7 -1
  48. package/src/esm/PlotBoilerplate.js +75 -33
  49. package/src/esm/PlotBoilerplate.js.map +1 -1
  50. package/src/esm/Triangle.js +1 -0
  51. package/src/esm/Triangle.js.map +1 -1
  52. package/src/esm/draw.d.ts +6 -5
  53. package/src/esm/draw.js +4 -3
  54. package/src/esm/draw.js.map +1 -1
  55. package/src/esm/drawgl.d.ts +7 -6
  56. package/src/esm/drawgl.js +5 -4
  57. package/src/esm/drawgl.js.map +1 -1
  58. package/src/esm/drawutilssvg.d.ts +8 -6
  59. package/src/esm/drawutilssvg.js +14 -7
  60. package/src/esm/drawutilssvg.js.map +1 -1
  61. package/src/esm/interfaces/DrawLib.d.ts +4 -3
  62. package/src/esm/interfaces/DrawLib.js +1 -0
  63. package/src/esm/interfaces/DrawLib.js.map +1 -1
  64. package/src/esm/interfaces/core.d.ts +33 -30
  65. package/src/esm/interfaces/core.js +1 -0
  66. package/src/esm/interfaces/core.js.map +1 -1
  67. package/src/esm/utils/datastructures/Color.d.ts +3 -1
  68. package/src/esm/utils/datastructures/Color.js +12 -1
  69. package/src/esm/utils/datastructures/Color.js.map +1 -1
  70. package/src/esm/utils/parsers/svg/parseSVGPathData.d.ts +2 -1
  71. package/src/esm/utils/parsers/svg/parseSVGPathData.js +228 -205
  72. package/src/esm/utils/parsers/svg/parseSVGPathData.js.map +1 -1
  73. package/src/esm/utils/parsers/svg/splitSVGPathData.js +6 -2
  74. package/src/esm/utils/parsers/svg/splitSVGPathData.js.map +1 -1
  75. package/src/esm/utils/parsers/svg/types.d.ts +29 -9
  76. package/src/esm/utils/parsers/svg/types.js +4 -3
  77. package/src/esm/utils/parsers/svg/types.js.map +1 -1
  78. package/src/ts/BezierPath.ts +2 -3
  79. package/src/ts/PlotBoilerplate.ts +75 -32
  80. package/src/ts/Triangle.ts +2 -1
  81. package/src/ts/draw.ts +6 -5
  82. package/src/ts/drawgl.ts +9 -8
  83. package/src/ts/drawutilssvg.ts +23 -16
  84. package/src/ts/interfaces/DrawLib.ts +4 -3
  85. package/src/ts/interfaces/core.ts +33 -30
  86. package/src/ts/utils/datastructures/Color.ts +13 -1
  87. package/src/ts/utils/parsers/svg/parseSVGPathData.ts +271 -212
  88. package/src/ts/utils/parsers/svg/splitSVGPathData.ts +6 -2
  89. package/src/ts/utils/parsers/svg/types.ts +29 -9
@@ -35,7 +35,9 @@
35
35
  * @modified 2022-03-26 Added the `texturedPoly` function to draw textures polygons.
36
36
  * @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
37
37
  * @modified 2022-11-10 Tweaking some type issues.
38
- * @version 1.6.2
38
+ * @modified 2023-02-04 Fixed a typo in the CSS classname for cubic Bézier paths: cubicBezier (was cubierBezier).
39
+ * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
40
+ * @version 1.6.4
39
41
  **/
40
42
 
41
43
  import { CircleSector } from "./CircleSector";
@@ -163,16 +165,16 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
163
165
  /**
164
166
  * The current drawable-ID. This can be any unique ID identifying the following drawn element.
165
167
  *
166
- * @member {UID|undefined}
168
+ * @member {UID|null}
167
169
  * @memberof drawutilssvg
168
170
  * @instance
169
171
  */
170
- private curId: UID | undefined;
172
+ private curId: UID | null;
171
173
 
172
174
  /**
173
175
  * The current drawable-classname.
174
176
  */
175
- private curClassName: string | undefined;
177
+ private curClassName: string | null;
176
178
 
177
179
  /**
178
180
  * The SVG element cache. On clear() all elements are kept for possible re-use on next draw cycle.
@@ -215,7 +217,7 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
215
217
  this.offset = new Vertex(0, 0).set(offset);
216
218
  this.scale = new Vertex(1, 1).set(scale);
217
219
  this.fillShapes = fillShapes;
218
- this.isSecondary = isSecondary;
220
+ this.isSecondary = Boolean(isSecondary);
219
221
 
220
222
  this.drawlibConfiguration = {} as DrawLibConfiguration;
221
223
  this.cache = new Map<UID, SVGElement>();
@@ -247,6 +249,8 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
247
249
  // Which default styles to add? -> All from the DrawConfig.
248
250
  // Compare with DrawConfig interface
249
251
  const keys = {
252
+ // "bezier": "CubicBezierCurve", // TODO: is this correct?
253
+ "bezierPath": "BezierPath",
250
254
  "polygon": "Polygon",
251
255
  "triangle": "Triangle",
252
256
  "ellipse": "Ellipse",
@@ -313,8 +317,11 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
313
317
  * @param {UID} key - The key of the desired element (used when re-drawing).
314
318
  * @param {string} nodeName - The expected node name.
315
319
  */
316
- private findElement(key: UID, nodeName: string): SVGElement | undefined {
317
- var node: SVGElement = this.cache.get(key);
320
+ private findElement(key: UID | null, nodeName: string): SVGElement | null {
321
+ if (!key) {
322
+ return null;
323
+ }
324
+ var node: SVGElement | undefined = this.cache.get(key);
318
325
  if (node && node.nodeName.toUpperCase() === nodeName.toUpperCase()) {
319
326
  this.cache.delete(key);
320
327
  return node;
@@ -353,7 +360,7 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
353
360
  // Unique node keys are strictly necessary.
354
361
 
355
362
  // Try to recycle an old element from cache.
356
- var node: SVGElement | undefined = this.findElement(this.curId, nodeName);
363
+ var node: SVGElement | null = this.findElement(this.curId, nodeName);
357
364
  if (!node) {
358
365
  // If no such old elements exists (key not found, tag name not matching),
359
366
  // then create a new one.
@@ -391,8 +398,8 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
391
398
  } else {
392
399
  node.setAttribute("class", className);
393
400
  }
394
- node.setAttribute("fill", this.fillShapes ? color : "none");
395
- node.setAttribute("stroke", this.fillShapes ? "none" : color);
401
+ node.setAttribute("fill", this.fillShapes && color ? color : "none");
402
+ node.setAttribute("stroke", this.fillShapes ? "none" : color || "none");
396
403
  node.setAttribute("stroke-width", `${lineWidth || 1}`);
397
404
  if (this.curId) {
398
405
  node.setAttribute("id", `${this.curId}`); // Maybe React-style 'key' would be better?
@@ -457,11 +464,11 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
457
464
  *
458
465
  * @name setCurrentId
459
466
  * @method
460
- * @param {UID} uid - A UID identifying the currently drawn element(s).
467
+ * @param {UID|null} uid - A UID identifying the currently drawn element(s).
461
468
  * @instance
462
469
  * @memberof drawutilssvg
463
470
  **/
464
- setCurrentId(uid: UID | undefined): void {
471
+ setCurrentId(uid: UID | null): void {
465
472
  this.curId = uid;
466
473
  }
467
474
 
@@ -471,11 +478,11 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
471
478
  *
472
479
  * @name setCurrentClassName
473
480
  * @method
474
- * @param {string} className - A class name for further custom use cases.
481
+ * @param {string|null} className - A class name for further custom use cases.
475
482
  * @instance
476
483
  * @memberof drawutilssvg
477
484
  **/
478
- setCurrentClassName(className: string | undefined): void {
485
+ setCurrentClassName(className: string | null): void {
479
486
  this.curClassName = className;
480
487
  }
481
488
 
@@ -498,7 +505,7 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
498
505
  // Hide all nodes here. Don't throw them away.
499
506
  // We can probably re-use them in the next draw cycle.
500
507
  var child: SVGElement = this.bufferGNode.childNodes[i] as SVGElement;
501
- this.cache.set(child.getAttribute("id"), child);
508
+ this.cache.set(child.getAttribute("id") as string, child);
502
509
  }
503
510
  this.removeAllChildNodes();
504
511
  }
@@ -763,7 +770,7 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
763
770
  this._y(endPoint.y)
764
771
  ];
765
772
  node.setAttribute("d", d.join(" "));
766
- return this._bindFillDraw(node, "cubierBezier", color, lineWidth);
773
+ return this._bindFillDraw(node, "cubicBezier", color, lineWidth);
767
774
  }
768
775
 
769
776
  /**
@@ -18,6 +18,7 @@
18
18
  * @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
19
19
  * @modified 2022-02-03 Added the `cross(...)` function.
20
20
  * @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
21
+ * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
21
22
  **/
22
23
 
23
24
  import { Bounds } from "../Bounds";
@@ -79,7 +80,7 @@ export interface DrawLib<R> {
79
80
  * @method
80
81
  * @param {UID|null} uid - A UID identifying the currently drawn element(s), or null to clear.
81
82
  **/
82
- setCurrentId: (uid: UID | undefined) => void;
83
+ setCurrentId: (uid: UID | null) => void;
83
84
 
84
85
  /**
85
86
  * This method shouled be called each time the currently drawn `Drawable` changes.
@@ -87,9 +88,9 @@ export interface DrawLib<R> {
87
88
  *
88
89
  * @name setCurrentClassName
89
90
  * @method
90
- * @param {string} className - A class name for further custom use cases.
91
+ * @param {string|null} className - A class name for further custom use cases.
91
92
  **/
92
- setCurrentClassName: (className: string | undefined) => void;
93
+ setCurrentClassName: (className: string | null) => void;
93
94
 
94
95
  /**
95
96
  * Called before each draw cycle.
@@ -17,6 +17,7 @@
17
17
  * @modified 2022-08-01 Added `title` param to the `PBParams` interface.
18
18
  * @modified 2022-10-25 Added `origin` param to the `DrawConfig` interface.
19
19
  * @modified 2022-11-23 Added `drawRaster` to the `Config` interface.
20
+ * @modified 2023-02-10 All non-function attributes of the `Config` interface are now mandatory.
20
21
  **/
21
22
 
22
23
  import { Vertex } from "../Vertex";
@@ -102,40 +103,40 @@ export interface CanvasWrapper {
102
103
  */
103
104
  export interface Config {
104
105
  canvas: HTMLCanvasElement | string; // Your canvas element in the DOM (required).
105
- fullSize?: boolean; // If set to true the canvas will gain full window size.
106
- fitToParent?: boolean; // If set to true the canvas will gain the size of its parent container (overrides fullSize).
107
- scaleX?: number; // The initial x-zoom. Default is 1.0.
108
- scaleY?: number; // The initial y-zoom. Default is 1.0.
109
- offsetX?: number; // The initial x-offset. Default is 0.0. Note that autoAdjustOffset=true overrides these values.
110
- offsetY?: number; // The initial y-offset. Default is 0.0. Note that autoAdjustOffset=true overrides these values.
111
- rasterGrid?: boolean; // If set to true the background grid will be drawn rastered.
112
- drawRaster?: boolean; // If set to false, no raster or grid will be drawn at all.
113
- rasterScaleX?: number; // Define the default horizontal raster scale (default=1.0).
114
- rasterScaleY?: number; // Define the default vertical raster scale (default=1.0).
115
- rasterAdjustFactor?: number; // The exponential limit for wrapping down the grid. (2.0 means: halve the grid each 2.0*n zoom step).
116
- drawOrigin?: boolean; // Draw a crosshair at (0,0).
117
- autoAdjustOffset?: boolean; // When set to true then the origin of the XY plane will
106
+ fullSize: boolean; // If set to true the canvas will gain full window size.
107
+ fitToParent: boolean; // If set to true the canvas will gain the size of its parent container (overrides fullSize).
108
+ scaleX: number; // The initial x-zoom. Default is 1.0.
109
+ scaleY: number; // The initial y-zoom. Default is 1.0.
110
+ offsetX: number; // The initial x-offset. Default is 0.0. Note that autoAdjustOffset=true overrides these values.
111
+ offsetY: number; // The initial y-offset. Default is 0.0. Note that autoAdjustOffset=true overrides these values.
112
+ rasterGrid: boolean; // If set to true the background grid will be drawn rastered.
113
+ drawRaster: boolean; // If set to false, no raster or grid will be drawn at all.
114
+ rasterScaleX: number; // Define the default horizontal raster scale (default=1.0).
115
+ rasterScaleY: number; // Define the default vertical raster scale (default=1.0).
116
+ rasterAdjustFactor: number; // The exponential limit for wrapping down the grid. (2.0 means: halve the grid each 2.0*n zoom step).
117
+ drawOrigin: boolean; // Draw a crosshair at (0,0).
118
+ autoAdjustOffset: boolean; // When set to true then the origin of the XY plane will
118
119
  // be re-adjusted automatically (see the params
119
120
  // offsetAdjust{X,Y}Percent for more).
120
- offsetAdjustXPercent?: number; // The x-fallback position for the origin after
121
+ offsetAdjustXPercent: number; // The x-fallback position for the origin after
121
122
  // resizing the canvas.
122
- offsetAdjustYPercent?: number; // The y-fallback position for the origin after
123
+ offsetAdjustYPercent: number; // The y-fallback position for the origin after
123
124
  // resizing the canvas.
124
- defaultCanvasWidth?: number; // The canvas size fallback (width) if no automatic resizing
125
+ defaultCanvasWidth: number; // The canvas size fallback (width) if no automatic resizing
125
126
  // is switched on.
126
- defaultCanvasHeight?: number; // The canvas size fallback (height) if no automatic resizing
127
+ defaultCanvasHeight: number; // The canvas size fallback (height) if no automatic resizing
127
128
  // is switched on.
128
- canvasWidthFactor?: number; // Scaling factor (width) upon the canvas size.
129
+ canvasWidthFactor: number; // Scaling factor (width) upon the canvas size.
129
130
  // In combination with cssScale{X,Y} this can be used to obtain
130
131
  // sub pixel resolutions for retina displays.
131
- canvasHeightFactor?: number; // Scaling factor (height) upon the canvas size.
132
+ canvasHeightFactor: number; // Scaling factor (height) upon the canvas size.
132
133
  // In combination with cssScale{X,Y} this can be used to obtain
133
134
  // sub pixel resolutions for retina displays.
134
- cssScaleX?: number; // Visually resize the canvas (horizontally) using CSS transforms (scale).
135
- cssScaleY?: number; // Visually resize the canvas (vertically) using CSS transforms (scale).
136
- cssUniformScale?: boolean; // CSS scale x and y obtaining aspect ratio.
137
- backgroundColor?: string; // The backround color.
138
- redrawOnResize?: boolean; // Switch auto-redrawing on resize on/off (some applications
135
+ cssScaleX: number; // Visually resize the canvas (horizontally) using CSS transforms (scale).
136
+ cssScaleY: number; // Visually resize the canvas (vertically) using CSS transforms (scale).
137
+ cssUniformScale: boolean; // CSS scale x and y obtaining aspect ratio.
138
+ backgroundColor: string; // The backround color.
139
+ redrawOnResize: boolean; // Switch auto-redrawing on resize on/off (some applications
139
140
  // might want to prevent automatic redrawing to avoid data loss from the draw buffer).
140
141
  preClear?: () => void; // A callback function that will be triggered just before the
141
142
  // draw function clears the canvas (before anything else was drawn).
@@ -143,17 +144,19 @@ export interface Config {
143
144
  // function starts.
144
145
  postDraw?: (draw: DrawLib<any>, fill: DrawLib<any>) => void; // A callback function that will be triggered right after the drawing
145
146
  // process finished.
146
- enableMouse?: boolean; // Indicates if the application should handle mouse events for you.
147
- enableTouch?: boolean; // Indicates if the application should handle touch events for you.
148
- enableKeys?: boolean; // Indicates if the application should handle key events for you.
149
- enableMouseWheel?: boolean; // Indicates if the application should handle mouse wheel events for you.
147
+ enableMouse: boolean; // Indicates if the application should handle mouse events for you.
148
+ enableTouch: boolean; // Indicates if the application should handle touch events for you.
149
+ enableKeys: boolean; // Indicates if the application should handle key events for you.
150
+ enableMouseWheel: boolean; // Indicates if the application should handle mouse wheel events for you.
151
+ enableZoom: boolean; // default=true
152
+ enablePan: boolean; // default=true
150
153
  enableGL?: boolean; // Indicates if the application should use the experimental WebGL features (not recommended).
151
- enableSVGExport?: boolean; // Indicates if the SVG export should be enabled (default is true).
154
+ enableSVGExport: boolean; // Indicates if the SVG export should be enabled (default is true).
152
155
  // Note that changes from the postDraw hook might not be visible in the export.
153
156
  saveFile?: () => void; // When called the save-file dialog will be triggered.
154
157
  setToRetina?: () => void; // When called the resolution will be set to retina.
155
158
 
156
- autoDetectRetina?: boolean; // When set to true (default) the canvas will try to use the display's pixel ratio.
159
+ autoDetectRetina: boolean; // When set to true (default) the canvas will try to use the display's pixel ratio.
157
160
  }
158
161
 
159
162
  /**
@@ -16,7 +16,8 @@
16
16
  * @modified 2021-11-07 Added setRed, setGreen, setBlue, setHue, setSaturation, setLiminance functions.
17
17
  * @modified 2022-05-11 Modified the `clone` function by just copying the numeric calues, not re-calculating the whole color.
18
18
  * @modified 2022-05-11 Fixed the `interpolate` function.
19
- * @version 0.0.11
19
+ * @modified 2023-01-23 Added `Color.set(Color)` function to set all values (r,g,b,h,s,l,a) simultanoeusly.
20
+ * @version 0.0.12
20
21
  **/
21
22
 
22
23
  /**
@@ -155,6 +156,17 @@ export class Color {
155
156
  return this.b;
156
157
  }
157
158
 
159
+ set(color: Color): Color {
160
+ this.r = color.r;
161
+ this.g = color.g;
162
+ this.b = color.b;
163
+ this.a = color.a;
164
+ this.h = color.h;
165
+ this.s = color.s;
166
+ this.l = color.l;
167
+ return this;
168
+ }
169
+
158
170
  setRed(r: number) {
159
171
  this.r = r;
160
172
  return this;