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