jmchart 1.1.95 → 1.1.96
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 +11 -2
- package/dist/jmchart.amd.js +518 -49
- package/dist/jmchart.cjs.js +518 -49
- package/dist/jmchart.esm.js +518 -49
- package/dist/jmchart.iife.js +518 -49
- package/dist/jmchart.system.js +518 -49
- package/example/bar.html +4 -3
- package/example/line.html +16 -2
- package/example/pie.html +37 -0
- package/example/radar.html +160 -0
- package/example/wk/line.html +1 -1
- package/package.json +1 -1
- package/src/common/style.js +28 -2
- package/src/core/axis/axis.js +142 -38
- package/src/jmChart.js +4 -3
- package/src/series/pieSeries.js +10 -11
- package/src/series/radarSeries.js +332 -0
- package/src/series/series.js +8 -3
- package/src/series/stackBarSeries.js +7 -3
package/dist/jmchart.iife.js
CHANGED
|
@@ -5377,7 +5377,6 @@
|
|
|
5377
5377
|
zIndex: 17,
|
|
5378
5378
|
cursor: 'default',
|
|
5379
5379
|
close: true,
|
|
5380
|
-
opacity: 0.8,
|
|
5381
5380
|
shadow: {
|
|
5382
5381
|
x: 1,
|
|
5383
5382
|
y: 1,
|
|
@@ -5406,7 +5405,34 @@
|
|
|
5406
5405
|
zIndex: 11,
|
|
5407
5406
|
cursor: 'default',
|
|
5408
5407
|
close: true,
|
|
5409
|
-
|
|
5408
|
+
shadow: {
|
|
5409
|
+
x: 1,
|
|
5410
|
+
y: 1,
|
|
5411
|
+
blur: 2,
|
|
5412
|
+
color: '#ccc'
|
|
5413
|
+
}
|
|
5414
|
+
},
|
|
5415
|
+
radar: {
|
|
5416
|
+
normal: {
|
|
5417
|
+
zIndex: 11,
|
|
5418
|
+
cursor: 'default',
|
|
5419
|
+
opacity: 0.8
|
|
5420
|
+
},
|
|
5421
|
+
hover: {
|
|
5422
|
+
//zIndex: 100,
|
|
5423
|
+
opacity: 1,
|
|
5424
|
+
cursor: 'pointer'
|
|
5425
|
+
},
|
|
5426
|
+
margin: {
|
|
5427
|
+
left: 10,
|
|
5428
|
+
top: 10,
|
|
5429
|
+
right: 10,
|
|
5430
|
+
bottom: 10
|
|
5431
|
+
},
|
|
5432
|
+
lineWidth: 1,
|
|
5433
|
+
zIndex: 11,
|
|
5434
|
+
cursor: 'default',
|
|
5435
|
+
close: true,
|
|
5410
5436
|
shadow: {
|
|
5411
5437
|
x: 1,
|
|
5412
5438
|
y: 1,
|
|
@@ -5460,6 +5486,8 @@
|
|
|
5460
5486
|
|
|
5461
5487
|
_defineProperty(this, "scalePoints", []);
|
|
5462
5488
|
|
|
5489
|
+
_defineProperty(this, "labels", []);
|
|
5490
|
+
|
|
5463
5491
|
this.arrowVisible = !!options.arrowVisible;
|
|
5464
5492
|
this.zeroBase = options.zeroBase || false;
|
|
5465
5493
|
this.labelCount = options.labelCount || 5;
|
|
@@ -5473,6 +5501,8 @@
|
|
|
5473
5501
|
|
|
5474
5502
|
this.field = options.field || '';
|
|
5475
5503
|
this.index = options.index || 0;
|
|
5504
|
+
this.gridLines = []; // 线条数组
|
|
5505
|
+
|
|
5476
5506
|
this.init(options);
|
|
5477
5507
|
} // 初始化一些参数
|
|
5478
5508
|
// 这个函数可能会重入。
|
|
@@ -5482,6 +5512,8 @@
|
|
|
5482
5512
|
options = options || {}; // 深度组件默认样式
|
|
5483
5513
|
|
|
5484
5514
|
if (options.style) this.graph.utils.clone(options.style, this.style, true);
|
|
5515
|
+
this.field = options.field || this.field || '';
|
|
5516
|
+
this.radarOption = options.radarOption;
|
|
5485
5517
|
|
|
5486
5518
|
if (this.type == 'x') {
|
|
5487
5519
|
if (typeof options.maxXValue !== 'undefined') this.maxValue = options.maxXValue; // 最大的值,如果指定了,则如果有数值比它大才会修改上限,否则以它为上限
|
|
@@ -5510,6 +5542,24 @@
|
|
|
5510
5542
|
|
|
5511
5543
|
set data(d) {
|
|
5512
5544
|
this.graph.data = d;
|
|
5545
|
+
} // 生成绘制点,
|
|
5546
|
+
// 重写原函数
|
|
5547
|
+
|
|
5548
|
+
|
|
5549
|
+
initPoints() {
|
|
5550
|
+
// 如果是雷达图
|
|
5551
|
+
if (this.radarOption && this.type === 'x') {
|
|
5552
|
+
this.points = [];
|
|
5553
|
+
|
|
5554
|
+
for (const axis of this.radarOption.yAxises) {
|
|
5555
|
+
this.points.push(axis.end);
|
|
5556
|
+
}
|
|
5557
|
+
|
|
5558
|
+
this.points.push(this.points[0]);
|
|
5559
|
+
return this.points;
|
|
5560
|
+
} else {
|
|
5561
|
+
return super.initPoints();
|
|
5562
|
+
}
|
|
5513
5563
|
}
|
|
5514
5564
|
/**
|
|
5515
5565
|
* 计算当前轴的位置
|
|
@@ -5525,7 +5575,39 @@
|
|
|
5525
5575
|
case 'x':
|
|
5526
5576
|
{
|
|
5527
5577
|
//初始化显示标签个数
|
|
5528
|
-
this.labelCount = this.style.xLabel.count || 5;
|
|
5578
|
+
this.labelCount = this.style.xLabel.count || 5; // 如果是雷达图,则画栅格线
|
|
5579
|
+
|
|
5580
|
+
if (this.radarOption) {
|
|
5581
|
+
if (this.style.grid && this.style.grid.x) {
|
|
5582
|
+
for (let i = 1; i < this.labelCount + 1; i++) {
|
|
5583
|
+
const points = [];
|
|
5584
|
+
const curRadius = this.radarOption.radius / this.labelCount * i;
|
|
5585
|
+
|
|
5586
|
+
for (const axis of this.radarOption.yAxises) {
|
|
5587
|
+
const point = {};
|
|
5588
|
+
point.x = axis.radarOption.center.x + axis.radarOption.cos * curRadius + bounds.left;
|
|
5589
|
+
point.y = axis.radarOption.center.y - axis.radarOption.sin * curRadius + bounds.top;
|
|
5590
|
+
points.push(point);
|
|
5591
|
+
} // 画栅格线
|
|
5592
|
+
|
|
5593
|
+
|
|
5594
|
+
for (let j = 0; j < points.length; j++) {
|
|
5595
|
+
const start = points[j];
|
|
5596
|
+
const end = points[j + 1] || points[0];
|
|
5597
|
+
const gridLine = this.graph.createShape('line', {
|
|
5598
|
+
start,
|
|
5599
|
+
end,
|
|
5600
|
+
style: this.style.grid
|
|
5601
|
+
});
|
|
5602
|
+
this.parent.children.add(gridLine);
|
|
5603
|
+
this.gridLines.push(gridLine);
|
|
5604
|
+
}
|
|
5605
|
+
}
|
|
5606
|
+
}
|
|
5607
|
+
|
|
5608
|
+
break;
|
|
5609
|
+
}
|
|
5610
|
+
|
|
5529
5611
|
this.start.x = bounds.left;
|
|
5530
5612
|
this.start.y = bounds.bottom;
|
|
5531
5613
|
this.end.x = bounds.right;
|
|
@@ -5544,21 +5626,30 @@
|
|
|
5544
5626
|
|
|
5545
5627
|
case 'y':
|
|
5546
5628
|
{
|
|
5547
|
-
|
|
5548
|
-
|
|
5629
|
+
//初始化显示标签个数
|
|
5630
|
+
this.labelCount = this.style.yLabel.count || 5;
|
|
5631
|
+
const index = this.index || 1; // 如果是雷达图,则画发散的线
|
|
5632
|
+
|
|
5633
|
+
if (this.radarOption) {
|
|
5634
|
+
this.end.x = this.radarOption.center.x + this.radarOption.cos * this.radarOption.radius + bounds.left;
|
|
5635
|
+
this.end.y = this.radarOption.center.y - this.radarOption.sin * this.radarOption.radius + bounds.top;
|
|
5636
|
+
this.start.x = this.radarOption.center.x + bounds.left;
|
|
5637
|
+
this.start.y = this.radarOption.center.y + bounds.top;
|
|
5638
|
+
} else {
|
|
5639
|
+
let xoffset = bounds.left; //多Y轴时,第二个为右边第一轴,其它的依此递推
|
|
5549
5640
|
|
|
5550
|
-
|
|
5641
|
+
if (index == 2) {
|
|
5642
|
+
xoffset = bounds.right;
|
|
5643
|
+
} else if (index > 2) {
|
|
5644
|
+
xoffset = this.graph.yAxises[index - 1].start.x + this.graph.yAxises[index - 1].width + 10;
|
|
5645
|
+
}
|
|
5551
5646
|
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5647
|
+
this.start.x = xoffset;
|
|
5648
|
+
this.start.y = bounds.bottom;
|
|
5649
|
+
this.end.x = this.start.x;
|
|
5650
|
+
this.end.y = bounds.top;
|
|
5556
5651
|
}
|
|
5557
5652
|
|
|
5558
|
-
this.start.x = xoffset;
|
|
5559
|
-
this.start.y = bounds.bottom;
|
|
5560
|
-
this.end.x = this.start.x;
|
|
5561
|
-
this.end.y = bounds.top;
|
|
5562
5653
|
break;
|
|
5563
5654
|
}
|
|
5564
5655
|
}
|
|
@@ -5580,11 +5671,12 @@
|
|
|
5580
5671
|
|
|
5581
5672
|
|
|
5582
5673
|
createLabel() {
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5674
|
+
if (this.visible === false) return; // 雷达图的标签单独处理
|
|
5675
|
+
|
|
5676
|
+
if (this.radarOption) {
|
|
5677
|
+
return this.createRadarLabel();
|
|
5678
|
+
} //如果是?X轴则执行X轴标签生成
|
|
5679
|
+
|
|
5588
5680
|
|
|
5589
5681
|
if (this.type == 'x') {
|
|
5590
5682
|
this.createXLabel();
|
|
@@ -5704,13 +5796,7 @@
|
|
|
5704
5796
|
|
|
5705
5797
|
let count = this.labelCount;
|
|
5706
5798
|
const mm = max - min;
|
|
5707
|
-
|
|
5708
|
-
count = mm;
|
|
5709
|
-
}*/
|
|
5710
|
-
// mm 放大10000倍,这里结果也需要除于10000
|
|
5711
|
-
|
|
5712
|
-
let pervalue = mm / count || 1; //if(pervalue > 1 || pervalue < -1) pervalue = Math.floor(pervalue);
|
|
5713
|
-
|
|
5799
|
+
let pervalue = mm / count || 1;
|
|
5714
5800
|
const format = this.option.format || this.format;
|
|
5715
5801
|
const marginLeft = this.style.yLabel.margin.left * this.graph.devicePixelRatio || 0;
|
|
5716
5802
|
const marginRight = this.style.yLabel.margin.right * this.graph.devicePixelRatio || 0;
|
|
@@ -5721,7 +5807,7 @@
|
|
|
5721
5807
|
if (p > max || i === count) p = max;
|
|
5722
5808
|
const h = (p - min) * step; // 当前点的偏移高度
|
|
5723
5809
|
|
|
5724
|
-
const label = this.graph.
|
|
5810
|
+
const label = this.graph.createShape('label', {
|
|
5725
5811
|
style: this.style.yLabel
|
|
5726
5812
|
});
|
|
5727
5813
|
label.text = format.call(this, p, label); // 格式化label
|
|
@@ -5754,7 +5840,7 @@
|
|
|
5754
5840
|
y: offy + this.end.y
|
|
5755
5841
|
}); // 指定要显示网格
|
|
5756
5842
|
|
|
5757
|
-
if (this.style.grid && this.style.grid.x) {
|
|
5843
|
+
if (!this.radarOption && this.style.grid && this.style.grid.x) {
|
|
5758
5844
|
// 它的坐标是相对于轴的,所以Y轴会用负的区域高度
|
|
5759
5845
|
const line = this.graph.createShape('line', {
|
|
5760
5846
|
start: {
|
|
@@ -5817,6 +5903,42 @@
|
|
|
5817
5903
|
}
|
|
5818
5904
|
}
|
|
5819
5905
|
}
|
|
5906
|
+
/**
|
|
5907
|
+
* 生成雷达图的Y轴标签
|
|
5908
|
+
*/
|
|
5909
|
+
|
|
5910
|
+
|
|
5911
|
+
createRadarLabel() {
|
|
5912
|
+
const format = this.option.format;
|
|
5913
|
+
const bounds = this.graph.chartArea.getBounds(); // 获取画图区域
|
|
5914
|
+
|
|
5915
|
+
const self = this;
|
|
5916
|
+
const label = this.graph.createShape('label', {
|
|
5917
|
+
style: this.style.yLabel,
|
|
5918
|
+
position: function () {
|
|
5919
|
+
// 因为axis是相对于chart的,而center是相对于chartArea的,所以要计算axis位置相对于chartArea来比较
|
|
5920
|
+
const pos = {
|
|
5921
|
+
x: self.end.x - bounds.left,
|
|
5922
|
+
y: self.end.y - bounds.top
|
|
5923
|
+
};
|
|
5924
|
+
const size = this.testSize();
|
|
5925
|
+
|
|
5926
|
+
if (pos.x < self.radarOption.center.x) {
|
|
5927
|
+
pos.x -= size.width;
|
|
5928
|
+
}
|
|
5929
|
+
|
|
5930
|
+
if (pos.y < self.radarOption.center.y) {
|
|
5931
|
+
pos.y -= size.height;
|
|
5932
|
+
}
|
|
5933
|
+
|
|
5934
|
+
return pos;
|
|
5935
|
+
}
|
|
5936
|
+
});
|
|
5937
|
+
label.text = typeof format === 'function' ? format.call(this, label) : this.field; // 格式化label
|
|
5938
|
+
|
|
5939
|
+
this.labels.push(label);
|
|
5940
|
+
this.graph.chartArea.children.add(label);
|
|
5941
|
+
}
|
|
5820
5942
|
/**
|
|
5821
5943
|
* 获取当前轴所占宽
|
|
5822
5944
|
*
|
|
@@ -5964,6 +6086,18 @@
|
|
|
5964
6086
|
clear() {
|
|
5965
6087
|
this._min = null;
|
|
5966
6088
|
this._max = null;
|
|
6089
|
+
this.children.each((i, c) => {
|
|
6090
|
+
c.remove();
|
|
6091
|
+
}, true); // 清空栅格线
|
|
6092
|
+
|
|
6093
|
+
this.gridLines && this.gridLines.forEach(line => {
|
|
6094
|
+
line.remove();
|
|
6095
|
+
});
|
|
6096
|
+
this.labels && this.labels.forEach(label => {
|
|
6097
|
+
label.remove();
|
|
6098
|
+
});
|
|
6099
|
+
this.labels = [];
|
|
6100
|
+
this.gridLines = [];
|
|
5967
6101
|
}
|
|
5968
6102
|
/**
|
|
5969
6103
|
* 计算当前轴的单位偏移量
|
|
@@ -5975,7 +6109,7 @@
|
|
|
5975
6109
|
|
|
5976
6110
|
step() {
|
|
5977
6111
|
if (this.type == 'x') {
|
|
5978
|
-
const w = this.width; //如果排版为内联,则单位占宽减少一个单位,
|
|
6112
|
+
const w = this.radarOption ? this.radarOption.radius : this.width; //如果排版为内联,则单位占宽减少一个单位,
|
|
5979
6113
|
//也就是起始位从一个单位开始
|
|
5980
6114
|
|
|
5981
6115
|
if (this.graph.style.layout == 'inside') {
|
|
@@ -5991,7 +6125,7 @@
|
|
|
5991
6125
|
|
|
5992
6126
|
return w / tmp;
|
|
5993
6127
|
} else if (this.type == 'y') {
|
|
5994
|
-
const h = this.height;
|
|
6128
|
+
const h = this.radarOption ? this.radarOption.radius : this.height;
|
|
5995
6129
|
|
|
5996
6130
|
switch (this.dataType) {
|
|
5997
6131
|
case 'string':
|
|
@@ -6255,7 +6389,7 @@
|
|
|
6255
6389
|
}); // 初始化一些参数, 因为这里有多个Y轴的可能,所以每次都需要重调一次init
|
|
6256
6390
|
|
|
6257
6391
|
this.yAxis.init({
|
|
6258
|
-
field: this.field,
|
|
6392
|
+
field: Array.isArray(this.field) ? this.field[0] : this.field,
|
|
6259
6393
|
minYValue: options.minYValue,
|
|
6260
6394
|
maxYValue: options.maxYValue
|
|
6261
6395
|
});
|
|
@@ -6310,6 +6444,11 @@
|
|
|
6310
6444
|
if (dataChanged) this.___animateCounter = 0; // 数据改变。动画重新开始
|
|
6311
6445
|
} else {
|
|
6312
6446
|
this.dataPoints = this.createPoints(...args);
|
|
6447
|
+
} // 执行初始化函数回调
|
|
6448
|
+
|
|
6449
|
+
|
|
6450
|
+
if (this.option && this.option.onInit) {
|
|
6451
|
+
this.option.onInit.apply(this, args);
|
|
6313
6452
|
}
|
|
6314
6453
|
|
|
6315
6454
|
return {
|
|
@@ -6378,12 +6517,12 @@
|
|
|
6378
6517
|
|
|
6379
6518
|
while (shape = this.shapes.shift()) {
|
|
6380
6519
|
shape && shape.remove();
|
|
6381
|
-
}
|
|
6382
|
-
|
|
6520
|
+
}
|
|
6383
6521
|
|
|
6384
|
-
this.createLegend();
|
|
6385
6522
|
this.initAxisValue(); // 处理最大值最小值
|
|
6523
|
+
//生成图例 这里要放到shape清理后面
|
|
6386
6524
|
|
|
6525
|
+
this.createLegend();
|
|
6387
6526
|
return this.chartInfo = {
|
|
6388
6527
|
xAxis: this.xAxis,
|
|
6389
6528
|
yAxis: this.yAxis
|
|
@@ -6509,6 +6648,7 @@
|
|
|
6509
6648
|
style
|
|
6510
6649
|
});
|
|
6511
6650
|
this.graph.legend.append(this, shape);
|
|
6651
|
+
return shape;
|
|
6512
6652
|
} // 生成柱图的标注
|
|
6513
6653
|
|
|
6514
6654
|
|
|
@@ -6774,15 +6914,18 @@
|
|
|
6774
6914
|
|
|
6775
6915
|
for (let index = 0; index < point.points.length; index++) {
|
|
6776
6916
|
const style = this.graph.utils.clone(this.style);
|
|
6917
|
+
const p = point.points[index];
|
|
6777
6918
|
|
|
6778
6919
|
if (style.color && typeof style.color === 'function') {
|
|
6779
|
-
style.fill = style.color.call(this,
|
|
6920
|
+
style.fill = style.color.call(this, {
|
|
6921
|
+
index,
|
|
6922
|
+
point: p
|
|
6923
|
+
});
|
|
6780
6924
|
} else {
|
|
6781
6925
|
style.fill = this.graph.getColor(index);
|
|
6782
6926
|
}
|
|
6783
6927
|
|
|
6784
6928
|
const sp = this.addShape(this.graph.createPath(null, style));
|
|
6785
|
-
const p = point.points[index];
|
|
6786
6929
|
let startY = topStartY;
|
|
6787
6930
|
if (p.yValue < this.baseYValue) startY = bottomStartY; //首先确定p1和p4,因为他们是底脚。会固定
|
|
6788
6931
|
|
|
@@ -6916,7 +7059,7 @@
|
|
|
6916
7059
|
x: this.graph.chartArea.width / 2,
|
|
6917
7060
|
y: this.graph.chartArea.height / 2
|
|
6918
7061
|
};
|
|
6919
|
-
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); //生成描点位
|
|
7062
|
+
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); //生成描点位
|
|
6920
7063
|
// super.init会把参数透传给 createPoints
|
|
6921
7064
|
|
|
6922
7065
|
const {
|
|
@@ -7008,7 +7151,8 @@
|
|
|
7008
7151
|
// 每个数值点比
|
|
7009
7152
|
style: this.graph.utils.clone(this.style),
|
|
7010
7153
|
anticlockwise
|
|
7011
|
-
};
|
|
7154
|
+
};
|
|
7155
|
+
points.push(p); //p.style.color = this.graph.getColor(index);
|
|
7012
7156
|
|
|
7013
7157
|
if (p.style.color && typeof p.style.color === 'function') {
|
|
7014
7158
|
p.style.fill = p.style.color.call(this, p);
|
|
@@ -7089,34 +7233,34 @@
|
|
|
7089
7233
|
|
|
7090
7234
|
if (this.option.onClick) {
|
|
7091
7235
|
p.shape.on('click', e => {
|
|
7092
|
-
this.option.onClick.call(this, p, e);
|
|
7236
|
+
return this.option.onClick.call(this, p, e);
|
|
7093
7237
|
});
|
|
7094
7238
|
}
|
|
7095
7239
|
|
|
7096
7240
|
if (this.option.onOver) {
|
|
7097
7241
|
p.shape.on('mouseover touchover', e => {
|
|
7098
|
-
this.option.onOver.call(this, p, e);
|
|
7242
|
+
return this.option.onOver.call(this, p, e);
|
|
7099
7243
|
});
|
|
7100
7244
|
}
|
|
7101
7245
|
|
|
7102
7246
|
if (this.option.onLeave) {
|
|
7103
7247
|
p.shape.on('mouseleave touchleave', e => {
|
|
7104
|
-
this.option.onLeave.call(this, p, e);
|
|
7248
|
+
return this.option.onLeave.call(this, p, e);
|
|
7105
7249
|
});
|
|
7106
7250
|
}
|
|
7107
7251
|
|
|
7108
7252
|
this.createLabel(p); // 生成标签
|
|
7109
|
-
|
|
7253
|
+
// 生成标点的回调
|
|
7110
7254
|
|
|
7111
|
-
|
|
7112
|
-
|
|
7255
|
+
this.emit('onPointCreated', p);
|
|
7256
|
+
}
|
|
7113
7257
|
|
|
7114
|
-
|
|
7258
|
+
index++;
|
|
7115
7259
|
}
|
|
7116
7260
|
}
|
|
7117
7261
|
|
|
7118
7262
|
return points;
|
|
7119
|
-
} //
|
|
7263
|
+
} // 生成图的标注
|
|
7120
7264
|
|
|
7121
7265
|
|
|
7122
7266
|
createLabel(point) {
|
|
@@ -7140,7 +7284,7 @@
|
|
|
7140
7284
|
}; // 动态计算位置
|
|
7141
7285
|
|
|
7142
7286
|
const parentRect = this.parent.getBounds(); //const rect = this.getBounds.call(this.parent);
|
|
7143
|
-
//
|
|
7287
|
+
// 圆弧的中间位,离圆心最近和最远的二个点
|
|
7144
7288
|
|
|
7145
7289
|
let centerMaxPoint = this.parent.points[Math.floor(this.parent.points.length / 2)];
|
|
7146
7290
|
let centerMinPoint = this.parent.center; // 如果是空心圆,则要计算 1/4 和 3/4位的点。顺时针和逆时针二个点大小不一样,这里只取,大小计算时处理
|
|
@@ -7217,6 +7361,329 @@
|
|
|
7217
7361
|
}
|
|
7218
7362
|
};
|
|
7219
7363
|
|
|
7364
|
+
/**
|
|
7365
|
+
* 雷达图
|
|
7366
|
+
*
|
|
7367
|
+
* @class jmRadarSeries
|
|
7368
|
+
* @module jmChart
|
|
7369
|
+
* @param {jmChart} chart 当前图表
|
|
7370
|
+
* @param {array} mappings 图形字段映射
|
|
7371
|
+
* @param {style} style 样式
|
|
7372
|
+
*/
|
|
7373
|
+
//构造函数
|
|
7374
|
+
|
|
7375
|
+
class jmRadarSeries extends jmSeries {
|
|
7376
|
+
constructor(options) {
|
|
7377
|
+
super(options);
|
|
7378
|
+
} // 重新生成轴,雷达图只需要Y轴即可
|
|
7379
|
+
|
|
7380
|
+
|
|
7381
|
+
createAxises(center, radius) {
|
|
7382
|
+
this.axises = [this.yAxis];
|
|
7383
|
+
const yCount = this.field.length;
|
|
7384
|
+
if (!yCount) return; //每个维度点的角度
|
|
7385
|
+
|
|
7386
|
+
const rotateStep = Math.PI * 2 / yCount; // 清空除了一个默认外的所有Y轴
|
|
7387
|
+
|
|
7388
|
+
for (let index in this.graph.yAxises) {
|
|
7389
|
+
const axis = this.graph.yAxises[index];
|
|
7390
|
+
if (!axis || axis === this.yAxis) continue;
|
|
7391
|
+
axis.remove();
|
|
7392
|
+
delete this.graph.yAxises[index];
|
|
7393
|
+
}
|
|
7394
|
+
|
|
7395
|
+
for (let index = 0; index < yCount; index++) {
|
|
7396
|
+
if (!this.field[index]) continue;
|
|
7397
|
+
let axis = this.yAxis; // 除了默认的y轴外,其它都重新生成
|
|
7398
|
+
|
|
7399
|
+
if (index > 0) {
|
|
7400
|
+
axis = this.graph.createYAxis({
|
|
7401
|
+
index: index + 1,
|
|
7402
|
+
format: this.option.yLabelFormat || this.graph.option.yLabelFormat
|
|
7403
|
+
});
|
|
7404
|
+
this.axises.push(axis);
|
|
7405
|
+
}
|
|
7406
|
+
|
|
7407
|
+
const rotate = Math.PI / 2 + rotateStep * index; //从向上90度开始
|
|
7408
|
+
|
|
7409
|
+
axis.init({
|
|
7410
|
+
field: this.field[index],
|
|
7411
|
+
radarOption: {
|
|
7412
|
+
center,
|
|
7413
|
+
radius,
|
|
7414
|
+
yCount,
|
|
7415
|
+
rotate: rotate,
|
|
7416
|
+
cos: Math.cos(rotate),
|
|
7417
|
+
sin: Math.sin(rotate)
|
|
7418
|
+
}
|
|
7419
|
+
});
|
|
7420
|
+
} // x轴初始化
|
|
7421
|
+
|
|
7422
|
+
|
|
7423
|
+
this.xAxis.init({
|
|
7424
|
+
radarOption: {
|
|
7425
|
+
center,
|
|
7426
|
+
radius,
|
|
7427
|
+
yCount,
|
|
7428
|
+
yAxises: this.axises
|
|
7429
|
+
}
|
|
7430
|
+
});
|
|
7431
|
+
return this.axises;
|
|
7432
|
+
} // 计算最大值和最小值,一般图形直接采用最大最小值即可,有些需要多值叠加
|
|
7433
|
+
|
|
7434
|
+
|
|
7435
|
+
initAxisValue() {
|
|
7436
|
+
this.center = {
|
|
7437
|
+
x: this.graph.chartArea.width / 2,
|
|
7438
|
+
y: this.graph.chartArea.height / 2
|
|
7439
|
+
};
|
|
7440
|
+
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);
|
|
7441
|
+
const axises = this.createAxises(this.center, this.radius); // 重置所有轴
|
|
7442
|
+
// 计算最大最小值
|
|
7443
|
+
// 当前需要先更新axis的边界值,轴好画图
|
|
7444
|
+
|
|
7445
|
+
for (let i = 0; i < this.data.length; i++) {
|
|
7446
|
+
axises.forEach(axis => {
|
|
7447
|
+
const v = this.data[i][axis.field];
|
|
7448
|
+
axis.max(v);
|
|
7449
|
+
axis.min(v);
|
|
7450
|
+
});
|
|
7451
|
+
}
|
|
7452
|
+
} // 重新初始化图形
|
|
7453
|
+
|
|
7454
|
+
|
|
7455
|
+
init() {
|
|
7456
|
+
//生成描点位
|
|
7457
|
+
// super.init会把参数透传给 createPoints
|
|
7458
|
+
const {
|
|
7459
|
+
points,
|
|
7460
|
+
dataChanged
|
|
7461
|
+
} = this.initDataPoint(this.center, this.radius);
|
|
7462
|
+
this.createLegend(points); // 是否正在动画中
|
|
7463
|
+
|
|
7464
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0);
|
|
7465
|
+
const aniCount = this.style.aniCount || 20;
|
|
7466
|
+
let aniIsEnd = true; // 当次是否结束动画
|
|
7467
|
+
|
|
7468
|
+
const len = points.length;
|
|
7469
|
+
const shapeMap = {};
|
|
7470
|
+
const self = this;
|
|
7471
|
+
|
|
7472
|
+
for (let i = 0; i < len; i++) {
|
|
7473
|
+
const p = points[i];
|
|
7474
|
+
let shape = shapeMap[p.index];
|
|
7475
|
+
|
|
7476
|
+
if (!shape) {
|
|
7477
|
+
shape = shapeMap[p.index] = this.graph.createShape('path', { ...p,
|
|
7478
|
+
style: p.style,
|
|
7479
|
+
points: []
|
|
7480
|
+
});
|
|
7481
|
+
this.addShape(shape); // 如果有点击事件
|
|
7482
|
+
|
|
7483
|
+
if (this.option.onClick) {
|
|
7484
|
+
shape.on('click', function (e) {
|
|
7485
|
+
return self.option.onClick.call(this, e);
|
|
7486
|
+
});
|
|
7487
|
+
}
|
|
7488
|
+
|
|
7489
|
+
if (this.option.onOver) {
|
|
7490
|
+
shape.on('mouseover touchover', function (e) {
|
|
7491
|
+
return self.option.onOver.call(this, e);
|
|
7492
|
+
});
|
|
7493
|
+
}
|
|
7494
|
+
|
|
7495
|
+
if (this.option.onLeave) {
|
|
7496
|
+
shape.on('mouseleave touchleave', function (e) {
|
|
7497
|
+
return self.option.onLeave.call(this, e);
|
|
7498
|
+
});
|
|
7499
|
+
}
|
|
7500
|
+
}
|
|
7501
|
+
|
|
7502
|
+
shape.zIndex += p.radius / this.radius; // 用每个轴占比做为排序号,这样占面积最大的排最底层
|
|
7503
|
+
|
|
7504
|
+
let point = null; // 在动画中,则一直刷新
|
|
7505
|
+
|
|
7506
|
+
if (isRunningAni) {
|
|
7507
|
+
let step = p.radius / aniCount * this.___animateCounter;
|
|
7508
|
+
|
|
7509
|
+
if (step >= p.radius) {
|
|
7510
|
+
step = p.radius;
|
|
7511
|
+
} else {
|
|
7512
|
+
aniIsEnd = false;
|
|
7513
|
+
}
|
|
7514
|
+
|
|
7515
|
+
point = { ...p,
|
|
7516
|
+
x: this.center.x + p.axis.radarOption.cos * step,
|
|
7517
|
+
y: this.center.y - p.axis.radarOption.sin * step
|
|
7518
|
+
};
|
|
7519
|
+
} else {
|
|
7520
|
+
point = p;
|
|
7521
|
+
}
|
|
7522
|
+
|
|
7523
|
+
shape.points.push(point);
|
|
7524
|
+
this.createLabel(point); // 生成标签
|
|
7525
|
+
} // 所有动画都完成,则清空计数器
|
|
7526
|
+
|
|
7527
|
+
|
|
7528
|
+
if (aniIsEnd) {
|
|
7529
|
+
this.___animateCounter = 0;
|
|
7530
|
+
} else {
|
|
7531
|
+
this.___animateCounter++; // next tick 再次刷新
|
|
7532
|
+
|
|
7533
|
+
this.graph.utils.requestAnimationFrame(() => {
|
|
7534
|
+
this.needUpdate = true; //需要刷新
|
|
7535
|
+
});
|
|
7536
|
+
}
|
|
7537
|
+
}
|
|
7538
|
+
/**
|
|
7539
|
+
* 生成序列图描点
|
|
7540
|
+
*
|
|
7541
|
+
* @method createPoints
|
|
7542
|
+
*/
|
|
7543
|
+
|
|
7544
|
+
|
|
7545
|
+
createPoints(center, radius) {
|
|
7546
|
+
if (!this.data || !this.axises) return [];
|
|
7547
|
+
center = center || this.center;
|
|
7548
|
+
const points = [];
|
|
7549
|
+
|
|
7550
|
+
for (var i = 0; i < this.data.length; i++) {
|
|
7551
|
+
const s = this.data[i];
|
|
7552
|
+
const style = this.graph.utils.clone(this.style);
|
|
7553
|
+
|
|
7554
|
+
if (style.color && typeof style.color === 'function') {
|
|
7555
|
+
style.stroke = style.color.call(this, {
|
|
7556
|
+
data: s,
|
|
7557
|
+
index: i
|
|
7558
|
+
});
|
|
7559
|
+
} else {
|
|
7560
|
+
style.stroke = this.graph.getColor(i);
|
|
7561
|
+
}
|
|
7562
|
+
|
|
7563
|
+
if (typeof style.fill === 'function') {
|
|
7564
|
+
style.fill = style.fill.call(this, style);
|
|
7565
|
+
} else {
|
|
7566
|
+
const color = this.graph.utils.hexToRGBA(style.stroke);
|
|
7567
|
+
style.fill = `rgba(${color.r},${color.g},${color.b}, 0.2)`;
|
|
7568
|
+
}
|
|
7569
|
+
|
|
7570
|
+
const shapePoints = [];
|
|
7571
|
+
|
|
7572
|
+
for (const axis of this.axises) {
|
|
7573
|
+
const yv = s[axis.field];
|
|
7574
|
+
const p = {
|
|
7575
|
+
x: center.x,
|
|
7576
|
+
y: center.y,
|
|
7577
|
+
index: i,
|
|
7578
|
+
radius: 0,
|
|
7579
|
+
data: s,
|
|
7580
|
+
yValue: yv,
|
|
7581
|
+
yLabel: yv,
|
|
7582
|
+
style,
|
|
7583
|
+
axis
|
|
7584
|
+
};
|
|
7585
|
+
shapePoints.push(p); //如果Y值不存在。则此点无效,不画图
|
|
7586
|
+
|
|
7587
|
+
if (yv == null || typeof yv == 'undefined') {
|
|
7588
|
+
continue;
|
|
7589
|
+
}
|
|
7590
|
+
|
|
7591
|
+
p.radius = Math.abs(yv - axis.min()) * axis.step();
|
|
7592
|
+
p.x = center.x + axis.radarOption.cos * p.radius;
|
|
7593
|
+
p.y = center.y - axis.radarOption.sin * p.radius; // 生成标点的回调
|
|
7594
|
+
|
|
7595
|
+
this.emit('onPointCreated', p);
|
|
7596
|
+
}
|
|
7597
|
+
|
|
7598
|
+
points.push(...shapePoints);
|
|
7599
|
+
}
|
|
7600
|
+
|
|
7601
|
+
return points;
|
|
7602
|
+
} // 生成图的标注
|
|
7603
|
+
|
|
7604
|
+
|
|
7605
|
+
createLabel(point) {
|
|
7606
|
+
if (this.style.label && this.style.label.show === false) return;
|
|
7607
|
+
const text = this.option.itemLabelFormat ? this.option.itemLabelFormat.call(this, point) : point.yValue;
|
|
7608
|
+
if (!text) return; // v如果指定了为控件,则直接加入
|
|
7609
|
+
|
|
7610
|
+
if (text instanceof jmControl) {
|
|
7611
|
+
this.addShape(text);
|
|
7612
|
+
return text;
|
|
7613
|
+
}
|
|
7614
|
+
|
|
7615
|
+
const self = this;
|
|
7616
|
+
const label = this.graph.createShape('label', {
|
|
7617
|
+
style: this.style.label,
|
|
7618
|
+
text: text,
|
|
7619
|
+
point,
|
|
7620
|
+
position: function () {
|
|
7621
|
+
const p = {
|
|
7622
|
+
x: this.option.point.x,
|
|
7623
|
+
y: this.option.point.y
|
|
7624
|
+
};
|
|
7625
|
+
|
|
7626
|
+
if (p.x < self.center.x) {
|
|
7627
|
+
p.x -= this.width;
|
|
7628
|
+
}
|
|
7629
|
+
|
|
7630
|
+
if (p.y < self.center.y) {
|
|
7631
|
+
p.y -= this.height;
|
|
7632
|
+
}
|
|
7633
|
+
|
|
7634
|
+
return p;
|
|
7635
|
+
}
|
|
7636
|
+
});
|
|
7637
|
+
this.addShape(label);
|
|
7638
|
+
}
|
|
7639
|
+
|
|
7640
|
+
}
|
|
7641
|
+
/**
|
|
7642
|
+
* 生成图例
|
|
7643
|
+
*
|
|
7644
|
+
* @method createLegend
|
|
7645
|
+
*/
|
|
7646
|
+
|
|
7647
|
+
jmRadarSeries.prototype.createLegend = function (points) {
|
|
7648
|
+
if (!points || !points.length) return;
|
|
7649
|
+
const legendMap = {};
|
|
7650
|
+
|
|
7651
|
+
for (let k in points) {
|
|
7652
|
+
const p = points[k];
|
|
7653
|
+
if (!p) continue;
|
|
7654
|
+
if (legendMap[p.index]) continue; //生成图例前的图标
|
|
7655
|
+
|
|
7656
|
+
const style = this.graph.utils.clone(p.style);
|
|
7657
|
+
style.fill = style.fill; //delete style.stroke;
|
|
7658
|
+
|
|
7659
|
+
const shape = legendMap[p.index] = this.graph.createShape('rect', {
|
|
7660
|
+
style: style,
|
|
7661
|
+
position: {
|
|
7662
|
+
x: 0,
|
|
7663
|
+
y: 0
|
|
7664
|
+
}
|
|
7665
|
+
}); //shape.targetShape = p.shape;
|
|
7666
|
+
//此处重写图例事件
|
|
7667
|
+
|
|
7668
|
+
this.graph.legend.append(this, shape, {
|
|
7669
|
+
name: this.legendLabel,
|
|
7670
|
+
hover: function () {
|
|
7671
|
+
//var sp = this.children.get(0);
|
|
7672
|
+
//应用图的动态样式
|
|
7673
|
+
Object.assign(this.targetShape.style, this.targetShape.style.hover);
|
|
7674
|
+
Object.assign(this.style, this.style.hover);
|
|
7675
|
+
},
|
|
7676
|
+
leave: function () {
|
|
7677
|
+
//var sp = this.children.get(0);
|
|
7678
|
+
//应用图的普通样式
|
|
7679
|
+
Object.assign(this.targetShape.style, this.targetShape.style.normal);
|
|
7680
|
+
Object.assign(this.style, this.style.normal);
|
|
7681
|
+
},
|
|
7682
|
+
data: p.data
|
|
7683
|
+
});
|
|
7684
|
+
}
|
|
7685
|
+
};
|
|
7686
|
+
|
|
7220
7687
|
/**
|
|
7221
7688
|
* 图形基类
|
|
7222
7689
|
*
|
|
@@ -8000,6 +8467,7 @@
|
|
|
8000
8467
|
|
|
8001
8468
|
if (chart.style.markLine.lock) {
|
|
8002
8469
|
// 标线状态一直禁用系统能力
|
|
8470
|
+
// 如果指定了锁定值,只需要一项符合要求就进行锁定
|
|
8003
8471
|
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) {
|
|
8004
8472
|
lineTouching = 1;
|
|
8005
8473
|
args.event.preventDefault(); // 阻止默认行为
|
|
@@ -8393,7 +8861,7 @@
|
|
|
8393
8861
|
type: 'x',
|
|
8394
8862
|
visible: this.style.axis.x === false ? false : true,
|
|
8395
8863
|
format: this.option.xLabelFormat,
|
|
8396
|
-
...this.option.
|
|
8864
|
+
...this.option.xAxisOption
|
|
8397
8865
|
}, options || {});
|
|
8398
8866
|
|
|
8399
8867
|
if (typeof this.option.minXValue !== 'undefined') {
|
|
@@ -8430,7 +8898,7 @@
|
|
|
8430
8898
|
visible: this.style.axis.y === false ? false : true,
|
|
8431
8899
|
format: this.option.yLabelFormat,
|
|
8432
8900
|
zeroBase: this.baseY === 0,
|
|
8433
|
-
...this.option.
|
|
8901
|
+
...this.option.yAxisOption
|
|
8434
8902
|
}, options || {});
|
|
8435
8903
|
|
|
8436
8904
|
if (typeof this.option.minYValue !== 'undefined') {
|
|
@@ -8462,6 +8930,7 @@
|
|
|
8462
8930
|
'bar': jmBarSeries,
|
|
8463
8931
|
'stackBar': jmStackBarSeries,
|
|
8464
8932
|
'pie': jmPieSeries,
|
|
8933
|
+
'radar': jmRadarSeries,
|
|
8465
8934
|
'stackLine': jmStackLineSeries,
|
|
8466
8935
|
'candlestick': jmCandlestickSeries
|
|
8467
8936
|
};
|