plotboilerplate 1.17.1 → 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 +12 -3
- package/dist/index.esm.js +112 -21
- 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 +112 -21
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +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/draw.d.ts +4 -1
- package/src/cjs/draw.js +15 -6
- package/src/cjs/draw.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/draw.d.ts +4 -1
- package/src/esm/draw.js +15 -6
- package/src/esm/draw.js.map +1 -1
- package/src/ts/Circle.ts +92 -2
- package/src/ts/MouseHandler.ts +16 -15
- package/src/ts/draw.ts +15 -6
package/dist/plotboilerplate.js
CHANGED
|
@@ -1810,7 +1810,10 @@ exports.Bounds = Bounds;
|
|
|
1810
1810
|
* @modified 2021-01-20 Added UID.
|
|
1811
1811
|
* @modified 2022-02-02 Added the `destroy` method.
|
|
1812
1812
|
* @modified 2022-02-02 Cleared the `toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
1813
|
-
* @
|
|
1813
|
+
* @modified 2022-08-15 Added the `containsPoint` function.
|
|
1814
|
+
* @modified 2022-08-23 Added the `lineIntersection` function.
|
|
1815
|
+
* @modified 2022-08-23 Added the `closestPoint` function.
|
|
1816
|
+
* @version 1.4.0
|
|
1814
1817
|
**/
|
|
1815
1818
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1816
1819
|
exports.Circle = void 0;
|
|
@@ -1847,6 +1850,18 @@ var Circle = /** @class */ (function () {
|
|
|
1847
1850
|
this.center = center;
|
|
1848
1851
|
this.radius = radius;
|
|
1849
1852
|
}
|
|
1853
|
+
/**
|
|
1854
|
+
* Check if the given circle is fully contained inside this circle.
|
|
1855
|
+
*
|
|
1856
|
+
* @method containsPoint
|
|
1857
|
+
* @param {XYCoords} point - The point to check if it is contained in this circle.
|
|
1858
|
+
* @instance
|
|
1859
|
+
* @memberof Circle
|
|
1860
|
+
* @return {boolean} `true` if the given point is inside this circle.
|
|
1861
|
+
*/
|
|
1862
|
+
Circle.prototype.containsPoint = function (point) {
|
|
1863
|
+
return this.center.distance(point) < this.radius;
|
|
1864
|
+
};
|
|
1850
1865
|
/**
|
|
1851
1866
|
* Check if the given circle is fully contained inside this circle.
|
|
1852
1867
|
*
|
|
@@ -1958,6 +1973,71 @@ var Circle = /** @class */ (function () {
|
|
|
1958
1973
|
var y4 = p2.y + (h * (p1.x - p0.x)) / d;
|
|
1959
1974
|
return new Line_1.Line(new Vertex_1.Vertex(x3, y3), new Vertex_1.Vertex(x4, y4));
|
|
1960
1975
|
};
|
|
1976
|
+
/**
|
|
1977
|
+
* Calculate the intersection points (if exists) with the given infinite line (defined by two points).
|
|
1978
|
+
*
|
|
1979
|
+
* @method lineIntersection
|
|
1980
|
+
* @instance
|
|
1981
|
+
* @memberof Circle
|
|
1982
|
+
* @param {Vertex} a- The first of the two points defining the line.
|
|
1983
|
+
* @param {Vertex} b - The second of the two points defining the line.
|
|
1984
|
+
* @return {Line|null} The intersection points (as a line) or null if this circle does not intersect the line given.
|
|
1985
|
+
**/
|
|
1986
|
+
Circle.prototype.lineIntersection = function (a, b) {
|
|
1987
|
+
// Based on the math from
|
|
1988
|
+
// https://mathworld.wolfram.com/Circle-LineIntersection.html
|
|
1989
|
+
var interA = new Vertex_1.Vertex();
|
|
1990
|
+
var interB = new Vertex_1.Vertex();
|
|
1991
|
+
// First do a transformation, because the calculation is based on a cicle at (0,0)
|
|
1992
|
+
var transA = new Vertex_1.Vertex(a).sub(this.center);
|
|
1993
|
+
var transB = new Vertex_1.Vertex(b).sub(this.center);
|
|
1994
|
+
var diff = transA.difference(transB);
|
|
1995
|
+
// There is a special case if diff.y=0, where the intersection is not calcuatable.
|
|
1996
|
+
// Use an non-zero epsilon here to approximate this case.
|
|
1997
|
+
// TODO for the future: find a better solution
|
|
1998
|
+
if (Math.abs(diff.y) === 0) {
|
|
1999
|
+
diff.y = 0.000001;
|
|
2000
|
+
}
|
|
2001
|
+
var dist = transA.distance(transB);
|
|
2002
|
+
var det = transA.x * transB.y - transA.y * transB.x;
|
|
2003
|
+
var distSquared = dist * dist;
|
|
2004
|
+
var radiusSquared = this.radius * this.radius;
|
|
2005
|
+
// Check if circle and line have an intersection at all
|
|
2006
|
+
if (radiusSquared * distSquared - det * det < 0) {
|
|
2007
|
+
return null;
|
|
2008
|
+
}
|
|
2009
|
+
var belowSqrt = this.radius * this.radius * dist * dist - det * det;
|
|
2010
|
+
var sqrt = Math.sqrt(belowSqrt);
|
|
2011
|
+
interA.x = (det * diff.y + Math.sign(diff.y) * diff.x * sqrt) / distSquared;
|
|
2012
|
+
interB.x = (det * diff.y - Math.sign(diff.y) * diff.x * sqrt) / distSquared;
|
|
2013
|
+
interA.y = (-det * diff.x + Math.abs(diff.y) * sqrt) / distSquared;
|
|
2014
|
+
interB.y = (-det * diff.x - Math.abs(diff.y) * sqrt) / distSquared;
|
|
2015
|
+
return new Line_1.Line(interA.add(this.center), interB.add(this.center));
|
|
2016
|
+
// return new Line(interA, interB);
|
|
2017
|
+
};
|
|
2018
|
+
/**
|
|
2019
|
+
* Calculate the closest point on the outline of this circle to the given point.
|
|
2020
|
+
*
|
|
2021
|
+
* @method closestPoint
|
|
2022
|
+
* @instance
|
|
2023
|
+
* @memberof Circle
|
|
2024
|
+
* @param {XYCoords} vert - The point to find the closest circle point for.
|
|
2025
|
+
* @return {Vertex} The closest point on this circle.
|
|
2026
|
+
**/
|
|
2027
|
+
Circle.prototype.closestPoint = function (vert) {
|
|
2028
|
+
var lineIntersection = this.lineIntersection(this.center, vert);
|
|
2029
|
+
if (!lineIntersection) {
|
|
2030
|
+
// Note: this case should not happen as a radial from the center always intersect this circle.
|
|
2031
|
+
return new Vertex_1.Vertex();
|
|
2032
|
+
}
|
|
2033
|
+
// Return closed of both
|
|
2034
|
+
if (lineIntersection.a.distance(vert) < lineIntersection.b.distance(vert)) {
|
|
2035
|
+
return lineIntersection.a;
|
|
2036
|
+
}
|
|
2037
|
+
else {
|
|
2038
|
+
return lineIntersection.b;
|
|
2039
|
+
}
|
|
2040
|
+
};
|
|
1961
2041
|
/**
|
|
1962
2042
|
* This function should invalidate any installed listeners and invalidate this object.
|
|
1963
2043
|
* After calling this function the object might not hold valid data any more and
|
|
@@ -3437,7 +3517,8 @@ exports.Line = Line;
|
|
|
3437
3517
|
* @modified 2020-10-04 Added extended JSDoc comments.
|
|
3438
3518
|
* @modified 2020-11-25 Added the `isTouchEvent` param.
|
|
3439
3519
|
* @modified 2021-01-10 The mouse handler is now also working with SVGElements.
|
|
3440
|
-
* @
|
|
3520
|
+
* @modified 2022-08-16 Fixed a bug in the mouse button detection.
|
|
3521
|
+
* @version 1.2.1
|
|
3441
3522
|
*
|
|
3442
3523
|
* @file MouseHandler
|
|
3443
3524
|
* @public
|
|
@@ -3554,8 +3635,8 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3554
3635
|
// +-------------------------------------------------
|
|
3555
3636
|
this.name = name;
|
|
3556
3637
|
this.element = element;
|
|
3557
|
-
this.mouseDownPos =
|
|
3558
|
-
this.mouseDragPos =
|
|
3638
|
+
this.mouseDownPos = undefined;
|
|
3639
|
+
this.mouseDragPos = undefined;
|
|
3559
3640
|
// this.mousePos = null;
|
|
3560
3641
|
this.mouseButton = -1;
|
|
3561
3642
|
this.listeners = {};
|
|
@@ -3624,26 +3705,27 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3624
3705
|
* @memberof MouseHandler
|
|
3625
3706
|
* @instance
|
|
3626
3707
|
* @private
|
|
3627
|
-
* @param {MouseEvent}
|
|
3708
|
+
* @param {MouseEvent} event - The mouse event to get the relative position for.
|
|
3628
3709
|
* @param {string} eventName - The name of the firing event.
|
|
3629
3710
|
* @return {XMouseEvent}
|
|
3630
3711
|
*/
|
|
3631
|
-
MouseHandler.prototype.mkParams = function (
|
|
3632
|
-
var
|
|
3633
|
-
var
|
|
3712
|
+
MouseHandler.prototype.mkParams = function (event, eventName) {
|
|
3713
|
+
var _a, _b;
|
|
3714
|
+
var rel = this.relPos(event);
|
|
3715
|
+
var xEvent = event;
|
|
3634
3716
|
xEvent.params = {
|
|
3635
3717
|
element: this.element,
|
|
3636
3718
|
name: eventName,
|
|
3637
3719
|
isTouchEvent: false,
|
|
3638
3720
|
pos: rel,
|
|
3639
|
-
button:
|
|
3640
|
-
leftButton:
|
|
3641
|
-
middleButton:
|
|
3642
|
-
rightButton:
|
|
3643
|
-
mouseDownPos: this.mouseDownPos,
|
|
3644
|
-
draggedFrom: this.mouseDragPos,
|
|
3721
|
+
button: event.button,
|
|
3722
|
+
leftButton: event.button === 0,
|
|
3723
|
+
middleButton: event.button === 1,
|
|
3724
|
+
rightButton: event.button === 2,
|
|
3725
|
+
mouseDownPos: (_a = this.mouseDownPos) !== null && _a !== void 0 ? _a : { x: NaN, y: NaN },
|
|
3726
|
+
draggedFrom: (_b = this.mouseDragPos) !== null && _b !== void 0 ? _b : { x: NaN, y: NaN },
|
|
3645
3727
|
wasDragged: this.mouseDownPos != null && (this.mouseDownPos.x != rel.x || this.mouseDownPos.y != rel.y),
|
|
3646
|
-
dragAmount: this.
|
|
3728
|
+
dragAmount: this.mouseDragPos != null ? { x: rel.x - this.mouseDragPos.x, y: rel.y - this.mouseDragPos.y } : { x: 0, y: 0 }
|
|
3647
3729
|
};
|
|
3648
3730
|
return xEvent;
|
|
3649
3731
|
};
|
|
@@ -9202,7 +9284,10 @@ exports.VertexListeners = VertexListeners;
|
|
|
9202
9284
|
* @modified 2022-03-27 Added the `texturedPoly` function.
|
|
9203
9285
|
* @modified 2022-06-01 Tweaked the `polyline` function; lineWidth now scales with scale.x.
|
|
9204
9286
|
* @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
|
|
9205
|
-
* @
|
|
9287
|
+
* @modified 2022-08-23 Fixed a type issue in the `polyline` function.
|
|
9288
|
+
* @modified 2022-08-23 Fixed a type issue in the `setConfiguration` function.
|
|
9289
|
+
* @modified 2022-08-23 Fixed a type issue in the `path` function.
|
|
9290
|
+
* @version 1.12.3
|
|
9206
9291
|
**/
|
|
9207
9292
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
9208
9293
|
exports.drawutils = void 0;
|
|
@@ -9261,7 +9346,7 @@ var drawutils = /** @class */ (function () {
|
|
|
9261
9346
|
* @param {DrawLibConfiguration} configuration - The new configuration settings to use for the next render methods.
|
|
9262
9347
|
*/
|
|
9263
9348
|
drawutils.prototype.setConfiguration = function (configuration) {
|
|
9264
|
-
this.ctx.globalCompositeOperation = configuration.blendMode;
|
|
9349
|
+
this.ctx.globalCompositeOperation = configuration.blendMode || "source-over";
|
|
9265
9350
|
};
|
|
9266
9351
|
/**
|
|
9267
9352
|
* This method shouled be called each time the currently drawn `Drawable` changes.
|
|
@@ -9972,7 +10057,7 @@ var drawutils = /** @class */ (function () {
|
|
|
9972
10057
|
}
|
|
9973
10058
|
this.ctx.save();
|
|
9974
10059
|
this.ctx.beginPath();
|
|
9975
|
-
this.ctx.lineWidth = lineWidth * this.scale.x
|
|
10060
|
+
this.ctx.lineWidth = (lineWidth || 1.0) * this.scale.x;
|
|
9976
10061
|
this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
|
|
9977
10062
|
for (var i = 0; i < vertices.length; i++) {
|
|
9978
10063
|
this.ctx.lineTo(this.offset.x + vertices[i].x * this.scale.x, this.offset.y + vertices[i].y * this.scale.y);
|
|
@@ -10089,14 +10174,20 @@ var drawutils = /** @class */ (function () {
|
|
|
10089
10174
|
drawutils.prototype.path = function (pathData, color, lineWidth, options) {
|
|
10090
10175
|
var d = options && options.inplace ? pathData : drawutilssvg_1.drawutilssvg.copyPathData(pathData);
|
|
10091
10176
|
drawutilssvg_1.drawutilssvg.transformPathData(d, this.offset, this.scale);
|
|
10092
|
-
|
|
10177
|
+
if (color) {
|
|
10178
|
+
this.ctx.strokeStyle = color;
|
|
10179
|
+
}
|
|
10093
10180
|
this.ctx.lineWidth = lineWidth || 1;
|
|
10094
10181
|
if (this.fillShapes) {
|
|
10095
|
-
|
|
10182
|
+
if (color) {
|
|
10183
|
+
this.ctx.fillStyle = color;
|
|
10184
|
+
}
|
|
10096
10185
|
this.ctx.fill(new Path2D(d.join(" ")));
|
|
10097
10186
|
}
|
|
10098
10187
|
else {
|
|
10099
|
-
|
|
10188
|
+
if (color) {
|
|
10189
|
+
this.ctx.strokeStyle = color;
|
|
10190
|
+
}
|
|
10100
10191
|
this.ctx.stroke(new Path2D(d.join(" ")));
|
|
10101
10192
|
}
|
|
10102
10193
|
};
|