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