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