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