plotboilerplate 1.13.0 → 1.14.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.
@@ -882,6 +882,35 @@ var BezierPath = /** @class */ (function () {
882
882
  this.updateArcLengths();
883
883
  return this;
884
884
  };
885
+ /**
886
+ * Scale the whole bezier path by the given uniform factor.
887
+ *
888
+ * @method scale
889
+ * @param {Vertex} anchor - The scale origin to scale from.
890
+ * @param {number} scaleFactor - The scalar to be multiplied with.
891
+ * @instance
892
+ * @memberof BezierPath
893
+ * @return {BezierPath} this for chaining.
894
+ **/
895
+ BezierPath.prototype.scale = function (anchor, scaleFactor) {
896
+ // var scaleFactors : XYCoords = { x : scaleFactor, y : scaleFactor };
897
+ // for (var i = 0; i < this.bezierCurves.length; i++) {
898
+ // var curve = this.bezierCurves[i];
899
+ // curve.getStartPoint().scale(scaleFactor, anchor);
900
+ // curve.getStartControlPoint().scale(scaleFactor, anchor);
901
+ // curve.getEndControlPoint().scale(scaleFactor, anchor);
902
+ // // Do NOT scale the end point here!
903
+ // // Don't forget that the curves are connected and on curve's end point
904
+ // // the the successor's start point (same instance)!
905
+ // }
906
+ // // Finally move the last end point (was not scaled yet)
907
+ // if (this.bezierCurves.length > 0 && !this.adjustCircular) {
908
+ // this.bezierCurves[this.bezierCurves.length - 1].getEndPoint().scale(scaleFactor, anchor);
909
+ // }
910
+ // this.updateArcLengths();
911
+ // return this;
912
+ return this.scaleXY({ x: scaleFactor, y: scaleFactor }, anchor);
913
+ };
885
914
  /**
886
915
  * Scale the whole bezier path by the given (x,y)-factors.
887
916
  *
@@ -892,19 +921,19 @@ var BezierPath = /** @class */ (function () {
892
921
  * @memberof BezierPath
893
922
  * @return {BezierPath} this for chaining.
894
923
  **/
895
- BezierPath.prototype.scale = function (anchor, scaling) {
924
+ BezierPath.prototype.scaleXY = function (scaleFactors, anchor) {
896
925
  for (var i = 0; i < this.bezierCurves.length; i++) {
897
926
  var curve = this.bezierCurves[i];
898
- curve.getStartPoint().scale(scaling, anchor);
899
- curve.getStartControlPoint().scale(scaling, anchor);
900
- curve.getEndControlPoint().scale(scaling, anchor);
927
+ curve.getStartPoint().scaleXY(scaleFactors, anchor);
928
+ curve.getStartControlPoint().scaleXY(scaleFactors, anchor);
929
+ curve.getEndControlPoint().scaleXY(scaleFactors, anchor);
901
930
  // Do NOT scale the end point here!
902
931
  // Don't forget that the curves are connected and on curve's end point
903
932
  // the the successor's start point (same instance)!
904
933
  }
905
934
  // Finally move the last end point (was not scaled yet)
906
935
  if (this.bezierCurves.length > 0 && !this.adjustCircular) {
907
- this.bezierCurves[this.bezierCurves.length - 1].getEndPoint().scale(scaling, anchor);
936
+ this.bezierCurves[this.bezierCurves.length - 1].getEndPoint().scaleXY(scaleFactors, anchor);
908
937
  }
909
938
  this.updateArcLengths();
910
939
  return this;
@@ -4447,7 +4476,7 @@ var PlotBoilerplate = /** @class */ (function () {
4447
4476
  var blob = new Blob([svgCode], { type: "image/svg;charset=utf-8" });
4448
4477
  // See documentation for FileSaver.js for usage.
4449
4478
  // https://github.com/eligrey/FileSaver.js
4450
- if (typeof globalThis["saveAs"] != "function")
4479
+ if (typeof globalThis["saveAs"] !== "function")
4451
4480
  throw "Cannot save file; did you load the ./utils/savefile helper function and the eligrey/SaveFile library?";
4452
4481
  var _saveAs = globalThis["saveAs"];
4453
4482
  _saveAs(blob, "plotboilerplate.svg");
@@ -4553,7 +4582,6 @@ var PlotBoilerplate = /** @class */ (function () {
4553
4582
  PlotBoilerplate.prototype.add = function (drawable, redraw) {
4554
4583
  if (Array.isArray(drawable)) {
4555
4584
  var arr = drawable;
4556
- // for( var i in arr )
4557
4585
  for (var i = 0; i < arr.length; i++) {
4558
4586
  this.add(arr[i], false);
4559
4587
  }
@@ -4599,9 +4627,9 @@ var PlotBoilerplate = /** @class */ (function () {
4599
4627
  }
4600
4628
  else if (drawable instanceof Polygon_1.Polygon) {
4601
4629
  this.drawables.push(drawable);
4602
- // for( var i in drawable.vertices )
4603
- for (var i = 0; i < drawable.vertices.length; i++)
4630
+ for (var i = 0; i < drawable.vertices.length; i++) {
4604
4631
  this.vertices.push(drawable.vertices[i]);
4632
+ }
4605
4633
  }
4606
4634
  else if (drawable instanceof Triangle_1.Triangle) {
4607
4635
  this.drawables.push(drawable);
@@ -4613,8 +4641,9 @@ var PlotBoilerplate = /** @class */ (function () {
4613
4641
  this.drawables.push(drawable);
4614
4642
  var bezierPath = drawable;
4615
4643
  for (var i = 0; i < bezierPath.bezierCurves.length; i++) {
4616
- if (!drawable.adjustCircular && i == 0)
4644
+ if (!drawable.adjustCircular && i == 0) {
4617
4645
  this.vertices.push(bezierPath.bezierCurves[i].startPoint);
4646
+ }
4618
4647
  this.vertices.push(bezierPath.bezierCurves[i].endPoint);
4619
4648
  this.vertices.push(bezierPath.bezierCurves[i].startControlPoint);
4620
4649
  this.vertices.push(bezierPath.bezierCurves[i].endControlPoint);
@@ -4760,8 +4789,9 @@ var PlotBoilerplate = /** @class */ (function () {
4760
4789
  for (var i = 0; i < this.vertices.length; i++) {
4761
4790
  if (this.vertices[i] === vert) {
4762
4791
  this.vertices.splice(i, 1);
4763
- if (redraw)
4792
+ if (redraw) {
4764
4793
  this.redraw();
4794
+ }
4765
4795
  return;
4766
4796
  }
4767
4797
  }
@@ -5353,7 +5383,6 @@ var PlotBoilerplate = /** @class */ (function () {
5353
5383
  // Apply the zoom (the tolerant area should not shrink or grow when zooming)
5354
5384
  tolerance /= _self.draw.scale.x;
5355
5385
  // Search in vertices
5356
- // for( var vindex in _self.vertices ) {
5357
5386
  for (var vindex = 0; vindex < _self.vertices.length; vindex++) {
5358
5387
  var vert = _self.vertices[vindex];
5359
5388
  if ((vert.attr.draggable || vert.attr.selectable) && vert.distance(point) < tolerance) {
@@ -5373,10 +5402,7 @@ var PlotBoilerplate = /** @class */ (function () {
5373
5402
  * @return {void}
5374
5403
  **/
5375
5404
  PlotBoilerplate.prototype.handleClick = function (e) {
5376
- // x:number,y:number) {
5377
5405
  var _self = this;
5378
- // const x:number = e.params.pos.x;
5379
- //const y:number = e.params.pos.y;
5380
5406
  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));
5381
5407
  if (p) {
5382
5408
  _self.vertices[p.vindex].listeners.fireClickEvent(e);
@@ -5393,7 +5419,7 @@ var PlotBoilerplate = /** @class */ (function () {
5393
5419
  }
5394
5420
  _self.redraw();
5395
5421
  }
5396
- else if (this.keyHandler.isDown("y") /* && p.type=='bpath' && (p.pid==BezierPath.START_POINT || p.pid==BezierPath.END_POINT) */) {
5422
+ else if (this.keyHandler.isDown("y")) {
5397
5423
  _self.vertices[p.vindex].attr.bezierAutoAdjust = !_self.vertices[p.vindex].attr.bezierAutoAdjust;
5398
5424
  _self.redraw();
5399
5425
  }
@@ -5691,6 +5717,7 @@ var PlotBoilerplate = /** @class */ (function () {
5691
5717
  _self.draggedElements = [];
5692
5718
  };
5693
5719
  var afProps = {
5720
+ // touchStart: (evt: TouchEvent) => {
5694
5721
  touchStart: function (evt) {
5695
5722
  if (evt.touches.length == 1) {
5696
5723
  touchMovePos = new Vertex_1.Vertex(relPos_1({ x: evt.touches[0].clientX, y: evt.touches[0].clientY }));
@@ -5793,10 +5820,13 @@ var PlotBoilerplate = /** @class */ (function () {
5793
5820
  _self.redraw();
5794
5821
  }
5795
5822
  }; // END afProps
5796
- if (window["createAlloyFinger"])
5823
+ if (window["createAlloyFinger"]) {
5797
5824
  window["createAlloyFinger"](this.eventCatcher ? this.eventCatcher : this.canvas, afProps);
5798
- else
5825
+ }
5826
+ else {
5827
+ /* tslint:disable-next-line */
5799
5828
  new alloyfinger_typescript_1.default(this.eventCatcher ? this.eventCatcher : this.canvas, afProps);
5829
+ }
5800
5830
  }
5801
5831
  catch (e) {
5802
5832
  console.error("Failed to initialize AlloyFinger!");
@@ -8257,7 +8287,9 @@ exports.VertTuple = VertTuple;
8257
8287
  * @modified 2020-05-26 Added functions addX(number) and addY(number).
8258
8288
  * @modified 2020-10-30 Changed the warnings in `sub(...)` and `add(...)` into real errors.
8259
8289
  * @modified 2021-03-01 Changed the second param `center` in the `rotate` function from Vertex to XYCoords.
8260
- * @version 2.4.2
8290
+ * @modified 2021-12-01 Changed the type of param of `scale` to XYCoords.
8291
+ * @modified 2021-12-01 Added function `scaleXY` for non uniform scaling.
8292
+ * @version 2.5.0
8261
8293
  *
8262
8294
  * @file Vertex
8263
8295
  * @public
@@ -8603,20 +8635,35 @@ var Vertex = /** @class */ (function () {
8603
8635
  };
8604
8636
  /**
8605
8637
  * This is a vector-like behavior and 'scales' this vertex
8606
- * towards/from a given center.
8638
+ * towards/from a given center by one uniform scale factor.
8607
8639
  *
8608
8640
  * @method scale
8609
8641
  * @param {number} factor - The factor to 'scale' this vertex; 1.0 means no change.
8610
- * @param {Vertex=} center - The origin of scaling; default is (0,0).
8642
+ * @param {XYCoords=} center - The origin of scaling; default is (0,0).
8611
8643
  * @return {Vertex} this
8612
8644
  * @instance
8613
8645
  * @memberof Vertex
8614
8646
  **/
8615
8647
  Vertex.prototype.scale = function (factor, center) {
8616
- if (!center || typeof center === "undefined")
8617
- center = new Vertex(0, 0);
8618
- this.x = center.x + (this.x - center.x) * factor;
8619
- this.y = center.y + (this.y - center.y) * factor;
8648
+ return this.scaleXY({ x: factor, y: factor }, center);
8649
+ };
8650
+ /**
8651
+ * This is a vector-like behavior and 'scales' this vertex
8652
+ * towards/from a given center by two independent x- and y- scale factors.
8653
+ *
8654
+ * @method scale
8655
+ * @param {number} factor - The factor to 'scale' this vertex; 1.0 means no change.
8656
+ * @param {XYCoords=} center - The origin of scaling; default is (0,0).
8657
+ * @return {Vertex} this
8658
+ * @instance
8659
+ * @memberof Vertex
8660
+ **/
8661
+ Vertex.prototype.scaleXY = function (factors, center) {
8662
+ if (!center || typeof center === "undefined") {
8663
+ center = { x: 0, y: 0 };
8664
+ }
8665
+ this.x = center.x + (this.x - center.x) * factors.x;
8666
+ this.y = center.y + (this.y - center.y) * factors.y;
8620
8667
  return this;
8621
8668
  };
8622
8669
  /**