plotboilerplate 1.18.0 → 1.19.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/dist/index.esm.js +166 -39
- 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 +164 -37
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/Bounds.d.ts +11 -1
- package/src/cjs/Bounds.js +13 -1
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +20 -3
- package/src/cjs/CubicBezierCurve.js +25 -2
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Line.d.ts +46 -4
- package/src/cjs/Line.js +60 -3
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +4 -2
- package/src/cjs/PlotBoilerplate.js +44 -28
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.js +1 -1
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Vector.d.ts +14 -3
- package/src/cjs/Vector.js +21 -2
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/interfaces/additionals.d.ts +95 -0
- package/src/cjs/interfaces/additionals.js +3 -0
- package/src/cjs/interfaces/additionals.js.map +1 -0
- package/src/cjs/interfaces/core.d.ts +4 -0
- package/src/cjs/interfaces/core.js +1 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/interfaces/index.d.ts +1 -0
- package/src/cjs/interfaces/index.js +1 -0
- package/src/cjs/interfaces/index.js.map +1 -1
- package/src/cjs/utils/algorithms/arrayShuffle.d.ts +8 -0
- package/src/cjs/utils/algorithms/arrayShuffle.js +15 -0
- package/src/cjs/utils/algorithms/arrayShuffle.js.map +1 -0
- package/src/cjs/utils/algorithms/detectPaths.d.ts +20 -0
- package/src/cjs/utils/algorithms/detectPaths.js +169 -0
- package/src/cjs/utils/algorithms/detectPaths.js.map +1 -0
- package/src/cjs/utils/datastructures/GenericPath.d.ts +75 -0
- package/src/cjs/utils/datastructures/GenericPath.js +105 -0
- package/src/cjs/utils/datastructures/GenericPath.js.map +1 -0
- package/src/cjs/utils/datastructures/GirihTile.d.ts +1 -1
- package/src/esm/Bounds.d.ts +11 -1
- package/src/esm/Bounds.js +13 -1
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +20 -3
- package/src/esm/CubicBezierCurve.js +25 -2
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Line.d.ts +46 -4
- package/src/esm/Line.js +60 -3
- package/src/esm/Line.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +4 -2
- package/src/esm/PlotBoilerplate.js +44 -28
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.js +1 -1
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Vector.d.ts +13 -2
- package/src/esm/Vector.js +23 -4
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/interfaces/additionals.d.ts +95 -0
- package/src/esm/interfaces/additionals.js +2 -0
- package/src/esm/interfaces/additionals.js.map +1 -0
- package/src/esm/interfaces/core.d.ts +4 -0
- package/src/esm/interfaces/core.js +1 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/interfaces/index.d.ts +1 -0
- package/src/esm/interfaces/index.js +1 -0
- package/src/esm/interfaces/index.js.map +1 -1
- package/src/esm/utils/algorithms/arrayShuffle.d.ts +8 -0
- package/src/esm/utils/algorithms/arrayShuffle.js +11 -0
- package/src/esm/utils/algorithms/arrayShuffle.js.map +1 -0
- package/src/esm/utils/algorithms/detectPaths.d.ts +20 -0
- package/src/esm/utils/algorithms/detectPaths.js +165 -0
- package/src/esm/utils/algorithms/detectPaths.js.map +1 -0
- package/src/esm/utils/datastructures/GenericPath.d.ts +75 -0
- package/src/esm/utils/datastructures/GenericPath.js +100 -0
- package/src/esm/utils/datastructures/GenericPath.js.map +1 -0
- package/src/esm/utils/datastructures/GirihTile.d.ts +1 -1
- package/src/ts/Bounds.ts +14 -1
- package/src/ts/CubicBezierCurve.ts +29 -4
- package/src/ts/Line.ts +70 -6
- package/src/ts/PlotBoilerplate.ts +47 -32
- package/src/ts/Polygon.ts +1 -1
- package/src/ts/Vector.ts +24 -4
- package/src/ts/interfaces/additionals.ts +105 -0
- package/src/ts/interfaces/core.ts +2 -0
- package/src/ts/interfaces/index.ts +1 -0
- package/src/ts/utils/algorithms/arrayShuffle.ts +11 -0
- package/src/ts/utils/algorithms/detectPaths.ts +195 -0
- package/src/ts/utils/datastructures/GenericPath.ts +113 -0
- package/src/ts/utils/datastructures/GirihTile.ts +1 -1
- package/changelog.md +0 -731
package/dist/index.esm.js
CHANGED
|
@@ -982,7 +982,7 @@ class Polygon {
|
|
|
982
982
|
if (typeof vertices == "undefined")
|
|
983
983
|
vertices = [];
|
|
984
984
|
this.vertices = vertices;
|
|
985
|
-
this.isOpen = isOpen;
|
|
985
|
+
this.isOpen = isOpen || false;
|
|
986
986
|
}
|
|
987
987
|
/**
|
|
988
988
|
* Add a vertex to the end of the `vertices` array.
|
|
@@ -1412,7 +1412,8 @@ Polygon.utils = {
|
|
|
1412
1412
|
* @modified 2021-02-02 Added the `toPolygon` method.
|
|
1413
1413
|
* @modified 2021-06-21 (mid-summer) Added `getCenter` method.
|
|
1414
1414
|
* @modified 2022-02-01 Added the `toString` function.
|
|
1415
|
-
* @
|
|
1415
|
+
* @modified 2022-10-09 Added the `fromDimension` function.
|
|
1416
|
+
* @version 1.5.0
|
|
1416
1417
|
**/
|
|
1417
1418
|
/**
|
|
1418
1419
|
* @classdesc A bounds class with min and max values. Implementing IBounds.
|
|
@@ -1514,6 +1515,17 @@ class Bounds {
|
|
|
1514
1515
|
}
|
|
1515
1516
|
return new Bounds(new Vertex(xMin, yMin), new Vertex(xMax, yMax));
|
|
1516
1517
|
}
|
|
1518
|
+
/**
|
|
1519
|
+
* Create a new `Bounds` instance just from `width` and `height`, located at (0,0) or the optionally given origin.
|
|
1520
|
+
*
|
|
1521
|
+
* @param {number} width - The width of the bounds
|
|
1522
|
+
* @param {number} height - The height of the bounds
|
|
1523
|
+
* @param {XYCoords={x:0,y:0}} origin - [optional] A origin to locate the new Bounds object at.
|
|
1524
|
+
* @returns {Bounds} A new `Bounds` instance width given width and height, located at (0,0) or the given origin..
|
|
1525
|
+
*/
|
|
1526
|
+
static fromDimension(width, height, origin) {
|
|
1527
|
+
return new Bounds(origin !== null && origin !== void 0 ? origin : { x: 0, y: 0 }, { x: (origin ? origin.x : 0) + width, y: (origin ? origin.y : 0) + height });
|
|
1528
|
+
}
|
|
1517
1529
|
} // END class bounds
|
|
1518
1530
|
|
|
1519
1531
|
/**
|
|
@@ -1831,7 +1843,8 @@ VertTuple.vtutils = {
|
|
|
1831
1843
|
* @modified 2021-01-20 Added UID.
|
|
1832
1844
|
* @modified 2022-02-02 Added the `destroy` method.
|
|
1833
1845
|
* @modified 2022-02-02 Cleared the `Vector.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
1834
|
-
* @
|
|
1846
|
+
* @modified 2022-10-25 Added the `getOrthogonal` method.
|
|
1847
|
+
* @version 1.5.0
|
|
1835
1848
|
*
|
|
1836
1849
|
* @file Vector
|
|
1837
1850
|
* @public
|
|
@@ -1877,7 +1890,7 @@ class Vector extends VertTuple {
|
|
|
1877
1890
|
return v;
|
|
1878
1891
|
}
|
|
1879
1892
|
/**
|
|
1880
|
-
* The inverse of a vector is a vector
|
|
1893
|
+
* The inverse of a vector is a vector with the same magnitude but oppose direction.
|
|
1881
1894
|
*
|
|
1882
1895
|
* Please not that the origin of this vector changes here: a->b becomes b->a.
|
|
1883
1896
|
*
|
|
@@ -1923,6 +1936,24 @@ class Vector extends VertTuple {
|
|
|
1923
1936
|
// if we cast these lines infinitely in both directions, they intersect here:
|
|
1924
1937
|
return new Vertex(this.a.x + a * (this.b.x - this.a.x), this.a.y + a * (this.b.y - this.a.y));
|
|
1925
1938
|
}
|
|
1939
|
+
/**
|
|
1940
|
+
* Get the orthogonal "vector" of this vector (rotated by 90° clockwise).
|
|
1941
|
+
*
|
|
1942
|
+
* @name getOrthogonal
|
|
1943
|
+
* @method getOrthogonal
|
|
1944
|
+
* @return {Vector} A new vector with the same length that stands on this vector's point a.
|
|
1945
|
+
* @instance
|
|
1946
|
+
* @memberof Vector
|
|
1947
|
+
**/
|
|
1948
|
+
getOrthogonal() {
|
|
1949
|
+
// Orthogonal of vector (0,0)->(x,y) is (0,0)->(-y,x)
|
|
1950
|
+
const linePoint = this.a.clone();
|
|
1951
|
+
const startPoint = this.b.clone().sub(this.a);
|
|
1952
|
+
const tmp = startPoint.x;
|
|
1953
|
+
startPoint.x = -startPoint.y;
|
|
1954
|
+
startPoint.y = tmp;
|
|
1955
|
+
return new Vector(linePoint, startPoint.add(this.a));
|
|
1956
|
+
}
|
|
1926
1957
|
}
|
|
1927
1958
|
Vector.utils = {
|
|
1928
1959
|
/**
|
|
@@ -1951,8 +1982,8 @@ Vector.utils = {
|
|
|
1951
1982
|
* @param {number} scaleY - the vertical scaling during draw.
|
|
1952
1983
|
**/
|
|
1953
1984
|
buildArrowHead: (zA, zB, headlen, scaleX, scaleY) => {
|
|
1954
|
-
|
|
1955
|
-
|
|
1985
|
+
const angle = Math.atan2((zB.y - zA.y) * scaleY, (zB.x - zA.x) * scaleX);
|
|
1986
|
+
const vertices = [];
|
|
1956
1987
|
vertices.push(new Vertex(zB.x * scaleX - headlen * Math.cos(angle), zB.y * scaleY - headlen * Math.sin(angle)));
|
|
1957
1988
|
vertices.push(new Vertex(zB.x * scaleX - headlen * 1.35 * Math.cos(angle - Math.PI / 8), zB.y * scaleY - headlen * 1.35 * Math.sin(angle - Math.PI / 8)));
|
|
1958
1989
|
vertices.push(new Vertex(zB.x * scaleX, zB.y * scaleY));
|
|
@@ -1983,7 +2014,8 @@ Vector.utils = {
|
|
|
1983
2014
|
* @modified 2021-01-20 Added UID.
|
|
1984
2015
|
* @modified 2022-02-02 Added the `destroy` method.
|
|
1985
2016
|
* @modified 2022-02-02 Cleared the `toSVGPathData` function (deprecated). Use `drawutilssvg` instead.
|
|
1986
|
-
* @
|
|
2017
|
+
* @modified 2022-10-17 The `CubicBezierCurve` class now implements the new `PathSegment` interface.
|
|
2018
|
+
* @version 2.7.1
|
|
1987
2019
|
*
|
|
1988
2020
|
* @file CubicBezierCurve
|
|
1989
2021
|
* @public
|
|
@@ -2029,7 +2061,7 @@ class CubicBezierCurve {
|
|
|
2029
2061
|
// An array of floats
|
|
2030
2062
|
this.segmentLengths = [];
|
|
2031
2063
|
// float
|
|
2032
|
-
this.arcLength = null;
|
|
2064
|
+
// this.arcLength = null;
|
|
2033
2065
|
this.updateArcLengths();
|
|
2034
2066
|
}
|
|
2035
2067
|
/**
|
|
@@ -2461,6 +2493,28 @@ class CubicBezierCurve {
|
|
|
2461
2493
|
clone() {
|
|
2462
2494
|
return new CubicBezierCurve(this.getStartPoint().clone(), this.getEndPoint().clone(), this.getStartControlPoint().clone(), this.getEndControlPoint().clone());
|
|
2463
2495
|
}
|
|
2496
|
+
//---BEGIN PathSegment-------------------------
|
|
2497
|
+
/**
|
|
2498
|
+
* Get the tangent's end point at the start point of this segment.
|
|
2499
|
+
*
|
|
2500
|
+
* @method getStartTangent
|
|
2501
|
+
* @memberof PathSegment
|
|
2502
|
+
* @return {Vertex} The end point of the starting point's tangent.
|
|
2503
|
+
*/
|
|
2504
|
+
getStartTangent() {
|
|
2505
|
+
return this.startControlPoint;
|
|
2506
|
+
}
|
|
2507
|
+
/**
|
|
2508
|
+
* Get the tangent's end point at the end point of this segment.
|
|
2509
|
+
*
|
|
2510
|
+
* @method getEndTangent
|
|
2511
|
+
* @memberof PathSegment
|
|
2512
|
+
* @return {Vertex} The end point of the ending point's tangent.
|
|
2513
|
+
*/
|
|
2514
|
+
getEndTangent() {
|
|
2515
|
+
return this.endControlPoint;
|
|
2516
|
+
}
|
|
2517
|
+
//---END PathSegment-------------------------
|
|
2464
2518
|
/**
|
|
2465
2519
|
* Check if this and the specified curve are equal.<br>
|
|
2466
2520
|
* <br>
|
|
@@ -3874,7 +3928,9 @@ BezierPath.END_POINT = 3;
|
|
|
3874
3928
|
* @modified 2020-03-23 Ported to Typescript from JS.
|
|
3875
3929
|
* @modified 2020-12-04 The `intersection` function returns undefined if both lines are parallel.
|
|
3876
3930
|
* @modified 2022-02-02 Added the `destroy` method.
|
|
3877
|
-
* @
|
|
3931
|
+
* @modified 2022-10-09 Changed the actual return value of the `intersection` function to null (was undefined before).
|
|
3932
|
+
* @modified 2022-10-17 Adding these methods from the `PathSegment` interface: getStartPoint, getEndPoint, revert.
|
|
3933
|
+
* @version 2.3.0
|
|
3878
3934
|
*
|
|
3879
3935
|
* @file Line
|
|
3880
3936
|
* @public
|
|
@@ -3915,8 +3971,9 @@ class Line extends VertTuple {
|
|
|
3915
3971
|
// !!! DO NOT MOVE TO VertTuple
|
|
3916
3972
|
intersection(line) {
|
|
3917
3973
|
const denominator = this.denominator(line);
|
|
3918
|
-
if (denominator == 0)
|
|
3974
|
+
if (denominator == 0) {
|
|
3919
3975
|
return null;
|
|
3976
|
+
}
|
|
3920
3977
|
let a = this.a.y - line.a.y;
|
|
3921
3978
|
let b = this.a.x - line.a.x;
|
|
3922
3979
|
const numerator1 = (line.b.x - line.a.x) * a - (line.b.y - line.a.y) * b;
|
|
@@ -3927,11 +3984,65 @@ class Line extends VertTuple {
|
|
|
3927
3984
|
const x = this.a.x + a * (this.b.x - this.a.x);
|
|
3928
3985
|
const y = this.a.y + a * (this.b.y - this.a.y);
|
|
3929
3986
|
if (isNaN(a) || isNaN(x) || isNaN(y)) {
|
|
3930
|
-
return
|
|
3987
|
+
return null;
|
|
3931
3988
|
}
|
|
3932
3989
|
// if we cast these lines infinitely in both directions, they intersect here:
|
|
3933
3990
|
return new Vertex(x, y);
|
|
3934
3991
|
}
|
|
3992
|
+
//--- Implement PathSegment ---
|
|
3993
|
+
/**
|
|
3994
|
+
* Get the start point of this path segment.
|
|
3995
|
+
*
|
|
3996
|
+
* @method getStartPoint
|
|
3997
|
+
* @memberof PathSegment
|
|
3998
|
+
* @return {Vertex} The start point of this path segment.
|
|
3999
|
+
*/
|
|
4000
|
+
getStartPoint() {
|
|
4001
|
+
return this.a;
|
|
4002
|
+
}
|
|
4003
|
+
/**
|
|
4004
|
+
* Get the end point of this path segment.
|
|
4005
|
+
*
|
|
4006
|
+
* @method getEndPoint
|
|
4007
|
+
* @memberof PathSegment
|
|
4008
|
+
* @return {Vertex} The end point of this path segment.
|
|
4009
|
+
*/
|
|
4010
|
+
getEndPoint() {
|
|
4011
|
+
return this.b;
|
|
4012
|
+
}
|
|
4013
|
+
/**
|
|
4014
|
+
* Get the tangent's end point at the start point of this segment.
|
|
4015
|
+
*
|
|
4016
|
+
* @method getStartTangent
|
|
4017
|
+
* @memberof PathSegment
|
|
4018
|
+
* @return {Vertex} The end point of the starting point's tangent.
|
|
4019
|
+
*/
|
|
4020
|
+
getStartTangent() {
|
|
4021
|
+
return this.b;
|
|
4022
|
+
}
|
|
4023
|
+
/**
|
|
4024
|
+
* Get the tangent's end point at the end point of this segment.
|
|
4025
|
+
*
|
|
4026
|
+
* @method getEndTangent
|
|
4027
|
+
* @memberof PathSegment
|
|
4028
|
+
* @return {Vertex} The end point of the ending point's tangent.
|
|
4029
|
+
*/
|
|
4030
|
+
getEndTangent() {
|
|
4031
|
+
return this.a;
|
|
4032
|
+
}
|
|
4033
|
+
/**
|
|
4034
|
+
* Inverse this path segment (in-place) and return this same instance (useful for chaining).
|
|
4035
|
+
*
|
|
4036
|
+
* @method reverse
|
|
4037
|
+
* @memberof PathSegment
|
|
4038
|
+
* @return {PathSegment} This path segment instance (for chaining).
|
|
4039
|
+
*/
|
|
4040
|
+
reverse() {
|
|
4041
|
+
var tmp = this.a;
|
|
4042
|
+
this.a = this.b;
|
|
4043
|
+
this.b = tmp;
|
|
4044
|
+
return this;
|
|
4045
|
+
}
|
|
3935
4046
|
}
|
|
3936
4047
|
|
|
3937
4048
|
/**
|
|
@@ -9984,7 +10095,9 @@ VEllipseSector.ellipseSectorUtils = {
|
|
|
9984
10095
|
* @modified 2021-04-25 Extending `remove` to accept arrays of drawables.
|
|
9985
10096
|
* @modified 2021-11-16 Adding the `PBText` drawable.
|
|
9986
10097
|
* @modified 2022-08-01 Added `title` to the params.
|
|
9987
|
-
* @
|
|
10098
|
+
* @modified 2022-10-25 Added the `origin` to the default draw config.
|
|
10099
|
+
* @modified 2022-11-06 Adding an XML declaration to the SVG export routine.
|
|
10100
|
+
* @version 1.16.0
|
|
9988
10101
|
*
|
|
9989
10102
|
* @file PlotBoilerplate
|
|
9990
10103
|
* @fileoverview The main class.
|
|
@@ -10080,6 +10193,7 @@ class PlotBoilerplate {
|
|
|
10080
10193
|
* @param {string=} [config.title=null] - Specify any hover tile here. It will be attached as a `title` attribute to the most elevated element.
|
|
10081
10194
|
*/
|
|
10082
10195
|
constructor(config) {
|
|
10196
|
+
var _a, _b;
|
|
10083
10197
|
/**
|
|
10084
10198
|
* A discrete timestamp to identify single render cycles.
|
|
10085
10199
|
* Note that using system time milliseconds is not a safe way to identify render frames, as on modern powerful machines
|
|
@@ -10236,6 +10350,9 @@ class PlotBoilerplate {
|
|
|
10236
10350
|
lineWidth: 1,
|
|
10237
10351
|
fill: true,
|
|
10238
10352
|
anchor: true
|
|
10353
|
+
},
|
|
10354
|
+
origin: {
|
|
10355
|
+
color: "#000000"
|
|
10239
10356
|
}
|
|
10240
10357
|
}; // END drawConfig
|
|
10241
10358
|
// +---------------------------------------------------------------------------------
|
|
@@ -10254,6 +10371,7 @@ class PlotBoilerplate {
|
|
|
10254
10371
|
this.config.enableGL = false;
|
|
10255
10372
|
}
|
|
10256
10373
|
if (this.config.enableGL) {
|
|
10374
|
+
// Override the case 'null' here. If GL is not supported, well then nothing works.
|
|
10257
10375
|
const ctx = this.canvas.getContext("webgl"); // webgl-experimental?
|
|
10258
10376
|
this.draw = new drawutilsgl(ctx, false);
|
|
10259
10377
|
// PROBLEM: same instance of fill and draw when using WebGL.
|
|
@@ -10262,6 +10380,7 @@ class PlotBoilerplate {
|
|
|
10262
10380
|
console.warn("Initialized with experimental mode enableGL=true. Note that this is not yet fully implemented.");
|
|
10263
10381
|
}
|
|
10264
10382
|
else {
|
|
10383
|
+
// Override the case 'null' here. If context creation is not supported, well then nothing works.
|
|
10265
10384
|
const ctx = this.canvas.getContext("2d");
|
|
10266
10385
|
this.draw = new drawutils(ctx, false);
|
|
10267
10386
|
this.fill = new drawutils(ctx, true);
|
|
@@ -10298,8 +10417,8 @@ class PlotBoilerplate {
|
|
|
10298
10417
|
if (config.title) {
|
|
10299
10418
|
this.eventCatcher.setAttribute("title", config.title);
|
|
10300
10419
|
}
|
|
10301
|
-
this.draw.scale.set(this.config.scaleX, this.config.scaleY);
|
|
10302
|
-
this.fill.scale.set(this.config.scaleX, this.config.scaleY);
|
|
10420
|
+
this.draw.scale.set((_a = this.config.scaleX) !== null && _a !== void 0 ? _a : 1.0, this.config.scaleY);
|
|
10421
|
+
this.fill.scale.set((_b = this.config.scaleX) !== null && _b !== void 0 ? _b : 1.0, this.config.scaleY);
|
|
10303
10422
|
this.vertices = [];
|
|
10304
10423
|
this.selectPolygon = null;
|
|
10305
10424
|
this.draggedElements = [];
|
|
@@ -10344,11 +10463,13 @@ class PlotBoilerplate {
|
|
|
10344
10463
|
var tosvgFill = tosvgDraw.copyInstance(true); // fillShapes=true
|
|
10345
10464
|
tosvgDraw.beginDrawCycle(0);
|
|
10346
10465
|
tosvgFill.beginDrawCycle(0);
|
|
10347
|
-
if (pb.config.preClear)
|
|
10466
|
+
if (pb.config.preClear) {
|
|
10348
10467
|
pb.config.preClear();
|
|
10349
|
-
|
|
10350
|
-
|
|
10468
|
+
}
|
|
10469
|
+
tosvgDraw.clear(pb.config.backgroundColor || "white");
|
|
10470
|
+
if (pb.config.preDraw) {
|
|
10351
10471
|
pb.config.preDraw(tosvgDraw, tosvgFill);
|
|
10472
|
+
}
|
|
10352
10473
|
pb.drawAll(0, tosvgDraw, tosvgFill);
|
|
10353
10474
|
pb.drawVertices(0, tosvgDraw);
|
|
10354
10475
|
if (pb.config.postDraw)
|
|
@@ -10359,7 +10480,8 @@ class PlotBoilerplate {
|
|
|
10359
10480
|
// https://caniuse.com/xml-serializer
|
|
10360
10481
|
var serializer = new XMLSerializer();
|
|
10361
10482
|
var svgCode = serializer.serializeToString(svgNode);
|
|
10362
|
-
|
|
10483
|
+
// Add: '<?xml version="1.0" encoding="utf-8"?>\n' ?
|
|
10484
|
+
var blob = new Blob(['<?xml version="1.0" encoding="utf-8"?>\n' + svgCode], { type: "image/svg;charset=utf-8" });
|
|
10363
10485
|
// See documentation for FileSaver.js for usage.
|
|
10364
10486
|
// https://github.com/eligrey/FileSaver.js
|
|
10365
10487
|
if (typeof globalThis["saveAs"] !== "function")
|
|
@@ -10434,11 +10556,12 @@ class PlotBoilerplate {
|
|
|
10434
10556
|
* @private
|
|
10435
10557
|
**/
|
|
10436
10558
|
updateCSSscale() {
|
|
10559
|
+
var _a, _b, _c, _d;
|
|
10437
10560
|
if (this.config.cssUniformScale) {
|
|
10438
|
-
PlotBoilerplate.utils.setCSSscale(this.canvas, this.config.cssScaleX, this.config.cssScaleX);
|
|
10561
|
+
PlotBoilerplate.utils.setCSSscale(this.canvas, (_a = this.config.cssScaleX) !== null && _a !== void 0 ? _a : 1.0, (_b = this.config.cssScaleX) !== null && _b !== void 0 ? _b : 1.0);
|
|
10439
10562
|
}
|
|
10440
10563
|
else {
|
|
10441
|
-
PlotBoilerplate.utils.setCSSscale(this.canvas, this.config.cssScaleX, this.config.cssScaleY);
|
|
10564
|
+
PlotBoilerplate.utils.setCSSscale(this.canvas, (_c = this.config.cssScaleX) !== null && _c !== void 0 ? _c : 1.0, (_d = this.config.cssScaleY) !== null && _d !== void 0 ? _d : 1.0);
|
|
10442
10565
|
}
|
|
10443
10566
|
}
|
|
10444
10567
|
/**
|
|
@@ -10711,7 +10834,8 @@ class PlotBoilerplate {
|
|
|
10711
10834
|
* @return The vertex near the given position or undefined if none was found there.
|
|
10712
10835
|
**/
|
|
10713
10836
|
getVertexNear(pixelPosition, pixelTolerance) {
|
|
10714
|
-
var
|
|
10837
|
+
var _a, _b;
|
|
10838
|
+
var p = this.locatePointNear(this.transformMousePosition(pixelPosition.x, pixelPosition.y), pixelTolerance / Math.min((_a = this.config.cssScaleX) !== null && _a !== void 0 ? _a : 1.0, (_b = this.config.cssScaleY) !== null && _b !== void 0 ? _b : 1.0));
|
|
10715
10839
|
if (p && p.typeName == "vertex") {
|
|
10716
10840
|
return this.vertices[p.vindex];
|
|
10717
10841
|
}
|
|
@@ -10777,7 +10901,7 @@ class PlotBoilerplate {
|
|
|
10777
10901
|
drawOrigin(draw) {
|
|
10778
10902
|
// Add a crosshair to mark the origin
|
|
10779
10903
|
draw.setCurrentId("origin");
|
|
10780
|
-
draw.crosshair({ x: 0, y: 0 }, 10,
|
|
10904
|
+
draw.crosshair({ x: 0, y: 0 }, 10, this.drawConfig.origin.color);
|
|
10781
10905
|
}
|
|
10782
10906
|
/**
|
|
10783
10907
|
* This is just a tiny helper function to determine the render color of vertices.
|
|
@@ -10994,10 +11118,10 @@ class PlotBoilerplate {
|
|
|
10994
11118
|
else {
|
|
10995
11119
|
console.error("Cannot draw object. Unknown class.");
|
|
10996
11120
|
}
|
|
10997
|
-
draw.setCurrentClassName(
|
|
10998
|
-
draw.setCurrentId(
|
|
10999
|
-
fill.setCurrentClassName(
|
|
11000
|
-
fill.setCurrentId(
|
|
11121
|
+
draw.setCurrentClassName(undefined);
|
|
11122
|
+
draw.setCurrentId(undefined);
|
|
11123
|
+
fill.setCurrentClassName(undefined);
|
|
11124
|
+
fill.setCurrentId(undefined);
|
|
11001
11125
|
}
|
|
11002
11126
|
/**
|
|
11003
11127
|
* Draw the select-polygon (if there is one).
|
|
@@ -11100,7 +11224,7 @@ class PlotBoilerplate {
|
|
|
11100
11224
|
**/
|
|
11101
11225
|
clear() {
|
|
11102
11226
|
// Note that elements might have an alpha channel. Clear the scene first.
|
|
11103
|
-
this.draw.clear(this.config.backgroundColor);
|
|
11227
|
+
this.draw.clear(this.config.backgroundColor || "white");
|
|
11104
11228
|
}
|
|
11105
11229
|
/**
|
|
11106
11230
|
* Clear the selection.<br>
|
|
@@ -11130,7 +11254,8 @@ class PlotBoilerplate {
|
|
|
11130
11254
|
* @return {Bounds} The current viewport.
|
|
11131
11255
|
**/
|
|
11132
11256
|
viewport() {
|
|
11133
|
-
|
|
11257
|
+
var _a, _b;
|
|
11258
|
+
return new Bounds(this.transformMousePosition(0, 0), this.transformMousePosition(this.canvasSize.width * ((_a = this.config.cssScaleX) !== null && _a !== void 0 ? _a : 1.0), this.canvasSize.height * ((_b = this.config.cssScaleY) !== null && _b !== void 0 ? _b : 1.0)));
|
|
11134
11259
|
}
|
|
11135
11260
|
/**
|
|
11136
11261
|
* Trigger the saveFile.hook.
|
|
@@ -11178,10 +11303,12 @@ class PlotBoilerplate {
|
|
|
11178
11303
|
* @return {void}
|
|
11179
11304
|
**/
|
|
11180
11305
|
resizeCanvas() {
|
|
11306
|
+
var _a, _b, _c, _d, _e, _f;
|
|
11181
11307
|
const _self = this;
|
|
11182
11308
|
const _setSize = (w, h) => {
|
|
11183
|
-
|
|
11184
|
-
|
|
11309
|
+
var _a, _b;
|
|
11310
|
+
w *= (_a = _self.config.canvasWidthFactor) !== null && _a !== void 0 ? _a : 1.0;
|
|
11311
|
+
h *= (_b = _self.config.canvasHeightFactor) !== null && _b !== void 0 ? _b : 1.0;
|
|
11185
11312
|
_self.canvasSize.width = w;
|
|
11186
11313
|
_self.canvasSize.height = h;
|
|
11187
11314
|
if (_self.canvas instanceof HTMLCanvasElement) {
|
|
@@ -11210,8 +11337,8 @@ class PlotBoilerplate {
|
|
|
11210
11337
|
var width = globalThis.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
|
11211
11338
|
var height = globalThis.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
|
|
11212
11339
|
_self.canvas.style.position = "absolute";
|
|
11213
|
-
_self.canvas.style.width = _self.config.canvasWidthFactor * width + "px";
|
|
11214
|
-
_self.canvas.style.height = _self.config.canvasWidthFactor * height + "px";
|
|
11340
|
+
_self.canvas.style.width = ((_a = _self.config.canvasWidthFactor) !== null && _a !== void 0 ? _a : 1.0) * width + "px";
|
|
11341
|
+
_self.canvas.style.height = ((_b = _self.config.canvasWidthFactor) !== null && _b !== void 0 ? _b : 1.0) * height + "px";
|
|
11215
11342
|
_self.canvas.style.top = "0px";
|
|
11216
11343
|
_self.canvas.style.left = "0px";
|
|
11217
11344
|
_setSize(width, height);
|
|
@@ -11220,16 +11347,16 @@ class PlotBoilerplate {
|
|
|
11220
11347
|
// Set editor size
|
|
11221
11348
|
_self.canvas.style.position = "absolute";
|
|
11222
11349
|
const space = this.getAvailableContainerSpace();
|
|
11223
|
-
_self.canvas.style.width = _self.config.canvasWidthFactor * space.width + "px";
|
|
11224
|
-
_self.canvas.style.height = _self.config.canvasHeightFactor * space.height + "px";
|
|
11225
|
-
_self.canvas.style.top =
|
|
11226
|
-
_self.canvas.style.left =
|
|
11350
|
+
_self.canvas.style.width = ((_c = _self.config.canvasWidthFactor) !== null && _c !== void 0 ? _c : 1.0) * space.width + "px";
|
|
11351
|
+
_self.canvas.style.height = ((_d = _self.config.canvasHeightFactor) !== null && _d !== void 0 ? _d : 1.0) * space.height + "px";
|
|
11352
|
+
_self.canvas.style.top = "";
|
|
11353
|
+
_self.canvas.style.left = "";
|
|
11227
11354
|
_setSize(space.width, space.height);
|
|
11228
11355
|
}
|
|
11229
11356
|
else {
|
|
11230
|
-
_self.canvas.style.width =
|
|
11231
|
-
_self.canvas.style.height =
|
|
11232
|
-
_setSize(_self.config.defaultCanvasWidth, _self.config.defaultCanvasHeight);
|
|
11357
|
+
_self.canvas.style.width = "";
|
|
11358
|
+
_self.canvas.style.height = "";
|
|
11359
|
+
_setSize((_e = _self.config.defaultCanvasWidth) !== null && _e !== void 0 ? _e : 1024, (_f = _self.config.defaultCanvasHeight) !== null && _f !== void 0 ? _f : 768);
|
|
11233
11360
|
}
|
|
11234
11361
|
if (_self.config.redrawOnResize)
|
|
11235
11362
|
_self.redraw();
|