jmgraph 3.2.17 → 3.2.19

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/jmgraph.js CHANGED
@@ -2623,8 +2623,16 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2623
2623
  }
2624
2624
  }
2625
2625
 
2626
- _this.canvas = canvas;
2627
- _this.context = canvas.getContext(_this.mode);
2626
+ _this.canvas = canvas; // Create context with preserveDrawingBuffer for webgl to prevent flickering
2627
+
2628
+ if (_this.mode === 'webgl') {
2629
+ _this.context = canvas.getContext(_this.mode, {
2630
+ preserveDrawingBuffer: true
2631
+ });
2632
+ } else {
2633
+ _this.context = canvas.getContext(_this.mode);
2634
+ }
2635
+
2628
2636
  _this.textureCanvas = option.textureCanvas || null; // webgl模式
2629
2637
 
2630
2638
  if (_this.mode === 'webgl') {
@@ -5452,7 +5460,21 @@ var _texture = require("./core/texture.js");
5452
5460
 
5453
5461
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
5454
5462
 
5455
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
5463
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
5464
+
5465
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
5466
+
5467
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5468
+
5469
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
5470
+
5471
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5472
+
5473
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
5474
+
5475
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
5476
+
5477
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5456
5478
 
5457
5479
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5458
5480
 
@@ -5466,12 +5488,6 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
5466
5488
 
5467
5489
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
5468
5490
 
5469
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
5470
-
5471
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
5472
-
5473
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5474
-
5475
5491
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5476
5492
 
5477
5493
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -5496,12 +5512,109 @@ var WeblBase = /*#__PURE__*/function () {
5496
5512
  this.style = {
5497
5513
  globalAlpha: 1
5498
5514
  };
5515
+ this.stateStack = [];
5516
+ this.transformMatrix = [1, 0, 0, 1, 0, 0]; // 2D 变换矩阵
5499
5517
  }
5500
5518
 
5501
5519
  _createClass(WeblBase, [{
5502
5520
  key: "context",
5503
5521
  get: function get() {
5504
5522
  if (this.graph) return this.graph.context;
5523
+ } // 保存当前状态
5524
+
5525
+ }, {
5526
+ key: "save",
5527
+ value: function save() {
5528
+ this.stateStack.push({
5529
+ transformMatrix: _toConsumableArray(this.transformMatrix),
5530
+ style: _objectSpread({}, this.style)
5531
+ });
5532
+ } // 恢复上一个状态
5533
+
5534
+ }, {
5535
+ key: "restore",
5536
+ value: function restore() {
5537
+ if (this.stateStack.length > 0) {
5538
+ var state = this.stateStack.pop();
5539
+ this.transformMatrix = state.transformMatrix;
5540
+ this.style = state.style;
5541
+ }
5542
+ } // 平移变换
5543
+
5544
+ }, {
5545
+ key: "translate",
5546
+ value: function translate(x, y) {
5547
+ // 更新变换矩阵
5548
+ this.transformMatrix[4] += x * this.transformMatrix[0] + y * this.transformMatrix[2];
5549
+ this.transformMatrix[5] += x * this.transformMatrix[1] + y * this.transformMatrix[3];
5550
+ } // 缩放变换
5551
+
5552
+ }, {
5553
+ key: "scale",
5554
+ value: function scale(sx, sy) {
5555
+ // 更新变换矩阵
5556
+ this.transformMatrix[0] *= sx;
5557
+ this.transformMatrix[1] *= sx;
5558
+ this.transformMatrix[2] *= sy;
5559
+ this.transformMatrix[3] *= sy;
5560
+ } // 旋转变换
5561
+
5562
+ }, {
5563
+ key: "rotate",
5564
+ value: function rotate(angle) {
5565
+ var cos = Math.cos(angle);
5566
+ var sin = Math.sin(angle);
5567
+
5568
+ var _this$transformMatrix = _slicedToArray(this.transformMatrix, 6),
5569
+ a = _this$transformMatrix[0],
5570
+ b = _this$transformMatrix[1],
5571
+ c = _this$transformMatrix[2],
5572
+ d = _this$transformMatrix[3],
5573
+ tx = _this$transformMatrix[4],
5574
+ ty = _this$transformMatrix[5]; // 更新变换矩阵
5575
+
5576
+
5577
+ this.transformMatrix[0] = a * cos - b * sin;
5578
+ this.transformMatrix[1] = a * sin + b * cos;
5579
+ this.transformMatrix[2] = c * cos - d * sin;
5580
+ this.transformMatrix[3] = c * sin + d * cos;
5581
+ } // 矩阵变换
5582
+
5583
+ }, {
5584
+ key: "transform",
5585
+ value: function transform(a, b, c, d, e, f) {
5586
+ var _this$transformMatrix2 = _slicedToArray(this.transformMatrix, 6),
5587
+ currentA = _this$transformMatrix2[0],
5588
+ currentB = _this$transformMatrix2[1],
5589
+ currentC = _this$transformMatrix2[2],
5590
+ currentD = _this$transformMatrix2[3],
5591
+ currentE = _this$transformMatrix2[4],
5592
+ currentF = _this$transformMatrix2[5]; // 矩阵乘法
5593
+
5594
+
5595
+ this.transformMatrix[0] = a * currentA + b * currentC;
5596
+ this.transformMatrix[1] = a * currentB + b * currentD;
5597
+ this.transformMatrix[2] = c * currentA + d * currentC;
5598
+ this.transformMatrix[3] = c * currentB + d * currentD;
5599
+ this.transformMatrix[4] = e * currentA + f * currentC + currentE;
5600
+ this.transformMatrix[5] = e * currentB + f * currentD + currentF;
5601
+ } // 应用变换到点
5602
+
5603
+ }, {
5604
+ key: "applyTransform",
5605
+ value: function applyTransform(point) {
5606
+ var _this$transformMatrix3 = _slicedToArray(this.transformMatrix, 6),
5607
+ a = _this$transformMatrix3[0],
5608
+ b = _this$transformMatrix3[1],
5609
+ c = _this$transformMatrix3[2],
5610
+ d = _this$transformMatrix3[3],
5611
+ tx = _this$transformMatrix3[4],
5612
+ ty = _this$transformMatrix3[5];
5613
+
5614
+ return {
5615
+ x: a * point.x + c * point.y + tx,
5616
+ y: b * point.x + d * point.y + ty
5617
+ };
5505
5618
  } // 纹理绘制canvas
5506
5619
 
5507
5620
  }, {
@@ -5731,6 +5844,9 @@ var WeblBase = /*#__PURE__*/function () {
5731
5844
  }, {
5732
5845
  key: "earCutPointsToTriangles",
5733
5846
  value: function earCutPointsToTriangles(points) {
5847
+ this.earCutCache = this.earCutCache || (this.earCutCache = {});
5848
+ var key = JSON.stringify(points);
5849
+ if (this.earCutCache[key]) return this.earCutCache[key];
5734
5850
  var ps = this.earCutPoints(points); // 切割得到3角色顶点索引,
5735
5851
 
5736
5852
  var triangles = []; // 用顶点索引再组合成坐标数组
@@ -5742,6 +5858,7 @@ var WeblBase = /*#__PURE__*/function () {
5742
5858
  triangles.push([p1, p2, p3]); // 每三个顶点构成一个三角
5743
5859
  }
5744
5860
 
5861
+ this.earCutCache[key] = triangles;
5745
5862
  return triangles;
5746
5863
  } // 点坐标数组转为一维数组
5747
5864
 
@@ -6512,6 +6629,10 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
6512
6629
 
6513
6630
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
6514
6631
 
6632
+ function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
6633
+
6634
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
6635
+
6515
6636
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
6516
6637
 
6517
6638
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
@@ -6544,9 +6665,15 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
6544
6665
  _this.control = option.control;
6545
6666
  _this.points = [];
6546
6667
  return _this;
6547
- }
6668
+ } // 应用变换到点
6669
+
6548
6670
 
6549
6671
  _createClass(WebglPath, [{
6672
+ key: "applyTransform",
6673
+ value: function applyTransform(point) {
6674
+ return _get(_getPrototypeOf(WebglPath.prototype), "applyTransform", this).call(this, point);
6675
+ }
6676
+ }, {
6550
6677
  key: "setParentBounds",
6551
6678
  value: function setParentBounds() {
6552
6679
  var parentBounds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.parentAbsoluteBounds;
@@ -6631,7 +6758,9 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
6631
6758
  try {
6632
6759
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
6633
6760
  var p = _step2.value;
6634
- fixedPoints.push(p.x + this.parentAbsoluteBounds.left, p.y + this.parentAbsoluteBounds.top);
6761
+ // 应用变换矩阵
6762
+ var transformedPoint = this.applyTransform(p);
6763
+ fixedPoints.push(transformedPoint.x + this.parentAbsoluteBounds.left, transformedPoint.y + this.parentAbsoluteBounds.top);
6635
6764
  }
6636
6765
  } catch (err) {
6637
6766
  _iterator2.e(err);
@@ -6954,9 +7083,9 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
6954
7083
  }, {
6955
7084
  key: "getTriangles",
6956
7085
  value: function getTriangles(points) {
6957
- //this.trianglesCache = this.trianglesCache||(this.trianglesCache={});
6958
- //const key = JSON.stringify(points);
6959
- //if(this.trianglesCache[key]) return this.trianglesCache[key];
7086
+ this.trianglesCache = this.trianglesCache || (this.trianglesCache = {});
7087
+ var key = JSON.stringify(points);
7088
+ if (this.trianglesCache[key]) return this.trianglesCache[key];
6960
7089
  var res = [];
6961
7090
  var polygons = this.getPolygon(points);
6962
7091
 
@@ -6976,9 +7105,9 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
6976
7105
  } finally {
6977
7106
  _iterator3.f();
6978
7107
  }
6979
- } //this.trianglesCache[key] = res;
6980
-
7108
+ }
6981
7109
 
7110
+ this.trianglesCache[key] = res;
6982
7111
  return res;
6983
7112
  } // 画线条
6984
7113
 
@@ -7094,25 +7223,33 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
7094
7223
  key: "fillPolygons",
7095
7224
  value: function fillPolygons(points) {
7096
7225
  var isTexture = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
7097
- //const indexBuffer = this.createUint16Buffer(triangles, this.context.ELEMENT_ARRAY_BUFFER);
7098
- //this.context.drawElements(this.context.TRIANGLES, triangles.length, this.context.UNSIGMED_SHORT, 0);
7099
- //this.deleteBuffer(indexBuffer);
7100
-
7101
- /*if(points.length > 3 && (!regular || this.needCut)) {
7102
- const triangles = regular && this.needCut? this.earCutPointsToTriangles(points): this.getTriangles(points);
7103
- if(triangles.length) {
7104
- for(const triangle of triangles) {
7105
- this.fillPolygons(triangle, isTexture);// 这里就变成了规则的图形了
7106
- }
7226
+
7227
+ if (points.length > 3) {
7228
+ var triangles = this.needCut ? this.earCutPointsToTriangles(points) : this.getTriangles(points);
7229
+
7230
+ if (triangles.length) {
7231
+ var _iterator4 = _createForOfIteratorHelper(triangles),
7232
+ _step4;
7233
+
7234
+ try {
7235
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
7236
+ var triangle = _step4.value;
7237
+ this.fillPolygons(triangle, isTexture); // 这里就变成了规则的图形了
7238
+ }
7239
+ } catch (err) {
7240
+ _iterator4.e(err);
7241
+ } finally {
7242
+ _iterator4.f();
7107
7243
  }
7108
- }
7109
- else {*/
7110
- var buffer = this.writePoints(points); // 纹理坐标
7244
+ }
7245
+ } else {
7246
+ var buffer = this.writePoints(points); // 纹理坐标
7111
7247
 
7112
- var coordBuffer = isTexture ? this.writePoints(points, this.program.attrs.a_text_coord) : null;
7113
- this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
7114
- this.deleteBuffer(buffer);
7115
- coordBuffer && this.deleteBuffer(coordBuffer); //}
7248
+ var coordBuffer = isTexture ? this.writePoints(points, this.program.attrs.a_text_coord) : null;
7249
+ this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
7250
+ this.deleteBuffer(buffer);
7251
+ coordBuffer && this.deleteBuffer(coordBuffer);
7252
+ }
7116
7253
  } // 填充图形
7117
7254
 
7118
7255
  }, {