jmchart 1.1.95 → 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.
@@ -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
 
@@ -5376,7 +5397,6 @@ define(['exports'], function (exports) { 'use strict';
5376
5397
  zIndex: 17,
5377
5398
  cursor: 'default',
5378
5399
  close: true,
5379
- opacity: 0.8,
5380
5400
  shadow: {
5381
5401
  x: 1,
5382
5402
  y: 1,
@@ -5405,7 +5425,34 @@ define(['exports'], function (exports) { 'use strict';
5405
5425
  zIndex: 11,
5406
5426
  cursor: 'default',
5407
5427
  close: true,
5408
- opacity: 0.8,
5428
+ shadow: {
5429
+ x: 1,
5430
+ y: 1,
5431
+ blur: 2,
5432
+ color: '#ccc'
5433
+ }
5434
+ },
5435
+ radar: {
5436
+ normal: {
5437
+ zIndex: 11,
5438
+ cursor: 'default',
5439
+ opacity: 0.8
5440
+ },
5441
+ hover: {
5442
+ //zIndex: 100,
5443
+ opacity: 1,
5444
+ cursor: 'pointer'
5445
+ },
5446
+ margin: {
5447
+ left: 10,
5448
+ top: 10,
5449
+ right: 10,
5450
+ bottom: 10
5451
+ },
5452
+ lineWidth: 1,
5453
+ zIndex: 11,
5454
+ cursor: 'default',
5455
+ close: true,
5409
5456
  shadow: {
5410
5457
  x: 1,
5411
5458
  y: 1,
@@ -5459,6 +5506,8 @@ define(['exports'], function (exports) { 'use strict';
5459
5506
 
5460
5507
  _defineProperty(this, "scalePoints", []);
5461
5508
 
5509
+ _defineProperty(this, "labels", []);
5510
+
5462
5511
  this.arrowVisible = !!options.arrowVisible;
5463
5512
  this.zeroBase = options.zeroBase || false;
5464
5513
  this.labelCount = options.labelCount || 5;
@@ -5472,6 +5521,8 @@ define(['exports'], function (exports) { 'use strict';
5472
5521
 
5473
5522
  this.field = options.field || '';
5474
5523
  this.index = options.index || 0;
5524
+ this.gridLines = []; // 线条数组
5525
+
5475
5526
  this.init(options);
5476
5527
  } // 初始化一些参数
5477
5528
  // 这个函数可能会重入。
@@ -5481,6 +5532,8 @@ define(['exports'], function (exports) { 'use strict';
5481
5532
  options = options || {}; // 深度组件默认样式
5482
5533
 
5483
5534
  if (options.style) this.graph.utils.clone(options.style, this.style, true);
5535
+ this.field = options.field || this.field || '';
5536
+ this.radarOption = options.radarOption;
5484
5537
 
5485
5538
  if (this.type == 'x') {
5486
5539
  if (typeof options.maxXValue !== 'undefined') this.maxValue = options.maxXValue; // 最大的值,如果指定了,则如果有数值比它大才会修改上限,否则以它为上限
@@ -5509,6 +5562,24 @@ define(['exports'], function (exports) { 'use strict';
5509
5562
 
5510
5563
  set data(d) {
5511
5564
  this.graph.data = d;
5565
+ } // 生成绘制点,
5566
+ // 重写原函数
5567
+
5568
+
5569
+ initPoints() {
5570
+ // 如果是雷达图
5571
+ if (this.radarOption && this.type === 'x') {
5572
+ this.points = [];
5573
+
5574
+ for (const axis of this.radarOption.yAxises) {
5575
+ axis.end && this.points.push(axis.end);
5576
+ }
5577
+
5578
+ this.points.push(this.points[0]);
5579
+ return this.points;
5580
+ } else {
5581
+ return super.initPoints();
5582
+ }
5512
5583
  }
5513
5584
  /**
5514
5585
  * 计算当前轴的位置
@@ -5524,7 +5595,40 @@ define(['exports'], function (exports) { 'use strict';
5524
5595
  case 'x':
5525
5596
  {
5526
5597
  //初始化显示标签个数
5527
- this.labelCount = this.style.xLabel.count || 5;
5598
+ this.labelCount = this.style.xLabel.count || 5; // 如果是雷达图,则画栅格线
5599
+
5600
+ if (this.radarOption) {
5601
+ if (this.style.grid && this.style.grid.x) {
5602
+ for (let i = 1; i < this.labelCount + 1; i++) {
5603
+ const points = [];
5604
+ const curRadius = this.radarOption.radius / this.labelCount * i;
5605
+
5606
+ for (const axis of this.radarOption.yAxises) {
5607
+ if (!axis.radarOption) continue;
5608
+ const point = {};
5609
+ point.x = axis.radarOption.center.x + axis.radarOption.cos * curRadius + bounds.left;
5610
+ point.y = axis.radarOption.center.y - axis.radarOption.sin * curRadius + bounds.top;
5611
+ points.push(point);
5612
+ } // 画栅格线
5613
+
5614
+
5615
+ for (let j = 0; j < points.length; j++) {
5616
+ const start = points[j];
5617
+ const end = points[j + 1] || points[0];
5618
+ const gridLine = this.graph.createShape('line', {
5619
+ start,
5620
+ end,
5621
+ style: this.style.grid
5622
+ });
5623
+ this.parent.children.add(gridLine);
5624
+ this.gridLines.push(gridLine);
5625
+ }
5626
+ }
5627
+ }
5628
+
5629
+ break;
5630
+ }
5631
+
5528
5632
  this.start.x = bounds.left;
5529
5633
  this.start.y = bounds.bottom;
5530
5634
  this.end.x = bounds.right;
@@ -5543,21 +5647,30 @@ define(['exports'], function (exports) { 'use strict';
5543
5647
 
5544
5648
  case 'y':
5545
5649
  {
5546
- const index = this.index || 1;
5547
- let xoffset = bounds.left; //初始化显示标签个数
5650
+ //初始化显示标签个数
5651
+ this.labelCount = this.style.yLabel.count || 5;
5652
+ const index = this.index || 1; // 如果是雷达图,则画发散的线
5653
+
5654
+ if (this.radarOption) {
5655
+ this.end.x = this.radarOption.center.x + this.radarOption.cos * this.radarOption.radius + bounds.left;
5656
+ this.end.y = this.radarOption.center.y - this.radarOption.sin * this.radarOption.radius + bounds.top;
5657
+ this.start.x = this.radarOption.center.x + bounds.left;
5658
+ this.start.y = this.radarOption.center.y + bounds.top;
5659
+ } else {
5660
+ let xoffset = bounds.left; //多Y轴时,第二个为右边第一轴,其它的依此递推
5548
5661
 
5549
- this.labelCount = this.style.yLabel.count || 5; //多Y轴时,第二个为右边第一轴,其它的依此递推
5662
+ if (index == 2) {
5663
+ xoffset = bounds.right;
5664
+ } else if (index > 2) {
5665
+ xoffset = this.graph.yAxises[index - 1].start.x + this.graph.yAxises[index - 1].width + 10;
5666
+ }
5550
5667
 
5551
- if (index == 2) {
5552
- xoffset = bounds.right;
5553
- } else if (index > 2) {
5554
- xoffset = this.graph.yAxises[index - 1].start.x + this.graph.yAxises[index - 1].width + 10;
5668
+ this.start.x = xoffset;
5669
+ this.start.y = bounds.bottom;
5670
+ this.end.x = this.start.x;
5671
+ this.end.y = bounds.top;
5555
5672
  }
5556
5673
 
5557
- this.start.x = xoffset;
5558
- this.start.y = bounds.bottom;
5559
- this.end.x = this.start.x;
5560
- this.end.y = bounds.top;
5561
5674
  break;
5562
5675
  }
5563
5676
  }
@@ -5579,11 +5692,12 @@ define(['exports'], function (exports) { 'use strict';
5579
5692
 
5580
5693
 
5581
5694
  createLabel() {
5582
- //移除原有的标签
5583
- this.children.each(function (i, c) {
5584
- c.remove();
5585
- }, true);
5586
- this.labels = []; //如果是?X轴则执行X轴标签生成
5695
+ if (this.visible === false) return; // 雷达图的标签单独处理
5696
+
5697
+ if (this.radarOption) {
5698
+ return this.createRadarLabel();
5699
+ } //如果是?X轴则执行X轴标签生成
5700
+
5587
5701
 
5588
5702
  if (this.type == 'x') {
5589
5703
  this.createXLabel();
@@ -5703,13 +5817,7 @@ define(['exports'], function (exports) { 'use strict';
5703
5817
 
5704
5818
  let count = this.labelCount;
5705
5819
  const mm = max - min;
5706
- /*if(mm <= 10) {
5707
- count = mm;
5708
- }*/
5709
- // mm 放大10000倍,这里结果也需要除于10000
5710
-
5711
- let pervalue = mm / count || 1; //if(pervalue > 1 || pervalue < -1) pervalue = Math.floor(pervalue);
5712
-
5820
+ let pervalue = mm / count || 1;
5713
5821
  const format = this.option.format || this.format;
5714
5822
  const marginLeft = this.style.yLabel.margin.left * this.graph.devicePixelRatio || 0;
5715
5823
  const marginRight = this.style.yLabel.margin.right * this.graph.devicePixelRatio || 0;
@@ -5720,7 +5828,7 @@ define(['exports'], function (exports) { 'use strict';
5720
5828
  if (p > max || i === count) p = max;
5721
5829
  const h = (p - min) * step; // 当前点的偏移高度
5722
5830
 
5723
- const label = this.graph.graph.createShape('label', {
5831
+ const label = this.graph.createShape('label', {
5724
5832
  style: this.style.yLabel
5725
5833
  });
5726
5834
  label.text = format.call(this, p, label); // 格式化label
@@ -5753,7 +5861,7 @@ define(['exports'], function (exports) { 'use strict';
5753
5861
  y: offy + this.end.y
5754
5862
  }); // 指定要显示网格
5755
5863
 
5756
- if (this.style.grid && this.style.grid.x) {
5864
+ if (!this.radarOption && this.style.grid && this.style.grid.x) {
5757
5865
  // 它的坐标是相对于轴的,所以Y轴会用负的区域高度
5758
5866
  const line = this.graph.createShape('line', {
5759
5867
  start: {
@@ -5816,6 +5924,42 @@ define(['exports'], function (exports) { 'use strict';
5816
5924
  }
5817
5925
  }
5818
5926
  }
5927
+ /**
5928
+ * 生成雷达图的Y轴标签
5929
+ */
5930
+
5931
+
5932
+ createRadarLabel() {
5933
+ const format = this.option.format;
5934
+ const bounds = this.graph.chartArea.getBounds(); // 获取画图区域
5935
+
5936
+ const self = this;
5937
+ const label = this.graph.createShape('label', {
5938
+ style: this.style.yLabel,
5939
+ position: function () {
5940
+ // 因为axis是相对于chart的,而center是相对于chartArea的,所以要计算axis位置相对于chartArea来比较
5941
+ const pos = {
5942
+ x: self.end.x - bounds.left,
5943
+ y: self.end.y - bounds.top
5944
+ };
5945
+ const size = this.testSize();
5946
+
5947
+ if (pos.x < self.radarOption.center.x) {
5948
+ pos.x -= size.width;
5949
+ }
5950
+
5951
+ if (pos.y < self.radarOption.center.y) {
5952
+ pos.y -= size.height;
5953
+ }
5954
+
5955
+ return pos;
5956
+ }
5957
+ });
5958
+ label.text = typeof format === 'function' ? format.call(this, label) : this.field; // 格式化label
5959
+
5960
+ this.labels.push(label);
5961
+ this.graph.chartArea.children.add(label);
5962
+ }
5819
5963
  /**
5820
5964
  * 获取当前轴所占宽
5821
5965
  *
@@ -5963,6 +6107,18 @@ define(['exports'], function (exports) { 'use strict';
5963
6107
  clear() {
5964
6108
  this._min = null;
5965
6109
  this._max = null;
6110
+ this.children.each((i, c) => {
6111
+ c.remove();
6112
+ }, true); // 清空栅格线
6113
+
6114
+ this.gridLines && this.gridLines.forEach(line => {
6115
+ line.remove();
6116
+ });
6117
+ this.labels && this.labels.forEach(label => {
6118
+ label.remove();
6119
+ });
6120
+ this.labels = [];
6121
+ this.gridLines = [];
5966
6122
  }
5967
6123
  /**
5968
6124
  * 计算当前轴的单位偏移量
@@ -5974,7 +6130,7 @@ define(['exports'], function (exports) { 'use strict';
5974
6130
 
5975
6131
  step() {
5976
6132
  if (this.type == 'x') {
5977
- const w = this.width; //如果排版为内联,则单位占宽减少一个单位,
6133
+ const w = this.radarOption ? this.radarOption.radius : this.width; //如果排版为内联,则单位占宽减少一个单位,
5978
6134
  //也就是起始位从一个单位开始
5979
6135
 
5980
6136
  if (this.graph.style.layout == 'inside') {
@@ -5990,7 +6146,7 @@ define(['exports'], function (exports) { 'use strict';
5990
6146
 
5991
6147
  return w / tmp;
5992
6148
  } else if (this.type == 'y') {
5993
- const h = this.height;
6149
+ const h = this.radarOption ? this.radarOption.radius : this.height;
5994
6150
 
5995
6151
  switch (this.dataType) {
5996
6152
  case 'string':
@@ -6085,28 +6241,9 @@ define(['exports'], function (exports) { 'use strict';
6085
6241
  }
6086
6242
 
6087
6243
  panel.height = shape.height; //执行进入事件
6088
- //触动图例后加粗显示图
6089
-
6090
- /*const hover = options.hover || function() {
6091
- //应用图的动态样式
6092
- //Object.assign(series.style, series.style.hover);
6093
-
6094
- //Object.assign(this.style, this.style.hover || {});
6095
-
6096
- //series.graph.refresh();
6097
- };
6098
- panel.bind('mouseover', hover);
6099
- //执行离开
6100
- const leave = options.leave || function() {
6101
- //应用图的普通样式
6102
- //Object.assign(series.style, series.style.normal);
6103
-
6104
- //Object.assign(this.style, this.style.normal || {});
6105
- //jmUtils.apply(this.series.style.normal,this.series.style);
6106
- //series.graph.refresh();
6107
- };
6108
- panel.bind('mouseleave', leave);*/
6109
6244
 
6245
+ options.hover && panel.bind('mouseover touchover', options.hover);
6246
+ options.leave && panel.bind('mouseleave touchleave', options.leave);
6110
6247
  const legendPosition = this.legendPosition || this.style.legendPosition || 'right';
6111
6248
 
6112
6249
  if (legendPosition == 'top' || legendPosition == 'bottom') {
@@ -6254,7 +6391,7 @@ define(['exports'], function (exports) { 'use strict';
6254
6391
  }); // 初始化一些参数, 因为这里有多个Y轴的可能,所以每次都需要重调一次init
6255
6392
 
6256
6393
  this.yAxis.init({
6257
- field: this.field,
6394
+ field: Array.isArray(this.field) ? this.field[0] : this.field,
6258
6395
  minYValue: options.minYValue,
6259
6396
  maxYValue: options.maxYValue
6260
6397
  });
@@ -6309,6 +6446,11 @@ define(['exports'], function (exports) { 'use strict';
6309
6446
  if (dataChanged) this.___animateCounter = 0; // 数据改变。动画重新开始
6310
6447
  } else {
6311
6448
  this.dataPoints = this.createPoints(...args);
6449
+ } // 执行初始化函数回调
6450
+
6451
+
6452
+ if (this.option && this.option.onInit) {
6453
+ this.option.onInit.apply(this, args);
6312
6454
  }
6313
6455
 
6314
6456
  return {
@@ -6377,12 +6519,12 @@ define(['exports'], function (exports) { 'use strict';
6377
6519
 
6378
6520
  while (shape = this.shapes.shift()) {
6379
6521
  shape && shape.remove();
6380
- } //生成图例 这里要放到shape清理后面
6381
-
6522
+ }
6382
6523
 
6383
- this.createLegend();
6384
6524
  this.initAxisValue(); // 处理最大值最小值
6525
+ //生成图例 这里要放到shape清理后面
6385
6526
 
6527
+ this.createLegend();
6386
6528
  return this.chartInfo = {
6387
6529
  xAxis: this.xAxis,
6388
6530
  yAxis: this.yAxis
@@ -6447,7 +6589,8 @@ define(['exports'], function (exports) { 'use strict';
6447
6589
 
6448
6590
  p.x = xstep * i + this.xAxis.labelStart;
6449
6591
 
6450
- for (const f of fields) {
6592
+ for (let j = 0; j < fields.length; j++) {
6593
+ const f = fields[j];
6451
6594
  const yv = s[f];
6452
6595
  p.yLabel = p.yValue = yv; // 高度
6453
6596
 
@@ -6508,6 +6651,7 @@ define(['exports'], function (exports) { 'use strict';
6508
6651
  style
6509
6652
  });
6510
6653
  this.graph.legend.append(this, shape);
6654
+ return shape;
6511
6655
  } // 生成柱图的标注
6512
6656
 
6513
6657
 
@@ -6773,15 +6917,18 @@ define(['exports'], function (exports) { 'use strict';
6773
6917
 
6774
6918
  for (let index = 0; index < point.points.length; index++) {
6775
6919
  const style = this.graph.utils.clone(this.style);
6920
+ const p = point.points[index];
6776
6921
 
6777
6922
  if (style.color && typeof style.color === 'function') {
6778
- style.fill = style.color.call(this, this, index);
6923
+ style.fill = style.color.call(this, {
6924
+ index,
6925
+ point: p
6926
+ });
6779
6927
  } else {
6780
6928
  style.fill = this.graph.getColor(index);
6781
6929
  }
6782
6930
 
6783
6931
  const sp = this.addShape(this.graph.createPath(null, style));
6784
- const p = point.points[index];
6785
6932
  let startY = topStartY;
6786
6933
  if (p.yValue < this.baseYValue) startY = bottomStartY; //首先确定p1和p4,因为他们是底脚。会固定
6787
6934
 
@@ -6853,7 +7000,8 @@ define(['exports'], function (exports) { 'use strict';
6853
7000
  for (const row of this.data) {
6854
7001
  let max, min;
6855
7002
 
6856
- for (const f of fields) {
7003
+ for (let i = 0; i < fields.length; i++) {
7004
+ const f = fields[i];
6857
7005
  const v = Number(row[f]);
6858
7006
  if (typeof max === 'undefined') max = v;else {
6859
7007
  if (v < 0 || max < 0) max = Math.max(max, v);else {
@@ -6915,7 +7063,7 @@ define(['exports'], function (exports) { 'use strict';
6915
7063
  x: this.graph.chartArea.width / 2,
6916
7064
  y: this.graph.chartArea.height / 2
6917
7065
  };
6918
- const radius = Math.min(center.x - this.style.margin.left - this.style.margin.right * this.graph.devicePixelRatio, center.y - this.style.margin.top * this.graph.devicePixelRatio - this.style.margin.bottom * this.graph.devicePixelRatio); //生成描点位
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); //生成描点位
6919
7067
  // super.init会把参数透传给 createPoints
6920
7068
 
6921
7069
  const {
@@ -7007,7 +7155,8 @@ define(['exports'], function (exports) { 'use strict';
7007
7155
  // 每个数值点比
7008
7156
  style: this.graph.utils.clone(this.style),
7009
7157
  anticlockwise
7010
- }; //p.style.color = this.graph.getColor(index);
7158
+ };
7159
+ points.push(p); //p.style.color = this.graph.getColor(index);
7011
7160
 
7012
7161
  if (p.style.color && typeof p.style.color === 'function') {
7013
7162
  p.style.fill = p.style.color.call(this, p);
@@ -7088,34 +7237,34 @@ define(['exports'], function (exports) { 'use strict';
7088
7237
 
7089
7238
  if (this.option.onClick) {
7090
7239
  p.shape.on('click', e => {
7091
- this.option.onClick.call(this, p, e);
7240
+ return this.option.onClick.call(this, p, e);
7092
7241
  });
7093
7242
  }
7094
7243
 
7095
7244
  if (this.option.onOver) {
7096
7245
  p.shape.on('mouseover touchover', e => {
7097
- this.option.onOver.call(this, p, e);
7246
+ return this.option.onOver.call(this, p, e);
7098
7247
  });
7099
7248
  }
7100
7249
 
7101
7250
  if (this.option.onLeave) {
7102
7251
  p.shape.on('mouseleave touchleave', e => {
7103
- this.option.onLeave.call(this, p, e);
7252
+ return this.option.onLeave.call(this, p, e);
7104
7253
  });
7105
7254
  }
7106
7255
 
7107
7256
  this.createLabel(p); // 生成标签
7108
- }
7257
+ // 生成标点的回调
7109
7258
 
7110
- points.push(p);
7111
- index++; // 生成标点的回调
7259
+ this.emit('onPointCreated', p);
7260
+ }
7112
7261
 
7113
- this.emit('onPointCreated', p);
7262
+ index++;
7114
7263
  }
7115
7264
  }
7116
7265
 
7117
7266
  return points;
7118
- } // 生成柱图的标注
7267
+ } // 生成图的标注
7119
7268
 
7120
7269
 
7121
7270
  createLabel(point) {
@@ -7139,7 +7288,7 @@ define(['exports'], function (exports) { 'use strict';
7139
7288
  }; // 动态计算位置
7140
7289
 
7141
7290
  const parentRect = this.parent.getBounds(); //const rect = this.getBounds.call(this.parent);
7142
- // 圆弧的中间位,离圆心最近和最完的二个点
7291
+ // 圆弧的中间位,离圆心最近和最远的二个点
7143
7292
 
7144
7293
  let centerMaxPoint = this.parent.points[Math.floor(this.parent.points.length / 2)];
7145
7294
  let centerMinPoint = this.parent.center; // 如果是空心圆,则要计算 1/4 和 3/4位的点。顺时针和逆时针二个点大小不一样,这里只取,大小计算时处理
@@ -7181,7 +7330,7 @@ define(['exports'], function (exports) { 'use strict';
7181
7330
  const points = this.createPoints();
7182
7331
  if (!points || !points.length) return;
7183
7332
 
7184
- for (let k in points) {
7333
+ for (let k = 0; k < points.length; k++) {
7185
7334
  const p = points[k];
7186
7335
  if (!p) continue; //生成图例前的图标
7187
7336
 
@@ -7199,23 +7348,315 @@ define(['exports'], function (exports) { 'use strict';
7199
7348
 
7200
7349
  this.graph.legend.append(this, shape, {
7201
7350
  name: this.legendLabel,
7202
- hover: function () {
7203
- //var sp = this.children.get(0);
7204
- //应用图的动态样式
7205
- Object.assign(this.targetShape.style, this.targetShape.style.hover);
7206
- Object.assign(this.style, this.style.hover);
7207
- },
7208
- leave: function () {
7209
- //var sp = this.children.get(0);
7210
- //应用图的普通样式
7211
- Object.assign(this.targetShape.style, this.targetShape.style.normal);
7212
- Object.assign(this.style, this.style.normal);
7213
- },
7214
7351
  data: this.data[k]
7215
7352
  });
7216
7353
  }
7217
7354
  };
7218
7355
 
7356
+ /**
7357
+ * 雷达图
7358
+ *
7359
+ * @class jmRadarSeries
7360
+ * @module jmChart
7361
+ * @param {jmChart} chart 当前图表
7362
+ * @param {array} mappings 图形字段映射
7363
+ * @param {style} style 样式
7364
+ */
7365
+ //构造函数
7366
+
7367
+ class jmRadarSeries extends jmSeries {
7368
+ constructor(options) {
7369
+ super(options);
7370
+ } // 重新生成轴,雷达图只需要Y轴即可
7371
+
7372
+
7373
+ createAxises(center, radius) {
7374
+ this.axises = [this.yAxis];
7375
+ const yCount = this.field.length;
7376
+ if (!yCount) return; //每个维度点的角度
7377
+
7378
+ const rotateStep = Math.PI * 2 / yCount; // 清空除了一个默认外的所有Y轴
7379
+
7380
+ for (let index in this.graph.yAxises) {
7381
+ const axis = this.graph.yAxises[index];
7382
+ if (!axis || axis === this.yAxis) continue;
7383
+ axis.remove();
7384
+ delete this.graph.yAxises[index];
7385
+ }
7386
+
7387
+ for (let index = 0; index < yCount; index++) {
7388
+ if (!this.field[index]) continue;
7389
+ let axis = this.yAxis; // 除了默认的y轴外,其它都重新生成
7390
+
7391
+ if (index > 0) {
7392
+ axis = this.graph.createYAxis({
7393
+ index: index + 1,
7394
+ format: this.option.yLabelFormat || this.graph.option.yLabelFormat
7395
+ });
7396
+ this.axises.push(axis);
7397
+ }
7398
+
7399
+ const rotate = Math.PI / 2 + rotateStep * index; //从向上90度开始
7400
+
7401
+ axis.init({
7402
+ field: this.field[index],
7403
+ radarOption: {
7404
+ center,
7405
+ radius,
7406
+ yCount,
7407
+ rotate: rotate,
7408
+ cos: Math.cos(rotate),
7409
+ sin: Math.sin(rotate)
7410
+ }
7411
+ });
7412
+ } // x轴初始化
7413
+
7414
+
7415
+ this.xAxis.init({
7416
+ radarOption: {
7417
+ center,
7418
+ radius,
7419
+ yCount,
7420
+ yAxises: this.axises
7421
+ }
7422
+ });
7423
+ return this.axises;
7424
+ } // 计算最大值和最小值,一般图形直接采用最大最小值即可,有些需要多值叠加
7425
+
7426
+
7427
+ initAxisValue() {
7428
+ this.center = {
7429
+ x: this.graph.chartArea.width / 2,
7430
+ y: this.graph.chartArea.height / 2
7431
+ };
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);
7433
+ const axises = this.createAxises(this.center, this.radius); // 重置所有轴
7434
+ // 计算最大最小值
7435
+ // 当前需要先更新axis的边界值,轴好画图
7436
+
7437
+ for (let i = 0; i < this.data.length; i++) {
7438
+ axises.forEach(axis => {
7439
+ const v = this.data[i][axis.field];
7440
+ axis.max(v);
7441
+ axis.min(v);
7442
+ });
7443
+ }
7444
+ } // 重新初始化图形
7445
+
7446
+
7447
+ init() {
7448
+ //生成描点位
7449
+ // super.init会把参数透传给 createPoints
7450
+ const {
7451
+ points,
7452
+ dataChanged
7453
+ } = this.initDataPoint(this.center, this.radius); // 是否正在动画中
7454
+
7455
+ const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0);
7456
+ const aniCount = this.style.aniCount || 20;
7457
+ let aniIsEnd = true; // 当次是否结束动画
7458
+
7459
+ const len = points.length;
7460
+ const shapeMap = {};
7461
+ const self = this;
7462
+
7463
+ for (let i = 0; i < len; i++) {
7464
+ const p = points[i];
7465
+ let shape = shapeMap[p.index];
7466
+
7467
+ if (!shape) {
7468
+ shape = shapeMap[p.index] = this.graph.createShape('path', { ...p,
7469
+ style: p.style,
7470
+ points: []
7471
+ });
7472
+ this.addShape(shape); // 如果有点击事件
7473
+
7474
+ if (this.option.onClick) {
7475
+ shape.on('click', function (e) {
7476
+ return self.option.onClick.call(this, e);
7477
+ });
7478
+ }
7479
+
7480
+ if (this.option.onOver) {
7481
+ shape.on('mouseover touchover', function (e) {
7482
+ return self.option.onOver.call(this, e);
7483
+ });
7484
+ }
7485
+
7486
+ if (this.option.onLeave) {
7487
+ shape.on('mouseleave touchleave', function (e) {
7488
+ return self.option.onLeave.call(this, e);
7489
+ });
7490
+ }
7491
+
7492
+ this.createLegend(p);
7493
+ }
7494
+
7495
+ shape.zIndex += p.radius / this.radius; // 用每个轴占比做为排序号,这样占面积最大的排最底层
7496
+
7497
+ let point = null; // 在动画中,则一直刷新
7498
+
7499
+ if (isRunningAni) {
7500
+ let step = p.radius / aniCount * this.___animateCounter;
7501
+
7502
+ if (step >= p.radius) {
7503
+ step = p.radius;
7504
+ } else {
7505
+ aniIsEnd = false;
7506
+ }
7507
+
7508
+ point = { ...p,
7509
+ x: this.center.x + p.axis.radarOption.cos * step,
7510
+ y: this.center.y - p.axis.radarOption.sin * step
7511
+ };
7512
+ } else {
7513
+ point = p;
7514
+ }
7515
+
7516
+ shape.points.push(point);
7517
+ this.createLabel(point); // 生成标签
7518
+ } // 所有动画都完成,则清空计数器
7519
+
7520
+
7521
+ if (aniIsEnd) {
7522
+ this.___animateCounter = 0;
7523
+ } else {
7524
+ this.___animateCounter++; // next tick 再次刷新
7525
+
7526
+ this.graph.utils.requestAnimationFrame(() => {
7527
+ this.needUpdate = true; //需要刷新
7528
+ });
7529
+ }
7530
+ }
7531
+ /**
7532
+ * 生成序列图描点
7533
+ *
7534
+ * @method createPoints
7535
+ */
7536
+
7537
+
7538
+ createPoints(center, radius) {
7539
+ if (!this.data || !this.axises) return [];
7540
+ center = center || this.center;
7541
+ const points = [];
7542
+
7543
+ for (var i = 0; i < this.data.length; i++) {
7544
+ const s = this.data[i];
7545
+ const style = this.graph.utils.clone(this.style);
7546
+
7547
+ if (style.color && typeof style.color === 'function') {
7548
+ style.stroke = style.color.call(this, {
7549
+ data: s,
7550
+ index: i
7551
+ });
7552
+ } else {
7553
+ style.stroke = this.graph.getColor(i);
7554
+ }
7555
+
7556
+ if (typeof style.fill === 'function') {
7557
+ style.fill = style.fill.call(this, style);
7558
+ } else {
7559
+ const color = this.graph.utils.hexToRGBA(style.stroke);
7560
+ style.fill = `rgba(${color.r},${color.g},${color.b}, 0.2)`;
7561
+ }
7562
+
7563
+ const shapePoints = [];
7564
+
7565
+ for (const axis of this.axises) {
7566
+ if (!axis || !axis.field) continue;
7567
+ const yv = s[axis.field];
7568
+ const p = {
7569
+ x: center.x,
7570
+ y: center.y,
7571
+ index: i,
7572
+ radius: 0,
7573
+ data: s,
7574
+ yValue: yv,
7575
+ yLabel: yv,
7576
+ style,
7577
+ axis
7578
+ };
7579
+ shapePoints.push(p); //如果Y值不存在。则此点无效,不画图
7580
+
7581
+ if (yv == null || typeof yv == 'undefined') {
7582
+ continue;
7583
+ }
7584
+
7585
+ p.radius = Math.abs(yv - axis.min()) * axis.step();
7586
+ p.x = center.x + axis.radarOption.cos * p.radius;
7587
+ p.y = center.y - axis.radarOption.sin * p.radius; // 生成标点的回调
7588
+
7589
+ this.emit('onPointCreated', p);
7590
+ }
7591
+
7592
+ points.push(...shapePoints);
7593
+ }
7594
+
7595
+ return points;
7596
+ } // 生成图的标注
7597
+
7598
+
7599
+ createLabel(point) {
7600
+ if (this.style.label && this.style.label.show === false) return;
7601
+ const text = this.option.itemLabelFormat ? this.option.itemLabelFormat.call(this, point) : point.yValue;
7602
+ if (!text) return; // v如果指定了为控件,则直接加入
7603
+
7604
+ if (text instanceof jmControl) {
7605
+ this.addShape(text);
7606
+ return text;
7607
+ }
7608
+
7609
+ const self = this;
7610
+ const label = this.graph.createShape('label', {
7611
+ style: this.style.label,
7612
+ text: text,
7613
+ point,
7614
+ position: function () {
7615
+ const p = {
7616
+ x: this.option.point.x,
7617
+ y: this.option.point.y
7618
+ };
7619
+
7620
+ if (p.x < self.center.x) {
7621
+ p.x -= this.width;
7622
+ }
7623
+
7624
+ if (p.y < self.center.y) {
7625
+ p.y -= this.height;
7626
+ }
7627
+
7628
+ return p;
7629
+ }
7630
+ });
7631
+ this.addShape(label);
7632
+ }
7633
+
7634
+ }
7635
+ /**
7636
+ * 生成图例
7637
+ *
7638
+ * @method createLegend
7639
+ */
7640
+
7641
+ jmRadarSeries.prototype.createLegend = function (point) {
7642
+ if (!point) return; //生成图例前的图标
7643
+
7644
+ const style = this.graph.utils.clone(point.style); //delete style.stroke;
7645
+
7646
+ const shape = this.graph.createShape('rect', {
7647
+ style: style,
7648
+ position: {
7649
+ x: 0,
7650
+ y: 0
7651
+ }
7652
+ }); //此处重写图例事件
7653
+
7654
+ this.graph.legend.append(this, shape, {
7655
+ name: this.legendLabel,
7656
+ data: point.data
7657
+ });
7658
+ };
7659
+
7219
7660
  /**
7220
7661
  * 图形基类
7221
7662
  *
@@ -7779,6 +8220,7 @@ define(['exports'], function (exports) { 'use strict';
7779
8220
  this.start.x = this.end.x = isTocuhGraph ? point.x + graph.chartArea.position.x : point.x;
7780
8221
 
7781
8222
  for (const p of point.points) {
8223
+ if (!p || typeof p.y === 'undefined') continue;
7782
8224
  this.markArc = graph.createShape('circle', {
7783
8225
  style: this.style,
7784
8226
  radius: (this.style.radius || 5) * this.graph.devicePixelRatio
@@ -7999,6 +8441,7 @@ define(['exports'], function (exports) { 'use strict';
7999
8441
 
8000
8442
  if (chart.style.markLine.lock) {
8001
8443
  // 标线状态一直禁用系统能力
8444
+ // 如果指定了锁定值,只需要一项符合要求就进行锁定
8002
8445
  if (lineTouching === 0 && (chart.style.markLine.lock.y && Math.abs(args.offsetInfo.y) < chart.style.markLine.lock.y || chart.style.markLine.lock.x && Math.abs(args.offsetInfo.x) < chart.style.markLine.lock.x) || lineTouching === 1) {
8003
8446
  lineTouching = 1;
8004
8447
  args.event.preventDefault(); // 阻止默认行为
@@ -8392,7 +8835,7 @@ define(['exports'], function (exports) { 'use strict';
8392
8835
  type: 'x',
8393
8836
  visible: this.style.axis.x === false ? false : true,
8394
8837
  format: this.option.xLabelFormat,
8395
- ...this.option.yAxisOption
8838
+ ...this.option.xAxisOption
8396
8839
  }, options || {});
8397
8840
 
8398
8841
  if (typeof this.option.minXValue !== 'undefined') {
@@ -8429,7 +8872,7 @@ define(['exports'], function (exports) { 'use strict';
8429
8872
  visible: this.style.axis.y === false ? false : true,
8430
8873
  format: this.option.yLabelFormat,
8431
8874
  zeroBase: this.baseY === 0,
8432
- ...this.option.xAxisOption
8875
+ ...this.option.yAxisOption
8433
8876
  }, options || {});
8434
8877
 
8435
8878
  if (typeof this.option.minYValue !== 'undefined') {
@@ -8461,6 +8904,7 @@ define(['exports'], function (exports) { 'use strict';
8461
8904
  'bar': jmBarSeries,
8462
8905
  'stackBar': jmStackBarSeries,
8463
8906
  'pie': jmPieSeries,
8907
+ 'radar': jmRadarSeries,
8464
8908
  'stackLine': jmStackLineSeries,
8465
8909
  'candlestick': jmCandlestickSeries
8466
8910
  };
@@ -8479,6 +8923,12 @@ define(['exports'], function (exports) { 'use strict';
8479
8923
  }
8480
8924
 
8481
8925
  return serie;
8926
+ } // 销毁
8927
+
8928
+
8929
+ destroy() {
8930
+ super.destroy();
8931
+ this.touchGraph && this.touchGraph.destroy();
8482
8932
  }
8483
8933
 
8484
8934
  }
@@ -8525,8 +8975,7 @@ define(['exports'], function (exports) { 'use strict';
8525
8975
 
8526
8976
  // 销毁
8527
8977
  destroyed() {
8528
- this.chartInstance && this.chartInstance.destory();
8529
- this.chartInstance && this.chartInstance.touchGraph && this.chartInstance.touchGraph.destory();
8978
+ this.chartInstance && this.chartInstance.destroy();
8530
8979
  },
8531
8980
 
8532
8981
  watch: {