jmgraph 3.2.21 → 3.2.22
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 +64 -21
- package/dist/jmgraph.min.js +1 -1
- package/package.json +1 -1
- package/src/core/jmControl.js +9 -1
- package/src/core/jmGraph.js +14 -8
- package/src/lib/webgl/path.js +8 -2
- package/src/shapes/jmArc.js +21 -7
package/package.json
CHANGED
package/src/core/jmControl.js
CHANGED
|
@@ -1114,7 +1114,15 @@ export default class jmControl extends jmProperty {
|
|
|
1114
1114
|
* @param {array} args 事件参数数组
|
|
1115
1115
|
*/
|
|
1116
1116
|
emit(...args) {
|
|
1117
|
-
|
|
1117
|
+
// 避免每帧 args.slice(1) 分配临时数组
|
|
1118
|
+
// runEventHandle 内部会把非数组参数包装成数组
|
|
1119
|
+
if(args.length > 2) {
|
|
1120
|
+
this.runEventHandle(args[0], args.slice(1));
|
|
1121
|
+
} else if(args.length === 2) {
|
|
1122
|
+
this.runEventHandle(args[0], [args[1]]);
|
|
1123
|
+
} else {
|
|
1124
|
+
this.runEventHandle(args[0], []);
|
|
1125
|
+
}
|
|
1118
1126
|
return this;
|
|
1119
1127
|
}
|
|
1120
1128
|
|
package/src/core/jmGraph.js
CHANGED
|
@@ -412,13 +412,19 @@ export default class jmGraph extends jmControl {
|
|
|
412
412
|
this.context.clearRect(0, 0, w, h);
|
|
413
413
|
}
|
|
414
414
|
else if(this.mode === 'webgl' && this.context.clear) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
a
|
|
420
|
-
}
|
|
421
|
-
this.
|
|
415
|
+
// 缓存 clearColor 对象,避免每帧创建
|
|
416
|
+
if(this.style && this.style.fill) {
|
|
417
|
+
const color = this.utils.hexToRGBA(this.style.fill);
|
|
418
|
+
this.__lastClearColor = color;
|
|
419
|
+
this.context.clearColor(color.r, color.g, color.b, color.a);
|
|
420
|
+
}
|
|
421
|
+
else if(!this.__lastClearColor) {
|
|
422
|
+
this.__lastClearColor = { r: 0, g: 0, b: 0, a: 0 };
|
|
423
|
+
this.context.clearColor(0, 0, 0, 0);
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
this.context.clearColor(this.__lastClearColor.r, this.__lastClearColor.g, this.__lastClearColor.b, this.__lastClearColor.a);
|
|
427
|
+
}
|
|
422
428
|
this.context.clear(this.context.COLOR_BUFFER_BIT); // 清空颜色缓冲区,也就是清空画布
|
|
423
429
|
}
|
|
424
430
|
}
|
|
@@ -745,7 +751,7 @@ export default class jmGraph extends jmControl {
|
|
|
745
751
|
// 触发刷新事件
|
|
746
752
|
self.emit('update', time);
|
|
747
753
|
|
|
748
|
-
|
|
754
|
+
// 直接 requestAnimationFrame,无需先 cancel
|
|
749
755
|
self.__requestAnimationFrameFunHandler = self.requestAnimationFrame(update);
|
|
750
756
|
if(callback) callback();
|
|
751
757
|
}
|
package/src/lib/webgl/path.js
CHANGED
|
@@ -55,8 +55,14 @@ class WebglPath extends WebglBase {
|
|
|
55
55
|
//this.useProgram();
|
|
56
56
|
|
|
57
57
|
if(parentBounds) this.parentAbsoluteBounds = parentBounds;
|
|
58
|
-
//
|
|
59
|
-
|
|
58
|
+
// 缓存中心点值,只在变化时才更新 uniform
|
|
59
|
+
const cx = this.graph.width / 2;
|
|
60
|
+
const cy = this.graph.height / 2;
|
|
61
|
+
if(this.__lastCenterX !== cx || this.__lastCenterY !== cy) {
|
|
62
|
+
this.context.uniform2f(this.program.uniforms.a_center_point.location, cx, cy);
|
|
63
|
+
this.__lastCenterX = cx;
|
|
64
|
+
this.__lastCenterY = cy;
|
|
65
|
+
}
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
setFragColor(color) {
|
package/src/shapes/jmArc.js
CHANGED
|
@@ -123,7 +123,6 @@ export default class jmArc extends jmPath {
|
|
|
123
123
|
if((mw == 0 && mh == 0) || start == end) return;
|
|
124
124
|
|
|
125
125
|
let anticlockwise = this.anticlockwise;
|
|
126
|
-
this.points = [];
|
|
127
126
|
let step = 1 / Math.max(mw, mh);
|
|
128
127
|
|
|
129
128
|
//如果是逆时针绘制,则角度为负数,并且结束角为2Math.PI-end
|
|
@@ -134,18 +133,33 @@ export default class jmArc extends jmPath {
|
|
|
134
133
|
}
|
|
135
134
|
if(start > end) step = -step;
|
|
136
135
|
|
|
137
|
-
|
|
136
|
+
// 预计算需要的点数量
|
|
137
|
+
let pointCount = Math.ceil(Math.abs(end - start) / Math.abs(step)) + 1;
|
|
138
|
+
if(this.isFan) pointCount++;
|
|
139
|
+
|
|
140
|
+
// 复用已有数组,避免每帧分配;大小变化时才重建
|
|
141
|
+
if(!this.points || this.points.length !== pointCount) {
|
|
142
|
+
this.points = new Array(pointCount);
|
|
143
|
+
for(let i = 0; i < pointCount; i++) {
|
|
144
|
+
this.points[i] = { x: 0, y: 0 };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let idx = 0;
|
|
149
|
+
if(this.isFan) {
|
|
150
|
+
this.points[idx].x = location.center.x;
|
|
151
|
+
this.points[idx].y = location.center.y;
|
|
152
|
+
idx++;
|
|
153
|
+
}
|
|
138
154
|
|
|
139
155
|
//椭圆方程x=a*cos(r) ,y=b*sin(r)
|
|
140
156
|
for(let r=start;;r += step) {
|
|
141
157
|
if(step > 0 && r > end) r = end;
|
|
142
158
|
else if(step < 0 && r < end) r = end;
|
|
143
159
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
};
|
|
148
|
-
this.points.push(p);
|
|
160
|
+
this.points[idx].x = Math.cos(r) * mw + cx;
|
|
161
|
+
this.points[idx].y = Math.sin(r) * mh + cy;
|
|
162
|
+
idx++;
|
|
149
163
|
|
|
150
164
|
if(r == end) break;
|
|
151
165
|
}
|