plotboilerplate 1.17.0 → 1.18.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 +63 -6
- package/changelog.md +25 -0
- package/dist/index.esm.js +152 -28
- 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 +155 -28
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/Bounds.d.ts +11 -0
- package/src/cjs/Bounds.js +14 -0
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/Circle.d.ts +36 -2
- package/src/cjs/Circle.js +81 -1
- package/src/cjs/Circle.js.map +1 -1
- package/src/cjs/MouseHandler.d.ts +3 -2
- package/src/cjs/MouseHandler.js +16 -14
- package/src/cjs/MouseHandler.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +3 -1
- package/src/cjs/PlotBoilerplate.js +8 -1
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/draw.d.ts +8 -2
- package/src/cjs/draw.js +23 -8
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +4 -2
- package/src/cjs/drawgl.js +5 -2
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +4 -2
- package/src/cjs/drawutilssvg.js +8 -2
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +3 -1
- package/src/cjs/interfaces/DrawLib.js +1 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +2 -0
- 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 +17 -6
- package/src/cjs/utils/datastructures/Color.js.map +1 -1
- package/src/esm/Bounds.d.ts +11 -0
- package/src/esm/Bounds.js +14 -0
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/Circle.d.ts +36 -2
- package/src/esm/Circle.js +81 -1
- package/src/esm/Circle.js.map +1 -1
- package/src/esm/MouseHandler.d.ts +3 -2
- package/src/esm/MouseHandler.js +16 -14
- package/src/esm/MouseHandler.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +3 -1
- package/src/esm/PlotBoilerplate.js +8 -1
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/draw.d.ts +8 -2
- package/src/esm/draw.js +22 -8
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +4 -2
- package/src/esm/drawgl.js +4 -2
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +4 -2
- package/src/esm/drawutilssvg.js +7 -2
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +3 -1
- package/src/esm/interfaces/DrawLib.js +1 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +2 -0
- 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 +17 -6
- package/src/esm/utils/datastructures/Color.js.map +1 -1
- package/src/ts/Bounds.ts +15 -0
- package/src/ts/Circle.ts +92 -2
- package/src/ts/MouseHandler.ts +16 -15
- package/src/ts/PlotBoilerplate.ts +8 -1
- package/src/ts/draw.ts +23 -8
- package/src/ts/drawgl.ts +4 -2
- package/src/ts/drawutilssvg.ts +7 -2
- package/src/ts/interfaces/DrawLib.ts +3 -1
- package/src/ts/interfaces/core.ts +3 -2
- package/src/ts/utils/datastructures/Color.ts +17 -6
package/src/ts/Circle.ts
CHANGED
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
* @modified 2021-01-20 Added UID.
|
|
10
10
|
* @modified 2022-02-02 Added the `destroy` method.
|
|
11
11
|
* @modified 2022-02-02 Cleared the `toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
12
|
-
* @
|
|
12
|
+
* @modified 2022-08-15 Added the `containsPoint` function.
|
|
13
|
+
* @modified 2022-08-23 Added the `lineIntersection` function.
|
|
14
|
+
* @modified 2022-08-23 Added the `closestPoint` function.
|
|
15
|
+
* @version 1.4.0
|
|
13
16
|
**/
|
|
14
17
|
|
|
15
18
|
import { Line } from "./Line";
|
|
@@ -17,7 +20,7 @@ import { UIDGenerator } from "./UIDGenerator";
|
|
|
17
20
|
import { Vector } from "./Vector";
|
|
18
21
|
import { VertTuple } from "./VertTuple";
|
|
19
22
|
import { Vertex } from "./Vertex";
|
|
20
|
-
import { SVGSerializable, UID } from "./interfaces";
|
|
23
|
+
import { SVGSerializable, UID, XYCoords } from "./interfaces";
|
|
21
24
|
|
|
22
25
|
/**
|
|
23
26
|
* @classdesc A simple circle: center point and radius.
|
|
@@ -82,6 +85,19 @@ export class Circle implements SVGSerializable {
|
|
|
82
85
|
this.radius = radius;
|
|
83
86
|
}
|
|
84
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Check if the given circle is fully contained inside this circle.
|
|
90
|
+
*
|
|
91
|
+
* @method containsPoint
|
|
92
|
+
* @param {XYCoords} point - The point to check if it is contained in this circle.
|
|
93
|
+
* @instance
|
|
94
|
+
* @memberof Circle
|
|
95
|
+
* @return {boolean} `true` if the given point is inside this circle.
|
|
96
|
+
*/
|
|
97
|
+
containsPoint(point: XYCoords): boolean {
|
|
98
|
+
return this.center.distance(point) < this.radius;
|
|
99
|
+
}
|
|
100
|
+
|
|
85
101
|
/**
|
|
86
102
|
* Check if the given circle is fully contained inside this circle.
|
|
87
103
|
*
|
|
@@ -198,6 +214,80 @@ export class Circle implements SVGSerializable {
|
|
|
198
214
|
return new Line(new Vertex(x3, y3), new Vertex(x4, y4));
|
|
199
215
|
}
|
|
200
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Calculate the intersection points (if exists) with the given infinite line (defined by two points).
|
|
219
|
+
*
|
|
220
|
+
* @method lineIntersection
|
|
221
|
+
* @instance
|
|
222
|
+
* @memberof Circle
|
|
223
|
+
* @param {Vertex} a- The first of the two points defining the line.
|
|
224
|
+
* @param {Vertex} b - The second of the two points defining the line.
|
|
225
|
+
* @return {Line|null} The intersection points (as a line) or null if this circle does not intersect the line given.
|
|
226
|
+
**/
|
|
227
|
+
lineIntersection(a: Vertex, b: XYCoords): Line | null {
|
|
228
|
+
// Based on the math from
|
|
229
|
+
// https://mathworld.wolfram.com/Circle-LineIntersection.html
|
|
230
|
+
const interA = new Vertex();
|
|
231
|
+
const interB = new Vertex();
|
|
232
|
+
|
|
233
|
+
// First do a transformation, because the calculation is based on a cicle at (0,0)
|
|
234
|
+
const transA = new Vertex(a).sub(this.center);
|
|
235
|
+
const transB = new Vertex(b).sub(this.center);
|
|
236
|
+
|
|
237
|
+
const diff: XYCoords = transA.difference(transB);
|
|
238
|
+
// There is a special case if diff.y=0, where the intersection is not calcuatable.
|
|
239
|
+
// Use an non-zero epsilon here to approximate this case.
|
|
240
|
+
// TODO for the future: find a better solution
|
|
241
|
+
if (Math.abs(diff.y) === 0) {
|
|
242
|
+
diff.y = 0.000001;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const dist: number = transA.distance(transB);
|
|
246
|
+
const det: number = transA.x * transB.y - transA.y * transB.x;
|
|
247
|
+
const distSquared: number = dist * dist;
|
|
248
|
+
const radiusSquared: number = this.radius * this.radius;
|
|
249
|
+
|
|
250
|
+
// Check if circle and line have an intersection at all
|
|
251
|
+
if (radiusSquared * distSquared - det * det < 0) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const belowSqrt: number = this.radius * this.radius * dist * dist - det * det;
|
|
256
|
+
const sqrt: number = Math.sqrt(belowSqrt);
|
|
257
|
+
|
|
258
|
+
interA.x = (det * diff.y + Math.sign(diff.y) * diff.x * sqrt) / distSquared;
|
|
259
|
+
interB.x = (det * diff.y - Math.sign(diff.y) * diff.x * sqrt) / distSquared;
|
|
260
|
+
|
|
261
|
+
interA.y = (-det * diff.x + Math.abs(diff.y) * sqrt) / distSquared;
|
|
262
|
+
interB.y = (-det * diff.x - Math.abs(diff.y) * sqrt) / distSquared;
|
|
263
|
+
|
|
264
|
+
return new Line(interA.add(this.center), interB.add(this.center));
|
|
265
|
+
// return new Line(interA, interB);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Calculate the closest point on the outline of this circle to the given point.
|
|
270
|
+
*
|
|
271
|
+
* @method closestPoint
|
|
272
|
+
* @instance
|
|
273
|
+
* @memberof Circle
|
|
274
|
+
* @param {XYCoords} vert - The point to find the closest circle point for.
|
|
275
|
+
* @return {Vertex} The closest point on this circle.
|
|
276
|
+
**/
|
|
277
|
+
closestPoint(vert: XYCoords): Vertex {
|
|
278
|
+
const lineIntersection = this.lineIntersection(this.center, vert);
|
|
279
|
+
if (!lineIntersection) {
|
|
280
|
+
// Note: this case should not happen as a radial from the center always intersect this circle.
|
|
281
|
+
return new Vertex();
|
|
282
|
+
}
|
|
283
|
+
// Return closed of both
|
|
284
|
+
if (lineIntersection.a.distance(vert) < lineIntersection.b.distance(vert)) {
|
|
285
|
+
return lineIntersection.a;
|
|
286
|
+
} else {
|
|
287
|
+
return lineIntersection.b;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
201
291
|
/**
|
|
202
292
|
* This function should invalidate any installed listeners and invalidate this object.
|
|
203
293
|
* After calling this function the object might not hold valid data any more and
|
package/src/ts/MouseHandler.ts
CHANGED
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
* @modified 2020-10-04 Added extended JSDoc comments.
|
|
18
18
|
* @modified 2020-11-25 Added the `isTouchEvent` param.
|
|
19
19
|
* @modified 2021-01-10 The mouse handler is now also working with SVGElements.
|
|
20
|
-
* @
|
|
20
|
+
* @modified 2022-08-16 Fixed a bug in the mouse button detection.
|
|
21
|
+
* @version 1.2.1
|
|
21
22
|
*
|
|
22
23
|
* @file MouseHandler
|
|
23
24
|
* @public
|
|
@@ -58,7 +59,7 @@ export type XWheelCallback = (e: XWheelEvent) => void;
|
|
|
58
59
|
* @requires XYCoords
|
|
59
60
|
*/
|
|
60
61
|
export class MouseHandler {
|
|
61
|
-
private name: string;
|
|
62
|
+
private name: string | undefined;
|
|
62
63
|
private element: HTMLElement | SVGElement;
|
|
63
64
|
private mouseDownPos: { x: number; y: number } | undefined = undefined;
|
|
64
65
|
private mouseDragPos: { x: number; y: number } | undefined = undefined;
|
|
@@ -135,8 +136,8 @@ export class MouseHandler {
|
|
|
135
136
|
// +-------------------------------------------------
|
|
136
137
|
this.name = name;
|
|
137
138
|
this.element = element;
|
|
138
|
-
this.mouseDownPos =
|
|
139
|
-
this.mouseDragPos =
|
|
139
|
+
this.mouseDownPos = undefined;
|
|
140
|
+
this.mouseDragPos = undefined;
|
|
140
141
|
// this.mousePos = null;
|
|
141
142
|
this.mouseButton = -1;
|
|
142
143
|
this.listeners = {};
|
|
@@ -202,26 +203,26 @@ export class MouseHandler {
|
|
|
202
203
|
* @memberof MouseHandler
|
|
203
204
|
* @instance
|
|
204
205
|
* @private
|
|
205
|
-
* @param {MouseEvent}
|
|
206
|
+
* @param {MouseEvent} event - The mouse event to get the relative position for.
|
|
206
207
|
* @param {string} eventName - The name of the firing event.
|
|
207
208
|
* @return {XMouseEvent}
|
|
208
209
|
*/
|
|
209
|
-
private mkParams(
|
|
210
|
-
const rel: { x: number; y: number } = this.relPos(
|
|
211
|
-
const xEvent: XMouseEvent =
|
|
210
|
+
private mkParams(event: MouseEvent, eventName: string): XMouseEvent {
|
|
211
|
+
const rel: { x: number; y: number } = this.relPos(event);
|
|
212
|
+
const xEvent: XMouseEvent = event as unknown as XMouseEvent;
|
|
212
213
|
xEvent.params = {
|
|
213
214
|
element: this.element,
|
|
214
215
|
name: eventName,
|
|
215
216
|
isTouchEvent: false,
|
|
216
217
|
pos: rel,
|
|
217
|
-
button: this.mouseButton,
|
|
218
|
-
leftButton: this.mouseButton
|
|
219
|
-
middleButton: this.mouseButton
|
|
220
|
-
rightButton: this.mouseButton
|
|
221
|
-
mouseDownPos: this.mouseDownPos,
|
|
222
|
-
draggedFrom: this.mouseDragPos,
|
|
218
|
+
button: event.button, // this.mouseButton,
|
|
219
|
+
leftButton: event.button === 0, // this.mouseButton === 0,
|
|
220
|
+
middleButton: event.button === 1, // this.mouseButton === 1,
|
|
221
|
+
rightButton: event.button === 2, // this.mouseButton === 2,
|
|
222
|
+
mouseDownPos: this.mouseDownPos ?? { x: NaN, y: NaN },
|
|
223
|
+
draggedFrom: this.mouseDragPos ?? { x: NaN, y: NaN },
|
|
223
224
|
wasDragged: this.mouseDownPos != null && (this.mouseDownPos.x != rel.x || this.mouseDownPos.y != rel.y),
|
|
224
|
-
dragAmount: this.
|
|
225
|
+
dragAmount: this.mouseDragPos != null ? { x: rel.x - this.mouseDragPos.x, y: rel.y - this.mouseDragPos.y } : { x: 0, y: 0 }
|
|
225
226
|
};
|
|
226
227
|
return xEvent;
|
|
227
228
|
}
|
|
@@ -74,7 +74,8 @@
|
|
|
74
74
|
* @modified 2021-03-29 Clearing `currentClassName` and `currentId` after drawing each drawable.
|
|
75
75
|
* @modified 2021-04-25 Extending `remove` to accept arrays of drawables.
|
|
76
76
|
* @modified 2021-11-16 Adding the `PBText` drawable.
|
|
77
|
-
* @
|
|
77
|
+
* @modified 2022-08-01 Added `title` to the params.
|
|
78
|
+
* @version 1.15.1
|
|
78
79
|
*
|
|
79
80
|
* @file PlotBoilerplate
|
|
80
81
|
* @fileoverview The main class.
|
|
@@ -376,6 +377,7 @@ export class PlotBoilerplate {
|
|
|
376
377
|
* @param {boolean=} [config.enableGL=false] - Indicates if the application should use the experimental WebGL features (not recommended).
|
|
377
378
|
* @param {boolean=} [config.enableSVGExport=true] - Indicates if the SVG export should be enabled (default is true).
|
|
378
379
|
* Note that changes from the postDraw hook might not be visible in the export.
|
|
380
|
+
* @param {string=} [config.title=null] - Specify any hover tile here. It will be attached as a `title` attribute to the most elevated element.
|
|
379
381
|
*/
|
|
380
382
|
constructor(config: PBParams) {
|
|
381
383
|
// This should be in some static block ...
|
|
@@ -592,6 +594,11 @@ export class PlotBoilerplate {
|
|
|
592
594
|
} else {
|
|
593
595
|
throw "Element is neither a canvas nor an svg element.";
|
|
594
596
|
}
|
|
597
|
+
// At this point the event cacher element is deinfed and located at highest elevation.
|
|
598
|
+
// Set `title` attribut?
|
|
599
|
+
if (config.title) {
|
|
600
|
+
this.eventCatcher.setAttribute("title", config.title);
|
|
601
|
+
}
|
|
595
602
|
this.draw.scale.set(this.config.scaleX, this.config.scaleY);
|
|
596
603
|
this.fill.scale.set(this.config.scaleX, this.config.scaleY);
|
|
597
604
|
this.vertices = [];
|
package/src/ts/draw.ts
CHANGED
|
@@ -42,7 +42,12 @@
|
|
|
42
42
|
* @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
|
|
43
43
|
* @modified 2022-02-03 Added the `cross(...)` function.
|
|
44
44
|
* @modified 2022-03-27 Added the `texturedPoly` function.
|
|
45
|
-
* @
|
|
45
|
+
* @modified 2022-06-01 Tweaked the `polyline` function; lineWidth now scales with scale.x.
|
|
46
|
+
* @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
|
|
47
|
+
* @modified 2022-08-23 Fixed a type issue in the `polyline` function.
|
|
48
|
+
* @modified 2022-08-23 Fixed a type issue in the `setConfiguration` function.
|
|
49
|
+
* @modified 2022-08-23 Fixed a type issue in the `path` function.
|
|
50
|
+
* @version 1.12.3
|
|
46
51
|
**/
|
|
47
52
|
|
|
48
53
|
import { CubicBezierCurve } from "./CubicBezierCurve";
|
|
@@ -139,7 +144,7 @@ export class drawutils implements DrawLib<void> {
|
|
|
139
144
|
* @param {DrawLibConfiguration} configuration - The new configuration settings to use for the next render methods.
|
|
140
145
|
*/
|
|
141
146
|
setConfiguration(configuration: DrawLibConfiguration): void {
|
|
142
|
-
this.ctx.globalCompositeOperation = configuration.blendMode;
|
|
147
|
+
this.ctx.globalCompositeOperation = configuration.blendMode || "source-over";
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
/**
|
|
@@ -229,16 +234,18 @@ export class drawutils implements DrawLib<void> {
|
|
|
229
234
|
* @param {Image} image - The image object to draw.
|
|
230
235
|
* @param {Vertex} position - The position to draw the the upper left corner at.
|
|
231
236
|
* @param {Vertex} size - The x/y-size to draw the image with.
|
|
237
|
+
* @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
|
|
232
238
|
* @return {void}
|
|
233
239
|
* @instance
|
|
234
240
|
* @memberof drawutils
|
|
235
241
|
**/
|
|
236
|
-
image(image: HTMLImageElement, position: Vertex, size: Vertex): void {
|
|
242
|
+
image(image: HTMLImageElement, position: Vertex, size: Vertex, alpha: number = 1.0): void {
|
|
237
243
|
if (!image.complete || !image.naturalWidth) {
|
|
238
244
|
// Avoid drawing un-unloaded or broken images
|
|
239
245
|
return;
|
|
240
246
|
}
|
|
241
247
|
this.ctx.save();
|
|
248
|
+
this.ctx.globalAlpha = alpha;
|
|
242
249
|
// Note that there is a Safari bug with the 3 or 5 params variant.
|
|
243
250
|
// Only the 9-param varaint works.
|
|
244
251
|
this.ctx.drawImage(
|
|
@@ -1003,10 +1010,12 @@ export class drawutils implements DrawLib<void> {
|
|
|
1003
1010
|
* @memberof drawutils
|
|
1004
1011
|
*/
|
|
1005
1012
|
polyline(vertices: Array<Vertex>, isOpen: boolean, color: string, lineWidth?: number) {
|
|
1006
|
-
if (vertices.length <= 1)
|
|
1013
|
+
if (vertices.length <= 1) {
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1007
1016
|
this.ctx.save();
|
|
1008
1017
|
this.ctx.beginPath();
|
|
1009
|
-
this.ctx.lineWidth = lineWidth || 1.0;
|
|
1018
|
+
this.ctx.lineWidth = (lineWidth || 1.0) * this.scale.x;
|
|
1010
1019
|
this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
|
|
1011
1020
|
for (var i = 0; i < vertices.length; i++) {
|
|
1012
1021
|
this.ctx.lineTo(this.offset.x + vertices[i].x * this.scale.x, this.offset.y + vertices[i].y * this.scale.y);
|
|
@@ -1141,13 +1150,19 @@ export class drawutils implements DrawLib<void> {
|
|
|
1141
1150
|
path(pathData: SVGPathParams, color?: string, lineWidth?: number, options?: { inplace?: boolean }) {
|
|
1142
1151
|
const d: SVGPathParams = options && options.inplace ? pathData : drawutilssvg.copyPathData(pathData);
|
|
1143
1152
|
drawutilssvg.transformPathData(d, this.offset, this.scale);
|
|
1144
|
-
|
|
1153
|
+
if (color) {
|
|
1154
|
+
this.ctx.strokeStyle = color;
|
|
1155
|
+
}
|
|
1145
1156
|
this.ctx.lineWidth = lineWidth || 1;
|
|
1146
1157
|
if (this.fillShapes) {
|
|
1147
|
-
|
|
1158
|
+
if (color) {
|
|
1159
|
+
this.ctx.fillStyle = color;
|
|
1160
|
+
}
|
|
1148
1161
|
this.ctx.fill(new Path2D(d.join(" ")));
|
|
1149
1162
|
} else {
|
|
1150
|
-
|
|
1163
|
+
if (color) {
|
|
1164
|
+
this.ctx.strokeStyle = color;
|
|
1165
|
+
}
|
|
1151
1166
|
this.ctx.stroke(new Path2D(d.join(" ")));
|
|
1152
1167
|
}
|
|
1153
1168
|
}
|
package/src/ts/drawgl.ts
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
|
|
10
10
|
* @modified 2022-02-03 Added the `cross(...)` function.
|
|
11
11
|
* @modified 2022-03-27 Added the `texturedPoly` function.
|
|
12
|
-
* @
|
|
12
|
+
* @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
|
|
13
|
+
* @version 0.0.8
|
|
13
14
|
**/
|
|
14
15
|
|
|
15
16
|
import { CubicBezierCurve } from "./CubicBezierCurve";
|
|
@@ -279,11 +280,12 @@ export class drawutilsgl implements DrawLib<void> {
|
|
|
279
280
|
* @param {Image} image - The image object to draw.
|
|
280
281
|
* @param {Vertex} position - The position to draw the the upper left corner at.
|
|
281
282
|
* @param {Vertex} size - The x/y-size to draw the image with.
|
|
283
|
+
* @param {number=0.0} alpha - (optional, default=0.0) The transparency (0.0=opaque, 1.0=transparent).
|
|
282
284
|
* @return {void}
|
|
283
285
|
* @instance
|
|
284
286
|
* @memberof drawutils
|
|
285
287
|
**/
|
|
286
|
-
image(image: HTMLImageElement, position: Vertex, size: Vertex) {
|
|
288
|
+
image(image: HTMLImageElement, position: Vertex, size: Vertex, alpha: number = 0.0) {
|
|
287
289
|
// NOT YET IMPLEMENTED
|
|
288
290
|
}
|
|
289
291
|
|
package/src/ts/drawutilssvg.ts
CHANGED
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
* @modified 2022-02-03 Added the `cross(...)` function.
|
|
34
34
|
* @modified 2022-03-26 Added the private `nodeDefs` and `bufferedNodeDefs` attributes.
|
|
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
|
+
* @version 1.6.1
|
|
37
38
|
**/
|
|
38
39
|
|
|
39
40
|
import { CircleSector } from "./CircleSector";
|
|
@@ -594,11 +595,12 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
594
595
|
* @param {Image} image - The image object to draw.
|
|
595
596
|
* @param {Vertex} position - The position to draw the the upper left corner at.
|
|
596
597
|
* @param {Vertex} size - The x/y-size to draw the image with.
|
|
598
|
+
* @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
|
|
597
599
|
* @return {void}
|
|
598
600
|
* @instance
|
|
599
601
|
* @memberof drawutilssvg
|
|
600
602
|
**/
|
|
601
|
-
image(image: HTMLImageElement, position: Vertex, size: Vertex) {
|
|
603
|
+
image(image: HTMLImageElement, position: Vertex, size: Vertex, alpha: number = 1.0) {
|
|
602
604
|
const node: SVGElement = this.makeNode("image");
|
|
603
605
|
|
|
604
606
|
// We need to re-adjust the image if it was not yet fully loaded before.
|
|
@@ -609,6 +611,9 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
609
611
|
node.setAttribute("width", `${image.naturalWidth * this.scale.x}`);
|
|
610
612
|
node.setAttribute("height", `${image.naturalHeight * this.scale.y}`);
|
|
611
613
|
node.setAttribute("display", null); // Dislay when loaded
|
|
614
|
+
// if (alpha) {
|
|
615
|
+
node.setAttribute("opacity", `${alpha}`);
|
|
616
|
+
// }
|
|
612
617
|
node.setAttribute("transform", `translate(${this._x(position.x)} ${this._y(position.y)}) scale(${ratioX} ${ratioY})`);
|
|
613
618
|
}
|
|
614
619
|
};
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* @modified 2021-11-19 Added the `color` param to the `label(...)` function.
|
|
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
|
+
* @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
|
|
20
21
|
**/
|
|
21
22
|
|
|
22
23
|
import { Bounds } from "../Bounds";
|
|
@@ -151,11 +152,12 @@ export interface DrawLib<R> {
|
|
|
151
152
|
* @param {Image} image - The image object to draw.
|
|
152
153
|
* @param {Vertex} position - The position to draw the the upper left corner at.
|
|
153
154
|
* @param {Vertex} size - The x/y-size to draw the image with.
|
|
155
|
+
* @param {number=1.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
|
|
154
156
|
* @return {void}
|
|
155
157
|
* @instance
|
|
156
158
|
* @memberof DrawLib
|
|
157
159
|
**/
|
|
158
|
-
image: (image: HTMLImageElement, position: Vertex, size: Vertex) => R;
|
|
160
|
+
image: (image: HTMLImageElement, position: Vertex, size: Vertex, alpha?: number) => R;
|
|
159
161
|
|
|
160
162
|
/**
|
|
161
163
|
* Draw an image at the given position with the given size.<br>
|
|
@@ -14,6 +14,7 @@
|
|
|
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
16
|
* @modified 2021-11-16 Added `text` options to the `DrawConfig`.
|
|
17
|
+
* @modified 2022-08-01 Added `title` param to the `PBParams` interface.
|
|
17
18
|
**/
|
|
18
19
|
|
|
19
20
|
import { Vertex } from "../Vertex";
|
|
@@ -156,8 +157,8 @@ export interface Config {
|
|
|
156
157
|
* For initialization the constructor needs a mix of config and draw-settings.
|
|
157
158
|
*/
|
|
158
159
|
export interface PBParams extends Config {
|
|
159
|
-
//
|
|
160
|
-
// No additional attributes, just merge two interfaces.
|
|
160
|
+
title?: string; // Specify any hover tile here. It will be attached as a `title` attribute to the most elevated element.
|
|
161
|
+
// No more additional attributes, just merge two interfaces.
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
export interface DrawSettings {
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
* @modified 2021-11-07 Did the same with `saturate` and `desaturate`.
|
|
15
15
|
* @modified 2021-11-07 Did the same with the `fadein` and `fadeout` functions.
|
|
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
|
+
* @modified 2022-05-11 Fixed the `interpolate` function.
|
|
19
|
+
* @version 0.0.11
|
|
18
20
|
**/
|
|
19
21
|
|
|
20
22
|
/**
|
|
@@ -698,7 +700,16 @@ export class Color {
|
|
|
698
700
|
* @return {Color} A clone of this color (in RGB mode).
|
|
699
701
|
*/
|
|
700
702
|
clone(): Color {
|
|
701
|
-
return Color.makeRGB(this.r, this.g, this.b, this.a);
|
|
703
|
+
// return Color.makeRGB(this.r, this.g, this.b, this.a);
|
|
704
|
+
const col = new Color();
|
|
705
|
+
col.r = this.r;
|
|
706
|
+
col.g = this.g;
|
|
707
|
+
col.b = this.b;
|
|
708
|
+
col.a = this.a;
|
|
709
|
+
col.h = this.h;
|
|
710
|
+
col.s = this.s;
|
|
711
|
+
col.l = this.l;
|
|
712
|
+
return col;
|
|
702
713
|
}
|
|
703
714
|
|
|
704
715
|
/**
|
|
@@ -712,10 +723,10 @@ export class Color {
|
|
|
712
723
|
* @return {Color} A clone of this color (in RGB mode).
|
|
713
724
|
*/
|
|
714
725
|
interpolate(c: Color, t: number): Color {
|
|
715
|
-
this.r += (c.r -
|
|
716
|
-
this.g += (c.g -
|
|
717
|
-
this.b += (c.b -
|
|
718
|
-
this.a += (c.a -
|
|
726
|
+
this.r += (c.r - this.r) * t;
|
|
727
|
+
this.g += (c.g - this.g) * t;
|
|
728
|
+
this.b += (c.b - this.b) * t;
|
|
729
|
+
this.a += (c.a - this.a) * t;
|
|
719
730
|
return this;
|
|
720
731
|
}
|
|
721
732
|
} // END class
|