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.
Files changed (141) hide show
  1. package/README.md +17 -1
  2. package/dist/index.esm.js +2065 -1397
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.esm.min.js +1 -1
  5. package/dist/index.esm.min.js.map +1 -1
  6. package/dist/plotboilerplate.browser.min.js +1 -1
  7. package/dist/plotboilerplate.browser.min.js.map +1 -1
  8. package/dist/plotboilerplate.js +1265 -584
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +2 -1
  11. package/src/cjs/BezierPath.d.ts +27 -49
  12. package/src/cjs/BezierPath.js +69 -237
  13. package/src/cjs/BezierPath.js.map +1 -1
  14. package/src/cjs/Bounds.d.ts +14 -1
  15. package/src/cjs/Bounds.js +21 -1
  16. package/src/cjs/Bounds.js.map +1 -1
  17. package/src/cjs/CubicBezierCurve.d.ts +70 -1
  18. package/src/cjs/CubicBezierCurve.js +130 -12
  19. package/src/cjs/CubicBezierCurve.js.map +1 -1
  20. package/src/cjs/Line.d.ts +2 -1
  21. package/src/cjs/Line.js +1 -0
  22. package/src/cjs/Line.js.map +1 -1
  23. package/src/cjs/PBText.d.ts +2 -1
  24. package/src/cjs/PBText.js +10 -9
  25. package/src/cjs/PBText.js.map +1 -1
  26. package/src/cjs/PlotBoilerplate.d.ts +10 -13
  27. package/src/cjs/PlotBoilerplate.js +136 -47
  28. package/src/cjs/PlotBoilerplate.js.map +1 -1
  29. package/src/cjs/Polygon.d.ts +35 -1
  30. package/src/cjs/Polygon.js +87 -1
  31. package/src/cjs/Polygon.js.map +1 -1
  32. package/src/cjs/Triangle.js +1 -0
  33. package/src/cjs/Triangle.js.map +1 -1
  34. package/src/cjs/VEllipse.js +1 -1
  35. package/src/cjs/VEllipse.js.map +1 -1
  36. package/src/cjs/Vector.d.ts +4 -4
  37. package/src/cjs/Vector.js +2 -2
  38. package/src/cjs/Vector.js.map +1 -1
  39. package/src/cjs/VertTuple.d.ts +2 -1
  40. package/src/cjs/VertTuple.js +4 -3
  41. package/src/cjs/VertTuple.js.map +1 -1
  42. package/src/cjs/Vertex.d.ts +14 -3
  43. package/src/cjs/Vertex.js +18 -3
  44. package/src/cjs/Vertex.js.map +1 -1
  45. package/src/cjs/draw.d.ts +159 -79
  46. package/src/cjs/draw.js +311 -139
  47. package/src/cjs/draw.js.map +1 -1
  48. package/src/cjs/drawgl.d.ts +93 -55
  49. package/src/cjs/drawgl.js +90 -34
  50. package/src/cjs/drawgl.js.map +1 -1
  51. package/src/cjs/drawutilssvg.d.ts +233 -58
  52. package/src/cjs/drawutilssvg.js +384 -95
  53. package/src/cjs/drawutilssvg.js.map +1 -1
  54. package/src/cjs/interfaces/DrawLib.d.ts +161 -82
  55. package/src/cjs/interfaces/DrawLib.js +7 -0
  56. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  57. package/src/cjs/interfaces/core.d.ts +46 -32
  58. package/src/cjs/interfaces/core.js +2 -0
  59. package/src/cjs/interfaces/core.js.map +1 -1
  60. package/src/cjs/utils/creategui.js +16 -10
  61. package/src/cjs/utils/datastructures/Color.d.ts +3 -1
  62. package/src/cjs/utils/datastructures/Color.js +12 -1
  63. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  64. package/src/cjs/utils/detectDarkMode.d.ts +10 -0
  65. package/src/cjs/utils/detectDarkMode.js +32 -0
  66. package/src/cjs/utils/detectDarkMode.js.map +1 -0
  67. package/src/cjs/utils/module.js +4 -2
  68. package/src/esm/BezierPath.d.ts +27 -49
  69. package/src/esm/BezierPath.js +69 -237
  70. package/src/esm/BezierPath.js.map +1 -1
  71. package/src/esm/Bounds.d.ts +14 -1
  72. package/src/esm/Bounds.js +19 -1
  73. package/src/esm/Bounds.js.map +1 -1
  74. package/src/esm/CubicBezierCurve.d.ts +70 -1
  75. package/src/esm/CubicBezierCurve.js +130 -12
  76. package/src/esm/CubicBezierCurve.js.map +1 -1
  77. package/src/esm/Line.d.ts +2 -1
  78. package/src/esm/Line.js +1 -0
  79. package/src/esm/Line.js.map +1 -1
  80. package/src/esm/PBText.d.ts +2 -1
  81. package/src/esm/PBText.js +10 -9
  82. package/src/esm/PBText.js.map +1 -1
  83. package/src/esm/PlotBoilerplate.d.ts +10 -13
  84. package/src/esm/PlotBoilerplate.js +136 -48
  85. package/src/esm/PlotBoilerplate.js.map +1 -1
  86. package/src/esm/Polygon.d.ts +35 -1
  87. package/src/esm/Polygon.js +85 -1
  88. package/src/esm/Polygon.js.map +1 -1
  89. package/src/esm/Triangle.js +1 -0
  90. package/src/esm/Triangle.js.map +1 -1
  91. package/src/esm/VEllipse.js +1 -1
  92. package/src/esm/VEllipse.js.map +1 -1
  93. package/src/esm/Vector.d.ts +4 -4
  94. package/src/esm/Vector.js +2 -2
  95. package/src/esm/Vector.js.map +1 -1
  96. package/src/esm/VertTuple.d.ts +2 -1
  97. package/src/esm/VertTuple.js +4 -3
  98. package/src/esm/VertTuple.js.map +1 -1
  99. package/src/esm/Vertex.d.ts +14 -3
  100. package/src/esm/Vertex.js +18 -3
  101. package/src/esm/Vertex.js.map +1 -1
  102. package/src/esm/draw.d.ts +159 -79
  103. package/src/esm/draw.js +307 -137
  104. package/src/esm/draw.js.map +1 -1
  105. package/src/esm/drawgl.d.ts +93 -55
  106. package/src/esm/drawgl.js +90 -34
  107. package/src/esm/drawgl.js.map +1 -1
  108. package/src/esm/drawutilssvg.d.ts +233 -58
  109. package/src/esm/drawutilssvg.js +379 -95
  110. package/src/esm/drawutilssvg.js.map +1 -1
  111. package/src/esm/interfaces/DrawLib.d.ts +161 -82
  112. package/src/esm/interfaces/DrawLib.js +7 -0
  113. package/src/esm/interfaces/DrawLib.js.map +1 -1
  114. package/src/esm/interfaces/core.d.ts +46 -32
  115. package/src/esm/interfaces/core.js +2 -0
  116. package/src/esm/interfaces/core.js.map +1 -1
  117. package/src/esm/utils/datastructures/Color.d.ts +3 -1
  118. package/src/esm/utils/datastructures/Color.js +12 -1
  119. package/src/esm/utils/datastructures/Color.js.map +1 -1
  120. package/src/esm/utils/detectDarkMode.d.ts +10 -0
  121. package/src/esm/utils/detectDarkMode.js +28 -0
  122. package/src/esm/utils/detectDarkMode.js.map +1 -0
  123. package/src/ts/BezierPath.ts +74 -244
  124. package/src/ts/Bounds.ts +25 -1
  125. package/src/ts/CubicBezierCurve.ts +139 -12
  126. package/src/ts/Line.ts +2 -1
  127. package/src/ts/PBText.ts +10 -9
  128. package/src/ts/PlotBoilerplate.ts +130 -50
  129. package/src/ts/Polygon.ts +91 -1
  130. package/src/ts/Triangle.ts +2 -1
  131. package/src/ts/VEllipse.ts +2 -2
  132. package/src/ts/Vector.ts +4 -4
  133. package/src/ts/VertTuple.ts +4 -3
  134. package/src/ts/Vertex.ts +20 -4
  135. package/src/ts/draw.ts +316 -119
  136. package/src/ts/drawgl.ts +141 -78
  137. package/src/ts/drawutilssvg.ts +562 -133
  138. package/src/ts/interfaces/DrawLib.ts +223 -86
  139. package/src/ts/interfaces/core.ts +47 -32
  140. package/src/ts/utils/datastructures/Color.ts +13 -1
  141. package/src/ts/utils/detectDarkMode.ts +30 -0
@@ -78,7 +78,12 @@
78
78
  * @modified 2022-10-25 Added the `origin` to the default draw config.
79
79
  * @modified 2022-11-06 Adding an XML declaration to the SVG export routine.
80
80
  * @modified 2022-11-23 Added the `drawRaster` (default=true) option to the config/drawconfig.
81
- * @version 1.17.0
81
+ * @modified 2023-02-04 Fixed a bug in the `drawDrawable` function; fill's current classname was not set.
82
+ * @modified 2023-02-10 Fixing an issue of the `style.position` setting when `fitToParent=true` from `absolute` to `static` (default).
83
+ * @modified 2023-02-10 Cleaning up most type errors in the main class (mostly null checks).
84
+ * @modified 2023-02-10 Adding `enableZoom` and `enablePan` (both default true) to have the option to disable these functions.
85
+ * @modified 2023-09-29 Adding proper dicionary key and value types to the params of `PlotBoilerplate.utils.safeMergeByKeys` (was `object` before).
86
+ * @version 1.17.3
82
87
  *
83
88
  * @file PlotBoilerplate
84
89
  * @fileoverview The main class.
@@ -189,6 +194,8 @@ export class PlotBoilerplate {
189
194
  * @param {boolean=} [config.enableTouch=true] - Indicates if the application should handle touch events for you.
190
195
  * @param {boolean=} [config.enableKeys=true] - Indicates if the application should handle key events for you.
191
196
  * @param {boolean=} [config.enableMouseWheel=true] - Indicates if the application should handle mouse wheel events for you.
197
+ * @param {boolean=} [config.enablePan=true] - (default true) Set to false if you want to disable panning completely.
198
+ * @param {boolean=} [config.enableZoom=true] - (default true) Set to false if you want to disable zooming completely.
192
199
  * @param {boolean=} [config.enableGL=false] - Indicates if the application should use the experimental WebGL features (not recommended).
193
200
  * @param {boolean=} [config.enableSVGExport=true] - Indicates if the SVG export should be enabled (default is true).
194
201
  * Note that changes from the postDraw hook might not be visible in the export.
@@ -215,7 +222,7 @@ export class PlotBoilerplate {
215
222
  draggable: true,
216
223
  visible: true
217
224
  };
218
- if (typeof config.canvas == "undefined") {
225
+ if (typeof config.canvas === "undefined") {
219
226
  throw "No canvas specified.";
220
227
  }
221
228
  /**
@@ -269,6 +276,8 @@ export class PlotBoilerplate {
269
276
  enableTouch: f.bool(config, "enableTouch", true),
270
277
  enableKeys: f.bool(config, "enableKeys", true),
271
278
  enableMouseWheel: f.bool(config, "enableMouseWheel", true),
279
+ enableZoom: f.bool(config, "enableZoom", true),
280
+ enablePan: f.bool(config, "enablePan", true),
272
281
  // Experimental (and unfinished)
273
282
  enableGL: f.bool(config, "enableGL", false)
274
283
  }; // END confog
@@ -305,6 +314,10 @@ export class PlotBoilerplate {
305
314
  fill: true
306
315
  }
307
316
  },
317
+ // bezierPath: {
318
+ // color: "#0022a8",
319
+ // lineWidth: 1
320
+ // },
308
321
  polygon: {
309
322
  color: "#0022a8",
310
323
  lineWidth: 1
@@ -364,7 +377,10 @@ export class PlotBoilerplate {
364
377
  // +-------------------------------
365
378
  this.grid = new Grid(new Vertex(0, 0), new Vertex(50, 50));
366
379
  this.canvasSize = { width: PlotBoilerplate.DEFAULT_CANVAS_WIDTH, height: PlotBoilerplate.DEFAULT_CANVAS_HEIGHT };
367
- const canvasElement = typeof config.canvas == "string" ? document.querySelector(config.canvas) : config.canvas;
380
+ const canvasElement = typeof config.canvas === "string" ? document.querySelector(config.canvas) : config.canvas;
381
+ if (typeof canvasElement === "undefined") {
382
+ throw `Cannot initialize PlotBoilerplate with a null canvas (element "${config.canvas} not found).`;
383
+ }
368
384
  // Which renderer to use: Canvas2D, WebGL (experimental) or SVG?
369
385
  if (canvasElement.tagName.toLowerCase() === "canvas") {
370
386
  this.canvas = canvasElement;
@@ -933,7 +949,7 @@ export class PlotBoilerplate {
933
949
  this.draw.setCurrentId(d.uid);
934
950
  this.fill.setCurrentId(d.uid);
935
951
  this.draw.setCurrentClassName(d.className);
936
- this.draw.setCurrentClassName(d.className);
952
+ this.fill.setCurrentClassName(d.className);
937
953
  this.drawDrawable(d, renderTime, draw, fill);
938
954
  }
939
955
  }
@@ -954,7 +970,13 @@ export class PlotBoilerplate {
954
970
  **/
955
971
  drawDrawable(d, renderTime, draw, fill) {
956
972
  if (d instanceof BezierPath) {
973
+ var curveIndex = 0;
957
974
  for (var c in d.bezierCurves) {
975
+ // Restore these settings again in each loop (will be overwritten)
976
+ this.draw.setCurrentId(`${d.uid}-${curveIndex}`);
977
+ this.fill.setCurrentId(`${d.uid}-${curveIndex}`);
978
+ this.draw.setCurrentClassName(d.className);
979
+ this.fill.setCurrentClassName(d.className);
958
980
  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);
959
981
  if (this.drawConfig.drawBezierHandlePoints && this.drawConfig.drawHandlePoints) {
960
982
  if (d.bezierCurves[c].startPoint.attr.visible) {
@@ -1006,12 +1028,13 @@ export class PlotBoilerplate {
1006
1028
  if (this.drawConfig.drawBezierHandleLines && this.drawConfig.drawHandleLines) {
1007
1029
  draw.setCurrentId(`${d.uid}_l0`);
1008
1030
  draw.setCurrentClassName(`${d.className}-start-line`);
1009
- draw.line(d.bezierCurves[c].startPoint, d.bezierCurves[c].startControlPoint, this.drawConfig.bezier.handleLine.color, this.drawConfig.bezier.handleLine.lineWidth);
1031
+ draw.handleLine(d.bezierCurves[c].startPoint, d.bezierCurves[c].startControlPoint);
1010
1032
  draw.setCurrentId(`${d.uid}_l1`);
1011
1033
  draw.setCurrentClassName(`${d.className}-end-line`);
1012
- draw.line(d.bezierCurves[c].endPoint, d.bezierCurves[c].endControlPoint, this.drawConfig.bezier.handleLine.color, this.drawConfig.bezier.handleLine.lineWidth);
1034
+ draw.handleLine(d.bezierCurves[c].endPoint, d.bezierCurves[c].endControlPoint);
1013
1035
  }
1014
- }
1036
+ curveIndex++;
1037
+ } // END for
1015
1038
  }
1016
1039
  else if (d instanceof Polygon) {
1017
1040
  draw.polygon(d, this.drawConfig.polygon.color, this.drawConfig.polygon.lineWidth);
@@ -1031,11 +1054,11 @@ export class PlotBoilerplate {
1031
1054
  draw.setCurrentId(`${d.uid}_e0`);
1032
1055
  draw.setCurrentClassName(`${d.className}-v-line`);
1033
1056
  // draw.line( d.center.clone().add(0,d.axis.y-d.center.y), d.axis, '#c8c8c8' );
1034
- draw.line(d.center.clone().add(0, d.signedRadiusV()).rotate(d.rotation, d.center), d.axis, "#c8c8c8");
1057
+ draw.handleLine(d.center.clone().add(0, d.signedRadiusV()).rotate(d.rotation, d.center), d.axis); // , "#c8c8c8");
1035
1058
  draw.setCurrentId(`${d.uid}_e1`);
1036
1059
  draw.setCurrentClassName(`${d.className}-h-line`);
1037
1060
  // draw.line( d.center.clone().add(d.axis.x-d.center.x,0), d.axis, '#c8c8c8' );
1038
- draw.line(d.center.clone().add(d.signedRadiusH(), 0).rotate(d.rotation, d.center), d.axis, "#c8c8c8");
1061
+ draw.handleLine(d.center.clone().add(d.signedRadiusH(), 0).rotate(d.rotation, d.center), d.axis); // , "#c8c8c8");
1039
1062
  }
1040
1063
  draw.setCurrentId(d.uid);
1041
1064
  draw.setCurrentClassName(`${d.className}`);
@@ -1122,10 +1145,10 @@ export class PlotBoilerplate {
1122
1145
  else {
1123
1146
  console.error("Cannot draw object. Unknown class.");
1124
1147
  }
1125
- draw.setCurrentClassName(undefined);
1126
- draw.setCurrentId(undefined);
1127
- fill.setCurrentClassName(undefined);
1128
- fill.setCurrentId(undefined);
1148
+ draw.setCurrentClassName(null);
1149
+ draw.setCurrentId(null);
1150
+ fill.setCurrentClassName(null);
1151
+ fill.setCurrentId(null);
1129
1152
  }
1130
1153
  /**
1131
1154
  * Draw the select-polygon (if there is one).
@@ -1215,8 +1238,8 @@ export class PlotBoilerplate {
1215
1238
  this.drawSelectPolygon(draw);
1216
1239
  // Clear IDs and classnames (postDraw hook might draw somthing and the do not want
1217
1240
  // to interfered with that).
1218
- draw.setCurrentId(undefined);
1219
- draw.setCurrentClassName(undefined);
1241
+ draw.setCurrentId(null);
1242
+ draw.setCurrentClassName(null);
1220
1243
  } // END redraw
1221
1244
  /**
1222
1245
  * This function clears the canvas with the configured background color.<br>
@@ -1352,7 +1375,7 @@ export class PlotBoilerplate {
1352
1375
  }
1353
1376
  else if (_self.config.fitToParent) {
1354
1377
  // Set editor size
1355
- _self.canvas.style.position = "absolute";
1378
+ _self.canvas.style.position = "static";
1356
1379
  const space = this.getAvailableContainerSpace();
1357
1380
  _self.canvas.style.width = ((_c = _self.config.canvasWidthFactor) !== null && _c !== void 0 ? _c : 1.0) * space.width + "px";
1358
1381
  _self.canvas.style.height = ((_d = _self.config.canvasHeightFactor) !== null && _d !== void 0 ? _d : 1.0) * space.height + "px";
@@ -1423,24 +1446,24 @@ export class PlotBoilerplate {
1423
1446
  **/
1424
1447
  handleClick(e) {
1425
1448
  const _self = this;
1426
- var p = this.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX, _self.config.cssScaleY));
1427
- if (p) {
1428
- _self.vertices[p.vindex].listeners.fireClickEvent(e);
1449
+ 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));
1450
+ if (point) {
1451
+ _self.vertices[point.vindex].listeners.fireClickEvent(e);
1429
1452
  if (this.keyHandler && this.keyHandler.isDown("shift")) {
1430
- if (p.typeName == "bpath") {
1431
- let vert = _self.paths[p.pindex].bezierCurves[p.cindex].getPointByID(p.pid);
1453
+ if (point.typeName == "bpath") {
1454
+ let vert = _self.paths[point.pindex].bezierCurves[point.cindex].getPointByID(point.pid);
1432
1455
  if (vert.attr.selectable)
1433
1456
  vert.attr.isSelected = !vert.attr.isSelected;
1434
1457
  }
1435
- else if (p.typeName == "vertex") {
1436
- let vert = _self.vertices[p.vindex];
1458
+ else if (point.typeName == "vertex") {
1459
+ let vert = _self.vertices[point.vindex];
1437
1460
  if (vert.attr.selectable)
1438
1461
  vert.attr.isSelected = !vert.attr.isSelected;
1439
1462
  }
1440
1463
  _self.redraw();
1441
1464
  }
1442
- else if (this.keyHandler.isDown("y")) {
1443
- _self.vertices[p.vindex].attr.bezierAutoAdjust = !_self.vertices[p.vindex].attr.bezierAutoAdjust;
1465
+ else if (this.keyHandler && this.keyHandler.isDown("y")) {
1466
+ _self.vertices[point.vindex].attr.bezierAutoAdjust = !_self.vertices[point.vindex].attr.bezierAutoAdjust;
1444
1467
  _self.redraw();
1445
1468
  }
1446
1469
  }
@@ -1507,11 +1530,11 @@ export class PlotBoilerplate {
1507
1530
  const _self = this;
1508
1531
  if (e.button != 0)
1509
1532
  return; // Only react on left mouse or touch events
1510
- var p = _self.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX, _self.config.cssScaleY));
1511
- if (!p)
1533
+ 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));
1534
+ if (!draggablePoint)
1512
1535
  return;
1513
1536
  // Drag all selected elements?
1514
- if (p.typeName == "vertex" && _self.vertices[p.vindex].attr.isSelected) {
1537
+ if (draggablePoint.typeName == "vertex" && _self.vertices[draggablePoint.vindex].attr.isSelected) {
1515
1538
  // Multi drag
1516
1539
  // for( var i in _self.vertices ) {
1517
1540
  for (var i = 0; i < _self.vertices.length; i++) {
@@ -1523,13 +1546,15 @@ export class PlotBoilerplate {
1523
1546
  }
1524
1547
  else {
1525
1548
  // Single drag
1526
- if (!_self.vertices[p.vindex].attr.draggable)
1549
+ if (!_self.vertices[draggablePoint.vindex].attr.draggable)
1527
1550
  return;
1528
- _self.draggedElements.push(p);
1529
- if (p.typeName == "bpath")
1530
- _self.paths[p.pindex].bezierCurves[p.cindex].getPointByID(p.pid).listeners.fireDragStartEvent(e);
1531
- else if (p.typeName == "vertex")
1532
- _self.vertices[p.vindex].listeners.fireDragStartEvent(e);
1551
+ _self.draggedElements.push(draggablePoint);
1552
+ if (draggablePoint.typeName == "bpath")
1553
+ _self.paths[draggablePoint.pindex].bezierCurves[draggablePoint.cindex]
1554
+ .getPointByID(draggablePoint.pid)
1555
+ .listeners.fireDragStartEvent(e);
1556
+ else if (draggablePoint.typeName == "vertex")
1557
+ _self.vertices[draggablePoint.vindex].listeners.fireDragStartEvent(e);
1533
1558
  }
1534
1559
  _self.redraw();
1535
1560
  }
@@ -1556,7 +1581,10 @@ export class PlotBoilerplate {
1556
1581
  // not this one. So this tab will never receive any [Ctrl-down] events
1557
1582
  // until next keypress; the implication is, that [Ctrl] would still
1558
1583
  // considered to be pressed which is not true.
1559
- if (this.keyHandler.isDown("alt") || this.keyHandler.isDown("spacebar")) {
1584
+ if (this.keyHandler && (this.keyHandler.isDown("alt") || this.keyHandler.isDown("spacebar"))) {
1585
+ if (!this.config.enablePan) {
1586
+ return;
1587
+ }
1560
1588
  _self.setOffset(_self.draw.offset.clone().add(e.params.dragAmount));
1561
1589
  _self.redraw();
1562
1590
  }
@@ -1625,6 +1653,9 @@ export class PlotBoilerplate {
1625
1653
  * @return {void}
1626
1654
  **/
1627
1655
  mouseWheelHandler(e) {
1656
+ if (!this.config.enableZoom) {
1657
+ return;
1658
+ }
1628
1659
  var zoomStep = 1.25; // Make configurable?
1629
1660
  // CHANGED replaced _self by this
1630
1661
  const _self = this;
@@ -1764,6 +1795,9 @@ export class PlotBoilerplate {
1764
1795
  if (evt.touches.length == 1 && draggedElement) {
1765
1796
  evt.preventDefault();
1766
1797
  evt.stopPropagation();
1798
+ if (!touchDownPos || !touchMovePos) {
1799
+ return;
1800
+ }
1767
1801
  var rel = relPos({ x: evt.touches[0].clientX, y: evt.touches[0].clientY });
1768
1802
  var trans = _self.transformMousePosition(rel.x, rel.y);
1769
1803
  var diff = new Vertex(_self.transformMousePosition(touchMovePos.x, touchMovePos.y)).difference(trans);
@@ -1788,6 +1822,9 @@ export class PlotBoilerplate {
1788
1822
  touchMovePos = new Vertex(rel);
1789
1823
  }
1790
1824
  else if (evt.touches.length == 2) {
1825
+ if (!this.config.enablePan) {
1826
+ return;
1827
+ }
1791
1828
  // If at least two fingers touch and move, then change the draw offset (panning).
1792
1829
  evt.preventDefault();
1793
1830
  evt.stopPropagation();
@@ -1800,6 +1837,9 @@ export class PlotBoilerplate {
1800
1837
  touchEnd: (evt) => {
1801
1838
  // Note: e.touches.length is 0 here
1802
1839
  if (draggedElement && draggedElement.typeName == "vertex") {
1840
+ if (!touchDownPos) {
1841
+ return;
1842
+ }
1803
1843
  var draggingVertex = _self.vertices[draggedElement.vindex];
1804
1844
  var fakeEvent = {
1805
1845
  isTouchEvent: true,
@@ -1832,9 +1872,17 @@ export class PlotBoilerplate {
1832
1872
  multiTouchStartScale = null;
1833
1873
  },
1834
1874
  pinch: (evt) => {
1875
+ if (!this.config.enableZoom) {
1876
+ return;
1877
+ }
1878
+ const touchItem0 = evt.touches.item(0);
1879
+ const touchItem1 = evt.touches.item(1);
1880
+ if (!evt.touches || !multiTouchStartScale || !touchItem0 || !touchItem1) {
1881
+ return;
1882
+ }
1835
1883
  // For pinching there must be at least two touch items
1836
- const fingerA = new Vertex(evt.touches.item(0).clientX, evt.touches.item(0).clientY);
1837
- const fingerB = new Vertex(evt.touches.item(1).clientX, evt.touches.item(1).clientY);
1884
+ const fingerA = new Vertex(touchItem0.clientX, touchItem0.clientY);
1885
+ const fingerB = new Vertex(touchItem1.clientX, touchItem1.clientY);
1838
1886
  const center = new Line(fingerA, fingerB).vertAt(0.5);
1839
1887
  _self.setZoom(multiTouchStartScale.x * evt.zoom, multiTouchStartScale.y * evt.zoom, center);
1840
1888
  _self.redraw();
@@ -1946,22 +1994,35 @@ PlotBoilerplate.utils = {
1946
1994
  **/
1947
1995
  safeMergeByKeys: (base, extension) => {
1948
1996
  for (var k in extension) {
1949
- if (!extension.hasOwnProperty(k))
1997
+ if (!extension.hasOwnProperty(k)) {
1950
1998
  continue;
1999
+ }
1951
2000
  if (base.hasOwnProperty(k)) {
1952
- var typ = typeof base[k];
2001
+ const typ = typeof base[k];
2002
+ const extVal = extension[k];
1953
2003
  try {
1954
- if (typ == "boolean")
1955
- base[k] = !!JSON.parse(extension[k]);
1956
- else if (typ == "number")
1957
- base[k] = JSON.parse(extension[k]) * 1;
1958
- else if (typ == "function" && typeof extension[k] == "function")
2004
+ if (typ == "boolean") {
2005
+ if (typeof extVal === "string")
2006
+ base[k] = Boolean(!!JSON.parse(extVal));
2007
+ else
2008
+ base[k] = extVal;
2009
+ }
2010
+ else if (typ == "number") {
2011
+ if (typeof extVal === "string")
2012
+ base[k] = Number(JSON.parse(extVal) * 1);
2013
+ else
2014
+ base[k] = extension[k];
2015
+ }
2016
+ else if (typ == "function" && typeof extVal == "function") {
1959
2017
  base[k] = extension[k];
1960
- else
2018
+ }
2019
+ else {
2020
+ // Probably a sting
1961
2021
  base[k] = extension[k];
2022
+ }
1962
2023
  }
1963
2024
  catch (e) {
1964
- console.error("error in key ", k, extension[k], e);
2025
+ console.error("error in key ", k, extVal, e);
1965
2026
  }
1966
2027
  }
1967
2028
  else {
@@ -1970,6 +2031,31 @@ PlotBoilerplate.utils = {
1970
2031
  }
1971
2032
  return base;
1972
2033
  },
2034
+ /*
2035
+ __safeMergeByKeys: <KeyType extends string | number | symbol, ValueType extends boolean | number | string | Function>(
2036
+ base: Record<KeyType, ValueType>,
2037
+ extension: Record<KeyType, string>
2038
+ ): Record<KeyType, ValueType> => {
2039
+ for (var k in extension) {
2040
+ if (!extension.hasOwnProperty(k)) continue;
2041
+ if (base.hasOwnProperty(k)) {
2042
+ var typ = typeof base[k];
2043
+ try {
2044
+ if (typ == "boolean") base[k] = !!JSON.parse(extension[k]);
2045
+ else if (typ == "number") base[k] = JSON.parse(extension[k]) * 1;
2046
+ else if (typ == "function" && typeof extension[k] == "function") base[k] = extension[k];
2047
+ else base[k] = extension[k];
2048
+ } catch (e) {
2049
+ console.error("error in key ", k, extension[k], e);
2050
+ }
2051
+ } else {
2052
+ base[k] = extension[k];
2053
+ }
2054
+ }
2055
+ return base;
2056
+ },
2057
+ *()
2058
+
1973
2059
  /**
1974
2060
  * A helper function to scale elements (usually the canvas) using CSS.
1975
2061
  *
@@ -1982,8 +2068,10 @@ PlotBoilerplate.utils = {
1982
2068
  **/
1983
2069
  setCSSscale: (element, scaleX, scaleY) => {
1984
2070
  element.style["transform-origin"] = "0 0";
1985
- if (scaleX == 1.0 && scaleY == 1.0)
1986
- element.style.transform = null;
2071
+ if (scaleX == 1.0 && scaleY == 1.0) {
2072
+ // element.style.transform = null;
2073
+ element.style.removeProperty("transform");
2074
+ }
1987
2075
  else
1988
2076
  element.style.transform = "scale(" + scaleX + "," + scaleY + ")";
1989
2077
  },