jmchart 1.1.96 → 1.1.99

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