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.
@@ -1403,7 +1403,7 @@ class jmControl extends jmProperty {
1403
1403
  get context() {
1404
1404
  let s = this.__pro('context');
1405
1405
  if(s) return s;
1406
- else if(this.is('jmGraph') && this.canvas) {
1406
+ else if(this.is('jmGraph') && this.canvas && this.canvas.getContext) {
1407
1407
  return this.context = this.canvas.getContext('2d');
1408
1408
  }
1409
1409
  let g = this.graph;
@@ -3754,39 +3754,21 @@ class jmImage extends jmControl {
3754
3754
  */
3755
3755
  draw() {
3756
3756
  try {
3757
- let bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
3758
- if(!bounds) bounds = this.parent && this.parent.getAbsoluteBounds?this.parent.getAbsoluteBounds():this.getAbsoluteBounds();
3759
- let p = this.getLocation();
3760
- p.left += bounds.left;
3761
- p.top += bounds.top;
3762
3757
 
3763
- let sp = this.sourcePosition;
3764
- let sw = this.sourceWidth;
3765
- let sh = this.sourceHeight;
3766
3758
  let img = this.getImage();
3767
-
3768
- if(sp || typeof sw != 'undefined' || typeof sh != 'undefined') {
3769
- if(typeof sw == 'undefined') sw= p.width || img.width || 0;
3770
- if(typeof sh == 'undefined') sh= p.height || img.height || 0;
3771
- sp = sp || {x:0, y:0};
3772
-
3773
- if(p.width && p.height) this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,p.height);
3774
- else if(p.width) {
3775
- this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,sh);
3776
- }
3777
- else if(p.height) {
3778
- this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,p.height);
3779
- }
3780
- else this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,sh);
3781
- }
3782
- else if(p) {
3783
- if(p.width && p.height) this.context.drawImage(img,p.left,p.top,p.width,p.height);
3784
- else if(p.width) this.context.drawImage(img,p.left,p.top,p.width,img.height);
3785
- else if(p.height) this.context.drawImage(img,p.left,p.top,img.width,p.height);
3786
- else this.context.drawImage(img,p.left,p.top);
3759
+ if(this.graph.isWXMiniApp && this.graph.canvas) {
3760
+ // 图片对象
3761
+ const image = this.graph.canvas.createImage();
3762
+ // 图片加载完成回调
3763
+ image.onload = () => {
3764
+ // 将图片绘制到 canvas 上
3765
+ this.drawImg(image);
3766
+ };
3767
+ // 设置图片src
3768
+ image.src = img;
3787
3769
  }
3788
3770
  else {
3789
- this.context.drawImage(img);
3771
+ this.drawImg(img);
3790
3772
  }
3791
3773
  }
3792
3774
  catch(e) {
@@ -3794,6 +3776,43 @@ class jmImage extends jmControl {
3794
3776
  }
3795
3777
  }
3796
3778
 
3779
+ // 绘制
3780
+ drawImg(img) {
3781
+ let bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
3782
+ if(!bounds) bounds = this.parent && this.parent.getAbsoluteBounds?this.parent.getAbsoluteBounds():this.getAbsoluteBounds();
3783
+ let p = this.getLocation();
3784
+ p.left += bounds.left;
3785
+ p.top += bounds.top;
3786
+
3787
+ let sp = this.sourcePosition;
3788
+ let sw = this.sourceWidth;
3789
+ let sh = this.sourceHeight;
3790
+
3791
+ if(sp || typeof sw != 'undefined' || typeof sh != 'undefined') {
3792
+ if(typeof sw == 'undefined') sw= p.width || img.width || 0;
3793
+ if(typeof sh == 'undefined') sh= p.height || img.height || 0;
3794
+ sp = sp || {x:0, y:0};
3795
+
3796
+ if(p.width && p.height) this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,p.height);
3797
+ else if(p.width) {
3798
+ this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,sh);
3799
+ }
3800
+ else if(p.height) {
3801
+ this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,p.height);
3802
+ }
3803
+ else this.context.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,sh);
3804
+ }
3805
+ else if(p) {
3806
+ if(p.width && p.height) this.context.drawImage(img,p.left,p.top,p.width,p.height);
3807
+ else if(p.width) this.context.drawImage(img,p.left,p.top,p.width,img.height);
3808
+ else if(p.height) this.context.drawImage(img,p.left,p.top,img.width,p.height);
3809
+ else this.context.drawImage(img,p.left,p.top);
3810
+ }
3811
+ else {
3812
+ this.context.drawImage(img);
3813
+ }
3814
+ }
3815
+
3797
3816
  /**
3798
3817
  * 获取当前控件的边界
3799
3818
  *
@@ -3829,7 +3848,7 @@ class jmImage extends jmControl {
3829
3848
  else if(src && src.src) {
3830
3849
  this.__img = src;
3831
3850
  }
3832
- else if(document && document.createElement) {
3851
+ else if(typeof document !== 'undefined' && document.createElement) {
3833
3852
  this.__img = document.createElement('img');
3834
3853
  if(src && typeof src == 'string') this.__img.src = src;
3835
3854
  }
@@ -4398,9 +4417,9 @@ class jmEvents {
4398
4417
  };
4399
4418
 
4400
4419
  // 销毁
4401
- destory() {
4402
- this.mouseHandler.destory();
4403
- this.keyHandler.destory();
4420
+ destroy() {
4421
+ this.mouseHandler.destroy();
4422
+ this.keyHandler.destroy();
4404
4423
  }
4405
4424
  }
4406
4425
 
@@ -4518,7 +4537,7 @@ class jmMouseEvent {
4518
4537
  }
4519
4538
 
4520
4539
  // 销毁所有事件
4521
- destory() {
4540
+ destroy() {
4522
4541
  for(let name in this.eventEvents) {
4523
4542
  const event = this.eventEvents[name];
4524
4543
  if(!event || !event.fun) continue;
@@ -4594,7 +4613,7 @@ class jmKeyEvent {
4594
4613
  }
4595
4614
 
4596
4615
  // 销毁所有事件
4597
- destory() {
4616
+ destroy() {
4598
4617
  for(let name in this.eventEvents) {
4599
4618
  const event = this.eventEvents[name];
4600
4619
  if(!event || !event.fun) continue;
@@ -4640,9 +4659,8 @@ class jmGraph$1 extends jmControl {
4640
4659
  this.util = this.utils = jmUtils;
4641
4660
 
4642
4661
  //如果是小程序
4643
- if(typeof wx != 'undefined' && wx.createCanvasContext) {
4644
- this.context = wx.createCanvasContext(canvas);
4645
- canvas = wx.createSelectorQuery().select('#' + canvas);
4662
+ if(typeof wx != 'undefined' && wx.canIUse && wx.canIUse('canvas')) {
4663
+ if(typeof canvas === 'string') canvas = wx.createSelectorQuery().select('#' + canvas);
4646
4664
  this.isWXMiniApp = true;// 微信小程序平台
4647
4665
  }
4648
4666
  else {
@@ -4663,10 +4681,10 @@ class jmGraph$1 extends jmControl {
4663
4681
  }
4664
4682
  else {
4665
4683
  this.container = canvas.parentElement;
4666
- }
4667
- this.context = canvas.getContext('2d');
4668
- }
4669
- this.canvas = canvas;
4684
+ }
4685
+ }
4686
+ this.canvas = canvas;
4687
+ this.context = canvas.getContext('2d');
4670
4688
  this.__init(callback);
4671
4689
  }
4672
4690
 
@@ -4717,16 +4735,19 @@ class jmGraph$1 extends jmControl {
4717
4735
  // 重置canvas大小,并判断高清屏,画图先放大二倍
4718
4736
  resize(w, h) {
4719
4737
 
4720
- const scale = typeof window != 'undefined' && window.devicePixelRatio > 1? window.devicePixelRatio : 1;
4721
- if (scale > 1) {
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) {
4722
4743
  this.__normalSize = this.__normalSize || { width: 0, height: 0};
4723
4744
  w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
4724
4745
 
4725
4746
  if(w) this.__normalSize.width = w;
4726
4747
  if(h) this.__normalSize.height = h;
4727
-
4728
- this.canvas.style.width = w + "px";
4729
- this.canvas.style.height = h + "px";
4748
+
4749
+ this.canvas.style && (this.canvas.style.width = w + "px");
4750
+ this.canvas.style && (this.canvas.style.height = h + "px");
4730
4751
  this.canvas.height = h * scale;
4731
4752
  this.canvas.width = w *scale;
4732
4753
  this.context.scale(scale, scale);
@@ -5093,7 +5114,7 @@ class jmGraph$1 extends jmControl {
5093
5114
  this.___isAutoRefreshing = true;
5094
5115
 
5095
5116
  function update() {
5096
- if(self.destoryed) {
5117
+ if(self.destroyed) {
5097
5118
  self.___isAutoRefreshing = false;
5098
5119
  return;// 已销毁
5099
5120
  }
@@ -5108,9 +5129,9 @@ class jmGraph$1 extends jmControl {
5108
5129
  }
5109
5130
 
5110
5131
  // 销毁当前对象
5111
- destory() {
5112
- this.eventHandler.destory();
5113
- this.destoryed = true;// 标记已销毁
5132
+ destroy() {
5133
+ this.eventHandler.destroy();
5134
+ this.destroyed = true;// 标记已销毁
5114
5135
  }
5115
5136
  }
5116
5137
 
@@ -5549,7 +5570,7 @@ class jmAxis extends jmArrowLine {
5549
5570
  this.points = [];
5550
5571
 
5551
5572
  for (const axis of this.radarOption.yAxises) {
5552
- this.points.push(axis.end);
5573
+ axis.end && this.points.push(axis.end);
5553
5574
  }
5554
5575
 
5555
5576
  this.points.push(this.points[0]);
@@ -5581,6 +5602,7 @@ class jmAxis extends jmArrowLine {
5581
5602
  const curRadius = this.radarOption.radius / this.labelCount * i;
5582
5603
 
5583
5604
  for (const axis of this.radarOption.yAxises) {
5605
+ if (!axis.radarOption) continue;
5584
5606
  const point = {};
5585
5607
  point.x = axis.radarOption.center.x + axis.radarOption.cos * curRadius + bounds.left;
5586
5608
  point.y = axis.radarOption.center.y - axis.radarOption.sin * curRadius + bounds.top;
@@ -6217,28 +6239,9 @@ jmLegend.prototype.append = function (series, shape, options = {}) {
6217
6239
  }
6218
6240
 
6219
6241
  panel.height = shape.height; //执行进入事件
6220
- //触动图例后加粗显示图
6221
-
6222
- /*const hover = options.hover || function() {
6223
- //应用图的动态样式
6224
- //Object.assign(series.style, series.style.hover);
6225
-
6226
- //Object.assign(this.style, this.style.hover || {});
6227
-
6228
- //series.graph.refresh();
6229
- };
6230
- panel.bind('mouseover', hover);
6231
- //执行离开
6232
- const leave = options.leave || function() {
6233
- //应用图的普通样式
6234
- //Object.assign(series.style, series.style.normal);
6235
-
6236
- //Object.assign(this.style, this.style.normal || {});
6237
- //jmUtils.apply(this.series.style.normal,this.series.style);
6238
- //series.graph.refresh();
6239
- };
6240
- panel.bind('mouseleave', leave);*/
6241
6242
 
6243
+ options.hover && panel.bind('mouseover touchover', options.hover);
6244
+ options.leave && panel.bind('mouseleave touchleave', options.leave);
6242
6245
  const legendPosition = this.legendPosition || this.style.legendPosition || 'right';
6243
6246
 
6244
6247
  if (legendPosition == 'top' || legendPosition == 'bottom') {
@@ -6584,7 +6587,8 @@ class jmSeries extends jmPath {
6584
6587
 
6585
6588
  p.x = xstep * i + this.xAxis.labelStart;
6586
6589
 
6587
- for (const f of fields) {
6590
+ for (let j = 0; j < fields.length; j++) {
6591
+ const f = fields[j];
6588
6592
  const yv = s[f];
6589
6593
  p.yLabel = p.yValue = yv; // 高度
6590
6594
 
@@ -6994,7 +6998,8 @@ class jmStackBarSeries extends jmBarSeries {
6994
6998
  for (const row of this.data) {
6995
6999
  let max, min;
6996
7000
 
6997
- for (const f of fields) {
7001
+ for (let i = 0; i < fields.length; i++) {
7002
+ const f = fields[i];
6998
7003
  const v = Number(row[f]);
6999
7004
  if (typeof max === 'undefined') max = v;else {
7000
7005
  if (v < 0 || max < 0) max = Math.max(max, v);else {
@@ -7323,7 +7328,7 @@ jmPieSeries.prototype.createLegend = function () {
7323
7328
  const points = this.createPoints();
7324
7329
  if (!points || !points.length) return;
7325
7330
 
7326
- for (let k in points) {
7331
+ for (let k = 0; k < points.length; k++) {
7327
7332
  const p = points[k];
7328
7333
  if (!p) continue; //生成图例前的图标
7329
7334
 
@@ -7341,18 +7346,6 @@ jmPieSeries.prototype.createLegend = function () {
7341
7346
 
7342
7347
  this.graph.legend.append(this, shape, {
7343
7348
  name: this.legendLabel,
7344
- hover: function () {
7345
- //var sp = this.children.get(0);
7346
- //应用图的动态样式
7347
- Object.assign(this.targetShape.style, this.targetShape.style.hover);
7348
- Object.assign(this.style, this.style.hover);
7349
- },
7350
- leave: function () {
7351
- //var sp = this.children.get(0);
7352
- //应用图的普通样式
7353
- Object.assign(this.targetShape.style, this.targetShape.style.normal);
7354
- Object.assign(this.style, this.style.normal);
7355
- },
7356
7349
  data: this.data[k]
7357
7350
  });
7358
7351
  }
@@ -7455,8 +7448,7 @@ class jmRadarSeries extends jmSeries {
7455
7448
  const {
7456
7449
  points,
7457
7450
  dataChanged
7458
- } = this.initDataPoint(this.center, this.radius);
7459
- this.createLegend(points); // 是否正在动画中
7451
+ } = this.initDataPoint(this.center, this.radius); // 是否正在动画中
7460
7452
 
7461
7453
  const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0);
7462
7454
  const aniCount = this.style.aniCount || 20;
@@ -7494,6 +7486,8 @@ class jmRadarSeries extends jmSeries {
7494
7486
  return self.option.onLeave.call(this, e);
7495
7487
  });
7496
7488
  }
7489
+
7490
+ this.createLegend(p);
7497
7491
  }
7498
7492
 
7499
7493
  shape.zIndex += p.radius / this.radius; // 用每个轴占比做为排序号,这样占面积最大的排最底层
@@ -7567,6 +7561,7 @@ class jmRadarSeries extends jmSeries {
7567
7561
  const shapePoints = [];
7568
7562
 
7569
7563
  for (const axis of this.axises) {
7564
+ if (!axis || !axis.field) continue;
7570
7565
  const yv = s[axis.field];
7571
7566
  const p = {
7572
7567
  x: center.x,
@@ -7641,44 +7636,23 @@ class jmRadarSeries extends jmSeries {
7641
7636
  * @method createLegend
7642
7637
  */
7643
7638
 
7644
- jmRadarSeries.prototype.createLegend = function (points) {
7645
- if (!points || !points.length) return;
7646
- const legendMap = {};
7639
+ jmRadarSeries.prototype.createLegend = function (point) {
7640
+ if (!point) return; //生成图例前的图标
7647
7641
 
7648
- for (let k in points) {
7649
- const p = points[k];
7650
- if (!p) continue;
7651
- if (legendMap[p.index]) continue; //生成图例前的图标
7642
+ const style = this.graph.utils.clone(point.style); //delete style.stroke;
7652
7643
 
7653
- const style = this.graph.utils.clone(p.style);
7654
- style.fill = style.fill; //delete style.stroke;
7655
-
7656
- const shape = legendMap[p.index] = this.graph.createShape('rect', {
7657
- style: style,
7658
- position: {
7659
- x: 0,
7660
- y: 0
7661
- }
7662
- }); //shape.targetShape = p.shape;
7663
- //此处重写图例事件
7644
+ const shape = this.graph.createShape('rect', {
7645
+ style: style,
7646
+ position: {
7647
+ x: 0,
7648
+ y: 0
7649
+ }
7650
+ }); //此处重写图例事件
7664
7651
 
7665
- this.graph.legend.append(this, shape, {
7666
- name: this.legendLabel,
7667
- hover: function () {
7668
- //var sp = this.children.get(0);
7669
- //应用图的动态样式
7670
- Object.assign(this.targetShape.style, this.targetShape.style.hover);
7671
- Object.assign(this.style, this.style.hover);
7672
- },
7673
- leave: function () {
7674
- //var sp = this.children.get(0);
7675
- //应用图的普通样式
7676
- Object.assign(this.targetShape.style, this.targetShape.style.normal);
7677
- Object.assign(this.style, this.style.normal);
7678
- },
7679
- data: p.data
7680
- });
7681
- }
7652
+ this.graph.legend.append(this, shape, {
7653
+ name: this.legendLabel,
7654
+ data: point.data
7655
+ });
7682
7656
  };
7683
7657
 
7684
7658
  /**
@@ -8244,6 +8218,7 @@ class jmMarkLine extends jmLine {
8244
8218
  this.start.x = this.end.x = isTocuhGraph ? point.x + graph.chartArea.position.x : point.x;
8245
8219
 
8246
8220
  for (const p of point.points) {
8221
+ if (!p || typeof p.y === 'undefined') continue;
8247
8222
  this.markArc = graph.createShape('circle', {
8248
8223
  style: this.style,
8249
8224
  radius: (this.style.radius || 5) * this.graph.devicePixelRatio
@@ -8946,6 +8921,12 @@ class jmChart extends jmGraph {
8946
8921
  }
8947
8922
 
8948
8923
  return serie;
8924
+ } // 销毁
8925
+
8926
+
8927
+ destroy() {
8928
+ super.destroy();
8929
+ this.touchGraph && this.touchGraph.destroy();
8949
8930
  }
8950
8931
 
8951
8932
  }
@@ -8992,8 +8973,7 @@ var vchart = {
8992
8973
 
8993
8974
  // 销毁
8994
8975
  destroyed() {
8995
- this.chartInstance && this.chartInstance.destory();
8996
- this.chartInstance && this.chartInstance.touchGraph && this.chartInstance.touchGraph.destory();
8976
+ this.chartInstance && this.chartInstance.destroy();
8997
8977
  },
8998
8978
 
8999
8979
  watch: {