jmchart 1.1.96 → 1.1.98

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.
@@ -1407,7 +1407,7 @@ class jmControl extends jmProperty {
1407
1407
  get context() {
1408
1408
  let s = this.__pro('context');
1409
1409
  if(s) return s;
1410
- else if(this.is('jmGraph') && this.canvas) {
1410
+ else if(this.is('jmGraph') && this.canvas && this.canvas.getContext) {
1411
1411
  return this.context = this.canvas.getContext('2d');
1412
1412
  }
1413
1413
  let g = this.graph;
@@ -3758,39 +3758,21 @@ class jmImage extends jmControl {
3758
3758
  */
3759
3759
  draw() {
3760
3760
  try {
3761
- let bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
3762
- if(!bounds) bounds = this.parent && this.parent.getAbsoluteBounds?this.parent.getAbsoluteBounds():this.getAbsoluteBounds();
3763
- let p = this.getLocation();
3764
- p.left += bounds.left;
3765
- p.top += bounds.top;
3766
3761
 
3767
- let sp = this.sourcePosition;
3768
- let sw = this.sourceWidth;
3769
- let sh = this.sourceHeight;
3770
3762
  let img = this.getImage();
3771
-
3772
- if(sp || typeof sw != 'undefined' || typeof sh != 'undefined') {
3773
- if(typeof sw == 'undefined') sw= p.width || img.width || 0;
3774
- if(typeof sh == 'undefined') sh= p.height || img.height || 0;
3775
- sp = sp || {x:0, y:0};
3776
-
3777
- if(p.width && p.height) this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,p.height);
3778
- else if(p.width) {
3779
- this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,sh);
3780
- }
3781
- else if(p.height) {
3782
- this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,p.height);
3783
- }
3784
- else this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,sh);
3785
- }
3786
- else if(p) {
3787
- if(p.width && p.height) this.context.drawImage(img,p.left,p.top,p.width,p.height);
3788
- else if(p.width) this.context.drawImage(img,p.left,p.top,p.width,img.height);
3789
- else if(p.height) this.context.drawImage(img,p.left,p.top,img.width,p.height);
3790
- else this.context.drawImage(img,p.left,p.top);
3763
+ if(this.graph.isWXMiniApp && this.graph.canvas) {
3764
+ // 图片对象
3765
+ const image = this.graph.canvas.createImage();
3766
+ // 图片加载完成回调
3767
+ image.onload = () => {
3768
+ // 将图片绘制到 canvas 上
3769
+ this.drawImg(image);
3770
+ };
3771
+ // 设置图片src
3772
+ image.src = img;
3791
3773
  }
3792
3774
  else {
3793
- this.context.drawImage(img);
3775
+ this.drawImg(img);
3794
3776
  }
3795
3777
  }
3796
3778
  catch(e) {
@@ -3798,6 +3780,43 @@ class jmImage extends jmControl {
3798
3780
  }
3799
3781
  }
3800
3782
 
3783
+ // 绘制
3784
+ drawImg(img) {
3785
+ let bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
3786
+ if(!bounds) bounds = this.parent && this.parent.getAbsoluteBounds?this.parent.getAbsoluteBounds():this.getAbsoluteBounds();
3787
+ let p = this.getLocation();
3788
+ p.left += bounds.left;
3789
+ p.top += bounds.top;
3790
+
3791
+ let sp = this.sourcePosition;
3792
+ let sw = this.sourceWidth;
3793
+ let sh = this.sourceHeight;
3794
+
3795
+ if(sp || typeof sw != 'undefined' || typeof sh != 'undefined') {
3796
+ if(typeof sw == 'undefined') sw= p.width || img.width || 0;
3797
+ if(typeof sh == 'undefined') sh= p.height || img.height || 0;
3798
+ sp = sp || {x:0, y:0};
3799
+
3800
+ if(p.width && p.height) this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,p.height);
3801
+ else if(p.width) {
3802
+ this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,sh);
3803
+ }
3804
+ else if(p.height) {
3805
+ this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,p.height);
3806
+ }
3807
+ else this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,sh);
3808
+ }
3809
+ else if(p) {
3810
+ if(p.width && p.height) this.context.drawImage(img,p.left,p.top,p.width,p.height);
3811
+ else if(p.width) this.context.drawImage(img,p.left,p.top,p.width,img.height);
3812
+ else if(p.height) this.context.drawImage(img,p.left,p.top,img.width,p.height);
3813
+ else this.context.drawImage(img,p.left,p.top);
3814
+ }
3815
+ else {
3816
+ this.context.drawImage(img);
3817
+ }
3818
+ }
3819
+
3801
3820
  /**
3802
3821
  * 获取当前控件的边界
3803
3822
  *
@@ -3833,7 +3852,7 @@ class jmImage extends jmControl {
3833
3852
  else if(src && src.src) {
3834
3853
  this.__img = src;
3835
3854
  }
3836
- else if(document && document.createElement) {
3855
+ else if(typeof document !== 'undefined' && document.createElement) {
3837
3856
  this.__img = document.createElement('img');
3838
3857
  if(src && typeof src == 'string') this.__img.src = src;
3839
3858
  }
@@ -4402,9 +4421,9 @@ class jmEvents {
4402
4421
  };
4403
4422
 
4404
4423
  // 销毁
4405
- destory() {
4406
- this.mouseHandler.destory();
4407
- this.keyHandler.destory();
4424
+ destroy() {
4425
+ this.mouseHandler.destroy();
4426
+ this.keyHandler.destroy();
4408
4427
  }
4409
4428
  }
4410
4429
 
@@ -4522,7 +4541,7 @@ class jmMouseEvent {
4522
4541
  }
4523
4542
 
4524
4543
  // 销毁所有事件
4525
- destory() {
4544
+ destroy() {
4526
4545
  for(let name in this.eventEvents) {
4527
4546
  const event = this.eventEvents[name];
4528
4547
  if(!event || !event.fun) continue;
@@ -4598,7 +4617,7 @@ class jmKeyEvent {
4598
4617
  }
4599
4618
 
4600
4619
  // 销毁所有事件
4601
- destory() {
4620
+ destroy() {
4602
4621
  for(let name in this.eventEvents) {
4603
4622
  const event = this.eventEvents[name];
4604
4623
  if(!event || !event.fun) continue;
@@ -4644,9 +4663,8 @@ class jmGraph$1 extends jmControl {
4644
4663
  this.util = this.utils = jmUtils;
4645
4664
 
4646
4665
  //如果是小程序
4647
- if(typeof wx != 'undefined' && wx.createCanvasContext) {
4648
- this.context = wx.createCanvasContext(canvas);
4649
- canvas = wx.createSelectorQuery().select('#' + canvas);
4666
+ if(typeof wx != 'undefined' && wx.canIUse && wx.canIUse('canvas')) {
4667
+ if(typeof canvas === 'string') canvas = wx.createSelectorQuery().select('#' + canvas);
4650
4668
  this.isWXMiniApp = true;// 微信小程序平台
4651
4669
  }
4652
4670
  else {
@@ -4667,10 +4685,10 @@ class jmGraph$1 extends jmControl {
4667
4685
  }
4668
4686
  else {
4669
4687
  this.container = canvas.parentElement;
4670
- }
4671
- this.context = canvas.getContext('2d');
4672
- }
4673
- this.canvas = canvas;
4688
+ }
4689
+ }
4690
+ this.canvas = canvas;
4691
+ this.context = canvas.getContext('2d');
4674
4692
  this.__init(callback);
4675
4693
  }
4676
4694
 
@@ -4721,16 +4739,19 @@ class jmGraph$1 extends jmControl {
4721
4739
  // 重置canvas大小,并判断高清屏,画图先放大二倍
4722
4740
  resize(w, h) {
4723
4741
 
4724
- const scale = typeof window != 'undefined' && window.devicePixelRatio > 1? window.devicePixelRatio : 1;
4725
- if (scale > 1) {
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) {
4726
4747
  this.__normalSize = this.__normalSize || { width: 0, height: 0};
4727
4748
  w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
4728
4749
 
4729
4750
  if(w) this.__normalSize.width = w;
4730
4751
  if(h) this.__normalSize.height = h;
4731
-
4732
- this.canvas.style.width = w + "px";
4733
- this.canvas.style.height = h + "px";
4752
+
4753
+ this.canvas.style && (this.canvas.style.width = w + "px");
4754
+ this.canvas.style && (this.canvas.style.height = h + "px");
4734
4755
  this.canvas.height = h * scale;
4735
4756
  this.canvas.width = w *scale;
4736
4757
  this.context.scale(scale, scale);
@@ -5097,7 +5118,7 @@ class jmGraph$1 extends jmControl {
5097
5118
  this.___isAutoRefreshing = true;
5098
5119
 
5099
5120
  function update() {
5100
- if(self.destoryed) {
5121
+ if(self.destroyed) {
5101
5122
  self.___isAutoRefreshing = false;
5102
5123
  return;// 已销毁
5103
5124
  }
@@ -5112,9 +5133,9 @@ class jmGraph$1 extends jmControl {
5112
5133
  }
5113
5134
 
5114
5135
  // 销毁当前对象
5115
- destory() {
5116
- this.eventHandler.destory();
5117
- this.destoryed = true;// 标记已销毁
5136
+ destroy() {
5137
+ this.eventHandler.destroy();
5138
+ this.destroyed = true;// 标记已销毁
5118
5139
  }
5119
5140
  }
5120
5141
 
@@ -5553,7 +5574,7 @@ class jmAxis extends jmArrowLine {
5553
5574
  this.points = [];
5554
5575
 
5555
5576
  for (const axis of this.radarOption.yAxises) {
5556
- this.points.push(axis.end);
5577
+ axis.end && this.points.push(axis.end);
5557
5578
  }
5558
5579
 
5559
5580
  this.points.push(this.points[0]);
@@ -5585,6 +5606,7 @@ class jmAxis extends jmArrowLine {
5585
5606
  const curRadius = this.radarOption.radius / this.labelCount * i;
5586
5607
 
5587
5608
  for (const axis of this.radarOption.yAxises) {
5609
+ if (!axis.radarOption) continue;
5588
5610
  const point = {};
5589
5611
  point.x = axis.radarOption.center.x + axis.radarOption.cos * curRadius + bounds.left;
5590
5612
  point.y = axis.radarOption.center.y - axis.radarOption.sin * curRadius + bounds.top;
@@ -6221,28 +6243,9 @@ jmLegend.prototype.append = function (series, shape, options = {}) {
6221
6243
  }
6222
6244
 
6223
6245
  panel.height = shape.height; //执行进入事件
6224
- //触动图例后加粗显示图
6225
-
6226
- /*const hover = options.hover || function() {
6227
- //应用图的动态样式
6228
- //Object.assign(series.style, series.style.hover);
6229
-
6230
- //Object.assign(this.style, this.style.hover || {});
6231
-
6232
- //series.graph.refresh();
6233
- };
6234
- panel.bind('mouseover', hover);
6235
- //执行离开
6236
- const leave = options.leave || function() {
6237
- //应用图的普通样式
6238
- //Object.assign(series.style, series.style.normal);
6239
-
6240
- //Object.assign(this.style, this.style.normal || {});
6241
- //jmUtils.apply(this.series.style.normal,this.series.style);
6242
- //series.graph.refresh();
6243
- };
6244
- panel.bind('mouseleave', leave);*/
6245
6246
 
6247
+ options.hover && panel.bind('mouseover touchover', options.hover);
6248
+ options.leave && panel.bind('mouseleave touchleave', options.leave);
6246
6249
  const legendPosition = this.legendPosition || this.style.legendPosition || 'right';
6247
6250
 
6248
6251
  if (legendPosition == 'top' || legendPosition == 'bottom') {
@@ -6588,7 +6591,8 @@ class jmSeries extends jmPath {
6588
6591
 
6589
6592
  p.x = xstep * i + this.xAxis.labelStart;
6590
6593
 
6591
- for (const f of fields) {
6594
+ for (let j = 0; j < fields.length; j++) {
6595
+ const f = fields[j];
6592
6596
  const yv = s[f];
6593
6597
  p.yLabel = p.yValue = yv; // 高度
6594
6598
 
@@ -6998,7 +7002,8 @@ class jmStackBarSeries extends jmBarSeries {
6998
7002
  for (const row of this.data) {
6999
7003
  let max, min;
7000
7004
 
7001
- for (const f of fields) {
7005
+ for (let i = 0; i < fields.length; i++) {
7006
+ const f = fields[i];
7002
7007
  const v = Number(row[f]);
7003
7008
  if (typeof max === 'undefined') max = v;else {
7004
7009
  if (v < 0 || max < 0) max = Math.max(max, v);else {
@@ -7327,7 +7332,7 @@ jmPieSeries.prototype.createLegend = function () {
7327
7332
  const points = this.createPoints();
7328
7333
  if (!points || !points.length) return;
7329
7334
 
7330
- for (let k in points) {
7335
+ for (let k = 0; k < points.length; k++) {
7331
7336
  const p = points[k];
7332
7337
  if (!p) continue; //生成图例前的图标
7333
7338
 
@@ -7345,18 +7350,6 @@ jmPieSeries.prototype.createLegend = function () {
7345
7350
 
7346
7351
  this.graph.legend.append(this, shape, {
7347
7352
  name: this.legendLabel,
7348
- hover: function () {
7349
- //var sp = this.children.get(0);
7350
- //应用图的动态样式
7351
- Object.assign(this.targetShape.style, this.targetShape.style.hover);
7352
- Object.assign(this.style, this.style.hover);
7353
- },
7354
- leave: function () {
7355
- //var sp = this.children.get(0);
7356
- //应用图的普通样式
7357
- Object.assign(this.targetShape.style, this.targetShape.style.normal);
7358
- Object.assign(this.style, this.style.normal);
7359
- },
7360
7353
  data: this.data[k]
7361
7354
  });
7362
7355
  }
@@ -7459,8 +7452,7 @@ class jmRadarSeries extends jmSeries {
7459
7452
  const {
7460
7453
  points,
7461
7454
  dataChanged
7462
- } = this.initDataPoint(this.center, this.radius);
7463
- this.createLegend(points); // 是否正在动画中
7455
+ } = this.initDataPoint(this.center, this.radius); // 是否正在动画中
7464
7456
 
7465
7457
  const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0);
7466
7458
  const aniCount = this.style.aniCount || 20;
@@ -7498,6 +7490,8 @@ class jmRadarSeries extends jmSeries {
7498
7490
  return self.option.onLeave.call(this, e);
7499
7491
  });
7500
7492
  }
7493
+
7494
+ this.createLegend(p);
7501
7495
  }
7502
7496
 
7503
7497
  shape.zIndex += p.radius / this.radius; // 用每个轴占比做为排序号,这样占面积最大的排最底层
@@ -7571,6 +7565,7 @@ class jmRadarSeries extends jmSeries {
7571
7565
  const shapePoints = [];
7572
7566
 
7573
7567
  for (const axis of this.axises) {
7568
+ if (!axis || !axis.field) continue;
7574
7569
  const yv = s[axis.field];
7575
7570
  const p = {
7576
7571
  x: center.x,
@@ -7645,44 +7640,23 @@ class jmRadarSeries extends jmSeries {
7645
7640
  * @method createLegend
7646
7641
  */
7647
7642
 
7648
- jmRadarSeries.prototype.createLegend = function (points) {
7649
- if (!points || !points.length) return;
7650
- const legendMap = {};
7643
+ jmRadarSeries.prototype.createLegend = function (point) {
7644
+ if (!point) return; //生成图例前的图标
7651
7645
 
7652
- for (let k in points) {
7653
- const p = points[k];
7654
- if (!p) continue;
7655
- if (legendMap[p.index]) continue; //生成图例前的图标
7646
+ const style = this.graph.utils.clone(point.style); //delete style.stroke;
7656
7647
 
7657
- const style = this.graph.utils.clone(p.style);
7658
- style.fill = style.fill; //delete style.stroke;
7659
-
7660
- const shape = legendMap[p.index] = this.graph.createShape('rect', {
7661
- style: style,
7662
- position: {
7663
- x: 0,
7664
- y: 0
7665
- }
7666
- }); //shape.targetShape = p.shape;
7667
- //此处重写图例事件
7648
+ const shape = this.graph.createShape('rect', {
7649
+ style: style,
7650
+ position: {
7651
+ x: 0,
7652
+ y: 0
7653
+ }
7654
+ }); //此处重写图例事件
7668
7655
 
7669
- this.graph.legend.append(this, shape, {
7670
- name: this.legendLabel,
7671
- hover: function () {
7672
- //var sp = this.children.get(0);
7673
- //应用图的动态样式
7674
- Object.assign(this.targetShape.style, this.targetShape.style.hover);
7675
- Object.assign(this.style, this.style.hover);
7676
- },
7677
- leave: function () {
7678
- //var sp = this.children.get(0);
7679
- //应用图的普通样式
7680
- Object.assign(this.targetShape.style, this.targetShape.style.normal);
7681
- Object.assign(this.style, this.style.normal);
7682
- },
7683
- data: p.data
7684
- });
7685
- }
7656
+ this.graph.legend.append(this, shape, {
7657
+ name: this.legendLabel,
7658
+ data: point.data
7659
+ });
7686
7660
  };
7687
7661
 
7688
7662
  /**
@@ -8248,6 +8222,7 @@ class jmMarkLine extends jmLine {
8248
8222
  this.start.x = this.end.x = isTocuhGraph ? point.x + graph.chartArea.position.x : point.x;
8249
8223
 
8250
8224
  for (const p of point.points) {
8225
+ if (!p || typeof p.y === 'undefined') continue;
8251
8226
  this.markArc = graph.createShape('circle', {
8252
8227
  style: this.style,
8253
8228
  radius: (this.style.radius || 5) * this.graph.devicePixelRatio
@@ -8950,6 +8925,12 @@ class jmChart extends jmGraph {
8950
8925
  }
8951
8926
 
8952
8927
  return serie;
8928
+ } // 销毁
8929
+
8930
+
8931
+ destroy() {
8932
+ super.destroy();
8933
+ this.touchGraph && this.touchGraph.destroy();
8953
8934
  }
8954
8935
 
8955
8936
  }
@@ -8996,8 +8977,7 @@ var vchart = {
8996
8977
 
8997
8978
  // 销毁
8998
8979
  destroyed() {
8999
- this.chartInstance && this.chartInstance.destory();
9000
- this.chartInstance && this.chartInstance.touchGraph && this.chartInstance.touchGraph.destory();
8980
+ this.chartInstance && this.chartInstance.destroy();
9001
8981
  },
9002
8982
 
9003
8983
  watch: {