plotboilerplate 1.20.1 → 1.21.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 +17 -1
- package/dist/index.esm.js +2065 -1397
- 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 +1265 -584
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +2 -1
- package/src/cjs/BezierPath.d.ts +27 -49
- package/src/cjs/BezierPath.js +69 -237
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Bounds.d.ts +14 -1
- package/src/cjs/Bounds.js +21 -1
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +70 -1
- package/src/cjs/CubicBezierCurve.js +130 -12
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Line.d.ts +2 -1
- package/src/cjs/Line.js +1 -0
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/PBText.d.ts +2 -1
- package/src/cjs/PBText.js +10 -9
- package/src/cjs/PBText.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +10 -13
- package/src/cjs/PlotBoilerplate.js +136 -47
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +35 -1
- package/src/cjs/Polygon.js +87 -1
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.js +1 -0
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/VEllipse.js +1 -1
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/Vector.d.ts +4 -4
- package/src/cjs/Vector.js +2 -2
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +2 -1
- package/src/cjs/VertTuple.js +4 -3
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +14 -3
- package/src/cjs/Vertex.js +18 -3
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/draw.d.ts +159 -79
- package/src/cjs/draw.js +311 -139
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +93 -55
- package/src/cjs/drawgl.js +90 -34
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +233 -58
- package/src/cjs/drawutilssvg.js +384 -95
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +161 -82
- package/src/cjs/interfaces/DrawLib.js +7 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +46 -32
- package/src/cjs/interfaces/core.js +2 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/creategui.js +16 -10
- package/src/cjs/utils/datastructures/Color.d.ts +3 -1
- package/src/cjs/utils/datastructures/Color.js +12 -1
- package/src/cjs/utils/datastructures/Color.js.map +1 -1
- package/src/cjs/utils/detectDarkMode.d.ts +10 -0
- package/src/cjs/utils/detectDarkMode.js +32 -0
- package/src/cjs/utils/detectDarkMode.js.map +1 -0
- package/src/cjs/utils/module.js +4 -2
- package/src/esm/BezierPath.d.ts +27 -49
- package/src/esm/BezierPath.js +69 -237
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Bounds.d.ts +14 -1
- package/src/esm/Bounds.js +19 -1
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +70 -1
- package/src/esm/CubicBezierCurve.js +130 -12
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Line.d.ts +2 -1
- package/src/esm/Line.js +1 -0
- package/src/esm/Line.js.map +1 -1
- package/src/esm/PBText.d.ts +2 -1
- package/src/esm/PBText.js +10 -9
- package/src/esm/PBText.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +10 -13
- package/src/esm/PlotBoilerplate.js +136 -48
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +35 -1
- package/src/esm/Polygon.js +85 -1
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.js +1 -0
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/VEllipse.js +1 -1
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/Vector.d.ts +4 -4
- package/src/esm/Vector.js +2 -2
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.d.ts +2 -1
- package/src/esm/VertTuple.js +4 -3
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +14 -3
- package/src/esm/Vertex.js +18 -3
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/draw.d.ts +159 -79
- package/src/esm/draw.js +307 -137
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +93 -55
- package/src/esm/drawgl.js +90 -34
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +233 -58
- package/src/esm/drawutilssvg.js +379 -95
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +161 -82
- package/src/esm/interfaces/DrawLib.js +7 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +46 -32
- package/src/esm/interfaces/core.js +2 -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 +12 -1
- package/src/esm/utils/datastructures/Color.js.map +1 -1
- package/src/esm/utils/detectDarkMode.d.ts +10 -0
- package/src/esm/utils/detectDarkMode.js +28 -0
- package/src/esm/utils/detectDarkMode.js.map +1 -0
- package/src/ts/BezierPath.ts +74 -244
- package/src/ts/Bounds.ts +25 -1
- package/src/ts/CubicBezierCurve.ts +139 -12
- package/src/ts/Line.ts +2 -1
- package/src/ts/PBText.ts +10 -9
- package/src/ts/PlotBoilerplate.ts +130 -50
- package/src/ts/Polygon.ts +91 -1
- package/src/ts/Triangle.ts +2 -1
- package/src/ts/VEllipse.ts +2 -2
- package/src/ts/Vector.ts +4 -4
- package/src/ts/VertTuple.ts +4 -3
- package/src/ts/Vertex.ts +20 -4
- package/src/ts/draw.ts +316 -119
- package/src/ts/drawgl.ts +141 -78
- package/src/ts/drawutilssvg.ts +562 -133
- package/src/ts/interfaces/DrawLib.ts +223 -86
- package/src/ts/interfaces/core.ts +47 -32
- package/src/ts/utils/datastructures/Color.ts +13 -1
- package/src/ts/utils/detectDarkMode.ts +30 -0
|
@@ -79,7 +79,12 @@
|
|
|
79
79
|
* @modified 2022-10-25 Added the `origin` to the default draw config.
|
|
80
80
|
* @modified 2022-11-06 Adding an XML declaration to the SVG export routine.
|
|
81
81
|
* @modified 2022-11-23 Added the `drawRaster` (default=true) option to the config/drawconfig.
|
|
82
|
-
* @
|
|
82
|
+
* @modified 2023-02-04 Fixed a bug in the `drawDrawable` function; fill's current classname was not set.
|
|
83
|
+
* @modified 2023-02-10 Fixing an issue of the `style.position` setting when `fitToParent=true` from `absolute` to `static` (default).
|
|
84
|
+
* @modified 2023-02-10 Cleaning up most type errors in the main class (mostly null checks).
|
|
85
|
+
* @modified 2023-02-10 Adding `enableZoom` and `enablePan` (both default true) to have the option to disable these functions.
|
|
86
|
+
* @modified 2023-09-29 Adding proper dicionary key and value types to the params of `PlotBoilerplate.utils.safeMergeByKeys` (was `object` before).
|
|
87
|
+
* @version 1.17.3
|
|
83
88
|
*
|
|
84
89
|
* @file PlotBoilerplate
|
|
85
90
|
* @fileoverview The main class.
|
|
@@ -191,6 +196,8 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
191
196
|
* @param {boolean=} [config.enableTouch=true] - Indicates if the application should handle touch events for you.
|
|
192
197
|
* @param {boolean=} [config.enableKeys=true] - Indicates if the application should handle key events for you.
|
|
193
198
|
* @param {boolean=} [config.enableMouseWheel=true] - Indicates if the application should handle mouse wheel events for you.
|
|
199
|
+
* @param {boolean=} [config.enablePan=true] - (default true) Set to false if you want to disable panning completely.
|
|
200
|
+
* @param {boolean=} [config.enableZoom=true] - (default true) Set to false if you want to disable zooming completely.
|
|
194
201
|
* @param {boolean=} [config.enableGL=false] - Indicates if the application should use the experimental WebGL features (not recommended).
|
|
195
202
|
* @param {boolean=} [config.enableSVGExport=true] - Indicates if the SVG export should be enabled (default is true).
|
|
196
203
|
* Note that changes from the postDraw hook might not be visible in the export.
|
|
@@ -217,7 +224,7 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
217
224
|
draggable: true,
|
|
218
225
|
visible: true
|
|
219
226
|
};
|
|
220
|
-
if (typeof config.canvas
|
|
227
|
+
if (typeof config.canvas === "undefined") {
|
|
221
228
|
throw "No canvas specified.";
|
|
222
229
|
}
|
|
223
230
|
/**
|
|
@@ -271,6 +278,8 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
271
278
|
enableTouch: f.bool(config, "enableTouch", true),
|
|
272
279
|
enableKeys: f.bool(config, "enableKeys", true),
|
|
273
280
|
enableMouseWheel: f.bool(config, "enableMouseWheel", true),
|
|
281
|
+
enableZoom: f.bool(config, "enableZoom", true),
|
|
282
|
+
enablePan: f.bool(config, "enablePan", true),
|
|
274
283
|
// Experimental (and unfinished)
|
|
275
284
|
enableGL: f.bool(config, "enableGL", false)
|
|
276
285
|
}; // END confog
|
|
@@ -307,6 +316,10 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
307
316
|
fill: true
|
|
308
317
|
}
|
|
309
318
|
},
|
|
319
|
+
// bezierPath: {
|
|
320
|
+
// color: "#0022a8",
|
|
321
|
+
// lineWidth: 1
|
|
322
|
+
// },
|
|
310
323
|
polygon: {
|
|
311
324
|
color: "#0022a8",
|
|
312
325
|
lineWidth: 1
|
|
@@ -366,7 +379,10 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
366
379
|
// +-------------------------------
|
|
367
380
|
this.grid = new Grid_1.Grid(new Vertex_1.Vertex(0, 0), new Vertex_1.Vertex(50, 50));
|
|
368
381
|
this.canvasSize = { width: PlotBoilerplate.DEFAULT_CANVAS_WIDTH, height: PlotBoilerplate.DEFAULT_CANVAS_HEIGHT };
|
|
369
|
-
var canvasElement = typeof config.canvas
|
|
382
|
+
var canvasElement = typeof config.canvas === "string" ? document.querySelector(config.canvas) : config.canvas;
|
|
383
|
+
if (typeof canvasElement === "undefined") {
|
|
384
|
+
throw "Cannot initialize PlotBoilerplate with a null canvas (element \"" + config.canvas + " not found).";
|
|
385
|
+
}
|
|
370
386
|
// Which renderer to use: Canvas2D, WebGL (experimental) or SVG?
|
|
371
387
|
if (canvasElement.tagName.toLowerCase() === "canvas") {
|
|
372
388
|
this.canvas = canvasElement;
|
|
@@ -935,7 +951,7 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
935
951
|
this.draw.setCurrentId(d.uid);
|
|
936
952
|
this.fill.setCurrentId(d.uid);
|
|
937
953
|
this.draw.setCurrentClassName(d.className);
|
|
938
|
-
this.
|
|
954
|
+
this.fill.setCurrentClassName(d.className);
|
|
939
955
|
this.drawDrawable(d, renderTime, draw, fill);
|
|
940
956
|
}
|
|
941
957
|
};
|
|
@@ -956,7 +972,13 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
956
972
|
**/
|
|
957
973
|
PlotBoilerplate.prototype.drawDrawable = function (d, renderTime, draw, fill) {
|
|
958
974
|
if (d instanceof BezierPath_1.BezierPath) {
|
|
975
|
+
var curveIndex = 0;
|
|
959
976
|
for (var c in d.bezierCurves) {
|
|
977
|
+
// Restore these settings again in each loop (will be overwritten)
|
|
978
|
+
this.draw.setCurrentId(d.uid + "-" + curveIndex);
|
|
979
|
+
this.fill.setCurrentId(d.uid + "-" + curveIndex);
|
|
980
|
+
this.draw.setCurrentClassName(d.className);
|
|
981
|
+
this.fill.setCurrentClassName(d.className);
|
|
960
982
|
draw.cubicBezier(d.bezierCurves[c].startPoint, d.bezierCurves[c].endPoint, d.bezierCurves[c].startControlPoint, d.bezierCurves[c].endControlPoint, this.drawConfig.bezier.color, this.drawConfig.bezier.lineWidth);
|
|
961
983
|
if (this.drawConfig.drawBezierHandlePoints && this.drawConfig.drawHandlePoints) {
|
|
962
984
|
if (d.bezierCurves[c].startPoint.attr.visible) {
|
|
@@ -1008,12 +1030,13 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1008
1030
|
if (this.drawConfig.drawBezierHandleLines && this.drawConfig.drawHandleLines) {
|
|
1009
1031
|
draw.setCurrentId(d.uid + "_l0");
|
|
1010
1032
|
draw.setCurrentClassName(d.className + "-start-line");
|
|
1011
|
-
draw.
|
|
1033
|
+
draw.handleLine(d.bezierCurves[c].startPoint, d.bezierCurves[c].startControlPoint);
|
|
1012
1034
|
draw.setCurrentId(d.uid + "_l1");
|
|
1013
1035
|
draw.setCurrentClassName(d.className + "-end-line");
|
|
1014
|
-
draw.
|
|
1036
|
+
draw.handleLine(d.bezierCurves[c].endPoint, d.bezierCurves[c].endControlPoint);
|
|
1015
1037
|
}
|
|
1016
|
-
|
|
1038
|
+
curveIndex++;
|
|
1039
|
+
} // END for
|
|
1017
1040
|
}
|
|
1018
1041
|
else if (d instanceof Polygon_1.Polygon) {
|
|
1019
1042
|
draw.polygon(d, this.drawConfig.polygon.color, this.drawConfig.polygon.lineWidth);
|
|
@@ -1033,11 +1056,11 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1033
1056
|
draw.setCurrentId(d.uid + "_e0");
|
|
1034
1057
|
draw.setCurrentClassName(d.className + "-v-line");
|
|
1035
1058
|
// draw.line( d.center.clone().add(0,d.axis.y-d.center.y), d.axis, '#c8c8c8' );
|
|
1036
|
-
draw.
|
|
1059
|
+
draw.handleLine(d.center.clone().add(0, d.signedRadiusV()).rotate(d.rotation, d.center), d.axis); // , "#c8c8c8");
|
|
1037
1060
|
draw.setCurrentId(d.uid + "_e1");
|
|
1038
1061
|
draw.setCurrentClassName(d.className + "-h-line");
|
|
1039
1062
|
// draw.line( d.center.clone().add(d.axis.x-d.center.x,0), d.axis, '#c8c8c8' );
|
|
1040
|
-
draw.
|
|
1063
|
+
draw.handleLine(d.center.clone().add(d.signedRadiusH(), 0).rotate(d.rotation, d.center), d.axis); // , "#c8c8c8");
|
|
1041
1064
|
}
|
|
1042
1065
|
draw.setCurrentId(d.uid);
|
|
1043
1066
|
draw.setCurrentClassName("" + d.className);
|
|
@@ -1124,10 +1147,10 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1124
1147
|
else {
|
|
1125
1148
|
console.error("Cannot draw object. Unknown class.");
|
|
1126
1149
|
}
|
|
1127
|
-
draw.setCurrentClassName(
|
|
1128
|
-
draw.setCurrentId(
|
|
1129
|
-
fill.setCurrentClassName(
|
|
1130
|
-
fill.setCurrentId(
|
|
1150
|
+
draw.setCurrentClassName(null);
|
|
1151
|
+
draw.setCurrentId(null);
|
|
1152
|
+
fill.setCurrentClassName(null);
|
|
1153
|
+
fill.setCurrentId(null);
|
|
1131
1154
|
};
|
|
1132
1155
|
/**
|
|
1133
1156
|
* Draw the select-polygon (if there is one).
|
|
@@ -1217,8 +1240,8 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1217
1240
|
this.drawSelectPolygon(draw);
|
|
1218
1241
|
// Clear IDs and classnames (postDraw hook might draw somthing and the do not want
|
|
1219
1242
|
// to interfered with that).
|
|
1220
|
-
draw.setCurrentId(
|
|
1221
|
-
draw.setCurrentClassName(
|
|
1243
|
+
draw.setCurrentId(null);
|
|
1244
|
+
draw.setCurrentClassName(null);
|
|
1222
1245
|
}; // END redraw
|
|
1223
1246
|
/**
|
|
1224
1247
|
* This function clears the canvas with the configured background color.<br>
|
|
@@ -1355,7 +1378,7 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1355
1378
|
}
|
|
1356
1379
|
else if (_self.config.fitToParent) {
|
|
1357
1380
|
// Set editor size
|
|
1358
|
-
_self.canvas.style.position = "
|
|
1381
|
+
_self.canvas.style.position = "static";
|
|
1359
1382
|
var space = this.getAvailableContainerSpace();
|
|
1360
1383
|
_self.canvas.style.width = ((_c = _self.config.canvasWidthFactor) !== null && _c !== void 0 ? _c : 1.0) * space.width + "px";
|
|
1361
1384
|
_self.canvas.style.height = ((_d = _self.config.canvasHeightFactor) !== null && _d !== void 0 ? _d : 1.0) * space.height + "px";
|
|
@@ -1426,24 +1449,24 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1426
1449
|
**/
|
|
1427
1450
|
PlotBoilerplate.prototype.handleClick = function (e) {
|
|
1428
1451
|
var _self = this;
|
|
1429
|
-
var
|
|
1430
|
-
if (
|
|
1431
|
-
_self.vertices[
|
|
1452
|
+
var point = this.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX || 1.0, _self.config.cssScaleY || 1.0));
|
|
1453
|
+
if (point) {
|
|
1454
|
+
_self.vertices[point.vindex].listeners.fireClickEvent(e);
|
|
1432
1455
|
if (this.keyHandler && this.keyHandler.isDown("shift")) {
|
|
1433
|
-
if (
|
|
1434
|
-
var vert = _self.paths[
|
|
1456
|
+
if (point.typeName == "bpath") {
|
|
1457
|
+
var vert = _self.paths[point.pindex].bezierCurves[point.cindex].getPointByID(point.pid);
|
|
1435
1458
|
if (vert.attr.selectable)
|
|
1436
1459
|
vert.attr.isSelected = !vert.attr.isSelected;
|
|
1437
1460
|
}
|
|
1438
|
-
else if (
|
|
1439
|
-
var vert = _self.vertices[
|
|
1461
|
+
else if (point.typeName == "vertex") {
|
|
1462
|
+
var vert = _self.vertices[point.vindex];
|
|
1440
1463
|
if (vert.attr.selectable)
|
|
1441
1464
|
vert.attr.isSelected = !vert.attr.isSelected;
|
|
1442
1465
|
}
|
|
1443
1466
|
_self.redraw();
|
|
1444
1467
|
}
|
|
1445
|
-
else if (this.keyHandler.isDown("y")) {
|
|
1446
|
-
_self.vertices[
|
|
1468
|
+
else if (this.keyHandler && this.keyHandler.isDown("y")) {
|
|
1469
|
+
_self.vertices[point.vindex].attr.bezierAutoAdjust = !_self.vertices[point.vindex].attr.bezierAutoAdjust;
|
|
1447
1470
|
_self.redraw();
|
|
1448
1471
|
}
|
|
1449
1472
|
}
|
|
@@ -1510,11 +1533,11 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1510
1533
|
var _self = this;
|
|
1511
1534
|
if (e.button != 0)
|
|
1512
1535
|
return; // Only react on left mouse or touch events
|
|
1513
|
-
var
|
|
1514
|
-
if (!
|
|
1536
|
+
var draggablePoint = _self.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX, _self.config.cssScaleY));
|
|
1537
|
+
if (!draggablePoint)
|
|
1515
1538
|
return;
|
|
1516
1539
|
// Drag all selected elements?
|
|
1517
|
-
if (
|
|
1540
|
+
if (draggablePoint.typeName == "vertex" && _self.vertices[draggablePoint.vindex].attr.isSelected) {
|
|
1518
1541
|
// Multi drag
|
|
1519
1542
|
// for( var i in _self.vertices ) {
|
|
1520
1543
|
for (var i = 0; i < _self.vertices.length; i++) {
|
|
@@ -1526,13 +1549,15 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1526
1549
|
}
|
|
1527
1550
|
else {
|
|
1528
1551
|
// Single drag
|
|
1529
|
-
if (!_self.vertices[
|
|
1552
|
+
if (!_self.vertices[draggablePoint.vindex].attr.draggable)
|
|
1530
1553
|
return;
|
|
1531
|
-
_self.draggedElements.push(
|
|
1532
|
-
if (
|
|
1533
|
-
_self.paths[
|
|
1534
|
-
|
|
1535
|
-
|
|
1554
|
+
_self.draggedElements.push(draggablePoint);
|
|
1555
|
+
if (draggablePoint.typeName == "bpath")
|
|
1556
|
+
_self.paths[draggablePoint.pindex].bezierCurves[draggablePoint.cindex]
|
|
1557
|
+
.getPointByID(draggablePoint.pid)
|
|
1558
|
+
.listeners.fireDragStartEvent(e);
|
|
1559
|
+
else if (draggablePoint.typeName == "vertex")
|
|
1560
|
+
_self.vertices[draggablePoint.vindex].listeners.fireDragStartEvent(e);
|
|
1536
1561
|
}
|
|
1537
1562
|
_self.redraw();
|
|
1538
1563
|
};
|
|
@@ -1559,7 +1584,10 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1559
1584
|
// not this one. So this tab will never receive any [Ctrl-down] events
|
|
1560
1585
|
// until next keypress; the implication is, that [Ctrl] would still
|
|
1561
1586
|
// considered to be pressed which is not true.
|
|
1562
|
-
if (this.keyHandler.isDown("alt") || this.keyHandler.isDown("spacebar")) {
|
|
1587
|
+
if (this.keyHandler && (this.keyHandler.isDown("alt") || this.keyHandler.isDown("spacebar"))) {
|
|
1588
|
+
if (!this.config.enablePan) {
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1563
1591
|
_self.setOffset(_self.draw.offset.clone().add(e.params.dragAmount));
|
|
1564
1592
|
_self.redraw();
|
|
1565
1593
|
}
|
|
@@ -1628,6 +1656,9 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1628
1656
|
* @return {void}
|
|
1629
1657
|
**/
|
|
1630
1658
|
PlotBoilerplate.prototype.mouseWheelHandler = function (e) {
|
|
1659
|
+
if (!this.config.enableZoom) {
|
|
1660
|
+
return;
|
|
1661
|
+
}
|
|
1631
1662
|
var zoomStep = 1.25; // Make configurable?
|
|
1632
1663
|
// CHANGED replaced _self by this
|
|
1633
1664
|
var _self = this;
|
|
@@ -1693,6 +1724,7 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1693
1724
|
this.setOffset({ x: newOffsetX, y: newOffsetY });
|
|
1694
1725
|
};
|
|
1695
1726
|
PlotBoilerplate.prototype.installInputListeners = function () {
|
|
1727
|
+
var _this = this;
|
|
1696
1728
|
var _self = this;
|
|
1697
1729
|
if (this.config.enableMouse) {
|
|
1698
1730
|
// Install a mouse handler on the canvas.
|
|
@@ -1767,6 +1799,9 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1767
1799
|
if (evt.touches.length == 1 && draggedElement) {
|
|
1768
1800
|
evt.preventDefault();
|
|
1769
1801
|
evt.stopPropagation();
|
|
1802
|
+
if (!touchDownPos || !touchMovePos) {
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1770
1805
|
var rel = relPos_1({ x: evt.touches[0].clientX, y: evt.touches[0].clientY });
|
|
1771
1806
|
var trans = _self.transformMousePosition(rel.x, rel.y);
|
|
1772
1807
|
var diff = new Vertex_1.Vertex(_self.transformMousePosition(touchMovePos.x, touchMovePos.y)).difference(trans);
|
|
@@ -1791,6 +1826,9 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1791
1826
|
touchMovePos = new Vertex_1.Vertex(rel);
|
|
1792
1827
|
}
|
|
1793
1828
|
else if (evt.touches.length == 2) {
|
|
1829
|
+
if (!_this.config.enablePan) {
|
|
1830
|
+
return;
|
|
1831
|
+
}
|
|
1794
1832
|
// If at least two fingers touch and move, then change the draw offset (panning).
|
|
1795
1833
|
evt.preventDefault();
|
|
1796
1834
|
evt.stopPropagation();
|
|
@@ -1803,6 +1841,9 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1803
1841
|
touchEnd: function (evt) {
|
|
1804
1842
|
// Note: e.touches.length is 0 here
|
|
1805
1843
|
if (draggedElement && draggedElement.typeName == "vertex") {
|
|
1844
|
+
if (!touchDownPos) {
|
|
1845
|
+
return;
|
|
1846
|
+
}
|
|
1806
1847
|
var draggingVertex = _self.vertices[draggedElement.vindex];
|
|
1807
1848
|
var fakeEvent = {
|
|
1808
1849
|
isTouchEvent: true,
|
|
@@ -1835,9 +1876,17 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1835
1876
|
multiTouchStartScale = null;
|
|
1836
1877
|
},
|
|
1837
1878
|
pinch: function (evt) {
|
|
1879
|
+
if (!_this.config.enableZoom) {
|
|
1880
|
+
return;
|
|
1881
|
+
}
|
|
1882
|
+
var touchItem0 = evt.touches.item(0);
|
|
1883
|
+
var touchItem1 = evt.touches.item(1);
|
|
1884
|
+
if (!evt.touches || !multiTouchStartScale || !touchItem0 || !touchItem1) {
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1838
1887
|
// For pinching there must be at least two touch items
|
|
1839
|
-
var fingerA = new Vertex_1.Vertex(
|
|
1840
|
-
var fingerB = new Vertex_1.Vertex(
|
|
1888
|
+
var fingerA = new Vertex_1.Vertex(touchItem0.clientX, touchItem0.clientY);
|
|
1889
|
+
var fingerB = new Vertex_1.Vertex(touchItem1.clientX, touchItem1.clientY);
|
|
1841
1890
|
var center = new Line_1.Line(fingerA, fingerB).vertAt(0.5);
|
|
1842
1891
|
_self.setZoom(multiTouchStartScale.x * evt.zoom, multiTouchStartScale.y * evt.zoom, center);
|
|
1843
1892
|
_self.redraw();
|
|
@@ -1950,22 +1999,35 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1950
1999
|
**/
|
|
1951
2000
|
safeMergeByKeys: function (base, extension) {
|
|
1952
2001
|
for (var k in extension) {
|
|
1953
|
-
if (!extension.hasOwnProperty(k))
|
|
2002
|
+
if (!extension.hasOwnProperty(k)) {
|
|
1954
2003
|
continue;
|
|
2004
|
+
}
|
|
1955
2005
|
if (base.hasOwnProperty(k)) {
|
|
1956
2006
|
var typ = typeof base[k];
|
|
2007
|
+
var extVal = extension[k];
|
|
1957
2008
|
try {
|
|
1958
|
-
if (typ == "boolean")
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
2009
|
+
if (typ == "boolean") {
|
|
2010
|
+
if (typeof extVal === "string")
|
|
2011
|
+
base[k] = Boolean(!!JSON.parse(extVal));
|
|
2012
|
+
else
|
|
2013
|
+
base[k] = extVal;
|
|
2014
|
+
}
|
|
2015
|
+
else if (typ == "number") {
|
|
2016
|
+
if (typeof extVal === "string")
|
|
2017
|
+
base[k] = Number(JSON.parse(extVal) * 1);
|
|
2018
|
+
else
|
|
2019
|
+
base[k] = extension[k];
|
|
2020
|
+
}
|
|
2021
|
+
else if (typ == "function" && typeof extVal == "function") {
|
|
1963
2022
|
base[k] = extension[k];
|
|
1964
|
-
|
|
2023
|
+
}
|
|
2024
|
+
else {
|
|
2025
|
+
// Probably a sting
|
|
1965
2026
|
base[k] = extension[k];
|
|
2027
|
+
}
|
|
1966
2028
|
}
|
|
1967
2029
|
catch (e) {
|
|
1968
|
-
console.error("error in key ", k,
|
|
2030
|
+
console.error("error in key ", k, extVal, e);
|
|
1969
2031
|
}
|
|
1970
2032
|
}
|
|
1971
2033
|
else {
|
|
@@ -1974,6 +2036,31 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1974
2036
|
}
|
|
1975
2037
|
return base;
|
|
1976
2038
|
},
|
|
2039
|
+
/*
|
|
2040
|
+
__safeMergeByKeys: <KeyType extends string | number | symbol, ValueType extends boolean | number | string | Function>(
|
|
2041
|
+
base: Record<KeyType, ValueType>,
|
|
2042
|
+
extension: Record<KeyType, string>
|
|
2043
|
+
): Record<KeyType, ValueType> => {
|
|
2044
|
+
for (var k in extension) {
|
|
2045
|
+
if (!extension.hasOwnProperty(k)) continue;
|
|
2046
|
+
if (base.hasOwnProperty(k)) {
|
|
2047
|
+
var typ = typeof base[k];
|
|
2048
|
+
try {
|
|
2049
|
+
if (typ == "boolean") base[k] = !!JSON.parse(extension[k]);
|
|
2050
|
+
else if (typ == "number") base[k] = JSON.parse(extension[k]) * 1;
|
|
2051
|
+
else if (typ == "function" && typeof extension[k] == "function") base[k] = extension[k];
|
|
2052
|
+
else base[k] = extension[k];
|
|
2053
|
+
} catch (e) {
|
|
2054
|
+
console.error("error in key ", k, extension[k], e);
|
|
2055
|
+
}
|
|
2056
|
+
} else {
|
|
2057
|
+
base[k] = extension[k];
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
return base;
|
|
2061
|
+
},
|
|
2062
|
+
*()
|
|
2063
|
+
|
|
1977
2064
|
/**
|
|
1978
2065
|
* A helper function to scale elements (usually the canvas) using CSS.
|
|
1979
2066
|
*
|
|
@@ -1986,8 +2073,10 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
1986
2073
|
**/
|
|
1987
2074
|
setCSSscale: function (element, scaleX, scaleY) {
|
|
1988
2075
|
element.style["transform-origin"] = "0 0";
|
|
1989
|
-
if (scaleX == 1.0 && scaleY == 1.0)
|
|
1990
|
-
element.style.transform = null;
|
|
2076
|
+
if (scaleX == 1.0 && scaleY == 1.0) {
|
|
2077
|
+
// element.style.transform = null;
|
|
2078
|
+
element.style.removeProperty("transform");
|
|
2079
|
+
}
|
|
1991
2080
|
else
|
|
1992
2081
|
element.style.transform = "scale(" + scaleX + "," + scaleY + ")";
|
|
1993
2082
|
},
|