jmchart 1.1.99 → 1.2.1

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 {
@@ -1914,10 +1911,10 @@ class jmControl extends jmProperty {
1914
1911
  local.height = this.height;
1915
1912
 
1916
1913
  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;
1914
+ margin.left = (margin.left || 0);
1915
+ margin.top = (margin.top || 0);
1916
+ margin.right = (margin.right || 0);
1917
+ margin.bottom = (margin.bottom || 0);
1921
1918
 
1922
1919
  //如果没有指定位置,但指定了margin。则位置取margin偏移量
1923
1920
  if(local.position) {
@@ -2436,14 +2433,7 @@ class jmControl extends jmProperty {
2436
2433
 
2437
2434
  const srcElement = args.srcElement || args.target;
2438
2435
 
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
- }
2436
+ const position = jmUtils.getEventPosition(args, graph.scaleSize);//初始化事件位置
2447
2437
 
2448
2438
  args = {
2449
2439
  position: position,
@@ -3756,7 +3746,7 @@ class jmImage extends jmControl {
3756
3746
  try {
3757
3747
 
3758
3748
  let img = this.getImage();
3759
- if(this.graph.isWXMiniApp && this.graph.canvas) {
3749
+ if(this.graph.isWXMiniApp && this.graph.canvas && typeof img === 'string') {
3760
3750
  // 图片对象
3761
3751
  const image = this.graph.canvas.createImage();
3762
3752
  // 图片加载完成回调
@@ -3778,6 +3768,10 @@ class jmImage extends jmControl {
3778
3768
 
3779
3769
  // 绘制
3780
3770
  drawImg(img) {
3771
+ if(!img) {
3772
+ console.warn('image is empty');
3773
+ return;
3774
+ }
3781
3775
  let bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
3782
3776
  if(!bounds) bounds = this.parent && this.parent.getAbsoluteBounds?this.parent.getAbsoluteBounds():this.getAbsoluteBounds();
3783
3777
  let p = this.getLocation();
@@ -4715,11 +4709,19 @@ class jmGraph$1 extends jmControl {
4715
4709
  this.on('endDraw', function() {
4716
4710
  this.context.translate(-0.5, -0.5);
4717
4711
  });
4718
-
4712
+
4713
+ // devicePixelRatio初始化
4714
+ let dpr = typeof window != 'undefined' && window.devicePixelRatio > 1? window.devicePixelRatio : 1;
4715
+ if(this.isWXMiniApp) {
4716
+ dpr = wx.getSystemInfoSync().pixelRatio || 1;
4717
+ }
4718
+ this.devicePixelRatio = dpr;
4719
+ // 为了解决锯齿问题,先放大canvas再缩放
4720
+ this.dprScaleSize = this.devicePixelRatio > 1? this.devicePixelRatio : 2;
4721
+
4719
4722
  if(this.option.width > 0) this.width = this.option.width;
4720
4723
  if(this.option.height > 0) this.height = this.option.height;
4721
-
4722
- this.resize();
4724
+ this.resize();
4723
4725
 
4724
4726
  //绑定事件
4725
4727
  this.eventHandler = new jmEvents(this, this.canvas.canvas || this.canvas);
@@ -4734,25 +4736,19 @@ class jmGraph$1 extends jmControl {
4734
4736
 
4735
4737
  // 重置canvas大小,并判断高清屏,画图先放大二倍
4736
4738
  resize(w, h) {
4739
+ if(!this.canvas) return;
4737
4740
 
4738
- let scale = typeof window != 'undefined' && window.devicePixelRatio > 1? window.devicePixelRatio : 1;
4739
- if(this.isWXMiniApp) {
4740
- scale = wx.getSystemInfoSync().pixelRatio || 1;
4741
- }
4742
- else if (scale > 1) {
4743
- this.__normalSize = this.__normalSize || { width: 0, height: 0};
4744
- w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
4741
+ this.__normalSize = this.__normalSize || { width: 0, height: 0};
4742
+ w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
4745
4743
 
4746
- if(w) this.__normalSize.width = w;
4747
- if(h) this.__normalSize.height = h;
4748
-
4749
- this.canvas.style && (this.canvas.style.width = w + "px");
4750
- this.canvas.style && (this.canvas.style.height = h + "px");
4751
- this.canvas.height = h * scale;
4752
- this.canvas.width = w *scale;
4753
- this.context.scale(scale, scale);
4754
- this.devicePixelRatio = scale;
4755
- }
4744
+ if(w) this.__normalSize.width = w;
4745
+ if(h) this.__normalSize.height = h;
4746
+
4747
+ this.css('width', w + "px");
4748
+ this.css('height', h + "px");
4749
+ this.canvas.height = h * this.dprScaleSize;
4750
+ this.canvas.width = w * this.dprScaleSize;
4751
+ this.context.scale(this.dprScaleSize, this.dprScaleSize);
4756
4752
  }
4757
4753
 
4758
4754
  /**
@@ -4760,10 +4756,10 @@ class jmGraph$1 extends jmControl {
4760
4756
  * @param {x, y} point 内部坐标
4761
4757
  */
4762
4758
  pointToPixes(point) {
4763
- if(this.devicePixelRatio && this.devicePixelRatio !== 1) {
4759
+ if(this.dprScaleSize && this.dprScaleSize !== 1) {
4764
4760
  point = Object.assign({}, point, {
4765
- x: point.x / this.devicePixelRatio,
4766
- y: point.y / this.devicePixelRatio
4761
+ x: point.x / this.dprScaleSize,
4762
+ y: point.y / this.dprScaleSize
4767
4763
  });
4768
4764
  }
4769
4765
  return point;
@@ -4775,13 +4771,13 @@ class jmGraph$1 extends jmControl {
4775
4771
  * @type {number}
4776
4772
  */
4777
4773
  get width() {
4774
+ if(this.__normalSize && this.__normalSize.width) return this.__normalSize.width;
4778
4775
  if(this.canvas) return this.canvas.width;
4779
4776
  return 0;
4780
4777
  }
4781
4778
  set width(v) {
4782
4779
  this.needUpdate = true;
4783
4780
  if(this.canvas) {
4784
- this.canvas.width = v;
4785
4781
  this.resize(v);
4786
4782
  }
4787
4783
  return v;
@@ -4793,13 +4789,13 @@ class jmGraph$1 extends jmControl {
4793
4789
  * @type {number}
4794
4790
  */
4795
4791
  get height() {
4792
+ if(this.__normalSize && this.__normalSize.height) return this.__normalSize.height;
4796
4793
  if(this.canvas) return this.canvas.height;
4797
4794
  return 0;
4798
4795
  }
4799
4796
  set height(v) {
4800
4797
  this.needUpdate = true;
4801
4798
  if(this.canvas) {
4802
- this.canvas.height = v;
4803
4799
  this.resize(0, v);
4804
4800
  }
4805
4801
  return v;
@@ -4958,23 +4954,13 @@ class jmGraph$1 extends jmControl {
4958
4954
  * @param {number} [h] 清除画布的高度
4959
4955
  */
4960
4956
  clear(w, h) {
4961
- //this.canvas.width = this.canvas.width;
4962
- if(w && h) {
4963
- //this.zoomActual();//恢复比例缩放
4964
- this.canvas.width = w;
4965
- this.canvas.height = h;
4966
- //保留原有缩放比例
4967
- if(this.scaleSize) {
4968
- if(this.context.scale) this.context.scale(this.scaleSize.x,this.scaleSize.y);
4969
- }
4970
- }
4971
- else {
4972
- w = this.canvas.width;
4973
- h = this.canvas.height;
4974
- if(this.scaleSize) {
4957
+ if(!w || !h) {
4958
+ w = this.width;
4959
+ h = this.height;
4960
+ /*if(this.scaleSize) {
4975
4961
  w = w / this.scaleSize.x;
4976
4962
  h = h / this.scaleSize.y;
4977
- }
4963
+ }*/
4978
4964
  }
4979
4965
  //如果有指定背景,则等到draw再全屏绘制一次,也同样达到清除画布的功能
4980
4966
  if(this.style && this.style.fill) {
@@ -5119,6 +5105,9 @@ class jmGraph$1 extends jmControl {
5119
5105
  return;// 已销毁
5120
5106
  }
5121
5107
  if(self.needUpdate) self.redraw();
5108
+ // 触发刷新事件
5109
+ self.emit('update');
5110
+
5122
5111
  self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5123
5112
  self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
5124
5113
  if(callback) callback();
@@ -5721,7 +5710,7 @@ class jmAxis extends jmArrowLine {
5721
5710
  //字符串轴。则显示每个标签
5722
5711
 
5723
5712
  const format = this.option.format || this.format;
5724
- const top = (this.style.xLabel.margin.top || 0) * this.graph.devicePixelRatio;
5713
+ const top = this.style.xLabel.margin.top || 0;
5725
5714
 
5726
5715
  for (let i = 0; i < this.data.length; i++) {
5727
5716
  const d = this.data[i];
@@ -5817,8 +5806,8 @@ class jmAxis extends jmArrowLine {
5817
5806
  const mm = max - min;
5818
5807
  let pervalue = mm / count || 1;
5819
5808
  const format = this.option.format || this.format;
5820
- const marginLeft = this.style.yLabel.margin.left * this.graph.devicePixelRatio || 0;
5821
- const marginRight = this.style.yLabel.margin.right * this.graph.devicePixelRatio || 0;
5809
+ const marginLeft = this.style.yLabel.margin.left || 0;
5810
+ const marginRight = this.style.yLabel.margin.right || 0;
5822
5811
  let p = 0;
5823
5812
 
5824
5813
  for (let i = 0; i < count + 1; i++) {
@@ -6246,13 +6235,13 @@ jmLegend.prototype.append = function (series, shape, options = {}) {
6246
6235
 
6247
6236
  if (legendPosition == 'top' || legendPosition == 'bottom') {
6248
6237
  //顶部和底部图例横排,每次右移位一个单位图例
6249
- panel.position.x = this.width + 15 * this.graph.devicePixelRatio;
6238
+ panel.position.x = this.width + 15;
6250
6239
  this.width = panel.position.x + panel.width; // 把容器宽指定为所有图例宽和
6251
6240
 
6252
6241
  this.height = Math.max(panel.height, this.height);
6253
6242
  } else {
6254
6243
  //右边和左边图例竖排
6255
- panel.position.y += this.height + 5 * this.graph.devicePixelRatio;
6244
+ panel.position.y += this.height + 5;
6256
6245
  this.height = panel.position.y + panel.height;
6257
6246
  this.width = Math.max(panel.width, this.width);
6258
6247
  }
@@ -6292,21 +6281,21 @@ jmLegend.prototype.reset = function () {
6292
6281
  {
6293
6282
  this.graph.chartArea.width = this.graph.chartArea.width - this.width; //画图区域向右偏移
6294
6283
 
6295
- this.graph.chartArea.position.x = this.position.x + this.width + this.style.margin.right * this.graph.devicePixelRatio;
6284
+ this.graph.chartArea.position.x = this.position.x + this.width + this.style.margin.right;
6296
6285
  break;
6297
6286
  }
6298
6287
 
6299
6288
  case 'top':
6300
6289
  {
6301
6290
  this.graph.chartArea.height = this.graph.chartArea.height - this.height;
6302
- this.graph.chartArea.position.y = this.position.y + this.height + this.style.margin.bottom * this.graph.devicePixelRatio;
6291
+ this.graph.chartArea.position.y = this.position.y + this.height + this.style.margin.bottom;
6303
6292
  break;
6304
6293
  }
6305
6294
 
6306
6295
  case 'bottom':
6307
6296
  {
6308
6297
  this.graph.chartArea.height = this.graph.chartArea.height - this.height;
6309
- this.position.y = this.graph.chartArea.position.y + this.graph.chartArea.height + this.style.margin.top * this.graph.devicePixelRatio;
6298
+ this.position.y = this.graph.chartArea.position.y + this.graph.chartArea.height + this.style.margin.top;
6310
6299
  break;
6311
6300
  }
6312
6301
 
@@ -6314,7 +6303,7 @@ jmLegend.prototype.reset = function () {
6314
6303
  default:
6315
6304
  {
6316
6305
  this.graph.chartArea.width = this.graph.chartArea.width - this.width;
6317
- this.position.x = this.graph.chartArea.position.x + this.graph.chartArea.width + this.style.margin.left * this.graph.devicePixelRatio;
6306
+ this.position.x = this.graph.chartArea.position.x + this.graph.chartArea.width + this.style.margin.left;
6318
6307
  break;
6319
6308
  }
6320
6309
  }
@@ -7061,7 +7050,7 @@ class jmPieSeries extends jmSeries {
7061
7050
  x: this.graph.chartArea.width / 2,
7062
7051
  y: this.graph.chartArea.height / 2
7063
7052
  };
7064
- 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); //生成描点位
7053
+ const radius = Math.min(center.x - this.style.margin.left - this.style.margin.right, center.y - this.style.margin.top - this.style.margin.bottom); //生成描点位
7065
7054
  // super.init会把参数透传给 createPoints
7066
7055
 
7067
7056
  const {
@@ -7427,7 +7416,7 @@ class jmRadarSeries extends jmSeries {
7427
7416
  x: this.graph.chartArea.width / 2,
7428
7417
  y: this.graph.chartArea.height / 2
7429
7418
  };
7430
- 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);
7419
+ 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);
7431
7420
  const axises = this.createAxises(this.center, this.radius); // 重置所有轴
7432
7421
  // 计算最大最小值
7433
7422
  // 当前需要先更新axis的边界值,轴好画图
@@ -8221,7 +8210,7 @@ class jmMarkLine extends jmLine {
8221
8210
  if (!p || typeof p.y === 'undefined') continue;
8222
8211
  this.markArc = graph.createShape('circle', {
8223
8212
  style: this.style,
8224
- radius: (this.style.radius || 5) * this.graph.devicePixelRatio
8213
+ radius: this.style.radius || 5
8225
8214
  });
8226
8215
  this.markArc.center.y = p.y;
8227
8216
  this.children.add(this.markArc);
@@ -8650,7 +8639,7 @@ class jmChart extends jmGraph {
8650
8639
  this.touchGraph.chartGraph = this;
8651
8640
  this.on('propertyChange', (name, args) => {
8652
8641
  if (['width', 'height'].includes(name)) {
8653
- this.touchGraph[name] = args.newValue / this.devicePixelRatio;
8642
+ this.touchGraph[name] = args.newValue;
8654
8643
  }
8655
8644
  }); // 把上层canvse事件传递给绘图层对象
8656
8645
 
@@ -8790,10 +8779,10 @@ class jmChart extends jmGraph {
8790
8779
 
8791
8780
 
8792
8781
  resetAreaPosition() {
8793
- this.chartArea.position.x = (this.style.margin.left || 0) * this.graph.devicePixelRatio;
8794
- this.chartArea.position.y = (this.style.margin.top || 0) * this.graph.devicePixelRatio;
8795
- const w = this.width - this.style.margin.right * this.graph.devicePixelRatio - this.chartArea.position.x;
8796
- const h = this.height - this.style.margin.bottom * this.graph.devicePixelRatio - this.chartArea.position.y;
8782
+ this.chartArea.position.x = this.style.margin.left || 0;
8783
+ this.chartArea.position.y = this.style.margin.top || 0;
8784
+ const w = this.width - this.style.margin.right - this.chartArea.position.x;
8785
+ const h = this.height - this.style.margin.bottom - this.chartArea.position.y;
8797
8786
  this.chartArea.width = w;
8798
8787
  this.chartArea.height = h;
8799
8788
  }
@@ -1666,9 +1666,6 @@
1666
1666
  style = style || jmUtils.clone(this.style, true);
1667
1667
  if(!style) return;
1668
1668
 
1669
- // 当前根据屏幕放大倍数,如果有倍数,则需要对线宽等同比放大
1670
- let scale = this.graph.devicePixelRatio;
1671
-
1672
1669
  /**
1673
1670
  * 样式设定
1674
1671
  *
@@ -1718,7 +1715,7 @@
1718
1715
  }
1719
1716
 
1720
1717
  // 按比例需要放大的样式
1721
- if(scale && style) {
1718
+ /*if(scale && style) {
1722
1719
  switch(mpname) {
1723
1720
  case 'lineWidth': {
1724
1721
  style *= scale;
@@ -1735,7 +1732,7 @@
1735
1732
  break;
1736
1733
  }
1737
1734
  }
1738
- }
1735
+ } */
1739
1736
  this.context[mpname] = style;
1740
1737
  }
1741
1738
  else {
@@ -1917,10 +1914,10 @@
1917
1914
  local.height = this.height;
1918
1915
 
1919
1916
  let margin = jmUtils.clone(this.style.margin, {});
1920
- margin.left = (margin.left || 0) * this.graph.devicePixelRatio;
1921
- margin.top = (margin.top || 0) * this.graph.devicePixelRatio;
1922
- margin.right = (margin.right || 0) * this.graph.devicePixelRatio;
1923
- margin.bottom = (margin.bottom || 0) * this.graph.devicePixelRatio;
1917
+ margin.left = (margin.left || 0);
1918
+ margin.top = (margin.top || 0);
1919
+ margin.right = (margin.right || 0);
1920
+ margin.bottom = (margin.bottom || 0);
1924
1921
 
1925
1922
  //如果没有指定位置,但指定了margin。则位置取margin偏移量
1926
1923
  if(local.position) {
@@ -2439,14 +2436,7 @@
2439
2436
 
2440
2437
  const srcElement = args.srcElement || args.target;
2441
2438
 
2442
- const position = jmUtils.getEventPosition(args, graph.scaleSize);//初始化事件位置
2443
-
2444
- // 如果有指定scale高清处理,需要对坐标处理
2445
- // 因为是对canvas放大N倍,再把style指定为当前大小,所以坐标需要放大N && srcElement === graph.canvas
2446
- if(graph.devicePixelRatio > 0) {
2447
- position.x = position.offsetX = position.x * graph.devicePixelRatio;
2448
- position.y = position.offsetY = position.y * graph.devicePixelRatio;
2449
- }
2439
+ const position = jmUtils.getEventPosition(args, graph.scaleSize);//初始化事件位置
2450
2440
 
2451
2441
  args = {
2452
2442
  position: position,
@@ -3759,7 +3749,7 @@
3759
3749
  try {
3760
3750
 
3761
3751
  let img = this.getImage();
3762
- if(this.graph.isWXMiniApp && this.graph.canvas) {
3752
+ if(this.graph.isWXMiniApp && this.graph.canvas && typeof img === 'string') {
3763
3753
  // 图片对象
3764
3754
  const image = this.graph.canvas.createImage();
3765
3755
  // 图片加载完成回调
@@ -3781,6 +3771,10 @@
3781
3771
 
3782
3772
  // 绘制
3783
3773
  drawImg(img) {
3774
+ if(!img) {
3775
+ console.warn('image is empty');
3776
+ return;
3777
+ }
3784
3778
  let bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
3785
3779
  if(!bounds) bounds = this.parent && this.parent.getAbsoluteBounds?this.parent.getAbsoluteBounds():this.getAbsoluteBounds();
3786
3780
  let p = this.getLocation();
@@ -4718,11 +4712,19 @@
4718
4712
  this.on('endDraw', function() {
4719
4713
  this.context.translate(-0.5, -0.5);
4720
4714
  });
4721
-
4715
+
4716
+ // devicePixelRatio初始化
4717
+ let dpr = typeof window != 'undefined' && window.devicePixelRatio > 1? window.devicePixelRatio : 1;
4718
+ if(this.isWXMiniApp) {
4719
+ dpr = wx.getSystemInfoSync().pixelRatio || 1;
4720
+ }
4721
+ this.devicePixelRatio = dpr;
4722
+ // 为了解决锯齿问题,先放大canvas再缩放
4723
+ this.dprScaleSize = this.devicePixelRatio > 1? this.devicePixelRatio : 2;
4724
+
4722
4725
  if(this.option.width > 0) this.width = this.option.width;
4723
4726
  if(this.option.height > 0) this.height = this.option.height;
4724
-
4725
- this.resize();
4727
+ this.resize();
4726
4728
 
4727
4729
  //绑定事件
4728
4730
  this.eventHandler = new jmEvents(this, this.canvas.canvas || this.canvas);
@@ -4737,25 +4739,19 @@
4737
4739
 
4738
4740
  // 重置canvas大小,并判断高清屏,画图先放大二倍
4739
4741
  resize(w, h) {
4742
+ if(!this.canvas) return;
4740
4743
 
4741
- let scale = typeof window != 'undefined' && window.devicePixelRatio > 1? window.devicePixelRatio : 1;
4742
- if(this.isWXMiniApp) {
4743
- scale = wx.getSystemInfoSync().pixelRatio || 1;
4744
- }
4745
- else if (scale > 1) {
4746
- this.__normalSize = this.__normalSize || { width: 0, height: 0};
4747
- w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
4744
+ this.__normalSize = this.__normalSize || { width: 0, height: 0};
4745
+ w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
4748
4746
 
4749
- if(w) this.__normalSize.width = w;
4750
- if(h) this.__normalSize.height = h;
4751
-
4752
- this.canvas.style && (this.canvas.style.width = w + "px");
4753
- this.canvas.style && (this.canvas.style.height = h + "px");
4754
- this.canvas.height = h * scale;
4755
- this.canvas.width = w *scale;
4756
- this.context.scale(scale, scale);
4757
- this.devicePixelRatio = scale;
4758
- }
4747
+ if(w) this.__normalSize.width = w;
4748
+ if(h) this.__normalSize.height = h;
4749
+
4750
+ this.css('width', w + "px");
4751
+ this.css('height', h + "px");
4752
+ this.canvas.height = h * this.dprScaleSize;
4753
+ this.canvas.width = w * this.dprScaleSize;
4754
+ this.context.scale(this.dprScaleSize, this.dprScaleSize);
4759
4755
  }
4760
4756
 
4761
4757
  /**
@@ -4763,10 +4759,10 @@
4763
4759
  * @param {x, y} point 内部坐标
4764
4760
  */
4765
4761
  pointToPixes(point) {
4766
- if(this.devicePixelRatio && this.devicePixelRatio !== 1) {
4762
+ if(this.dprScaleSize && this.dprScaleSize !== 1) {
4767
4763
  point = Object.assign({}, point, {
4768
- x: point.x / this.devicePixelRatio,
4769
- y: point.y / this.devicePixelRatio
4764
+ x: point.x / this.dprScaleSize,
4765
+ y: point.y / this.dprScaleSize
4770
4766
  });
4771
4767
  }
4772
4768
  return point;
@@ -4778,13 +4774,13 @@
4778
4774
  * @type {number}
4779
4775
  */
4780
4776
  get width() {
4777
+ if(this.__normalSize && this.__normalSize.width) return this.__normalSize.width;
4781
4778
  if(this.canvas) return this.canvas.width;
4782
4779
  return 0;
4783
4780
  }
4784
4781
  set width(v) {
4785
4782
  this.needUpdate = true;
4786
4783
  if(this.canvas) {
4787
- this.canvas.width = v;
4788
4784
  this.resize(v);
4789
4785
  }
4790
4786
  return v;
@@ -4796,13 +4792,13 @@
4796
4792
  * @type {number}
4797
4793
  */
4798
4794
  get height() {
4795
+ if(this.__normalSize && this.__normalSize.height) return this.__normalSize.height;
4799
4796
  if(this.canvas) return this.canvas.height;
4800
4797
  return 0;
4801
4798
  }
4802
4799
  set height(v) {
4803
4800
  this.needUpdate = true;
4804
4801
  if(this.canvas) {
4805
- this.canvas.height = v;
4806
4802
  this.resize(0, v);
4807
4803
  }
4808
4804
  return v;
@@ -4961,23 +4957,13 @@
4961
4957
  * @param {number} [h] 清除画布的高度
4962
4958
  */
4963
4959
  clear(w, h) {
4964
- //this.canvas.width = this.canvas.width;
4965
- if(w && h) {
4966
- //this.zoomActual();//恢复比例缩放
4967
- this.canvas.width = w;
4968
- this.canvas.height = h;
4969
- //保留原有缩放比例
4970
- if(this.scaleSize) {
4971
- if(this.context.scale) this.context.scale(this.scaleSize.x,this.scaleSize.y);
4972
- }
4973
- }
4974
- else {
4975
- w = this.canvas.width;
4976
- h = this.canvas.height;
4977
- if(this.scaleSize) {
4960
+ if(!w || !h) {
4961
+ w = this.width;
4962
+ h = this.height;
4963
+ /*if(this.scaleSize) {
4978
4964
  w = w / this.scaleSize.x;
4979
4965
  h = h / this.scaleSize.y;
4980
- }
4966
+ }*/
4981
4967
  }
4982
4968
  //如果有指定背景,则等到draw再全屏绘制一次,也同样达到清除画布的功能
4983
4969
  if(this.style && this.style.fill) {
@@ -5122,6 +5108,9 @@
5122
5108
  return;// 已销毁
5123
5109
  }
5124
5110
  if(self.needUpdate) self.redraw();
5111
+ // 触发刷新事件
5112
+ self.emit('update');
5113
+
5125
5114
  self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
5126
5115
  self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
5127
5116
  if(callback) callback();
@@ -5724,7 +5713,7 @@
5724
5713
  //字符串轴。则显示每个标签
5725
5714
 
5726
5715
  const format = this.option.format || this.format;
5727
- const top = (this.style.xLabel.margin.top || 0) * this.graph.devicePixelRatio;
5716
+ const top = this.style.xLabel.margin.top || 0;
5728
5717
 
5729
5718
  for (let i = 0; i < this.data.length; i++) {
5730
5719
  const d = this.data[i];
@@ -5820,8 +5809,8 @@
5820
5809
  const mm = max - min;
5821
5810
  let pervalue = mm / count || 1;
5822
5811
  const format = this.option.format || this.format;
5823
- const marginLeft = this.style.yLabel.margin.left * this.graph.devicePixelRatio || 0;
5824
- const marginRight = this.style.yLabel.margin.right * this.graph.devicePixelRatio || 0;
5812
+ const marginLeft = this.style.yLabel.margin.left || 0;
5813
+ const marginRight = this.style.yLabel.margin.right || 0;
5825
5814
  let p = 0;
5826
5815
 
5827
5816
  for (let i = 0; i < count + 1; i++) {
@@ -6249,13 +6238,13 @@
6249
6238
 
6250
6239
  if (legendPosition == 'top' || legendPosition == 'bottom') {
6251
6240
  //顶部和底部图例横排,每次右移位一个单位图例
6252
- panel.position.x = this.width + 15 * this.graph.devicePixelRatio;
6241
+ panel.position.x = this.width + 15;
6253
6242
  this.width = panel.position.x + panel.width; // 把容器宽指定为所有图例宽和
6254
6243
 
6255
6244
  this.height = Math.max(panel.height, this.height);
6256
6245
  } else {
6257
6246
  //右边和左边图例竖排
6258
- panel.position.y += this.height + 5 * this.graph.devicePixelRatio;
6247
+ panel.position.y += this.height + 5;
6259
6248
  this.height = panel.position.y + panel.height;
6260
6249
  this.width = Math.max(panel.width, this.width);
6261
6250
  }
@@ -6295,21 +6284,21 @@
6295
6284
  {
6296
6285
  this.graph.chartArea.width = this.graph.chartArea.width - this.width; //画图区域向右偏移
6297
6286
 
6298
- this.graph.chartArea.position.x = this.position.x + this.width + this.style.margin.right * this.graph.devicePixelRatio;
6287
+ this.graph.chartArea.position.x = this.position.x + this.width + this.style.margin.right;
6299
6288
  break;
6300
6289
  }
6301
6290
 
6302
6291
  case 'top':
6303
6292
  {
6304
6293
  this.graph.chartArea.height = this.graph.chartArea.height - this.height;
6305
- this.graph.chartArea.position.y = this.position.y + this.height + this.style.margin.bottom * this.graph.devicePixelRatio;
6294
+ this.graph.chartArea.position.y = this.position.y + this.height + this.style.margin.bottom;
6306
6295
  break;
6307
6296
  }
6308
6297
 
6309
6298
  case 'bottom':
6310
6299
  {
6311
6300
  this.graph.chartArea.height = this.graph.chartArea.height - this.height;
6312
- this.position.y = this.graph.chartArea.position.y + this.graph.chartArea.height + this.style.margin.top * this.graph.devicePixelRatio;
6301
+ this.position.y = this.graph.chartArea.position.y + this.graph.chartArea.height + this.style.margin.top;
6313
6302
  break;
6314
6303
  }
6315
6304
 
@@ -6317,7 +6306,7 @@
6317
6306
  default:
6318
6307
  {
6319
6308
  this.graph.chartArea.width = this.graph.chartArea.width - this.width;
6320
- this.position.x = this.graph.chartArea.position.x + this.graph.chartArea.width + this.style.margin.left * this.graph.devicePixelRatio;
6309
+ this.position.x = this.graph.chartArea.position.x + this.graph.chartArea.width + this.style.margin.left;
6321
6310
  break;
6322
6311
  }
6323
6312
  }
@@ -7064,7 +7053,7 @@
7064
7053
  x: this.graph.chartArea.width / 2,
7065
7054
  y: this.graph.chartArea.height / 2
7066
7055
  };
7067
- 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); //生成描点位
7056
+ const radius = Math.min(center.x - this.style.margin.left - this.style.margin.right, center.y - this.style.margin.top - this.style.margin.bottom); //生成描点位
7068
7057
  // super.init会把参数透传给 createPoints
7069
7058
 
7070
7059
  const {
@@ -7430,7 +7419,7 @@
7430
7419
  x: this.graph.chartArea.width / 2,
7431
7420
  y: this.graph.chartArea.height / 2
7432
7421
  };
7433
- 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);
7422
+ 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);
7434
7423
  const axises = this.createAxises(this.center, this.radius); // 重置所有轴
7435
7424
  // 计算最大最小值
7436
7425
  // 当前需要先更新axis的边界值,轴好画图
@@ -8224,7 +8213,7 @@
8224
8213
  if (!p || typeof p.y === 'undefined') continue;
8225
8214
  this.markArc = graph.createShape('circle', {
8226
8215
  style: this.style,
8227
- radius: (this.style.radius || 5) * this.graph.devicePixelRatio
8216
+ radius: this.style.radius || 5
8228
8217
  });
8229
8218
  this.markArc.center.y = p.y;
8230
8219
  this.children.add(this.markArc);
@@ -8653,7 +8642,7 @@
8653
8642
  this.touchGraph.chartGraph = this;
8654
8643
  this.on('propertyChange', (name, args) => {
8655
8644
  if (['width', 'height'].includes(name)) {
8656
- this.touchGraph[name] = args.newValue / this.devicePixelRatio;
8645
+ this.touchGraph[name] = args.newValue;
8657
8646
  }
8658
8647
  }); // 把上层canvse事件传递给绘图层对象
8659
8648
 
@@ -8793,10 +8782,10 @@
8793
8782
 
8794
8783
 
8795
8784
  resetAreaPosition() {
8796
- this.chartArea.position.x = (this.style.margin.left || 0) * this.graph.devicePixelRatio;
8797
- this.chartArea.position.y = (this.style.margin.top || 0) * this.graph.devicePixelRatio;
8798
- const w = this.width - this.style.margin.right * this.graph.devicePixelRatio - this.chartArea.position.x;
8799
- const h = this.height - this.style.margin.bottom * this.graph.devicePixelRatio - this.chartArea.position.y;
8785
+ this.chartArea.position.x = this.style.margin.left || 0;
8786
+ this.chartArea.position.y = this.style.margin.top || 0;
8787
+ const w = this.width - this.style.margin.right - this.chartArea.position.x;
8788
+ const h = this.height - this.style.margin.bottom - this.chartArea.position.y;
8800
8789
  this.chartArea.width = w;
8801
8790
  this.chartArea.height = h;
8802
8791
  }