plotboilerplate 1.12.7 → 1.13.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 +4 -1
- package/changelog.md +25 -0
- package/dist/index.esm.js +259 -44
- 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 +273 -43
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/PBText.d.ts +116 -0
- package/src/cjs/PBText.js +66 -0
- package/src/cjs/PBText.js.map +1 -0
- package/src/cjs/PlotBoilerplate.d.ts +2 -1
- package/src/cjs/PlotBoilerplate.js +66 -19
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/draw.d.ts +30 -2
- package/src/cjs/draw.js +51 -6
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +29 -2
- package/src/cjs/drawgl.js +21 -4
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +25 -7
- package/src/cjs/drawutilssvg.js +62 -14
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/entry.js +1 -0
- package/src/cjs/index.d.ts +1 -0
- package/src/cjs/index.js +1 -0
- package/src/cjs/index.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +27 -6
- package/src/cjs/interfaces/DrawLib.js +3 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +12 -1
- 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 +28 -15
- package/src/cjs/utils/datastructures/Color.js +276 -88
- package/src/cjs/utils/datastructures/Color.js.map +1 -1
- package/src/esm/PBText.d.ts +116 -0
- package/src/esm/PBText.js +61 -0
- package/src/esm/PBText.js.map +1 -0
- package/src/esm/PlotBoilerplate.d.ts +2 -1
- package/src/esm/PlotBoilerplate.js +66 -19
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/draw.d.ts +30 -2
- package/src/esm/draw.js +51 -6
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +29 -2
- package/src/esm/drawgl.js +21 -4
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +25 -7
- package/src/esm/drawutilssvg.js +62 -14
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/entry.js +1 -0
- package/src/esm/index.d.ts +1 -0
- package/src/esm/index.js +1 -0
- package/src/esm/index.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +27 -6
- package/src/esm/interfaces/DrawLib.js +3 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +12 -1
- 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 +28 -15
- package/src/esm/utils/datastructures/Color.js +277 -89
- package/src/esm/utils/datastructures/Color.js.map +1 -1
- package/src/ts/PBText.ts +147 -0
- package/src/ts/PlotBoilerplate.ts +74 -23
- package/src/ts/draw.ts +71 -8
- package/src/ts/drawgl.ts +48 -8
- package/src/ts/drawutilssvg.ts +94 -17
- package/src/ts/index.ts +1 -0
- package/src/ts/interfaces/DrawLib.ts +30 -4
- package/src/ts/interfaces/core.ts +12 -0
- package/src/ts/utils/datastructures/Color.ts +695 -508
- package/src/ts/utils/algorithms/clearPolygonDuplicateVertices.ts~ +0 -5
- package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts~ +0 -45
- package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts~ +0 -113
- package/src/ts/utils/algorithms/sutherlandHodgman.ts~ +0 -88
- package/src/ts/utils/datastructures/Color.ts~ +0 -331
- package/src/ts/utils/datastructures/Girih.ts~ +0 -151
- package/src/ts/utils/datastructures/GirihTile.ts~ +0 -419
package/src/ts/drawutilssvg.ts
CHANGED
|
@@ -26,14 +26,30 @@
|
|
|
26
26
|
* @modified 2021-03-31 Added 'ellipseSector' the the class names.
|
|
27
27
|
* @modified 2021-03-31 Implemented buffering using a buffer <g> node and the beginDrawCycle and endDrawCycle methods.
|
|
28
28
|
* @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
|
|
29
|
-
* @
|
|
29
|
+
* @modified 2021-11-15 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
|
|
30
|
+
* @modified 2021-11-19 Fixing the `label(text,x,y)` position.
|
|
31
|
+
* @modified 2021-11-19 Added the `color` param to the `label(...)` function.
|
|
32
|
+
* @version 1.4.0
|
|
30
33
|
**/
|
|
31
34
|
|
|
32
35
|
import { CircleSector } from "./CircleSector";
|
|
33
36
|
import { CubicBezierCurve } from "./CubicBezierCurve";
|
|
34
37
|
import { Polygon } from "./Polygon";
|
|
35
38
|
import { Vertex } from "./Vertex";
|
|
36
|
-
import {
|
|
39
|
+
import {
|
|
40
|
+
DrawConfig,
|
|
41
|
+
DrawLib,
|
|
42
|
+
DrawSettings,
|
|
43
|
+
XYCoords,
|
|
44
|
+
XYDimension,
|
|
45
|
+
SVGPathParams,
|
|
46
|
+
UID,
|
|
47
|
+
DrawLibConfiguration,
|
|
48
|
+
FontStyle,
|
|
49
|
+
FontWeight
|
|
50
|
+
} from "./interfaces";
|
|
51
|
+
|
|
52
|
+
const RAD_TO_DEG = 180 / Math.PI;
|
|
37
53
|
|
|
38
54
|
/**
|
|
39
55
|
* @classdesc A helper class for basic SVG drawing operations. This class should
|
|
@@ -203,7 +219,8 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
203
219
|
"vertex": "Vertex",
|
|
204
220
|
"line": "Line",
|
|
205
221
|
"vector": "Vector",
|
|
206
|
-
"image": "Image"
|
|
222
|
+
"image": "Image",
|
|
223
|
+
"text": "Text"
|
|
207
224
|
};
|
|
208
225
|
// Question: why isn't this working if the svgNode is created dynamically? (nodeStyle.sheet is null)
|
|
209
226
|
const rules = [];
|
|
@@ -1065,29 +1082,82 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
1065
1082
|
}
|
|
1066
1083
|
if (!isOpen) d.push("Z");
|
|
1067
1084
|
node.setAttribute("d", d.join(" "));
|
|
1068
|
-
return this._bindFillDraw(node, "
|
|
1085
|
+
return this._bindFillDraw(node, "polygon", color, lineWidth || 1);
|
|
1069
1086
|
}
|
|
1070
1087
|
|
|
1071
1088
|
/**
|
|
1072
|
-
* Draw a text
|
|
1089
|
+
* Draw a text at the given relative position.
|
|
1073
1090
|
*
|
|
1074
|
-
* @method
|
|
1091
|
+
* @method text
|
|
1075
1092
|
* @param {string} text - The text to draw.
|
|
1076
1093
|
* @param {number} x - The x-position to draw the text at.
|
|
1077
1094
|
* @param {number} y - The y-position to draw the text at.
|
|
1078
|
-
* @param {
|
|
1095
|
+
* @param {string=} options.color - The Color to use.
|
|
1096
|
+
* @param {string=} options.fontFamily - The font family to use.
|
|
1097
|
+
* @param {number=} options.fontSize - The font size (in pixels) to use.
|
|
1098
|
+
* @param {FontStyle=} options.fontStyle - The font style to use.
|
|
1099
|
+
* @param {FontWeight=} options.fontWeight - The font weight to use.
|
|
1100
|
+
* @param {number=} options.lineHeight - The line height (in pixels) to use.
|
|
1101
|
+
* @param {number=} options.rotation - The (optional) rotation in radians.
|
|
1102
|
+
* @param {string=} options.textAlign - The text align to use. According to the specifiactions (https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign) valid values are `"left" || "right" || "center" || "start" || "end"`.
|
|
1079
1103
|
* @return {void}
|
|
1080
1104
|
* @instance
|
|
1081
|
-
* @memberof
|
|
1105
|
+
* @memberof drawutils
|
|
1082
1106
|
*/
|
|
1083
|
-
text(
|
|
1107
|
+
text(
|
|
1108
|
+
text: string,
|
|
1109
|
+
x: number,
|
|
1110
|
+
y: number,
|
|
1111
|
+
options?: {
|
|
1112
|
+
color?: string;
|
|
1113
|
+
fontFamily?: string;
|
|
1114
|
+
fontSize?: number;
|
|
1115
|
+
fontStyle?: FontStyle;
|
|
1116
|
+
fontWeight?: FontWeight;
|
|
1117
|
+
lineHeight?: number;
|
|
1118
|
+
textAlign?: CanvasRenderingContext2D["textAlign"];
|
|
1119
|
+
rotation?: number;
|
|
1120
|
+
}
|
|
1121
|
+
): SVGElement {
|
|
1084
1122
|
options = options || {};
|
|
1085
1123
|
const color: string = options.color || "black";
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1124
|
+
const lineHeight = (options.lineHeight ?? options.fontSize ?? 0) * this.scale.x;
|
|
1125
|
+
// https://www.w3.org/TR/SVG/text.html#TextAnchorProperty
|
|
1126
|
+
// start | middle | end
|
|
1127
|
+
const textAlign: "start" | "middle" | "end" =
|
|
1128
|
+
options.textAlign === "left" || options.textAlign === "start"
|
|
1129
|
+
? "start"
|
|
1130
|
+
: options.textAlign === "center"
|
|
1131
|
+
? "middle"
|
|
1132
|
+
: options.textAlign === "right" || options.textAlign === "end"
|
|
1133
|
+
? "end"
|
|
1134
|
+
: "start";
|
|
1135
|
+
const transformOrigin = `${this._x(x)}px ${this._y(y)}px`;
|
|
1136
|
+
const translate = `translate(${this._x(x)} ${this._y(y) + lineHeight / 2})`;
|
|
1137
|
+
// Safari has a transform-origin/rotation bug.
|
|
1138
|
+
// It's essential to use rotate(r,x,y) here. "rotate(r)"" with transform-origin(x,y) won't do the job.
|
|
1139
|
+
// And rotate and translate cannot be used is combination on a text object.
|
|
1140
|
+
// So wrap the text inside a <g>, translate the <g>, and rotate the text inside.
|
|
1141
|
+
const rotate = options.rotation ? `rotate(${options.rotation * RAD_TO_DEG} 0 0)` : ``;
|
|
1142
|
+
|
|
1143
|
+
const node: SVGElement = this.makeNode("g");
|
|
1144
|
+
const curId = this.curId;
|
|
1145
|
+
this.curId = curId + "_text";
|
|
1146
|
+
const textNode: SVGElement = this.makeNode("text");
|
|
1147
|
+
node.appendChild(textNode);
|
|
1148
|
+
textNode.setAttribute("font-family", options.fontFamily); // May be undefined
|
|
1149
|
+
textNode.setAttribute("font-size", options.fontSize ? `${options.fontSize * this.scale.x}` : null);
|
|
1150
|
+
textNode.setAttribute("font-style", options.fontStyle ? `${options.fontStyle}` : null);
|
|
1151
|
+
textNode.setAttribute("font-weight", options.fontWeight ? `${options.fontWeight}` : null);
|
|
1152
|
+
textNode.setAttribute("text-anchor", textAlign);
|
|
1153
|
+
textNode.setAttribute("transform-origin", "0 0");
|
|
1154
|
+
textNode.setAttribute("transform", rotate);
|
|
1155
|
+
node.setAttribute("transform-origin", transformOrigin);
|
|
1156
|
+
node.setAttribute("transform", translate);
|
|
1157
|
+
|
|
1158
|
+
textNode.innerHTML = text;
|
|
1159
|
+
// Restore old ID
|
|
1160
|
+
this.curId = curId;
|
|
1091
1161
|
return this._bindFillDraw(node, "text", color, 1);
|
|
1092
1162
|
}
|
|
1093
1163
|
|
|
@@ -1099,16 +1169,23 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
1099
1169
|
* @param {number} x - The x-position to draw the text at.
|
|
1100
1170
|
* @param {number} y - The y-position to draw the text at.
|
|
1101
1171
|
* @param {number=} rotation - The (optional) rotation in radians.
|
|
1172
|
+
* @param {string="black"} color - The color to use (default is black).
|
|
1102
1173
|
* @return {void}
|
|
1103
1174
|
* @instance
|
|
1104
1175
|
* @memberof drawutilssvg
|
|
1105
1176
|
*/
|
|
1106
|
-
label(text: string, x: number, y: number, rotation
|
|
1177
|
+
label(text: string, x: number, y: number, rotation?: number, color?: string): SVGElement {
|
|
1107
1178
|
const node: SVGElement = this.makeNode("text");
|
|
1108
1179
|
// For some strange reason SVG rotation transforms use degrees instead of radians
|
|
1109
|
-
node.setAttribute("transform", `translate(${
|
|
1180
|
+
node.setAttribute("transform", `translate(${x},${y}), rotate(${((rotation || 0) / Math.PI) * 180})`);
|
|
1181
|
+
|
|
1182
|
+
node.setAttribute("font-family", "Arial");
|
|
1183
|
+
node.setAttribute("font-size", "9pt");
|
|
1184
|
+
node.setAttribute("font-style", "normal");
|
|
1185
|
+
node.setAttribute("font-weight", "lighter");
|
|
1186
|
+
|
|
1110
1187
|
node.innerHTML = text;
|
|
1111
|
-
return this._bindFillDraw(node, "label", "black", null);
|
|
1188
|
+
return this._bindFillDraw(node, "label", color || "black", null);
|
|
1112
1189
|
}
|
|
1113
1190
|
|
|
1114
1191
|
/**
|
package/src/ts/index.ts
CHANGED
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
* @modified 2021-03-30 Added the `endDrawCycle` function to `DrawLib`.
|
|
13
13
|
* @modified 2021-05-31 Added the `drawLib.setConfiguration` function.
|
|
14
14
|
* @modified 2021-05-31 Splitted the large interfaces.ts file into this one and others.
|
|
15
|
+
* @modified 2021-11-12 Added `text()` params fontSize, fontFamily, rotation, textAlign.
|
|
16
|
+
* @modified 2021-11-16 Added `text()` params fontWeight and fontStyle.
|
|
17
|
+
* @modified 2021-11-19 Added the `color` param to the `label(...)` function.
|
|
15
18
|
**/
|
|
16
19
|
|
|
17
20
|
import { Polygon } from "../Polygon";
|
|
@@ -27,6 +30,21 @@ export interface DrawLibConfiguration {
|
|
|
27
30
|
blendMode?: 'source-over' | 'source-in' | 'source-out' | 'source-atop' | 'destination-over' | 'destination-in' | 'destination-out' | 'destination-atop' | 'lighter' | 'copy' | 'xor' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity' | null;
|
|
28
31
|
}
|
|
29
32
|
|
|
33
|
+
export type FontWeight = "normal" | "bold" | "bolder" | "lighter" | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
34
|
+
|
|
35
|
+
export type FontStyle = "normal" | "italic" | "oblique";
|
|
36
|
+
|
|
37
|
+
export interface FontOptions {
|
|
38
|
+
color?: string;
|
|
39
|
+
fontFamily?: string;
|
|
40
|
+
fontSize?: number;
|
|
41
|
+
fontStyle?: FontStyle;
|
|
42
|
+
fontWeight?: FontWeight;
|
|
43
|
+
lineHeight?: number;
|
|
44
|
+
textAlign?: CanvasRenderingContext2D["textAlign"];
|
|
45
|
+
rotation?: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
30
48
|
/**
|
|
31
49
|
* An interface all drawing libraries must implement to be used with PlotBoilerplate.
|
|
32
50
|
*
|
|
@@ -432,18 +450,25 @@ export interface DrawLib<R> {
|
|
|
432
450
|
polyline: (vertices: Array<Vertex>, isOpen: boolean, color: string, lineWidth?: number) => R;
|
|
433
451
|
|
|
434
452
|
/**
|
|
435
|
-
* Draw a text
|
|
453
|
+
* Draw a text at the given relative position.
|
|
436
454
|
*
|
|
437
455
|
* @method text
|
|
438
456
|
* @param {string} text - The text to draw.
|
|
439
457
|
* @param {number} x - The x-position to draw the text at.
|
|
440
458
|
* @param {number} y - The y-position to draw the text at.
|
|
441
|
-
* @param {
|
|
459
|
+
* @param {string=} options.color - The Color to use.
|
|
460
|
+
* @param {string=} options.fontFamily - The font family to use.
|
|
461
|
+
* @param {number=} options.fontSize - The font size (in pixels) to use.
|
|
462
|
+
* @param {FontStyle=} options.fontStyle - The font style to use.
|
|
463
|
+
* @param {FontWeight=} options.fontWeight - The font weight to use.
|
|
464
|
+
* @param {number=} options.lineHeight - The line height (in pixels) to use.
|
|
465
|
+
* @param {number=} options.rotation - The (optional) rotation in radians.
|
|
466
|
+
* @param {string=} options.textAlign - The text align to use. According to the specifiactions (https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign) valid values are `"left" || "right" || "center" || "start" || "end"`.
|
|
442
467
|
* @return {void}
|
|
443
468
|
* @instance
|
|
444
469
|
* @memberof drawutils
|
|
445
470
|
*/
|
|
446
|
-
text: (text: string, x: number, y: number, options?:
|
|
471
|
+
text: (text: string, x: number, y: number, options?: FontOptions) => R;
|
|
447
472
|
|
|
448
473
|
/**
|
|
449
474
|
* Draw a non-scaling text label at the given absolute position.
|
|
@@ -453,11 +478,12 @@ export interface DrawLib<R> {
|
|
|
453
478
|
* @param {number} x - The x-position to draw the text at.
|
|
454
479
|
* @param {number} y - The y-position to draw the text at.
|
|
455
480
|
* @param {number=} rotation - The (aoptional) rotation in radians.
|
|
481
|
+
* @param {string="black"} color - The color to use (default is black).
|
|
456
482
|
* @return {void}
|
|
457
483
|
* @instance
|
|
458
484
|
* @memberof drawutils
|
|
459
485
|
*/
|
|
460
|
-
label: (text: string, x: number, y: number, rotation
|
|
486
|
+
label: (text: string, x: number, y: number, rotation?: number, color?: string) => R;
|
|
461
487
|
|
|
462
488
|
/**
|
|
463
489
|
* Draw an SVG-like path given by the specified path data.
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* @modified 2021-05-31 Added the `drawLib.setConfiguration` function.
|
|
14
14
|
* @modified 2021-05-31 Splitted the large interfaces.ts file into this one and others.
|
|
15
15
|
* @modified 2021-06-21 Added `IBounds.getCenter()`.
|
|
16
|
+
* @modified 2021-11-16 Added `text` options to the `DrawConfig`.
|
|
16
17
|
**/
|
|
17
18
|
|
|
18
19
|
import { Vertex } from "../Vertex";
|
|
@@ -28,6 +29,7 @@ import { BezierPath } from "../BezierPath";
|
|
|
28
29
|
import { Line } from "../Line";
|
|
29
30
|
import { PlotBoilerplate } from "../PlotBoilerplate";
|
|
30
31
|
import { DrawLib } from "./DrawLib";
|
|
32
|
+
import { PBText } from "../PBText";
|
|
31
33
|
|
|
32
34
|
/**
|
|
33
35
|
* @classdesc Coordinates (x,y) on the plane.
|
|
@@ -73,6 +75,7 @@ export type Drawable =
|
|
|
73
75
|
| Circle
|
|
74
76
|
| CircleSector
|
|
75
77
|
| PBImage
|
|
78
|
+
| PBText
|
|
76
79
|
| VEllipse
|
|
77
80
|
| VEllipseSector
|
|
78
81
|
| Polygon
|
|
@@ -160,6 +163,7 @@ export interface PBParams extends Config {
|
|
|
160
163
|
export interface DrawSettings {
|
|
161
164
|
color: string;
|
|
162
165
|
lineWidth: number;
|
|
166
|
+
fill?: boolean;
|
|
163
167
|
}
|
|
164
168
|
|
|
165
169
|
export interface DrawConfig {
|
|
@@ -174,6 +178,8 @@ export interface DrawConfig {
|
|
|
174
178
|
color: string;
|
|
175
179
|
lineWidth: number;
|
|
176
180
|
handleLine: DrawSettings;
|
|
181
|
+
pathVertex: DrawSettings;
|
|
182
|
+
controlVertex: DrawSettings;
|
|
177
183
|
};
|
|
178
184
|
polygon: DrawSettings;
|
|
179
185
|
triangle: DrawSettings;
|
|
@@ -186,6 +192,12 @@ export interface DrawConfig {
|
|
|
186
192
|
line: DrawSettings;
|
|
187
193
|
vector: DrawSettings;
|
|
188
194
|
image: DrawSettings;
|
|
195
|
+
text: {
|
|
196
|
+
color: string;
|
|
197
|
+
lineWidth: number;
|
|
198
|
+
fill?: boolean;
|
|
199
|
+
anchor?: boolean;
|
|
200
|
+
};
|
|
189
201
|
}
|
|
190
202
|
|
|
191
203
|
/** This is a fix for the problem, that the constructor's "name" attribute is not
|