jmchart 1.2.10 → 1.2.11
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 +322 -40
- package/build.js +35 -35
- package/dist/jmchart.amd.js +8206 -6502
- package/dist/jmchart.cjs.js +8203 -6499
- package/dist/jmchart.esm.js +8202 -6498
- package/dist/jmchart.iife.js +8204 -6500
- package/dist/jmchart.system.js +8204 -6500
- package/index.js +8 -8
- package/package.json +7 -7
- package/rollup.config.js +26 -26
- package/server.js +48 -48
- package/src/common/style.js +285 -285
- package/src/common/tooltip.js +165 -165
- package/src/common/utils.js +21 -21
- package/src/component/vchart.js +130 -143
- package/src/core/axis/axis.js +727 -727
- package/src/core/legend/legend.js +145 -145
- package/src/core/markLine/manager.js +186 -186
- package/src/core/markLine/markLine.js +191 -191
- package/src/jmChart.js +427 -427
- package/src/series/barSeries.js +123 -135
- package/src/series/candlestickSeries.js +114 -114
- package/src/series/lineSeries.js +224 -243
- package/src/series/pieSeries.js +337 -337
- package/src/series/radarSeries.js +313 -313
- package/src/series/series.js +387 -404
- package/src/series/stackBarSeries.js +149 -149
- package/src/series/stackLineSeries.js +145 -145
|
@@ -1,313 +1,313 @@
|
|
|
1
|
-
import {
|
|
2
|
-
jmControl
|
|
3
|
-
} from 'jmgraph';
|
|
4
|
-
import jmSeries from './series.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 雷达图
|
|
8
|
-
*
|
|
9
|
-
* @class jmRadarSeries
|
|
10
|
-
* @module jmChart
|
|
11
|
-
* @param {jmChart} chart 当前图表
|
|
12
|
-
* @param {array} mappings 图形字段映射
|
|
13
|
-
* @param {style} style 样式
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
//构造函数
|
|
17
|
-
export default class jmRadarSeries extends jmSeries {
|
|
18
|
-
constructor(options) {
|
|
19
|
-
super(options);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// 重新生成轴,雷达图只需要Y轴即可
|
|
23
|
-
createAxises(center, radius) {
|
|
24
|
-
|
|
25
|
-
this.axises = [
|
|
26
|
-
this.yAxis
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
const yCount = this.field.length;
|
|
30
|
-
if(!yCount) return;
|
|
31
|
-
|
|
32
|
-
//每个维度点的角度
|
|
33
|
-
const rotateStep = Math.PI * 2 / yCount;
|
|
34
|
-
|
|
35
|
-
// 清空除了一个默认外的所有Y轴
|
|
36
|
-
for(let index in this.graph.yAxises) {
|
|
37
|
-
const axis = this.graph.yAxises[index];
|
|
38
|
-
if(!axis || axis === this.yAxis) continue;
|
|
39
|
-
axis.remove();
|
|
40
|
-
delete this.graph.yAxises[index];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
for(let index=0; index < yCount; index++) {
|
|
44
|
-
if(!this.field[index]) continue;
|
|
45
|
-
let axis = this.yAxis;
|
|
46
|
-
// 除了默认的y轴外,其它都重新生成
|
|
47
|
-
if(index > 0) {
|
|
48
|
-
axis = this.graph.createYAxis({
|
|
49
|
-
index: index + 1,
|
|
50
|
-
format: this.option.yLabelFormat || this.graph.option.yLabelFormat
|
|
51
|
-
});
|
|
52
|
-
this.axises.push(axis);
|
|
53
|
-
}
|
|
54
|
-
const rotate = Math.PI/2 + rotateStep * index; //从向上90度开始
|
|
55
|
-
axis.init({
|
|
56
|
-
field: this.field[index],
|
|
57
|
-
radarOption: {
|
|
58
|
-
center,
|
|
59
|
-
radius,
|
|
60
|
-
yCount,
|
|
61
|
-
rotate: rotate,
|
|
62
|
-
cos: Math.cos(rotate),
|
|
63
|
-
sin: Math.sin(rotate)
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// x轴初始化
|
|
70
|
-
this.xAxis.init({
|
|
71
|
-
radarOption: {
|
|
72
|
-
center,
|
|
73
|
-
radius,
|
|
74
|
-
yCount,
|
|
75
|
-
yAxises: this.axises
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
return this.axises;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// 计算最大值和最小值,一般图形直接采用最大最小值即可,有些需要多值叠加
|
|
83
|
-
initAxisValue() {
|
|
84
|
-
this.center = {
|
|
85
|
-
x: this.graph.chartArea.width / 2,
|
|
86
|
-
y: this.graph.chartArea.height / 2
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
this.radius = Math.min(this.center.x - this.style.margin.left -
|
|
90
|
-
this.style.margin.right,
|
|
91
|
-
this.center.y - this.style.margin.top - this.style.margin.bottom);
|
|
92
|
-
|
|
93
|
-
const axises = this.createAxises(this.center, this.radius);// 重置所有轴
|
|
94
|
-
// 计算最大最小值
|
|
95
|
-
// 当前需要先更新axis的边界值,轴好画图
|
|
96
|
-
for(let i=0; i< this.data.length;i++) {
|
|
97
|
-
axises.forEach((axis)=> {
|
|
98
|
-
const v = this.data[i][axis.field];
|
|
99
|
-
axis.max(v);
|
|
100
|
-
axis.min(v);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// 重新初始化图形
|
|
106
|
-
init() {
|
|
107
|
-
//生成描点位
|
|
108
|
-
// super.init会把参数透传给 createPoints
|
|
109
|
-
const { points, dataChanged } = this.initDataPoint(this.center, this.radius);
|
|
110
|
-
|
|
111
|
-
// 是否正在动画中
|
|
112
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0 );
|
|
113
|
-
|
|
114
|
-
const aniCount = (this.style.aniCount || 20);
|
|
115
|
-
let aniIsEnd = true;// 当次是否结束动画
|
|
116
|
-
const len = points.length;
|
|
117
|
-
const shapeMap = {};
|
|
118
|
-
const self = this;
|
|
119
|
-
|
|
120
|
-
for(let i=0; i<len; i++) {
|
|
121
|
-
const p = points[i];
|
|
122
|
-
let shape = shapeMap[p.index];
|
|
123
|
-
if(!shape) {
|
|
124
|
-
shape = shapeMap[p.index] = this.graph.createShape('path', {
|
|
125
|
-
...p,
|
|
126
|
-
style: p.style,
|
|
127
|
-
points: [],
|
|
128
|
-
});
|
|
129
|
-
this.addShape(shape);
|
|
130
|
-
|
|
131
|
-
// 如果有点击事件
|
|
132
|
-
if(this.option.onClick) {
|
|
133
|
-
shape.on('click', function(e) {
|
|
134
|
-
return self.option.onClick.call(this, e);
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
if(this.option.onOver) {
|
|
138
|
-
shape.on('mouseover touchover', function(e) {
|
|
139
|
-
return self.option.onOver.call(this, e);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
if(this.option.onLeave) {
|
|
143
|
-
shape.on('mouseleave touchleave', function(e) {
|
|
144
|
-
return self.option.onLeave.call(this, e);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
this.createLegend(p);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
shape.zIndex += p.radius / this.radius;// 用每个轴占比做为排序号,这样占面积最大的排最底层
|
|
151
|
-
let point = null;
|
|
152
|
-
// 在动画中,则一直刷新
|
|
153
|
-
if(isRunningAni) {
|
|
154
|
-
let step = p.radius / aniCount * this.___animateCounter;
|
|
155
|
-
if(step >= p.radius) {
|
|
156
|
-
step = p.radius;
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
aniIsEnd = false;
|
|
160
|
-
}
|
|
161
|
-
point = {
|
|
162
|
-
...p,
|
|
163
|
-
x: this.center.x + p.axis.radarOption.cos * step,
|
|
164
|
-
y: this.center.y - p.axis.radarOption.sin * step,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
point = p;
|
|
169
|
-
}
|
|
170
|
-
shape.points.push(point);
|
|
171
|
-
this.createLabel(point);// 生成标签
|
|
172
|
-
}
|
|
173
|
-
// 所有动画都完成,则清空计数器
|
|
174
|
-
if(aniIsEnd) {
|
|
175
|
-
this.___animateCounter = 0;
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
this.___animateCounter ++;
|
|
179
|
-
// next tick 再次刷新
|
|
180
|
-
this.graph.utils.requestAnimationFrame(()=>{
|
|
181
|
-
this.needUpdate = true;//需要刷新
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* 生成序列图描点
|
|
188
|
-
*
|
|
189
|
-
* @method createPoints
|
|
190
|
-
*/
|
|
191
|
-
createPoints(center, radius) {
|
|
192
|
-
if(!this.data || !this.axises) return [];
|
|
193
|
-
center = center || this.center;
|
|
194
|
-
const points = [];
|
|
195
|
-
|
|
196
|
-
for(var i=0;i< this.data.length;i++) {
|
|
197
|
-
const s = this.data[i];
|
|
198
|
-
const style = this.graph.utils.clone(this.style);
|
|
199
|
-
if(style.color && typeof style.color === 'function') {
|
|
200
|
-
style.stroke = style.color.call(this, {
|
|
201
|
-
data: s,
|
|
202
|
-
index: i
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
style.stroke = this.graph.getColor(i);
|
|
207
|
-
}
|
|
208
|
-
if(typeof style.fill === 'function') {
|
|
209
|
-
style.fill = style.fill.call(this, style);
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
const color = this.graph.utils.hexToRGBA(style.stroke);
|
|
213
|
-
style.fill = `rgba(${color.r},${color.g},${color.b}, 0.2)`;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const shapePoints = [];
|
|
217
|
-
for(const axis of this.axises) {
|
|
218
|
-
if(!axis || !axis.field) continue;
|
|
219
|
-
const yv = s[axis.field];
|
|
220
|
-
|
|
221
|
-
const p = {
|
|
222
|
-
x: center.x,
|
|
223
|
-
y: center.y,
|
|
224
|
-
index: i,
|
|
225
|
-
radius: 0,
|
|
226
|
-
data: s,
|
|
227
|
-
yValue: yv,
|
|
228
|
-
yLabel: yv,
|
|
229
|
-
style,
|
|
230
|
-
axis
|
|
231
|
-
};
|
|
232
|
-
shapePoints.push(p);
|
|
233
|
-
|
|
234
|
-
//如果Y值不存在。则此点无效,不画图
|
|
235
|
-
if(yv == null || typeof yv == 'undefined') {
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
p.radius = Math.abs(yv - axis.min()) * axis.step();
|
|
240
|
-
p.x = center.x + axis.radarOption.cos * p.radius;
|
|
241
|
-
p.y = center.y - axis.radarOption.sin * p.radius;
|
|
242
|
-
|
|
243
|
-
// 生成标点的回调
|
|
244
|
-
this.emit('onPointCreated', p);
|
|
245
|
-
}
|
|
246
|
-
points.push(...shapePoints);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return points;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// 生成图的标注
|
|
253
|
-
createLabel(point) {
|
|
254
|
-
if(this.style.label && this.style.label.show === false) return;
|
|
255
|
-
|
|
256
|
-
const text = this.option.itemLabelFormat?this.option.itemLabelFormat.call(this, point): point.yValue;
|
|
257
|
-
if(!text) return;
|
|
258
|
-
|
|
259
|
-
// v如果指定了为控件,则直接加入
|
|
260
|
-
if(text instanceof jmControl) {
|
|
261
|
-
this.addShape(text);
|
|
262
|
-
return text;
|
|
263
|
-
}
|
|
264
|
-
const self = this;
|
|
265
|
-
const label = this.graph.createShape('label', {
|
|
266
|
-
style: this.style.label,
|
|
267
|
-
text: text,
|
|
268
|
-
point,
|
|
269
|
-
position: function() {
|
|
270
|
-
const p = {
|
|
271
|
-
x: this.option.point.x,
|
|
272
|
-
y: this.option.point.y
|
|
273
|
-
}
|
|
274
|
-
if(p.x < self.center.x) {
|
|
275
|
-
p.x -= this.width;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if(p.y < self.center.y) {
|
|
279
|
-
p.y -= this.height;
|
|
280
|
-
}
|
|
281
|
-
return p;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
this.addShape(label);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* 生成图例
|
|
293
|
-
*
|
|
294
|
-
* @method createLegend
|
|
295
|
-
*/
|
|
296
|
-
jmRadarSeries.prototype.createLegend = function(point) {
|
|
297
|
-
if(!point) return;
|
|
298
|
-
|
|
299
|
-
//生成图例前的图标
|
|
300
|
-
const style = this.graph.utils.clone(point.style);
|
|
301
|
-
|
|
302
|
-
//delete style.stroke;
|
|
303
|
-
const shape = this.graph.createShape('rect',{
|
|
304
|
-
style: style,
|
|
305
|
-
position : {x: 0, y: 0}
|
|
306
|
-
});
|
|
307
|
-
//此处重写图例事件
|
|
308
|
-
this.graph.legend.append(this, shape, {
|
|
309
|
-
name: this.legendLabel,
|
|
310
|
-
data: point.data
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
|
|
1
|
+
import {
|
|
2
|
+
jmControl
|
|
3
|
+
} from 'jmgraph';
|
|
4
|
+
import jmSeries from './series.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 雷达图
|
|
8
|
+
*
|
|
9
|
+
* @class jmRadarSeries
|
|
10
|
+
* @module jmChart
|
|
11
|
+
* @param {jmChart} chart 当前图表
|
|
12
|
+
* @param {array} mappings 图形字段映射
|
|
13
|
+
* @param {style} style 样式
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
//构造函数
|
|
17
|
+
export default class jmRadarSeries extends jmSeries {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
super(options);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 重新生成轴,雷达图只需要Y轴即可
|
|
23
|
+
createAxises(center, radius) {
|
|
24
|
+
|
|
25
|
+
this.axises = [
|
|
26
|
+
this.yAxis
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const yCount = this.field.length;
|
|
30
|
+
if(!yCount) return;
|
|
31
|
+
|
|
32
|
+
//每个维度点的角度
|
|
33
|
+
const rotateStep = Math.PI * 2 / yCount;
|
|
34
|
+
|
|
35
|
+
// 清空除了一个默认外的所有Y轴
|
|
36
|
+
for(let index in this.graph.yAxises) {
|
|
37
|
+
const axis = this.graph.yAxises[index];
|
|
38
|
+
if(!axis || axis === this.yAxis) continue;
|
|
39
|
+
axis.remove();
|
|
40
|
+
delete this.graph.yAxises[index];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for(let index=0; index < yCount; index++) {
|
|
44
|
+
if(!this.field[index]) continue;
|
|
45
|
+
let axis = this.yAxis;
|
|
46
|
+
// 除了默认的y轴外,其它都重新生成
|
|
47
|
+
if(index > 0) {
|
|
48
|
+
axis = this.graph.createYAxis({
|
|
49
|
+
index: index + 1,
|
|
50
|
+
format: this.option.yLabelFormat || this.graph.option.yLabelFormat
|
|
51
|
+
});
|
|
52
|
+
this.axises.push(axis);
|
|
53
|
+
}
|
|
54
|
+
const rotate = Math.PI/2 + rotateStep * index; //从向上90度开始
|
|
55
|
+
axis.init({
|
|
56
|
+
field: this.field[index],
|
|
57
|
+
radarOption: {
|
|
58
|
+
center,
|
|
59
|
+
radius,
|
|
60
|
+
yCount,
|
|
61
|
+
rotate: rotate,
|
|
62
|
+
cos: Math.cos(rotate),
|
|
63
|
+
sin: Math.sin(rotate)
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// x轴初始化
|
|
70
|
+
this.xAxis.init({
|
|
71
|
+
radarOption: {
|
|
72
|
+
center,
|
|
73
|
+
radius,
|
|
74
|
+
yCount,
|
|
75
|
+
yAxises: this.axises
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return this.axises;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 计算最大值和最小值,一般图形直接采用最大最小值即可,有些需要多值叠加
|
|
83
|
+
initAxisValue() {
|
|
84
|
+
this.center = {
|
|
85
|
+
x: this.graph.chartArea.width / 2,
|
|
86
|
+
y: this.graph.chartArea.height / 2
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
this.radius = Math.min(this.center.x - this.style.margin.left -
|
|
90
|
+
this.style.margin.right,
|
|
91
|
+
this.center.y - this.style.margin.top - this.style.margin.bottom);
|
|
92
|
+
|
|
93
|
+
const axises = this.createAxises(this.center, this.radius);// 重置所有轴
|
|
94
|
+
// 计算最大最小值
|
|
95
|
+
// 当前需要先更新axis的边界值,轴好画图
|
|
96
|
+
for(let i=0; i< this.data.length;i++) {
|
|
97
|
+
axises.forEach((axis)=> {
|
|
98
|
+
const v = this.data[i][axis.field];
|
|
99
|
+
axis.max(v);
|
|
100
|
+
axis.min(v);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 重新初始化图形
|
|
106
|
+
init() {
|
|
107
|
+
//生成描点位
|
|
108
|
+
// super.init会把参数透传给 createPoints
|
|
109
|
+
const { points, dataChanged } = this.initDataPoint(this.center, this.radius);
|
|
110
|
+
|
|
111
|
+
// 是否正在动画中
|
|
112
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0 );
|
|
113
|
+
|
|
114
|
+
const aniCount = (this.style.aniCount || 20);
|
|
115
|
+
let aniIsEnd = true;// 当次是否结束动画
|
|
116
|
+
const len = points.length;
|
|
117
|
+
const shapeMap = {};
|
|
118
|
+
const self = this;
|
|
119
|
+
|
|
120
|
+
for(let i=0; i<len; i++) {
|
|
121
|
+
const p = points[i];
|
|
122
|
+
let shape = shapeMap[p.index];
|
|
123
|
+
if(!shape) {
|
|
124
|
+
shape = shapeMap[p.index] = this.graph.createShape('path', {
|
|
125
|
+
...p,
|
|
126
|
+
style: p.style,
|
|
127
|
+
points: [],
|
|
128
|
+
});
|
|
129
|
+
this.addShape(shape);
|
|
130
|
+
|
|
131
|
+
// 如果有点击事件
|
|
132
|
+
if(this.option.onClick) {
|
|
133
|
+
shape.on('click', function(e) {
|
|
134
|
+
return self.option.onClick.call(this, e);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if(this.option.onOver) {
|
|
138
|
+
shape.on('mouseover touchover', function(e) {
|
|
139
|
+
return self.option.onOver.call(this, e);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if(this.option.onLeave) {
|
|
143
|
+
shape.on('mouseleave touchleave', function(e) {
|
|
144
|
+
return self.option.onLeave.call(this, e);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
this.createLegend(p);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
shape.zIndex += p.radius / this.radius;// 用每个轴占比做为排序号,这样占面积最大的排最底层
|
|
151
|
+
let point = null;
|
|
152
|
+
// 在动画中,则一直刷新
|
|
153
|
+
if(isRunningAni) {
|
|
154
|
+
let step = p.radius / aniCount * this.___animateCounter;
|
|
155
|
+
if(step >= p.radius) {
|
|
156
|
+
step = p.radius;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
aniIsEnd = false;
|
|
160
|
+
}
|
|
161
|
+
point = {
|
|
162
|
+
...p,
|
|
163
|
+
x: this.center.x + p.axis.radarOption.cos * step,
|
|
164
|
+
y: this.center.y - p.axis.radarOption.sin * step,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
point = p;
|
|
169
|
+
}
|
|
170
|
+
shape.points.push(point);
|
|
171
|
+
this.createLabel(point);// 生成标签
|
|
172
|
+
}
|
|
173
|
+
// 所有动画都完成,则清空计数器
|
|
174
|
+
if(aniIsEnd) {
|
|
175
|
+
this.___animateCounter = 0;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
this.___animateCounter ++;
|
|
179
|
+
// next tick 再次刷新
|
|
180
|
+
this.graph.utils.requestAnimationFrame(()=>{
|
|
181
|
+
this.needUpdate = true;//需要刷新
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 生成序列图描点
|
|
188
|
+
*
|
|
189
|
+
* @method createPoints
|
|
190
|
+
*/
|
|
191
|
+
createPoints(center, radius) {
|
|
192
|
+
if(!this.data || !this.axises) return [];
|
|
193
|
+
center = center || this.center;
|
|
194
|
+
const points = [];
|
|
195
|
+
|
|
196
|
+
for(var i=0;i< this.data.length;i++) {
|
|
197
|
+
const s = this.data[i];
|
|
198
|
+
const style = this.graph.utils.clone(this.style);
|
|
199
|
+
if(style.color && typeof style.color === 'function') {
|
|
200
|
+
style.stroke = style.color.call(this, {
|
|
201
|
+
data: s,
|
|
202
|
+
index: i
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
style.stroke = this.graph.getColor(i);
|
|
207
|
+
}
|
|
208
|
+
if(typeof style.fill === 'function') {
|
|
209
|
+
style.fill = style.fill.call(this, style);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
const color = this.graph.utils.hexToRGBA(style.stroke);
|
|
213
|
+
style.fill = `rgba(${color.r},${color.g},${color.b}, 0.2)`;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const shapePoints = [];
|
|
217
|
+
for(const axis of this.axises) {
|
|
218
|
+
if(!axis || !axis.field) continue;
|
|
219
|
+
const yv = s[axis.field];
|
|
220
|
+
|
|
221
|
+
const p = {
|
|
222
|
+
x: center.x,
|
|
223
|
+
y: center.y,
|
|
224
|
+
index: i,
|
|
225
|
+
radius: 0,
|
|
226
|
+
data: s,
|
|
227
|
+
yValue: yv,
|
|
228
|
+
yLabel: yv,
|
|
229
|
+
style,
|
|
230
|
+
axis
|
|
231
|
+
};
|
|
232
|
+
shapePoints.push(p);
|
|
233
|
+
|
|
234
|
+
//如果Y值不存在。则此点无效,不画图
|
|
235
|
+
if(yv == null || typeof yv == 'undefined') {
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
p.radius = Math.abs(yv - axis.min()) * axis.step();
|
|
240
|
+
p.x = center.x + axis.radarOption.cos * p.radius;
|
|
241
|
+
p.y = center.y - axis.radarOption.sin * p.radius;
|
|
242
|
+
|
|
243
|
+
// 生成标点的回调
|
|
244
|
+
this.emit('onPointCreated', p);
|
|
245
|
+
}
|
|
246
|
+
points.push(...shapePoints);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return points;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// 生成图的标注
|
|
253
|
+
createLabel(point) {
|
|
254
|
+
if(this.style.label && this.style.label.show === false) return;
|
|
255
|
+
|
|
256
|
+
const text = this.option.itemLabelFormat?this.option.itemLabelFormat.call(this, point): point.yValue;
|
|
257
|
+
if(!text) return;
|
|
258
|
+
|
|
259
|
+
// v如果指定了为控件,则直接加入
|
|
260
|
+
if(text instanceof jmControl) {
|
|
261
|
+
this.addShape(text);
|
|
262
|
+
return text;
|
|
263
|
+
}
|
|
264
|
+
const self = this;
|
|
265
|
+
const label = this.graph.createShape('label', {
|
|
266
|
+
style: this.style.label,
|
|
267
|
+
text: text,
|
|
268
|
+
point,
|
|
269
|
+
position: function() {
|
|
270
|
+
const p = {
|
|
271
|
+
x: this.option.point.x,
|
|
272
|
+
y: this.option.point.y
|
|
273
|
+
}
|
|
274
|
+
if(p.x < self.center.x) {
|
|
275
|
+
p.x -= this.width;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if(p.y < self.center.y) {
|
|
279
|
+
p.y -= this.height;
|
|
280
|
+
}
|
|
281
|
+
return p;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
this.addShape(label);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* 生成图例
|
|
293
|
+
*
|
|
294
|
+
* @method createLegend
|
|
295
|
+
*/
|
|
296
|
+
jmRadarSeries.prototype.createLegend = function(point) {
|
|
297
|
+
if(!point) return;
|
|
298
|
+
|
|
299
|
+
//生成图例前的图标
|
|
300
|
+
const style = this.graph.utils.clone(point.style);
|
|
301
|
+
|
|
302
|
+
//delete style.stroke;
|
|
303
|
+
const shape = this.graph.createShape('rect',{
|
|
304
|
+
style: style,
|
|
305
|
+
position : {x: 0, y: 0}
|
|
306
|
+
});
|
|
307
|
+
//此处重写图例事件
|
|
308
|
+
this.graph.legend.append(this, shape, {
|
|
309
|
+
name: this.legendLabel,
|
|
310
|
+
data: point.data
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|