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