jmchart 1.2.0 → 1.2.2

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.
@@ -1663,9 +1663,6 @@ class jmControl extends jmProperty {
1663
1663
  style = style || jmUtils.clone(this.style, true);
1664
1664
  if(!style) return;
1665
1665
 
1666
- // 当前根据屏幕放大倍数,如果有倍数,则需要对线宽等同比放大
1667
- let scale = this.graph.devicePixelRatio;
1668
-
1669
1666
  /**
1670
1667
  * 样式设定
1671
1668
  *
@@ -1715,7 +1712,7 @@ class jmControl extends jmProperty {
1715
1712
  }
1716
1713
 
1717
1714
  // 按比例需要放大的样式
1718
- if(scale && style) {
1715
+ /*if(scale && style) {
1719
1716
  switch(mpname) {
1720
1717
  case 'lineWidth': {
1721
1718
  style *= scale;
@@ -1732,7 +1729,7 @@ class jmControl extends jmProperty {
1732
1729
  break;
1733
1730
  }
1734
1731
  }
1735
- }
1732
+ } */
1736
1733
  this.context[mpname] = style;
1737
1734
  }
1738
1735
  else {
@@ -1839,9 +1836,6 @@ class jmControl extends jmProperty {
1839
1836
  if(typeof this.canvas.width === 'function') {
1840
1837
  rect.right = this.canvas.width();
1841
1838
  }
1842
- else if(this.canvas.width) {
1843
- rect.right = this.canvas.width;
1844
- }
1845
1839
  else if(this.width) {
1846
1840
  rect.right = this.width;
1847
1841
  }
@@ -1849,9 +1843,6 @@ class jmControl extends jmProperty {
1849
1843
  if(typeof this.canvas.height === 'function') {
1850
1844
  rect.bottom = this.canvas.height();
1851
1845
  }
1852
- else if(this.canvas.height) {
1853
- rect.bottom = this.canvas.height;
1854
- }
1855
1846
  else if(this.height) {
1856
1847
  rect.bottom = this.height;
1857
1848
  }
@@ -1914,10 +1905,10 @@ class jmControl extends jmProperty {
1914
1905
  local.height = this.height;
1915
1906
 
1916
1907
  let margin = jmUtils.clone(this.style.margin, {});
1917
- margin.left = (margin.left || 0) * this.graph.devicePixelRatio;
1918
- margin.top = (margin.top || 0) * this.graph.devicePixelRatio;
1919
- margin.right = (margin.right || 0) * this.graph.devicePixelRatio;
1920
- margin.bottom = (margin.bottom || 0) * this.graph.devicePixelRatio;
1908
+ margin.left = (margin.left || 0);
1909
+ margin.top = (margin.top || 0);
1910
+ margin.right = (margin.right || 0);
1911
+ margin.bottom = (margin.bottom || 0);
1921
1912
 
1922
1913
  //如果没有指定位置,但指定了margin。则位置取margin偏移量
1923
1914
  if(local.position) {
@@ -2346,8 +2337,8 @@ class jmControl extends jmProperty {
2346
2337
  //获取dom位置
2347
2338
  let position = this.getPosition();
2348
2339
  // 由于高清屏会有放大坐标,所以这里用pagex就只能用真实的canvas大小
2349
- const right = position.left + (this.canvas.clientWidth || this.canvas.offsetWidth || this.canvas.width);
2350
- const bottom = position.top + (this.canvas.clientHeight || this.canvas.offsetHeight || this.canvas.height);
2340
+ const right = position.left + this.width;
2341
+ const bottom = position.top + this.height;
2351
2342
  if(p.pageX > right || p.pageX < position.left) {
2352
2343
  return false;
2353
2344
  }
@@ -2436,14 +2427,7 @@ class jmControl extends jmProperty {
2436
2427
 
2437
2428
  const srcElement = args.srcElement || args.target;
2438
2429
 
2439
- const position = jmUtils.getEventPosition(args, graph.scaleSize);//初始化事件位置
2440
-
2441
- // 如果有指定scale高清处理,需要对坐标处理
2442
- // 因为是对canvas放大N倍,再把style指定为当前大小,所以坐标需要放大N && srcElement === graph.canvas
2443
- if(graph.devicePixelRatio > 0) {
2444
- position.x = position.offsetX = position.x * graph.devicePixelRatio;
2445
- position.y = position.offsetY = position.y * graph.devicePixelRatio;
2446
- }
2430
+ const position = jmUtils.getEventPosition(args, graph.scaleSize);//初始化事件位置
2447
2431
 
2448
2432
  args = {
2449
2433
  position: position,
@@ -4719,11 +4703,19 @@ class jmGraph$1 extends jmControl {
4719
4703
  this.on('endDraw', function() {
4720
4704
  this.context.translate(-0.5, -0.5);
4721
4705
  });
4722
-
4706
+
4707
+ // devicePixelRatio初始化
4708
+ let dpr = typeof window != 'undefined' && window.devicePixelRatio > 1? window.devicePixelRatio : 1;
4709
+ if(this.isWXMiniApp) {
4710
+ dpr = wx.getSystemInfoSync().pixelRatio || 1;
4711
+ }
4712
+ this.devicePixelRatio = dpr;
4713
+ // 为了解决锯齿问题,先放大canvas再缩放
4714
+ this.dprScaleSize = this.devicePixelRatio > 1? this.devicePixelRatio : 2;
4715
+
4723
4716
  if(this.option.width > 0) this.width = this.option.width;
4724
4717
  if(this.option.height > 0) this.height = this.option.height;
4725
-
4726
- this.resize();
4718
+ this.resize();
4727
4719
 
4728
4720
  //绑定事件
4729
4721
  this.eventHandler = new jmEvents(this, this.canvas.canvas || this.canvas);
@@ -4738,25 +4730,19 @@ class jmGraph$1 extends jmControl {
4738
4730
 
4739
4731
  // 重置canvas大小,并判断高清屏,画图先放大二倍
4740
4732
  resize(w, h) {
4733
+ if(!this.canvas) return;
4741
4734
 
4742
- let scale = typeof window != 'undefined' && window.devicePixelRatio > 1? window.devicePixelRatio : 1;
4743
- if(this.isWXMiniApp) {
4744
- scale = wx.getSystemInfoSync().pixelRatio || 1;
4745
- }
4746
- else if (scale > 1) {
4747
- this.__normalSize = this.__normalSize || { width: 0, height: 0};
4748
- w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
4735
+ this.__normalSize = this.__normalSize || { width: 0, height: 0};
4736
+ w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
4749
4737
 
4750
- if(w) this.__normalSize.width = w;
4751
- if(h) this.__normalSize.height = h;
4752
-
4753
- this.canvas.style && (this.canvas.style.width = w + "px");
4754
- this.canvas.style && (this.canvas.style.height = h + "px");
4755
- this.canvas.height = h * scale;
4756
- this.canvas.width = w *scale;
4757
- this.context.scale(scale, scale);
4758
- this.devicePixelRatio = scale;
4759
- }
4738
+ if(w) this.__normalSize.width = w;
4739
+ if(h) this.__normalSize.height = h;
4740
+
4741
+ this.css('width', w + "px");
4742
+ this.css('height', h + "px");
4743
+ this.canvas.height = h * this.dprScaleSize;
4744
+ this.canvas.width = w * this.dprScaleSize;
4745
+ this.context.scale(this.dprScaleSize, this.dprScaleSize);
4760
4746
  }
4761
4747
 
4762
4748
  /**
@@ -4764,10 +4750,10 @@ class jmGraph$1 extends jmControl {
4764
4750
  * @param {x, y} point 内部坐标
4765
4751
  */
4766
4752
  pointToPixes(point) {
4767
- if(this.devicePixelRatio && this.devicePixelRatio !== 1) {
4753
+ if(this.dprScaleSize && this.dprScaleSize !== 1) {
4768
4754
  point = Object.assign({}, point, {
4769
- x: point.x / this.devicePixelRatio,
4770
- y: point.y / this.devicePixelRatio
4755
+ x: point.x / this.dprScaleSize,
4756
+ y: point.y / this.dprScaleSize
4771
4757
  });
4772
4758
  }
4773
4759
  return point;
@@ -4779,13 +4765,13 @@ class jmGraph$1 extends jmControl {
4779
4765
  * @type {number}
4780
4766
  */
4781
4767
  get width() {
4768
+ if(this.__normalSize && this.__normalSize.width) return this.__normalSize.width;
4782
4769
  if(this.canvas) return this.canvas.width;
4783
4770
  return 0;
4784
4771
  }
4785
4772
  set width(v) {
4786
4773
  this.needUpdate = true;
4787
4774
  if(this.canvas) {
4788
- this.canvas.width = v;
4789
4775
  this.resize(v);
4790
4776
  }
4791
4777
  return v;
@@ -4797,13 +4783,13 @@ class jmGraph$1 extends jmControl {
4797
4783
  * @type {number}
4798
4784
  */
4799
4785
  get height() {
4786
+ if(this.__normalSize && this.__normalSize.height) return this.__normalSize.height;
4800
4787
  if(this.canvas) return this.canvas.height;
4801
4788
  return 0;
4802
4789
  }
4803
4790
  set height(v) {
4804
4791
  this.needUpdate = true;
4805
4792
  if(this.canvas) {
4806
- this.canvas.height = v;
4807
4793
  this.resize(0, v);
4808
4794
  }
4809
4795
  return v;
@@ -4827,8 +4813,8 @@ class jmGraph$1 extends jmControl {
4827
4813
  */
4828
4814
  getPosition() {
4829
4815
  let p = jmUtils.getElementPosition(this.canvas.canvas || this.canvas);
4830
- p.width = this.canvas.width;
4831
- p.height = this.canvas.height;
4816
+ p.width = this.width;
4817
+ p.height = this.height;
4832
4818
  p.right = p.left + p.width;
4833
4819
  p.bottom = p.top + p.height;
4834
4820
  return p;
@@ -4962,23 +4948,13 @@ class jmGraph$1 extends jmControl {
4962
4948
  * @param {number} [h] 清除画布的高度
4963
4949
  */
4964
4950
  clear(w, h) {
4965
- //this.canvas.width = this.canvas.width;
4966
- if(w && h) {
4967
- //this.zoomActual();//恢复比例缩放
4968
- this.canvas.width = w;
4969
- this.canvas.height = h;
4970
- //保留原有缩放比例
4971
- if(this.scaleSize) {
4972
- if(this.context.scale) this.context.scale(this.scaleSize.x,this.scaleSize.y);
4973
- }
4974
- }
4975
- else {
4976
- w = this.canvas.width;
4977
- h = this.canvas.height;
4978
- if(this.scaleSize) {
4951
+ if(!w || !h) {
4952
+ w = this.width;
4953
+ h = this.height;
4954
+ /*if(this.scaleSize) {
4979
4955
  w = w / this.scaleSize.x;
4980
4956
  h = h / this.scaleSize.y;
4981
- }
4957
+ }*/
4982
4958
  }
4983
4959
  //如果有指定背景,则等到draw再全屏绘制一次,也同样达到清除画布的功能
4984
4960
  if(this.style && this.style.fill) {
@@ -5123,6 +5099,9 @@ class jmGraph$1 extends jmControl {
5123
5099
  return;// 已销毁
5124
5100
  }
5125
5101
  if(self.needUpdate) self.redraw();
5102
+ // 触发刷新事件
5103
+ self.emit('update');
5104
+
5126
5105
  self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5127
5106
  self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
5128
5107
  if(callback) callback();
@@ -5725,7 +5704,7 @@ class jmAxis extends jmArrowLine {
5725
5704
  //字符串轴。则显示每个标签
5726
5705
 
5727
5706
  const format = this.option.format || this.format;
5728
- const top = (this.style.xLabel.margin.top || 0) * this.graph.devicePixelRatio;
5707
+ const top = this.style.xLabel.margin.top || 0;
5729
5708
 
5730
5709
  for (let i = 0; i < this.data.length; i++) {
5731
5710
  const d = this.data[i];
@@ -5821,8 +5800,8 @@ class jmAxis extends jmArrowLine {
5821
5800
  const mm = max - min;
5822
5801
  let pervalue = mm / count || 1;
5823
5802
  const format = this.option.format || this.format;
5824
- const marginLeft = this.style.yLabel.margin.left * this.graph.devicePixelRatio || 0;
5825
- const marginRight = this.style.yLabel.margin.right * this.graph.devicePixelRatio || 0;
5803
+ const marginLeft = this.style.yLabel.margin.left || 0;
5804
+ const marginRight = this.style.yLabel.margin.right || 0;
5826
5805
  let p = 0;
5827
5806
 
5828
5807
  for (let i = 0; i < count + 1; i++) {
@@ -6250,13 +6229,13 @@ jmLegend.prototype.append = function (series, shape, options = {}) {
6250
6229
 
6251
6230
  if (legendPosition == 'top' || legendPosition == 'bottom') {
6252
6231
  //顶部和底部图例横排,每次右移位一个单位图例
6253
- panel.position.x = this.width + 15 * this.graph.devicePixelRatio;
6232
+ panel.position.x = this.width + 15;
6254
6233
  this.width = panel.position.x + panel.width; // 把容器宽指定为所有图例宽和
6255
6234
 
6256
6235
  this.height = Math.max(panel.height, this.height);
6257
6236
  } else {
6258
6237
  //右边和左边图例竖排
6259
- panel.position.y += this.height + 5 * this.graph.devicePixelRatio;
6238
+ panel.position.y += this.height + 5;
6260
6239
  this.height = panel.position.y + panel.height;
6261
6240
  this.width = Math.max(panel.width, this.width);
6262
6241
  }
@@ -6296,21 +6275,21 @@ jmLegend.prototype.reset = function () {
6296
6275
  {
6297
6276
  this.graph.chartArea.width = this.graph.chartArea.width - this.width; //画图区域向右偏移
6298
6277
 
6299
- this.graph.chartArea.position.x = this.position.x + this.width + this.style.margin.right * this.graph.devicePixelRatio;
6278
+ this.graph.chartArea.position.x = this.position.x + this.width + this.style.margin.right;
6300
6279
  break;
6301
6280
  }
6302
6281
 
6303
6282
  case 'top':
6304
6283
  {
6305
6284
  this.graph.chartArea.height = this.graph.chartArea.height - this.height;
6306
- this.graph.chartArea.position.y = this.position.y + this.height + this.style.margin.bottom * this.graph.devicePixelRatio;
6285
+ this.graph.chartArea.position.y = this.position.y + this.height + this.style.margin.bottom;
6307
6286
  break;
6308
6287
  }
6309
6288
 
6310
6289
  case 'bottom':
6311
6290
  {
6312
6291
  this.graph.chartArea.height = this.graph.chartArea.height - this.height;
6313
- this.position.y = this.graph.chartArea.position.y + this.graph.chartArea.height + this.style.margin.top * this.graph.devicePixelRatio;
6292
+ this.position.y = this.graph.chartArea.position.y + this.graph.chartArea.height + this.style.margin.top;
6314
6293
  break;
6315
6294
  }
6316
6295
 
@@ -6318,7 +6297,7 @@ jmLegend.prototype.reset = function () {
6318
6297
  default:
6319
6298
  {
6320
6299
  this.graph.chartArea.width = this.graph.chartArea.width - this.width;
6321
- this.position.x = this.graph.chartArea.position.x + this.graph.chartArea.width + this.style.margin.left * this.graph.devicePixelRatio;
6300
+ this.position.x = this.graph.chartArea.position.x + this.graph.chartArea.width + this.style.margin.left;
6322
6301
  break;
6323
6302
  }
6324
6303
  }
@@ -7065,7 +7044,7 @@ class jmPieSeries extends jmSeries {
7065
7044
  x: this.graph.chartArea.width / 2,
7066
7045
  y: this.graph.chartArea.height / 2
7067
7046
  };
7068
- const radius = Math.min(center.x - this.style.margin.left * this.graph.devicePixelRatio - this.style.margin.right * this.graph.devicePixelRatio, center.y - this.style.margin.top * this.graph.devicePixelRatio - this.style.margin.bottom * this.graph.devicePixelRatio); //生成描点位
7047
+ const radius = Math.min(center.x - this.style.margin.left - this.style.margin.right, center.y - this.style.margin.top - this.style.margin.bottom); //生成描点位
7069
7048
  // super.init会把参数透传给 createPoints
7070
7049
 
7071
7050
  const {
@@ -7431,7 +7410,7 @@ class jmRadarSeries extends jmSeries {
7431
7410
  x: this.graph.chartArea.width / 2,
7432
7411
  y: this.graph.chartArea.height / 2
7433
7412
  };
7434
- this.radius = Math.min(this.center.x - this.style.margin.left * this.graph.devicePixelRatio - this.style.margin.right * this.graph.devicePixelRatio, this.center.y - this.style.margin.top * this.graph.devicePixelRatio - this.style.margin.bottom * this.graph.devicePixelRatio);
7413
+ this.radius = Math.min(this.center.x - this.style.margin.left - this.style.margin.right, this.center.y - this.style.margin.top - this.style.margin.bottom);
7435
7414
  const axises = this.createAxises(this.center, this.radius); // 重置所有轴
7436
7415
  // 计算最大最小值
7437
7416
  // 当前需要先更新axis的边界值,轴好画图
@@ -8225,7 +8204,7 @@ class jmMarkLine extends jmLine {
8225
8204
  if (!p || typeof p.y === 'undefined') continue;
8226
8205
  this.markArc = graph.createShape('circle', {
8227
8206
  style: this.style,
8228
- radius: (this.style.radius || 5) * this.graph.devicePixelRatio
8207
+ radius: this.style.radius || 5
8229
8208
  });
8230
8209
  this.markArc.center.y = p.y;
8231
8210
  this.children.add(this.markArc);
@@ -8439,14 +8418,14 @@ class jmMarkLineManager {
8439
8418
  else lineTouching = 1;
8440
8419
  }
8441
8420
 
8442
- args.event.stopPropagation && args.event.stopPropagation(); // 如果指定了锁定图表标线操作值,则触发后当次滑动不再响应系统默认行为
8421
+ args.event && args.event.stopPropagation && args.event.stopPropagation(); // 如果指定了锁定图表标线操作值,则触发后当次滑动不再响应系统默认行为
8443
8422
 
8444
8423
  if (chart.style.markLine.lock) {
8445
8424
  // 标线状态一直禁用系统能力
8446
8425
  // 如果指定了锁定值,只需要一项符合要求就进行锁定
8447
8426
  if (lineTouching === 0 && (chart.style.markLine.lock.y && Math.abs(args.offsetInfo.y) < chart.style.markLine.lock.y || chart.style.markLine.lock.x && Math.abs(args.offsetInfo.x) < chart.style.markLine.lock.x) || lineTouching === 1) {
8448
8427
  lineTouching = 1;
8449
- args.event.preventDefault(); // 阻止默认行为
8428
+ args.event && args.event.preventDefault && args.event.preventDefault(); // 阻止默认行为
8450
8429
  }
8451
8430
  }
8452
8431
 
@@ -8654,7 +8633,7 @@ class jmChart extends jmGraph {
8654
8633
  this.touchGraph.chartGraph = this;
8655
8634
  this.on('propertyChange', (name, args) => {
8656
8635
  if (['width', 'height'].includes(name)) {
8657
- this.touchGraph[name] = args.newValue / this.devicePixelRatio;
8636
+ this.touchGraph[name] = args.newValue;
8658
8637
  }
8659
8638
  }); // 把上层canvse事件传递给绘图层对象
8660
8639
 
@@ -8794,10 +8773,10 @@ class jmChart extends jmGraph {
8794
8773
 
8795
8774
 
8796
8775
  resetAreaPosition() {
8797
- this.chartArea.position.x = (this.style.margin.left || 0) * this.graph.devicePixelRatio;
8798
- this.chartArea.position.y = (this.style.margin.top || 0) * this.graph.devicePixelRatio;
8799
- const w = this.width - this.style.margin.right * this.graph.devicePixelRatio - this.chartArea.position.x;
8800
- const h = this.height - this.style.margin.bottom * this.graph.devicePixelRatio - this.chartArea.position.y;
8776
+ this.chartArea.position.x = this.style.margin.left || 0;
8777
+ this.chartArea.position.y = this.style.margin.top || 0;
8778
+ const w = this.width - this.style.margin.right - this.chartArea.position.x;
8779
+ const h = this.height - this.style.margin.bottom - this.chartArea.position.y;
8801
8780
  this.chartArea.width = w;
8802
8781
  this.chartArea.height = h;
8803
8782
  }