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.js CHANGED
@@ -1598,7 +1598,16 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1598
1598
  args[_key] = arguments[_key];
1599
1599
  }
1600
1600
 
1601
- this.runEventHandle(args[0], args.slice(1));
1601
+ // 避免每帧 args.slice(1) 分配临时数组
1602
+ // runEventHandle 内部会把非数组参数包装成数组
1603
+ if (args.length > 2) {
1604
+ this.runEventHandle(args[0], args.slice(1));
1605
+ } else if (args.length === 2) {
1606
+ this.runEventHandle(args[0], [args[1]]);
1607
+ } else {
1608
+ this.runEventHandle(args[0], []);
1609
+ }
1610
+
1602
1611
  return this;
1603
1612
  }
1604
1613
  /**
@@ -3430,13 +3439,22 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
3430
3439
 
3431
3440
  this.context.clearRect(0, 0, w, h);
3432
3441
  } else if (this.mode === 'webgl' && this.context.clear) {
3433
- var color = this.style && this.style.fill ? this.utils.hexToRGBA(this.style.fill) : {
3434
- r: 0,
3435
- g: 0,
3436
- b: 0,
3437
- a: 0
3438
- };
3439
- this.context.clearColor(color.r, color.g, color.b, color.a); // 设置清空颜色缓冲时的颜色值
3442
+ // 缓存 clearColor 对象,避免每帧创建
3443
+ if (this.style && this.style.fill) {
3444
+ var color = this.utils.hexToRGBA(this.style.fill);
3445
+ this.__lastClearColor = color;
3446
+ this.context.clearColor(color.r, color.g, color.b, color.a);
3447
+ } else if (!this.__lastClearColor) {
3448
+ this.__lastClearColor = {
3449
+ r: 0,
3450
+ g: 0,
3451
+ b: 0,
3452
+ a: 0
3453
+ };
3454
+ this.context.clearColor(0, 0, 0, 0);
3455
+ } else {
3456
+ this.context.clearColor(this.__lastClearColor.r, this.__lastClearColor.g, this.__lastClearColor.b, this.__lastClearColor.a);
3457
+ }
3440
3458
 
3441
3459
  this.context.clear(this.context.COLOR_BUFFER_BIT); // 清空颜色缓冲区,也就是清空画布
3442
3460
  }
@@ -3808,8 +3826,8 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
3808
3826
  if (self.needUpdate) self.redraw();
3809
3827
  var time = Date.now() - refreshStartTime; // 触发刷新事件
3810
3828
 
3811
- self.emit('update', time);
3812
- self.__requestAnimationFrameFunHandler && self.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
3829
+ self.emit('update', time); // 直接 requestAnimationFrame,无需先 cancel
3830
+
3813
3831
  self.__requestAnimationFrameFunHandler = self.requestAnimationFrame(update);
3814
3832
  if (callback) callback();
3815
3833
  }
@@ -7456,9 +7474,16 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
7456
7474
  value: function setParentBounds() {
7457
7475
  var parentBounds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.parentAbsoluteBounds;
7458
7476
  //this.useProgram();
7459
- if (parentBounds) this.parentAbsoluteBounds = parentBounds; // 写入当前canvas大小
7477
+ if (parentBounds) this.parentAbsoluteBounds = parentBounds; // 缓存中心点值,只在变化时才更新 uniform
7478
+
7479
+ var cx = this.graph.width / 2;
7480
+ var cy = this.graph.height / 2;
7460
7481
 
7461
- this.context.uniform2f(this.program.uniforms.a_center_point.location, this.graph.width / 2, this.graph.height / 2);
7482
+ if (this.__lastCenterX !== cx || this.__lastCenterY !== cy) {
7483
+ this.context.uniform2f(this.program.uniforms.a_center_point.location, cx, cy);
7484
+ this.__lastCenterX = cx;
7485
+ this.__lastCenterY = cy;
7486
+ }
7462
7487
  }
7463
7488
  }, {
7464
7489
  key: "setFragColor",
@@ -8403,7 +8428,6 @@ var jmArc = /*#__PURE__*/function (_jmPath) {
8403
8428
  var end = this.endAngle;
8404
8429
  if (mw == 0 && mh == 0 || start == end) return;
8405
8430
  var anticlockwise = this.anticlockwise;
8406
- this.points = [];
8407
8431
  var step = 1 / Math.max(mw, mh); //如果是逆时针绘制,则角度为负数,并且结束角为2Math.PI-end
8408
8432
 
8409
8433
  if (anticlockwise) {
@@ -8412,17 +8436,36 @@ var jmArc = /*#__PURE__*/function (_jmPath) {
8412
8436
  end = p2 - end;
8413
8437
  }
8414
8438
 
8415
- if (start > end) step = -step;
8416
- if (this.isFan) this.points.push(location.center); // 如果是扇形,则从中心开始画
8417
- //椭圆方程x=a*cos(r) ,y=b*sin(r)
8439
+ if (start > end) step = -step; // 预计算需要的点数量
8440
+
8441
+ var pointCount = Math.ceil(Math.abs(end - start) / Math.abs(step)) + 1;
8442
+ if (this.isFan) pointCount++; // 复用已有数组,避免每帧分配;大小变化时才重建
8443
+
8444
+ if (!this.points || this.points.length !== pointCount) {
8445
+ this.points = new Array(pointCount);
8446
+
8447
+ for (var i = 0; i < pointCount; i++) {
8448
+ this.points[i] = {
8449
+ x: 0,
8450
+ y: 0
8451
+ };
8452
+ }
8453
+ }
8454
+
8455
+ var idx = 0;
8456
+
8457
+ if (this.isFan) {
8458
+ this.points[idx].x = location.center.x;
8459
+ this.points[idx].y = location.center.y;
8460
+ idx++;
8461
+ } //椭圆方程x=a*cos(r) ,y=b*sin(r)
8462
+
8418
8463
 
8419
8464
  for (var r = start;; r += step) {
8420
8465
  if (step > 0 && r > end) r = end;else if (step < 0 && r < end) r = end;
8421
- var p = {
8422
- x: Math.cos(r) * mw + cx,
8423
- y: Math.sin(r) * mh + cy
8424
- };
8425
- this.points.push(p);
8466
+ this.points[idx].x = Math.cos(r) * mw + cx;
8467
+ this.points[idx].y = Math.sin(r) * mh + cy;
8468
+ idx++;
8426
8469
  if (r == end) break;
8427
8470
  }
8428
8471