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.
- package/README.md +17 -0
- package/dist/index.esm.js +101 -50
- 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 +102 -50
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +2 -1
- package/src/cjs/BezierPath.js +2 -3
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +7 -1
- package/src/cjs/PlotBoilerplate.js +76 -33
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Triangle.js +1 -0
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/draw.d.ts +6 -5
- package/src/cjs/draw.js +4 -3
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +7 -6
- package/src/cjs/drawgl.js +5 -4
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +8 -6
- package/src/cjs/drawutilssvg.js +14 -7
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +4 -3
- package/src/cjs/interfaces/DrawLib.js +1 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +33 -30
- package/src/cjs/interfaces/core.js +1 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- 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/module.js +4 -2
- package/src/cjs/utils/parsers/svg/parseSVGPathData.d.ts +2 -1
- package/src/cjs/utils/parsers/svg/parseSVGPathData.js +228 -205
- package/src/cjs/utils/parsers/svg/parseSVGPathData.js.map +1 -1
- package/src/cjs/utils/parsers/svg/splitSVGPathData.js +6 -2
- package/src/cjs/utils/parsers/svg/splitSVGPathData.js.map +1 -1
- package/src/cjs/utils/parsers/svg/types.d.ts +29 -9
- package/src/cjs/utils/parsers/svg/types.js +4 -3
- package/src/cjs/utils/parsers/svg/types.js.map +1 -1
- package/src/esm/BezierPath.js +2 -3
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +7 -1
- package/src/esm/PlotBoilerplate.js +75 -33
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Triangle.js +1 -0
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/draw.d.ts +6 -5
- package/src/esm/draw.js +4 -3
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +7 -6
- package/src/esm/drawgl.js +5 -4
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +8 -6
- package/src/esm/drawutilssvg.js +14 -7
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +4 -3
- package/src/esm/interfaces/DrawLib.js +1 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +33 -30
- package/src/esm/interfaces/core.js +1 -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/parsers/svg/parseSVGPathData.d.ts +2 -1
- package/src/esm/utils/parsers/svg/parseSVGPathData.js +228 -205
- package/src/esm/utils/parsers/svg/parseSVGPathData.js.map +1 -1
- package/src/esm/utils/parsers/svg/splitSVGPathData.js +6 -2
- package/src/esm/utils/parsers/svg/splitSVGPathData.js.map +1 -1
- package/src/esm/utils/parsers/svg/types.d.ts +29 -9
- package/src/esm/utils/parsers/svg/types.js +4 -3
- package/src/esm/utils/parsers/svg/types.js.map +1 -1
- package/src/ts/BezierPath.ts +2 -3
- package/src/ts/PlotBoilerplate.ts +75 -32
- package/src/ts/Triangle.ts +2 -1
- package/src/ts/draw.ts +6 -5
- package/src/ts/drawgl.ts +9 -8
- package/src/ts/drawutilssvg.ts +23 -16
- package/src/ts/interfaces/DrawLib.ts +4 -3
- package/src/ts/interfaces/core.ts +33 -30
- package/src/ts/utils/datastructures/Color.ts +13 -1
- package/src/ts/utils/parsers/svg/parseSVGPathData.ts +271 -212
- package/src/ts/utils/parsers/svg/splitSVGPathData.ts +6 -2
- package/src/ts/utils/parsers/svg/types.ts +29 -9
package/src/ts/drawutilssvg.ts
CHANGED
|
@@ -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
|
-
* @
|
|
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|
|
|
168
|
+
* @member {UID|null}
|
|
167
169
|
* @memberof drawutilssvg
|
|
168
170
|
* @instance
|
|
169
171
|
*/
|
|
170
|
-
private curId: UID |
|
|
172
|
+
private curId: UID | null;
|
|
171
173
|
|
|
172
174
|
/**
|
|
173
175
|
* The current drawable-classname.
|
|
174
176
|
*/
|
|
175
|
-
private curClassName: string |
|
|
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 |
|
|
317
|
-
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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, "
|
|
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 |
|
|
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 |
|
|
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
|
|
106
|
-
fitToParent
|
|
107
|
-
scaleX
|
|
108
|
-
scaleY
|
|
109
|
-
offsetX
|
|
110
|
-
offsetY
|
|
111
|
-
rasterGrid
|
|
112
|
-
drawRaster
|
|
113
|
-
rasterScaleX
|
|
114
|
-
rasterScaleY
|
|
115
|
-
rasterAdjustFactor
|
|
116
|
-
drawOrigin
|
|
117
|
-
autoAdjustOffset
|
|
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
|
|
121
|
+
offsetAdjustXPercent: number; // The x-fallback position for the origin after
|
|
121
122
|
// resizing the canvas.
|
|
122
|
-
offsetAdjustYPercent
|
|
123
|
+
offsetAdjustYPercent: number; // The y-fallback position for the origin after
|
|
123
124
|
// resizing the canvas.
|
|
124
|
-
defaultCanvasWidth
|
|
125
|
+
defaultCanvasWidth: number; // The canvas size fallback (width) if no automatic resizing
|
|
125
126
|
// is switched on.
|
|
126
|
-
defaultCanvasHeight
|
|
127
|
+
defaultCanvasHeight: number; // The canvas size fallback (height) if no automatic resizing
|
|
127
128
|
// is switched on.
|
|
128
|
-
canvasWidthFactor
|
|
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
|
|
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
|
|
135
|
-
cssScaleY
|
|
136
|
-
cssUniformScale
|
|
137
|
-
backgroundColor
|
|
138
|
-
redrawOnResize
|
|
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
|
|
147
|
-
enableTouch
|
|
148
|
-
enableKeys
|
|
149
|
-
enableMouseWheel
|
|
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
|
|
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
|
|
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
|
-
* @
|
|
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;
|