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