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/README.md
CHANGED
|
@@ -47,12 +47,18 @@ often use for the visualization of 2D geometries. Basic features are
|
|
|
47
47
|
- text
|
|
48
48
|
([docs](https://plotboilerplate.io/docs_typedoc/classes/pbtext.html "PBText class"),
|
|
49
49
|
[example](https://plotboilerplate.io/repo/demos/basic-PBText "PBText example"))
|
|
50
|
-
- configuration of the canvas behavior
|
|
51
|
-
-
|
|
52
|
-
- keyboard interaction
|
|
53
|
-
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
- configuration of the canvas behavior
|
|
51
|
+
- fullsize and auto-resizing
|
|
52
|
+
- enable/disable mouse, touch or keyboard interaction
|
|
53
|
+
- draw rasters
|
|
54
|
+
- default colors and darkmode
|
|
55
|
+
- mouse and touch interaction
|
|
56
|
+
- zoom
|
|
57
|
+
- pan
|
|
58
|
+
- drag and select elements
|
|
59
|
+
- keyboard interaction customizable
|
|
60
|
+
|
|
61
|
+
The compressed library has 133kb.
|
|
56
62
|
|
|
57
63
|
## Install the package via npm
|
|
58
64
|
|
|
@@ -143,6 +149,8 @@ globalThis.addEventListener("load", () => {
|
|
|
143
149
|
});
|
|
144
150
|
```
|
|
145
151
|
|
|
152
|
+
For a guide of how to [Getting Started click here](https://github.com/IkarosKappler/plotboilerplate/blob/master/Getting-Started.md "Getting Started click here.").
|
|
153
|
+
|
|
146
154
|
A full working demo repository about the [Usage with Typescript is here](https://github.com/IkarosKappler/plotboilerplate-typescript-example "usage with Typescript is here").
|
|
147
155
|
|
|
148
156
|
### Screenshot
|
|
@@ -442,6 +450,55 @@ vert.listeners.addDragListener(function (e) {
|
|
|
442
450
|
- Touch & move (2 fingers): Pan the area
|
|
443
451
|
- Touch & pinch: Zoom in/out
|
|
444
452
|
|
|
453
|
+
## Custom keyboard events
|
|
454
|
+
|
|
455
|
+
```javascript
|
|
456
|
+
new KeyHandler({ trackAll: true })
|
|
457
|
+
.down("enter", function () {
|
|
458
|
+
console.log("ENTER was hit.");
|
|
459
|
+
})
|
|
460
|
+
.press("enter", function () {
|
|
461
|
+
console.log("ENTER was pressed.");
|
|
462
|
+
})
|
|
463
|
+
.up("enter", function () {
|
|
464
|
+
console.log("ENTER was released.");
|
|
465
|
+
})
|
|
466
|
+
.down("e", function () {
|
|
467
|
+
console.log("e was hit. shift is pressed?", keyHandler.isDown("shift"));
|
|
468
|
+
})
|
|
469
|
+
.up("spacebar", function () {
|
|
470
|
+
console.log("spacebar was released.");
|
|
471
|
+
});
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
For a list of all supported key codes see [Full list of supported key codes](https://github.com/IkarosKappler/plotboilerplate/blob/master/keycodes.md "Full list of supported key codes").
|
|
475
|
+
|
|
476
|
+
## Custom mouse event
|
|
477
|
+
|
|
478
|
+
```javascript
|
|
479
|
+
new MouseHandler(document.getElementById("mycanvas"))
|
|
480
|
+
.drag(function (e) {
|
|
481
|
+
console.log("Mouse dragged: " + JSON.stringify(e));
|
|
482
|
+
if (e.params.leftMouse);
|
|
483
|
+
else if (e.params.rightMouse);
|
|
484
|
+
})
|
|
485
|
+
.move(function (e) {
|
|
486
|
+
console.log("Mouse moved: " + JSON.stringify(e.params));
|
|
487
|
+
})
|
|
488
|
+
.up(function (e) {
|
|
489
|
+
console.log("Mouse up. Was dragged?", e.params.wasDragged);
|
|
490
|
+
})
|
|
491
|
+
.down(function (e) {
|
|
492
|
+
console.log("Mouse down.");
|
|
493
|
+
})
|
|
494
|
+
.click(function (e) {
|
|
495
|
+
console.log("Click.");
|
|
496
|
+
})
|
|
497
|
+
.wheel(function (e) {
|
|
498
|
+
console.log("Wheel. delta=" + e.deltaY);
|
|
499
|
+
});
|
|
500
|
+
```
|
|
501
|
+
|
|
445
502
|
## Build the package
|
|
446
503
|
|
|
447
504
|
[Compile and build howto](https://github.com/IkarosKappler/plotboilerplate/blob/master/build.md "Compile and build howto")
|
package/changelog.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
- 2022-09-11
|
|
4
|
+
- Added the extended circle-line-intersection demo (because I am stupid and need visual confirmation).
|
|
5
|
+
- 2022-08-23
|
|
6
|
+
- Added the `Circle.lineIntersection(Vertex,Vertex)` function.
|
|
7
|
+
- Added the `Circle.closestPoint(XYCoords)` function.
|
|
8
|
+
- Fixed a type issue in the `draw.polyline` function.
|
|
9
|
+
- Fixed a type issue in the `draw.setConfiguration` function.
|
|
10
|
+
- Fixed a type issue in the `draw.path` function.
|
|
11
|
+
- 2022-08-16
|
|
12
|
+
- MouseHandler: Fixed a bug in the mouse button detection.
|
|
13
|
+
- 2022-08-15
|
|
14
|
+
- Added the `Circle.containsPoint(XYCoords)` function.
|
|
15
|
+
- 2022-08-01
|
|
16
|
+
- Added `title` param to the `PBParams` interface.
|
|
17
|
+
- 2022-07-26
|
|
18
|
+
- Adding `alpha` to the `draw.image(...)` function.
|
|
19
|
+
- 2022-06-02
|
|
20
|
+
- Adding the demo 42 (Hick's Hexagons).
|
|
21
|
+
- 2022-06-01
|
|
22
|
+
- Tweaked the `draw.polyline` function; lineWidth now scales with scale.x.
|
|
23
|
+
- 2022-05-11
|
|
24
|
+
- Adding new demo: raindrops.
|
|
25
|
+
- 2022-05-11
|
|
26
|
+
- Modified the `Color.clone` function by just copying the numeric calues, not re-calculating the whole color.
|
|
27
|
+
- Fixed the `Color.interpolate` function.
|
|
3
28
|
- 2022-03-27
|
|
4
29
|
- Added the `texturedPoly` function to the `DrawLib` interface.
|
|
5
30
|
- Added the `texturedPoly` function to the `drawutils` and `drawutilssvg` class.
|
package/dist/index.esm.js
CHANGED
|
@@ -1472,6 +1472,20 @@ class Bounds {
|
|
|
1472
1472
|
toString() {
|
|
1473
1473
|
return `{ min: ${this.min.toString()}, max : ${this.max.toString()}, width: ${this.width}, height : ${this.height} }`;
|
|
1474
1474
|
}
|
|
1475
|
+
/**
|
|
1476
|
+
* Clone this bounds object (create a deep clone).
|
|
1477
|
+
*
|
|
1478
|
+
* Note: the returned format might change in the future, so please do not
|
|
1479
|
+
* rely on the returned string format.
|
|
1480
|
+
*
|
|
1481
|
+
* @method clone
|
|
1482
|
+
* @instance
|
|
1483
|
+
* @memberof Bounds
|
|
1484
|
+
* @returns {string} Creates a deep clone of this bounds object. The returned object's `min` and `max` instances are `Vertex` instances.
|
|
1485
|
+
*/
|
|
1486
|
+
// clone() {
|
|
1487
|
+
// return new Bounds(new Vertex(this.min.x, this.min.y), new Vertex(this.max.x, this.max.y));
|
|
1488
|
+
// }
|
|
1475
1489
|
/**
|
|
1476
1490
|
* Compute the minimal bounding box for a given set of vertices.
|
|
1477
1491
|
*
|
|
@@ -3931,7 +3945,10 @@ class Line extends VertTuple {
|
|
|
3931
3945
|
* @modified 2021-01-20 Added UID.
|
|
3932
3946
|
* @modified 2022-02-02 Added the `destroy` method.
|
|
3933
3947
|
* @modified 2022-02-02 Cleared the `toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
3934
|
-
* @
|
|
3948
|
+
* @modified 2022-08-15 Added the `containsPoint` function.
|
|
3949
|
+
* @modified 2022-08-23 Added the `lineIntersection` function.
|
|
3950
|
+
* @modified 2022-08-23 Added the `closestPoint` function.
|
|
3951
|
+
* @version 1.4.0
|
|
3935
3952
|
**/
|
|
3936
3953
|
/**
|
|
3937
3954
|
* @classdesc A simple circle: center point and radius.
|
|
@@ -3962,6 +3979,18 @@ class Circle {
|
|
|
3962
3979
|
this.center = center;
|
|
3963
3980
|
this.radius = radius;
|
|
3964
3981
|
}
|
|
3982
|
+
/**
|
|
3983
|
+
* Check if the given circle is fully contained inside this circle.
|
|
3984
|
+
*
|
|
3985
|
+
* @method containsPoint
|
|
3986
|
+
* @param {XYCoords} point - The point to check if it is contained in this circle.
|
|
3987
|
+
* @instance
|
|
3988
|
+
* @memberof Circle
|
|
3989
|
+
* @return {boolean} `true` if the given point is inside this circle.
|
|
3990
|
+
*/
|
|
3991
|
+
containsPoint(point) {
|
|
3992
|
+
return this.center.distance(point) < this.radius;
|
|
3993
|
+
}
|
|
3965
3994
|
/**
|
|
3966
3995
|
* Check if the given circle is fully contained inside this circle.
|
|
3967
3996
|
*
|
|
@@ -4073,6 +4102,71 @@ class Circle {
|
|
|
4073
4102
|
var y4 = p2.y + (h * (p1.x - p0.x)) / d;
|
|
4074
4103
|
return new Line(new Vertex(x3, y3), new Vertex(x4, y4));
|
|
4075
4104
|
}
|
|
4105
|
+
/**
|
|
4106
|
+
* Calculate the intersection points (if exists) with the given infinite line (defined by two points).
|
|
4107
|
+
*
|
|
4108
|
+
* @method lineIntersection
|
|
4109
|
+
* @instance
|
|
4110
|
+
* @memberof Circle
|
|
4111
|
+
* @param {Vertex} a- The first of the two points defining the line.
|
|
4112
|
+
* @param {Vertex} b - The second of the two points defining the line.
|
|
4113
|
+
* @return {Line|null} The intersection points (as a line) or null if this circle does not intersect the line given.
|
|
4114
|
+
**/
|
|
4115
|
+
lineIntersection(a, b) {
|
|
4116
|
+
// Based on the math from
|
|
4117
|
+
// https://mathworld.wolfram.com/Circle-LineIntersection.html
|
|
4118
|
+
const interA = new Vertex();
|
|
4119
|
+
const interB = new Vertex();
|
|
4120
|
+
// First do a transformation, because the calculation is based on a cicle at (0,0)
|
|
4121
|
+
const transA = new Vertex(a).sub(this.center);
|
|
4122
|
+
const transB = new Vertex(b).sub(this.center);
|
|
4123
|
+
const diff = transA.difference(transB);
|
|
4124
|
+
// There is a special case if diff.y=0, where the intersection is not calcuatable.
|
|
4125
|
+
// Use an non-zero epsilon here to approximate this case.
|
|
4126
|
+
// TODO for the future: find a better solution
|
|
4127
|
+
if (Math.abs(diff.y) === 0) {
|
|
4128
|
+
diff.y = 0.000001;
|
|
4129
|
+
}
|
|
4130
|
+
const dist = transA.distance(transB);
|
|
4131
|
+
const det = transA.x * transB.y - transA.y * transB.x;
|
|
4132
|
+
const distSquared = dist * dist;
|
|
4133
|
+
const radiusSquared = this.radius * this.radius;
|
|
4134
|
+
// Check if circle and line have an intersection at all
|
|
4135
|
+
if (radiusSquared * distSquared - det * det < 0) {
|
|
4136
|
+
return null;
|
|
4137
|
+
}
|
|
4138
|
+
const belowSqrt = this.radius * this.radius * dist * dist - det * det;
|
|
4139
|
+
const sqrt = Math.sqrt(belowSqrt);
|
|
4140
|
+
interA.x = (det * diff.y + Math.sign(diff.y) * diff.x * sqrt) / distSquared;
|
|
4141
|
+
interB.x = (det * diff.y - Math.sign(diff.y) * diff.x * sqrt) / distSquared;
|
|
4142
|
+
interA.y = (-det * diff.x + Math.abs(diff.y) * sqrt) / distSquared;
|
|
4143
|
+
interB.y = (-det * diff.x - Math.abs(diff.y) * sqrt) / distSquared;
|
|
4144
|
+
return new Line(interA.add(this.center), interB.add(this.center));
|
|
4145
|
+
// return new Line(interA, interB);
|
|
4146
|
+
}
|
|
4147
|
+
/**
|
|
4148
|
+
* Calculate the closest point on the outline of this circle to the given point.
|
|
4149
|
+
*
|
|
4150
|
+
* @method closestPoint
|
|
4151
|
+
* @instance
|
|
4152
|
+
* @memberof Circle
|
|
4153
|
+
* @param {XYCoords} vert - The point to find the closest circle point for.
|
|
4154
|
+
* @return {Vertex} The closest point on this circle.
|
|
4155
|
+
**/
|
|
4156
|
+
closestPoint(vert) {
|
|
4157
|
+
const lineIntersection = this.lineIntersection(this.center, vert);
|
|
4158
|
+
if (!lineIntersection) {
|
|
4159
|
+
// Note: this case should not happen as a radial from the center always intersect this circle.
|
|
4160
|
+
return new Vertex();
|
|
4161
|
+
}
|
|
4162
|
+
// Return closed of both
|
|
4163
|
+
if (lineIntersection.a.distance(vert) < lineIntersection.b.distance(vert)) {
|
|
4164
|
+
return lineIntersection.a;
|
|
4165
|
+
}
|
|
4166
|
+
else {
|
|
4167
|
+
return lineIntersection.b;
|
|
4168
|
+
}
|
|
4169
|
+
}
|
|
4076
4170
|
/**
|
|
4077
4171
|
* This function should invalidate any installed listeners and invalidate this object.
|
|
4078
4172
|
* After calling this function the object might not hold valid data any more and
|
|
@@ -4228,7 +4322,8 @@ CircleSector.circleSectorUtils = {
|
|
|
4228
4322
|
* @modified 2022-02-03 Added the `cross(...)` function.
|
|
4229
4323
|
* @modified 2022-03-26 Added the private `nodeDefs` and `bufferedNodeDefs` attributes.
|
|
4230
4324
|
* @modified 2022-03-26 Added the `texturedPoly` function to draw textures polygons.
|
|
4231
|
-
* @
|
|
4325
|
+
* @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
|
|
4326
|
+
* @version 1.6.1
|
|
4232
4327
|
**/
|
|
4233
4328
|
const RAD_TO_DEG = 180 / Math.PI;
|
|
4234
4329
|
/**
|
|
@@ -4610,11 +4705,12 @@ class drawutilssvg {
|
|
|
4610
4705
|
* @param {Image} image - The image object to draw.
|
|
4611
4706
|
* @param {Vertex} position - The position to draw the the upper left corner at.
|
|
4612
4707
|
* @param {Vertex} size - The x/y-size to draw the image with.
|
|
4708
|
+
* @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
|
|
4613
4709
|
* @return {void}
|
|
4614
4710
|
* @instance
|
|
4615
4711
|
* @memberof drawutilssvg
|
|
4616
4712
|
**/
|
|
4617
|
-
image(image, position, size) {
|
|
4713
|
+
image(image, position, size, alpha = 1.0) {
|
|
4618
4714
|
const node = this.makeNode("image");
|
|
4619
4715
|
// We need to re-adjust the image if it was not yet fully loaded before.
|
|
4620
4716
|
const setImageSize = (image) => {
|
|
@@ -4624,6 +4720,9 @@ class drawutilssvg {
|
|
|
4624
4720
|
node.setAttribute("width", `${image.naturalWidth * this.scale.x}`);
|
|
4625
4721
|
node.setAttribute("height", `${image.naturalHeight * this.scale.y}`);
|
|
4626
4722
|
node.setAttribute("display", null); // Dislay when loaded
|
|
4723
|
+
// if (alpha) {
|
|
4724
|
+
node.setAttribute("opacity", `${alpha}`);
|
|
4725
|
+
// }
|
|
4627
4726
|
node.setAttribute("transform", `translate(${this._x(position.x)} ${this._y(position.y)}) scale(${ratioX} ${ratioY})`);
|
|
4628
4727
|
}
|
|
4629
4728
|
};
|
|
@@ -5587,7 +5686,12 @@ drawutilssvg.HEAD_XML = [
|
|
|
5587
5686
|
* @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
|
|
5588
5687
|
* @modified 2022-02-03 Added the `cross(...)` function.
|
|
5589
5688
|
* @modified 2022-03-27 Added the `texturedPoly` function.
|
|
5590
|
-
* @
|
|
5689
|
+
* @modified 2022-06-01 Tweaked the `polyline` function; lineWidth now scales with scale.x.
|
|
5690
|
+
* @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
|
|
5691
|
+
* @modified 2022-08-23 Fixed a type issue in the `polyline` function.
|
|
5692
|
+
* @modified 2022-08-23 Fixed a type issue in the `setConfiguration` function.
|
|
5693
|
+
* @modified 2022-08-23 Fixed a type issue in the `path` function.
|
|
5694
|
+
* @version 1.12.3
|
|
5591
5695
|
**/
|
|
5592
5696
|
// Todo: rename this class to Drawutils?
|
|
5593
5697
|
/**
|
|
@@ -5641,7 +5745,7 @@ class drawutils {
|
|
|
5641
5745
|
* @param {DrawLibConfiguration} configuration - The new configuration settings to use for the next render methods.
|
|
5642
5746
|
*/
|
|
5643
5747
|
setConfiguration(configuration) {
|
|
5644
|
-
this.ctx.globalCompositeOperation = configuration.blendMode;
|
|
5748
|
+
this.ctx.globalCompositeOperation = configuration.blendMode || "source-over";
|
|
5645
5749
|
}
|
|
5646
5750
|
/**
|
|
5647
5751
|
* This method shouled be called each time the currently drawn `Drawable` changes.
|
|
@@ -5724,16 +5828,18 @@ class drawutils {
|
|
|
5724
5828
|
* @param {Image} image - The image object to draw.
|
|
5725
5829
|
* @param {Vertex} position - The position to draw the the upper left corner at.
|
|
5726
5830
|
* @param {Vertex} size - The x/y-size to draw the image with.
|
|
5831
|
+
* @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
|
|
5727
5832
|
* @return {void}
|
|
5728
5833
|
* @instance
|
|
5729
5834
|
* @memberof drawutils
|
|
5730
5835
|
**/
|
|
5731
|
-
image(image, position, size) {
|
|
5836
|
+
image(image, position, size, alpha = 1.0) {
|
|
5732
5837
|
if (!image.complete || !image.naturalWidth) {
|
|
5733
5838
|
// Avoid drawing un-unloaded or broken images
|
|
5734
5839
|
return;
|
|
5735
5840
|
}
|
|
5736
5841
|
this.ctx.save();
|
|
5842
|
+
this.ctx.globalAlpha = alpha;
|
|
5737
5843
|
// Note that there is a Safari bug with the 3 or 5 params variant.
|
|
5738
5844
|
// Only the 9-param varaint works.
|
|
5739
5845
|
this.ctx.drawImage(image, 0, 0, image.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
|
|
@@ -6343,11 +6449,12 @@ class drawutils {
|
|
|
6343
6449
|
* @memberof drawutils
|
|
6344
6450
|
*/
|
|
6345
6451
|
polyline(vertices, isOpen, color, lineWidth) {
|
|
6346
|
-
if (vertices.length <= 1)
|
|
6452
|
+
if (vertices.length <= 1) {
|
|
6347
6453
|
return;
|
|
6454
|
+
}
|
|
6348
6455
|
this.ctx.save();
|
|
6349
6456
|
this.ctx.beginPath();
|
|
6350
|
-
this.ctx.lineWidth = lineWidth || 1.0;
|
|
6457
|
+
this.ctx.lineWidth = (lineWidth || 1.0) * this.scale.x;
|
|
6351
6458
|
this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
|
|
6352
6459
|
for (var i = 0; i < vertices.length; i++) {
|
|
6353
6460
|
this.ctx.lineTo(this.offset.x + vertices[i].x * this.scale.x, this.offset.y + vertices[i].y * this.scale.y);
|
|
@@ -6464,14 +6571,20 @@ class drawutils {
|
|
|
6464
6571
|
path(pathData, color, lineWidth, options) {
|
|
6465
6572
|
const d = options && options.inplace ? pathData : drawutilssvg.copyPathData(pathData);
|
|
6466
6573
|
drawutilssvg.transformPathData(d, this.offset, this.scale);
|
|
6467
|
-
|
|
6574
|
+
if (color) {
|
|
6575
|
+
this.ctx.strokeStyle = color;
|
|
6576
|
+
}
|
|
6468
6577
|
this.ctx.lineWidth = lineWidth || 1;
|
|
6469
6578
|
if (this.fillShapes) {
|
|
6470
|
-
|
|
6579
|
+
if (color) {
|
|
6580
|
+
this.ctx.fillStyle = color;
|
|
6581
|
+
}
|
|
6471
6582
|
this.ctx.fill(new Path2D(d.join(" ")));
|
|
6472
6583
|
}
|
|
6473
6584
|
else {
|
|
6474
|
-
|
|
6585
|
+
if (color) {
|
|
6586
|
+
this.ctx.strokeStyle = color;
|
|
6587
|
+
}
|
|
6475
6588
|
this.ctx.stroke(new Path2D(d.join(" ")));
|
|
6476
6589
|
}
|
|
6477
6590
|
}
|
|
@@ -6516,7 +6629,8 @@ drawutils.helpers = {
|
|
|
6516
6629
|
* @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
|
|
6517
6630
|
* @modified 2022-02-03 Added the `cross(...)` function.
|
|
6518
6631
|
* @modified 2022-03-27 Added the `texturedPoly` function.
|
|
6519
|
-
* @
|
|
6632
|
+
* @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
|
|
6633
|
+
* @version 0.0.8
|
|
6520
6634
|
**/
|
|
6521
6635
|
/**
|
|
6522
6636
|
* @classdesc A wrapper class for basic drawing operations. This is the WebGL
|
|
@@ -6706,11 +6820,12 @@ class drawutilsgl {
|
|
|
6706
6820
|
* @param {Image} image - The image object to draw.
|
|
6707
6821
|
* @param {Vertex} position - The position to draw the the upper left corner at.
|
|
6708
6822
|
* @param {Vertex} size - The x/y-size to draw the image with.
|
|
6823
|
+
* @param {number=0.0} alpha - (optional, default=0.0) The transparency (0.0=opaque, 1.0=transparent).
|
|
6709
6824
|
* @return {void}
|
|
6710
6825
|
* @instance
|
|
6711
6826
|
* @memberof drawutils
|
|
6712
6827
|
**/
|
|
6713
|
-
image(image, position, size) {
|
|
6828
|
+
image(image, position, size, alpha = 0.0) {
|
|
6714
6829
|
// NOT YET IMPLEMENTED
|
|
6715
6830
|
}
|
|
6716
6831
|
/**
|
|
@@ -8254,7 +8369,8 @@ KeyHandler.KEY_CODES = {
|
|
|
8254
8369
|
* @modified 2020-10-04 Added extended JSDoc comments.
|
|
8255
8370
|
* @modified 2020-11-25 Added the `isTouchEvent` param.
|
|
8256
8371
|
* @modified 2021-01-10 The mouse handler is now also working with SVGElements.
|
|
8257
|
-
* @
|
|
8372
|
+
* @modified 2022-08-16 Fixed a bug in the mouse button detection.
|
|
8373
|
+
* @version 1.2.1
|
|
8258
8374
|
*
|
|
8259
8375
|
* @file MouseHandler
|
|
8260
8376
|
* @public
|
|
@@ -8344,8 +8460,8 @@ class MouseHandler {
|
|
|
8344
8460
|
// +-------------------------------------------------
|
|
8345
8461
|
this.name = name;
|
|
8346
8462
|
this.element = element;
|
|
8347
|
-
this.mouseDownPos =
|
|
8348
|
-
this.mouseDragPos =
|
|
8463
|
+
this.mouseDownPos = undefined;
|
|
8464
|
+
this.mouseDragPos = undefined;
|
|
8349
8465
|
// this.mousePos = null;
|
|
8350
8466
|
this.mouseButton = -1;
|
|
8351
8467
|
this.listeners = {};
|
|
@@ -8414,26 +8530,27 @@ class MouseHandler {
|
|
|
8414
8530
|
* @memberof MouseHandler
|
|
8415
8531
|
* @instance
|
|
8416
8532
|
* @private
|
|
8417
|
-
* @param {MouseEvent}
|
|
8533
|
+
* @param {MouseEvent} event - The mouse event to get the relative position for.
|
|
8418
8534
|
* @param {string} eventName - The name of the firing event.
|
|
8419
8535
|
* @return {XMouseEvent}
|
|
8420
8536
|
*/
|
|
8421
|
-
mkParams(
|
|
8422
|
-
|
|
8423
|
-
const
|
|
8537
|
+
mkParams(event, eventName) {
|
|
8538
|
+
var _a, _b;
|
|
8539
|
+
const rel = this.relPos(event);
|
|
8540
|
+
const xEvent = event;
|
|
8424
8541
|
xEvent.params = {
|
|
8425
8542
|
element: this.element,
|
|
8426
8543
|
name: eventName,
|
|
8427
8544
|
isTouchEvent: false,
|
|
8428
8545
|
pos: rel,
|
|
8429
|
-
button:
|
|
8430
|
-
leftButton:
|
|
8431
|
-
middleButton:
|
|
8432
|
-
rightButton:
|
|
8433
|
-
mouseDownPos: this.mouseDownPos,
|
|
8434
|
-
draggedFrom: this.mouseDragPos,
|
|
8546
|
+
button: event.button,
|
|
8547
|
+
leftButton: event.button === 0,
|
|
8548
|
+
middleButton: event.button === 1,
|
|
8549
|
+
rightButton: event.button === 2,
|
|
8550
|
+
mouseDownPos: (_a = this.mouseDownPos) !== null && _a !== void 0 ? _a : { x: NaN, y: NaN },
|
|
8551
|
+
draggedFrom: (_b = this.mouseDragPos) !== null && _b !== void 0 ? _b : { x: NaN, y: NaN },
|
|
8435
8552
|
wasDragged: this.mouseDownPos != null && (this.mouseDownPos.x != rel.x || this.mouseDownPos.y != rel.y),
|
|
8436
|
-
dragAmount: this.
|
|
8553
|
+
dragAmount: this.mouseDragPos != null ? { x: rel.x - this.mouseDragPos.x, y: rel.y - this.mouseDragPos.y } : { x: 0, y: 0 }
|
|
8437
8554
|
};
|
|
8438
8555
|
return xEvent;
|
|
8439
8556
|
}
|
|
@@ -9866,7 +9983,8 @@ VEllipseSector.ellipseSectorUtils = {
|
|
|
9866
9983
|
* @modified 2021-03-29 Clearing `currentClassName` and `currentId` after drawing each drawable.
|
|
9867
9984
|
* @modified 2021-04-25 Extending `remove` to accept arrays of drawables.
|
|
9868
9985
|
* @modified 2021-11-16 Adding the `PBText` drawable.
|
|
9869
|
-
* @
|
|
9986
|
+
* @modified 2022-08-01 Added `title` to the params.
|
|
9987
|
+
* @version 1.15.1
|
|
9870
9988
|
*
|
|
9871
9989
|
* @file PlotBoilerplate
|
|
9872
9990
|
* @fileoverview The main class.
|
|
@@ -9959,6 +10077,7 @@ class PlotBoilerplate {
|
|
|
9959
10077
|
* @param {boolean=} [config.enableGL=false] - Indicates if the application should use the experimental WebGL features (not recommended).
|
|
9960
10078
|
* @param {boolean=} [config.enableSVGExport=true] - Indicates if the SVG export should be enabled (default is true).
|
|
9961
10079
|
* Note that changes from the postDraw hook might not be visible in the export.
|
|
10080
|
+
* @param {string=} [config.title=null] - Specify any hover tile here. It will be attached as a `title` attribute to the most elevated element.
|
|
9962
10081
|
*/
|
|
9963
10082
|
constructor(config) {
|
|
9964
10083
|
/**
|
|
@@ -10174,6 +10293,11 @@ class PlotBoilerplate {
|
|
|
10174
10293
|
else {
|
|
10175
10294
|
throw "Element is neither a canvas nor an svg element.";
|
|
10176
10295
|
}
|
|
10296
|
+
// At this point the event cacher element is deinfed and located at highest elevation.
|
|
10297
|
+
// Set `title` attribut?
|
|
10298
|
+
if (config.title) {
|
|
10299
|
+
this.eventCatcher.setAttribute("title", config.title);
|
|
10300
|
+
}
|
|
10177
10301
|
this.draw.scale.set(this.config.scaleX, this.config.scaleY);
|
|
10178
10302
|
this.fill.scale.set(this.config.scaleX, this.config.scaleY);
|
|
10179
10303
|
this.vertices = [];
|