jmgraph 3.2.18 → 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') {
@@ -5836,6 +5844,9 @@ var WeblBase = /*#__PURE__*/function () {
5836
5844
  }, {
5837
5845
  key: "earCutPointsToTriangles",
5838
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];
5839
5850
  var ps = this.earCutPoints(points); // 切割得到3角色顶点索引,
5840
5851
 
5841
5852
  var triangles = []; // 用顶点索引再组合成坐标数组
@@ -5847,6 +5858,7 @@ var WeblBase = /*#__PURE__*/function () {
5847
5858
  triangles.push([p1, p2, p3]); // 每三个顶点构成一个三角
5848
5859
  }
5849
5860
 
5861
+ this.earCutCache[key] = triangles;
5850
5862
  return triangles;
5851
5863
  } // 点坐标数组转为一维数组
5852
5864
 
@@ -7071,9 +7083,9 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
7071
7083
  }, {
7072
7084
  key: "getTriangles",
7073
7085
  value: function getTriangles(points) {
7074
- //this.trianglesCache = this.trianglesCache||(this.trianglesCache={});
7075
- //const key = JSON.stringify(points);
7076
- //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];
7077
7089
  var res = [];
7078
7090
  var polygons = this.getPolygon(points);
7079
7091
 
@@ -7093,9 +7105,9 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
7093
7105
  } finally {
7094
7106
  _iterator3.f();
7095
7107
  }
7096
- } //this.trianglesCache[key] = res;
7097
-
7108
+ }
7098
7109
 
7110
+ this.trianglesCache[key] = res;
7099
7111
  return res;
7100
7112
  } // 画线条
7101
7113
 
@@ -7211,25 +7223,33 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
7211
7223
  key: "fillPolygons",
7212
7224
  value: function fillPolygons(points) {
7213
7225
  var isTexture = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
7214
- //const indexBuffer = this.createUint16Buffer(triangles, this.context.ELEMENT_ARRAY_BUFFER);
7215
- //this.context.drawElements(this.context.TRIANGLES, triangles.length, this.context.UNSIGMED_SHORT, 0);
7216
- //this.deleteBuffer(indexBuffer);
7217
-
7218
- /*if(points.length > 3 && (!regular || this.needCut)) {
7219
- const triangles = regular && this.needCut? this.earCutPointsToTriangles(points): this.getTriangles(points);
7220
- if(triangles.length) {
7221
- for(const triangle of triangles) {
7222
- this.fillPolygons(triangle, isTexture);// 这里就变成了规则的图形了
7223
- }
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();
7224
7243
  }
7225
- }
7226
- else {*/
7227
- var buffer = this.writePoints(points); // 纹理坐标
7244
+ }
7245
+ } else {
7246
+ var buffer = this.writePoints(points); // 纹理坐标
7228
7247
 
7229
- var coordBuffer = isTexture ? this.writePoints(points, this.program.attrs.a_text_coord) : null;
7230
- this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
7231
- this.deleteBuffer(buffer);
7232
- 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
+ }
7233
7253
  } // 填充图形
7234
7254
 
7235
7255
  }, {