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