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.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +44 -24
- package/dist/jmgraph.min.js +1 -1
- package/example/progress.html +1 -1
- package/package.json +1 -1
- package/src/core/jmGraph.js +7 -1
- package/src/lib/webgl/base.js +6 -0
- package/src/lib/webgl/path.js +8 -11
package/example/progress.html
CHANGED
package/package.json
CHANGED
package/src/core/jmGraph.js
CHANGED
|
@@ -73,7 +73,13 @@ export default class jmGraph extends jmControl {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
this.canvas = canvas;
|
|
76
|
-
|
|
76
|
+
// Create context with preserveDrawingBuffer for webgl to prevent flickering
|
|
77
|
+
if(this.mode === 'webgl') {
|
|
78
|
+
this.context = canvas.getContext(this.mode, { preserveDrawingBuffer: true });
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.context = canvas.getContext(this.mode);
|
|
82
|
+
}
|
|
77
83
|
|
|
78
84
|
this.textureCanvas = option.textureCanvas || null;
|
|
79
85
|
|
package/src/lib/webgl/base.js
CHANGED
|
@@ -377,6 +377,10 @@ class WeblBase {
|
|
|
377
377
|
// 多边切割, 得到三角形顶点
|
|
378
378
|
// polygonIndices 顶点索引,
|
|
379
379
|
earCutPointsToTriangles(points) {
|
|
380
|
+
this.earCutCache = this.earCutCache || (this.earCutCache = {});
|
|
381
|
+
const key = JSON.stringify(points);
|
|
382
|
+
if (this.earCutCache[key]) return this.earCutCache[key];
|
|
383
|
+
|
|
380
384
|
const ps = this.earCutPoints(points);// 切割得到3角色顶点索引,
|
|
381
385
|
const triangles = [];
|
|
382
386
|
// 用顶点索引再组合成坐标数组
|
|
@@ -387,6 +391,8 @@ class WeblBase {
|
|
|
387
391
|
|
|
388
392
|
triangles.push([p1, p2, p3]);// 每三个顶点构成一个三角
|
|
389
393
|
}
|
|
394
|
+
|
|
395
|
+
this.earCutCache[key] = triangles;
|
|
390
396
|
return triangles;
|
|
391
397
|
}
|
|
392
398
|
|
package/src/lib/webgl/path.js
CHANGED
|
@@ -371,9 +371,9 @@ class WebglPath extends WebglBase {
|
|
|
371
371
|
// 分割成一个个规则的三角形,不规则的多边形不全割的话纹理就会没法正确覆盖
|
|
372
372
|
getTriangles(points) {
|
|
373
373
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
374
|
+
this.trianglesCache = this.trianglesCache||(this.trianglesCache={});
|
|
375
|
+
const key = JSON.stringify(points);
|
|
376
|
+
if(this.trianglesCache[key]) return this.trianglesCache[key];
|
|
377
377
|
|
|
378
378
|
const res = [];
|
|
379
379
|
const polygons = this.getPolygon(points);
|
|
@@ -384,7 +384,7 @@ class WebglPath extends WebglBase {
|
|
|
384
384
|
res.push(...triangles);
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
|
-
|
|
387
|
+
this.trianglesCache[key] = res;
|
|
388
388
|
return res;
|
|
389
389
|
}
|
|
390
390
|
|
|
@@ -486,18 +486,15 @@ class WebglPath extends WebglBase {
|
|
|
486
486
|
|
|
487
487
|
// 进行多边形填充
|
|
488
488
|
fillPolygons(points, isTexture = false) {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
//this.deleteBuffer(indexBuffer);
|
|
492
|
-
/*if(points.length > 3 && (!regular || this.needCut)) {
|
|
493
|
-
const triangles = regular && this.needCut? this.earCutPointsToTriangles(points): this.getTriangles(points);
|
|
489
|
+
if(points.length > 3) {
|
|
490
|
+
const triangles = this.needCut? this.earCutPointsToTriangles(points): this.getTriangles(points);
|
|
494
491
|
if(triangles.length) {
|
|
495
492
|
for(const triangle of triangles) {
|
|
496
493
|
this.fillPolygons(triangle, isTexture);// 这里就变成了规则的图形了
|
|
497
494
|
}
|
|
498
495
|
}
|
|
499
496
|
}
|
|
500
|
-
else {
|
|
497
|
+
else {
|
|
501
498
|
const buffer = this.writePoints(points);
|
|
502
499
|
// 纹理坐标
|
|
503
500
|
const coordBuffer = isTexture? this.writePoints(points, this.program.attrs.a_text_coord): null;
|
|
@@ -505,7 +502,7 @@ class WebglPath extends WebglBase {
|
|
|
505
502
|
this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
|
|
506
503
|
this.deleteBuffer(buffer);
|
|
507
504
|
coordBuffer && this.deleteBuffer(coordBuffer);
|
|
508
|
-
|
|
505
|
+
}
|
|
509
506
|
}
|
|
510
507
|
|
|
511
508
|
// 填充图形
|